Dec 11, 2007

Callback function

/** $g++ callback.c -o callback ./callback Item 4 http://en.wikipedia.org/wiki/Callback_%28computer_science%29 */ #include /* LIBRARY CODE */ int traverseWith(int array[], size_t length, int (*callback)(int index, int item, void *param), void *param) { int exitCode = 0; for (int i = 0; i < length; i++) { exitCode = callback(i, array[i], param); if (exitCode != 0) { break; } } return exitCode; } /* APPLICATION CODE */ int search (int index, int item, void *param) { if (item > 5) { *(int *)param = index; return 1; } else { return 0; } } main() { /* (in another function) */ int index; int found; int array[] = {1, 2, 3, 4, 7, 10, 12, 15 }; int length = 6; found = traverseWith(array, length, &search, &index); if (found) { printf("Item %d\n", index); } else { printf("Not found\n"); } }

Dec 9, 2007

pngcrush; png optimizer

[地図ログ] [vuhung@aoclife pngcrush-1.6.4]$ ./pngcrush 14_1689_295.png 14_1689_295.png.crush | pngcrush 1.6.4 | Copyright (C) 1998-2002,2006 Glenn Randers-Pehrson | Copyright (C) 2005 Greg Roelofs | This is a free, open-source program. Permission is irrevocably | granted to everyone to use this version of pngcrush without | payment of any fee. | Executable name is pngcrush | It was built with libpng version 1.2.11beta4, and is | running with libpng version 1.2.11beta4 - June 7, 2006 (header) | Copyright (C) 1998-2004,2006 Glenn Randers-Pehrson, | Copyright (C) 1996, 1997 Andreas Dilger, | Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc., | and zlib version 1.2.3, Copyright (C) 1998-2002 (or later), | Jean-loup Gailly and Mark Adler. | It was compiled with gcc version 4.1.1 20070105 (Red Hat 4.1.1-52) and gas version 2.17.50.0.6-2.el5. Recompressing 14_1689_295.png Total length of data found in IDAT chunks = 24878 unknown chunk handling done. IDAT length with method 1 (fm 0 zl 4 zs 0) = 25646 IDAT length with method 2 (fm 1 zl 4 zs 0) = 29197 IDAT length with method 3 (fm 5 zl 4 zs 1) = 31397 IDAT length with method 4 (fm 0 zl 9 zs 1) = 25218 IDAT length with method 7 (fm 0 zl 9 zs 0) = 24212 Best pngcrush method = 7 (fm 0 zl 9 zs 0) for 14_1689_295.png.crush (2.68% IDAT reduction) (2.75% filesize reduction) CPU time used = 0.210 seconds (decoding 0.030, encoding 0.180, other 0.000 seconds) [vuhung@aoclife pngcrush-1.6.4]$ ls -l 14_1689_295.png* -rw-rw-r-- 1 vuhung vuhung 25565 12\u6708 9 03:20 14_1689_295.png -rw-rw-r-- 1 vuhung vuhung 24863 12\u6708 9 03:20 14_1689_295.png.crush [google] [vuhung@aoclife pngcrush-1.6.4]$ ./pngcrush mt_024.png mt_024.png.crush | pngcrush 1.6.4 | Copyright (C) 1998-2002,2006 Glenn Randers-Pehrson | Copyright (C) 2005 Greg Roelofs | This is a free, open-source program. Permission is irrevocably | granted to everyone to use this version of pngcrush without | payment of any fee. | Executable name is pngcrush | It was built with libpng version 1.2.11beta4, and is | running with libpng version 1.2.11beta4 - June 7, 2006 (header) | Copyright (C) 1998-2004,2006 Glenn Randers-Pehrson, | Copyright (C) 1996, 1997 Andreas Dilger, | Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc., | and zlib version 1.2.3, Copyright (C) 1998-2002 (or later), | Jean-loup Gailly and Mark Adler. | It was compiled with gcc version 4.1.1 20070105 (Red Hat 4.1.1-52) and gas version 2.17.50.0.6-2.el5. Recompressing mt_024.png Total length of data found in IDAT chunks = 16658 unknown chunk handling done. IDAT length with method 1 (fm 0 zl 4 zs 0) = 17939 IDAT length with method 2 (fm 1 zl 4 zs 0) = 20757 IDAT length with method 3 (fm 5 zl 4 zs 1) = 25521 IDAT length with method 4 (fm 0 zl 9 zs 1) = 17030 IDAT length with method 7 (fm 0 zl 9 zs 0) = 16686 Best pngcrush method = 0 (fm 5 zl 9 zs 1) for mt_024.png.crush (no IDAT change) (no filesize change) CPU time used = 0.220 seconds (decoding 0.020, encoding 0.180, other 0.020 seconds)