blewett@RESEARCH.ATT.COM (C. Douglas Blewett) (01/05/89)
The following is some code to look at doing simple image presentation
using standard X and X widgets. Two features that have been mentioned
so far in the image processing group are pan and zoom. The patch I
posted a fews days ago does a nice job on panning. The following
contains patches to the HP static raster widget to turn it into a
magnifier widget. This seems to be effective for zooming. Because it
is a widget it can be contained within a scrolled window widget or
otherwise manipulated effectively. This was just a couple hours worth
of amusement while I had a cold. This is definitely not a bug fix.
The bundle contains a makefile, simple test code, and the diff to
convert the HP widget files. The test code gets a snap shot of the
screen and hands it off to the magnifier widget. There are two
magnifying techniques used in the widget. The monochrome version
constructs rectangles - pretty standard. The color constructs new X
image parts and is designed to work well with images containing a lot
of detail (colors).
Doug Blewett (201) 582-6496
AT&T Bell Laboratories research!blewett
office 2c470 blewett%research.att.com@relay.cs.net
600 Mountain Avenue blewett@research.att.com
Murray Hill, NJ 07974
# To unbundle, sh this file
echo xwmagnify.mk 1>&2
sed 's/.//' >xwmagnify.mk <<'//GO.SYSIN DD xwmagnify.mk'
-DIR= /usr/local/src/lib/X.V11R3/contrib/widgets/Xhp
-LIBS= $(DIR)/lib/libXw.a $(DIR)/lib/libXt.a -lX11
-INCLUDE=-I$(DIR)/Xw -I$(DIR)/Xt -I$(DIR)
-CFLAGS= -O $(INCLUDE)
-
-xwmagnify: xwmagnify.o SMRaster.o
- cc -o xwmagnify -g xwmagnify.o SMRaster.o $(LIBS)
//GO.SYSIN DD xwmagnify.mk
echo xwmagnify.c 1>&2
sed 's/.//' >xwmagnify.c <<'//GO.SYSIN DD xwmagnify.c'
-#include <stdio.h>
-#include <X11/Xlib.h>
-#include <X11/IntrinsicP.h>
-#include <X11/IntrinsicI.h> /* definition of XtDefaultDB */
-#include <X11/Intrinsic.h>
-#include <X11/Xatom.h>
-#include <X11/cursorfont.h>
-#include <Xw/Xw.h>
-#include <Xw/XwP.h>
-#include <Form.h>
-#include <PButton.h>
-#include <Xw/Arrow.h>
-#include <Valuator.h>
-#include <ScrollBar.h>
-#include <SWindow.h>
-#include <SText.h>
-#include <TextEdit.h>
-#include "SMRaster.h"
-
-#define MIN(x,y) ((x) < (y) ? (x) : (y))
-#define MAX(x,y) ((x) > (y) ? (x) : (y))
-
-/*
- * Command line options data
- */
-static XrmOptionDescRec options[] =
-{
- {"-mag", "magnification", XrmoptionSepArg, NULL},
- {"-m", "magnification", XrmoptionSepArg, NULL},
- {"-box", "box_size", XrmoptionSepArg, NULL},
- {"-b", "box_size", XrmoptionSepArg, NULL},
-};
-
-typedef struct
-{
- int magnification;
- int box_size;
-} app_resourceRec, *app_res;
-
-app_resourceRec app_resources;
-
-static XtResource resources[] =
-{
- {
- "magnification", "Magnification",
- XtRInt, sizeof (int),
- XtOffset (app_res, magnification),
- XtRString, (caddr_t) "4"
- },
- {
- "box_size", "Box_Size",
- XtRInt, sizeof (int),
- XtOffset (app_res, box_size),
- XtRString, (caddr_t) "256"
- },
-};
-
-/*
- * Report the syntax
- */
-Syntax (call)
-char *call;
-{
- fprintf (stderr,
- "%s: usage\n %s [-box <size in pixels>] [-mag <magnification>]\n",
- call, call);
- fprintf (stderr,
- "The default box size is 256 and default magnification is 4\n");
- exit (1);
-}
-
-void
-main (argc, argv)
-unsigned int argc;
-char **argv;
-{
- extern XImage *process_image ();
- extern void AppNewImage ();
- extern void AppNewMagnification ();
- extern void AppExit ();
- Widget toplevel, form, NewImagew, Exitw, sw;
- Widget label, Magnification, MagnifierWidget;
- XtCallbackRec toll_call[2];
- XtTranslations text_trans;
- Arg args[20];
- char buf[4];
- int i;
- XImage *image;
- XColor xch, xce;
-
- toplevel = XtInitialize (argv[0], "Test",
- options, XtNumber (options),
- &argc, argv);
-
- if (argc > 1)
- Syntax (argv[0]);
-
- XrmPutLineResource (&XtDefaultDB, "*font: fixed");
-
- XtGetApplicationResources (toplevel, &app_resources,
- resources, XtNumber (resources),
- NULL, 0);
-
- image = XGetImage (XtDisplay (toplevel),
- RootWindow (XtDisplay (toplevel),
- DefaultScreen (XtDisplay (toplevel))),
- 0, 0,
- app_resources.box_size, app_resources.box_size,
- AllPlanes,
- (DefaultDepth (XtDisplay (toplevel),
- DefaultScreen (XtDisplay (toplevel))) > 1) ?
- ZPixmap : XYPixmap);
- if (image == (XImage *) NULL)
- exit (1);
-
- if (XAllocNamedColor (XtDisplay (toplevel),
- DefaultColormap (XtDisplay (toplevel), 0),
- "blue",
- &xch, &xce) == FALSE)
- xch.pixel = NULL;
-
- form = XtCreateManagedWidget ("form", XwformWidgetClass,
- toplevel, NULL, 0);
- i = 0;
- XtSetArg (args[i], XtNxRefWidget, form); i++;
- XtSetArg (args[i], XtNyRefWidget, form); i++;
- XtSetArg (args[i], XtNyOffset, 5); i++;
- XtSetArg (args[i], XtNhighlightThickness, 2); i++;
- XtSetArg (args[i], XtNtraversalType, XwHIGHLIGHT_ENTER); i++;
- if (xch.pixel)
- XtSetArg (args[i], XtNhighlightColor, xch.pixel), i++;
- XtSetArg (args[i], XtNlabel, "New Image"); i++;
- toll_call[0].callback = (XtCallbackProc) AppNewImage;
- toll_call[0].closure = (caddr_t) &MagnifierWidget;
- toll_call[1].callback = (XtCallbackProc) NULL;
- toll_call[1].closure = NULL;
- XtSetArg (args[0], XtNrelease, toll_call);
- NewImagew = XtCreateManagedWidget ("NewImage", XwpushButtonWidgetClass,
- form, args, i);
- i = 0;
- XtSetArg (args[i], XtNxRefWidget, form); i++;
- XtSetArg (args[i], XtNyRefWidget, form); i++;
- XtSetArg (args[i], XtNyOffset, 5); i++;
- XtSetArg (args[i], XtNxAttachRight, TRUE); i++;
- XtSetArg (args[i], XtNxVaryOffset, TRUE); i++;
- XtSetArg (args[i], XtNhighlightThickness, 2); i++;
- XtSetArg (args[i], XtNtraversalType, XwHIGHLIGHT_ENTER); i++;
- if (xch.pixel)
- XtSetArg (args[i], XtNhighlightColor, xch.pixel), i++;
- XtSetArg (args[i], XtNlabel, "Exit"); i++;
- toll_call[0].callback = (XtCallbackProc) AppExit;
- toll_call[0].closure = NULL;
- toll_call[1].callback = (XtCallbackProc) NULL;
- toll_call[1].closure = NULL;
- XtSetArg (args[i], XtNrelease, toll_call); i++;
- Exitw = XtCreateManagedWidget ("Exit", XwpushButtonWidgetClass,
- form, args, i);
- i = 0;
- XtSetArg (args[i], XtNxRefWidget, NewImagew); i++;
- XtSetArg (args[i], XtNyRefWidget, NewImagew); i++;
- XtSetArg (args[i], XtNxOffset, 5); i++;
- XtSetArg (args[i], XtNyOffset, 5); i++;
- XtSetArg (args[i], XtNyAddHeight, TRUE); i++;
- XtSetArg (args[i], XtNstring, "Magnification:"); i++;
- XtSetArg (args[i], XtNborderWidth, 0); i++;
- label = XtCreateManagedWidget ("label",
- XwstatictextWidgetClass,
- form,
- args, i);
- i = 0;
- XtSetArg (args[i], XtNxOffset, 5); i++;
- XtSetArg (args[i], XtNxRefWidget, label); i++;
- XtSetArg (args[i], XtNyRefWidget, label); i++;
- XtSetArg (args[i], XtNxAddWidth, TRUE); i++;
- if (app_resources.magnification < 1)
- app_resources.magnification = 1;
- if (app_resources.magnification > 64)
- app_resources.magnification = 64;
- sprintf (buf, "%d", app_resources.magnification);
- XtSetArg (args[i], XtNstring, buf); i++;
- XtSetArg (args[i], XtNheight, 30); i++;
- XtSetArg (args[i], XtNwidth, 80); i++;
- XtSetArg (args[i], XtNmaximumSize, 3); i++;
- toll_call[0].callback = (XtCallbackProc) AppNewMagnification;
- toll_call[0].closure = (caddr_t) &MagnifierWidget;
- toll_call[1].callback = (XtCallbackProc) NULL;
- toll_call[1].closure = NULL;
- XtSetArg (args[i], XtNleaveVerification, toll_call); i++;
- XtSetArg (args[i], XtNhighlightThickness, 2); i++;
- XtSetArg (args[i], XtNtraversalType, XwHIGHLIGHT_ENTER); i++;
- if (xch.pixel)
- XtSetArg (args[i], XtNhighlightColor, xch.pixel), i++;
- Magnification = XtCreateManagedWidget ("Magnification",
- XwtexteditWidgetClass,
- form,
- args, i);
- i = 0;
- XtSetArg (args[i], XtNxRefWidget, form); i++;
- XtSetArg (args[i], XtNyRefWidget, Magnification); i++;
- XtSetArg (args[i], XtNyAddHeight, TRUE); i++;
- XtSetArg (args[i], XtNxResizable, TRUE); i++;
- XtSetArg (args[i], XtNyResizable, TRUE); i++;
- XtSetArg (args[i], XtNyOffset, 5); i++;
- XtSetArg (args[i], XtNxAttachRight, TRUE); i++;
- XtSetArg (args[i], XtNyAttachBottom, TRUE); i++;
- XtSetArg (args[i], XtNwidth, image -> width); i++;
- XtSetArg (args[i], XtNheight, image -> height); i++;
- sw = XtCreateManagedWidget ("window", XwswindowWidgetClass,
- form, args, i);
- i = 0;
- XtSetArg (args[i], XtNxRefWidget, sw); i++;
- XtSetArg (args[i], XtNyRefWidget, sw); i++;
- XtSetArg (args[i], XtNxResizable, TRUE); i++;
- XtSetArg (args[i], XtNyResizable, TRUE); i++;
- XtSetArg (args[i], XtNxOffset, 5); i++;
- XtSetArg (args[i], XtNyOffset, 5); i++;
- XtSetArg (args[i], XtNxAttachRight, TRUE); i++;
- XtSetArg (args[i], XtNsRimage, image); i++;
- XtSetArg (args[i], XtNsMRmagnification, app_resources.magnification); i++;
- MagnifierWidget = XtCreateManagedWidget ("magnifier",
- XwsmrasterWidgetClass,
- sw,
- args, i);
-
- XtRealizeWidget (toplevel);
-
- text_trans = XtParseTranslationTable (
- "Ctrl<Key>M: leave() enter()\n\
- Ctrl<Key>J: leave() enter()\n\
- <Key>Delete: delete-previous-character()\n\
- Ctrl<Key>?: delete-previous-character()\n\
- <Key>Return: leave() enter()\n");
-
- XtOverrideTranslations (Magnification, text_trans);
-
- XtMainLoop ();
-}
-
-static void
-AppNewImage (w, closure, call_data)
-Widget w;
-Widget *closure;
-caddr_t call_data;
-{
- extern XRectangle getrect ();
- XRectangle r;
- XImage *image;
- Arg arg;
- int RootWidth, RootHeight;
- Display *display = XtDisplay (w);
- int screen = DefaultScreen (display);
- Window root = RootWindow (display, screen);
- Widget MagnifierWidget = *closure;
-
- do
- {
- r = getrect (display, screen, 1);
- } while (r.width < 1 || r.height < 1);
-
- RootWidth = XDisplayWidth (display, screen) - 1;
- RootHeight = XDisplayHeight (display, screen) - 1;
-
- if (r.x < 0)
- r.x = 0;
- if (r.y < 0)
- r.y = 0;
- if (r.x + r.width > RootWidth)
- r.width = RootWidth - r.x;
- if (r.y + r.height > RootHeight)
- r.height = RootHeight - r.y;
-
- image = XGetImage (display, root,
- r.x, r.y,
- r.width, r.height,
- AllPlanes,
- (DefaultDepth (display, screen) > 1) ?
- ZPixmap : XYPixmap);
-
- if (image != (XImage *) NULL)
- {
- UnmapSMRasterWidget (MagnifierWidget);
- XtSetArg (arg, XtNsRimage, image);
- XtSetValues (MagnifierWidget, &arg, 1);
- MapSMRasterWidget (MagnifierWidget);
- }
-}
-
-static XRectangle
-rcanon (p1, p2)
-XPoint p1, p2;
-{
- int mx, my, lx, ly;
- XRectangle r;
-
- lx = MAX (p1.x, p2.x);
- ly = MAX (p1.y, p2.y);
- mx = MIN (p1.x, p2.x);
- my = MIN (p1.y, p2.y);
- r.x = mx;
- r.y = my;
- r.width = lx - mx;
- r.height = ly - my;
-
- return r;
-}
-
-static XRectangle
-getrect (display, screen, theButton)
-Display *display;
-int screen;
-int theButton;
-{
- XPoint p1, p2;
- XRectangle r;
- int state;
- Window rootwindow, subwindow;
- int x, y;
- int cx, cy;
- static Cursor c = 0;
- static GC gc;
- XGCValues gcvalues;
- Window root = RootWindow (display, screen);;
-
- if (c == 0)
- {
- c = XCreateFontCursor(display, XC_icon);
-
- gcvalues.function = GXinvert;
- gcvalues.subwindow_mode = IncludeInferiors;
- gcvalues.foreground = BlackPixel(display,
- XDefaultScreen (display));
- gcvalues.line_width = 2;
- gc = XCreateGC (display, root,
- GCFunction | GCSubwindowMode |
- GCLineWidth | GCForeground,
- &gcvalues);
- }
-
- r.x = r.y = r.width = r.height = 0;
-
- /*
- * Grab the server (avoid collisons) and mouse (set the cursor)
- */
- for (;;)
- {
- if (XGrabPointer (display, root,
- True, ButtonPressMask | ButtonReleaseMask,
- GrabModeAsync, GrabModeAsync,
- None,
- c,
- CurrentTime) == GrabSuccess)
- break;
- }
- XGrabServer (display);
-
- while (button (display, root, theButton) == 0)
- XSync (display, 0);
-
- if (button (display, root, theButton) == 0)
- {
- XUngrabServer (display);
- XUngrabPointer (display, CurrentTime);
- return r;
- }
-
- XQueryPointer (display, root, &rootwindow, &subwindow,
- &x, &y, &cx, &cy, &state);
-
- r.x = p1.x = p2.x = x;
- r.y = p1.y = p2.y = y;
-
- XDrawRectangle (display, root, gc, r.x, r.y, r.width, r.height);
-
- while (button (display, root, theButton))
- {
- XDrawRectangle (display, root, gc, r.x, r.y,
- r.width, r.height);
- XQueryPointer (display, root, &rootwindow, &subwindow,
- &x, &y, &cx, &cy, &state);
- p2.x = x;
- p2.y = y;
- r = rcanon (p1, p2);
- XDrawRectangle (display, root, gc, r.x, r.y,
- r.width, r.height);
- }
- XDrawRectangle (display, root, gc, r.x, r.y, r.width, r.height);
- XUngrabServer (display);
- XUngrabPointer (display, CurrentTime);
- XSync (display, 0);
-
- return r;
-}
-
-static int
-button (display, root, it)
-Display *display;
-Window root;
-int it;
-{
- static int b[] =
- {
- Button1Mask, Button2Mask, Button3Mask,
- Button4Mask, Button5Mask
- };
- Window rootwindow, subwindow;
- int x, y;
- int cx, cy;
- int state;
-
- if (it < 1 || it > 5)
- return FALSE;
-
- XQueryPointer (display, root, &rootwindow, &subwindow,
- &x, &y, &cx, &cy, &state);
-
- return b[it - 1] & state;
-}
-
-static void
-AppNewMagnification (w, closure, call_data)
-Widget w;
-Widget *closure;
-caddr_t call_data;
-{
- Widget MagnifierWidget = *closure;
- int newmagnification;
- unsigned char buf[4];
- int used;
- int length;
- Arg arg;
-
- length = XwTextGetLastPos(w);
- if (length < 1)
- return;
-
- XwTextReadSubString (w, 0, length, buf, 64, &used);
- buf[length] = '\0';
- newmagnification = atoi (buf);
- if (newmagnification < 1)
- newmagnification = 1;
- else if (newmagnification > 64)
- newmagnification = 64;
-
- sprintf (buf, "%d", newmagnification);
- XtSetArg (arg, XtNstring, buf);
- XtSetValues (w, &arg, 1);
-
- if (app_resources.magnification == newmagnification)
- return;
-
- app_resources.magnification = newmagnification;
- UnmapSMRasterWidget (MagnifierWidget);
- XtSetArg (arg, XtNsMRmagnification, newmagnification);
- XtSetValues (MagnifierWidget, &arg, 1);
- MapSMRasterWidget (MagnifierWidget);
-}
-
-static void
-AppExit (w, client_data, call_data)
-Widget w;
-caddr_t client_data;
-caddr_t call_data;
-{
- exit (0);
-}
//GO.SYSIN DD xwmagnify.c
echo xdiff 1>&2
sed 's/.//' >xdiff <<'//GO.SYSIN DD xdiff'
-*** SRaster.c Wed Jan 4 20:22:46 1989
---- SMRaster.c Wed Jan 4 20:23:08 1989
-***************
-*** 1,7 ****
- /*************************************<+>*************************************
- *****************************************************************************
- **
-! ** File: SRaster.c
- **
- ** Project: X Widgets (Part II)
- **
---- 1,7 ----
- /*************************************<+>*************************************
- *****************************************************************************
- **
-! ** File: SMRaster.c
- **
- ** Project: X Widgets (Part II)
- **
-***************
-*** 39,51 ****
-
- #include <Xw/Xw.h>
- #include <Xw/XwP.h>
-! #include <Xw/SRaster.h>
-! #include <Xw/SRasterP.h>
-
-
-! static void ClassInitialize();
- static Boolean SetValues();
-! static void SRasterDestroy();
-
- static void Select();
- static void Release();
---- 39,52 ----
-
- #include <Xw/Xw.h>
- #include <Xw/XwP.h>
-! #include "SMRaster.h"
-! #include "SMRasterP.h"
-
-
-! static void magnify ();
-! static void ClassInitialize();
- static Boolean SetValues();
-! static void SMRasterDestroy();
-
- static void Select();
- static void Release();
-***************
-*** 91,116 ****
-
- static XtResource resources[] =
- {
--
- {
- XtNsRimage, XtCSRimage, XtRImage, sizeof(XImage *),
-! XtOffset (XwSRasterWidget, sraster.image),
- XtRImage, NULL
- },
- {
- XtNinvertOnSelect, XtCInvertOnSelect, XtRBoolean, sizeof(Boolean),
-! XtOffset (XwSRasterWidget, sraster.invert),
- XtRString,"TRUE"
- },
- {
- XtNshowSelected, XtCShowSelected, XtRBoolean, sizeof(Boolean),
-! XtOffset (XwSRasterWidget, sraster.showme),
- XtRString,"TRUE"
- },
- {
- XtNset, XtCSet, XtRBoolean, sizeof(Boolean),
-! XtOffset (XwSRasterWidget, sraster.poked),
- XtRString,"FALSE"
- }
- };
-
---- 92,121 ----
-
- static XtResource resources[] =
- {
- {
- XtNsRimage, XtCSRimage, XtRImage, sizeof(XImage *),
-! XtOffset (XwSMRasterWidget, smraster.image),
- XtRImage, NULL
- },
- {
- XtNinvertOnSelect, XtCInvertOnSelect, XtRBoolean, sizeof(Boolean),
-! XtOffset (XwSMRasterWidget, smraster.invert),
- XtRString,"TRUE"
- },
- {
- XtNshowSelected, XtCShowSelected, XtRBoolean, sizeof(Boolean),
-! XtOffset (XwSMRasterWidget, smraster.showme),
- XtRString,"TRUE"
- },
- {
- XtNset, XtCSet, XtRBoolean, sizeof(Boolean),
-! XtOffset (XwSMRasterWidget, smraster.poked),
- XtRString,"FALSE"
-+ },
-+ {
-+ XtNsMRmagnification, XtCSMRmagnification, XtRInt,
-+ sizeof (int), XtOffset (XwSMRasterWidget, smraster.magnification),
-+ XtRString, "4"
- }
- };
-
-***************
-*** 122,137 ****
- *
- *************************************<->***********************************/
-
-! SRasterClassRec srasterClassRec =
- {
- {
- (WidgetClass) &XwprimitiveClassRec, /* superclass */
- "StaticRaster", /* class_name */
-! sizeof(SRasterRec), /* widget_size */
- ClassInitialize, /* class_initialize */
- NULL, /* class_part_initialize */
- FALSE, /* class_inited */
-! InitSRaster, /* initialize */
- NULL, /* initialize hook */
- Realize, /* realize */
- actionsList, /* actions */
---- 127,142 ----
- *
- *************************************<->***********************************/
-
-! SMRasterClassRec smrasterClassRec =
- {
- {
- (WidgetClass) &XwprimitiveClassRec, /* superclass */
- "StaticRaster", /* class_name */
-! sizeof(SMRasterRec), /* widget_size */
- ClassInitialize, /* class_initialize */
- NULL, /* class_part_initialize */
- FALSE, /* class_inited */
-! InitSMRaster, /* initialize */
- NULL, /* initialize hook */
- Realize, /* realize */
- actionsList, /* actions */
-***************
-*** 143,149 ****
- TRUE, /* compress_exposure */
- TRUE, /* compress_enterleave */
- FALSE, /* visible_interest */
-! SRasterDestroy, /* destroy */
- Resize, /* resize */
- Resize, /* expose */
- SetValues, /* set_values */
---- 148,154 ----
- TRUE, /* compress_exposure */
- TRUE, /* compress_enterleave */
- FALSE, /* visible_interest */
-! SMRasterDestroy, /* destroy */
- Resize, /* resize */
- Resize, /* expose */
- SetValues, /* set_values */
-***************
-*** 170,177 ****
- },
- };
-
-! WidgetClass XwsrasterWidgetClass = (WidgetClass) &srasterClassRec;
-! WidgetClass XwstaticRasterWidgetClass = (WidgetClass) &srasterClassRec;
-
-
-
---- 175,182 ----
- },
- };
-
-! WidgetClass XwsmrasterWidgetClass = (WidgetClass) &smrasterClassRec;
-! WidgetClass XwstaticMagnifyingRasterWidgetClass = (WidgetClass) &smrasterClassRec;
-
-
-
-***************
-*** 188,202 ****
- *************************************<->***********************************/
- static void ClassInitialize()
- {
-! srasterClassRec.primitive_class.select_proc = (XtWidgetProc) Select;
-! srasterClassRec.primitive_class.release_proc = (XtWidgetProc) Release;
-! srasterClassRec.primitive_class.toggle_proc = (XtWidgetProc) NULL;
- }
-
-
- /*************************************<->*************************************
- *
-! * InitSRaster
- *
- * Description:
- * -----------
---- 193,207 ----
- *************************************<->***********************************/
- static void ClassInitialize()
- {
-! smrasterClassRec.primitive_class.select_proc = (XtWidgetProc) Select;
-! smrasterClassRec.primitive_class.release_proc = (XtWidgetProc) Release;
-! smrasterClassRec.primitive_class.toggle_proc = (XtWidgetProc) NULL;
- }
-
-
- /*************************************<->*************************************
- *
-! * InitSMRaster
- *
- * Description:
- * -----------
-***************
-*** 225,245 ****
- *
- *************************************<->***********************************/
-
-! static void InitSRaster(request, new, args, p_num_args)
-! XwSRasterWidget request, new;
- ArgList args;
- Cardinal *p_num_args;
- {
-
- if (request->core.width == 0)
-! if (request->sraster.image != NULL)
-! new->core.width += request->sraster.image->width;
- else
- new->core.width += 10;
-
- if (request->core.height == 0 )
-! if (request->sraster.image != NULL)
-! new->core.height += request->sraster.image->height;
- else
- new->core.height += 10;
- BuildInvGC(new);
---- 230,252 ----
- *
- *************************************<->***********************************/
-
-! static void InitSMRaster(request, new, args, p_num_args)
-! XwSMRasterWidget request, new;
- ArgList args;
- Cardinal *p_num_args;
- {
-
- if (request->core.width == 0)
-! if (request->smraster.image != NULL)
-! new->core.width += (request->smraster.image->width *
-! request->smraster.magnification);
- else
- new->core.width += 10;
-
- if (request->core.height == 0 )
-! if (request->smraster.image != NULL)
-! new->core.height += (request->smraster.image->height *
-! request->smraster.magnification);
- else
- new->core.height += 10;
- BuildInvGC(new);
-***************
-*** 273,279 ****
- *************************************<->***********************************/
-
- static void Realize(w, p_valueMask, attributes)
-! register Widget w;
- Mask *p_valueMask;
- XSetWindowAttributes *attributes;
- {
---- 280,286 ----
- *************************************<->***********************************/
-
- static void Realize(w, p_valueMask, attributes)
-! register XwSMRasterWidget w;
- Mask *p_valueMask;
- XSetWindowAttributes *attributes;
- {
-***************
-*** 285,290 ****
---- 292,298 ----
-
- XtCreateWindow(w,InputOutput, (Visual *)CopyFromParent,
- valueMask, attributes);
-+ w->smraster.ismapped = True;
- }
-
-
-***************
-*** 304,325 ****
- * event = XEvent structure
- * gc = GC to use
- ****************************************************************/
-! static void ShowSR(w, event,gc)
-! register XwSRasterWidget w;
-! XEvent *event;
- GC gc;
- {
- int HOffset,WOffset;
- int VisHeight,VisWidth;
- register ImageW,ImageH;
-
-! if ((w->sraster.image == NULL) || (w->sraster.image->data == NULL))
- {
- XtWarning("StaticRaster: NULL Image or bitmap pointer");
- return;
- }
-! VisWidth = w->sraster.image->width;
-! VisHeight = w->sraster.image->height;
- HOffset = WOffset = (int) w->primitive.highlight_thickness;
- ImageW = VisWidth + (WOffset << 1);
- ImageH = VisHeight + (HOffset << 1);
---- 312,337 ----
- * event = XEvent structure
- * gc = GC to use
- ****************************************************************/
-! static void ShowSR(w, event, gc)
-! register XwSMRasterWidget w;
-! XExposeEvent *event;
- GC gc;
- {
- int HOffset,WOffset;
- int VisHeight,VisWidth;
- register ImageW,ImageH;
-+ int src_x = 0;
-+ int src_y = 0;
-
-! if (w->smraster.ismapped == False)
-! return;
-! if ((w->smraster.image == NULL) || (w->smraster.image->data == NULL))
- {
- XtWarning("StaticRaster: NULL Image or bitmap pointer");
- return;
- }
-! VisWidth = w->smraster.image->width * w->smraster.magnification;
-! VisHeight = w->smraster.image->height * w->smraster.magnification;
- HOffset = WOffset = (int) w->primitive.highlight_thickness;
- ImageW = VisWidth + (WOffset << 1);
- ImageH = VisHeight + (HOffset << 1);
-***************
-*** 345,353 ****
- VisHeight = w->core.height - (HOffset << 1);
- }
-
-! if (XtIsRealized(w)) {
-! XPutImage(XtDisplay(w),XtWindow(w),gc,w->sraster.image,
-! 0,0, WOffset, HOffset,VisWidth,VisHeight);
- /*
- * We don't want to lose the highlight on redisplay
- * do we?
---- 357,385 ----
- VisHeight = w->core.height - (HOffset << 1);
- }
-
-! if (event && event -> type == Expose)
-! {
-! src_x = event -> x;
-! src_y = event -> y;
-! WOffset += src_x;
-! HOffset += src_y;
-! if (event -> width < VisWidth)
-! VisWidth = event -> width;
-! if (event -> height < VisHeight)
-! VisHeight = event -> height;
-! }
-!
-! if (XtIsRealized(w))
-! {
-! if (w->smraster.magnification == 1)
-! XPutImage(XtDisplay(w),XtWindow(w),gc,w->smraster.image,
-! src_x, src_y, WOffset, HOffset,
-! VisWidth,VisHeight);
-! else
-! magnify (w, gc, w->smraster.image, w->smraster.magnification,
-! src_x, src_y,
-! WOffset, HOffset,
-! VisWidth, VisHeight);
- /*
- * We don't want to lose the highlight on redisplay
- * do we?
-***************
-*** 367,376 ****
- }
- }
-
-
- /*************************************<->*************************************
- *
-! * SRasterDestroy
- *
- * Description:
- * -----------
---- 399,581 ----
- }
- }
-
-+ /*
-+ * The magnifier routine - this uses a very simple pixel replication
-+ * scheme. DATASIZ is the size of the image data space.
-+ */
-+ #define DATASIZ (32 * 1024)
-+
-+ static void
-+ magnify (w, gc, image, mag,
-+ src_x, src_y,
-+ WOffset, HOffset,
-+ width, height)
-+ Widget w;
-+ GC gc;
-+ XImage *image;
-+ int mag;
-+ int src_x;
-+ int src_y;
-+ int WOffset;
-+ int HOffset;
-+ int width;
-+ int height;
-+ {
-+ register int i;
-+ register int j;
-+ int x;
-+ int y;
-+ int end_x;
-+ int end_y;
-+ register long bits;
-+ int screen = DefaultScreen (XtDisplay (w));
-+
-+ i = (src_x % mag);
-+ src_x -= i;
-+ width += i;
-+ WOffset -= i;
-+ i = (src_y % mag);
-+ src_y -= i;
-+ height += i;
-+ HOffset -= i;
-+
-+ if (image -> depth > 1)
-+ {
-+ XImage *large_image;
-+ static char *data = NULL;
-+ int len;
-+ char *lptr;
-+ int lx;
-+ int end_lx;
-+
-+ if (data == (char *) NULL &&
-+ (data = (char *) malloc (DATASIZ)) == (char *) NULL)
-+ {
-+ XtWarning ("Cannot allocate image space.\n");
-+ return;
-+ }
-+
-+ lx = (image -> depth * width + 7) / 8;
-+ len = lx * height;
-+ if (len > DATASIZ)
-+ {
-+ magnify (w, gc, image, mag,
-+ src_x, src_y,
-+ WOffset, HOffset,
-+ width, (height + 1) / 2);
-+ magnify (w, gc, image, mag,
-+ src_x, src_y + height / 2,
-+ WOffset, HOffset + height / 2,
-+ width, (height + 1) / 2);
-+ return;
-+ }
-+
-+ large_image = XCreateImage (XtDisplay (w),
-+ DefaultVisual (XtDisplay (w),
-+ screen),
-+ image -> depth,
-+ ZPixmap,
-+ 0, /* Offset */
-+ data,
-+ width, height,
-+ 8, /* line quantum */
-+ lx);
-+
-+ if (large_image == (XImage *) NULL)
-+ {
-+ XtWarning ("Cannot allocate image space.\n");
-+ return;
-+ }
-+
-+ lptr = data;
-+ end_y = (src_y + height + mag - 1) / mag;
-+ if (end_y > image -> height)
-+ end_y = image -> height;
-+ end_x = (src_x + width + mag - 1) / mag;
-+ if (end_x > image -> width)
-+ end_x = image -> width;
-+ for (j = src_y / mag, y = 0; j < end_y; j++, y += mag)
-+ {
-+ for (i = src_x / mag, x = 0; i < end_x; i++, x += mag)
-+ {
-+ bits = (*image -> f.get_pixel) (image, i, j);
-+ end_lx = x + mag;
-+ for (lx = x; lx < end_lx; lx++)
-+ (*large_image -> f.put_pixel)
-+ (large_image, lx, y, bits);
-+ }
-+
-+ for (i = 1; (i < mag) && (y + i < height); i++)
-+ bcopy (lptr,
-+ lptr + large_image -> bytes_per_line * i,
-+ large_image -> bytes_per_line);
-+
-+ lptr += (large_image -> bytes_per_line * mag);
-+ }
-+ XPutImage (XtDisplay(w), XtWindow(w), gc, large_image,
-+ 0, 0, WOffset, HOffset,
-+ width, height);
-+
-+ XFree (large_image);
-+ }
-+ else
-+ {
-+ register long obits;
-+ int count, starting_x;
-+ long white = WhitePixel (XtDisplay (w), screen);
-+
-+ end_y = (src_y + height + mag - 1) / mag;
-+ if (end_y > image -> height)
-+ end_y = image -> height;
-+ end_x = (src_x + width + mag - 1) / mag;
-+ if (end_x > image -> width)
-+ end_x = image -> width;
-+
-+ for (j = src_y / mag, y = src_y; j < end_y;
-+ j++, y += mag)
-+ {
-+ obits = (*image -> f.get_pixel) (image, src_x / mag, j);
-+ count = 0;
-+ starting_x = src_x;
-+ for (i = src_x / mag, x = src_x; i < end_x;
-+ i++, x += mag)
-+ {
-+ bits = (*image -> f.get_pixel) (image, i, j);
-+ if (bits == obits)
-+ {
-+ if (count == 0)
-+ starting_x = x;
-+ count++;
-+ }
-+ else if (count)
-+ {
-+ if (obits != white)
-+ XFillRectangle (XtDisplay(w),
-+ XtWindow (w),
-+ gc,
-+ starting_x, y,
-+ count * mag,
-+ mag);
-+ count = 1;
-+ starting_x = x;
-+ obits = bits;
-+ }
-+ }
-+ if (count && obits != white)
-+ XFillRectangle (XtDisplay(w),
-+ XtWindow (w),
-+ gc,
-+ starting_x, y,
-+ count * mag,
-+ mag);
-+ }
-+ }
-+ }
-+
-
- /*************************************<->*************************************
- *
-! * SMRasterDestroy
- *
- * Description:
- * -----------
-***************
-*** 377,387 ****
- * Free up the GC's and stuff on destroy.
- *
- *************************************<->***********************************/
-! static void SRasterDestroy (srw)
-! XwSRasterWidget srw;
- {
-! XtDestroyGC (srw->sraster.NormalGC);
-! XtDestroyGC (srw->sraster.InverseGC);
- }
-
-
---- 582,592 ----
- * Free up the GC's and stuff on destroy.
- *
- *************************************<->***********************************/
-! static void SMRasterDestroy (srw)
-! XwSMRasterWidget srw;
- {
-! XtDestroyGC (srw->smraster.NormalGC);
-! XtDestroyGC (srw->smraster.InverseGC);
- }
-
-
-***************
-*** 397,419 ****
-
-
- static void Select(w,event)
-! XwSRasterWidget w;
- XEvent *event;
- {
-! w->sraster.poked = TRUE;
-! if (w->sraster.invert)
-! ShowSR(w,NULL,w->sraster.InverseGC);
-
- XtCallCallbacks(w,XtNselect,event);
- }
-
- static void Release(w,event)
-! XwSRasterWidget w;
- XEvent *event;
- {
-! w->sraster.poked = FALSE;
-! if (w->sraster.invert)
-! ShowSR(w,NULL,w->sraster.NormalGC);
-
- XtCallCallbacks(w,XtNrelease,event);
- }
---- 602,624 ----
-
-
- static void Select(w,event)
-! XwSMRasterWidget w;
- XEvent *event;
- {
-! w->smraster.poked = TRUE;
-! if (w->smraster.invert)
-! ShowSR(w,NULL,w->smraster.InverseGC);
-
- XtCallCallbacks(w,XtNselect,event);
- }
-
- static void Release(w,event)
-! XwSMRasterWidget w;
- XEvent *event;
- {
-! w->smraster.poked = FALSE;
-! if (w->smraster.invert)
-! ShowSR(w,NULL,w->smraster.NormalGC);
-
- XtCallCallbacks(w,XtNrelease,event);
- }
-***************
-*** 444,454 ****
- * XwGeomCheck;
- *************************************<->***********************************/
-
-! static Boolean SetValues(current, request, new)
- Widget current, request, new;
- {
-! XwSRasterWidget cw = (XwSRasterWidget) current;
-! XwSRasterWidget nw = (XwSRasterWidget) new;
- Boolean flag = FALSE; /* our return value */
- int ht;
-
---- 649,660 ----
- * XwGeomCheck;
- *************************************<->***********************************/
-
-! static Boolean SetValues(current, request, new, last)
- Widget current, request, new;
-+ Boolean last;
- {
-! XwSMRasterWidget cw = (XwSMRasterWidget) current;
-! XwSMRasterWidget nw = (XwSMRasterWidget) new;
- Boolean flag = FALSE; /* our return value */
- int ht;
-
-***************
-*** 461,475 ****
- cw->core.background_pixel != nw->core.background_pixel)
- flag = TRUE;
-
-! if ((cw->sraster.image != nw->sraster.image ||
-! cw->sraster.image->data != nw->sraster.image->data) &&
- nw->primitive.recompute_size)
- {
-! nw->core.width = nw->sraster.image->width + ht;
-! nw->core.height = nw->sraster.image->height + ht;
- flag = TRUE;
- }
-! if (cw->sraster.invert != nw->sraster.invert)
- flag = TRUE;
-
- return( flag );
---- 667,684 ----
- cw->core.background_pixel != nw->core.background_pixel)
- flag = TRUE;
-
-! if ((cw->smraster.magnification != nw->smraster.magnification ||
-! cw->smraster.image != nw->smraster.image ||
-! cw->smraster.image->data != nw->smraster.image->data) &&
- nw->primitive.recompute_size)
- {
-! nw->core.width = nw->smraster.image->width *
-! nw->smraster.magnification + ht;
-! nw->core.height = nw->smraster.image->height *
-! nw->smraster.magnification + ht;
- flag = TRUE;
- }
-! if (cw->smraster.invert != nw->smraster.invert)
- flag = TRUE;
-
- return( flag );
-***************
-*** 495,504 ****
- *************************************<->***********************************/
-
-
-! static void Resize(w)
-! XwSRasterWidget w;
- {
-! ShowSR(w,NULL,w->sraster.NormalGC);
- }
-
-
---- 704,714 ----
- *************************************<->***********************************/
-
-
-! static void Resize (w, event)
-! XwSMRasterWidget w;
-! XExposeEvent *event;
- {
-! ShowSR(w, event, w->smraster.NormalGC);
- }
-
-
-***************
-*** 505,511 ****
- /*************************************<->*************************************
- *
- * BuildNormGC(srw)
-! * XwSRasterWidget srw;
- *
- * Description:
- * -----------
---- 715,721 ----
- /*************************************<->*************************************
- *
- * BuildNormGC(srw)
-! * XwSMRasterWidget srw;
- *
- * Description:
- * -----------
-***************
-*** 526,532 ****
- *************************************<->***********************************/
-
- static void BuildNormGC(srw)
-! XwSRasterWidget srw;
- {
- XGCValues values;
-
---- 736,742 ----
- *************************************<->***********************************/
-
- static void BuildNormGC(srw)
-! XwSMRasterWidget srw;
- {
- XGCValues values;
-
-***************
-*** 535,541 ****
- values.line_width = 1;
-
-
-! srw->sraster.NormalGC = XtGetGC((Widget)srw,
- (unsigned) GCForeground |
- (unsigned) GCBackground,
- &values);
---- 745,751 ----
- values.line_width = 1;
-
-
-! srw->smraster.NormalGC = XtGetGC((Widget)srw,
- (unsigned) GCForeground |
- (unsigned) GCBackground,
- &values);
-***************
-*** 544,550 ****
- /*************************************<->*************************************
- *
- * void BuildInvGC(srw)
-! * XwSRasterWidget srw;
- *
- * Description:
- * -----------
---- 754,760 ----
- /*************************************<->*************************************
- *
- * void BuildInvGC(srw)
-! * XwSMRasterWidget srw;
- *
- * Description:
- * -----------
-***************
-*** 562,575 ****
- *************************************<->***********************************/
-
- static void BuildInvGC(srw)
-! XwSRasterWidget srw;
- {
- XGCValues values;
- values.foreground = srw->core.background_pixel;
- values.background = srw->primitive.foreground;
-
-! srw->sraster.InverseGC = XtGetGC((Widget)srw,
- (unsigned) GCForeground |
- (unsigned) GCBackground,
- &values);
- }
---- 772,799 ----
- *************************************<->***********************************/
-
- static void BuildInvGC(srw)
-! XwSMRasterWidget srw;
- {
- XGCValues values;
- values.foreground = srw->core.background_pixel;
- values.background = srw->primitive.foreground;
-
-! srw->smraster.InverseGC = XtGetGC((Widget)srw,
- (unsigned) GCForeground |
- (unsigned) GCBackground,
- &values);
-+ }
-+
-+ void UnmapSMRasterWidget (w)
-+ register XwSMRasterWidget w;
-+ {
-+ w->smraster.ismapped = False;
-+ XtUnmapWidget (w);
-+ }
-+
-+ void MapSMRasterWidget (w)
-+ register XwSMRasterWidget w;
-+ {
-+ w->smraster.ismapped = True;
-+ XtMapWidget (w);
- }
-*** SRaster.h Wed Jan 4 20:22:46 1989
---- SMRaster.h Wed Jan 4 20:23:08 1989
-***************
-*** 1,7 ****
- /*************************************<+>*************************************
- *****************************************************************************
- **
-! ** File: SRaster.h
- **
- ** Project: X Widgets
- **
---- 1,7 ----
- /*************************************<+>*************************************
- *****************************************************************************
- **
-! ** File: SMRaster.h
- **
- ** Project: X Widgets
- **
-***************
-*** 25,41 ****
- *************************************<+>*************************************/
-
-
-! /* Static Raster Widget */
-
-! extern WidgetClass XwsrasterWidgetClass;
-
-! typedef struct _XwSRasterClassRec * XwSRasterWidgetClass;
-! typedef struct _XwSRasterRec * XwSRasterWidget;
-
-
- /* synonyms added for consistent naming conventions */
-
-! extern WidgetClass XwstaticRasterWidgetClass;
-
-! typedef struct _XwSRasterClassRec * XwStaticRasterWidgetClass;
-! typedef struct _XwSRasterRec * XwStaticRasterWidget;
---- 25,44 ----
- *************************************<+>*************************************/
-
-
-! /* Static Magnifying Raster Widget */
-
-! extern WidgetClass XwsmrasterWidgetClass;
-
-! typedef struct _XwSMRasterClassRec * XwSMRasterWidgetClass;
-! typedef struct _XwSMRasterRec * XwSMRasterWidget;
-
-
- /* synonyms added for consistent naming conventions */
-
-! extern WidgetClass XwstaticMagnifyingRasterWidgetClass;
-
-! typedef struct _XwSMRasterClassRec * XwStaticMagnifyingRasterWidgetClass;
-! typedef struct _XwSMRasterRec * XwStaticMagnifyingRasterWidget;
-!
-! #define XtNsMRmagnification "magnification"
-! #define XtCSMRmagnification "Magnification"
-*** SRasterP.h Wed Jan 4 20:22:46 1989
---- SMRasterP.h Wed Jan 4 20:23:08 1989
-***************
-*** 31,47 ****
- *
- **************************************************/
-
-! typedef struct _SRasterClassPart
- {
- int mumble;
-! } SRasterClassPart;
-
-! typedef struct _XwSRasterClassRec
- {
- CoreClassPart core_class;
- XwPrimitiveClassPart primitive_class;
-! SRasterClassPart sraster_class;
-! } SRasterClassRec;
-
- /****************
- *
---- 31,47 ----
- *
- **************************************************/
-
-! typedef struct _SMRasterClassPart
- {
- int mumble;
-! } SMRasterClassPart;
-
-! typedef struct _XwSMRasterClassRec
- {
- CoreClassPart core_class;
- XwPrimitiveClassPart primitive_class;
-! SMRasterClassPart smraster_class;
-! } SMRasterClassRec;
-
- /****************
- *
-***************
-*** 48,54 ****
- * Forward Declarations - I thought unix was smart!
- *
- ****************/
-! void InitSRaster();
- void Realize();
- void Resize();
- void ShowSR();
---- 48,54 ----
- * Forward Declarations - I thought unix was smart!
- *
- ****************/
-! void InitSMRaster();
- void Realize();
- void Resize();
- void ShowSR();
-***************
-*** 60,66 ****
- *
- ***************************************************/
-
-! typedef struct _SRasterPart
- {
- XImage * image;
- Boolean invert;
---- 60,66 ----
- *
- ***************************************************/
-
-! typedef struct _SMRasterPart
- {
- XImage * image;
- Boolean invert;
-***************
-*** 68,80 ****
- Boolean showme;
- GC NormalGC;
- GC InverseGC;
-! } SRasterPart;
-
-! typedef struct _XwSRasterRec
- {
- CorePart core;
- XwPrimitivePart primitive;
-! SRasterPart sraster;
-! } SRasterRec;
-
-
---- 68,82 ----
- Boolean showme;
- GC NormalGC;
- GC InverseGC;
-! int magnification;
-! int ismapped;
-! } SMRasterPart;
-
-! typedef struct _XwSMRasterRec
- {
- CorePart core;
- XwPrimitivePart primitive;
-! SMRasterPart smraster;
-! } SMRasterRec;
-
-
//GO.SYSIN DD xdiff