wincodecs: Use bottom-up orientation in BMP encoder.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Vincent Povirk <vincent@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2018-03-13 02:52:30 +03:00 committed by Alexandre Julliard
parent b4539f7136
commit f46235ce4f
2 changed files with 22 additions and 13 deletions

View File

@ -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;

View File

@ -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);