Commit 88eed3c0 authored by Vincent Povirk's avatar Vincent Povirk Committed by Alexandre Julliard

windowscodecs: Implement IWICImagingFactory::CreateBitmapFromSource.

parent 32bfd810
......@@ -466,8 +466,83 @@ static HRESULT WINAPI ComponentFactory_CreateBitmapFromSource(IWICComponentFacto
IWICBitmapSource *piBitmapSource, WICBitmapCreateCacheOption option,
IWICBitmap **ppIBitmap)
{
FIXME("(%p,%p,%u,%p): stub\n", iface, piBitmapSource, option, ppIBitmap);
return E_NOTIMPL;
IWICBitmap *result;
IWICBitmapLock *lock;
IWICPalette *palette;
UINT width, height;
WICPixelFormatGUID pixelformat = {0};
HRESULT hr;
WICRect rc;
double dpix, dpiy;
TRACE("(%p,%p,%u,%p)\n", iface, piBitmapSource, option, ppIBitmap);
if (!piBitmapSource || !ppIBitmap)
return E_INVALIDARG;
hr = IWICBitmapSource_GetSize(piBitmapSource, &width, &height);
if (SUCCEEDED(hr))
hr = IWICBitmapSource_GetPixelFormat(piBitmapSource, &pixelformat);
if (SUCCEEDED(hr))
hr = BitmapImpl_Create(width, height, &pixelformat, option, &result);
if (SUCCEEDED(hr))
{
hr = IWICBitmap_Lock(result, NULL, WICBitmapLockWrite, &lock);
if (SUCCEEDED(hr))
{
UINT stride, buffersize;
BYTE *buffer;
rc.X = rc.Y = 0;
rc.Width = width;
rc.Height = height;
hr = IWICBitmapLock_GetStride(lock, &stride);
if (SUCCEEDED(hr))
hr = IWICBitmapLock_GetDataPointer(lock, &buffersize, &buffer);
if (SUCCEEDED(hr))
hr = IWICBitmapSource_CopyPixels(piBitmapSource, &rc, stride,
buffersize, buffer);
IWICBitmapLock_Release(lock);
}
if (SUCCEEDED(hr))
hr = PaletteImpl_Create(&palette);
if (SUCCEEDED(hr))
{
hr = IWICBitmapSource_CopyPalette(piBitmapSource, palette);
if (SUCCEEDED(hr))
hr = IWICBitmap_SetPalette(result, palette);
else
hr = S_OK;
IWICPalette_Release(palette);
}
if (SUCCEEDED(hr))
{
hr = IWICBitmapSource_GetResolution(piBitmapSource, &dpix, &dpiy);
if (SUCCEEDED(hr))
hr = IWICBitmap_SetResolution(result, dpix, dpiy);
else
hr = S_OK;
}
if (SUCCEEDED(hr))
*ppIBitmap = result;
else
IWICBitmap_Release(result);
}
return hr;
}
static HRESULT WINAPI ComponentFactory_CreateBitmapFromSourceRect(IWICComponentFactory *iface,
......
......@@ -329,7 +329,7 @@ static void test_createbitmapfromsource(void)
hr = IWICImagingFactory_CreateBitmapFromSource(factory, (IWICBitmapSource*)bitmap,
WICBitmapCacheOnLoad, &bitmap2);
todo_wine ok(hr == S_OK, "IWICImagingFactory_CreateBitmapFromSource failed hr=%x\n", hr);
ok(hr == S_OK, "IWICImagingFactory_CreateBitmapFromSource failed hr=%x\n", hr);
IWICBitmap_Release(bitmap);
......@@ -338,8 +338,9 @@ static void test_createbitmapfromsource(void)
hr = IWICImagingFactory_CreatePalette(factory, &palette);
ok(hr == S_OK, "IWICImagingFactory_CreatePalette failed hr=%x\n", hr);
/* palette isn't copied for non-indexed formats? */
hr = IWICBitmap_CopyPalette(bitmap2, palette);
ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "IWICBitmap_CopyPalette failed hr=%x\n", hr);
todo_wine ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "IWICBitmap_CopyPalette failed hr=%x\n", hr);
IWICPalette_Release(palette);
......
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