2007-07-25 02:19:02 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 Google (Evan Stade)
|
2016-08-18 21:22:02 +02:00
|
|
|
* Copyright (C) 2012,2016 Dmitry Timoshkov
|
2007-07-25 02:19:02 +02:00
|
|
|
*
|
|
|
|
* 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>
|
2012-06-25 13:30:34 +02:00
|
|
|
#include <assert.h>
|
2007-07-25 02:19:21 +02:00
|
|
|
|
2009-02-02 17:15:53 +01:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
|
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"
|
2009-08-31 23:56:47 +02:00
|
|
|
#include "wincodec.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);
|
|
|
|
|
2015-03-06 11:20:33 +01:00
|
|
|
HRESULT WINAPI WICCreateImagingFactory_Proxy(UINT, IWICImagingFactory**);
|
|
|
|
|
2007-08-04 02:30:30 +02:00
|
|
|
#define PIXELFORMATBPP(x) ((x) ? ((x) >> 8) & 255 : 24)
|
2016-08-18 21:22:02 +02:00
|
|
|
#define WMF_PLACEABLE_KEY 0x9ac6cdd7
|
2007-08-04 02:30:30 +02:00
|
|
|
|
2012-07-18 10:26:38 +02:00
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const WICPixelFormatGUID *wic_format;
|
|
|
|
PixelFormat gdip_format;
|
|
|
|
/* predefined palette type to use for pixel format conversions */
|
|
|
|
WICBitmapPaletteType palette_type;
|
|
|
|
} pixel_formats[] =
|
|
|
|
{
|
|
|
|
{ &GUID_WICPixelFormat1bppIndexed, PixelFormat1bppIndexed, WICBitmapPaletteTypeFixedBW },
|
2020-04-29 01:24:46 +02:00
|
|
|
{ &GUID_WICPixelFormatBlackWhite, PixelFormat1bppIndexed, WICBitmapPaletteTypeFixedBW },
|
2018-11-08 14:17:06 +01:00
|
|
|
{ &GUID_WICPixelFormat4bppIndexed, PixelFormat4bppIndexed, WICBitmapPaletteTypeFixedHalftone8 },
|
2012-07-18 10:26:38 +02:00
|
|
|
{ &GUID_WICPixelFormat8bppIndexed, PixelFormat8bppIndexed, WICBitmapPaletteTypeFixedHalftone256 },
|
2020-04-29 01:24:46 +02:00
|
|
|
{ &GUID_WICPixelFormat8bppGray, PixelFormat8bppIndexed, WICBitmapPaletteTypeFixedGray256 },
|
2020-05-15 03:51:09 +02:00
|
|
|
{ &GUID_WICPixelFormat16bppBGR555, PixelFormat16bppRGB555, 0 },
|
|
|
|
{ &GUID_WICPixelFormat24bppBGR, PixelFormat24bppRGB, 0 },
|
|
|
|
{ &GUID_WICPixelFormat32bppBGR, PixelFormat32bppRGB, 0 },
|
|
|
|
{ &GUID_WICPixelFormat32bppBGRA, PixelFormat32bppARGB, 0 },
|
|
|
|
{ &GUID_WICPixelFormat32bppPBGRA, PixelFormat32bppPARGB, 0 },
|
2012-07-18 10:26:38 +02:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static ColorPalette *get_palette(IWICBitmapFrameDecode *frame, WICBitmapPaletteType palette_type)
|
2012-07-18 10:24:58 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IWICImagingFactory *factory;
|
|
|
|
IWICPalette *wic_palette;
|
|
|
|
ColorPalette *palette = NULL;
|
|
|
|
|
2015-03-06 11:20:43 +01:00
|
|
|
hr = WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION, &factory);
|
2012-07-18 10:24:58 +02:00
|
|
|
if (hr != S_OK) return NULL;
|
|
|
|
|
|
|
|
hr = IWICImagingFactory_CreatePalette(factory, &wic_palette);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
2012-07-18 10:28:20 +02:00
|
|
|
hr = WINCODEC_ERR_PALETTEUNAVAILABLE;
|
|
|
|
if (frame)
|
|
|
|
hr = IWICBitmapFrameDecode_CopyPalette(frame, wic_palette);
|
2020-05-15 03:51:09 +02:00
|
|
|
if (hr != S_OK && palette_type != 0)
|
2012-07-18 10:26:38 +02:00
|
|
|
{
|
|
|
|
TRACE("using predefined palette %#x\n", palette_type);
|
|
|
|
hr = IWICPalette_InitializePredefined(wic_palette, palette_type, FALSE);
|
|
|
|
}
|
2012-07-18 10:24:58 +02:00
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
2015-03-13 15:14:37 +01:00
|
|
|
WICBitmapPaletteType type;
|
|
|
|
BOOL alpha;
|
2012-07-18 10:24:58 +02:00
|
|
|
UINT count;
|
|
|
|
|
|
|
|
IWICPalette_GetColorCount(wic_palette, &count);
|
2015-10-21 00:53:12 +02:00
|
|
|
palette = heap_alloc(2 * sizeof(UINT) + count * sizeof(ARGB));
|
2012-07-18 10:24:58 +02:00
|
|
|
IWICPalette_GetColors(wic_palette, count, palette->Entries, &palette->Count);
|
|
|
|
|
2015-03-13 15:14:37 +01:00
|
|
|
IWICPalette_GetType(wic_palette, &type);
|
|
|
|
switch(type) {
|
|
|
|
case WICBitmapPaletteTypeFixedGray4:
|
|
|
|
case WICBitmapPaletteTypeFixedGray16:
|
|
|
|
case WICBitmapPaletteTypeFixedGray256:
|
|
|
|
palette->Flags = PaletteFlagsGrayScale;
|
|
|
|
break;
|
|
|
|
case WICBitmapPaletteTypeFixedHalftone8:
|
|
|
|
case WICBitmapPaletteTypeFixedHalftone27:
|
|
|
|
case WICBitmapPaletteTypeFixedHalftone64:
|
|
|
|
case WICBitmapPaletteTypeFixedHalftone125:
|
|
|
|
case WICBitmapPaletteTypeFixedHalftone216:
|
|
|
|
case WICBitmapPaletteTypeFixedHalftone252:
|
|
|
|
case WICBitmapPaletteTypeFixedHalftone256:
|
|
|
|
palette->Flags = PaletteFlagsHalftone;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
palette->Flags = 0;
|
|
|
|
}
|
|
|
|
IWICPalette_HasAlpha(wic_palette, &alpha);
|
|
|
|
if(alpha)
|
|
|
|
palette->Flags |= PaletteFlagsHasAlpha;
|
2012-07-18 10:24:58 +02:00
|
|
|
}
|
|
|
|
IWICPalette_Release(wic_palette);
|
|
|
|
}
|
|
|
|
IWICImagingFactory_Release(factory);
|
|
|
|
return palette;
|
|
|
|
}
|
|
|
|
|
2020-04-29 01:24:46 +02:00
|
|
|
static HRESULT set_palette(IWICBitmapFrameEncode *frame, ColorPalette *palette)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IWICImagingFactory *factory;
|
|
|
|
IWICPalette *wic_palette;
|
|
|
|
|
|
|
|
hr = WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION, &factory);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = IWICImagingFactory_CreatePalette(factory, &wic_palette);
|
|
|
|
IWICImagingFactory_Release(factory);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IWICPalette_InitializeCustom(wic_palette, palette->Entries, palette->Count);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IWICBitmapFrameEncode_SetPalette(frame, wic_palette);
|
|
|
|
|
|
|
|
IWICPalette_Release(wic_palette);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2009-06-05 06:36:22 +02:00
|
|
|
GpStatus WINGDIPAPI GdipBitmapApplyEffect(GpBitmap* bitmap, CGpEffect* effect,
|
|
|
|
RECT* roi, BOOL useAuxData, VOID** auxData, INT* auxDataSize)
|
|
|
|
{
|
|
|
|
FIXME("(%p %p %p %d %p %p): stub\n", bitmap, effect, roi, useAuxData, auxData, auxDataSize);
|
|
|
|
/*
|
|
|
|
* Note: According to Jose Roca's GDI+ docs, this function is not
|
|
|
|
* implemented in Windows's GDI+.
|
|
|
|
*/
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2009-06-05 06:36:33 +02:00
|
|
|
GpStatus WINGDIPAPI GdipBitmapCreateApplyEffect(GpBitmap** inputBitmaps,
|
|
|
|
INT numInputs, CGpEffect* effect, RECT* roi, RECT* outputRect,
|
|
|
|
GpBitmap** outputBitmap, BOOL useAuxData, VOID** auxData, INT* auxDataSize)
|
|
|
|
{
|
|
|
|
FIXME("(%p %d %p %p %p %p %d %p %p): stub\n", inputBitmaps, numInputs, effect, roi, outputRect, outputBitmap, useAuxData, auxData, auxDataSize);
|
|
|
|
/*
|
|
|
|
* Note: According to Jose Roca's GDI+ docs, this function is not
|
|
|
|
* implemented in Windows's GDI+.
|
|
|
|
*/
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2010-01-31 02:01:52 +01:00
|
|
|
static inline void getpixel_1bppIndexed(BYTE *index, const BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
*index = (row[x/8]>>(7-x%8)) & 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void getpixel_4bppIndexed(BYTE *index, const BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
if (x & 1)
|
|
|
|
*index = row[x/2]&0xf;
|
|
|
|
else
|
|
|
|
*index = row[x/2]>>4;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void getpixel_8bppIndexed(BYTE *index, const BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
*index = row[x];
|
|
|
|
}
|
|
|
|
|
2009-09-23 17:41:13 +02:00
|
|
|
static inline void getpixel_16bppGrayScale(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
|
|
|
|
const BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
*r = *g = *b = row[x*2+1];
|
|
|
|
*a = 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void getpixel_16bppRGB555(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
|
|
|
|
const BYTE *row, UINT x)
|
|
|
|
{
|
2010-03-27 12:58:23 +01:00
|
|
|
WORD pixel = *((const WORD*)(row)+x);
|
2009-09-23 17:41:13 +02:00
|
|
|
*r = (pixel>>7&0xf8)|(pixel>>12&0x7);
|
|
|
|
*g = (pixel>>2&0xf8)|(pixel>>6&0x7);
|
|
|
|
*b = (pixel<<3&0xf8)|(pixel>>2&0x7);
|
|
|
|
*a = 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void getpixel_16bppRGB565(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
|
|
|
|
const BYTE *row, UINT x)
|
|
|
|
{
|
2010-03-27 12:58:23 +01:00
|
|
|
WORD pixel = *((const WORD*)(row)+x);
|
2009-09-23 17:41:13 +02:00
|
|
|
*r = (pixel>>8&0xf8)|(pixel>>13&0x7);
|
|
|
|
*g = (pixel>>3&0xfc)|(pixel>>9&0x3);
|
|
|
|
*b = (pixel<<3&0xf8)|(pixel>>2&0x7);
|
|
|
|
*a = 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void getpixel_16bppARGB1555(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
|
|
|
|
const BYTE *row, UINT x)
|
|
|
|
{
|
2010-03-27 12:58:23 +01:00
|
|
|
WORD pixel = *((const WORD*)(row)+x);
|
2009-09-23 17:41:13 +02:00
|
|
|
*r = (pixel>>7&0xf8)|(pixel>>12&0x7);
|
|
|
|
*g = (pixel>>2&0xf8)|(pixel>>6&0x7);
|
|
|
|
*b = (pixel<<3&0xf8)|(pixel>>2&0x7);
|
|
|
|
if ((pixel&0x8000) == 0x8000)
|
|
|
|
*a = 255;
|
|
|
|
else
|
|
|
|
*a = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void getpixel_24bppRGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
|
|
|
|
const BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
*r = row[x*3+2];
|
|
|
|
*g = row[x*3+1];
|
|
|
|
*b = row[x*3];
|
|
|
|
*a = 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void getpixel_32bppRGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
|
|
|
|
const BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
*r = row[x*4+2];
|
|
|
|
*g = row[x*4+1];
|
|
|
|
*b = row[x*4];
|
|
|
|
*a = 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void getpixel_32bppARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
|
|
|
|
const BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
*r = row[x*4+2];
|
|
|
|
*g = row[x*4+1];
|
|
|
|
*b = row[x*4];
|
|
|
|
*a = row[x*4+3];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void getpixel_32bppPARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
|
|
|
|
const BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
*a = row[x*4+3];
|
|
|
|
if (*a == 0)
|
2020-02-11 00:32:51 +01:00
|
|
|
{
|
|
|
|
*r = row[x*4+2];
|
|
|
|
*g = row[x*4+1];
|
|
|
|
*b = row[x*4];
|
|
|
|
}
|
2009-09-23 17:41:13 +02:00
|
|
|
else
|
|
|
|
{
|
2020-02-11 00:32:51 +01:00
|
|
|
DWORD scaled_q = (255 << 15) / *a;
|
|
|
|
*r = (row[x*4+2] > *a) ? 0xff : (row[x*4+2] * scaled_q) >> 15;
|
|
|
|
*g = (row[x*4+1] > *a) ? 0xff : (row[x*4+1] * scaled_q) >> 15;
|
|
|
|
*b = (row[x*4] > *a) ? 0xff : (row[x*4] * scaled_q) >> 15;
|
2009-09-23 17:41:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void getpixel_48bppRGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
|
|
|
|
const BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
*r = row[x*6+5];
|
|
|
|
*g = row[x*6+3];
|
|
|
|
*b = row[x*6+1];
|
|
|
|
*a = 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void getpixel_64bppARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
|
|
|
|
const BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
*r = row[x*8+5];
|
|
|
|
*g = row[x*8+3];
|
|
|
|
*b = row[x*8+1];
|
|
|
|
*a = row[x*8+7];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void getpixel_64bppPARGB(BYTE *r, BYTE *g, BYTE *b, BYTE *a,
|
|
|
|
const BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
*a = row[x*8+7];
|
|
|
|
if (*a == 0)
|
|
|
|
*r = *g = *b = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*r = row[x*8+5] * 255 / *a;
|
|
|
|
*g = row[x*8+3] * 255 / *a;
|
|
|
|
*b = row[x*8+1] * 255 / *a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-01 04:16:13 +02:00
|
|
|
GpStatus WINGDIPAPI GdipBitmapGetPixel(GpBitmap* bitmap, INT x, INT y,
|
|
|
|
ARGB *color)
|
|
|
|
{
|
2009-09-23 17:41:13 +02:00
|
|
|
BYTE r, g, b, a;
|
2010-01-31 02:01:52 +01:00
|
|
|
BYTE index;
|
2009-09-23 17:41:13 +02:00
|
|
|
BYTE *row;
|
2007-08-01 04:16:13 +02:00
|
|
|
|
2009-09-23 17:41:13 +02:00
|
|
|
if(!bitmap || !color ||
|
|
|
|
x < 0 || y < 0 || x >= bitmap->width || y >= bitmap->height)
|
2007-08-01 04:16:13 +02:00
|
|
|
return InvalidParameter;
|
|
|
|
|
2009-09-23 17:41:13 +02:00
|
|
|
row = bitmap->bits+bitmap->stride*y;
|
2007-08-01 04:16:13 +02:00
|
|
|
|
2009-09-23 17:41:13 +02:00
|
|
|
switch (bitmap->format)
|
|
|
|
{
|
2010-01-31 02:01:52 +01:00
|
|
|
case PixelFormat1bppIndexed:
|
|
|
|
getpixel_1bppIndexed(&index,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat4bppIndexed:
|
|
|
|
getpixel_4bppIndexed(&index,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat8bppIndexed:
|
|
|
|
getpixel_8bppIndexed(&index,row,x);
|
|
|
|
break;
|
2009-09-23 17:41:13 +02:00
|
|
|
case PixelFormat16bppGrayScale:
|
|
|
|
getpixel_16bppGrayScale(&r,&g,&b,&a,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat16bppRGB555:
|
|
|
|
getpixel_16bppRGB555(&r,&g,&b,&a,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat16bppRGB565:
|
|
|
|
getpixel_16bppRGB565(&r,&g,&b,&a,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat16bppARGB1555:
|
|
|
|
getpixel_16bppARGB1555(&r,&g,&b,&a,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat24bppRGB:
|
|
|
|
getpixel_24bppRGB(&r,&g,&b,&a,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat32bppRGB:
|
|
|
|
getpixel_32bppRGB(&r,&g,&b,&a,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat32bppARGB:
|
|
|
|
getpixel_32bppARGB(&r,&g,&b,&a,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat32bppPARGB:
|
|
|
|
getpixel_32bppPARGB(&r,&g,&b,&a,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat48bppRGB:
|
|
|
|
getpixel_48bppRGB(&r,&g,&b,&a,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat64bppARGB:
|
|
|
|
getpixel_64bppARGB(&r,&g,&b,&a,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat64bppPARGB:
|
|
|
|
getpixel_64bppPARGB(&r,&g,&b,&a,row,x);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("not implemented for format 0x%x\n", bitmap->format);
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
2007-08-01 04:16:13 +02:00
|
|
|
|
2010-01-31 02:01:52 +01:00
|
|
|
if (bitmap->format & PixelFormatIndexed)
|
2012-07-17 07:59:43 +02:00
|
|
|
*color = bitmap->image.palette->Entries[index];
|
2010-01-31 02:01:52 +01:00
|
|
|
else
|
|
|
|
*color = a<<24|r<<16|g<<8|b;
|
2009-09-23 17:41:13 +02:00
|
|
|
|
|
|
|
return Ok;
|
2007-08-01 04:16:13 +02:00
|
|
|
}
|
|
|
|
|
2020-05-27 23:55:18 +02:00
|
|
|
static unsigned int absdiff(unsigned int x, unsigned int y)
|
|
|
|
{
|
|
|
|
return x > y ? x - y : y - x;
|
|
|
|
}
|
|
|
|
|
2012-07-17 08:01:16 +02:00
|
|
|
static inline UINT get_palette_index(BYTE r, BYTE g, BYTE b, BYTE a, ColorPalette *palette)
|
|
|
|
{
|
2011-01-12 04:34:47 +01:00
|
|
|
BYTE index = 0;
|
|
|
|
int best_distance = 0x7fff;
|
|
|
|
int distance;
|
2013-01-23 22:42:47 +01:00
|
|
|
UINT i;
|
2012-07-17 08:01:16 +02:00
|
|
|
|
|
|
|
if (!palette) return 0;
|
2011-07-27 13:38:43 +02:00
|
|
|
/* This algorithm scans entire palette,
|
2011-01-12 04:34:47 +01:00
|
|
|
computes difference from desired color (all color components have equal weight)
|
|
|
|
and returns the index of color with least difference.
|
|
|
|
|
|
|
|
Note: Maybe it could be replaced with a better algorithm for better image quality
|
|
|
|
and performance, though better algorithm would probably need some pre-built lookup
|
|
|
|
tables and thus may actually be slower if this method is called only few times per
|
|
|
|
every image.
|
|
|
|
*/
|
2012-07-17 08:01:16 +02:00
|
|
|
for(i=0;i<palette->Count;i++) {
|
|
|
|
ARGB color=palette->Entries[i];
|
2020-05-27 23:55:18 +02:00
|
|
|
distance=absdiff(b, color & 0xff) + absdiff(g, color>>8 & 0xff) + absdiff(r, color>>16 & 0xff) + absdiff(a, color>>24 & 0xff);
|
2011-01-12 04:34:47 +01:00
|
|
|
if (distance<best_distance) {
|
|
|
|
best_distance=distance;
|
|
|
|
index=i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void setpixel_8bppIndexed(BYTE r, BYTE g, BYTE b, BYTE a,
|
2012-07-17 08:01:16 +02:00
|
|
|
BYTE *row, UINT x, ColorPalette *palette)
|
2011-01-12 04:34:47 +01:00
|
|
|
{
|
2012-07-17 08:01:16 +02:00
|
|
|
BYTE index = get_palette_index(r,g,b,a,palette);
|
2011-01-12 04:34:47 +01:00
|
|
|
row[x]=index;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void setpixel_1bppIndexed(BYTE r, BYTE g, BYTE b, BYTE a,
|
2012-07-17 08:01:16 +02:00
|
|
|
BYTE *row, UINT x, ColorPalette *palette)
|
2011-01-12 04:34:47 +01:00
|
|
|
{
|
2012-07-17 08:01:16 +02:00
|
|
|
row[x/8] = (row[x/8] & ~(1<<(7-x%8))) | (get_palette_index(r,g,b,a,palette)<<(7-x%8));
|
2011-01-12 04:34:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void setpixel_4bppIndexed(BYTE r, BYTE g, BYTE b, BYTE a,
|
2012-07-17 08:01:16 +02:00
|
|
|
BYTE *row, UINT x, ColorPalette *palette)
|
2011-01-12 04:34:47 +01:00
|
|
|
{
|
|
|
|
if (x & 1)
|
2012-07-17 08:01:16 +02:00
|
|
|
row[x/2] = (row[x/2] & 0xf0) | get_palette_index(r,g,b,a,palette);
|
2011-01-12 04:34:47 +01:00
|
|
|
else
|
2012-07-17 08:01:16 +02:00
|
|
|
row[x/2] = (row[x/2] & 0x0f) | get_palette_index(r,g,b,a,palette)<<4;
|
2011-01-12 04:34:47 +01:00
|
|
|
}
|
|
|
|
|
2009-09-23 18:22:39 +02:00
|
|
|
static inline void setpixel_16bppGrayScale(BYTE r, BYTE g, BYTE b, BYTE a,
|
|
|
|
BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
*((WORD*)(row)+x) = (r+g+b)*85;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void setpixel_16bppRGB555(BYTE r, BYTE g, BYTE b, BYTE a,
|
|
|
|
BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
*((WORD*)(row)+x) = (r<<7&0x7c00)|
|
|
|
|
(g<<2&0x03e0)|
|
|
|
|
(b>>3&0x001f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void setpixel_16bppRGB565(BYTE r, BYTE g, BYTE b, BYTE a,
|
|
|
|
BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
*((WORD*)(row)+x) = (r<<8&0xf800)|
|
|
|
|
(g<<3&0x07e0)|
|
|
|
|
(b>>3&0x001f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void setpixel_16bppARGB1555(BYTE r, BYTE g, BYTE b, BYTE a,
|
|
|
|
BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
*((WORD*)(row)+x) = (a<<8&0x8000)|
|
|
|
|
(r<<7&0x7c00)|
|
|
|
|
(g<<2&0x03e0)|
|
|
|
|
(b>>3&0x001f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void setpixel_24bppRGB(BYTE r, BYTE g, BYTE b, BYTE a,
|
|
|
|
BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
row[x*3+2] = r;
|
|
|
|
row[x*3+1] = g;
|
|
|
|
row[x*3] = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void setpixel_32bppRGB(BYTE r, BYTE g, BYTE b, BYTE a,
|
|
|
|
BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
*((DWORD*)(row)+x) = (r<<16)|(g<<8)|b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void setpixel_32bppARGB(BYTE r, BYTE g, BYTE b, BYTE a,
|
|
|
|
BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
*((DWORD*)(row)+x) = (a<<24)|(r<<16)|(g<<8)|b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void setpixel_32bppPARGB(BYTE r, BYTE g, BYTE b, BYTE a,
|
|
|
|
BYTE *row, UINT x)
|
|
|
|
{
|
2020-02-11 00:32:52 +01:00
|
|
|
r = (r * a + 127) / 255;
|
|
|
|
g = (g * a + 127) / 255;
|
|
|
|
b = (b * a + 127) / 255;
|
2009-09-23 18:22:39 +02:00
|
|
|
*((DWORD*)(row)+x) = (a<<24)|(r<<16)|(g<<8)|b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void setpixel_48bppRGB(BYTE r, BYTE g, BYTE b, BYTE a,
|
|
|
|
BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
row[x*6+5] = row[x*6+4] = r;
|
|
|
|
row[x*6+3] = row[x*6+2] = g;
|
|
|
|
row[x*6+1] = row[x*6] = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void setpixel_64bppARGB(BYTE r, BYTE g, BYTE b, BYTE a,
|
|
|
|
BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
UINT64 a64=a, r64=r, g64=g, b64=b;
|
|
|
|
*((UINT64*)(row)+x) = (a64<<56)|(a64<<48)|(r64<<40)|(r64<<32)|(g64<<24)|(g64<<16)|(b64<<8)|b64;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void setpixel_64bppPARGB(BYTE r, BYTE g, BYTE b, BYTE a,
|
|
|
|
BYTE *row, UINT x)
|
|
|
|
{
|
|
|
|
UINT64 a64, r64, g64, b64;
|
|
|
|
a64 = a * 257;
|
|
|
|
r64 = r * a / 255;
|
|
|
|
g64 = g * a / 255;
|
|
|
|
b64 = b * a / 255;
|
|
|
|
*((UINT64*)(row)+x) = (a64<<48)|(r64<<32)|(g64<<16)|b64;
|
|
|
|
}
|
|
|
|
|
2009-04-27 23:20:27 +02:00
|
|
|
GpStatus WINGDIPAPI GdipBitmapSetPixel(GpBitmap* bitmap, INT x, INT y,
|
|
|
|
ARGB color)
|
|
|
|
{
|
2009-09-23 18:22:39 +02:00
|
|
|
BYTE a, r, g, b;
|
|
|
|
BYTE *row;
|
2009-04-27 23:20:27 +02:00
|
|
|
|
2009-09-23 18:22:39 +02:00
|
|
|
if(!bitmap || x < 0 || y < 0 || x >= bitmap->width || y >= bitmap->height)
|
2009-04-27 23:20:27 +02:00
|
|
|
return InvalidParameter;
|
|
|
|
|
2009-09-23 18:22:39 +02:00
|
|
|
a = color>>24;
|
|
|
|
r = color>>16;
|
|
|
|
g = color>>8;
|
|
|
|
b = color;
|
2009-04-27 23:20:27 +02:00
|
|
|
|
2009-09-23 18:22:39 +02:00
|
|
|
row = bitmap->bits + bitmap->stride * y;
|
|
|
|
|
|
|
|
switch (bitmap->format)
|
|
|
|
{
|
|
|
|
case PixelFormat16bppGrayScale:
|
|
|
|
setpixel_16bppGrayScale(r,g,b,a,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat16bppRGB555:
|
|
|
|
setpixel_16bppRGB555(r,g,b,a,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat16bppRGB565:
|
|
|
|
setpixel_16bppRGB565(r,g,b,a,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat16bppARGB1555:
|
|
|
|
setpixel_16bppARGB1555(r,g,b,a,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat24bppRGB:
|
|
|
|
setpixel_24bppRGB(r,g,b,a,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat32bppRGB:
|
|
|
|
setpixel_32bppRGB(r,g,b,a,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat32bppARGB:
|
|
|
|
setpixel_32bppARGB(r,g,b,a,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat32bppPARGB:
|
|
|
|
setpixel_32bppPARGB(r,g,b,a,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat48bppRGB:
|
|
|
|
setpixel_48bppRGB(r,g,b,a,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat64bppARGB:
|
|
|
|
setpixel_64bppARGB(r,g,b,a,row,x);
|
|
|
|
break;
|
|
|
|
case PixelFormat64bppPARGB:
|
|
|
|
setpixel_64bppPARGB(r,g,b,a,row,x);
|
|
|
|
break;
|
2011-01-12 04:34:47 +01:00
|
|
|
case PixelFormat8bppIndexed:
|
2012-07-17 08:01:16 +02:00
|
|
|
setpixel_8bppIndexed(r,g,b,a,row,x,bitmap->image.palette);
|
2011-01-12 04:34:47 +01:00
|
|
|
break;
|
|
|
|
case PixelFormat4bppIndexed:
|
2012-07-17 08:01:16 +02:00
|
|
|
setpixel_4bppIndexed(r,g,b,a,row,x,bitmap->image.palette);
|
2011-01-12 04:34:47 +01:00
|
|
|
break;
|
|
|
|
case PixelFormat1bppIndexed:
|
2012-07-17 08:01:16 +02:00
|
|
|
setpixel_1bppIndexed(r,g,b,a,row,x,bitmap->image.palette);
|
2011-01-12 04:34:47 +01:00
|
|
|
break;
|
2009-09-23 18:22:39 +02:00
|
|
|
default:
|
|
|
|
FIXME("not implemented for format 0x%x\n", bitmap->format);
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok;
|
2009-04-27 23:20:27 +02:00
|
|
|
}
|
|
|
|
|
2011-03-10 14:09:56 +01:00
|
|
|
GpStatus convert_pixels(INT width, INT height,
|
2010-02-05 02:05:54 +01:00
|
|
|
INT dst_stride, BYTE *dst_bits, PixelFormat dst_format,
|
2012-07-17 08:00:21 +02:00
|
|
|
INT src_stride, const BYTE *src_bits, PixelFormat src_format,
|
|
|
|
ColorPalette *palette)
|
2010-02-05 02:05:54 +01:00
|
|
|
{
|
2011-03-10 14:09:56 +01:00
|
|
|
INT x, y;
|
2010-02-05 02:05:54 +01:00
|
|
|
|
|
|
|
if (src_format == dst_format ||
|
|
|
|
(dst_format == PixelFormat32bppRGB && PIXELFORMATBPP(src_format) == 32))
|
|
|
|
{
|
|
|
|
UINT widthbytes = PIXELFORMATBPP(src_format) * width / 8;
|
|
|
|
for (y=0; y<height; y++)
|
|
|
|
memcpy(dst_bits+dst_stride*y, src_bits+src_stride*y, widthbytes);
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define convert_indexed_to_rgb(getpixel_function, setpixel_function) do { \
|
2014-09-18 20:22:14 +02:00
|
|
|
for (y=0; y<height; y++) \
|
|
|
|
for (x=0; x<width; x++) { \
|
2010-02-05 02:05:54 +01:00
|
|
|
BYTE index; \
|
2012-07-17 08:00:21 +02:00
|
|
|
ARGB argb; \
|
|
|
|
BYTE *color = (BYTE *)&argb; \
|
2010-02-05 02:05:54 +01:00
|
|
|
getpixel_function(&index, src_bits+src_stride*y, x); \
|
2012-07-17 08:00:21 +02:00
|
|
|
argb = (palette && index < palette->Count) ? palette->Entries[index] : 0; \
|
2010-02-05 02:05:54 +01:00
|
|
|
setpixel_function(color[2], color[1], color[0], color[3], dst_bits+dst_stride*y, x); \
|
|
|
|
} \
|
|
|
|
return Ok; \
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
#define convert_rgb_to_rgb(getpixel_function, setpixel_function) do { \
|
2014-09-18 20:22:14 +02:00
|
|
|
for (y=0; y<height; y++) \
|
|
|
|
for (x=0; x<width; x++) { \
|
2010-02-05 02:05:54 +01:00
|
|
|
BYTE r, g, b, a; \
|
|
|
|
getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \
|
|
|
|
setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x); \
|
|
|
|
} \
|
|
|
|
return Ok; \
|
|
|
|
} while (0);
|
|
|
|
|
2012-07-17 08:01:51 +02:00
|
|
|
#define convert_rgb_to_indexed(getpixel_function, setpixel_function) do { \
|
2014-09-18 20:22:14 +02:00
|
|
|
for (y=0; y<height; y++) \
|
|
|
|
for (x=0; x<width; x++) { \
|
2012-07-17 08:01:51 +02:00
|
|
|
BYTE r, g, b, a; \
|
|
|
|
getpixel_function(&r, &g, &b, &a, src_bits+src_stride*y, x); \
|
|
|
|
setpixel_function(r, g, b, a, dst_bits+dst_stride*y, x, palette); \
|
|
|
|
} \
|
|
|
|
return Ok; \
|
|
|
|
} while (0);
|
|
|
|
|
2010-02-05 02:05:54 +01:00
|
|
|
switch (src_format)
|
|
|
|
{
|
|
|
|
case PixelFormat1bppIndexed:
|
|
|
|
switch (dst_format)
|
|
|
|
{
|
|
|
|
case PixelFormat16bppGrayScale:
|
|
|
|
convert_indexed_to_rgb(getpixel_1bppIndexed, setpixel_16bppGrayScale);
|
|
|
|
case PixelFormat16bppRGB555:
|
|
|
|
convert_indexed_to_rgb(getpixel_1bppIndexed, setpixel_16bppRGB555);
|
|
|
|
case PixelFormat16bppRGB565:
|
|
|
|
convert_indexed_to_rgb(getpixel_1bppIndexed, setpixel_16bppRGB565);
|
|
|
|
case PixelFormat16bppARGB1555:
|
|
|
|
convert_indexed_to_rgb(getpixel_1bppIndexed, setpixel_16bppARGB1555);
|
|
|
|
case PixelFormat24bppRGB:
|
|
|
|
convert_indexed_to_rgb(getpixel_1bppIndexed, setpixel_24bppRGB);
|
|
|
|
case PixelFormat32bppRGB:
|
|
|
|
convert_indexed_to_rgb(getpixel_1bppIndexed, setpixel_32bppRGB);
|
|
|
|
case PixelFormat32bppARGB:
|
|
|
|
convert_indexed_to_rgb(getpixel_1bppIndexed, setpixel_32bppARGB);
|
|
|
|
case PixelFormat32bppPARGB:
|
|
|
|
convert_indexed_to_rgb(getpixel_1bppIndexed, setpixel_32bppPARGB);
|
|
|
|
case PixelFormat48bppRGB:
|
|
|
|
convert_indexed_to_rgb(getpixel_1bppIndexed, setpixel_48bppRGB);
|
|
|
|
case PixelFormat64bppARGB:
|
|
|
|
convert_indexed_to_rgb(getpixel_1bppIndexed, setpixel_64bppARGB);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PixelFormat4bppIndexed:
|
|
|
|
switch (dst_format)
|
|
|
|
{
|
|
|
|
case PixelFormat16bppGrayScale:
|
|
|
|
convert_indexed_to_rgb(getpixel_4bppIndexed, setpixel_16bppGrayScale);
|
|
|
|
case PixelFormat16bppRGB555:
|
|
|
|
convert_indexed_to_rgb(getpixel_4bppIndexed, setpixel_16bppRGB555);
|
|
|
|
case PixelFormat16bppRGB565:
|
|
|
|
convert_indexed_to_rgb(getpixel_4bppIndexed, setpixel_16bppRGB565);
|
|
|
|
case PixelFormat16bppARGB1555:
|
|
|
|
convert_indexed_to_rgb(getpixel_4bppIndexed, setpixel_16bppARGB1555);
|
|
|
|
case PixelFormat24bppRGB:
|
|
|
|
convert_indexed_to_rgb(getpixel_4bppIndexed, setpixel_24bppRGB);
|
|
|
|
case PixelFormat32bppRGB:
|
|
|
|
convert_indexed_to_rgb(getpixel_4bppIndexed, setpixel_32bppRGB);
|
|
|
|
case PixelFormat32bppARGB:
|
|
|
|
convert_indexed_to_rgb(getpixel_4bppIndexed, setpixel_32bppARGB);
|
|
|
|
case PixelFormat32bppPARGB:
|
|
|
|
convert_indexed_to_rgb(getpixel_4bppIndexed, setpixel_32bppPARGB);
|
|
|
|
case PixelFormat48bppRGB:
|
|
|
|
convert_indexed_to_rgb(getpixel_4bppIndexed, setpixel_48bppRGB);
|
|
|
|
case PixelFormat64bppARGB:
|
|
|
|
convert_indexed_to_rgb(getpixel_4bppIndexed, setpixel_64bppARGB);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PixelFormat8bppIndexed:
|
|
|
|
switch (dst_format)
|
|
|
|
{
|
|
|
|
case PixelFormat16bppGrayScale:
|
|
|
|
convert_indexed_to_rgb(getpixel_8bppIndexed, setpixel_16bppGrayScale);
|
|
|
|
case PixelFormat16bppRGB555:
|
|
|
|
convert_indexed_to_rgb(getpixel_8bppIndexed, setpixel_16bppRGB555);
|
|
|
|
case PixelFormat16bppRGB565:
|
|
|
|
convert_indexed_to_rgb(getpixel_8bppIndexed, setpixel_16bppRGB565);
|
|
|
|
case PixelFormat16bppARGB1555:
|
|
|
|
convert_indexed_to_rgb(getpixel_8bppIndexed, setpixel_16bppARGB1555);
|
|
|
|
case PixelFormat24bppRGB:
|
|
|
|
convert_indexed_to_rgb(getpixel_8bppIndexed, setpixel_24bppRGB);
|
|
|
|
case PixelFormat32bppRGB:
|
|
|
|
convert_indexed_to_rgb(getpixel_8bppIndexed, setpixel_32bppRGB);
|
|
|
|
case PixelFormat32bppARGB:
|
|
|
|
convert_indexed_to_rgb(getpixel_8bppIndexed, setpixel_32bppARGB);
|
|
|
|
case PixelFormat32bppPARGB:
|
|
|
|
convert_indexed_to_rgb(getpixel_8bppIndexed, setpixel_32bppPARGB);
|
|
|
|
case PixelFormat48bppRGB:
|
|
|
|
convert_indexed_to_rgb(getpixel_8bppIndexed, setpixel_48bppRGB);
|
|
|
|
case PixelFormat64bppARGB:
|
|
|
|
convert_indexed_to_rgb(getpixel_8bppIndexed, setpixel_64bppARGB);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PixelFormat16bppGrayScale:
|
|
|
|
switch (dst_format)
|
|
|
|
{
|
2012-07-17 08:02:31 +02:00
|
|
|
case PixelFormat1bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_16bppGrayScale, setpixel_1bppIndexed);
|
2012-07-17 08:01:51 +02:00
|
|
|
case PixelFormat8bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_16bppGrayScale, setpixel_8bppIndexed);
|
2010-02-05 02:05:54 +01:00
|
|
|
case PixelFormat16bppRGB555:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppGrayScale, setpixel_16bppRGB555);
|
|
|
|
case PixelFormat16bppRGB565:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppGrayScale, setpixel_16bppRGB565);
|
|
|
|
case PixelFormat16bppARGB1555:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppGrayScale, setpixel_16bppARGB1555);
|
|
|
|
case PixelFormat24bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppGrayScale, setpixel_24bppRGB);
|
|
|
|
case PixelFormat32bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppGrayScale, setpixel_32bppRGB);
|
|
|
|
case PixelFormat32bppARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppGrayScale, setpixel_32bppARGB);
|
|
|
|
case PixelFormat32bppPARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppGrayScale, setpixel_32bppPARGB);
|
|
|
|
case PixelFormat48bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppGrayScale, setpixel_48bppRGB);
|
|
|
|
case PixelFormat64bppARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppGrayScale, setpixel_64bppARGB);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PixelFormat16bppRGB555:
|
|
|
|
switch (dst_format)
|
|
|
|
{
|
2012-07-17 08:02:31 +02:00
|
|
|
case PixelFormat1bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_16bppRGB555, setpixel_1bppIndexed);
|
2012-07-17 08:01:51 +02:00
|
|
|
case PixelFormat8bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_16bppRGB555, setpixel_8bppIndexed);
|
2010-02-05 02:05:54 +01:00
|
|
|
case PixelFormat16bppGrayScale:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppRGB555, setpixel_16bppGrayScale);
|
|
|
|
case PixelFormat16bppRGB565:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppRGB555, setpixel_16bppRGB565);
|
|
|
|
case PixelFormat16bppARGB1555:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppRGB555, setpixel_16bppARGB1555);
|
|
|
|
case PixelFormat24bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppRGB555, setpixel_24bppRGB);
|
|
|
|
case PixelFormat32bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppRGB555, setpixel_32bppRGB);
|
|
|
|
case PixelFormat32bppARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppRGB555, setpixel_32bppARGB);
|
|
|
|
case PixelFormat32bppPARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppRGB555, setpixel_32bppPARGB);
|
|
|
|
case PixelFormat48bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppRGB555, setpixel_48bppRGB);
|
|
|
|
case PixelFormat64bppARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppRGB555, setpixel_64bppARGB);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PixelFormat16bppRGB565:
|
|
|
|
switch (dst_format)
|
|
|
|
{
|
2012-07-17 08:02:31 +02:00
|
|
|
case PixelFormat1bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_16bppRGB565, setpixel_1bppIndexed);
|
2012-07-17 08:01:51 +02:00
|
|
|
case PixelFormat8bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_16bppRGB565, setpixel_8bppIndexed);
|
2010-02-05 02:05:54 +01:00
|
|
|
case PixelFormat16bppGrayScale:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppRGB565, setpixel_16bppGrayScale);
|
|
|
|
case PixelFormat16bppRGB555:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppRGB565, setpixel_16bppRGB555);
|
|
|
|
case PixelFormat16bppARGB1555:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppRGB565, setpixel_16bppARGB1555);
|
|
|
|
case PixelFormat24bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppRGB565, setpixel_24bppRGB);
|
|
|
|
case PixelFormat32bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppRGB565, setpixel_32bppRGB);
|
|
|
|
case PixelFormat32bppARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppRGB565, setpixel_32bppARGB);
|
|
|
|
case PixelFormat32bppPARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppRGB565, setpixel_32bppPARGB);
|
|
|
|
case PixelFormat48bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppRGB565, setpixel_48bppRGB);
|
|
|
|
case PixelFormat64bppARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppRGB565, setpixel_64bppARGB);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PixelFormat16bppARGB1555:
|
|
|
|
switch (dst_format)
|
|
|
|
{
|
2012-07-17 08:02:31 +02:00
|
|
|
case PixelFormat1bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_16bppARGB1555, setpixel_1bppIndexed);
|
2012-07-17 08:01:51 +02:00
|
|
|
case PixelFormat8bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_16bppARGB1555, setpixel_8bppIndexed);
|
2010-02-05 02:05:54 +01:00
|
|
|
case PixelFormat16bppGrayScale:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppARGB1555, setpixel_16bppGrayScale);
|
|
|
|
case PixelFormat16bppRGB555:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppARGB1555, setpixel_16bppRGB555);
|
|
|
|
case PixelFormat16bppRGB565:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppARGB1555, setpixel_16bppRGB565);
|
|
|
|
case PixelFormat24bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppARGB1555, setpixel_24bppRGB);
|
|
|
|
case PixelFormat32bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppARGB1555, setpixel_32bppRGB);
|
|
|
|
case PixelFormat32bppARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppARGB1555, setpixel_32bppARGB);
|
|
|
|
case PixelFormat32bppPARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppARGB1555, setpixel_32bppPARGB);
|
|
|
|
case PixelFormat48bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppARGB1555, setpixel_48bppRGB);
|
|
|
|
case PixelFormat64bppARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_16bppARGB1555, setpixel_64bppARGB);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PixelFormat24bppRGB:
|
|
|
|
switch (dst_format)
|
|
|
|
{
|
2012-07-17 08:02:31 +02:00
|
|
|
case PixelFormat1bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_24bppRGB, setpixel_1bppIndexed);
|
2012-07-17 08:01:51 +02:00
|
|
|
case PixelFormat8bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_24bppRGB, setpixel_8bppIndexed);
|
2010-02-05 02:05:54 +01:00
|
|
|
case PixelFormat16bppGrayScale:
|
|
|
|
convert_rgb_to_rgb(getpixel_24bppRGB, setpixel_16bppGrayScale);
|
|
|
|
case PixelFormat16bppRGB555:
|
|
|
|
convert_rgb_to_rgb(getpixel_24bppRGB, setpixel_16bppRGB555);
|
|
|
|
case PixelFormat16bppRGB565:
|
|
|
|
convert_rgb_to_rgb(getpixel_24bppRGB, setpixel_16bppRGB565);
|
|
|
|
case PixelFormat16bppARGB1555:
|
|
|
|
convert_rgb_to_rgb(getpixel_24bppRGB, setpixel_16bppARGB1555);
|
|
|
|
case PixelFormat32bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_24bppRGB, setpixel_32bppRGB);
|
|
|
|
case PixelFormat32bppARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_24bppRGB, setpixel_32bppARGB);
|
|
|
|
case PixelFormat32bppPARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_24bppRGB, setpixel_32bppPARGB);
|
|
|
|
case PixelFormat48bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_24bppRGB, setpixel_48bppRGB);
|
|
|
|
case PixelFormat64bppARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_24bppRGB, setpixel_64bppARGB);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PixelFormat32bppRGB:
|
|
|
|
switch (dst_format)
|
|
|
|
{
|
2012-07-17 08:02:31 +02:00
|
|
|
case PixelFormat1bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_32bppRGB, setpixel_1bppIndexed);
|
2012-07-17 08:01:51 +02:00
|
|
|
case PixelFormat8bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_32bppRGB, setpixel_8bppIndexed);
|
2010-02-05 02:05:54 +01:00
|
|
|
case PixelFormat16bppGrayScale:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppRGB, setpixel_16bppGrayScale);
|
|
|
|
case PixelFormat16bppRGB555:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppRGB, setpixel_16bppRGB555);
|
|
|
|
case PixelFormat16bppRGB565:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppRGB, setpixel_16bppRGB565);
|
|
|
|
case PixelFormat16bppARGB1555:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppRGB, setpixel_16bppARGB1555);
|
|
|
|
case PixelFormat24bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppRGB, setpixel_24bppRGB);
|
|
|
|
case PixelFormat32bppARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppRGB, setpixel_32bppARGB);
|
|
|
|
case PixelFormat32bppPARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppRGB, setpixel_32bppPARGB);
|
|
|
|
case PixelFormat48bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppRGB, setpixel_48bppRGB);
|
|
|
|
case PixelFormat64bppARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppRGB, setpixel_64bppARGB);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PixelFormat32bppARGB:
|
|
|
|
switch (dst_format)
|
|
|
|
{
|
2012-07-17 08:02:31 +02:00
|
|
|
case PixelFormat1bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_32bppARGB, setpixel_1bppIndexed);
|
2012-07-17 08:01:51 +02:00
|
|
|
case PixelFormat8bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_32bppARGB, setpixel_8bppIndexed);
|
2010-02-05 02:05:54 +01:00
|
|
|
case PixelFormat16bppGrayScale:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppARGB, setpixel_16bppGrayScale);
|
|
|
|
case PixelFormat16bppRGB555:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppARGB, setpixel_16bppRGB555);
|
|
|
|
case PixelFormat16bppRGB565:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppARGB, setpixel_16bppRGB565);
|
|
|
|
case PixelFormat16bppARGB1555:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppARGB, setpixel_16bppARGB1555);
|
|
|
|
case PixelFormat24bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppARGB, setpixel_24bppRGB);
|
|
|
|
case PixelFormat32bppPARGB:
|
|
|
|
convert_32bppARGB_to_32bppPARGB(width, height, dst_bits, dst_stride, src_bits, src_stride);
|
|
|
|
return Ok;
|
|
|
|
case PixelFormat48bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppARGB, setpixel_48bppRGB);
|
|
|
|
case PixelFormat64bppARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppARGB, setpixel_64bppARGB);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PixelFormat32bppPARGB:
|
|
|
|
switch (dst_format)
|
|
|
|
{
|
2012-07-17 08:02:31 +02:00
|
|
|
case PixelFormat1bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_32bppPARGB, setpixel_1bppIndexed);
|
2012-07-17 08:01:51 +02:00
|
|
|
case PixelFormat8bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_32bppPARGB, setpixel_8bppIndexed);
|
2010-02-05 02:05:54 +01:00
|
|
|
case PixelFormat16bppGrayScale:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppPARGB, setpixel_16bppGrayScale);
|
|
|
|
case PixelFormat16bppRGB555:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppPARGB, setpixel_16bppRGB555);
|
|
|
|
case PixelFormat16bppRGB565:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppPARGB, setpixel_16bppRGB565);
|
|
|
|
case PixelFormat16bppARGB1555:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppPARGB, setpixel_16bppARGB1555);
|
|
|
|
case PixelFormat24bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppPARGB, setpixel_24bppRGB);
|
|
|
|
case PixelFormat32bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppPARGB, setpixel_32bppRGB);
|
|
|
|
case PixelFormat32bppARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppPARGB, setpixel_32bppARGB);
|
|
|
|
case PixelFormat48bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppPARGB, setpixel_48bppRGB);
|
|
|
|
case PixelFormat64bppARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_32bppPARGB, setpixel_64bppARGB);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PixelFormat48bppRGB:
|
|
|
|
switch (dst_format)
|
|
|
|
{
|
2012-07-17 08:02:31 +02:00
|
|
|
case PixelFormat1bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_48bppRGB, setpixel_1bppIndexed);
|
2012-07-17 08:01:51 +02:00
|
|
|
case PixelFormat8bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_48bppRGB, setpixel_8bppIndexed);
|
2010-02-05 02:05:54 +01:00
|
|
|
case PixelFormat16bppGrayScale:
|
|
|
|
convert_rgb_to_rgb(getpixel_48bppRGB, setpixel_16bppGrayScale);
|
|
|
|
case PixelFormat16bppRGB555:
|
|
|
|
convert_rgb_to_rgb(getpixel_48bppRGB, setpixel_16bppRGB555);
|
|
|
|
case PixelFormat16bppRGB565:
|
|
|
|
convert_rgb_to_rgb(getpixel_48bppRGB, setpixel_16bppRGB565);
|
|
|
|
case PixelFormat16bppARGB1555:
|
|
|
|
convert_rgb_to_rgb(getpixel_48bppRGB, setpixel_16bppARGB1555);
|
|
|
|
case PixelFormat24bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_48bppRGB, setpixel_24bppRGB);
|
|
|
|
case PixelFormat32bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_48bppRGB, setpixel_32bppRGB);
|
|
|
|
case PixelFormat32bppARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_48bppRGB, setpixel_32bppARGB);
|
|
|
|
case PixelFormat32bppPARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_48bppRGB, setpixel_32bppPARGB);
|
|
|
|
case PixelFormat64bppARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_48bppRGB, setpixel_64bppARGB);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PixelFormat64bppARGB:
|
|
|
|
switch (dst_format)
|
|
|
|
{
|
2012-07-17 08:02:31 +02:00
|
|
|
case PixelFormat1bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_64bppARGB, setpixel_1bppIndexed);
|
2012-07-17 08:01:51 +02:00
|
|
|
case PixelFormat8bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_64bppARGB, setpixel_8bppIndexed);
|
2010-02-05 02:05:54 +01:00
|
|
|
case PixelFormat16bppGrayScale:
|
|
|
|
convert_rgb_to_rgb(getpixel_64bppARGB, setpixel_16bppGrayScale);
|
|
|
|
case PixelFormat16bppRGB555:
|
|
|
|
convert_rgb_to_rgb(getpixel_64bppARGB, setpixel_16bppRGB555);
|
|
|
|
case PixelFormat16bppRGB565:
|
|
|
|
convert_rgb_to_rgb(getpixel_64bppARGB, setpixel_16bppRGB565);
|
|
|
|
case PixelFormat16bppARGB1555:
|
|
|
|
convert_rgb_to_rgb(getpixel_64bppARGB, setpixel_16bppARGB1555);
|
|
|
|
case PixelFormat24bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_64bppARGB, setpixel_24bppRGB);
|
|
|
|
case PixelFormat32bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_64bppARGB, setpixel_32bppRGB);
|
|
|
|
case PixelFormat32bppARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_64bppARGB, setpixel_32bppARGB);
|
|
|
|
case PixelFormat32bppPARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_64bppARGB, setpixel_32bppPARGB);
|
|
|
|
case PixelFormat48bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_64bppARGB, setpixel_48bppRGB);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PixelFormat64bppPARGB:
|
|
|
|
switch (dst_format)
|
|
|
|
{
|
2012-07-17 08:02:31 +02:00
|
|
|
case PixelFormat1bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_64bppPARGB, setpixel_1bppIndexed);
|
2012-07-17 08:01:51 +02:00
|
|
|
case PixelFormat8bppIndexed:
|
|
|
|
convert_rgb_to_indexed(getpixel_64bppPARGB, setpixel_8bppIndexed);
|
2010-02-05 02:05:54 +01:00
|
|
|
case PixelFormat16bppGrayScale:
|
|
|
|
convert_rgb_to_rgb(getpixel_64bppPARGB, setpixel_16bppGrayScale);
|
|
|
|
case PixelFormat16bppRGB555:
|
|
|
|
convert_rgb_to_rgb(getpixel_64bppPARGB, setpixel_16bppRGB555);
|
|
|
|
case PixelFormat16bppRGB565:
|
|
|
|
convert_rgb_to_rgb(getpixel_64bppPARGB, setpixel_16bppRGB565);
|
|
|
|
case PixelFormat16bppARGB1555:
|
|
|
|
convert_rgb_to_rgb(getpixel_64bppPARGB, setpixel_16bppARGB1555);
|
|
|
|
case PixelFormat24bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_64bppPARGB, setpixel_24bppRGB);
|
|
|
|
case PixelFormat32bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_64bppPARGB, setpixel_32bppRGB);
|
|
|
|
case PixelFormat32bppARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_64bppPARGB, setpixel_32bppARGB);
|
|
|
|
case PixelFormat32bppPARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_64bppPARGB, setpixel_32bppPARGB);
|
|
|
|
case PixelFormat48bppRGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_64bppPARGB, setpixel_48bppRGB);
|
|
|
|
case PixelFormat64bppARGB:
|
|
|
|
convert_rgb_to_rgb(getpixel_64bppPARGB, setpixel_64bppARGB);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef convert_indexed_to_rgb
|
|
|
|
#undef convert_rgb_to_rgb
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2011-02-24 23:48:03 +01:00
|
|
|
INT bitspp = PIXELFORMATBPP(format);
|
2008-05-21 17:47:50 +02:00
|
|
|
GpRect act_rect; /* actual rect to be used */
|
2010-02-05 02:05:54 +01:00
|
|
|
GpStatus stat;
|
2017-02-14 10:24:36 +01:00
|
|
|
BOOL unlock;
|
2007-08-08 03:41:55 +02:00
|
|
|
|
2009-12-18 23:22:25 +01:00
|
|
|
TRACE("%p %p %d 0x%x %p\n", bitmap, rect, flags, format, lockeddata);
|
2007-08-08 03:41:55 +02:00
|
|
|
|
2008-05-21 17:47:50 +02:00
|
|
|
if(!lockeddata || !bitmap)
|
2007-08-08 03:41:55 +02:00
|
|
|
return InvalidParameter;
|
2017-02-14 10:24:36 +01:00
|
|
|
if(!image_lock(&bitmap->image, &unlock))
|
|
|
|
return ObjectBusy;
|
2007-08-08 03:41:55 +02:00
|
|
|
|
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)
|
2017-02-14 10:24:36 +01:00
|
|
|
{
|
|
|
|
image_unlock(&bitmap->image, unlock);
|
2008-05-21 17:47:50 +02:00
|
|
|
return InvalidParameter;
|
2017-02-14 10:24:36 +01:00
|
|
|
}
|
2008-05-21 17:47:50 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2008-03-07 10:19:05 +01:00
|
|
|
if(bitmap->lockmode)
|
2010-02-05 02:05:54 +01:00
|
|
|
{
|
|
|
|
WARN("bitmap is already locked and cannot be locked again\n");
|
2017-02-14 10:24:36 +01:00
|
|
|
image_unlock(&bitmap->image, unlock);
|
2007-08-08 03:41:55 +02:00
|
|
|
return WrongState;
|
2010-02-05 02:05:54 +01:00
|
|
|
}
|
2007-08-08 03:41:55 +02:00
|
|
|
|
2011-02-24 23:48:03 +01:00
|
|
|
if (bitmap->bits && bitmap->format == format && !(flags & ImageLockModeUserInputBuf))
|
2009-08-28 23:53:57 +02:00
|
|
|
{
|
|
|
|
/* no conversion is necessary; just use the bits directly */
|
|
|
|
lockeddata->Width = act_rect.Width;
|
|
|
|
lockeddata->Height = act_rect.Height;
|
|
|
|
lockeddata->PixelFormat = format;
|
|
|
|
lockeddata->Reserved = flags;
|
|
|
|
lockeddata->Stride = bitmap->stride;
|
|
|
|
lockeddata->Scan0 = bitmap->bits + (bitspp / 8) * act_rect.X +
|
|
|
|
bitmap->stride * act_rect.Y;
|
|
|
|
|
2012-07-17 07:57:40 +02:00
|
|
|
bitmap->lockmode = flags | ImageLockModeRead;
|
2009-08-28 23:53:57 +02:00
|
|
|
|
2017-02-14 10:24:36 +01:00
|
|
|
image_unlock(&bitmap->image, unlock);
|
2009-08-28 23:53:57 +02:00
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2010-02-05 02:05:54 +01:00
|
|
|
/* Make sure we can convert to the requested format. */
|
2011-02-24 23:12:43 +01:00
|
|
|
if (flags & ImageLockModeRead)
|
2010-02-05 02:05:54 +01:00
|
|
|
{
|
2011-02-24 23:12:43 +01:00
|
|
|
stat = convert_pixels(0, 0, 0, NULL, format, 0, NULL, bitmap->format, NULL);
|
|
|
|
if (stat == NotImplemented)
|
|
|
|
{
|
|
|
|
FIXME("cannot read bitmap from %x to %x\n", bitmap->format, format);
|
2017-02-14 10:24:36 +01:00
|
|
|
image_unlock(&bitmap->image, unlock);
|
2011-02-24 23:12:43 +01:00
|
|
|
return NotImplemented;
|
|
|
|
}
|
2007-08-08 03:41:55 +02:00
|
|
|
}
|
|
|
|
|
2010-02-05 02:05:54 +01:00
|
|
|
/* If we're opening for writing, make sure we'll be able to write back in
|
|
|
|
* the original format. */
|
|
|
|
if (flags & ImageLockModeWrite)
|
|
|
|
{
|
|
|
|
stat = convert_pixels(0, 0, 0, NULL, bitmap->format, 0, NULL, format, NULL);
|
|
|
|
if (stat == NotImplemented)
|
|
|
|
{
|
|
|
|
FIXME("cannot write bitmap from %x to %x\n", format, bitmap->format);
|
2017-02-14 10:24:36 +01:00
|
|
|
image_unlock(&bitmap->image, unlock);
|
2010-02-05 02:05:54 +01:00
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
}
|
2007-08-08 03:41:55 +02:00
|
|
|
|
2011-02-24 23:48:03 +01:00
|
|
|
lockeddata->Width = act_rect.Width;
|
|
|
|
lockeddata->Height = act_rect.Height;
|
|
|
|
lockeddata->PixelFormat = format;
|
|
|
|
lockeddata->Reserved = flags;
|
|
|
|
|
|
|
|
if(!(flags & ImageLockModeUserInputBuf))
|
|
|
|
{
|
|
|
|
lockeddata->Stride = (((act_rect.Width * bitspp + 7) / 8) + 3) & ~3;
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
bitmap->bitmapbits = heap_alloc_zero(lockeddata->Stride * act_rect.Height);
|
2007-08-08 03:41:55 +02:00
|
|
|
|
2017-02-14 10:24:36 +01:00
|
|
|
if (!bitmap->bitmapbits)
|
|
|
|
{
|
|
|
|
image_unlock(&bitmap->image, unlock);
|
|
|
|
return OutOfMemory;
|
|
|
|
}
|
2007-08-08 03:41:55 +02:00
|
|
|
|
2011-02-24 23:48:03 +01:00
|
|
|
lockeddata->Scan0 = bitmap->bitmapbits;
|
|
|
|
}
|
2007-08-08 03:41:55 +02:00
|
|
|
|
2011-02-24 23:12:43 +01:00
|
|
|
if (flags & ImageLockModeRead)
|
2010-02-05 02:05:54 +01:00
|
|
|
{
|
2013-11-19 01:05:53 +01:00
|
|
|
static BOOL fixme = FALSE;
|
2011-02-24 23:32:54 +01:00
|
|
|
|
|
|
|
if (!fixme && (PIXELFORMATBPP(bitmap->format) * act_rect.X) % 8 != 0)
|
|
|
|
{
|
|
|
|
FIXME("Cannot copy rows that don't start at a whole byte.\n");
|
2013-11-19 01:05:53 +01:00
|
|
|
fixme = TRUE;
|
2011-02-24 23:32:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
stat = convert_pixels(act_rect.Width, act_rect.Height,
|
2011-02-24 23:48:03 +01:00
|
|
|
lockeddata->Stride, lockeddata->Scan0, format,
|
2011-02-24 23:32:54 +01:00
|
|
|
bitmap->stride,
|
|
|
|
bitmap->bits + bitmap->stride * act_rect.Y + PIXELFORMATBPP(bitmap->format) * act_rect.X / 8,
|
2012-07-17 08:00:21 +02:00
|
|
|
bitmap->format, bitmap->image.palette);
|
2011-02-24 23:12:43 +01:00
|
|
|
|
|
|
|
if (stat != Ok)
|
|
|
|
{
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(bitmap->bitmapbits);
|
2011-02-24 23:48:03 +01:00
|
|
|
bitmap->bitmapbits = NULL;
|
2017-02-14 10:24:36 +01:00
|
|
|
image_unlock(&bitmap->image, unlock);
|
2011-02-24 23:12:43 +01:00
|
|
|
return stat;
|
|
|
|
}
|
2008-09-28 21:21:47 +02:00
|
|
|
}
|
2007-08-10 03:25:27 +02:00
|
|
|
|
2012-07-17 07:57:40 +02:00
|
|
|
bitmap->lockmode = flags | ImageLockModeRead;
|
2011-02-24 23:32:54 +01:00
|
|
|
bitmap->lockx = act_rect.X;
|
|
|
|
bitmap->locky = act_rect.Y;
|
2007-08-08 03:41:55 +02:00
|
|
|
|
2017-02-14 10:24:36 +01:00
|
|
|
image_unlock(&bitmap->image, unlock);
|
2007-08-08 03:41:55 +02:00
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2009-04-20 09:46:36 +02:00
|
|
|
GpStatus WINGDIPAPI GdipBitmapSetResolution(GpBitmap* bitmap, REAL xdpi, REAL ydpi)
|
|
|
|
{
|
2009-12-27 03:05:58 +01:00
|
|
|
TRACE("(%p, %.2f, %.2f)\n", bitmap, xdpi, ydpi);
|
2009-04-20 09:46:36 +02:00
|
|
|
|
2009-12-27 03:05:58 +01:00
|
|
|
if (!bitmap || xdpi == 0.0 || ydpi == 0.0)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
bitmap->image.xres = xdpi;
|
|
|
|
bitmap->image.yres = ydpi;
|
|
|
|
|
|
|
|
return Ok;
|
2009-04-20 09:46:36 +02:00
|
|
|
}
|
|
|
|
|
2007-08-08 03:41:55 +02:00
|
|
|
GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap* bitmap,
|
|
|
|
BitmapData* lockeddata)
|
|
|
|
{
|
2010-02-05 02:05:54 +01:00
|
|
|
GpStatus stat;
|
2013-11-19 01:05:53 +01:00
|
|
|
static BOOL fixme = FALSE;
|
2017-02-14 10:24:36 +01:00
|
|
|
BOOL unlock;
|
2007-08-08 03:41:55 +02:00
|
|
|
|
2009-12-18 23:07:12 +01:00
|
|
|
TRACE("(%p,%p)\n", bitmap, lockeddata);
|
|
|
|
|
2007-08-08 03:41:55 +02:00
|
|
|
if(!bitmap || !lockeddata)
|
|
|
|
return InvalidParameter;
|
2017-02-14 10:24:36 +01:00
|
|
|
if(!image_lock(&bitmap->image, &unlock))
|
|
|
|
return ObjectBusy;
|
2007-08-08 03:41:55 +02:00
|
|
|
|
|
|
|
if(!bitmap->lockmode)
|
2017-02-14 10:24:36 +01:00
|
|
|
{
|
|
|
|
image_unlock(&bitmap->image, unlock);
|
2007-08-08 03:41:55 +02:00
|
|
|
return WrongState;
|
2017-02-14 10:24:36 +01:00
|
|
|
}
|
2007-08-08 03:41:55 +02:00
|
|
|
|
2011-02-24 23:09:17 +01:00
|
|
|
if(!(lockeddata->Reserved & ImageLockModeWrite)){
|
2017-02-14 10:24:43 +01:00
|
|
|
bitmap->lockmode = 0;
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(bitmap->bitmapbits);
|
2008-03-07 10:19:03 +01:00
|
|
|
bitmap->bitmapbits = NULL;
|
2017-02-14 10:24:36 +01:00
|
|
|
image_unlock(&bitmap->image, unlock);
|
2007-08-08 03:41:55 +02:00
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2011-02-24 23:48:03 +01:00
|
|
|
if (!bitmap->bitmapbits && !(lockeddata->Reserved & ImageLockModeUserInputBuf))
|
2009-08-28 23:53:57 +02:00
|
|
|
{
|
|
|
|
/* we passed a direct reference; no need to do anything */
|
|
|
|
bitmap->lockmode = 0;
|
2017-02-14 10:24:36 +01:00
|
|
|
image_unlock(&bitmap->image, unlock);
|
2009-08-28 23:53:57 +02:00
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2011-02-24 23:32:54 +01:00
|
|
|
if (!fixme && (PIXELFORMATBPP(bitmap->format) * bitmap->lockx) % 8 != 0)
|
|
|
|
{
|
|
|
|
FIXME("Cannot copy rows that don't start at a whole byte.\n");
|
2013-11-19 01:05:53 +01:00
|
|
|
fixme = TRUE;
|
2011-02-24 23:32:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
stat = convert_pixels(lockeddata->Width, lockeddata->Height,
|
|
|
|
bitmap->stride,
|
|
|
|
bitmap->bits + bitmap->stride * bitmap->locky + PIXELFORMATBPP(bitmap->format) * bitmap->lockx / 8,
|
|
|
|
bitmap->format,
|
|
|
|
lockeddata->Stride, lockeddata->Scan0, lockeddata->PixelFormat, NULL);
|
2007-08-08 03:41:55 +02:00
|
|
|
|
2010-02-05 02:05:54 +01:00
|
|
|
if (stat != Ok)
|
|
|
|
{
|
|
|
|
ERR("failed to convert pixels; this should never happen\n");
|
2007-08-08 03:41:55 +02:00
|
|
|
}
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(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
|
|
|
|
2017-02-14 10:24:36 +01:00
|
|
|
image_unlock(&bitmap->image, unlock);
|
2010-02-05 02:05:54 +01:00
|
|
|
return stat;
|
2007-08-08 03:41:55 +02:00
|
|
|
}
|
|
|
|
|
2009-06-02 03:01:26 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCloneBitmapArea(REAL x, REAL y, REAL width, REAL height,
|
|
|
|
PixelFormat format, GpBitmap* srcBitmap, GpBitmap** dstBitmap)
|
|
|
|
{
|
2009-12-07 03:02:35 +01:00
|
|
|
Rect area;
|
|
|
|
GpStatus stat;
|
2009-06-02 03:01:26 +02:00
|
|
|
|
2009-12-18 23:22:25 +01:00
|
|
|
TRACE("(%f,%f,%f,%f,0x%x,%p,%p)\n", x, y, width, height, format, srcBitmap, dstBitmap);
|
2009-12-07 03:02:35 +01:00
|
|
|
|
|
|
|
if (!srcBitmap || !dstBitmap || srcBitmap->image.type != ImageTypeBitmap ||
|
|
|
|
x < 0 || y < 0 ||
|
|
|
|
x + width > srcBitmap->width || y + height > srcBitmap->height)
|
|
|
|
{
|
|
|
|
TRACE("<-- InvalidParameter\n");
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format == PixelFormatDontCare)
|
|
|
|
format = srcBitmap->format;
|
|
|
|
|
2012-08-21 04:02:06 +02:00
|
|
|
area.X = gdip_round(x);
|
|
|
|
area.Y = gdip_round(y);
|
|
|
|
area.Width = gdip_round(width);
|
|
|
|
area.Height = gdip_round(height);
|
2009-12-07 03:02:35 +01:00
|
|
|
|
2013-10-18 07:04:46 +02:00
|
|
|
stat = GdipCreateBitmapFromScan0(area.Width, area.Height, 0, format, NULL, dstBitmap);
|
2009-12-07 03:02:35 +01:00
|
|
|
if (stat == Ok)
|
|
|
|
{
|
2013-10-18 07:04:46 +02:00
|
|
|
stat = convert_pixels(area.Width, area.Height, (*dstBitmap)->stride, (*dstBitmap)->bits, (*dstBitmap)->format,
|
|
|
|
srcBitmap->stride,
|
|
|
|
srcBitmap->bits + srcBitmap->stride * area.Y + PIXELFORMATBPP(srcBitmap->format) * area.X / 8,
|
|
|
|
srcBitmap->format, srcBitmap->image.palette);
|
2014-03-24 22:36:35 +01:00
|
|
|
|
|
|
|
if (stat == Ok && srcBitmap->image.palette)
|
|
|
|
{
|
|
|
|
ColorPalette *src_palette, *dst_palette;
|
|
|
|
|
|
|
|
src_palette = srcBitmap->image.palette;
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
dst_palette = heap_alloc_zero(sizeof(UINT) * 2 + sizeof(ARGB) * src_palette->Count);
|
2014-03-24 22:36:35 +01:00
|
|
|
|
|
|
|
if (dst_palette)
|
|
|
|
{
|
|
|
|
dst_palette->Flags = src_palette->Flags;
|
|
|
|
dst_palette->Count = src_palette->Count;
|
|
|
|
memcpy(dst_palette->Entries, src_palette->Entries, sizeof(ARGB) * src_palette->Count);
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free((*dstBitmap)->image.palette);
|
2014-03-24 22:36:35 +01:00
|
|
|
(*dstBitmap)->image.palette = dst_palette;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
stat = OutOfMemory;
|
|
|
|
}
|
|
|
|
|
2009-12-07 03:02:35 +01:00
|
|
|
if (stat != Ok)
|
2016-08-05 08:32:46 +02:00
|
|
|
GdipDisposeImage(&(*dstBitmap)->image);
|
2009-12-07 03:02:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (stat != Ok)
|
|
|
|
*dstBitmap = NULL;
|
|
|
|
|
|
|
|
return stat;
|
2009-06-02 03:01:26 +02:00
|
|
|
}
|
|
|
|
|
2009-03-07 18:33:55 +01:00
|
|
|
GpStatus WINGDIPAPI GdipCloneBitmapAreaI(INT x, INT y, INT width, INT height,
|
|
|
|
PixelFormat format, GpBitmap* srcBitmap, GpBitmap** dstBitmap)
|
|
|
|
{
|
2009-12-18 23:22:25 +01:00
|
|
|
TRACE("(%i,%i,%i,%i,0x%x,%p,%p)\n", x, y, width, height, format, srcBitmap, dstBitmap);
|
2009-03-07 18:33:55 +01:00
|
|
|
|
2009-12-07 03:02:35 +01:00
|
|
|
return GdipCloneBitmapArea(x, y, width, height, format, srcBitmap, dstBitmap);
|
2009-03-07 18:33:55 +01:00
|
|
|
}
|
|
|
|
|
2008-07-02 03:03:34 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCloneImage(GpImage *image, GpImage **cloneImage)
|
|
|
|
{
|
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;
|
|
|
|
|
2016-08-18 21:22:02 +02:00
|
|
|
if (image->type == ImageTypeBitmap)
|
2009-08-28 23:21:27 +02:00
|
|
|
{
|
2013-10-18 07:04:56 +02:00
|
|
|
GpBitmap *bitmap = (GpBitmap *)image;
|
2009-09-14 18:23:45 +02:00
|
|
|
|
2013-10-18 07:04:56 +02:00
|
|
|
return GdipCloneBitmapAreaI(0, 0, bitmap->width, bitmap->height,
|
|
|
|
bitmap->format, bitmap, (GpBitmap **)cloneImage);
|
2009-08-28 23:21:27 +02:00
|
|
|
}
|
2012-10-31 20:33:50 +01:00
|
|
|
else if (image->type == ImageTypeMetafile && ((GpMetafile*)image)->hemf)
|
|
|
|
{
|
|
|
|
GpMetafile *result, *metafile;
|
|
|
|
|
|
|
|
metafile = (GpMetafile*)image;
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
result = heap_alloc_zero(sizeof(*result));
|
2012-10-31 20:33:50 +01:00
|
|
|
if (!result)
|
|
|
|
return OutOfMemory;
|
|
|
|
|
|
|
|
result->image.type = ImageTypeMetafile;
|
|
|
|
result->image.format = image->format;
|
|
|
|
result->image.flags = image->flags;
|
|
|
|
result->image.frame_count = 1;
|
|
|
|
result->image.xres = image->xres;
|
|
|
|
result->image.yres = image->yres;
|
|
|
|
result->bounds = metafile->bounds;
|
|
|
|
result->unit = metafile->unit;
|
|
|
|
result->metafile_type = metafile->metafile_type;
|
|
|
|
result->hemf = CopyEnhMetaFileW(metafile->hemf, NULL);
|
2017-06-16 16:06:12 +02:00
|
|
|
list_init(&result->containers);
|
2012-10-31 20:33:50 +01:00
|
|
|
|
|
|
|
if (!result->hemf)
|
|
|
|
{
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(result);
|
2012-10-31 20:33:50 +01:00
|
|
|
return OutOfMemory;
|
|
|
|
}
|
|
|
|
|
|
|
|
*cloneImage = &result->image;
|
|
|
|
return Ok;
|
|
|
|
}
|
2009-08-28 23:21:27 +02:00
|
|
|
else
|
|
|
|
{
|
2012-10-31 20:33:50 +01:00
|
|
|
WARN("GpImage with no image data (metafile in wrong state?)\n");
|
|
|
|
return InvalidParameter;
|
2009-08-28 23:21:27 +02:00
|
|
|
}
|
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;
|
|
|
|
|
2014-07-11 09:55:53 +02:00
|
|
|
*bitmap = NULL;
|
|
|
|
|
2007-08-08 03:42:04 +02:00
|
|
|
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;
|
2020-01-27 05:13:48 +01:00
|
|
|
HBITMAP hbm;
|
|
|
|
void *bmbits;
|
|
|
|
GpStatus status;
|
2008-07-10 16:39:29 +02:00
|
|
|
|
2020-01-27 05:13:48 +01:00
|
|
|
TRACE("(%p, %p, %p)\n", info, bits, bitmap);
|
2008-07-10 16:39:29 +02:00
|
|
|
|
2010-04-24 16:37:51 +02:00
|
|
|
if (!info || !bits || !bitmap)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2020-01-27 05:13:48 +01:00
|
|
|
hbm = CreateDIBSection(0, info, DIB_RGB_COLORS, &bmbits, NULL, 0);
|
|
|
|
if (!hbm)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2008-07-10 16:39:29 +02:00
|
|
|
height = abs(info->bmiHeader.biHeight);
|
|
|
|
stride = ((info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 31) >> 3) & ~3;
|
2020-01-27 05:13:48 +01:00
|
|
|
TRACE("height %u, stride %u, image size %u\n", height, stride, height * stride);
|
2008-07-10 16:39:29 +02:00
|
|
|
|
2020-01-27 05:13:48 +01:00
|
|
|
memcpy(bmbits, bits, height * stride);
|
2008-07-10 16:39:29 +02:00
|
|
|
|
2020-01-27 05:13:48 +01:00
|
|
|
status = GdipCreateBitmapFromHBITMAP(hbm, NULL, bitmap);
|
|
|
|
DeleteObject(hbm);
|
2008-07-10 16:39:29 +02:00
|
|
|
|
2020-01-27 05:13:48 +01:00
|
|
|
return status;
|
2008-07-10 16:39:29 +02:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-10-28 17:28:47 +01:00
|
|
|
static inline DWORD blend_argb_no_bkgnd_alpha(DWORD src, DWORD bkgnd)
|
|
|
|
{
|
|
|
|
BYTE b = (BYTE)src;
|
|
|
|
BYTE g = (BYTE)(src >> 8);
|
|
|
|
BYTE r = (BYTE)(src >> 16);
|
|
|
|
DWORD alpha = (BYTE)(src >> 24);
|
|
|
|
return ((b + ((BYTE)bkgnd * (255 - alpha) + 127) / 255) |
|
|
|
|
(g + ((BYTE)(bkgnd >> 8) * (255 - alpha) + 127) / 255) << 8 |
|
|
|
|
(r + ((BYTE)(bkgnd >> 16) * (255 - alpha) + 127) / 255) << 16 |
|
|
|
|
(alpha << 24));
|
|
|
|
}
|
|
|
|
|
2007-12-19 09:58:51 +01:00
|
|
|
GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
|
|
|
|
HBITMAP* hbmReturn, ARGB background)
|
|
|
|
{
|
2009-08-27 23:58:11 +02:00
|
|
|
GpStatus stat;
|
2011-09-29 18:58:17 +02:00
|
|
|
HBITMAP result;
|
2009-08-27 23:58:11 +02:00
|
|
|
UINT width, height;
|
|
|
|
BITMAPINFOHEADER bih;
|
2011-09-29 18:58:17 +02:00
|
|
|
LPBYTE bits;
|
2017-02-14 10:24:47 +01:00
|
|
|
BOOL unlock;
|
|
|
|
|
2009-08-27 23:58:11 +02:00
|
|
|
TRACE("(%p,%p,%x)\n", bitmap, hbmReturn, background);
|
|
|
|
|
|
|
|
if (!bitmap || !hbmReturn) return InvalidParameter;
|
2017-02-14 10:24:47 +01:00
|
|
|
if (!image_lock(&bitmap->image, &unlock)) return ObjectBusy;
|
2009-08-27 23:58:11 +02:00
|
|
|
|
2016-08-05 08:32:46 +02:00
|
|
|
GdipGetImageWidth(&bitmap->image, &width);
|
|
|
|
GdipGetImageHeight(&bitmap->image, &height);
|
2009-08-27 23:58:11 +02:00
|
|
|
|
|
|
|
bih.biSize = sizeof(bih);
|
|
|
|
bih.biWidth = width;
|
|
|
|
bih.biHeight = height;
|
|
|
|
bih.biPlanes = 1;
|
|
|
|
bih.biBitCount = 32;
|
|
|
|
bih.biCompression = BI_RGB;
|
|
|
|
bih.biSizeImage = 0;
|
|
|
|
bih.biXPelsPerMeter = 0;
|
|
|
|
bih.biYPelsPerMeter = 0;
|
|
|
|
bih.biClrUsed = 0;
|
|
|
|
bih.biClrImportant = 0;
|
|
|
|
|
2012-05-02 12:02:17 +02:00
|
|
|
result = CreateDIBSection(0, (BITMAPINFO*)&bih, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
|
2017-02-14 10:24:47 +01:00
|
|
|
if (!result)
|
2009-08-27 23:58:11 +02:00
|
|
|
{
|
2017-02-14 10:24:47 +01:00
|
|
|
image_unlock(&bitmap->image, unlock);
|
|
|
|
return GenericError;
|
2009-08-27 23:58:11 +02:00
|
|
|
}
|
|
|
|
|
2017-02-14 10:24:47 +01:00
|
|
|
stat = convert_pixels(width, height, -width*4,
|
|
|
|
bits + (width * 4 * (height - 1)), PixelFormat32bppPARGB,
|
|
|
|
bitmap->stride, bitmap->bits, bitmap->format, bitmap->image.palette);
|
|
|
|
if (stat != Ok)
|
2009-08-27 23:58:11 +02:00
|
|
|
{
|
|
|
|
DeleteObject(result);
|
2017-02-14 10:24:47 +01:00
|
|
|
image_unlock(&bitmap->image, unlock);
|
|
|
|
return stat;
|
2009-08-27 23:58:11 +02:00
|
|
|
}
|
|
|
|
|
2017-02-14 10:24:47 +01:00
|
|
|
if (background & 0xffffff)
|
|
|
|
{
|
|
|
|
DWORD *ptr;
|
|
|
|
UINT i;
|
|
|
|
for (ptr = (DWORD*)bits, i = 0; i < width * height; ptr++, i++)
|
|
|
|
{
|
|
|
|
if ((*ptr & 0xff000000) == 0xff000000) continue;
|
|
|
|
*ptr = blend_argb_no_bkgnd_alpha(*ptr, background);
|
|
|
|
}
|
|
|
|
}
|
2009-08-27 23:58:11 +02:00
|
|
|
|
2017-02-14 10:24:47 +01:00
|
|
|
*hbmReturn = result;
|
|
|
|
image_unlock(&bitmap->image, unlock);
|
|
|
|
return Ok;
|
2007-12-19 09:58:51 +01:00
|
|
|
}
|
|
|
|
|
2007-08-09 04:42:28 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCreateBitmapFromGraphics(INT width, INT height,
|
|
|
|
GpGraphics* target, GpBitmap** bitmap)
|
|
|
|
{
|
|
|
|
GpStatus ret;
|
|
|
|
|
2010-06-25 11:26:53 +02:00
|
|
|
TRACE("(%d, %d, %p, %p)\n", width, height, target, bitmap);
|
|
|
|
|
2007-08-09 04:42:28 +02:00
|
|
|
if(!target || !bitmap)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2013-03-09 19:08:27 +01:00
|
|
|
ret = GdipCreateBitmapFromScan0(width, height, 0, PixelFormat32bppPARGB,
|
2007-08-09 04:42:28 +02:00
|
|
|
NULL, bitmap);
|
|
|
|
|
2013-03-09 19:08:27 +01:00
|
|
|
if (ret == Ok)
|
|
|
|
{
|
|
|
|
GdipGetDpiX(target, &(*bitmap)->image.xres);
|
|
|
|
GdipGetDpiY(target, &(*bitmap)->image.yres);
|
|
|
|
}
|
|
|
|
|
2007-08-09 04:42:28 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-02-02 17:15:53 +01:00
|
|
|
GpStatus WINGDIPAPI GdipCreateBitmapFromHICON(HICON hicon, GpBitmap** bitmap)
|
|
|
|
{
|
2009-08-25 00:05:24 +02:00
|
|
|
GpStatus stat;
|
2009-02-02 17:15:53 +01:00
|
|
|
ICONINFO iinfo;
|
2009-08-25 00:05:24 +02:00
|
|
|
BITMAP bm;
|
|
|
|
int ret;
|
2013-01-16 10:18:30 +01:00
|
|
|
UINT width, height, stride;
|
2009-08-25 00:05:24 +02:00
|
|
|
GpRect rect;
|
|
|
|
BitmapData lockeddata;
|
|
|
|
HDC screendc;
|
|
|
|
BOOL has_alpha;
|
|
|
|
int x, y;
|
|
|
|
BITMAPINFOHEADER bih;
|
|
|
|
DWORD *src;
|
|
|
|
BYTE *dst_row;
|
|
|
|
DWORD *dst;
|
2009-02-02 17:15:53 +01:00
|
|
|
|
|
|
|
TRACE("%p, %p\n", hicon, bitmap);
|
|
|
|
|
|
|
|
if(!bitmap || !GetIconInfo(hicon, &iinfo))
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2009-08-25 00:05:24 +02:00
|
|
|
/* get the size of the icon */
|
|
|
|
ret = GetObjectA(iinfo.hbmColor ? iinfo.hbmColor : iinfo.hbmMask, sizeof(bm), &bm);
|
|
|
|
if (ret == 0) {
|
|
|
|
DeleteObject(iinfo.hbmColor);
|
|
|
|
DeleteObject(iinfo.hbmMask);
|
|
|
|
return GenericError;
|
|
|
|
}
|
2009-02-02 17:15:53 +01:00
|
|
|
|
2009-08-25 00:05:24 +02:00
|
|
|
width = bm.bmWidth;
|
2013-01-16 10:18:30 +01:00
|
|
|
height = iinfo.hbmColor ? abs(bm.bmHeight) : abs(bm.bmHeight) / 2;
|
|
|
|
stride = width * 4;
|
2009-02-02 17:15:53 +01:00
|
|
|
|
2013-01-16 10:18:30 +01:00
|
|
|
stat = GdipCreateBitmapFromScan0(width, height, stride, PixelFormat32bppARGB, NULL, bitmap);
|
2009-08-25 00:05:24 +02:00
|
|
|
if (stat != Ok) {
|
|
|
|
DeleteObject(iinfo.hbmColor);
|
|
|
|
DeleteObject(iinfo.hbmMask);
|
|
|
|
return stat;
|
|
|
|
}
|
2009-02-02 17:15:53 +01:00
|
|
|
|
2009-08-25 00:05:24 +02:00
|
|
|
rect.X = 0;
|
|
|
|
rect.Y = 0;
|
|
|
|
rect.Width = width;
|
|
|
|
rect.Height = height;
|
|
|
|
|
|
|
|
stat = GdipBitmapLockBits(*bitmap, &rect, ImageLockModeWrite, PixelFormat32bppARGB, &lockeddata);
|
|
|
|
if (stat != Ok) {
|
|
|
|
DeleteObject(iinfo.hbmColor);
|
|
|
|
DeleteObject(iinfo.hbmMask);
|
2016-08-05 08:32:46 +02:00
|
|
|
GdipDisposeImage(&(*bitmap)->image);
|
2009-08-25 00:05:24 +02:00
|
|
|
return stat;
|
2009-02-02 17:15:53 +01:00
|
|
|
}
|
|
|
|
|
2009-08-25 00:05:24 +02:00
|
|
|
bih.biSize = sizeof(bih);
|
|
|
|
bih.biWidth = width;
|
2013-01-15 05:48:08 +01:00
|
|
|
bih.biHeight = iinfo.hbmColor ? -height: -height * 2;
|
2009-08-25 00:05:24 +02:00
|
|
|
bih.biPlanes = 1;
|
|
|
|
bih.biBitCount = 32;
|
|
|
|
bih.biCompression = BI_RGB;
|
|
|
|
bih.biSizeImage = 0;
|
|
|
|
bih.biXPelsPerMeter = 0;
|
|
|
|
bih.biYPelsPerMeter = 0;
|
|
|
|
bih.biClrUsed = 0;
|
|
|
|
bih.biClrImportant = 0;
|
|
|
|
|
2013-02-20 07:18:13 +01:00
|
|
|
screendc = CreateCompatibleDC(0);
|
2009-08-25 00:05:24 +02:00
|
|
|
if (iinfo.hbmColor)
|
|
|
|
{
|
2013-01-16 10:18:30 +01:00
|
|
|
GetDIBits(screendc, iinfo.hbmColor, 0, height, lockeddata.Scan0, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
|
2009-08-25 00:05:24 +02:00
|
|
|
|
|
|
|
if (bm.bmBitsPixel == 32)
|
|
|
|
{
|
|
|
|
has_alpha = FALSE;
|
|
|
|
|
|
|
|
/* If any pixel has a non-zero alpha, ignore hbmMask */
|
2013-01-16 10:18:30 +01:00
|
|
|
src = (DWORD*)lockeddata.Scan0;
|
2009-08-25 00:05:24 +02:00
|
|
|
for (x=0; x<width && !has_alpha; x++)
|
|
|
|
for (y=0; y<height && !has_alpha; y++)
|
|
|
|
if ((*src++ & 0xff000000) != 0)
|
|
|
|
has_alpha = TRUE;
|
|
|
|
}
|
|
|
|
else has_alpha = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-16 10:18:30 +01:00
|
|
|
GetDIBits(screendc, iinfo.hbmMask, 0, height, lockeddata.Scan0, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
|
2009-08-25 00:05:24 +02:00
|
|
|
has_alpha = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!has_alpha)
|
|
|
|
{
|
|
|
|
if (iinfo.hbmMask)
|
|
|
|
{
|
2015-10-21 00:53:12 +02:00
|
|
|
BYTE *bits = heap_alloc(height * stride);
|
2013-01-16 10:18:30 +01:00
|
|
|
|
2009-08-25 00:05:24 +02:00
|
|
|
/* read alpha data from the mask */
|
|
|
|
if (iinfo.hbmColor)
|
|
|
|
GetDIBits(screendc, iinfo.hbmMask, 0, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
|
|
|
|
else
|
|
|
|
GetDIBits(screendc, iinfo.hbmMask, height, height, bits, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
|
|
|
|
|
|
|
|
src = (DWORD*)bits;
|
|
|
|
dst_row = lockeddata.Scan0;
|
|
|
|
for (y=0; y<height; y++)
|
|
|
|
{
|
|
|
|
dst = (DWORD*)dst_row;
|
|
|
|
for (x=0; x<height; x++)
|
|
|
|
{
|
|
|
|
DWORD src_value = *src++;
|
|
|
|
if (src_value)
|
|
|
|
*dst++ = 0;
|
|
|
|
else
|
|
|
|
*dst++ |= 0xff000000;
|
|
|
|
}
|
|
|
|
dst_row += lockeddata.Stride;
|
|
|
|
}
|
2013-01-16 10:18:30 +01:00
|
|
|
|
2015-10-21 00:53:48 +02:00
|
|
|
heap_free(bits);
|
2009-08-25 00:05:24 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* set constant alpha of 255 */
|
2013-01-16 10:18:30 +01:00
|
|
|
dst_row = lockeddata.Scan0;
|
2009-08-25 00:05:24 +02:00
|
|
|
for (y=0; y<height; y++)
|
|
|
|
{
|
|
|
|
dst = (DWORD*)dst_row;
|
|
|
|
for (x=0; x<height; x++)
|
|
|
|
*dst++ |= 0xff000000;
|
|
|
|
dst_row += lockeddata.Stride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-20 07:18:13 +01:00
|
|
|
DeleteDC(screendc);
|
2009-02-02 17:15:53 +01:00
|
|
|
|
|
|
|
DeleteObject(iinfo.hbmColor);
|
|
|
|
DeleteObject(iinfo.hbmMask);
|
|
|
|
|
2009-08-25 00:05:24 +02:00
|
|
|
GdipBitmapUnlockBits(*bitmap, &lockeddata);
|
|
|
|
|
2009-02-02 17:15:53 +01:00
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2009-12-12 00:16:21 +01:00
|
|
|
static void generate_halftone_palette(ARGB *entries, UINT count)
|
|
|
|
{
|
|
|
|
static const BYTE halftone_values[6]={0x00,0x33,0x66,0x99,0xcc,0xff};
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
for (i=0; i<8 && i<count; i++)
|
|
|
|
{
|
|
|
|
entries[i] = 0xff000000;
|
|
|
|
if (i&1) entries[i] |= 0x800000;
|
|
|
|
if (i&2) entries[i] |= 0x8000;
|
|
|
|
if (i&4) entries[i] |= 0x80;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (8 < count)
|
|
|
|
entries[i] = 0xffc0c0c0;
|
|
|
|
|
|
|
|
for (i=9; i<16 && i<count; i++)
|
|
|
|
{
|
|
|
|
entries[i] = 0xff000000;
|
|
|
|
if (i&1) entries[i] |= 0xff0000;
|
|
|
|
if (i&2) entries[i] |= 0xff00;
|
|
|
|
if (i&4) entries[i] |= 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=16; i<40 && i<count; i++)
|
|
|
|
{
|
|
|
|
entries[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=40; i<256 && i<count; i++)
|
|
|
|
{
|
|
|
|
entries[i] = 0xff000000;
|
|
|
|
entries[i] |= halftone_values[(i-40)%6];
|
|
|
|
entries[i] |= halftone_values[((i-40)/6)%6] << 8;
|
|
|
|
entries[i] |= halftone_values[((i-40)/36)%6] << 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-27 02:46:55 +01:00
|
|
|
static GpStatus get_screen_resolution(REAL *xres, REAL *yres)
|
|
|
|
{
|
2013-02-20 07:18:13 +01:00
|
|
|
HDC screendc = CreateCompatibleDC(0);
|
2009-12-27 02:46:55 +01:00
|
|
|
|
|
|
|
if (!screendc) return GenericError;
|
|
|
|
|
|
|
|
*xres = (REAL)GetDeviceCaps(screendc, LOGPIXELSX);
|
|
|
|
*yres = (REAL)GetDeviceCaps(screendc, LOGPIXELSY);
|
|
|
|
|
2013-02-20 07:18:13 +01:00
|
|
|
DeleteDC(screendc);
|
2009-12-27 02:46:55 +01:00
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-08-01 04:15:52 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
|
|
|
|
PixelFormat format, BYTE* scan0, GpBitmap** bitmap)
|
|
|
|
{
|
2010-08-08 23:18:40 +02:00
|
|
|
HBITMAP hbitmap=NULL;
|
2009-08-28 23:21:27 +02:00
|
|
|
INT row_size, dib_stride;
|
2010-08-08 23:18:40 +02:00
|
|
|
BYTE *bits=NULL, *own_bits=NULL;
|
2009-12-27 02:46:55 +01:00
|
|
|
REAL xres, yres;
|
|
|
|
GpStatus stat;
|
2007-08-01 04:15:52 +02:00
|
|
|
|
2009-12-18 23:22:25 +01:00
|
|
|
TRACE("%d %d %d 0x%x %p %p\n", width, height, stride, format, scan0, bitmap);
|
2007-08-01 04:15:52 +02:00
|
|
|
|
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;
|
|
|
|
|
2009-12-27 02:46:55 +01:00
|
|
|
stat = get_screen_resolution(&xres, &yres);
|
|
|
|
if (stat != Ok) return stat;
|
|
|
|
|
2009-08-28 23:21:27 +02:00
|
|
|
row_size = (width * PIXELFORMATBPP(format)+7) / 8;
|
|
|
|
dib_stride = (row_size + 3) & ~3;
|
2007-08-01 04:15:52 +02:00
|
|
|
|
2009-08-28 23:21:27 +02:00
|
|
|
if(stride == 0)
|
|
|
|
stride = dib_stride;
|
2007-08-09 04:42:24 +02:00
|
|
|
|
2010-09-30 23:07:53 +02:00
|
|
|
if (format & PixelFormatGDI && !(format & (PixelFormatAlpha|PixelFormatIndexed)) && !scan0)
|
2010-08-08 23:18:40 +02:00
|
|
|
{
|
2013-01-30 11:02:14 +01:00
|
|
|
char bmibuf[FIELD_OFFSET(BITMAPINFO, bmiColors[256])];
|
|
|
|
BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
|
2010-03-05 03:21:19 +01:00
|
|
|
|
2010-08-08 23:18:40 +02:00
|
|
|
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
pbmi->bmiHeader.biWidth = width;
|
|
|
|
pbmi->bmiHeader.biHeight = -height;
|
|
|
|
pbmi->bmiHeader.biPlanes = 1;
|
|
|
|
/* FIXME: use the rest of the data from format */
|
|
|
|
pbmi->bmiHeader.biBitCount = PIXELFORMATBPP(format);
|
|
|
|
pbmi->bmiHeader.biCompression = BI_RGB;
|
|
|
|
pbmi->bmiHeader.biSizeImage = 0;
|
|
|
|
pbmi->bmiHeader.biXPelsPerMeter = 0;
|
|
|
|
pbmi->bmiHeader.biYPelsPerMeter = 0;
|
|
|
|
pbmi->bmiHeader.biClrUsed = 0;
|
|
|
|
pbmi->bmiHeader.biClrImportant = 0;
|
|
|
|
|
2012-05-02 12:02:17 +02:00
|
|
|
hbitmap = CreateDIBSection(0, pbmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
|
2010-08-08 23:18:40 +02:00
|
|
|
|
|
|
|
if (!hbitmap) return GenericError;
|
2010-11-12 17:17:32 +01:00
|
|
|
|
|
|
|
stride = dib_stride;
|
2010-08-08 23:18:40 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Not a GDI format; don't try to make an HBITMAP. */
|
|
|
|
if (scan0)
|
|
|
|
bits = scan0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
INT size = abs(stride) * height;
|
2007-08-01 04:15:52 +02:00
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
own_bits = bits = heap_alloc_zero(size);
|
2010-08-08 23:18:40 +02:00
|
|
|
if (!own_bits) return OutOfMemory;
|
2007-08-01 04:15:52 +02:00
|
|
|
|
2010-08-08 23:18:40 +02:00
|
|
|
if (stride < 0)
|
|
|
|
bits += stride * (1 - height);
|
|
|
|
}
|
|
|
|
}
|
2007-08-01 04:15:52 +02:00
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
*bitmap = heap_alloc_zero(sizeof(GpBitmap));
|
2009-08-28 23:21:27 +02:00
|
|
|
if(!*bitmap)
|
|
|
|
{
|
|
|
|
DeleteObject(hbitmap);
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(own_bits);
|
2009-08-28 23:21:27 +02:00
|
|
|
return OutOfMemory;
|
2007-08-01 04:15:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
(*bitmap)->image.type = ImageTypeBitmap;
|
2009-09-14 18:23:45 +02:00
|
|
|
memcpy(&(*bitmap)->image.format, &ImageFormatMemoryBMP, sizeof(GUID));
|
2008-05-09 14:39:43 +02:00
|
|
|
(*bitmap)->image.flags = ImageFlagsNone;
|
2012-05-16 16:33:48 +02:00
|
|
|
(*bitmap)->image.frame_count = 1;
|
|
|
|
(*bitmap)->image.current_frame = 0;
|
2012-07-17 07:59:43 +02:00
|
|
|
(*bitmap)->image.palette = NULL;
|
2009-12-27 02:46:55 +01:00
|
|
|
(*bitmap)->image.xres = xres;
|
|
|
|
(*bitmap)->image.yres = yres;
|
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;
|
2015-03-12 10:17:03 +01:00
|
|
|
(*bitmap)->image.decoder = NULL;
|
2020-02-19 08:47:03 +01:00
|
|
|
(*bitmap)->image.encoder = NULL;
|
2009-08-28 23:21:27 +02:00
|
|
|
(*bitmap)->hbitmap = hbitmap;
|
|
|
|
(*bitmap)->hdc = NULL;
|
2009-08-28 23:53:57 +02:00
|
|
|
(*bitmap)->bits = bits;
|
2010-11-12 17:17:32 +01:00
|
|
|
(*bitmap)->stride = stride;
|
2010-08-08 23:18:40 +02:00
|
|
|
(*bitmap)->own_bits = own_bits;
|
2012-06-25 13:30:34 +02:00
|
|
|
(*bitmap)->metadata_reader = NULL;
|
2012-09-21 12:58:20 +02:00
|
|
|
(*bitmap)->prop_count = 0;
|
|
|
|
(*bitmap)->prop_item = NULL;
|
2007-08-01 04:15:52 +02:00
|
|
|
|
2010-07-02 23:12:07 +02:00
|
|
|
/* set format-related flags */
|
|
|
|
if (format & (PixelFormatAlpha|PixelFormatPAlpha|PixelFormatIndexed))
|
|
|
|
(*bitmap)->image.flags |= ImageFlagsHasAlpha;
|
|
|
|
|
2009-12-12 00:16:21 +01:00
|
|
|
if (format == PixelFormat1bppIndexed ||
|
|
|
|
format == PixelFormat4bppIndexed ||
|
|
|
|
format == PixelFormat8bppIndexed)
|
|
|
|
{
|
2015-10-05 00:22:34 +02:00
|
|
|
(*bitmap)->image.palette = heap_alloc_zero(sizeof(UINT) * 2 + sizeof(ARGB) * (1 << PIXELFORMATBPP(format)));
|
2009-12-12 00:16:21 +01:00
|
|
|
|
2012-07-17 07:59:43 +02:00
|
|
|
if (!(*bitmap)->image.palette)
|
2009-12-12 00:16:21 +01:00
|
|
|
{
|
|
|
|
GdipDisposeImage(&(*bitmap)->image);
|
|
|
|
*bitmap = NULL;
|
|
|
|
return OutOfMemory;
|
|
|
|
}
|
|
|
|
|
2012-07-17 07:59:43 +02:00
|
|
|
(*bitmap)->image.palette->Count = 1 << PIXELFORMATBPP(format);
|
|
|
|
|
2009-12-12 00:16:21 +01:00
|
|
|
if (format == PixelFormat1bppIndexed)
|
|
|
|
{
|
2012-07-17 07:59:43 +02:00
|
|
|
(*bitmap)->image.palette->Flags = PaletteFlagsGrayScale;
|
|
|
|
(*bitmap)->image.palette->Entries[0] = 0xff000000;
|
|
|
|
(*bitmap)->image.palette->Entries[1] = 0xffffffff;
|
2009-12-12 00:16:21 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (format == PixelFormat8bppIndexed)
|
2012-07-17 07:59:43 +02:00
|
|
|
(*bitmap)->image.palette->Flags = PaletteFlagsHalftone;
|
2009-12-12 00:16:21 +01:00
|
|
|
|
2012-07-17 07:59:43 +02:00
|
|
|
generate_halftone_palette((*bitmap)->image.palette->Entries,
|
|
|
|
(*bitmap)->image.palette->Count);
|
2009-12-12 00:16:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-18 22:09:45 +01:00
|
|
|
TRACE("<-- %p\n", *bitmap);
|
|
|
|
|
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){
|
2009-08-20 23:43:47 +02:00
|
|
|
GdipDisposeImage(&(*bitmap)->image);
|
|
|
|
*bitmap = NULL;
|
2007-08-08 03:42:20 +02:00
|
|
|
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;
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
*cachedbmp = heap_alloc_zero(sizeof(GpCachedBitmap));
|
2008-11-04 06:54:32 +01:00
|
|
|
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){
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(*cachedbmp);
|
2008-11-04 06:54:32 +01:00
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2009-05-27 20:16:20 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCreateHICONFromBitmap(GpBitmap *bitmap, HICON *hicon)
|
|
|
|
{
|
2010-05-08 19:01:07 +02:00
|
|
|
GpStatus stat;
|
|
|
|
BitmapData lockeddata;
|
|
|
|
ULONG andstride, xorstride, bitssize;
|
|
|
|
LPBYTE andbits, xorbits, androw, xorrow, srcrow;
|
|
|
|
UINT x, y;
|
2009-05-27 20:16:20 +02:00
|
|
|
|
2010-05-08 19:01:07 +02:00
|
|
|
TRACE("(%p, %p)\n", bitmap, hicon);
|
|
|
|
|
|
|
|
if (!bitmap || !hicon)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
stat = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead,
|
|
|
|
PixelFormat32bppPARGB, &lockeddata);
|
|
|
|
if (stat == Ok)
|
|
|
|
{
|
|
|
|
andstride = ((lockeddata.Width+31)/32)*4;
|
|
|
|
xorstride = lockeddata.Width*4;
|
|
|
|
bitssize = (andstride + xorstride) * lockeddata.Height;
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
andbits = heap_alloc_zero(bitssize);
|
2010-05-08 19:01:07 +02:00
|
|
|
|
|
|
|
if (andbits)
|
|
|
|
{
|
|
|
|
xorbits = andbits + andstride * lockeddata.Height;
|
|
|
|
|
|
|
|
for (y=0; y<lockeddata.Height; y++)
|
|
|
|
{
|
|
|
|
srcrow = ((LPBYTE)lockeddata.Scan0) + lockeddata.Stride * y;
|
|
|
|
|
|
|
|
androw = andbits + andstride * y;
|
|
|
|
for (x=0; x<lockeddata.Width; x++)
|
|
|
|
if (srcrow[3+4*x] >= 128)
|
|
|
|
androw[x/8] |= 1 << (7-x%8);
|
|
|
|
|
|
|
|
xorrow = xorbits + xorstride * y;
|
|
|
|
memcpy(xorrow, srcrow, xorstride);
|
|
|
|
}
|
|
|
|
|
|
|
|
*hicon = CreateIcon(NULL, lockeddata.Width, lockeddata.Height, 1, 32,
|
|
|
|
andbits, xorbits);
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(andbits);
|
2010-05-08 19:01:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
stat = OutOfMemory;
|
|
|
|
|
|
|
|
GdipBitmapUnlockBits(bitmap, &lockeddata);
|
|
|
|
}
|
|
|
|
|
|
|
|
return stat;
|
2009-05-27 20:16:20 +02:00
|
|
|
}
|
|
|
|
|
2008-11-04 06:54:32 +01:00
|
|
|
GpStatus WINGDIPAPI GdipDeleteCachedBitmap(GpCachedBitmap *cachedbmp)
|
|
|
|
{
|
|
|
|
TRACE("%p\n", cachedbmp);
|
|
|
|
|
|
|
|
if(!cachedbmp)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2008-11-21 23:57:48 +01:00
|
|
|
GdipDisposeImage(cachedbmp->image);
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(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
|
|
|
}
|
|
|
|
|
2010-02-24 23:59:50 +01:00
|
|
|
/* Internal utility function: Replace the image data of dst with that of src,
|
|
|
|
* and free src. */
|
|
|
|
static void move_bitmap(GpBitmap *dst, GpBitmap *src, BOOL clobber_palette)
|
|
|
|
{
|
2012-06-25 13:30:34 +02:00
|
|
|
assert(src->image.type == ImageTypeBitmap);
|
|
|
|
assert(dst->image.type == ImageTypeBitmap);
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(dst->bitmapbits);
|
|
|
|
heap_free(dst->own_bits);
|
2010-02-24 23:59:50 +01:00
|
|
|
DeleteDC(dst->hdc);
|
|
|
|
DeleteObject(dst->hbitmap);
|
|
|
|
|
|
|
|
if (clobber_palette)
|
|
|
|
{
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(dst->image.palette);
|
2012-07-17 07:59:43 +02:00
|
|
|
dst->image.palette = src->image.palette;
|
2010-02-24 23:59:50 +01:00
|
|
|
}
|
|
|
|
else
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(src->image.palette);
|
2010-02-24 23:59:50 +01:00
|
|
|
|
|
|
|
dst->image.xres = src->image.xres;
|
|
|
|
dst->image.yres = src->image.yres;
|
|
|
|
dst->width = src->width;
|
|
|
|
dst->height = src->height;
|
|
|
|
dst->format = src->format;
|
|
|
|
dst->hbitmap = src->hbitmap;
|
|
|
|
dst->hdc = src->hdc;
|
|
|
|
dst->bits = src->bits;
|
|
|
|
dst->stride = src->stride;
|
2010-08-08 23:18:40 +02:00
|
|
|
dst->own_bits = src->own_bits;
|
2012-06-25 13:30:34 +02:00
|
|
|
if (dst->metadata_reader)
|
|
|
|
IWICMetadataReader_Release(dst->metadata_reader);
|
|
|
|
dst->metadata_reader = src->metadata_reader;
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(dst->prop_item);
|
2012-09-21 12:58:20 +02:00
|
|
|
dst->prop_item = src->prop_item;
|
|
|
|
dst->prop_count = src->prop_count;
|
2015-03-12 10:17:03 +01:00
|
|
|
if (dst->image.decoder)
|
|
|
|
IWICBitmapDecoder_Release(dst->image.decoder);
|
|
|
|
dst->image.decoder = src->image.decoder;
|
2020-02-19 08:47:03 +01:00
|
|
|
terminate_encoder_wic(&dst->image); /* terminate active encoder before overwriting with src */
|
|
|
|
dst->image.encoder = src->image.encoder;
|
2012-07-12 16:17:09 +02:00
|
|
|
dst->image.frame_count = src->image.frame_count;
|
|
|
|
dst->image.current_frame = src->image.current_frame;
|
|
|
|
dst->image.format = src->image.format;
|
2010-02-24 23:59:50 +01:00
|
|
|
|
2012-06-25 13:30:34 +02:00
|
|
|
src->image.type = ~0;
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(src);
|
2010-02-24 23:59:50 +01:00
|
|
|
}
|
|
|
|
|
2012-06-20 06:45:39 +02:00
|
|
|
static GpStatus free_image_data(GpImage *image)
|
2007-07-25 02:19:18 +02:00
|
|
|
{
|
2007-08-01 04:14:57 +02:00
|
|
|
if(!image)
|
|
|
|
return InvalidParameter;
|
2007-07-25 02:19:18 +02:00
|
|
|
|
2008-03-07 10:19:03 +01:00
|
|
|
if (image->type == ImageTypeBitmap)
|
2009-08-28 22:05:38 +02:00
|
|
|
{
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(((GpBitmap*)image)->bitmapbits);
|
|
|
|
heap_free(((GpBitmap*)image)->own_bits);
|
2009-08-28 22:05:38 +02:00
|
|
|
DeleteDC(((GpBitmap*)image)->hdc);
|
2010-02-25 00:01:39 +01:00
|
|
|
DeleteObject(((GpBitmap*)image)->hbitmap);
|
2012-06-25 13:30:34 +02:00
|
|
|
if (((GpBitmap*)image)->metadata_reader)
|
|
|
|
IWICMetadataReader_Release(((GpBitmap*)image)->metadata_reader);
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(((GpBitmap*)image)->prop_item);
|
2009-08-28 22:05:38 +02:00
|
|
|
}
|
2011-06-21 19:48:11 +02:00
|
|
|
else if (image->type == ImageTypeMetafile)
|
2017-10-12 12:44:29 +02:00
|
|
|
METAFILE_Free((GpMetafile *)image);
|
2011-06-21 19:48:11 +02:00
|
|
|
else
|
2010-09-30 19:33:36 +02:00
|
|
|
{
|
|
|
|
WARN("invalid image: %p\n", image);
|
|
|
|
return ObjectBusy;
|
|
|
|
}
|
2015-03-12 10:17:03 +01:00
|
|
|
if (image->decoder)
|
|
|
|
IWICBitmapDecoder_Release(image->decoder);
|
2020-02-19 08:47:03 +01:00
|
|
|
terminate_encoder_wic(image);
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(image->palette);
|
2012-06-20 06:45:39 +02:00
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
|
|
|
|
{
|
|
|
|
GpStatus status;
|
|
|
|
|
|
|
|
TRACE("%p\n", image);
|
|
|
|
|
|
|
|
status = free_image_data(image);
|
|
|
|
if (status != Ok) return status;
|
2010-09-30 19:33:36 +02:00
|
|
|
image->type = ~0;
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(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)
|
|
|
|
{
|
2009-12-18 23:12:51 +01:00
|
|
|
static int calls;
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", image, item);
|
|
|
|
|
2007-08-01 04:15:33 +02:00
|
|
|
if(!image || !item)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2009-12-18 23:12:51 +01:00
|
|
|
if (!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
2007-08-01 04:15:33 +02:00
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2010-02-25 00:25:49 +01:00
|
|
|
GpStatus WINGDIPAPI GdipGetImageItemData(GpImage *image, ImageItemData *item)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", image, item);
|
|
|
|
|
|
|
|
if (!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
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{
|
2016-08-18 21:22:02 +02:00
|
|
|
WARN("GpImage with no image data\n");
|
|
|
|
return InvalidParameter;
|
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){
|
2012-08-15 05:04:52 +02:00
|
|
|
*height = units_to_pixels(((GpMetafile*)image)->bounds.Height, ((GpMetafile*)image)->unit, image->yres);
|
|
|
|
*width = units_to_pixels(((GpMetafile*)image)->bounds.Width, ((GpMetafile*)image)->unit, image->xres);
|
2008-02-27 10:36:44 +01:00
|
|
|
}
|
|
|
|
else if(image->type == ImageTypeBitmap){
|
|
|
|
*height = ((GpBitmap*)image)->height;
|
|
|
|
*width = ((GpBitmap*)image)->width;
|
|
|
|
}
|
|
|
|
else{
|
2016-08-18 21:22:02 +02:00
|
|
|
WARN("GpImage with no image data\n");
|
|
|
|
return InvalidParameter;
|
2008-02-27 10:36:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2010-03-29 03:05:04 +02:00
|
|
|
GpStatus stat;
|
2007-08-10 03:25:01 +02:00
|
|
|
|
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;
|
|
|
|
|
2011-04-02 00:09:23 +02:00
|
|
|
if (image->type == ImageTypeBitmap && ((GpBitmap*)image)->hbitmap)
|
2010-08-08 23:18:40 +02:00
|
|
|
{
|
|
|
|
hdc = ((GpBitmap*)image)->hdc;
|
2007-08-10 03:25:01 +02:00
|
|
|
|
2010-08-08 23:18:40 +02:00
|
|
|
if(!hdc){
|
|
|
|
hdc = CreateCompatibleDC(0);
|
|
|
|
SelectObject(hdc, ((GpBitmap*)image)->hbitmap);
|
|
|
|
((GpBitmap*)image)->hdc = hdc;
|
|
|
|
}
|
2007-08-10 03:25:01 +02:00
|
|
|
|
2010-08-08 23:18:40 +02:00
|
|
|
stat = GdipCreateFromHDC(hdc, graphics);
|
2010-03-29 03:05:04 +02:00
|
|
|
|
2010-08-08 23:18:40 +02:00
|
|
|
if (stat == Ok)
|
2012-07-24 10:18:48 +02:00
|
|
|
{
|
2010-08-08 23:18:40 +02:00
|
|
|
(*graphics)->image = image;
|
2012-07-24 10:18:48 +02:00
|
|
|
(*graphics)->xres = image->xres;
|
|
|
|
(*graphics)->yres = image->yres;
|
|
|
|
}
|
2010-08-08 23:18:40 +02:00
|
|
|
}
|
2011-04-02 00:09:23 +02:00
|
|
|
else if (image->type == ImageTypeMetafile)
|
|
|
|
stat = METAFILE_GetGraphicsContext((GpMetafile*)image, graphics);
|
2010-08-08 23:18:40 +02:00
|
|
|
else
|
|
|
|
stat = graphics_from_image(image, graphics);
|
2010-03-29 03:05:04 +02:00
|
|
|
|
|
|
|
return stat;
|
2007-08-10 03:25:01 +02:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2012-08-15 05:04:52 +02:00
|
|
|
if(image->type == ImageTypeMetafile)
|
|
|
|
*height = units_to_pixels(((GpMetafile*)image)->bounds.Height, ((GpMetafile*)image)->unit, image->yres);
|
2007-08-01 04:16:20 +02:00
|
|
|
else if(image->type == ImageTypeBitmap)
|
|
|
|
*height = ((GpBitmap*)image)->height;
|
|
|
|
else
|
2016-08-18 21:22:02 +02:00
|
|
|
{
|
|
|
|
WARN("GpImage with no image data\n");
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
if(!image || !res)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2009-12-27 02:46:55 +01:00
|
|
|
*res = image->xres;
|
2007-07-25 02:19:02 +02:00
|
|
|
|
2009-12-27 02:46:55 +01:00
|
|
|
TRACE("(%p) <-- %0.2f\n", image, *res);
|
|
|
|
|
|
|
|
return Ok;
|
2007-07-25 02:19:02 +02:00
|
|
|
}
|
|
|
|
|
2008-12-01 22:17:10 +01:00
|
|
|
GpStatus WINGDIPAPI GdipGetImagePaletteSize(GpImage *image, INT *size)
|
|
|
|
{
|
2009-12-11 23:56:08 +01:00
|
|
|
TRACE("%p %p\n", image, size);
|
2008-12-01 22:17:10 +01:00
|
|
|
|
|
|
|
if(!image || !size)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2020-05-15 03:51:10 +02:00
|
|
|
if (image->type == ImageTypeMetafile)
|
|
|
|
{
|
|
|
|
*size = 0;
|
|
|
|
return GenericError;
|
|
|
|
}
|
|
|
|
|
2012-07-17 07:59:43 +02:00
|
|
|
if (!image->palette || image->palette->Count == 0)
|
2009-12-11 23:56:08 +01:00
|
|
|
*size = sizeof(ColorPalette);
|
|
|
|
else
|
2012-07-17 07:59:43 +02:00
|
|
|
*size = sizeof(UINT)*2 + sizeof(ARGB)*image->palette->Count;
|
2009-12-11 23:56:08 +01:00
|
|
|
|
|
|
|
TRACE("<-- %u\n", *size);
|
|
|
|
|
|
|
|
return Ok;
|
2008-12-01 22:17:10 +01:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2010-06-25 11:26:53 +02:00
|
|
|
TRACE("(%p, %p)\n", image, format);
|
|
|
|
|
2007-07-25 02:19:02 +02:00
|
|
|
if(!image || !format)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2009-09-14 18:23:45 +02:00
|
|
|
memcpy(format, &image->format, sizeof(GUID));
|
2007-07-25 02:19:02 +02:00
|
|
|
|
2008-11-24 10:23:16 +01:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
if(!image || !res)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2009-12-27 02:46:55 +01:00
|
|
|
*res = image->yres;
|
2007-07-25 02:19:02 +02:00
|
|
|
|
2009-12-27 02:46:55 +01:00
|
|
|
TRACE("(%p) <-- %0.2f\n", image, *res);
|
|
|
|
|
|
|
|
return Ok;
|
2007-07-25 02:19:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2012-08-15 05:04:52 +02:00
|
|
|
if(image->type == ImageTypeMetafile)
|
|
|
|
*width = units_to_pixels(((GpMetafile*)image)->bounds.Width, ((GpMetafile*)image)->unit, image->xres);
|
2007-08-01 04:16:20 +02:00
|
|
|
else if(image->type == ImageTypeBitmap)
|
|
|
|
*width = ((GpBitmap*)image)->width;
|
|
|
|
else
|
2016-08-18 21:22:02 +02:00
|
|
|
{
|
|
|
|
WARN("GpImage with no image data\n");
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2012-06-25 13:30:43 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetPropertyCount(GpImage *image, UINT *num)
|
2008-09-07 23:25:04 +02:00
|
|
|
{
|
2010-06-25 11:26:53 +02:00
|
|
|
TRACE("(%p, %p)\n", image, num);
|
|
|
|
|
2012-06-25 13:30:43 +02:00
|
|
|
if (!image || !num) return InvalidParameter;
|
2008-09-07 23:25:04 +02:00
|
|
|
|
2011-10-06 20:45:26 +02:00
|
|
|
*num = 0;
|
2012-06-25 13:30:43 +02:00
|
|
|
|
|
|
|
if (image->type == ImageTypeBitmap)
|
|
|
|
{
|
2012-09-21 12:58:20 +02:00
|
|
|
if (((GpBitmap *)image)->prop_item)
|
|
|
|
{
|
|
|
|
*num = ((GpBitmap *)image)->prop_count;
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2012-06-25 13:30:43 +02:00
|
|
|
if (((GpBitmap *)image)->metadata_reader)
|
|
|
|
IWICMetadataReader_GetCount(((GpBitmap *)image)->metadata_reader, num);
|
|
|
|
}
|
|
|
|
|
2011-10-06 20:45:26 +02:00
|
|
|
return Ok;
|
2008-09-07 23:25:04 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 13:30:50 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetPropertyIdList(GpImage *image, UINT num, PROPID *list)
|
2008-09-07 23:25:04 +02:00
|
|
|
{
|
2012-06-25 13:30:50 +02:00
|
|
|
HRESULT hr;
|
|
|
|
IWICMetadataReader *reader;
|
|
|
|
IWICEnumMetadataItem *enumerator;
|
|
|
|
UINT prop_count, i, items_returned;
|
2008-09-07 23:25:04 +02:00
|
|
|
|
2010-06-25 11:26:53 +02:00
|
|
|
TRACE("(%p, %u, %p)\n", image, num, list);
|
|
|
|
|
2012-06-25 13:30:50 +02:00
|
|
|
if (!image || !list) return InvalidParameter;
|
2008-09-07 23:25:04 +02:00
|
|
|
|
2012-06-25 13:30:50 +02:00
|
|
|
if (image->type != ImageTypeBitmap)
|
|
|
|
{
|
|
|
|
FIXME("Not implemented for type %d\n", image->type);
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2012-09-21 12:58:20 +02:00
|
|
|
if (((GpBitmap *)image)->prop_item)
|
|
|
|
{
|
|
|
|
if (num != ((GpBitmap *)image)->prop_count) return InvalidParameter;
|
|
|
|
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
list[i] = ((GpBitmap *)image)->prop_item[i].id;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2012-06-25 13:30:50 +02:00
|
|
|
reader = ((GpBitmap *)image)->metadata_reader;
|
|
|
|
if (!reader)
|
|
|
|
{
|
|
|
|
if (num != 0) return InvalidParameter;
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IWICMetadataReader_GetCount(reader, &prop_count);
|
|
|
|
if (FAILED(hr)) return hresult_to_status(hr);
|
|
|
|
|
|
|
|
if (num != prop_count) return InvalidParameter;
|
|
|
|
|
|
|
|
hr = IWICMetadataReader_GetEnumerator(reader, &enumerator);
|
|
|
|
if (FAILED(hr)) return hresult_to_status(hr);
|
|
|
|
|
|
|
|
IWICEnumMetadataItem_Reset(enumerator);
|
|
|
|
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
PROPVARIANT id;
|
|
|
|
|
|
|
|
hr = IWICEnumMetadataItem_Next(enumerator, 1, NULL, &id, NULL, &items_returned);
|
|
|
|
if (hr != S_OK) break;
|
|
|
|
|
|
|
|
if (id.vt != VT_UI2)
|
|
|
|
{
|
|
|
|
FIXME("not supported propvariant type for id: %u\n", id.vt);
|
|
|
|
list[i] = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
list[i] = id.u.uiVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
IWICEnumMetadataItem_Release(enumerator);
|
|
|
|
|
|
|
|
return hr == S_OK ? Ok : hresult_to_status(hr);
|
2008-09-07 23:25:04 +02:00
|
|
|
}
|
|
|
|
|
2012-06-28 06:25:57 +02:00
|
|
|
static UINT propvariant_size(PROPVARIANT *value)
|
2007-08-01 04:15:56 +02:00
|
|
|
{
|
2012-06-28 06:25:57 +02:00
|
|
|
switch (value->vt & ~VT_VECTOR)
|
|
|
|
{
|
|
|
|
case VT_EMPTY:
|
|
|
|
return 0;
|
|
|
|
case VT_I1:
|
|
|
|
case VT_UI1:
|
|
|
|
if (!(value->vt & VT_VECTOR)) return 1;
|
|
|
|
return value->u.caub.cElems;
|
|
|
|
case VT_I2:
|
|
|
|
case VT_UI2:
|
|
|
|
if (!(value->vt & VT_VECTOR)) return 2;
|
|
|
|
return value->u.caui.cElems * 2;
|
|
|
|
case VT_I4:
|
|
|
|
case VT_UI4:
|
|
|
|
case VT_R4:
|
|
|
|
if (!(value->vt & VT_VECTOR)) return 4;
|
|
|
|
return value->u.caul.cElems * 4;
|
|
|
|
case VT_I8:
|
|
|
|
case VT_UI8:
|
|
|
|
case VT_R8:
|
|
|
|
if (!(value->vt & VT_VECTOR)) return 8;
|
|
|
|
return value->u.cauh.cElems * 8;
|
|
|
|
case VT_LPSTR:
|
|
|
|
return value->u.pszVal ? strlen(value->u.pszVal) + 1 : 0;
|
|
|
|
case VT_BLOB:
|
|
|
|
return value->u.blob.cbSize;
|
|
|
|
default:
|
|
|
|
FIXME("not supported variant type %d\n", value->vt);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2007-08-01 04:15:56 +02:00
|
|
|
|
2012-06-28 06:25:57 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetPropertyItemSize(GpImage *image, PROPID propid, UINT *size)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IWICMetadataReader *reader;
|
|
|
|
PROPVARIANT id, value;
|
2007-08-01 04:15:56 +02:00
|
|
|
|
2012-06-28 06:25:57 +02:00
|
|
|
TRACE("(%p,%#x,%p)\n", image, propid, size);
|
2007-08-01 04:15:56 +02:00
|
|
|
|
2012-06-28 06:25:57 +02:00
|
|
|
if (!size || !image) return InvalidParameter;
|
2007-08-01 04:15:56 +02:00
|
|
|
|
2012-06-28 06:25:57 +02:00
|
|
|
if (image->type != ImageTypeBitmap)
|
|
|
|
{
|
|
|
|
FIXME("Not implemented for type %d\n", image->type);
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2012-09-21 12:58:20 +02:00
|
|
|
if (((GpBitmap *)image)->prop_item)
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
for (i = 0; i < ((GpBitmap *)image)->prop_count; i++)
|
|
|
|
{
|
|
|
|
if (propid == ((GpBitmap *)image)->prop_item[i].id)
|
|
|
|
{
|
|
|
|
*size = sizeof(PropertyItem) + ((GpBitmap *)image)->prop_item[i].length;
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PropertyNotFound;
|
|
|
|
}
|
|
|
|
|
2012-06-28 06:25:57 +02:00
|
|
|
reader = ((GpBitmap *)image)->metadata_reader;
|
|
|
|
if (!reader) return PropertyNotFound;
|
|
|
|
|
|
|
|
id.vt = VT_UI2;
|
|
|
|
id.u.uiVal = propid;
|
|
|
|
hr = IWICMetadataReader_GetValue(reader, NULL, &id, &value);
|
|
|
|
if (FAILED(hr)) return PropertyNotFound;
|
|
|
|
|
|
|
|
*size = propvariant_size(&value);
|
|
|
|
if (*size) *size += sizeof(PropertyItem);
|
|
|
|
PropVariantClear(&value);
|
|
|
|
|
|
|
|
return Ok;
|
2007-08-01 04:15:56 +02:00
|
|
|
}
|
|
|
|
|
2012-06-28 06:26:49 +02:00
|
|
|
#ifndef PropertyTagTypeSByte
|
|
|
|
#define PropertyTagTypeSByte 6
|
|
|
|
#define PropertyTagTypeSShort 8
|
|
|
|
#define PropertyTagTypeFloat 11
|
|
|
|
#define PropertyTagTypeDouble 12
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static UINT vt_to_itemtype(UINT vt)
|
|
|
|
{
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
UINT vt, type;
|
|
|
|
} vt2type[] =
|
|
|
|
{
|
|
|
|
{ VT_I1, PropertyTagTypeSByte },
|
|
|
|
{ VT_UI1, PropertyTagTypeByte },
|
|
|
|
{ VT_I2, PropertyTagTypeSShort },
|
|
|
|
{ VT_UI2, PropertyTagTypeShort },
|
|
|
|
{ VT_I4, PropertyTagTypeSLONG },
|
|
|
|
{ VT_UI4, PropertyTagTypeLong },
|
|
|
|
{ VT_I8, PropertyTagTypeSRational },
|
|
|
|
{ VT_UI8, PropertyTagTypeRational },
|
|
|
|
{ VT_R4, PropertyTagTypeFloat },
|
|
|
|
{ VT_R8, PropertyTagTypeDouble },
|
|
|
|
{ VT_LPSTR, PropertyTagTypeASCII },
|
|
|
|
{ VT_BLOB, PropertyTagTypeUndefined }
|
|
|
|
};
|
|
|
|
UINT i;
|
2018-05-14 06:59:34 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(vt2type); i++)
|
2012-06-28 06:26:49 +02:00
|
|
|
{
|
|
|
|
if (vt2type[i].vt == vt) return vt2type[i].type;
|
|
|
|
}
|
|
|
|
FIXME("not supported variant type %u\n", vt);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GpStatus propvariant_to_item(PROPVARIANT *value, PropertyItem *item,
|
|
|
|
UINT size, PROPID id)
|
|
|
|
{
|
|
|
|
UINT item_size, item_type;
|
|
|
|
|
|
|
|
item_size = propvariant_size(value);
|
|
|
|
if (size != item_size + sizeof(PropertyItem)) return InvalidParameter;
|
|
|
|
|
|
|
|
item_type = vt_to_itemtype(value->vt & ~VT_VECTOR);
|
|
|
|
if (!item_type) return InvalidParameter;
|
|
|
|
|
|
|
|
item->value = item + 1;
|
|
|
|
|
|
|
|
switch (value->vt & ~VT_VECTOR)
|
|
|
|
{
|
|
|
|
case VT_I1:
|
|
|
|
case VT_UI1:
|
|
|
|
if (!(value->vt & VT_VECTOR))
|
|
|
|
*(BYTE *)item->value = value->u.bVal;
|
|
|
|
else
|
|
|
|
memcpy(item->value, value->u.caub.pElems, item_size);
|
|
|
|
break;
|
|
|
|
case VT_I2:
|
|
|
|
case VT_UI2:
|
|
|
|
if (!(value->vt & VT_VECTOR))
|
|
|
|
*(USHORT *)item->value = value->u.uiVal;
|
|
|
|
else
|
|
|
|
memcpy(item->value, value->u.caui.pElems, item_size);
|
|
|
|
break;
|
|
|
|
case VT_I4:
|
|
|
|
case VT_UI4:
|
|
|
|
case VT_R4:
|
|
|
|
if (!(value->vt & VT_VECTOR))
|
|
|
|
*(ULONG *)item->value = value->u.ulVal;
|
|
|
|
else
|
|
|
|
memcpy(item->value, value->u.caul.pElems, item_size);
|
|
|
|
break;
|
|
|
|
case VT_I8:
|
|
|
|
case VT_UI8:
|
|
|
|
case VT_R8:
|
|
|
|
if (!(value->vt & VT_VECTOR))
|
|
|
|
*(ULONGLONG *)item->value = value->u.uhVal.QuadPart;
|
|
|
|
else
|
|
|
|
memcpy(item->value, value->u.cauh.pElems, item_size);
|
|
|
|
break;
|
|
|
|
case VT_LPSTR:
|
|
|
|
memcpy(item->value, value->u.pszVal, item_size);
|
|
|
|
break;
|
|
|
|
case VT_BLOB:
|
|
|
|
memcpy(item->value, value->u.blob.pBlobData, item_size);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("not supported variant type %d\n", value->vt);
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|
|
|
|
|
|
|
|
item->length = item_size;
|
|
|
|
item->type = item_type;
|
|
|
|
item->id = id;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipGetPropertyItem(GpImage *image, PROPID propid, UINT size,
|
|
|
|
PropertyItem *buffer)
|
|
|
|
{
|
|
|
|
GpStatus stat;
|
|
|
|
HRESULT hr;
|
|
|
|
IWICMetadataReader *reader;
|
|
|
|
PROPVARIANT id, value;
|
|
|
|
|
|
|
|
TRACE("(%p,%#x,%u,%p)\n", image, propid, size, buffer);
|
|
|
|
|
|
|
|
if (!image || !buffer) return InvalidParameter;
|
|
|
|
|
|
|
|
if (image->type != ImageTypeBitmap)
|
|
|
|
{
|
|
|
|
FIXME("Not implemented for type %d\n", image->type);
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2012-09-21 12:58:20 +02:00
|
|
|
if (((GpBitmap *)image)->prop_item)
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
for (i = 0; i < ((GpBitmap *)image)->prop_count; i++)
|
|
|
|
{
|
|
|
|
if (propid == ((GpBitmap *)image)->prop_item[i].id)
|
|
|
|
{
|
|
|
|
if (size != sizeof(PropertyItem) + ((GpBitmap *)image)->prop_item[i].length)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
*buffer = ((GpBitmap *)image)->prop_item[i];
|
|
|
|
buffer->value = buffer + 1;
|
|
|
|
memcpy(buffer->value, ((GpBitmap *)image)->prop_item[i].value, buffer->length);
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PropertyNotFound;
|
|
|
|
}
|
|
|
|
|
2012-06-28 06:26:49 +02:00
|
|
|
reader = ((GpBitmap *)image)->metadata_reader;
|
|
|
|
if (!reader) return PropertyNotFound;
|
|
|
|
|
|
|
|
id.vt = VT_UI2;
|
|
|
|
id.u.uiVal = propid;
|
|
|
|
hr = IWICMetadataReader_GetValue(reader, NULL, &id, &value);
|
|
|
|
if (FAILED(hr)) return PropertyNotFound;
|
|
|
|
|
|
|
|
stat = propvariant_to_item(&value, buffer, size, propid);
|
|
|
|
PropVariantClear(&value);
|
|
|
|
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2012-07-02 05:58:48 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetPropertySize(GpImage *image, UINT *size, UINT *count)
|
2008-09-07 23:25:04 +02:00
|
|
|
{
|
2012-07-02 05:58:48 +02:00
|
|
|
HRESULT hr;
|
|
|
|
IWICMetadataReader *reader;
|
|
|
|
IWICEnumMetadataItem *enumerator;
|
|
|
|
UINT prop_count, prop_size, i;
|
|
|
|
PROPVARIANT id, value;
|
2008-09-07 23:25:04 +02:00
|
|
|
|
2012-07-02 05:58:48 +02:00
|
|
|
TRACE("(%p,%p,%p)\n", image, size, count);
|
2009-12-18 23:12:51 +01:00
|
|
|
|
2012-07-02 05:58:48 +02:00
|
|
|
if (!image || !size || !count) return InvalidParameter;
|
2008-09-07 23:25:04 +02:00
|
|
|
|
2012-07-02 05:58:48 +02:00
|
|
|
if (image->type != ImageTypeBitmap)
|
|
|
|
{
|
|
|
|
FIXME("Not implemented for type %d\n", image->type);
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2012-09-21 12:58:20 +02:00
|
|
|
if (((GpBitmap *)image)->prop_item)
|
|
|
|
{
|
|
|
|
*count = ((GpBitmap *)image)->prop_count;
|
|
|
|
*size = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < ((GpBitmap *)image)->prop_count; i++)
|
|
|
|
{
|
|
|
|
*size += sizeof(PropertyItem) + ((GpBitmap *)image)->prop_item[i].length;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2012-07-02 05:58:48 +02:00
|
|
|
reader = ((GpBitmap *)image)->metadata_reader;
|
|
|
|
if (!reader) return PropertyNotFound;
|
|
|
|
|
|
|
|
hr = IWICMetadataReader_GetCount(reader, &prop_count);
|
|
|
|
if (FAILED(hr)) return hresult_to_status(hr);
|
|
|
|
|
|
|
|
hr = IWICMetadataReader_GetEnumerator(reader, &enumerator);
|
|
|
|
if (FAILED(hr)) return hresult_to_status(hr);
|
|
|
|
|
|
|
|
IWICEnumMetadataItem_Reset(enumerator);
|
|
|
|
|
|
|
|
prop_size = 0;
|
|
|
|
|
|
|
|
PropVariantInit(&id);
|
|
|
|
PropVariantInit(&value);
|
|
|
|
|
|
|
|
for (i = 0; i < prop_count; i++)
|
|
|
|
{
|
|
|
|
UINT items_returned, item_size;
|
|
|
|
|
|
|
|
hr = IWICEnumMetadataItem_Next(enumerator, 1, NULL, &id, &value, &items_returned);
|
|
|
|
if (hr != S_OK) break;
|
|
|
|
|
|
|
|
item_size = propvariant_size(&value);
|
|
|
|
if (item_size) prop_size += sizeof(PropertyItem) + item_size;
|
|
|
|
|
|
|
|
PropVariantClear(&id);
|
|
|
|
PropVariantClear(&value);
|
|
|
|
}
|
|
|
|
|
|
|
|
IWICEnumMetadataItem_Release(enumerator);
|
|
|
|
|
|
|
|
if (hr != S_OK) return PropertyNotFound;
|
|
|
|
|
|
|
|
*count = prop_count;
|
|
|
|
*size = prop_size;
|
|
|
|
return Ok;
|
2008-09-07 23:25:04 +02:00
|
|
|
}
|
|
|
|
|
2012-07-02 05:59:27 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetAllPropertyItems(GpImage *image, UINT size,
|
|
|
|
UINT count, PropertyItem *buf)
|
|
|
|
{
|
|
|
|
GpStatus status;
|
|
|
|
HRESULT hr;
|
|
|
|
IWICMetadataReader *reader;
|
|
|
|
IWICEnumMetadataItem *enumerator;
|
|
|
|
UINT prop_count, prop_size, i;
|
|
|
|
PROPVARIANT id, value;
|
|
|
|
char *item_value;
|
|
|
|
|
|
|
|
TRACE("(%p,%u,%u,%p)\n", image, size, count, buf);
|
|
|
|
|
|
|
|
if (!image || !buf) return InvalidParameter;
|
|
|
|
|
|
|
|
if (image->type != ImageTypeBitmap)
|
|
|
|
{
|
|
|
|
FIXME("Not implemented for type %d\n", image->type);
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = GdipGetPropertySize(image, &prop_size, &prop_count);
|
|
|
|
if (status != Ok) return status;
|
|
|
|
|
|
|
|
if (prop_count != count || prop_size != size) return InvalidParameter;
|
|
|
|
|
2012-09-21 12:58:20 +02:00
|
|
|
if (((GpBitmap *)image)->prop_item)
|
|
|
|
{
|
|
|
|
memcpy(buf, ((GpBitmap *)image)->prop_item, prop_size);
|
|
|
|
|
|
|
|
item_value = (char *)(buf + prop_count);
|
|
|
|
|
|
|
|
for (i = 0; i < prop_count; i++)
|
|
|
|
{
|
|
|
|
buf[i].value = item_value;
|
|
|
|
item_value += buf[i].length;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2012-07-02 05:59:27 +02:00
|
|
|
reader = ((GpBitmap *)image)->metadata_reader;
|
|
|
|
if (!reader) return PropertyNotFound;
|
|
|
|
|
|
|
|
hr = IWICMetadataReader_GetEnumerator(reader, &enumerator);
|
|
|
|
if (FAILED(hr)) return hresult_to_status(hr);
|
|
|
|
|
|
|
|
IWICEnumMetadataItem_Reset(enumerator);
|
|
|
|
|
|
|
|
item_value = (char *)(buf + prop_count);
|
|
|
|
|
|
|
|
PropVariantInit(&id);
|
|
|
|
PropVariantInit(&value);
|
|
|
|
|
|
|
|
for (i = 0; i < prop_count; i++)
|
|
|
|
{
|
|
|
|
PropertyItem *item;
|
|
|
|
UINT items_returned, item_size;
|
|
|
|
|
|
|
|
hr = IWICEnumMetadataItem_Next(enumerator, 1, NULL, &id, &value, &items_returned);
|
|
|
|
if (hr != S_OK) break;
|
|
|
|
|
|
|
|
if (id.vt != VT_UI2)
|
|
|
|
{
|
|
|
|
FIXME("not supported propvariant type for id: %u\n", id.vt);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
item_size = propvariant_size(&value);
|
|
|
|
if (item_size)
|
|
|
|
{
|
2015-10-21 00:53:12 +02:00
|
|
|
item = heap_alloc(item_size + sizeof(*item));
|
2012-07-02 05:59:27 +02:00
|
|
|
|
|
|
|
propvariant_to_item(&value, item, item_size + sizeof(*item), id.u.uiVal);
|
|
|
|
buf[i].id = item->id;
|
|
|
|
buf[i].type = item->type;
|
|
|
|
buf[i].length = item_size;
|
|
|
|
buf[i].value = item_value;
|
|
|
|
memcpy(item_value, item->value, item_size);
|
|
|
|
item_value += item_size;
|
|
|
|
|
2015-10-21 00:53:48 +02:00
|
|
|
heap_free(item);
|
2012-07-02 05:59:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PropVariantClear(&id);
|
|
|
|
PropVariantClear(&value);
|
|
|
|
}
|
|
|
|
|
|
|
|
IWICEnumMetadataItem_Release(enumerator);
|
|
|
|
|
|
|
|
if (hr != S_OK) return PropertyNotFound;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2009-12-24 22:04:32 +01:00
|
|
|
struct image_format_dimension
|
|
|
|
{
|
|
|
|
const GUID *format;
|
|
|
|
const GUID *dimension;
|
|
|
|
};
|
|
|
|
|
2012-06-21 06:30:57 +02:00
|
|
|
static const struct image_format_dimension image_format_dimensions[] =
|
2009-12-24 22:04:32 +01:00
|
|
|
{
|
|
|
|
{&ImageFormatGIF, &FrameDimensionTime},
|
|
|
|
{&ImageFormatIcon, &FrameDimensionResolution},
|
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
|
2007-07-25 02:19:02 +02:00
|
|
|
GpStatus WINGDIPAPI GdipImageGetFrameCount(GpImage *image,
|
|
|
|
GDIPCONST GUID* dimensionID, UINT* count)
|
|
|
|
{
|
2009-12-18 23:12:51 +01:00
|
|
|
TRACE("(%p,%s,%p)\n", image, debugstr_guid(dimensionID), count);
|
|
|
|
|
2010-03-16 00:14:28 +01:00
|
|
|
if(!image || !count)
|
2007-07-25 02:19:02 +02:00
|
|
|
return InvalidParameter;
|
|
|
|
|
2012-05-16 16:33:55 +02:00
|
|
|
if (!dimensionID ||
|
|
|
|
IsEqualGUID(dimensionID, &image->format) ||
|
|
|
|
IsEqualGUID(dimensionID, &FrameDimensionPage) ||
|
|
|
|
IsEqualGUID(dimensionID, &FrameDimensionTime))
|
|
|
|
{
|
|
|
|
*count = image->frame_count;
|
|
|
|
return Ok;
|
|
|
|
}
|
2010-03-16 00:14:28 +01:00
|
|
|
|
2012-05-16 16:33:55 +02:00
|
|
|
return InvalidParameter;
|
2007-07-25 02:19:02 +02:00
|
|
|
}
|
2007-07-25 02:19:21 +02:00
|
|
|
|
2008-06-19 10:38:09 +02:00
|
|
|
GpStatus WINGDIPAPI GdipImageGetFrameDimensionsCount(GpImage *image,
|
|
|
|
UINT* count)
|
|
|
|
{
|
2010-06-25 11:26:53 +02:00
|
|
|
TRACE("(%p, %p)\n", image, count);
|
|
|
|
|
2009-12-24 21:52:02 +01:00
|
|
|
/* Native gdiplus 1.1 does not yet support multiple frame dimensions. */
|
|
|
|
|
2008-06-19 10:38:09 +02:00
|
|
|
if(!image || !count)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
*count = 1;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-08-04 02:30:26 +02:00
|
|
|
GpStatus WINGDIPAPI GdipImageGetFrameDimensionsList(GpImage* image,
|
|
|
|
GUID* dimensionIDs, UINT count)
|
|
|
|
{
|
2009-12-24 22:04:32 +01:00
|
|
|
int i;
|
|
|
|
const GUID *result=NULL;
|
2007-08-04 02:30:26 +02:00
|
|
|
|
2009-12-24 22:04:32 +01:00
|
|
|
TRACE("(%p,%p,%u)\n", image, dimensionIDs, count);
|
|
|
|
|
|
|
|
if(!image || !dimensionIDs || count != 1)
|
2007-08-04 02:30:26 +02:00
|
|
|
return InvalidParameter;
|
|
|
|
|
2009-12-24 22:04:32 +01:00
|
|
|
for (i=0; image_format_dimensions[i].format; i++)
|
|
|
|
{
|
|
|
|
if (IsEqualGUID(&image->format, image_format_dimensions[i].format))
|
|
|
|
{
|
|
|
|
result = image_format_dimensions[i].dimension;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
result = &FrameDimensionPage;
|
|
|
|
|
|
|
|
memcpy(dimensionIDs, result, sizeof(GUID));
|
2007-08-04 02:30:26 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2014-07-11 09:55:53 +02:00
|
|
|
*image = NULL;
|
|
|
|
|
2008-02-24 16:41:29 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-09-25 05:51:23 +02:00
|
|
|
static void add_property(GpBitmap *bitmap, PropertyItem *item)
|
2012-09-21 12:58:20 +02:00
|
|
|
{
|
2012-09-25 05:51:23 +02:00
|
|
|
UINT prop_size, prop_count;
|
|
|
|
PropertyItem *prop_item;
|
|
|
|
|
|
|
|
if (bitmap->prop_item == NULL)
|
|
|
|
{
|
|
|
|
prop_size = prop_count = 0;
|
2015-10-05 00:22:34 +02:00
|
|
|
prop_item = heap_alloc_zero(item->length + sizeof(PropertyItem));
|
2012-09-25 05:51:23 +02:00
|
|
|
if (!prop_item) return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
char *item_value;
|
|
|
|
|
2016-08-05 08:32:46 +02:00
|
|
|
GdipGetPropertySize(&bitmap->image, &prop_size, &prop_count);
|
2012-09-25 05:51:23 +02:00
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
prop_item = heap_alloc_zero(prop_size + item->length + sizeof(PropertyItem));
|
2012-09-25 05:51:23 +02:00
|
|
|
if (!prop_item) return;
|
|
|
|
memcpy(prop_item, bitmap->prop_item, sizeof(PropertyItem) * bitmap->prop_count);
|
|
|
|
prop_size -= sizeof(PropertyItem) * bitmap->prop_count;
|
|
|
|
memcpy(prop_item + prop_count + 1, bitmap->prop_item + prop_count, prop_size);
|
|
|
|
|
|
|
|
item_value = (char *)(prop_item + prop_count + 1);
|
|
|
|
|
|
|
|
for (i = 0; i < prop_count; i++)
|
|
|
|
{
|
|
|
|
prop_item[i].value = item_value;
|
|
|
|
item_value += prop_item[i].length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
prop_item[prop_count].id = item->id;
|
|
|
|
prop_item[prop_count].type = item->type;
|
|
|
|
prop_item[prop_count].length = item->length;
|
|
|
|
prop_item[prop_count].value = (char *)(prop_item + prop_count + 1) + prop_size;
|
|
|
|
memcpy(prop_item[prop_count].value, item->value, item->length);
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(bitmap->prop_item);
|
2012-09-25 05:51:23 +02:00
|
|
|
bitmap->prop_item = prop_item;
|
|
|
|
bitmap->prop_count++;
|
|
|
|
}
|
|
|
|
|
2012-09-25 05:54:01 +02:00
|
|
|
static BOOL get_bool_property(IWICMetadataReader *reader, const GUID *guid, const WCHAR *prop_name)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
GUID format;
|
|
|
|
PROPVARIANT id, value;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
2015-06-27 13:29:37 +02:00
|
|
|
hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
|
|
|
|
if (FAILED(hr) || !IsEqualGUID(&format, guid)) return FALSE;
|
2012-09-25 05:54:01 +02:00
|
|
|
|
|
|
|
PropVariantInit(&id);
|
|
|
|
PropVariantInit(&value);
|
|
|
|
|
|
|
|
id.vt = VT_LPWSTR;
|
2015-10-21 00:52:51 +02:00
|
|
|
id.u.pwszVal = CoTaskMemAlloc((lstrlenW(prop_name) + 1) * sizeof(WCHAR));
|
2012-09-25 05:54:01 +02:00
|
|
|
if (!id.u.pwszVal) return FALSE;
|
|
|
|
lstrcpyW(id.u.pwszVal, prop_name);
|
|
|
|
hr = IWICMetadataReader_GetValue(reader, NULL, &id, &value);
|
|
|
|
if (hr == S_OK && value.vt == VT_BOOL)
|
|
|
|
ret = value.u.boolVal;
|
|
|
|
|
|
|
|
PropVariantClear(&id);
|
|
|
|
PropVariantClear(&value);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-09-25 05:51:23 +02:00
|
|
|
static PropertyItem *get_property(IWICMetadataReader *reader, const GUID *guid, const WCHAR *prop_name)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
GUID format;
|
|
|
|
PROPVARIANT id, value;
|
|
|
|
PropertyItem *item = NULL;
|
|
|
|
|
2015-06-27 13:29:37 +02:00
|
|
|
hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
|
|
|
|
if (FAILED(hr) || !IsEqualGUID(&format, guid)) return NULL;
|
2012-09-25 05:51:23 +02:00
|
|
|
|
|
|
|
PropVariantInit(&id);
|
|
|
|
PropVariantInit(&value);
|
|
|
|
|
|
|
|
id.vt = VT_LPWSTR;
|
2015-10-21 00:52:51 +02:00
|
|
|
id.u.pwszVal = CoTaskMemAlloc((lstrlenW(prop_name) + 1) * sizeof(WCHAR));
|
2012-09-25 05:51:23 +02:00
|
|
|
if (!id.u.pwszVal) return NULL;
|
|
|
|
lstrcpyW(id.u.pwszVal, prop_name);
|
|
|
|
hr = IWICMetadataReader_GetValue(reader, NULL, &id, &value);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
UINT item_size = propvariant_size(&value);
|
|
|
|
if (item_size)
|
|
|
|
{
|
|
|
|
item_size += sizeof(*item);
|
2015-10-05 00:22:34 +02:00
|
|
|
item = heap_alloc_zero(item_size);
|
2012-09-25 05:51:23 +02:00
|
|
|
if (propvariant_to_item(&value, item, item_size, 0) != Ok)
|
|
|
|
{
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(item);
|
2012-09-25 05:51:23 +02:00
|
|
|
item = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PropVariantClear(&id);
|
|
|
|
PropVariantClear(&value);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PropertyItem *get_gif_comment(IWICMetadataReader *reader)
|
|
|
|
{
|
|
|
|
PropertyItem *comment;
|
|
|
|
|
2020-11-13 00:20:30 +01:00
|
|
|
comment = get_property(reader, &GUID_MetadataFormatGifComment, L"TextEntry");
|
2012-09-25 05:51:23 +02:00
|
|
|
if (comment)
|
|
|
|
comment->id = PropertyTagExifUserComment;
|
|
|
|
|
|
|
|
return comment;
|
|
|
|
}
|
|
|
|
|
2012-09-25 05:55:04 +02:00
|
|
|
static PropertyItem *get_gif_loopcount(IWICMetadataReader *reader)
|
|
|
|
{
|
|
|
|
PropertyItem *appext = NULL, *appdata = NULL, *loop = NULL;
|
|
|
|
|
2020-11-13 00:20:30 +01:00
|
|
|
appext = get_property(reader, &GUID_MetadataFormatAPE, L"Application");
|
2012-09-25 05:55:04 +02:00
|
|
|
if (appext)
|
|
|
|
{
|
|
|
|
if (appext->type == PropertyTagTypeByte && appext->length == 11 &&
|
|
|
|
(!memcmp(appext->value, "NETSCAPE2.0", 11) || !memcmp(appext->value, "ANIMEXTS1.0", 11)))
|
|
|
|
{
|
2020-11-13 00:20:30 +01:00
|
|
|
appdata = get_property(reader, &GUID_MetadataFormatAPE, L"Data");
|
2012-09-25 05:55:04 +02:00
|
|
|
if (appdata)
|
|
|
|
{
|
|
|
|
if (appdata->type == PropertyTagTypeByte && appdata->length == 4)
|
|
|
|
{
|
|
|
|
BYTE *data = appdata->value;
|
|
|
|
if (data[0] == 3 && data[1] == 1)
|
|
|
|
{
|
2015-10-05 00:22:34 +02:00
|
|
|
loop = heap_alloc_zero(sizeof(*loop) + sizeof(SHORT));
|
2012-09-25 05:55:04 +02:00
|
|
|
if (loop)
|
|
|
|
{
|
|
|
|
loop->type = PropertyTagTypeShort;
|
|
|
|
loop->id = PropertyTagLoopCount;
|
|
|
|
loop->length = sizeof(SHORT);
|
|
|
|
loop->value = loop + 1;
|
|
|
|
*(SHORT *)loop->value = data[2] | (data[3] << 8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(appext);
|
|
|
|
heap_free(appdata);
|
2012-09-25 05:55:04 +02:00
|
|
|
|
|
|
|
return loop;
|
|
|
|
}
|
|
|
|
|
2012-09-25 05:53:08 +02:00
|
|
|
static PropertyItem *get_gif_background(IWICMetadataReader *reader)
|
|
|
|
{
|
|
|
|
PropertyItem *background;
|
|
|
|
|
2020-11-13 00:20:30 +01:00
|
|
|
background = get_property(reader, &GUID_MetadataFormatLSD, L"BackgroundColorIndex");
|
2012-09-25 05:53:08 +02:00
|
|
|
if (background)
|
|
|
|
background->id = PropertyTagIndexBackground;
|
|
|
|
|
|
|
|
return background;
|
|
|
|
}
|
|
|
|
|
2012-09-25 05:55:57 +02:00
|
|
|
static PropertyItem *get_gif_palette(IWICBitmapDecoder *decoder, IWICMetadataReader *reader)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IWICImagingFactory *factory;
|
|
|
|
IWICPalette *palette;
|
|
|
|
UINT count = 0;
|
|
|
|
WICColor colors[256];
|
|
|
|
|
2020-11-13 00:20:30 +01:00
|
|
|
if (!get_bool_property(reader, &GUID_MetadataFormatLSD, L"GlobalColorTableFlag"))
|
2012-09-25 05:55:57 +02:00
|
|
|
return NULL;
|
|
|
|
|
2015-03-06 11:20:43 +01:00
|
|
|
hr = WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION, &factory);
|
2012-09-25 05:55:57 +02:00
|
|
|
if (hr != S_OK) return NULL;
|
|
|
|
|
|
|
|
hr = IWICImagingFactory_CreatePalette(factory, &palette);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
|
|
|
|
if (hr == S_OK)
|
|
|
|
IWICPalette_GetColors(palette, 256, colors, &count);
|
|
|
|
|
|
|
|
IWICPalette_Release(palette);
|
|
|
|
}
|
|
|
|
|
|
|
|
IWICImagingFactory_Release(factory);
|
|
|
|
|
|
|
|
if (count)
|
|
|
|
{
|
|
|
|
PropertyItem *pal;
|
|
|
|
UINT i;
|
|
|
|
BYTE *rgb;
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
pal = heap_alloc_zero(sizeof(*pal) + count * 3);
|
2012-09-25 05:55:57 +02:00
|
|
|
if (!pal) return NULL;
|
|
|
|
pal->type = PropertyTagTypeByte;
|
|
|
|
pal->id = PropertyTagGlobalPalette;
|
|
|
|
pal->value = pal + 1;
|
|
|
|
pal->length = count * 3;
|
|
|
|
|
|
|
|
rgb = pal->value;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
rgb[i*3] = (colors[i] >> 16) & 0xff;
|
|
|
|
rgb[i*3 + 1] = (colors[i] >> 8) & 0xff;
|
|
|
|
rgb[i*3 + 2] = colors[i] & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pal;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-09-25 05:54:01 +02:00
|
|
|
static PropertyItem *get_gif_transparent_idx(IWICMetadataReader *reader)
|
|
|
|
{
|
|
|
|
PropertyItem *index = NULL;
|
|
|
|
|
2020-11-13 00:20:30 +01:00
|
|
|
if (get_bool_property(reader, &GUID_MetadataFormatGCE, L"TransparencyFlag"))
|
2012-09-25 05:54:01 +02:00
|
|
|
{
|
2020-11-13 00:20:30 +01:00
|
|
|
index = get_property(reader, &GUID_MetadataFormatGCE, L"TransparentColorIndex");
|
2012-09-25 05:54:01 +02:00
|
|
|
if (index)
|
|
|
|
index->id = PropertyTagIndexTransparent;
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2015-03-12 10:17:40 +01:00
|
|
|
static LONG get_gif_frame_property(IWICBitmapFrameDecode *frame, const GUID *format, const WCHAR *property)
|
2012-09-25 05:51:23 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IWICMetadataBlockReader *block_reader;
|
|
|
|
IWICMetadataReader *reader;
|
|
|
|
UINT block_count, i;
|
2015-03-12 10:17:40 +01:00
|
|
|
PropertyItem *prop;
|
2012-09-25 05:52:19 +02:00
|
|
|
LONG value = 0;
|
|
|
|
|
|
|
|
hr = IWICBitmapFrameDecode_QueryInterface(frame, &IID_IWICMetadataBlockReader, (void **)&block_reader);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
hr = IWICMetadataBlockReader_GetCount(block_reader, &block_count);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
for (i = 0; i < block_count; i++)
|
|
|
|
{
|
|
|
|
hr = IWICMetadataBlockReader_GetReaderByIndex(block_reader, i, &reader);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
2015-03-12 10:17:40 +01:00
|
|
|
prop = get_property(reader, format, property);
|
|
|
|
if (prop)
|
2012-09-25 05:52:19 +02:00
|
|
|
{
|
2015-03-12 10:17:40 +01:00
|
|
|
if (prop->type == PropertyTagTypeByte && prop->length == 1)
|
|
|
|
value = *(BYTE *)prop->value;
|
|
|
|
else if (prop->type == PropertyTagTypeShort && prop->length == 2)
|
|
|
|
value = *(SHORT *)prop->value;
|
2012-09-25 05:52:19 +02:00
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(prop);
|
2012-09-25 05:52:19 +02:00
|
|
|
}
|
|
|
|
IWICMetadataReader_Release(reader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IWICMetadataBlockReader_Release(block_reader);
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gif_metadata_reader(GpBitmap *bitmap, IWICBitmapDecoder *decoder, UINT active_frame)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IWICBitmapFrameDecode *frame;
|
|
|
|
IWICMetadataBlockReader *block_reader;
|
|
|
|
IWICMetadataReader *reader;
|
|
|
|
UINT frame_count, block_count, i;
|
2012-09-25 05:53:08 +02:00
|
|
|
PropertyItem *delay = NULL, *comment = NULL, *background = NULL;
|
2012-09-25 05:55:57 +02:00
|
|
|
PropertyItem *transparent_idx = NULL, *loop = NULL, *palette = NULL;
|
2012-09-25 05:52:19 +02:00
|
|
|
|
|
|
|
IWICBitmapDecoder_GetFrameCount(decoder, &frame_count);
|
|
|
|
if (frame_count > 1)
|
|
|
|
{
|
2015-10-05 00:22:34 +02:00
|
|
|
delay = heap_alloc_zero(sizeof(*delay) + frame_count * sizeof(LONG));
|
2012-09-25 05:52:19 +02:00
|
|
|
if (delay)
|
|
|
|
{
|
|
|
|
LONG *value;
|
|
|
|
|
|
|
|
delay->type = PropertyTagTypeLong;
|
|
|
|
delay->id = PropertyTagFrameDelay;
|
|
|
|
delay->length = frame_count * sizeof(LONG);
|
|
|
|
delay->value = delay + 1;
|
|
|
|
|
|
|
|
value = delay->value;
|
|
|
|
|
|
|
|
for (i = 0; i < frame_count; i++)
|
|
|
|
{
|
|
|
|
hr = IWICBitmapDecoder_GetFrame(decoder, i, &frame);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
2020-11-13 00:20:30 +01:00
|
|
|
value[i] = get_gif_frame_property(frame, &GUID_MetadataFormatGCE, L"Delay");
|
2012-09-25 05:52:19 +02:00
|
|
|
IWICBitmapFrameDecode_Release(frame);
|
|
|
|
}
|
|
|
|
else value[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-25 05:51:23 +02:00
|
|
|
|
|
|
|
hr = IWICBitmapDecoder_QueryInterface(decoder, &IID_IWICMetadataBlockReader, (void **)&block_reader);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
hr = IWICMetadataBlockReader_GetCount(block_reader, &block_count);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
for (i = 0; i < block_count; i++)
|
|
|
|
{
|
|
|
|
hr = IWICMetadataBlockReader_GetReaderByIndex(block_reader, i, &reader);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
if (!comment)
|
|
|
|
comment = get_gif_comment(reader);
|
|
|
|
|
2012-09-25 05:55:04 +02:00
|
|
|
if (frame_count > 1 && !loop)
|
|
|
|
loop = get_gif_loopcount(reader);
|
|
|
|
|
2012-09-25 05:53:08 +02:00
|
|
|
if (!background)
|
|
|
|
background = get_gif_background(reader);
|
|
|
|
|
2012-09-25 05:55:57 +02:00
|
|
|
if (!palette)
|
|
|
|
palette = get_gif_palette(decoder, reader);
|
|
|
|
|
2012-09-25 05:51:23 +02:00
|
|
|
IWICMetadataReader_Release(reader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IWICMetadataBlockReader_Release(block_reader);
|
|
|
|
}
|
|
|
|
|
2012-09-25 05:55:04 +02:00
|
|
|
if (frame_count > 1 && !loop)
|
|
|
|
{
|
2015-10-05 00:22:34 +02:00
|
|
|
loop = heap_alloc_zero(sizeof(*loop) + sizeof(SHORT));
|
2012-09-25 05:55:04 +02:00
|
|
|
if (loop)
|
|
|
|
{
|
|
|
|
loop->type = PropertyTagTypeShort;
|
|
|
|
loop->id = PropertyTagLoopCount;
|
|
|
|
loop->length = sizeof(SHORT);
|
|
|
|
loop->value = loop + 1;
|
|
|
|
*(SHORT *)loop->value = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-25 05:52:19 +02:00
|
|
|
if (delay) add_property(bitmap, delay);
|
2012-09-25 05:51:23 +02:00
|
|
|
if (comment) add_property(bitmap, comment);
|
2012-09-25 05:55:04 +02:00
|
|
|
if (loop) add_property(bitmap, loop);
|
2012-09-25 05:55:57 +02:00
|
|
|
if (palette) add_property(bitmap, palette);
|
2012-09-25 05:53:08 +02:00
|
|
|
if (background) add_property(bitmap, background);
|
2012-09-25 05:51:23 +02:00
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(delay);
|
|
|
|
heap_free(comment);
|
|
|
|
heap_free(loop);
|
|
|
|
heap_free(palette);
|
|
|
|
heap_free(background);
|
2012-09-25 05:54:01 +02:00
|
|
|
|
|
|
|
/* Win7 gdiplus always returns transparent color index from frame 0 */
|
|
|
|
hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
|
|
|
|
if (hr != S_OK) return;
|
|
|
|
|
|
|
|
hr = IWICBitmapFrameDecode_QueryInterface(frame, &IID_IWICMetadataBlockReader, (void **)&block_reader);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
hr = IWICMetadataBlockReader_GetCount(block_reader, &block_count);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
for (i = 0; i < block_count; i++)
|
|
|
|
{
|
|
|
|
hr = IWICMetadataBlockReader_GetReaderByIndex(block_reader, i, &reader);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
if (!transparent_idx)
|
|
|
|
transparent_idx = get_gif_transparent_idx(reader);
|
|
|
|
|
|
|
|
IWICMetadataReader_Release(reader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IWICMetadataBlockReader_Release(block_reader);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (transparent_idx) add_property(bitmap, transparent_idx);
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(transparent_idx);
|
2012-09-25 05:54:01 +02:00
|
|
|
|
|
|
|
IWICBitmapFrameDecode_Release(frame);
|
2012-09-21 12:58:20 +02:00
|
|
|
}
|
|
|
|
|
2015-03-25 22:34:35 +01:00
|
|
|
static PropertyItem* create_prop(PROPID propid, PROPVARIANT* value)
|
|
|
|
{
|
|
|
|
PropertyItem *item = NULL;
|
|
|
|
UINT item_size = propvariant_size(value);
|
|
|
|
|
|
|
|
if (item_size)
|
|
|
|
{
|
|
|
|
item_size += sizeof(*item);
|
2015-10-05 00:22:34 +02:00
|
|
|
item = heap_alloc_zero(item_size);
|
2015-03-25 22:34:35 +01:00
|
|
|
if (propvariant_to_item(value, item, item_size, propid) != Ok)
|
|
|
|
{
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(item);
|
2015-03-25 22:34:35 +01:00
|
|
|
item = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2015-04-01 22:26:00 +02:00
|
|
|
static ULONG get_ulong_by_index(IWICMetadataReader* reader, ULONG index)
|
|
|
|
{
|
|
|
|
PROPVARIANT value;
|
|
|
|
HRESULT hr;
|
|
|
|
ULONG result=0;
|
|
|
|
|
|
|
|
hr = IWICMetadataReader_GetValueByIndex(reader, index, NULL, NULL, &value);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
switch (value.vt)
|
|
|
|
{
|
|
|
|
case VT_UI4:
|
|
|
|
result = value.u.ulVal;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("unhandled case %u\n", value.vt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PropVariantClear(&value);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-03-25 22:34:35 +01:00
|
|
|
static void png_metadata_reader(GpBitmap *bitmap, IWICBitmapDecoder *decoder, UINT active_frame)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IWICBitmapFrameDecode *frame;
|
|
|
|
IWICMetadataBlockReader *block_reader;
|
|
|
|
IWICMetadataReader *reader;
|
|
|
|
UINT block_count, i, j;
|
|
|
|
struct keyword_info {
|
|
|
|
const char* name;
|
|
|
|
PROPID propid;
|
|
|
|
BOOL seen;
|
|
|
|
} keywords[] = {
|
|
|
|
{ "Title", PropertyTagImageTitle },
|
|
|
|
{ "Author", PropertyTagArtist },
|
|
|
|
{ "Description", PropertyTagImageDescription },
|
|
|
|
{ "Copyright", PropertyTagCopyright },
|
|
|
|
{ "Software", PropertyTagSoftwareUsed },
|
|
|
|
{ "Source", PropertyTagEquipModel },
|
|
|
|
{ "Comment", PropertyTagExifUserComment },
|
|
|
|
};
|
2016-06-15 19:43:41 +02:00
|
|
|
BOOL seen_gamma=FALSE, seen_whitepoint=FALSE, seen_chrm=FALSE;
|
2015-03-25 22:34:35 +01:00
|
|
|
|
|
|
|
hr = IWICBitmapDecoder_GetFrame(decoder, active_frame, &frame);
|
|
|
|
if (hr != S_OK) return;
|
|
|
|
|
|
|
|
hr = IWICBitmapFrameDecode_QueryInterface(frame, &IID_IWICMetadataBlockReader, (void **)&block_reader);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
hr = IWICMetadataBlockReader_GetCount(block_reader, &block_count);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
for (i = 0; i < block_count; i++)
|
|
|
|
{
|
|
|
|
hr = IWICMetadataBlockReader_GetReaderByIndex(block_reader, i, &reader);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
GUID format;
|
|
|
|
|
|
|
|
hr = IWICMetadataReader_GetMetadataFormat(reader, &format);
|
|
|
|
if (SUCCEEDED(hr) && IsEqualGUID(&GUID_MetadataFormatChunktEXt, &format))
|
|
|
|
{
|
|
|
|
PROPVARIANT name, value;
|
|
|
|
PropertyItem* item;
|
|
|
|
|
|
|
|
hr = IWICMetadataReader_GetValueByIndex(reader, 0, NULL, &name, &value);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
if (name.vt == VT_LPSTR)
|
|
|
|
{
|
2018-05-14 06:59:34 +02:00
|
|
|
for (j = 0; j < ARRAY_SIZE(keywords); j++)
|
2015-03-25 22:34:35 +01:00
|
|
|
if (!strcmp(keywords[j].name, name.u.pszVal))
|
|
|
|
break;
|
2018-05-14 06:59:34 +02:00
|
|
|
if (j < ARRAY_SIZE(keywords) && !keywords[j].seen)
|
2015-03-25 22:34:35 +01:00
|
|
|
{
|
|
|
|
keywords[j].seen = TRUE;
|
|
|
|
item = create_prop(keywords[j].propid, &value);
|
|
|
|
if (item)
|
|
|
|
add_property(bitmap, item);
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(item);
|
2015-03-25 22:34:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PropVariantClear(&name);
|
|
|
|
PropVariantClear(&value);
|
|
|
|
}
|
|
|
|
}
|
2015-04-01 22:26:00 +02:00
|
|
|
else if (SUCCEEDED(hr) && IsEqualGUID(&GUID_MetadataFormatChunkgAMA, &format))
|
|
|
|
{
|
|
|
|
PropertyItem* item;
|
|
|
|
|
|
|
|
if (!seen_gamma)
|
|
|
|
{
|
2015-10-05 00:22:34 +02:00
|
|
|
item = heap_alloc_zero(sizeof(PropertyItem) + sizeof(ULONG) * 2);
|
2015-04-01 22:26:00 +02:00
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
ULONG *rational;
|
|
|
|
item->length = sizeof(ULONG) * 2;
|
|
|
|
item->type = PropertyTagTypeRational;
|
|
|
|
item->id = PropertyTagGamma;
|
|
|
|
rational = item->value = item + 1;
|
|
|
|
rational[0] = 100000;
|
|
|
|
rational[1] = get_ulong_by_index(reader, 0);
|
|
|
|
add_property(bitmap, item);
|
|
|
|
seen_gamma = TRUE;
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(item);
|
2015-04-01 22:26:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-15 19:43:41 +02:00
|
|
|
else if (SUCCEEDED(hr) && IsEqualGUID(&GUID_MetadataFormatChunkcHRM, &format))
|
|
|
|
{
|
|
|
|
PropertyItem* item;
|
|
|
|
|
|
|
|
if (!seen_whitepoint)
|
|
|
|
{
|
|
|
|
item = GdipAlloc(sizeof(PropertyItem) + sizeof(ULONG) * 4);
|
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
ULONG *rational;
|
|
|
|
item->length = sizeof(ULONG) * 4;
|
|
|
|
item->type = PropertyTagTypeRational;
|
|
|
|
item->id = PropertyTagWhitePoint;
|
|
|
|
rational = item->value = item + 1;
|
|
|
|
rational[0] = get_ulong_by_index(reader, 0);
|
|
|
|
rational[1] = 100000;
|
|
|
|
rational[2] = get_ulong_by_index(reader, 1);
|
|
|
|
rational[3] = 100000;
|
|
|
|
add_property(bitmap, item);
|
|
|
|
seen_whitepoint = TRUE;
|
|
|
|
GdipFree(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!seen_chrm)
|
|
|
|
{
|
|
|
|
item = GdipAlloc(sizeof(PropertyItem) + sizeof(ULONG) * 12);
|
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
ULONG *rational;
|
|
|
|
item->length = sizeof(ULONG) * 12;
|
|
|
|
item->type = PropertyTagTypeRational;
|
|
|
|
item->id = PropertyTagPrimaryChromaticities;
|
|
|
|
rational = item->value = item + 1;
|
|
|
|
rational[0] = get_ulong_by_index(reader, 2);
|
|
|
|
rational[1] = 100000;
|
|
|
|
rational[2] = get_ulong_by_index(reader, 3);
|
|
|
|
rational[3] = 100000;
|
|
|
|
rational[4] = get_ulong_by_index(reader, 4);
|
|
|
|
rational[5] = 100000;
|
|
|
|
rational[6] = get_ulong_by_index(reader, 5);
|
|
|
|
rational[7] = 100000;
|
|
|
|
rational[8] = get_ulong_by_index(reader, 6);
|
|
|
|
rational[9] = 100000;
|
|
|
|
rational[10] = get_ulong_by_index(reader, 7);
|
|
|
|
rational[11] = 100000;
|
|
|
|
add_property(bitmap, item);
|
|
|
|
seen_chrm = TRUE;
|
|
|
|
GdipFree(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-25 22:34:35 +01:00
|
|
|
|
|
|
|
IWICMetadataReader_Release(reader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IWICMetadataBlockReader_Release(block_reader);
|
|
|
|
}
|
|
|
|
|
|
|
|
IWICBitmapFrameDecode_Release(frame);
|
|
|
|
}
|
|
|
|
|
2015-03-12 10:17:03 +01:00
|
|
|
static GpStatus initialize_decoder_wic(IStream *stream, REFGUID container, IWICBitmapDecoder **decoder)
|
|
|
|
{
|
|
|
|
IWICImagingFactory *factory;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p,%s\n", stream, wine_dbgstr_guid(container));
|
|
|
|
|
|
|
|
hr = WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION, &factory);
|
2015-03-20 22:34:49 +01:00
|
|
|
if (FAILED(hr)) return hresult_to_status(hr);
|
2015-03-12 10:17:03 +01:00
|
|
|
hr = IWICImagingFactory_CreateDecoder(factory, container, NULL, decoder);
|
|
|
|
IWICImagingFactory_Release(factory);
|
2015-03-20 22:34:49 +01:00
|
|
|
if (FAILED(hr)) return hresult_to_status(hr);
|
2015-03-12 10:17:03 +01:00
|
|
|
|
|
|
|
hr = IWICBitmapDecoder_Initialize(*decoder, stream, WICDecodeMetadataCacheOnLoad);
|
2019-01-24 11:59:47 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IWICBitmapDecoder_Release(*decoder);
|
|
|
|
return hresult_to_status(hr);
|
|
|
|
}
|
2015-03-12 10:17:03 +01:00
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2012-09-21 12:58:20 +02:00
|
|
|
typedef void (*metadata_reader_func)(GpBitmap *bitmap, IWICBitmapDecoder *decoder, UINT frame);
|
|
|
|
|
2015-03-12 10:17:34 +01:00
|
|
|
static GpStatus decode_frame_wic(IWICBitmapDecoder *decoder, BOOL force_conversion,
|
2012-09-21 12:58:20 +02:00
|
|
|
UINT active_frame, metadata_reader_func metadata_reader, GpImage **image)
|
2007-07-25 02:19:21 +02:00
|
|
|
{
|
2009-08-31 23:56:47 +02:00
|
|
|
GpStatus status=Ok;
|
|
|
|
GpBitmap *bitmap;
|
|
|
|
HRESULT hr;
|
|
|
|
IWICBitmapFrameDecode *frame;
|
|
|
|
IWICBitmapSource *source=NULL;
|
2012-06-25 13:30:34 +02:00
|
|
|
IWICMetadataBlockReader *block_reader;
|
2009-08-31 23:56:47 +02:00
|
|
|
WICPixelFormatGUID wic_format;
|
|
|
|
PixelFormat gdip_format=0;
|
2012-07-18 10:24:58 +02:00
|
|
|
ColorPalette *palette = NULL;
|
2012-07-18 10:26:38 +02:00
|
|
|
WICBitmapPaletteType palette_type = WICBitmapPaletteTypeFixedHalftone256;
|
2009-08-31 23:56:47 +02:00
|
|
|
int i;
|
2012-05-16 16:33:48 +02:00
|
|
|
UINT width, height, frame_count;
|
2009-08-31 23:56:47 +02:00
|
|
|
BitmapData lockeddata;
|
|
|
|
WICRect wrc;
|
2007-08-08 03:42:20 +02:00
|
|
|
|
2015-03-12 10:17:03 +01:00
|
|
|
TRACE("%p,%u,%p\n", decoder, active_frame, image);
|
2009-08-31 23:56:47 +02:00
|
|
|
|
2015-03-12 10:17:03 +01:00
|
|
|
IWICBitmapDecoder_GetFrameCount(decoder, &frame_count);
|
|
|
|
hr = IWICBitmapDecoder_GetFrame(decoder, active_frame, &frame);
|
2009-08-31 23:56:47 +02:00
|
|
|
if (SUCCEEDED(hr)) /* got frame */
|
|
|
|
{
|
|
|
|
hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &wic_format);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2015-03-12 10:17:34 +01:00
|
|
|
if (!force_conversion)
|
2009-08-31 23:56:47 +02:00
|
|
|
{
|
2015-03-12 10:17:34 +01:00
|
|
|
for (i=0; pixel_formats[i].wic_format; i++)
|
2009-08-31 23:56:47 +02:00
|
|
|
{
|
2015-03-12 10:17:34 +01:00
|
|
|
if (IsEqualGUID(&wic_format, pixel_formats[i].wic_format))
|
|
|
|
{
|
|
|
|
source = (IWICBitmapSource*)frame;
|
|
|
|
IWICBitmapSource_AddRef(source);
|
|
|
|
gdip_format = pixel_formats[i].gdip_format;
|
|
|
|
palette_type = pixel_formats[i].palette_type;
|
|
|
|
break;
|
|
|
|
}
|
2009-08-31 23:56:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!source)
|
|
|
|
{
|
|
|
|
/* unknown format; fall back on 32bppARGB */
|
2015-03-12 10:17:34 +01:00
|
|
|
hr = WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA, (IWICBitmapSource*)frame, &source);
|
2009-08-31 23:56:47 +02:00
|
|
|
gdip_format = PixelFormat32bppARGB;
|
|
|
|
}
|
2012-07-13 04:50:05 +02:00
|
|
|
TRACE("%s => %#x\n", wine_dbgstr_guid(&wic_format), gdip_format);
|
2009-08-31 23:56:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr)) /* got source */
|
|
|
|
{
|
|
|
|
hr = IWICBitmapSource_GetSize(source, &width, &height);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
status = GdipCreateBitmapFromScan0(width, height, 0, gdip_format,
|
|
|
|
NULL, &bitmap);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr) && status == Ok) /* created bitmap */
|
|
|
|
{
|
|
|
|
status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeWrite,
|
|
|
|
gdip_format, &lockeddata);
|
|
|
|
if (status == Ok) /* locked bitmap */
|
|
|
|
{
|
|
|
|
wrc.X = 0;
|
|
|
|
wrc.Width = width;
|
|
|
|
wrc.Height = 1;
|
|
|
|
for (i=0; i<height; i++)
|
|
|
|
{
|
|
|
|
wrc.Y = i;
|
|
|
|
hr = IWICBitmapSource_CopyPixels(source, &wrc, abs(lockeddata.Stride),
|
|
|
|
abs(lockeddata.Stride), (BYTE*)lockeddata.Scan0+lockeddata.Stride*i);
|
|
|
|
if (FAILED(hr)) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GdipBitmapUnlockBits(bitmap, &lockeddata);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr) && status == Ok)
|
2016-08-05 08:32:46 +02:00
|
|
|
*image = &bitmap->image;
|
2009-08-31 23:56:47 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*image = NULL;
|
2016-08-05 08:32:46 +02:00
|
|
|
GdipDisposeImage(&bitmap->image);
|
2009-08-31 23:56:47 +02:00
|
|
|
}
|
2010-07-02 23:39:17 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr) && status == Ok)
|
|
|
|
{
|
|
|
|
double dpix, dpiy;
|
|
|
|
hr = IWICBitmapSource_GetResolution(source, &dpix, &dpiy);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
bitmap->image.xres = dpix;
|
|
|
|
bitmap->image.yres = dpiy;
|
|
|
|
}
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
2009-08-31 23:56:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
IWICBitmapSource_Release(source);
|
|
|
|
}
|
|
|
|
|
2020-01-13 00:28:58 +01:00
|
|
|
if (SUCCEEDED(hr) && status == Ok) {
|
2012-09-03 18:56:47 +02:00
|
|
|
bitmap->metadata_reader = NULL;
|
2012-09-21 12:58:20 +02:00
|
|
|
|
|
|
|
if (metadata_reader)
|
|
|
|
metadata_reader(bitmap, decoder, active_frame);
|
|
|
|
else if (IWICBitmapFrameDecode_QueryInterface(frame, &IID_IWICMetadataBlockReader, (void **)&block_reader) == S_OK)
|
2012-09-03 18:56:47 +02:00
|
|
|
{
|
|
|
|
UINT block_count = 0;
|
|
|
|
if (IWICMetadataBlockReader_GetCount(block_reader, &block_count) == S_OK && block_count)
|
|
|
|
IWICMetadataBlockReader_GetReaderByIndex(block_reader, 0, &bitmap->metadata_reader);
|
|
|
|
IWICMetadataBlockReader_Release(block_reader);
|
|
|
|
}
|
2012-06-25 13:30:34 +02:00
|
|
|
|
2012-09-03 18:56:47 +02:00
|
|
|
palette = get_palette(frame, palette_type);
|
|
|
|
IWICBitmapFrameDecode_Release(frame);
|
|
|
|
}
|
2007-08-01 04:15:48 +02:00
|
|
|
}
|
|
|
|
|
2009-08-31 23:56:47 +02:00
|
|
|
if (FAILED(hr) && status == Ok) status = hresult_to_status(hr);
|
|
|
|
|
2010-07-02 23:39:17 +02:00
|
|
|
if (status == Ok)
|
|
|
|
{
|
|
|
|
/* Native GDI+ used to be smarter, but since Win7 it just sets these flags. */
|
2017-08-28 18:30:16 +02:00
|
|
|
bitmap->image.flags |= ImageFlagsReadOnly|ImageFlagsHasRealPixelSize|ImageFlagsHasRealDPI;
|
|
|
|
if (IsEqualGUID(&wic_format, &GUID_WICPixelFormat2bppGray) ||
|
|
|
|
IsEqualGUID(&wic_format, &GUID_WICPixelFormat4bppGray) ||
|
|
|
|
IsEqualGUID(&wic_format, &GUID_WICPixelFormat8bppGray) ||
|
|
|
|
IsEqualGUID(&wic_format, &GUID_WICPixelFormat16bppGray))
|
|
|
|
bitmap->image.flags |= ImageFlagsColorSpaceGRAY;
|
|
|
|
else
|
|
|
|
bitmap->image.flags |= ImageFlagsColorSpaceRGB;
|
2012-05-16 16:33:48 +02:00
|
|
|
bitmap->image.frame_count = frame_count;
|
2012-06-19 09:51:45 +02:00
|
|
|
bitmap->image.current_frame = active_frame;
|
2015-03-12 10:17:03 +01:00
|
|
|
bitmap->image.decoder = decoder;
|
|
|
|
IWICBitmapDecoder_AddRef(decoder);
|
2012-07-18 10:24:58 +02:00
|
|
|
if (palette)
|
|
|
|
{
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(bitmap->image.palette);
|
2012-07-18 10:24:58 +02:00
|
|
|
bitmap->image.palette = palette;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (IsEqualGUID(&wic_format, &GUID_WICPixelFormatBlackWhite))
|
|
|
|
bitmap->image.palette->Flags = 0;
|
|
|
|
}
|
2012-09-28 03:15:39 +02:00
|
|
|
TRACE("=> %p\n", *image);
|
2010-07-02 23:39:17 +02:00
|
|
|
}
|
|
|
|
|
2009-08-31 23:56:47 +02:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-03-12 10:17:03 +01:00
|
|
|
static GpStatus decode_image_wic(IStream *stream, REFGUID container,
|
|
|
|
metadata_reader_func metadata_reader, GpImage **image)
|
2009-08-31 23:56:47 +02:00
|
|
|
{
|
2015-03-12 10:17:03 +01:00
|
|
|
IWICBitmapDecoder *decoder;
|
|
|
|
GpStatus status;
|
|
|
|
|
|
|
|
status = initialize_decoder_wic(stream, container, &decoder);
|
|
|
|
if(status != Ok)
|
|
|
|
return status;
|
|
|
|
|
2015-03-12 10:17:34 +01:00
|
|
|
status = decode_frame_wic(decoder, FALSE, 0, metadata_reader, image);
|
2015-03-12 10:17:03 +01:00
|
|
|
IWICBitmapDecoder_Release(decoder);
|
|
|
|
return status;
|
2009-08-26 00:43:33 +02:00
|
|
|
}
|
2007-08-08 03:42:20 +02:00
|
|
|
|
2015-03-12 10:17:03 +01:00
|
|
|
static GpStatus select_frame_wic(GpImage *image, UINT active_frame)
|
|
|
|
{
|
|
|
|
GpImage *new_image;
|
|
|
|
GpStatus status;
|
|
|
|
|
2015-03-12 10:17:34 +01:00
|
|
|
status = decode_frame_wic(image->decoder, FALSE, active_frame, NULL, &new_image);
|
2015-03-12 10:17:03 +01:00
|
|
|
if(status != Ok)
|
|
|
|
return status;
|
|
|
|
|
2017-02-14 10:24:36 +01:00
|
|
|
new_image->busy = image->busy;
|
2015-03-12 10:17:03 +01:00
|
|
|
memcpy(&new_image->format, &image->format, sizeof(GUID));
|
2020-02-19 08:47:03 +01:00
|
|
|
new_image->encoder = image->encoder;
|
|
|
|
image->encoder = NULL;
|
2015-03-12 10:17:03 +01:00
|
|
|
free_image_data(image);
|
|
|
|
if (image->type == ImageTypeBitmap)
|
|
|
|
*(GpBitmap *)image = *(GpBitmap *)new_image;
|
|
|
|
else if (image->type == ImageTypeMetafile)
|
|
|
|
*(GpMetafile *)image = *(GpMetafile *)new_image;
|
|
|
|
new_image->type = ~0;
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(new_image);
|
2015-03-12 10:17:03 +01:00
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2015-03-12 10:17:40 +01:00
|
|
|
static HRESULT get_gif_frame_rect(IWICBitmapFrameDecode *frame,
|
|
|
|
UINT *left, UINT *top, UINT *width, UINT *height)
|
2015-03-12 10:17:03 +01:00
|
|
|
{
|
2020-11-13 00:20:30 +01:00
|
|
|
*left = get_gif_frame_property(frame, &GUID_MetadataFormatIMD, L"Left");
|
|
|
|
*top = get_gif_frame_property(frame, &GUID_MetadataFormatIMD, L"Top");
|
2015-03-12 10:17:03 +01:00
|
|
|
|
2015-03-12 10:17:40 +01:00
|
|
|
return IWICBitmapFrameDecode_GetSize(frame, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT blit_gif_frame(GpBitmap *bitmap, IWICBitmapFrameDecode *frame, BOOL first_frame)
|
|
|
|
{
|
|
|
|
UINT i, j, left, top, width, height;
|
|
|
|
IWICBitmapSource *source;
|
|
|
|
BYTE *new_bits;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = get_gif_frame_rect(frame, &left, &top, &width, &height);
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA, (IWICBitmapSource*)frame, &source);
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
new_bits = heap_alloc_zero(width*height*4);
|
2015-03-12 10:17:40 +01:00
|
|
|
if(!new_bits)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
hr = IWICBitmapSource_CopyPixels(source, NULL, width*4, width*height*4, new_bits);
|
|
|
|
IWICBitmapSource_Release(source);
|
|
|
|
if(FAILED(hr)) {
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(new_bits);
|
2015-03-12 10:17:40 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0; i<height && i+top<bitmap->height; i++) {
|
|
|
|
for(j=0; j<width && j+left<bitmap->width; j++) {
|
|
|
|
DWORD *src = (DWORD*)(new_bits+i*width*4+j*4);
|
|
|
|
DWORD *dst = (DWORD*)(bitmap->bits+(i+top)*bitmap->stride+(j+left)*4);
|
|
|
|
|
|
|
|
if(first_frame || *src>>24 != 0)
|
|
|
|
*dst = *src;
|
|
|
|
}
|
|
|
|
}
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(new_bits);
|
2015-03-12 10:17:40 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD get_gif_background_color(GpBitmap *bitmap)
|
|
|
|
{
|
|
|
|
BYTE bgcolor_idx = 0;
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
for(i=0; i<bitmap->prop_count; i++) {
|
|
|
|
if(bitmap->prop_item[i].id == PropertyTagIndexBackground) {
|
|
|
|
bgcolor_idx = *(BYTE*)bitmap->prop_item[i].value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0; i<bitmap->prop_count; i++) {
|
|
|
|
if(bitmap->prop_item[i].id == PropertyTagIndexTransparent) {
|
|
|
|
BYTE transparent_idx;
|
|
|
|
transparent_idx = *(BYTE*)bitmap->prop_item[i].value;
|
|
|
|
|
|
|
|
if(transparent_idx == bgcolor_idx)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0; i<bitmap->prop_count; i++) {
|
|
|
|
if(bitmap->prop_item[i].id == PropertyTagGlobalPalette) {
|
|
|
|
if(bitmap->prop_item[i].length/3 > bgcolor_idx) {
|
|
|
|
BYTE *color = ((BYTE*)bitmap->prop_item[i].value)+bgcolor_idx*3;
|
2015-10-19 22:06:42 +02:00
|
|
|
return color[2] + (color[1]<<8) + (color[0]<<16) + (0xffu<<24);
|
2015-03-12 10:17:40 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("can't get gif background color\n");
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GpStatus select_frame_gif(GpImage* image, UINT active_frame)
|
|
|
|
{
|
|
|
|
GpBitmap *bitmap = (GpBitmap*)image;
|
|
|
|
IWICBitmapFrameDecode *frame;
|
|
|
|
int cur_frame=0, disposal;
|
|
|
|
BOOL bgcolor_set = FALSE;
|
|
|
|
DWORD bgcolor = 0;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if(active_frame > image->current_frame) {
|
|
|
|
hr = IWICBitmapDecoder_GetFrame(bitmap->image.decoder, image->current_frame, &frame);
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hresult_to_status(hr);
|
2020-11-13 00:20:30 +01:00
|
|
|
disposal = get_gif_frame_property(frame, &GUID_MetadataFormatGCE, L"Disposal");
|
2015-03-12 10:17:40 +01:00
|
|
|
IWICBitmapFrameDecode_Release(frame);
|
|
|
|
|
|
|
|
if(disposal == GIF_DISPOSE_RESTORE_TO_BKGND)
|
|
|
|
cur_frame = image->current_frame;
|
|
|
|
else if(disposal != GIF_DISPOSE_RESTORE_TO_PREV)
|
|
|
|
cur_frame = image->current_frame+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(cur_frame != active_frame) {
|
|
|
|
hr = IWICBitmapDecoder_GetFrame(bitmap->image.decoder, cur_frame, &frame);
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hresult_to_status(hr);
|
2020-11-13 00:20:30 +01:00
|
|
|
disposal = get_gif_frame_property(frame, &GUID_MetadataFormatGCE, L"Disposal");
|
2015-03-12 10:17:40 +01:00
|
|
|
|
|
|
|
if(disposal==GIF_DISPOSE_UNSPECIFIED || disposal==GIF_DISPOSE_DO_NOT_DISPOSE) {
|
|
|
|
hr = blit_gif_frame(bitmap, frame, cur_frame==0);
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hresult_to_status(hr);
|
|
|
|
}else if(disposal == GIF_DISPOSE_RESTORE_TO_BKGND) {
|
|
|
|
UINT left, top, width, height, i, j;
|
|
|
|
|
|
|
|
if(!bgcolor_set) {
|
|
|
|
bgcolor = get_gif_background_color(bitmap);
|
|
|
|
bgcolor_set = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = get_gif_frame_rect(frame, &left, &top, &width, &height);
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hresult_to_status(hr);
|
|
|
|
for(i=top; i<top+height && i<bitmap->height; i++) {
|
|
|
|
DWORD *bits = (DWORD*)(bitmap->bits+i*bitmap->stride);
|
|
|
|
for(j=left; j<left+width && j<bitmap->width; j++)
|
|
|
|
bits[j] = bgcolor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IWICBitmapFrameDecode_Release(frame);
|
|
|
|
cur_frame++;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IWICBitmapDecoder_GetFrame(bitmap->image.decoder, active_frame, &frame);
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hresult_to_status(hr);
|
|
|
|
|
|
|
|
hr = blit_gif_frame(bitmap, frame, cur_frame==0);
|
|
|
|
IWICBitmapFrameDecode_Release(frame);
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hresult_to_status(hr);
|
|
|
|
|
|
|
|
image->current_frame = active_frame;
|
2015-03-12 10:17:03 +01:00
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GpStatus decode_image_icon(IStream* stream, GpImage **image)
|
|
|
|
{
|
|
|
|
return decode_image_wic(stream, &GUID_ContainerFormatIco, NULL, image);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GpStatus decode_image_bmp(IStream* stream, GpImage **image)
|
2009-09-04 16:54:55 +02:00
|
|
|
{
|
2009-09-04 17:23:30 +02:00
|
|
|
GpStatus status;
|
|
|
|
GpBitmap* bitmap;
|
|
|
|
|
2015-03-12 10:17:03 +01:00
|
|
|
status = decode_image_wic(stream, &GUID_ContainerFormatBmp, NULL, image);
|
2009-09-04 17:23:30 +02:00
|
|
|
|
|
|
|
bitmap = (GpBitmap*)*image;
|
|
|
|
|
|
|
|
if (status == Ok && bitmap->format == PixelFormat32bppARGB)
|
|
|
|
{
|
|
|
|
/* WIC supports bmp files with alpha, but gdiplus does not */
|
|
|
|
bitmap->format = PixelFormat32bppRGB;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
2009-09-04 16:54:55 +02:00
|
|
|
}
|
|
|
|
|
2015-03-12 10:17:03 +01:00
|
|
|
static GpStatus decode_image_jpeg(IStream* stream, GpImage **image)
|
2009-09-02 00:54:45 +02:00
|
|
|
{
|
2015-03-12 10:17:03 +01:00
|
|
|
return decode_image_wic(stream, &GUID_ContainerFormatJpeg, NULL, image);
|
2009-09-02 00:54:45 +02:00
|
|
|
}
|
|
|
|
|
2018-11-08 14:17:04 +01:00
|
|
|
static BOOL has_png_transparency_chunk(IStream *pIStream)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER seek;
|
|
|
|
BOOL has_tRNS = FALSE;
|
|
|
|
HRESULT hr;
|
|
|
|
BYTE header[8];
|
|
|
|
|
|
|
|
seek.QuadPart = 8;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ULARGE_INTEGER chunk_start;
|
|
|
|
ULONG bytesread, chunk_size;
|
|
|
|
|
|
|
|
hr = IStream_Seek(pIStream, seek, STREAM_SEEK_SET, &chunk_start);
|
|
|
|
if (FAILED(hr)) break;
|
|
|
|
|
|
|
|
hr = IStream_Read(pIStream, header, 8, &bytesread);
|
|
|
|
if (FAILED(hr) || bytesread < 8) break;
|
|
|
|
|
|
|
|
chunk_size = (header[0] << 24) | (header[1] << 16) | (header[2] << 8) | header[3];
|
|
|
|
if (!memcmp(&header[4], "tRNS", 4))
|
|
|
|
{
|
|
|
|
has_tRNS = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
seek.QuadPart = chunk_start.QuadPart + chunk_size + 12; /* skip data and CRC */
|
|
|
|
} while (memcmp(&header[4], "IDAT", 4) && memcmp(&header[4], "IEND", 4));
|
|
|
|
|
|
|
|
TRACE("has_tRNS = %d\n", has_tRNS);
|
|
|
|
return has_tRNS;
|
|
|
|
}
|
|
|
|
|
2015-03-12 10:17:03 +01:00
|
|
|
static GpStatus decode_image_png(IStream* stream, GpImage **image)
|
2009-09-02 00:56:42 +02:00
|
|
|
{
|
2017-08-24 18:19:01 +02:00
|
|
|
IWICBitmapDecoder *decoder;
|
|
|
|
IWICBitmapFrameDecode *frame;
|
|
|
|
GpStatus status;
|
|
|
|
HRESULT hr;
|
|
|
|
GUID format;
|
|
|
|
BOOL force_conversion = FALSE;
|
|
|
|
|
|
|
|
status = initialize_decoder_wic(stream, &GUID_ContainerFormatPng, &decoder);
|
|
|
|
if (status != Ok)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
if (IsEqualGUID(&format, &GUID_WICPixelFormat8bppGray))
|
|
|
|
force_conversion = TRUE;
|
2018-11-08 14:17:04 +01:00
|
|
|
else if ((IsEqualGUID(&format, &GUID_WICPixelFormat8bppIndexed) ||
|
|
|
|
IsEqualGUID(&format, &GUID_WICPixelFormat4bppIndexed) ||
|
|
|
|
IsEqualGUID(&format, &GUID_WICPixelFormat2bppIndexed) ||
|
|
|
|
IsEqualGUID(&format, &GUID_WICPixelFormat1bppIndexed) ||
|
|
|
|
IsEqualGUID(&format, &GUID_WICPixelFormat24bppBGR)) &&
|
|
|
|
has_png_transparency_chunk(stream))
|
|
|
|
force_conversion = TRUE;
|
|
|
|
|
2017-08-24 18:19:01 +02:00
|
|
|
status = decode_frame_wic(decoder, force_conversion, 0, png_metadata_reader, image);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
status = hresult_to_status(hr);
|
|
|
|
|
|
|
|
IWICBitmapFrameDecode_Release(frame);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
status = hresult_to_status(hr);
|
|
|
|
|
|
|
|
IWICBitmapDecoder_Release(decoder);
|
|
|
|
return status;
|
2009-09-02 00:56:42 +02:00
|
|
|
}
|
|
|
|
|
2015-03-12 10:17:03 +01:00
|
|
|
static GpStatus decode_image_gif(IStream* stream, GpImage **image)
|
2009-08-26 00:43:33 +02:00
|
|
|
{
|
2015-03-12 10:17:34 +01:00
|
|
|
IWICBitmapDecoder *decoder;
|
|
|
|
UINT frame_count;
|
|
|
|
GpStatus status;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
status = initialize_decoder_wic(stream, &GUID_ContainerFormatGif, &decoder);
|
|
|
|
if(status != Ok)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
hr = IWICBitmapDecoder_GetFrameCount(decoder, &frame_count);
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hresult_to_status(hr);
|
|
|
|
|
2015-04-01 09:48:48 +02:00
|
|
|
status = decode_frame_wic(decoder, frame_count > 1, 0, gif_metadata_reader, image);
|
2015-03-12 10:17:34 +01:00
|
|
|
IWICBitmapDecoder_Release(decoder);
|
|
|
|
if(status != Ok)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
if(frame_count > 1) {
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free((*image)->palette);
|
2015-03-12 10:17:34 +01:00
|
|
|
(*image)->palette = NULL;
|
|
|
|
}
|
|
|
|
return Ok;
|
2009-08-26 00:43:33 +02:00
|
|
|
}
|
|
|
|
|
2015-03-12 10:17:03 +01:00
|
|
|
static GpStatus decode_image_tiff(IStream* stream, GpImage **image)
|
2010-03-08 23:42:51 +01:00
|
|
|
{
|
2015-03-12 10:17:03 +01:00
|
|
|
return decode_image_wic(stream, &GUID_ContainerFormatTiff, NULL, image);
|
2010-03-08 23:42:51 +01:00
|
|
|
}
|
|
|
|
|
2016-08-18 21:22:02 +02:00
|
|
|
static GpStatus load_wmf(IStream *stream, GpMetafile **metafile)
|
|
|
|
{
|
|
|
|
WmfPlaceableFileHeader pfh;
|
|
|
|
BOOL is_placeable = FALSE;
|
|
|
|
LARGE_INTEGER seek;
|
|
|
|
GpStatus status;
|
|
|
|
METAHEADER mh;
|
|
|
|
HMETAFILE hmf;
|
|
|
|
HRESULT hr;
|
|
|
|
UINT size;
|
|
|
|
void *buf;
|
|
|
|
|
|
|
|
hr = IStream_Read(stream, &mh, sizeof(mh), &size);
|
|
|
|
if (hr != S_OK || size != sizeof(mh))
|
|
|
|
return GenericError;
|
|
|
|
|
|
|
|
if (((WmfPlaceableFileHeader *)&mh)->Key == WMF_PLACEABLE_KEY)
|
|
|
|
{
|
|
|
|
seek.QuadPart = 0;
|
|
|
|
hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr)) return hresult_to_status(hr);
|
|
|
|
|
|
|
|
hr = IStream_Read(stream, &pfh, sizeof(pfh), &size);
|
|
|
|
if (hr != S_OK || size != sizeof(pfh))
|
|
|
|
return GenericError;
|
|
|
|
|
|
|
|
hr = IStream_Read(stream, &mh, sizeof(mh), &size);
|
|
|
|
if (hr != S_OK || size != sizeof(mh))
|
|
|
|
return GenericError;
|
|
|
|
|
|
|
|
is_placeable = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
seek.QuadPart = is_placeable ? sizeof(pfh) : 0;
|
|
|
|
hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr)) return hresult_to_status(hr);
|
|
|
|
|
|
|
|
buf = heap_alloc(mh.mtSize * 2);
|
|
|
|
if (!buf) return OutOfMemory;
|
|
|
|
|
|
|
|
hr = IStream_Read(stream, buf, mh.mtSize * 2, &size);
|
|
|
|
if (hr != S_OK || size != mh.mtSize * 2)
|
|
|
|
{
|
|
|
|
heap_free(buf);
|
|
|
|
return GenericError;
|
|
|
|
}
|
|
|
|
|
|
|
|
hmf = SetMetaFileBitsEx(mh.mtSize * 2, buf);
|
|
|
|
heap_free(buf);
|
|
|
|
if (!hmf)
|
|
|
|
return GenericError;
|
|
|
|
|
|
|
|
status = GdipCreateMetafileFromWmf(hmf, TRUE, is_placeable ? &pfh : NULL, metafile);
|
|
|
|
if (status != Ok)
|
|
|
|
DeleteMetaFile(hmf);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GpStatus decode_image_wmf(IStream *stream, GpImage **image)
|
2009-08-26 00:43:33 +02:00
|
|
|
{
|
2016-08-18 21:22:02 +02:00
|
|
|
GpMetafile *metafile;
|
|
|
|
GpStatus status;
|
2009-08-26 00:43:33 +02:00
|
|
|
|
|
|
|
TRACE("%p %p\n", stream, image);
|
|
|
|
|
2016-08-18 21:22:02 +02:00
|
|
|
if (!stream || !image)
|
2009-08-26 00:43:33 +02:00
|
|
|
return InvalidParameter;
|
|
|
|
|
2016-08-18 21:22:02 +02:00
|
|
|
status = load_wmf(stream, &metafile);
|
|
|
|
if (status != Ok)
|
|
|
|
{
|
|
|
|
TRACE("Could not load metafile\n");
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
*image = (GpImage *)metafile;
|
|
|
|
TRACE("<-- %p\n", *image);
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GpStatus load_emf(IStream *stream, GpMetafile **metafile)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER seek;
|
|
|
|
ENHMETAHEADER emh;
|
|
|
|
HENHMETAFILE hemf;
|
|
|
|
GpStatus status;
|
|
|
|
HRESULT hr;
|
|
|
|
UINT size;
|
|
|
|
void *buf;
|
|
|
|
|
|
|
|
hr = IStream_Read(stream, &emh, sizeof(emh), &size);
|
|
|
|
if (hr != S_OK || size != sizeof(emh) || emh.dSignature != ENHMETA_SIGNATURE)
|
|
|
|
return GenericError;
|
|
|
|
|
|
|
|
seek.QuadPart = 0;
|
|
|
|
hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr)) return hresult_to_status(hr);
|
|
|
|
|
|
|
|
buf = heap_alloc(emh.nBytes);
|
|
|
|
if (!buf) return OutOfMemory;
|
|
|
|
|
|
|
|
hr = IStream_Read(stream, buf, emh.nBytes, &size);
|
|
|
|
if (hr != S_OK || size != emh.nBytes)
|
|
|
|
{
|
|
|
|
heap_free(buf);
|
2009-08-26 00:43:33 +02:00
|
|
|
return GenericError;
|
2007-08-08 03:42:20 +02:00
|
|
|
}
|
|
|
|
|
2016-08-18 21:22:02 +02:00
|
|
|
hemf = SetEnhMetaFileBits(emh.nBytes, buf);
|
|
|
|
heap_free(buf);
|
|
|
|
if (!hemf)
|
|
|
|
return GenericError;
|
|
|
|
|
|
|
|
status = GdipCreateMetafileFromEmf(hemf, TRUE, metafile);
|
|
|
|
if (status != Ok)
|
|
|
|
DeleteEnhMetaFile(hemf);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GpStatus decode_image_emf(IStream *stream, GpImage **image)
|
|
|
|
{
|
|
|
|
GpMetafile *metafile;
|
|
|
|
GpStatus status;
|
|
|
|
|
|
|
|
TRACE("%p %p\n", stream, image);
|
|
|
|
|
|
|
|
if (!stream || !image)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
status = load_emf(stream, &metafile);
|
|
|
|
if (status != Ok)
|
|
|
|
{
|
|
|
|
TRACE("Could not load metafile\n");
|
|
|
|
return status;
|
|
|
|
}
|
2007-08-01 04:15:48 +02:00
|
|
|
|
2016-08-18 21:22:02 +02:00
|
|
|
*image = (GpImage *)metafile;
|
2009-12-18 22:09:45 +01:00
|
|
|
TRACE("<-- %p\n", *image);
|
|
|
|
|
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
|
|
|
|
2009-08-24 22:15:31 +02:00
|
|
|
typedef GpStatus (*encode_image_func)(GpImage *image, IStream* stream,
|
2017-07-10 11:29:56 +02:00
|
|
|
GDIPCONST EncoderParameters* params);
|
2009-08-26 00:43:33 +02:00
|
|
|
|
2015-03-12 10:17:03 +01:00
|
|
|
typedef GpStatus (*decode_image_func)(IStream *stream, GpImage **image);
|
|
|
|
|
|
|
|
typedef GpStatus (*select_image_func)(GpImage *image, UINT active_frame);
|
2009-08-26 00:43:33 +02:00
|
|
|
|
|
|
|
typedef struct image_codec {
|
|
|
|
ImageCodecInfo info;
|
|
|
|
encode_image_func encode_func;
|
|
|
|
decode_image_func decode_func;
|
2015-03-12 10:17:03 +01:00
|
|
|
select_image_func select_func;
|
2009-08-26 00:43:33 +02:00
|
|
|
} image_codec;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
BMP,
|
|
|
|
JPEG,
|
|
|
|
GIF,
|
2010-03-08 23:42:51 +01:00
|
|
|
TIFF,
|
2009-08-26 00:43:33 +02:00
|
|
|
EMF,
|
|
|
|
WMF,
|
|
|
|
PNG,
|
|
|
|
ICO,
|
|
|
|
NUM_CODECS
|
|
|
|
} ImageFormat;
|
|
|
|
|
|
|
|
static const struct image_codec codecs[NUM_CODECS];
|
|
|
|
|
|
|
|
static GpStatus get_decoder_info(IStream* stream, const struct image_codec **result)
|
|
|
|
{
|
|
|
|
BYTE signature[8];
|
2010-03-08 23:42:36 +01:00
|
|
|
const BYTE *pattern, *mask;
|
2009-08-26 00:43:33 +02:00
|
|
|
LARGE_INTEGER seek;
|
|
|
|
HRESULT hr;
|
|
|
|
UINT bytesread;
|
2013-01-23 22:42:47 +01:00
|
|
|
int i;
|
|
|
|
DWORD j, sig;
|
2009-08-26 00:43:33 +02:00
|
|
|
|
|
|
|
/* seek to the start of the stream */
|
|
|
|
seek.QuadPart = 0;
|
|
|
|
hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr)) return hresult_to_status(hr);
|
|
|
|
|
|
|
|
/* read the first 8 bytes */
|
2010-03-08 23:42:36 +01:00
|
|
|
/* FIXME: This assumes all codecs have signatures <= 8 bytes in length */
|
2009-08-26 00:43:33 +02:00
|
|
|
hr = IStream_Read(stream, signature, 8, &bytesread);
|
|
|
|
if (FAILED(hr)) return hresult_to_status(hr);
|
|
|
|
if (hr == S_FALSE || bytesread == 0) return GenericError;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_CODECS; i++) {
|
|
|
|
if ((codecs[i].info.Flags & ImageCodecFlagsDecoder) &&
|
|
|
|
bytesread >= codecs[i].info.SigSize)
|
|
|
|
{
|
2010-03-08 23:42:36 +01:00
|
|
|
for (sig=0; sig<codecs[i].info.SigCount; sig++)
|
2009-08-26 00:43:33 +02:00
|
|
|
{
|
2010-03-08 23:42:36 +01:00
|
|
|
pattern = &codecs[i].info.SigPattern[codecs[i].info.SigSize*sig];
|
|
|
|
mask = &codecs[i].info.SigMask[codecs[i].info.SigSize*sig];
|
|
|
|
for (j=0; j<codecs[i].info.SigSize; j++)
|
|
|
|
if ((signature[j] & mask[j]) != pattern[j])
|
|
|
|
break;
|
|
|
|
if (j == codecs[i].info.SigSize)
|
|
|
|
{
|
|
|
|
*result = &codecs[i];
|
|
|
|
return Ok;
|
|
|
|
}
|
2009-08-26 00:43:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("no match for %i byte signature %x %x %x %x %x %x %x %x\n", bytesread,
|
|
|
|
signature[0],signature[1],signature[2],signature[3],
|
|
|
|
signature[4],signature[5],signature[6],signature[7]);
|
|
|
|
|
|
|
|
return GenericError;
|
|
|
|
}
|
|
|
|
|
2015-03-12 10:17:25 +01:00
|
|
|
static GpStatus get_decoder_info_from_image(GpImage *image, const struct image_codec **result)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_CODECS; i++) {
|
|
|
|
if ((codecs[i].info.Flags & ImageCodecFlagsDecoder) &&
|
|
|
|
IsEqualIID(&codecs[i].info.FormatID, &image->format))
|
|
|
|
{
|
|
|
|
*result = &codecs[i];
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("no match for format: %s\n", wine_dbgstr_guid(&image->format));
|
|
|
|
return GenericError;
|
|
|
|
}
|
|
|
|
|
2012-06-20 06:45:39 +02:00
|
|
|
GpStatus WINGDIPAPI GdipImageSelectActiveFrame(GpImage *image, GDIPCONST GUID *dimensionID,
|
|
|
|
UINT frame)
|
|
|
|
{
|
|
|
|
GpStatus stat;
|
|
|
|
const struct image_codec *codec = NULL;
|
2017-02-14 10:24:36 +01:00
|
|
|
BOOL unlock;
|
2012-06-20 06:45:39 +02:00
|
|
|
|
|
|
|
TRACE("(%p,%s,%u)\n", image, debugstr_guid(dimensionID), frame);
|
|
|
|
|
|
|
|
if (!image || !dimensionID)
|
|
|
|
return InvalidParameter;
|
2017-02-14 10:24:36 +01:00
|
|
|
if(!image_lock(image, &unlock))
|
|
|
|
return ObjectBusy;
|
2012-06-20 06:45:39 +02:00
|
|
|
|
|
|
|
if (frame >= image->frame_count)
|
2012-09-28 03:15:39 +02:00
|
|
|
{
|
|
|
|
WARN("requested frame %u, but image has only %u\n", frame, image->frame_count);
|
2017-02-14 10:24:36 +01:00
|
|
|
image_unlock(image, unlock);
|
2012-06-20 06:45:39 +02:00
|
|
|
return InvalidParameter;
|
2012-09-28 03:15:39 +02:00
|
|
|
}
|
2012-06-20 06:45:39 +02:00
|
|
|
|
|
|
|
if (image->type != ImageTypeBitmap && image->type != ImageTypeMetafile)
|
|
|
|
{
|
|
|
|
WARN("invalid image type %d\n", image->type);
|
2017-02-14 10:24:36 +01:00
|
|
|
image_unlock(image, unlock);
|
2012-06-20 06:45:39 +02:00
|
|
|
return InvalidParameter;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (image->current_frame == frame)
|
2017-02-14 10:24:36 +01:00
|
|
|
{
|
|
|
|
image_unlock(image, unlock);
|
2012-06-20 06:45:39 +02:00
|
|
|
return Ok;
|
2017-02-14 10:24:36 +01:00
|
|
|
}
|
2012-06-20 06:45:39 +02:00
|
|
|
|
2015-03-12 10:17:03 +01:00
|
|
|
if (!image->decoder)
|
|
|
|
{
|
|
|
|
TRACE("image doesn't have an associated decoder\n");
|
2017-02-14 10:24:36 +01:00
|
|
|
image_unlock(image, unlock);
|
2015-03-12 10:17:03 +01:00
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2012-06-20 06:45:39 +02:00
|
|
|
/* choose an appropriate image decoder */
|
2015-03-12 10:17:25 +01:00
|
|
|
stat = get_decoder_info_from_image(image, &codec);
|
2012-06-20 06:45:39 +02:00
|
|
|
if (stat != Ok)
|
|
|
|
{
|
2012-09-28 03:15:39 +02:00
|
|
|
WARN("can't find decoder info\n");
|
2017-02-14 10:24:36 +01:00
|
|
|
image_unlock(image, unlock);
|
2012-06-20 06:45:39 +02:00
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2017-02-14 10:24:36 +01:00
|
|
|
stat = codec->select_func(image, frame);
|
|
|
|
image_unlock(image, unlock);
|
|
|
|
return stat;
|
2012-06-20 06:45:39 +02:00
|
|
|
}
|
|
|
|
|
2012-06-27 07:29:08 +02:00
|
|
|
GpStatus WINGDIPAPI GdipLoadImageFromStream(IStream *stream, GpImage **image)
|
2009-08-26 00:43:33 +02:00
|
|
|
{
|
|
|
|
GpStatus stat;
|
|
|
|
LARGE_INTEGER seek;
|
|
|
|
HRESULT hr;
|
|
|
|
const struct image_codec *codec=NULL;
|
|
|
|
|
2018-02-28 07:34:34 +01:00
|
|
|
TRACE("%p %p\n", stream, image);
|
|
|
|
|
|
|
|
if (!stream || !image)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2009-08-26 00:43:33 +02:00
|
|
|
/* choose an appropriate image decoder */
|
|
|
|
stat = get_decoder_info(stream, &codec);
|
2012-06-27 07:29:08 +02:00
|
|
|
if (stat != Ok) return stat;
|
2009-08-26 00:43:33 +02:00
|
|
|
|
|
|
|
/* seek to the start of the stream */
|
|
|
|
seek.QuadPart = 0;
|
|
|
|
hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, NULL);
|
2012-06-27 07:29:08 +02:00
|
|
|
if (FAILED(hr)) return hresult_to_status(hr);
|
2009-08-26 00:43:33 +02:00
|
|
|
|
|
|
|
/* call on the image decoder to do the real work */
|
2015-03-12 10:17:03 +01:00
|
|
|
stat = codec->decode_func(stream, image);
|
2009-09-14 18:23:45 +02:00
|
|
|
|
|
|
|
/* take note of the original data format */
|
|
|
|
if (stat == Ok)
|
|
|
|
{
|
|
|
|
memcpy(&(*image)->format, &codec->info.FormatID, sizeof(GUID));
|
2012-06-19 09:51:54 +02:00
|
|
|
return Ok;
|
2009-09-14 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return stat;
|
2009-08-26 00:43:33 +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;
|
|
|
|
|
2009-12-18 23:12:51 +01:00
|
|
|
TRACE("(%p,%u)\n", image, propId);
|
|
|
|
|
2007-08-01 04:16:08 +02:00
|
|
|
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;
|
|
|
|
|
2012-07-03 04:58:21 +02:00
|
|
|
if (!image || !item) return InvalidParameter;
|
|
|
|
|
|
|
|
TRACE("(%p,%p:%#x,%u,%u,%p)\n", image, item, item->id, item->type, item->length, item->value);
|
2009-12-18 23:12:51 +01:00
|
|
|
|
2008-09-07 23:25:04 +02:00
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
2012-08-15 05:12:28 +02:00
|
|
|
return Ok;
|
2008-09-07 23:25:04 +02:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2020-02-19 08:47:07 +01:00
|
|
|
/* this might release an old file stream held by the encoder so we can re-create it below */
|
|
|
|
terminate_encoder_wic(image);
|
|
|
|
|
2008-03-10 16:16:54 +01:00
|
|
|
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
|
|
|
|
2020-02-19 08:47:03 +01:00
|
|
|
static GpStatus initialize_encoder_wic(IStream *stream, REFGUID container, GpImage *image)
|
|
|
|
{
|
|
|
|
IWICImagingFactory *factory;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p,%s\n", stream, wine_dbgstr_guid(container));
|
|
|
|
|
|
|
|
terminate_encoder_wic(image); /* terminate previous encoder if it exists */
|
|
|
|
|
|
|
|
hr = WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION, &factory);
|
|
|
|
if (FAILED(hr)) return hresult_to_status(hr);
|
|
|
|
hr = IWICImagingFactory_CreateEncoder(factory, container, NULL, &image->encoder);
|
|
|
|
IWICImagingFactory_Release(factory);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
image->encoder = NULL;
|
|
|
|
return hresult_to_status(hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IWICBitmapEncoder_Initialize(image->encoder, stream, WICBitmapEncoderNoCache);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IWICBitmapEncoder_Release(image->encoder);
|
|
|
|
image->encoder = NULL;
|
|
|
|
return hresult_to_status(hr);
|
|
|
|
}
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpStatus terminate_encoder_wic(GpImage *image)
|
|
|
|
{
|
|
|
|
if (!image->encoder)
|
|
|
|
return Ok;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HRESULT hr = IWICBitmapEncoder_Commit(image->encoder);
|
|
|
|
IWICBitmapEncoder_Release(image->encoder);
|
|
|
|
image->encoder = NULL;
|
|
|
|
return hresult_to_status(hr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GpStatus encode_frame_wic(IWICBitmapEncoder *encoder, GpImage *image)
|
2008-03-10 16:16:55 +01:00
|
|
|
{
|
2009-08-24 22:15:31 +02:00
|
|
|
GpStatus stat;
|
|
|
|
GpBitmap *bitmap;
|
|
|
|
IWICBitmapFrameEncode *frameencode;
|
|
|
|
IPropertyBag2 *encoderoptions;
|
|
|
|
HRESULT hr;
|
|
|
|
UINT width, height;
|
|
|
|
PixelFormat gdipformat=0;
|
2013-08-14 22:04:13 +02:00
|
|
|
const WICPixelFormatGUID *desired_wicformat;
|
2009-08-24 22:15:31 +02:00
|
|
|
WICPixelFormatGUID wicformat;
|
|
|
|
GpRect rc;
|
|
|
|
BitmapData lockeddata;
|
|
|
|
UINT i;
|
2008-03-10 16:16:56 +01:00
|
|
|
|
2009-08-24 22:15:31 +02:00
|
|
|
if (image->type != ImageTypeBitmap)
|
|
|
|
return GenericError;
|
|
|
|
|
|
|
|
bitmap = (GpBitmap*)image;
|
|
|
|
|
|
|
|
GdipGetImageWidth(image, &width);
|
|
|
|
GdipGetImageHeight(image, &height);
|
|
|
|
|
|
|
|
rc.X = 0;
|
|
|
|
rc.Y = 0;
|
|
|
|
rc.Width = width;
|
|
|
|
rc.Height = height;
|
|
|
|
|
2020-02-19 08:47:03 +01:00
|
|
|
hr = IWICBitmapEncoder_CreateNewFrame(encoder, &frameencode, &encoderoptions);
|
2009-08-24 22:15:31 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr)) /* created frame */
|
|
|
|
{
|
|
|
|
hr = IWICBitmapFrameEncode_Initialize(frameencode, encoderoptions);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IWICBitmapFrameEncode_SetSize(frameencode, width, height);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
2012-07-20 12:52:36 +02:00
|
|
|
hr = IWICBitmapFrameEncode_SetResolution(frameencode, image->xres, image->yres);
|
2009-08-24 22:15:31 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2012-07-18 10:26:38 +02:00
|
|
|
for (i=0; pixel_formats[i].wic_format; i++)
|
2009-08-24 22:15:31 +02:00
|
|
|
{
|
2012-07-18 10:26:38 +02:00
|
|
|
if (pixel_formats[i].gdip_format == bitmap->format)
|
|
|
|
{
|
2013-08-14 22:04:13 +02:00
|
|
|
desired_wicformat = pixel_formats[i].wic_format;
|
2012-07-18 10:26:38 +02:00
|
|
|
gdipformat = bitmap->format;
|
2012-07-26 04:29:25 +02:00
|
|
|
break;
|
2012-07-18 10:26:38 +02:00
|
|
|
}
|
2009-08-24 22:15:31 +02:00
|
|
|
}
|
2012-07-18 10:26:38 +02:00
|
|
|
if (!gdipformat)
|
|
|
|
{
|
2013-08-14 22:04:13 +02:00
|
|
|
desired_wicformat = &GUID_WICPixelFormat32bppBGRA;
|
2012-07-18 10:26:38 +02:00
|
|
|
gdipformat = PixelFormat32bppARGB;
|
|
|
|
}
|
2009-08-24 22:15:31 +02:00
|
|
|
|
2013-08-14 22:04:13 +02:00
|
|
|
memcpy(&wicformat, desired_wicformat, sizeof(GUID));
|
2009-08-24 22:15:31 +02:00
|
|
|
hr = IWICBitmapFrameEncode_SetPixelFormat(frameencode, &wicformat);
|
|
|
|
}
|
|
|
|
|
2013-08-14 22:04:13 +02:00
|
|
|
if (SUCCEEDED(hr) && !IsEqualGUID(desired_wicformat, &wicformat))
|
|
|
|
{
|
|
|
|
/* Encoder doesn't support this bitmap's format. */
|
|
|
|
gdipformat = 0;
|
|
|
|
for (i=0; pixel_formats[i].wic_format; i++)
|
|
|
|
{
|
|
|
|
if (IsEqualGUID(&wicformat, pixel_formats[i].wic_format))
|
|
|
|
{
|
2013-10-04 21:30:48 +02:00
|
|
|
gdipformat = pixel_formats[i].gdip_format;
|
2013-08-14 22:04:13 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!gdipformat)
|
|
|
|
{
|
|
|
|
ERR("Cannot support encoder format %s\n", debugstr_guid(&wicformat));
|
|
|
|
hr = E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-29 01:24:46 +02:00
|
|
|
if (SUCCEEDED(hr) && IsIndexedPixelFormat(gdipformat) && image->palette)
|
|
|
|
hr = set_palette(frameencode, image->palette);
|
|
|
|
|
2009-08-24 22:15:31 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
stat = GdipBitmapLockBits(bitmap, &rc, ImageLockModeRead, gdipformat,
|
|
|
|
&lockeddata);
|
|
|
|
|
|
|
|
if (stat == Ok)
|
|
|
|
{
|
|
|
|
UINT row_size = (lockeddata.Width * PIXELFORMATBPP(gdipformat) + 7)/8;
|
|
|
|
BYTE *row;
|
|
|
|
|
|
|
|
/* write one row at a time in case stride is negative */
|
|
|
|
row = lockeddata.Scan0;
|
|
|
|
for (i=0; i<lockeddata.Height; i++)
|
|
|
|
{
|
|
|
|
hr = IWICBitmapFrameEncode_WritePixels(frameencode, 1, row_size, row_size, row);
|
|
|
|
if (FAILED(hr)) break;
|
|
|
|
row += lockeddata.Stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
GdipBitmapUnlockBits(bitmap, &lockeddata);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IWICBitmapFrameEncode_Commit(frameencode);
|
|
|
|
|
|
|
|
IWICBitmapFrameEncode_Release(frameencode);
|
|
|
|
IPropertyBag2_Release(encoderoptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hresult_to_status(hr);
|
|
|
|
}
|
|
|
|
|
2020-02-19 08:47:07 +01:00
|
|
|
static BOOL has_encoder_param_long(GDIPCONST EncoderParameters *params, GUID param_guid, ULONG val)
|
|
|
|
{
|
|
|
|
int param_idx, value_idx;
|
|
|
|
|
|
|
|
if (!params)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (param_idx = 0; param_idx < params->Count; param_idx++)
|
|
|
|
{
|
|
|
|
EncoderParameter param = params->Parameter[param_idx];
|
|
|
|
if (param.Type == EncoderParameterValueTypeLong && IsEqualCLSID(¶m.Guid, ¶m_guid))
|
|
|
|
{
|
|
|
|
ULONG *value_array = (ULONG*) param.Value;
|
|
|
|
for (value_idx = 0; value_idx < param.NumberOfValues; value_idx++)
|
|
|
|
{
|
|
|
|
if (value_array[value_idx] == val)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-02-19 08:47:03 +01:00
|
|
|
static GpStatus encode_image_wic(GpImage *image, IStream *stream,
|
|
|
|
REFGUID container, GDIPCONST EncoderParameters *params)
|
|
|
|
{
|
|
|
|
GpStatus status, terminate_status;
|
|
|
|
|
|
|
|
if (image->type != ImageTypeBitmap)
|
|
|
|
return GenericError;
|
|
|
|
|
|
|
|
status = initialize_encoder_wic(stream, container, image);
|
|
|
|
|
|
|
|
if (status == Ok)
|
|
|
|
status = encode_frame_wic(image->encoder, image);
|
|
|
|
|
2020-02-19 08:47:07 +01:00
|
|
|
if (!has_encoder_param_long(params, EncoderSaveFlag, EncoderValueMultiFrame))
|
|
|
|
{
|
|
|
|
/* always try to terminate, but if something already failed earlier, keep the old status. */
|
|
|
|
terminate_status = terminate_encoder_wic(image);
|
|
|
|
if (status == Ok)
|
|
|
|
status = terminate_status;
|
|
|
|
}
|
2020-02-19 08:47:03 +01:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2009-08-24 22:15:31 +02:00
|
|
|
static GpStatus encode_image_BMP(GpImage *image, IStream* stream,
|
2017-07-10 11:29:56 +02:00
|
|
|
GDIPCONST EncoderParameters* params)
|
2009-08-24 22:15:31 +02:00
|
|
|
{
|
2015-03-06 11:20:57 +01:00
|
|
|
return encode_image_wic(image, stream, &GUID_ContainerFormatBmp, params);
|
2008-03-10 16:16:55 +01:00
|
|
|
}
|
|
|
|
|
2011-04-05 23:48:55 +02:00
|
|
|
static GpStatus encode_image_tiff(GpImage *image, IStream* stream,
|
2017-07-10 11:29:56 +02:00
|
|
|
GDIPCONST EncoderParameters* params)
|
2011-04-05 23:48:55 +02:00
|
|
|
{
|
2015-03-06 11:20:57 +01:00
|
|
|
return encode_image_wic(image, stream, &GUID_ContainerFormatTiff, params);
|
2011-04-05 23:48:55 +02:00
|
|
|
}
|
|
|
|
|
2017-07-10 11:30:08 +02:00
|
|
|
GpStatus encode_image_png(GpImage *image, IStream* stream,
|
2017-07-10 11:29:56 +02:00
|
|
|
GDIPCONST EncoderParameters* params)
|
2009-09-24 00:33:53 +02:00
|
|
|
{
|
2015-03-06 11:20:57 +01:00
|
|
|
return encode_image_wic(image, stream, &GUID_ContainerFormatPng, params);
|
2009-09-24 00:33:53 +02:00
|
|
|
}
|
|
|
|
|
2012-04-12 00:25:01 +02:00
|
|
|
static GpStatus encode_image_jpeg(GpImage *image, IStream* stream,
|
2017-07-10 11:29:56 +02:00
|
|
|
GDIPCONST EncoderParameters* params)
|
2012-04-12 00:25:01 +02:00
|
|
|
{
|
2015-03-06 11:20:57 +01:00
|
|
|
return encode_image_wic(image, stream, &GUID_ContainerFormatJpeg, params);
|
2012-04-12 00:25:01 +02:00
|
|
|
}
|
|
|
|
|
2015-07-13 09:02:12 +02:00
|
|
|
static GpStatus encode_image_gif(GpImage *image, IStream* stream,
|
2017-07-10 11:29:56 +02:00
|
|
|
GDIPCONST EncoderParameters* params)
|
2015-07-13 09:02:12 +02:00
|
|
|
{
|
2018-05-24 06:06:26 +02:00
|
|
|
return encode_image_wic(image, stream, &GUID_ContainerFormatGif, params);
|
2015-07-13 09:02:12 +02:00
|
|
|
}
|
|
|
|
|
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;
|
2009-08-21 00:21:41 +02:00
|
|
|
encode_image_func encode_image;
|
2008-03-10 16:16:55 +01:00
|
|
|
int i;
|
|
|
|
|
2018-05-24 06:06:28 +02:00
|
|
|
TRACE("%p, %p, %s, %p\n", image, stream, wine_dbgstr_guid(clsid), params);
|
2008-09-10 22:20:42 +02:00
|
|
|
|
2007-08-01 04:16:00 +02:00
|
|
|
if(!image || !stream)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2008-03-10 16:16:55 +01:00
|
|
|
/* select correct encoder */
|
|
|
|
encode_image = NULL;
|
2009-08-21 00:33:39 +02:00
|
|
|
for (i = 0; i < NUM_CODECS; i++) {
|
2009-08-21 00:36:36 +02:00
|
|
|
if ((codecs[i].info.Flags & ImageCodecFlagsEncoder) &&
|
|
|
|
IsEqualCLSID(clsid, &codecs[i].info.Clsid))
|
2009-08-21 00:21:41 +02:00
|
|
|
encode_image = codecs[i].encode_func;
|
2008-03-10 16:16:55 +01:00
|
|
|
}
|
|
|
|
if (encode_image == NULL)
|
|
|
|
return UnknownImageFormat;
|
2007-08-01 04:16:00 +02:00
|
|
|
|
2017-07-10 11:29:56 +02:00
|
|
|
stat = encode_image(image, stream, params);
|
2008-03-10 16:16:55 +01:00
|
|
|
|
|
|
|
return stat;
|
2007-08-01 04:16:00 +02:00
|
|
|
}
|
2007-08-09 04:42:16 +02:00
|
|
|
|
2012-06-29 11:48:50 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipSaveAdd [GDIPLUS.@]
|
2020-02-19 08:47:05 +01:00
|
|
|
*
|
|
|
|
* Like GdipSaveAddImage(), but encode the currently active frame of the given image into the file
|
|
|
|
* or stream that is currently being encoded.
|
2012-06-29 11:48:50 +02:00
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipSaveAdd(GpImage *image, GDIPCONST EncoderParameters *params)
|
|
|
|
{
|
2020-02-19 08:47:07 +01:00
|
|
|
return GdipSaveAddImage(image, image, params);
|
2020-02-19 08:47:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GdipSaveAddImage [GDIPLUS.@]
|
|
|
|
*
|
|
|
|
* Encode the currently active frame of additional_image into the file or stream that is currently
|
|
|
|
* being encoded by the image given in the image parameter. The first frame of a multi-frame image
|
|
|
|
* must be encoded using the normal GdipSaveImageToStream() or GdipSaveImageToFile() functions,
|
|
|
|
* but with the "MultiFrame" encoding parameter set. The multi-frame encoding process must be
|
|
|
|
* finished after adding the last frame by calling GdipSaveAdd() with the "Flush" encoding parameter
|
|
|
|
* set.
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipSaveAddImage(GpImage *image, GpImage *additional_image,
|
|
|
|
GDIPCONST EncoderParameters *params)
|
|
|
|
{
|
2020-02-19 08:47:07 +01:00
|
|
|
TRACE("%p, %p, %p\n", image, additional_image, params);
|
|
|
|
|
|
|
|
if (!image || !additional_image || !params)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if (!image->encoder)
|
|
|
|
return Win32Error;
|
|
|
|
|
|
|
|
if (has_encoder_param_long(params, EncoderSaveFlag, EncoderValueFlush))
|
|
|
|
return terminate_encoder_wic(image);
|
|
|
|
else if (has_encoder_param_long(params, EncoderSaveFlag, EncoderValueFrameDimensionPage))
|
|
|
|
return encode_frame_wic(image->encoder, additional_image);
|
|
|
|
else
|
|
|
|
return InvalidParameter;
|
2012-06-29 11:48:50 +02:00
|
|
|
}
|
|
|
|
|
2009-07-24 13:48:15 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipGetImagePalette [GDIPLUS.@]
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipGetImagePalette(GpImage *image, ColorPalette *palette, INT size)
|
|
|
|
{
|
2012-07-17 07:59:43 +02:00
|
|
|
INT count;
|
|
|
|
|
2009-12-12 00:00:19 +01:00
|
|
|
TRACE("(%p,%p,%i)\n", image, palette, size);
|
2009-07-24 13:48:15 +02:00
|
|
|
|
2009-12-12 00:00:19 +01:00
|
|
|
if (!image || !palette)
|
2009-07-24 13:48:15 +02:00
|
|
|
return InvalidParameter;
|
|
|
|
|
2012-07-17 07:59:43 +02:00
|
|
|
count = image->palette ? image->palette->Count : 0;
|
|
|
|
|
|
|
|
if (size < (sizeof(UINT)*2+sizeof(ARGB)*count))
|
2009-12-12 00:00:19 +01:00
|
|
|
{
|
|
|
|
TRACE("<-- InsufficientBuffer\n");
|
|
|
|
return InsufficientBuffer;
|
|
|
|
}
|
2009-07-24 13:48:15 +02:00
|
|
|
|
2012-07-17 07:59:43 +02:00
|
|
|
if (image->palette)
|
|
|
|
{
|
|
|
|
palette->Flags = image->palette->Flags;
|
|
|
|
palette->Count = image->palette->Count;
|
|
|
|
memcpy(palette->Entries, image->palette->Entries, sizeof(ARGB)*image->palette->Count);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
palette->Flags = 0;
|
|
|
|
palette->Count = 0;
|
|
|
|
}
|
2009-12-12 00:00:19 +01:00
|
|
|
return Ok;
|
2009-07-24 13:48:15 +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)
|
|
|
|
{
|
2012-07-17 07:59:43 +02:00
|
|
|
ColorPalette *new_palette;
|
|
|
|
|
2009-12-11 23:51:46 +01:00
|
|
|
TRACE("(%p,%p)\n", image, palette);
|
2007-08-09 04:42:16 +02:00
|
|
|
|
2009-12-11 23:51:46 +01:00
|
|
|
if(!image || !palette || palette->Count > 256)
|
2007-08-09 04:42:16 +02:00
|
|
|
return InvalidParameter;
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
new_palette = heap_alloc_zero(2 * sizeof(UINT) + palette->Count * sizeof(ARGB));
|
2012-07-17 07:59:43 +02:00
|
|
|
if (!new_palette) return OutOfMemory;
|
2009-12-11 23:51:46 +01:00
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(image->palette);
|
2012-07-17 07:59:43 +02:00
|
|
|
image->palette = new_palette;
|
|
|
|
image->palette->Flags = palette->Flags;
|
|
|
|
image->palette->Count = palette->Count;
|
|
|
|
memcpy(image->palette->Entries, palette->Entries, sizeof(ARGB)*palette->Count);
|
2009-12-11 23:51:46 +01:00
|
|
|
|
|
|
|
return Ok;
|
2007-08-09 04:42:16 +02:00
|
|
|
}
|
2008-03-06 10:17:00 +01:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* Encoders -
|
|
|
|
* Structures that represent which formats we support for encoding.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ImageCodecInfo creation routines taken from libgdiplus */
|
2020-11-13 00:20:30 +01:00
|
|
|
static const WCHAR bmp_codecname[] = L"Built-in BMP";
|
|
|
|
static const WCHAR bmp_extension[] = L"*.BMP;*.DIB;*.RLE";
|
|
|
|
static const WCHAR bmp_mimetype[] = L"image/bmp";
|
|
|
|
static const WCHAR bmp_format[] = L"BMP";
|
2008-03-06 10:17:00 +01:00
|
|
|
static const BYTE bmp_sig_pattern[] = { 0x42, 0x4D };
|
|
|
|
static const BYTE bmp_sig_mask[] = { 0xFF, 0xFF };
|
|
|
|
|
2020-11-13 00:20:30 +01:00
|
|
|
static const WCHAR jpeg_codecname[] = L"Built-in JPEG";
|
|
|
|
static const WCHAR jpeg_extension[] = L"*.JPG;*.JPEG;*.JPE;*.JFIF";
|
|
|
|
static const WCHAR jpeg_mimetype[] = L"image/jpeg";
|
|
|
|
static const WCHAR jpeg_format[] = L"JPEG";
|
2009-08-21 00:59:13 +02:00
|
|
|
static const BYTE jpeg_sig_pattern[] = { 0xFF, 0xD8 };
|
|
|
|
static const BYTE jpeg_sig_mask[] = { 0xFF, 0xFF };
|
|
|
|
|
2020-11-13 00:20:30 +01:00
|
|
|
static const WCHAR gif_codecname[] = L"Built-in GIF";
|
|
|
|
static const WCHAR gif_extension[] = L"*.GIF";
|
|
|
|
static const WCHAR gif_mimetype[] = L"image/gif";
|
|
|
|
static const WCHAR gif_format[] = L"GIF";
|
2012-08-27 05:04:31 +02:00
|
|
|
static const BYTE gif_sig_pattern[12] = "GIF87aGIF89a";
|
|
|
|
static const BYTE gif_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
2009-08-21 00:59:13 +02:00
|
|
|
|
2020-11-13 00:20:30 +01:00
|
|
|
static const WCHAR tiff_codecname[] = L"Built-in TIFF";
|
|
|
|
static const WCHAR tiff_extension[] = L"*.TIFF;*.TIF";
|
|
|
|
static const WCHAR tiff_mimetype[] = L"image/tiff";
|
|
|
|
static const WCHAR tiff_format[] = L"TIFF";
|
2010-03-08 23:42:51 +01:00
|
|
|
static const BYTE tiff_sig_pattern[] = {0x49,0x49,42,0,0x4d,0x4d,0,42};
|
|
|
|
static const BYTE tiff_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
|
|
|
|
2020-11-13 00:20:30 +01:00
|
|
|
static const WCHAR emf_codecname[] = L"Built-in EMF";
|
|
|
|
static const WCHAR emf_extension[] = L"*.EMF";
|
|
|
|
static const WCHAR emf_mimetype[] = L"image/x-emf";
|
|
|
|
static const WCHAR emf_format[] = L"EMF";
|
2009-08-21 00:59:13 +02:00
|
|
|
static const BYTE emf_sig_pattern[] = { 0x01, 0x00, 0x00, 0x00 };
|
|
|
|
static const BYTE emf_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF };
|
|
|
|
|
2020-11-13 00:20:30 +01:00
|
|
|
static const WCHAR wmf_codecname[] = L"Built-in WMF";
|
|
|
|
static const WCHAR wmf_extension[] = L"*.WMF";
|
|
|
|
static const WCHAR wmf_mimetype[] = L"image/x-wmf";
|
|
|
|
static const WCHAR wmf_format[] = L"WMF";
|
2009-08-21 00:59:13 +02:00
|
|
|
static const BYTE wmf_sig_pattern[] = { 0xd7, 0xcd };
|
|
|
|
static const BYTE wmf_sig_mask[] = { 0xFF, 0xFF };
|
|
|
|
|
2020-11-13 00:20:30 +01:00
|
|
|
static const WCHAR png_codecname[] = L"Built-in PNG";
|
|
|
|
static const WCHAR png_extension[] = L"*.PNG";
|
|
|
|
static const WCHAR png_mimetype[] = L"image/png";
|
|
|
|
static const WCHAR png_format[] = L"PNG";
|
2009-08-25 23:53:56 +02:00
|
|
|
static const BYTE png_sig_pattern[] = { 137, 80, 78, 71, 13, 10, 26, 10, };
|
|
|
|
static const BYTE png_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
|
|
|
|
2020-11-13 00:20:30 +01:00
|
|
|
static const WCHAR ico_codecname[] = L"Built-in ICO";
|
|
|
|
static const WCHAR ico_extension[] = L"*.ICO";
|
|
|
|
static const WCHAR ico_mimetype[] = L"image/x-icon";
|
|
|
|
static const WCHAR ico_format[] = L"ICO";
|
2009-08-21 00:59:13 +02:00
|
|
|
static const BYTE ico_sig_pattern[] = { 0x00, 0x00, 0x01, 0x00 };
|
|
|
|
static const BYTE ico_sig_mask[] = { 0xFF, 0xFF, 0xFF, 0xFF };
|
|
|
|
|
2009-08-21 00:33:39 +02:00
|
|
|
static const struct image_codec codecs[NUM_CODECS] = {
|
2008-03-06 10:17:00 +01:00
|
|
|
{
|
|
|
|
{ /* 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,
|
|
|
|
},
|
2009-08-26 00:43:33 +02:00
|
|
|
encode_image_BMP,
|
2015-03-12 10:17:03 +01:00
|
|
|
decode_image_bmp,
|
|
|
|
select_frame_wic
|
2009-08-21 00:59:13 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
{ /* JPEG */
|
|
|
|
/* Clsid */ { 0x557cf401, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
|
|
|
|
/* FormatID */ { 0xb96b3caeU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
|
|
|
|
/* CodecName */ jpeg_codecname,
|
|
|
|
/* DllName */ NULL,
|
|
|
|
/* FormatDescription */ jpeg_format,
|
|
|
|
/* FilenameExtension */ jpeg_extension,
|
|
|
|
/* MimeType */ jpeg_mimetype,
|
2012-04-12 00:25:01 +02:00
|
|
|
/* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
|
2009-08-21 00:59:13 +02:00
|
|
|
/* Version */ 1,
|
|
|
|
/* SigCount */ 1,
|
|
|
|
/* SigSize */ 2,
|
|
|
|
/* SigPattern */ jpeg_sig_pattern,
|
|
|
|
/* SigMask */ jpeg_sig_mask,
|
|
|
|
},
|
2012-04-12 00:25:01 +02:00
|
|
|
encode_image_jpeg,
|
2015-03-12 10:17:03 +01:00
|
|
|
decode_image_jpeg,
|
|
|
|
select_frame_wic
|
2009-08-21 00:59:13 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
{ /* GIF */
|
|
|
|
/* Clsid */ { 0x557cf402, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
|
|
|
|
/* FormatID */ { 0xb96b3cb0U, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
|
|
|
|
/* CodecName */ gif_codecname,
|
|
|
|
/* DllName */ NULL,
|
|
|
|
/* FormatDescription */ gif_format,
|
|
|
|
/* FilenameExtension */ gif_extension,
|
|
|
|
/* MimeType */ gif_mimetype,
|
2015-07-13 09:02:12 +02:00
|
|
|
/* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsEncoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
|
2009-08-21 00:59:13 +02:00
|
|
|
/* Version */ 1,
|
2012-08-27 05:04:31 +02:00
|
|
|
/* SigCount */ 2,
|
|
|
|
/* SigSize */ 6,
|
2009-08-21 00:59:13 +02:00
|
|
|
/* SigPattern */ gif_sig_pattern,
|
|
|
|
/* SigMask */ gif_sig_mask,
|
|
|
|
},
|
2015-07-13 09:02:12 +02:00
|
|
|
encode_image_gif,
|
2015-03-12 10:17:03 +01:00
|
|
|
decode_image_gif,
|
|
|
|
select_frame_gif
|
2009-08-21 00:59:13 +02:00
|
|
|
},
|
2010-03-08 23:42:51 +01:00
|
|
|
{
|
|
|
|
{ /* TIFF */
|
|
|
|
/* Clsid */ { 0x557cf405, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
|
|
|
|
/* FormatID */ { 0xb96b3cb1U, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
|
|
|
|
/* CodecName */ tiff_codecname,
|
|
|
|
/* DllName */ NULL,
|
|
|
|
/* FormatDescription */ tiff_format,
|
|
|
|
/* FilenameExtension */ tiff_extension,
|
|
|
|
/* MimeType */ tiff_mimetype,
|
2011-04-05 23:48:55 +02:00
|
|
|
/* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsEncoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
|
2010-03-08 23:42:51 +01:00
|
|
|
/* Version */ 1,
|
|
|
|
/* SigCount */ 2,
|
|
|
|
/* SigSize */ 4,
|
|
|
|
/* SigPattern */ tiff_sig_pattern,
|
|
|
|
/* SigMask */ tiff_sig_mask,
|
|
|
|
},
|
2011-04-05 23:48:55 +02:00
|
|
|
encode_image_tiff,
|
2015-03-12 10:17:03 +01:00
|
|
|
decode_image_tiff,
|
|
|
|
select_frame_wic
|
2010-03-08 23:42:51 +01:00
|
|
|
},
|
2009-08-21 00:59:13 +02:00
|
|
|
{
|
|
|
|
{ /* EMF */
|
|
|
|
/* Clsid */ { 0x557cf403, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
|
|
|
|
/* FormatID */ { 0xb96b3cacU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
|
|
|
|
/* CodecName */ emf_codecname,
|
|
|
|
/* DllName */ NULL,
|
|
|
|
/* FormatDescription */ emf_format,
|
|
|
|
/* FilenameExtension */ emf_extension,
|
|
|
|
/* MimeType */ emf_mimetype,
|
|
|
|
/* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportVector | ImageCodecFlagsBuiltin,
|
|
|
|
/* Version */ 1,
|
|
|
|
/* SigCount */ 1,
|
|
|
|
/* SigSize */ 4,
|
|
|
|
/* SigPattern */ emf_sig_pattern,
|
|
|
|
/* SigMask */ emf_sig_mask,
|
|
|
|
},
|
2009-08-26 00:43:33 +02:00
|
|
|
NULL,
|
2016-08-18 21:22:02 +02:00
|
|
|
decode_image_emf,
|
2015-03-12 10:17:03 +01:00
|
|
|
NULL
|
2009-08-21 00:59:13 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
{ /* WMF */
|
|
|
|
/* Clsid */ { 0x557cf404, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
|
|
|
|
/* FormatID */ { 0xb96b3cadU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
|
|
|
|
/* CodecName */ wmf_codecname,
|
|
|
|
/* DllName */ NULL,
|
|
|
|
/* FormatDescription */ wmf_format,
|
|
|
|
/* FilenameExtension */ wmf_extension,
|
|
|
|
/* MimeType */ wmf_mimetype,
|
|
|
|
/* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportVector | ImageCodecFlagsBuiltin,
|
|
|
|
/* Version */ 1,
|
|
|
|
/* SigCount */ 1,
|
|
|
|
/* SigSize */ 2,
|
|
|
|
/* SigPattern */ wmf_sig_pattern,
|
|
|
|
/* SigMask */ wmf_sig_mask,
|
|
|
|
},
|
2009-08-26 00:43:33 +02:00
|
|
|
NULL,
|
2016-08-18 21:22:02 +02:00
|
|
|
decode_image_wmf,
|
2015-03-12 10:17:03 +01:00
|
|
|
NULL
|
2009-08-21 00:59:13 +02:00
|
|
|
},
|
2009-08-25 23:53:56 +02:00
|
|
|
{
|
|
|
|
{ /* PNG */
|
|
|
|
/* Clsid */ { 0x557cf406, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
|
|
|
|
/* FormatID */ { 0xb96b3cafU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
|
|
|
|
/* CodecName */ png_codecname,
|
|
|
|
/* DllName */ NULL,
|
|
|
|
/* FormatDescription */ png_format,
|
|
|
|
/* FilenameExtension */ png_extension,
|
|
|
|
/* MimeType */ png_mimetype,
|
2009-09-24 00:33:53 +02:00
|
|
|
/* Flags */ ImageCodecFlagsEncoder | ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
|
2009-08-25 23:53:56 +02:00
|
|
|
/* Version */ 1,
|
|
|
|
/* SigCount */ 1,
|
|
|
|
/* SigSize */ 8,
|
|
|
|
/* SigPattern */ png_sig_pattern,
|
|
|
|
/* SigMask */ png_sig_mask,
|
|
|
|
},
|
2009-09-24 00:33:53 +02:00
|
|
|
encode_image_png,
|
2015-03-12 10:17:03 +01:00
|
|
|
decode_image_png,
|
|
|
|
select_frame_wic
|
2009-08-25 23:53:56 +02:00
|
|
|
},
|
2009-08-21 00:59:13 +02:00
|
|
|
{
|
|
|
|
{ /* ICO */
|
|
|
|
/* Clsid */ { 0x557cf407, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } },
|
|
|
|
/* FormatID */ { 0xb96b3cabU, 0x0728U, 0x11d3U, {0x9d, 0x7b, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e} },
|
|
|
|
/* CodecName */ ico_codecname,
|
|
|
|
/* DllName */ NULL,
|
|
|
|
/* FormatDescription */ ico_format,
|
|
|
|
/* FilenameExtension */ ico_extension,
|
|
|
|
/* MimeType */ ico_mimetype,
|
|
|
|
/* Flags */ ImageCodecFlagsDecoder | ImageCodecFlagsSupportBitmap | ImageCodecFlagsBuiltin,
|
|
|
|
/* Version */ 1,
|
|
|
|
/* SigCount */ 1,
|
|
|
|
/* SigSize */ 4,
|
|
|
|
/* SigPattern */ ico_sig_pattern,
|
|
|
|
/* SigMask */ ico_sig_mask,
|
|
|
|
},
|
2009-08-26 00:43:33 +02:00
|
|
|
NULL,
|
2015-03-12 10:17:03 +01:00
|
|
|
decode_image_icon,
|
|
|
|
select_frame_wic
|
2009-08-21 00:59:13 +02:00
|
|
|
},
|
2009-08-21 00:21:41 +02:00
|
|
|
};
|
2008-03-06 10:17:00 +01:00
|
|
|
|
2008-09-13 02:40:28 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipGetImageDecodersSize [GDIPLUS.@]
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipGetImageDecodersSize(UINT *numDecoders, UINT *size)
|
|
|
|
{
|
2009-08-21 00:33:39 +02:00
|
|
|
int decoder_count=0;
|
|
|
|
int i;
|
|
|
|
TRACE("%p %p\n", numDecoders, size);
|
2008-09-13 02:40:28 +02:00
|
|
|
|
|
|
|
if (!numDecoders || !size)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2009-08-21 00:33:39 +02:00
|
|
|
for (i=0; i<NUM_CODECS; i++)
|
|
|
|
{
|
|
|
|
if (codecs[i].info.Flags & ImageCodecFlagsDecoder)
|
|
|
|
decoder_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*numDecoders = decoder_count;
|
|
|
|
*size = decoder_count * sizeof(ImageCodecInfo);
|
2008-09-13 02:40:28 +02:00
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GdipGetImageDecoders [GDIPLUS.@]
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipGetImageDecoders(UINT numDecoders, UINT size, ImageCodecInfo *decoders)
|
|
|
|
{
|
2009-08-21 00:33:39 +02:00
|
|
|
int i, decoder_count=0;
|
|
|
|
TRACE("%u %u %p\n", numDecoders, size, decoders);
|
2008-09-13 02:40:28 +02:00
|
|
|
|
2009-08-21 00:33:39 +02:00
|
|
|
if (!decoders ||
|
|
|
|
size != numDecoders * sizeof(ImageCodecInfo))
|
2008-09-13 02:40:28 +02:00
|
|
|
return GenericError;
|
|
|
|
|
2009-08-21 00:33:39 +02:00
|
|
|
for (i=0; i<NUM_CODECS; i++)
|
|
|
|
{
|
|
|
|
if (codecs[i].info.Flags & ImageCodecFlagsDecoder)
|
|
|
|
{
|
|
|
|
if (decoder_count == numDecoders) return GenericError;
|
|
|
|
memcpy(&decoders[decoder_count], &codecs[i].info, sizeof(ImageCodecInfo));
|
|
|
|
decoder_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (decoder_count < numDecoders) return GenericError;
|
|
|
|
|
|
|
|
return Ok;
|
2008-09-13 02:40:28 +02:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2009-08-21 00:33:39 +02:00
|
|
|
int encoder_count=0;
|
|
|
|
int i;
|
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;
|
|
|
|
|
2009-08-21 00:33:39 +02:00
|
|
|
for (i=0; i<NUM_CODECS; i++)
|
|
|
|
{
|
|
|
|
if (codecs[i].info.Flags & ImageCodecFlagsEncoder)
|
|
|
|
encoder_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*numEncoders = encoder_count;
|
|
|
|
*size = encoder_count * sizeof(ImageCodecInfo);
|
2008-03-06 10:17:00 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2009-08-21 00:33:39 +02:00
|
|
|
int i, encoder_count=0;
|
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 ||
|
2009-08-21 00:33:39 +02:00
|
|
|
size != numEncoders * sizeof(ImageCodecInfo))
|
2008-03-06 10:17:00 +01:00
|
|
|
return GenericError;
|
|
|
|
|
2009-08-21 00:33:39 +02:00
|
|
|
for (i=0; i<NUM_CODECS; i++)
|
|
|
|
{
|
|
|
|
if (codecs[i].info.Flags & ImageCodecFlagsEncoder)
|
|
|
|
{
|
|
|
|
if (encoder_count == numEncoders) return GenericError;
|
|
|
|
memcpy(&encoders[encoder_count], &codecs[i].info, sizeof(ImageCodecInfo));
|
|
|
|
encoder_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (encoder_count < numEncoders) return GenericError;
|
2008-03-06 10:17:00 +01:00
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
2008-07-26 19:20:33 +02:00
|
|
|
|
2010-06-19 23:40:11 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetEncoderParameterListSize(GpImage *image,
|
|
|
|
GDIPCONST CLSID* clsidEncoder, UINT *size)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
TRACE("(%p,%s,%p)\n", image, debugstr_guid(clsidEncoder), size);
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
*size = 0;
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2012-03-29 21:18:15 +02:00
|
|
|
static PixelFormat get_16bpp_format(HBITMAP hbm)
|
|
|
|
{
|
|
|
|
BITMAPV4HEADER bmh;
|
|
|
|
HDC hdc;
|
|
|
|
PixelFormat result;
|
|
|
|
|
|
|
|
hdc = CreateCompatibleDC(NULL);
|
|
|
|
|
|
|
|
memset(&bmh, 0, sizeof(bmh));
|
|
|
|
bmh.bV4Size = sizeof(bmh);
|
|
|
|
bmh.bV4Width = 1;
|
|
|
|
bmh.bV4Height = 1;
|
|
|
|
bmh.bV4V4Compression = BI_BITFIELDS;
|
|
|
|
bmh.bV4BitCount = 16;
|
|
|
|
|
|
|
|
GetDIBits(hdc, hbm, 0, 0, NULL, (BITMAPINFO*)&bmh, DIB_RGB_COLORS);
|
|
|
|
|
|
|
|
if (bmh.bV4RedMask == 0x7c00 &&
|
|
|
|
bmh.bV4GreenMask == 0x3e0 &&
|
|
|
|
bmh.bV4BlueMask == 0x1f)
|
|
|
|
{
|
|
|
|
result = PixelFormat16bppRGB555;
|
|
|
|
}
|
|
|
|
else if (bmh.bV4RedMask == 0xf800 &&
|
|
|
|
bmh.bV4GreenMask == 0x7e0 &&
|
|
|
|
bmh.bV4BlueMask == 0x1f)
|
|
|
|
{
|
|
|
|
result = PixelFormat16bppRGB565;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("unrecognized bitfields %x,%x,%x\n", bmh.bV4RedMask,
|
|
|
|
bmh.bV4GreenMask, bmh.bV4BlueMask);
|
|
|
|
result = PixelFormatUndefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeleteDC(hdc);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
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;
|
2009-12-13 00:13:39 +01:00
|
|
|
BitmapData lockeddata;
|
2020-01-27 05:13:40 +01:00
|
|
|
char bmibuf[FIELD_OFFSET(BITMAPINFO, bmiColors[256])];
|
|
|
|
BITMAPINFO *pbmi = (BITMAPINFO *)bmibuf;
|
2008-03-22 00:39:22 +01:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
2012-01-11 20:41:19 +01:00
|
|
|
case 16:
|
2012-03-29 21:18:15 +02:00
|
|
|
format = get_16bpp_format(hbm);
|
|
|
|
if (format == PixelFormatUndefined)
|
2012-01-11 20:41:19 +01:00
|
|
|
return InvalidParameter;
|
|
|
|
break;
|
2008-03-22 00:39:22 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-12-13 00:13:39 +01:00
|
|
|
retval = GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, 0,
|
|
|
|
format, NULL, bitmap);
|
|
|
|
|
|
|
|
if (retval == Ok)
|
2009-02-17 21:39:17 +01:00
|
|
|
{
|
2009-12-13 00:13:39 +01:00
|
|
|
retval = GdipBitmapLockBits(*bitmap, NULL, ImageLockModeWrite,
|
|
|
|
format, &lockeddata);
|
|
|
|
if (retval == Ok)
|
|
|
|
{
|
2012-12-05 17:36:40 +01:00
|
|
|
HDC hdc;
|
2012-12-05 17:42:49 +01:00
|
|
|
INT src_height;
|
2009-12-13 00:33:58 +01:00
|
|
|
|
2012-12-05 17:36:40 +01:00
|
|
|
hdc = CreateCompatibleDC(NULL);
|
2009-12-13 00:33:58 +01:00
|
|
|
|
2013-01-15 05:48:56 +01:00
|
|
|
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
pbmi->bmiHeader.biBitCount = 0;
|
2009-12-13 00:33:58 +01:00
|
|
|
|
2013-01-15 05:48:56 +01:00
|
|
|
GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
|
2009-12-13 00:33:58 +01:00
|
|
|
|
2013-01-15 05:48:56 +01:00
|
|
|
src_height = abs(pbmi->bmiHeader.biHeight);
|
|
|
|
pbmi->bmiHeader.biHeight = -src_height;
|
2009-12-13 00:33:58 +01:00
|
|
|
|
2013-01-15 05:48:56 +01:00
|
|
|
GetDIBits(hdc, hbm, 0, src_height, lockeddata.Scan0, pbmi, DIB_RGB_COLORS);
|
2012-12-05 17:36:40 +01:00
|
|
|
|
|
|
|
DeleteDC(hdc);
|
2009-02-17 21:39:17 +01:00
|
|
|
|
2009-12-13 00:13:39 +01:00
|
|
|
GdipBitmapUnlockBits(*bitmap, &lockeddata);
|
|
|
|
}
|
2011-03-28 23:03:29 +02:00
|
|
|
|
2020-01-27 05:13:40 +01:00
|
|
|
/* According to the tests hpal is ignored */
|
|
|
|
if (retval == Ok && pbmi->bmiHeader.biBitCount <= 8)
|
2011-03-28 23:03:29 +02:00
|
|
|
{
|
2020-01-27 05:13:40 +01:00
|
|
|
ColorPalette *palette;
|
2013-01-15 05:48:34 +01:00
|
|
|
int i, num_palette_entries;
|
2011-03-28 23:03:29 +02:00
|
|
|
|
2020-01-27 05:13:40 +01:00
|
|
|
num_palette_entries = pbmi->bmiHeader.biClrUsed;
|
2013-01-15 05:48:34 +01:00
|
|
|
if (!num_palette_entries)
|
2020-01-27 05:13:40 +01:00
|
|
|
num_palette_entries = 1 << pbmi->bmiHeader.biBitCount;
|
2011-03-28 23:03:29 +02:00
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
palette = heap_alloc_zero(sizeof(ColorPalette) + sizeof(ARGB) * (num_palette_entries-1));
|
2013-01-15 05:48:34 +01:00
|
|
|
if (!palette)
|
|
|
|
retval = OutOfMemory;
|
2020-01-27 05:13:40 +01:00
|
|
|
else
|
2011-03-28 23:03:29 +02:00
|
|
|
{
|
|
|
|
palette->Flags = 0;
|
|
|
|
palette->Count = num_palette_entries;
|
|
|
|
|
|
|
|
for (i=0; i<num_palette_entries; i++)
|
|
|
|
{
|
2020-01-27 05:13:40 +01:00
|
|
|
palette->Entries[i] = 0xff000000 | pbmi->bmiColors[i].rgbRed << 16 |
|
|
|
|
pbmi->bmiColors[i].rgbGreen << 8 | pbmi->bmiColors[i].rgbBlue;
|
2011-03-28 23:03:29 +02:00
|
|
|
}
|
|
|
|
|
2016-08-05 08:32:46 +02:00
|
|
|
retval = GdipSetImagePalette(&(*bitmap)->image, palette);
|
2011-03-28 23:03:29 +02:00
|
|
|
}
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(palette);
|
2011-03-28 23:03:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (retval != Ok)
|
|
|
|
{
|
2016-08-05 08:32:46 +02:00
|
|
|
GdipDisposeImage(&(*bitmap)->image);
|
2011-03-28 23:03:29 +02:00
|
|
|
*bitmap = NULL;
|
|
|
|
}
|
2009-12-13 00:13:39 +01:00
|
|
|
}
|
2008-03-22 00:39:22 +01:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2008-04-09 22:00:16 +02:00
|
|
|
|
2015-10-09 09:07:50 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipCreateEffect [GDIPLUS.@]
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipCreateEffect(const GUID guid, CGpEffect **effect)
|
|
|
|
{
|
|
|
|
FIXME("(%s, %p): stub\n", debugstr_guid(&guid), effect);
|
|
|
|
|
|
|
|
if(!effect)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
*effect = NULL;
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GdipDeleteEffect [GDIPLUS.@]
|
|
|
|
*/
|
2009-06-03 05:33:32 +02:00
|
|
|
GpStatus WINGDIPAPI GdipDeleteEffect(CGpEffect *effect)
|
|
|
|
{
|
|
|
|
FIXME("(%p): stub\n", effect);
|
|
|
|
/* note: According to Jose Roca's GDI+ Docs, this is not implemented
|
|
|
|
* in Windows's gdiplus */
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2009-12-18 23:12:51 +01:00
|
|
|
TRACE("(%p,%p,%u)\n", effect, params, size);
|
|
|
|
|
2008-04-09 22:00:16 +02:00
|
|
|
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
|
|
|
|
2008-11-24 10:23:03 +01:00
|
|
|
GpStatus WINGDIPAPI GdipImageForceValidation(GpImage *image)
|
|
|
|
{
|
2010-05-08 19:40:45 +02:00
|
|
|
TRACE("%p\n", image);
|
2008-11-24 10:23:03 +01:00
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
2009-05-05 22:02:25 +02:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GdipGetImageThumbnail [GDIPLUS.@]
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipGetImageThumbnail(GpImage *image, UINT width, UINT height,
|
|
|
|
GpImage **ret_image, GetThumbnailImageAbort cb,
|
|
|
|
VOID * cb_data)
|
|
|
|
{
|
2010-05-08 20:29:53 +02:00
|
|
|
GpStatus stat;
|
|
|
|
GpGraphics *graphics;
|
|
|
|
UINT srcwidth, srcheight;
|
|
|
|
|
|
|
|
TRACE("(%p %u %u %p %p %p)\n",
|
2009-05-05 22:02:25 +02:00
|
|
|
image, width, height, ret_image, cb, cb_data);
|
2010-05-08 20:29:53 +02:00
|
|
|
|
|
|
|
if (!image || !ret_image)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if (!width) width = 120;
|
|
|
|
if (!height) height = 120;
|
|
|
|
|
|
|
|
GdipGetImageWidth(image, &srcwidth);
|
|
|
|
GdipGetImageHeight(image, &srcheight);
|
|
|
|
|
2012-08-20 05:08:17 +02:00
|
|
|
stat = GdipCreateBitmapFromScan0(width, height, 0, PixelFormat32bppPARGB,
|
2010-05-08 20:29:53 +02:00
|
|
|
NULL, (GpBitmap**)ret_image);
|
|
|
|
|
|
|
|
if (stat == Ok)
|
|
|
|
{
|
|
|
|
stat = GdipGetImageGraphicsContext(*ret_image, &graphics);
|
|
|
|
|
|
|
|
if (stat == Ok)
|
|
|
|
{
|
|
|
|
stat = GdipDrawImageRectRectI(graphics, image,
|
|
|
|
0, 0, width, height, 0, 0, srcwidth, srcheight, UnitPixel,
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
|
|
|
|
GdipDeleteGraphics(graphics);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stat != Ok)
|
|
|
|
{
|
|
|
|
GdipDisposeImage(*ret_image);
|
|
|
|
*ret_image = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return stat;
|
2009-05-05 22:02:25 +02:00
|
|
|
}
|
2009-05-08 07:31:15 +02:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GdipImageRotateFlip [GDIPLUS.@]
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipImageRotateFlip(GpImage *image, RotateFlipType type)
|
|
|
|
{
|
2010-02-24 23:59:50 +01:00
|
|
|
GpBitmap *new_bitmap;
|
|
|
|
GpBitmap *bitmap;
|
|
|
|
int bpp, bytesperpixel;
|
2014-03-17 07:50:26 +01:00
|
|
|
BOOL rotate_90, flip_x, flip_y;
|
2010-02-24 23:59:50 +01:00
|
|
|
int src_x_offset, src_y_offset;
|
|
|
|
LPBYTE src_origin;
|
|
|
|
UINT x, y, width, height;
|
|
|
|
BitmapData src_lock, dst_lock;
|
|
|
|
GpStatus stat;
|
2017-02-14 10:24:36 +01:00
|
|
|
BOOL unlock;
|
2010-02-24 23:59:50 +01:00
|
|
|
|
|
|
|
TRACE("(%p, %u)\n", image, type);
|
|
|
|
|
2012-06-13 20:39:35 +02:00
|
|
|
if (!image)
|
|
|
|
return InvalidParameter;
|
2017-02-14 10:24:36 +01:00
|
|
|
if (!image_lock(image, &unlock))
|
|
|
|
return ObjectBusy;
|
2012-06-13 20:39:35 +02:00
|
|
|
|
2010-02-24 23:59:50 +01:00
|
|
|
rotate_90 = type&1;
|
|
|
|
flip_x = (type&6) == 2 || (type&6) == 4;
|
|
|
|
flip_y = (type&3) == 1 || (type&3) == 2;
|
|
|
|
|
|
|
|
if (image->type != ImageTypeBitmap)
|
|
|
|
{
|
|
|
|
FIXME("Not implemented for type %i\n", image->type);
|
2017-02-14 10:24:36 +01:00
|
|
|
image_unlock(image, unlock);
|
2010-02-24 23:59:50 +01:00
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
|
|
|
bitmap = (GpBitmap*)image;
|
|
|
|
bpp = PIXELFORMATBPP(bitmap->format);
|
|
|
|
|
|
|
|
if (bpp < 8)
|
|
|
|
{
|
|
|
|
FIXME("Not implemented for %i bit images\n", bpp);
|
2017-02-14 10:24:36 +01:00
|
|
|
image_unlock(image, unlock);
|
2010-02-24 23:59:50 +01:00
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rotate_90)
|
|
|
|
{
|
|
|
|
width = bitmap->height;
|
|
|
|
height = bitmap->width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = bitmap->width;
|
|
|
|
height = bitmap->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
bytesperpixel = bpp/8;
|
|
|
|
|
|
|
|
stat = GdipCreateBitmapFromScan0(width, height, 0, bitmap->format, NULL, &new_bitmap);
|
|
|
|
|
|
|
|
if (stat != Ok)
|
2017-02-14 10:24:36 +01:00
|
|
|
{
|
|
|
|
image_unlock(image, unlock);
|
2010-02-24 23:59:50 +01:00
|
|
|
return stat;
|
2017-02-14 10:24:36 +01:00
|
|
|
}
|
2010-02-24 23:59:50 +01:00
|
|
|
|
|
|
|
stat = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, bitmap->format, &src_lock);
|
|
|
|
|
|
|
|
if (stat == Ok)
|
|
|
|
{
|
|
|
|
stat = GdipBitmapLockBits(new_bitmap, NULL, ImageLockModeWrite, bitmap->format, &dst_lock);
|
|
|
|
|
|
|
|
if (stat == Ok)
|
|
|
|
{
|
|
|
|
LPBYTE src_row, src_pixel;
|
|
|
|
LPBYTE dst_row, dst_pixel;
|
|
|
|
|
|
|
|
src_origin = src_lock.Scan0;
|
|
|
|
if (flip_x) src_origin += bytesperpixel * (bitmap->width - 1);
|
|
|
|
if (flip_y) src_origin += src_lock.Stride * (bitmap->height - 1);
|
|
|
|
|
|
|
|
if (rotate_90)
|
|
|
|
{
|
|
|
|
if (flip_y) src_x_offset = -src_lock.Stride;
|
|
|
|
else src_x_offset = src_lock.Stride;
|
|
|
|
if (flip_x) src_y_offset = -bytesperpixel;
|
|
|
|
else src_y_offset = bytesperpixel;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (flip_x) src_x_offset = -bytesperpixel;
|
|
|
|
else src_x_offset = bytesperpixel;
|
|
|
|
if (flip_y) src_y_offset = -src_lock.Stride;
|
|
|
|
else src_y_offset = src_lock.Stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
src_row = src_origin;
|
|
|
|
dst_row = dst_lock.Scan0;
|
|
|
|
for (y=0; y<height; y++)
|
|
|
|
{
|
|
|
|
src_pixel = src_row;
|
|
|
|
dst_pixel = dst_row;
|
|
|
|
for (x=0; x<width; x++)
|
|
|
|
{
|
|
|
|
/* FIXME: This could probably be faster without memcpy. */
|
|
|
|
memcpy(dst_pixel, src_pixel, bytesperpixel);
|
|
|
|
dst_pixel += bytesperpixel;
|
|
|
|
src_pixel += src_x_offset;
|
|
|
|
}
|
|
|
|
src_row += src_y_offset;
|
|
|
|
dst_row += dst_lock.Stride;
|
|
|
|
}
|
|
|
|
|
|
|
|
GdipBitmapUnlockBits(new_bitmap, &dst_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
GdipBitmapUnlockBits(bitmap, &src_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stat == Ok)
|
|
|
|
move_bitmap(bitmap, new_bitmap, FALSE);
|
|
|
|
else
|
2016-08-05 08:32:46 +02:00
|
|
|
GdipDisposeImage(&new_bitmap->image);
|
2010-02-24 23:59:50 +01:00
|
|
|
|
2017-02-14 10:24:36 +01:00
|
|
|
image_unlock(image, unlock);
|
2010-02-24 23:59:50 +01:00
|
|
|
return stat;
|
2009-05-08 07:31:15 +02:00
|
|
|
}
|
2015-06-08 15:44:40 +02:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GdipImageSetAbort [GDIPLUS.@]
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipImageSetAbort(GpImage *image, GdiplusAbort *pabort)
|
|
|
|
{
|
2016-11-03 21:34:44 +01:00
|
|
|
TRACE("(%p, %p)\n", image, pabort);
|
|
|
|
|
|
|
|
if (!image)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if (pabort)
|
|
|
|
FIXME("Abort callback is not supported.\n");
|
|
|
|
|
|
|
|
return Ok;
|
2015-06-08 15:44:40 +02:00
|
|
|
}
|
2015-10-21 21:07:02 +02:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GdipBitmapConvertFormat [GDIPLUS.@]
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipBitmapConvertFormat(GpBitmap *bitmap, PixelFormat format, DitherType dithertype,
|
|
|
|
PaletteType palettetype, ColorPalette *palette, REAL alphathreshold)
|
|
|
|
{
|
|
|
|
FIXME("(%p, 0x%08x, %d, %d, %p, %f): stub\n", bitmap, format, dithertype, palettetype, palette, alphathreshold);
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
2016-11-02 10:56:30 +01:00
|
|
|
|
2016-11-02 19:24:21 +01:00
|
|
|
static void set_histogram_point_argb(ARGB color, UINT *ch0, UINT *ch1, UINT *ch2, UINT *ch3)
|
|
|
|
{
|
|
|
|
ch0[ color >> 24 ]++;
|
|
|
|
ch1[(color >> 16) & 0xff]++;
|
|
|
|
ch2[(color >> 8) & 0xff]++;
|
|
|
|
ch3[ color & 0xff]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_histogram_point_pargb(ARGB color, UINT *ch0, UINT *ch1, UINT *ch2, UINT *ch3)
|
|
|
|
{
|
|
|
|
BYTE alpha = color >> 24;
|
|
|
|
|
|
|
|
ch0[alpha]++;
|
|
|
|
ch1[(((color >> 16) & 0xff) * alpha) / 0xff]++;
|
|
|
|
ch2[(((color >> 8) & 0xff) * alpha) / 0xff]++;
|
|
|
|
ch3[(( color & 0xff) * alpha) / 0xff]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_histogram_point_rgb(ARGB color, UINT *ch0, UINT *ch1, UINT *ch2, UINT *ch3)
|
|
|
|
{
|
|
|
|
ch0[(color >> 16) & 0xff]++;
|
|
|
|
ch1[(color >> 8) & 0xff]++;
|
|
|
|
ch2[ color & 0xff]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_histogram_point_gray(ARGB color, UINT *ch0, UINT *ch1, UINT *ch2, UINT *ch3)
|
|
|
|
{
|
|
|
|
ch0[(76 * ((color >> 16) & 0xff) + 150 * ((color >> 8) & 0xff) + 29 * (color & 0xff)) / 0xff]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_histogram_point_b(ARGB color, UINT *ch0, UINT *ch1, UINT *ch2, UINT *ch3)
|
|
|
|
{
|
|
|
|
ch0[color & 0xff]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_histogram_point_g(ARGB color, UINT *ch0, UINT *ch1, UINT *ch2, UINT *ch3)
|
|
|
|
{
|
|
|
|
ch0[(color >> 8) & 0xff]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_histogram_point_r(ARGB color, UINT *ch0, UINT *ch1, UINT *ch2, UINT *ch3)
|
|
|
|
{
|
|
|
|
ch0[(color >> 16) & 0xff]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_histogram_point_a(ARGB color, UINT *ch0, UINT *ch1, UINT *ch2, UINT *ch3)
|
|
|
|
{
|
|
|
|
ch0[(color >> 24) & 0xff]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GdipBitmapGetHistogram [GDIPLUS.@]
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipBitmapGetHistogram(GpBitmap *bitmap, HistogramFormat format, UINT num_of_entries,
|
|
|
|
UINT *ch0, UINT *ch1, UINT *ch2, UINT *ch3)
|
|
|
|
{
|
|
|
|
static void (* const set_histogram_point[])(ARGB color, UINT *ch0, UINT *ch1, UINT *ch2, UINT *ch3) =
|
|
|
|
{
|
|
|
|
set_histogram_point_argb,
|
|
|
|
set_histogram_point_pargb,
|
|
|
|
set_histogram_point_rgb,
|
|
|
|
set_histogram_point_gray,
|
|
|
|
set_histogram_point_b,
|
|
|
|
set_histogram_point_g,
|
|
|
|
set_histogram_point_r,
|
|
|
|
set_histogram_point_a,
|
|
|
|
};
|
|
|
|
UINT width, height, x, y;
|
|
|
|
|
|
|
|
TRACE("(%p, %d, %u, %p, %p, %p, %p)\n", bitmap, format, num_of_entries,
|
|
|
|
ch0, ch1, ch2, ch3);
|
|
|
|
|
|
|
|
if (!bitmap || num_of_entries != 256)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
/* Make sure passed channel pointers match requested format */
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
case HistogramFormatARGB:
|
|
|
|
case HistogramFormatPARGB:
|
|
|
|
if (!ch0 || !ch1 || !ch2 || !ch3)
|
|
|
|
return InvalidParameter;
|
|
|
|
memset(ch0, 0, num_of_entries * sizeof(UINT));
|
|
|
|
memset(ch1, 0, num_of_entries * sizeof(UINT));
|
|
|
|
memset(ch2, 0, num_of_entries * sizeof(UINT));
|
|
|
|
memset(ch3, 0, num_of_entries * sizeof(UINT));
|
|
|
|
break;
|
|
|
|
case HistogramFormatRGB:
|
|
|
|
if (!ch0 || !ch1 || !ch2 || ch3)
|
|
|
|
return InvalidParameter;
|
|
|
|
memset(ch0, 0, num_of_entries * sizeof(UINT));
|
|
|
|
memset(ch1, 0, num_of_entries * sizeof(UINT));
|
|
|
|
memset(ch2, 0, num_of_entries * sizeof(UINT));
|
|
|
|
break;
|
|
|
|
case HistogramFormatGray:
|
|
|
|
case HistogramFormatB:
|
|
|
|
case HistogramFormatG:
|
|
|
|
case HistogramFormatR:
|
|
|
|
case HistogramFormatA:
|
|
|
|
if (!ch0 || ch1 || ch2 || ch3)
|
|
|
|
return InvalidParameter;
|
|
|
|
memset(ch0, 0, num_of_entries * sizeof(UINT));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN("Invalid histogram format requested, %d\n", format);
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|
|
|
|
|
|
|
|
GdipGetImageWidth(&bitmap->image, &width);
|
|
|
|
GdipGetImageHeight(&bitmap->image, &height);
|
|
|
|
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
ARGB color;
|
|
|
|
|
|
|
|
GdipBitmapGetPixel(bitmap, x, y, &color);
|
|
|
|
set_histogram_point[format](color, ch0, ch1, ch2, ch3);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2016-11-02 10:56:30 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipBitmapGetHistogramSize [GDIPLUS.@]
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipBitmapGetHistogramSize(HistogramFormat format, UINT *num_of_entries)
|
|
|
|
{
|
|
|
|
TRACE("(%d, %p)\n", format, num_of_entries);
|
|
|
|
|
|
|
|
if (!num_of_entries)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
*num_of_entries = 256;
|
|
|
|
return Ok;
|
|
|
|
}
|
2019-01-31 02:56:03 +01:00
|
|
|
|
|
|
|
static GpStatus create_optimal_palette(ColorPalette *palette, INT desired,
|
|
|
|
BOOL transparent, GpBitmap *bitmap)
|
|
|
|
{
|
|
|
|
GpStatus status;
|
|
|
|
BitmapData data;
|
|
|
|
HRESULT hr;
|
|
|
|
IWICImagingFactory *factory;
|
|
|
|
IWICPalette *wic_palette;
|
|
|
|
|
|
|
|
if (!bitmap) return InvalidParameter;
|
|
|
|
if (palette->Count < desired) return GenericError;
|
|
|
|
|
|
|
|
status = GdipBitmapLockBits(bitmap, NULL, ImageLockModeRead, PixelFormat24bppRGB, &data);
|
|
|
|
if (status != Ok) return status;
|
|
|
|
|
|
|
|
hr = WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION, &factory);
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
GdipBitmapUnlockBits(bitmap, &data);
|
|
|
|
return hresult_to_status(hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IWICImagingFactory_CreatePalette(factory, &wic_palette);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
IWICBitmap *bitmap;
|
|
|
|
|
|
|
|
/* PixelFormat24bppRGB actually stores the bitmap bits as BGR. */
|
|
|
|
hr = IWICImagingFactory_CreateBitmapFromMemory(factory, data.Width, data.Height,
|
|
|
|
&GUID_WICPixelFormat24bppBGR, data.Stride, data.Stride * data.Width, data.Scan0, &bitmap);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
hr = IWICPalette_InitializeFromBitmap(wic_palette, (IWICBitmapSource *)bitmap, desired, transparent);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
palette->Flags = 0;
|
|
|
|
IWICPalette_GetColorCount(wic_palette, &palette->Count);
|
|
|
|
IWICPalette_GetColors(wic_palette, palette->Count, palette->Entries, &palette->Count);
|
|
|
|
}
|
|
|
|
|
|
|
|
IWICBitmap_Release(bitmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
IWICPalette_Release(wic_palette);
|
|
|
|
}
|
|
|
|
|
|
|
|
IWICImagingFactory_Release(factory);
|
|
|
|
GdipBitmapUnlockBits(bitmap, &data);
|
|
|
|
|
|
|
|
return hresult_to_status(hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GdipInitializePalette [GDIPLUS.@]
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipInitializePalette(ColorPalette *palette,
|
|
|
|
PaletteType type, INT desired, BOOL transparent, GpBitmap *bitmap)
|
|
|
|
{
|
|
|
|
TRACE("(%p,%d,%d,%d,%p)\n", palette, type, desired, transparent, bitmap);
|
|
|
|
|
|
|
|
if (!palette) return InvalidParameter;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case PaletteTypeCustom:
|
|
|
|
return Ok;
|
|
|
|
|
|
|
|
case PaletteTypeOptimal:
|
|
|
|
return create_optimal_palette(palette, desired, transparent, bitmap);
|
|
|
|
|
|
|
|
/* WIC palette type enumeration matches these gdiplus enums */
|
|
|
|
case PaletteTypeFixedBW:
|
|
|
|
case PaletteTypeFixedHalftone8:
|
|
|
|
case PaletteTypeFixedHalftone27:
|
|
|
|
case PaletteTypeFixedHalftone64:
|
|
|
|
case PaletteTypeFixedHalftone125:
|
|
|
|
case PaletteTypeFixedHalftone216:
|
|
|
|
case PaletteTypeFixedHalftone252:
|
|
|
|
case PaletteTypeFixedHalftone256:
|
|
|
|
{
|
|
|
|
ColorPalette *wic_palette;
|
|
|
|
GpStatus status = Ok;
|
|
|
|
|
|
|
|
wic_palette = get_palette(NULL, type);
|
|
|
|
if (!wic_palette) return OutOfMemory;
|
|
|
|
|
|
|
|
if (palette->Count >= wic_palette->Count)
|
|
|
|
{
|
|
|
|
palette->Flags = wic_palette->Flags;
|
|
|
|
palette->Count = wic_palette->Count;
|
|
|
|
memcpy(palette->Entries, wic_palette->Entries, wic_palette->Count * sizeof(wic_palette->Entries[0]));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
status = GenericError;
|
|
|
|
|
|
|
|
heap_free(wic_palette);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("unknown palette type %d\n", type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|