gdiplus: Implement GdipGetImageEncoders.

This commit is contained in:
Nathan Beckmann 2008-03-06 01:17:00 -08:00 committed by Alexandre Julliard
parent 7f50e42bbc
commit 366854a7cc
6 changed files with 162 additions and 2 deletions

View File

@ -284,8 +284,8 @@
@ stub GdipGetImageDecoders
@ stub GdipGetImageDecodersSize
@ stdcall GdipGetImageDimension(ptr ptr ptr)
@ stub GdipGetImageEncoders
@ stub GdipGetImageEncodersSize
@ stdcall GdipGetImageEncoders(long long ptr)
@ stdcall GdipGetImageEncodersSize(ptr ptr)
@ stub GdipGetImageFlags
@ stdcall GdipGetImageGraphicsContext(ptr ptr)
@ stdcall GdipGetImageHeight(ptr ptr)

View File

@ -836,3 +836,63 @@ GpStatus WINGDIPAPI GdipSetImagePalette(GpImage *image,
return NotImplemented;
}
/*************************************************************************
* Encoders -
* Structures that represent which formats we support for encoding.
*/
typedef enum {
BMP,
NUM_ENCODERS_SUPPORTED
} ImageFormat;
/* ImageCodecInfo creation routines taken from libgdiplus */
static const WCHAR bmp_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
static const WCHAR bmp_extension[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
static const WCHAR bmp_mimetype[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
static const WCHAR bmp_format[] = {'B', 'M', 'P', 0}; /* BMP */
static const BYTE bmp_sig_pattern[] = { 0x42, 0x4D };
static const BYTE bmp_sig_mask[] = { 0xFF, 0xFF };
static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED] =
{
{ /* BMP */
/* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
/* FormatID */ { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
/* CodecName */ bmp_codecname,
/* DllName */ NULL,
/* FormatDescription */ bmp_format,
/* FilenameExtension */ bmp_extension,
/* MimeType */ bmp_mimetype,
/* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
/* Version */ 1,
/* SigCount */ 1,
/* SigSize */ 2,
/* SigPattern */ bmp_sig_pattern,
/* SigMask */ bmp_sig_mask,
},
};
GpStatus WINGDIPAPI GdipGetImageEncodersSize(UINT *numEncoders, UINT *size)
{
if (!numEncoders || !size)
return InvalidParameter;
*numEncoders = NUM_ENCODERS_SUPPORTED;
*size = sizeof (codecs);
return Ok;
}
GpStatus WINGDIPAPI GdipGetImageEncoders(UINT numEncoders, UINT size, ImageCodecInfo *encoders)
{
if (!encoders ||
(numEncoders != NUM_ENCODERS_SUPPORTED) ||
(size != sizeof (codecs)))
return GenericError;
memcpy(encoders, codecs, sizeof (codecs));
return Ok;
}

View File

@ -122,6 +122,55 @@ static void test_LoadingImages(void)
expect(InvalidParameter, stat);
}
static void test_encoders(void)
{
GpStatus stat;
UINT n;
UINT s;
ImageCodecInfo *codecs;
int i;
int bmp_found;
static const WCHAR bmp_format[] = {'B', 'M', 'P', 0};
stat = GdipGetImageEncodersSize(&n, &s);
expect(stat, Ok);
codecs = GdipAlloc(s);
if (!codecs)
return;
stat = GdipGetImageEncoders(n, s, NULL);
expect(GenericError, stat);
stat = GdipGetImageEncoders(0, s, codecs);
expect(GenericError, stat);
stat = GdipGetImageEncoders(n, s-1, codecs);
expect(GenericError, stat);
stat = GdipGetImageEncoders(n, s+1, codecs);
expect(GenericError, stat);
stat = GdipGetImageEncoders(n, s, codecs);
expect(stat, Ok);
bmp_found = FALSE;
for (i = 0; i < n; i++)
{
if (CompareStringW(LOCALE_SYSTEM_DEFAULT, 0,
codecs[i].FormatDescription, -1,
bmp_format, -1) == CSTR_EQUAL) {
bmp_found = TRUE;
break;
}
}
if (!bmp_found)
ok(FALSE, "No BMP codec found.\n");
GdipFree(codecs);
}
START_TEST(image)
{
struct GdiplusStartupInput gdiplusStartupInput;
@ -137,6 +186,7 @@ START_TEST(image)
test_Scan0();
test_GetImageDimension();
test_LoadingImages();
test_encoders();
GdiplusShutdown(gdiplusToken);
}

View File

@ -257,6 +257,18 @@ enum HotkeyPrefix
HotkeyPrefixHide = 2
};
enum ImageCodecFlags
{
ImageCodecFlagsEncoder = 1,
ImageCodecFlagsDecoder = 2,
ImageCodecFlagsSupportBitmap = 4,
ImageCodecFlagsSupportVector = 8,
ImageCodecFlagsSeekableEncode = 16,
ImageCodecFlagsBlockingDecode = 32,
ImageCodecFlagsBuiltin = 65536,
ImageCodecFlagsSystem = 131072,
ImageCodecFlagsUser = 262144
};
#ifndef __cplusplus
@ -286,6 +298,7 @@ typedef enum StringTrimming StringTrimming;
typedef enum StringFormatFlags StringFormatFlags;
typedef enum HotkeyPrefix HotkeyPrefix;
typedef enum PenAlignment GpPenAlignment;
typedef enum ImageCodecFlags ImageCodecFlags;
#endif /* end of c typedefs */

View File

@ -258,6 +258,8 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromStreamICM(IStream*,GpBitmap**);
GpStatus WINGDIPAPI GdipDisposeImage(GpImage*);
GpStatus WINGDIPAPI GdipFindFirstImageItem(GpImage*,ImageItemData*);
GpStatus WINGDIPAPI GdipFindNextImageItem(GpImage*,ImageItemData*);
GpStatus WINGDIPAPI GdipGetImageEncodersSize(UINT *numEncoders, UINT *size);
GpStatus WINGDIPAPI GdipGetImageEncoders(UINT numEncoders, UINT size, ImageCodecInfo *encoders);
GpStatus WINGDIPAPI GdipGetImageItemData(GpImage*,ImageItemData*);
GpStatus WINGDIPAPI GdipGetImageBounds(GpImage*,GpRectF*,GpUnit*);
GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage*,GpGraphics**);

View File

@ -43,6 +43,24 @@ public:
EncoderParameter Parameter[1];
};
class ImageCodecInfo
{
public:
CLSID Clsid;
GUID FormatID;
const WCHAR* CodecName;
const WCHAR* DllName;
const WCHAR* FormatDescription;
const WCHAR* FilenameExtension;
const WCHAR* MimeType;
DWORD Flags;
DWORD Version;
DWORD SigCount;
DWORD SigSize;
const BYTE* SigPattern;
const BYTE* SigMask;
};
class BitmapData
{
public:
@ -84,6 +102,23 @@ typedef struct EncoderParameters
EncoderParameter Parameter[1];
} EncoderParameters;
typedef struct ImageCodecInfo
{
CLSID Clsid;
GUID FormatID;
const WCHAR* CodecName;
const WCHAR* DllName;
const WCHAR* FormatDescription;
const WCHAR* FilenameExtension;
const WCHAR* MimeType;
DWORD Flags;
DWORD Version;
DWORD SigCount;
DWORD SigSize;
const BYTE* SigPattern;
const BYTE* SigMask;
} ImageCodecInfo;
typedef struct BitmapData
{
UINT Width;