Imported from libpng-1.0.9beta7.tar
diff --git a/pngset.c b/pngset.c
index a85feec..3c9e265 100644
--- a/pngset.c
+++ b/pngset.c
@@ -1,7 +1,7 @@
/* pngset.c - storage of image information into info struct
*
- * libpng 1.0.9rc1 - December 23, 2000
+ * libpng 1.0.9beta7 - December 28, 2000
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -133,12 +133,31 @@
void PNGAPI
png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
{
+ int i;
+
png_debug1(1, "in %s storage function\n", "hIST");
if (png_ptr == NULL || info_ptr == NULL)
return;
+ if (info_ptr->num_palette == 0)
+ png_warning(png_ptr,
+ "Palette size 0, hIST allocation skipped.");
- info_ptr->hist = hist;
+#ifdef PNG_FREE_ME_SUPPORTED
+ png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
+#endif
+ png_ptr->hist = (png_uint_16p)png_malloc(png_ptr,
+ (png_uint_32)(info_ptr->num_palette * sizeof (png_uint_16)));
+
+ for (i = 0; i < info_ptr->num_palette; i++)
+ png_ptr->hist[i] = hist[i];
+ info_ptr->hist = png_ptr->hist;
info_ptr->valid |= PNG_INFO_hIST;
+
+#ifdef PNG_FREE_ME_SUPPORTED
+ info_ptr->free_me |= PNG_FREE_HIST;
+#else
+ png_ptr->flags |= PNG_FLAG_FREE_HIST;
+#endif
}
#endif
@@ -320,9 +339,26 @@
if (png_ptr == NULL || info_ptr == NULL)
return;
- info_ptr->palette = palette;
+ /*
+ * It may not actually be necessary to set png_ptr->palette here;
+ * we do it for backward compatibility with the way the png_handle_tRNS
+ * function used to do the allocation.
+ */
+#ifdef PNG_FREE_ME_SUPPORTED
+ png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
+#endif
+ png_ptr->palette = (png_colorp)png_zalloc(png_ptr, (uInt)num_palette,
+ sizeof (png_color));
+ memcpy(png_ptr->palette, palette, num_palette * sizeof (png_color));
+ info_ptr->palette = png_ptr->palette;
+ info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
- info_ptr->num_palette = (png_uint_16)num_palette;
+#ifdef PNG_FREE_ME_SUPPORTED
+ info_ptr->free_me |= PNG_FREE_PLTE;
+#else
+ png_ptr->flags |= PNG_FLAG_FREE_PLTE;
+#endif
+
info_ptr->valid |= PNG_INFO_PLTE;
}
@@ -631,7 +667,23 @@
return;
if (trans != NULL)
- info_ptr->trans = trans;
+ {
+ /*
+ * It may not actually be necessary to set png_ptr->trans here;
+ * we do it for backward compatibility with the way the png_handle_tRNS
+ * function used to do the allocation.
+ */
+#ifdef PNG_FREE_ME_SUPPORTED
+ png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
+#endif
+ png_ptr->trans = info_ptr->trans = png_malloc(png_ptr, num_trans);
+ memcpy(info_ptr->trans, trans, num_trans);
+#ifdef PNG_FREE_ME_SUPPORTED
+ info_ptr->free_me |= PNG_FREE_TRNS;
+#else
+ png_ptr->flags |= PNG_FLAG_FREE_TRNS;
+#endif
+ }
if (trans_values != NULL)
{