[gimp/gimp-2-6] Bug 555777 – Export to MNG animation fails



commit 0bcae79295af02fed3e1433905fda011618536bb
Author: Massimo Valentini <sixtysix inwind it>
Date:   Mon Jul 20 22:55:43 2009 +0200

    Bug 555777 â?? Export to MNG animation fails
    
    'mng_putchunk_plte' and 'mng_putchunk_trns' both copy  the array passed in
    as if it was full size even when it is only partly used. This commit wraps
    their calls passing the arrays dimensioned correctly.
    
    In function 'respin_cmap', when 'find_unused_ia_colour' returns an index
    suitable for transparency the number of colors in the colormap, the
    following loop used to access three values beyond the end of the array
    'before'.
    
    Finally fix a typo in a call to mng_putchunk_text().
    (cherry picked from commit e0f21468d4f6d887a8f0f26baee6da59abe59618)

 plug-ins/common/file-mng.c |   61 +++++++++++++++++++++++++++++++++----------
 1 files changed, 47 insertions(+), 14 deletions(-)
---
diff --git a/plug-ins/common/file-mng.c b/plug-ins/common/file-mng.c
index be669a9..29dd155 100644
--- a/plug-ins/common/file-mng.c
+++ b/plug-ins/common/file-mng.c
@@ -464,7 +464,7 @@ respin_cmap (png_structp  png_ptr,
 
       if (transparent != -1)
         {
-          png_color palette[256];
+          png_color palette[256] = { {0, 0, 0} };
           gint i;
 
           png_set_tRNS (png_ptr, png_info_ptr, (png_bytep) trans, 1, NULL);
@@ -482,7 +482,7 @@ respin_cmap (png_structp  png_ptr,
            * unchanged, and finally from index transparent to index 0.
            */
 
-          for (i = 0; i < colors; i++)
+          for (i = 1; i < colors; i++)
             {
               palette[i].red = before[3 * remap[i]];
               palette[i].green = before[3 * remap[i] + 1];
@@ -505,6 +505,41 @@ respin_cmap (png_structp  png_ptr,
   return FALSE;
 }
 
+static mng_retcode
+mng_putchunk_plte_wrapper (mng_handle    handle,
+                           gint          numcolors,
+                           const guchar *colormap)
+{
+  mng_palette8 palette;
+
+  memset (palette, 0, sizeof palette);
+  if (0 < numcolors)
+    memcpy (palette, colormap, numcolors * sizeof palette[0]);
+
+  return mng_putchunk_plte (handle, numcolors, palette);
+}
+
+static mng_retcode
+mng_putchunk_trns_wrapper (mng_handle    handle,
+                           gint          n_alphas,
+                           const guchar *buffer)
+{
+  const mng_bool mng_global = TRUE;
+  const mng_bool mng_empty  = TRUE;
+  mng_uint8arr   alphas;
+
+  memset (alphas, 0, sizeof alphas);
+  if (buffer && 0 < n_alphas)
+    memcpy (alphas, buffer, n_alphas * sizeof alphas[0]);
+
+  return mng_putchunk_trns (handle,
+                            ! mng_empty,
+                            ! mng_global,
+                            MNG_COLORTYPE_INDEXED,
+                            n_alphas,
+                            alphas,
+                            0, 0, 0, 0, 0, alphas);
+}
 
 static gboolean
 mng_save_image (const gchar  *filename,
@@ -638,7 +673,7 @@ mng_save_image (const gchar  *filename,
 
   if (mng_putchunk_text (handle,
                          strlen (MNG_TEXT_TITLE), MNG_TEXT_TITLE,
-                         22, "Created using GIMP") != MNG_NOERROR)
+                         18, "Created using GIMP") != MNG_NOERROR)
     {
       g_warning ("Unable to mng_putchunk_text() in mng_save_image()");
       goto err3;
@@ -732,8 +767,8 @@ mng_save_image (const gchar  *filename,
       palette = gimp_image_get_colormap (image_id, &numcolors);
 
       if ((numcolors != 0) &&
-          (mng_putchunk_plte (handle, numcolors,
-                              (mng_palette8e *) palette) != MNG_NOERROR))
+          (mng_putchunk_plte_wrapper (handle, numcolors,
+                                      palette) != MNG_NOERROR))
         {
           g_warning ("Unable to mng_putchunk_plte() in mng_save_image()");
           goto err3;
@@ -1169,11 +1204,10 @@ mng_save_image (const gchar  *filename,
               /* If this frame's palette is the same as the global palette,
                * write a 0-color palette chunk.
                */
-              if (mng_putchunk_plte (handle,
-                                     (layer_has_unique_palette ?
-                                      (chunksize / 3) : 0),
-                                     (mng_palette8e *) chunkbuffer) !=
-                  MNG_NOERROR)
+              if (mng_putchunk_plte_wrapper (handle,
+                                             (layer_has_unique_palette ?
+                                              (chunksize / 3) : 0),
+                                             chunkbuffer) != MNG_NOERROR)
                 {
                   g_warning ("Unable to mng_putchunk_plte() "
                              "in mng_save_image()");
@@ -1182,10 +1216,9 @@ mng_save_image (const gchar  *filename,
             }
           else if (strncmp (chunkname, "tRNS", 4) == 0)
             {
-              if (mng_putchunk_trns (handle, 0, 0, 3, chunksize,
-                                     (mng_uint8 *) chunkbuffer,
-                                     0, 0, 0, 0, 0,
-                                     (mng_uint8 *) chunkbuffer) != MNG_NOERROR)
+              if (mng_putchunk_trns_wrapper (handle,
+                                             chunksize,
+                                             chunkbuffer) != MNG_NOERROR)
                 {
                   g_warning ("Unable to mng_putchunk_trns() "
                              "in mng_save_image()");



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