Vincent Povirk : windowscodecs: Implement conversion from 16bppBGR565 to 32bppBGRA.

Alexandre Julliard julliard at winehq.org
Fri Aug 14 08:59:53 CDT 2009


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

Author: Vincent Povirk <vincent at codeweavers.com>
Date:   Thu Aug 13 13:34:20 2009 -0500

windowscodecs: Implement conversion from 16bppBGR565 to 32bppBGRA.

---

 dlls/windowscodecs/converter.c |   50 ++++++++++++++++++++++++++++++++++++++++
 dlls/windowscodecs/regsvr.c    |    1 +
 2 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/dlls/windowscodecs/converter.c b/dlls/windowscodecs/converter.c
index c53a0cd..fb8bd87 100644
--- a/dlls/windowscodecs/converter.c
+++ b/dlls/windowscodecs/converter.c
@@ -37,6 +37,7 @@ struct FormatConverter;
 
 enum pixelformat {
     format_16bppBGR555,
+    format_16bppBGR565,
     format_32bppBGR,
     format_32bppBGRA
 };
@@ -113,6 +114,54 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe
             return res;
         }
         return S_OK;
+    case format_16bppBGR565:
+        if (prc)
+        {
+            HRESULT res;
+            UINT x, y;
+            BYTE *srcdata;
+            UINT srcstride, srcdatasize;
+            const BYTE *srcrow;
+            const WORD *srcpixel;
+            BYTE *dstrow;
+            DWORD *dstpixel;
+
+            srcstride = 2 * prc->Width;
+            srcdatasize = srcstride * prc->Height;
+
+            srcdata = HeapAlloc(GetProcessHeap(), 0, srcdatasize);
+            if (!srcdata) return E_OUTOFMEMORY;
+
+            res = IWICBitmapSource_CopyPixels(This->source, prc, srcstride, srcdatasize, srcdata);
+
+            if (SUCCEEDED(res))
+            {
+                srcrow = srcdata;
+                dstrow = pbBuffer;
+                for (y=0; y<prc->Height; y++) {
+                    srcpixel=(const WORD*)srcrow;
+                    dstpixel=(DWORD*)dstrow;
+                    for (x=0; x<prc->Width; x++) {
+                        WORD srcval;
+                        srcval=*srcpixel++;
+                        *dstpixel++=0xff000000 | /* constant 255 alpha */
+                                    ((srcval << 8) & 0xf80000) | /* r */
+                                    ((srcval << 3) & 0x070000) | /* r - 3 bits */
+                                    ((srcval << 5) & 0x00fc00) | /* g */
+                                    ((srcval >> 1) & 0x000300) | /* g - 2 bits */
+                                    ((srcval << 3) & 0x0000f8) | /* b */
+                                    ((srcval >> 2) & 0x000007);  /* b - 3 bits */
+                    }
+                    srcrow += srcstride;
+                    dstrow += cbStride;
+                }
+            }
+
+            HeapFree(GetProcessHeap(), 0, srcdata);
+
+            return res;
+        }
+        return S_OK;
     case format_32bppBGR:
         if (prc)
         {
@@ -154,6 +203,7 @@ static HRESULT copypixels_to_32bppBGR(struct FormatConverter *This, const WICRec
 
 static const struct pixelformatinfo supported_formats[] = {
     {format_16bppBGR555, &GUID_WICPixelFormat16bppBGR555, NULL},
+    {format_16bppBGR565, &GUID_WICPixelFormat16bppBGR565, NULL},
     {format_32bppBGR, &GUID_WICPixelFormat32bppBGR, copypixels_to_32bppBGR},
     {format_32bppBGRA, &GUID_WICPixelFormat32bppBGRA, copypixels_to_32bppBGRA},
     {0}
diff --git a/dlls/windowscodecs/regsvr.c b/dlls/windowscodecs/regsvr.c
index f8e2f3f..7886a6d 100644
--- a/dlls/windowscodecs/regsvr.c
+++ b/dlls/windowscodecs/regsvr.c
@@ -790,6 +790,7 @@ static struct regsvr_decoder const decoder_list[] = {
 
 static GUID const * const converter_formats[] = {
     &GUID_WICPixelFormat16bppBGR555,
+    &GUID_WICPixelFormat16bppBGR565,
     &GUID_WICPixelFormat32bppBGR,
     &GUID_WICPixelFormat32bppBGRA,
     NULL




More information about the wine-cvs mailing list