[comp.sources.misc] v06i050: Source Code for TIFF->SunRaster

allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) (03/07/89)

Posting-number: Volume 6, Issue 50
Submitted-by: nobody@cs.buffalo.edu
Archive-name: tif2rast-p2

[Here we go again.  PLEASE MARK MULTIPART SUBMISSIONS IN ALL SUBJECT LINES!!!
It makes things a lot easier for me and for people searching the archives
++bsa]

# This is a shell archive.  Remove anything before this line, then
# unpack it by saving it in a file and typing "sh file".  (Files
# unpacked will be owned by you and have default permissions.)
#
# This archive contains:
# genrast.c getopt.c version.c tif2rast.1

echo x - genrast.c
sed -e 's/^X//' > "genrast.c" << '//E*O*F genrast.c//'
X
X#include <rasterfile.h>
X#include <stdio.h>
X#include "defs.h"
X#include "tif.h"
X
Xstruct rasterfile ras;
X
Xint bytes_per_row = 0;
X
Xgenrast(filename, picts)
X     char    *filename;
X     PICTURE *picts;
X{
X  int i;
X
X  /* calculate raster header and swap bytes */
X  bytes_per_row = (int) (picts[0].image.imWidth / 8);
X  ras.ras_magic = RAS_MAGIC;
X  ras.ras_width = picts[0].image.imWidth;
X  ras.ras_height = picts[0].image.imLength;
X  ras.ras_depth = 1;
X  ras.ras_length = (bytes_per_row * picts[0].image.imLength);
X  ras.ras_type = 1;
X  ras.ras_maptype = 0;
X  ras.ras_maplength = 0;
X  
X  /* write out rasterfile header */
X  fwrite((char *) &ras,sizeof(struct rasterfile),1,stdout);
X  for (i = 0; i < picts[0].image.strips[0].byteCount; i++) 
X    printf("%c", picts[0].image.strips[0].data[i]);
X}
X
X
//E*O*F genrast.c//

echo x - getopt.c
sed -e 's/^X//' > "getopt.c" << '//E*O*F getopt.c//'
X/*
X *	I got this off net.sources from Henry Spencer.
X *	It is a public domain getopt(3) like in System V.
X *
X *	I made some minor modifications while porting it to MS-DOS.
X *		andy@coma
X */
X#include <stdio.h>
X#include <string.h>
X
X#define	ARGCH    (int)':'
X#define BADCH	 (int)'?'
X#define EMSG	 ""
X#define	ENDARGS  "--"
X
X/*
X * get option letter from argument vector
X */
Xint	optind = 1,		/* index into parent argv vector */
X	optopt;			/* character checked for validity */
Xchar	*optarg;		/* argument associated with option */
X
X#define tell(s)	fputs(*nargv,stderr);fputs(s,stderr); \
X		(void)fputc(optopt,stderr);(void)fputc('\n',stderr); \
X                return(BADCH);
X
Xint getopt(nargc,nargv,ostr)
Xint	nargc;
Xchar	**nargv,
X	*ostr;
X{
X	static char	*place = EMSG;	/* option letter processing */
X	register char	*oli;		/* option letter list index */
X
X	if(!*place) {			/* update scanning pointer */
X		if(optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) return(EOF);
X		if (*place == '-') {	/* found "--" */
X			++optind;
X			return(EOF);
X		}
X	}				/* option letter okay? */
X	if ((optopt = (int)*place++) == ARGCH || !(oli = strchr (ostr,optopt))) {
X		if(!*place) ++optind;
X		tell(": illegal option -- ");
X	}
X	if (*++oli != ARGCH) {		/* don't need argument */
X		optarg = NULL;
X		if (!*place) ++optind;
X	}
X	else {				/* need an argument */
X		if (*place) optarg = place;	/* no white space */
X		else if (nargc <= ++optind) {	/* no arg */
X			place = EMSG;
X			tell(": option requires an argument -- ");
X		}
X	 	else optarg = nargv[optind];	/* white space */
X		place = EMSG;
X		++optind;
X	}
X	return(optopt);			/* dump back option letter */
X}
//E*O*F getopt.c//

echo x - version.c
sed -e 's/^X//' > "version.c" << '//E*O*F version.c//'
X#include "defs.h"
XCHAR *version () {
X  STATIC CHAR ConfID[] =  "1.0 (Sun Feb 12 21:55:10 1989 by wu@sunybcs)";
X  return ConfID;
X}
//E*O*F version.c//

echo x - tif2rast.1
sed -e 's/^X//' > "tif2rast.1" << '//E*O*F tif2rast.1//'
X...
X... tif2rast/tifdump -- convert TIFF to Sun raster
X...
X... written by:
X... Andreas Lampen, TU-Berlin (andy@coma.UUCP)
X...			     (andy@db0tui62.BITNET)
X... William W.C. Wu, State University of New York at Buffalo
X...                  (wu@sunybcs.bitnet)
X...                  (wu@cs.buffalo.edu)
X...
X... Copyright (C) 1988 by the author.
X... Permission is granted to copy and distribute this program
X... without charge, provided this copyright notice is included
X... in the copy.
X... This Software is distributed on an as-is basis. There will be
X... ABSOLUTELY NO WARRANTY for any part of this software to work
X... correct. In no case will the author be liable to you for damages
X... caused by the usage of this software.
X...
X.TH TIF2RAST 1
X.SH NAME
Xtif2Rast, tifdump \- convert TIFF files to Sun Raster
X.SH SYNOPSIS
X.B tif2rast
X.RB [ \-h
X.IR height ]
X.RB [ \-s ]
X.IR scalefactor ]
X.RB [ \-v ]
X.RB [ \-x
X.IR x-offset ]
X.RB [ \-y
X.IR y-offset ]
Xfile1 ...
X.LP
X.B tifdump 
X.RB [ \-v ]
Xfile1 ...
X.SH DESCRIPTION
X\fITif2rast\fR converts a TIFF file to Sun Raster file, and writes the result
Xto standard output.
X\fITif2rast\fR recognizes the following options:
X.TP
X.BI \-v
Xprints the version identification of \fItif2rast\fR.
X.LP
X\fITifdump\fR produces a human readable dump of the given TIFF-files.
XThe result is written to standard output.
X.SH BUGS
XThis version of \fItif2rast\fR has not been tested very extensively yet.
XSo don't be too angry if it produces core dumps or incorrect Sun Raster
Xfiles.
XIn that case, please drop a short error report to the author.
X.br
X.PP
XData compression is not yet supported.
X.PP
X.SH AUTHOR 1
XAndreas Lampen, TU Berlin
X.sp
X.ta 0.7i 
XUUCP:	unido!coma!andy
X.br
XBITNET:	andy@db0tui62
X.PP
X.SH AUTHOR 2
XWilliam W.C. Wu, State University of New York at Buffalo
X.sp
X.ta 0.7i 
XUUCP:	..!{boulder,decvax,rutgers}!sunybcs!wu
X.br
XBITNET:	wu@sunybcs.bitnet
X.br
XINTERNET: wu@cs.buffalo.edu
//E*O*F tif2rast.1//

exit 0