Commit f46235ce authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

wincodecs: Use bottom-up orientation in BMP encoder.

parent b4539f71
......@@ -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;
dstbuffersize = This->stride * (This->height - This->lineswritten);
if ((This->stride * (lineCount - 1)) + bytesperrow > dstbuffersize)
return E_INVALIDARG;
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;
}
if (SUCCEEDED(hr))
This->lineswritten += lineCount;
return hr;
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;
......
......@@ -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);
......
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