v09i026: PBMPLUS part 10 of 19: pgm.shar3 of 3

Brandon S. Allbery - comp.sources.misc allbery at uunet.UU.NET
Mon Nov 27 07:27:51 AEST 1989


Posting-number: Volume 9, Issue 26
Submitted-by: jef at helios.ee.lbl.gov (Jef Poskanzer)
Archive-name: pbmplus/part10

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	pgm/pgmtofits.c
#	pgm/pgmtofits.1
#	pgm/tifftopgm.c
#	pgm/tifftopgm.1
#	pgm/rawtopgm.c
#	pgm/rawtopgm.1
#	pgm/pgmhist.c
#	pgm/pgmhist.1
#	pgm/pgmnorm.c
#	pgm/pgmnorm.1
# This archive created: Wed Nov 22 21:13:52 1989
# By:	Jef Poskanzer (Paratheo-Anametamystikhood Of Eris Esoteric, Ada Lovelace Cabal)
export PATH; PATH=/bin:$PATH
if test ! -d 'pgm'
then
	echo shar: creating directory "'pgm'"
	mkdir 'pgm'
fi
echo shar: extracting "'pgm/pgmtofits.c'" '(3280 characters)'
if test -f 'pgm/pgmtofits.c'
then
	echo shar: will not over-write existing file "'pgm/pgmtofits.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pgm/pgmtofits.c'
