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

Alexandre Julliard julliard at winehq.org
Tue Jan 11 10:08:25 CST 2011


Module: wine
Branch: master
Commit: d9fb1a4b92ddf186bd17cb89cc1cd7ed3f9c2951
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=d9fb1a4b92ddf186bd17cb89cc1cd7ed3f9c2951

Author: Vincent Povirk <vincent at codeweavers.com>
Date:   Mon Jan 10 15:23:17 2011 -0600

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

---

 dlls/windowscodecs/jpegformat.c        |   17 ++++-------------
 dlls/windowscodecs/main.c              |   19 +++++++++++++++++++
 dlls/windowscodecs/tiffformat.c        |   15 +++------------
 dlls/windowscodecs/wincodecs_private.h |    2 ++
 4 files changed, 28 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; i<This->cinfo.output_scanline; i++)
-            {
-                BYTE *pixel = This->image_data + stride * i;
-                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;
-                }
-            }
+            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..a6588fd 100644
--- a/dlls/windowscodecs/main.c
+++ b/dlls/windowscodecs/main.c
@@ -112,3 +112,22 @@ 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; 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;
+        }
+    }
+}
diff --git a/dlls/windowscodecs/tiffformat.c b/dlls/windowscodecs/tiffformat.c
index 9dfd4ba..5c8aae9 100644
--- a/dlls/windowscodecs/tiffformat.c
+++ b/dlls/windowscodecs/tiffformat.c
@@ -800,19 +800,10 @@ static HRESULT TiffFrameDecode_ReadTile(TiffFrameDecode *This, UINT tile_x, UINT
     {
         if (This->decode_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; i<total_pixels; i++)
-            {
-                temp = pixel[2];
-                pixel[2] = pixel[0];
-                pixel[0] = temp;
-                pixel += sample_count;
-            }
+            reverse_bgr8(sample_count, This->cached_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);




More information about the wine-cvs mailing list