src/lib/pngwrite.c 1.2

1.2 2009/08/20 21:34:44 angie
Used more civilized language in comment & errAbort per Larry's code review feedback. Also corrected terminology: PNG palette images do not have an alpha channel, just a parallel map of opacity values. So useAlpha-->useTransparency.
Index: src/lib/pngwrite.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/pngwrite.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -b -B -U 4 -r1.1 -r1.2
--- src/lib/pngwrite.c	5 Aug 2009 23:34:31 -0000	1.1
+++ src/lib/pngwrite.c	20 Aug 2009 21:34:44 -0000	1.2
@@ -6,11 +6,11 @@
 #ifdef USE_PNG
 
 #include "common.h"
 #include "memgfx.h"
-#ifdef SETJMP_H
-//.crap!;
-#endif
+#ifdef _SETJMP_H
+//.!$ simulate syntax error like the distro /usr/include/pngconf.h does when setjmp.h has already been included.  currently common.h includes it.
+#endif//def _SETJMP_H
 #include "png.h"
 
 static char const rcsid[] = "$Id$";
 
@@ -25,17 +25,17 @@
 {
 warn((char *)warningMessage);
 }
 
-boolean mgSaveToPng(FILE *png_file, struct memGfx *mg, boolean useAlpha)
+boolean mgSaveToPng(FILE *png_file, struct memGfx *mg, boolean useTransparency)
 /* Save PNG to an already open file.
- * If useAlpha, then the first color in memgfx's colormap/palette is
+ * If useTransparency, then the first color in memgfx's colormap/palette is
  * assumed to be the image background color, and pixels of that color
  * are made transparent. */
 /* Reference: http://libpng.org/pub/png/libpng-1.2.5-manual.html */
 {
 if (!png_file || !mg)
-    errAbort("mgSaveToPng: caller screwed up: png_file=[%lld], mg=[%lld]",
+    errAbort("mgSaveToPng: called with a NULL: png_file=[%lld], mg=[%lld]",
 	     (long long int)png_file, (long long int)mg);
 png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING,
 					  NULL, // don't need pointer to data for err/warn handlers
 					  pngAbort, pngWarn);
@@ -70,9 +70,9 @@
 	     PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
 png_set_PLTE(png, info,
 	     (png_color *)(mg->colorMap), // png_color is same as struct rgbColor!
 	     mg->colorsUsed);
-if (useAlpha)
+if (useTransparency)
     {
     // First palette color is assumed to be background/transparent, so
     // that's the only one we need in the parallel array opacities[].
     png_byte opacities[] = {0};
@@ -94,16 +94,16 @@
 png_destroy_write_struct(&png, &info);
 return TRUE;
 }
 
-void mgSavePng(struct memGfx *mg, char *filename, boolean useAlpha)
+void mgSavePng(struct memGfx *mg, char *filename, boolean useTransparency)
 /* Save memory bitmap to filename as a PNG.
- * If useAlpha, then the first color in memgfx's colormap/palette is
+ * If useTransparency, then the first color in memgfx's colormap/palette is
  * assumed to be the image background color, and pixels of that color
  * are made transparent. */
 {
 FILE *pngFile = mustOpen(filename, "wb");
-if (!mgSaveToPng(pngFile, mg, useAlpha))
+if (!mgSaveToPng(pngFile, mg, useTransparency))
     {
     remove(filename);
     errAbort("Couldn't save %s", filename);
     }