2007-07-25 00:19:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 Google (Evan Stade)
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2007-07-25 00:19:21 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2007-07-25 00:19:02 +00:00
|
|
|
#include "windef.h"
|
2007-07-25 00:19:21 +00:00
|
|
|
#include "winbase.h"
|
2007-08-01 02:15:48 +00:00
|
|
|
#include "winuser.h"
|
2007-07-25 00:19:02 +00:00
|
|
|
#include "wingdi.h"
|
2007-08-01 02:14:57 +00:00
|
|
|
|
|
|
|
#define COBJMACROS
|
2007-07-25 00:19:21 +00:00
|
|
|
#include "objbase.h"
|
2007-08-01 02:15:48 +00:00
|
|
|
#include "olectl.h"
|
2007-08-01 02:15:52 +00:00
|
|
|
#include "ole2.h"
|
2007-07-25 00:19:21 +00:00
|
|
|
|
2007-07-25 00:19:02 +00:00
|
|
|
#include "gdiplus.h"
|
|
|
|
#include "gdiplus_private.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
|
|
|
|
|
2007-08-01 02:15:33 +00:00
|
|
|
typedef void ImageItemData;
|
|
|
|
|
2007-08-01 02:16:20 +00:00
|
|
|
static INT ipicture_pixel_height(IPicture *pic)
|
|
|
|
{
|
|
|
|
HDC hdcref;
|
|
|
|
OLE_YSIZE_HIMETRIC y;
|
|
|
|
|
|
|
|
IPicture_get_Height(pic, &y);
|
|
|
|
|
|
|
|
hdcref = GetDC(0);
|
|
|
|
|
|
|
|
y = (UINT)(((REAL)y) * ((REAL)GetDeviceCaps(hdcref, LOGPIXELSY)) /
|
|
|
|
((REAL)INCH_HIMETRIC));
|
|
|
|
ReleaseDC(0, hdcref);
|
|
|
|
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INT ipicture_pixel_width(IPicture *pic)
|
|
|
|
{
|
|
|
|
HDC hdcref;
|
|
|
|
OLE_XSIZE_HIMETRIC x;
|
|
|
|
|
|
|
|
IPicture_get_Width(pic, &x);
|
|
|
|
|
|
|
|
hdcref = GetDC(0);
|
|
|
|
|
|
|
|
x = (UINT)(((REAL)x) * ((REAL)GetDeviceCaps(hdcref, LOGPIXELSX)) /
|
|
|
|
((REAL)INCH_HIMETRIC));
|
|
|
|
|
|
|
|
ReleaseDC(0, hdcref);
|
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2007-08-01 02:16:13 +00:00
|
|
|
GpStatus WINGDIPAPI GdipBitmapGetPixel(GpBitmap* bitmap, INT x, INT y,
|
|
|
|
ARGB *color)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
TRACE("%p %d %d %p\n", bitmap, x, y, color);
|
|
|
|
|
|
|
|
if(!bitmap || !color)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
*color = 0xdeadbeef;
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2007-08-01 02:15:52 +00:00
|
|
|
GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
|
|
|
|
PixelFormat format, BYTE* scan0, GpBitmap** bitmap)
|
|
|
|
{
|
|
|
|
BITMAPFILEHEADER *bmfh;
|
|
|
|
BITMAPINFOHEADER *bmih;
|
|
|
|
BYTE *buff;
|
|
|
|
INT datalen = stride * height, size;
|
|
|
|
IStream *stream;
|
|
|
|
|
|
|
|
TRACE("%d %d %d %d %p %p\n", width, height, stride, format, scan0, bitmap);
|
|
|
|
|
|
|
|
if(!scan0 || !bitmap)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
*bitmap = GdipAlloc(sizeof(GpBitmap));
|
|
|
|
if(!*bitmap) return OutOfMemory;
|
|
|
|
|
|
|
|
size = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + datalen;
|
|
|
|
buff = GdipAlloc(size);
|
|
|
|
if(!buff){
|
|
|
|
GdipFree(*bitmap);
|
|
|
|
return OutOfMemory;
|
|
|
|
}
|
|
|
|
|
|
|
|
bmfh = (BITMAPFILEHEADER*) buff;
|
|
|
|
bmih = (BITMAPINFOHEADER*) (bmfh + 1);
|
|
|
|
|
|
|
|
bmfh->bfType = (((WORD)'M') << 8) + (WORD)'B';
|
|
|
|
bmfh->bfSize = size;
|
|
|
|
bmfh->bfOffBits = size - datalen;
|
|
|
|
|
|
|
|
bmih->biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
bmih->biWidth = width;
|
|
|
|
bmih->biHeight = height;
|
|
|
|
/* FIXME: use the rest of the data from format */
|
|
|
|
bmih->biBitCount = format >> 8;
|
|
|
|
bmih->biCompression = BI_RGB;
|
|
|
|
|
|
|
|
memcpy(bmih + 1, scan0, datalen);
|
|
|
|
|
|
|
|
if(CreateStreamOnHGlobal(buff, TRUE, &stream) != S_OK){
|
|
|
|
ERR("could not make stream\n");
|
|
|
|
GdipFree(*bitmap);
|
|
|
|
GdipFree(buff);
|
|
|
|
return GenericError;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
|
|
|
|
(LPVOID*) &((*bitmap)->image.picture)) != S_OK){
|
|
|
|
TRACE("Could not load picture\n");
|
|
|
|
IStream_Release(stream);
|
|
|
|
GdipFree(*bitmap);
|
|
|
|
GdipFree(buff);
|
|
|
|
return GenericError;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*bitmap)->image.type = ImageTypeBitmap;
|
2007-08-01 02:16:20 +00:00
|
|
|
(*bitmap)->width = width;
|
|
|
|
(*bitmap)->height = height;
|
2007-08-01 02:15:52 +00:00
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-08-01 02:16:04 +00:00
|
|
|
GpStatus WINGDIPAPI GdipCreateBitmapFromStreamICM(IStream* stream,
|
|
|
|
GpBitmap **bitmap)
|
|
|
|
{
|
|
|
|
GpStatus stat;
|
|
|
|
|
|
|
|
stat = GdipLoadImageFromStreamICM(stream, (GpImage**) bitmap);
|
|
|
|
|
2007-08-01 02:16:20 +00:00
|
|
|
if(stat != Ok)
|
|
|
|
return stat;
|
|
|
|
|
|
|
|
(*bitmap)->image.type = ImageTypeBitmap;
|
|
|
|
(*bitmap)->width = ipicture_pixel_width((*bitmap)->image.picture);
|
|
|
|
(*bitmap)->height = ipicture_pixel_height((*bitmap)->image.picture);
|
2007-08-01 02:16:04 +00:00
|
|
|
|
2007-08-01 02:16:20 +00:00
|
|
|
return Ok;
|
2007-08-01 02:16:04 +00:00
|
|
|
}
|
|
|
|
|
2007-07-25 00:19:18 +00:00
|
|
|
GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
|
|
|
|
{
|
2007-08-01 02:14:57 +00:00
|
|
|
if(!image)
|
|
|
|
return InvalidParameter;
|
2007-07-25 00:19:18 +00:00
|
|
|
|
2007-08-01 02:14:57 +00:00
|
|
|
IPicture_Release(image->picture);
|
|
|
|
GdipFree(image);
|
2007-07-25 00:19:18 +00:00
|
|
|
|
2007-08-01 02:14:57 +00:00
|
|
|
return Ok;
|
2007-07-25 00:19:18 +00:00
|
|
|
}
|
|
|
|
|
2007-08-01 02:15:33 +00:00
|
|
|
GpStatus WINGDIPAPI GdipFindFirstImageItem(GpImage *image, ImageItemData* item)
|
|
|
|
{
|
|
|
|
if(!image || !item)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2007-07-31 02:09:37 +00:00
|
|
|
GpStatus WINGDIPAPI GdipGetImageBounds(GpImage *image, GpRectF *srcRect,
|
|
|
|
GpUnit *srcUnit)
|
|
|
|
{
|
|
|
|
if(!image || !srcRect || !srcUnit)
|
|
|
|
return InvalidParameter;
|
2007-07-31 02:09:57 +00:00
|
|
|
if(image->type == ImageTypeMetafile){
|
|
|
|
memcpy(srcRect, &((GpMetafile*)image)->bounds, sizeof(GpRectF));
|
|
|
|
*srcUnit = ((GpMetafile*)image)->unit;
|
|
|
|
}
|
2007-08-01 02:16:20 +00:00
|
|
|
else if(image->type == ImageTypeBitmap){
|
|
|
|
srcRect->X = srcRect->Y = 0.0;
|
|
|
|
srcRect->Width = (REAL) ((GpBitmap*)image)->width;
|
|
|
|
srcRect->Height = (REAL) ((GpBitmap*)image)->height;
|
|
|
|
*srcUnit = UnitPixel;
|
|
|
|
}
|
2007-07-31 02:09:57 +00:00
|
|
|
else{
|
2007-08-01 02:16:20 +00:00
|
|
|
srcRect->X = srcRect->Y = 0.0;
|
|
|
|
srcRect->Width = ipicture_pixel_width(image->picture);
|
|
|
|
srcRect->Height = ipicture_pixel_height(image->picture);
|
|
|
|
*srcUnit = UnitPixel;
|
2007-07-31 02:09:57 +00:00
|
|
|
}
|
2007-07-31 02:09:37 +00:00
|
|
|
|
2007-08-01 02:16:20 +00:00
|
|
|
TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect->X, srcRect->Y,
|
|
|
|
srcRect->Width, srcRect->Height, *srcUnit);
|
|
|
|
|
2007-07-31 02:09:57 +00:00
|
|
|
return Ok;
|
2007-07-31 02:09:37 +00:00
|
|
|
}
|
|
|
|
|
2007-07-25 00:19:02 +00:00
|
|
|
GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
|
|
|
|
{
|
|
|
|
if(!image || !height)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-08-01 02:16:20 +00:00
|
|
|
if(image->type == ImageTypeMetafile){
|
|
|
|
FIXME("not implemented for metafiles\n");
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
else if(image->type == ImageTypeBitmap)
|
|
|
|
*height = ((GpBitmap*)image)->height;
|
|
|
|
else
|
|
|
|
*height = ipicture_pixel_height(image->picture);
|
2007-07-25 00:19:02 +00:00
|
|
|
|
2007-08-01 02:16:20 +00:00
|
|
|
TRACE("returning %d\n", *height);
|
|
|
|
|
|
|
|
return Ok;
|
2007-07-25 00:19:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipGetImageHorizontalResolution(GpImage *image, REAL *res)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!image || !res)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipGetImageRawFormat(GpImage *image, GUID *format)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!image || !format)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2007-07-25 00:19:12 +00:00
|
|
|
GpStatus WINGDIPAPI GdipGetImageType(GpImage *image, ImageType *type)
|
|
|
|
{
|
|
|
|
if(!image || !type)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-08-01 02:15:08 +00:00
|
|
|
*type = image->type;
|
2007-07-25 00:19:12 +00:00
|
|
|
|
2007-07-31 02:09:49 +00:00
|
|
|
return Ok;
|
2007-07-25 00:19:12 +00:00
|
|
|
}
|
|
|
|
|
2007-07-25 00:19:02 +00:00
|
|
|
GpStatus WINGDIPAPI GdipGetImageVerticalResolution(GpImage *image, REAL *res)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!image || !res)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
|
|
|
|
{
|
|
|
|
if(!image || !width)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-08-01 02:16:20 +00:00
|
|
|
if(image->type == ImageTypeMetafile){
|
|
|
|
FIXME("not implemented for metafiles\n");
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
else if(image->type == ImageTypeBitmap)
|
|
|
|
*width = ((GpBitmap*)image)->width;
|
|
|
|
else
|
|
|
|
*width = ipicture_pixel_width(image->picture);
|
2007-07-25 00:19:02 +00:00
|
|
|
|
2007-08-01 02:16:20 +00:00
|
|
|
TRACE("returning %d\n", *width);
|
|
|
|
|
|
|
|
return Ok;
|
2007-07-25 00:19:02 +00:00
|
|
|
}
|
|
|
|
|
2007-08-01 02:15:29 +00:00
|
|
|
GpStatus WINGDIPAPI GdipGetMetafileHeaderFromMetafile(GpMetafile * metafile,
|
|
|
|
MetafileHeader * header)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!metafile || !header)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2007-08-01 02:15:56 +00:00
|
|
|
GpStatus WINGDIPAPI GdipGetPropertyItemSize(GpImage *image, PROPID pid,
|
|
|
|
UINT* size)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
TRACE("%p %x %p\n", image, pid, size);
|
|
|
|
|
|
|
|
if(!size || !image)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2007-07-25 00:19:02 +00:00
|
|
|
GpStatus WINGDIPAPI GdipImageGetFrameCount(GpImage *image,
|
|
|
|
GDIPCONST GUID* dimensionID, UINT* count)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!image || !dimensionID || !count)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
2007-07-25 00:19:21 +00:00
|
|
|
|
2007-08-01 02:15:48 +00:00
|
|
|
/* FIXME: no ICM */
|
2007-07-25 00:19:21 +00:00
|
|
|
GpStatus WINGDIPAPI GdipLoadImageFromStreamICM(IStream* stream, GpImage **image)
|
|
|
|
{
|
|
|
|
if(!stream || !image)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-08-01 02:15:48 +00:00
|
|
|
*image = GdipAlloc(sizeof(GpImage));
|
|
|
|
if(!*image) return OutOfMemory;
|
2007-07-25 00:19:21 +00:00
|
|
|
|
2007-08-01 02:15:48 +00:00
|
|
|
if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
|
|
|
|
(LPVOID*) &((*image)->picture)) != S_OK){
|
|
|
|
TRACE("Could not load picture\n");
|
|
|
|
GdipFree(*image);
|
|
|
|
return GenericError;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: use IPicture_get_Type to get image type */
|
|
|
|
(*image)->type = ImageTypeUnknown;
|
|
|
|
|
|
|
|
return Ok;
|
2007-07-25 00:19:21 +00:00
|
|
|
}
|
2007-08-01 02:16:00 +00:00
|
|
|
|
2007-08-01 02:16:08 +00:00
|
|
|
GpStatus WINGDIPAPI GdipRemovePropertyItem(GpImage *image, PROPID propId)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!image)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2007-08-01 02:16:00 +00:00
|
|
|
GpStatus WINGDIPAPI GdipSaveImageToStream(GpImage *image, IStream* stream,
|
|
|
|
GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
|
|
|
|
{
|
|
|
|
if(!image || !stream)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
/* FIXME: CLSID, EncoderParameters not used */
|
|
|
|
|
|
|
|
IPicture_SaveAsFile(image->picture, stream, FALSE, NULL);
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|