4 * Copyright (c) 2004, Andrey Kiselev <dron@ak4719.spb.edu>
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.
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.
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
29 * Module to test ASCII tags read/write functions.
32 #include "tif_config.h"
43 static const char filename
[] = "ascii_test.tiff";
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_COPYRIGHT
, "Copyright (c) 2004, Andrey Kiselev" },
60 { TIFFTAG_FAXSUBADDRESS
, "Fax subaddress" },
62 { TIFFTAG_UNIQUECAMERAMODEL
, "No camera" },
63 { TIFFTAG_CAMERASERIALNUMBER
, "1234567890" }
65 #define NTAGS (sizeof (ascii_tags) / sizeof (ascii_tags[0]))
67 static const char ink_names
[] = "Red\0Green\0Blue";
68 const int ink_names_size
= 15;
75 unsigned char buf
[] = { 0, 127, 255 };
78 /* Test whether we can write tags. */
79 tif
= TIFFOpen(filename
, "w");
81 fprintf (stderr
, "Can't create test TIFF file %s.\n", filename
);
85 if (!TIFFSetField(tif
, TIFFTAG_IMAGEWIDTH
, 1)) {
86 fprintf (stderr
, "Can't set ImageWidth tag.\n");
89 if (!TIFFSetField(tif
, TIFFTAG_IMAGELENGTH
, 1)) {
90 fprintf (stderr
, "Can't set ImageLength tag.\n");
93 if (!TIFFSetField(tif
, TIFFTAG_BITSPERSAMPLE
, 8)) {
94 fprintf (stderr
, "Can't set BitsPerSample tag.\n");
97 if (!TIFFSetField(tif
, TIFFTAG_SAMPLESPERPIXEL
, sizeof(buf
))) {
98 fprintf (stderr
, "Can't set SamplesPerPixel tag.\n");
101 if (!TIFFSetField(tif
, TIFFTAG_PLANARCONFIG
, PLANARCONFIG_CONTIG
)) {
102 fprintf (stderr
, "Can't set PlanarConfiguration tag.\n");
105 if (!TIFFSetField(tif
, TIFFTAG_PHOTOMETRIC
, PHOTOMETRIC_RGB
)) {
106 fprintf (stderr
, "Can't set PhotometricInterpretation tag.\n");
110 for (i
= 0; i
< NTAGS
; i
++) {
111 if (!TIFFSetField(tif
, ascii_tags
[i
].tag
,
112 ascii_tags
[i
].value
)) {
113 fprintf(stderr
, "Can't set tag %lu.\n",
114 (unsigned long)ascii_tags
[i
].tag
);
119 /* InkNames tag has special form, so we handle it separately. */
120 if (!TIFFSetField(tif
, TIFFTAG_NUMBEROFINKS
, 3)) {
121 fprintf (stderr
, "Can't set tag %d (NUMBEROFINKS).\n",
122 TIFFTAG_NUMBEROFINKS
);
125 if (!TIFFSetField(tif
, TIFFTAG_INKNAMES
, ink_names_size
, ink_names
)) {
126 fprintf (stderr
, "Can't set tag %d (INKNAMES).\n",
131 /* Write dummy pixel data. */
132 if (!TIFFWriteScanline(tif
, buf
, 0, 0) < 0) {
133 fprintf (stderr
, "Can't write image data.\n");
139 /* Ok, now test whether we can read written values. */
140 tif
= TIFFOpen(filename
, "r");
142 fprintf (stderr
, "Can't open test TIFF file %s.\n", filename
);
146 for (i
= 0; i
< NTAGS
; i
++) {
147 if (!TIFFGetField(tif
, ascii_tags
[i
].tag
, &value
)
148 || strcmp(value
, ascii_tags
[i
].value
)) {
149 fprintf(stderr
, "Can't get tag %lu.\n",
150 (unsigned long)ascii_tags
[i
].tag
);
155 if (!TIFFGetField(tif
, TIFFTAG_INKNAMES
, &value
)
156 || memcmp(value
, ink_names
, ink_names_size
)) {
157 fprintf (stderr
, "Can't get tag %d (INKNAMES).\n",
164 /* All tests passed; delete file and exit with success status. */
170 * Something goes wrong; close file and return unsuccessful status.
171 * Do not remove the file for further manual investigation.
177 /* vim: set ts=8 sts=8 sw=8 noet: */