From f77dade774e5a9652fe487b1468c56db8c68bdd2 Mon Sep 17 00:00:00 2001
From: Dmitry Timoshkov <dmitry@baikal.ru>
Date: Fri, 9 Dec 2016 12:58:30 +0800
Subject: windowscodecs: Add support for 4bpp RGBA format to TIFF decoder.

---
 dlls/windowscodecs/tiffformat.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/dlls/windowscodecs/tiffformat.c b/dlls/windowscodecs/tiffformat.c
index 15c4b69..bfb495c 100644
--- a/dlls/windowscodecs/tiffformat.c
+++ b/dlls/windowscodecs/tiffformat.c
@@ -1148,6 +1148,33 @@ static HRESULT TiffFrameDecode_ReadTile(TiffFrameDecode *This, UINT tile_x, UINT
 
         HeapFree(GetProcessHeap(), 0, srcdata);
     }
+    /* 4bpp RGBA */
+    else if (This->decode_info.source_bpp == 4 && This->decode_info.samples == 4 && This->decode_info.bpp == 32)
+    {
+        BYTE *src, *dst;
+        DWORD count;
+
+        /* 1 source byte expands to 2 BGRA samples */
+        count = (This->decode_info.tile_width * This->decode_info.tile_height + 1) / 2;
+
+        src = This->cached_tile + count - 1;
+        dst = This->cached_tile + This->decode_info.tile_size;
+
+        while (count--)
+        {
+            BYTE b = *src--;
+
+            dst -= 8;
+            dst[2] = (b & 0x80) ? 0xff : 0; /* R */
+            dst[1] = (b & 0x40) ? 0xff : 0; /* G */
+            dst[0] = (b & 0x20) ? 0xff : 0; /* B */
+            dst[3] = (b & 0x10) ? 0xff : 0; /* A */
+            dst[6] = (b & 0x08) ? 0xff : 0; /* R */
+            dst[5] = (b & 0x04) ? 0xff : 0; /* G */
+            dst[4] = (b & 0x02) ? 0xff : 0; /* B */
+            dst[7] = (b & 0x01) ? 0xff : 0; /* A */
+        }
+    }
     /* 8bpp grayscale with extra alpha */
     else if (This->decode_info.source_bpp == 16 && This->decode_info.samples == 2 && This->decode_info.bpp == 32)
     {
-- 
2.9.0

