Vincent Povirk : windowscodecs: Implement WriteSource for the PNG encoder.
Alexandre Julliard
julliard at winehq.org
Fri Oct 9 09:24:16 CDT 2009
Module: wine
Branch: master
Commit: b3790010fdf1eaae04a6cfc8c59d0699b93418d6
URL: http://source.winehq.org/git/wine.git/?a=commit;h=b3790010fdf1eaae04a6cfc8c59d0699b93418d6
Author: Vincent Povirk <vincent at codeweavers.com>
Date: Wed Sep 23 16:53:15 2009 -0500
windowscodecs: Implement WriteSource for the PNG encoder.
---
dlls/windowscodecs/pngformat.c | 70 ++++++++++++++++++++++++++++++++++++++-
1 files changed, 68 insertions(+), 2 deletions(-)
diff --git a/dlls/windowscodecs/pngformat.c b/dlls/windowscodecs/pngformat.c
index 1ac4772..c888b5a 100644
--- a/dlls/windowscodecs/pngformat.c
+++ b/dlls/windowscodecs/pngformat.c
@@ -901,8 +901,74 @@ static HRESULT WINAPI PngFrameEncode_WritePixels(IWICBitmapFrameEncode *iface,
static HRESULT WINAPI PngFrameEncode_WriteSource(IWICBitmapFrameEncode *iface,
IWICBitmapSource *pIBitmapSource, WICRect *prc)
{
- FIXME("(%p,%p,%p): stub\n", iface, pIBitmapSource, prc);
- return E_NOTIMPL;
+ PngEncoder *This = encoder_from_frame(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)
+ 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);
+
+ if (SUCCEEDED(hr))
+ {
+ hr = IWICBitmapFrameEncode_WritePixels(iface, prc->Height, stride,
+ stride*prc->Height, pixeldata);
+ }
+
+ HeapFree(GetProcessHeap(), 0, pixeldata);
+
+ return hr;
}
static HRESULT WINAPI PngFrameEncode_Commit(IWICBitmapFrameEncode *iface)
More information about the wine-cvs
mailing list