X/* pgmtofits.c - read a portable pixmap and produce a FITS file
X**
X** Copyright (C) 1989 by Wilson H. Bent (whb at hoh-2.att.com).
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation.  This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include <stdio.h>
X#include "pgm.h"
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    register gray *grayrow, *gP;
X    int argn, rows, cols, i, format;
X    register int col, row;
X    gray maxval;
X
X    pm_progname = argv[0];
X
X    argn = 1;
X
X    if ( argn < argc )
X	{
X	ifd = pm_openr( argv[argn] );
X	argn++;
X	}
X    else
X	ifd = stdin;
X
X    if ( argn != argc )
X	pm_usage( "[pgmfile]" );
X
X    pgm_readpgminit( ifd, &cols, &rows, &maxval, &format );
X    if ( maxval > 255 )
X	pm_error( "maxval (%d) is greater than maximum of 255", maxval, 0,0,0,0 );
X    grayrow = pgm_allocrow( cols );
X
X    putFitsHead( cols, rows, maxval );
X
X    for ( row = 0; row < rows; row++ )
X	{
X	pgm_readpgmrow( ifd, grayrow, cols, maxval, format );
X	for ( col = 0, gP = grayrow; col < cols; col++, gP++ )
X	    putchar( *gP );
X	}
X
X    for ( i = ( rows * cols ) % 2880; i < 2880; i++ )
X	putchar( '\0' );
X
X    pm_close( ifd );
X
X    exit( 0 );
X    }
X
XputFitsHead( cols, rows, maxval )
Xint cols, rows, maxval;
X    {
X    int i = 0;
X    char card[81];
X
X    sprintf( card, "SIMPLE  =                    T                                                  " );
X    write_card( card ); ++i;
X    sprintf( card, "BITPIX  =                    8                                                  " );
X    write_card( card ); ++i;
X    sprintf( card, "NAXIS   =                    2                                                  " );
X    write_card( card ); ++i;
X    sprintf( card, "NAXIS1  =           %10d                                                  ", cols );
X    write_card( card ); ++i;
X    sprintf( card, "NAXIS2  =           %10d                                                  ", rows );
X    write_card( card ); ++i;
X    sprintf( card, "DATAMIN =           %10d                                                  ", 0 );
X    write_card( card ); ++i;
X    sprintf( card, "DATAMAX =           %10d                                                  ", maxval );
X    write_card( card ); ++i;
X    sprintf( card, "BZERO   =                  0.0                                                  " );
X    write_card( card ); ++i;
X    sprintf( card, "BSCALE  =                  1.0                                                  " );
X    write_card( card ); ++i;
X    sprintf( card, "HISTORY Created by fitstopgm.                                                   " );
X    write_card( card ); ++i;
X    sprintf( card, "END                                                                             " );
X    write_card( card ); ++i;
X    sprintf( card, "                                                                                " );
X    while ( i < 36 )
X	{
X	write_card( card ); ++i;
X	}
X    }
X
Xwrite_card( str )
Xchar *str;
X    {
X    fwrite( str, sizeof (char), 80, stdout );
X    }
SHAR_EOF
if test 3280 -ne "`wc -c < 'pgm/pgmtofits.c'`"
then
	echo shar: error transmitting "'pgm/pgmtofits.c'" '(should have been 3280 characters)'
fi
fi # end of overwriting check
if test ! -d 'pgm'
then
	echo shar: creating directory "'pgm'"
	mkdir 'pgm'
fi
echo shar: extracting "'pgm/pgmtofits.1'" '(434 characters)'
if test -f 'pgm/pgmtofits.1'
then
	echo shar: will not over-write existing file "'pgm/pgmtofits.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pgm/pgmtofits.1'
X.TH pgmtofits 1 "20 September 1989"
X.SH NAME
Xpgmtofits - convert a portable graymap into FITS format
X.SH SYNOPSIS
Xpgmtofits [<pgmfile>]
X.SH DESCRIPTION
XReads a portable graymap as input.
XProduces a FITS file as output.
X.PP
XFITS stands for Flexible Image Transport System.  A full description
Xcan be found in Astronomy & Astrophysics Supplement Series 44 (1981),
Xpage 363.
X.SH "SEE ALSO"
Xfitstopgm(1), pgm(5)
X.SH AUTHOR
XWilson H. Bent
SHAR_EOF
if test 434 -ne "`wc -c < 'pgm/pgmtofits.1'`"
then
	echo shar: error transmitting "'pgm/pgmtofits.1'" '(should have been 434 characters)'
fi
fi # end of overwriting check
if test ! -d 'pgm'
then
	echo shar: creating directory "'pgm'"
	mkdir 'pgm'
fi
echo shar: extracting "'pgm/tifftopgm.c'" '(12431 characters)'
if test -f 'pgm/tifftopgm.c'
then
	echo shar: will not over-write existing file "'pgm/tifftopgm.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pgm/tifftopgm.c'
X/*
X** tifftopgm.c
X**
X**      Copyright 1988 by Paul J. Emerson
X**
X**      Permission to use, copy, modify, and distribute this software
X**      and its documentation for any purpose and without fee is
X**      hereby granted, provided that the above copyright notice
X**      appear in all copies and that both that copyright notice and
X**      this permission notice appear in supporting documentation, and
X**      that the name of Paul J. Emerson not be used in advertising or
X**      publicity pertaining to distribution of the software without
X**      specific, written prior permission.  Paul J. Emerson makes no
X**      representations about the suitability of this software for
X**      any purpose.  It is provided "as is" without express or implied
X**      warranty.
X*/
X
X#include <stdio.h>
X#include <fcntl.h>
X#include "tiff.h"
X#include "pgm.h"
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    int argn, dump;
X    struct Tiffstruct Tiff;
X    struct TiffHeader Header;
X    char *usage = "[-h] [tifffile]";
X
X    pm_progname = argv[0];
X
X    argn = 1;
X    dump = 0;
X
X    if ( argn < argc && argv[argn][0] == '-' )
X	{
X	if ( argv[argn][1] == 'h' && argv[argn][2] == '\0' )
X	    dump = 1;
X	else
X	    pm_usage( usage );
X	argn++;
X	}
X
X    if ( argn < argc )
X	{
X	ifd = pm_openr( argv[argn] );
X	argn++;
X	}
X    else
X	ifd = stdin;
X
X    if ( argn != argc )
X	pm_usage( usage );
X
X    if ( readTiff( &Tiff, &Header, ifd ) )
X	{
X	if ( dump )
X	    dumpHeader( &Tiff, &Header );
X	PgmOut( ifd, &Tiff );
X	}
X    else
X	pm_error( "readTiff failure", 0,0,0,0,0 );
X
X    pm_close( ifd );
X    exit( 0 );
X    }
X
X/*
X**  Send image to stdout in PGM format
X*/
XPgmOut( fd, t )
XFILE *fd;
Xstruct Tiffstruct *t;
X    {
X    register int i, row;
X    char *bptr;
X    LONG *cntptr, count;
X    LONG *dataptr;
X    gray **grays;
X    int maxval;
X    extern char *malloc();
X
X    grays = pgm_allocarray( t->ImageWidth, t->ImageLength );
X
X    dataptr = t->StripOffset;
X    cntptr  = t->SBytesCntOffset;
X    if ( cntptr == (LONG *) 0 )
X	{ /* Fucking AppleScan writes bogus TIFF files... */
X	fprintf( stderr, "Missing StripByteCounts, proceeding to guess...\n" );
X	count = ( t->ImageWidth * t->ImageLength * t->BitsPerSample + 7 ) / 8 / t->StOffsetCnt;
X	}
X    else
X	count = *cntptr;
X    maxval = ( 1 << t->BitsPerSample ) - 1;
X    if ( maxval > PGM_MAXMAXVAL )
X	pm_error( "BitsPerSample is too large - try recompiling with a larger gray type" );
X
X    for ( i=0, row=0; i < t->StOffsetCnt; i++, row += t->RowsStrip )
X	{
X	fseek( fd, (long) *dataptr, 0);
X	bptr = malloc( count );
X	if ( bptr == 0 )
X	    pm_error( "out of memory", 0,0,0,0,0 );
X	if  ( fread( bptr, 1, count, fd ) != count )
X	    pm_perror( "StripOffset read" );
X
X	PgmDoStrip(
X	    bptr, count, grays, row, t->ImageWidth, t->BitsPerSample,
X	    (gray) maxval );
X
X	free( bptr );
X	if ( cntptr != (LONG *) 0 )
X	    count = *(++cntptr);
X	dataptr++;
X	}
X
X    pgm_writepgm( stdout, grays, t->ImageWidth, t->ImageLength, (gray) maxval );
X    }
X/*
X** Output a strip in PGM format
X*/
XPgmDoStrip(buffer,count,grays,row,cols,bps,maxval)
Xchar *buffer;
Xint count;
Xgray **grays;
Xint maxval;
Xint row, cols, bps;
X    {
X    register int i, col;
X
X    col = 0;
X    while ( count-- )
X	{
X	for ( i = 7 ; i >= 0; i -= bps )
X	    {
X	    grays[row][col++] = maxval - ( ( *buffer >> i ) & maxval );
X	    if ( col >= cols )
X		{
X		col = 0;
X		row++;
X		break;
X		}
X	    }
X	buffer++;
X	}
X    }
X
Xint bigendian;
X
X/*
X** Read and decode a Tiff header.  Not all TIFF capabilities are supported.
X*/
Xint
XreadTiff( T, H, fd )
Xstruct Tiffstruct *T;
Xstruct TiffHeader *H;
XFILE *fd;
X    {
X    struct IDF idf;
X    struct IDF_Entry  *ptr;
X    LONG TempRational[2];
X    int i;
X
X#ifdef SYSV
X    memset((char *)T,0,sizeof(struct Tiffstruct));
X#else /*SYSV*/
X    bzero((char *)T,sizeof(struct Tiffstruct));
X#endif /*SYSV*/
X
X    if (fread(H->ByteOrder,sizeof(H->ByteOrder),1,fd) != 1)
X	pm_perror("reading header byte order");
X    if ( H->ByteOrder[0] == 0x4d && H->ByteOrder[1] == 0x4d )
X	bigendian = 1;
X    else if ( H->ByteOrder[0] == 0x49 && H->ByteOrder[1] == 0x49 )
X	bigendian = 0;
X    else
X	pm_error(
X	    "unknown byte order: 0x%02x%02x", H->ByteOrder[0], H->ByteOrder[1],
X	    0,0,0 );
X
X    {
X    if (readshort(fd,&H->Version) == -1)
X	pm_perror("reading header version");
X    if (readlong(fd,&H->IdfOffset) == -1)
X	pm_perror("reading header ifd offset");
X    }
X
X    fseek(fd,(long)H->IdfOffset,0);
X
X    if (readshort(fd,&idf.NumEntries) == -1)
X	pm_perror("reading idf count ");
X
X    if ((idf.idfptr = (struct IDF_Entry *) calloc(idf.NumEntries,sizeof(struct IDF_Entry))) == NULL)
X	pm_error( "out of memory", 0,0,0,0,0 );
X
X    for( i = 0; i < idf.NumEntries; ++i )
X	{
X	if (readshort(fd,&idf.idfptr[i].Tag) == -1)
X	    pm_perror("reading idf entries");
X	if (readshort(fd,&idf.idfptr[i].Type) == -1)
X	    pm_perror("reading idf entries");
X	if (readlong(fd,&idf.idfptr[i].Length) == -1)
X	    pm_perror("reading idf entries");
X	if (readlong(fd,&idf.idfptr[i].ValueOffset) == -1)
X	    pm_perror("reading idf entries");
X	}
X
X    ptr = idf.idfptr;
X
X    while (idf.NumEntries--)
X	{
X	switch (ptr->Tag)
X	    {
X	    case  0x00FF:
X	    T->SubFileType = (ptr->ValueOffset >> 16);
X	    break;
X
X	    case  0x0100:
X	    T->ImageWidth = (ptr->ValueOffset >> 16);
X	    break;
X
X	    case  0x0101:
X	    T->ImageLength = (ptr->ValueOffset >> 16);
X	    break;
X
X	    case  0x0102:
X	    T->BitsPerSample = (ptr->ValueOffset >> 16);
X	    break;
X
X	    case  0x0103:
X	    T->Compression = (ptr->ValueOffset >> 16);
X	    break;
X
X	    case  0x0106:
X	    T->PhotoInterp = (ptr->ValueOffset >> 16);
X	    break;
X
X	    case  0x0107:
X	    T->Threshold = (ptr->ValueOffset >> 16);
X	    break;
X
X	    case  0x0108:
X	    T->CellWidth = (ptr->ValueOffset >> 16);
X	    break;
X
X	    case  0x0109:
X	    T->CellLength = (ptr->ValueOffset >> 16);
X	    break;
X
X	    case  0x010A:
X	    T->FillOrder = (ptr->ValueOffset >> 16);
X	    break;
X
X	    case  0x010D:
X	    fprintf(stderr,"Unsupported feature\n");
X	    /*
X	    fseek(fd,(long)ptr->ValueOffset,0);
X	    */
X	    break;
X
X	    case  0x010E:
X	    fprintf(stderr,"Unsupported feature\n");
X	    /*
X	    fseek(fd,(long)ptr->ValueOffset,0);
X	    */
X	    break;
X
X	    case  0x010F:
X	    /*
X	    fseek(fd,(long)ptr->ValueOffset,0);
X	    */
X	    fprintf(stderr,"Make: %s\n", T->Make);
X	    break;
X
X	    case  0x0110:
X	    fprintf(stderr,"Unsupported feature\n");
X	    /*
X	    fseek(fd,(long)ptr->ValueOffset,0);
X	    */
X	    break;
X
X	    case  0x0111:
X	    T->StOffsetCnt = ptr->Length;
X	    if ((T->StripOffset = (LONG *) calloc(T->StOffsetCnt, sizeof (LONG)))== NULL)
X		pm_error( "out of memory", 0,0,0,0,0 );
X	    if(T->StOffsetCnt == 1)
X		*(T->StripOffset) = ptr->ValueOffset;
X	    else
X		{
X		fseek(fd, (long) ptr->ValueOffset, 0);
X		for( i = 0; i < T->StOffsetCnt; ++i)
X		    if(readlong(fd,T->StripOffset+i) == -1)
X			pm_error( "reading strip offsets", 0,0,0,0,0 );
X		}
X	    break;
X
X	    case  0x0112:
X	    T->Orientation= (ptr->ValueOffset >> 16);
X	    break;
X
X	    case  0x0115:
X	    T->SamplesPixel= (ptr->ValueOffset >> 16);
X	    break;
X
X	    case  0x0116:
X	    T->RowsStrip= (ptr->ValueOffset);
X	    break;
X
X	    case  0x0117:
X	    T->StripByteCnt = (ptr->Length);
X	    if ((T->SBytesCntOffset = (LONG *) calloc(T->StripByteCnt, sizeof (LONG)))== NULL)
X		pm_error( "out of memory", 0,0,0,0,0 );
X	    if(T->StripByteCnt == 1)
X		*(T->SBytesCntOffset) = ptr->ValueOffset;
X	    else
X		{
X		fseek(fd,(long)ptr->ValueOffset,0);
X		for( i = 0; i < T->StripByteCnt; ++i)
X		    if(readlong(fd,T->SBytesCntOffset+i) == -1)
X			pm_error( "reading strip byte count offsets", 0,0,0,0,0 );
X		}
X	    break;
X
X	    case  0x0118:
X	    T->MinSampleValue= (ptr->ValueOffset >> 16);
X	    break;
X
X	    case  0x0119:
X	    T->MaxSampleValue= (ptr->ValueOffset >> 16);
X	    break;
X
X	    case  0x011A:
X	    fseek(fd,(long)ptr->ValueOffset,0);
X	    if(readlong(fd,&TempRational[0]) == -1)
X		pm_error( "reading X resolution", 0,0,0,0,0 );
X	    if(readlong(fd,&TempRational[1]) == -1)
X		pm_error( "reading X resolution", 0,0,0,0,0 );
X	    T->Xres = TempRational[0]/TempRational[1];
X	    break;
X
X	    case  0x011B:
X	    fseek(fd,(long)ptr->ValueOffset,0);
X	    if(readlong(fd,&TempRational[0]) == -1)
X		pm_error( "reading Y resolution", 0,0,0,0,0 );
X	    if(readlong(fd,&TempRational[1]) == -1)
X		pm_error( "reading Y resolution", 0,0,0,0,0 );
X	    T->Yres = TempRational[0]/TempRational[1];
X	    break;
X
X	    case  0x011C:
X	    T->PlanarConfig= (ptr->ValueOffset >> 16);
X	    break;
X
X	    case  0x011D:
X	    fprintf(stderr,"Unsupported feature: PageName\n");
X	    /* T->PageName */
X	    break;
X
X	    case  0x011E:
X	    fprintf(stderr,"Unsupported feature: Xpos\n");
X	    /* T->XPos */
X	    break;
X
X	    case  0x011F:
X	    fprintf(stderr,"Unsupported feature: Ypos\n");
X	    /* T->YPos */
X	    break;
X
X	    case  0x0120:
X	    fprintf(stderr,"Unsupported feature: FreeOffsets\n");
X	    /* T->FreeOffsets */
X	    break;
X
X	    case  0x0121:
X	    fprintf(stderr,"Unsupported feature: FreeByteCount \n");
X	    /* T->FreeByteCount */
X	    break;
X
X	    case  0x0122:
X	    fprintf(stderr,"Unsupported feature: GrayResUnit\n");
X	    /* T->GrayResUnit */
X	    break;
X
X	    case  0x0123:
X	    fprintf(stderr,"Unsupported feature: GrayResCurve\n");
X	    /* T->GrayResCurve */
X	    break;
X
X	    case  0x0124:
X	    fprintf(stderr,"Unsupported feature: Group3Option\n");
X	    /* T->Group3Option */
X	    break;
X
X	    case  0x0125:
X	    fprintf(stderr,"Unsupported feature: Group4Option\n");
X	    /* T->Group4Option */
X	    break;
X
X	    case  0x0128:
X	    fprintf(stderr,"Unsupported feature: ResolutionUnit\n");
X	    /* T->ResolutionUnit */
X	    break;
X
X	    case  0x0129:
X	    fprintf(stderr,"Unsupported feature: PageNumber\n");
X	    /* T->PageNumber */
X	    break;
X
X	    case  0x012C:
X	    fprintf(stderr,"Unsupported feature: ColorResUnit\n");
X	    /* T->ColorResUnit */
X	    break;
X
X	    case  0x012D:
X	    fprintf(stderr,"Unsupported feature: ColorResCurv\n");
X	    /* T->ColorResCurv */
X	    break;
X
X	    default:
X	    fprintf(stderr,"Unsupported feature: Unknown Tag\n");
X	    fprintf(stderr,"Default\n");
X	    break;
X	    }
X	ptr++;
X	}
X
X    return 1;
X    }
X
X/*
X** Dump header information
X*/
XdumpHeader( T, H )
Xstruct Tiffstruct *T;
Xstruct TiffHeader *H;
X    {
X    int i;
X    LONG *offptr;
X
X    fprintf( stderr, "Version:        %d\n",H->Version );
X    fprintf( stderr, "ByteOrder:      %c%c\n", H->ByteOrder[0], H->ByteOrder[1] );
X    fprintf( stderr, "Subfile Type:   %d\n", T->SubFileType );
X    fprintf( stderr, "ImageWidth:     %d\n", T->ImageWidth );
X    fprintf( stderr, "ImageLength:    %d\n", T->ImageLength );
X    fprintf( stderr, "BitsPerSample:  %d\n", T->BitsPerSample );
X    fprintf( stderr, "Compression:    %d\n", T->Compression );
X    fprintf( stderr, "PhotoInterp:    %d\n", T->PhotoInterp );
X    fprintf( stderr, "Threshold:      %d\n", T->Threshold );
X    fprintf( stderr, "CellWidth:      %d\n", T->CellWidth );
X    fprintf( stderr, "CellLength:     %d\n", T->CellLength );
X    fprintf( stderr, "FillOrder:      %d\n", T->FillOrder );
X    fprintf( stderr, "DocName:        %s\n", T->DocName );
X    fprintf( stderr, "ImageDescript:  %s\n", T->ImageDescript );
X    fprintf( stderr, "Model:          %s\n", T->Model );
X    fprintf( stderr, "StripOffsetCnt: %d\n", T->StOffsetCnt );
X    offptr = T->StripOffset;
X    for( i=0; i < T->StOffsetCnt; i++ )
X	{
X	fprintf( stderr, "Strip [%02d] starts at: %d \n", i,*offptr );
X	offptr++;
X	}
X    fprintf( stderr, "Orientation:    %d\n", T->Orientation );
X    fprintf( stderr, "SamplesPixel:   %d\n", T->SamplesPixel );
X    fprintf( stderr, "RowsStrip:      %d\n", T->RowsStrip );
X    fprintf( stderr, "StripByteCnt:   %d\n", T->StripByteCnt );
X    offptr = T->SBytesCntOffset;
X    for( i=0; i < T->StripByteCnt; i++ )
X	{
X	fprintf( stderr, "Strip [%02d]: %d bytes\n", i,*offptr );
X	offptr++;
X	}
X    fprintf( stderr, "MinSampleValue: %d\n", T->MinSampleValue );
X    fprintf( stderr, "MaxSampleValue: %d\n", T->MaxSampleValue );
X    fprintf( stderr, "Xres:           %d\n", T->Xres );
X    fprintf( stderr, "Yres:           %d\n", T->Yres );
X    fprintf( stderr, "PlanarConfig:   %d\n", T->PlanarConfig );
X    }
X
Xreadshort( in, sP )
XFILE *in;
Xshort *sP;
X    {
X    if ( bigendian )
X	return pm_readbigshort( in, sP );
X    else
X	return pm_readlittleshort( in, sP );
X    }
X
Xreadlong( in, lP )
XFILE *in;
Xlong *lP;
X    {
X    if ( bigendian )
X	return pm_readbiglong( in, lP );
X    else
X	return pm_readlittlelong( in, lP );
X    }
SHAR_EOF
if test 12431 -ne "`wc -c < 'pgm/tifftopgm.c'`"
then
	echo shar: error transmitting "'pgm/tifftopgm.c'" '(should have been 12431 characters)'
