Commit 03724685 authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

windowscodecs: Implement ComponentFactory_CreateBitmapFromMemory.

parent 44b462c9
......@@ -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;
......
/*
* 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,
......
......@@ -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);
}
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment