In the next two examples, the end user uses the box cursor to indicate the
boundaries to which a displayed image is subsequently trimmed.
The example in Figure 98 restores the image from a saved GDDM image object
to the default image field, which implies a full screen image field. The
box cursor can therefore never be positioned outside this field.
The example in Figure 99 shows how an image field covering part of the
screen can be used.
IMPROG5: PROC OPTIONS(MAIN);
DCL H_PIXELS FIXED BIN(31); /* Display image horizontal */
/* size in pixels */
DCL V_PIXELS FIXED BIN(31); /* Display image vertical */
/* size in pixels */
DCL IM_TYPE FIXED BIN(31); /* Display device image type */
DCL RES FIXED BIN(31); /* Defined/undefined resolutn.*/
DCL RES_UNIT FIXED BIN(31) /* Display device resolution */
INIT(0); /* units to be inches */
DCL H_RES FLOAT DEC(6); /* Display image horizontal */
/* resn. in pixels per inch */
DCL V_RES FLOAT DEC(6); /* Display image vertical */
/* resn. in pixels per inch */
DCL (ATTYPE,ATTVAL,COUNT) /* ASREAD parameters */
FIXED BIN(31);
DCL BOX_ECHO FIXED BIN(31); /* ISQBOX parameter */
DCL BOX_LEFT FIXED BIN(31); /* Box left edge position */
/* in pixels */
DCL BOX_RIGHT FIXED BIN(31); /* Box right edge position */
/* in pixels */
DCL BOX_TOP FIXED BIN(31); /* Box top edge position */
/* in pixels */
DCL BOX_BOTTOM FIXED BIN(31); /* Box bottom edge position */
/* in pixels */
DCL BOX_IN_IMAGE FIXED BIN(31); /* Box within image */
DCL BOX_STATUS FIXED BIN(31); /* Box status (enabled or not)*/
DCL DESCR CHAR(30); /* Imarst parameter */
CALL FSINIT;
CALL IMARST(0,0,'IMAGNAME',30,DESCR); /* Restore saved image */ A
/* to display screen */
CALL IMAQRY(0,H_PIXELS,V_PIXELS,IM_TYPE, B
RES,RES_UNIT,H_RES,V_RES);
/* Query the display image */
CALL ISIBOX(0,0.25*H_PIXELS,0.75*H_PIXELS, C
0.25*V_PIXELS,0.75*V_PIXELS);
/* Initialize box cursor */
CALL FSENAB(3,1); /* Enable image input */ D
CALL ISENAB(2,1); /* Enable box cursor */ E
LOOP:
DO WHILE(1=1); /* Cursor process loop */
CALL ASREAD(ATTYPE,ATTVAL,COUNT);
IF ATTYPE=1 THEN
IF ATTVAL=3 THEN LEAVE LOOP; /* Exit if PF3 key pressed */ F
ELSE
IF ATTVAL=12 THEN /* Restore original image */
CALL IMARST(0,0,'IMAGNAME',30,DESCR);/* If PF12 pressed */ G
ELSE; /* Ignore other PF keys */
ELSE DO; /* Trim image to box size */
CALL ISQBOX(BOX_ECHO, /* Query box cursor */ H
BOX_LEFT,BOX_RIGHT,
BOX_TOP,BOX_BOTTOM,
BOX_IN_IMAGE,BOX_STATUS);
CALL IMATRM(0,BOX_LEFT,BOX_RIGHT, /* Trim the display image */ I
BOX_TOP,BOX_BOTTOM);
END; /* Trim image to box size */
END LOOP; /* Cursor process loop */
CALL ISENAB(2,0); /* Disable box cursor */ J
CALL FSTERM;
%INCLUDE ADMUPINA;
%INCLUDE ADMUPINF;
%INCLUDE ADMUPINI;
END IMPROG5;
Figure 98. Interactive program that enables end users to trim the edges of
an image
In the above program, at A , a previously saved image with the file name
IMAGNAME is restored to the display screen. The image field defaults to
full screen size.
At B , the size of the display device image (the image field) is queried.
This is used, at C , to set the box cursor size to half of this size, and
to position it centrally.
At D and E , image input is enabled. You must code both of these
statements. The first enables image input as the input type, and the
second specifically enables the box cursor.
The loop following these statements enables the terminal user to
reposition and change the size of the box cursor, and press the ENTER key,
after which the displayed image is trimmed to the box; all of this can be
repeated as many times as required.
At F , the user can exit from the loop by pressing PF3.
At G , the user is able to restore the original, untrimmed image by
pressing PF12.
At H , the box cursor is queried, and in this simple example the returned
values are used directly, at I , to trim the displayed image to the box
size.
At J , the box cursor is disabled before terminating GDDM. In a real
application, other functions might precede the GDDM termination, and it is
good practice to disable the image cursor once the associated processing
is completed.
Figure 99 shows an extension of the above example demonstrating how to
handle an image field that occupies only part of the screen. In this
case, the box cursor can lie partly or completely outside the image field.
IMPROG6: PROC OPTIONS(MAIN);
.
.
/* Declarations as in previous example, plus: */
DCL ERROR BIT(1); /* On for error in box position*/
DCL NO BIT(1) INIT('0'B);
DCL YES BIT(1) INIT('1'B);
CALL FSINIT;
CALL ISFLD(10,15,20,50,0); /* 20 row by 50 col field */ A
CALL IMARST(0,0,'IMAGNAME',30,DESCR); /* Restore saved image */
/* to display screen */
CALL IMAQRY(0,H_PIXELS,V_PIXELS,IM_TYPE,
RES,RES_UNIT,H_RES,V_RES);
/* Query the display image */
CALL ISIBOX(0,0.25*H_PIXELS,0.75*H_PIXELS,
0.25*V_PIXELS,0.75*V_PIXELS);
/* Initialize box cursor */
CALL FSENAB(3,1); /* Enable image input */
CALL ISENAB(2,1); /* Enable box cursor */
LOOP:
DO WHILE(1=1); /* Cursor process loop */
CALL ASREAD(ATTYPE,ATTVAL,COUNT);
IF ATTYPE=1 THEN
IF ATTVAL=3 THEN LEAVE LOOP; /* Exit if PF3 key pressed */
ELSE
IF ATTVAL=12 THEN /* Restore original image */
CALL IMARST(0,0,'IMAGNAME',30,DESCR);/* If PF12 pressed */
ELSE; /* Ignore other PF keys */
ELSE DO; /* Trim image to box size */
CALL ISQBOX(BOX_ECHO, /* Query box cursor */
BOX_LEFT,BOX_RIGHT,
BOX_TOP,BOX_BOTTOM,
BOX_IN_IMAGE,BOX_STATUS);
IF BOX_IN_IMAGE=0 THEN ERROR=YES;/* Box is completely outside*/ B
/* image */
ELSE
IF BOX_IN_IMAGE=1 THEN ERROR=NO;/* Box is fully within */ C
/* image */
ELSE /*BOX_IN_IMAGE=2*/ /* Box is partly outside image*/
DO; /* Sub-box process */ D
ERROR=NO;
IF BOX_LEFT < 0 THEN BOX_LEFT = 0;
IF BOX_TOP < 0 THEN BOX_TOP = 0;
IF BOX_RIGHT > H_PIXELS-1 THEN BOX_RIGHT = H_PIXELS-1;
IF BOX_BOTTOM > V_PIXELS-1 THEN BOX_BOTTOM = V_PIXELS-1;
END; /* Sub-box process */
IF ERROR THEN E
CALL IMATRM(0,BOX_LEFT,BOX_RIGHT,/* Trim the display image */
BOX_TOP,BOX_BOTTOM);
END; /* Trim image to box size */
END LOOP; /* Cursor process loop */
CALL ISENAB(2,0); /* Disable box cursor */
CALL FSTERM;
%INCLUDE ADMUPINA;
%INCLUDE ADMUPINF;
%INCLUDE ADMUPINI;
END IMPROG6;
Figure 99. Program manipulating an image that is larger than the screen
At A in Figure 99, an image field 20 rows deep by 50 columns wide is
created.
At B , the error switch is set if the box cursor has been positioned
completely outside the image field. In a real program, an alphanumeric
prompting message might be provided, telling the end user to reposition
the cursor.
At C , when the box is fully within the image field, the switch setting
ensures that the processing is the same as in the previous example.
At D , the box that is partly outside the image field is redefined, to
force it to be entirely within the image field boundaries. If this were
not done, an IMATRM error condition would occur.
At E , the actual image trimming takes place, and is precluded if the box
cursor is completely outside the image field.
|