fi
fi # end of overwriting check
if test ! -d 'pgm'
then
	echo shar: creating directory "'pgm'"
	mkdir 'pgm'
fi
echo shar: extracting "'pgm/tifftopgm.1'" '(990 characters)'
if test -f 'pgm/tifftopgm.1'
then
	echo shar: will not over-write existing file "'pgm/tifftopgm.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pgm/tifftopgm.1'
X.TH tifftopgm 1 "26 September 1989"
X.SH NAME
Xtifftopgm - convert a TIFF file into a portable graymap
X.SH SYNOPSIS
Xtifftopgm [-h] [tifffile]
X.SH DESCRIPTION
XReads a TIFF file as input.
XProduces a portable graymap as output.
XHandles black&white and grayscale TIFF, but not color.
X.TP 5
X.B \-h
XDump TIFF file information to stderr.  This information may be useful 
Xin debugging TIFF file conversion problems.  
X.SH BUGS
XThis is only a partial implemention of the TIFF standard.
XFor a more complete implementation, check out the TIFF Software
Xlisted in the OTHER.SYSTEMS file.
X.SH AUTHOR
XCopyright (C) 1988 by Paul Emerson. 
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted, provided
Xthat the above copyright notice appear in all copies and that both that
Xcopyright notice and this permission notice appear in supporting
Xdocumentation.  This software is provided "as is" without express or
Ximplied warranty.
SHAR_EOF
if test 990 -ne "`wc -c < 'pgm/tifftopgm.1'`"
then
	echo shar: error transmitting "'pgm/tifftopgm.1'" '(should have been 990 characters)'
