55522258891354ea6a0a963ca48d2db621c7257f
[reactos.git] / reactos / dll / win32 / gdiplus / image.c
1 /*
2 * Copyright (C) 2007 Google (Evan Stade)
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #include <stdarg.h>
20
21 #define NONAMELESSUNION
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "wingdi.h"
27
28 #define COBJMACROS
29 #include "objbase.h"
30 #include "olectl.h"
31 #include "ole2.h"
32
33 #include "initguid.h"
34 #include "gdiplus.h"
35 #include "gdiplus_private.h"
36 #include "wine/debug.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
39
40 #define PIXELFORMATBPP(x) ((x) ? ((x) >> 8) & 255 : 24)
41
42 static INT ipicture_pixel_height(IPicture *pic)
43 {
44 HDC hdcref;
45 OLE_YSIZE_HIMETRIC y;
46
47 IPicture_get_Height(pic, &y);
48
49 hdcref = GetDC(0);
50
51 y = MulDiv(y, GetDeviceCaps(hdcref, LOGPIXELSY), INCH_HIMETRIC);
52 ReleaseDC(0, hdcref);
53
54 return y;
55 }
56
57 static INT ipicture_pixel_width(IPicture *pic)
58 {
59 HDC hdcref;
60 OLE_XSIZE_HIMETRIC x;
61
62 IPicture_get_Width(pic, &x);
63
64 hdcref = GetDC(0);
65
66 x = MulDiv(x, GetDeviceCaps(hdcref, LOGPIXELSX), INCH_HIMETRIC);
67
68 ReleaseDC(0, hdcref);
69
70 return x;
71 }
72
73 GpStatus WINGDIPAPI GdipBitmapGetPixel(GpBitmap* bitmap, INT x, INT y,
74 ARGB *color)
75 {
76 static int calls;
77 TRACE("%p %d %d %p\n", bitmap, x, y, color);
78
79 if(!bitmap || !color)
80 return InvalidParameter;
81
82 if(!(calls++))
83 FIXME("not implemented\n");
84
85 *color = 0xdeadbeef;
86
87 return NotImplemented;
88 }
89
90 /* This function returns a pointer to an array of pixels that represents the
91 * bitmap. The *entire* bitmap is locked according to the lock mode specified by
92 * flags. It is correct behavior that a user who calls this function with write
93 * privileges can write to the whole bitmap (not just the area in rect).
94 *
95 * FIXME: only used portion of format is bits per pixel. */
96 GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect,
97 UINT flags, PixelFormat format, BitmapData* lockeddata)
98 {
99 BOOL bm_is_selected;
100 INT stride, bitspp = PIXELFORMATBPP(format);
101 HDC hdc;
102 HBITMAP hbm, old = NULL;
103 BITMAPINFO *pbmi;
104 BYTE *buff = NULL;
105 UINT abs_height;
106 GpRect act_rect; /* actual rect to be used */
107
108 TRACE("%p %p %d %d %p\n", bitmap, rect, flags, format, lockeddata);
109
110 if(!lockeddata || !bitmap)
111 return InvalidParameter;
112
113 if(rect){
114 if(rect->X < 0 || rect->Y < 0 || (rect->X + rect->Width > bitmap->width) ||
115 (rect->Y + rect->Height > bitmap->height) || !flags)
116 return InvalidParameter;
117
118 act_rect = *rect;
119 }
120 else{
121 act_rect.X = act_rect.Y = 0;
122 act_rect.Width = bitmap->width;
123 act_rect.Height = bitmap->height;
124 }
125
126 if(flags & ImageLockModeUserInputBuf)
127 return NotImplemented;
128
129 if(bitmap->lockmode)
130 return WrongState;
131
132 IPicture_get_Handle(bitmap->image.picture, (OLE_HANDLE*)&hbm);
133 IPicture_get_CurDC(bitmap->image.picture, &hdc);
134 bm_is_selected = (hdc != 0);
135
136 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
137 if (!pbmi)
138 return OutOfMemory;
139 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
140 pbmi->bmiHeader.biBitCount = 0;
141
142 if(!bm_is_selected){
143 hdc = CreateCompatibleDC(0);
144 old = SelectObject(hdc, hbm);
145 }
146
147 /* fill out bmi */
148 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
149
150 abs_height = abs(pbmi->bmiHeader.biHeight);
151 stride = pbmi->bmiHeader.biWidth * bitspp / 8;
152 stride = (stride + 3) & ~3;
153
154 buff = GdipAlloc(stride * abs_height);
155
156 pbmi->bmiHeader.biBitCount = bitspp;
157
158 if(buff)
159 GetDIBits(hdc, hbm, 0, abs_height, buff, pbmi, DIB_RGB_COLORS);
160
161 if(!bm_is_selected){
162 SelectObject(hdc, old);
163 DeleteDC(hdc);
164 }
165
166 if(!buff){
167 GdipFree(pbmi);
168 return OutOfMemory;
169 }
170
171 lockeddata->Width = act_rect.Width;
172 lockeddata->Height = act_rect.Height;
173 lockeddata->PixelFormat = format;
174 lockeddata->Reserved = flags;
175
176 if(pbmi->bmiHeader.biHeight > 0){
177 lockeddata->Stride = -stride;
178 lockeddata->Scan0 = buff + (bitspp / 8) * act_rect.X +
179 stride * (abs_height - 1 - act_rect.Y);
180 }
181 else{
182 lockeddata->Stride = stride;
183 lockeddata->Scan0 = buff + (bitspp / 8) * act_rect.X + stride * act_rect.Y;
184 }
185
186 bitmap->lockmode = flags;
187 bitmap->numlocks++;
188
189 bitmap->bitmapbits = buff;
190
191 GdipFree(pbmi);
192 return Ok;
193 }
194
195 GpStatus WINGDIPAPI GdipBitmapSetResolution(GpBitmap* bitmap, REAL xdpi, REAL ydpi)
196 {
197 FIXME("(%p, %.2f, %.2f)\n", bitmap, xdpi, ydpi);
198
199 return NotImplemented;
200 }
201
202 GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap* bitmap,
203 BitmapData* lockeddata)
204 {
205 HDC hdc;
206 HBITMAP hbm, old = NULL;
207 BOOL bm_is_selected;
208 BITMAPINFO *pbmi;
209
210 if(!bitmap || !lockeddata)
211 return InvalidParameter;
212
213 if(!bitmap->lockmode)
214 return WrongState;
215
216 if(lockeddata->Reserved & ImageLockModeUserInputBuf)
217 return NotImplemented;
218
219 if(lockeddata->Reserved & ImageLockModeRead){
220 if(!(--bitmap->numlocks))
221 bitmap->lockmode = 0;
222
223 GdipFree(bitmap->bitmapbits);
224 bitmap->bitmapbits = NULL;
225 return Ok;
226 }
227
228 IPicture_get_Handle(bitmap->image.picture, (OLE_HANDLE*)&hbm);
229 IPicture_get_CurDC(bitmap->image.picture, &hdc);
230 bm_is_selected = (hdc != 0);
231
232 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
233 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
234 pbmi->bmiHeader.biBitCount = 0;
235
236 if(!bm_is_selected){
237 hdc = CreateCompatibleDC(0);
238 old = SelectObject(hdc, hbm);
239 }
240
241 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
242 pbmi->bmiHeader.biBitCount = PIXELFORMATBPP(lockeddata->PixelFormat);
243 SetDIBits(hdc, hbm, 0, abs(pbmi->bmiHeader.biHeight),
244 bitmap->bitmapbits, pbmi, DIB_RGB_COLORS);
245
246 if(!bm_is_selected){
247 SelectObject(hdc, old);
248 DeleteDC(hdc);
249 }
250
251 GdipFree(pbmi);
252 GdipFree(bitmap->bitmapbits);
253 bitmap->bitmapbits = NULL;
254 bitmap->lockmode = 0;
255
256 return Ok;
257 }
258
259 GpStatus WINGDIPAPI GdipCloneBitmapAreaI(INT x, INT y, INT width, INT height,
260 PixelFormat format, GpBitmap* srcBitmap, GpBitmap** dstBitmap)
261 {
262 FIXME("(%i,%i,%i,%i,%i,%p,%p)\n", x, y, width, height, format, srcBitmap, dstBitmap);
263
264 return NotImplemented;
265 }
266
267 GpStatus WINGDIPAPI GdipCloneImage(GpImage *image, GpImage **cloneImage)
268 {
269 IStream* stream;
270 HRESULT hr;
271 INT size;
272 LARGE_INTEGER move;
273 GpStatus stat = GenericError;
274
275 TRACE("%p, %p\n", image, cloneImage);
276
277 if (!image || !cloneImage)
278 return InvalidParameter;
279
280 hr = CreateStreamOnHGlobal(0, TRUE, &stream);
281 if (FAILED(hr))
282 return GenericError;
283
284 hr = IPicture_SaveAsFile(image->picture, stream, FALSE, &size);
285 if(FAILED(hr))
286 {
287 WARN("Failed to save image on stream\n");
288 goto out;
289 }
290
291 /* Set seek pointer back to the beginning of the picture */
292 move.QuadPart = 0;
293 hr = IStream_Seek(stream, move, STREAM_SEEK_SET, NULL);
294 if (FAILED(hr))
295 goto out;
296
297 stat = GdipLoadImageFromStream(stream, cloneImage);
298 if (stat != Ok) WARN("Failed to load image from stream\n");
299
300 out:
301 IStream_Release(stream);
302 return stat;
303 }
304
305 GpStatus WINGDIPAPI GdipCreateBitmapFromFile(GDIPCONST WCHAR* filename,
306 GpBitmap **bitmap)
307 {
308 GpStatus stat;
309 IStream *stream;
310
311 TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
312
313 if(!filename || !bitmap)
314 return InvalidParameter;
315
316 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
317
318 if(stat != Ok)
319 return stat;
320
321 stat = GdipCreateBitmapFromStream(stream, bitmap);
322
323 IStream_Release(stream);
324
325 return stat;
326 }
327
328 GpStatus WINGDIPAPI GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO* info,
329 VOID *bits, GpBitmap **bitmap)
330 {
331 DWORD height, stride;
332 PixelFormat format;
333
334 FIXME("(%p, %p, %p) - partially implemented\n", info, bits, bitmap);
335
336 height = abs(info->bmiHeader.biHeight);
337 stride = ((info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 31) >> 3) & ~3;
338
339 if(info->bmiHeader.biHeight > 0) /* bottom-up */
340 {
341 bits = (BYTE*)bits + (height - 1) * stride;
342 stride = -stride;
343 }
344
345 switch(info->bmiHeader.biBitCount) {
346 case 1:
347 format = PixelFormat1bppIndexed;
348 break;
349 case 4:
350 format = PixelFormat4bppIndexed;
351 break;
352 case 8:
353 format = PixelFormat8bppIndexed;
354 break;
355 case 24:
356 format = PixelFormat24bppRGB;
357 break;
358 default:
359 FIXME("don't know how to handle %d bpp\n", info->bmiHeader.biBitCount);
360 *bitmap = NULL;
361 return InvalidParameter;
362 }
363
364 return GdipCreateBitmapFromScan0(info->bmiHeader.biWidth, height, stride, format,
365 bits, bitmap);
366
367 }
368
369 /* FIXME: no icm */
370 GpStatus WINGDIPAPI GdipCreateBitmapFromFileICM(GDIPCONST WCHAR* filename,
371 GpBitmap **bitmap)
372 {
373 TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
374
375 return GdipCreateBitmapFromFile(filename, bitmap);
376 }
377
378 GpStatus WINGDIPAPI GdipCreateBitmapFromResource(HINSTANCE hInstance,
379 GDIPCONST WCHAR* lpBitmapName, GpBitmap** bitmap)
380 {
381 HBITMAP hbm;
382 GpStatus stat = InvalidParameter;
383
384 TRACE("%p (%s) %p\n", hInstance, debugstr_w(lpBitmapName), bitmap);
385
386 if(!lpBitmapName || !bitmap)
387 return InvalidParameter;
388
389 /* load DIB */
390 hbm = LoadImageW(hInstance, lpBitmapName, IMAGE_BITMAP, 0, 0,
391 LR_CREATEDIBSECTION);
392
393 if(hbm){
394 stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, bitmap);
395 DeleteObject(hbm);
396 }
397
398 return stat;
399 }
400
401 GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
402 HBITMAP* hbmReturn, ARGB background)
403 {
404 FIXME("stub\n");
405
406 hbmReturn = NULL;
407
408 return NotImplemented;
409 }
410
411 GpStatus WINGDIPAPI GdipConvertToEmfPlus(const GpGraphics* ref,
412 GpMetafile* metafile, BOOL* succ, EmfType emfType,
413 const WCHAR* description, GpMetafile** out_metafile)
414 {
415 static int calls;
416
417 if(!ref || !metafile || !out_metafile)
418 return InvalidParameter;
419
420 *succ = FALSE;
421 *out_metafile = NULL;
422
423 if(!(calls++))
424 FIXME("not implemented\n");
425
426 return NotImplemented;
427 }
428
429 /* FIXME: this should create a bitmap in the given size with the attributes
430 * (resolution etc.) of the graphics object */
431 GpStatus WINGDIPAPI GdipCreateBitmapFromGraphics(INT width, INT height,
432 GpGraphics* target, GpBitmap** bitmap)
433 {
434 static int calls;
435 GpStatus ret;
436
437 if(!target || !bitmap)
438 return InvalidParameter;
439
440 if(!(calls++))
441 FIXME("hacked stub\n");
442
443 ret = GdipCreateBitmapFromScan0(width, height, 0, PixelFormat24bppRGB,
444 NULL, bitmap);
445
446 return ret;
447 }
448
449 GpStatus WINGDIPAPI GdipCreateBitmapFromHICON(HICON hicon, GpBitmap** bitmap)
450 {
451 HICON icon_copy;
452 ICONINFO iinfo;
453 PICTDESC desc;
454
455 TRACE("%p, %p\n", hicon, bitmap);
456
457 if(!bitmap || !GetIconInfo(hicon, &iinfo))
458 return InvalidParameter;
459
460 *bitmap = GdipAlloc(sizeof(GpBitmap));
461 if(!*bitmap) return OutOfMemory;
462
463 icon_copy = CreateIconIndirect(&iinfo);
464
465 if(!icon_copy){
466 GdipFree(*bitmap);
467 return InvalidParameter;
468 }
469
470 desc.cbSizeofstruct = sizeof(PICTDESC);
471 desc.picType = PICTYPE_ICON;
472 desc.u.icon.hicon = icon_copy;
473
474 if(OleCreatePictureIndirect(&desc, &IID_IPicture, TRUE,
475 (LPVOID*) &((*bitmap)->image.picture)) != S_OK){
476 DestroyIcon(icon_copy);
477 GdipFree(*bitmap);
478 return GenericError;
479 }
480
481 (*bitmap)->format = PixelFormat32bppARGB;
482 (*bitmap)->image.type = ImageTypeBitmap;
483 (*bitmap)->image.flags = ImageFlagsNone;
484 (*bitmap)->width = ipicture_pixel_width((*bitmap)->image.picture);
485 (*bitmap)->height = ipicture_pixel_height((*bitmap)->image.picture);
486
487 DeleteObject(iinfo.hbmColor);
488 DeleteObject(iinfo.hbmMask);
489
490 return Ok;
491 }
492
493 GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
494 PixelFormat format, BYTE* scan0, GpBitmap** bitmap)
495 {
496 BITMAPFILEHEADER *bmfh;
497 BITMAPINFOHEADER *bmih;
498 BYTE *buff;
499 INT datalen, size;
500 IStream *stream;
501
502 TRACE("%d %d %d %d %p %p\n", width, height, stride, format, scan0, bitmap);
503
504 if (!bitmap) return InvalidParameter;
505
506 if(width <= 0 || height <= 0 || (scan0 && (stride % 4))){
507 *bitmap = NULL;
508 return InvalidParameter;
509 }
510
511 if(scan0 && !stride)
512 return InvalidParameter;
513
514 *bitmap = GdipAlloc(sizeof(GpBitmap));
515 if(!*bitmap) return OutOfMemory;
516
517 if(stride == 0){
518 stride = width * (PIXELFORMATBPP(format) / 8);
519 stride = (stride + 3) & ~3;
520 }
521
522 datalen = abs(stride * height);
523 size = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + datalen;
524 buff = GdipAlloc(size);
525 if(!buff){
526 GdipFree(*bitmap);
527 return OutOfMemory;
528 }
529
530 bmfh = (BITMAPFILEHEADER*) buff;
531 bmih = (BITMAPINFOHEADER*) (bmfh + 1);
532
533 bmfh->bfType = (((WORD)'M') << 8) + (WORD)'B';
534 bmfh->bfSize = size;
535 bmfh->bfOffBits = size - datalen;
536
537 bmih->biSize = sizeof(BITMAPINFOHEADER);
538 bmih->biWidth = width;
539 /* FIXME: use the rest of the data from format */
540 bmih->biBitCount = PIXELFORMATBPP(format);
541 bmih->biCompression = BI_RGB;
542 bmih->biSizeImage = datalen;
543
544 if (scan0)
545 {
546 if (stride > 0)
547 {
548 bmih->biHeight = -height;
549 memcpy(bmih + 1, scan0, datalen);
550 }
551 else
552 {
553 bmih->biHeight = height;
554 memcpy(bmih + 1, scan0 + stride * (height - 1), datalen);
555 }
556 }
557 else
558 {
559 bmih->biHeight = height;
560 memset(bmih + 1, 0, datalen);
561 }
562
563 if(CreateStreamOnHGlobal(buff, TRUE, &stream) != S_OK){
564 ERR("could not make stream\n");
565 GdipFree(*bitmap);
566 GdipFree(buff);
567 *bitmap = NULL;
568 return GenericError;
569 }
570
571 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
572 (LPVOID*) &((*bitmap)->image.picture)) != S_OK){
573 TRACE("Could not load picture\n");
574 IStream_Release(stream);
575 GdipFree(*bitmap);
576 GdipFree(buff);
577 *bitmap = NULL;
578 return GenericError;
579 }
580
581 (*bitmap)->image.type = ImageTypeBitmap;
582 (*bitmap)->image.flags = ImageFlagsNone;
583 (*bitmap)->width = width;
584 (*bitmap)->height = height;
585 (*bitmap)->format = format;
586
587 return Ok;
588 }
589
590 GpStatus WINGDIPAPI GdipCreateBitmapFromStream(IStream* stream,
591 GpBitmap **bitmap)
592 {
593 GpStatus stat;
594
595 TRACE("%p %p\n", stream, bitmap);
596
597 stat = GdipLoadImageFromStream(stream, (GpImage**) bitmap);
598
599 if(stat != Ok)
600 return stat;
601
602 if((*bitmap)->image.type != ImageTypeBitmap){
603 IPicture_Release((*bitmap)->image.picture);
604 GdipFree(bitmap);
605 return GenericError; /* FIXME: what error to return? */
606 }
607
608 return Ok;
609 }
610
611 /* FIXME: no icm */
612 GpStatus WINGDIPAPI GdipCreateBitmapFromStreamICM(IStream* stream,
613 GpBitmap **bitmap)
614 {
615 TRACE("%p %p\n", stream, bitmap);
616
617 return GdipCreateBitmapFromStream(stream, bitmap);
618 }
619
620 GpStatus WINGDIPAPI GdipCreateCachedBitmap(GpBitmap *bitmap, GpGraphics *graphics,
621 GpCachedBitmap **cachedbmp)
622 {
623 GpStatus stat;
624
625 TRACE("%p %p %p\n", bitmap, graphics, cachedbmp);
626
627 if(!bitmap || !graphics || !cachedbmp)
628 return InvalidParameter;
629
630 *cachedbmp = GdipAlloc(sizeof(GpCachedBitmap));
631 if(!*cachedbmp)
632 return OutOfMemory;
633
634 stat = GdipCloneImage(&(bitmap->image), &(*cachedbmp)->image);
635 if(stat != Ok){
636 GdipFree(*cachedbmp);
637 return stat;
638 }
639
640 return Ok;
641 }
642
643 GpStatus WINGDIPAPI GdipDeleteCachedBitmap(GpCachedBitmap *cachedbmp)
644 {
645 TRACE("%p\n", cachedbmp);
646
647 if(!cachedbmp)
648 return InvalidParameter;
649
650 GdipDisposeImage(cachedbmp->image);
651 GdipFree(cachedbmp);
652
653 return Ok;
654 }
655
656 GpStatus WINGDIPAPI GdipDrawCachedBitmap(GpGraphics *graphics,
657 GpCachedBitmap *cachedbmp, INT x, INT y)
658 {
659 TRACE("%p %p %d %d\n", graphics, cachedbmp, x, y);
660
661 if(!graphics || !cachedbmp)
662 return InvalidParameter;
663
664 return GdipDrawImage(graphics, cachedbmp->image, (REAL)x, (REAL)y);
665 }
666
667 GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
668 {
669 HDC hdc;
670
671 TRACE("%p\n", image);
672
673 if(!image)
674 return InvalidParameter;
675
676 IPicture_get_CurDC(image->picture, &hdc);
677 DeleteDC(hdc);
678 IPicture_Release(image->picture);
679 if (image->type == ImageTypeBitmap)
680 GdipFree(((GpBitmap*)image)->bitmapbits);
681 GdipFree(image);
682
683 return Ok;
684 }
685
686 GpStatus WINGDIPAPI GdipFindFirstImageItem(GpImage *image, ImageItemData* item)
687 {
688 if(!image || !item)
689 return InvalidParameter;
690
691 return NotImplemented;
692 }
693
694 GpStatus WINGDIPAPI GdipGetImageBounds(GpImage *image, GpRectF *srcRect,
695 GpUnit *srcUnit)
696 {
697 TRACE("%p %p %p\n", image, srcRect, srcUnit);
698
699 if(!image || !srcRect || !srcUnit)
700 return InvalidParameter;
701 if(image->type == ImageTypeMetafile){
702 *srcRect = ((GpMetafile*)image)->bounds;
703 *srcUnit = ((GpMetafile*)image)->unit;
704 }
705 else if(image->type == ImageTypeBitmap){
706 srcRect->X = srcRect->Y = 0.0;
707 srcRect->Width = (REAL) ((GpBitmap*)image)->width;
708 srcRect->Height = (REAL) ((GpBitmap*)image)->height;
709 *srcUnit = UnitPixel;
710 }
711 else{
712 srcRect->X = srcRect->Y = 0.0;
713 srcRect->Width = ipicture_pixel_width(image->picture);
714 srcRect->Height = ipicture_pixel_height(image->picture);
715 *srcUnit = UnitPixel;
716 }
717
718 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect->X, srcRect->Y,
719 srcRect->Width, srcRect->Height, *srcUnit);
720
721 return Ok;
722 }
723
724 GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width,
725 REAL *height)
726 {
727 TRACE("%p %p %p\n", image, width, height);
728
729 if(!image || !height || !width)
730 return InvalidParameter;
731
732 if(image->type == ImageTypeMetafile){
733 HDC hdc = GetDC(0);
734
735 *height = convert_unit(hdc, ((GpMetafile*)image)->unit) *
736 ((GpMetafile*)image)->bounds.Height;
737
738 *width = convert_unit(hdc, ((GpMetafile*)image)->unit) *
739 ((GpMetafile*)image)->bounds.Width;
740
741 ReleaseDC(0, hdc);
742 }
743
744 else if(image->type == ImageTypeBitmap){
745 *height = ((GpBitmap*)image)->height;
746 *width = ((GpBitmap*)image)->width;
747 }
748 else{
749 *height = ipicture_pixel_height(image->picture);
750 *width = ipicture_pixel_width(image->picture);
751 }
752
753 TRACE("returning (%f, %f)\n", *height, *width);
754 return Ok;
755 }
756
757 GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage *image,
758 GpGraphics **graphics)
759 {
760 HDC hdc;
761
762 TRACE("%p %p\n", image, graphics);
763
764 if(!image || !graphics)
765 return InvalidParameter;
766
767 if(image->type != ImageTypeBitmap){
768 FIXME("not implemented for image type %d\n", image->type);
769 return NotImplemented;
770 }
771
772 IPicture_get_CurDC(image->picture, &hdc);
773
774 if(!hdc){
775 hdc = CreateCompatibleDC(0);
776 IPicture_SelectPicture(image->picture, hdc, NULL, NULL);
777 }
778
779 return GdipCreateFromHDC(hdc, graphics);
780 }
781
782 GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
783 {
784 TRACE("%p %p\n", image, height);
785
786 if(!image || !height)
787 return InvalidParameter;
788
789 if(image->type == ImageTypeMetafile){
790 HDC hdc = GetDC(0);
791
792 *height = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
793 ((GpMetafile*)image)->bounds.Height);
794
795 ReleaseDC(0, hdc);
796 }
797 else if(image->type == ImageTypeBitmap)
798 *height = ((GpBitmap*)image)->height;
799 else
800 *height = ipicture_pixel_height(image->picture);
801
802 TRACE("returning %d\n", *height);
803
804 return Ok;
805 }
806
807 GpStatus WINGDIPAPI GdipGetImageHorizontalResolution(GpImage *image, REAL *res)
808 {
809 static int calls;
810
811 if(!image || !res)
812 return InvalidParameter;
813
814 if(!(calls++))
815 FIXME("not implemented\n");
816
817 return NotImplemented;
818 }
819
820 GpStatus WINGDIPAPI GdipGetImagePaletteSize(GpImage *image, INT *size)
821 {
822 FIXME("%p %p\n", image, size);
823
824 if(!image || !size)
825 return InvalidParameter;
826
827 return NotImplemented;
828 }
829
830 /* FIXME: test this function for non-bitmap types */
831 GpStatus WINGDIPAPI GdipGetImagePixelFormat(GpImage *image, PixelFormat *format)
832 {
833 TRACE("%p %p\n", image, format);
834
835 if(!image || !format)
836 return InvalidParameter;
837
838 if(image->type != ImageTypeBitmap)
839 *format = PixelFormat24bppRGB;
840 else
841 *format = ((GpBitmap*) image)->format;
842
843 return Ok;
844 }
845
846 GpStatus WINGDIPAPI GdipGetImageRawFormat(GpImage *image, GUID *format)
847 {
848 static int calls;
849
850 if(!image || !format)
851 return InvalidParameter;
852
853 if(!(calls++))
854 FIXME("stub\n");
855
856 /* FIXME: should be detected from embedded picture or stored separately */
857 switch (image->type)
858 {
859 case ImageTypeBitmap: *format = ImageFormatBMP; break;
860 case ImageTypeMetafile: *format = ImageFormatEMF; break;
861 default:
862 WARN("unknown type %u\n", image->type);
863 *format = ImageFormatUndefined;
864 }
865 return Ok;
866 }
867
868 GpStatus WINGDIPAPI GdipGetImageType(GpImage *image, ImageType *type)
869 {
870 TRACE("%p %p\n", image, type);
871
872 if(!image || !type)
873 return InvalidParameter;
874
875 *type = image->type;
876
877 return Ok;
878 }
879
880 GpStatus WINGDIPAPI GdipGetImageVerticalResolution(GpImage *image, REAL *res)
881 {
882 static int calls;
883
884 if(!image || !res)
885 return InvalidParameter;
886
887 if(!(calls++))
888 FIXME("not implemented\n");
889
890 return NotImplemented;
891 }
892
893 GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
894 {
895 TRACE("%p %p\n", image, width);
896
897 if(!image || !width)
898 return InvalidParameter;
899
900 if(image->type == ImageTypeMetafile){
901 HDC hdc = GetDC(0);
902
903 *width = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
904 ((GpMetafile*)image)->bounds.Width);
905
906 ReleaseDC(0, hdc);
907 }
908 else if(image->type == ImageTypeBitmap)
909 *width = ((GpBitmap*)image)->width;
910 else
911 *width = ipicture_pixel_width(image->picture);
912
913 TRACE("returning %d\n", *width);
914
915 return Ok;
916 }
917
918 GpStatus WINGDIPAPI GdipGetMetafileHeaderFromMetafile(GpMetafile * metafile,
919 MetafileHeader * header)
920 {
921 static int calls;
922
923 if(!metafile || !header)
924 return InvalidParameter;
925
926 if(!(calls++))
927 FIXME("not implemented\n");
928
929 return Ok;
930 }
931
932 GpStatus WINGDIPAPI GdipGetAllPropertyItems(GpImage *image, UINT size,
933 UINT num, PropertyItem* items)
934 {
935 static int calls;
936
937 if(!(calls++))
938 FIXME("not implemented\n");
939
940 return InvalidParameter;
941 }
942
943 GpStatus WINGDIPAPI GdipGetPropertyCount(GpImage *image, UINT* num)
944 {
945 static int calls;
946
947 if(!(calls++))
948 FIXME("not implemented\n");
949
950 return InvalidParameter;
951 }
952
953 GpStatus WINGDIPAPI GdipGetPropertyIdList(GpImage *image, UINT num, PROPID* list)
954 {
955 static int calls;
956
957 if(!(calls++))
958 FIXME("not implemented\n");
959
960 return InvalidParameter;
961 }
962
963 GpStatus WINGDIPAPI GdipGetPropertyItem(GpImage *image, PROPID id, UINT size,
964 PropertyItem* buffer)
965 {
966 static int calls;
967
968 if(!(calls++))
969 FIXME("not implemented\n");
970
971 return InvalidParameter;
972 }
973
974 GpStatus WINGDIPAPI GdipGetPropertyItemSize(GpImage *image, PROPID pid,
975 UINT* size)
976 {
977 static int calls;
978
979 TRACE("%p %x %p\n", image, pid, size);
980
981 if(!size || !image)
982 return InvalidParameter;
983
984 if(!(calls++))
985 FIXME("not implemented\n");
986
987 return NotImplemented;
988 }
989
990 GpStatus WINGDIPAPI GdipGetPropertySize(GpImage *image, UINT* size, UINT* num)
991 {
992 static int calls;
993
994 if(!(calls++))
995 FIXME("not implemented\n");
996
997 return InvalidParameter;
998 }
999
1000 GpStatus WINGDIPAPI GdipImageGetFrameCount(GpImage *image,
1001 GDIPCONST GUID* dimensionID, UINT* count)
1002 {
1003 static int calls;
1004
1005 if(!image || !dimensionID || !count)
1006 return InvalidParameter;
1007
1008 if(!(calls++))
1009 FIXME("not implemented\n");
1010
1011 return NotImplemented;
1012 }
1013
1014 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsCount(GpImage *image,
1015 UINT* count)
1016 {
1017 if(!image || !count)
1018 return InvalidParameter;
1019
1020 *count = 1;
1021
1022 FIXME("stub\n");
1023
1024 return Ok;
1025 }
1026
1027 GpStatus WINGDIPAPI GdipImageGetFrameDimensionsList(GpImage* image,
1028 GUID* dimensionIDs, UINT count)
1029 {
1030 static int calls;
1031
1032 if(!image || !dimensionIDs)
1033 return InvalidParameter;
1034
1035 if(!(calls++))
1036 FIXME("not implemented\n");
1037
1038 return Ok;
1039 }
1040
1041 GpStatus WINGDIPAPI GdipImageSelectActiveFrame(GpImage *image,
1042 GDIPCONST GUID* dimensionID, UINT frameidx)
1043 {
1044 static int calls;
1045
1046 if(!image || !dimensionID)
1047 return InvalidParameter;
1048
1049 if(!(calls++))
1050 FIXME("not implemented\n");
1051
1052 return Ok;
1053 }
1054
1055 GpStatus WINGDIPAPI GdipLoadImageFromFile(GDIPCONST WCHAR* filename,
1056 GpImage **image)
1057 {
1058 GpStatus stat;
1059 IStream *stream;
1060
1061 TRACE("(%s) %p\n", debugstr_w(filename), image);
1062
1063 if (!filename || !image)
1064 return InvalidParameter;
1065
1066 stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
1067
1068 if (stat != Ok)
1069 return stat;
1070
1071 stat = GdipLoadImageFromStream(stream, image);
1072
1073 IStream_Release(stream);
1074
1075 return stat;
1076 }
1077
1078 /* FIXME: no icm handling */
1079 GpStatus WINGDIPAPI GdipLoadImageFromFileICM(GDIPCONST WCHAR* filename,GpImage **image)
1080 {
1081 TRACE("(%s) %p\n", debugstr_w(filename), image);
1082
1083 return GdipLoadImageFromFile(filename, image);
1084 }
1085
1086 GpStatus WINGDIPAPI GdipLoadImageFromStream(IStream* stream, GpImage **image)
1087 {
1088 IPicture *pic;
1089 short type;
1090
1091 TRACE("%p %p\n", stream, image);
1092
1093 if(!stream || !image)
1094 return InvalidParameter;
1095
1096 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
1097 (LPVOID*) &pic) != S_OK){
1098 TRACE("Could not load picture\n");
1099 return GenericError;
1100 }
1101
1102 IPicture_get_Type(pic, &type);
1103
1104 if(type == PICTYPE_BITMAP){
1105 BITMAPINFO *pbmi;
1106 BITMAPCOREHEADER* bmch;
1107 HBITMAP hbm;
1108 HDC hdc;
1109
1110 pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
1111 if (!pbmi)
1112 return OutOfMemory;
1113 *image = GdipAlloc(sizeof(GpBitmap));
1114 if(!*image){
1115 GdipFree(pbmi);
1116 return OutOfMemory;
1117 }
1118 (*image)->type = ImageTypeBitmap;
1119
1120 (*((GpBitmap**) image))->width = ipicture_pixel_width(pic);
1121 (*((GpBitmap**) image))->height = ipicture_pixel_height(pic);
1122
1123 /* get the pixel format */
1124 IPicture_get_Handle(pic, (OLE_HANDLE*)&hbm);
1125 IPicture_get_CurDC(pic, &hdc);
1126
1127 bmch = (BITMAPCOREHEADER*) (&pbmi->bmiHeader);
1128 bmch->bcSize = sizeof(BITMAPCOREHEADER);
1129
1130 if(!hdc){
1131 HBITMAP old;
1132 hdc = CreateCompatibleDC(0);
1133 old = SelectObject(hdc, hbm);
1134 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
1135 SelectObject(hdc, old);
1136 DeleteDC(hdc);
1137 }
1138 else
1139 GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
1140
1141 switch(bmch->bcBitCount)
1142 {
1143 case 1:
1144 (*((GpBitmap**) image))->format = PixelFormat1bppIndexed;
1145 break;
1146 case 4:
1147 (*((GpBitmap**) image))->format = PixelFormat4bppIndexed;
1148 break;
1149 case 8:
1150 (*((GpBitmap**) image))->format = PixelFormat8bppIndexed;
1151 break;
1152 case 16:
1153 (*((GpBitmap**) image))->format = PixelFormat16bppRGB565;
1154 break;
1155 case 24:
1156 (*((GpBitmap**) image))->format = PixelFormat24bppRGB;
1157 break;
1158 case 32:
1159 (*((GpBitmap**) image))->format = PixelFormat32bppRGB;
1160 break;
1161 case 48:
1162 (*((GpBitmap**) image))->format = PixelFormat48bppRGB;
1163 break;
1164 default:
1165 FIXME("Bit depth %d is not fully supported yet\n", bmch->bcBitCount);
1166 (*((GpBitmap**) image))->format = (bmch->bcBitCount << 8) | PixelFormatGDI;
1167 break;
1168 }
1169
1170 GdipFree(pbmi);
1171 }
1172 else if(type == PICTYPE_METAFILE || type == PICTYPE_ENHMETAFILE){
1173 /* FIXME: missing initialization code */
1174 *image = GdipAlloc(sizeof(GpMetafile));
1175 if(!*image) return OutOfMemory;
1176 (*image)->type = ImageTypeMetafile;
1177 }
1178 else{
1179 *image = GdipAlloc(sizeof(GpImage));
1180 if(!*image) return OutOfMemory;
1181 (*image)->type = ImageTypeUnknown;
1182 }
1183
1184 (*image)->picture = pic;
1185 (*image)->flags = ImageFlagsNone;
1186
1187 return Ok;
1188 }
1189
1190 /* FIXME: no ICM */
1191 GpStatus WINGDIPAPI GdipLoadImageFromStreamICM(IStream* stream, GpImage **image)
1192 {
1193 TRACE("%p %p\n", stream, image);
1194
1195 return GdipLoadImageFromStream(stream, image);
1196 }
1197
1198 GpStatus WINGDIPAPI GdipRemovePropertyItem(GpImage *image, PROPID propId)
1199 {
1200 static int calls;
1201
1202 if(!image)
1203 return InvalidParameter;
1204
1205 if(!(calls++))
1206 FIXME("not implemented\n");
1207
1208 return NotImplemented;
1209 }
1210
1211 GpStatus WINGDIPAPI GdipSetPropertyItem(GpImage *image, GDIPCONST PropertyItem* item)
1212 {
1213 static int calls;
1214
1215 if(!(calls++))
1216 FIXME("not implemented\n");
1217
1218 return NotImplemented;
1219 }
1220
1221 GpStatus WINGDIPAPI GdipSaveImageToFile(GpImage *image, GDIPCONST WCHAR* filename,
1222 GDIPCONST CLSID *clsidEncoder,
1223 GDIPCONST EncoderParameters *encoderParams)
1224 {
1225 GpStatus stat;
1226 IStream *stream;
1227
1228 TRACE("%p (%s) %p %p\n", image, debugstr_w(filename), clsidEncoder, encoderParams);
1229
1230 if (!image || !filename|| !clsidEncoder)
1231 return InvalidParameter;
1232
1233 if (!(image->picture))
1234 return InvalidParameter;
1235
1236 stat = GdipCreateStreamOnFile(filename, GENERIC_WRITE, &stream);
1237 if (stat != Ok)
1238 return GenericError;
1239
1240 stat = GdipSaveImageToStream(image, stream, clsidEncoder, encoderParams);
1241
1242 IStream_Release(stream);
1243 return stat;
1244 }
1245
1246 /*************************************************************************
1247 * Encoding functions -
1248 * These functions encode an image in different image file formats.
1249 */
1250 #define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
1251 #define BITMAP_FORMAT_JPEG 0xd8ff
1252 #define BITMAP_FORMAT_GIF 0x4947
1253 #define BITMAP_FORMAT_PNG 0x5089
1254 #define BITMAP_FORMAT_APM 0xcdd7
1255
1256 static GpStatus encode_image_BMP(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
1257 void **output, unsigned int *output_size)
1258 {
1259 int num_palette_entries;
1260 BITMAPFILEHEADER *bmp_file_hdr;
1261 BITMAPINFO *bmp_info_hdr;
1262
1263 if (bitmap_info->bmiHeader.biClrUsed) {
1264 num_palette_entries = bitmap_info->bmiHeader.biClrUsed;
1265 if (num_palette_entries > 256) num_palette_entries = 256;
1266 } else {
1267 if (bitmap_info->bmiHeader.biBitCount <= 8)
1268 num_palette_entries = 1 << bitmap_info->bmiHeader.biBitCount;
1269 else
1270 num_palette_entries = 0;
1271 }
1272
1273 *output_size =
1274 sizeof(BITMAPFILEHEADER) +
1275 sizeof(BITMAPINFOHEADER) +
1276 num_palette_entries * sizeof(RGBQUAD) +
1277 bitmap_info->bmiHeader.biSizeImage;
1278
1279 *output = GdipAlloc(*output_size);
1280
1281 bmp_file_hdr = *output;
1282 bmp_file_hdr->bfType = BITMAP_FORMAT_BMP;
1283 bmp_file_hdr->bfSize = *output_size;
1284 bmp_file_hdr->bfOffBits =
1285 sizeof(BITMAPFILEHEADER) +
1286 sizeof(BITMAPINFOHEADER) +
1287 num_palette_entries * sizeof (RGBQUAD);
1288
1289 bmp_info_hdr = (BITMAPINFO*) ((unsigned char*)(*output) + sizeof(BITMAPFILEHEADER));
1290 memcpy(bmp_info_hdr, bitmap_info, sizeof(BITMAPINFOHEADER) + num_palette_entries * sizeof(RGBQUAD));
1291 memcpy((unsigned char *)(*output) +
1292 sizeof(BITMAPFILEHEADER) +
1293 sizeof(BITMAPINFOHEADER) +
1294 num_palette_entries * sizeof(RGBQUAD),
1295 bitmap_bits, bitmap_info->bmiHeader.biSizeImage);
1296
1297 return Ok;
1298 }
1299
1300 typedef GpStatus encode_image_func(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
1301 void **output, unsigned int *output_size);
1302
1303 typedef enum {
1304 BMP,
1305 NUM_ENCODERS_SUPPORTED
1306 } ImageFormat;
1307
1308 static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED];
1309 static encode_image_func *const encode_image_funcs[NUM_ENCODERS_SUPPORTED] = {
1310 encode_image_BMP,
1311 };
1312
1313 /*****************************************************************************
1314 * GdipSaveImageToStream [GDIPLUS.@]
1315 */
1316 GpStatus WINGDIPAPI GdipSaveImageToStream(GpImage *image, IStream* stream,
1317 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
1318 {
1319 GpStatus stat;
1320 HRESULT hr;
1321 short type;
1322 HBITMAP hbmp;
1323 HBITMAP old_hbmp;
1324 HDC hdc;
1325 int bm_is_selected;
1326 BITMAPINFO bmp_info;
1327 LPVOID bmp_bits;
1328 encode_image_func* encode_image;
1329 LPVOID output;
1330 unsigned int output_size;
1331 unsigned int dummy;
1332 int i;
1333
1334 old_hbmp = 0;
1335 output = NULL;
1336 output_size = 0;
1337
1338 TRACE("%p %p %p %p\n", image, stream, clsid, params);
1339
1340 if(!image || !stream)
1341 return InvalidParameter;
1342
1343 if (!image->picture)
1344 return GenericError;
1345
1346 hr = IPicture_get_Type(image->picture, &type);
1347 if (FAILED(hr) || type != PICTYPE_BITMAP)
1348 return GenericError;
1349
1350 /* select correct encoder */
1351 encode_image = NULL;
1352 for (i = 0; i < NUM_ENCODERS_SUPPORTED; i++) {
1353 if (IsEqualCLSID(clsid, &codecs[i].Clsid))
1354 encode_image = encode_image_funcs[i];
1355 }
1356 if (encode_image == NULL)
1357 return UnknownImageFormat;
1358
1359 /* extract underlying hbitmap representation from the IPicture */
1360 hr = IPicture_get_Handle(image->picture, (OLE_HANDLE*)&hbmp);
1361 if (FAILED(hr) || !hbmp)
1362 return GenericError;
1363 hr = IPicture_get_CurDC(image->picture, &hdc);
1364 if (FAILED(hr))
1365 return GenericError;
1366 bm_is_selected = (hdc != 0);
1367 if (!bm_is_selected) {
1368 hdc = CreateCompatibleDC(0);
1369 old_hbmp = SelectObject(hdc, hbmp);
1370 }
1371
1372 /* get bits from HBITMAP */
1373 bmp_info.bmiHeader.biSize = sizeof(bmp_info.bmiHeader);
1374 bmp_info.bmiHeader.biBitCount = 0;
1375 GetDIBits(hdc, hbmp, 0, 0, NULL, &bmp_info, DIB_RGB_COLORS);
1376
1377 bmp_bits = GdipAlloc(bmp_info.bmiHeader.biSizeImage);
1378
1379 if (bmp_bits)
1380 GetDIBits(hdc, hbmp, 0, abs(bmp_info.bmiHeader.biHeight), bmp_bits, &bmp_info, DIB_RGB_COLORS);
1381
1382 if (!bm_is_selected) {
1383 SelectObject(hdc, old_hbmp);
1384 DeleteDC(hdc);
1385 }
1386
1387 if (!bmp_bits)
1388 return OutOfMemory;
1389
1390 stat = encode_image(bmp_bits, &bmp_info, &output, &output_size);
1391 if (stat == Ok)
1392 IStream_Write(stream, output, output_size, &dummy);
1393
1394 GdipFree(output);
1395 GdipFree(bmp_bits);
1396
1397 return stat;
1398 }
1399
1400 /*****************************************************************************
1401 * GdipSetImagePalette [GDIPLUS.@]
1402 */
1403 GpStatus WINGDIPAPI GdipSetImagePalette(GpImage *image,
1404 GDIPCONST ColorPalette *palette)
1405 {
1406 static int calls;
1407
1408 if(!image || !palette)
1409 return InvalidParameter;
1410
1411 if(!(calls++))
1412 FIXME("not implemented\n");
1413
1414 return NotImplemented;
1415 }
1416
1417 /*************************************************************************
1418 * Encoders -
1419 * Structures that represent which formats we support for encoding.
1420 */
1421
1422 /* ImageCodecInfo creation routines taken from libgdiplus */
1423 static const WCHAR bmp_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
1424 static const WCHAR bmp_extension[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
1425 static const WCHAR bmp_mimetype[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
1426 static const WCHAR bmp_format[] = {'B', 'M', 'P', 0}; /* BMP */
1427 static const BYTE bmp_sig_pattern[] = { 0x42, 0x4D };
1428 static const BYTE bmp_sig_mask[] = { 0xFF, 0xFF };
1429
1430 static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED] =
1431 {
1432 { /* BMP */
1433 /* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
1434 /* FormatID */ { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
1435 /* CodecName */ bmp_codecname,
1436 /* DllName */ NULL,
1437 /* FormatDescription */ bmp_format,
1438 /* FilenameExtension */ bmp_extension,
1439 /* MimeType */ bmp_mimetype,
1440 /* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
1441 /* Version */ 1,
1442 /* SigCount */ 1,
1443 /* SigSize */ 2,
1444 /* SigPattern */ bmp_sig_pattern,
1445 /* SigMask */ bmp_sig_mask,
1446 },
1447 };
1448
1449 /*****************************************************************************
1450 * GdipGetImageDecodersSize [GDIPLUS.@]
1451 */
1452 GpStatus WINGDIPAPI GdipGetImageDecodersSize(UINT *numDecoders, UINT *size)
1453 {
1454 FIXME("%p %p stub!\n", numDecoders, size);
1455
1456 if (!numDecoders || !size)
1457 return InvalidParameter;
1458
1459 *numDecoders = 0;
1460 *size = 0;
1461
1462 return Ok;
1463 }
1464
1465 /*****************************************************************************
1466 * GdipGetImageDecoders [GDIPLUS.@]
1467 */
1468 GpStatus WINGDIPAPI GdipGetImageDecoders(UINT numDecoders, UINT size, ImageCodecInfo *decoders)
1469 {
1470 FIXME("%u %u %p stub!\n", numDecoders, size, decoders);
1471
1472 if (!decoders)
1473 return GenericError;
1474
1475 return NotImplemented;
1476 }
1477
1478 /*****************************************************************************
1479 * GdipGetImageEncodersSize [GDIPLUS.@]
1480 */
1481 GpStatus WINGDIPAPI GdipGetImageEncodersSize(UINT *numEncoders, UINT *size)
1482 {
1483 TRACE("%p %p\n", numEncoders, size);
1484
1485 if (!numEncoders || !size)
1486 return InvalidParameter;
1487
1488 *numEncoders = NUM_ENCODERS_SUPPORTED;
1489 *size = sizeof (codecs);
1490
1491 return Ok;
1492 }
1493
1494 /*****************************************************************************
1495 * GdipGetImageEncoders [GDIPLUS.@]
1496 */
1497 GpStatus WINGDIPAPI GdipGetImageEncoders(UINT numEncoders, UINT size, ImageCodecInfo *encoders)
1498 {
1499 TRACE("%u %u %p\n", numEncoders, size, encoders);
1500
1501 if (!encoders ||
1502 (numEncoders != NUM_ENCODERS_SUPPORTED) ||
1503 (size != sizeof (codecs)))
1504 return GenericError;
1505
1506 memcpy(encoders, codecs, sizeof (codecs));
1507
1508 return Ok;
1509 }
1510
1511 /*****************************************************************************
1512 * GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
1513 */
1514 GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBitmap** bitmap)
1515 {
1516 BITMAP bm;
1517 GpStatus retval;
1518 PixelFormat format;
1519 BYTE* bits;
1520
1521 TRACE("%p %p %p\n", hbm, hpal, bitmap);
1522
1523 if(!hbm || !bitmap)
1524 return InvalidParameter;
1525
1526 /* TODO: Support for device-dependent bitmaps */
1527 if(hpal){
1528 FIXME("no support for device-dependent bitmaps\n");
1529 return NotImplemented;
1530 }
1531
1532 if (GetObjectA(hbm, sizeof(bm), &bm) != sizeof(bm))
1533 return InvalidParameter;
1534
1535 /* TODO: Figure out the correct format for 16, 32, 64 bpp */
1536 switch(bm.bmBitsPixel) {
1537 case 1:
1538 format = PixelFormat1bppIndexed;
1539 break;
1540 case 4:
1541 format = PixelFormat4bppIndexed;
1542 break;
1543 case 8:
1544 format = PixelFormat8bppIndexed;
1545 break;
1546 case 24:
1547 format = PixelFormat24bppRGB;
1548 break;
1549 case 32:
1550 format = PixelFormat32bppRGB;
1551 break;
1552 case 48:
1553 format = PixelFormat48bppRGB;
1554 break;
1555 default:
1556 FIXME("don't know how to handle %d bpp\n", bm.bmBitsPixel);
1557 return InvalidParameter;
1558 }
1559
1560 if (bm.bmBits)
1561 bits = (BYTE*)bm.bmBits + (bm.bmHeight - 1) * bm.bmWidthBytes;
1562 else
1563 {
1564 FIXME("can only get image data from DIB sections\n");
1565 bits = NULL;
1566 }
1567
1568 retval = GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, -bm.bmWidthBytes,
1569 format, bits, bitmap);
1570
1571 return retval;
1572 }
1573
1574 /*****************************************************************************
1575 * GdipSetEffectParameters [GDIPLUS.@]
1576 */
1577 GpStatus WINGDIPAPI GdipSetEffectParameters(CGpEffect *effect,
1578 const VOID *params, const UINT size)
1579 {
1580 static int calls;
1581
1582 if(!(calls++))
1583 FIXME("not implemented\n");
1584
1585 return NotImplemented;
1586 }
1587
1588 /*****************************************************************************
1589 * GdipGetImageFlags [GDIPLUS.@]
1590 */
1591 GpStatus WINGDIPAPI GdipGetImageFlags(GpImage *image, UINT *flags)
1592 {
1593 TRACE("%p %p\n", image, flags);
1594
1595 if(!image || !flags)
1596 return InvalidParameter;
1597
1598 *flags = image->flags;
1599
1600 return Ok;
1601 }
1602
1603 GpStatus WINGDIPAPI GdipTestControl(GpTestControlEnum control, void *param)
1604 {
1605 TRACE("(%d, %p)\n", control, param);
1606
1607 switch(control){
1608 case TestControlForceBilinear:
1609 if(param)
1610 FIXME("TestControlForceBilinear not handled\n");
1611 break;
1612 case TestControlNoICM:
1613 if(param)
1614 FIXME("TestControlNoICM not handled\n");
1615 break;
1616 case TestControlGetBuildNumber:
1617 *((DWORD*)param) = 3102;
1618 break;
1619 }
1620
1621 return Ok;
1622 }
1623
1624 GpStatus WINGDIPAPI GdipRecordMetafileFileName(GDIPCONST WCHAR* fileName,
1625 HDC hdc, EmfType type, GDIPCONST GpRectF *pFrameRect,
1626 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc,
1627 GpMetafile **metafile)
1628 {
1629 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
1630 frameUnit, debugstr_w(desc), metafile);
1631
1632 return NotImplemented;
1633 }
1634
1635 GpStatus WINGDIPAPI GdipRecordMetafileFileNameI(GDIPCONST WCHAR* fileName, HDC hdc, EmfType type,
1636 GDIPCONST GpRect *pFrameRect, MetafileFrameUnit frameUnit,
1637 GDIPCONST WCHAR *desc, GpMetafile **metafile)
1638 {
1639 FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
1640 frameUnit, debugstr_w(desc), metafile);
1641
1642 return NotImplemented;
1643 }
1644
1645 GpStatus WINGDIPAPI GdipImageForceValidation(GpImage *image)
1646 {
1647 FIXME("%p\n", image);
1648
1649 return Ok;
1650 }