summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2015-09-20 17:59:29 +0200
committerBenjamin Otte <otte@redhat.com>2015-10-13 02:56:47 +0200
commit9314e129a7651f24abb15a92cfd3a59dabda0afd (patch)
tree60f522ab37f4c4bd4eca408b8d72d23756983e09
parent8348f54c28fcff6f4ddf34245854182f8403916c (diff)
downloadgdk-pixbuf-9314e129a7651f24abb15a92cfd3a59dabda0afd.tar.gz
tga: Split out a function
Simplifies code and thereby makes it clearer which formats are supported.
-rw-r--r--gdk-pixbuf/io-tga.c69
1 files changed, 33 insertions, 36 deletions
diff --git a/gdk-pixbuf/io-tga.c b/gdk-pixbuf/io-tga.c
index e41f42f25..e313843f0 100644
--- a/gdk-pixbuf/io-tga.c
+++ b/gdk-pixbuf/io-tga.c
@@ -267,6 +267,31 @@ tga_emit_update (TGAContext *ctx)
ctx->pbuf_y_notified = ctx->pbuf_y;
}
+static gboolean
+tga_format_supported (guint type,
+ guint bits_per_pixel)
+{
+ switch (type)
+ {
+ case TGA_TYPE_PSEUDOCOLOR:
+ case TGA_TYPE_RLE_PSEUDOCOLOR:
+ return bits_per_pixel == 8;
+
+ case TGA_TYPE_TRUECOLOR:
+ case TGA_TYPE_RLE_TRUECOLOR:
+ return bits_per_pixel == 24
+ || bits_per_pixel == 32;
+
+ case TGA_TYPE_GRAYSCALE:
+ case TGA_TYPE_RLE_GRAYSCALE:
+ return bits_per_pixel == 8
+ || bits_per_pixel == 16;
+
+ default:
+ return FALSE;
+ }
+}
+
static gboolean fill_in_context(TGAContext *ctx, GError **err)
{
gboolean alpha;
@@ -754,42 +779,14 @@ tga_load_header (TGAContext *ctx,
_("TGA image type not supported"));
return FALSE;
}
- switch (ctx->hdr->type) {
- case TGA_TYPE_PSEUDOCOLOR:
- case TGA_TYPE_RLE_PSEUDOCOLOR:
- if (ctx->hdr->bpp != 8) {
- g_set_error_literal(err, GDK_PIXBUF_ERROR,
- GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
- _("TGA image type not supported"));
- return FALSE;
- }
- break;
- case TGA_TYPE_TRUECOLOR:
- case TGA_TYPE_RLE_TRUECOLOR:
- if (ctx->hdr->bpp != 24 &&
- ctx->hdr->bpp != 32) {
- g_set_error_literal(err, GDK_PIXBUF_ERROR,
- GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
- _("TGA image type not supported"));
- return FALSE;
- }
- break;
- case TGA_TYPE_GRAYSCALE:
- case TGA_TYPE_RLE_GRAYSCALE:
- if (ctx->hdr->bpp != 8 &&
- ctx->hdr->bpp != 16) {
- g_set_error_literal(err, GDK_PIXBUF_ERROR,
- GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
- _("TGA image type not supported"));
- return FALSE;
- }
- break;
- default:
- g_set_error_literal(err, GDK_PIXBUF_ERROR,
- GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
- _("TGA image type not supported"));
- return FALSE;
- }
+ if (!tga_format_supported (ctx->hdr->type, ctx->hdr->bpp))
+ {
+ g_set_error_literal(err, GDK_PIXBUF_ERROR,
+ GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
+ _("TGA image type not supported"));
+ return FALSE;
+ }
+
if (!fill_in_context(ctx, err))
return FALSE;