fi
fi # end of overwriting check
if test ! -d 'pgm'
then
	echo shar: creating directory "'pgm'"
	mkdir 'pgm'
fi
echo shar: extracting "'pgm/rawtopgm.c'" '(1768 characters)'
if test -f 'pgm/rawtopgm.c'
then
	echo shar: will not over-write existing file "'pgm/rawtopgm.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pgm/rawtopgm.c'
X/* rawtopgm.c - convert raw grayscale bytes into a portable graymap
X**
X** Copyright (C) 1989 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation.  This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include <stdio.h>
X#include "pgm.h"
X#ifdef SYSV
X#include <string.h>
X#else /*SYSV*/
X#include <strings.h>
X#endif /*SYSV*/
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    register gray *grayrow, *gP;
X    int argn, row;
X    register int col, val;
X    int maxval;
X    int rows, cols;
X    char *usage = "<width> <height> [rawdata]";
X
X    pm_progname = argv[0];
X
X    argn = 1;
X
X    if ( argn + 3 > argc )
X	pm_usage( usage );
X
X    cols = atoi( argv[argn++] );
X    rows = atoi( argv[argn++] );
X    if ( cols <= 0 || rows <= 0 )
X	pm_usage( usage );
X
X    if ( argn < argc )
X	{
X	ifd = pm_openr( argv[argn] );
X	argn++;
X	}
X    else
X	ifd = stdin;
X
X    if ( argn != argc )
X	pm_usage( usage );
X
X    maxval = 255;
X    if ( maxval > PGM_MAXMAXVAL )
X	pm_error( "maxval of 255 is too large - try recompiling with a larger gray type" );
X
X    pgm_writepgminit( stdout, cols, rows, (gray) maxval );
X    grayrow = pgm_allocrow( ( cols + 7 ) / 8 * 8 );
X    for ( row = 0; row < rows; row++)
X	{
X	for ( col = 0, gP = grayrow; col < cols; ++col )
X	    {
X	    val = getc( ifd );
X	    if ( val == EOF )
X		pm_error( "premature EOF", 0,0,0,0,0 );
X	    *gP++ = val;
X	    }
X	pgm_writepgmrow( stdout, grayrow, cols, (gray) maxval );
X	}
X    pm_close( ifd );
X
X    exit( 0 );
X    }
SHAR_EOF
if test 1768 -ne "`wc -c < 'pgm/rawtopgm.c'`"
then
	echo shar: error transmitting "'pgm/rawtopgm.c'" '(should have been 1768 characters)'
