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 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_PIXAR_TEXTUREFORMAT
, "No texture" },
60 { TIFFTAG_PIXAR_WRAPMODES
, "No wrap" },
61 { TIFFTAG_COPYRIGHT
, "Copyright (c) 2004, Andrey Kiselev" }
63 #define NTAGS (sizeof (ascii_tags) / sizeof (ascii_tags[0]))
65 const char *ink_names
= "Red\0Green\0Blue";
66 const int ink_names_size
= 15;
69 main(int argc
, char **argv
)
73 unsigned char buf
[3] = { 0, 127, 255 };
76 /* Test whether we can write tags. */
77 tif
= TIFFOpen(filename
, "w");
79 fprintf (stderr
, "Can't create test TIFF file %s.\n", filename
);
83 if (!TIFFSetField(tif
, TIFFTAG_IMAGEWIDTH
, 1)) {
84 fprintf (stderr
, "Can't set ImageWidth tag.\n");
87 if (!TIFFSetField(tif
, TIFFTAG_IMAGELENGTH
, 1)) {
88 fprintf (stderr
, "Can't set ImageLength tag.\n");
91 if (!TIFFSetField(tif
, TIFFTAG_BITSPERSAMPLE
, 8)) {
92 fprintf (stderr
, "Can't set BitsPerSample tag.\n");
95 if (!TIFFSetField(tif
, TIFFTAG_SAMPLESPERPIXEL
, 3)) {
96 fprintf (stderr
, "Can't set SamplesPerPixel tag.\n");
99 if (!TIFFSetField(tif
, TIFFTAG_PLANARCONFIG
, PLANARCONFIG_CONTIG
)) {
100 fprintf (stderr
, "Can't set PlanarConfiguration tag.\n");
103 if (!TIFFSetField(tif
, TIFFTAG_PHOTOMETRIC
, PHOTOMETRIC_RGB
)) {
104 fprintf (stderr
, "Can't set PhotometricInterpretation tag.\n");
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
);
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
);
122 if (!TIFFSetField(tif
, TIFFTAG_INKNAMES
, ink_names_size
, ink_names
)) {
123 fprintf (stderr
, "Can't set tag %d.\n", TIFFTAG_INKNAMES
);
127 /* Write dummy pixel data. */
128 if (!TIFFWriteScanline(tif
, buf
, 0, 0) < 0) {
129 fprintf (stderr
, "Can't write image data.\n");
135 /* Ok, now test whether we can read written values. */
136 tif
= TIFFOpen(filename
, "r");
138 fprintf (stderr
, "Can't open test TIFF file %s.\n", filename
);
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
);
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
);
159 /* All tests passed; delete file and exit with success status. */
164 /* Something goes wrong; close file and return unsuccessful status. */
170 /* vim: set ts=8 sts=8 sw=8 noet: */