From 41d830e0c110e378fc4473948390674f4ea65305 Mon Sep 17 00:00:00 2001 From: pajoye Date: Wed, 27 Feb 2008 23:25:00 +0000 Subject: - #129: - revert horizontal/vertical, was too confusing, it acts now like any application (ie. gimp/ps) instead of talking about h/v axis - optimize both - add simple example --- examples/CMakeLists.txt | 15 ++++++++-- examples/flip.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 examples/flip.c (limited to 'examples') diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 368046f..0388d4c 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -3,10 +3,19 @@ include_directories (BEFORE ${GD_SOURCE_DIR}/src "${CMAKE_BINARY_DIR}") SET(TESTS_FILES - tgaread + tiffread + resize + copyrotated + ellipseaa + ellipse + arc + ellipsearc + flip crop - nnquant - gif + ellfullaa + tgaread + nnquant + gif ) if (WIN32) diff --git a/examples/flip.c b/examples/flip.c new file mode 100644 index 0000000..99f2188 --- /dev/null +++ b/examples/flip.c @@ -0,0 +1,76 @@ +/* $Id$ */ +#include "gd.h" +#include +#include +gdImagePtr loadImage(const char *name) +{ + FILE *fp; + gdImagePtr im; + + fp = fopen(name, "rb"); + if (!fp) { + fprintf(stderr, "Can't open jpeg file\n"); + gdImageDestroy(im); + return NULL; + } + + im = gdImageCreateFromJpeg(fp); + fclose(fp); + return im; +} + +int savePngImage(gdImagePtr im, const char *name) +{ + FILE *fp; + fp = fopen(name, "wb"); + if (!fp) { + fprintf(stderr, "Can't save png image fromtiff.png\n"); + return 0; + } + gdImagePng(im, fp); + fclose(fp); + return 1; +} + +int main(int argc, char **arg) +{ + gdImagePtr im; + int returncode = 0; + + if (argc < 2) { + fprintf(stderr, "Usage: flip [filename.png]\n"); + return 1; + } + + im = loadImage(arg[1]); + if (!im) goto error; + gdImageFlipHorizontal(im); + if (!savePngImage(im, "flip_horizontal.png")) { + goto error; + } + gdImageDestroy(im); + + im = loadImage(arg[1]); + if (!im) goto error; + gdImageFlipVertical(im); + if (!savePngImage(im, "flip_vertical.png")) { + goto error; + } + gdImageDestroy(im); + + im = loadImage(arg[1]); + if (!im) goto error; + gdImageFlipBoth(im); + if (!savePngImage(im, "flip_both.png")) { + goto error; + } + gdImageDestroy(im); + + goto done; + +error: + returncode = 1; + +done: + return returncode; +} -- cgit v1.2.1