fi
fi # end of overwriting check
if test ! -d 'pgm'
then
	echo shar: creating directory "'pgm'"
	mkdir 'pgm'
fi
echo shar: extracting "'pgm/rawtopgm.1'" '(871 characters)'
if test -f 'pgm/rawtopgm.1'
then
	echo shar: will not over-write existing file "'pgm/rawtopgm.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pgm/rawtopgm.1'
X.TH rawtopgm 1 "02 November 89"
X.SH NAME
Xrawtopgm - convert raw grayscale bytes into a portable graymap
X.SH SYNOPSIS
Xrawtopgm <width> <height> [imagedata]
X.SH DESCRIPTION
XReads raw grayscale bytes as input.
XProduces a portable graymap as output.
XThe input file is just grayscale bytes, no header and no padding.
XYou have to specify the width and height on the command line,
Xsince the program obviously can't get them from the file.
X.SH "SEE ALSO"
Xpgm(5)
X.SH AUTHOR
XCopyright (C) 1989 by Jef Poskanzer.
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted, provided
Xthat the above copyright notice appear in all copies and that both that
Xcopyright notice and this permission notice appear in supporting
Xdocumentation.  This software is provided "as is" without express or
Ximplied warranty.
SHAR_EOF
if test 871 -ne "`wc -c < 'pgm/rawtopgm.1'`"
then
	echo shar: error transmitting "'pgm/rawtopgm.1'" '(should have been 871 characters)'
