[gdk-pixbuf/wip/otte/tga: 14/17] tga: Support 16bpp images



commit 38d02d07c70921b7504bd0784ee78fcab862a28f
Author: Benjamin Otte <otte redhat com>
Date:   Sun Sep 20 21:44:08 2015 +0200

    tga: Support 16bpp images

 gdk-pixbuf/io-tga.c |   29 ++++++++++++++++++++++-------
 1 files changed, 22 insertions(+), 7 deletions(-)
---
diff --git a/gdk-pixbuf/io-tga.c b/gdk-pixbuf/io-tga.c
index 34fd5b4..12a3281 100644
--- a/gdk-pixbuf/io-tga.c
+++ b/gdk-pixbuf/io-tga.c
@@ -253,7 +253,8 @@ tga_format_supported (guint type,
 
       case TGA_TYPE_TRUECOLOR:
       case TGA_TYPE_RLE_TRUECOLOR:
-        return bits_per_pixel == 24
+        return bits_per_pixel == 16
+            || bits_per_pixel == 24
             || bits_per_pixel == 32;
 
       case TGA_TYPE_GRAYSCALE:
@@ -280,13 +281,27 @@ tga_read_pixel (TGAContext   *ctx,
 
       case TGA_TYPE_TRUECOLOR:
       case TGA_TYPE_RLE_TRUECOLOR:
-        color->b = data[0];
-        color->g = data[1];
-        color->r = data[2];
-        if (ctx->hdr->bpp == 32)
-          color->a = data[3];
+        if (ctx->hdr->bpp == 16)
+          {
+            guint16 col = data[0] + (data[1] << 8);
+            color->r = (col >> 7) & 0xf8;
+            color->r |= color->r >> 5;
+            color->g = (col >> 2) & 0xf8;
+            color->g |= color->g >> 5;
+            color->b = col << 3;
+            color->b |= color->b >> 5;
+            color->a = 255;
+          }
         else
-          color->a = 255;
+          {
+            color->b = data[0];
+            color->g = data[1];
+            color->r = data[2];
+            if (ctx->hdr->bpp == 32)
+              color->a = data[3];
+            else
+              color->a = 255;
+          }
         break;
 
       case TGA_TYPE_GRAYSCALE:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]