diff options
author | Matt Bosworth <mbosworth@neuropace.com> | 2016-01-19 15:42:31 -0800 |
---|---|---|
committer | Matt Bosworth <mbosworth@neuropace.com> | 2016-01-22 12:52:50 -0800 |
commit | 4e53ed79929e4f0d9654ccd8c557fd38cda9d846 (patch) | |
tree | c772f4bb34080b7c6633f8419e15b35317cab568 /tests/tiff | |
parent | 6913dd3cd2a7c2914ad9622419f9343bfe956135 (diff) | |
download | libgd-4e53ed79929e4f0d9654ccd8c557fd38cda9d846.tar.gz |
Added support for reading and writing TIFFTAG_XRESOLUTION and
TIFFTAG_YRESOLUTION. Includes a unit test.
Diffstat (limited to 'tests/tiff')
-rw-r--r-- | tests/tiff/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/tiff/tiff_dpi.c | 79 |
2 files changed, 80 insertions, 0 deletions
diff --git a/tests/tiff/CMakeLists.txt b/tests/tiff/CMakeLists.txt index da49800..aa8b8b2 100644 --- a/tests/tiff/CMakeLists.txt +++ b/tests/tiff/CMakeLists.txt @@ -2,6 +2,7 @@ SET(TESTS_FILES tiff_im2im tiff_null + tiff_dpi ) FOREACH(test_name ${TESTS_FILES}) diff --git a/tests/tiff/tiff_dpi.c b/tests/tiff/tiff_dpi.c new file mode 100644 index 0000000..3d4a21a --- /dev/null +++ b/tests/tiff/tiff_dpi.c @@ -0,0 +1,79 @@ +/* + * Test that reading and writing image resolution values to/from TIFF files + * works correctly. Set the image resolution, write the file, read the file + * back and test that the image resolution comes back correct. + */ +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr src, dst; + int r, res_x, res_y; + void *p; + int size = 0; + int status = 0; + + src = gdImageCreate(100, 100); + if (src == NULL) { + printf("could not create src\n"); + return 1; + } + r = gdImageColorAllocate(src, 0xFF, 0, 0); + gdImageFilledRectangle(src, 0, 0, 99, 99, r); + + // gd default DPI is 96; libtiff default is 72. + // Use something else so we know the value has been + // written / read correctly. + res_x = 100; + res_y = 200; + src->res_x = res_x; + src->res_y = res_y; + +#define OUTPUT_TIFF(name) do { \ + FILE *fp; \ + \ + fp = fopen("tiff_dpi_" #name ".tiff", "wb"); \ + if (fp) { \ + gdImageTiff(name, fp); \ + fclose(fp); \ + } \ + } while (0) + + OUTPUT_TIFF(src); + p = gdImageTiffPtr(src, &size); + if (p == NULL) { + status = 1; + printf("p is null\n"); + goto door0; + } + if (size <= 0) { + status = 1; + printf("size is non-positive\n"); + goto door1; + } + + dst = gdImageCreateFromTiffPtr(size, p); + if (dst == NULL) { + status = 1; + printf("could not create dst\n"); + goto door1; + } + + if (dst->res_x != res_x) { + status = 1; + printf("mismatch in res_x (got %d, expected %d)", dst->res_x, res_x); + } + + if (dst->res_y != res_y) { + status = 1; + printf("mismatch in res_y (got %d, expected %d)", dst->res_y, res_y); + } + + gdImageDestroy(dst); +door1: + gdFree(p); +door0: + gdImageDestroy(src); + return status; +} |