v13i030: ImageMagick - Graphics display programs, Part14/21

cristy at dupont.com cristy at dupont.com
Fri May 24 13:19:36 AEST 1991


Submitted-by: cristy at dupont.com
Posting-number: Volume 13, Issue 30
Archive-name: imagemagic/part14

#!/bin/sh
# this is img.14 (part 14 of ImageMagick)
# do not concatenate these parts, unpack them in order with /bin/sh
# file ImageMagick/filters/Imakefile continued
#
if test ! -r _shar_seq_.tmp; then
	echo 'Please unpack part 1 first!'
	exit 1
fi
(read Scheck
 if test "$Scheck" != 14; then
	echo Please unpack part "$Scheck" next!
	exit 1
 else
	exit 0
 fi
) < _shar_seq_.tmp || exit 1
if test ! -f _shar_wnt_.tmp; then
	echo 'x - still skipping ImageMagick/filters/Imakefile'
else
echo 'x - continuing file ImageMagick/filters/Imakefile'
sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/filters/Imakefile' &&
EXTRA_LIBRARIES= -lX11 -lm
PPM_LIBRARIES= /usr/local/lib/libppm.a /usr/local/lib/libpgm.a  \
X  /usr/local/lib/libpbm.a
TIFF_LIBRARIES= /usr/local/lib/libtiff.a
X
AVStoMIFFSources= AVStoMIFF.c
AVStoMIFFObjects= AVStoMIFF.o image.o compress.o
GIFtoMIFFSources= GIFtoMIFF.c
GIFtoMIFFObjects= GIFtoMIFF.o image.o compress.o
GRAYtoMIFFSources= GRAYtoMIFF.c
GRAYtoMIFFObjects= GRAYtoMIFF.o image.o compress.o
MIFFtoAVSSources= MIFFtoAVS.c
MIFFtoAVSObjects= MIFFtoAVS.o image.o compress.o
MIFFtoGIFSources= MIFFtoGIF.c
MIFFtoGIFObjects= MIFFtoGIF.o image.o kolb.o quantize.o compress.o
MIFFtoGRAYSources= MIFFtoGRAY.c
MIFFtoGRAYObjects= MIFFtoGRAY.o image.o kolb.o quantize.o compress.o
MIFFtoPPMSources= MIFFtoPPM.c
MIFFtoPPMObjects= MIFFtoPPM.o image.o compress.o
MIFFtoRGBSources= MIFFtoRGB.c
MIFFtoRGBObjects= MIFFtoRGB.o image.o compress.o
MIFFtoSUNSources= MIFFtoSUN.c
MIFFtoSUNObjects= MIFFtoSUN.o image.o compress.o
MIFFtoTIFFSources= MIFFtoTIFF.c
MIFFtoTIFFObjects= MIFFtoTIFF.o image.o compress.o
MIFFtoXBMSources= MIFFtoXBM.c
MIFFtoXBMObjects= MIFFtoXBM.o image.o kolb.o quantize.o compress.o
MIFFtoXWDSources= MIFFtoXWD.c
MIFFtoXWDObjects= MIFFtoXWD.o image.o compress.o
MTVtoMIFFSources= MTVtoMIFF.c
MTVtoMIFFObjects= MTVtoMIFF.o image.o compress.o
SUNtoMIFFSources= SUNtoMIFF.c
SUNtoMIFFObjects= SUNtoMIFF.o image.o compress.o
RGBtoMIFFSources= RGBtoMIFF.c
RGBtoMIFFObjects= RGBtoMIFF.o image.o compress.o
PPMtoMIFFSources= PPMtoMIFF.c
PPMtoMIFFObjects= PPMtoMIFF.o image.o kolb.o quantize.o colors.o compress.o
TIFFtoMIFFSources= TIFFtoMIFF.c
TIFFtoMIFFObjects= TIFFtoMIFF.o image.o kolb.o quantize.o compress.o
XXBMtoMIFFSources= XBMtoMIFF.c
XXBMtoMIFFObjects= XBMtoMIFF.o image.o compress.o
XXWDtoMIFFSources= XWDtoMIFF.c
XXWDtoMIFFObjects= XWDtoMIFF.o image.o compress.o
X
PROGRAMS= AVStoMIFF MIFFtoAVS GIFtoMIFF MIFFtoGIF GRAYtoMIFF MIFFtoGRAY  \
X  MTVtoMIFF RGBtoMIFF MIFFtoRGB SUNtoMIFF MIFFtoSUN XBMtoMIFF MIFFtoXBM  \
X  XWDtoMIFF MIFFtoXWD PPMtoMIFF MIFFtoPPM TIFFtoMIFF MIFFtoTIFF
X
AllTarget($(PROGRAMS))
X
NormalProgramTarget(AVStoMIFF,$(AVStoMIFFObjects), , , )
InstallProgram(AVStoMIFF,$(BINDIR))
NormalProgramTarget(MIFFtoAVS,$(MIFFtoAVSObjects), , , )
InstallProgram(MIFFtoAVS,$(BINDIR))
NormalProgramTarget(GIFtoMIFF,$(GIFtoMIFFObjects), , , )
InstallProgram(GIFtoMIFF,$(BINDIR))
NormalProgramTarget(MIFFtoGIF,$(MIFFtoGIFObjects), , , )
InstallProgram(MIFFtoGIF,$(BINDIR))
NormalProgramTarget(GRAYtoMIFF,$(GRAYtoMIFFObjects), , , )
InstallProgram(GRAYtoMIFF,$(BINDIR))
NormalProgramTarget(MIFFtoGRAY,$(MIFFtoGRAYObjects), , , )
InstallProgram(MIFFtoGRAY,$(BINDIR))
NormalProgramTarget(MTVtoMIFF,$(MTVtoMIFFObjects), , , )
InstallProgram(MTVtoMIFF,$(BINDIR))
NormalProgramTarget(RGBtoMIFF,$(RGBtoMIFFObjects), , , )
InstallProgram(RGBtoMIFF,$(BINDIR))
NormalProgramTarget(MIFFtoRGB,$(MIFFtoRGBObjects), , , )
InstallProgram(MIFFtoRGB,$(BINDIR))
NormalProgramTarget(SUNtoMIFF,$(SUNtoMIFFObjects), , , )
InstallProgram(SUNtoMIFF,$(BINDIR))
NormalProgramTarget(MIFFtoSUN,$(MIFFtoSUNObjects), , , )
InstallProgram(MIFFtoSUN,$(BINDIR))
NormalProgramTarget(XBMtoMIFF,$(XBMtoMIFFObjects), , , )
InstallProgram(XBMtoMIFF,$(BINDIR))
NormalProgramTarget(MIFFtoXBM,$(MIFFtoXBMObjects), , , )
InstallProgram(MIFFtoXBM,$(BINDIR))
NormalProgramTarget(XWDtoMIFF,$(XWDtoMIFFObjects), , , )
InstallProgram(XWDtoMIFF,$(BINDIR))
NormalProgramTarget(MIFFtoXWD,$(MIFFtoXWDObjects), , , )
InstallProgram(MIFFtoXWD,$(BINDIR))
NormalProgramTarget(PPMtoMIFF,$(PPMtoMIFFObjects), ,$(PPM_LIBRARIES), )
InstallProgram(PPMtoMIFF,$(BINDIR))
NormalProgramTarget(MIFFtoPPM,$(MIFFtoPPMObjects), ,$(PPM_LIBRARIES), )
InstallProgram(MIFFtoPPM,$(BINDIR))
NormalProgramTarget(TIFFtoMIFF,$(TIFFtoMIFFObjects), ,$(TIFF_LIBRARIES), )
InstallProgram(TIFFtoMIFF,$(BINDIR))
NormalProgramTarget(MIFFtoTIFF,$(MIFFtoTIFFObjects), ,$(TIFF_LIBRARIES), )
InstallProgram(MIFFtoTIFF,$(BINDIR))
DependTarget()
X
image.o:
X	$(CC) $(CFLAGS) -c ../image.c
X
kolb.o:
X	$(CC) $(CFLAGS) -c ../kolb.c
X
quantize.o:
X	$(CC) $(CFLAGS) -c ../quantize.c
X
colors.o:
X	$(CC) $(CFLAGS) -c ../colors.c
X
compress.o:
X	$(CC) $(CFLAGS) -c ../compress.c
SHAR_EOF
echo 'File ImageMagick/filters/Imakefile is complete' &&
chmod 0755 ImageMagick/filters/Imakefile ||
echo 'restore of ImageMagick/filters/Imakefile failed'
Wc_c="`wc -c < 'ImageMagick/filters/Imakefile'`"
test 4132 -eq "$Wc_c" ||
	echo 'ImageMagick/filters/Imakefile: original size 4132, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ImageMagick/filters/MIFFtoXBM.c ==============
