3 * Copyright (c) 2004, Andrey Kiselev <dron@ak4719.spb.edu>
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that (i) the above copyright notices and this permission notice appear in
8 * all copies of the software and related documentation, and (ii) the names of
9 * Sam Leffler and Silicon Graphics may not be used in any advertising or
10 * publicity relating to the software without the specific, prior written
11 * permission of Sam Leffler and Silicon Graphics.
13 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
17 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
28 * Module to test ASCII tags read/write functions.
31 #include "tif_config.h"
42 static const char filename
[] = "ascii_test.tiff";
48 { TIFFTAG_DOCUMENTNAME
, "Test TIFF image" },
49 { TIFFTAG_IMAGEDESCRIPTION
, "Temporary test image" },
50 { TIFFTAG_MAKE
, "This is not scanned image" },
51 { TIFFTAG_MODEL
, "No scanner" },
52 { TIFFTAG_PAGENAME
, "Test page" },
53 { TIFFTAG_SOFTWARE
, "Libtiff library" },
54 { TIFFTAG_DATETIME
, "2004:09:10 16:09:00" },
55 { TIFFTAG_ARTIST
, "Andrey V. Kiselev" },
56 { TIFFTAG_HOSTCOMPUTER
, "Debian GNU/Linux (Sarge)" },
57 { TIFFTAG_TARGETPRINTER
, "No printer" },
58 { TIFFTAG_COPYRIGHT
, "Copyright (c) 2004, Andrey Kiselev" },
59 { TIFFTAG_FAXSUBADDRESS
, "Fax subaddress" },
61 { TIFFTAG_UNIQUECAMERAMODEL
, "No camera" },
62 { TIFFTAG_CAMERASERIALNUMBER
, "1234567890" }
64 #define NTAGS (sizeof (ascii_tags) / sizeof (ascii_tags[0]))
66 static const char ink_names
[] = "Red\0Green\0Blue";
67 const int ink_names_size
= 15;
74 unsigned char buf
[] = { 0, 127, 255 };
77 /* Test whether we can write tags. */
78 tif
= TIFFOpen(filename
, "w");
80 fprintf (stderr
, "Can't create test TIFF file %s.\n", filename
);
84 if (!TIFFSetField(tif
, TIFFTAG_IMAGEWIDTH
, 1)) {
85 fprintf (stderr
, "Can't set ImageWidth tag.\n");
88 if (!TIFFSetField(tif
, TIFFTAG_IMAGELENGTH
, 1)) {
89 fprintf (stderr
, "Can't set ImageLength tag.\n");
92 if (!TIFFSetField(tif
, TIFFTAG_BITSPERSAMPLE
, 8)) {
93 fprintf (stderr
, "Can't set BitsPerSample tag.\n");
96 if (!TIFFSetField(tif
, TIFFTAG_SAMPLESPERPIXEL
, sizeof(buf
))) {
97 fprintf (stderr
, "Can't set SamplesPerPixel tag.\n");
100 if (!TIFFSetField(tif
, TIFFTAG_PLANARCONFIG
, PLANARCONFIG_CONTIG
)) {
101 fprintf (stderr
, "Can't set PlanarConfiguration tag.\n");
104 if (!TIFFSetField(tif
, TIFFTAG_PHOTOMETRIC
, PHOTOMETRIC_RGB
)) {
105 fprintf (stderr
, "Can't set PhotometricInterpretation tag.\n");
109 for (i
= 0; i
< NTAGS
; i
++) {
110 if (!TIFFSetField(tif
, ascii_tags
[i
].tag
,
111 ascii_tags
[i
].value
)) {
112 fprintf(stderr
, "Can't set tag %lu.\n",
113 (unsigned long)ascii_tags
[i
].tag
);
118 /* InkNames tag has special form, so we handle it separately. */
119 if (!TIFFSetField(tif
, TIFFTAG_NUMBEROFINKS
, 3)) {
120 fprintf (stderr
, "Can't set tag %d (NUMBEROFINKS).\n",
121 TIFFTAG_NUMBEROFINKS
);
124 if (!TIFFSetField(tif
, TIFFTAG_INKNAMES
, ink_names_size
, ink_names
)) {
125 fprintf (stderr
, "Can't set tag %d (INKNAMES).\n",
130 /* Write dummy pixel data. */
131 if (!TIFFWriteScanline(tif
, buf
, 0, 0) < 0) {
132 fprintf (stderr
, "Can't write image data.\n");
138 /* Ok, now test whether we can read written values. */
139 tif
= TIFFOpen(filename
, "r");
141 fprintf (stderr
, "Can't open test TIFF file %s.\n", filename
);
145 for (i
= 0; i
< NTAGS
; i
++) {
146 if (!TIFFGetField(tif
, ascii_tags
[i
].tag
, &value
)
147 || strcmp(value
, ascii_tags
[i
].value
)) {
148 fprintf(stderr
, "Can't get tag %lu.\n",
149 (unsigned long)ascii_tags
[i
].tag
);
154 if (!TIFFGetField(tif
, TIFFTAG_INKNAMES
, &value
)
155 || memcmp(value
, ink_names
, ink_names_size
)) {
156 fprintf (stderr
, "Can't get tag %d (INKNAMES).\n",
163 /* All tests passed; delete file and exit with success status. */
169 * Something goes wrong; close file and return unsuccessful status.
170 * Do not remove the file for further manual investigation.
176 /* vim: set ts=8 sts=8 sw=8 noet: */