fi
fi # end of overwriting check
if test ! -d 'pgm'
then
	echo shar: creating directory "'pgm'"
	mkdir 'pgm'
fi
echo shar: extracting "'pgm/pgmhist.c'" '(2078 characters)'
if test -f 'pgm/pgmhist.c'
then
	echo shar: will not over-write existing file "'pgm/pgmhist.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pgm/pgmhist.c'
X/* pgmhist.c - print a histogram of the values in a portable graymap
X**
X** Copyright (C) 1989 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation.  This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include <stdio.h>
X#include "pgm.h"
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    gray maxval, *grayrow;
X    register gray *gP;
X    int argn, rows, cols, format, row;
X    int i, *hist, *rcount, count, size;
X    register int col;
X    char *usage = "[pgmfile]";
X
X    pm_progname = argv[0];
X
X    argn = 1;
X
X    if ( argn < argc )
X	{
X	ifd = pm_openr( argv[argn] );
X	argn++;
X	}
X    else
X	ifd = stdin;
X
X    if ( argn != argc )
X	pm_usage( usage );
X
X    pgm_readpgminit( ifd, &cols, &rows, &maxval, &format );
X    grayrow = pgm_allocrow( cols );
X
X    /* Build histogram. */
X    hist = (int *) malloc( ( maxval + 1 ) * sizeof(int) );
X    rcount = (int *) malloc( ( maxval + 1 ) * sizeof(int) );
X    if ( hist == (int *) 0 || rcount == (int *) 0 )
X	pm_error( "out of memory", 0,0,0,0,0 );
X    for ( i = 0; i <= maxval; i++ )
X	hist[i] = 0;
X    for ( row = 0; row < rows; row++ )
X	{
X	pgm_readpgmrow( ifd, grayrow, cols, maxval, format );
X        for ( col = 0, gP = grayrow; col < cols; col++, gP++ )
X	    hist[(int) *gP]++;
X	}
X
X    pm_close( ifd );
X
X    /* Compute count-down */
X    count = 0;
X    for ( i = maxval; i >= 0; i-- )
X	{
X	count += hist[i];
X	rcount[i] = count;
X	}
X
X    /* And print it. */
X    printf( "value\tcount\tb%%\tw%%\n" );
X    printf( "-----\t-----\t--\t--\n" );
X    count = 0;
X    size = rows * cols;
X    for ( i = 0; i <= maxval; i++ )
X	if ( hist[i] > 0 )
X	    {
X	    count += hist[i];
X	    printf(
X		"%d\t%d\t%5.3g%%\t%5.3g%%\n", i, hist[i],
X		(float) count * 100.0 / size, (float) rcount[i] * 100.0 / size );
X	    }
X
X    exit( 0 );
X    }
SHAR_EOF
if test 2078 -ne "`wc -c < 'pgm/pgmhist.c'`"
then
	echo shar: error transmitting "'pgm/pgmhist.c'" '(should have been 2078 characters)'
fi
fi # end of overwriting check
if test ! -d 'pgm'
then
	echo shar: creating directory "'pgm'"
	mkdir 'pgm'
