Blame test/strip_rw.c

Packit 7838c8
/* $Id: strip_rw.c,v 1.6 2008/03/28 01:42:07 bfriesen Exp $ */
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * Copyright (c) 2004, Andrey Kiselev  <dron@ak4719.spb.edu>
Packit 7838c8
 *
Packit 7838c8
 * Permission to use, copy, modify, distribute, and sell this software and 
Packit 7838c8
 * its documentation for any purpose is hereby granted without fee, provided
Packit 7838c8
 * that (i) the above copyright notices and this permission notice appear in
Packit 7838c8
 * all copies of the software and related documentation, and (ii) the names of
Packit 7838c8
 * Sam Leffler and Silicon Graphics may not be used in any advertising or
Packit 7838c8
 * publicity relating to the software without the specific, prior written
Packit 7838c8
 * permission of Sam Leffler and Silicon Graphics.
Packit 7838c8
 * 
Packit 7838c8
 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
Packit 7838c8
 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
Packit 7838c8
 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
Packit 7838c8
 * 
Packit 7838c8
 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
Packit 7838c8
 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
Packit 7838c8
 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
Packit 7838c8
 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
Packit 7838c8
 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
Packit 7838c8
 * OF THIS SOFTWARE.
Packit 7838c8
 */
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * TIFF Library
Packit 7838c8
 *
Packit 7838c8
 * Test libtiff input/output routines.
Packit 7838c8
 */
Packit 7838c8
Packit 7838c8
#include "tif_config.h"
Packit 7838c8
Packit 7838c8
#include <stdio.h>
Packit 7838c8
Packit 7838c8
#ifdef HAVE_UNISTD_H 
Packit 7838c8
# include <unistd.h> 
Packit 7838c8
#endif 
Packit 7838c8
Packit 7838c8
#include "tiffio.h"
Packit 7838c8
#include "test_arrays.h"
Packit 7838c8
Packit 7838c8
extern int
Packit 7838c8
create_image_striped(const char *, uint32, uint32, uint32, uint16, uint16,
Packit 7838c8
		     uint16, uint16, uint16, uint16, const tdata_t,
Packit 7838c8
		     const tsize_t);
Packit 7838c8
extern int
Packit 7838c8
read_image_striped(const char *, uint32, uint32, uint32, uint16, uint16,
Packit 7838c8
		   uint16, uint16, uint16, uint16, const tdata_t,
Packit 7838c8
		   const tsize_t);
