v13i031: ImageMagick - Graphics display programs, Part15/21

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


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

#!/bin/sh
# this is img.15 (part 15 of ImageMagick)
# do not concatenate these parts, unpack them in order with /bin/sh
# file ImageMagick/filters/TIFFtoSUN.c continued
#
if test ! -r _shar_seq_.tmp; then
	echo 'Please unpack part 1 first!'
	exit 1
fi
(read Scheck
 if test "$Scheck" != 15; 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/TIFFtoSUN.c'
else
echo 'x - continuing file ImageMagick/filters/TIFFtoSUN.c'
sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/filters/TIFFtoSUN.c' &&
X        image->file);
X    }
X  if (image->class == PseudoClass)
X    {
X      unsigned char
X        *sun_colormap;
X
X      /*
X         Dump colormap to file.
X      */
X      sun_colormap=(unsigned char *) 
X        malloc((unsigned int) sun_header.maplength);
X      if (sun_colormap == (unsigned char *) NULL)
X        Error("unable to allocate memory",(char *) NULL);
X      q=sun_colormap;
X      for (i=0; i < image->colors; i++)
X        *q++=image->colormap[i].red;
X      for (i=0; i < image->colors; i++)
X        *q++=image->colormap[i].green;
X      for (i=0; i < image->colors; i++)
X        *q++=image->colormap[i].blue;
X      (void) fwrite((char *) sun_colormap,sizeof(char),sun_header.maplength,
X        image->file);
X      (void) free((char *) sun_colormap);
X    }
X  /*
X    Convert MIFF to SUN raster pixels.
X  */
X  sun_pixels=(unsigned char *) malloc((unsigned int) sun_header.length);
X  if (sun_pixels == (unsigned char *) NULL)
X    Error("unable to allocate memory",(char *) NULL);
X  p=image->pixels;
X  q=sun_pixels;
X  x=0;
X  for (i=0; i < image->packets; i++)
X  {
X    for (j=0; j <= p->length; j++)
X    {
X      if (image->class == PseudoClass)
X        *q++=p->index;
X      else
X        {
X          *q++=p->blue;
X          *q++=p->green;
X          *q++=p->red;
X        }
X      if ((image->columns % 2) != 0)
X        {
X          x++;
X          if ((x % image->columns) == 0)
X            *q++;  /* pad scanline */
X        }
X    }
X    p++;
X  }
X  (void) fwrite((char *) sun_pixels,sizeof(char),sun_header.length,image->file);
X  (void) free((char *) sun_pixels);
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=ReadTiffImage(argv[1],True);
X  if (image == (Image *) NULL)
X    exit(1);
X  (void) strcpy(image->filename,argv[2]);
X  WriteRasterImage(image);
X  DestroyImage(image);
X  return(False);
}
SHAR_EOF
echo 'File ImageMagick/filters/TIFFtoSUN.c is complete' &&
chmod 0755 ImageMagick/filters/TIFFtoSUN.c ||
echo 'restore of ImageMagick/filters/TIFFtoSUN.c failed'
Wc_c="`wc -c < 'ImageMagick/filters/TIFFtoSUN.c'`"
test 31233 -eq "$Wc_c" ||
	echo 'ImageMagick/filters/TIFFtoSUN.c: original size 31233, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ImageMagick/filters/MIFFtoPPM.c ==============
if test -f 'ImageMagick/filters/MIFFtoPPM.c' -a X"$1" != X"-c"; then
	echo 'x - skipping ImageMagick/filters/MIFFtoPPM.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ImageMagick/filters/MIFFtoPPM.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/MIFFtoPPM.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 PPM raster 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.ppm
