Module: wine Branch: master Commit: 03724685d64a8be97e11c27f2039824837134d8c URL: http://source.winehq.org/git/wine.git/?a=commit;h=03724685d64a8be97e11c27f20...
Author: Dmitry Timoshkov dmitry@baikal.ru Date: Fri Jan 4 18:05:30 2013 +0800
windowscodecs: Implement ComponentFactory_CreateBitmapFromMemory.
---
dlls/windowscodecs/bitmap.c | 11 ++++++++--- dlls/windowscodecs/imgfactory.c | 18 +++++++++++------- dlls/windowscodecs/tests/bitmap.c | 13 ++++--------- dlls/windowscodecs/wincodecs_private.h | 1 + 4 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/dlls/windowscodecs/bitmap.c b/dlls/windowscodecs/bitmap.c index 520fdef..f8904df 100644 --- a/dlls/windowscodecs/bitmap.c +++ b/dlls/windowscodecs/bitmap.c @@ -447,19 +447,23 @@ static const IWICBitmapVtbl BitmapImpl_Vtbl = { };
HRESULT BitmapImpl_Create(UINT uiWidth, UINT uiHeight, + UINT stride, UINT datasize, BYTE *bits, REFWICPixelFormatGUID pixelFormat, WICBitmapCreateCacheOption option, IWICBitmap **ppIBitmap) { HRESULT hr; BitmapImpl *This; - UINT bpp, stride, datasize; BYTE *data; + UINT bpp;
hr = get_pixelformat_bpp(pixelFormat, &bpp); if (FAILED(hr)) return hr;
- stride = (((bpp*uiWidth)+31)/32)*4; - datasize = stride * uiHeight; + if (!stride) stride = (((bpp*uiWidth)+31)/32)*4; + if (!datasize) datasize = stride * uiHeight; + + if (datasize < stride * uiHeight) return WINCODEC_ERR_INSUFFICIENTBUFFER; + if (stride < ((bpp*uiWidth)+7)/8) return E_INVALIDARG;
This = HeapAlloc(GetProcessHeap(), 0, sizeof(BitmapImpl)); data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, datasize); @@ -469,6 +473,7 @@ HRESULT BitmapImpl_Create(UINT uiWidth, UINT uiHeight, HeapFree(GetProcessHeap(), 0, data); return E_OUTOFMEMORY; } + if (bits) memcpy(data, bits, datasize);
This->IWICBitmap_iface.lpVtbl = &BitmapImpl_Vtbl; This->ref = 1; diff --git a/dlls/windowscodecs/imgfactory.c b/dlls/windowscodecs/imgfactory.c index 54b390b..1d05ef5 100644 --- a/dlls/windowscodecs/imgfactory.c +++ b/dlls/windowscodecs/imgfactory.c @@ -1,5 +1,6 @@ /* * Copyright 2009 Vincent Povirk for CodeWeavers + * Copyright 2012 Dmitry Timoshkov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -459,7 +460,7 @@ static HRESULT WINAPI ComponentFactory_CreateBitmap(IWICComponentFactory *iface, { TRACE("(%p,%u,%u,%s,%u,%p)\n", iface, uiWidth, uiHeight, debugstr_guid(pixelFormat), option, ppIBitmap); - return BitmapImpl_Create(uiWidth, uiHeight, pixelFormat, option, ppIBitmap); + return BitmapImpl_Create(uiWidth, uiHeight, 0, 0, NULL, pixelFormat, option, ppIBitmap); }
static HRESULT WINAPI ComponentFactory_CreateBitmapFromSource(IWICComponentFactory *iface, @@ -506,7 +507,7 @@ static HRESULT WINAPI ComponentFactory_CreateBitmapFromSource(IWICComponentFacto }
if (SUCCEEDED(hr)) - hr = BitmapImpl_Create(width, height, &pixelformat, option, &result); + hr = BitmapImpl_Create(width, height, 0, 0, NULL, &pixelformat, option, &result);
if (SUCCEEDED(hr)) { @@ -576,12 +577,15 @@ static HRESULT WINAPI ComponentFactory_CreateBitmapFromSourceRect(IWICComponentF }
static HRESULT WINAPI ComponentFactory_CreateBitmapFromMemory(IWICComponentFactory *iface, - UINT uiWidth, UINT uiHeight, REFWICPixelFormatGUID pixelFormat, UINT cbStride, - UINT cbBufferSize, BYTE *pbBuffer, IWICBitmap **ppIBitmap) + UINT width, UINT height, REFWICPixelFormatGUID format, UINT stride, + UINT size, BYTE *buffer, IWICBitmap **bitmap) { - FIXME("(%p,%u,%u,%s,%u,%u,%p,%p): stub\n", iface, uiWidth, uiHeight, - debugstr_guid(pixelFormat), cbStride, cbBufferSize, pbBuffer, ppIBitmap); - return E_NOTIMPL; + TRACE("(%p,%u,%u,%s,%u,%u,%p,%p\n", iface, width, height, + debugstr_guid(format), stride, size, buffer, bitmap); + + if (!stride || !size || !buffer || !bitmap) return E_INVALIDARG; + + return BitmapImpl_Create(width, height, stride, size, buffer, format, WICBitmapCacheOnLoad, bitmap); }
static HRESULT WINAPI ComponentFactory_CreateBitmapFromHBITMAP(IWICComponentFactory *iface, diff --git a/dlls/windowscodecs/tests/bitmap.c b/dlls/windowscodecs/tests/bitmap.c index af0446c..f2f9cb6 100644 --- a/dlls/windowscodecs/tests/bitmap.c +++ b/dlls/windowscodecs/tests/bitmap.c @@ -439,34 +439,27 @@ static void test_CreateBitmapFromMemory(void)
hr = IWICImagingFactory_CreateBitmapFromMemory(factory, 3, 3, &GUID_WICPixelFormat24bppBGR, 0, 0, NULL, &bitmap); -todo_wine ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
hr = IWICImagingFactory_CreateBitmapFromMemory(factory, 3, 3, &GUID_WICPixelFormat24bppBGR, 0, sizeof(data3x3), data3x3, &bitmap); -todo_wine ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
hr = IWICImagingFactory_CreateBitmapFromMemory(factory, 3, 3, &GUID_WICPixelFormat24bppBGR, 6, sizeof(data3x3), data3x3, &bitmap); -todo_wine ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
hr = IWICImagingFactory_CreateBitmapFromMemory(factory, 3, 3, &GUID_WICPixelFormat24bppBGR, 12, sizeof(data3x3), data3x3, &bitmap); -todo_wine ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "expected WINCODEC_ERR_INSUFFICIENTBUFFER, got %#x\n", hr);
hr = IWICImagingFactory_CreateBitmapFromMemory(factory, 3, 3, &GUID_WICPixelFormat24bppBGR, 9, sizeof(data3x3) - 1, data3x3, &bitmap); -todo_wine ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "expected WINCODEC_ERR_INSUFFICIENTBUFFER, got %#x\n", hr);
hr = IWICImagingFactory_CreateBitmapFromMemory(factory, 3, 3, &GUID_WICPixelFormat24bppBGR, 9, sizeof(data3x3), data3x3, &bitmap); -todo_wine ok(hr == S_OK, "IWICImagingFactory_CreateBitmapFromMemory error %#x\n", hr); - if (hr != S_OK) return;
hr = IWICBitmap_GetSize(bitmap, &width, &height); ok(hr == S_OK, "IWICBitmap_GetSize error %#x\n", hr); @@ -486,7 +479,6 @@ todo_wine hr = IWICImagingFactory_CreateBitmapFromMemory(factory, 3, 2, &GUID_WICPixelFormat24bppBGR, 13, sizeof(orig_data3x3), orig_data3x3, &bitmap); ok(hr == S_OK, "IWICImagingFactory_CreateBitmapFromMemory error %#x\n", hr); - if (hr != S_OK) return;
hr = IWICBitmap_GetSize(bitmap, &width, &height); ok(hr == S_OK, "IWICBitmap_GetSize error %#x\n", hr); @@ -497,7 +489,10 @@ todo_wine hr = IWICBitmap_CopyPixels(bitmap, NULL, 13, sizeof(data), data); ok(hr == S_OK, "IWICBitmap_CopyPixels error %#x\n", hr); for (i = 0; i < sizeof(data); i++) - ok(data[i] == data3x2[i], "%u: expected %u, got %u\n", i, data3x2[i], data[i]); + if ((i % 13) < 9) + ok(data[i] == data3x2[i], "%u: expected %u, got %u\n", i, data3x2[i], data[i]); + else + todo_wine ok(data[i] == data3x2[i], "%u: expected %u, got %u\n", i, data3x2[i], data[i]);
IWICBitmap_Release(bitmap); } diff --git a/dlls/windowscodecs/wincodecs_private.h b/dlls/windowscodecs/wincodecs_private.h index 6857176..f8b7789 100644 --- a/dlls/windowscodecs/wincodecs_private.h +++ b/dlls/windowscodecs/wincodecs_private.h @@ -45,6 +45,7 @@ extern HRESULT IcnsEncoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void* extern HRESULT TgaDecoder_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv) DECLSPEC_HIDDEN;
extern HRESULT BitmapImpl_Create(UINT uiWidth, UINT uiHeight, + UINT stride, UINT datasize, BYTE *bits, REFWICPixelFormatGUID pixelFormat, WICBitmapCreateCacheOption option, IWICBitmap **ppIBitmap) DECLSPEC_HIDDEN; extern HRESULT BitmapScaler_Create(IWICBitmapScaler **scaler) DECLSPEC_HIDDEN;