Blame test/short_tag.c

Packit 994f1a
/* $Id: short_tag.c,v 1.6.2.2 2010-06-10 22:52:45 bfriesen Exp $ */
Packit 994f1a
Packit 994f1a
/*
Packit 994f1a
 * Copyright (c) 2004, Andrey Kiselev  <dron@ak4719.spb.edu>
Packit 994f1a
 *
Packit 994f1a
 * Permission to use, copy, modify, distribute, and sell this software and 
Packit 994f1a
 * its documentation for any purpose is hereby granted without fee, provided
Packit 994f1a
 * that (i) the above copyright notices and this permission notice appear in
Packit 994f1a
 * all copies of the software and related documentation, and (ii) the names of
Packit 994f1a
 * Sam Leffler and Silicon Graphics may not be used in any advertising or
Packit 994f1a
 * publicity relating to the software without the specific, prior written
Packit 994f1a
 * permission of Sam Leffler and Silicon Graphics.
Packit 994f1a
 * 
Packit 994f1a
 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
Packit 994f1a
 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
Packit 994f1a
 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
Packit 994f1a
 * 
Packit 994f1a
 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
Packit 994f1a
 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
Packit 994f1a
 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
Packit 994f1a
 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
Packit 994f1a
 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
Packit 994f1a
 * OF THIS SOFTWARE.
Packit 994f1a
 */
Packit 994f1a
Packit 994f1a
/*
Packit 994f1a
 * TIFF Library
Packit 994f1a
 *
Packit 994f1a
 * Module to test SHORT tags read/write functions.
Packit 994f1a
 */
Packit 994f1a
Packit 994f1a
#include "tif_config.h"
Packit 994f1a
Packit 994f1a
#include <stdio.h>
Packit 994f1a
Packit 994f1a
#ifdef HAVE_UNISTD_H 
Packit 994f1a
# include <unistd.h> 
Packit 994f1a
#endif 
Packit 994f1a
Packit 994f1a
#include "tiffio.h"
Packit 994f1a
Packit 994f1a
extern int CheckLongField(TIFF *, ttag_t, uint32);
Packit 994f1a
extern int CheckShortField(TIFF *, ttag_t, uint16);
Packit 994f1a
Packit 994f1a
const char	*filename = "short_test.tiff";
Packit 994f1a
Packit 994f1a
#define	SPP	3		/* Samples per pixel */
Packit 994f1a
const uint16	width = 1;
Packit 994f1a
const uint16	length = 1;
Packit 994f1a
const uint16	bps = 8;
Packit 994f1a
const uint16	photometric = PHOTOMETRIC_RGB;
Packit 994f1a
const uint16	rows_per_strip = 1;
Packit 994f1a
const uint16	planarconfig = PLANARCONFIG_CONTIG;
Packit 994f1a
Packit 994f1a
static struct SingleTags {
Packit 994f1a
	ttag_t		tag;
Packit 994f1a
	uint16		value;
Packit 994f1a
} short_single_tags[] = {
Packit 994f1a
	{ TIFFTAG_COMPRESSION, COMPRESSION_NONE },
Packit 994f1a
	{ TIFFTAG_FILLORDER, FILLORDER_MSB2LSB },
Packit 994f1a
	{ TIFFTAG_ORIENTATION, ORIENTATION_BOTRIGHT },
Packit 994f1a
	{ TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH },
Packit 994f1a
	{ TIFFTAG_INKSET, INKSET_MULTIINK },
Packit 994f1a
	{ TIFFTAG_MINSAMPLEVALUE, 23 },
Packit 994f1a
	{ TIFFTAG_MAXSAMPLEVALUE, 241 },
Packit 994f1a
	{ TIFFTAG_NUMBEROFINKS, SPP },
Packit 994f1a
	{ TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT }
Packit 994f1a
	/*{ TIFFTAG_IMAGEDEPTH, 1 },
Packit 994f1a
	{ TIFFTAG_TILEDEPTH, 1 }*/
Packit 994f1a
};
Packit 994f1a
#define NSINGLETAGS   (sizeof(short_single_tags) / sizeof(short_single_tags[0]))
Packit 994f1a
Packit 994f1a
int
Packit 994f1a
main(int argc, char **argv)
Packit 994f1a
{
Packit 994f1a
	TIFF		*tif;
Packit 994f1a
	int		i;
Packit 994f1a
	unsigned char	buf[3] = { 0, 127, 255 };
Packit 994f1a
Packit 994f1a
	/* Test whether we can write tags. */
Packit 994f1a
	tif = TIFFOpen(filename, "w");
Packit 994f1a
	if (!tif) {
Packit 994f1a
		fprintf (stderr, "Can't create test TIFF file %s.\n", filename);
Packit 994f1a
		return 1;
Packit 994f1a
	}
Packit 994f1a
Packit 994f1a
	if (!TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width)) {
Packit 994f1a
		fprintf (stderr, "Can't set ImageWidth tag.\n");
Packit 994f1a
		goto failure;
Packit 994f1a
	}
Packit 994f1a
	if (!TIFFSetField(tif, TIFFTAG_IMAGELENGTH, length)) {
Packit 994f1a
		fprintf (stderr, "Can't set ImageLength tag.\n");
Packit 994f1a
		goto failure;
Packit 994f1a
	}
