[comp.graphics] sun rasterfile filter?

yylu@walsh.harvard.edu (Ya Yan Lu) (05/11/89)

I am looking for a program which transfers the colored 
rasterfiles on SUN workstations to black and white rasterfiles. 
Can someone please give me some point on this? 
Thanks in advance.


*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*
Ya Yan Lu  Office: Harvard Science Center Room 341 (617)495-8477
           Home:   1010 Mass. Ave., Cambridge, MA  (617)547-3340
           e-mail: yylu@zariski.harvard.edu
*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*

greg@bilbo (Greg Wageman) (05/14/89)

In article <1795@husc6.harvard.edu> yylu@zariski.harvard.edu writes:
>I am looking for a program which transfers the colored 
>rasterfiles on SUN workstations to black and white rasterfiles. 
>Can someone please give me some point on this? 

Read the man page for the command "rasfilter8to1".  This command can
be used in a pipe or redirected to a file.  The default is to do
thresholding; if you want dithering you must supply the "-d" flag to
the command.



Longish .signature follows.  Skip now, or don't complain.

Greg Wageman			DOMAIN: greg@sj.ate.slb.com
Schlumberger Technologies	UUCP:   ...!uunet!sjsca4!greg
1601 Technology Drive		BIX:    gwage
San Jose, CA 95110-1397		CIS:    74016,352
(408) 437-5198			GEnie:  G.WAGEMAN
------------------
"Live Free; Die Anyway."
------------------
Opinions expressed herein are solely the responsibility of the author.

falk@sun.Eng.Sun.COM (Ed Falk) (06/01/89)

In article <1795@husc6.harvard.edu>, yylu@walsh.harvard.edu (Ya Yan Lu) writes:
> I am looking for a program which transfers the colored 
> rasterfiles on SUN workstations to black and white rasterfiles. 
> Can someone please give me some point on this? 
> Thanks in advance.
> 

You don't explain what you want.  Did you mean a program to convert a color
image into a greyscale image or did you want a program to convert a
color or greyscale image into a monochrome (1-bit/pixel) image?

At any rate, here are three programs which I wrote on my lunch hour.
"grey.c" converts a color image into a greyscale image.  "odither.c"
converts a color or greyscale image to a monochrome image through
ordered dithering.  "fsdither.c" does the same, but with Floyd-Steinberg
dithering.   All three of these are executed with the command format

	<program> [-ign] [infile [outfile]]

Where "-ign" tells the program to ignore the input colormap annd just
treat the input as grey values.

All three programs are compiled with

	cc -o <program> <program.c> pr_stream.c -lpixrect


