2007-07-25 02:19:02 +02: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 02:19:21 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2007-07-25 02:19:02 +02:00
|
|
|
#include "windef.h"
|
2007-07-25 02:19:21 +02:00
|
|
|
#include "winbase.h"
|
2007-08-01 04:15:48 +02:00
|
|
|
#include "winuser.h"
|
2007-07-25 02:19:02 +02:00
|
|
|
#include "wingdi.h"
|
2007-08-01 04:14:57 +02:00
|
|
|
|
|
|
|
#define COBJMACROS
|
2007-07-25 02:19:21 +02:00
|
|
|
#include "objbase.h"
|
2007-08-01 04:15:48 +02:00
|
|
|
#include "olectl.h"
|
2007-08-01 04:15:52 +02:00
|
|
|
#include "ole2.h"
|
2007-07-25 02:19:21 +02:00
|
|
|
|
2008-11-24 10:23:16 +01:00
|
|
|
#include "initguid.h"
|
2007-07-25 02:19:02 +02:00
|
|
|
#include "gdiplus.h"
|
|
|
|
#include "gdiplus_private.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
|
|
|
|
|
2007-08-04 02:30:30 +02:00
|
|
|
#define PIXELFORMATBPP(x) ((x) ? ((x) >> 8) & 255 : 24)
|
|
|
|
|
2007-08-01 04:16:20 +02:00
|
|
|
static INT ipicture_pixel_height(IPicture *pic)
|
|
|
|
{
|
|
|
|
HDC hdcref;
|
|
|
|
OLE_YSIZE_HIMETRIC y;
|
|
|
|
|
|
|
|
IPicture_get_Height(pic, &y);
|
|
|
|
|
|
|
|
hdcref = GetDC(0);
|
|
|
|
|
2008-03-06 09:28:04 +01:00
|
|
|
y = MulDiv(y, GetDeviceCaps(hdcref, LOGPIXELSY), INCH_HIMETRIC);
|
2007-08-01 04:16:20 +02:00
|
|
|
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);
|
|
|
|
|
2008-03-06 09:28:04 +01:00
|
|
|
x = MulDiv(x, GetDeviceCaps(hdcref, LOGPIXELSX), INCH_HIMETRIC);
|
2007-08-01 04:16:20 +02:00
|
|
|
|
|
|
|
ReleaseDC(0, hdcref);
|
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2007-08-01 04:16:13 +02: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-08 03:41:55 +02:00
|
|
|
/* This function returns a pointer to an array of pixels that represents the
|
|
|
|
* bitmap. The *entire* bitmap is locked according to the lock mode specified by
|
|
|
|
* flags. It is correct behavior that a user who calls this function with write
|
|
|
|
* privileges can write to the whole bitmap (not just the area in rect).
|
|
|
|
*
|
|
|
|
* FIXME: only used portion of format is bits per pixel. */
|
|
|
|
GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect,
|
|
|
|
UINT flags, PixelFormat format, BitmapData* lockeddata)
|
|
|
|
{
|
|
|
|
BOOL bm_is_selected;
|
|
|
|
INT stride, bitspp = PIXELFORMATBPP(format);
|
|
|
|
HDC hdc;
|
2008-12-05 07:52:51 +01:00
|
|
|
HBITMAP hbm, old = NULL;
|
2008-09-28 21:21:47 +02:00
|
|
|
BITMAPINFO *pbmi;
|
2007-08-08 03:41:55 +02:00
|
|
|
BYTE *buff = NULL;
|
|
|
|
UINT abs_height;
|
2008-05-21 17:47:50 +02:00
|
|
|
GpRect act_rect; /* actual rect to be used */
|
2007-08-08 03:41:55 +02:00
|
|
|
|
|
|
|
TRACE("%p %p %d %d %p\n", bitmap, rect, flags, format, lockeddata);
|
|
|
|
|
2008-05-21 17:47:50 +02:00
|
|
|
if(!lockeddata || !bitmap)
|
2007-08-08 03:41:55 +02:00
|
|
|
return InvalidParameter;
|
|
|
|
|
2008-05-21 17:47:50 +02:00
|
|
|
if(rect){
|
|
|
|
if(rect->X < 0 || rect->Y < 0 || (rect->X + rect->Width > bitmap->width) ||
|
|
|
|
(rect->Y + rect->Height > bitmap->height) || !flags)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
act_rect = *rect;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
act_rect.X = act_rect.Y = 0;
|
|
|
|
act_rect.Width = bitmap->width;
|
|
|
|
act_rect.Height = bitmap->height;
|
|
|
|
}
|
2007-08-08 03:41:55 +02:00
|
|
|
|
|
|
|
if(flags & ImageLockModeUserInputBuf)
|
|
|
|
return NotImplemented;
|
|
|
|
|
2008-03-07 10:19:05 +01:00
|
|
|
if(bitmap->lockmode)
|
2007-08-08 03:41:55 +02:00
|
|
|
return WrongState;
|
|
|
|
|
2008-12-05 07:52:51 +01:00
|
|
|
IPicture_get_Handle(bitmap->image.picture, (OLE_HANDLE*)&hbm);
|
2007-08-08 03:41:55 +02:00
|
|
|
IPicture_get_CurDC(bitmap->image.picture, &hdc);
|
|
|
|
bm_is_selected = (hdc != 0);
|
|
|
|
|
2008-09-28 21:21:47 +02:00
|
|
|
pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
|
|
|
|
if (!pbmi)
|
|
|
|
return OutOfMemory;
|
|
|
|
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
pbmi->bmiHeader.biBitCount = 0;
|
2007-08-08 03:41:55 +02:00
|
|
|
|
|
|
|
if(!bm_is_selected){
|
2007-08-10 03:25:05 +02:00
|
|
|
hdc = CreateCompatibleDC(0);
|
2008-12-05 07:52:51 +01:00
|
|
|
old = SelectObject(hdc, hbm);
|
2007-08-08 03:41:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* fill out bmi */
|
2008-12-05 07:52:51 +01:00
|
|
|
GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
|
2007-08-08 03:41:55 +02:00
|
|
|
|
2008-09-28 21:21:47 +02:00
|
|
|
abs_height = abs(pbmi->bmiHeader.biHeight);
|
|
|
|
stride = pbmi->bmiHeader.biWidth * bitspp / 8;
|
2007-08-08 03:41:55 +02:00
|
|
|
stride = (stride + 3) & ~3;
|
|
|
|
|
|
|
|
buff = GdipAlloc(stride * abs_height);
|
|
|
|
|
2008-09-28 21:21:47 +02:00
|
|
|
pbmi->bmiHeader.biBitCount = bitspp;
|
2007-08-10 03:25:27 +02:00
|
|
|
|
|
|
|
if(buff)
|
2008-12-05 07:52:51 +01:00
|
|
|
GetDIBits(hdc, hbm, 0, abs_height, buff, pbmi, DIB_RGB_COLORS);
|
2007-08-08 03:41:55 +02:00
|
|
|
|
|
|
|
if(!bm_is_selected){
|
|
|
|
SelectObject(hdc, old);
|
2007-08-10 03:25:05 +02:00
|
|
|
DeleteDC(hdc);
|
2007-08-08 03:41:55 +02:00
|
|
|
}
|
|
|
|
|
2008-09-28 21:21:47 +02:00
|
|
|
if(!buff){
|
|
|
|
GdipFree(pbmi);
|
2007-08-10 03:25:27 +02:00
|
|
|
return OutOfMemory;
|
2008-09-28 21:21:47 +02:00
|
|
|
}
|
2007-08-10 03:25:27 +02:00
|
|
|
|
2008-05-21 17:47:50 +02:00
|
|
|
lockeddata->Width = act_rect.Width;
|
|
|
|
lockeddata->Height = act_rect.Height;
|
2007-08-08 03:41:55 +02:00
|
|
|
lockeddata->PixelFormat = format;
|
|
|
|
lockeddata->Reserved = flags;
|
|
|
|
|
2008-09-28 21:21:47 +02:00
|
|
|
if(pbmi->bmiHeader.biHeight > 0){
|
2007-08-08 03:41:55 +02:00
|
|
|
lockeddata->Stride = -stride;
|
2008-05-21 17:47:50 +02:00
|
|
|
lockeddata->Scan0 = buff + (bitspp / 8) * act_rect.X +
|
|
|
|
stride * (abs_height - 1 - act_rect.Y);
|
2007-08-08 03:41:55 +02:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
lockeddata->Stride = stride;
|
2008-05-21 17:47:50 +02:00
|
|
|
lockeddata->Scan0 = buff + (bitspp / 8) * act_rect.X + stride * act_rect.Y;
|
2007-08-08 03:41:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bitmap->lockmode = flags;
|
|
|
|
bitmap->numlocks++;
|
|
|
|
|
2008-03-07 10:19:03 +01:00
|
|
|
bitmap->bitmapbits = buff;
|
2007-08-08 03:41:55 +02:00
|
|
|
|
2008-09-28 21:21:47 +02:00
|
|
|
GdipFree(pbmi);
|
2007-08-08 03:41:55 +02:00
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap* bitmap,
|
|
|
|
BitmapData* lockeddata)
|
|
|
|
{
|
|
|
|
HDC hdc;
|
2008-12-05 07:52:51 +01:00
|
|
|
HBITMAP hbm, old = NULL;
|
2007-08-08 03:41:55 +02:00
|
|
|
BOOL bm_is_selected;
|
2008-09-28 21:25:44 +02:00
|
|
|
BITMAPINFO *pbmi;
|
2007-08-08 03:41:55 +02:00
|
|
|
|
|
|
|
if(!bitmap || !lockeddata)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(!bitmap->lockmode)
|
|
|
|
return WrongState;
|
|
|
|
|
|
|
|
if(lockeddata->Reserved & ImageLockModeUserInputBuf)
|
|
|
|
return NotImplemented;
|
|
|
|
|
|
|
|
if(lockeddata->Reserved & ImageLockModeRead){
|
|
|
|
if(!(--bitmap->numlocks))
|
|
|
|
bitmap->lockmode = 0;
|
|
|
|
|
2008-03-07 10:19:03 +01:00
|
|
|
GdipFree(bitmap->bitmapbits);
|
|
|
|
bitmap->bitmapbits = NULL;
|
2007-08-08 03:41:55 +02:00
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2008-12-05 07:52:51 +01:00
|
|
|
IPicture_get_Handle(bitmap->image.picture, (OLE_HANDLE*)&hbm);
|
2007-08-08 03:41:55 +02:00
|
|
|
IPicture_get_CurDC(bitmap->image.picture, &hdc);
|
|
|
|
bm_is_selected = (hdc != 0);
|
|
|
|
|
2008-09-28 21:25:44 +02:00
|
|
|
pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
|
|
|
|
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
pbmi->bmiHeader.biBitCount = 0;
|
2007-08-08 03:41:55 +02:00
|
|
|
|
|
|
|
if(!bm_is_selected){
|
2007-08-10 03:25:05 +02:00
|
|
|
hdc = CreateCompatibleDC(0);
|
2008-12-05 07:52:51 +01:00
|
|
|
old = SelectObject(hdc, hbm);
|
2007-08-08 03:41:55 +02:00
|
|
|
}
|
|
|
|
|
2008-12-05 07:52:51 +01:00
|
|
|
GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
|
2008-09-28 21:25:44 +02:00
|
|
|
pbmi->bmiHeader.biBitCount = PIXELFORMATBPP(lockeddata->PixelFormat);
|
2008-12-05 07:52:51 +01:00
|
|
|
SetDIBits(hdc, hbm, 0, abs(pbmi->bmiHeader.biHeight),
|
2008-09-28 21:25:44 +02:00
|
|
|
bitmap->bitmapbits, pbmi, DIB_RGB_COLORS);
|
2007-08-08 03:41:55 +02:00
|
|
|
|
|
|
|
if(!bm_is_selected){
|
|
|
|
SelectObject(hdc, old);
|
2007-08-10 03:25:05 +02:00
|
|
|
DeleteDC(hdc);
|
2007-08-08 03:41:55 +02:00
|
|
|
}
|
|
|
|
|
2008-09-28 21:25:44 +02:00
|
|
|
GdipFree(pbmi);
|
2007-08-08 03:41:55 +02:00
|
|
|
GdipFree(bitmap->bitmapbits);
|
2008-03-07 10:19:03 +01:00
|
|
|
bitmap->bitmapbits = NULL;
|
2008-03-07 10:19:04 +01:00
|
|
|
bitmap->lockmode = 0;
|
2007-08-08 03:41:55 +02:00
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2008-07-02 03:03:34 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCloneImage(GpImage *image, GpImage **cloneImage)
|
|
|
|
{
|
2008-09-05 12:41:49 +02:00
|
|
|
IStream* stream;
|
|
|
|
HRESULT hr;
|
|
|
|
INT size;
|
2008-10-16 16:07:44 +02:00
|
|
|
LARGE_INTEGER move;
|
2008-10-20 15:10:10 +02:00
|
|
|
GpStatus stat = GenericError;
|
2008-07-02 03:03:34 +02:00
|
|
|
|
2008-09-05 12:41:49 +02:00
|
|
|
TRACE("%p, %p\n", image, cloneImage);
|
2008-07-02 03:03:34 +02:00
|
|
|
|
2008-09-05 12:41:49 +02:00
|
|
|
if (!image || !cloneImage)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
hr = CreateStreamOnHGlobal(0, TRUE, &stream);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return GenericError;
|
|
|
|
|
|
|
|
hr = IPicture_SaveAsFile(image->picture, stream, FALSE, &size);
|
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to save image on stream\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2008-10-16 16:07:44 +02:00
|
|
|
/* Set seek pointer back to the beginning of the picture */
|
|
|
|
move.QuadPart = 0;
|
|
|
|
hr = IStream_Seek(stream, move, STREAM_SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto out;
|
|
|
|
|
2008-10-20 15:10:10 +02:00
|
|
|
stat = GdipLoadImageFromStream(stream, cloneImage);
|
|
|
|
if (stat != Ok) WARN("Failed to load image from stream\n");
|
2008-09-05 12:41:49 +02:00
|
|
|
|
|
|
|
out:
|
|
|
|
IStream_Release(stream);
|
2008-10-20 15:10:10 +02:00
|
|
|
return stat;
|
2008-07-02 03:03:34 +02:00
|
|
|
}
|
|
|
|
|
2007-08-08 03:42:04 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCreateBitmapFromFile(GDIPCONST WCHAR* filename,
|
|
|
|
GpBitmap **bitmap)
|
|
|
|
{
|
|
|
|
GpStatus stat;
|
|
|
|
IStream *stream;
|
|
|
|
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
|
|
|
|
|
2007-08-08 03:42:04 +02:00
|
|
|
if(!filename || !bitmap)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
|
|
|
|
|
|
|
|
if(stat != Ok)
|
|
|
|
return stat;
|
|
|
|
|
|
|
|
stat = GdipCreateBitmapFromStream(stream, bitmap);
|
|
|
|
|
2008-02-24 16:41:27 +01:00
|
|
|
IStream_Release(stream);
|
2007-08-08 03:42:04 +02:00
|
|
|
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2008-07-10 16:39:29 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO* info,
|
|
|
|
VOID *bits, GpBitmap **bitmap)
|
|
|
|
{
|
|
|
|
DWORD height, stride;
|
|
|
|
PixelFormat format;
|
|
|
|
|
|
|
|
FIXME("(%p, %p, %p) - partially implemented\n", info, bits, bitmap);
|
|
|
|
|
|
|
|
height = abs(info->bmiHeader.biHeight);
|
|
|
|
stride = ((info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 31) >> 3) & ~3;
|
|
|
|
|
|
|
|
if(info->bmiHeader.biHeight > 0) /* bottom-up */
|
|
|
|
{
|
|
|
|
bits = (BYTE*)bits + (height - 1) * stride;
|
|
|
|
stride = -stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(info->bmiHeader.biBitCount) {
|
|
|
|
case 1:
|
|
|
|
format = PixelFormat1bppIndexed;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
format = PixelFormat4bppIndexed;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
format = PixelFormat8bppIndexed;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
format = PixelFormat24bppRGB;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("don't know how to handle %d bpp\n", info->bmiHeader.biBitCount);
|
|
|
|
*bitmap = NULL;
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GdipCreateBitmapFromScan0(info->bmiHeader.biWidth, height, stride, format,
|
|
|
|
bits, bitmap);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-03-05 04:22:01 +01:00
|
|
|
/* FIXME: no icm */
|
|
|
|
GpStatus WINGDIPAPI GdipCreateBitmapFromFileICM(GDIPCONST WCHAR* filename,
|
|
|
|
GpBitmap **bitmap)
|
|
|
|
{
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("(%s) %p\n", debugstr_w(filename), bitmap);
|
|
|
|
|
2008-03-05 04:22:01 +01:00
|
|
|
return GdipCreateBitmapFromFile(filename, bitmap);
|
|
|
|
}
|
|
|
|
|
2008-07-11 22:43:50 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCreateBitmapFromResource(HINSTANCE hInstance,
|
|
|
|
GDIPCONST WCHAR* lpBitmapName, GpBitmap** bitmap)
|
|
|
|
{
|
|
|
|
HBITMAP hbm;
|
|
|
|
GpStatus stat = InvalidParameter;
|
|
|
|
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("%p (%s) %p\n", hInstance, debugstr_w(lpBitmapName), bitmap);
|
|
|
|
|
2008-07-11 22:43:50 +02:00
|
|
|
if(!lpBitmapName || !bitmap)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
/* load DIB */
|
2008-12-05 07:53:04 +01:00
|
|
|
hbm = LoadImageW(hInstance, lpBitmapName, IMAGE_BITMAP, 0, 0,
|
|
|
|
LR_CREATEDIBSECTION);
|
2008-07-11 22:43:50 +02:00
|
|
|
|
|
|
|
if(hbm){
|
|
|
|
stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, bitmap);
|
|
|
|
DeleteObject(hbm);
|
|
|
|
}
|
|
|
|
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2007-12-19 09:58:51 +01:00
|
|
|
GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
|
|
|
|
HBITMAP* hbmReturn, ARGB background)
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
|
|
|
|
hbmReturn = NULL;
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2007-08-10 03:25:37 +02:00
|
|
|
GpStatus WINGDIPAPI GdipConvertToEmfPlus(const GpGraphics* ref,
|
|
|
|
GpMetafile* metafile, BOOL* succ, EmfType emfType,
|
|
|
|
const WCHAR* description, GpMetafile** out_metafile)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!ref || !metafile || !out_metafile)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
*succ = FALSE;
|
|
|
|
*out_metafile = NULL;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2007-08-09 04:42:28 +02:00
|
|
|
/* FIXME: this should create a bitmap in the given size with the attributes
|
|
|
|
* (resolution etc.) of the graphics object */
|
|
|
|
GpStatus WINGDIPAPI GdipCreateBitmapFromGraphics(INT width, INT height,
|
|
|
|
GpGraphics* target, GpBitmap** bitmap)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
GpStatus ret;
|
|
|
|
|
|
|
|
if(!target || !bitmap)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("hacked stub\n");
|
|
|
|
|
|
|
|
ret = GdipCreateBitmapFromScan0(width, height, 0, PixelFormat24bppRGB,
|
|
|
|
NULL, bitmap);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-08-01 04:15:52 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
|
|
|
|
PixelFormat format, BYTE* scan0, GpBitmap** bitmap)
|
|
|
|
{
|
|
|
|
BITMAPFILEHEADER *bmfh;
|
|
|
|
BITMAPINFOHEADER *bmih;
|
|
|
|
BYTE *buff;
|
2007-08-09 04:42:24 +02:00
|
|
|
INT datalen, size;
|
2007-08-01 04:15:52 +02:00
|
|
|
IStream *stream;
|
|
|
|
|
|
|
|
TRACE("%d %d %d %d %p %p\n", width, height, stride, format, scan0, bitmap);
|
|
|
|
|
2008-10-16 16:09:49 +02:00
|
|
|
if (!bitmap) return InvalidParameter;
|
|
|
|
|
|
|
|
if(width <= 0 || height <= 0 || (scan0 && (stride % 4))){
|
2007-08-09 04:42:24 +02:00
|
|
|
*bitmap = NULL;
|
2007-08-01 04:15:52 +02:00
|
|
|
return InvalidParameter;
|
2007-08-09 04:42:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(scan0 && !stride)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
/* FIXME: windows allows negative stride (reads backwards from scan0) */
|
|
|
|
if(stride < 0){
|
|
|
|
FIXME("negative stride\n");
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|
2007-08-01 04:15:52 +02:00
|
|
|
|
|
|
|
*bitmap = GdipAlloc(sizeof(GpBitmap));
|
|
|
|
if(!*bitmap) return OutOfMemory;
|
|
|
|
|
2007-08-09 04:42:24 +02:00
|
|
|
if(stride == 0){
|
|
|
|
stride = width * (PIXELFORMATBPP(format) / 8);
|
|
|
|
stride = (stride + 3) & ~3;
|
|
|
|
}
|
|
|
|
|
|
|
|
datalen = abs(stride * height);
|
2007-08-01 04:15:52 +02:00
|
|
|
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;
|
2007-08-09 04:42:24 +02:00
|
|
|
bmih->biHeight = -height;
|
2007-08-01 04:15:52 +02:00
|
|
|
/* FIXME: use the rest of the data from format */
|
2007-08-04 02:30:30 +02:00
|
|
|
bmih->biBitCount = PIXELFORMATBPP(format);
|
2007-08-01 04:15:52 +02:00
|
|
|
bmih->biCompression = BI_RGB;
|
2007-08-09 04:42:24 +02:00
|
|
|
bmih->biSizeImage = datalen;
|
2007-08-01 04:15:52 +02:00
|
|
|
|
2007-08-09 04:42:24 +02:00
|
|
|
if(scan0)
|
|
|
|
memcpy(bmih + 1, scan0, datalen);
|
|
|
|
else
|
|
|
|
memset(bmih + 1, 0, datalen);
|
2007-08-01 04:15:52 +02:00
|
|
|
|
|
|
|
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;
|
2008-05-09 14:39:43 +02:00
|
|
|
(*bitmap)->image.flags = ImageFlagsNone;
|
2007-08-01 04:16:20 +02:00
|
|
|
(*bitmap)->width = width;
|
|
|
|
(*bitmap)->height = height;
|
2007-08-04 02:30:30 +02:00
|
|
|
(*bitmap)->format = format;
|
2007-08-01 04:15:52 +02:00
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-08-04 02:30:22 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCreateBitmapFromStream(IStream* stream,
|
|
|
|
GpBitmap **bitmap)
|
|
|
|
{
|
|
|
|
GpStatus stat;
|
|
|
|
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("%p %p\n", stream, bitmap);
|
|
|
|
|
2007-08-04 02:30:22 +02:00
|
|
|
stat = GdipLoadImageFromStream(stream, (GpImage**) bitmap);
|
|
|
|
|
|
|
|
if(stat != Ok)
|
|
|
|
return stat;
|
|
|
|
|
2007-08-08 03:42:20 +02:00
|
|
|
if((*bitmap)->image.type != ImageTypeBitmap){
|
|
|
|
IPicture_Release((*bitmap)->image.picture);
|
|
|
|
GdipFree(bitmap);
|
|
|
|
return GenericError; /* FIXME: what error to return? */
|
2007-08-04 02:30:30 +02:00
|
|
|
}
|
|
|
|
|
2007-08-04 02:30:22 +02:00
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-08-04 02:30:30 +02:00
|
|
|
/* FIXME: no icm */
|
2007-08-01 04:16:04 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCreateBitmapFromStreamICM(IStream* stream,
|
|
|
|
GpBitmap **bitmap)
|
|
|
|
{
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("%p %p\n", stream, bitmap);
|
|
|
|
|
2007-08-04 02:30:30 +02:00
|
|
|
return GdipCreateBitmapFromStream(stream, bitmap);
|
2007-08-01 04:16:04 +02:00
|
|
|
}
|
|
|
|
|
2008-11-04 06:54:32 +01:00
|
|
|
GpStatus WINGDIPAPI GdipCreateCachedBitmap(GpBitmap *bitmap, GpGraphics *graphics,
|
|
|
|
GpCachedBitmap **cachedbmp)
|
|
|
|
{
|
|
|
|
GpStatus stat;
|
|
|
|
|
|
|
|
TRACE("%p %p %p\n", bitmap, graphics, cachedbmp);
|
|
|
|
|
|
|
|
if(!bitmap || !graphics || !cachedbmp)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
*cachedbmp = GdipAlloc(sizeof(GpCachedBitmap));
|
|
|
|
if(!*cachedbmp)
|
|
|
|
return OutOfMemory;
|
|
|
|
|
2008-11-21 23:57:48 +01:00
|
|
|
stat = GdipCloneImage(&(bitmap->image), &(*cachedbmp)->image);
|
2008-11-04 06:54:32 +01:00
|
|
|
if(stat != Ok){
|
|
|
|
GdipFree(*cachedbmp);
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipDeleteCachedBitmap(GpCachedBitmap *cachedbmp)
|
|
|
|
{
|
|
|
|
TRACE("%p\n", cachedbmp);
|
|
|
|
|
|
|
|
if(!cachedbmp)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2008-11-21 23:57:48 +01:00
|
|
|
GdipDisposeImage(cachedbmp->image);
|
|
|
|
GdipFree(cachedbmp);
|
2008-11-04 06:54:32 +01:00
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipDrawCachedBitmap(GpGraphics *graphics,
|
|
|
|
GpCachedBitmap *cachedbmp, INT x, INT y)
|
|
|
|
{
|
|
|
|
TRACE("%p %p %d %d\n", graphics, cachedbmp, x, y);
|
|
|
|
|
|
|
|
if(!graphics || !cachedbmp)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2008-11-21 23:57:48 +01:00
|
|
|
return GdipDrawImage(graphics, cachedbmp->image, (REAL)x, (REAL)y);
|
2008-11-04 06:54:32 +01:00
|
|
|
}
|
|
|
|
|
2007-07-25 02:19:18 +02:00
|
|
|
GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
|
|
|
|
{
|
2007-08-10 03:25:01 +02:00
|
|
|
HDC hdc;
|
|
|
|
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("%p\n", image);
|
|
|
|
|
2007-08-01 04:14:57 +02:00
|
|
|
if(!image)
|
|
|
|
return InvalidParameter;
|
2007-07-25 02:19:18 +02:00
|
|
|
|
2007-08-10 03:25:01 +02:00
|
|
|
IPicture_get_CurDC(image->picture, &hdc);
|
|
|
|
DeleteDC(hdc);
|
2007-08-01 04:14:57 +02:00
|
|
|
IPicture_Release(image->picture);
|
2008-03-07 10:19:03 +01:00
|
|
|
if (image->type == ImageTypeBitmap)
|
|
|
|
GdipFree(((GpBitmap*)image)->bitmapbits);
|
2007-08-01 04:14:57 +02:00
|
|
|
GdipFree(image);
|
2007-07-25 02:19:18 +02:00
|
|
|
|
2007-08-01 04:14:57 +02:00
|
|
|
return Ok;
|
2007-07-25 02:19:18 +02:00
|
|
|
}
|
|
|
|
|
2007-08-01 04:15:33 +02:00
|
|
|
GpStatus WINGDIPAPI GdipFindFirstImageItem(GpImage *image, ImageItemData* item)
|
|
|
|
{
|
|
|
|
if(!image || !item)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2007-07-31 04:09:37 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetImageBounds(GpImage *image, GpRectF *srcRect,
|
|
|
|
GpUnit *srcUnit)
|
|
|
|
{
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("%p %p %p\n", image, srcRect, srcUnit);
|
|
|
|
|
2007-07-31 04:09:37 +02:00
|
|
|
if(!image || !srcRect || !srcUnit)
|
|
|
|
return InvalidParameter;
|
2007-07-31 04:09:57 +02:00
|
|
|
if(image->type == ImageTypeMetafile){
|
2008-02-29 23:06:47 +01:00
|
|
|
*srcRect = ((GpMetafile*)image)->bounds;
|
2007-07-31 04:09:57 +02:00
|
|
|
*srcUnit = ((GpMetafile*)image)->unit;
|
|
|
|
}
|
2007-08-01 04:16:20 +02: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 04:09:57 +02:00
|
|
|
else{
|
2007-08-01 04:16:20 +02: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 04:09:57 +02:00
|
|
|
}
|
2007-07-31 04:09:37 +02:00
|
|
|
|
2007-08-01 04:16:20 +02:00
|
|
|
TRACE("returning (%f, %f) (%f, %f) unit type %d\n", srcRect->X, srcRect->Y,
|
|
|
|
srcRect->Width, srcRect->Height, *srcUnit);
|
|
|
|
|
2007-07-31 04:09:57 +02:00
|
|
|
return Ok;
|
2007-07-31 04:09:37 +02:00
|
|
|
}
|
|
|
|
|
2008-02-27 10:36:44 +01:00
|
|
|
GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width,
|
|
|
|
REAL *height)
|
|
|
|
{
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("%p %p %p\n", image, width, height);
|
|
|
|
|
2008-02-27 10:36:44 +01:00
|
|
|
if(!image || !height || !width)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(image->type == ImageTypeMetafile){
|
|
|
|
HDC hdc = GetDC(0);
|
|
|
|
|
|
|
|
*height = convert_unit(hdc, ((GpMetafile*)image)->unit) *
|
|
|
|
((GpMetafile*)image)->bounds.Height;
|
|
|
|
|
|
|
|
*width = convert_unit(hdc, ((GpMetafile*)image)->unit) *
|
|
|
|
((GpMetafile*)image)->bounds.Width;
|
|
|
|
|
|
|
|
ReleaseDC(0, hdc);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(image->type == ImageTypeBitmap){
|
|
|
|
*height = ((GpBitmap*)image)->height;
|
|
|
|
*width = ((GpBitmap*)image)->width;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
*height = ipicture_pixel_height(image->picture);
|
|
|
|
*width = ipicture_pixel_width(image->picture);
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("returning (%f, %f)\n", *height, *width);
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-08-10 03:25:01 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage *image,
|
|
|
|
GpGraphics **graphics)
|
|
|
|
{
|
|
|
|
HDC hdc;
|
|
|
|
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("%p %p\n", image, graphics);
|
|
|
|
|
2007-08-10 03:25:01 +02:00
|
|
|
if(!image || !graphics)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(image->type != ImageTypeBitmap){
|
|
|
|
FIXME("not implemented for image type %d\n", image->type);
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
|
|
|
IPicture_get_CurDC(image->picture, &hdc);
|
|
|
|
|
|
|
|
if(!hdc){
|
|
|
|
hdc = CreateCompatibleDC(0);
|
|
|
|
IPicture_SelectPicture(image->picture, hdc, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GdipCreateFromHDC(hdc, graphics);
|
|
|
|
}
|
|
|
|
|
2007-07-25 02:19:02 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
|
|
|
|
{
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("%p %p\n", image, height);
|
|
|
|
|
2007-07-25 02:19:02 +02:00
|
|
|
if(!image || !height)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-08-01 04:16:20 +02:00
|
|
|
if(image->type == ImageTypeMetafile){
|
2007-08-08 03:42:09 +02:00
|
|
|
HDC hdc = GetDC(0);
|
|
|
|
|
|
|
|
*height = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
|
|
|
|
((GpMetafile*)image)->bounds.Height);
|
|
|
|
|
|
|
|
ReleaseDC(0, hdc);
|
2007-08-01 04:16:20 +02:00
|
|
|
}
|
|
|
|
else if(image->type == ImageTypeBitmap)
|
|
|
|
*height = ((GpBitmap*)image)->height;
|
|
|
|
else
|
|
|
|
*height = ipicture_pixel_height(image->picture);
|
2007-07-25 02:19:02 +02:00
|
|
|
|
2007-08-01 04:16:20 +02:00
|
|
|
TRACE("returning %d\n", *height);
|
|
|
|
|
|
|
|
return Ok;
|
2007-07-25 02:19:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipGetImageHorizontalResolution(GpImage *image, REAL *res)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!image || !res)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2008-12-01 22:17:10 +01:00
|
|
|
GpStatus WINGDIPAPI GdipGetImagePaletteSize(GpImage *image, INT *size)
|
|
|
|
{
|
|
|
|
FIXME("%p %p\n", image, size);
|
|
|
|
|
|
|
|
if(!image || !size)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2007-08-04 02:30:30 +02:00
|
|
|
/* FIXME: test this function for non-bitmap types */
|
|
|
|
GpStatus WINGDIPAPI GdipGetImagePixelFormat(GpImage *image, PixelFormat *format)
|
|
|
|
{
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("%p %p\n", image, format);
|
|
|
|
|
2007-08-04 02:30:30 +02:00
|
|
|
if(!image || !format)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(image->type != ImageTypeBitmap)
|
|
|
|
*format = PixelFormat24bppRGB;
|
|
|
|
else
|
|
|
|
*format = ((GpBitmap*) image)->format;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-07-25 02:19:02 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetImageRawFormat(GpImage *image, GUID *format)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!image || !format)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(!(calls++))
|
2008-11-24 10:23:16 +01:00
|
|
|
FIXME("stub\n");
|
2007-07-25 02:19:02 +02:00
|
|
|
|
2008-11-24 10:23:16 +01:00
|
|
|
/* FIXME: should be detected from embedded picture or stored separately */
|
|
|
|
switch (image->type)
|
|
|
|
{
|
|
|
|
case ImageTypeBitmap: *format = ImageFormatBMP; break;
|
|
|
|
case ImageTypeMetafile: *format = ImageFormatEMF; break;
|
|
|
|
default:
|
|
|
|
WARN("unknown type %u\n", image->type);
|
|
|
|
*format = ImageFormatUndefined;
|
|
|
|
}
|
|
|
|
return Ok;
|
2007-07-25 02:19:02 +02:00
|
|
|
}
|
|
|
|
|
2007-07-25 02:19:12 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetImageType(GpImage *image, ImageType *type)
|
|
|
|
{
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("%p %p\n", image, type);
|
|
|
|
|
2007-07-25 02:19:12 +02:00
|
|
|
if(!image || !type)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-08-01 04:15:08 +02:00
|
|
|
*type = image->type;
|
2007-07-25 02:19:12 +02:00
|
|
|
|
2007-07-31 04:09:49 +02:00
|
|
|
return Ok;
|
2007-07-25 02:19:12 +02:00
|
|
|
}
|
|
|
|
|
2007-07-25 02:19:02 +02: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)
|
|
|
|
{
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("%p %p\n", image, width);
|
|
|
|
|
2007-07-25 02:19:02 +02:00
|
|
|
if(!image || !width)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-08-01 04:16:20 +02:00
|
|
|
if(image->type == ImageTypeMetafile){
|
2007-08-08 03:42:09 +02:00
|
|
|
HDC hdc = GetDC(0);
|
|
|
|
|
|
|
|
*width = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
|
|
|
|
((GpMetafile*)image)->bounds.Width);
|
|
|
|
|
|
|
|
ReleaseDC(0, hdc);
|
2007-08-01 04:16:20 +02:00
|
|
|
}
|
|
|
|
else if(image->type == ImageTypeBitmap)
|
|
|
|
*width = ((GpBitmap*)image)->width;
|
|
|
|
else
|
|
|
|
*width = ipicture_pixel_width(image->picture);
|
2007-07-25 02:19:02 +02:00
|
|
|
|
2007-08-01 04:16:20 +02:00
|
|
|
TRACE("returning %d\n", *width);
|
|
|
|
|
|
|
|
return Ok;
|
2007-07-25 02:19:02 +02:00
|
|
|
}
|
|
|
|
|
2007-08-01 04:15:29 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetMetafileHeaderFromMetafile(GpMetafile * metafile,
|
|
|
|
MetafileHeader * header)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!metafile || !header)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
2007-08-08 03:42:24 +02:00
|
|
|
return Ok;
|
2007-08-01 04:15:29 +02:00
|
|
|
}
|
|
|
|
|
2008-09-07 23:25:04 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetAllPropertyItems(GpImage *image, UINT size,
|
|
|
|
UINT num, PropertyItem* items)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipGetPropertyCount(GpImage *image, UINT* num)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipGetPropertyIdList(GpImage *image, UINT num, PROPID* list)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipGetPropertyItem(GpImage *image, PROPID id, UINT size,
|
|
|
|
PropertyItem* buffer)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|
|
|
|
|
2007-08-01 04:15:56 +02: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;
|
|
|
|
}
|
|
|
|
|
2008-09-07 23:25:04 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetPropertySize(GpImage *image, UINT* size, UINT* num)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|
|
|
|
|
2007-07-25 02:19:02 +02: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 02:19:21 +02:00
|
|
|
|
2008-06-19 10:38:09 +02:00
|
|
|
GpStatus WINGDIPAPI GdipImageGetFrameDimensionsCount(GpImage *image,
|
|
|
|
UINT* count)
|
|
|
|
{
|
|
|
|
if(!image || !count)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
*count = 1;
|
|
|
|
|
|
|
|
FIXME("stub\n");
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-08-04 02:30:26 +02:00
|
|
|
GpStatus WINGDIPAPI GdipImageGetFrameDimensionsList(GpImage* image,
|
|
|
|
GUID* dimensionIDs, UINT count)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!image || !dimensionIDs)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-08-04 02:30:34 +02:00
|
|
|
GpStatus WINGDIPAPI GdipImageSelectActiveFrame(GpImage *image,
|
|
|
|
GDIPCONST GUID* dimensionID, UINT frameidx)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!image || !dimensionID)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2008-02-24 16:41:29 +01:00
|
|
|
GpStatus WINGDIPAPI GdipLoadImageFromFile(GDIPCONST WCHAR* filename,
|
|
|
|
GpImage **image)
|
|
|
|
{
|
|
|
|
GpStatus stat;
|
|
|
|
IStream *stream;
|
|
|
|
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("(%s) %p\n", debugstr_w(filename), image);
|
|
|
|
|
2008-02-24 16:41:29 +01:00
|
|
|
if (!filename || !image)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
stat = GdipCreateStreamOnFile(filename, GENERIC_READ, &stream);
|
|
|
|
|
|
|
|
if (stat != Ok)
|
|
|
|
return stat;
|
|
|
|
|
|
|
|
stat = GdipLoadImageFromStream(stream, image);
|
|
|
|
|
|
|
|
IStream_Release(stream);
|
|
|
|
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2008-05-09 14:40:21 +02:00
|
|
|
/* FIXME: no icm handling */
|
|
|
|
GpStatus WINGDIPAPI GdipLoadImageFromFileICM(GDIPCONST WCHAR* filename,GpImage **image)
|
|
|
|
{
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("(%s) %p\n", debugstr_w(filename), image);
|
|
|
|
|
2008-05-09 14:40:21 +02:00
|
|
|
return GdipLoadImageFromFile(filename, image);
|
|
|
|
}
|
|
|
|
|
2007-08-04 02:30:22 +02:00
|
|
|
GpStatus WINGDIPAPI GdipLoadImageFromStream(IStream* stream, GpImage **image)
|
2007-07-25 02:19:21 +02:00
|
|
|
{
|
2007-08-08 03:42:20 +02:00
|
|
|
IPicture *pic;
|
|
|
|
short type;
|
|
|
|
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("%p %p\n", stream, image);
|
|
|
|
|
2007-07-25 02:19:21 +02:00
|
|
|
if(!stream || !image)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-08-01 04:15:48 +02:00
|
|
|
if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
|
2007-08-08 03:42:20 +02:00
|
|
|
(LPVOID*) &pic) != S_OK){
|
2007-08-01 04:15:48 +02:00
|
|
|
TRACE("Could not load picture\n");
|
|
|
|
return GenericError;
|
|
|
|
}
|
|
|
|
|
2007-08-08 03:42:20 +02:00
|
|
|
IPicture_get_Type(pic, &type);
|
|
|
|
|
|
|
|
if(type == PICTYPE_BITMAP){
|
2008-09-28 21:36:30 +02:00
|
|
|
BITMAPINFO *pbmi;
|
2007-08-08 03:42:20 +02:00
|
|
|
BITMAPCOREHEADER* bmch;
|
2008-12-05 07:52:51 +01:00
|
|
|
HBITMAP hbm;
|
2007-08-08 03:42:20 +02:00
|
|
|
HDC hdc;
|
|
|
|
|
2008-09-28 21:36:30 +02:00
|
|
|
pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
|
|
|
|
if (!pbmi)
|
|
|
|
return OutOfMemory;
|
2007-08-08 03:42:20 +02:00
|
|
|
*image = GdipAlloc(sizeof(GpBitmap));
|
2008-09-28 21:36:30 +02:00
|
|
|
if(!*image){
|
|
|
|
GdipFree(pbmi);
|
|
|
|
return OutOfMemory;
|
|
|
|
}
|
2007-08-08 03:42:20 +02:00
|
|
|
(*image)->type = ImageTypeBitmap;
|
|
|
|
|
|
|
|
(*((GpBitmap**) image))->width = ipicture_pixel_width(pic);
|
|
|
|
(*((GpBitmap**) image))->height = ipicture_pixel_height(pic);
|
|
|
|
|
|
|
|
/* get the pixel format */
|
2008-12-05 07:52:51 +01:00
|
|
|
IPicture_get_Handle(pic, (OLE_HANDLE*)&hbm);
|
2007-08-08 03:42:20 +02:00
|
|
|
IPicture_get_CurDC(pic, &hdc);
|
|
|
|
|
2008-09-28 21:36:30 +02:00
|
|
|
bmch = (BITMAPCOREHEADER*) (&pbmi->bmiHeader);
|
2007-08-08 03:42:20 +02:00
|
|
|
bmch->bcSize = sizeof(BITMAPCOREHEADER);
|
|
|
|
|
|
|
|
if(!hdc){
|
|
|
|
HBITMAP old;
|
2007-08-10 03:25:05 +02:00
|
|
|
hdc = CreateCompatibleDC(0);
|
2008-12-05 07:52:51 +01:00
|
|
|
old = SelectObject(hdc, hbm);
|
|
|
|
GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
|
2007-08-08 03:42:20 +02:00
|
|
|
SelectObject(hdc, old);
|
2007-08-10 03:25:05 +02:00
|
|
|
DeleteDC(hdc);
|
2007-08-08 03:42:20 +02:00
|
|
|
}
|
|
|
|
else
|
2008-12-05 07:52:51 +01:00
|
|
|
GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
|
2007-08-08 03:42:20 +02:00
|
|
|
|
2009-01-15 10:39:47 +01:00
|
|
|
switch(bmch->bcBitCount)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
(*((GpBitmap**) image))->format = PixelFormat1bppIndexed;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
(*((GpBitmap**) image))->format = PixelFormat4bppIndexed;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
(*((GpBitmap**) image))->format = PixelFormat8bppIndexed;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
(*((GpBitmap**) image))->format = PixelFormat16bppRGB565;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
(*((GpBitmap**) image))->format = PixelFormat24bppRGB;
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
(*((GpBitmap**) image))->format = PixelFormat32bppRGB;
|
|
|
|
break;
|
|
|
|
case 48:
|
|
|
|
(*((GpBitmap**) image))->format = PixelFormat48bppRGB;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Bit depth %d is not fully supported yet\n", bmch->bcBitCount);
|
|
|
|
(*((GpBitmap**) image))->format = (bmch->bcBitCount << 8) | PixelFormatGDI;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-09-28 21:36:30 +02:00
|
|
|
GdipFree(pbmi);
|
2007-08-08 03:42:20 +02:00
|
|
|
}
|
|
|
|
else if(type == PICTYPE_METAFILE || type == PICTYPE_ENHMETAFILE){
|
|
|
|
/* FIXME: missing initialization code */
|
|
|
|
*image = GdipAlloc(sizeof(GpMetafile));
|
|
|
|
if(!*image) return OutOfMemory;
|
|
|
|
(*image)->type = ImageTypeMetafile;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
*image = GdipAlloc(sizeof(GpImage));
|
|
|
|
if(!*image) return OutOfMemory;
|
|
|
|
(*image)->type = ImageTypeUnknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*image)->picture = pic;
|
2008-05-09 14:39:43 +02:00
|
|
|
(*image)->flags = ImageFlagsNone;
|
2007-08-01 04:15:48 +02:00
|
|
|
|
|
|
|
return Ok;
|
2007-07-25 02:19:21 +02:00
|
|
|
}
|
2007-08-01 04:16:00 +02:00
|
|
|
|
2007-08-04 02:30:22 +02:00
|
|
|
/* FIXME: no ICM */
|
|
|
|
GpStatus WINGDIPAPI GdipLoadImageFromStreamICM(IStream* stream, GpImage **image)
|
|
|
|
{
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("%p %p\n", stream, image);
|
|
|
|
|
2007-08-04 02:30:22 +02:00
|
|
|
return GdipLoadImageFromStream(stream, image);
|
|
|
|
}
|
|
|
|
|
2007-08-01 04:16:08 +02:00
|
|
|
GpStatus WINGDIPAPI GdipRemovePropertyItem(GpImage *image, PROPID propId)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!image)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2008-09-07 23:25:04 +02:00
|
|
|
GpStatus WINGDIPAPI GdipSetPropertyItem(GpImage *image, GDIPCONST PropertyItem* item)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2008-03-10 16:16:54 +01:00
|
|
|
GpStatus WINGDIPAPI GdipSaveImageToFile(GpImage *image, GDIPCONST WCHAR* filename,
|
|
|
|
GDIPCONST CLSID *clsidEncoder,
|
|
|
|
GDIPCONST EncoderParameters *encoderParams)
|
|
|
|
{
|
|
|
|
GpStatus stat;
|
|
|
|
IStream *stream;
|
|
|
|
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("%p (%s) %p %p\n", image, debugstr_w(filename), clsidEncoder, encoderParams);
|
|
|
|
|
2008-03-10 16:16:54 +01:00
|
|
|
if (!image || !filename|| !clsidEncoder)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if (!(image->picture))
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
stat = GdipCreateStreamOnFile(filename, GENERIC_WRITE, &stream);
|
|
|
|
if (stat != Ok)
|
|
|
|
return GenericError;
|
|
|
|
|
|
|
|
stat = GdipSaveImageToStream(image, stream, clsidEncoder, encoderParams);
|
|
|
|
|
|
|
|
IStream_Release(stream);
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2008-03-10 16:16:55 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* Encoding functions -
|
|
|
|
* These functions encode an image in different image file formats.
|
|
|
|
*/
|
2008-03-10 16:16:56 +01:00
|
|
|
#define BITMAP_FORMAT_BMP 0x4d42 /* "BM" */
|
|
|
|
#define BITMAP_FORMAT_JPEG 0xd8ff
|
|
|
|
#define BITMAP_FORMAT_GIF 0x4947
|
|
|
|
#define BITMAP_FORMAT_PNG 0x5089
|
|
|
|
#define BITMAP_FORMAT_APM 0xcdd7
|
|
|
|
|
2008-03-10 16:16:55 +01:00
|
|
|
static GpStatus encode_image_BMP(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
|
|
|
|
void **output, unsigned int *output_size)
|
|
|
|
{
|
2008-03-10 16:16:56 +01:00
|
|
|
int num_palette_entries;
|
|
|
|
BITMAPFILEHEADER *bmp_file_hdr;
|
|
|
|
BITMAPINFO *bmp_info_hdr;
|
|
|
|
|
|
|
|
if (bitmap_info->bmiHeader.biClrUsed) {
|
|
|
|
num_palette_entries = bitmap_info->bmiHeader.biClrUsed;
|
|
|
|
if (num_palette_entries > 256) num_palette_entries = 256;
|
|
|
|
} else {
|
|
|
|
if (bitmap_info->bmiHeader.biBitCount <= 8)
|
|
|
|
num_palette_entries = 1 << bitmap_info->bmiHeader.biBitCount;
|
|
|
|
else
|
|
|
|
num_palette_entries = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
*output_size =
|
|
|
|
sizeof(BITMAPFILEHEADER) +
|
|
|
|
sizeof(BITMAPINFOHEADER) +
|
|
|
|
num_palette_entries * sizeof(RGBQUAD) +
|
|
|
|
bitmap_info->bmiHeader.biSizeImage;
|
|
|
|
|
|
|
|
*output = GdipAlloc(*output_size);
|
|
|
|
|
2009-01-14 09:52:24 +01:00
|
|
|
bmp_file_hdr = *output;
|
2008-03-10 16:16:56 +01:00
|
|
|
bmp_file_hdr->bfType = BITMAP_FORMAT_BMP;
|
|
|
|
bmp_file_hdr->bfSize = *output_size;
|
|
|
|
bmp_file_hdr->bfOffBits =
|
|
|
|
sizeof(BITMAPFILEHEADER) +
|
|
|
|
sizeof(BITMAPINFOHEADER) +
|
|
|
|
num_palette_entries * sizeof (RGBQUAD);
|
|
|
|
|
|
|
|
bmp_info_hdr = (BITMAPINFO*) ((unsigned char*)(*output) + sizeof(BITMAPFILEHEADER));
|
|
|
|
memcpy(bmp_info_hdr, bitmap_info, sizeof(BITMAPINFOHEADER) + num_palette_entries * sizeof(RGBQUAD));
|
|
|
|
memcpy((unsigned char *)(*output) +
|
|
|
|
sizeof(BITMAPFILEHEADER) +
|
|
|
|
sizeof(BITMAPINFOHEADER) +
|
|
|
|
num_palette_entries * sizeof(RGBQUAD),
|
|
|
|
bitmap_bits, bitmap_info->bmiHeader.biSizeImage);
|
|
|
|
|
|
|
|
return Ok;
|
2008-03-10 16:16:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef GpStatus encode_image_func(LPVOID bitmap_bits, LPBITMAPINFO bitmap_info,
|
|
|
|
void **output, unsigned int *output_size);
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
BMP,
|
|
|
|
NUM_ENCODERS_SUPPORTED
|
|
|
|
} ImageFormat;
|
|
|
|
|
|
|
|
static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED];
|
|
|
|
static encode_image_func *const encode_image_funcs[NUM_ENCODERS_SUPPORTED] = {
|
|
|
|
encode_image_BMP,
|
|
|
|
};
|
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipSaveImageToStream [GDIPLUS.@]
|
|
|
|
*/
|
2007-08-01 04:16:00 +02:00
|
|
|
GpStatus WINGDIPAPI GdipSaveImageToStream(GpImage *image, IStream* stream,
|
|
|
|
GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
|
|
|
|
{
|
2008-03-10 16:16:55 +01:00
|
|
|
GpStatus stat;
|
|
|
|
HRESULT hr;
|
|
|
|
short type;
|
|
|
|
HBITMAP hbmp;
|
2008-03-15 23:05:43 +01:00
|
|
|
HBITMAP old_hbmp;
|
2008-03-10 16:16:55 +01:00
|
|
|
HDC hdc;
|
2008-03-15 23:05:43 +01:00
|
|
|
int bm_is_selected;
|
2008-03-10 16:16:55 +01:00
|
|
|
BITMAPINFO bmp_info;
|
|
|
|
LPVOID bmp_bits;
|
|
|
|
encode_image_func* encode_image;
|
|
|
|
LPVOID output;
|
|
|
|
unsigned int output_size;
|
|
|
|
unsigned int dummy;
|
|
|
|
int i;
|
|
|
|
|
2008-03-15 23:05:43 +01:00
|
|
|
old_hbmp = 0;
|
2008-03-10 16:16:55 +01:00
|
|
|
output = NULL;
|
|
|
|
output_size = 0;
|
|
|
|
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("%p %p %p %p\n", image, stream, clsid, params);
|
|
|
|
|
2007-08-01 04:16:00 +02:00
|
|
|
if(!image || !stream)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2008-03-10 16:16:55 +01:00
|
|
|
if (!image->picture)
|
|
|
|
return GenericError;
|
|
|
|
|
|
|
|
hr = IPicture_get_Type(image->picture, &type);
|
|
|
|
if (FAILED(hr) || type != PICTYPE_BITMAP)
|
|
|
|
return GenericError;
|
2007-08-01 04:16:00 +02:00
|
|
|
|
2008-03-10 16:16:55 +01:00
|
|
|
/* select correct encoder */
|
|
|
|
encode_image = NULL;
|
|
|
|
for (i = 0; i < NUM_ENCODERS_SUPPORTED; i++) {
|
|
|
|
if (IsEqualCLSID(clsid, &codecs[i].Clsid))
|
|
|
|
encode_image = encode_image_funcs[i];
|
|
|
|
}
|
|
|
|
if (encode_image == NULL)
|
|
|
|
return UnknownImageFormat;
|
2007-08-01 04:16:00 +02:00
|
|
|
|
2008-03-10 16:16:55 +01:00
|
|
|
/* extract underlying hbitmap representation from the IPicture */
|
|
|
|
hr = IPicture_get_Handle(image->picture, (OLE_HANDLE*)&hbmp);
|
|
|
|
if (FAILED(hr) || !hbmp)
|
|
|
|
return GenericError;
|
2008-03-15 23:05:43 +01:00
|
|
|
hr = IPicture_get_CurDC(image->picture, &hdc);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return GenericError;
|
|
|
|
bm_is_selected = (hdc != 0);
|
|
|
|
if (!bm_is_selected) {
|
|
|
|
hdc = CreateCompatibleDC(0);
|
|
|
|
old_hbmp = SelectObject(hdc, hbmp);
|
|
|
|
}
|
2008-03-10 16:16:55 +01:00
|
|
|
|
|
|
|
/* get bits from HBITMAP */
|
|
|
|
bmp_info.bmiHeader.biSize = sizeof(bmp_info.bmiHeader);
|
2008-03-15 23:05:43 +01:00
|
|
|
bmp_info.bmiHeader.biBitCount = 0;
|
2008-03-10 16:16:55 +01:00
|
|
|
GetDIBits(hdc, hbmp, 0, 0, NULL, &bmp_info, DIB_RGB_COLORS);
|
|
|
|
|
|
|
|
bmp_bits = GdipAlloc(bmp_info.bmiHeader.biSizeImage);
|
2008-03-15 23:05:43 +01:00
|
|
|
|
|
|
|
if (bmp_bits)
|
|
|
|
GetDIBits(hdc, hbmp, 0, abs(bmp_info.bmiHeader.biHeight), bmp_bits, &bmp_info, DIB_RGB_COLORS);
|
|
|
|
|
|
|
|
if (!bm_is_selected) {
|
|
|
|
SelectObject(hdc, old_hbmp);
|
|
|
|
DeleteDC(hdc);
|
2008-03-10 16:16:55 +01:00
|
|
|
}
|
2008-03-15 23:05:43 +01:00
|
|
|
|
|
|
|
if (!bmp_bits)
|
|
|
|
return OutOfMemory;
|
2008-03-10 16:16:55 +01:00
|
|
|
|
|
|
|
stat = encode_image(bmp_bits, &bmp_info, &output, &output_size);
|
|
|
|
if (stat == Ok)
|
|
|
|
IStream_Write(stream, output, output_size, &dummy);
|
|
|
|
|
|
|
|
GdipFree(output);
|
|
|
|
GdipFree(bmp_bits);
|
|
|
|
|
|
|
|
return stat;
|
2007-08-01 04:16:00 +02:00
|
|
|
}
|
2007-08-09 04:42:16 +02:00
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipSetImagePalette [GDIPLUS.@]
|
|
|
|
*/
|
2007-08-09 04:42:16 +02:00
|
|
|
GpStatus WINGDIPAPI GdipSetImagePalette(GpImage *image,
|
|
|
|
GDIPCONST ColorPalette *palette)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!image || !palette)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
2008-03-06 10:17:00 +01:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* Encoders -
|
|
|
|
* Structures that represent which formats we support for encoding.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ImageCodecInfo creation routines taken from libgdiplus */
|
|
|
|
static const WCHAR bmp_codecname[] = {'B', 'u', 'i','l', 't', '-','i', 'n', ' ', 'B', 'M', 'P', 0}; /* Built-in BMP */
|
|
|
|
static const WCHAR bmp_extension[] = {'*','.','B', 'M', 'P',';', '*','.', 'D','I', 'B',';', '*','.', 'R', 'L', 'E',0}; /* *.BMP;*.DIB;*.RLE */
|
|
|
|
static const WCHAR bmp_mimetype[] = {'i', 'm', 'a','g', 'e', '/', 'b', 'm', 'p', 0}; /* image/bmp */
|
|
|
|
static const WCHAR bmp_format[] = {'B', 'M', 'P', 0}; /* BMP */
|
|
|
|
static const BYTE bmp_sig_pattern[] = { 0x42, 0x4D };
|
|
|
|
static const BYTE bmp_sig_mask[] = { 0xFF, 0xFF };
|
|
|
|
|
|
|
|
static const ImageCodecInfo codecs[NUM_ENCODERS_SUPPORTED] =
|
|
|
|
{
|
|
|
|
{ /* BMP */
|
|
|
|
/* Clsid */ { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
|
|
|
|
/* FormatID */ { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
|
|
|
|
/* CodecName */ bmp_codecname,
|
|
|
|
/* DllName */ NULL,
|
|
|
|
/* FormatDescription */ bmp_format,
|
|
|
|
/* FilenameExtension */ bmp_extension,
|
|
|
|
/* MimeType */ bmp_mimetype,
|
|
|
|
/* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
|
|
|
|
/* Version */ 1,
|
|
|
|
/* SigCount */ 1,
|
|
|
|
/* SigSize */ 2,
|
|
|
|
/* SigPattern */ bmp_sig_pattern,
|
|
|
|
/* SigMask */ bmp_sig_mask,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2008-09-13 02:40:28 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipGetImageDecodersSize [GDIPLUS.@]
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipGetImageDecodersSize(UINT *numDecoders, UINT *size)
|
|
|
|
{
|
|
|
|
FIXME("%p %p stub!\n", numDecoders, size);
|
|
|
|
|
|
|
|
if (!numDecoders || !size)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
*numDecoders = 0;
|
|
|
|
*size = 0;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GdipGetImageDecoders [GDIPLUS.@]
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipGetImageDecoders(UINT numDecoders, UINT size, ImageCodecInfo *decoders)
|
|
|
|
{
|
|
|
|
FIXME("%u %u %p stub!\n", numDecoders, size, decoders);
|
|
|
|
|
|
|
|
if (!decoders)
|
|
|
|
return GenericError;
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipGetImageEncodersSize [GDIPLUS.@]
|
|
|
|
*/
|
2008-03-06 10:17:00 +01:00
|
|
|
GpStatus WINGDIPAPI GdipGetImageEncodersSize(UINT *numEncoders, UINT *size)
|
|
|
|
{
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("%p %p\n", numEncoders, size);
|
|
|
|
|
2008-03-06 10:17:00 +01:00
|
|
|
if (!numEncoders || !size)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
*numEncoders = NUM_ENCODERS_SUPPORTED;
|
|
|
|
*size = sizeof (codecs);
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipGetImageEncoders [GDIPLUS.@]
|
|
|
|
*/
|
2008-03-06 10:17:00 +01:00
|
|
|
GpStatus WINGDIPAPI GdipGetImageEncoders(UINT numEncoders, UINT size, ImageCodecInfo *encoders)
|
|
|
|
{
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("%u %u %p\n", numEncoders, size, encoders);
|
|
|
|
|
2008-03-06 10:17:00 +01:00
|
|
|
if (!encoders ||
|
|
|
|
(numEncoders != NUM_ENCODERS_SUPPORTED) ||
|
|
|
|
(size != sizeof (codecs)))
|
|
|
|
return GenericError;
|
|
|
|
|
|
|
|
memcpy(encoders, codecs, sizeof (codecs));
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
2008-07-26 19:20:33 +02:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GdipCreateBitmapFromHBITMAP [GDIPLUS.@]
|
|
|
|
*/
|
2008-03-22 00:39:22 +01:00
|
|
|
GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal, GpBitmap** bitmap)
|
|
|
|
{
|
|
|
|
BITMAP bm;
|
|
|
|
GpStatus retval;
|
|
|
|
PixelFormat format;
|
|
|
|
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("%p %p %p\n", hbm, hpal, bitmap);
|
|
|
|
|
2008-03-22 00:39:22 +01:00
|
|
|
if(!hbm || !bitmap)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
/* TODO: Support for device-dependent bitmaps */
|
|
|
|
if(hpal){
|
|
|
|
FIXME("no support for device-dependent bitmaps\n");
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetObjectA(hbm, sizeof(bm), &bm) != sizeof(bm))
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
/* TODO: Figure out the correct format for 16, 32, 64 bpp */
|
|
|
|
switch(bm.bmBitsPixel) {
|
|
|
|
case 1:
|
|
|
|
format = PixelFormat1bppIndexed;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
format = PixelFormat4bppIndexed;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
format = PixelFormat8bppIndexed;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
format = PixelFormat24bppRGB;
|
|
|
|
break;
|
2008-10-04 11:30:09 +02:00
|
|
|
case 32:
|
|
|
|
format = PixelFormat32bppRGB;
|
|
|
|
break;
|
2008-03-22 00:39:22 +01:00
|
|
|
case 48:
|
|
|
|
format = PixelFormat48bppRGB;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("don't know how to handle %d bpp\n", bm.bmBitsPixel);
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, bm.bmWidthBytes,
|
|
|
|
format, bm.bmBits, bitmap);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2008-04-09 22:00:16 +02:00
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipSetEffectParameters [GDIPLUS.@]
|
|
|
|
*/
|
2008-04-09 22:00:16 +02:00
|
|
|
GpStatus WINGDIPAPI GdipSetEffectParameters(CGpEffect *effect,
|
|
|
|
const VOID *params, const UINT size)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
2008-05-09 14:39:43 +02:00
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipGetImageFlags [GDIPLUS.@]
|
|
|
|
*/
|
2008-05-09 14:39:43 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetImageFlags(GpImage *image, UINT *flags)
|
|
|
|
{
|
2008-09-10 22:20:42 +02:00
|
|
|
TRACE("%p %p\n", image, flags);
|
|
|
|
|
2008-05-09 14:39:43 +02:00
|
|
|
if(!image || !flags)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
*flags = image->flags;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
2008-09-06 23:40:26 +02:00
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipTestControl(GpTestControlEnum control, void *param)
|
|
|
|
{
|
|
|
|
TRACE("(%d, %p)\n", control, param);
|
|
|
|
|
|
|
|
switch(control){
|
|
|
|
case TestControlForceBilinear:
|
|
|
|
if(param)
|
|
|
|
FIXME("TestControlForceBilinear not handled\n");
|
|
|
|
break;
|
|
|
|
case TestControlNoICM:
|
|
|
|
if(param)
|
|
|
|
FIXME("TestControlNoICM not handled\n");
|
|
|
|
break;
|
|
|
|
case TestControlGetBuildNumber:
|
|
|
|
*((DWORD*)param) = 3102;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
2008-10-03 12:56:40 +02:00
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipRecordMetafileFileName(GDIPCONST WCHAR* fileName,
|
|
|
|
HDC hdc, EmfType type, GDIPCONST GpRectF *pFrameRect,
|
|
|
|
MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc,
|
|
|
|
GpMetafile **metafile)
|
|
|
|
{
|
|
|
|
FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
|
|
|
|
frameUnit, debugstr_w(desc), metafile);
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipRecordMetafileFileNameI(GDIPCONST WCHAR* fileName, HDC hdc, EmfType type,
|
|
|
|
GDIPCONST GpRect *pFrameRect, MetafileFrameUnit frameUnit,
|
|
|
|
GDIPCONST WCHAR *desc, GpMetafile **metafile)
|
|
|
|
{
|
|
|
|
FIXME("%s %p %d %p %d %s %p stub!\n", debugstr_w(fileName), hdc, type, pFrameRect,
|
|
|
|
frameUnit, debugstr_w(desc), metafile);
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
2008-11-24 10:23:03 +01:00
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipImageForceValidation(GpImage *image)
|
|
|
|
{
|
|
|
|
FIXME("%p\n", image);
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|