Packit 7838c8
Packit 7838c8
const char	*filename = "strip_test.tiff";
Packit 7838c8
Packit 7838c8
int
Packit 7838c8
main(int argc, char **argv)
Packit 7838c8
{
Packit 7838c8
	uint32		rowsperstrip;
Packit 7838c8
	uint16		compression;
Packit 7838c8
	uint16		spp, bps, photometric, sampleformat, planarconfig;
Packit 7838c8
        (void) argc;
Packit 7838c8
        (void) argv;
Packit 7838c8
Packit 7838c8
	/* 
Packit 7838c8
	 * Test two special cases: image consisting from single line and image
Packit 7838c8
	 * consisting from single column.
Packit 7838c8
	 */
Packit 7838c8
	rowsperstrip = 1;
Packit 7838c8
	compression = COMPRESSION_NONE;
Packit 7838c8
	spp = 1;
Packit 7838c8
	bps = 8;
Packit 7838c8
        photometric = PHOTOMETRIC_MINISBLACK;
Packit 7838c8
	sampleformat = SAMPLEFORMAT_UINT;
Packit 7838c8
	planarconfig = PLANARCONFIG_CONTIG;
Packit 7838c8
Packit 7838c8
	if (create_image_striped(filename, XSIZE * YSIZE, 1, rowsperstrip,
Packit 7838c8
				  compression, spp, bps, photometric,
Packit 7838c8
				  sampleformat, planarconfig,
Packit 7838c8
				  (const tdata_t) byte_array1, byte_array1_size) < 0) {
Packit 7838c8
		fprintf (stderr, "Can't create TIFF file %s.\n", filename);
Packit 7838c8
		goto failure;
Packit 7838c8
	}
Packit 7838c8
	if (read_image_striped(filename, XSIZE * YSIZE, 1, rowsperstrip,
Packit 7838c8
				compression, spp, bps, photometric,
Packit 7838c8
				sampleformat, planarconfig,
Packit 7838c8
				(const tdata_t) byte_array1, byte_array1_size) < 0) {
Packit 7838c8
		fprintf (stderr, "Can't read TIFF file %s.\n", filename);
Packit 7838c8
		goto failure;
Packit 7838c8
	}
Packit 7838c8
	unlink(filename);
Packit 7838c8
		
Packit 7838c8
	if (create_image_striped(filename, 1, XSIZE * YSIZE, rowsperstrip,
Packit 7838c8
				  compression, spp, bps, photometric,
Packit 7838c8
				  sampleformat, planarconfig,
Packit 7838c8
				  (const tdata_t) byte_array1, byte_array1_size) < 0) {
Packit 7838c8
		fprintf (stderr, "Can't create TIFF file %s.\n", filename);
Packit 7838c8
		goto failure;
Packit 7838c8
	}
Packit 7838c8
	if (read_image_striped(filename, 1, XSIZE * YSIZE, rowsperstrip,
Packit 7838c8
				compression, spp, bps, photometric,
Packit 7838c8
				sampleformat, planarconfig,
Packit 7838c8
				(const tdata_t) byte_array1, byte_array1_size) < 0) {
Packit 7838c8
		fprintf (stderr, "Can't read TIFF file %s.\n", filename);
Packit 7838c8
		goto failure;
Packit 7838c8
	}
Packit 7838c8
	unlink(filename);
Packit 7838c8
		
Packit 7838c8
	/* 
Packit 7838c8
	 * Test one-channel image with different parameters.
Packit 7838c8
	 */
Packit 7838c8
	rowsperstrip = 1;
Packit 7838c8
	spp = 1;
Packit 7838c8
	bps = 8;
Packit 7838c8
        photometric = PHOTOMETRIC_MINISBLACK;
Packit 7838c8
	sampleformat = SAMPLEFORMAT_UINT;
Packit 7838c8
	planarconfig = PLANARCONFIG_CONTIG;
Packit 7838c8
Packit 7838c8
	if (create_image_striped(filename, XSIZE, YSIZE, rowsperstrip,
Packit 7838c8
				  compression, spp, bps, photometric,
Packit 7838c8
				  sampleformat, planarconfig,
Packit 7838c8
				  (const tdata_t) byte_array1, byte_array1_size) < 0) {
Packit 7838c8
		fprintf (stderr, "Can't create TIFF file %s.\n", filename);
Packit 7838c8
		goto failure;
Packit 7838c8
	}
Packit 7838c8
	if (read_image_striped(filename, XSIZE, YSIZE, rowsperstrip,
Packit 7838c8
				compression, spp, bps, photometric,
Packit 7838c8
				sampleformat, planarconfig,
Packit 7838c8
				(const tdata_t) byte_array1, byte_array1_size) < 0) {
Packit 7838c8
		fprintf (stderr, "Can't read TIFF file %s.\n", filename);
Packit 7838c8
		goto failure;
Packit 7838c8
	}
Packit 7838c8
	unlink(filename);
Packit 7838c8
	
Packit 7838c8
	rowsperstrip = YSIZE;
Packit 7838c8
	if (create_image_striped(filename, XSIZE, YSIZE, rowsperstrip,
Packit 7838c8
				  compression, spp, bps, photometric,
Packit 7838c8
				  sampleformat, planarconfig,
Packit 7838c8
				  (const tdata_t) byte_array1, byte_array1_size) < 0) {
Packit 7838c8
		fprintf (stderr, "Can't create TIFF file %s.\n", filename);
Packit 7838c8
		goto failure;
Packit 7838c8
	}
Packit 7838c8
	if (read_image_striped(filename, XSIZE, YSIZE, rowsperstrip,
Packit 7838c8
				compression, spp, bps, photometric,
Packit 7838c8
				sampleformat, planarconfig,
Packit 7838c8
				(const tdata_t) byte_array1, byte_array1_size) < 0) {
Packit 7838c8
		fprintf (stderr, "Can't read TIFF file %s.\n", filename);
Packit 7838c8
		goto failure;
Packit 7838c8
	}
Packit 7838c8
	unlink(filename);
Packit 7838c8
Packit 7838c8
	return 0;
Packit 7838c8
Packit 7838c8
failure:
Packit 7838c8
	unlink(filename);
Packit 7838c8
	return 1;
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
/* vim: set ts=8 sts=8 sw=8 noet: */