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