]> git.saurik.com Git - wxWidgets.git/blob - src/tiff/test/ascii_tag.c
Load the wxWidgets homepage by default in the wxWebView sample
[wxWidgets.git] / src / tiff / test / ascii_tag.c
1 /* $Id$ */
2
3 /*
4 * Copyright (c) 2004, Andrey Kiselev <dron@ak4719.spb.edu>
5 *
6 * Permission to use, copy, modify, distribute, and sell this software and
7 * its documentation for any purpose is hereby granted without fee, provided
8 * that (i) the above copyright notices and this permission notice appear in
9 * all copies of the software and related documentation, and (ii) the names of
10 * Sam Leffler and Silicon Graphics may not be used in any advertising or
11 * publicity relating to the software without the specific, prior written
12 * permission of Sam Leffler and Silicon Graphics.
13 *
14 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
16 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
17 *
18 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
19 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
20 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
21 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
22 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
23 * OF THIS SOFTWARE.
24 */
25
26 /*
27 * TIFF Library
28 *
29 * Module to test ASCII tags read/write functions.
30 */
31
32 #include "tif_config.h"
33
34 #include <stdio.h>
35 #include <string.h>
36
37 #ifdef HAVE_UNISTD_H
38 # include <unistd.h>
39 #endif
40
41 #include "tiffio.h"
42
43 const char *filename = "ascii_test.tiff";
44
45 static struct Tags {
46 ttag_t tag;
47 const char *value;
48 } ascii_tags[] = {
49 { TIFFTAG_DOCUMENTNAME, "Test TIFF image" },
50 { TIFFTAG_IMAGEDESCRIPTION, "Temporary test image" },
51 { TIFFTAG_MAKE, "This is not scanned image" },
52 { TIFFTAG_MODEL, "No scanner" },
53 { TIFFTAG_PAGENAME, "Test page" },
54 { TIFFTAG_SOFTWARE, "Libtiff library" },
55 { TIFFTAG_DATETIME, "2004:09:10 16:09:00" },
56 { TIFFTAG_ARTIST, "Andrey V. Kiselev" },
57 { TIFFTAG_HOSTCOMPUTER, "Debian GNU/Linux (Sarge)" },
58 { TIFFTAG_TARGETPRINTER, "No printer" },
59 { TIFFTAG_PIXAR_TEXTUREFORMAT, "No texture" },
60 { TIFFTAG_PIXAR_WRAPMODES, "No wrap" },
61 { TIFFTAG_COPYRIGHT, "Copyright (c) 2004, Andrey Kiselev" }
62 };
63 #define NTAGS (sizeof (ascii_tags) / sizeof (ascii_tags[0]))
64
65 const char *ink_names = "Red\0Green\0Blue";
66 const int ink_names_size = 15;
67
68 int
69 main(int argc, char **argv)
70 {
71 TIFF *tif;
72 int i;
73 unsigned char buf[3] = { 0, 127, 255 };
74 char *value;
75
76 /* Test whether we can write tags. */
77 tif = TIFFOpen(filename, "w");
78 if (!tif) {
79 fprintf (stderr, "Can't create test TIFF file %s.\n", filename);
80 return 1;
81 }
82
83 if (!TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, 1)) {
84 fprintf (stderr, "Can't set ImageWidth tag.\n");
85 goto failure;
86 }
87 if (!TIFFSetField(tif, TIFFTAG_IMAGELENGTH, 1)) {
88 fprintf (stderr, "Can't set ImageLength tag.\n");
89 goto failure;
90 }
91 if (!TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8)) {
92 fprintf (stderr, "Can't set BitsPerSample tag.\n");
93 goto failure;
94 }
95 if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3)) {
96 fprintf (stderr, "Can't set SamplesPerPixel tag.\n");
97 goto failure;
98 }
99 if (!TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG)) {
100 fprintf (stderr, "Can't set PlanarConfiguration tag.\n");
101 goto failure;
102 }
103 if (!TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB)) {
104 fprintf (stderr, "Can't set PhotometricInterpretation tag.\n");
105 goto failure;
106 }
107
108 for (i = 0; i < NTAGS; i++) {
109 if (!TIFFSetField(tif, ascii_tags[i].tag,
110 ascii_tags[i].value)) {
111 fprintf(stderr, "Can't set tag %d.\n",
112 (int)ascii_tags[i].tag);
113 goto failure;
114 }
115 }
116
117 /* InkNames tag has special form, so we handle it separately. */
118 if (!TIFFSetField(tif, TIFFTAG_NUMBEROFINKS, 3)) {
119 fprintf (stderr, "Can't set tag %d.\n", TIFFTAG_NUMBEROFINKS);
120 goto failure;
121 }
122 if (!TIFFSetField(tif, TIFFTAG_INKNAMES, ink_names_size, ink_names)) {
123 fprintf (stderr, "Can't set tag %d.\n", TIFFTAG_INKNAMES);
124 goto failure;
125 }
126
127 /* Write dummy pixel data. */
128 if (!TIFFWriteScanline(tif, buf, 0, 0) < 0) {
129 fprintf (stderr, "Can't write image data.\n");
130 goto failure;
131 }
132
133 TIFFClose(tif);
134
135 /* Ok, now test whether we can read written values. */
136 tif = TIFFOpen(filename, "r");
137 if (!tif) {
138 fprintf (stderr, "Can't open test TIFF file %s.\n", filename);
139 return 1;
140 }
141
142 for (i = 0; i < NTAGS; i++) {
143 if (!TIFFGetField(tif, ascii_tags[i].tag, &value)
144 || strcmp(value, ascii_tags[i].value)) {
145 fprintf(stderr, "Can't get tag %d.\n",
146 (int)ascii_tags[i].tag);
147 goto failure;
148 }
149 }
150
151 if (!TIFFGetField(tif, TIFFTAG_INKNAMES, &value)
152 || memcmp(value, ink_names, ink_names_size)) {
153 fprintf (stderr, "Can't get tag %d.\n", TIFFTAG_INKNAMES);
154 goto failure;
155 }
156
157 TIFFClose(tif);
158
159 /* All tests passed; delete file and exit with success status. */
160 unlink(filename);
161 return 0;
162
163 failure:
164 /* Something goes wrong; close file and return unsuccessful status. */
165 TIFFClose(tif);
166 unlink(filename);
167 return 1;
168 }
169
170 /* vim: set ts=8 sts=8 sw=8 noet: */