Nikolay Sivov : wincodecs: Use bottom-up orientation in BMP encoder.
Alexandre Julliard
julliard at winehq.org
Tue Mar 13 17:10:54 CDT 2018
Module: wine
Branch: master
Commit: f46235ce4f5a2cc7056f884e3415cd8908ef12ab
URL: https://source.winehq.org/git/wine.git/?a=commit;h=f46235ce4f5a2cc7056f884e3415cd8908ef12ab
Author: Nikolay Sivov <nsivov at codeweavers.com>
Date: Tue Mar 13 02:52:30 2018 +0300
wincodecs: Use bottom-up orientation in BMP encoder.
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Vincent Povirk <vincent at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/windowscodecs/bmpencode.c | 34 ++++++++++++++++++++++------------
dlls/windowscodecs/tests/converter.c | 1 -
2 files changed, 22 insertions(+), 13 deletions(-)
diff --git a/dlls/windowscodecs/bmpencode.c b/dlls/windowscodecs/bmpencode.c
index afd0baf..97f30d7 100644
--- a/dlls/windowscodecs/bmpencode.c
+++ b/dlls/windowscodecs/bmpencode.c
@@ -244,8 +244,10 @@ static HRESULT WINAPI BmpFrameEncode_WritePixels(IWICBitmapFrameEncode *iface,
UINT lineCount, UINT cbStride, UINT cbBufferSize, BYTE *pbPixels)
{
BmpFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
+ UINT dstbuffersize, bytesperrow, row;
+ BYTE *dst, *src;
HRESULT hr;
- WICRect rc;
+
TRACE("(%p,%u,%u,%u,%p)\n", iface, lineCount, cbStride, cbBufferSize, pbPixels);
if (!This->initialized || !This->width || !This->height || !This->format)
@@ -254,19 +256,27 @@ static HRESULT WINAPI BmpFrameEncode_WritePixels(IWICBitmapFrameEncode *iface,
hr = BmpFrameEncode_AllocateBits(This);
if (FAILED(hr)) return hr;
- rc.X = 0;
- rc.Y = 0;
- rc.Width = This->width;
- rc.Height = lineCount;
+ bytesperrow = ((This->format->bpp * This->width) + 7) / 8;
- hr = copy_pixels(This->format->bpp, pbPixels, This->width, lineCount, cbStride,
- &rc, This->stride, This->stride*(This->height-This->lineswritten),
- This->bits + This->stride*This->lineswritten);
+ if (This->stride < bytesperrow)
+ return E_INVALIDARG;
- if (SUCCEEDED(hr))
- This->lineswritten += lineCount;
+ dstbuffersize = This->stride * (This->height - This->lineswritten);
+ if ((This->stride * (lineCount - 1)) + bytesperrow > dstbuffersize)
+ return E_INVALIDARG;
- return hr;
+ src = pbPixels;
+ dst = This->bits + This->stride * (This->height - This->lineswritten - 1);
+ for (row = 0; row < lineCount; row++)
+ {
+ memcpy(dst, src, bytesperrow);
+ src += cbStride;
+ dst -= This->stride;
+ }
+
+ This->lineswritten += lineCount;
+
+ return S_OK;
}
static HRESULT WINAPI BmpFrameEncode_WriteSource(IWICBitmapFrameEncode *iface,
@@ -313,7 +323,7 @@ static HRESULT WINAPI BmpFrameEncode_Commit(IWICBitmapFrameEncode *iface)
bih.bV5Size = info_size = sizeof(BITMAPINFOHEADER);
bih.bV5Width = This->width;
- bih.bV5Height = -This->height; /* top-down bitmap */
+ bih.bV5Height = This->height;
bih.bV5Planes = 1;
bih.bV5BitCount = This->format->bpp;
bih.bV5Compression = This->format->compression;
diff --git a/dlls/windowscodecs/tests/converter.c b/dlls/windowscodecs/tests/converter.c
index 472bee5..5f9f1d8 100644
--- a/dlls/windowscodecs/tests/converter.c
+++ b/dlls/windowscodecs/tests/converter.c
@@ -663,7 +663,6 @@ static void check_bmp_format(IStream *stream, const struct bitmap_data *data)
ok(bih.biSize == sizeof(bih), "Unexpected header size %d.\n", bih.biSize);
ok(bih.biWidth == data->width, "Unexpected bitmap width %d.\n", bih.biWidth);
-todo_wine
ok(bih.biHeight == data->height, "Unexpected bitmap height %d.\n", bih.biHeight);
ok(bih.biPlanes == 1, "Unexpected planes count %d.\n", bih.biPlanes);
More information about the wine-cvs
mailing list