[gdk-pixbuf] tga: Split out a function
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdk-pixbuf] tga: Split out a function
- Date: Tue, 13 Oct 2015 01:00:17 +0000 (UTC)
commit 9314e129a7651f24abb15a92cfd3a59dabda0afd
Author: Benjamin Otte <otte redhat com>
Date: Sun Sep 20 17:59:29 2015 +0200
tga: Split out a function
Simplifies code and thereby makes it clearer which formats are
supported.
gdk-pixbuf/io-tga.c | 69 ++++++++++++++++++++++++--------------------------
1 files changed, 33 insertions(+), 36 deletions(-)
---
diff --git a/gdk-pixbuf/io-tga.c b/gdk-pixbuf/io-tga.c
index e41f42f..e313843 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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]