]> Pileus Git - ~andy/gtk/blobdiff - gdk-pixbuf/io-tga.c
Always check for NULL when using callbacks. (#330563, Benjamin Otte)
[~andy/gtk] / gdk-pixbuf / io-tga.c
index ef49e79315bb0f2699ea11d6f748a725524fa860..2cde75f767cc38c867cd0e9b0d57bc0d3a9e9b5c 100644 (file)
 /*
  * Some NOTES about the TGA loader (2001/06/07, nikke@swlibero.org)
  *
- * - The module doesn't currently provide support for TGA images where the
- *   order of the pixels isn't left-to-right and top-to-bottom.  I plan to
- *   add support for those files as soon as I get one of them.  I haven't
- *   run into one yet.  (And I don't seem to be able to create it with GIMP.)
- *
  * - The TGAFooter isn't present in all TGA files.  In fact, there's an older
  *   format specification, still in use, which doesn't cover the TGAFooter.
  *   Actually, most TGA files I have are of the older type.  Anyway I put the 
@@ -635,19 +630,16 @@ static guint parse_rle_data_grayscale(TGAContext *ctx)
 
 static gboolean parse_rle_data(TGAContext *ctx, GError **err)
 {
+       guint rows = 0;
        guint count = 0;
-       guint pbuf_count = 0;
        guint bytes_done_before = ctx->pbuf_bytes_done;
-       if (ctx->hdr->type == TGA_TYPE_RLE_PSEUDOCOLOR) {
+
+       if (ctx->hdr->type == TGA_TYPE_RLE_PSEUDOCOLOR)
                count = parse_rle_data_pseudocolor(ctx);
-               pbuf_count = count * ctx->pbuf->n_channels;
-       } else if (ctx->hdr->type == TGA_TYPE_RLE_TRUECOLOR) {
+       else if (ctx->hdr->type == TGA_TYPE_RLE_TRUECOLOR)
                count = parse_rle_data_truecolor(ctx);
-               pbuf_count = count;
-       } else if (ctx->hdr->type == TGA_TYPE_RLE_GRAYSCALE) {
+       else if (ctx->hdr->type == TGA_TYPE_RLE_GRAYSCALE)
                count = parse_rle_data_grayscale(ctx);
-               pbuf_count = count * (ctx->pbuf->n_channels == 4 ? 2 : 3);
-       }
 
        if (ctx->hdr->flags & TGA_ORIGIN_RIGHT) {
                guchar *row = ctx->pbuf->pixels + (bytes_done_before / ctx->pbuf->rowstride) * ctx->pbuf->rowstride;
@@ -667,14 +659,15 @@ static gboolean parse_rle_data(TGAContext *ctx, GError **err)
                 */
                if (!(ctx->hdr->flags & TGA_ORIGIN_UPPER))
                        pixbuf_flip_vertically (ctx->pbuf);
-       }
 
+       }
+               
+       rows = ctx->pbuf_bytes_done / ctx->pbuf->rowstride - bytes_done_before / ctx->pbuf->rowstride;
        if (ctx->ufunc)
-               (*ctx->ufunc) (ctx->pbuf, 0, ctx->pbuf_bytes_done / ctx->pbuf->rowstride,
-                              ctx->pbuf->width, pbuf_count / ctx->pbuf->rowstride,
+               (*ctx->ufunc) (ctx->pbuf, 0, bytes_done_before / ctx->pbuf->rowstride,
+                              ctx->pbuf->width, rows,
                               ctx->udata);
 
-
        return TRUE;
 }
 
@@ -995,5 +988,6 @@ MODULE_ENTRY (tga, fill_info) (GdkPixbufFormat *info)
        info->description = N_("The Targa image format");
        info->mime_types = mime_types;
        info->extensions = extensions;
-       info->flags = 0;
+       info->flags = GDK_PIXBUF_FORMAT_THREADSAFE;
+       info->license = "LGPL";
 }