2 * Copyright (C) 2007 Google (Evan Stade)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "gdiplus_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
37 #define PIXELFORMATBPP(x) ((x) ? ((x) >> 8) & 255 : 24)
39 static INT ipicture_pixel_height(IPicture *pic)
44 IPicture_get_Height(pic, &y);
48 y = MulDiv(y, GetDeviceCaps(hdcref, LOGPIXELSY), INCH_HIMETRIC);
54 static INT ipicture_pixel_width(IPicture *pic)
59 IPicture_get_Width(pic, &x);
63 x = MulDiv(x, GetDeviceCaps(hdcref, LOGPIXELSX), INCH_HIMETRIC);
70 GpStatus WINGDIPAPI GdipBitmapGetPixel(GpBitmap* bitmap, INT x, INT y,
74 TRACE("%p %d %d %p\n", bitmap, x, y, color);
77 return InvalidParameter;
80 FIXME("not implemented\n");
84 return NotImplemented;
87 /* This function returns a pointer to an array of pixels that represents the
88 * bitmap. The *entire* bitmap is locked according to the lock mode specified by
89 * flags. It is correct behavior that a user who calls this function with write
90 * privileges can write to the whole bitmap (not just the area in rect).
92 * FIXME: only used portion of format is bits per pixel. */
93 GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect,
94 UINT flags, PixelFormat format, BitmapData* lockeddata)
97 INT stride, bitspp = PIXELFORMATBPP(format);
105 TRACE("%p %p %d %d %p\n", bitmap, rect, flags, format, lockeddata);
107 if(!lockeddata || !bitmap || !rect)
108 return InvalidParameter;
110 if(rect->X < 0 || rect->Y < 0 || (rect->X + rect->Width > bitmap->width) ||
111 (rect->Y + rect->Height > bitmap->height) || !flags)
112 return InvalidParameter;
114 if(flags & ImageLockModeUserInputBuf)
115 return NotImplemented;
120 IPicture_get_Handle(bitmap->image.picture, &hbm);
121 IPicture_get_CurDC(bitmap->image.picture, &hdc);
122 bm_is_selected = (hdc != 0);
124 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
125 bmi.bmiHeader.biBitCount = 0;
128 hdc = CreateCompatibleDC(0);
129 old = SelectObject(hdc, (HBITMAP)hbm);
133 GetDIBits(hdc, (HBITMAP)hbm, 0, 0, NULL, &bmi, DIB_RGB_COLORS);
135 abs_height = abs(bmi.bmiHeader.biHeight);
136 stride = bmi.bmiHeader.biWidth * bitspp / 8;
137 stride = (stride + 3) & ~3;
139 buff = GdipAlloc(stride * abs_height);
141 bmi.bmiHeader.biBitCount = bitspp;
144 GetDIBits(hdc, (HBITMAP)hbm, 0, abs_height, buff, &bmi, DIB_RGB_COLORS);
147 SelectObject(hdc, old);
154 lockeddata->Width = rect->Width;
155 lockeddata->Height = rect->Height;
156 lockeddata->PixelFormat = format;
157 lockeddata->Reserved = flags;
159 if(bmi.bmiHeader.biHeight > 0){
160 lockeddata->Stride = -stride;
161 lockeddata->Scan0 = buff + (bitspp / 8) * rect->X +
162 stride * (abs_height - 1 - rect->Y);
165 lockeddata->Stride = stride;
166 lockeddata->Scan0 = buff + (bitspp / 8) * rect->X + stride * rect->Y;
169 bitmap->lockmode = flags;
172 bitmap->bitmapbits = buff;
177 GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap* bitmap,
178 BitmapData* lockeddata)
186 if(!bitmap || !lockeddata)
187 return InvalidParameter;
189 if(!bitmap->lockmode)
192 if(lockeddata->Reserved & ImageLockModeUserInputBuf)
193 return NotImplemented;
195 if(lockeddata->Reserved & ImageLockModeRead){
196 if(!(--bitmap->numlocks))
197 bitmap->lockmode = 0;
199 GdipFree(bitmap->bitmapbits);
200 bitmap->bitmapbits = NULL;
204 IPicture_get_Handle(bitmap->image.picture, &hbm);
205 IPicture_get_CurDC(bitmap->image.picture, &hdc);
206 bm_is_selected = (hdc != 0);
208 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
209 bmi.bmiHeader.biBitCount = 0;
212 hdc = CreateCompatibleDC(0);
213 old = SelectObject(hdc, (HBITMAP)hbm);
216 GetDIBits(hdc, (HBITMAP)hbm, 0, 0, NULL, &bmi, DIB_RGB_COLORS);
217 bmi.bmiHeader.biBitCount = PIXELFORMATBPP(lockeddata->PixelFormat);
218 SetDIBits(hdc, (HBITMAP)hbm, 0, abs(bmi.bmiHeader.biHeight),
219 bitmap->bitmapbits, &bmi, DIB_RGB_COLORS);
222 SelectObject(hdc, old);
226 GdipFree(bitmap->bitmapbits);
227 bitmap->bitmapbits = NULL;
228 bitmap->lockmode = 0;
233 GpStatus WINGDIPAPI GdipCreateBitmapFromFile(GDIPCONST WCHAR* filename,
239 if(!filename || !bitmap)
240 return InvalidParameter;
242 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
247 stat = GdipCreateBitmapFromStream(stream, bitmap);
249 IStream_Release(stream);
255 GpStatus WINGDIPAPI GdipCreateBitmapFromFileICM(GDIPCONST WCHAR* filename,
258 return GdipCreateBitmapFromFile(filename, bitmap);
261 GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
262 HBITMAP* hbmReturn, ARGB background)
268 return NotImplemented;
271 GpStatus WINGDIPAPI GdipConvertToEmfPlus(const GpGraphics* ref,
272 GpMetafile* metafile, BOOL* succ, EmfType emfType,
273 const WCHAR* description, GpMetafile** out_metafile)
277 if(!ref || !metafile || !out_metafile)
278 return InvalidParameter;
281 *out_metafile = NULL;
284 FIXME("not implemented\n");
286 return NotImplemented;
289 /* FIXME: this should create a bitmap in the given size with the attributes
290 * (resolution etc.) of the graphics object */
291 GpStatus WINGDIPAPI GdipCreateBitmapFromGraphics(INT width, INT height,
292 GpGraphics* target, GpBitmap** bitmap)
297 if(!target || !bitmap)
298 return InvalidParameter;
301 FIXME("hacked stub\n");
303 ret = GdipCreateBitmapFromScan0(width, height, 0, PixelFormat24bppRGB,
309 GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
310 PixelFormat format, BYTE* scan0, GpBitmap** bitmap)
312 BITMAPFILEHEADER *bmfh;
313 BITMAPINFOHEADER *bmih;
318 TRACE("%d %d %d %d %p %p\n", width, height, stride, format, scan0, bitmap);
320 if(!bitmap || width <= 0 || height <= 0 || (scan0 && (stride % 4))){
322 return InvalidParameter;
326 return InvalidParameter;
328 /* FIXME: windows allows negative stride (reads backwards from scan0) */
330 FIXME("negative stride\n");
331 return InvalidParameter;
334 *bitmap = GdipAlloc(sizeof(GpBitmap));
335 if(!*bitmap) return OutOfMemory;
338 stride = width * (PIXELFORMATBPP(format) / 8);
339 stride = (stride + 3) & ~3;
342 datalen = abs(stride * height);
343 size = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + datalen;
344 buff = GdipAlloc(size);
350 bmfh = (BITMAPFILEHEADER*) buff;
351 bmih = (BITMAPINFOHEADER*) (bmfh + 1);
353 bmfh->bfType = (((WORD)'M') << 8) + (WORD)'B';
355 bmfh->bfOffBits = size - datalen;
357 bmih->biSize = sizeof(BITMAPINFOHEADER);
358 bmih->biWidth = width;
359 bmih->biHeight = -height;
360 /* FIXME: use the rest of the data from format */
361 bmih->biBitCount = PIXELFORMATBPP(format);
362 bmih->biCompression = BI_RGB;
363 bmih->biSizeImage = datalen;
366 memcpy(bmih + 1, scan0, datalen);
368 memset(bmih + 1, 0, datalen);
370 if(CreateStreamOnHGlobal(buff, TRUE, &stream) != S_OK){
371 ERR("could not make stream\n");
377 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
378 (LPVOID*) &((*bitmap)->image.picture)) != S_OK){
379 TRACE("Could not load picture\n");
380 IStream_Release(stream);
386 (*bitmap)->image.type = ImageTypeBitmap;
387 (*bitmap)->width = width;
388 (*bitmap)->height = height;
389 (*bitmap)->format = format;
394 GpStatus WINGDIPAPI GdipCreateBitmapFromStream(IStream* stream,
399 stat = GdipLoadImageFromStream(stream, (GpImage**) bitmap);
404 if((*bitmap)->image.type != ImageTypeBitmap){
405 IPicture_Release((*bitmap)->image.picture);
407 return GenericError; /* FIXME: what error to return? */
414 GpStatus WINGDIPAPI GdipCreateBitmapFromStreamICM(IStream* stream,
417 return GdipCreateBitmapFromStream(stream, bitmap);
420 GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
425 return InvalidParameter;
427 IPicture_get_CurDC(image->picture, &hdc);
429 IPicture_Release(image->picture);
430 if (image->type == ImageTypeBitmap)
431 GdipFree(((GpBitmap*)image)->bitmapbits);
437 GpStatus WINGDIPAPI GdipFindFirstImageItem(GpImage *image, ImageItemData* item)
440 return InvalidParameter;
442 return NotImplemented;
445 GpStatus WINGDIPAPI GdipGetImageBounds(GpImage *image, GpRectF *srcRect,
448 if(!image || !srcRect || !srcUnit)
449 return InvalidParameter;
450 if(image->type == ImageTypeMetafile){
451 *srcRect = ((GpMetafile*)image)->bounds;
452 *srcUnit = ((GpMetafile*)image)->unit;
454 else if(image->type == ImageTypeBitmap){
455 srcRect->X = srcRect->Y = 0.0;
456 srcRect->Width = (REAL) ((GpBitmap*)image)->width;
457 srcRect->Height = (REAL) ((GpBitmap*)image)->height;
458 *srcUnit = UnitPixel;
461 srcRect->X = srcRect->Y = 0.0;
462 srcRect->Width = ipicture_pixel_width(image->picture);
463 srcRect->Height = ipicture_pixel_height(image->picture);
464 *srcUnit = UnitPixel;
467 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect->X, srcRect->Y,
468 srcRect->Width, srcRect->Height, *srcUnit);
473 GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width,
476 if(!image || !height || !width)
477 return InvalidParameter;
479 if(image->type == ImageTypeMetafile){
482 *height = convert_unit(hdc, ((GpMetafile*)image)->unit) *
483 ((GpMetafile*)image)->bounds.Height;
485 *width = convert_unit(hdc, ((GpMetafile*)image)->unit) *
486 ((GpMetafile*)image)->bounds.Width;
491 else if(image->type == ImageTypeBitmap){
492 *height = ((GpBitmap*)image)->height;
493 *width = ((GpBitmap*)image)->width;
496 *height = ipicture_pixel_height(image->picture);
497 *width = ipicture_pixel_width(image->picture);
500 TRACE("returning (%f, %f)\n", *height, *width);
504 GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage *image,
505 GpGraphics **graphics)
509 if(!image || !graphics)
510 return InvalidParameter;
512 if(image->type != ImageTypeBitmap){
513 FIXME("not implemented for image type %d\n", image->type);
514 return NotImplemented;
517 IPicture_get_CurDC(image->picture, &hdc);
520 hdc = CreateCompatibleDC(0);
521 IPicture_SelectPicture(image->picture, hdc, NULL, NULL);
524 return GdipCreateFromHDC(hdc, graphics);
527 GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
529 if(!image || !height)
530 return InvalidParameter;
532 if(image->type == ImageTypeMetafile){
535 *height = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
536 ((GpMetafile*)image)->bounds.Height);
540 else if(image->type == ImageTypeBitmap)
541 *height = ((GpBitmap*)image)->height;
543 *height = ipicture_pixel_height(image->picture);
545 TRACE("returning %d\n", *height);
550 GpStatus WINGDIPAPI GdipGetImageHorizontalResolution(GpImage *image, REAL *res)
555 return InvalidParameter;
558 FIXME("not implemented\n");
560 return NotImplemented;
563 /* FIXME: test this function for non-bitmap types */
564 GpStatus WINGDIPAPI GdipGetImagePixelFormat(GpImage *image, PixelFormat *format)
566 if(!image || !format)
567 return InvalidParameter;
569 if(image->type != ImageTypeBitmap)
570 *format = PixelFormat24bppRGB;
572 *format = ((GpBitmap*) image)->format;
577 GpStatus WINGDIPAPI GdipGetImageRawFormat(GpImage *image, GUID *format)
581 if(!image || !format)
582 return InvalidParameter;
585 FIXME("not implemented\n");
587 return NotImplemented;
590 GpStatus WINGDIPAPI GdipGetImageType(GpImage *image, ImageType *type)
593 return InvalidParameter;
600 GpStatus WINGDIPAPI GdipGetImageVerticalResolution(GpImage *image, REAL *res)
605 return InvalidParameter;
608 FIXME("not implemented\n");
610 return NotImplemented;
613 GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
616 return InvalidParameter;
618 if(image->type == ImageTypeMetafile){
621 *width = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
622 ((GpMetafile*)image)->bounds.Width);
626 else if(image->type == ImageTypeBitmap)
627 *width = ((GpBitmap*)image)->width;
629 *width = ipicture_pixel_width(image->picture);
631 TRACE("returning %d\n", *width);
636 GpStatus WINGDIPAPI GdipGetMetafileHeaderFromMetafile(GpMetafile * metafile,
637 MetafileHeader * header)
641 if(!metafile || !header)
642 return InvalidParameter;
645 FIXME("not implemented\n");
650 GpStatus WINGDIPAPI GdipGetPropertyItemSize(GpImage *image, PROPID pid,
655 TRACE("%p %x %p\n", image, pid, size);
658 return InvalidParameter;
661 FIXME("not implemented\n");
663 return NotImplemented;
666 GpStatus WINGDIPAPI GdipImageGetFrameCount(GpImage *image,
667 GDIPCONST GUID* dimensionID, UINT* count)
671 if(!image || !dimensionID || !count)
672 return InvalidParameter;
675 FIXME("not implemented\n");
677 return NotImplemented;
680 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsList(GpImage* image,
681 GUID* dimensionIDs, UINT count)
685 if(!image || !dimensionIDs)
686 return InvalidParameter;
689 FIXME("not implemented\n");
694 GpStatus WINGDIPAPI GdipImageSelectActiveFrame(GpImage *image,
695 GDIPCONST GUID* dimensionID, UINT frameidx)
699 if(!image || !dimensionID)
700 return InvalidParameter;
703 FIXME("not implemented\n");
708 GpStatus WINGDIPAPI GdipLoadImageFromFile(GDIPCONST WCHAR* filename,
714 if (!filename || !image)
715 return InvalidParameter;
717 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
722 stat = GdipLoadImageFromStream(stream, image);
724 IStream_Release(stream);
729 GpStatus WINGDIPAPI GdipLoadImageFromStream(IStream* stream, GpImage **image)
734 if(!stream || !image)
735 return InvalidParameter;
737 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
738 (LPVOID*) &pic) != S_OK){
739 TRACE("Could not load picture\n");
743 IPicture_get_Type(pic, &type);
745 if(type == PICTYPE_BITMAP){
747 BITMAPCOREHEADER* bmch;
751 *image = GdipAlloc(sizeof(GpBitmap));
752 if(!*image) return OutOfMemory;
753 (*image)->type = ImageTypeBitmap;
755 (*((GpBitmap**) image))->width = ipicture_pixel_width(pic);
756 (*((GpBitmap**) image))->height = ipicture_pixel_height(pic);
758 /* get the pixel format */
759 IPicture_get_Handle(pic, &hbm);
760 IPicture_get_CurDC(pic, &hdc);
762 bmch = (BITMAPCOREHEADER*) (&bmi.bmiHeader);
763 bmch->bcSize = sizeof(BITMAPCOREHEADER);
767 hdc = CreateCompatibleDC(0);
768 old = SelectObject(hdc, (HBITMAP)hbm);
769 GetDIBits(hdc, (HBITMAP)hbm, 0, 0, NULL, &bmi, DIB_RGB_COLORS);
770 SelectObject(hdc, old);
774 GetDIBits(hdc, (HBITMAP)hbm, 0, 0, NULL, &bmi, DIB_RGB_COLORS);
776 (*((GpBitmap**) image))->format = (bmch->bcBitCount << 8) | PixelFormatGDI;
778 else if(type == PICTYPE_METAFILE || type == PICTYPE_ENHMETAFILE){
779 /* FIXME: missing initialization code */
780 *image = GdipAlloc(sizeof(GpMetafile));
781 if(!*image) return OutOfMemory;
782 (*image)->type = ImageTypeMetafile;
785 *image = GdipAlloc(sizeof(GpImage));
786 if(!*image) return OutOfMemory;
787 (*image)->type = ImageTypeUnknown;
790 (*image)->picture = pic;
796 GpStatus WINGDIPAPI GdipLoadImageFromStreamICM(IStream* stream, GpImage **image)
798 return GdipLoadImageFromStream(stream, image);
801 GpStatus WINGDIPAPI GdipRemovePropertyItem(GpImage *image, PROPID propId)
806 return InvalidParameter;
809 FIXME("not implemented\n");
811 return NotImplemented;
814 GpStatus WINGDIPAPI GdipSaveImageToFile(GpImage *image, GDIPCONST WCHAR* filename,
815 GDIPCONST CLSID *clsidEncoder,
816 GDIPCONST EncoderParameters *encoderParams)
821 if (!image || !filename|| !clsidEncoder)
822 return InvalidParameter;
824 if (!(image->picture))
825 return InvalidParameter;
827 stat = GdipCreateStreamOnFile(filename, GENERIC_WRITE, &stream);
831 stat = GdipSaveImageToStream(image, stream, clsidEncoder, encoderParams);
833 IStream_Release(stream);
837 /*************************************************************************
838 * Encoding functions -
839 * These functions encode an image in different image file formats.
841 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
842 #define BITMAP_FORMAT_JPEG 0xd8ff
843 #define BITMAP_FORMAT_GIF 0x4947
844 #define BITMAP_FORMAT_PNG 0x5089
845 #define BITMAP_FORMAT_APM 0xcdd7
847 static GpStatus encode_image_BMP(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
848 void **output, unsigned int *output_size)
850 int num_palette_entries;
851 BITMAPFILEHEADER *bmp_file_hdr;
852 BITMAPINFO *bmp_info_hdr;
854 if (bitmap_info->bmiHeader.biClrUsed) {
855 num_palette_entries = bitmap_info->bmiHeader.biClrUsed;
856 if (num_palette_entries > 256) num_palette_entries = 256;
858 if (bitmap_info->bmiHeader.biBitCount <= 8)
859 num_palette_entries = 1 << bitmap_info->bmiHeader.biBitCount;
861 num_palette_entries = 0;
865 sizeof(BITMAPFILEHEADER) +
866 sizeof(BITMAPINFOHEADER) +
867 num_palette_entries * sizeof(RGBQUAD) +
868 bitmap_info->bmiHeader.biSizeImage;
870 *output = GdipAlloc(*output_size);
872 bmp_file_hdr = (BITMAPFILEHEADER*) *output;
873 bmp_file_hdr->bfType = BITMAP_FORMAT_BMP;
874 bmp_file_hdr->bfSize = *output_size;
875 bmp_file_hdr->bfOffBits =
876 sizeof(BITMAPFILEHEADER) +
877 sizeof(BITMAPINFOHEADER) +
878 num_palette_entries * sizeof (RGBQUAD);
880 bmp_info_hdr = (BITMAPINFO*) ((unsigned char*)(*output) + sizeof(BITMAPFILEHEADER));
881 memcpy(bmp_info_hdr, bitmap_info, sizeof(BITMAPINFOHEADER) + num_palette_entries * sizeof(RGBQUAD));
882 memcpy((unsigned char *)(*output) +
883 sizeof(BITMAPFILEHEADER) +
884 sizeof(BITMAPINFOHEADER) +
885 num_palette_entries * sizeof(RGBQUAD),
886 bitmap_bits, bitmap_info->bmiHeader.biSizeImage);
891 typedef GpStatus encode_image_func(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
892 void **output, unsigned int *output_size);
896 NUM_ENCODERS_SUPPORTED
899 static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED];
900 static encode_image_func *const encode_image_funcs[NUM_ENCODERS_SUPPORTED] = {
904 GpStatus WINGDIPAPI GdipSaveImageToStream(GpImage *image, IStream* stream,
905 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
916 encode_image_func* encode_image;
918 unsigned int output_size;
926 if(!image || !stream)
927 return InvalidParameter;
932 hr = IPicture_get_Type(image->picture, &type);
933 if (FAILED(hr) || type != PICTYPE_BITMAP)
936 /* select correct encoder */
938 for (i = 0; i < NUM_ENCODERS_SUPPORTED; i++) {
939 if (IsEqualCLSID(clsid, &codecs[i].Clsid))
940 encode_image = encode_image_funcs[i];
942 if (encode_image == NULL)
943 return UnknownImageFormat;
945 /* extract underlying hbitmap representation from the IPicture */
946 hr = IPicture_get_Handle(image->picture, (OLE_HANDLE*)&hbmp);
947 if (FAILED(hr) || !hbmp)
949 hr = IPicture_get_CurDC(image->picture, &hdc);
952 bm_is_selected = (hdc != 0);
953 if (!bm_is_selected) {
954 hdc = CreateCompatibleDC(0);
955 old_hbmp = SelectObject(hdc, hbmp);
958 /* get bits from HBITMAP */
959 bmp_info.bmiHeader.biSize = sizeof(bmp_info.bmiHeader);
960 bmp_info.bmiHeader.biBitCount = 0;
961 GetDIBits(hdc, hbmp, 0, 0, NULL, &bmp_info, DIB_RGB_COLORS);
963 bmp_bits = GdipAlloc(bmp_info.bmiHeader.biSizeImage);
966 GetDIBits(hdc, hbmp, 0, abs(bmp_info.bmiHeader.biHeight), bmp_bits, &bmp_info, DIB_RGB_COLORS);
968 if (!bm_is_selected) {
969 SelectObject(hdc, old_hbmp);
976 stat = encode_image(bmp_bits, &bmp_info, &output, &output_size);
978 IStream_Write(stream, output, output_size, &dummy);
986 GpStatus WINGDIPAPI GdipSetImagePalette(GpImage *image,
987 GDIPCONST ColorPalette *palette)
991 if(!image || !palette)
992 return InvalidParameter;
995 FIXME("not implemented\n");
997 return NotImplemented;
1000 /*************************************************************************
1002 * Structures that represent which formats we support for encoding.
1005 /* ImageCodecInfo creation routines taken from libgdiplus */
1006 static const WCHAR bmp_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
1007 static const WCHAR bmp_extension[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
1008 static const WCHAR bmp_mimetype[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
1009 static const WCHAR bmp_format[] = {'B', 'M', 'P', 0}; /* BMP */
1010 static const BYTE bmp_sig_pattern[] = { 0x42, 0x4D };
1011 static const BYTE bmp_sig_mask[] = { 0xFF, 0xFF };
1013 static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED] =
1016 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
1017 /* FormatID */ { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
1018 /* CodecName */ bmp_codecname,
1020 /* FormatDescription */ bmp_format,
1021 /* FilenameExtension */ bmp_extension,
1022 /* MimeType */ bmp_mimetype,
1023 /* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
1027 /* SigPattern */ bmp_sig_pattern,
1028 /* SigMask */ bmp_sig_mask,
1032 GpStatus WINGDIPAPI GdipGetImageEncodersSize(UINT *numEncoders, UINT *size)
1034 if (!numEncoders || !size)
1035 return InvalidParameter;
1037 *numEncoders = NUM_ENCODERS_SUPPORTED;
1038 *size = sizeof (codecs);
1043 GpStatus WINGDIPAPI GdipGetImageEncoders(UINT numEncoders, UINT size, ImageCodecInfo *encoders)
1046 (numEncoders != NUM_ENCODERS_SUPPORTED) ||
1047 (size != sizeof (codecs)))
1048 return GenericError;
1050 memcpy(encoders, codecs, sizeof (codecs));
1054 GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBitmap** bitmap)
1061 return InvalidParameter;
1063 /* TODO: Support for device-dependent bitmaps */
1065 FIXME("no support for device-dependent bitmaps\n");
1066 return NotImplemented;
1069 if (GetObjectA(hbm, sizeof(bm), &bm) != sizeof(bm))
1070 return InvalidParameter;
1072 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
1073 switch(bm.bmBitsPixel) {
1075 format = PixelFormat1bppIndexed;
1078 format = PixelFormat4bppIndexed;
1081 format = PixelFormat8bppIndexed;
1084 format = PixelFormat24bppRGB;
1087 format = PixelFormat48bppRGB;
1090 FIXME("don't know how to handle %d bpp\n", bm.bmBitsPixel);
1091 return InvalidParameter;
1094 retval = GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, bm.bmWidthBytes,
1095 format, bm.bmBits, bitmap);
1100 GpStatus WINGDIPAPI GdipSetEffectParameters(CGpEffect *effect,
1101 const VOID *params, const UINT size)
1106 FIXME("not implemented\n");
1108 return NotImplemented;