home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
x
/
volume13
/
imagemagic
/
part18
< prev
next >
Wrap
Internet Message Format
|
1991-05-23
|
75KB
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: v13i034: ImageMagick - Graphics display programs, Part18/21
Message-ID: <13948@exodus.Eng.Sun.COM>
Date: 24 May 91 03:20:35 GMT
References: <csx-13i017:imagemagic@uunet.UU.NET>
Sender: news@exodus.Eng.Sun.COM
Lines: 2370
Approved: argv@sun.com
Submitted-by: cristy@dupont.com
Posting-number: Volume 13, Issue 34
Archive-name: imagemagic/part18
#!/bin/sh
# this is img.18 (part 18 of ImageMagick)
# do not concatenate these parts, unpack them in order with /bin/sh
# file ImageMagick/display.c continued
#
if test ! -r _shar_seq_.tmp; then
echo 'Please unpack part 1 first!'
exit 1
fi
(read Scheck
if test "$Scheck" != 18; 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/display.c'
else
echo 'x - continuing file ImageMagick/display.c'
sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/display.c' &&
X magnify_window)
Display
X *display;
X
XXResourceInfo
X *resource_info;
X
XXWindowInfo
X *info_window,
X *image_window,
X *magnify_window;
{
X char
X text[256];
X
X register int
X x,
X y;
X
X unsigned int
X state;
X
X XColor
X color;
X
X XEvent
X event;
X
X /*
X Map info window.
X */
X state=DefaultState;
X (void) sprintf(text," %+d%+d #%02x%02x%02x \0",image_window->width,
X image_window->height,MaxRgb,MaxRgb,MaxRgb);
X info_window->width=XTextWidth(info_window->font_info,text,strlen(text));
X info_window->height=
X info_window->font_info->ascent+info_window->font_info->descent+4;
X XResizeWindow(display,info_window->id,info_window->width,
X info_window->height);
X XMapWindow(display,info_window->id);
X state|=InfoMappedState;
X /*
X Update magnified image until the mouse button is released.
X */
X XDefineCursor(display,image_window->id,magnify_window->cursor);
X ConstrainMagnifyFactor(image_window,magnify_window,resource_info->magnify);
X state|=MagnifyState;
X do
X {
X if (state & MagnifyState)
X {
X /*
X Display pointer position.
X */
X color.pixel=
X XGetPixel(image_window->ximage,magnify_window->x,magnify_window->y);
X XQueryColor(display,image_window->map_info->colormap,&color);
X (void) sprintf(text," %+d%+d #%02x%02x%02x \0",magnify_window->x,
X magnify_window->y,color.red >> 8,color.green >> 8,color.blue >> 8);
X XClearWindow(display,info_window->id);
X XDrawString(display,info_window->id,info_window->graphic_context,2,
X info_window->font_info->ascent+2,text,strlen(text));
X /*
X Display magnified image.
X */
X XMakeMagnifyImage(magnify_window,image_window->ximage,
X resource_info->magnify);
X XPutImage(display,magnify_window->id,magnify_window->graphic_context,
X magnify_window->ximage,0,0,0,0,magnify_window->width,
X magnify_window->height);
X }
X /*
X Wait for next event.
X */
X XMaskEvent(display,ButtonPressMask | Button3MotionMask |
X ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | KeyPressMask,
X &event);
X switch (event.type)
X {
X case ButtonPress:
X break;
X case ButtonRelease:
X {
X /*
X User has finished magnifying image.
X */
X if (event.xbutton.button != Button3)
X break;
X state|=ExitState;
X break;
X }
X case KeyPress:
X {
X static char
X command[256];
X
X static KeySym
X key_symbol;
X
X /*
X Respond to a user key press.
X */
X *command=(char) NULL;
X XLookupString((XKeyEvent *) &event.xkey,command,sizeof(command),
X &key_symbol,(XComposeStatus *) NULL);
X if (!isdigit(*command))
X XBell(display,0);
X else
X {
X /*
X User specified a new magnify factor.
X */
X resource_info->magnify=1 << atoi(command);
X ConstrainMagnifyFactor(image_window,magnify_window,
X resource_info->magnify);
X break;
X }
X break;
X }
X case EnterNotify:
X {
X x=event.xcrossing.x;
X y=event.xcrossing.y;
X /*
X Check boundary conditions.
X */
X if (x < 0)
X x=0;
X else
X if (x >= image_window->width)
X x=image_window->width-1;
X if (y < 0)
X y=0;
X else
X if (y >= image_window->height)
X y=image_window->height-1;
X magnify_window->x=x-image_window->x;
X magnify_window->y=y-image_window->y;
X state|=MagnifyState;
X break;
X }
X case LeaveNotify:
X {
X state&=(~MagnifyState);
X break;
X }
X case MotionNotify:
X {
X /*
X Discard pending button motion events.
X */
X while (XCheckMaskEvent(display,Button3MotionMask,&event));
X x=event.xmotion.x;
X y=event.xmotion.y;
X /*
X Check boundary conditions.
X */
X if (x < 0)
X x=0;
X else
X if (x >= image_window->width)
X x=image_window->width-1;
X if (y < 0)
X y=0;
X else
X if (y >= image_window->height)
X y=image_window->height-1;
X magnify_window->x=x-image_window->x;
X magnify_window->y=y-image_window->y;
X break;
X }
X default:
X break;
X }
X } while (!(state & ExitState));
X XDefineCursor(display,image_window->id,image_window->cursor);
X XWithdrawWindow(display,info_window->id,info_window->screen);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% X M a k e C u r s o r %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Function XMakeCursor creates a crosshairs X11 cursor.
%
% The format of the XMakeCursor routine is:
%
% XMakeCursor(display,window,colormap,background_color,foreground_color)
%
% A description of each parameter follows:
%
% o display: Specifies a connection to an X server; returned from
% XOpenDisplay.
%
% o window: Specifies the ID of the window for which the cursor is
% assigned.
%
% o colormap: Specifies the ID of the colormap from which the background
% and foreground color will be retrieved.
%
% o background_color: Specifies the color to use for the cursor background.
%
% o foreground_color: Specifies the color to use for the cursor foreground.
%
%
*/
static Cursor XMakeCursor(display,window,colormap,background_color,
X foreground_color)
Display
X *display;
X
Colormap
X colormap;
X
Window
X window;
X
char
X *background_color,
X *foreground_color;
{
#define scope_height 17
#define scope_mask_width 17
#define scope_mask_height 17
#define scope_x_hot 8
#define scope_y_hot 8
#define scope_width 17
X
X static unsigned char scope_bit[] =
X {
X 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00,
X 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
X 0x7e, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00,
X 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00,
X 0x00, 0x00, 0x00
X };
X
X static unsigned char scope_mask_bit[] =
X {
X 0x80, 0x03, 0x00, 0x80, 0x03, 0x00, 0x80, 0x03, 0x00, 0x80, 0x03, 0x00,
X 0x80, 0x03, 0x00, 0x80, 0x03, 0x00, 0x80, 0x03, 0x00, 0x7f, 0xfc, 0x01,
X 0x7f, 0xfc, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x03, 0x00, 0x80, 0x03, 0x00,
X 0x80, 0x03, 0x00, 0x80, 0x03, 0x00, 0x80, 0x03, 0x00, 0x80, 0x03, 0x00,
X 0x80, 0x03, 0x00
X };
X
X Cursor
X cursor;
X
X Pixmap
X mask,
X source;
X
X XColor
X background,
X foreground;
X
X source=XCreateBitmapFromData(display,window,(char *) scope_bit,scope_width,
X scope_height);
X mask=XCreateBitmapFromData(display,window,(char *) scope_mask_bit,
X scope_width,scope_height);
X if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
X Error("unable to create pixmap",(char *) NULL);
X XParseColor(display,colormap,background_color,&background);
X XParseColor(display,colormap,foreground_color,&foreground);
X cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
X scope_x_hot,scope_y_hot);
X if (cursor == (Cursor) NULL)
X Error("unable to create cursor",(char *) NULL);
X XFreePixmap(display,source);
X XFreePixmap(display,mask);
X return(cursor);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% X M a k e M a g n i f y I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Function XMakeMagnifyImage magnifies a region of an X image and returns it.
%
% The format of the XMakeMagnifyImage routine is:
%
% XMakeMagnifyImage(magnify_window,ximage,magnify)
%
% A description of each parameter follows:
%
% o magnify_window: Specifies a pointer to a XWindowInfo structure.
%
% o ximage: Specifies a pointer to a XImage structure; returned from
% XMakeImage.
%
% o magnify: level of image magnification.
%
%
*/
static void XMakeMagnifyImage(magnify_window,ximage,magnify)
XXWindowInfo
X *magnify_window;
X
XXImage
X *ximage;
X
unsigned int
X magnify;
{
X int
X x,
X y;
X
X register unsigned char
X *p,
X *q;
X
X register unsigned int
X j,
X k,
X l;
X
X unsigned int
X i,
X scanline_pad;
X
X /*
X Check boundry conditions.
X */
X x=magnify_window->x-(magnify_window->ximage->width/magnify/2);
X if (x < 0)
X x=0;
X else
X if (x > (ximage->width-(magnify_window->ximage->width/magnify)))
X x=ximage->width-magnify_window->ximage->width/magnify;
X y=magnify_window->y-(magnify_window->ximage->width/magnify/2);
X if (y < 0)
X y=0;
X else
X if (y > (ximage->height-(magnify_window->ximage->height/magnify)))
X y=ximage->height-magnify_window->ximage->height/magnify;
X q=(unsigned char *) magnify_window->ximage->data;
X scanline_pad=magnify_window->ximage->bytes_per_line-
X ((magnify_window->ximage->width*
X magnify_window->ximage->bits_per_pixel) >> 3);
X if (ximage->bits_per_pixel < 8)
X {
X register unsigned char
X byte,
X p_bit,
X q_bit;
X
X register unsigned int
X plane;
X
X switch (ximage->bitmap_bit_order)
X {
X case LSBFirst:
X {
X /*
X Magnify little-endian bitmap.
X */
X for (i=0; i < magnify_window->ximage->height; i+=magnify)
X {
X /*
X Propogate pixel magnify rows.
X */
X for (j=0; j < magnify; j++)
X {
X p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
X ((x*ximage->bits_per_pixel) >> 3);
X p_bit=(x*ximage->bits_per_pixel) & 0x07;
X q_bit=0;
X byte=0;
X for (k=0; k < magnify_window->ximage->width; k+=magnify)
X {
X /*
X Propogate pixel magnify columns.
X */
X for (l=0; l < magnify; l++)
X {
X /*
X Propogate each bit plane.
X */
X for (plane=0; plane < ximage->bits_per_pixel; plane++)
X {
X byte>>=1;
X if (*p & (0x01 << (p_bit+plane)))
X byte|=0x80;
X q_bit++;
X if (q_bit == 8)
X {
X *q++=byte;
X q_bit=0;
X byte=0;
X }
X }
X }
X p_bit+=ximage->bits_per_pixel;
X if (p_bit == 8)
X {
X p++;
X p_bit=0;
X }
X if (q_bit > 0)
X *q=byte >> (8-q_bit);
X q+=scanline_pad;
X }
X }
X y++;
X }
X break;
X }
X case MSBFirst:
X default:
X {
X /*
X Magnify big-endian bitmap.
X */
X for (i=0; i < magnify_window->ximage->height; i+=magnify)
X {
X /*
X Propogate pixel magnify rows.
X */
X for (j=0; j < magnify; j++)
X {
X p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
X ((x*ximage->bits_per_pixel) >> 3);
X p_bit=(x*ximage->bits_per_pixel) & 0x07;
X q_bit=0;
X byte=0;
X for (k=0; k < magnify_window->ximage->width; k+=magnify)
X {
X /*
X Propogate pixel magnify columns.
X */
X for (l=0; l < magnify; l++)
X {
X /*
X Propogate each bit plane.
X */
X for (plane=0; plane < ximage->bits_per_pixel; plane++)
X {
X byte<<=1;
X if (*p & (0x80 >> (p_bit+plane)))
X byte|=0x01;
X q_bit++;
X if (q_bit == 8)
X {
X *q++=byte;
X q_bit=0;
X byte=0;
X }
X }
X }
X p_bit+=ximage->bits_per_pixel;
X if (p_bit == 8)
X {
X p++;
X p_bit=0;
X }
X if (q_bit > 0)
X *q=byte << (8-q_bit);
X q+=scanline_pad;
X }
X }
X y++;
X }
X break;
X }
X }
X }
X else
X switch (ximage->bits_per_pixel)
X {
X case 8:
X {
X /*
X Magnify 8 bit X image.
X */
X for (i=0; i < magnify_window->ximage->height; i+=magnify)
X {
X /*
X Propogate pixel magnify rows.
X */
X for (j=0; j < magnify; j++)
X {
X p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
X ((x*ximage->bits_per_pixel) >> 3);
X for (k=0; k < magnify_window->ximage->width; k+=magnify)
X {
X /*
X Propogate pixel magnify columns.
X */
X for (l=0; l < magnify; l++)
X *q++=(*p);
X p++;
X }
X q+=scanline_pad;
X }
X y++;
X }
X break;
X }
X default:
X {
X register unsigned int
X bytes_per_pixel,
X m;
X
X /*
X Magnify multi-byte X image.
X */
X bytes_per_pixel=ximage->bits_per_pixel >> 3;
X for (i=0; i < magnify_window->ximage->height; i+=magnify)
X {
X /*
X Propogate pixel magnify rows.
X */
X for (j=0; j < magnify; j++)
X {
X p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
X ((x*ximage->bits_per_pixel) >> 3);
X for (k=0; k < magnify_window->ximage->width; k+=magnify)
X {
X /*
X Propogate pixel magnify columns.
X */
X for (l=0; l < magnify; l++)
X for (m=0; m < bytes_per_pixel; m++)
X *q++=(*(p+m));
X p+=bytes_per_pixel;
X }
X q+=scanline_pad;
X }
X y++;
X }
X break;
X }
X }
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% X M e n u W i n d o w %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Function XMenuWindow maps a menu and returns the command pointed to by the
% user when the button is released.
%
% The format of the XMenuWindow routine is:
%
% XMenuWindow(display,menu_window,x,y)
%
% A description of each parameter follows:
%
% o display: Specifies a connection to an X server; returned from
% XOpenDisplay.
%
% o menu_window: Specifies a pointer to a XWindowInfo structure.
%
% o x: Specifies an unsigned integer representing the root offset the
% x-direction.
%
% o y: Specifies an unsigned integer representing the root offset the
% x-direction.
%
% o command: Specifies a character array. The command selected from
% the menu is returned here.
%
%
*/
static void XMenuWindow(display,menu_window,x,y,command)
Display
X *display;
X
XXWindowInfo
X *menu_window;
X
int
X x,
X y;
X
char
X *command;
{
#define MaxMenuSelections 11
X
X typedef struct _Selection
X {
X int
X id,
X x,
X y;
X
X unsigned int
X width,
X height;
X } Selection;
X
X static char
X *MenuSelections[]=
X {
X "iImage Info ",
X "<Half Size ",
X ">Double Size ",
X "/Rotate Right ",
X "\\Rotate Left ",
X "rReflect Image ",
X "oRestore Image ",
X "wRestore Window",
X "mMagnify Window",
X "nNext Image ",
X "qQuit ",
X };
X
X char
X text[256];
X
X Selection
X last_selection,
X selection;
X
X unsigned int
X height,
X state,
X width;
X
X XEvent
X event;
X
X /*
X Size and position menu window under current pointer location and map.
X */
X (void) sprintf(text," %s\0",MenuSelections[0]);
X menu_window->width=XTextWidth(menu_window->font_info,text,strlen(text));
X menu_window->height=MaxMenuSelections*
X (menu_window->font_info->ascent+menu_window->font_info->descent+4);
X width=menu_window->width+2*menu_window->border_width;
X menu_window->x=x-(int) width/2;
X if (menu_window->x < 0)
X menu_window->x=0;
X else
X if (menu_window->x > (XDisplayWidth(display,menu_window->screen)-width))
X menu_window->x=XDisplayWidth(display,menu_window->screen)-width;
X height=menu_window->height+2*menu_window->border_width;
X menu_window->y=y-(int) menu_window->border_width;
X if (menu_window->y < 0)
X menu_window->y=0;
X else
X if (menu_window->y > (XDisplayHeight(display,menu_window->screen)-height))
X menu_window->y=XDisplayHeight(display,menu_window->screen)-height;
X XMoveResizeWindow(display,menu_window->id,menu_window->x,menu_window->y,
X menu_window->width,menu_window->height);
X XMapRaised(display,menu_window->id);
X XWindowEvent(display,menu_window->id,ExposureMask,&event);
X /*
X Draw menu selection selections.
X */
X selection.x=menu_window->font_info->max_bounds.rbearing-
X menu_window->font_info->min_bounds.lbearing;
X selection.y=menu_window->font_info->ascent+2;
X selection.width=strlen(MenuSelections[0]+1);
X selection.height=menu_window->font_info->descent+
X menu_window->font_info->ascent+4;
X for (selection.id=0; selection.id < MaxMenuSelections; selection.id++)
X {
X XDrawString(display,menu_window->id,menu_window->graphic_context,
X selection.x,selection.y,MenuSelections[selection.id]+1,selection.width);
X selection.y+=(int) selection.height;
X }
X /*
X Highlight menu as pointer moves; return command on button release.
X */
X selection.id=0;
X last_selection=selection;
X state=DefaultState;
X do
X {
X /*
X Wait for next event.
X */
X XMaskEvent(display,ButtonPressMask | Button1MotionMask |
X ButtonReleaseMask | EnterWindowMask | LeaveWindowMask,&event);
X switch (event.type)
X {
X case ButtonPress:
X break;
X case ButtonRelease:
X {
X /*
X Determine if user choose a menu item.
X */
X if (event.xbutton.button != Button1)
X break;
X state|=ExitState;
X break;
X }
X case EnterNotify:
X {
X if (event.xcrossing.window != menu_window->id)
X break;
X selection.id=event.xcrossing.y/(int) selection.height;
X /*
X Check boundary conditions.
X */
X if (selection.id < 0)
X selection.id=0;
X if (selection.id >= MaxMenuSelections)
X selection.id=MaxMenuSelections-1;
X /*
X Highlight this selection.
X */
X selection.y=
X menu_window->font_info->ascent+2+selection.id*selection.height;
X XSetBackground(display,menu_window->graphic_context,
X menu_window->pixel_info->foreground_pixel);
X XSetForeground(display,menu_window->graphic_context,
X menu_window->pixel_info->background_pixel);
X XDrawImageString(display,menu_window->id,
X menu_window->graphic_context,selection.x,selection.y,
X MenuSelections[selection.id]+1,selection.width);
X XSetBackground(display,menu_window->graphic_context,
X menu_window->pixel_info->background_pixel);
X XSetForeground(display,menu_window->graphic_context,
X menu_window->pixel_info->foreground_pixel);
X last_selection=selection;
X state|=HighlightState;
X break;
X }
X case LeaveNotify:
X {
X if (event.xcrossing.window != menu_window->id)
X break;
X /*
X Unhighlight last selection.
X */
X XDrawImageString(display,menu_window->id,
X menu_window->graphic_context,last_selection.x,last_selection.y,
X MenuSelections[last_selection.id]+1,last_selection.width);
X state&=(~HighlightState);
X break;
X }
X case MotionNotify:
X {
X /*
X Discard pending selection motion events.
X */
X while (XCheckMaskEvent(display,Button1MotionMask,&event));
X if (event.xmotion.window != menu_window->id)
X break;
X /*
X Check boundary conditions.
X */
X selection.id=event.xmotion.y/(int) selection.height;
X if (selection.id < 0)
X selection.id=0;
X if (selection.id >= MaxMenuSelections)
X selection.id=MaxMenuSelections-1;
X if (!(state & HighlightState))
X break;
X if (selection.id == last_selection.id)
X break;
X /*
X Unhighlight last selection.
X */
X XDrawImageString(display,menu_window->id,
X menu_window->graphic_context,last_selection.x,last_selection.y,
X MenuSelections[last_selection.id]+1,last_selection.width);
X /*
X Highlight this selection.
X */
X selection.y=
X menu_window->font_info->ascent+2+selection.id*selection.height;
X XSetBackground(display,menu_window->graphic_context,
X menu_window->pixel_info->foreground_pixel);
X XSetForeground(display,menu_window->graphic_context,
X menu_window->pixel_info->background_pixel);
X XDrawImageString(display,menu_window->id,
X menu_window->graphic_context,selection.x,selection.y,
X MenuSelections[selection.id]+1,selection.width);
X XSetBackground(display,menu_window->graphic_context,
X menu_window->pixel_info->background_pixel);
X XSetForeground(display,menu_window->graphic_context,
X menu_window->pixel_info->foreground_pixel);
X last_selection=selection;
X break;
X }
X default:
X break;
X }
X } while (!(state & ExitState));
X XWithdrawWindow(display,menu_window->id,menu_window->screen);
X *command=(char) NULL;
X if (state & HighlightState)
X (void) strcpy(command,MenuSelections[selection.id]);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% X P a n I m a g e W i n d o w %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Function XPanImageWindow pans the image until the mouse button is released.
%
% The format of the XPanImageWindow routine is:
%
% XPanImageWindow(display,info_window,image_window,x_offset,y_offset)
%
% A description of each parameter follows:
%
% o display: Specifies a connection to an X server; returned from
% XOpenDisplay.
%
% o info_window: Specifies a pointer to a XWindowInfo structure.
%
% o image_window: Specifies a pointer to a XWindowInfo structure.
%
% o x_offset: Specifies the initial offset in the x-direction.
%
% o y_offset: Specifies the initial offset in the y-direction.
%
%
*/
static void XPanImageWindow(display,info_window,image_window,x_offset,y_offset)
Display
X *display;
X
XXWindowInfo
X *info_window,
X *image_window;
X
int
X x_offset,
X y_offset;
{
X char
X text[256];
X
X Cursor
X cursor;
X
X unsigned int
X state;
X
X XEvent
X event;
X
X /*
X Map info window.
X */
X state=DefaultState;
X (void) sprintf(text," %dx%d%+d%+d \0",image_window->ximage->width,
X image_window->ximage->height,image_window->ximage->width,
X image_window->ximage->height);
X info_window->width=XTextWidth(info_window->font_info,text,strlen(text));
X info_window->height=
X info_window->font_info->ascent+info_window->font_info->descent+4;
X XResizeWindow(display,info_window->id,info_window->width,
X info_window->height);
X XMapWindow(display,info_window->id);
X state|=InfoMappedState;
X /*
X Define cursor.
X */
X if ((image_window->ximage->width > image_window->width) &&
X (image_window->ximage->height > image_window->height))
X cursor=XCreateFontCursor(display,XC_fleur);
X else
X if (image_window->ximage->width > image_window->width)
X cursor=XCreateFontCursor(display,XC_sb_h_double_arrow);
X else
X if (image_window->ximage->height > image_window->height)
X cursor=XCreateFontCursor(display,XC_sb_v_double_arrow);
X else
X cursor=XCreateFontCursor(display,XC_arrow);
X if (cursor == (Cursor) NULL)
X Error("unable to create cursor",(char *) NULL);
X XDefineCursor(display,image_window->id,cursor);
X /*
X Pan image as pointer moves until the mouse button is released.
X */
X do
X {
X /*
X Display image pan offset.
X */
X (void) sprintf(text," %dx%d%+d%+d \0",image_window->ximage->width,
X image_window->ximage->height,image_window->x,image_window->y);
X XClearWindow(display,info_window->id);
X XDrawString(display,info_window->id,info_window->graphic_context,2,
X info_window->font_info->ascent+2,text,strlen(text));
X /*
X Display image window.
X */
X XDisplayImageWindow(display,image_window,0,0,image_window->width,
X image_window->height);
X /*
X Wait for next event.
X */
X XMaskEvent(display,ButtonPressMask | Button1MotionMask | ButtonReleaseMask,
X &event);
X switch (event.type)
X {
X case ButtonPress:
X break;
X case ButtonRelease:
X {
X /*
X User has finished panning the image.
X */
X if (event.xbutton.button != Button1)
X break;
X state|=ExitState;
X break;
X }
X case MotionNotify:
X {
X /*
X Discard pending button motion events.
X */
X while (XCheckMaskEvent(display,Button1MotionMask,&event));
X image_window->x-=(x_offset-event.xmotion.x);
X image_window->y-=(y_offset-event.xmotion.y);
X x_offset=event.xmotion.x;
X y_offset=event.xmotion.y;
X /*
X Check boundary conditions.
X */
X if (image_window->x < (-image_window->ximage->width))
X image_window->x=(-image_window->ximage->width);
X else
X if (image_window->x > image_window->ximage->width)
X image_window->x=image_window->ximage->width;
X if (image_window->y < (-image_window->ximage->height))
X image_window->y=(-image_window->ximage->height);
X else
X if (image_window->y > image_window->ximage->height)
X image_window->y=image_window->ximage->height;
X }
X default:
X break;
X }
X } while (!(state & ExitState));
X XDefineCursor(display,image_window->id,image_window->cursor);
X XFreeCursor(display,cursor);
X XWithdrawWindow(display,info_window->id,info_window->screen);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% X R e f l e c t I m a g e W i n d o w %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Function XReflectImageWindow reflects the scanlines of an image.
%
% The format of the XReflectImageWindow routine is:
%
% status=XReflectImageWindow(display,info_window,image_window,image)
%
% A description of each parameter follows:
%
% o status: Function XReflectImageWindow return True if the window scanlines
% reverse. False is returned is there is a memory shortage or if the
% window scanlines fails to reverse.
%
% o display: Specifies a connection to an X server; returned from
% XOpenDisplay.
%
% o info_window: Specifies a pointer to a XWindowInfo structure.
%
% o image_window: Specifies a pointer to a XWindowInfo structure.
%
% o image: Specifies a pointer to a Image structure; returned from
% ReadImage.
%
%
*/
static unsigned int XReflectImageWindow(display,info_window,image_window,image)
Display
X *display;
X
XXWindowInfo
X *info_window,
X *image_window;
X
Image
X **image;
{
X char
X text[256];
X
X Image
X *reflected_image;
X
X unsigned int
X state;
X
X state=DefaultState;
X if (((*image)->columns*(*image)->rows) > MinInfoSize)
X {
X /*
X Map image window.
X */
X (void) strcpy(text," Reflecting image... ");
X info_window->width=XTextWidth(info_window->font_info,text,strlen(text));
X info_window->height=
X info_window->font_info->ascent+info_window->font_info->descent+4;
X XResizeWindow(display,info_window->id,info_window->width,
X info_window->height);
X XMapWindow(display,info_window->id);
X XClearWindow(display,info_window->id);
X XDrawString(display,info_window->id,info_window->graphic_context,2,
X info_window->font_info->ascent+2,text,strlen(text));
X state|=InfoMappedState;
X }
X /*
X Reflect image scanlines.
X */
X XDefineCursor(display,image_window->id,image_window->busy_cursor);
X XFlush(display);
X reflected_image=ReflectImage(*image);
X if (reflected_image == (Image *) NULL)
X {
X Warning("unable to reflect X image",image_window->name);
X XDefineCursor(display,image_window->id,image_window->cursor);
X if (state & InfoMappedState)
X XWithdrawWindow(display,info_window->id,info_window->screen);
X return(False);
X }
X DestroyImage(*image);
X *image=reflected_image;
X if (image_window->clip_geometry != (char *) NULL)
X {
X int
X x,
X y;
X
X unsigned int
X height,
X width;
X
X /*
X Reverse clip geometry.
X */
X (void) XParseGeometry(image_window->clip_geometry,&x,&y,&width,&height);
X (void) sprintf(image_window->clip_geometry,"%dx%d%+d%+d\0",width,height,
X (*image)->columns-width-x,y);
X }
X /*
X Restore cursor.
X */
X XDefineCursor(display,image_window->id,image_window->cursor);
X if (state & InfoMappedState)
X XWithdrawWindow(display,info_window->id,info_window->screen);
X return(True);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% X R e s i z e I m a g e W i n d o w %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Function XResizeImageWindow creates a new X image the same size as the
% image window.
%
% The format of the XResizeImageWindow routine is:
%
% status=XResizeImageWindow(display,resource_info,info_window,image_window,
% image);
%
% A description of each parameter follows:
%
% o status: Function XResizeImageWindow return True if the window is
% resized. False is returned is there is a memory shortage or if the
% window fails to resize.
%
% o display: Specifies a connection to an X server; returned from
% XOpenDisplay.
%
% o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
%
% o info_window: Specifies a pointer to a XWindowInfo structure.
%
% o image_window: Specifies a pointer to a XWindowInfo structure.
%
% o image: Specifies a pointer to a Image structure; returned from
% ReadImage.
%
%
*/
static unsigned int XResizeImageWindow(display,resource_info,info_window,
X image_window,image)
Display
X *display;
X
XXResourceInfo
X *resource_info;
X
XXWindowInfo
X *info_window,
X *image_window;
X
Image
X *image;
{
X char
X text[256];
X
X unsigned int
X state;
X
X XImage
X *resized_ximage;
X
X state=DefaultState;
X if ((image_window->width*image_window->height) > MinInfoSize)
X {
X /*
X Map image window.
X */
X (void) strcpy(text," Resizing image... ");
X info_window->width=XTextWidth(info_window->font_info,text,strlen(text));
X info_window->height=info_window->font_info->ascent+
X info_window->font_info->descent+4;
X XResizeWindow(display,info_window->id,info_window->width,
X info_window->height);
X XMapWindow(display,info_window->id);
X XClearWindow(display,info_window->id);
X XDrawString(display,info_window->id,info_window->graphic_context,2,
X info_window->font_info->ascent+2,text,strlen(text));
X state|=InfoMappedState;
X }
X /*
X Resize image to fit image window dimensions.
X */
X XDefineCursor(display,image_window->id,image_window->busy_cursor);
X XFlush(display);
X resized_ximage=XMakeImage(display,resource_info,image_window,image,
X image_window->width,image_window->height);
X if (resized_ximage == (XImage *) NULL)
X {
X Warning("unable to resize X image",image_window->name);
X XDefineCursor(display,image_window->id,image_window->cursor);
X if (state & InfoMappedState)
X XWithdrawWindow(display,info_window->id,info_window->screen);
X return(False);
X }
X XDestroyImage(image_window->ximage);
X image_window->x=0;
X image_window->y=0;
X image_window->ximage=resized_ximage;
X /*
X Restore cursor.
X */
X XDefineCursor(display,image_window->id,image_window->cursor);
X if (state & InfoMappedState)
X XWithdrawWindow(display,info_window->id,info_window->screen);
X return(True);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% X R o t a t e I m a g e W i n d o w %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Function XRotateImageWindow rotates the X image left or right 90 degrees.
%
% The format of the XRotateImageWindow routine is:
%
% status=XRotateImageWindow(display,info_window,image_window,degrees,image)
%
% A description of each parameter follows:
%
% o status: Function XRotateImageWindow return True if the window is
% rotated. False is returned is there is a memory shortage or if the
% window fails to rotate.
%
% o display: Specifies a connection to an X server; returned from
% XOpenDisplay.
%
% o info_window: Specifies a pointer to a XWindowInfo structure.
%
% o image_window: Specifies a pointer to a XWindowInfo structure.
%
% o degrees: Specifies the number of degrees to rotate the image.
%
% o image: Specifies a pointer to a Image structure; returned from
% ReadImage.
%
%
*/
static unsigned int XRotateImageWindow(display,info_window,image_window,
X degrees,image)
Display
X *display;
X
XXWindowInfo
X *info_window,
X *image_window;
X
unsigned int
X degrees;
X
Image
X **image;
{
X char
X text[256];
X
X int
X x,
X y;
X
X Image
X *rotated_image;
X
X unsigned int
X state;
X
X state=DefaultState;
X if (((*image)->columns*(*image)->rows) > MinInfoSize)
X {
X /*
X Map info window.
X */
X (void) strcpy(text," Rotating image... ");
X info_window->width=XTextWidth(info_window->font_info,text,strlen(text));
X info_window->height=info_window->font_info->ascent+
X info_window->font_info->descent+4;
X XResizeWindow(display,info_window->id,info_window->width,
X info_window->height);
X XMapWindow(display,info_window->id);
X XClearWindow(display,info_window->id);
X XDrawString(display,info_window->id,info_window->graphic_context,2,
X info_window->font_info->ascent+2,text,strlen(text));
X state|=InfoMappedState;
X }
X /*
X Rotate image.
X */
X XDefineCursor(display,image_window->id,image_window->busy_cursor);
X XFlush(display);
X rotated_image=RotateImage(*image,(double) degrees,True);
X if (rotated_image == (Image *) NULL)
X {
X Warning("unable to rotate X image",image_window->name);
X XDefineCursor(display,image_window->id,image_window->cursor);
X if (state & InfoMappedState)
X XWithdrawWindow(display,info_window->id,info_window->screen);
X return(False);
X }
X DestroyImage(*image);
X *image=rotated_image;
X if (image_window->clip_geometry != (char *) NULL)
X {
X unsigned int
X height,
X width;
X
X /*
X Rotate clip geometry.
X */
X (void) XParseGeometry(image_window->clip_geometry,&x,&y,&width,&height);
X if (degrees < 180.0)
X (void) sprintf(image_window->clip_geometry,"%dx%d%+d%+d\0",height,
X width,(*image)->columns-height-y,x);
X else
X (void) sprintf(image_window->clip_geometry,"%dx%d%+d%+d\0",height,
X width,y,(*image)->rows-width-x);
X }
X /*
X Restore cursor.
X */
X XDefineCursor(display,image_window->id,image_window->cursor);
X if (state & InfoMappedState)
X XWithdrawWindow(display,info_window->id,info_window->screen);
X return(True);
}
X
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M a i n %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
int main(argc,argv)
int
X argc;
X
char
X **argv;
{
X char
X *clip_geometry,
X *image_geometry,
X *option,
X *print_filename,
X *scale_geometry,
X *server_name,
X *write_filename;
X
X Display
X *display;
X
X double
X gamma;
X
X int
X degrees;
X
X register int
X i;
X
X unsigned int
X compression,
X display_image,
X dither,
X enhance,
X gray,
X image_number,
X inverse,
X monochrome,
X noise,
X normalize,
X number_colors,
X reflect,
X scene,
X tree_depth,
X root,
X verbose;
X
X XResourceInfo
X resource_info;
X
X /*
X Display usage profile if there are no command line arguments.
X */
X application_name=(*argv);
X if (argc < 2)
X Usage((char *) NULL,True);
X /*
X Set defaults.
X */
X clip_geometry=(char *) NULL;
X compression=UnknownCompression;
X degrees=0;
X display=(Display *) NULL;
X display_image=True;
X dither=False;
X enhance=False;
X gamma=0.0;
X gray=False;
X image_geometry=(char *) NULL;
X inverse=False;
X monochrome=False;
X noise=False;
X normalize=False;
X number_colors=0;
X print_filename=(char *) NULL;
X reflect=False;
X root=False;
X scale_geometry=(char *) NULL;
X scene=0;
X server_name=(char *) NULL;
X tree_depth=0;
X verbose=False;
X write_filename=(char *) NULL;
X /*
X Check for server name specified on the command line.
X */
X for (i=1; i < argc-1; i++)
X {
X /*
X Check command line for server name.
X */
X option=argv[i];
X if ((strlen(option) > 1) && ((*option == '-') || (*option == '+')))
X if (strncmp("display",option+1,3) == 0)
X {
X /*
X User specified server name.
X */
X display_image=(*option == '-');
X if (display_image)
X {
X i++;
X if (i == argc)
X Usage("missing server name on -display",True);
X server_name=argv[i];
X }
X break;
X }
X }
X if (display_image)
X {
X char
X *user_default;
X
X /*
X Open X server connection.
X */
X display=XOpenDisplay(server_name);
X if (display == (Display *) NULL)
X Error("unable to connect to X server",XDisplayName(server_name));
X /*
X Get user_defaults from X resource database.
X */
X user_default=XGetDefault(display,application_name,"backdrop");
X resource_info.backdrop=IsTrue(user_default);
X user_default=XGetDefault(display,application_name,"background");
X if (user_default == (char *) NULL)
X user_default=XGetDefault(display,application_name,"Background");
X if (user_default == (char *) NULL)
X user_default="black";
X resource_info.background_color=user_default;
X user_default=XGetDefault(display,application_name,"borderColor");
X if (user_default == (char *) NULL)
X user_default=XGetDefault(display,application_name,"BorderColor");
X if (user_default == (char *) NULL)
X user_default="white";
X resource_info.border_color=user_default;
X user_default=XGetDefault(display,application_name,"borderWidth");
X if (user_default == (char *) NULL)
X user_default=XGetDefault(display,application_name,"BorderWidth");
X resource_info.border_width=
X (user_default == (char *) NULL) ? 2 : atoi(user_default);
X clip_geometry=XGetDefault(display,application_name,"clip");
X user_default=XGetDefault(display,application_name,"colors");
X number_colors=user_default ? atoi(user_default) : 0;
X user_default=XGetDefault(display,application_name,"compression");
X if (user_default == (char *) NULL)
X compression=UnknownCompression;
X else
X if (*user_default == 'R')
X compression=RunlengthEncodedCompression;
X else
X if (*user_default == 'Q')
X compression=QEncodedCompression;
X else
X compression=UnknownCompression;
X user_default=XGetDefault(display,application_name,"delay");
X resource_info.delay=
X (user_default == (char *) NULL) ? 0 : atoi(user_default);
X user_default=XGetDefault(display,application_name,"dither");
X dither=IsTrue(user_default);
X user_default=XGetDefault(display,application_name,"enhance");
X enhance=IsTrue(user_default);
X user_default=XGetDefault(display,application_name,"font");
X if (user_default == (char *) NULL)
X user_default=XGetDefault(display,application_name,"Font");
X resource_info.font_name=user_default;
X user_default=XGetDefault(display,application_name,"foreground");
X if (user_default == (char *) NULL)
X user_default=XGetDefault(display,application_name,"Foreground");
X if (user_default == (char *) NULL)
X user_default="white";
X resource_info.foreground_color=user_default;
X user_default=XGetDefault(display,application_name,"gamma");
X gamma=(user_default == (char *) NULL) ? 0.0 : atof(user_default);
X user_default=XGetDefault(display,application_name,"geometry");
X if (user_default == (char *) NULL)
X user_default=XGetDefault(display,application_name,"Geometry");
X image_geometry=user_default;
X user_default=XGetDefault(display,application_name,"gray");
X gray=IsTrue(user_default);
X user_default=XGetDefault(display,application_name,"iconGeometry");
X if (user_default == (char *) NULL)
X user_default=XGetDefault(display,application_name,"IconGeometry");
X resource_info.icon_geometry=user_default;
X user_default=XGetDefault(display,application_name,"iconic");
X if (user_default == (char *) NULL)
X user_default=XGetDefault(display,application_name,"Iconic");
X resource_info.iconic=IsTrue(user_default);
X user_default=XGetDefault(display,application_name,"inverse");
X inverse=IsTrue(user_default);
X user_default=XGetDefault(display,application_name,"magnify");
X resource_info.magnify=
X (user_default == (char *) NULL) ? 2 : Max(atoi(user_default),2);
X resource_info.map_type=XGetDefault(display,application_name,"map");
X user_default=XGetDefault(display,application_name,"monochrome");
X monochrome=IsTrue(user_default);
X user_default=XGetDefault(display,application_name,"name");
X if (user_default == (char *) NULL)
X user_default=XGetDefault(display,application_name,"Name");
X resource_info.name=user_default;
X user_default=XGetDefault(display,application_name,"noise");
X noise=IsTrue(user_default);
X user_default=XGetDefault(display,application_name,"normalize");
X normalize=IsTrue(user_default);
X print_filename=XGetDefault(display,application_name,"print");
X user_default=XGetDefault(display,application_name,"reflect");
X reflect=IsTrue(user_default);
X user_default=XGetDefault(display,application_name,"root");
X root=IsTrue(user_default);
X user_default=XGetDefault(display,application_name,"rotate");
X user_default=XGetDefault(display,application_name,"scale");
X if (user_default == (char *) NULL)
X user_default=XGetDefault(display,application_name,"Scale");
X scale_geometry=user_default;
X user_default=XGetDefault(display,application_name,"scene");
X scene=(user_default == (char *) NULL) ? 0 : atoi(user_default);
X user_default=XGetDefault(display,application_name,"title");
X if (user_default == (char *) NULL)
X user_default=XGetDefault(display,application_name,"Title");
X resource_info.title=user_default;
X degrees=(user_default == (char *) NULL) ? 0 : atoi(user_default);
X user_default=XGetDefault(display,application_name,"treedepth");
X tree_depth=(user_default == (char *) NULL) ? 0 : atoi(user_default);
X user_default=XGetDefault(display,application_name,"verbose");
X verbose=IsTrue(user_default);
X resource_info.visual_type=XGetDefault(display,application_name,"visual");
X write_filename=XGetDefault(display,application_name,"write");
X }
X /*
X Parse command line.
X */
X image_number=0;
X for (i=1; i < argc; i++)
X {
X option=argv[i];
X if ((strlen(option) > 1) && ((*option == '-') || (*option == '+')))
X switch (*(option+1))
X {
X case 'b':
X {
X if (strncmp("backdrop",option+1,5) == 0)
X resource_info.backdrop=(*option == '-');
X else
X if (strncmp("background",option+1,5) == 0)
X {
X resource_info.background_color=(char *) NULL;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing color on -background",True);
X resource_info.background_color=argv[i];
X }
X }
X else
X if (strncmp("bordercolor",option+1,7) == 0)
X {
X resource_info.border_color=(char *) NULL;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing color on -bordercolor",True);
X resource_info.border_color=argv[i];
X }
X }
X else
X if (strncmp("borderwidth",option+1,7) == 0)
X {
X resource_info.border_width=0;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing width on -borderwidth",True);
X resource_info.border_width=atoi(argv[i]);
X }
X }
X else
X Usage(option,True);
X break;
X }
X case 'c':
X {
X if (strncmp("clip",option+1,2) == 0)
X {
X clip_geometry=(char *) NULL;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing geometry on -clip",True);
X clip_geometry=argv[i];
X }
X }
X else
X if (strncmp("color",option+1,3) == 0)
X {
X number_colors=0;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing colors on -colors",True);
X number_colors=atoi(argv[i]);
X }
X }
X else
X if (strncmp("compress",option+1,3) == 0)
X {
X compression=NoCompression;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing type on -compress",True);
X if ((*argv[i] == 'R') || (*argv[i] == 'r'))
X compression=RunlengthEncodedCompression;
X else
X if ((*argv[i] == 'Q') || (*argv[i] == 'q'))
X compression=QEncodedCompression;
X else
X Usage("invalid compression type on -compress",True);
X }
X }
X else
X Usage(option,True);
X break;
X }
X case 'd':
X {
X if (strncmp("delay",option+1,2) == 0)
X {
X resource_info.delay=0;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing seconds on -delay",True);
X resource_info.delay=atoi(argv[i]);
X }
X }
X else
X if (strncmp("display",option+1,3) == 0)
X {
X server_name=(char *) NULL;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing server name on -display",True);
X server_name=argv[i];
X }
X }
X else
X if (strncmp("dither",option+1,3) == 0)
X dither=(*option == '-');
X else
X Usage(option,True);
X break;
X }
X case 'e':
X {
X enhance=(*option == '-');
X break;
X }
X case 'f':
X {
X if (strncmp("font",option+1,3) == 0)
X {
X resource_info.font_name=(char *) NULL;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing font name on -font",True);
X resource_info.font_name=argv[i];
X }
X }
X else
X if (strncmp("foreground",option+1,3) == 0)
X {
X resource_info.foreground_color=(char *) NULL;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing foreground on -foreground",True);
X resource_info.foreground_color=argv[i];
X }
X }
X else
X Usage(option,True);
X break;
X }
X case 'g':
X {
X if (strncmp("gamma",option+1,2) == 0)
X {
X gamma=0.0;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing gamma on -gamma",True);
X gamma=atof(argv[i]);
X }
X }
X else
X if (strncmp("geometry",option+1,2) == 0)
X {
X image_geometry=(char *) NULL;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing geometry on -geometry",True);
X image_geometry=argv[i];
X }
X }
X else
X if (strncmp("gray",option+1,2) == 0)
X gray=(*option == '-');
X else
X Usage(option,True);
X break;
X }
X case 'h':
X {
X Usage((char *) NULL,True);
X break;
X }
X case 'i':
X {
X if (strncmp("iconGeometry",option+1,5) == 0)
X {
X resource_info.icon_geometry=(char *) NULL;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing geometry on -iconGeometry",True);
X resource_info.icon_geometry=argv[i];
X }
X }
X else
X if (strncmp("iconic",option+1,5) == 0)
X resource_info.iconic=(*option == '-');
X else
X if (strncmp("inverse",option+1,2) == 0)
X inverse=(*option == '-');
X else
X Usage(option,True);
X break;
X }
X case 'm':
X {
X if (strncmp("magnify",option+1,3) == 0)
X {
X resource_info.magnify=2;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing level on -magnify",True);
X resource_info.magnify=Max(1 << atoi(argv[i]),2);
X }
X }
X else
X if (strncmp("map",option+1,3) == 0)
X {
X resource_info.map_type=(char *) NULL;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing map type on -map",True);
X resource_info.map_type=argv[i];
X }
X }
X else
X if (strncmp("monochrome",option+1,2) == 0)
X monochrome=(*option == '-');
X else
X Usage(option,True);
X break;
X }
X case 'n':
X {
X if (strncmp("name",option+1,2) == 0)
X {
X resource_info.name=(char *) NULL;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing name on -name",True);
X resource_info.name=argv[i];
X }
X }
X else
X if (strncmp("noise",option+1,3) == 0)
X noise=(*option == '-');
X else
X if (strncmp("normalize",option+1,3) == 0)
X normalize=(*option == '-');
X else
X Usage(option,True);
X break;
X }
X case 'p':
X {
X if (strncmp("print",option+1,2) == 0)
X {
X print_filename=(char *) NULL;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing file name on -print",True);
X print_filename=argv[i];
X if (access(print_filename,0) == 0)
X {
X char
X answer[2];
X
X (void) fprintf(stderr,"Overwrite %s? ",print_filename);
X (void) gets(answer);
X if (!((*answer == 'y') || (*answer == 'Y')))
X exit(1);
X }
X }
X }
X else
X Usage(option,True);
X break;
X }
X case 'r':
X {
X if (strncmp("reflect",option+1,2) == 0)
X reflect=(*option == '-');
X else
X if (strncmp("root",option+1,3) == 0)
X root=(*option == '-');
X else
X if (strncmp("rotate",option+1,3) == 0)
X {
X degrees=0.0;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing degrees on -rotate",True);
X degrees=atoi(argv[i]);
X }
X }
X else
X Usage(option,True);
X break;
X }
X case 's':
X {
X if (strncmp("scale",option+1,3) == 0)
X {
X scale_geometry=(char *) NULL;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing scale geometry on -scale",True);
X scale_geometry=argv[i];
X }
X }
X else
X if (strncmp("scene",option+1,3) == 0)
X {
X scene=0;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing scene number on -scene",True);
X scene=atoi(argv[i]);
X }
X }
X else
X Usage(option,True);
X break;
X }
X case 't':
X {
X if (strncmp("title",option+1,2) == 0)
X {
X resource_info.title=(char *) NULL;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing title on -title",True);
X resource_info.title=argv[i];
X }
X }
X else
X if (strncmp("treedepth",option+1,2) == 0)
X {
X tree_depth=0;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing depth on -treedepth",True);
X tree_depth=atoi(argv[i]);
X }
X }
X else
X Usage(option,True);
X break;
X }
X case 'v':
X {
X if (strncmp("verbose",option+1,2) == 0)
X verbose=(*option == '-');
X else
X if (strncmp("visual",option+1,2) == 0)
X {
X resource_info.visual_type=(char *) NULL;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing visual class on -visual",True);
X resource_info.visual_type=argv[i];
X }
X }
X else
X Usage(option,True);
X break;
X }
X case 'w':
X {
X write_filename=(char *) NULL;
X if (*option == '-')
X {
X i++;
X if (i == argc)
X Usage("missing file name on -write",True);
X write_filename=argv[i];
X if (access(write_filename,0) == 0)
X {
X char
X answer[2];
X
X (void) fprintf(stderr,"Overwrite %s? ",write_filename);
X (void) gets(answer);
X if (!((*answer == 'y') || (*answer == 'Y')))
X exit(1);
X }
X }
X break;
X }
X default:
X {
X Usage((char *) NULL,True);
X break;
X }
X }
X else
X {
X Image
X *image,
X info_image;
X
X long
X start_time;
X
X unsigned int
X terminate;
X
X unsigned long
X total_colors;
X
X /*
X Option is a file name: begin by reading image from specified file.
X */
X terminate=root;
X image_number++;
X (void) strcpy(info_image.filename,option);
X start_time=time((long *) 0);
X image=ReadImage(info_image.filename);
X if (image == (Image *) NULL)
X continue;
X info_image=(*image);
X if (scene > 0)
X image->scene=scene;
X /*
X Transform image as defined by the clip, image and scale geometries.
X */
X image=
X TransformImage(image,clip_geometry,image_geometry,scale_geometry);
X if (reflect)
X {
X Image
X *reflected_image;
X
X /*
X Reverse image scanlines.
X */
X reflected_image=ReflectImage(image);
X if (reflected_image != (Image *) NULL)
X {
X DestroyImage(image);
X image=reflected_image;
X }
X }
X if ((degrees % 360) != 0)
X {
X Image
X *rotated_image;
X
X /*
X Rotate image.
X */
X rotated_image=RotateImage(image,(double) degrees,False);
X if (rotated_image != (Image *) NULL)
X {
X DestroyImage(image);
X image=rotated_image;
X }
X }
X if (enhance)
X {
X Image
X *enhanced_image;
X
X /*
X Enhance image.
X */
X enhanced_image=EnhanceImage(image);
X if (enhanced_image != (Image *) NULL)
X {
X DestroyImage(image);
X image=enhanced_image;
X }
X }
X if (noise)
X {
X Image
X *noisy_image;
X
X /*
X Reduce noise in image.
X */
X noisy_image=NoisyImage(image);
X if (noisy_image != (Image *) NULL)
X {
X DestroyImage(image);
X image=noisy_image;
X }
X }
X if (gamma > 0.0)
X (void) GammaImage(image,gamma);
X if (inverse)
X (void) InverseImage(image);
X if (normalize)
X (void) NormalizeImage(image);
X if (verbose)
X {
X /*
X Initialize image error attributes.
X */
X if (image->class == DirectClass)
X image->colors=NumberColors(image);
X total_colors=image->colors;
X }
X if (gray)
X {
X /*
X Convert image to gray scale PseudoColor class.
X */
X (void) GrayImage(image);
X if (image->class == DirectClass)
X QuantizeImage(image,256,tree_depth,dither,True);
X }
X if (monochrome)
X {
X register unsigned int
X bit;
X
X /*
X Convert image to monochrome PseudoColor class.
X */
X (void) GrayImage(image);
X if ((image->class == DirectClass) || (image->colors > 2))
X (void) QuantizeImage(image,2,tree_depth,dither,True);
X bit=Intensity(image->colormap[0]) > Intensity(image->colormap[1]);
X image->colormap[bit].red=0;
X image->colormap[bit].green=0;
X image->colormap[bit].blue=0;
X image->colormap[!bit].red=255;
X image->colormap[!bit].green=255;
X image->colormap[!bit].blue=255;
X }
X if (number_colors > 0)
X if ((image->class == DirectClass) || (image->colors > number_colors))
X QuantizeImage(image,number_colors,tree_depth,dither,True);
X if (display != (Display *) NULL)
X {
X /*
X Display image to X server.
X */
X resource_info.monochrome=monochrome;
X resource_info.image_geometry=image_geometry;
X if (root)
X XDisplayRootImage(display,&resource_info,image);
X else
X {
X char
X *clip_geometry,
X *image_geometry;
X
X image=XDisplayImage(display,&resource_info,argv,argc,image,
X &clip_geometry,&image_geometry,&terminate);
X if ((print_filename != (char *) NULL) ||
X (write_filename != (char *) NULL))
X if ((clip_geometry != (char *) NULL) ||
X (image_geometry != (char *) NULL))
X {
X /*
X Apply user specified changes to the image.
X */
X image=TransformImage(image,clip_geometry,image_geometry,
X (char *) NULL);
X if (number_colors > 0)
X if ((image->class == DirectClass) ||
X (image->colors > number_colors))
X QuantizeImage(image,number_colors,tree_depth,dither,
X True);
X }
X if (clip_geometry != (char *) NULL)
X (void) free((char *) clip_geometry);
X if (image_geometry != (char *) NULL)
X (void) free((char *) image_geometry);
X }
X }
X if (compression != UnknownCompression)
X image->compression=compression;
X else
X image->compression=info_image.compression;
X if (print_filename != (char *) NULL)
X {
X /*
X Print image as Encapsulated Postscript.
X */
X (void) strcpy(image->filename,print_filename);
X (void) PrintImage(image,image_geometry);
X (void) strcpy(image->filename,info_image.filename);
X }
X if (write_filename != (char *) NULL)
X {
X /*
X Write image in MIFF format.
X */
X (void) strcpy(image->filename,write_filename);
X (void) WriteImage(image);
X (void) strcpy(image->filename,info_image.filename);
X }
X if (verbose)
X {
X /*
X Display detailed info about the image.
X */
X (void) fprintf(stderr,"[%d] %s",(image->scene == 0 ? image_number :
X image->scene),image->filename);
X if (write_filename != (char *) NULL)
X (void) fprintf(stderr,"=>%s",write_filename);
X (void) fprintf(stderr," %dx%d",info_image.columns,info_image.rows);
X if ((info_image.columns != image->columns) ||
X (info_image.rows != image->rows))
X (void) fprintf(stderr,"=>%dx%d",image->columns,image->rows);
X if (image->class == DirectClass)
X (void) fprintf(stderr," DirectClass ");
X else
X (void) fprintf(stderr," PseudoClass ");
X if (total_colors != image->colors)
X (void) fprintf(stderr,"%d=>",total_colors);
X (void) fprintf(stderr,"%dc",image->colors);
X if ((number_colors > 0) || gray || monochrome)
X {
X double
X normalized_maximum_error,
X normalized_mean_error;
X
X unsigned int
X mean_error_per_pixel;
X
X /*
X Measure quantization error.
X */
X QuantizationError(image,&mean_error_per_pixel,
X &normalized_mean_error,&normalized_maximum_error);
X (void) fprintf(stderr," %d/%.6f/%.6fe",mean_error_per_pixel,
X normalized_mean_error,normalized_maximum_error);
X }
X (void) fprintf(stderr," %ds\n",time((long *) 0)-start_time+1);
X }
X /*
X Deallocate image resources.
X */
X DestroyImage(image);
X if (terminate)
X break;
X }
X }
X if (image_number == 0)
X Usage("missing an image file name",True);
X if (display != (Display *) NULL)
X XCloseDisplay(display);
X return(False);
}
SHAR_EOF
echo 'File ImageMagick/display.c is complete' &&
chmod 0755 ImageMagick/display.c ||
echo 'restore of ImageMagick/display.c failed'
Wc_c="`wc -c < 'ImageMagick/display.c'`"
test 148390 -eq "$Wc_c" ||
echo 'ImageMagick/display.c: original size 148390, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= ImageMagick/X.h ==============
if test -f 'ImageMagick/X.h' -a X"$1" != X"-c"; then
echo 'x - skipping ImageMagick/X.h (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ImageMagick/X.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/X.h' &&
X
#undef False
#undef True
#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/cursorfont.h>
#include <X11/keysym.h>
#undef index
/*
X Define declarations.
*/
#define XStandardPixel(map,color,shift) map->base_pixel+ \
X ((color.red*map->red_max+(1 << (shift-1))) >> shift)*map->red_mult+ \
X ((color.green*map->green_max+(1 << (shift-1))) >> shift)*map->green_mult+ \
X ((color.blue*map->blue_max+(1 << (shift-1))) >> shift)*map->blue_mult
X
/*
X Typedef declarations.
*/
typedef struct _XPixelInfo
{
X unsigned long
X background_pixel,
X border_pixel,
X foreground_pixel,
X *pixels;
} XPixelInfo;
X
typedef struct _XResourceInfo
{
X unsigned int
X backdrop;
X
X char
X *background_color;
X
X char
X *border_color;
X
X unsigned int
X border_width,
X delay;
X
X char
X *font_name;
X
X char
X *foreground_color,
X *icon_geometry;
X
X unsigned int
X iconic;
X
X char
X *image_geometry;
X
X unsigned int
X magnify;
X
X char
X *map_type;
SHAR_EOF
true || echo 'restore of ImageMagick/X.h failed'
fi
echo 'End of ImageMagick part 18'
echo 'File ImageMagick/X.h is continued in part 19'
echo 19 > _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