Skip to content

Commit

Permalink
[WINDOWSCODECS]
Browse files Browse the repository at this point in the history
* Sync with Wine 1.7.27.
CORE-8540

git-svn-id: svn://svn.reactos.org/reactos/trunk@64615 97493ccd-5924-5043-b1f5-66cb403b36ce
  • Loading branch information
AmineKhaldi committed Oct 8, 2014
1 parent d527751 commit 0a6dab4
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 285 deletions.
57 changes: 8 additions & 49 deletions reactos/dll/win32/windowscodecs/bmpencode.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,63 +245,22 @@ static HRESULT WINAPI BmpFrameEncode_WriteSource(IWICBitmapFrameEncode *iface,
{
BmpFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
HRESULT hr;
WICRect rc;
WICPixelFormatGUID guid;
TRACE("(%p,%p,%p)\n", iface, pIBitmapSource, prc);

if (!This->initialized || !This->width || !This->height)
if (!This->initialized)
return WINCODEC_ERR_WRONGSTATE;

if (!This->format)
{
hr = IWICBitmapSource_GetPixelFormat(pIBitmapSource, &guid);
if (FAILED(hr)) return hr;
hr = BmpFrameEncode_SetPixelFormat(iface, &guid);
if (FAILED(hr)) return hr;
}

hr = IWICBitmapSource_GetPixelFormat(pIBitmapSource, &guid);
if (FAILED(hr)) return hr;
if (memcmp(&guid, This->format->guid, sizeof(GUID)) != 0)
{
/* should use WICConvertBitmapSource to convert, but that's unimplemented */
ERR("format %s unsupported\n", debugstr_guid(&guid));
return E_FAIL;
}

if (This->xres == 0.0 || This->yres == 0.0)
{
double xres, yres;
hr = IWICBitmapSource_GetResolution(pIBitmapSource, &xres, &yres);
if (FAILED(hr)) return hr;
hr = BmpFrameEncode_SetResolution(iface, xres, yres);
if (FAILED(hr)) return hr;
}
hr = configure_write_source(iface, pIBitmapSource, prc,
This->format ? This->format->guid : NULL, This->width, This->height,
This->xres, This->yres);

if (!prc)
if (SUCCEEDED(hr))
{
UINT width, height;
hr = IWICBitmapSource_GetSize(pIBitmapSource, &width, &height);
if (FAILED(hr)) return hr;
rc.X = 0;
rc.Y = 0;
rc.Width = width;
rc.Height = height;
prc = &rc;
hr = write_source(iface, pIBitmapSource, prc,
This->format->guid, This->format->bpp, This->width, This->height);
}

if (prc->Width != This->width) return E_INVALIDARG;

hr = BmpFrameEncode_AllocateBits(This);
if (FAILED(hr)) return hr;

hr = IWICBitmapSource_CopyPixels(pIBitmapSource, prc, This->stride,
This->stride*(This->height-This->lineswritten),
This->bits + This->stride*This->lineswritten);

This->lineswritten += prc->Height;

return S_OK;
return hr;
}

static HRESULT WINAPI BmpFrameEncode_Commit(IWICBitmapFrameEncode *iface)
Expand Down
58 changes: 7 additions & 51 deletions reactos/dll/win32/windowscodecs/icnsformat.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,66 +374,22 @@ static HRESULT WINAPI IcnsFrameEncode_WriteSource(IWICBitmapFrameEncode *iface,
{
IcnsFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
HRESULT hr;
WICRect rc;
WICPixelFormatGUID guid;
UINT stride;
BYTE *pixeldata = NULL;

TRACE("(%p,%p,%p)\n", iface, pIBitmapSource, prc);

if (!This->initialized || !This->size)
{
hr = WINCODEC_ERR_WRONGSTATE;
goto end;
}

hr = IWICBitmapSource_GetPixelFormat(pIBitmapSource, &guid);
if (FAILED(hr))
goto end;
if (!IsEqualGUID(&guid, &GUID_WICPixelFormat32bppBGRA))
{
FIXME("format %s unsupported, could use WICConvertBitmapSource to convert\n", debugstr_guid(&guid));
hr = E_FAIL;
goto end;
}

if (!prc)
{
UINT width, height;
hr = IWICBitmapSource_GetSize(pIBitmapSource, &width, &height);
if (FAILED(hr))
goto end;
rc.X = 0;
rc.Y = 0;
rc.Width = width;
rc.Height = height;
prc = &rc;
}
if (!This->initialized)
return WINCODEC_ERR_WRONGSTATE;

if (prc->Width != This->size)
{
hr = E_INVALIDARG;
goto end;
}
hr = configure_write_source(iface, pIBitmapSource, &prc,
&GUID_WICPixelFormat32bppBGRA, This->size, This->size,
1.0, 1.0);

stride = (32 * This->size + 7)/8;
pixeldata = HeapAlloc(GetProcessHeap(), 0, stride * prc->Height);
if (!pixeldata)
{
hr = E_OUTOFMEMORY;
goto end;
}

hr = IWICBitmapSource_CopyPixels(pIBitmapSource, prc, stride,
stride*prc->Height, pixeldata);
if (SUCCEEDED(hr))
{
hr = IWICBitmapFrameEncode_WritePixels(iface, prc->Height, stride,
stride*prc->Height, pixeldata);
hr = write_source(iface, pIBitmapSource, prc,
&GUID_WICPixelFormat32bppBGRA, 32, This->size, This->size);
}

end:
HeapFree(GetProcessHeap(), 0, pixeldata);
return hr;
}

Expand Down
18 changes: 10 additions & 8 deletions reactos/dll/win32/windowscodecs/imgfactory.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,20 +529,22 @@ static HRESULT WINAPI ComponentFactory_CreateBitmapFromSource(IWICComponentFacto
IWICBitmapLock_Release(lock);
}

if (SUCCEEDED(hr))
hr = PaletteImpl_Create(&palette);

if (SUCCEEDED(hr) && (format_type == WICPixelFormatNumericRepresentationUnspecified ||
format_type == WICPixelFormatNumericRepresentationIndexed))
{
hr = IWICBitmapSource_CopyPalette(piBitmapSource, palette);
hr = PaletteImpl_Create(&palette);

if (SUCCEEDED(hr))
hr = IWICBitmap_SetPalette(result, palette);
else
hr = S_OK;
{
hr = IWICBitmapSource_CopyPalette(piBitmapSource, palette);

if (SUCCEEDED(hr))
hr = IWICBitmap_SetPalette(result, palette);
else
hr = S_OK;

IWICPalette_Release(palette);
IWICPalette_Release(palette);
}
}

if (SUCCEEDED(hr))
Expand Down
62 changes: 6 additions & 56 deletions reactos/dll/win32/windowscodecs/jpegformat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1088,71 +1088,21 @@ static HRESULT WINAPI JpegEncoder_Frame_WriteSource(IWICBitmapFrameEncode *iface
{
JpegEncoder *This = impl_from_IWICBitmapFrameEncode(iface);
HRESULT hr;
WICRect rc;
WICPixelFormatGUID guid;
UINT stride;
BYTE *pixeldata;
TRACE("(%p,%p,%p)\n", iface, pIBitmapSource, prc);

if (!This->frame_initialized || !This->width || !This->height)
if (!This->frame_initialized)
return WINCODEC_ERR_WRONGSTATE;

if (!This->format)
{
hr = IWICBitmapSource_GetPixelFormat(pIBitmapSource, &guid);
if (FAILED(hr)) return hr;
hr = IWICBitmapFrameEncode_SetPixelFormat(iface, &guid);
if (FAILED(hr)) return hr;
}

hr = IWICBitmapSource_GetPixelFormat(pIBitmapSource, &guid);
if (FAILED(hr)) return hr;
if (memcmp(&guid, This->format->guid, sizeof(GUID)) != 0)
{
/* FIXME: should use WICConvertBitmapSource to convert */
ERR("format %s unsupported\n", debugstr_guid(&guid));
return E_FAIL;
}

if (This->xres == 0.0 || This->yres == 0.0)
{
double xres, yres;
hr = IWICBitmapSource_GetResolution(pIBitmapSource, &xres, &yres);
if (FAILED(hr)) return hr;
hr = IWICBitmapFrameEncode_SetResolution(iface, xres, yres);
if (FAILED(hr)) return hr;
}

if (!prc)
{
UINT width, height;
hr = IWICBitmapSource_GetSize(pIBitmapSource, &width, &height);
if (FAILED(hr)) return hr;
rc.X = 0;
rc.Y = 0;
rc.Width = width;
rc.Height = height;
prc = &rc;
}

if (prc->Width != This->width) return E_INVALIDARG;

stride = (This->format->bpp * This->width + 7)/8;

pixeldata = HeapAlloc(GetProcessHeap(), 0, stride * prc->Height);
if (!pixeldata) return E_OUTOFMEMORY;

hr = IWICBitmapSource_CopyPixels(pIBitmapSource, prc, stride,
stride*prc->Height, pixeldata);
hr = configure_write_source(iface, pIBitmapSource, prc,
This->format ? This->format->guid : NULL, This->width, This->height,
This->xres, This->yres);

if (SUCCEEDED(hr))
{
hr = IWICBitmapFrameEncode_WritePixels(iface, prc->Height, stride,
stride*prc->Height, pixeldata);
hr = write_source(iface, pIBitmapSource, prc,
This->format->guid, This->format->bpp, This->width, This->height);
}

HeapFree(GetProcessHeap(), 0, pixeldata);

return hr;
}

Expand Down
86 changes: 86 additions & 0 deletions reactos/dll/win32/windowscodecs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,92 @@ HRESULT copy_pixels(UINT bpp, const BYTE *srcbuffer,
}
}

HRESULT configure_write_source(IWICBitmapFrameEncode *iface,
IWICBitmapSource *source, const WICRect *prc,
const WICPixelFormatGUID *format,
INT width, INT height, double xres, double yres)
{
HRESULT hr=S_OK;
WICPixelFormatGUID src_format, dst_format;

if (width == 0 || height == 0)
return WINCODEC_ERR_WRONGSTATE;

hr = IWICBitmapSource_GetPixelFormat(source, &src_format);
if (FAILED(hr)) return hr;

if (!format)
{
dst_format = src_format;

hr = IWICBitmapFrameEncode_SetPixelFormat(iface, &dst_format);
if (FAILED(hr)) return hr;

format = &dst_format;
}

if (!IsEqualGUID(&src_format, format))
{
/* FIXME: should use WICConvertBitmapSource to convert */
ERR("format %s unsupported\n", debugstr_guid(&src_format));
return E_FAIL;
}

if (xres == 0.0 || yres == 0.0)
{
hr = IWICBitmapSource_GetResolution(source, &xres, &yres);
if (FAILED(hr)) return hr;
hr = IWICBitmapFrameEncode_SetResolution(iface, xres, yres);
if (FAILED(hr)) return hr;
}

return hr;
}

HRESULT write_source(IWICBitmapFrameEncode *iface,
IWICBitmapSource *source, const WICRect *prc,
const WICPixelFormatGUID *format, UINT bpp,
INT width, INT height)
{
HRESULT hr=S_OK;
WICRect rc;
UINT stride;
BYTE* pixeldata;

if (!prc)
{
UINT src_width, src_height;
hr = IWICBitmapSource_GetSize(source, &src_width, &src_height);
if (FAILED(hr)) return hr;
rc.X = 0;
rc.Y = 0;
rc.Width = src_width;
rc.Height = src_height;
prc = &rc;
}

if (prc->Width != width || prc->Height <= 0)
return E_INVALIDARG;

stride = (bpp * width + 7)/8;

pixeldata = HeapAlloc(GetProcessHeap(), 0, stride * prc->Height);
if (!pixeldata) return E_OUTOFMEMORY;

hr = IWICBitmapSource_CopyPixels(source, prc, stride,
stride*prc->Height, pixeldata);

if (SUCCEEDED(hr))
{
hr = IWICBitmapFrameEncode_WritePixels(iface, prc->Height, stride,
stride*prc->Height, pixeldata);
}

HeapFree(GetProcessHeap(), 0, pixeldata);

return hr;
}

void reverse_bgr8(UINT bytesperpixel, LPBYTE bits, UINT width, UINT height, INT stride)
{
UINT x, y;
Expand Down
Loading

0 comments on commit 0a6dab4

Please sign in to comment.