%
%  Specify 'image.miff' as '-' for standard input.  
%  Specify 'image.ppm' 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
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   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.ppm\n\n",application_name);
X  (void) fprintf(stderr,"Specify 'image.miff' as '-' for standard input.\n");
X  (void) fprintf(stderr,"Specify 'image.ppm' as '-' for standard output.\n");
X  exit(1);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   W r i t e P P M I m a g e                                                 %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Procedure WritePPMImage writes an image to a file on disk in PPM 
%  rasterfile format.
%
%  The format of the WritePPMImage routine is:
%
%      WritePPMImage(image)
%
%  A description of each parameter follows.
%
%    o image:  A pointer to a Image structure.
%
%
*/
static void WritePPMImage(image)
Image
X  *image;
{
X  pixel
X    **pixels;
X
X  register int
X    i,
X    j,
X    x;
X
X  register RunlengthPacket
X    *p;
X
X  register pixel
X    *q;
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    Convert MIFF to PPM raster pixels.
X  */
X  pixels=ppm_allocarray(image->columns,image->rows);
X  if (pixels == (pixel **) NULL)
X    Error("unable to allocate memory",(char *) NULL);
X  p=image->pixels;
X  q=(*pixels);
X  x=0;
X  for (i=0; i < image->packets; i++)
X  {
X    for (j=0; j <= p->length; j++)
X    {
X      PPM_ASSIGN(*q,p->red,p->green,p->blue);
X      q++;
X    }
X    p++;
X  }
X  ppm_writeppm(image->file,pixels,image->columns,image->rows,
X    (pixval) MaxRgb,0);
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
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%    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  WritePPMImage(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/MIFFtoPPM.c ||
echo 'restore of ImageMagick/filters/MIFFtoPPM.c failed'
Wc_c="`wc -c < 'ImageMagick/filters/MIFFtoPPM.c'`"
test 9806 -eq "$Wc_c" ||
	echo 'ImageMagick/filters/MIFFtoPPM.c: original size 9806, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ImageMagick/filters/MTVtoMIFF.c ==============
if test -f 'ImageMagick/filters/MTVtoMIFF.c' -a X"$1" != X"-c"; then
	echo 'x - skipping ImageMagick/filters/MTVtoMIFF.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ImageMagick/filters/MTVtoMIFF.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/MTVtoMIFF.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 MTV 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.mtv image.miff
%  
%  Specify 'image.mtv' as '-' for standard input.  
%  Specify 'image.miff' as '-' for standard output.
%  
%
*/
X
#include <string.h>
#include "display.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 I m a g e                                                          %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Function ReadMTVImage 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 ReadMTVImage routine is:
%
%      image=ReadMTVImage(filename)
%
%  A description of each parameter follows:
%
%    o image:  Function ReadMTVImage 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 *ReadMTVImage(filename)
char
X  *filename;
{
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  unsigned char
X    blue,
X    green,
X    *mtv_pixels,
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 MTV image.
X  */
X  (void) fscanf(image->file,"%d %d\n",&image->columns,&image->rows);
X  mtv_pixels=(unsigned char *) 
X    malloc((unsigned int) image->columns*image->rows*3*sizeof(unsigned char));
X  if (mtv_pixels == (unsigned char *) NULL)
X    Error("memory allocation error",(char *) NULL);
X  (void) ReadData((char *) mtv_pixels,1,(int) (image->columns*image->rows*3),
X    image->file);
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,"\n  Imported from MTV raster image:  %s\n",
X    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 MTV raster image to runlength-encoded packets.
X  */
X  p=mtv_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=(*p++);
X    green=(*p++);
X    blue=(*p++);
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  }
X  (void) free((char *) mtv_pixels);
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                                                                 %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  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.mtv image.miff\n",
X    application_name);
X  (void) fprintf(stderr,"\nSpecify 'image.mtv' 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=ReadMTVImage(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/MTVtoMIFF.c ||
echo 'restore of ImageMagick/filters/MTVtoMIFF.c failed'
Wc_c="`wc -c < 'ImageMagick/filters/MTVtoMIFF.c'`"
test 12356 -eq "$Wc_c" ||
	echo 'ImageMagick/filters/MTVtoMIFF.c: original size 12356, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ImageMagick/filters/ANIMOLtoMIFF.c ==============
if test -f 'ImageMagick/filters/ANIMOLtoMIFF.c' -a X"$1" != X"-c"; then
	echo 'x - skipping ImageMagick/filters/ANIMOLtoMIFF.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ImageMagick/filters/ANIMOLtoMIFF.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/ANIMOLtoMIFF.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 ANIMOL 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.animol image.miff
%  
%  Specify 'image.animol' 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 A n i m o l I m a g e                                              %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Function ReadAnimolImage 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 ReadAnimolImage routine is:
%
%      image=ReadAnimolImage(filename)
%
%  A description of each parameter follows:
%
%    o image:  Function ReadAnimolImage 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 *ReadAnimolImage(filename)
char
X  *filename;
{
X  extern void
X    animol_();
X
X  Image
X    *image;
X
X  register int
X    i;
X
X  register RunlengthPacket
X    *p;
X
X  unsigned char
X    blue[3100*3100],
X    green[3100*3100],
X    red[3100*3100];
X
X  /*
X    Allocate image structure.
X  */
X  image=(Image *) malloc(sizeof(Image));
X  if (image == (Image *) NULL)
X    return((Image *) 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  (void) animol_(image->filename,&image->columns,&image->rows,red,green,blue);
X  /*
X    Create image.
X  */
X  image->comments=(char *) malloc((unsigned int) (strlen(image->filename)+256));
X  if (image->comments == (char *) NULL)
X    Error("unable to read image","unable to allocate memory");
X  (void) strcpy(image->comments,"  Imported from Animol raster image:  ");
X  (void) strcat(image->comments,image->filename);
X  image->pixels=(RunlengthPacket *) 
X    malloc(image->columns*image->rows*sizeof(RunlengthPacket));
X  if (image->pixels == (RunlengthPacket *) NULL)
X    Error("unable to read image","unable to allocate memory");
X  /*
X    Convert Animol raster image to runlength-encoded packets.
X  */
X  image->packets=0;
X  p=image->pixels;
X  p->length=MaxRunlength;
X  for (i=0; i < (image->rows*image->columns); i++)
X  {
X    if ((red[i] == p->red) && (green[i] == p->green) && (blue[i] == 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[i];
X        p->green=green[i];
X        p->blue=blue[i];
X        p->index=0;
X        p->length=0;
X      }
X  }
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.animol image.miff\n",
X    application_name);
X  (void) fprintf(stderr,"\nSpecify 'image.animol' as '-' for standard input.");
X  (void) fprintf(stderr,"\nSpecify '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=ReadAnimolImage(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/ANIMOLtoMIFF.c ||
echo 'restore of ImageMagick/filters/ANIMOLtoMIFF.c failed'
Wc_c="`wc -c < 'ImageMagick/filters/ANIMOLtoMIFF.c'`"
test 11346 -eq "$Wc_c" ||
	echo 'ImageMagick/filters/ANIMOLtoMIFF.c: original size 11346, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ImageMagick/filters/GRAYtoMIFF.c ==============
if test -f 'ImageMagick/filters/GRAYtoMIFF.c' -a X"$1" != X"-c"; then
	echo 'x - skipping ImageMagick/filters/GRAYtoMIFF.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ImageMagick/filters/GRAYtoMIFF.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/GRAYtoMIFF.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 GRAY 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 width height image.gray image.miff
%
%  Specify 'image.gray' 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.
%
%
*/
static 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 G R A Y I m a g e                                                  %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Function ReadGRAYImage 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 ReadGRAYImage routine is:
%
%      image=ReadGRAYImage(filename,columns,rows)
%
%  A description of each parameter follows:
%
%    o image:  Function ReadGRAYImage 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 *ReadGRAYImage(filename,columns,rows)
char
X  *filename;
X
unsigned int
X  columns,
X  rows;
{
X  Image
X    *image;
X
X  register int
X    i;
X
X  register RunlengthPacket
X    *q;
X
X  register unsigned char
X    gray,
X    *p;
X
X  unsigned char
X    *gray_pixels;
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=columns;
X  image->rows=rows;
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    Create linear colormap.
X  */
X  image->colors=256;
X  image->colormap=(ColorPacket *) malloc(image->colors*sizeof(ColorPacket));
X  if (image->colormap == (ColorPacket *) NULL)
X    Error("memory allocation error",(char *) NULL);
X  for (i=0; i < image->colors; i++)
X  {
X    image->colormap[i].red=(unsigned char) i;
X    image->colormap[i].green=(unsigned char) i;
X    image->colormap[i].blue=(unsigned char) i;
X  }
X  /*
X    Create image.
X  */
X  gray_pixels=(unsigned char *)
X    malloc(image->columns*image->rows*sizeof(unsigned char));
X  image->pixels=(RunlengthPacket *)
X    malloc(image->columns*image->rows*sizeof(RunlengthPacket));
X  if ((gray_pixels == (unsigned char *) NULL) ||
X      (image->pixels == (RunlengthPacket *) NULL))
X    Error("memory allocation error",(char *) NULL);
X  /*
X    Convert raster image to runlength-encoded packets.
X  */
X  (void) ReadData((char *) gray_pixels,1,image->columns*image->rows,
X    image->file);
X  p=gray_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    gray=(*p++);
X    if ((gray == q->index) && (q->length < MaxRunlength))
X      q->length++;
X    else
X      {
X        if (image->packets > 0)
X          q++;
X        image->packets++;
X        q->red=gray;
X        q->green=gray;
X        q->blue=gray;
X        q->index=gray;
X        q->length=0;
X      }
X  }
X  (void) free((char *) gray_pixels);
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.gray image.miff\n",application_name);
X  (void) fprintf(stderr,"\nSpecify 'image.gray' 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    columns,
X    rows,
X    scene;
X
X  /*
X    Initialize program variables.
X  */
X  application_name=argv[0];
X  i=1;
X  scene=0;
X  if (argc < 5)
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  columns=atoi(argv[i++]);
X  rows=atoi(argv[i++]);
X  (void) strcpy(filename,argv[i++]);
X  image=ReadGRAYImage(filename,columns,rows);
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/GRAYtoMIFF.c ||
echo 'restore of ImageMagick/filters/GRAYtoMIFF.c failed'
Wc_c="`wc -c < 'ImageMagick/filters/GRAYtoMIFF.c'`"
test 12419 -eq "$Wc_c" ||
	echo 'ImageMagick/filters/GRAYtoMIFF.c: original size 12419, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ImageMagick/filters/MIFFtoGRAY.c ==============
if test -f 'ImageMagick/filters/MIFFtoGRAY.c' -a X"$1" != X"-c"; then
	echo 'x - skipping ImageMagick/filters/MIFFtoGRAY.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ImageMagick/filters/MIFFtoGRAY.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/MIFFtoGRAY.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 GRAY raster 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.gray
%
%  Specify 'image.miff' as '-' for standard input.  
%  Specify 'image.gray' as '-' for standard output.
%
%
*/
X
#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.
%
%
*/
static 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.gray\n\n",application_name);
X  (void) fprintf(stderr,"Specify 'image.miff' as '-' for standard input.\n");
X  (void) fprintf(stderr,"Specify 'image.gray' as '-' for standard output.\n");
X  exit(1);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   W r i t e G R A Y I m a g e                                               %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Procedure WriteGRAYImage writes an image to a file on disk in red, green,
%  blue rasterfile format.
%
%  The format of the WriteGRAYImage routine is:
%
%      WriteGRAYImage(image)
%
%  A description of each parameter follows.
%
%    o image:  A pointer to a Image structure.
%
%
*/
static void WriteGRAYImage(image)
Image
X  *image;
{
X  register int
X    i,
X    j;
X
X  register RunlengthPacket
X    *p;
X
X  register unsigned char
X    *q;
X
X  unsigned char
X    *pixels;
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    Convert image to gray scale PseudoColor class.
X  */
X  pixels=(unsigned char *) 
X    malloc(image->columns*image->rows*sizeof(unsigned char));
X  if (pixels == (unsigned char *) NULL)
X    Error("unable to allocate memory",(char *) NULL);
X  (void) GrayImage(image);
X  if (image->class == DirectClass)
X    QuantizeImage(image,256,0,False,True);
X  p=image->pixels;
X  q=pixels;
X  for (i=0; i < image->packets; i++)
X  {
X    for (j=0; j <= p->length; j++)
X      *q++=p->red;
X    p++;
X  }
X  (void) fwrite((char *) pixels,sizeof(unsigned char),
X    (int) image->columns*image->rows,image->file);
X  (void) free((char *) pixels);
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  WriteGRAYImage(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/MIFFtoGRAY.c ||
echo 'restore of ImageMagick/filters/MIFFtoGRAY.c failed'
Wc_c="`wc -c < 'ImageMagick/filters/MIFFtoGRAY.c'`"
test 9941 -eq "$Wc_c" ||
	echo 'ImageMagick/filters/MIFFtoGRAY.c: original size 9941, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ImageMagick/filters/MIFFtoMTV.c ==============
if test -f 'ImageMagick/filters/MIFFtoMTV.c' -a X"$1" != X"-c"; then
	echo 'x - skipping ImageMagick/filters/MIFFtoMTV.c (File already exists)'
	rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ImageMagick/filters/MIFFtoMTV.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/MIFFtoMTV.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 MTV raster 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.mtv
%
%  Specify 'image.miff' as '-' for standard input.  
%  Specify 'image.mtv' as '-' for standard output.
%
%
*/
X
#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.
%
%
*/
static 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.mtv\n\n",application_name);
X  (void) fprintf(stderr,"Specify 'image.miff' as '-' for standard input.\n");
X  (void) fprintf(stderr,"Specify 'image.mtv' as '-' for standard output.\n");
X  exit(1);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   W r i t e M T V I m a g e                                                 %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Procedure WriteMTVImage writes an image to a file on disk in red, green,
%  blue rasterfile format.
%
%  The format of the WriteMTVImage routine is:
%
%      WriteMTVImage(image)
%
%  A description of each parameter follows.
%
%    o image:  A pointer to a Image structure.
%
%
*/
static void WriteMTVImage(image)
Image
X  *image;
{
X  register int
X    i,
X    j;
X
X  register RunlengthPacket
X    *p;
X
X  register unsigned char
X    *q;
X
X  unsigned char
X    *pixels;
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    Convert MIFF to MTV raster pixels.
X  */
X  pixels=(unsigned char *) 
X    malloc(3*image->columns*image->rows*sizeof(unsigned char));
X  if (pixels == (unsigned char *) NULL)
X    Error("unable to allocate memory",(char *) NULL);
X  p=image->pixels;
X  q=pixels;
X  for (i=0; i < image->packets; i++)
X  {
X    for (j=0; j <= p->length; j++)
X    {
X      *q++=p->red;
X      *q++=p->green;
X      *q++=p->blue;
X    }
X    p++;
X  }
X  (void) fprintf(image->file,"%d %d",image->columns,image->rows);
X  (void) fwrite((char *) pixels,sizeof(unsigned char),
X    (int) 3*image->columns*image->rows,image->file);
X  (void) free((char *) pixels);
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)
SHAR_EOF
true || echo 'restore of ImageMagick/filters/MIFFtoMTV.c failed'
fi
echo 'End of ImageMagick part 15'
echo 'File ImageMagick/filters/MIFFtoMTV.c is continued in part 16'
echo 16 > _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