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