home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dream 52
/
Amiga_Dream_52.iso
/
Linux
/
Divers
/
ImageMagick-4.0.6.tar.gz
/
ImageMagick-4.0.6.tar
/
ImageMagick-4.0.6
/
import.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-04-22
|
30KB
|
796 lines
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% 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 X11 image to a machine independent format. %
% %
% %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1998 E. I. du Pont de Nemours and Company %
% %
% Permission is hereby granted, free of charge, to any person obtaining a %
% copy of this software and associated documentation files ("ImageMagick"), %
% to deal in ImageMagick without restriction, including without limitation %
% the rights to use, copy, modify, merge, publish, distribute, sublicense, %
% and/or sell copies of ImageMagick, and to permit persons to whom the %
% ImageMagick is furnished to do so, subject to the following conditions: %
% %
% The above copyright notice and this permission notice shall be included in %
% all copies or substantial portions of ImageMagick. %
% %
% The software is provided "as is", without warranty of any kind, express or %
% implied, including but not limited to the warranties of merchantability, %
% fitness for a particular purpose and noninfringement. In no event shall %
% E. I. du Pont de Nemours and Company be liable for any claim, damages or %
% other liability, whether in an action of contract, tort or otherwise, %
% arising from, out of or in connection with ImageMagick or the use or other %
% dealings in ImageMagick. %
% %
% Except as contained in this notice, the name of the E. I. du Pont de %
% Nemours and Company shall not be used in advertising or otherwise to %
% promote the sale, use or other dealings in ImageMagick without prior %
% written authorization from the E. I. du Pont de Nemours and Company. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Import is an X Window System window dumping utility. Import allows X
% users to store window images in a specially formatted dump file. This
% file can then be read by the Display utility for redisplay, printing,
% editing, formatting, archiving, image processing, etc. The target
% window can be specified by id or name or be selected by clicking the
% mouse in the desired window. The keyboard bell is rung once at the
% beginning of the dump and twice when the dump is completed.
%
% The import program command syntax is:
%
% Usage: import [options ...] [file]
%
% Where options include:
% -border include image borders in the output image
% -colors value preferred number of colors in the image
% -colorspace type alternate image colorspace
% -comment string annotate image with comment
% -compress type None, JPEG, LZW, RunlengthEncoded, or Zip
% -crop geometry preferred size and location of the cropped image
% -delay seconds pause before selecting target window
% -density geometry vertical and horizontal density of the image
% -descend obtain image by descending window hierarchy
% -display server X server to contact
% -dispose method GIF disposal method
% -dither apply Floyd/Steinberg error diffusion to image
% -frame include window manager frame
% -geometry geometry perferred size or location of the image
% -interlace type None, Line, Plane, or Partition
% -label name assign a label to an image
% -monochrome transform image to black and white
% -negate apply color inversion to image
% -page geometry size and location of an image canvas
% -ping efficiently determine image width and height
% -pointsize value pointsize of Postscript font
% -quality value JPEG/MIFF/PNG compression level
% -rotate degrees apply Paeth rotation to the image
% -scene value image scene number
% -screen select image from root window
% -silent operate silently, i.e. don't ring any bells
% -transparent color make this color transparent within the image
% -treedepth value depth of the color classification tree
% -verbose print detailed information about the image
% -window id select window with this id or name
%
% By default, 'file' is written in the Postscript image format. To specify
% a particular image format, precede the filename with an image format
% name and a colon (i.e. ps:image) or specify the image type as the
% filename suffix (i.e. image.ps). Specify 'file' as '-' for standard
% input or output.
%
%
*/
/*
Include declarations.
*/
#include "magick.h"
#include "version.h"
/*
Define declarations.
*/
#define DefaultImportName "magick.ps"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U s a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Procedure Usage displays the program usage;
%
% The format of the Usage routine is:
%
% Usage(client_name)
%
% o client_name: a character string representing the name of the client
% program.
%
%
*/
static void Usage(const char *client_name)
{
char
**p;
static char
*options[]=
{
"-border include image borders in the output image",
"-colors value preferred number of colors in the image",
"-colorspace type alternate image colorspace",
"-comment string annotate image with comment",
"-compress type None, JPEG, LZW, RunlengthEncoded, or Zip",
"-crop geometry preferred size and location of the cropped image",
"-delay seconds pause before selecting target window",
"-density geometry vertical and horizontal density of the image",
"-descend obtain image by descending window hierarchy",
"-display server X server to contact",
"-dispose method GIF disposal method",
"-dither apply Floyd/Steinberg error diffusion to image",
"-frame include window manager frame",
"-geometry geometry perferred size or location of the image",
"-interlace type None, Line, Plane, or Partition",
"-label name assign a label to an image",
"-monochrome transform image to black and white",
"-negate apply color inversion to image",
"-page geometry size and location of an image canvas",
"-ping efficiently determine image width and height",
"-pointsize value pointsize of Postscript font",
"-quality value JPEG/MIFF/PNG compression level",
"-rotate degrees apply Paeth rotation to the image",
"-scene value image scene number",
"-treedepth value depth of the color classification tree",
"-transparent color make this color transparent within the image",
"-silent operate silently, i.e. don't ring any bells ",
"-screen select image from root window",
"-verbose print detailed information about the image",
"-window id select window with this id or name",
(char *) NULL
};
(void) printf("Version: %s\n",Version);
(void) printf("Copyright: %s\n\n",Copyright);
(void) printf("Usage: %s [options ...] [file]\n",client_name);
(void) printf("\nWhere options include:\n");
for (p=options; *p != (char *) NULL; p++)
(void) printf(" %s\n",*p);
(void) printf(
"\nBy default, 'file' is written in the Postscript image format. To\n");
(void) printf(
"specify a particular image format, precede the filename with an image\n");
(void) printf(
"format name and a colon (i.e. ps:image) or specify the image type as\n");
(void) printf(
"the filename suffix (i.e. image.ps). Specify 'file' as '-' for\n");
(void) printf("standard input or output.\n");
Exit(0);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M a i n %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
int main(int argc,char **argv)
{
char
*client_name,
*filename,
*option,
*resource_value,
*target_window;
Display
*display;
Image
*image;
ImageInfo
image_info;
int
i,
x;
QuantizeInfo
quantize_info;
unsigned int
scene;
XImportInfo
ximage_info;
XResourceInfo
resource_info;
XrmDatabase
resource_database;
/*
Connect to X server.
*/
#if defined(WIN32)
SetErrorHandler(NTErrorHandler);
SetWarningHandler(NTWarningHandler);
#endif
GetImageInfo(&image_info);
GetQuantizeInfo(&quantize_info);
ReadCommandlLine(argc,&argv);
client_name=SetClientName(*argv);
for (i=1; i < argc; i++)
{
/*
Check command line for server name.
*/
option=argv[i];
if ((Extent(option) == 1) || ((*option != '-') && (*option != '+')))
continue;
if (strcmp("display",option+1) == 0)
{
/*
User specified server name.
*/
i++;
if (i == argc)
MagickError(OptionError,"Missing server name on -display",option);
image_info.server_name=argv[i];
break;
}
if (strncmp("help",option+1,2) == 0)
Usage(client_name);
}
/*
Get user defaults from X resource database.
*/
display=XOpenDisplay(image_info.server_name);
if (display == (Display *) NULL)
MagickError(OptionError,"Unable to connect to X server",
XDisplayName(image_info.server_name));
XSetErrorHandler(XError);
resource_database=XGetResourceDatabase(display,client_name);
GetImageInfo(&image_info);
XGetImportInfo(&ximage_info);
XGetResourceInfo(resource_database,client_name,&resource_info);
resource_value=
XGetResourceInstance(resource_database,client_name,"border","False");
ximage_info.borders=IsTrue(resource_value);
image_info.density=XGetResourceInstance(resource_database,client_name,
"density",(char *) NULL);
resource_value=
XGetResourceInstance(resource_database,client_name,"descend","True");
ximage_info.descend=IsTrue(resource_value);
resource_value=
XGetResourceInstance(resource_database,client_name,"frame","False");
ximage_info.frame=IsTrue(resource_value);
resource_value=
XGetResourceInstance(resource_database,client_name,"interlace","none");
image_info.interlace=UndefinedInterlace;
if (Latin1Compare("None",resource_value) == 0)
image_info.interlace=NoInterlace;
if (Latin1Compare("Line",resource_value) == 0)
image_info.interlace=LineInterlace;
if (Latin1Compare("Plane",resource_value) == 0)
image_info.interlace=PlaneInterlace;
if (Latin1Compare("Partition",resource_value) == 0)
image_info.interlace=PartitionInterlace;
if (image_info.interlace == UndefinedInterlace)
MagickWarning(OptionWarning,"Unrecognized interlace type",resource_value);
image_info.page=XGetResourceInstance(resource_database,client_name,
"pageGeometry",(char *) NULL);
resource_value=
XGetResourceInstance(resource_database,client_name,"quality","85");
image_info.quality=atoi(resource_value);
resource_value=
XGetResourceInstance(resource_database,client_name,"scene","0");
scene=atoi(resource_value);
resource_value=
XGetResourceInstance(resource_database,client_name,"screen","False");
ximage_info.screen=IsTrue(resource_value);
resource_value=
XGetResourceInstance(resource_database,client_name,"silent","False");
ximage_info.silent=IsTrue(resource_value);
resource_value=
XGetResourceInstance(resource_database,client_name,"verbose","False");
image_info.verbose=IsTrue(resource_value);
/*
Check command syntax.
*/
filename=(char *) NULL;
target_window=(char *) NULL;
for (i=1; i < argc; i++)
{
option=argv[i];
if ((Extent(option) < 2) || ((*option != '-') && (*option != '+')))
filename=argv[i];
else
switch(*(option+1))
{
case 'b':
{
if (strcmp("border",option+1) == 0)
{
ximage_info.borders=(*option == '-');
break;
}
if (strncmp("bordercolor",option+1,7) == 0)
{
if ((i == argc) || !sscanf(argv[i],"%d",&x))
{
i++;
if (i == argc)
MagickError(OptionError,"Missing color",option);
}
break;
}
MagickError(OptionError,"Unrecognized option",option);
break;
}
case 'c':
{
if (strncmp("colors",option+1,7) == 0)
{
quantize_info.number_colors=0;
if (*option == '-')
{
i++;
if ((i == argc) || !sscanf(argv[i],"%d",&x))
MagickError(OptionError,"Missing colors",option);
quantize_info.number_colors=atoi(argv[i]);
}
break;
}
if (strncmp("colorspace",option+1,7) == 0)
{
quantize_info.colorspace=RGBColorspace;
if (*option == '-')
{
i++;
if (i == argc)
MagickError(OptionError,"Missing type",option);
option=argv[i];
quantize_info.colorspace=UndefinedColorspace;
if (Latin1Compare("cmyk",option) == 0)
quantize_info.colorspace=CMYKColorspace;
if (Latin1Compare("gray",option) == 0)
{
quantize_info.colorspace=GRAYColorspace;
quantize_info.number_colors=256;
quantize_info.tree_depth=8;
}
if (Latin1Compare("ohta",option) == 0)
quantize_info.colorspace=OHTAColorspace;
if (Latin1Compare("rgb",option) == 0)
quantize_info.colorspace=RGBColorspace;
if (Latin1Compare("transparent",option) == 0)
quantize_info.colorspace=TransparentColorspace;
if (Latin1Compare("xyz",option) == 0)
quantize_info.colorspace=XYZColorspace;
if (Latin1Compare("ycbcr",option) == 0)
quantize_info.colorspace=YCbCrColorspace;
if (Latin1Compare("yiq",option) == 0)
quantize_info.colorspace=YIQColorspace;
if (Latin1Compare("ypbpr",option) == 0)
quantize_info.colorspace=YPbPrColorspace;
if (Latin1Compare("yuv",option) == 0)
quantize_info.colorspace=YUVColorspace;
if (quantize_info.colorspace == UndefinedColorspace)
MagickError(OptionError,"Invalid colorspace type",option);
}
break;
}
if (strncmp("comment",option+1,4) == 0)
{
if (*option == '-')
{
i++;
if (i == argc)
MagickError(OptionError,"Missing comment",option);
}
break;
}
if (strncmp("compress",option+1,5) == 0)
{
image_info.compression=NoCompression;
if (*option == '-')
{
i++;
if (i == argc)
MagickError(OptionError,"Missing type",option);
option=argv[i];
image_info.compression=UndefinedCompression;
if (Latin1Compare("None",option) == 0)
image_info.compression=NoCompression;
if (Latin1Compare("JPEG",option) == 0)
image_info.compression=JPEGCompression;
if (Latin1Compare("LZW",option) == 0)
image_info.compression=LZWCompression;
if (Latin1Compare("RunlengthEncoded",option) == 0)
image_info.compression=RunlengthEncodedCompression;
if (Latin1Compare("Zip",option) == 0)
image_info.compression=ZipCompression;
if (image_info.compression == UndefinedCompression)
MagickError(OptionError,"Invalid compression type",option);
}
break;
}
if (strncmp("crop",option+1,2) == 0)
{
if (*option == '-')
{
i++;
if ((i == argc) || !IsGeometry(argv[i]))
MagickError(OptionError,"Missing geometry",option);
}
break;
}
MagickError(OptionError,"Unrecognized option",option);
break;
}
case 'd':
{
if (strncmp("delay",option+1,3) == 0)
{
image_info.delay=(char *) NULL;
if (*option == '-')
{
i++;
if ((i == argc) || !sscanf(argv[i],"%d",&x))
MagickError(OptionError,"Missing delay",option);
image_info.delay=PostscriptGeometry(argv[i]);
}
break;
}
if (strncmp("density",option+1,3) == 0)
{
image_info.density=(char *) NULL;
if (*option == '-')
{
i++;
if ((i == argc) || !IsGeometry(argv[i]))
MagickError(OptionError,"Missing geometry",option);
image_info.density=argv[i];
}
break;
}
if (strncmp("descend",option+1,3) == 0)
{
ximage_info.descend=(*option == '-');
break;
}
if (strcmp("display",option+1) == 0)
{
image_info.server_name=(char *) NULL;
if (*option == '-')
{
i++;
if (i == argc)
MagickError(OptionError,"Missing server name",option);
image_info.server_name=argv[i];
}
break;
}
if (strncmp("dispose",option+1,5) == 0)
{
image_info.dispose=(char *) NULL;
if (*option == '-')
{
i++;
if ((i == argc) || !sscanf(argv[i],"%d",&x))
MagickError(OptionError,"Missing method",option);
image_info.dispose=PostscriptGeometry(argv[i]);
}
break;
}
if (strncmp("dither",option+1,3) == 0)
{
quantize_info.dither=(*option == '-');
break;
}
MagickError(OptionError,"Unrecognized option",option);
break;
}
case 'f':
{
argv[i]="-ignore"; /* resolve option confict */
ximage_info.frame=(*option == '-');
break;
}
case 'g':
{
if (strncmp("geometry",option+1,2) == 0)
{
if (*option == '-')
{
i++;
if ((i == argc) || !IsGeometry(argv[i]))
MagickError(OptionError,"Missing geometry",option);
}
break;
}
MagickError(OptionError,"Unrecognized option",option);
break;
}
case 'h':
{
if (strncmp("help",option+1,2) == 0)
{
Usage(client_name);
break;
}
MagickError(OptionError,"Unrecognized option",option);
break;
}
case 'i':
{
if (strncmp("interlace",option+1,3) == 0)
{
image_info.interlace=NoInterlace;
if (*option == '-')
{
i++;
if (i == argc)
MagickError(OptionError,"Missing type",option);
option=argv[i];
image_info.interlace=UndefinedInterlace;
if (Latin1Compare("No",option) == 0)
image_info.interlace=NoInterlace;
if (Latin1Compare("Line",option) == 0)
image_info.interlace=LineInterlace;
if (Latin1Compare("Plane",option) == 0)
image_info.interlace=PlaneInterlace;
if (Latin1Compare("Partition",option) == 0)
image_info.interlace=PartitionInterlace;
if (image_info.interlace == UndefinedInterlace)
MagickError(OptionError,"Invalid interlace type",option);
}
break;
}
MagickError(OptionError,"Unrecognized option",option);
break;
}
case 'l':
{
if (strncmp("label",option+1,3) == 0)
{
if (*option == '-')
{
i++;
if (i == argc)
MagickError(OptionError,"Missing label name",option);
}
break;
}
MagickError(OptionError,"Unrecognized option",option);
break;
}
case 'm':
{
if (strncmp("monochrome",option+1,2) == 0)
{
image_info.monochrome=(*option == '-');
if (image_info.monochrome)
{
quantize_info.number_colors=2;
quantize_info.tree_depth=8;
quantize_info.colorspace=GRAYColorspace;
}
break;
}
MagickError(OptionError,"Unrecognized option",option);
}
case 'n':
{
if (strncmp("negate",option+1,2) == 0)
break;
MagickError(OptionError,"Unrecognized option",option);
}
case 'p':
{
if (strncmp("page",option+1,3) == 0)
{
image_info.page=(char *) NULL;
if (*option == '-')
{
i++;
if (i == argc)
MagickError(OptionError,"Missing page geometry",option);
image_info.page=PostscriptGeometry(argv[i]);
}
break;
}
if (strncmp("ping",option+1,2) == 0)
{
image_info.ping=(*option == '-');
break;
}
if (strncmp("pointsize",option+1,2) == 0)
{
image_info.pointsize=atoi(DefaultPointSize);
if (*option == '-')
{
i++;
if ((i == argc) || !sscanf(argv[i],"%d",&x))
MagickError(OptionError,"Missing size",option);
image_info.pointsize=atoi(argv[i]);
}
break;
}
MagickError(OptionError,"Unrecognized option",option);
break;
}
case 'q':
{
if (strncmp("quality",option+1,2) == 0)
{
image_info.quality=0;
if (*option == '-')
{
i++;
if ((i == argc) || !sscanf(argv[i],"%d",&x))
MagickError(OptionError,"Missing quality",option);
image_info.quality=atoi(argv[i]);
}
break;
}
MagickError(OptionError,"Unrecognized option",option);
break;
}
case 'r':
{
if (strncmp("rotate",option+1,3) == 0)
{
if (*option == '-')
{
i++;
if ((i == argc) || !IsGeometry(argv[i]))
MagickError(OptionError,"Missing degrees",option);
}
break;
}
MagickError(OptionError,"Unrecognized option",option);
break;
}
case 's':
{
if (strncmp("scene",option+1,3) == 0)
{
i++;
if ((i == argc) || !sscanf(argv[i],"%d",&x))
MagickError(OptionError,"Missing scene",option);
scene=atoi(argv[i]);
break;
}
if (strncmp("screen",option+1,3) == 0)
{
ximage_info.screen=(*option == '-');
break;
}
if (strncmp("silent",option+1,3) == 0)
{
ximage_info.silent=(*option == '-');
break;
}
MagickError(OptionError,"Unrecognized option",option);
break;
}
case 't':
{
if (strncmp("transparent",option+1,3) == 0)
{
if (*option == '-')
{
i++;
if (i == argc)
MagickError(OptionError,"Missing color",option);
}
break;
}
if (strncmp("treedepth",option+1,3) == 0)
{
quantize_info.tree_depth=0;
if (*option == '-')
{
i++;
if ((i == argc) || !sscanf(argv[i],"%d",&x))
MagickError(OptionError,"Missing depth",option);
quantize_info.tree_depth=atoi(argv[i]);
}
break;
}
MagickError(OptionError,"Unrecognized option",option);
break;
}
case 'w':
{
i++;
if (i == argc)
MagickError(OptionError,"Missing id, name, or 'root'",option);
target_window=argv[i];
break;
}
case 'v':
{
image_info.verbose=(*option == '-');
break;
}
case '?':
{
Usage(client_name);
break;
}
default:
{
MagickError(OptionError,"Unrecognized option",option);
break;
}
}
}
if (filename == (char *) NULL)
filename=DefaultImportName;
/*
Read image from X server.
*/
if (target_window != (char *) NULL)
(void) strcpy(image_info.filename,target_window);
if (image_info.delay != (char *) NULL)
(void) sleep(atoi(image_info.delay));
image_info.colorspace=quantize_info.colorspace;
image_info.dither=quantize_info.dither;
image=ReadXImage(&image_info,&ximage_info);
if (image == (Image *) NULL)
MagickError(OptionError,"Missing an image file name",(char *) NULL);
(void) strcpy(image->magick,"X");
/*
Transmogrify image as defined by the image processing options.
*/
MogrifyImage(&image_info,argc,argv,&image);
/*
Write import X image.
*/
image->scene=scene;
(void) strcpy(image_info.filename,filename);
(void) strcpy(image->magick,"PS");
(void) strcpy(image->filename,filename);
(void) WriteImage(&image_info,image);
if (image_info.verbose)
DescribeImage(image,stdout,False);
DestroyImage(image);
Exit(0);
return(False);
}