if test -f 'ImageMagick/filters/MIFFtoXBM.c' -a X"$1" != X"-c"; then
	echo 'x - skipping ImageMagick/filters/MIFFtoXBM.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ImageMagick/filters/MIFFtoXBM.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/MIFFtoXBM.c' &&
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%                 EEEEE  X   X  PPPP    OOO   RRRR    TTTTT                   %
%                 E       X X   P   P  O   O  R   R     T                     %
%                 EEE      X    PPPP   O   O  RRRR      T                     %
%                 E       X X   P      O   O  R R       T                     %
%                 EEEEE  X   X  P       OOO   R  R      T                     %
%                                                                             %
%                                                                             %
%                   Export MIFF image to a X bitmap format.                   %
%                                                                             %
%                                                                             %
%                                                                             %
%                           Software Design                                   %
%                             John Cristy                                     %
%                            January  1991                                    %
%                                                                             %
%                                                                             %
%  Copyright 1991 E. I. Dupont de Nemours & Company                           %
%                                                                             %
%  Permission to use, copy, modify, distribute, and sell this software and    %
%  its documentation for any purpose is hereby granted without fee,           %
%  provided that the above Copyright notice appear in all copies and that     %
%  both that Copyright notice and this permission notice appear in            %
%  supporting documentation, and that the name of E. I. Dupont de Nemours     %
%  & Company not be used in advertising or publicity pertaining to            %
%  distribution of the software without specific, written prior               %
%  permission.  E. I. Dupont de Nemours & Company makes no representations    %
%  about the suitability of this software for any purpose.  It is provided    %
%  "as is" without express or implied warranty.                               %
%                                                                             %
%  E. I. Dupont de Nemours & Company disclaims all warranties with regard     %
%  to this software, including all implied warranties of merchantability      %
%  and fitness, in no event shall E. I. Dupont de Nemours & Company be        %
%  liable for any special, indirect or consequential damages or any           %
%  damages whatsoever resulting from loss of use, data or profits, whether    %
%  in an action of contract, negligence or other tortious action, arising     %
%  out of or in connection with the use or performance of this software.      %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Command syntax:
%
%  export image.miff image.xbm
%
%  Specify 'image.miff' as '-' for standard input.  
%  Specify 'image.xbm' as '-' for standard output.
%
%
*/
X
#include <string.h>
#include "display.h"
#include "image.h"
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   E r r o r                                                                 %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Function Error displays an error message and then terminates the program.
%
%  The format of the Error routine is:
%
%      Error(message,qualifier)
%
%  A description of each parameter follows:
%
%    o message:  Specifies the message to display before terminating the
%      program.
%
%    o qualifier:  Specifies any qualifier to the message.
%
%
*/
void Error(message,qualifier)
char
X  *message,
X  *qualifier;
{
X  (void) fprintf(stderr,"%s: %s",application_name,message); 
X  if (qualifier != (char *) NULL)
X    (void) fprintf(stderr," %s",qualifier);
X  (void) fprintf(stderr,".\n");
X  exit(1);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   U s a g e                                                                 %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Procedure Usage displays the program usage;
%
%  The format of the Usage routine is:
%
%      Usage(message)
%
%  A description of each parameter follows:
%
%    message:  Specifies a specific message to display to the user.
%
*/
static void Usage(message)
char
X  *message;
{
X  if (message != (char *) NULL)
X    (void) fprintf(stderr,"Can't continue, %s\n\n",message);
X  (void) fprintf(stderr,"Usage: %s image.miff image.xbm\n\n",application_name);
X  (void) fprintf(stderr,"Specify 'image.miff' as '-' for standard input.\n");
X  (void) fprintf(stderr,"Specify 'image.xbm' as '-' for standard output.\n");
X  exit(1);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   W r i t e X B M I m a g e                                                 %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Procedure WriteXBMImage writes an image to a file on disk in X
%  bitmap format.
%
%  The format of the WriteXBMImage routine is:
%
%      WriteXBMImage(image)
%
%  A description of each parameter follows.
%
%    o image:  A pointer to a Image structure.
%
%
*/
static void WriteXBMImage(image)
Image
X  *image;
{
X  char
X    name[256];
X
X  register int
X    i,
X    j,
X    x;
X
X  register char
X    *q;
X
X  register RunlengthPacket
X    *p;
X
X  register unsigned char
X    bit,
X    byte;
X
X  register unsigned short
X    foreground_pixel;
X
X  unsigned int
X    count;
X
X  /*
X    Open output image file.
X  */
X  if (*image->filename == '-')
X    image->file=stdout;
X  else
X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
X      image->file=fopen(image->filename,"w");
X    else
X      {
X        char
X          command[256];
X
X        /*
X          Image file is compressed-- uncompress it.
X        */
X        (void) sprintf(command,"compress -c > %s",image->filename);
X        image->file=(FILE *) popen(command,"w");
X      }
X  if (image->file == (FILE *) NULL)
X    Error("unable to open file",image->filename);
X  /*
X    Write X bitmap header.
X  */
X  (void) strcpy(name,image->filename);
X  q=strchr(name,'.');
X  if (q)
X    *q=(char) NULL;
X  (void) fprintf(image->file,"#define %s_width %d\n",name,image->columns);
X  (void) fprintf(image->file,"#define %s_height %d\n",name,image->rows);
X  (void) fprintf(image->file,"static char %s_bits[] = {\n",name);
X  (void) fprintf(image->file," ");
X  /*
X    Convert MIFF to monochrome.
X  */
X  (void) GrayImage(image);
X  QuantizeImage(image,2,0,True,True);
X  /*
X    Convert MIFF to X bitmap pixels.
X  */
X  p=image->pixels;
X  foreground_pixel=(Intensity(image->colormap[0]) > 
X    Intensity(image->colormap[1]) ? 0 : 1);
X  bit=0;
X  byte=0;
X  count=0;
X  x=0;
X  (void) fprintf(image->file," ");
X  for (i=0; i < image->packets; i++)
X  {
X    for (j=0; j <= p->length; j++)
X    {
X      byte>>=1;
X      if (p->index == foreground_pixel)
X        byte|=0x80;
X      bit++;
X      if (bit == 8)
X        {
X          /*
X            Write a bitmap byte to the image file.
X          */
X          (void) fprintf(image->file,"0x%02x, ",~byte & 0xff);
X          count++;
X          if (count == 12)
X            {
X              (void) fprintf(image->file,"\n  ");
X              count=0;
X            };
X          bit=0;
X          byte=0;
X        }
X      x++;
X      if (x == image->columns)
X        {
X          if (bit > 0)
X            {
X              /*
X                Write a bitmap byte to the image file.
X              */
X              byte>>=(8-bit);
X              (void) fprintf(image->file,"0x%02x, ",~byte & 0xff);
X              count++;
X              if (count == 12)
X                {
X                  (void) fprintf(image->file,"\n  ");
X                  count=0;
X                };
X              bit=0;
X              byte=0;
X            };
X          x=0;
X        }
X    }
X    p++;
X  }
X  fprintf(image->file,"};\n");
X  if (image->file != stdin)
X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
X      (void) fclose(image->file);
X    else
X      (void) pclose(image->file);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%    M a i n                                                                  %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
int main(argc,argv)
int
X  argc;
X
char
X  *argv[];
{
X  Image
X    *image;
X
X  application_name=argv[0];
X  if (argc < 3)
X    Usage((char *) NULL);
X  image=ReadImage(argv[1]);
X  if (image == (Image *) NULL)
X    exit(1);
X  (void) strcpy(image->filename,argv[2]);
X  WriteXBMImage(image);
X  (void) fprintf(stderr,"%s=> %s  %dx%d\n",argv[1],argv[2],image->columns,
X    image->rows);
X  return(False);
}
SHAR_EOF
chmod 0755 ImageMagick/filters/MIFFtoXBM.c ||
echo 'restore of ImageMagick/filters/MIFFtoXBM.c failed'
Wc_c="`wc -c < 'ImageMagick/filters/MIFFtoXBM.c'`"
test 11243 -eq "$Wc_c" ||
	echo 'ImageMagick/filters/MIFFtoXBM.c: original size 11243, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ImageMagick/filters/XBMtoMIFF.c ==============
if test -f 'ImageMagick/filters/XBMtoMIFF.c' -a X"$1" != X"-c"; then
	echo 'x - skipping ImageMagick/filters/XBMtoMIFF.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ImageMagick/filters/XBMtoMIFF.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/XBMtoMIFF.c' &&
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%                 IIIII  M   M  PPPP    OOO   RRRR    TTTTT                   %
%                   I    MM MM  P   P  O   O  R   R     T                     %
%                   I    M M M  PPPP   O   O  RRRR      T                     %
%                   I    M   M  P      O   O  R R       T                     %
%                 IIIII  M   M  P       OOO   R  R      T                     % 
%                                                                             %
%                                                                             %
%                  Import X bitmap image to a MIFF format.                    %
%                                                                             %
%                                                                             %
%                                                                             %
%                           Software Design                                   %
%                             John Cristy                                     %
%                            January  1991                                    %
%                                                                             %
%                                                                             %
%  Copyright 1991 E. I. Dupont de Nemours & Company                           %
%                                                                             %
%  Permission to use, copy, modify, distribute, and sell this software and    %
%  its documentation for any purpose is hereby granted without fee,           %
%  provided that the above Copyright notice appear in all copies and that     %
%  both that Copyright notice and this permission notice appear in            %
%  supporting documentation, and that the name of E. I. Dupont de Nemours     %
%  & Company not be used in advertising or publicity pertaining to            %
%  distribution of the software without specific, written prior               %
%  permission.  E. I. Dupont de Nemours & Company makes no representations    %
%  about the suitability of this software for any purpose.  It is provided    %
%  "as is" without express or implied warranty.                               %
%                                                                             %
%  E. I. Dupont de Nemours & Company disclaims all warranties with regard     %
%  to this software, including all implied warranties of merchantability      %
%  and fitness, in no event shall E. I. Dupont de Nemours & Company be        %
%  liable for any special, indirect or consequential damages or any           %
%  damages whatsoever resulting from loss of use, data or profits, whether    %
%  in an action of contract, negligence or other tortious action, arising     %
%  out of or in connection with the use or performance of this software.      %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
%  Command syntax:
%
%  import [-scene #] image.xbm image.miff
%  
%  Specify 'image.xbm' as '-' for standard input.  
%  Specify 'image.miff' as '-' for standard output.
%  
%
*/
X
#include <string.h>
#include "display.h"
#include "image.h"
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   E r r o r                                                                 %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Function Error displays an error message and then terminates the program.
%
%  The format of the Error routine is:
%
%      Error(message,qualifier)
%
%  A description of each parameter follows:
%
%    o message:  Specifies the message to display before terminating the
%      program.
%
%    o qualifier:  Specifies any qualifier to the message.
%
%
*/
void Error(message,qualifier)
char
X  *message,
X  *qualifier;
{
X  (void) fprintf(stderr,"%s: %s",application_name,message); 
X  if (qualifier != (char *) NULL)
X    (void) fprintf(stderr," %s",qualifier);
X  (void) fprintf(stderr,".\n");
X  exit(1);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%  R e a d X B M I m a g e                                                    %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Function ReadImage reads an image file and returns it.  It allocates the 
%  memory necessary for the new Image structure and returns a pointer to the 
%  new image.
%
%  The format of the ReadImage routine is:
%
%      image=ReadImage(filename)
%
%  A description of each parameter follows:
%
%    o image:  Function ReadImage returns a pointer to the image after 
%      reading.  A null image is returned if there is a a memory shortage or 
%      if the image cannot be read.
%
%    o filename:  Specifies the name of the image to read.
%
%
*/
static Image *ReadXBMImage(filename)
char
X  *filename;
{
#define MaxLineLength  256
X
X  char
X    data[MaxLineLength];
X
X  Image
X    *image;
X
X  int
X    byte;
X
X  register int
X    x,
X    y;
X
X  register RunlengthPacket
X    *p;
X
X  register unsigned char
X    bit,
X    blue,
X    green,
X    red;
X
X  register unsigned short
X    index;
X
X  unsigned int
X    value;
X
X  /*
X    Allocate image structure.
X  */
X  image=(Image *) malloc(sizeof(Image));
X  if (image == (Image *) NULL)
X    Error("memory allocation error",(char *) NULL);
X  /*
X    Initialize Image structure.
X  */
X  image->id=UnknownId;
X  image->class=PseudoClass;
X  image->compression=RunlengthEncodedCompression;
X  image->columns=0;
X  image->rows=0;
X  image->packets=0;
X  image->colors=0;
X  image->scene=0;
X  image->colormap=(ColorPacket *) NULL;
X  image->pixels=(RunlengthPacket *) NULL;
X  image->comments=(char *) NULL;
X  /*
X    Open image file.
X  */
X  (void) strcpy(image->filename,filename);
X  if (*image->filename == '-')
X    image->file=stdin;
X  else
X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
X      image->file=fopen(image->filename,"r");
X    else
X      {
X        char
X          command[256];
X
X        /*
X          Image file is compressed-- uncompress it.
X        */
X        (void) sprintf(command,"uncompress -c %s",image->filename);
X        image->file=(FILE *) popen(command,"r");
X      }
X  if (image->file == (FILE *) NULL)
X    Error("unable to open file",image->filename);
X  /*
X    Read X bitmap header.
X  */
X  while (!feof(image->file))
X  {
X    (void) fgets(data,MaxLineLength,image->file);
X    if (sscanf(data,"#define %*32[a-zA-Z0-9]_width %d",&value) == 1)
X      image->columns=value;
X    if (sscanf(data,"#define %*32[a-zA-Z0-9]_height %d",&value) == 1)
X      image->rows=value;
X    if (sscanf(data,"%*[^#] char"))
X      break;
X  }
X  if ((image->columns == 0) || (image->rows == 0))
X    Error("XBM file is not in the correct format",image->filename);
X  /*
X    Create image.
X  */
X  image->pixels=(RunlengthPacket *) 
X    malloc(image->columns*image->rows*sizeof(RunlengthPacket));
X  if (image->pixels == (RunlengthPacket *) NULL)
X    Error("memory allocation error",(char *) NULL);
X  /*
X    Create colormap.
X  */
X  image->colors=2;
X  image->colormap=(ColorPacket *) malloc(image->colors*sizeof(ColorPacket));
X  if (image->colormap == (ColorPacket *) NULL)
X    Error("memory allocation error",(char *) NULL);
X  image->colormap[0].red=0;
X  image->colormap[0].green=0;
X  image->colormap[0].blue=0;
X  image->colormap[1].red=255;
X  image->colormap[1].green=255;
X  image->colormap[1].blue=255;
X  /*
X    Initial image comment.
X  */
X  image->comments=(char *) malloc((unsigned int) strlen(image->filename)+256);
X  if (image->comments == (char *) NULL)
X    Error("unable to allocate memory",(char *) NULL);
X  (void) sprintf(image->comments,"\n  Imported from X11 bitmap file:  %s\n\0",
X    image->filename);
X  /*
X    Convert X bitmap image to runlength-encoded packets.
X  */
X  image->packets=0;
X  p=image->pixels;
X  p->length=MaxRunlength;
X  for (y=0; y < image->rows; y++)
X  {
X    bit=0;
X    for (x=0; x < image->columns; x++)
X    {
X      if (bit == 0)
X        (void) fscanf(image->file,"%i,",&byte);
X      index=(byte & 0x01) ? 0 : 1;
X      byte>>=1;
X      red=image->colormap[index].red;
X      green=image->colormap[index].green;
X      blue=image->colormap[index].blue;
X      if ((red == p->red) && (green == p->green) && (blue == p->blue) &&
X          (p->length < MaxRunlength))
X        p->length++;
X      else
X        {
X          if (image->packets > 0)
X            p++;
X          image->packets++;
X          p->red=red;
X          p->green=green;
X          p->blue=blue;
X          p->index=index;
X          p->length=0;
X        }
X      bit++;
X      if (bit == 8)
X        bit=0;
X    }
X  }
X  if (image->file != stdin)
X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
X      (void) fclose(image->file);
X    else
X      (void) pclose(image->file);
X  if (image->packets > ((image->columns*image->rows*3) >> 2))
X    image->compression=NoCompression;
X  image->pixels=(RunlengthPacket *)
X    realloc((char *) image->pixels,image->packets*sizeof(RunlengthPacket));
X  return(image);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   U s a g e                                                                 %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Function Usage displays the program usage;
%
%  The format of the Usage routine is:
%
%      Usage(message)
%
%  A description of each parameter follows:
%
%    message:  Specifies a specific message to display to the user.
%
*/
static void Usage(message)
char
X  *message;
{
X  if (message != (char *) NULL)
X    (void) fprintf(stderr,"Can't continue, %s\n\n",message);
X  (void) fprintf(stderr,
X    "Usage: %s [-scene] width height image.xbm image.miff\n",application_name);
X  (void) fprintf(stderr,"\nSpecify 'image.xbm' as '-' for standard input.\n");
X  (void) fprintf(stderr,"Specify 'image.miff' as '-' for standard output.\n");
X  exit(1);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%  M a i n                                                                    %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
int main(argc,argv)
int
X  argc;
X   
char
X  *argv[];
{
X  char
X    filename[256];
X
X  Image
X    *image;
X
X  int
X    i;
X
X  unsigned int
X    scene;
X
X  /*
X    Initialize program variables.
X  */
X  application_name=argv[0];
X  i=1;
X  scene=0;
X  if (argc < 3)
X    Usage((char *) NULL);
X  /*
X    Read image and convert to MIFF format.
X  */
X  if (strncmp(argv[i],"-scene",2) == 0)
X    {
X      i++;
X      scene=atoi(argv[i++]);
X    }
X  (void) strcpy(filename,argv[i++]);
X  image=ReadXBMImage(filename);
X  if (image == (Image *) NULL)
X    exit(1);
X  (void) strcpy(image->filename,argv[i++]);
X  image->scene=scene;
X  (void) WriteImage(image);
X  (void) fprintf(stderr,"%s => %s  %dx%d\n",filename,image->filename,
X    image->columns,image->rows);
X  DestroyImage(image);
X  return(False);
}
SHAR_EOF
chmod 0755 ImageMagick/filters/XBMtoMIFF.c ||
echo 'restore of ImageMagick/filters/XBMtoMIFF.c failed'
Wc_c="`wc -c < 'ImageMagick/filters/XBMtoMIFF.c'`"
test 13275 -eq "$Wc_c" ||
	echo 'ImageMagick/filters/XBMtoMIFF.c: original size 13275, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ImageMagick/filters/PPMtoMIFF.c ==============
if test -f 'ImageMagick/filters/PPMtoMIFF.c' -a X"$1" != X"-c"; then
	echo 'x - skipping ImageMagick/filters/PPMtoMIFF.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ImageMagick/filters/PPMtoMIFF.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/PPMtoMIFF.c' &&
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%                 IIIII  M   M  PPPP    OOO   RRRR    TTTTT                   %
%                   I    MM MM  P   P  O   O  R   R     T                     %
%                   I    M M M  PPPP   O   O  RRRR      T                     %
%                   I    M   M  P      O   O  R R       T                     %
%                 IIIII  M   M  P       OOO   R  R      T                     % 
%                                                                             %
%                                                                             %
%                 Import PPM raster image to a MIFF format.                   %
%                                                                             %
%                                                                             %
%                                                                             %
%                           Software Design                                   %
%                             John Cristy                                     %
%                            January  1991                                    %
%                                                                             %
%                                                                             %
%  Copyright 1991 E. I. Dupont de Nemours & Company                           %
%                                                                             %
%  Permission to use, copy, modify, distribute, and sell this software and    %
%  its documentation for any purpose is hereby granted without fee,           %
%  provided that the above Copyright notice appear in all copies and that     %
%  both that Copyright notice and this permission notice appear in            %
%  supporting documentation, and that the name of E. I. Dupont de Nemours     %
%  & Company not be used in advertising or publicity pertaining to            %
%  distribution of the software without specific, written prior               %
%  permission.  E. I. Dupont de Nemours & Company makes no representations    %
%  about the suitability of this software for any purpose.  It is provided    %
%  "as is" without express or implied warranty.                               %
%                                                                             %
%  E. I. Dupont de Nemours & Company disclaims all warranties with regard     %
%  to this software, including all implied warranties of merchantability      %
%  and fitness, in no event shall E. I. Dupont de Nemours & Company be        %
%  liable for any special, indirect or consequential damages or any           %
%  damages whatsoever resulting from loss of use, data or profits, whether    %
%  in an action of contract, negligence or other tortious action, arising     %
%  out of or in connection with the use or performance of this software.      %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
%  Command syntax:
%
%  import [-scene #] image.ppm image.miff
%  
%  Specify 'image.ppm' as '-' for standard input.  
%  Specify 'image.miff' as '-' for standard output.
%  
%
*/
X
#include "display.h"
#include "image.h"
#include "ppm.h"
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   E r r o r                                                                 %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Function Error displays an error message and then terminates the program.
%
%  The format of the Error routine is:
%
%      Error(message,qualifier)
%
%  A description of each parameter follows:
%
%    o message:  Specifies the message to display before terminating the
%      program.
%
%    o qualifier:  Specifies any qualifier to the message.
%
%
*/
void Error(message,qualifier)
char
X  *message,
X  *qualifier;
{
X  (void) fprintf(stderr,"%s: %s",application_name,message); 
X  if (qualifier != (char *) NULL)
X    (void) fprintf(stderr," %s",qualifier);
X  (void) fprintf(stderr,".\n");
X  exit(1);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%  R e a d P P M I m a g e                                                    %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Function ReadPPMImage reads an image file and returns it.  It allocates 
%  the memory necessary for the new Image structure and returns a pointer to 
%  the new image.
%
%  The format of the ReadPPMImage routine is:
%
%      image=ReadPPMImage(filename)
%
%  A description of each parameter follows:
%
%    o image:  Function ReadPPMImage returns a pointer to the image after 
%      reading.  A null image is returned if there is a a memory shortage or 
%      if the image cannot be read.
%
%    o filename:  Specifies the name of the image to read.
%
%
*/
static Image *ReadPPMImage(filename)
char
X  *filename;
{
X  Image
X    *image;
X
X  int
X    format;
X
X  pixel
X    **pixels;
X
X  pixval
X    max_value;
X
X  register int
X    i;
X
X  register pixel
X    *p;
X
X  register RunlengthPacket
X    *q;
X
X  unsigned char
X    blue,
X    green,
X    red;
X
X  /*
X    Allocate image structure.
X  */
X  image=(Image *) malloc(sizeof(Image));
X  if (image == (Image *) NULL)
X    Error("memory allocation error",(char *) NULL);
X  /*
X    Initialize Image structure.
X  */
X  image->id=UnknownId;
X  image->class=DirectClass;
X  image->compression=RunlengthEncodedCompression;
X  image->columns=0;
X  image->rows=0;
X  image->packets=0;
X  image->colors=0;
X  image->scene=0;
X  image->colormap=(ColorPacket *) NULL;
X  image->pixels=(RunlengthPacket *) NULL;
X  image->comments=(char *) NULL;
X  /*
X    Open image file.
X  */
X  (void) strcpy(image->filename,filename);
X  if (*image->filename == '-')
X    image->file=stdin;
X  else
X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
X      image->file=fopen(image->filename,"r");
X    else
X      {
X        char
X          command[256];
X
X        /*
X          Image file is compressed-- uncompress it.
X        */
X        (void) sprintf(command,"uncompress -c %s",image->filename);
X        image->file=(FILE *) popen(command,"r");
X      }
X  if (image->file == (FILE *) NULL)
X    Error("unable to open file",image->filename);
X  /*
X    Read PPM image.
X  */
X  pixels=ppm_readppm(image->file,&image->columns,&image->rows,&max_value);
X  /*
X    Create image.
X  */
X  image->comments=(char *) malloc((unsigned int) (strlen(image->filename)+256));
X  if (image->comments == (char *) NULL)
X    Error("memory allocation error",(char *) NULL);
X  (void) sprintf(image->comments,
X    "\n  Imported from PPM raster image:  %s\n",image->filename);
X  image->pixels=(RunlengthPacket *) 
X    malloc(image->columns*image->rows*sizeof(RunlengthPacket));
X  if (image->pixels == (RunlengthPacket *) NULL)
X    Error("memory allocation error",(char *) NULL);
X  /*
X    Convert PPM raster image to runlength-encoded packets.
X  */
X  p=(*pixels);
X  image->packets=0;
X  q=image->pixels;
X  q->length=MaxRunlength;
X  for (i=0; i < (image->columns*image->rows); i++)
X  {
X    red=(unsigned char) ((unsigned long) PPM_GETR(*p)*MaxRgb/max_value);
X    green=(unsigned char) ((unsigned long) PPM_GETG(*p)*MaxRgb/max_value);
X    blue=(unsigned char) ((unsigned long) PPM_GETB(*p)*MaxRgb/max_value);
X    if ((red == q->red) && (green == q->green) && (blue == q->blue) &&
X        (q->length < MaxRunlength))
X      q->length++;
X    else
X      {
X        if (image->packets > 0)
X          q++;
X        image->packets++;
X        q->red=red;
X        q->green=green;
X        q->blue=blue;
X        q->index=0;
X        q->length=0;
X      }
X    p++;
X  }
X  ppm_freearray(pixels,image->rows);
X  if (image->file != stdin)
X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
X      (void) fclose(image->file);
X    else
X      (void) pclose(image->file);
X  image->colors=NumberColors(image);
X  if (image->colors <= 256)
X    QuantizeImage(image,image->colors,0,False,True);
X  if (image->packets > ((image->columns*image->rows*3) >> 2))
X    image->compression=NoCompression;
X  image->pixels=(RunlengthPacket *)
X    realloc((char *) image->pixels,image->packets*sizeof(RunlengthPacket));
X  return(image);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   U s a g e                                                                 %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Procedure Usage displays the program usage;
%
%  The format of the Usage routine is:
%
%      Usage(message)
%
%  A description of each parameter follows:
%
%    message:  Specifies a specific message to display to the user.
%
*/
static void Usage(message)
char
X  *message;
{
X  if (message != (char *) NULL)
X    (void) fprintf(stderr,"Can't continue, %s\n\n",message);
X  (void) fprintf(stderr,"Usage: %s [-scene #] image.ppm image.miff\n",
X    application_name);
X  (void) fprintf(stderr,"\nSpecify 'image.ppm' as '-' for standard input.\n");
X  (void) fprintf(stderr,"Specify 'image.miff' as '-' for standard output.\n");
X  exit(1);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%  M a i n                                                                    %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
int main(argc,argv)
int
X  argc;
X   
char
X  *argv[];
{
X  char
X    filename[256];
X
X  Image
X    *image;
X
X  int
X    i;
X
X  unsigned int
X    scene;
X
X  /*
X    Initialize program variables.
X  */
X  application_name=argv[0];
X  i=1;
X  scene=0;
X  if (argc < 3)
X    Usage((char *) NULL);
X  /*
X    Read image and convert to MIFF format.
X  */
X  if (strncmp(argv[i],"-scene",2) == 0)
X    {
X      i++;
X      scene=atoi(argv[i++]);
X    }
X  (void) strcpy(filename,argv[i++]);
X  image=ReadPPMImage(filename);
X  if (image == (Image *) NULL)
X    exit(1);
X  (void) strcpy(image->filename,argv[i++]);
X  image->scene=scene;
X  (void) WriteImage(image);
X  (void) fprintf(stderr,"%s => %s  %dx%d\n",filename,image->filename,
X    image->columns,image->rows);
X  DestroyImage(image);
X  return(False);
}
SHAR_EOF
chmod 0755 ImageMagick/filters/PPMtoMIFF.c ||
echo 'restore of ImageMagick/filters/PPMtoMIFF.c failed'
Wc_c="`wc -c < 'ImageMagick/filters/PPMtoMIFF.c'`"
test 12416 -eq "$Wc_c" ||
	echo 'ImageMagick/filters/PPMtoMIFF.c: original size 12416, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ImageMagick/filters/TIFFtoSUN.c ==============
if test -f 'ImageMagick/filters/TIFFtoSUN.c' -a X"$1" != X"-c"; then
	echo 'x - skipping ImageMagick/filters/TIFFtoSUN.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ImageMagick/filters/TIFFtoSUN.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/TIFFtoSUN.c' &&
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%                 IIIII  M   M  PPPP    OOO   RRRR    TTTTT                   %
%                   I    MM MM  P   P  O   O  R   R     T                     %
%                   I    M M M  PPPP   O   O  RRRR      T                     %
%                   I    M   M  P      O   O  R R       T                     %
%                 IIIII  M   M  P       OOO   R  R      T                     % 
%                                                                             %
%                                                                             %
%                    Import TIFF image to a MIFF format.                      %
%                                                                             %
%                                                                             %
%                                                                             %
%                           Software Design                                   %
%                             John Cristy                                     %
%                            January  1991                                    %
%                                                                             %
%                                                                             %
%  Copyright 1991 E. I. Dupont de Nemours & Company                           %
%                                                                             %
%  Permission to use, copy, modify, distribute, and sell this software and    %
%  its documentation for any purpose is hereby granted without fee,           %
%  provided that the above Copyright notice appear in all copies and that     %
%  both that Copyright notice and this permission notice appear in            %
%  supporting documentation, and that the name of E. I. Dupont de Nemours     %
%  & Company not be used in advertising or publicity pertaining to            %
%  distribution of the software without specific, written prior               %
%  permission.  E. I. Dupont de Nemours & Company makes no representations    %
%  about the suitability of this software for any purpose.  It is provided    %
%  "as is" without express or implied warranty.                               %
%                                                                             %
%  E. I. Dupont de Nemours & Company disclaims all warranties with regard     %
%  to this software, including all implied warranties of merchantability      %
%  and fitness, in no event shall E. I. Dupont de Nemours & Company be        %
%  liable for any special, indirect or consequential damages or any           %
%  damages whatsoever resulting from loss of use, data or profits, whether    %
%  in an action of contract, negligence or other tortious action, arising     %
%  out of or in connection with the use or performance of this software.      %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
%  Command syntax:
%
%  import [-scene #] image.tiff image.miff
%  
%  Specify 'image.tiff' as '-' for standard input.  
%  Specify 'image.miff' as '-' for standard output.
% 
%
*/
X
#include <string.h>
#include "display.h"
#include "image.h"
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   E r r o r                                                                 %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Function Error displays an error message and then terminates the program.
%
%  The format of the Error routine is:
%
%      Error(message,qualifier)
%
%  A description of each parameter follows:
%
%    o message:  Specifies the message to display before terminating the
%      program.
%
%    o qualifier:  Specifies any qualifier to the message.
%
%
*/
void Error(message,qualifier)
char
X  *message,
X  *qualifier;
{
X  (void) fprintf(stderr,"%s: %s",application_name,message); 
X  if (qualifier != (char *) NULL)
X    (void) fprintf(stderr," %s",qualifier);
X  (void) fprintf(stderr,".\n");
X  exit(1);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%  M S B F i r s t O r d e r                                                  %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Function MSBFirstOrder converts a least-significant byte first buffer of
%  integers to most-significant byte first.
%
%  The format of the MSBFirstOrder routine is:
%
%       MSBFirstOrder(p,length);
%
%  A description of each parameter follows.
%
%   o  p:  Specifies a pointer to a buffer of integers.
%
%   o  length:  Specifies the length of the buffer.
%
%
*/
MSBFirstOrder(p,length)
register char 
X  *p;
X
register unsigned 
X  length;
{
X  register char 
X    c,
X    *q,
X    *sp;
X
X  q=p+length;
X  while (p < q) 
X  {
X    sp=p+3;
X    c=(*sp);
X    *sp=(*p);
X    *p++=c;
X    sp=p+1;
X    c=(*sp);
X    *sp=(*p);
X    *p++=c;
X    p+=2;
X  }
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%  R e a d T i f f I m a g e                                                  %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Function ReadTiffImage reads an image file and returns it.  It allocates the 
%  memory necessary for the new Image structure and returns a pointer to the 
%  new image.
%
%  The format of the ReadTiffImage routine is:
%
%      image=ReadTiffImage(filename)
%
%  A description of each parameter follows:
%
%    o image:  Function ReadTiffImage returns a pointer to the image after 
%      reading.  A null image is returned if there is a a memory shortage or 
%      if the image cannot be read.
%
%    o filename:  Specifies the name of the image to read.
%
%    o  verbose:  A value greater than zero prints detailed information about 
%       the image.
%
%
*/
static Image *ReadTiffImage(filename,verbose)
char
X  *filename;
X
unsigned int
X  verbose;
{
#include <tiff.h>
#include <tiffio.h>
X
X  Image
X    *image;
X
X  register int
X    i;
X
X  register RunlengthPacket
X    *q;
X
X  register unsigned char
X    *p;
X
X  register unsigned int 
X    x,
X    y;
X
X  register unsigned short
X    index;
X
X  TIFF
X    *file;
X
X  unsigned char
X    blue,
X    green,
X    red,
X    *scanline;
X
X  unsigned short
X    bits_per_sample,
X    fill_order,
X    image_length,
X    image_width,
X    photometric,
X    planar_configuration,
X    samples_per_pixel;
X
X  /*
X    Allocate image structure.
X  */
X  image=(Image *) malloc(sizeof(Image));
X  if (image == (Image *) NULL)
X    Error("unable to allocate memory",(char *) NULL);
X  /*
X    Initialize Image structure.
X  */
X  image->id=UnknownId;
X  image->class=DirectClass;
X  image->compression=RunlengthEncodedCompression;
X  image->columns=0;
X  image->rows=0;
X  image->packets=0;
X  image->colors=0;
X  image->scene=0;
X  image->colormap=(ColorPacket *) NULL;
X  image->pixels=(RunlengthPacket *) NULL;
X  image->comments=(char *) NULL;
X  /*
X    Open TIFF image file.
X  */
X  (void) strcpy(image->filename,filename);
X  file=TIFFOpen(image->filename,"r"); 
X  if (file == (TIFF *) NULL)
X    exit(1);
X  if (verbose)
X    TIFFPrintDirectory(file,stderr,False,False,False);
X  /*
X    Verify this image is acceptable.
X  */
X  if (!TIFFGetField(file,TIFFTAG_BITSPERSAMPLE,&bits_per_sample))
X    bits_per_sample=1;
X  if (!TIFFGetField(file,TIFFTAG_PHOTOMETRIC,&photometric))
X    photometric=PHOTOMETRIC_PALETTE;
X  if ((bits_per_sample > 8) && (photometric != PHOTOMETRIC_RGB))
X    Error("image is more than 8-bits per sample",(char *) NULL);
X  if (!TIFFGetField(file,TIFFTAG_SAMPLESPERPIXEL,&samples_per_pixel))
X    samples_per_pixel=1;
X  if ((samples_per_pixel != 1) && (samples_per_pixel != 3) &&
X      (samples_per_pixel != 4))
X    Error("samples per pixel must be 1, 3, or 4",(char *) NULL);
X  /*
X    Initialize image attributes.
X  */
X  if (!TIFFGetField(file,TIFFTAG_PHOTOMETRIC,&photometric))
X    photometric=PHOTOMETRIC_PALETTE;
X  TIFFGetField(file,TIFFTAG_IMAGEWIDTH,&image_width);
X  TIFFGetField(file,TIFFTAG_IMAGELENGTH,&image_length);
X  image->comments=(char *) malloc((unsigned int) (strlen(image->filename)+256));
X  if (image->comments == (char *) NULL)
X    Error("unable to allocate memory",(char *) NULL);
X  (void) sprintf(image->comments,"\n  Imported from TIFF image %s.\n\0",
X    image->filename);
X  image->class=(photometric == PHOTOMETRIC_RGB ? DirectClass : PseudoClass);
X  image->columns=image_width;
X  image->rows=image_length;
X  image->colors=1 << bits_per_sample;
X  if (image->class == PseudoClass)
X    {
X      /*
X        Prepare for pseudo-color image.
X      */
X      image->colormap=(ColorPacket *) malloc(image->colors*sizeof(ColorPacket));
X      if (image->colormap == (ColorPacket *) NULL)
X        Error("unable to allocate memory",(char *) NULL);
X      /*
X        Create colormap.
X      */
X      switch (photometric)
X      {
X        case PHOTOMETRIC_MINISBLACK:
X        {
X          for (i=0; i < image->colors; i++)
X          {
X            image->colormap[i].red=(255*i)/(image->colors-1);
X            image->colormap[i].green=(255*i)/(image->colors-1);
X            image->colormap[i].blue=(255*i)/(image->colors-1);
X          }
X          break;
X        }
X        case PHOTOMETRIC_MINISWHITE:
X        {
X          for (i=0; i < image->colors; i++)
X          {
X            image->colormap[i].red=255-(255*i)/(image->colors-1);
X            image->colormap[i].green=255-(255*i)/(image->colors-1);
X            image->colormap[i].blue=255-(255*i)/(image->colors-1);
X          }
X          break;
X        }
X        case PHOTOMETRIC_PALETTE:
X        {
X          unsigned short
X            *blue_colormap,
X            *green_colormap,
X            *red_colormap;
X
X          TIFFGetField(file,TIFFTAG_COLORMAP,&red_colormap,&green_colormap,
X            &blue_colormap);
X          for (i=0; i < image->colors; i++)
X          {
X            image->colormap[i].red=red_colormap[i] >> 8;
X            image->colormap[i].green=green_colormap[i] >> 8;
X            image->colormap[i].blue=blue_colormap[i] >> 8;
X          }
X          break;
X        }
X        default:
X          break;
X      }
X    }
X  /*
X    Allocate memory for the image and scanline buffer.
X  */
X  image->pixels=(RunlengthPacket *) 
X    malloc(image->columns*image->rows*sizeof(RunlengthPacket));
X  TIFFGetField(file,TIFFTAG_PLANARCONFIG,&planar_configuration);
X  if (planar_configuration == PLANARCONFIG_CONTIG)
X    scanline=(unsigned char *) malloc((unsigned int) TIFFScanlineSize(file));
X  else
X    scanline=(unsigned char *) 
X      malloc((unsigned int) samples_per_pixel*TIFFScanlineSize(file));
X  if ((image->pixels == (RunlengthPacket *) NULL) ||
X      (scanline == (unsigned char *) NULL))
X    Error("unable to allocate memory",(char *) NULL);
X  /*
X    Read the TIFF image and write to image pixel buffer.
X  */
X  if (!TIFFGetField(file,TIFFTAG_FILLORDER,&fill_order))
X    fill_order=FILLORDER_MSB2LSB;
X  image->packets=0;
X  q=image->pixels;
X  q->length=MaxRunlength;
X  for (y=0; y < image->rows; y++)
X  {
X    p=scanline;
X    if (TIFFReadScanline(file,p,y,0) < 0)
X      Error("unable to read TIFF scanline",(char *) NULL);
X    if (planar_configuration != PLANARCONFIG_CONTIG)
X      for (i=1; i < samples_per_pixel; i++)
X        if (TIFFReadScanline(file,p+i*TIFFScanlineSize(file),y,i) < 0)
X          Error("unable to read TIFF scanline",(char *) NULL);
X    switch (photometric)
X    {
X      case PHOTOMETRIC_RGB:
X      {
X        switch (bits_per_sample)
X        {
X          case 8:
X          default:
X          {
X            /*
X              Assumes Max Sample Value is 255.
X            */
X            for (x=0; x < image->columns; x++)
X            {
X              if (planar_configuration == PLANARCONFIG_CONTIG)
X                {
X                  red=(*p++);
X                  green=(*p++);
X                  blue=(*p++);
X                }
X              else
X                {
X                  red=(*p);
X                  green=(*(p+TIFFScanlineSize(file)));
X                  blue=(*(p+2*TIFFScanlineSize(file)));
X                  p++;
X                }
X              if ((red == q->red) && (green == q->green) && 
X                  (blue == q->blue) && (q->length < MaxRunlength))
X                q->length++;
X              else
X                {
X                  if (image->packets > 0)
X                    q++;
X                  image->packets++;
X                  q->red=red;
X                  q->green=green;
X                  q->blue=blue;
X                  q->index=0;
X                  q->length=0;
X                }
X              if (samples_per_pixel == 4)
X                p++;
X            }
X            break;
X          }
X          case 16:
X          {
X            register unsigned short
X              *p;
X
X            /*
X              Assumes Max Sample Value is 2047.
X            */
X            p=(unsigned short *) scanline;
X            for (x=0; x < image->columns; x++)
X            {
X              if (planar_configuration == PLANARCONFIG_CONTIG)
X                {
X                  red=(*p++ >> 3);
X                  green=(*p++ >> 3);
X                  blue=(*p++ >> 3);
X                }
X              else
X                {
X                  red=(*p >> 3);
X                  green=(*(p+TIFFScanlineSize(file)) >> 3);
X                  blue=(*(p+2*TIFFScanlineSize(file)) >> 3);
X                  p++;
X                }
X              if ((red == q->red) && (green == q->green) && 
X                  (blue == q->blue) && (q->length < MaxRunlength))
X                q->length++;
X              else
X                {
X                  if (image->packets > 0)
X                    q++;
X                  image->packets++;
X                  q->red=red;
X                  q->green=green;
X                  q->blue=blue;
X                  q->index=0;
X                  q->length=0;
X                }
X              if (samples_per_pixel == 4)
X                p++;
X            }
X            break;
X          }
X        }
X        break;
X      }
X      case PHOTOMETRIC_MINISBLACK:
X      case PHOTOMETRIC_MINISWHITE:
X      {
X        switch (bits_per_sample)
X        {
X          case 1:
X          {
X            register int
X              bit;
X
X            for (x=0; x < image->columns; x+=8)
X            {
X              for (bit=7; bit >= 0; bit--)
X              {
X                index=((*p) & (0x01 << bit) ? 0x01 : 0x00);
X                red=image->colormap[index].red;
X                green=image->colormap[index].green;
X                blue=image->colormap[index].blue;
X                if ((red == q->red) && (green == q->green) &&
X                    (blue == q->blue) && (q->length < MaxRunlength))
X                  q->length++;
X                else
X                  {
X                    if (image->packets > 0)
X                      q++;
X                    image->packets++;
X                    q->red=red;
X                    q->green=green;
X                    q->blue=blue;
X                    q->index=index;
X                    q->length=0;
X                  }
X              }
X              p++;
X            }
X            if ((image->columns % 8) != 0)
X              {
X                for (bit=7; bit >= (8-(image->columns % 8)); bit--)
X                {
X                  index=((*p) & (0x01 << bit) ? 0x00 : 0x01);
X                  red=image->colormap[index].red;
X                  green=image->colormap[index].green;
X                  blue=image->colormap[index].blue;
X                  if ((red == q->red) && (green == q->green) &&
X                      (blue == q->blue) && (q->length < MaxRunlength))
X                    q->length++;
X                  else
X                    {
X                      if (image->packets > 0)
X                        q++;
X                      image->packets++;
X                      q->red=red;
X                      q->green=green;
X                      q->blue=blue;
X                      q->index=index;
X                      q->length=0;
X                    }
X                }
X                p++;
X              }
X            break;
X          }
X          case 2:
X          {
X            for (x=0; x < image->columns; x+=4)
X            {
X              index=(*p >> 6) & 3;
X              red=image->colormap[index].red;
X              green=image->colormap[index].green;
X              blue=image->colormap[index].blue;
X              if ((red == q->red) && (green == q->green) &&
X                  (blue == q->blue) && (q->length < MaxRunlength))
X                q->length++;
X              else
X                {
X                  if (image->packets > 0)
X                    q++;
X                  image->packets++;
X                  q->red=red;
X                  q->green=green;
X                  q->blue=blue;
X                  q->index=index;
X                  q->length=0;
X                }
X              index=(*p >> 4) & 3;
X              red=image->colormap[index].red;
X              green=image->colormap[index].green;
X              blue=image->colormap[index].blue;
X              if ((red == q->red) && (green == q->green) &&
X                  (blue == q->blue) && (q->length < MaxRunlength))
X                q->length++;
X              else
X                {
X                  if (image->packets > 0)
X                    q++;
X                  image->packets++;
X                  q->red=red;
X                  q->green=green;
X                  q->blue=blue;
X                  q->index=index;
X                  q->length=0;
X                }
X              index=(*p >> 2) & 3;
X              red=image->colormap[index].red;
X              green=image->colormap[index].green;
X              blue=image->colormap[index].blue;
X              if ((red == q->red) && (green == q->green) &&
X                  (blue == q->blue) && (q->length < MaxRunlength))
X                q->length++;
X              else
X                {
X                  if (image->packets > 0)
X                    q++;
X                  image->packets++;
X                  q->red=red;
X                  q->green=green;
X                  q->blue=blue;
X                  q->index=index;
X                  q->length=0;
X                }
X              index=(*p) & 3;
X              red=image->colormap[index].red;
X              green=image->colormap[index].green;
X              blue=image->colormap[index].blue;
X              if ((red == q->red) && (green == q->green) &&
X                  (blue == q->blue) && (q->length < MaxRunlength))
X                q->length++;
X              else
X                {
X                  if (image->packets > 0)
X                    q++;
X                  image->packets++;
X                  q->red=red;
X                  q->green=green;
X                  q->blue=blue;
X                  q->index=index;
X                  q->length=0;
X                }
X              p++;
X            }
X            break;
X          }
X          case 4:
X          {
X            for (x=0; x < image->columns; x+=2)
X            {
X              index=(*p >> 4);
X              red=image->colormap[index].red;
X              green=image->colormap[index].green;
X              blue=image->colormap[index].blue;
X              if ((red == q->red) && (green == q->green) &&
X                  (blue == q->blue) && (q->length < MaxRunlength))
X                q->length++;
X              else
X                {
X                  if (image->packets > 0)
X                    q++;
X                  image->packets++;
X                  q->red=red;
X                  q->green=green;
X                  q->blue=blue;
X                  q->index=index;
X                  q->length=0;
X                }
X              index=(*p) & 0xf;
X              red=image->colormap[index].red;
X              green=image->colormap[index].green;
X              blue=image->colormap[index].blue;
X              if ((red == q->red) && (green == q->green) &&
X                  (blue == q->blue) && (q->length < MaxRunlength))
X                q->length++;
X              else
X                {
X                  if (image->packets > 0)
X                    q++;
X                  image->packets++;
X                  q->red=red;
X                  q->green=green;
X                  q->blue=blue;
X                  q->index=index;
X                  q->length=0;
X                }
X              p++;
X            }
X            break;
X          }
X          case 8:
X          {
X            for (x=0; x < image->columns; x++)
X            {
X              index=(*p);
X              red=image->colormap[index].red;
X              green=image->colormap[index].green;
X              blue=image->colormap[index].blue;
X              if ((red == q->red) && (green == q->green) &&
X                  (blue == q->blue) && (q->length < MaxRunlength))
X                q->length++;
X              else
X                {
X                  if (image->packets > 0)
X                    q++;
X                  image->packets++;
X                  q->red=red;
X                  q->green=green;
X                  q->blue=blue;
X                  q->index=index;
X                  q->length=0;
X                }
X              p++;
X            }
X            break;
X          }
X          default:
X            break;
X        }
X        break;
X      }
X      case PHOTOMETRIC_PALETTE:
X      {
X        for (x=0; x < image->columns; x++)
X        {
X          index=(*p++);
X          red=image->colormap[index].red;
X          green=image->colormap[index].green;
X          blue=image->colormap[index].blue;
X          if ((red == q->red) && (green == q->green) && (blue == q->blue) && 
X              (q->length < MaxRunlength))
X            q->length++;
X          else
X            {
X              if (image->packets > 0)
X                q++;
X              image->packets++;
X              q->red=red;
X              q->green=green;
X              q->blue=blue;
X              q->index=index;
X              q->length=0;
X            }
X        }
X        break;
X      }
X      default:
X        break;
X    }
X  }
X  free((char *) scanline);
X  TIFFClose(file);
X  if (image->class == PseudoClass)
X    QuantizeImage(image,image->colors,0,False,True);
X  if (image->packets > ((image->columns*image->rows*3) >> 2))
X    image->compression=NoCompression;
X  image->pixels=(RunlengthPacket *)
X    realloc((char *) image->pixels,image->packets*sizeof(RunlengthPacket));
X  return(image);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   U s a g e                                                                 %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Procedure Usage displays the program usage;
%
%  The format of the Usage routine is:
%
%      Usage(message)
%
%  A description of each parameter follows:
%
%    program_name:  Specifies the name of this program.
%
%    message:  Specifies a specific message to display to the user.
%
*/
static void Usage(message)
char
X  *message;
{
X  if (message != (char *) NULL)
X    (void) fprintf(stderr,"Can't continue, %s\n\n",message);
X  (void) fprintf(stderr,"Usage: %s image.tiff image.miff\n\n",application_name);
X  (void) fprintf(stderr,"Specify 'image.tiff' as '-' for standard input.\n");
X  (void) fprintf(stderr,"Specify 'image.miff' as '-' for standard output.\n");
X  exit(1);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   W r i t e R a s t e r I m a g e                                           %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Procedure WriteRasterImage writes an image to a file on disk in SUN 
%  rasterfile format.
%
%  The format of the WriteRasterImage routine is:
%
%      WriteRasterImage(image)
%
%  A description of each parameter follows.
%
%    o image:  A pointer to a Image structure.
%
%
*/
static void WriteRasterImage(image)
Image
X  *image;
{
#define RT_STANDARD  1
#define RMT_NONE  0
#define RMT_EQUAL_RGB  1
X
X  typedef struct Raster
X  {
X    int
X      magic,
X      width,
X      height,
X      depth,
X      length,
X      type,
X      maptype,
X      maplength;
X  } Raster;
X
X  Raster
X    sun_header;
X
X  register int
X    i,
X    j,
X    x;
X
X  register RunlengthPacket
X    *p;
X
X  register unsigned char
X    *q;
X
X  unsigned char
X    *sun_pixels;
X
X  unsigned long
X    lsb_first;
X
X  /*
X    Open output image file.
X  */
X  if (*image->filename == '-')
X    image->file=stdout;
X  else
X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
X      image->file=fopen(image->filename,"w");
X    else
X      {
X        char
X          command[256];
X
X        /*
X          Image file is compressed-- uncompress it.
X        */
X        (void) sprintf(command,"compress -c > %s",image->filename);
X        image->file=(FILE *) popen(command,"w");
X      }
X  if (image->file == (FILE *) NULL)
X    Error("unable to open file",image->filename);
X  /*
X    Initialize raster file sun_header.
X  */
X  sun_header.magic=0x59a66a95;
X  sun_header.width=image->columns;
X  sun_header.height=image->rows;
X  sun_header.depth=(image->class == DirectClass ? 24 : 8);
X  sun_header.length=image->columns*image->rows*(sun_header.depth >> 3)+
X    (image->columns % 2 ? image->rows : 0);
X  sun_header.type=RT_STANDARD;
X  sun_header.maptype=(image->class == DirectClass ? RMT_NONE : RMT_EQUAL_RGB);
X  sun_header.maplength=(image->class == DirectClass ? 0 : image->colors*3);
X  /*
X    Ensure the sun_header byte-order is most-significant byte first.
X  */
X  lsb_first=1;
X  if ((*(char *) &lsb_first) == 0)
X    (void) fwrite((char *) &sun_header,sizeof(sun_header),1,image->file);
X  else
X    {
X      Raster
X        reverse_header;
X
X      reverse_header=sun_header;
X      MSBFirstOrder((char *) &reverse_header,sizeof(reverse_header));
X      (void) fwrite((char *) &reverse_header,sizeof(reverse_header),1,
SHAR_EOF
true || echo 'restore of ImageMagick/filters/TIFFtoSUN.c failed'
fi
echo 'End of ImageMagick part 14'
echo 'File ImageMagick/filters/TIFFtoSUN.c is continued in part 15'
echo 15 > _shar_seq_.tmp
exit 0
--
Dan Heller
O'Reilly && Associates       Z-Code Software    Comp-sources-x:
Senior Writer                President          comp-sources-x at uunet.uu.net
argv at ora.com                 argv at zipcode.com



More information about the Comp.sources.x mailing list