2 * Copyright (C) 2007 Google (Evan Stade)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "gdiplus_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
37 typedef void ImageItemData;
39 static INT ipicture_pixel_height(IPicture *pic)
44 IPicture_get_Height(pic, &y);
48 y = (UINT)(((REAL)y) * ((REAL)GetDeviceCaps(hdcref, LOGPIXELSY)) /
49 ((REAL)INCH_HIMETRIC));
55 static INT ipicture_pixel_width(IPicture *pic)
60 IPicture_get_Width(pic, &x);
64 x = (UINT)(((REAL)x) * ((REAL)GetDeviceCaps(hdcref, LOGPIXELSX)) /
65 ((REAL)INCH_HIMETRIC));
72 GpStatus WINGDIPAPI GdipBitmapGetPixel(GpBitmap* bitmap, INT x, INT y,
76 TRACE("%p %d %d %p\n", bitmap, x, y, color);
79 return InvalidParameter;
82 FIXME("not implemented\n");
86 return NotImplemented;
89 GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
90 PixelFormat format, BYTE* scan0, GpBitmap** bitmap)
92 BITMAPFILEHEADER *bmfh;
93 BITMAPINFOHEADER *bmih;
95 INT datalen = stride * height, size;
98 TRACE("%d %d %d %d %p %p\n", width, height, stride, format, scan0, bitmap);
100 if(!scan0 || !bitmap)
101 return InvalidParameter;
103 *bitmap = GdipAlloc(sizeof(GpBitmap));
104 if(!*bitmap) return OutOfMemory;
106 size = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + datalen;
107 buff = GdipAlloc(size);
113 bmfh = (BITMAPFILEHEADER*) buff;
114 bmih = (BITMAPINFOHEADER*) (bmfh + 1);
116 bmfh->bfType = (((WORD)'M') << 8) + (WORD)'B';
118 bmfh->bfOffBits = size - datalen;
120 bmih->biSize = sizeof(BITMAPINFOHEADER);
121 bmih->biWidth = width;
122 bmih->biHeight = height;
123 /* FIXME: use the rest of the data from format */
124 bmih->biBitCount = format >> 8;
125 bmih->biCompression = BI_RGB;
127 memcpy(bmih + 1, scan0, datalen);
129 if(CreateStreamOnHGlobal(buff, TRUE, &stream) != S_OK){
130 ERR("could not make stream\n");
136 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
137 (LPVOID*) &((*bitmap)->image.picture)) != S_OK){
138 TRACE("Could not load picture\n");
139 IStream_Release(stream);
145 (*bitmap)->image.type = ImageTypeBitmap;
146 (*bitmap)->width = width;
147 (*bitmap)->height = height;
152 GpStatus WINGDIPAPI GdipCreateBitmapFromStreamICM(IStream* stream,
157 stat = GdipLoadImageFromStreamICM(stream, (GpImage**) bitmap);
162 (*bitmap)->image.type = ImageTypeBitmap;
163 (*bitmap)->width = ipicture_pixel_width((*bitmap)->image.picture);
164 (*bitmap)->height = ipicture_pixel_height((*bitmap)->image.picture);
169 GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
172 return InvalidParameter;
174 IPicture_Release(image->picture);
180 GpStatus WINGDIPAPI GdipFindFirstImageItem(GpImage *image, ImageItemData* item)
183 return InvalidParameter;
185 return NotImplemented;
188 GpStatus WINGDIPAPI GdipGetImageBounds(GpImage *image, GpRectF *srcRect,
191 if(!image || !srcRect || !srcUnit)
192 return InvalidParameter;
193 if(image->type == ImageTypeMetafile){
194 memcpy(srcRect, &((GpMetafile*)image)->bounds, sizeof(GpRectF));
195 *srcUnit = ((GpMetafile*)image)->unit;
197 else if(image->type == ImageTypeBitmap){
198 srcRect->X = srcRect->Y = 0.0;
199 srcRect->Width = (REAL) ((GpBitmap*)image)->width;
200 srcRect->Height = (REAL) ((GpBitmap*)image)->height;
201 *srcUnit = UnitPixel;
204 srcRect->X = srcRect->Y = 0.0;
205 srcRect->Width = ipicture_pixel_width(image->picture);
206 srcRect->Height = ipicture_pixel_height(image->picture);
207 *srcUnit = UnitPixel;
210 TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect->X, srcRect->Y,
211 srcRect->Width, srcRect->Height, *srcUnit);
216 GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
218 if(!image || !height)
219 return InvalidParameter;
221 if(image->type == ImageTypeMetafile){
222 FIXME("not implemented for metafiles\n");
223 return NotImplemented;
225 else if(image->type == ImageTypeBitmap)
226 *height = ((GpBitmap*)image)->height;
228 *height = ipicture_pixel_height(image->picture);
230 TRACE("returning %d\n", *height);
235 GpStatus WINGDIPAPI GdipGetImageHorizontalResolution(GpImage *image, REAL *res)
240 return InvalidParameter;
243 FIXME("not implemented\n");
245 return NotImplemented;
248 GpStatus WINGDIPAPI GdipGetImageRawFormat(GpImage *image, GUID *format)
252 if(!image || !format)
253 return InvalidParameter;
256 FIXME("not implemented\n");
258 return NotImplemented;
261 GpStatus WINGDIPAPI GdipGetImageType(GpImage *image, ImageType *type)
264 return InvalidParameter;
271 GpStatus WINGDIPAPI GdipGetImageVerticalResolution(GpImage *image, REAL *res)
276 return InvalidParameter;
279 FIXME("not implemented\n");
281 return NotImplemented;
284 GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
287 return InvalidParameter;
289 if(image->type == ImageTypeMetafile){
290 FIXME("not implemented for metafiles\n");
291 return NotImplemented;
293 else if(image->type == ImageTypeBitmap)
294 *width = ((GpBitmap*)image)->width;
296 *width = ipicture_pixel_width(image->picture);
298 TRACE("returning %d\n", *width);
303 GpStatus WINGDIPAPI GdipGetMetafileHeaderFromMetafile(GpMetafile * metafile,
304 MetafileHeader * header)
308 if(!metafile || !header)
309 return InvalidParameter;
312 FIXME("not implemented\n");
314 return NotImplemented;
317 GpStatus WINGDIPAPI GdipGetPropertyItemSize(GpImage *image, PROPID pid,
322 TRACE("%p %x %p\n", image, pid, size);
325 return InvalidParameter;
328 FIXME("not implemented\n");
330 return NotImplemented;
333 GpStatus WINGDIPAPI GdipImageGetFrameCount(GpImage *image,
334 GDIPCONST GUID* dimensionID, UINT* count)
338 if(!image || !dimensionID || !count)
339 return InvalidParameter;
342 FIXME("not implemented\n");
344 return NotImplemented;
348 GpStatus WINGDIPAPI GdipLoadImageFromStreamICM(IStream* stream, GpImage **image)
350 if(!stream || !image)
351 return InvalidParameter;
353 *image = GdipAlloc(sizeof(GpImage));
354 if(!*image) return OutOfMemory;
356 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
357 (LPVOID*) &((*image)->picture)) != S_OK){
358 TRACE("Could not load picture\n");
363 /* FIXME: use IPicture_get_Type to get image type */
364 (*image)->type = ImageTypeUnknown;
369 GpStatus WINGDIPAPI GdipRemovePropertyItem(GpImage *image, PROPID propId)
374 return InvalidParameter;
377 FIXME("not implemented\n");
379 return NotImplemented;
382 GpStatus WINGDIPAPI GdipSaveImageToStream(GpImage *image, IStream* stream,
383 GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
385 if(!image || !stream)
386 return InvalidParameter;
388 /* FIXME: CLSID, EncoderParameters not used */
390 IPicture_SaveAsFile(image->picture, stream, FALSE, NULL);