fi
echo shar: extracting "'pgm/pgmhist.1'" '(690 characters)'
if test -f 'pgm/pgmhist.1'
then
	echo shar: will not over-write existing file "'pgm/pgmhist.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pgm/pgmhist.1'
X.TH pgmhist 1 "28 February 1989"
X.SH NAME
Xpgmhist - print a histogram of the values in a portable graymap
X.SH SYNOPSIS
Xpgmhist [pgmfile]
X.SH DESCRIPTION
XReads a portable graymap as input.
XPrints a histogram of the gray values.
X.SH "SEE ALSO"
Xpgmnorm(1), pgm(5), ppmhist(1)
X.SH AUTHOR
XCopyright (C) 1989 by Jef Poskanzer.
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted, provided
Xthat the above copyright notice appear in all copies and that both that
Xcopyright notice and this permission notice appear in supporting
Xdocumentation.  This software is provided "as is" without express or
Ximplied warranty.
SHAR_EOF
if test 690 -ne "`wc -c < 'pgm/pgmhist.1'`"
then
	echo shar: error transmitting "'pgm/pgmhist.1'" '(should have been 690 characters)'
fi
fi # end of overwriting check
if test ! -d 'pgm'
then
	echo shar: creating directory "'pgm'"
	mkdir 'pgm'
fi
echo shar: extracting "'pgm/pgmnorm.c'" '(5154 characters)'
if test -f 'pgm/pgmnorm.c'
then
	echo shar: will not over-write existing file "'pgm/pgmnorm.c'"
else
sed 's/^X//' << \SHAR_EOF > 'pgm/pgmnorm.c'
X/* pgmnorm.c - read a portable graymap and normalize the contrast
X**
X** Copyright (C) 1989 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation.  This software is provided "as is" without express or
X** implied warranty.
X*/
X
X#include <stdio.h>
X#include "pgm.h"
X#ifdef SYSV
X#include <string.h>
X#else /*SYSV*/
X#include <strings.h>
X#endif /*SYSV*/
X
X#define max(a,b) ((a) > (b) ? (a) : (b))
X#define MAXMAXVAL 1023
X
Xmain( argc, argv )
Xint argc;
Xchar *argv[];
X    {
X    FILE *ifd;
X    gray maxval, **grays, *grayrow;
X    register gray range, *gP;
X    int argn, rows, cols, format, row;
X    int hist[MAXMAXVAL+1], i, size, cutoff, count;
X    float bpercent, wpercent;
X    int bvalue, wvalue;
X    int specbpercent, specbvalue, specwpercent, specwvalue;
X    register int col;
X    char *usage = "[-bpercent <n> | -bvalue <n>] [-wpercent <n> | -wvalue <n>] [pgmfile]";
X
X    pm_progname = argv[0];
X
X    argn = 1;
X    bpercent = 2.0;
X    wpercent = 1.0;
X    specbpercent = specbvalue = specwpercent = specwvalue = 0;
X
X    while ( argn + 1 < argc && argv[argn][0] == '-' )
X	{
X	if ( strncmp(argv[argn],"-bpercent",max(strlen(argv[argn]),3)) == 0 )
X	    {
X	    if ( specbvalue )
X		pm_error(
X		    "only one of -bpercent and -bvalue may be specified",
X		    0,0,0,0,0 );
X	    if ( sscanf( argv[argn+1], "%g", &bpercent ) != 1 )
X		pm_usage( usage );
X	    if ( bpercent < 0.0  || bpercent > 100.0 )
X		pm_error(
X		    "black percentage must between 0 and 100", 0,0,0,0,0 );
X	    specbpercent = 1;
X	    }
X	else if ( strncmp(argv[argn],"-bvalue",max(strlen(argv[argn]),3)) == 0 )
X	    {
X	    if ( specbpercent )
X		pm_error(
X		    "only one of -bpercent and -bvalue may be specified",
X		    0,0,0,0,0 );
X	    if ( sscanf( argv[argn+1], "%d", &bvalue ) != 1 )
X		pm_usage( usage );
X	    if ( bvalue < 0 )
X		pm_error( "black value must be >= 0", 0,0,0,0,0 );
X	    specbvalue = 1;
X	    }
X	else if ( strncmp(argv[argn],"-wpercent",max(strlen(argv[argn]),3)) == 0 )
X	    {
X	    if ( specwvalue )
X		pm_error(
X		    "only one of -wpercent and -wvalue may be specified",
X		    0,0,0,0,0 );
X	    if ( sscanf( argv[argn+1], "%g", &wpercent ) != 1 )
X		pm_usage( usage );
X	    if ( wpercent < 0.0 || wpercent > 100.0 )
X		pm_error(
X		    "white percentage must be between 0 and 100", 0,0,0,0,0 );
X	    specwpercent = 1;
X	    }
X	else if ( strncmp(argv[argn],"-wvalue",max(strlen(argv[argn]),3)) == 0 )
X	    {
X	    if ( specwpercent )
X		pm_error(
X		    "only one of -wpercent and -wvalue may be specified",
X		    0,0,0,0,0 );
X	    if ( sscanf( argv[argn+1], "%d", &wvalue ) != 1 )
X		pm_usage( usage );
X	    if ( wvalue < 0 )
X		pm_error( "white value must be >= 0", 0,0,0,0,0 );
X	    specwvalue = 1;
X	    }
X	else
X	    pm_usage( usage );
X	argn += 2;
X	}
X
X    if ( argn < argc )
X	{
X	ifd = pm_openr( argv[argn] );
X	argn++;
X	}
X    else
X	ifd = stdin;
X
X    if ( argn != argc )
X	pm_usage( usage );
X
X    if ( specbvalue && specwvalue )
X	{
X	/* Rescale so that bvalue maps to 0, wvalue maps to maxval. */
X	pgm_readpgminit( ifd, &cols, &rows, &maxval, &format );
X	grayrow = pgm_allocrow( cols );
X	pgm_writepgminit( stdout, cols, rows, maxval );
X	range = wvalue - bvalue;
X	for ( row = 0; row < rows; row++ )
X	    {
X	    pgm_readpgmrow( ifd, grayrow, cols, maxval, format );
X	    for ( col = 0, gP = grayrow; col < cols; col++, gP++ )
X		{
X		if ( *gP <= bvalue )
X		    *gP = 0;
X		else if ( *gP >= wvalue )
X		    *gP = maxval;
X		else
X		    *gP = ( *gP - bvalue ) * maxval / range;
X		}
X	    pgm_writepgmrow( stdout, grayrow, cols, maxval );
X	    }
X	pm_close( ifd );
X	}
X    else
X	{
X	grays = pgm_readpgm( ifd, &cols, &rows, &maxval );
X	pm_close( ifd );
X
X	/* Build histogram. */
X	for ( i = 0; i <= maxval; i++ )
X	    hist[i] = 0;
X	for ( row = 0; row < rows; row++ )
X	    for ( col = 0, gP = grays[row]; col < cols; col++, gP++ )
X		hist[*gP]++;
X	size = rows * cols;
X	if ( ! specbvalue )
X	    { /* Compute bvalue from bpercent. */
X	    cutoff = size * bpercent / 100.0;
X	    count = 0;
X	    for ( bvalue = 0; bvalue <= maxval; bvalue++ )
X		{
X		count += hist[bvalue];
X		if ( count > cutoff )
X		break;
X		}
X	    }
X	if ( ! specwvalue )
X	    { /* Compute wvalue from wpercent. */
X	    cutoff = size * wpercent / 100.0;
X	    count = 0;
X	    for ( wvalue = maxval; wvalue >= 0; wvalue-- )
X		{
X		count += hist[wvalue];
X		if ( count > cutoff )
X		    break;
X		}
X	    }
X
X	/* Now rescale so that bvalue maps to 0, wvalue maps to maxval. */
X	fprintf(
X	    stderr, "(Remapping %d..%d to %d..%d.)\n", bvalue, wvalue, 0,
X	    maxval );
X	pgm_writepgminit( stdout, cols, rows, maxval );
X	range = wvalue - bvalue;
X	for ( row = 0; row < rows; row++ )
X	    {
X	    for ( col = 0, gP = grays[row]; col < cols; col++, gP++ )
X		{
X		if ( *gP <= bvalue )
X		    *gP = 0;
X		else if ( *gP >= wvalue )
X		    *gP = maxval;
X		else
X		    *gP = ( *gP - bvalue ) * maxval / range;
X		}
X	    pgm_writepgmrow( stdout, grays[row], cols, maxval );
X	    }
X	}
X
X    exit( 0 );
X    }
SHAR_EOF
if test 5154 -ne "`wc -c < 'pgm/pgmnorm.c'`"
then
	echo shar: error transmitting "'pgm/pgmnorm.c'" '(should have been 5154 characters)'
