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 ZeroMemory(&bmi, sizeof(bmi));
763 bmch = (BITMAPCOREHEADER*) (&bmi.bmiHeader);
764 bmch->bcSize = sizeof(BITMAPCOREHEADER);
768 hdc = CreateCompatibleDC(0);
769 old = SelectObject(hdc, (HBITMAP)hbm);
770 GetDIBits(hdc, (HBITMAP)hbm, 0, 0, NULL, &bmi, DIB_RGB_COLORS);
771 SelectObject(hdc, old);
775 GetDIBits(hdc, (HBITMAP)hbm, 0, 0, NULL, &bmi, DIB_RGB_COLORS);
777 (*((GpBitmap**) image))->format = (bmch->bcBitCount << 8) | PixelFormatGDI;
779 else if(type == PICTYPE_METAFILE || type == PICTYPE_ENHMETAFILE){
780 /* FIXME: missing initialization code */
781 *image = GdipAlloc(sizeof(GpMetafile));
782 if(!*image) return OutOfMemory;
783 (*image)->type = ImageTypeMetafile;
786 *image = GdipAlloc(sizeof(GpImage));
787 if(!*image) return OutOfMemory;
788 (*image)->type = ImageTypeUnknown;
791 (*image)->picture = pic;
797 GpStatus WINGDIPAPI GdipLoadImageFromStreamICM(IStream* stream, GpImage **image)
799 return GdipLoadImageFromStream(stream, image);
802 GpStatus WINGDIPAPI GdipRemovePropertyItem(GpImage *image, PROPID propId)
807 return InvalidParameter;
810 FIXME("not implemented\n");
812 return NotImplemented;
815 GpStatus WINGDIPAPI GdipSaveImageToFile(GpImage *image, GDIPCONST WCHAR* filename,
816 GDIPCONST CLSID *clsidEncoder,
817 GDIPCONST EncoderParameters *encoderParams)
822 if (!image || !filename|| !clsidEncoder)
823 return InvalidParameter;
825 if (!(image->picture))
826 return InvalidParameter;
828 stat = GdipCreateStreamOnFile(filename, GENERIC_WRITE, &stream);
832 stat = GdipSaveImageToStream(image, stream, clsidEncoder, encoderParams);
834 IStream_Release(stream);
838 /*************************************************************************
839 * Encoding functions -
840 * These functions encode an image in different image file formats.
842 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
843 #define BITMAP_FORMAT_JPEG 0xd8ff
844 #define BITMAP_FORMAT_GIF 0x4947
845 #define BITMAP_FORMAT_PNG 0x5089
846 #define BITMAP_FORMAT_APM 0xcdd7
848 static GpStatus encode_image_BMP(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
849 void **output, unsigned int *output_size)
851 int num_palette_entries;
852 BITMAPFILEHEADER *bmp_file_hdr;
853 BITMAPINFO *bmp_info_hdr;
855 if (bitmap_info->bmiHeader.biClrUsed) {
856 num_palette_entries = bitmap_info->bmiHeader.biClrUsed;
857 if (num_palette_entries > 256) num_palette_entries = 256;
859 if (bitmap_info->bmiHeader.biBitCount <= 8)
860 num_palette_entries = 1 << bitmap_info->bmiHeader.biBitCount;
862 num_palette_entries = 0;
866 sizeof(BITMAPFILEHEADER) +
867 sizeof(BITMAPINFOHEADER) +
868 num_palette_entries * sizeof(RGBQUAD) +
869 bitmap_info->bmiHeader.biSizeImage;
871 *output = GdipAlloc(*output_size);
873 bmp_file_hdr = (BITMAPFILEHEADER*) *output;
874 bmp_file_hdr->bfType = BITMAP_FORMAT_BMP;
875 bmp_file_hdr->bfSize = *output_size;
876 bmp_file_hdr->bfOffBits =
877 sizeof(BITMAPFILEHEADER) +
878 sizeof(BITMAPINFOHEADER) +
879 num_palette_entries * sizeof (RGBQUAD);
881 bmp_info_hdr = (BITMAPINFO*) ((unsigned char*)(*output) + sizeof(BITMAPFILEHEADER));
882 memcpy(bmp_info_hdr, bitmap_info, sizeof(BITMAPINFOHEADER) + num_palette_entries * sizeof(RGBQUAD));
883 memcpy((unsigned char *)(*output) +
884 sizeof(BITMAPFILEHEADER) +
885 sizeof(BITMAPINFOHEADER) +
886 num_palette_entries * sizeof(RGBQUAD),
887 bitmap_bits, bitmap_info->bmiHeader.biSizeImage);
892 typedef GpStatus encode_image_func(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
893 void **output, unsigned int *output_size);
897 NUM_ENCODERS_SUPPORTED
900 static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED];
901 static encode_image_func *const encode_image_funcs[NUM_ENCODERS_SUPPORTED] = {
905 GpStatus WINGDIPAPI GdipSaveImageToStream(GpImage *image, IStream* stream,
906 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
917 encode_image_func* encode_image;
919 unsigned int output_size;
927 if(!image || !stream)
928 return InvalidParameter;
933 hr = IPicture_get_Type(image->picture, &type);
934 if (FAILED(hr) || type != PICTYPE_BITMAP)
937 /* select correct encoder */
939 for (i = 0; i < NUM_ENCODERS_SUPPORTED; i++) {
940 if (IsEqualCLSID(clsid, &codecs[i].Clsid))
941 encode_image = encode_image_funcs[i];
943 if (encode_image == NULL)
944 return UnknownImageFormat;
946 /* extract underlying hbitmap representation from the IPicture */
947 hr = IPicture_get_Handle(image->picture, (OLE_HANDLE*)&hbmp);
948 if (FAILED(hr) || !hbmp)
950 hr = IPicture_get_CurDC(image->picture, &hdc);
953 bm_is_selected = (hdc != 0);
954 if (!bm_is_selected) {
955 hdc = CreateCompatibleDC(0);
956 old_hbmp = SelectObject(hdc, hbmp);
959 /* get bits from HBITMAP */
960 bmp_info.bmiHeader.biSize = sizeof(bmp_info.bmiHeader);
961 bmp_info.bmiHeader.biBitCount = 0;
962 GetDIBits(hdc, hbmp, 0, 0, NULL, &bmp_info, DIB_RGB_COLORS);
964 bmp_bits = GdipAlloc(bmp_info.bmiHeader.biSizeImage);
967 GetDIBits(hdc, hbmp, 0, abs(bmp_info.bmiHeader.biHeight), bmp_bits, &bmp_info, DIB_RGB_COLORS);
969 if (!bm_is_selected) {
970 SelectObject(hdc, old_hbmp);
977 stat = encode_image(bmp_bits, &bmp_info, &output, &output_size);
979 IStream_Write(stream, output, output_size, &dummy);
987 GpStatus WINGDIPAPI GdipSetImagePalette(GpImage *image,
988 GDIPCONST ColorPalette *palette)
992 if(!image || !palette)
993 return InvalidParameter;
996 FIXME("not implemented\n");
998 return NotImplemented;
1001 /*************************************************************************
1003 * Structures that represent which formats we support for encoding.
1006 /* ImageCodecInfo creation routines taken from libgdiplus */
1007 static const WCHAR bmp_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
1008 static const WCHAR bmp_extension[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
1009 static const WCHAR bmp_mimetype[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
1010 static const WCHAR bmp_format[] = {'B', 'M', 'P', 0}; /* BMP */
1011 static const BYTE bmp_sig_pattern[] = { 0x42, 0x4D };
1012 static const BYTE bmp_sig_mask[] = { 0xFF, 0xFF };
1014 static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED] =
1017 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
1018 /* FormatID */ { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
1019 /* CodecName */ bmp_codecname,
1021 /* FormatDescription */ bmp_format,
1022 /* FilenameExtension */ bmp_extension,
1023 /* MimeType */ bmp_mimetype,
1024 /* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
1028 /* SigPattern */ bmp_sig_pattern,
1029 /* SigMask */ bmp_sig_mask,
1033 GpStatus WINGDIPAPI GdipGetImageEncodersSize(UINT *numEncoders, UINT *size)
1035 if (!numEncoders || !size)
1036 return InvalidParameter;
1038 *numEncoders = NUM_ENCODERS_SUPPORTED;
1039 *size = sizeof (codecs);
1044 GpStatus WINGDIPAPI GdipGetImageEncoders(UINT numEncoders, UINT size, ImageCodecInfo *encoders)
1047 (numEncoders != NUM_ENCODERS_SUPPORTED) ||
1048 (size != sizeof (codecs)))
1049 return GenericError;
1051 memcpy(encoders, codecs, sizeof (codecs));
1055 GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBitmap** bitmap)
1062 return InvalidParameter;
1064 /* TODO: Support for device-dependent bitmaps */
1066 FIXME("no support for device-dependent bitmaps\n");
1067 return NotImplemented;
1070 if (GetObjectA(hbm, sizeof(bm), &bm) != sizeof(bm))
1071 return InvalidParameter;
1073 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
1074 switch(bm.bmBitsPixel) {
1076 format = PixelFormat1bppIndexed;
1079 format = PixelFormat4bppIndexed;
1082 format = PixelFormat8bppIndexed;
1085 format = PixelFormat24bppRGB;
1088 format = PixelFormat48bppRGB;
1091 FIXME("don't know how to handle %d bpp\n", bm.bmBitsPixel);
1092 return InvalidParameter;
1095 retval = GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, bm.bmWidthBytes,
1096 format, bm.bmBits, bitmap);
1101 GpStatus WINGDIPAPI GdipSetEffectParameters(CGpEffect *effect,
1102 const VOID *params, const UINT size)
1107 FIXME("not implemented\n");
1109 return NotImplemented;