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