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, ...@@ -244,8 +244,10 @@ static HRESULT WINAPI BmpFrameEncode_WritePixels(IWICBitmapFrameEncode *iface,
UINT lineCount, UINT cbStride, UINT cbBufferSize, BYTE *pbPixels) UINT lineCount, UINT cbStride, UINT cbBufferSize, BYTE *pbPixels)
{ {
BmpFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); BmpFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface);
UINT dstbuffersize, bytesperrow, row;
BYTE *dst, *src;
HRESULT hr; HRESULT hr;
WICRect rc;
TRACE("(%p,%u,%u,%u,%p)\n", iface, lineCount, cbStride, cbBufferSize, pbPixels); TRACE("(%p,%u,%u,%u,%p)\n", iface, lineCount, cbStride, cbBufferSize, pbPixels);
if (!This->initialized || !This->width || !This->height || !This->format) if (!This->initialized || !This->width || !This->height || !This->format)
...@@ -254,19 +256,27 @@ static HRESULT WINAPI BmpFrameEncode_WritePixels(IWICBitmapFrameEncode *iface, ...@@ -254,19 +256,27 @@ static HRESULT WINAPI BmpFrameEncode_WritePixels(IWICBitmapFrameEncode *iface,
hr = BmpFrameEncode_AllocateBits(This); hr = BmpFrameEncode_AllocateBits(This);
if (FAILED(hr)) return hr; if (FAILED(hr)) return hr;
rc.X = 0; bytesperrow = ((This->format->bpp * This->width) + 7) / 8;
rc.Y = 0;
rc.Width = This->width;
rc.Height = lineCount;
hr = copy_pixels(This->format->bpp, pbPixels, This->width, lineCount, cbStride, if (This->stride < bytesperrow)
&rc, This->stride, This->stride*(This->height-This->lineswritten), return E_INVALIDARG;
This->bits + This->stride*This->lineswritten);
if (SUCCEEDED(hr)) dstbuffersize = This->stride * (This->height - This->lineswritten);
This->lineswritten += lineCount; 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, static HRESULT WINAPI BmpFrameEncode_WriteSource(IWICBitmapFrameEncode *iface,
...@@ -313,7 +323,7 @@ static HRESULT WINAPI BmpFrameEncode_Commit(IWICBitmapFrameEncode *iface) ...@@ -313,7 +323,7 @@ static HRESULT WINAPI BmpFrameEncode_Commit(IWICBitmapFrameEncode *iface)
bih.bV5Size = info_size = sizeof(BITMAPINFOHEADER); bih.bV5Size = info_size = sizeof(BITMAPINFOHEADER);
bih.bV5Width = This->width; bih.bV5Width = This->width;
bih.bV5Height = -This->height; /* top-down bitmap */ bih.bV5Height = This->height;
bih.bV5Planes = 1; bih.bV5Planes = 1;
bih.bV5BitCount = This->format->bpp; bih.bV5BitCount = This->format->bpp;
bih.bV5Compression = This->format->compression; bih.bV5Compression = This->format->compression;
......
...@@ -663,7 +663,6 @@ static void check_bmp_format(IStream *stream, const struct bitmap_data *data) ...@@ -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.biSize == sizeof(bih), "Unexpected header size %d.\n", bih.biSize);
ok(bih.biWidth == data->width, "Unexpected bitmap width %d.\n", bih.biWidth); 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.biHeight == data->height, "Unexpected bitmap height %d.\n", bih.biHeight);
ok(bih.biPlanes == 1, "Unexpected planes count %d.\n", bih.biPlanes); 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