summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorpajoye <none@none>2007-12-31 00:58:38 +0000
committerpajoye <none@none>2007-12-31 00:58:38 +0000
commit346dea25e1ec92323e12d8c147afaf87e44868c1 (patch)
tree1b87620bcfda4846f4b480f83ae155dfefce77fa /examples
parent176627adf36a2070d216dc9921fdd3fea3f596e4 (diff)
downloadlibgd-346dea25e1ec92323e12d8c147afaf87e44868c1.tar.gz
- #58, Add new dithering alogirthm based on nthony Dekker's neuquant
algorithm using http://pngnq.sourceforge.net/ with alpha support
Diffstat (limited to 'examples')
-rw-r--r--examples/CMakeLists.txt1
-rw-r--r--examples/nnquant.c64
2 files changed, 65 insertions, 0 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 26e2de4..882af2a 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -6,6 +6,7 @@ SET(TESTS_FILES
tiffread
tgaread
crop
+ nnquant
)
FOREACH(test_name ${TESTS_FILES})
diff --git a/examples/nnquant.c b/examples/nnquant.c
new file mode 100644
index 0000000..6fcdc63
--- /dev/null
+++ b/examples/nnquant.c
@@ -0,0 +1,64 @@
+/* $Id$ */
+/*
+ * You can fetch a set of samples TIFF images here:
+ * ftp://ftp.remotesensing.org/pub/libtiff/
+ * (pics-x.y.z.tar.gz)
+ */
+
+#include "gd.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "gd_resize.h"
+
+void save_png(gdImagePtr im, const char *filename)
+{
+ FILE *fp;
+ fp = fopen(filename, "wb");
+ if (!fp) {
+ fprintf(stderr, "Can't save png image %s\n", filename);
+ return;
+ }
+ gdImagePng(im, fp);
+ fclose(fp);
+}
+
+int main()
+{
+ gdImagePtr im, im2;
+ FILE *fp;
+ char path[2048];
+ char dst[2048];
+
+// fp = fopen("/home/pierre/IMG_3801.jpg", "rb");
+ fp=fopen("resampledbug.jpeg", "rb");
+ //fp = fopen("/home/pierre/bug_new.png", "rb");
+ if (!fp) {
+ fprintf(stderr, "Can't load /home/pierre/IM3801.jpg\n");
+ return 1;
+ }
+
+ im = gdImageCreateFromJpeg(fp);
+ fclose(fp);
+ if (!im) {
+ fprintf(stderr, "Can't load TIFF image %s\n", path);
+ return 1;
+ }
+
+ im2 = gdImageNeuQuant(im, 256, 3);
+
+ if (im2) {
+ gdImageSaveAlpha(im2, 1);
+ save_png(im2, "a_nnquant.png");
+ gdImageDestroy(im2);
+ } else {
+ printf("neu quant failed.\n");
+ }
+
+ gdImageTrueColorToPalette(im, 1, 256);
+
+ gdImageSaveAlpha(im, 1);
+ save_png(im, "a_jquant_dither.png");
+
+ gdImageDestroy(im);
+ return 0;
+}