summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorpajoye <none@none>2007-10-04 19:47:41 +0000
committerpajoye <none@none>2007-10-04 19:47:41 +0000
commitcddcba1908bdd1edeaf0842949df60198f861b0d (patch)
tree55cb35313546e97ad146d2741ae2cc626adc2af9 /examples
parent59625e2e8c3bc2b51d8991572aaa807defa75945 (diff)
downloadlibgd-cddcba1908bdd1edeaf0842949df60198f861b0d.tar.gz
- add examples directory
- add tiff usage example
Diffstat (limited to 'examples')
-rw-r--r--examples/CMakeLists.txt14
-rw-r--r--examples/tiffread.c38
2 files changed, 52 insertions, 0 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
new file mode 100644
index 0000000..842a6c4
--- /dev/null
+++ b/examples/CMakeLists.txt
@@ -0,0 +1,14 @@
+
+message("inc: ${GD_INCLUDE_DIR}")
+include_directories (BEFORE ${GD_SOURCE_DIR}/src "${CMAKE_BINARY_DIR}")
+
+
+SET(TESTS_FILES
+ tiffread
+)
+
+FOREACH(test_name ${TESTS_FILES})
+ add_executable(${test_name} "${test_name}.c")
+ target_link_libraries (${test_name} ${GD_LIB})
+ ADD_TEST(${test_name} ${EXECUTABLE_OUTPUT_PATH}/${test_name})
+ENDFOREACH(test_name)
diff --git a/examples/tiffread.c b/examples/tiffread.c
new file mode 100644
index 0000000..c6f4c38
--- /dev/null
+++ b/examples/tiffread.c
@@ -0,0 +1,38 @@
+/* $Id$ */
+#include <gd.h>
+#include <stdio.h>
+#include <stdlib.h>
+int main()
+{
+ gdImagePtr im;
+ FILE *fp;
+ char path[2048];
+
+// sprintf(path, "/home/pierre/projects/gd/patches/tiff/images/cramps-tile.tif");
+ sprintf(path, "/home/pierre/projects/gd/patches/tiff/images/ycbcr-cat.tif");
+
+ printf("opening %s\n", path);
+ fp = fopen(path, "rb");
+ if (!fp) {
+ printf("failed, cannot open file\n");
+ return 1;
+ }
+
+ im = gdImageCreateFromTiff(fp);
+ fclose(fp);
+ if (!im) {
+ fprintf(stderr, "Can't load TIFF image %s\n", path);
+ return 1;
+ }
+
+ fp = fopen("fromtiff.png", "wb");
+ if (!fp) {
+ fprintf(stderr, "Can't save png image fromtiff.png\n");
+ gdImageDestroy(im);
+ return 1;
+ }
+
+ gdImagePng(im, fp);
+ fclose(fp);
+ gdImageDestroy(im);
+}