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