Commit d9fb1a4b authored by Vincent Povirk's avatar Vincent Povirk Committed by Alexandre Julliard

windowscodecs: Add a utility function for swapping 8-bit BGR/RGB data.

parent d7476521
...@@ -577,7 +577,7 @@ static HRESULT WINAPI JpegDecoder_Frame_CopyPixels(IWICBitmapFrameDecode *iface, ...@@ -577,7 +577,7 @@ static HRESULT WINAPI JpegDecoder_Frame_CopyPixels(IWICBitmapFrameDecode *iface,
UINT first_scanline = This->cinfo.output_scanline; UINT first_scanline = This->cinfo.output_scanline;
UINT max_rows; UINT max_rows;
JSAMPROW out_rows[4]; JSAMPROW out_rows[4];
UINT i, j; UINT i;
JDIMENSION ret; JDIMENSION ret;
max_rows = min(This->cinfo.output_height-first_scanline, 4); max_rows = min(This->cinfo.output_height-first_scanline, 4);
...@@ -596,18 +596,9 @@ static HRESULT WINAPI JpegDecoder_Frame_CopyPixels(IWICBitmapFrameDecode *iface, ...@@ -596,18 +596,9 @@ static HRESULT WINAPI JpegDecoder_Frame_CopyPixels(IWICBitmapFrameDecode *iface,
if (bpp == 24) if (bpp == 24)
{ {
/* libjpeg gives us RGB data and we want BGR, so byteswap the data */ /* libjpeg gives us RGB data and we want BGR, so byteswap the data */
for (i=first_scanline; i<This->cinfo.output_scanline; i++) reverse_bgr8(3, This->image_data + stride * first_scanline,
{ This->cinfo.output_width, This->cinfo.output_scanline - first_scanline,
BYTE *pixel = This->image_data + stride * i; stride);
for (j=0; j<This->cinfo.output_width; j++)
{
BYTE red=pixel[0];
BYTE blue=pixel[2];
pixel[0]=blue;
pixel[2]=red;
pixel+=3;
}
}
} }
if (This->cinfo.out_color_space == JCS_CMYK && This->cinfo.saw_Adobe_marker) if (This->cinfo.out_color_space == JCS_CMYK && This->cinfo.saw_Adobe_marker)
......
...@@ -112,3 +112,22 @@ HRESULT copy_pixels(UINT bpp, const BYTE *srcbuffer, ...@@ -112,3 +112,22 @@ HRESULT copy_pixels(UINT bpp, const BYTE *srcbuffer,
return E_FAIL; return E_FAIL;
} }
} }
void reverse_bgr8(UINT bytesperpixel, LPBYTE bits, UINT width, UINT height, INT stride)
{
UINT x, y;
BYTE *pixel, temp;
for (y=0; y<height; y++)
{
pixel = bits + stride * y;
for (x=0; x<width; x++)
{
temp = pixel[2];
pixel[2] = pixel[0];
pixel[0] = temp;
pixel += bytesperpixel;
}
}
}
...@@ -800,19 +800,10 @@ static HRESULT TiffFrameDecode_ReadTile(TiffFrameDecode *This, UINT tile_x, UINT ...@@ -800,19 +800,10 @@ static HRESULT TiffFrameDecode_ReadTile(TiffFrameDecode *This, UINT tile_x, UINT
{ {
if (This->decode_info.bps == 8) if (This->decode_info.bps == 8)
{ {
UINT i, total_pixels, sample_count; UINT sample_count = This->decode_info.samples;
BYTE *pixel, temp;
total_pixels = This->decode_info.tile_width * This->decode_info.tile_height; reverse_bgr8(sample_count, This->cached_tile, This->decode_info.tile_width,
pixel = This->cached_tile; This->decode_info.tile_height, This->decode_info.tile_width * sample_count);
sample_count = This->decode_info.samples;
for (i=0; i<total_pixels; i++)
{
temp = pixel[2];
pixel[2] = pixel[0];
pixel[0] = temp;
pixel += sample_count;
}
} }
} }
......
...@@ -51,6 +51,8 @@ extern HRESULT copy_pixels(UINT bpp, const BYTE *srcbuffer, ...@@ -51,6 +51,8 @@ extern HRESULT copy_pixels(UINT bpp, const BYTE *srcbuffer,
UINT srcwidth, UINT srcheight, INT srcstride, UINT srcwidth, UINT srcheight, INT srcstride,
const WICRect *rc, UINT dststride, UINT dstbuffersize, BYTE *dstbuffer); const WICRect *rc, UINT dststride, UINT dstbuffersize, BYTE *dstbuffer);
extern void reverse_bgr8(UINT bytesperpixel, LPBYTE bits, UINT width, UINT height, INT stride);
extern HRESULT CreatePropertyBag2(IPropertyBag2 **ppPropertyBag2); extern HRESULT CreatePropertyBag2(IPropertyBag2 **ppPropertyBag2);
extern HRESULT CreateComponentInfo(REFCLSID clsid, IWICComponentInfo **ppIInfo); extern HRESULT CreateComponentInfo(REFCLSID clsid, IWICComponentInfo **ppIInfo);
......
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