src/hg/oneShot/timeGifPng/timeGifPng.c 1.2
1.2 2010/05/04 23:56:01 braney
some changes
Index: src/hg/oneShot/timeGifPng/timeGifPng.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/oneShot/timeGifPng/timeGifPng.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -b -B -U 4 -r1.1 -r1.2
--- src/hg/oneShot/timeGifPng/timeGifPng.c 3 May 2010 17:22:11 -0000 1.1
+++ src/hg/oneShot/timeGifPng/timeGifPng.c 4 May 2010 23:56:01 -0000 1.2
@@ -16,9 +16,9 @@
{
errAbort(
"timeGifPng - program to do some GIF and PNG timing\n"
"usage:\n"
- " timeGifPng file.gif\n"
+ " timeGifPng nTimes file.gif [file.gif ..]\n"
"options:\n"
" -xxx=XXX\n"
);
}
@@ -53,9 +53,9 @@
{
warn("%s", (char *)warningMessage);
}
-boolean saveToPng(FILE *f, struct rgbaGfx *rg)
+boolean saveToPng(FILE *f, struct rgbaGfx *rg, int level)
/* Save RGBA PNG to an already open file.
* Reference: http://libpng.org/pub/png/libpng-1.2.5-manual.html */
{
png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING,
@@ -89,8 +90,9 @@
png_init_io(png, f);
png_set_IHDR(png, info, rg->width, rg->height, 8, // 8=bit_depth
PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
+png_set_compression_level(png, level);
// Write header/params, write pixels, close and clean up.
// PNG wants a 2D array of pointers to byte offsets into palette/colorMap.
// rg has a 1D array of byte offsets. Make row pointers for PNG:
@@ -104,12 +106,12 @@
png_destroy_write_struct(&png, &info);
return TRUE;
}
-void savePng(char *filename, struct rgbaGfx *rg)
+void savePng(char *filename, struct rgbaGfx *rg, int level)
{
FILE *pngFile = mustOpen(filename, "wb");
-if (!saveToPng(pngFile, rg))
+if (!saveToPng(pngFile, rg, level))
{
remove(filename);
errAbort("Couldn't save %s", filename);
}
@@ -160,9 +162,9 @@
return rg;
}
-void timeGifPng(char *gifFile)
+void timeGifPng( int count, int fileNo, char *gifFile)
/* timeGifPng - program to do some GIF and PNG timing. */
{
/* first read in GIF to memory */
verboseTimeInit();
@@ -173,31 +175,38 @@
struct rgbaGfx *rg = convertMemToRgba(mem);
lastTime = clock1000();
-savePng("test.png", rg);
-pngTime = clock1000() - lastTime;
-
-lastTime = clock1000();
mgSaveGif(mem, "test.gif", FALSE);
gifTime = clock1000() - lastTime;
int fd = open("test.gif", O_RDONLY);
long gifSize = lseek(fd, 0L, 2);
close(fd);
-fd = open("test.png", O_RDONLY);
-long pngSize = lseek(fd, 0L, 2);
-close(fd);
+printf("%d %d gif %ld %ld\n",count, fileNo, gifTime, gifSize);
+int ii;
+for(ii=0; ii < 10; ii++)
+ {
+ lastTime = clock1000();
+ savePng("test.png", rg, ii);
+ pngTime = clock1000() - lastTime;
+
+ fd = open("test.png", O_RDONLY);
+ long pngSize = lseek(fd, 0L, 2);
+ close(fd);
+ printf("%d %d png%d %ld %ld\n",count, fileNo, ii, pngTime, pngSize);
+ }
-printf("%ld %ld %ld %ld\n", gifSize, pngSize, gifTime, pngTime);
}
int main(int argc, char *argv[])
/* Process command line. */
{
optionInit(&argc, argv, options);
-int ii;
-for(ii=1; ii < argc; ii++)
- timeGifPng(argv[ii]);
+int ii,jj;
+int numTimes = atoi(argv[1]);
+for(jj=0; jj < numTimes; jj++)
+ for(ii=2; ii < argc; ii++)
+ timeGifPng(jj, ii -2 , argv[ii]);
return 0;
}