From 4cc2f878faea04c3532963701531bd07dcc4f801 Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Mon, 10 Jan 2011 15:23:17 -0600 Subject: [PATCH 2/5] windowscodecs: Add a utility function for swapping 8-bit BGR/RGB data. --- dlls/windowscodecs/jpegformat.c | 17 ++++------------- dlls/windowscodecs/main.c | 20 ++++++++++++++++++++ dlls/windowscodecs/tiffformat.c | 15 +++------------ dlls/windowscodecs/wincodecs_private.h | 2 ++ 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/dlls/windowscodecs/jpegformat.c b/dlls/windowscodecs/jpegformat.c index e7a22c9..789a60b 100644 --- a/dlls/windowscodecs/jpegformat.c +++ b/dlls/windowscodecs/jpegformat.c @@ -577,7 +577,7 @@ static HRESULT WINAPI JpegDecoder_Frame_CopyPixels(IWICBitmapFrameDecode *iface, UINT first_scanline = This->cinfo.output_scanline; UINT max_rows; JSAMPROW out_rows[4]; - UINT i, j; + UINT i; JDIMENSION ret; max_rows = min(This->cinfo.output_height-first_scanline, 4); @@ -596,18 +596,9 @@ static HRESULT WINAPI JpegDecoder_Frame_CopyPixels(IWICBitmapFrameDecode *iface, if (bpp == 24) { /* libjpeg gives us RGB data and we want BGR, so byteswap the data */ - for (i=first_scanline; icinfo.output_scanline; i++) - { - BYTE *pixel = This->image_data + stride * i; - for (j=0; jcinfo.output_width; j++) - { - BYTE red=pixel[0]; - BYTE blue=pixel[2]; - pixel[0]=blue; - pixel[2]=red; - pixel+=3; - } - } + reverse_bgr8(3, This->image_data + stride * first_scanline, + This->cinfo.output_width, This->cinfo.output_scanline - first_scanline, + stride); } if (This->cinfo.out_color_space == JCS_CMYK && This->cinfo.saw_Adobe_marker) diff --git a/dlls/windowscodecs/main.c b/dlls/windowscodecs/main.c index 823fec2..69284c2 100644 --- a/dlls/windowscodecs/main.c +++ b/dlls/windowscodecs/main.c @@ -112,3 +112,23 @@ HRESULT copy_pixels(UINT bpp, const BYTE *srcbuffer, 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; ydecode_info.bps == 8) { - UINT i, total_pixels, sample_count; - BYTE *pixel, temp; + UINT sample_count = This->decode_info.samples; - total_pixels = This->decode_info.tile_width * This->decode_info.tile_height; - pixel = This->cached_tile; - sample_count = This->decode_info.samples; - for (i=0; icached_tile, This->decode_info.tile_width, + This->decode_info.tile_height, This->decode_info.tile_width * sample_count); } } diff --git a/dlls/windowscodecs/wincodecs_private.h b/dlls/windowscodecs/wincodecs_private.h index e50d130..3c416b0 100644 --- a/dlls/windowscodecs/wincodecs_private.h +++ b/dlls/windowscodecs/wincodecs_private.h @@ -51,6 +51,8 @@ extern HRESULT copy_pixels(UINT bpp, const BYTE *srcbuffer, UINT srcwidth, UINT srcheight, INT srcstride, 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 CreateComponentInfo(REFCLSID clsid, IWICComponentInfo **ppIInfo); -- 1.7.1