2009-08-06 04:41:38 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Vincent Povirk
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
2011-01-12 00:51:41 +01:00
|
|
|
#define CONST_VTABLE
|
2009-08-06 04:41:38 +02:00
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
#include "wincodec.h"
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
|
|
|
typedef struct bitmap_data {
|
|
|
|
const WICPixelFormatGUID *format;
|
|
|
|
UINT bpp;
|
|
|
|
const BYTE *bits;
|
|
|
|
UINT width;
|
|
|
|
UINT height;
|
|
|
|
double xres;
|
|
|
|
double yres;
|
|
|
|
} bitmap_data;
|
|
|
|
|
|
|
|
typedef struct BitmapTestSrc {
|
2011-01-12 00:51:41 +01:00
|
|
|
IWICBitmapSource IWICBitmapSource_iface;
|
2009-08-06 04:41:38 +02:00
|
|
|
LONG ref;
|
|
|
|
const bitmap_data *data;
|
|
|
|
} BitmapTestSrc;
|
|
|
|
|
2011-01-12 00:51:41 +01:00
|
|
|
static inline BitmapTestSrc *impl_from_IWICBitmapSource(IWICBitmapSource *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, BitmapTestSrc, IWICBitmapSource_iface);
|
|
|
|
}
|
|
|
|
|
2009-08-06 04:41:38 +02:00
|
|
|
static HRESULT WINAPI BitmapTestSrc_QueryInterface(IWICBitmapSource *iface, REFIID iid,
|
|
|
|
void **ppv)
|
|
|
|
{
|
|
|
|
if (!ppv) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (IsEqualIID(&IID_IUnknown, iid) ||
|
|
|
|
IsEqualIID(&IID_IWICBitmapSource, iid))
|
|
|
|
*ppv = iface;
|
|
|
|
else
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI BitmapTestSrc_AddRef(IWICBitmapSource *iface)
|
|
|
|
{
|
2011-01-12 00:51:41 +01:00
|
|
|
BitmapTestSrc *This = impl_from_IWICBitmapSource(iface);
|
2009-08-06 04:41:38 +02:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI BitmapTestSrc_Release(IWICBitmapSource *iface)
|
|
|
|
{
|
2011-01-12 00:51:41 +01:00
|
|
|
BitmapTestSrc *This = impl_from_IWICBitmapSource(iface);
|
2009-08-06 04:41:38 +02:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BitmapTestSrc_GetSize(IWICBitmapSource *iface,
|
|
|
|
UINT *puiWidth, UINT *puiHeight)
|
|
|
|
{
|
2011-01-12 00:51:41 +01:00
|
|
|
BitmapTestSrc *This = impl_from_IWICBitmapSource(iface);
|
2009-08-06 04:41:38 +02:00
|
|
|
*puiWidth = This->data->width;
|
|
|
|
*puiHeight = This->data->height;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BitmapTestSrc_GetPixelFormat(IWICBitmapSource *iface,
|
|
|
|
WICPixelFormatGUID *pPixelFormat)
|
|
|
|
{
|
2011-01-12 00:51:41 +01:00
|
|
|
BitmapTestSrc *This = impl_from_IWICBitmapSource(iface);
|
2009-08-06 04:41:38 +02:00
|
|
|
memcpy(pPixelFormat, This->data->format, sizeof(GUID));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BitmapTestSrc_GetResolution(IWICBitmapSource *iface,
|
|
|
|
double *pDpiX, double *pDpiY)
|
|
|
|
{
|
2011-01-12 00:51:41 +01:00
|
|
|
BitmapTestSrc *This = impl_from_IWICBitmapSource(iface);
|
2009-08-06 04:41:38 +02:00
|
|
|
*pDpiX = This->data->xres;
|
|
|
|
*pDpiY = This->data->yres;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BitmapTestSrc_CopyPalette(IWICBitmapSource *iface,
|
|
|
|
IWICPalette *pIPalette)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BitmapTestSrc_CopyPixels(IWICBitmapSource *iface,
|
|
|
|
const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
|
|
|
|
{
|
2011-01-12 00:51:41 +01:00
|
|
|
BitmapTestSrc *This = impl_from_IWICBitmapSource(iface);
|
2009-08-06 04:41:38 +02:00
|
|
|
UINT bytesperrow;
|
|
|
|
UINT srcstride;
|
|
|
|
UINT row_offset;
|
2010-10-19 18:57:47 +02:00
|
|
|
WICRect rc;
|
2009-08-06 04:41:38 +02:00
|
|
|
|
2010-10-19 18:57:47 +02:00
|
|
|
if (!prc)
|
|
|
|
{
|
|
|
|
rc.X = 0;
|
|
|
|
rc.Y = 0;
|
|
|
|
rc.Width = This->data->width;
|
|
|
|
rc.Height = This->data->height;
|
|
|
|
prc = &rc;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (prc->X < 0 || prc->Y < 0 || prc->X+prc->Width > This->data->width || prc->Y+prc->Height > This->data->height)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2009-08-06 04:41:38 +02:00
|
|
|
|
|
|
|
bytesperrow = ((This->data->bpp * prc->Width)+7)/8;
|
|
|
|
srcstride = ((This->data->bpp * This->data->width)+7)/8;
|
|
|
|
|
|
|
|
if (cbStride < bytesperrow)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if ((cbStride * prc->Height) > cbBufferSize)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
row_offset = prc->X * This->data->bpp;
|
|
|
|
|
|
|
|
if (row_offset % 8 == 0)
|
|
|
|
{
|
|
|
|
UINT row;
|
|
|
|
const BYTE *src;
|
|
|
|
BYTE *dst;
|
|
|
|
|
|
|
|
src = This->data->bits + (row_offset / 8) + prc->Y * srcstride;
|
|
|
|
dst = pbBuffer;
|
|
|
|
for (row=0; row < prc->Height; row++)
|
|
|
|
{
|
|
|
|
memcpy(dst, src, bytesperrow);
|
|
|
|
src += srcstride;
|
|
|
|
dst += cbStride;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok(0, "bitmap %p was asked to copy pixels not aligned on a byte boundary\n", iface);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IWICBitmapSourceVtbl BitmapTestSrc_Vtbl = {
|
|
|
|
BitmapTestSrc_QueryInterface,
|
|
|
|
BitmapTestSrc_AddRef,
|
|
|
|
BitmapTestSrc_Release,
|
|
|
|
BitmapTestSrc_GetSize,
|
|
|
|
BitmapTestSrc_GetPixelFormat,
|
|
|
|
BitmapTestSrc_GetResolution,
|
|
|
|
BitmapTestSrc_CopyPalette,
|
|
|
|
BitmapTestSrc_CopyPixels
|
|
|
|
};
|
|
|
|
|
2011-01-12 00:51:41 +01:00
|
|
|
static void CreateTestBitmap(const bitmap_data *data, BitmapTestSrc **This)
|
2009-08-06 04:41:38 +02:00
|
|
|
{
|
2011-01-12 22:00:41 +01:00
|
|
|
*This = HeapAlloc(GetProcessHeap(), 0, sizeof(**This));
|
2009-08-06 04:41:38 +02:00
|
|
|
|
2011-01-12 00:51:41 +01:00
|
|
|
if (*This)
|
2009-08-06 04:41:38 +02:00
|
|
|
{
|
2011-01-12 00:51:41 +01:00
|
|
|
(*This)->IWICBitmapSource_iface.lpVtbl = &BitmapTestSrc_Vtbl;
|
|
|
|
(*This)->ref = 1;
|
|
|
|
(*This)->data = data;
|
2009-08-06 04:41:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-12 00:51:41 +01:00
|
|
|
static void DeleteTestBitmap(BitmapTestSrc *This)
|
2009-08-06 04:41:38 +02:00
|
|
|
{
|
2011-01-12 00:51:41 +01:00
|
|
|
ok(This->IWICBitmapSource_iface.lpVtbl == &BitmapTestSrc_Vtbl, "test bitmap %p deleted with incorrect vtable\n", This);
|
|
|
|
ok(This->ref == 1, "test bitmap %p deleted with %i references instead of 1\n", This, This->ref);
|
2009-08-06 04:41:38 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
2009-08-26 10:54:50 +02:00
|
|
|
static void compare_bitmap_data(const struct bitmap_data *expect, IWICBitmapSource *source, const char *name)
|
2009-08-06 04:41:38 +02:00
|
|
|
{
|
|
|
|
BYTE *converted_bits;
|
|
|
|
UINT width, height;
|
|
|
|
double xres, yres;
|
|
|
|
WICRect prc;
|
|
|
|
UINT stride, buffersize;
|
|
|
|
GUID dst_pixelformat;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IWICBitmapSource_GetSize(source, &width, &height);
|
|
|
|
ok(SUCCEEDED(hr), "GetSize(%s) failed, hr=%x\n", name, hr);
|
|
|
|
ok(width == expect->width, "expecting %u, got %u (%s)\n", expect->width, width, name);
|
|
|
|
ok(height == expect->height, "expecting %u, got %u (%s)\n", expect->height, height, name);
|
|
|
|
|
|
|
|
hr = IWICBitmapSource_GetResolution(source, &xres, &yres);
|
|
|
|
ok(SUCCEEDED(hr), "GetResolution(%s) failed, hr=%x\n", name, hr);
|
2009-09-23 20:10:41 +02:00
|
|
|
ok(fabs(xres - expect->xres) < 0.02, "expecting %0.2f, got %0.2f (%s)\n", expect->xres, xres, name);
|
|
|
|
ok(fabs(yres - expect->yres) < 0.02, "expecting %0.2f, got %0.2f (%s)\n", expect->yres, yres, name);
|
2009-08-06 04:41:38 +02:00
|
|
|
|
|
|
|
hr = IWICBitmapSource_GetPixelFormat(source, &dst_pixelformat);
|
|
|
|
ok(SUCCEEDED(hr), "GetPixelFormat(%s) failed, hr=%x\n", name, hr);
|
|
|
|
ok(IsEqualGUID(&dst_pixelformat, expect->format), "got unexpected pixel format (%s)\n", name);
|
|
|
|
|
|
|
|
prc.X = 0;
|
|
|
|
prc.Y = 0;
|
|
|
|
prc.Width = expect->width;
|
|
|
|
prc.Height = expect->height;
|
|
|
|
|
|
|
|
stride = (expect->bpp * expect->width + 7) / 8;
|
|
|
|
buffersize = stride * expect->height;
|
|
|
|
|
|
|
|
converted_bits = HeapAlloc(GetProcessHeap(), 0, buffersize);
|
|
|
|
hr = IWICBitmapSource_CopyPixels(source, &prc, stride, buffersize, converted_bits);
|
|
|
|
ok(SUCCEEDED(hr), "CopyPixels(%s) failed, hr=%x\n", name, hr);
|
|
|
|
if (IsEqualGUID(expect->format, &GUID_WICPixelFormat32bppBGR))
|
|
|
|
{
|
|
|
|
/* ignore the padding byte when comparing data */
|
|
|
|
UINT i;
|
|
|
|
BOOL equal=TRUE;
|
|
|
|
const DWORD *a=(const DWORD*)expect->bits, *b=(const DWORD*)converted_bits;
|
|
|
|
for (i=0; i<(buffersize/4); i++)
|
|
|
|
if ((a[i]&0xffffff) != (b[i]&0xffffff))
|
|
|
|
{
|
|
|
|
equal = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ok(equal, "unexpected pixel data (%s)\n", name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok(memcmp(expect->bits, converted_bits, buffersize) == 0, "unexpected pixel data (%s)\n", name);
|
2010-10-19 18:57:47 +02:00
|
|
|
|
|
|
|
/* Test with NULL rectangle - should copy the whole bitmap */
|
|
|
|
hr = IWICBitmapSource_CopyPixels(source, NULL, stride, buffersize, converted_bits);
|
|
|
|
ok(SUCCEEDED(hr), "CopyPixels(%s,rc=NULL) failed, hr=%x\n", name, hr);
|
|
|
|
if (IsEqualGUID(expect->format, &GUID_WICPixelFormat32bppBGR))
|
|
|
|
{
|
|
|
|
/* ignore the padding byte when comparing data */
|
|
|
|
UINT i;
|
|
|
|
BOOL equal=TRUE;
|
|
|
|
const DWORD *a=(const DWORD*)expect->bits, *b=(const DWORD*)converted_bits;
|
|
|
|
for (i=0; i<(buffersize/4); i++)
|
|
|
|
if ((a[i]&0xffffff) != (b[i]&0xffffff))
|
|
|
|
{
|
|
|
|
equal = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ok(equal, "unexpected pixel data with rc=NULL (%s)\n", name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok(memcmp(expect->bits, converted_bits, buffersize) == 0, "unexpected pixel data with rc=NULL (%s)\n", name);
|
|
|
|
|
2009-08-06 04:41:38 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, converted_bits);
|
|
|
|
}
|
|
|
|
|
2009-09-23 20:46:06 +02:00
|
|
|
static const BYTE bits_24bppBGR[] = {
|
|
|
|
255,0,0, 0,255,0, 0,0,255, 0,0,0,
|
|
|
|
0,255,255, 255,0,255, 255,255,0, 255,255,255};
|
|
|
|
static const struct bitmap_data testdata_24bppBGR = {
|
|
|
|
&GUID_WICPixelFormat24bppBGR, 24, bits_24bppBGR, 4, 2, 96.0, 96.0};
|
|
|
|
|
2009-08-06 04:41:38 +02:00
|
|
|
static const BYTE bits_32bppBGR[] = {
|
|
|
|
255,0,0,80, 0,255,0,80, 0,0,255,80, 0,0,0,80,
|
|
|
|
0,255,255,80, 255,0,255,80, 255,255,0,80, 255,255,255,80};
|
|
|
|
static const struct bitmap_data testdata_32bppBGR = {
|
|
|
|
&GUID_WICPixelFormat32bppBGR, 32, bits_32bppBGR, 4, 2, 96.0, 96.0};
|
|
|
|
|
|
|
|
static const BYTE bits_32bppBGRA[] = {
|
|
|
|
255,0,0,255, 0,255,0,255, 0,0,255,255, 0,0,0,255,
|
|
|
|
0,255,255,255, 255,0,255,255, 255,255,0,255, 255,255,255,255};
|
|
|
|
static const struct bitmap_data testdata_32bppBGRA = {
|
|
|
|
&GUID_WICPixelFormat32bppBGRA, 32, bits_32bppBGRA, 4, 2, 96.0, 96.0};
|
|
|
|
|
2009-08-26 10:54:50 +02:00
|
|
|
static void test_conversion(const struct bitmap_data *src, const struct bitmap_data *dst, const char *name, BOOL todo)
|
2009-08-06 04:41:38 +02:00
|
|
|
{
|
2011-01-12 00:51:41 +01:00
|
|
|
BitmapTestSrc *src_obj;
|
|
|
|
IWICBitmapSource *dst_bitmap;
|
2009-08-06 04:41:38 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2011-01-12 00:51:41 +01:00
|
|
|
CreateTestBitmap(src, &src_obj);
|
2009-08-06 04:41:38 +02:00
|
|
|
|
2011-01-12 00:51:41 +01:00
|
|
|
hr = WICConvertBitmapSource(dst->format, &src_obj->IWICBitmapSource_iface, &dst_bitmap);
|
2009-08-06 04:41:38 +02:00
|
|
|
if (todo)
|
|
|
|
todo_wine ok(SUCCEEDED(hr), "WICConvertBitmapSource(%s) failed, hr=%x\n", name, hr);
|
|
|
|
else
|
|
|
|
ok(SUCCEEDED(hr), "WICConvertBitmapSource(%s) failed, hr=%x\n", name, hr);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
compare_bitmap_data(dst, dst_bitmap, name);
|
|
|
|
|
|
|
|
IWICBitmapSource_Release(dst_bitmap);
|
|
|
|
}
|
|
|
|
|
2011-01-12 00:51:41 +01:00
|
|
|
DeleteTestBitmap(src_obj);
|
2009-08-06 04:41:38 +02:00
|
|
|
}
|
|
|
|
|
2009-08-26 10:54:50 +02:00
|
|
|
static void test_invalid_conversion(void)
|
2009-08-06 04:41:38 +02:00
|
|
|
{
|
2011-01-12 00:51:41 +01:00
|
|
|
BitmapTestSrc *src_obj;
|
|
|
|
IWICBitmapSource *dst_bitmap;
|
2009-08-06 04:41:38 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2011-01-12 00:51:41 +01:00
|
|
|
CreateTestBitmap(&testdata_32bppBGRA, &src_obj);
|
2009-08-06 04:41:38 +02:00
|
|
|
|
|
|
|
/* convert to a non-pixel-format GUID */
|
2011-01-12 00:51:41 +01:00
|
|
|
hr = WICConvertBitmapSource(&GUID_VendorMicrosoft, &src_obj->IWICBitmapSource_iface, &dst_bitmap);
|
2009-08-06 04:41:38 +02:00
|
|
|
ok(hr == WINCODEC_ERR_COMPONENTNOTFOUND, "WICConvertBitmapSource returned %x\n", hr);
|
|
|
|
|
2011-01-12 00:51:41 +01:00
|
|
|
DeleteTestBitmap(src_obj);
|
2009-08-06 04:41:38 +02:00
|
|
|
}
|
|
|
|
|
2009-08-26 10:54:50 +02:00
|
|
|
static void test_default_converter(void)
|
2009-08-06 04:41:38 +02:00
|
|
|
{
|
2011-01-12 00:51:41 +01:00
|
|
|
BitmapTestSrc *src_obj;
|
2009-08-06 04:41:38 +02:00
|
|
|
IWICFormatConverter *converter;
|
|
|
|
BOOL can_convert=1;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2011-01-12 00:51:41 +01:00
|
|
|
CreateTestBitmap(&testdata_32bppBGRA, &src_obj);
|
2009-08-06 04:41:38 +02:00
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_WICDefaultFormatConverter, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IWICFormatConverter, (void**)&converter);
|
|
|
|
ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IWICFormatConverter_CanConvert(converter, &GUID_WICPixelFormat32bppBGRA,
|
|
|
|
&GUID_WICPixelFormat32bppBGR, &can_convert);
|
|
|
|
ok(SUCCEEDED(hr), "CanConvert returned %x\n", hr);
|
|
|
|
ok(can_convert, "expected TRUE, got %i\n", can_convert);
|
|
|
|
|
2011-01-12 00:51:41 +01:00
|
|
|
hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface,
|
2009-08-06 04:41:38 +02:00
|
|
|
&GUID_WICPixelFormat32bppBGR, WICBitmapDitherTypeNone, NULL, 0.0,
|
|
|
|
WICBitmapPaletteTypeCustom);
|
|
|
|
ok(SUCCEEDED(hr), "Initialize returned %x\n", hr);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
compare_bitmap_data(&testdata_32bppBGR, (IWICBitmapSource*)converter, "default converter");
|
|
|
|
|
|
|
|
IWICFormatConverter_Release(converter);
|
|
|
|
}
|
|
|
|
|
2011-01-12 00:51:41 +01:00
|
|
|
DeleteTestBitmap(src_obj);
|
2009-08-06 04:41:38 +02:00
|
|
|
}
|
|
|
|
|
2011-03-29 22:55:36 +02:00
|
|
|
static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* clsid_encoder,
|
|
|
|
const struct bitmap_data **dsts, const CLSID *clsid_decoder, const char *name)
|
2009-09-23 20:10:41 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IWICBitmapEncoder *encoder;
|
2011-01-12 00:51:41 +01:00
|
|
|
BitmapTestSrc *src_obj;
|
2009-09-23 20:10:41 +02:00
|
|
|
HGLOBAL hglobal;
|
|
|
|
IStream *stream;
|
|
|
|
IWICBitmapFrameEncode *frameencode;
|
|
|
|
IPropertyBag2 *options=NULL;
|
|
|
|
IWICBitmapDecoder *decoder;
|
|
|
|
IWICBitmapFrameDecode *framedecode;
|
|
|
|
WICPixelFormatGUID pixelformat;
|
2011-03-29 22:55:36 +02:00
|
|
|
int i;
|
2009-09-23 20:10:41 +02:00
|
|
|
|
|
|
|
hr = CoCreateInstance(clsid_encoder, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IWICBitmapEncoder, (void**)&encoder);
|
|
|
|
ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hglobal = GlobalAlloc(GMEM_MOVEABLE, 0);
|
|
|
|
ok(hglobal != NULL, "GlobalAlloc failed\n");
|
|
|
|
if (hglobal)
|
|
|
|
{
|
|
|
|
hr = CreateStreamOnHGlobal(hglobal, TRUE, &stream);
|
|
|
|
ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hglobal && SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IWICBitmapEncoder_Initialize(encoder, stream, WICBitmapEncoderNoCache);
|
|
|
|
ok(SUCCEEDED(hr), "Initialize failed, hr=%x\n", hr);
|
|
|
|
|
2011-03-29 22:55:36 +02:00
|
|
|
i=0;
|
|
|
|
while (SUCCEEDED(hr) && srcs[i])
|
2009-09-23 20:10:41 +02:00
|
|
|
{
|
2011-03-29 22:55:36 +02:00
|
|
|
CreateTestBitmap(srcs[i], &src_obj);
|
|
|
|
|
|
|
|
hr = IWICBitmapEncoder_CreateNewFrame(encoder, &frameencode, &options);
|
|
|
|
ok(SUCCEEDED(hr), "CreateFrame failed, hr=%x\n", hr);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IWICBitmapFrameEncode_Initialize(frameencode, options);
|
|
|
|
ok(SUCCEEDED(hr), "Initialize failed, hr=%x\n", hr);
|
2009-09-23 20:10:41 +02:00
|
|
|
|
2011-03-29 22:55:36 +02:00
|
|
|
memcpy(&pixelformat, srcs[i]->format, sizeof(GUID));
|
|
|
|
hr = IWICBitmapFrameEncode_SetPixelFormat(frameencode, &pixelformat);
|
|
|
|
ok(SUCCEEDED(hr), "SetPixelFormat failed, hr=%x\n", hr);
|
|
|
|
ok(IsEqualGUID(&pixelformat, srcs[i]->format), "SetPixelFormat changed the format\n");
|
2009-09-23 20:10:41 +02:00
|
|
|
|
2011-03-29 22:55:36 +02:00
|
|
|
hr = IWICBitmapFrameEncode_SetSize(frameencode, srcs[i]->width, srcs[i]->height);
|
|
|
|
ok(SUCCEEDED(hr), "SetSize failed, hr=%x\n", hr);
|
2009-09-23 20:10:41 +02:00
|
|
|
|
2011-03-29 22:55:36 +02:00
|
|
|
hr = IWICBitmapFrameEncode_WriteSource(frameencode, &src_obj->IWICBitmapSource_iface, NULL);
|
|
|
|
ok(SUCCEEDED(hr), "WriteSource failed, hr=%x\n", hr);
|
2009-09-23 20:10:41 +02:00
|
|
|
|
2011-03-29 22:55:36 +02:00
|
|
|
hr = IWICBitmapFrameEncode_Commit(frameencode);
|
|
|
|
ok(SUCCEEDED(hr), "Commit failed, hr=%x\n", hr);
|
|
|
|
|
|
|
|
IWICBitmapFrameEncode_Release(frameencode);
|
|
|
|
IPropertyBag2_Release(options);
|
|
|
|
}
|
2009-09-23 20:10:41 +02:00
|
|
|
|
2011-03-29 22:55:36 +02:00
|
|
|
DeleteTestBitmap(src_obj);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2009-09-23 20:10:41 +02:00
|
|
|
hr = IWICBitmapEncoder_Commit(encoder);
|
|
|
|
ok(SUCCEEDED(hr), "Commit failed, hr=%x\n", hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = CoCreateInstance(clsid_decoder, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IWICBitmapDecoder, (void**)&decoder);
|
|
|
|
ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IWICBitmapDecoder_Initialize(decoder, stream, WICDecodeMetadataCacheOnDemand);
|
|
|
|
ok(SUCCEEDED(hr), "Initialize failed, hr=%x\n", hr);
|
|
|
|
|
2011-03-29 22:55:36 +02:00
|
|
|
i=0;
|
|
|
|
while (SUCCEEDED(hr) && dsts[i])
|
2009-09-23 20:10:41 +02:00
|
|
|
{
|
2011-03-29 22:55:36 +02:00
|
|
|
hr = IWICBitmapDecoder_GetFrame(decoder, i, &framedecode);
|
|
|
|
ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
|
2009-09-23 20:10:41 +02:00
|
|
|
|
2011-03-29 22:55:36 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
compare_bitmap_data(dsts[i], (IWICBitmapSource*)framedecode, name);
|
|
|
|
|
|
|
|
IWICBitmapFrameDecode_Release(framedecode);
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
2009-09-23 20:10:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
IWICBitmapDecoder_Release(decoder);
|
|
|
|
}
|
|
|
|
|
|
|
|
IStream_Release(stream);
|
|
|
|
}
|
2009-12-14 02:20:58 +01:00
|
|
|
|
|
|
|
IWICBitmapEncoder_Release(encoder);
|
2009-09-23 20:10:41 +02:00
|
|
|
}
|
2011-03-29 22:55:36 +02:00
|
|
|
}
|
2009-09-23 20:10:41 +02:00
|
|
|
|
2011-03-29 22:55:36 +02:00
|
|
|
static void test_encoder(const struct bitmap_data *src, const CLSID* clsid_encoder,
|
|
|
|
const struct bitmap_data *dst, const CLSID *clsid_decoder, const char *name)
|
|
|
|
{
|
|
|
|
const struct bitmap_data *srcs[2];
|
|
|
|
const struct bitmap_data *dsts[2];
|
|
|
|
|
|
|
|
srcs[0] = src;
|
|
|
|
srcs[1] = NULL;
|
|
|
|
dsts[0] = dst;
|
|
|
|
dsts[1] = NULL;
|
|
|
|
|
|
|
|
test_multi_encoder(srcs, clsid_encoder, dsts, clsid_decoder, name);
|
2009-09-23 20:10:41 +02:00
|
|
|
}
|
|
|
|
|
2011-03-29 22:55:36 +02:00
|
|
|
static const struct bitmap_data *multiple_frames[3] = {
|
|
|
|
&testdata_24bppBGR,
|
|
|
|
&testdata_24bppBGR,
|
|
|
|
NULL};
|
|
|
|
|
2009-08-06 04:41:38 +02:00
|
|
|
START_TEST(converter)
|
|
|
|
{
|
|
|
|
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
|
|
|
|
test_conversion(&testdata_32bppBGRA, &testdata_32bppBGR, "BGRA -> BGR", 0);
|
|
|
|
test_conversion(&testdata_32bppBGR, &testdata_32bppBGRA, "BGR -> BGRA", 0);
|
|
|
|
test_conversion(&testdata_32bppBGRA, &testdata_32bppBGRA, "BGRA -> BGRA", 0);
|
|
|
|
test_invalid_conversion();
|
|
|
|
test_default_converter();
|
|
|
|
|
2009-09-23 20:10:41 +02:00
|
|
|
test_encoder(&testdata_32bppBGR, &CLSID_WICBmpEncoder,
|
|
|
|
&testdata_32bppBGR, &CLSID_WICBmpDecoder, "BMP encoder 32bppBGR");
|
|
|
|
|
2009-09-23 20:46:06 +02:00
|
|
|
test_encoder(&testdata_24bppBGR, &CLSID_WICPngEncoder,
|
|
|
|
&testdata_24bppBGR, &CLSID_WICPngDecoder, "PNG encoder 24bppBGR");
|
|
|
|
|
2011-03-29 21:56:21 +02:00
|
|
|
test_encoder(&testdata_24bppBGR, &CLSID_WICTiffEncoder,
|
|
|
|
&testdata_24bppBGR, &CLSID_WICTiffDecoder, "TIFF encoder 24bppBGR");
|
|
|
|
|
2011-03-29 22:55:36 +02:00
|
|
|
test_multi_encoder(multiple_frames, &CLSID_WICTiffEncoder,
|
|
|
|
multiple_frames, &CLSID_WICTiffDecoder, "TIFF encoder multi-frame");
|
|
|
|
|
2009-08-06 04:41:38 +02:00
|
|
|
CoUninitialize();
|
|
|
|
}
|