fi
fi # end of overwriting check
if test ! -d 'pgm'
then
	echo shar: creating directory "'pgm'"
	mkdir 'pgm'
fi
echo shar: extracting "'pgm/pgmnorm.1'" '(1382 characters)'
if test -f 'pgm/pgmnorm.1'
then
	echo shar: will not over-write existing file "'pgm/pgmnorm.1'"
else
sed 's/^X//' << \SHAR_EOF > 'pgm/pgmnorm.1'
X.TH pgmnorm 1 "28 February 1989"
X.SH NAME
Xpgmnorm - normalize the contrast in a portable graymap
X.SH SYNOPSIS
Xpgmnorm [-bpercent <n> | -bvalue <n>] [-wpercent <n> | -wvalue] [pgmfile]
X.SH DESCRIPTION
XReads a portable graymap as input.
XNormalizes the contrast by forcing the lightest pixels to white, the
Xdarkest pixels to black, and linearly rescaling the ones in between;
Xand produces a portable graymap as output.
X.PP
XBy default, the darkest 2 percent of all pixels are mapped to black, and
Xthe lightest 1 percent are mapped to white.
XYou can override these percentages by using the -bpercent and -wpercent flags,
Xor you can specify the exact pixel values to be mapped by using the
X-bvalue and -wvalue flags.
XAppropriate numbers for the flags can be gotten from the pgmhist tool.
X.PP
XAll flags can be abbreviated to their shortest unique prefix.
X.SH "SEE ALSO"
Xpgmhist(1), pgm(5)
X.SH AUTHOR
XPartially based on the fbnorm filter in Michael Mauldin's "Fuzzy Pixmap"
Xpackage.
X
XCopyright (C) 1989 by Jef Poskanzer.
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted, provided
Xthat the above copyright notice appear in all copies and that both that
Xcopyright notice and this permission notice appear in supporting
Xdocumentation.  This software is provided "as is" without express or
Ximplied warranty.
SHAR_EOF
if test 1382 -ne "`wc -c < 'pgm/pgmnorm.1'`"
then
	echo shar: error transmitting "'pgm/pgmnorm.1'" '(should have been 1382 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0



More information about the Comp.sources.misc mailing list