home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
x
/
volume13
/
imagemagic
/
part16
< prev
next >
Wrap
Text File
|
1991-05-23
|
75KB
|
2,126 lines
Path: uunet!uunet!elroy.jpl.nasa.gov!usc!apple!sun-barr!newstop!exodus!dupont.com!cristy
From: cristy@dupont.com
Newsgroups: comp.sources.x
Subject: v13i032: ImageMagick - Graphics display programs, Part16/21
Message-ID: <13946@exodus.Eng.Sun.COM>
Date: 24 May 91 03:19:55 GMT
References: <csx-13i017:imagemagic@uunet.UU.NET>
Sender: news@exodus.Eng.Sun.COM
Lines: 2114
Approved: argv@sun.com
Submitted-by: cristy@dupont.com
Posting-number: Volume 13, Issue 32
Archive-name: imagemagic/part16
#!/bin/sh
# this is img.16 (part 16 of ImageMagick)
# do not concatenate these parts, unpack them in order with /bin/sh
# file ImageMagick/filters/MIFFtoMTV.c continued
#
if test ! -r _shar_seq_.tmp; then
echo 'Please unpack part 1 first!'
exit 1
fi
(read Scheck
if test "$Scheck" != 16; 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/MIFFtoMTV.c'
else
echo 'x - continuing file ImageMagick/filters/MIFFtoMTV.c'
sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/filters/MIFFtoMTV.c' &&
X exit(1);
X (void) strcpy(image->filename,argv[2]);
X WriteMTVImage(image);
X (void) fprintf(stderr,"%s=> %s %dx%d\n",argv[1],argv[2],image->columns,
X image->rows);
X return(False);
}
SHAR_EOF
echo 'File ImageMagick/filters/MIFFtoMTV.c is complete' &&
chmod 0755 ImageMagick/filters/MIFFtoMTV.c ||
echo 'restore of ImageMagick/filters/MIFFtoMTV.c failed'
Wc_c="`wc -c < 'ImageMagick/filters/MIFFtoMTV.c'`"
test 9938 -eq "$Wc_c" ||
echo 'ImageMagick/filters/MIFFtoMTV.c: original size 9938, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ImageMagick/filters/MIFFtoRGB.c ==============
if test -f 'ImageMagick/filters/MIFFtoRGB.c' -a X"$1" != X"-c"; then
echo 'x - skipping ImageMagick/filters/MIFFtoRGB.c (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ImageMagick/filters/MIFFtoRGB.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/MIFFtoRGB.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 RGB 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.rgb
%
% Specify 'image.miff' as '-' for standard input.
% Specify 'image.rgb' 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.rgb\n\n",application_name);
X (void) fprintf(stderr,"Specify 'image.miff' as '-' for standard input.\n");
X (void) fprintf(stderr,"Specify 'image.rgb' as '-' for standard output.\n");
X exit(1);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e R G B I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Procedure WriteRGBImage writes an image to a file on disk in red, green,
% blue rasterfile format.
%
% The format of the WriteRGBImage routine is:
%
% WriteRGBImage(image)
%
% A description of each parameter follows.
%
% o image: A pointer to a Image structure.
%
%
*/
static void WriteRGBImage(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 RGB 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) 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)
X exit(1);
X (void) strcpy(image->filename,argv[2]);
X WriteRGBImage(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/MIFFtoRGB.c ||
echo 'restore of ImageMagick/filters/MIFFtoRGB.c failed'
Wc_c="`wc -c < 'ImageMagick/filters/MIFFtoRGB.c'`"
test 9872 -eq "$Wc_c" ||
echo 'ImageMagick/filters/MIFFtoRGB.c: original size 9872, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ImageMagick/filters/MIFFtoXWD.c ==============
if test -f 'ImageMagick/filters/MIFFtoXWD.c' -a X"$1" != X"-c"; then
echo 'x - skipping ImageMagick/filters/MIFFtoXWD.c (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ImageMagick/filters/MIFFtoXWD.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/MIFFtoXWD.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 XWD 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.xwd
%
% Specify 'image.miff' as '-' for standard input.
% Specify 'image.xwd' as '-' for standard output.
%
%
*/
X
#include "display.h"
#include "image.h"
#include "X.h"
#include "X11/XWDFile.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
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M S B F i r s t O r d e r L o n g %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Function MSBFirstOrderLong converts a least-significant byte first buffer
% of long integers to most-significant byte first.
%
% The format of the MSBFirstOrderLong routine is:
%
% MSBFirstOrderLong(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.
%
%
*/
MSBFirstOrderLong(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
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M S B F i r s t O r d e r S h o r t %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Function MSBFirstOrderShort converts a least-significant byte first buffer
% of short integers to most-significant byte first.
%
% The format of the MSBFirstOrderShort routine is:
%
% MSBFirstOrderShort(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.
%
%
*/
MSBFirstOrderShort(p,length)
register char
X *p;
X
register unsigned
X length;
{
X register char
X c,
X *q;
X
X q=p+length;
X while (p < q)
X {
X c=(*p);
X *p=(*(p+1));
X p++;
X *p++=c;
X }
}
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.xwd\n\n",application_name);
X (void) fprintf(stderr,"Specify 'image.miff' as '-' for standard input.\n");
X (void) fprintf(stderr,"Specify 'image.xwd' 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 WriteXWDImage writes an image to a file on disk in XWD
% rasterfile format.
%
% The format of the WriteXWDImage routine is:
%
% WriteXWDImage(image)
%
% A description of each parameter follows.
%
% o image: A pointer to a Image structure.
%
%
*/
static void WriteXWDImage(image)
Image
X *image;
{
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 *xwd_pixels;
X
X unsigned long
X lsb_first;
X
X XWDFileHeader
X xwd_header;
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 XWD file header.
X */
X xwd_header.header_size=sizeof(xwd_header)+strlen(image->filename)+1;
X xwd_header.file_version=(unsigned long) XWD_FILE_VERSION;
X xwd_header.pixmap_format=(unsigned long) ZPixmap;
X xwd_header.pixmap_depth=(unsigned long)
X (image->class == DirectClass ? 24 : 8);
X xwd_header.pixmap_width=(unsigned long) image->columns;
X xwd_header.pixmap_height=(unsigned long) image->rows;
X xwd_header.xoffset=(unsigned long) 0;
X xwd_header.byte_order=(unsigned long) MSBFirst;
X xwd_header.bitmap_unit=(unsigned long)
X (image->class == DirectClass ? 24 : 8);
X xwd_header.bitmap_bit_order=(unsigned long) MSBFirst;
X xwd_header.bitmap_pad=(unsigned long)
X (image->class == DirectClass ? 24 : 8);
X xwd_header.bits_per_pixel=(unsigned long)
X (image->class == DirectClass ? 24 : 8);
X xwd_header.bytes_per_line=(unsigned long) image->columns*
X (image->class == DirectClass ? 3 : 1);
X xwd_header.visual_class=(unsigned long)
X (image->class == DirectClass ? DirectColor : PseudoColor);
X xwd_header.red_mask=(unsigned long)
X (image->class == DirectClass ? 0xff0000 : 0);
X xwd_header.green_mask=(unsigned long)
X (image->class == DirectClass ? 0xff00 : 0);
X xwd_header.blue_mask=(unsigned long)
X (image->class == DirectClass ? 0xff : 0);
X xwd_header.bits_per_rgb=(unsigned long)
X (image->class == DirectClass ? 24 : 8);
X xwd_header.colormap_entries=(unsigned long)
X (image->class == DirectClass ? 256 : image->colors);
X xwd_header.ncolors=(image->class == DirectClass ? 0 : image->colors);
X xwd_header.window_width=(unsigned long) image->columns;
X xwd_header.window_height=(unsigned long) image->rows;
X xwd_header.window_x=0;
X xwd_header.window_y=0;
X xwd_header.window_bdrwidth=(unsigned long) 0;
X /*
X Ensure the xwd_header byte-order is most-significant byte first.
X */
X lsb_first=1;
X if (*(char *) &lsb_first)
X MSBFirstOrderLong((char *) &xwd_header,sizeof(xwd_header));
X (void) fwrite((char *) &xwd_header,sizeof(xwd_header),1,image->file);
X (void) fwrite((char *) image->filename,1,strlen(image->filename)+1,
X image->file);
X if (image->class == PseudoClass)
X {
X XColor
X *colors;
X
X /*
X Dump colormap to file.
X */
X colors=(XColor *) malloc((unsigned int) image->colors*sizeof(XColor));
X if (colors == (XColor *) NULL)
X Error("unable to allocate memory",(char *) NULL);
X for (i=0; i < image->colors; i++)
X {
X colors[i].pixel=i;
X colors[i].red=image->colormap[i].red << 8;
X colors[i].green=image->colormap[i].green << 8;
X colors[i].blue=image->colormap[i].blue << 8;
X colors[i].flags=DoRed | DoGreen | DoBlue;
X colors[i].pad=0;
X if (*(char *) &lsb_first)
X {
X MSBFirstOrderLong((char *) &colors[i].pixel,sizeof(long));
X MSBFirstOrderShort((char *) &colors[i].red,3*sizeof(short));
X }
X }
X (void) fwrite((char *) colors,sizeof(XColor),image->colors,image->file);
X (void) free((char *) colors);
X }
X /*
X Convert MIFF to XWD raster pixels.
X */
X xwd_pixels=(unsigned char *)
X malloc((unsigned int) xwd_header.bytes_per_line*xwd_header.pixmap_height);
X if (xwd_pixels == (unsigned char *) NULL)
X Error("unable to allocate memory",(char *) NULL);
X p=image->pixels;
X q=xwd_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->red;
X *q++=p->green;
X *q++=p->blue;
X }
X }
X p++;
X }
X /*
X Dump pixels to file.
X */
X (void) fwrite((char *) xwd_pixels,sizeof(char),
X xwd_header.bytes_per_line*xwd_header.pixmap_height,image->file);
X (void) free((char *) xwd_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 WriteXWDImage(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/MIFFtoXWD.c ||
echo 'restore of ImageMagick/filters/MIFFtoXWD.c failed'
Wc_c="`wc -c < 'ImageMagick/filters/MIFFtoXWD.c'`"
test 15929 -eq "$Wc_c" ||
echo 'ImageMagick/filters/MIFFtoXWD.c: original size 15929, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ImageMagick/filters/README ==============
if test -f 'ImageMagick/filters/README' -a X"$1" != X"-c"; then
echo 'x - skipping ImageMagick/filters/README (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ImageMagick/filters/README (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/README' &&
X The X utilites read and write MIFF images. You can find filters to
X convert to and from the MIFF format in this directory.
X
X To compile, type
X
X xmkmf
X make
X
X Two examples of using a filter follow:
X
X GIFtoMIFF image.gif - | display -
X
X or
X
X TIFFtoMIFF image.tiff image.miff
X display image.miff
X
X The TIFFtoMIFF and MIFFtoTIFF filters require Sam Leffler's TIFF
X software available via FTP as ucbvax.berkeley.edu:pub/tiff/v2.2.tar.Z.
X
X The PPMtoMIFF and MIFFtoPPM filters require Jef Poskanzer's PBMPLUS
X software available via FTP as export.lcs.mit.edu:contrib/pbmplus.tar.Z.
X
X To succesfully compile the PPMtoMIFF and MIFFtoPPM filters, first compile
X the pbmplus routines. Next copy pbmplus.h, pbm/pbm.h, pgm/pgm.h,
X ppm/ppm.h, and pnm/pnm.h to /usr/local/include. Change
X
X #include "../pbmplus.h"
X
X to
X
X #include "pbmplus.h"
X
X in /usr/local/include/pbm.h.
X
X Next copy pbm/libpbm.a, pgm/libpgm.a, ppm/libppm.a, and pnm/libpnm.a
X to /usr/local/lib.
X
X Finally, type
X
X make PPMtoMIFF
X make MIFFtoPPM
X
SHAR_EOF
chmod 0755 ImageMagick/filters/README ||
echo 'restore of ImageMagick/filters/README failed'
Wc_c="`wc -c < 'ImageMagick/filters/README'`"
test 1055 -eq "$Wc_c" ||
echo 'ImageMagick/filters/README: original size 1055, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ImageMagick/filters/RGBtoMIFF.c ==============
if test -f 'ImageMagick/filters/RGBtoMIFF.c' -a X"$1" != X"-c"; then
echo 'x - skipping ImageMagick/filters/RGBtoMIFF.c (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ImageMagick/filters/RGBtoMIFF.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/RGBtoMIFF.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 RGB 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.rgb image.miff
%
% Specify 'image.rgb' 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 R G B I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Function ReadRGBImage 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 ReadRGBImage routine is:
%
% image=ReadRGBImage(filename,columns,rows)
%
% A description of each parameter follows:
%
% o image: Function ReadRGBImage 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 *ReadRGBImage(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 blue,
X green,
X *p,
X red;
X
X unsigned char
X *rgb_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=DirectClass;
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 image.
X */
X rgb_pixels=(unsigned char *)
X malloc(3*image->columns*image->rows*sizeof(unsigned char));
X image->pixels=(RunlengthPacket *)
X malloc(image->columns*image->rows*sizeof(RunlengthPacket));
X if ((rgb_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 *) rgb_pixels,3,image->columns*image->rows,
X image->file);
X p=rgb_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 *) rgb_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.rgb image.miff\n",application_name);
X (void) fprintf(stderr,"\nSpecify 'image.rgb' 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=ReadRGBImage(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/RGBtoMIFF.c ||
echo 'restore of ImageMagick/filters/RGBtoMIFF.c failed'
Wc_c="`wc -c < 'ImageMagick/filters/RGBtoMIFF.c'`"
test 12104 -eq "$Wc_c" ||
echo 'ImageMagick/filters/RGBtoMIFF.c: original size 12104, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ImageMagick/filters/MIFFtoGIF.c ==============
if test -f 'ImageMagick/filters/MIFFtoGIF.c' -a X"$1" != X"-c"; then
echo 'x - skipping ImageMagick/filters/MIFFtoGIF.c (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ImageMagick/filters/MIFFtoGIF.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/MIFFtoGIF.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 GIF 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.gif
%
% Specify 'image.miff' as '-' for standard input.
% Specify 'image.gif' 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.
%
%
*/
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.gif\n\n",application_name);
X (void) fprintf(stderr,"Specify 'image.miff' as '-' for standard input.\n");
X (void) fprintf(stderr,"Specify 'image.gif' as '-' for standard output.\n");
X exit(1);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e G I F I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Procedure WriteGIFImage writes an image to a file on disk in GIF
% rasterfile format.
%
% The format of the WriteGIFImage routine is:
%
% WriteGIFImage(image)
%
% A description of each parameter follows.
%
% o image: A pointer to a Image structure.
%
%
*/
static void WriteGIFImage(image)
Image
X *image;
{
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 Blue[256],
X Green[256],
X *pixels,
X Red[256];
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 Image must be less than or equal to 256 colors.
X */
X if ((image->class == DirectClass) || (image->colors > 256))
X QuantizeImage(image,256,0,False,True);
X for (i=0; i < image->colors; i++)
X {
X Red[i]=image->colormap[i].red;
X Green[i]=image->colormap[i].green;
X Blue[i]=image->colormap[i].blue;
X }
X /*
X Convert runlength packets to a rectangular array of colormap indexes.
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 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->index;
X p++;
X }
X /*
X Convert MIFF to GIF raster pixels.
X */
X WriteGIF(image->file,pixels,image->columns,image->rows,Red,Green,Blue,
X image->colors,image->colors == 2 ? 2 : 0);
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
/*****************************************************************
X * Portions of this code Copyright (C) 1989 by Michael Mauldin.
X * Permission is granted to use this file in whole or in part provided
X * that you do not sell it for profit and that this copyright notice
X * and the names of all authors are retained unchanged.
X *
X * Authors: Michael Mauldin (mlm@cs.cmu.edu)
X * David Rowley (mgardi@watdcsu.waterloo.edu)
X *
X * Based on: compress.c - File compression ala IEEE Computer,June 1984.
X *
X * Spencer W. Thomas (decvax!harpo!utah-cs!utah-gr!thomas)
X * Jim McKie (decvax!mcvax!jim)
X * Steve Davies (decvax!vax135!petsd!peora!srd)
X * Ken Turkowski (decvax!decwrl!turtlevax!ken)
X * James A. Woods (decvax!ihnp4!ames!jaw)
X * Joe Orost (decvax!vax135!petsd!joe)
X *****************************************************************/
X
typedef long int count_int;
X
static int Width,Height;
static int curx,cury;
static long CountDown;
static int Interlace;
static unsigned char bw[2]={0,0xff};
X
static void putword(),compress(),output(),cl_block(),cl_hash();
static void char_init(),char_out(),flush_char();
X
/*************************************************************/
int WriteGIF(fp,pic,w,h,rmap,gmap,bmap,numcols,colorstyle)
FILE *fp;
unsigned char *pic;
int w,h;
unsigned char *rmap,*gmap,*bmap;
int numcols,colorstyle;
{
X int RWidth,RHeight;
X int LeftOfs,TopOfs;
X int Resolution,ColorMapSize,InitCodeSize,Background,BitsPerPixel;
X int i,j;
X
X
X /* if writing B/W stipple... */
X if (colorstyle==2) {
X rmap=gmap=bmap=bw;
X numcols=2;
X }
X
X Interlace=0;
X Background=0;
X
X /* figure out 'BitsPerPixel' */
X for (i=1; i<8; i++)
X if ((1<<i) >= numcols) break;
X
X BitsPerPixel=i;
X
X ColorMapSize=1 << BitsPerPixel;
X
X RWidth =Width =w;
X RHeight=Height=h;
X LeftOfs=TopOfs=0;
X
X Resolution=BitsPerPixel;
X
X CountDown=w * h; /* # of pixels we'll be doing */
X
X if (BitsPerPixel <= 1) InitCodeSize=2;
X else InitCodeSize=BitsPerPixel;
X
X curx=cury=0;
X
X if (!fp) {
X fprintf(stderr, "WriteGIF: file not open for writing\n");
X return (1);
X }
X
X fwrite("GIF87a",1,6,fp); /* the GIF magic number */
X
X putword(RWidth,fp); /* screen descriptor */
X putword(RHeight,fp);
X
X i=0x80; /* Yes,there is a color map */
X i |= (8-1)<<4; /* OR in the color resolution (hardwired 8) */
X i |= (BitsPerPixel - 1); /* OR in the # of bits per pixel */
X fputc(i,fp);
X
X fputc(Background,fp); /* background color */
X
X fputc(0,fp); /* future expansion unsigned char */
X
X
X if (colorstyle == 1) { /* greyscale */
X for (i=0; i<ColorMapSize; i++) {
X j=(rmap[i]*77+gmap[i]*150+bmap[i]*29) >> 8;
X fputc(j,fp);
X fputc(j,fp);
X fputc(j,fp);
X }
X }
X else {
X for (i=0; i<ColorMapSize; i++) { /* write out Global colormap */
X fputc(rmap[i],fp);
X fputc(gmap[i],fp);
X fputc(bmap[i],fp);
X }
X }
X
X fputc(',',fp); /* image separator */
X
X /* Write the Image header */
X putword(LeftOfs,fp);
X putword(TopOfs, fp);
X putword(Width, fp);
X putword(Height, fp);
X if (Interlace) fputc(0x40,fp); /* Use Global Colormap,maybe Interlace */
X else fputc(0x00,fp);
X
X fputc(InitCodeSize,fp);
X compress(InitCodeSize+1,fp,pic,w*h);
X
X fputc(0,fp); /* Write out a Zero-length packet (EOF) */
X fputc(';',fp); /* Write GIF file terminator */
X
X return (0);
}
X
/******************************/
static void putword(w,fp)
int w;
FILE *fp;
{
X /* writes a 16-bit integer in GIF order (LSB first) */
X fputc(w & 0xff,fp);
X fputc((w>>8)&0xff,fp);
}
X
X
X
X
/***********************************************************************/
X
X
static unsigned long cur_accum=0;
static int cur_bits=0;
X
X
#define min(a,b) ((a>b) ? b : a)
X
#define BITS 12
#define MSDOS 1
X
#define HSIZE 5003 /* 80% occupancy */
X
typedef unsigned char char_type;
X
X
static int n_bits; /* number of bits/code */
static int maxbits=BITS; /* user settable max # bits/code */
static int maxcode; /* maximum code,given n_bits */
static int maxmaxcode=1 << BITS; /* NEVER generate this */
X
#define MAXCODE(n_bits) ((1 << (n_bits)) - 1)
X
static count_int htab [HSIZE];
static unsigned short codetab [HSIZE];
#define HashTabOf(i) htab[i]
#define CodeTabOf(i) codetab[i]
X
static int hsize=HSIZE; /* for dynamic table sizing */
X
/*
X * To save much memory,we overlay the table used by compress() with those
X * used by decompress(). The tab_prefix table is the same size and type
X * as the codetab. The tab_suffix table needs 2**BITS characters. We
X * get this from the beginning of htab. The output stack uses the rest
X * of htab,and contains characters. There is plenty of room for any
X * possible stack (stack used to be 8000 characters).
X */
X
#define tab_prefixof(i) CodeTabOf(i)
#define tab_suffixof(i) ((char_type *)(htab))[i]
#define de_stack ((char_type *)&tab_suffixof(1<<BITS))
X
static int free_ent=0; /* first unused entry */
X
/*
X * block compression parameters -- after all codes are used up,
X * and compression rate changes,start over.
X */
static int clear_flg=0;
X
static long int in_count=1; /* length of input */
static long int out_count=0; /* # of codes output (for debugging) */
X
/*
X * compress stdin to stdout
X *
X * Algorithm: use open addressing double hashing (no chaining) on the
X * prefix code/g next character combination. We do a variant of Knuth's
X * algorithm D (vol. 3,sec. 6.4) along with G. Knott's relatively-prime
X * secondary probe. Here,the modular division first probe is gives way
X * to a faster exclusive-or manipulation. Also do block compression with
X * an adaptive reset,whereby the code table is cleared when the compression
X * ratio decreases,but after the table fills. The variable-length output
X * codes are re-sized at this point,and a special CLEAR code is generated
X * for the decompressor. Late addition: construct the table according to
X * file size for noticeable speed improvement on small files. Please direct
X * questions about this implementation to ames!jaw.
X */
X
static int g_init_bits;
static FILE *g_outfile;
X
static int ClearCode;
static int EOFCode;
X
X
/********************************************************/
static void compress(init_bits,outfile,data,len)
int init_bits;
FILE *outfile;
unsigned char *data;
int len;
{
X register long fcode;
X register int i=0;
X register int c;
X register int ent;
X register int disp;
X register int hsize_reg;
X register int hshift;
X
X /*
X * Set up the globals: g_init_bits - initial number of bits
X * g_outfile - pointer to output file
X */
X g_init_bits=init_bits;
X g_outfile =outfile;
X
X /* initialize 'compress' globals */
X maxbits=BITS;
X maxmaxcode=1<<BITS;
X memset((char *) htab,0,sizeof(htab));
X memset((char *) codetab,0,sizeof(codetab));
X hsize=HSIZE;
X free_ent=0;
X clear_flg=0;
X in_count=1;
X out_count=0;
X cur_accum=0;
X cur_bits=0;
X
X /*
X * Set up the necessary values
X */
X out_count=0;
X clear_flg=0;
X in_count=1;
X maxcode=MAXCODE(n_bits=g_init_bits);
X
X ClearCode=(1 << (init_bits - 1));
X EOFCode=ClearCode+1;
X free_ent=ClearCode+2;
X
X char_init();
X ent=(*data++); len--;
X
X hshift=0;
X for (fcode=(long) hsize; fcode < 65536L; fcode *= 2L)
X hshift++;
X hshift=8 - hshift; /* set hash code range bound */
X
X hsize_reg=hsize;
X cl_hash((count_int) hsize_reg); /* clear hash table */
X
X output(ClearCode);
X
X while (len) {
X c=(*data++); len--;
X in_count++;
X
X fcode=(long) (((long) c << maxbits)+ent);
X i=(((int) c << hshift) ^ ent); /* xor hashing */
X
X if (HashTabOf (i) == fcode) {
X ent=CodeTabOf (i);
X continue;
X }
X
X else if ((long)HashTabOf (i) < 0) /* empty slot */
X goto nomatch;
X
X disp=hsize_reg - i; /* secondary hash (after G. Knott) */
X if (i == 0)
X disp=1;
X
probe:
X if ((i -= disp) < 0)
X i += hsize_reg;
X
X if (HashTabOf (i) == fcode) {
X ent=CodeTabOf (i);
X continue;
X }
X
X if ((long)HashTabOf (i) > 0)
X goto probe;
X
nomatch:
X output(ent);
X out_count++;
X ent=c;
X
X if (free_ent < maxmaxcode) {
X CodeTabOf (i)=free_ent++;/* code -> hashtable */
X HashTabOf (i)=fcode;
X }
X else
X cl_block();
X }
X
X /* Put out the final code */
X output(ent);
X out_count++;
X output(EOFCode);
}
X
X
/*****************************************************************
X * TAG(output)
X *
X * Output the given code.
X * Inputs:
X * code: A n_bits-bit integer. If == -1,then EOF. This assumes
X * that n_bits =< (long)wordsize - 1.
X * Outputs:
X * Outputs code to the file.
X * Assumptions:
X * Chars are 8 bits long.
X * Algorithm:
X * Maintain a BITS character long buffer (so that 8 codes will
X * fit in it exactly). Use the VAX insv instruction to insert each
X * code in turn. When the buffer fills up empty it and start over.
X */
X
static
unsigned long masks[]={ 0x0000,0x0001,0x0003,0x0007,0x000F,
X 0x001F,0x003F,0x007F,0x00FF,
X 0x01FF,0x03FF,0x07FF,0x0FFF,
X 0x1FFF,0x3FFF,0x7FFF,0xFFFF };
X
static void output(code)
int code;
{
X cur_accum &= masks[cur_bits];
X
X if (cur_bits > 0)
X cur_accum |= ((long)code << cur_bits);
X else
X cur_accum=code;
X
X cur_bits += n_bits;
X
X while(cur_bits >= 8) {
X char_out((unsigned int) (cur_accum & 0xff));
X cur_accum >>= 8;
X cur_bits -= 8;
X }
X
X /*
X * If the next entry is going to be too big for the code size,
X * then increase it,if possible.
X */
X
X if (free_ent > maxcode || clear_flg) {
X
X if(clear_flg) {
X maxcode=MAXCODE (n_bits=g_init_bits);
X clear_flg=0;
X }
X else {
X n_bits++;
X if (n_bits == maxbits)
X maxcode=maxmaxcode;
X else
X maxcode=MAXCODE(n_bits);
X }
X }
X
X if(code == EOFCode) {
X /* At EOF,write the rest of the buffer */
X while(cur_bits > 0) {
X char_out((unsigned int)(cur_accum & 0xff));
X cur_accum >>= 8;
X cur_bits -= 8;
X }
X
X flush_char();
X
X fflush(g_outfile);
X
X if(ferror(g_outfile))
X Error("unable to write GIF file",(char *) NULL);
X }
}
X
X
/********************************/
static void cl_block () /* table clear for block compress */
{
X /* Clear out the hash table */
X
X cl_hash ((count_int) hsize);
X free_ent=ClearCode+2;
X clear_flg=1;
X
X output(ClearCode);
}
X
X
/********************************/
static void cl_hash(hsize) /* reset code table */
register count_int hsize;
{
X register count_int *htab_p=htab+hsize;
X register long i;
X register long m1=(-1);
X
X i=hsize - 16;
X do { /* might use Sys V memset(3) here */
X *(htab_p-16)=m1;
X *(htab_p-15)=m1;
X *(htab_p-14)=m1;
X *(htab_p-13)=m1;
X *(htab_p-12)=m1;
X *(htab_p-11)=m1;
X *(htab_p-10)=m1;
X *(htab_p-9)=m1;
X *(htab_p-8)=m1;
X *(htab_p-7)=m1;
X *(htab_p-6)=m1;
X *(htab_p-5)=m1;
X *(htab_p-4)=m1;
X *(htab_p-3)=m1;
X *(htab_p-2)=m1;
X *(htab_p-1)=m1;
X htab_p -= 16;
X } while ((i -= 16) >= 0);
X
X for (i += 16; i > 0; i--)
X *--htab_p=m1;
}
X
X
/******************************************************************************
X *
X * GIF Specific routines
X *
X ******************************************************************************/
X
/*
X * Number of characters so far in this 'packet'
X */
static int a_count;
X
/*
X * Set up the 'unsigned char output' routine
X */
static void char_init()
{
X a_count=0;
}
X
/*
X * Define the storage for the packet accumulator
X */
static char accum[256];
X
/*
X * Add a character to the end of the current packet,and if it is 254
X * characters,flush the packet to disk.
X */
static void char_out(c)
int c;
{
X accum[a_count++]=c;
X if(a_count >= 254)
X flush_char();
}
X
/*
X * Flush the packet to disk,and reset the accumulator
X */
static void flush_char()
{
X if(a_count > 0) {
X fputc(a_count,g_outfile);
X fwrite(accum,1,a_count,g_outfile);
X a_count=0;
X }
}
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 WriteGIFImage(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/MIFFtoGIF.c ||
echo 'restore of ImageMagick/filters/MIFFtoGIF.c failed'
Wc_c="`wc -c < 'ImageMagick/filters/MIFFtoGIF.c'`"
test 22524 -eq "$Wc_c" ||
echo 'ImageMagick/filters/MIFFtoGIF.c: original size 22524, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ImageMagick/display.c ==============
if test -f 'ImageMagick/display.c' -a X"$1" != X"-c"; then
echo 'x - skipping ImageMagick/display.c (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ImageMagick/display.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/display.c' &&
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% DDDD IIIII SSSSS PPPP L AAA Y Y %
% D D I SS P P L A A Y Y %
% D D I SSS PPPP L AAAAA Y %
% D D I SS P L A A Y %
% DDDD IIIII SSSSS P LLLLL A A Y %
% %
% %
% Display Machine Independent File Format Image via X11. %
% %
% %
% %
% 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. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Display is a machine architecture independent image processing
% and display program. It can display any image in the MIFF format on
% any workstation display running X. Display first determines the
% hardware capabilities of the workstation. If the number of unique
% colors in the image is less than or equal to the number the workstation
% can support, the image is displayed in an X window. Otherwise the
% number of colors in the image is first reduced to match the color
% resolution of the workstation before it is displayed.
%
% This means that a continuous-tone 24 bits/pixel image can display on a
% 8 bit pseudo-color device or monochrome device. In most instances the
% reduced color image closely resembles the original. Alternatively, a
% monochrome or pseudo-color image can display on a continuous-tone 24
% bits/pixels device.
%
% The Display program command syntax is:
%
% Usage: display [options ...] file [ [options ...] file ...]
%
% Where options include:
% -backdrop display image centered on a backdrop
% -clip geometry preferred size and location of the clipped image
% -colors value preferred number of colors in the image
% -compress type compress image: RunlengthEncoded or QEncoded
% -delay seconds display the next image after pausing
% -display server display image to this X server
% -dither apply Floyd/Steinberg error diffusion to image
% -enhance apply a digital filter to enhance a noisy image
% -gamma value level of gamma correction
% -geometry geometry preferred size and location of the image window
% -gray transform image to gray scale colors
% -inverse apply color inversion to image
% -magnify value level of image magnification
% -map type display image using this Standard Colormap
% -monochrome transform image to black and white
% -noise reduce noise with a noise peak elimination filter
% -normalize tranform image to span the full the range of colors
% -print file write image as Postscript to a file
% -reflect reverse image scanlines
% -root display image on the root window
% -rotate degrees apply Paeth rotation to the image
% -scale geometry preferred size factors of the image
% -scene number image scene number
% -treedepth value depth of the color classification tree
% -verbose print detailed information about the image
% -visual type display image using this visual type
% -write file write image to a file
%
% In addition to those listed above, you can specify these standard X
% resources as command line options: -background, -bordercolor,
% -borderwidth, -font, -foreground, -iconGeometry, -iconic, -name, or
% -title.
%
% Change '-' to '+' in any option above to reverse its effect. For
% example, specify +compress to store the image as uncompressed.
%
% Specify 'file' as '-' for standard input or output.
%
% Buttons
% Control-1
% press and drag to pan the image
% 1 press and drag to select a command from a pop-up menu
% 2 press and drag to define a region of the image to clip
SHAR_EOF
true || echo 'restore of ImageMagick/display.c failed'
fi
echo 'End of ImageMagick part 16'
echo 'File ImageMagick/display.c is continued in part 17'
echo 17 > _shar_seq_.tmp
exit 0
--
Dan Heller
O'Reilly && Associates Z-Code Software Comp-sources-x:
Senior Writer President comp-sources-x@uunet.uu.net
argv@ora.com argv@zipcode.com