Packit 994f1a
	if (!TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps)) {
Packit 994f1a
		fprintf (stderr, "Can't set BitsPerSample tag.\n");
Packit 994f1a
		goto failure;
Packit 994f1a
	}
Packit 994f1a
	if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, SPP)) {
Packit 994f1a
		fprintf (stderr, "Can't set SamplesPerPixel tag.\n");
Packit 994f1a
		goto failure;
Packit 994f1a
	}
Packit 994f1a
	if (!TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip)) {
Packit 994f1a
		fprintf (stderr, "Can't set SamplesPerPixel tag.\n");
Packit 994f1a
		goto failure;
Packit 994f1a
	}
Packit 994f1a
	if (!TIFFSetField(tif, TIFFTAG_PLANARCONFIG, planarconfig)) {
Packit 994f1a
		fprintf (stderr, "Can't set PlanarConfiguration tag.\n");
Packit 994f1a
		goto failure;
Packit 994f1a
	}
Packit 994f1a
	if (!TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, photometric)) {
Packit 994f1a
		fprintf (stderr, "Can't set PhotometricInterpretation tag.\n");
Packit 994f1a
		goto failure;
Packit 994f1a
	}
Packit 994f1a
Packit 994f1a
	for (i = 0; i < NSINGLETAGS; i++) {
Packit 994f1a
		if (!TIFFSetField(tif, short_single_tags[i].tag,
Packit 994f1a
				  short_single_tags[i].value)) {
Packit 994f1a
			fprintf(stderr, "Can't set tag %d.\n",
Packit 994f1a
				(int)short_single_tags[i].tag);
Packit 994f1a
			goto failure;
Packit 994f1a
		}
Packit 994f1a
	}
Packit 994f1a
Packit 994f1a
	/* Write dummy pixel data. */
Packit Service 55a0b9
	if (!TIFFWriteScanline(tif, buf, 0, 0) < 0) {
Packit 994f1a
		fprintf (stderr, "Can't write image data.\n");
Packit 994f1a
		goto failure;
Packit 994f1a
	}
Packit 994f1a
Packit 994f1a
	TIFFClose(tif);
Packit 994f1a
	
Packit 994f1a
	/* Ok, now test whether we can read written values. */
Packit 994f1a
	tif = TIFFOpen(filename, "r");
Packit 994f1a
	if (!tif) {
Packit 994f1a
		fprintf (stderr, "Can't open test TIFF file %s.\n", filename);
Packit 994f1a
		return 1;
Packit 994f1a
	}
Packit 994f1a
	
Packit 994f1a
	if (CheckLongField(tif, TIFFTAG_IMAGEWIDTH, width) < 0)
Packit 994f1a
		goto failure;
Packit 994f1a
Packit 994f1a
	if (CheckLongField(tif, TIFFTAG_IMAGELENGTH, length) < 0)
Packit 994f1a
		goto failure;
Packit 994f1a
Packit 994f1a
	if (CheckShortField(tif, TIFFTAG_BITSPERSAMPLE, bps) < 0)
Packit 994f1a
		goto failure;
Packit 994f1a
Packit 994f1a
	if (CheckShortField(tif, TIFFTAG_PHOTOMETRIC, photometric) < 0)
Packit 994f1a
		goto failure;
Packit 994f1a
Packit 994f1a
	if (CheckShortField(tif, TIFFTAG_SAMPLESPERPIXEL, SPP) < 0)
Packit 994f1a
		goto failure;
Packit 994f1a
Packit 994f1a
	if (CheckLongField(tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip) < 0)
Packit 994f1a
		goto failure;
Packit 994f1a
Packit 994f1a
	if (CheckShortField(tif, TIFFTAG_PLANARCONFIG, planarconfig) < 0)
Packit 994f1a
		goto failure;
Packit 994f1a
Packit 994f1a
	for (i = 0; i < NSINGLETAGS; i++) {
Packit 994f1a
		if (CheckShortField(tif, short_single_tags[i].tag,
Packit 994f1a
				    short_single_tags[i].value) < 0)
Packit 994f1a
			goto failure;
Packit 994f1a
	}
Packit 994f1a
Packit 994f1a
	TIFFClose(tif);
Packit 994f1a
	
Packit 994f1a
	/* All tests passed; delete file and exit with success status. */
Packit 994f1a
	unlink(filename);
Packit 994f1a
	return 0;
Packit 994f1a
Packit 994f1a
failure:
Packit 994f1a
	/* Something goes wrong; close file and return unsuccessful status. */
Packit 994f1a
	TIFFClose(tif);
Packit 994f1a
	unlink(filename);
Packit 994f1a
	return 1;
Packit 994f1a
}
Packit 994f1a
Packit 994f1a
/* vim: set ts=8 sts=8 sw=8 noet: */
Packit 994f1a
/*
Packit 994f1a
 * Local Variables:
Packit 994f1a
 * mode: c
Packit 994f1a
 * c-basic-offset: 8
Packit 994f1a
 * fill-column: 78
Packit 994f1a
 * End:
Packit 994f1a
 */