#! /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 to create the files:
#	odither.c
#	fsdither.c
#	grey.c
#	ntsc.h
#	pr_stream.c
# This archive created: Wed May 31 19:22:58 PDT 1989 by falk
#
#
export PATH; PATH=/bin:$PATH
#
if test -f odither.c
then
echo shar: will not over-write existing file odither.c
else
echo shar: extracting 'odither.c',     4132 characters
sed 's/^X//' > odither.c <<'SHAR_EOF'
X#include <stdio.h>
X#include <pixrect/pixrect_hs.h>
X#include "ntsc.h"
X
X
X/* 255 has been changed to 254 in this table so that all-white values will
X   appear all-white in the output */
X
Xstatic	int	d16[16][16] = {
X	{  0,192, 48,240, 12,204, 60,252,  3,195, 51,243, 15,207, 63,254},
X	{128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127},
X	{ 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223},
X	{160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95},
X	{  8,200, 56,248,  4,196, 52,244, 11,203, 59,251,  7,199, 55,247},
X	{136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119},
X	{ 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215},
X	{168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87},
X	{  2,194, 50,242, 14,206, 62,254,  1,193, 49,241, 13,205, 61,253},
X	{130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125},
X	{ 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221},
X	{162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93},
X	{ 10,202, 58,250,  6,198, 54,246,  9,201, 57,249,  5,197, 53,245},
X	{138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117},
X	{ 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213},
X	{170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85}} ;
X
Xstatic	char	*usage = "usage: \"odither [-ign] [infile [outfile]]\"\n" ;
X
Xextern	int	errno ;
Xextern	char	*sys_errlist[] ;
X
X
Xmain(argc,argv)
X	int	argc ;
X	char	*argv[] ;
X{
X	char			*infile, *outfile ;
X	struct rasterfile	header ;
X	colormap_t		colormap ;
X	struct pixrect		*pr_load(), *mem_create() ;
X	int			linebytes ;
X	unsigned char		*inline ;
Xregister struct pixrect		*outpic ;
Xregister int			i,j ;
Xregister int			val, v2, oval ;
Xregister int			r,g,b ;
Xregister int			error ;
Xregister unsigned char		*inptr ;
X	int			ignore = 0 ;
X	int			use_cmap ;
X
X	infile = outfile = NULL ;
X
X	while(--argc)
X	{
X	  ++argv ;
X
X	  if( strcmp(*argv,"-ign") == 0 )
X	    ignore = 1 ;
X
X	  else if( !infile )
X	    infile = *argv ;
X
X	  else if( !outfile )
X	    outfile = *argv ;
X
X	  else
X	  {
X	    fprintf(stderr, usage) ;
X	    exit(1) ;
X	  }
X	}
X
X	if( infile != NULL)
X	  if (freopen(infile, "r", stdin) == NULL)
X	  {
X	    fprintf(stderr, "odither: can't open input file %s, %s\n%s",
X		infile,sys_errlist[errno],usage) ;
X	    exit(1) ;
X	  }
X
X	if( outfile != NULL)
X	  if (freopen(outfile, "w", stdout) == NULL)
X	  {
X	    fprintf(stderr, "odither: can't open output file %s, %s\n%s",
X		outfile,sys_errlist[errno],usage) ;
X	    exit(1) ;
X	  }
X
X
X	colormap.type = RMT_NONE ;
X	if( pr_load_header(stdin, &header) != 0  ||
X	    pr_load_colormap(stdin, &header, &colormap) != 0 )
X	{
X	  fprintf(stderr, "error reading rasterfile header\n") ;
X	  exit(1) ;
X	}
X	use_cmap = !ignore && colormap.type == RMT_EQUAL_RGB ;
X
X	linebytes = header.ras_width ;
X	switch(header.ras_depth)
X	{
X	  case 1:
X	    fprintf(stderr, "odither: input is a 1-bit image\n") ;
X	    exit(1) ;
X
X	  case 8: break ;
X	  case 24: linebytes *= 3 ; break ;
X	  case 32: linebytes *= 4 ; break ;
X
X	  default:
X	    fprintf(stderr, "odither: unknown depth %d\n",header.ras_depth) ;
X	    exit(1) ;
X	}
X	linebytes += linebytes % 2 ;
X
X	pr_read_init(&header) ;
X
X	inline = (unsigned char *) malloc(linebytes) ;
X	outpic = mem_create(header.ras_width, header.ras_height, 1) ;
X
X	for(i=0; i<header.ras_height; ++i)
X	{
X	  pr_get_bytes(stdin, &header, linebytes, inline) ;
X	  inptr = inline ;
X	  for(j=0; j<header.ras_width; ++j)
X	  {
X	    switch(header.ras_depth)
X	    {
X	      case 8: r = g = b = *inptr++ ; break ;
X	      case 32: ++inptr ;
X	      case 24: r = *inptr++ ; g = *inptr++ ; b = *inptr++ ; break ;
X	    }
X
X	    if( use_cmap )
X	    {
X	      r = colormap.map[0][r] ;
X	      g = colormap.map[1][g] ;
X	      b = colormap.map[2][b] ;
X	    }
X	    				/* NTSC weights (.3,.59,.11) */
X	    val = (ntscr[r] + ntscg[g] + ntscb[b])/256 ;
X	    v2 = d16[i%16][j%16] ;
X	    oval = val <= v2 ;
X	    if(oval == 1 && val == 255)
X	      fprintf(stderr,"i=%d,j=%d,val=%d,v2=%d,oval=%d\n",
X		i,j,val,v2,oval) ;
X	    pr_put(outpic, j,i, oval) ;
X	   }
X	}
X	pr_dump(outpic, stdout, NULL, RT_STANDARD, 0) ;
X	free(inline) ;
X	exit(0) ;
X}
SHAR_EOF
len=`wc -c < odither.c`
if test $len !=     4132 ; then
echo error: odither.c was $len bytes long, should have been     4132
fi
fi # end of overwriting check
if test -f fsdither.c
then
echo shar: will not over-write existing file fsdither.c
else
echo shar: extracting 'fsdither.c',     4572 characters
sed 's/^X//' > fsdither.c <<'SHAR_EOF'
X#include <stdio.h>
X#include <pixrect/pixrect_hs.h>
X#include "ntsc.h"
X
X
X
Xstatic	char	*usage = "usage: \"fsdither [-ign] [infile [outfile]]\"\n" ;
X
Xextern	int	errno ;
Xextern	char	*sys_errlist[] ;
X
X
Xmain(argc,argv)
X	int	argc ;
X	char	*argv[] ;
X{
X	char			*infile, *outfile ;
X	struct rasterfile	header ;
X	colormap_t		colormap ;
X	struct pixrect		*pr_load(), *mem_create() ;
X	int			linebytes ;
Xregister struct pixrect		*outpic ;
X	int			ignore = 0 ;
X	int			use_cmap ;
X
X	unsigned char	*inline, *inptr ;
X	short		*thisline, *nextline, *tmpptr ;
Xregister short		*thisptr, *nextptr ;
X	int		i,j ;
X	int		imax, jmax ;
X	int		lastline, lastpixel ;
X
X	infile = outfile = NULL ;
X
X	while(--argc)
X	{
X	  ++argv ;
X
X	  if( strcmp(*argv,"-ign") == 0 )
X	    ignore = 1 ;
X
X	  else if( !infile )
X	    infile = *argv ;
X
X	  else if( !outfile )
X	    outfile = *argv ;
X
X	  else
X	  {
X	    fprintf(stderr, usage) ;
X	    exit(1) ;
X	  }
X	}
X
X	if( infile != NULL)
X	  if (freopen(infile, "r", stdin) == NULL)
X	  {
X	    fprintf(stderr, "edither: can't open input file %s, %s\n%s",
X		infile,sys_errlist[errno],usage) ;
X	    exit(1) ;
X	  }
X
X	if( outfile != NULL)
X	  if (freopen(outfile, "w", stdout) == NULL)
X	  {
X	    fprintf(stderr, "edither: can't open output file %s, %s\n%s",
X		outfile,sys_errlist[errno],usage) ;
X	    exit(1) ;
X	  }
X
X
X	colormap.type = RMT_NONE ;
X	if( pr_load_header(stdin, &header) != 0  ||
X	    pr_load_colormap(stdin, &header, &colormap) != 0 )
X	{
X	  fprintf(stderr, "error reading rasterfile header\n") ;
X	  exit(1) ;
X	}
X	use_cmap = !ignore && colormap.type == RMT_EQUAL_RGB ;
X
X	linebytes = header.ras_width ;
X	switch(header.ras_depth)
X	{
X	  case 1:
X	    fprintf(stderr, "edither: input is a 1-bit image\n") ;
X	    exit(1) ;
X
X	  case 8: break ;
X	  case 24: linebytes *= 3 ; break ;
X	  case 32: linebytes *= 4 ; break ;
X
X	  default:
X	    fprintf(stderr, "edither: unknown depth %d\n",header.ras_depth) ;
X	    exit(1) ;
X	}
X	linebytes += linebytes % 2 ;
X
X	pr_read_init(&header) ;
X
X
X
X	imax = header.ras_height - 1 ;
X	jmax = header.ras_width - 1 ;
X
X	outpic = mem_create(header.ras_width, header.ras_height, 1) ;
X	inline = (unsigned char *) malloc( linebytes ) ;
X	thisline = (short *) malloc( header.ras_width * sizeof(short)) ;
X	nextline = (short *) malloc( header.ras_width * sizeof(short)) ;
X
X	/*
X	 * get first line
X	 */
X	pr_get_bytes(stdin, &header, linebytes, inline) ;
X	{
X	  register int r,g,b ;
X	  inptr = inline ;
X	  nextptr = nextline ;
X	  for(j=0; j < header.ras_width; ++j)
X	  {
X	    switch(header.ras_depth)
X	    {
X	      case 8: r = g = b = *inptr++ ; break ;
X	      case 32: ++inptr ;
X	      case 24: r = *inptr++ ; g = *inptr++ ; b = *inptr++ ; break ;
X	    }
X
X	    if( use_cmap )
X	    {
X	      r = colormap.map[0][r] ;
X	      g = colormap.map[1][g] ;
X	      b = colormap.map[2][b] ;
X	    }
X	    				/* NTSC weights (.3,.59,.11) */
X	    *nextptr++ = (ntscr[r] + ntscg[g] + ntscb[b])/256 ;
X	  }
X	}
X
X
X
X	/* loop for all lines in image */
X
X	for(i=0; i < header.ras_height; ++i)
X	{
X	  tmpptr = thisline ;
X	  thisline = nextline ;
X	  nextline = tmpptr ;
X	  lastline = (i == imax) ;
X	  pr_get_bytes(stdin, &header, linebytes, inline) ;
X	  {
X	    register int r,g,b ;
X	    inptr = inline ;
X	    nextptr = nextline ;
X	    for(j=0; j < header.ras_width; ++j)
X	    {
X	      switch(header.ras_depth)
X	      {
X		case 8: r = g = b = *inptr++ ; break ;
X		case 32: ++inptr ;
X		case 24: r = *inptr++ ; g = *inptr++ ; b = *inptr++ ; break ;
X	      }
X
X	      if( use_cmap )
X	      {
X		r = colormap.map[0][r] ;
X		g = colormap.map[1][g] ;
X		b = colormap.map[2][b] ;
X	      }
X	      *nextptr++ = (ntscr[r] + ntscg[g] + ntscb[b])/256 ;
X	    }
X	  }
X
X	  thisptr = thisline ;
X	  nextptr = nextline ;
X
X	  for(j=0; j < header.ras_width ; ++j)
X	  {
X	    register int val, error ;
X
X	    lastpixel = (j == jmax) ;
X
X	    val = *thisptr++ ;
X
X
X#ifdef	COMMENT
X	    if( val < 0 ) val = 0 ;
X	    else if( val > 255 ) val = 255 ;
X#endif	COMMENT
X
X	    if( val < 128 )
X	    {
X	      pr_put(outpic, j,i, 1) ;
X	      error = val ;
X	    }
X	    else
X	    {
X	      pr_put(outpic, j,i, 0) ;
X	      error = val - 255 ;
X	    }
X
X	    if( !lastline )
X	    {
X	      if( j != 0 )
X		nextptr[-1] += error * 3 / 16 ;
X
X	      nextptr[0] += error * 5 / 16 ;
X
X	      if( !lastpixel )
X	      {
X		nextptr[1] += error / 16 ;
X	      }
X	      ++nextptr ;
X	    }
X	    if( !lastpixel )
X	    {
X	      val = error ;
X	      val -= error * 3 / 16 ;
X	      val -= error * 5 / 16 ;
X	      val -= error / 16 ;
X	      *thisptr += val ;
X	    }
X	  }
X	}
X	free(inline) ;
X	free(thisline) ;
X	free(nextline) ;
X
X	pr_dump(outpic, stdout, NULL, RT_STANDARD, 0) ;
X}
SHAR_EOF
len=`wc -c < fsdither.c`
if test $len !=     4572 ; then
echo error: fsdither.c was $len bytes long, should have been     4572
fi
fi # end of overwriting check
if test -f grey.c
then
echo shar: will not over-write existing file grey.c
else
echo shar: extracting 'grey.c',     3147 characters
sed 's/^X//' > grey.c <<'SHAR_EOF'
X#include <stdio.h>
X#include <pixrect/pixrect_hs.h>
X#include "ntsc.h"
X
X
Xstatic	char	*usage = "usage: \"grey [-ign] [ infile [ outfile]]\"\n" ;
X
Xextern	int	errno ;
Xextern	char	*sys_errlist[] ;
X
X
Xmain(argc,argv)
X	int	argc ;
X	char	*argv[] ;
X{
X	char			*infile, *outfile ;
X	struct rasterfile	header, outheader ;
X	colormap_t		colormap, outcolormap ;
X	int			linebytes, outlinebytes ;
X	unsigned char		*inline, *outline ;
X	unsigned char		greyramp[256] ;
Xregister int			i,j ;
Xregister unsigned char		*inptr, *outptr ;
X	int			ignore = 0 ;
X	int			use_cmap ;
X
X
X	infile = outfile = NULL ;
X
X	while(--argc)
X	{
X	  ++argv ;
X
X	  if( strcmp(*argv,"-ign") == 0 )
X	    ignore = 1 ;
X
X	  else if( !infile )
X	    infile = *argv ;
X
X	  else if( !outfile )
X	    outfile = *argv ;
X
X	  else
X	  {
X	    fprintf(stderr, usage) ;
X	    exit(1) ;
X	  }
X	}
X
X	if( infile != NULL)
X	  if (freopen(infile, "r", stdin) == NULL)
X	  {
X	    fprintf(stderr, "grey: can't open input file %s, %s\n%s",
X		infile,sys_errlist[errno],usage) ;
X	    exit(1) ;
X	  }
X
X	if( outfile != NULL)
X	  if (freopen(outfile, "w", stdout) == NULL)
X	  {
X	    fprintf(stderr, "grey: can't open output file %s, %s\n%s",
X		outfile,sys_errlist[errno],usage) ;
X	    exit(1) ;
X	  }
X
X
X	colormap.type = RMT_NONE ;
X	if( pr_load_header(stdin, &header) != 0  ||
X	    pr_load_colormap(stdin, &header, &colormap) != 0 )
X	{
X	  fprintf(stderr, "error reading rasterfile header\n") ;
X	  exit(1) ;
X	}
X	use_cmap = !ignore && colormap.type == RMT_EQUAL_RGB ;
X
X	switch(header.ras_depth)
X	{
X	  case 8: linebytes = header.ras_width ; break ;
X	  case 24: linebytes = header.ras_width*3 ; break ;
X	  case 32: linebytes = header.ras_width*4 ; break ;
X	  default:
X	    fprintf(stderr, "grey: only works with 32, 24 or 8 bit images\n") ;
X	    exit(1) ;
X	}
X	linebytes += linebytes % 2 ;
X	outlinebytes = header.ras_width + header.ras_width % 2 ;
X
X	outheader = header ;
X	outheader.ras_depth = 8 ;
X	outheader.ras_type = RT_STANDARD ;
X	outheader.ras_maptype = RMT_EQUAL_RGB ;
X	outheader.ras_maplength = 256*3 ;
X	outheader.ras_length = outlinebytes * outheader.ras_height ;
X
X	outcolormap.type = RMT_EQUAL_RGB ;
X	outcolormap.length = 256 ;
X	outcolormap.map[0] =
X	outcolormap.map[1] =
X	outcolormap.map[2] = greyramp ;
X
X	for(i=0; i<outcolormap.length; ++i)
X	  greyramp[i] = i ;
X
X	pr_dump_header(stdout, &outheader, &outcolormap) ;
X
X	pr_read_init(&header) ;
X
X	inline = (unsigned char *) malloc(linebytes) ;
X	outline = (unsigned char *) malloc(outlinebytes) ;
X
X	for(i=0; i<outheader.ras_height; ++i)
X	{
X	  pr_get_bytes(stdin, &header, linebytes, inline) ;
X	  inptr = inline ;
X	  outptr = outline ;
X
X	  for(j=0; j<outheader.ras_width; ++j)
X	  {
X	    register int r,g,b ;
X	    switch(header.ras_depth)
X	    {
X	      case 8: r = g = b = *inptr++ ; break ;
X	      case 32: ++inptr ;
X	      case 24: r = *inptr++ ; g = *inptr++ ; b = *inptr++ ; break ;
X	    }
X	    if( use_cmap )
X	    {
X	      r = colormap.map[0][r] ;
X	      g = colormap.map[1][g] ;
X	      b = colormap.map[2][b] ;
X	    }
X	    					/* NTSC weights (.3,.59,.11)*/
X	    *outptr++ = (ntscr[r] + ntscg[g] + ntscb[b])/256 ;
X	  }
X	  fwrite(outline, 1, outlinebytes, stdout) ;
X	}
X	fclose(stdout) ;
X}
SHAR_EOF
len=`wc -c < grey.c`
if test $len !=     3147 ; then
echo error: grey.c was $len bytes long, should have been     3147
fi
fi # end of overwriting check
if test -f ntsc.h
then
echo shar: will not over-write existing file ntsc.h
else
echo shar: extracting 'ntsc.h',     4905 characters
sed 's/^X//' > ntsc.h <<'SHAR_EOF'
Xstatic	unsigned int	ntscr[] = {
X	    0,   77,  153,  230,  306,  383,  459,  536,
X	  612,  689,  765,  842,  919,  995, 1072, 1148,
X	 1225, 1301, 1378, 1454, 1531, 1607, 1684, 1761,
X	 1837, 1914, 1990, 2067, 2143, 2220, 2296, 2373,
X	 2449, 2526, 2602, 2679, 2756, 2832, 2909, 2985,
X	 3062, 3138, 3215, 3291, 3368, 3444, 3521, 3598,
X	 3674, 3751, 3827, 3904, 3980, 4057, 4133, 4210,
X	 4286, 4363, 4440, 4516, 4593, 4669, 4746, 4822,
X	 4899, 4975, 5052, 5128, 5205, 5282, 5358, 5435,
X	 5511, 5588, 5664, 5741, 5817, 5894, 5970, 6047,
X	 6124, 6200, 6277, 6353, 6430, 6506, 6583, 6659,
X	 6736, 6812, 6889, 6966, 7042, 7119, 7195, 7272,
X	 7348, 7425, 7501, 7578, 7654, 7731, 7807, 7884,
X	 7961, 8037, 8114, 8190, 8267, 8343, 8420, 8496,
X	 8573, 8649, 8726, 8803, 8879, 8956, 9032, 9109,
X	 9185, 9262, 9338, 9415, 9491, 9568, 9645, 9721,
X	 9798, 9874, 9951,10027,10104,10180,10257,10333,
X	10410,10487,10563,10640,10716,10793,10869,10946,
X	11022,11099,11175,11252,11329,11405,11482,11558,
X	11635,11711,11788,11864,11941,12017,12094,12170,
X	12247,12324,12400,12477,12553,12630,12706,12783,
X	12859,12936,13012,13089,13166,13242,13319,13395,
X	13472,13548,13625,13701,13778,13854,13931,14008,
X	14084,14161,14237,14314,14390,14467,14543,14620,
X	14696,14773,14850,14926,15003,15079,15156,15232,
X	15309,15385,15462,15538,15615,15692,15768,15845,
X	15921,15998,16074,16151,16227,16304,16380,16457,
X	16534,16610,16687,16763,16840,16916,16993,17069,
X	17146,17222,17299,17375,17452,17529,17605,17682,
X	17758,17835,17911,17988,18064,18141,18217,18294,
X	18371,18447,18524,18600,18677,18753,18830,18906,
X	18983,19059,19136,19213,19289,19366,19442,19519,} ;
Xstatic	unsigned int	ntscg[] = {
X	    0,  150,  301,  451,  601,  751,  902, 1052,
X	 1202, 1352, 1503, 1653, 1803, 1954, 2104, 2254,
X	 2404, 2555, 2705, 2855, 3005, 3156, 3306, 3456,
X	 3607, 3757, 3907, 4057, 4208, 4358, 4508, 4658,
X	 4809, 4959, 5109, 5260, 5410, 5560, 5710, 5861,
X	 6011, 6161, 6311, 6462, 6612, 6762, 6913, 7063,
X	 7213, 7363, 7514, 7664, 7814, 7964, 8115, 8265,
X	 8415, 8566, 8716, 8866, 9016, 9167, 9317, 9467,
X	 9617, 9768, 9918,10068,10218,10369,10519,10669,
X	10820,10970,11120,11270,11421,11571,11721,11871,
X	12022,12172,12322,12473,12623,12773,12923,13074,
X	13224,13374,13524,13675,13825,13975,14126,14276,
X	14426,14576,14727,14877,15027,15177,15328,15478,
X	15628,15779,15929,16079,16229,16380,16530,16680,
X	16830,16981,17131,17281,17432,17582,17732,17882,
X	18033,18183,18333,18483,18634,18784,18934,19085,
X	19235,19385,19535,19686,19836,19986,20136,20287,
X	20437,20587,20738,20888,21038,21188,21339,21489,
X	21639,21789,21940,22090,22240,22391,22541,22691,
X	22841,22992,23142,23292,23442,23593,23743,23893,
X	24044,24194,24344,24494,24645,24795,24945,25095,
X	25246,25396,25546,25697,25847,25997,26147,26298,
X	26448,26598,26748,26899,27049,27199,27350,27500,
X	27650,27800,27951,28101,28251,28401,28552,28702,
X	28852,29002,29153,29303,29453,29604,29754,29904,
X	30054,30205,30355,30505,30655,30806,30956,31106,
X	31257,31407,31557,31707,31858,32008,32158,32308,
X	32459,32609,32759,32910,33060,33210,33360,33511,
X	33661,33811,33961,34112,34262,34412,34563,34713,
X	34863,35013,35164,35314,35464,35614,35765,35915,
X	36065,36216,36366,36516,36666,36817,36967,37117,
X	37267,37418,37568,37718,37869,38019,38169,38319,} ;
Xstatic	unsigned int	ntscb[] = {
X	    0,   29,   58,   88,  117,  146,  175,  204,
X	  233,  263,  292,  321,  350,  379,  409,  438,
X	  467,  496,  525,  554,  584,  613,  642,  671,
X	  700,  730,  759,  788,  817,  846,  876,  905,
X	  934,  963,  992, 1021, 1051, 1080, 1109, 1138,
X	 1167, 1197, 1226, 1255, 1284, 1313, 1342, 1372,
X	 1401, 1430, 1459, 1488, 1518, 1547, 1576, 1605,
X	 1634, 1663, 1693, 1722, 1751, 1780, 1809, 1839,
X	 1868, 1897, 1926, 1955, 1985, 2014, 2043, 2072,
X	 2101, 2130, 2160, 2189, 2218, 2247, 2276, 2306,
X	 2335, 2364, 2393, 2422, 2451, 2481, 2510, 2539,
X	 2568, 2597, 2627, 2656, 2685, 2714, 2743, 2772,
X	 2802, 2831, 2860, 2889, 2918, 2948, 2977, 3006,
X	 3035, 3064, 3094, 3123, 3152, 3181, 3210, 3239,
X	 3269, 3298, 3327, 3356, 3385, 3415, 3444, 3473,
X	 3502, 3531, 3560, 3590, 3619, 3648, 3677, 3706,
X	 3736, 3765, 3794, 3823, 3852, 3881, 3911, 3940,
X	 3969, 3998, 4027, 4057, 4086, 4115, 4144, 4173,
X	 4202, 4232, 4261, 4290, 4319, 4348, 4378, 4407,
X	 4436, 4465, 4494, 4524, 4553, 4582, 4611, 4640,
X	 4669, 4699, 4728, 4757, 4786, 4815, 4845, 4874,
X	 4903, 4932, 4961, 4990, 5020, 5049, 5078, 5107,
X	 5136, 5166, 5195, 5224, 5253, 5282, 5311, 5341,
X	 5370, 5399, 5428, 5457, 5487, 5516, 5545, 5574,
X	 5603, 5633, 5662, 5691, 5720, 5749, 5778, 5808,
X	 5837, 5866, 5895, 5924, 5954, 5983, 6012, 6041,
X	 6070, 6099, 6129, 6158, 6187, 6216, 6245, 6275,
X	 6304, 6333, 6362, 6391, 6420, 6450, 6479, 6508,
X	 6537, 6566, 6596, 6625, 6654, 6683, 6712, 6742,
X	 6771, 6800, 6829, 6858, 6887, 6917, 6946, 6975,
X	 7004, 7033, 7063, 7092, 7121, 7150, 7179, 7208,
X	 7238, 7267, 7296, 7325, 7354, 7384, 7413, 7442,} ;
SHAR_EOF
len=`wc -c < ntsc.h`
if test $len !=     4905 ; then
echo error: ntsc.h was $len bytes long, should have been     4905
fi
fi # end of overwriting check
if test -f pr_stream.c
then
echo shar: will not over-write existing file pr_stream.c
else
echo shar: extracting 'pr_stream.c',     3512 characters
sed 's/^X//' > pr_stream.c <<'SHAR_EOF'
X/* pr_stream routines:  allow images to be read in stream
X * fashion rather than loading them into memory.
X *
X * These routines are used in conjunction with the pr_io routines.  It
X * is the application's responsibility to read the header and
X * colormaps
X *
X *
X * routines:
X *
X * pr_read_init(header)
X *	struct rasterfile *header ;
X *
X *	sets up to read an image
X *
X *
X * pr_get_bytes(file, header, len, buffer)
X *	FILE		*file ;
X *	struct rasterfile *header ;
X *	int		len ;
X *	char		*buffer ;
X *
X *	read data from input.  len should be a multiple of 3 for 24-bit
X *	images and a multiple of 4 for 32-bit images.
X *
X *
X * int
X * pr_get_byte(file, header)
X *	FILE		*file ;
X *	struct rasterfile *header ;
X *
X *	read and return one byte from input
X *
X */
X
X#include <stdio.h>
X#include <sys/types.h>
X#include <pixrect/pixrect.h>
X#include <pixrect/memvar.h>
X#include <pixrect/pr_io.h>
X#include <rasterfile.h>
X
X#define	ESCAPE	128
X
X
X
Xstatic	unsigned char	icvalue ;
Xstatic	int		icount ;
Xstatic	unsigned char	icalpha, icblue, icgreen, icred ;
X
X
X
Xint
Xpr_read_init(header)
X	struct rasterfile	*header ;
X{
X	icount = 0 ;
X}
X
X
X
Xint
Xpr_get_bytes(file, header, len, buffer)
Xregister FILE			*file ;
Xregister struct rasterfile	*header ;
Xregister int			len ;
Xregister unsigned char		*buffer ;
X{
X	if(header->ras_type != RT_BYTE_ENCODED)
X	  return( fread(buffer, 1, len, file) ) ;
X
X	else
X	  switch( header->ras_depth )
X	  {
X	    case 1:
X	    case 8:
X	      while( --len >= 0)
X	      {
X		if(icount > 0)
X		{
X		  --icount ;
X		  *buffer++ = icvalue ;
X		}
X		else
X		{
X		  if( (icvalue = getc(file)) != ESCAPE )
X		    *buffer++ = icvalue ;
X		  else
X		  {
X		    if( (icount = getc(file)) == 0 )
X		      *buffer++ = ESCAPE ;
X		    else
X		    {
X		      *buffer++ = icvalue = getc(file) ;
X		    }
X		  }
X		}
X	      }
X	      break ;
X	    
X	    case 24:
X	      len /= 3 ;
X	      while( len-- > 0 )
X	      {
X		if(icount > 0)
X		{
X		  --icount ;
X		  *buffer++ = icred ;
X		  *buffer++ = icgreen ;
X		  *buffer++ = icblue ;
X		}
X		else
X		{
X		  if( (icvalue = getc(file)) != ESCAPE )
X		  {
X		    *buffer++ = icvalue ;
X		    *buffer++ = getc(file) ;
X		    *buffer++ = getc(file) ;
X		  }
X		  else
X		  {
X		    if( (icount = getc(file)) == 0 )
X		    {
X		      *buffer++ = ESCAPE ;
X		      *buffer++ = getc(file) ;
X		      *buffer++ = getc(file) ;
X		    }
X		    else
X		    {
X		      *buffer++ = icred = getc(file) ;
X		      *buffer++ = icgreen = getc(file) ;
X		      *buffer++ = icblue = getc(file) ;
X		    }
X		  }
X		}
X	      }
X	      break ;
X
X	    case 32:
X	      len /= 4 ;
X	      while( len-- > 0 )
X	      {
X		if(icount > 0)
X		{
X		  --icount ;
X		  *buffer++ = icalpha ;
X		  *buffer++ = icred ;
X		  *buffer++ = icgreen ;
X		  *buffer++ = icblue ;
X		}
X		else
X		{
X		  if( (icvalue = getc(file)) != ESCAPE )
X		  {
X		    *buffer++ = icvalue ;
X		    *buffer++ = getc(file) ;
X		    *buffer++ = getc(file) ;
X		    *buffer++ = getc(file) ;
X		  }
X		  else
X		  {
X		    if( (icount = getc(file)) == 0 )
X		    {
X		      *buffer++ = ESCAPE ;
X		      *buffer++ = getc(file) ;
X		      *buffer++ = getc(file) ;
X		      *buffer++ = getc(file) ;
X		    }
X		    else
X		    {
X		      *buffer++ = icalpha = getc(file) ;
X		      *buffer++ = icred = getc(file) ;
X		      *buffer++ = icgreen = getc(file) ;
X		      *buffer++ = icblue = getc(file) ;
X		    }
X		  }
X		}
X	      }
X	      break ;
X	  }
X
X
X
X	return 0 ;
X}
X
X
X
Xunsigned char
Xpr_get_byte(file, header)
X	FILE			*file ;
X	struct rasterfile	*header ;
X{
X	unsigned char		rval ;
X
X	pr_get_bytes(file, header, 1, &rval) ;
X	return( rval ) ;
X}
SHAR_EOF
len=`wc -c < pr_stream.c`
if test $len !=     3512 ; then
echo error: pr_stream.c was $len bytes long, should have been     3512
fi
fi # end of overwriting check
exit 0
-- 
		-ed falk, sun microsystems
		 sun!falk, falk@sun.com
		 card-carrying ACLU member.