home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume22
/
popi
/
part07
< prev
next >
Wrap
Text File
|
1991-08-22
|
38KB
|
1,370 lines
Newsgroups: comp.sources.misc
From: Rich Burridge <richb@Aus.Sun.COM>
Subject: v22i046: popi - The Digital Darkroom, Part07/09
Message-ID: <1991Aug22.153136.15915@sparky.IMD.Sterling.COM>
X-Md4-Signature: 261348ffed967e3e6fa56fffea3504fd
Date: Thu, 22 Aug 1991 15:31:36 GMT
Approved: kent@sparky.imd.sterling.com
Submitted-by: Rich Burridge <richb@Aus.Sun.COM>
Posting-number: Volume 22, Issue 46
Archive-name: popi/part07
Environment: Xlib, Xview, SunView
Supersedes: popi: Volume 9, Issue 47-55
#! /bin/sh
# 1. Remove everything above the #! /bin/sh line
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh to create the files:
# nulldev.c
# sunview.c
# x11.c
# xview.c
# This archive created: Wed Aug 21 10:36:06 EST 1991
#
#
export PATH; PATH=/bin:$PATH
#
if [ -f nulldev.c ]
then
echo shar: will not over-write existing file nulldev.c
else
echo shar: extracting 'nulldev.c', 2995 characters
cat > nulldev.c <<'Funky_Stuff'
/*LINTLIBRARY*/
/* @(#)nulldev.c 1.2 90/12/28
*
* Popi device driver for a null device.
* written by Stephen Frede, Softway Pty Ltd.
*
* Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
* This version is based on the code in his Prentice Hall book,
* "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
* which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
*
* Permission is given to distribute these extensions, as long as these
* introductory messages are not removed, and no monies are exchanged.
*
* No responsibility is taken for any errors or inaccuracies inherent
* either to the comments or the code of this program, but if reported
* (see README file) then an attempt will be made to fix them.
*/
#include "popi.h"
/* These are the exportable routines used by the popi program.
*
* disp_init(argc, argv) - called from main at the start.
* disp_finish() - called from main prior to exit.
* disp_imgstart() - called prior to drawing an image.
* disp_imgend() - called after drawing an image.
* disp_putline(lines, y) - to draw an image scanline triple.
* disp_getchar() - to get the next character typed.
* disp_prompt() - display popi prompt and clear input buffer.
* disp_error(errtype) - display error message.
* disp_percentdone(n) - display percentage value of conversion.
*/
/*ARGSUSED*/
void
disp_init(argc,argv) /* called from main at the atart. */
int argc;
char *argv[];
{
}
void
disp_finish() /* called from main prior to exit. */
{
}
void
disp_imgstart() /* called prior to drawing an image. */
{
}
void
disp_imgend() /* called after drawing an image. */
{
}
void
disp_putline(lines, y) /* called to draw image scanline y. */
pixel_t **lines;
int y;
{
}
int
disp_getchar() /* get next user typed character. */
{
return(getchar());
}
int
disp_prompt() /* display popi prompt. */
{
static char prompt[] = "-> ";
PRINTF(prompt);
return sizeof prompt - 1;
}
void
disp_error(errtype, pos) /* display error message. */
int errtype,
pos;
{
extern int errno;
extern char *sys_errlist[];
if (errtype & ERR_PARSE)
{
int i;
for (i=1; i < pos; ++i)
PUTC('-', stderr);
PUTC('^', stderr);
PUTC('\n', stderr);
}
FPRINTF(stderr, "%s\n", ErrBuf);
/* we assume errno hasn't been reset by the preceding output */
if (errtype & ERR_SYS)
FPRINTF(stderr, "\t(%s)\n", sys_errlist[errno]);
}
void
disp_percentdone(percent)
int percent;
{
static int lastpercent = 100;
if (!Verbose)
return;
if (percent == 100)
{
printf("\r \n");
return;
}
if (percent != lastpercent && percent % 5 == 0)
{
printf("\r%2d%% ", percent);
fflush(stdout);
lastpercent = percent;
}
}
Funky_Stuff
len=`wc -c < nulldev.c`
if [ $len != 2995 ] ; then
echo error: nulldev.c was $len bytes long, should have been 2995
fi
fi # end of overwriting check
if [ -f sunview.c ]
then
echo shar: will not over-write existing file sunview.c
else
echo shar: extracting 'sunview.c', 10134 characters
cat > sunview.c <<'Funky_Stuff'
/*LINTLIBRARY*/
/* @(#)sunview.c 1.3 91/01/03
*
* SunView dependent graphics routines used by popi.
* written by Rich Burridge - Sun Microsystems.
*
* Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
* This version is based on the code in his Prentice Hall book,
* "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
* which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
*
* Permission is given to distribute these extensions, as long as these
* introductory messages are not removed, and no monies are exchanged.
*
* No responsibility is taken for any errors or inaccuracies inherent
* either to the comments or the code of this program, but if reported
* (see README file) then an attempt will be made to fix them.
*/
#include "popi.h"
#include <suntool/sunview.h>
#include <suntool/canvas.h>
#include <suntool/panel.h>
#include <suntool/tty.h>
Canvas canvas ;
Cursor busy_cursor, main_cursor ;
Frame cframe, tframe ;
Icon popi_icon ;
Notify_value destroy_proc() ;
Panel panel ;
Panel_item slider ;
Pixrect *pr ; /* Offscreen image area. */
Pixwin *cpw ;
Tty ttysw ;
short busy_cursor_array[] = {
#include <images/hglass.cursor>
} ;
mpr_static(busy_cursor_pr, 16, 16, 1, busy_cursor_array) ;
static int depth ; /* 1, 8, or 32 */
unsigned short icon_image[] = {
#include "popi.icon"
} ;
mpr_static(icon_pr, 64, 64, 1, icon_image) ;
extern int errno ;
extern char *sys_errlist[] ;
void canvas_proc() ;
char ttybuf[MAXLINE] ; /* Input from user in ttysw window. */
unsigned char *mptr ; /* Pointer to scanline data. */
int iscolor ; /* Set if this is a color screen. */
int opercent = -1 ; /* Previous display percent done value. */
int tbufptr ; /* Current pointer into ttybuf. */
/* These are the exportable routines used by the popi program.
*
* disp_init(argc, argv) - called from main at the start.
* disp_finish() - called from main prior to exit.
* disp_imgstart() - called prior to drawing an image.
* disp_imgend() - called after drawing an image.
* disp_putline(lines, y) - to draw an image scanline triple.
* disp_getchar() - to get the next character typed.
* disp_prompt() - display popi prompt and clear input buffer.
* disp_error(errtype, pos) - display error message.
* disp_percentdone(n) - display percentage value of conversion.
*/
void
disp_init(argc, argv) /* Called from main at the start. */
int argc ;
char *argv[] ;
{
char title[MAXLINE] ; /* Used to constructure window title lines. */
int cht ; /* Height of the popi term window. */
int cx ; /* X position of the popi term window. */
int cy ; /* Y position of the popi term window. */
int ttyfd ; /* File descriptor for tty subwindow. */
STRCPY(ttybuf, "") ; /* Zeroise tty input buffer. */
tbufptr = 0 ; /* Reset tty buffer pointer. */
if (getenv("WINDOW_PARENT") == NULL)
{
FPRINTF(stderr,"%s: Not a native SunView window\n", ProgName) ;
exit(1) ;
}
popi_icon = icon_create(ICON_IMAGE, &icon_pr, 0) ; /* Create icon. */
SPRINTF(title, "%s commands", ProgName) ;
tframe = window_create((Window) 0, FRAME, /* Create tty frame. */
FRAME_ICON, popi_icon,
WIN_ROWS, 10,
WIN_COLUMNS, 80,
FRAME_LABEL, title,
FRAME_ARGS, argc, argv,
0) ;
ttysw = window_create(tframe, TERM, /* Create tty window. */
TTY_ARGV, TTY_ARGV_DO_NOT_FORK,
0) ;
cx = (int) window_get(tframe, WIN_X) ;
cy = (int) window_get(tframe, WIN_Y) ;
cht = (int) window_get(tframe, WIN_HEIGHT) ;
SPRINTF(title, "%s image canvas", ProgName) ;
cframe = window_create((Window) 0, FRAME, /* Create canvas frame. */
WIN_X, cx,
WIN_Y, cy + cht + 10,
FRAME_LABEL, title,
FRAME_SHOW_LABEL, TRUE,
0) ;
panel = window_create(cframe, PANEL, /* Create panel for slider. */
WIN_SHOW, FALSE,
0) ;
slider = panel_create_item(panel, PANEL_SLIDER,
PANEL_LABEL_STRING, "% done",
PANEL_MIN_VALUE, 0,
PANEL_MAX_VALUE, 100,
0) ;
canvas = window_create(cframe, CANVAS, /* Create canvas. */
WIN_WIDTH, Xsize,
WIN_HEIGHT, Ysize,
CANVAS_RETAINED, TRUE,
WIN_EVENT_PROC, canvas_proc,
0) ;
cpw = canvas_pixwin(canvas) ;
depth = cpw->pw_pixrect->pr_depth;
window_fit(cframe) ;
(void) signal(SIGHUP, SIG_IGN) ;
ttyfd = (int) window_get(ttysw, TTY_TTY_FD) ;
(void) dup2(ttyfd, 0) ;
(void) dup2(ttyfd, 1) ;
(void) dup2(ttyfd, 2) ;
(void) window_set(canvas, WIN_INPUT_DESIGNEE,
(int) window_get(ttysw, WIN_DEVICE_NUMBER), 0) ;
main_cursor = window_get(canvas, WIN_CURSOR) ;
busy_cursor = cursor_create(CURSOR_IMAGE, &busy_cursor_pr, 0) ;
load_colors() ; /* Load the popi grayscale colormap. */
(void) notify_interpose_destroy_func(cframe, destroy_proc) ;
(void) notify_interpose_destroy_func(tframe, destroy_proc) ;
(void) window_set(tframe, WIN_SHOW, TRUE, 0) ;
(void) window_set(cframe, WIN_SHOW, TRUE, 0) ;
(void) notify_dispatch() ; /* Make the window appear. */
(void) notify_do_dispatch() ;
init_dither() ; /* Initialise dither arrays and variables. */
}
void
disp_finish() /* Called from main prior to exit - null routine. */
{}
void
disp_imgstart() /* Called prior to drawing an image. */
{
(void) window_set(cframe, WIN_SHOW, TRUE, 0) ;
(void) pw_writebackground(cpw, 0, 0, Xsize, Ysize, PIX_CLR) ;
(void) window_set(panel, WIN_SHOW, FALSE, 0) ;
(void) notify_dispatch() ;
}
void
disp_imgend() /* Called after drawing an image. */
{}
void
disp_putline(lines, y) /* Draw an image scanline. */
unsigned char **lines ;
int y ;
{
int color, i, j, x ;
unsigned char *line, tmp;
mptr = (unsigned char *) ((struct mpr_data *) pr->pr_data)->md_image ;
if (depth == 32)
{
if (colors == 1)
for (i = j = 0; i < Xsize; i++)
{
tmp = lines[0][i] ;
mptr[j++] = 0; /* X */
mptr[j++] = tmp; /* B */
mptr[j++] = tmp; /* G */
mptr[j++] = tmp; /* R */
}
else
for (i = j = 0; i < Xsize; i++)
{
mptr[j++] = 0; /* X */
for (color = 2; color >= 0; color--)
mptr[j++] = lines[color][i] ; /* G, B, R */
}
}
else if (depth == 8)
{
line = ntsc_luma(lines);
for (x = 0; x < Xsize; x++)
mptr[x] = 255 - line[x] ;
}
else
{
line = ntsc_luma(lines);
halftone(line, y) ;
}
(void) pw_rop(cpw, 0, y, Xsize, 1, PIX_SRC, pr, 0, 0) ;
}
disp_getchar() /* Get next user typed character. */
{
int c ;
if (!tbufptr) /* If buffer empty, get next line. */
if (gets(ttybuf) == NULL) { /* fake up 'q' for ^D... */
ttybuf[0] = 'q';
ttybuf[1] = 0;
}
c = ttybuf[tbufptr++] ;
if (c == '\0') /* Is it end of input buffer? */
{
c = '\n' ;
tbufptr = 0 ; /* Reset to force another read. */
set_cursor(BUSY_CUR) ; /* We will now get busy! */
}
return c ;
}
disp_prompt() /* Display popi prompt and clear input line. */
{
char *prompt = "\r-> " ;
set_cursor(NORMAL_CUR) ;
PRINTF(prompt) ;
FFLUSH(stdout) ;
return(sizeof prompt - 1) ;
}
void
disp_error(errtype, pos) /* Display error message. */
int errtype ;
int pos ;
{
int i ;
if (errtype & ERR_PARSE)
{
for (i = 1; i < pos; ++i) PUTC('-', stderr) ;
PUTC('^', stderr) ;
PUTC('\n', stderr) ;
}
FPRINTF(stderr, "%s\n", ErrBuf) ;
/* We assume errno hasn't been reset by the preceding output */
if (errtype & ERR_SYS)
FPRINTF(stderr, "\t(%s)\n", sys_errlist[errno]) ;
FFLUSH(stderr) ;
}
void
disp_percentdone(percent)
int percent ;
{
if (percent == opercent) return ; /* Same as last time? */
panel_set_value(slider, percent) ;
if (!percent) (void) window_set(panel, WIN_SHOW, TRUE, 0) ;
opercent = percent ;
(void) notify_dispatch() ;
}
/*ARGSUSED*/
void
canvas_proc(window, event)
Window window ;
Event *event ;
{
window_default_event_proc(canvas, event, (char *) 0) ;
}
/*ARGSUSED*/
Notify_value
destroy_proc(client, status)
Notify_client client ;
Destroy_status status ;
{
exit(0) ;
}
load_colors() /* Create and load popi color map. */
{
int i ;
char cmsname[MAXLINE] ;
u_char red[CMAPLEN], green[CMAPLEN], blue[CMAPLEN] ;
iscolor = (depth > 1) ? 1 : 0 ;
if (depth == 32)
pr = mem_create(Xsize, 1, 32) ;
else if (depth == 8)
{
for (i = 0; i < CMAPLEN; i++)
red[i] = green[i] = blue[i] = 255 - i ;
SPRINTF(cmsname, "popi%10ld", getpid()) ;
(void) pw_setcmsname(cpw, cmsname) ;
(void) pw_putcolormap(cpw, 0, CMAPLEN, red, green, blue) ;
pr = mem_create(Xsize, 1, 8) ;
}
else
pr = mem_create(Xsize, 1, 1) ;
}
set_cursor(type)
enum cur_type type ;
{
switch (type)
{
case BUSY_CUR :
(void) window_set(canvas, WIN_CURSOR, busy_cursor, 0) ;
break ;
case NORMAL_CUR:
(void) window_set(canvas, WIN_CURSOR, main_cursor, 0) ;
}
}
Funky_Stuff
len=`wc -c < sunview.c`
if [ $len != 10134 ] ; then
echo error: sunview.c was $len bytes long, should have been 10134
fi
fi # end of overwriting check
if [ -f x11.c ]
then
echo shar: will not over-write existing file x11.c
else
echo shar: extracting 'x11.c', 10182 characters
cat > x11.c <<'Funky_Stuff'
/*LINTLIBRARY*/
/* @(#)x11.c 1.5 91/08/21
*
* X11 dependent graphics routines used by popi.
* written by Rich Burridge - Sun Microsystems.
*
* Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
* This version is based on the code in his Prentice Hall book,
* "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
* which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
*
* Permission is given to distribute these extensions, as long as these
* introductory messages are not removed, and no monies are exchanged.
*
* No responsibility is taken for any errors or inaccuracies inherent
* either to the comments or the code of this program, but if reported
* (see README file) then an attempt will be made to fix them.
*/
#include "popi.h"
#include "graphics.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/cursorfont.h>
#include <X11/keysym.h>
#define BOLDFONT "lucidasanstypewriter-bold-12"
#define DEFFONT "fixed"
#define NORMALFONT "lucidasanstypewriter-12"
#define POPI_BORDER_WIDTH 2
#define FRAME_MASK (KeyPressMask | KeyReleaseMask | ExposureMask)
short icon_image[] = {
#include "popi.icon"
} ;
Atom protocol_atom, kill_atom ;
Cursor busy_cursor, main_cursor ;
Display *dpy ;
GC gc, pix_gc ;
Pixmap memarea, popi_icon, load_icon() ;
Visual *visual ;
Window frame, frame_icon ;
XColor ccol ;
XEvent event ;
XFontStruct *bfont, *font, *nfont ;
XGCValues gc_val ;
XSetWindowAttributes attributes ;
XSizeHints size ;
XVisualInfo vinfo ;
XWMHints wm_hints ;
unsigned long gc_mask ;
int screen ;
unsigned int scr_depth ;
unsigned long backgnd, foregnd ;
unsigned long palette[CMAPLEN] ;
cleanup() /* Null routine for the X11 version. */
{
}
draw_scanline(lines, y) /* Display image scanline on the screen. */
unsigned char **lines ;
int y ;
{
XImage *image ;
int i, len ;
unsigned char *line ;
len = (iscolor) ? Xsize : ((Xsize / 8) + 1) ;
mptr = (unsigned char *) Emalloc(len) ;
line = ntsc_luma(lines) ;
if (iscolor)
{
for (i = 0; i < len; i++) mptr[i] = palette[255 - line[i]] ;
}
else
{
halftone(line, y) ;
}
image = XCreateImage(dpy, DefaultVisual(dpy, screen),
scr_depth,
(scr_depth > 1) ? ZPixmap : XYPixmap,
0, mptr, Xsize, 1, 8, len) ;
XPutImage(dpy, memarea, pix_gc, image, 0, 0, 0, y+100,
(unsigned) image->width, (unsigned) image->height) ;
XDestroyImage(image) ;
XSetFunction(dpy, gc, GXcopy) ;
XCopyArea(dpy, memarea, frame, gc, 0, y+100, Xsize, 1, 0, y+100) ;
FREE(mptr) ;
}
drawarea(x, y, width, height, op)
int x, y, width, height ;
enum op_type op ;
{
XSetFunction(dpy, gc, ops[(int) op]) ;
XFillRectangle(dpy, frame, gc, x, y,
(unsigned int) width, (unsigned int) height) ;
XSync(dpy, 0) ;
}
drawline(x1, y1, x2, y2)
int x1, y1, x2, y2 ;
{
gc_val.foreground = foregnd ;
gc_val.function = GXcopy ;
XChangeGC(dpy, gc, GCForeground | GCFunction, &gc_val) ;
XDrawLine(dpy, frame, gc, x1, y1, x2, y2) ;
}
drawtext(x, y, fontno, str)
enum font_type fontno ;
int x, y ;
char *str ;
{
int len = strlen(str) ;
if (len && str[len-1] == '\n') len-- ;
if (fontno == NFONT) font = nfont ;
else if (fontno == BFONT) font = bfont ;
gc_val.font = font->fid ;
gc_val.function = GXset ;
XChangeGC(dpy, gc, GCFont | GCFunction, &gc_val) ;
XDrawString(dpy, frame, gc, x, y, str, len) ;
}
XFontStruct *
get_font(name)
char *name ;
{
XFontStruct *font ;
if (!(font = XLoadQueryFont(dpy, name)))
if (!(font = XLoadQueryFont(dpy, DEFFONT)))
{
perror("couldn't get the default font.") ;
exit(1) ;
}
return(font) ;
}
get_next_char(c)
char *c ;
{
XClientMessageEvent *ev ;
XKeyPressedEvent *key_event ;
KeySym keysym ;
char chs[2] ;
for (;;)
{
if (!XCheckMaskEvent(dpy, ExposureMask, &event))
XNextEvent(dpy, &event) ;
switch (event.type)
{
case ClientMessage : /* Catch ICCCM kill from WM. */
ev = (XClientMessageEvent *) &event ;
if (ev->message_type == protocol_atom &&
ev->data.l[0] == kill_atom)
exit(0) ;
break ;
case Expose : process_expose((XExposeEvent *) &event) ;
break ;
case KeyPress : key_event = (XKeyPressedEvent *) &event ;
(void) XLookupString(key_event, chs, 1,
&keysym, (XComposeStatus *) NULL) ;
if (keysym == XK_Shift_L ||
keysym == XK_Shift_R) break ;
*c = chs[0] ;
return ;
}
}
/*NOTREACHED*/
}
init_fonts()
{
bfont = get_font(BOLDFONT) ;
nfont = get_font(NORMALFONT) ;
nfont_width = nfont->max_bounds.rbearing + nfont->min_bounds.lbearing ;
}
init_ws_type()
{
if ((dpy = XOpenDisplay(x11_display)) == NULL)
{
FPRINTF(stderr,"%s: Couldn't open display %s\n", ProgName,
(getenv ("DISPLAY") ? getenv("DISPLAY") : x11_display)) ;
exit(1) ;
}
screen = DefaultScreen(dpy) ;
if (!geometry)
STRCPY(geometry, XGetDefault(dpy, ProgName, "Geometry")) ;
foregnd = BlackPixel(dpy, screen) ;
backgnd = WhitePixel(dpy, screen) ;
scr_depth = DefaultDepth(dpy, screen) ;
ops[(int) GCLR] = GXclear ;
ops[(int) GSET] = GXset ;
return 0 ;
}
load_colors() /* Create and load popi color map. */
{
int i, numcolors ;
iscolor = 0 ;
if (DisplayCells(dpy, screen) > 2)
{
ccol.flags = DoRed | DoGreen | DoBlue ;
iscolor = 1 ;
numcolors = 0 ;
for (i = 0; i < CMAPLEN; i++)
{
ccol.red = ccol.green =
ccol.blue = (unsigned short) ((255 - i) << 8) ;
if (XAllocColor(dpy, DefaultColormap(dpy, screen), &ccol) == True)
palette[numcolors++] = ccol.pixel ;
}
if (numcolors < 2)
{
iscolor = 0 ;
FPRINTF(stderr, "%s: cannot allocate colors.\n", ProgName) ;
return ;
}
}
}
Pixmap
load_icon(sbuf)
short sbuf[] ;
{
char cbuf[512] ;
int i ;
GC igc ;
Pixmap pixmap ;
XImage *image ;
for (i = 0; i < 256; i++)
{
cbuf[i*2+0] = (sbuf[i] >> 8) & 0xFF ;
cbuf[i*2+1] = sbuf[i] & 0xFF ;
}
pixmap = XCreatePixmap(dpy, RootWindow(dpy, screen), 64, 64, 1) ;
gc_mask = GCForeground | GCBackground | GCGraphicsExposures ;
gc_val.foreground = foregnd ;
gc_val.background = backgnd ;
gc_val.graphics_exposures = False ;
igc = XCreateGC(dpy, pixmap, gc_mask, &gc_val) ;
image = XCreateImage(dpy, DefaultVisual(dpy, screen), 1, XYPixmap,
0, cbuf, 64, 64, BitmapPad(dpy), 0) ;
XPutImage(dpy, pixmap, igc, image, 0, 0, 0, 0, 64, 64) ;
XDestroyImage(image) ;
return(pixmap) ;
}
make_items(argc, argv) /* Create icon, frame, canvas etc.. */
int argc ;
char *argv[] ;
{
unsigned int h, w ; /* Window dimensions. */
int flags ;
int x, y ; /* Window position. */
load_colors() ;
popi_icon = load_icon(icon_image) ;
size.flags = PMinSize | PMaxSize | PPosition | PSize ;
size.x = 0 ;
size.y = 0 ;
size.max_width = size.min_width = size.width = TXsize ;
size.max_height = size.min_height = size.height = TYsize ;
if (strlen(geometry))
{
flags = XParseGeometry(geometry, &x, &y, &w, &h) ;
if (XValue & flags)
{
if (XNegative & flags)
x = DisplayWidth(dpy, screen) + x - size.width ;
size.flags |= USPosition ;
size.x = x ;
}
if (YValue & flags)
{
if (YNegative & flags)
y = DisplayHeight(dpy, screen) + y - size.height ;
size.flags |= USPosition ;
size.y = y ;
}
}
frame = XCreateSimpleWindow(dpy, RootWindow(dpy, screen),
size.x, size.y, size.width, size.height,
POPI_BORDER_WIDTH, foregnd, backgnd) ;
memarea = XCreatePixmap(dpy, frame, size.width, size.height, scr_depth) ;
protocol_atom = XInternAtom(dpy, "WM_PROTOCOLS", False) ;
kill_atom = XInternAtom(dpy, "WM_DELETE_WINDOW", False) ;
XSetStandardProperties(dpy, frame, "popi", NULL, popi_icon,
argv, argc, &size) ;
wm_hints.icon_x = ix ;
wm_hints.icon_y = iy ;
wm_hints.input = True ;
wm_hints.icon_pixmap = popi_icon ;
wm_hints.flags = IconPositionHint | InputHint | IconPixmapHint ;
if (iconic)
{
wm_hints.initial_state = IconicState ;
wm_hints.flags |= StateHint ;
}
XSetWMHints(dpy, frame, &wm_hints) ;
gc_mask = GCFont | GCForeground | GCBackground | GCGraphicsExposures ;
gc_val.font = nfont->fid ;
gc_val.foreground = foregnd ;
gc_val.background = backgnd ;
gc_val.graphics_exposures = False ;
gc = XCreateGC(dpy, RootWindow(dpy, screen), gc_mask, &gc_val) ;
XSetFunction(dpy, gc, GXcopy) ;
pix_gc = DefaultGC(dpy, screen) ;
main_cursor = XCreateFontCursor(dpy, XC_top_left_arrow) ;
busy_cursor = XCreateFontCursor(dpy, XC_watch) ;
}
process_expose(event)
XExposeEvent *event ;
{
int doframe = 0 ;
do
{
if (event->count == 0)
if (event->window == frame) doframe++ ;
}
while (XCheckMaskEvent(dpy, ExposureMask, event)) ;
if (doframe)
{
paint_canvas() ;
XSetFunction(dpy, gc, GXcopy) ;
XCopyArea(dpy, memarea, frame, gc, 0, 100, Xsize, Ysize, 0, 100) ;
}
}
set_cursor(type)
enum cur_type type ;
{
switch (type)
{
case BUSY_CUR : XDefineCursor(dpy, frame, busy_cursor) ;
break ;
case NORMAL_CUR : XDefineCursor(dpy, frame, main_cursor) ;
}
}
start_tool()
{
XSelectInput(dpy, frame, FRAME_MASK) ;
XMapWindow(dpy, frame) ;
}
Funky_Stuff
len=`wc -c < x11.c`
if [ $len != 10182 ] ; then
echo error: x11.c was $len bytes long, should have been 10182
fi
fi # end of overwriting check
if [ -f xview.c ]
then
echo shar: will not over-write existing file xview.c
else
echo shar: extracting 'xview.c', 12966 characters
cat > xview.c <<'Funky_Stuff'
/*LINTLIBRARY*/
/* @(#)xview.c 1.5 91/08/20
*
* XView dependent graphics routines used by popi.
* written by Rich Burridge - Sun Microsystems.
*
* Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
* This version is based on the code in his Prentice Hall book,
* "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
* which is copyright (c) 1988 by Bell Telephone Laboratories, Inc.
*
* Permission is given to distribute these extensions, as long as these
* introductory messages are not removed, and no monies are exchanged.
*
* No responsibility is taken for any errors or inaccuracies inherent
* either to the comments or the code of this program, but if reported
* (see README file) then an attempt will be made to fix them.
*/
#include "popi.h"
#include <xview/xview.h>
#include <xview/canvas.h>
#include <xview/cursor.h>
#include <xview/panel.h>
#include <xview/svrimage.h>
#include <xview/tty.h>
#include <xview/termsw.h>
#include <xview/xv_xrect.h>
#include <X11/Xlib.h>
#define DUP2 (void) dup2
#define SIGNAL (void) signal
#define NOTIFY_DISPATCH (void) notify_dispatch
#define NOTIFY_DO_DISPATCH (void) notify_do_dispatch
#define NOTIFY_INTERPOSE_DESTROY_FUNC (void) notify_interpose_destroy_func
#define XV_SET (void) xv_set
Canvas canvas ;
Canvas_paint_window cpw ;
Frame cframe, tframe ;
Icon popi_icon ;
Notify_value destroy_proc() ;
Panel panel ;
Panel_item slider ;
Server_image busy_cursor_pr, icon_pr ;
Tty ttysw ;
Xv_Cursor busy_cursor, main_cursor ;
Display *dpy ; /* Display id of popi frame. */
Drawable xid ; /* Xid for popi canvas. */
GC gc ; /* Graphics context for text and lines. */
GC pix_gc ; /* Graphics context for rops. */
Pixmap memarea, mpr ;
Window root ;
XColor ccol ;
XGCValues gc_val ; /* Used to setup graphics context values. */
int gc_flags ; /* Used to set up graphics context flags. */
int screen ; /* Default graphics display screen. */
unsigned int scr_depth ;
unsigned long backgnd ; /* Default background color. */
unsigned long foregnd ; /* Default foreground color. */
unsigned long gc_mask ; /* Mask for setting graphic context values. */
unsigned long palette[CMAPLEN] ;
static unsigned short busy_cursor_array[] = {
#include <images/hglass.cursor>
} ;
static unsigned short icon_image[] = {
#include "popi.icon"
} ;
extern int errno ;
extern char *sys_errlist[] ;
char ttybuf[MAXLINE] ; /* Input from user in ttysw window. */
unsigned char *mptr ; /* Pointer to scanline data. */
int iscolor ; /* Set if this is a color screen. */
int opercent = -1 ; /* Previous display percent done value. */
int tbufptr ; /* Current pointer into ttybuf. */
/*ARGSUSED*/
static void
canvas_repaint(canvas, window, display, xid, xrects)
Canvas canvas ;
Xv_Window window ;
Display *display ;
Xv_Window xid ;
Xv_xrectlist *xrects ;
{
XCopyArea(dpy, memarea, xid, gc, 0, 0, Xsize, Ysize, 0, 00) ;
}
/* These are the exportable routines used by the popi program.
*
* disp_init(argc, argv) - called from main at the start.
* disp_finish() - called from main prior to exit.
* disp_imgstart() - called prior to drawing an image.
* disp_imgend() - called after drawing an image.
* disp_putline(lines, y) - to draw an image scanline triple.
* disp_getchar() - to get the next character typed.
* disp_prompt() - display popi prompt and clear input buffer.
* disp_error(errtype, pos) - display error message.
* disp_percentdone(n) - display percentage value of conversion.
*/
void
disp_init(argc, argv) /* Called from main at the start. */
int argc ;
char *argv[] ;
{
char title[MAXLINE] ; /* Used to constructure window title lines. */
int cht ; /* Height of the popi term window. */
int cx ; /* X position of the popi term window. */
int cy ; /* Y position of the popi term window. */
int ttyfd ; /* File descriptor for tty subwindow. */
STRCPY(ttybuf, "") ; /* Zeroise tty input buffer. */
tbufptr = 0 ; /* Reset tty buffer pointer. */
xv_init(XV_INIT_ARGS, argc, argv, 0) ;
icon_pr = xv_create(XV_NULL, SERVER_IMAGE,
SERVER_IMAGE_BITS, icon_image,
SERVER_IMAGE_DEPTH, 1,
XV_WIDTH, 64,
XV_HEIGHT, 64,
0) ;
popi_icon = xv_create(XV_NULL, ICON, /* Create icon. */
ICON_IMAGE, icon_pr,
0) ;
SPRINTF(title, "%s commands", ProgName) ;
tframe = xv_create(XV_NULL, FRAME, /* Create tty frame. */
FRAME_ICON, popi_icon,
WIN_ROWS, 10,
WIN_COLUMNS, 80,
FRAME_LABEL, title,
0) ;
ttysw = xv_create(tframe, TERMSW,
TTY_ARGV, TTY_ARGV_DO_NOT_FORK,
0) ;
XV_SET(ttysw, TERMSW_MODE, TERMSW_MODE_TYPE, 0) ;
cx = (int) xv_get(tframe, XV_X) ;
cy = (int) xv_get(tframe, XV_Y) ;
cht = (int) xv_get(tframe, XV_HEIGHT) ;
SPRINTF(title, "%s image canvas", ProgName) ;
cframe = xv_create(XV_NULL, FRAME, /* Create canvas frame. */
XV_X, cx,
XV_Y, cy + cht + 10,
FRAME_LABEL, title,
FRAME_SHOW_LABEL, TRUE,
0) ;
panel = xv_create(cframe, PANEL, /* Create panel for slider. */
XV_X, 0,
XV_Y, 0,
XV_SHOW, FALSE,
0) ;
slider = xv_create(panel, PANEL_SLIDER,
PANEL_LABEL_STRING, "% done",
PANEL_MIN_VALUE, 0,
PANEL_MAX_VALUE, 100,
0) ;
canvas = window_create(cframe, CANVAS, /* Create canvas. */
XV_X, 0,
XV_Y, 0,
XV_WIDTH, Xsize,
XV_HEIGHT, Ysize,
CANVAS_X_PAINT_WINDOW, TRUE,
CANVAS_REPAINT_PROC, canvas_repaint,
CANVAS_RETAINED, FALSE,
0) ;
cpw = canvas_paint_window(canvas) ;
window_fit(cframe) ;
dpy = (Display *) xv_get(cframe, XV_DISPLAY, NULL) ;
xid = (Drawable) xv_get(cpw, XV_XID, NULL) ;
screen = DefaultScreen(dpy) ;
root = RootWindow(dpy, screen) ;
foregnd = BlackPixel(dpy, screen) ;
backgnd = WhitePixel(dpy, screen) ;
scr_depth = DefaultDepth(dpy, screen) ;
gc_mask = GCForeground | GCBackground | GCGraphicsExposures ;
gc_val.foreground = foregnd ;
gc_val.background = backgnd ;
gc_val.graphics_exposures = False ;
gc = XCreateGC(dpy, root, gc_mask, &gc_val) ;
pix_gc = DefaultGC(dpy, screen) ;
memarea = XCreatePixmap(dpy, xid, Xsize, Ysize, scr_depth) ;
SIGNAL(SIGHUP, SIG_IGN) ;
ttyfd = (int) xv_get(ttysw, TTY_TTY_FD) ;
DUP2(ttyfd, 0) ;
DUP2(ttyfd, 1) ;
DUP2(ttyfd, 2) ;
main_cursor = xv_get(canvas, WIN_CURSOR) ;
busy_cursor_pr = xv_create(XV_NULL, SERVER_IMAGE,
XV_WIDTH, 16,
XV_HEIGHT, 16,
SERVER_IMAGE_BITS, busy_cursor_array,
0) ;
busy_cursor = xv_create(XV_NULL, CURSOR,
CURSOR_IMAGE, busy_cursor_pr,
0) ;
load_colors() ; /* Load the popi grayscale colormap. */
NOTIFY_INTERPOSE_DESTROY_FUNC(cframe, destroy_proc) ;
NOTIFY_INTERPOSE_DESTROY_FUNC(tframe, destroy_proc) ;
XV_SET(tframe, XV_SHOW, TRUE, 0) ;
XV_SET(cframe, XV_SHOW, TRUE, 0) ;
NOTIFY_DISPATCH() ; /* Make the windows appear. */
NOTIFY_DO_DISPATCH() ;
init_dither() ; /* Initialise dither arrays and variables. */
}
void
disp_finish() /* Called from main prior to exit - null routine. */
{}
void
disp_imgstart() /* Called prior to drawing an image. */
{
XV_SET(cframe, WIN_SHOW, TRUE, 0) ;
XClearWindow(dpy, xid) ;
XV_SET(panel, WIN_SHOW, FALSE, 0) ;
NOTIFY_DISPATCH() ;
}
void
disp_imgend() /* Called after drawing an image. */
{}
void
disp_putline(lines, y) /* Draw an image scanline. */
unsigned char **lines ;
int y ;
{
XImage *image ;
int color, i, j, len ;
unsigned char *line, tmp ;
if (scr_depth == 32) len = Xsize * 4 ;
else if (scr_depth == 8) len = Xsize ;
else len = (Xsize / 8) + 1 ;
mptr = (unsigned char *) Emalloc(len) ;
if (scr_depth == 32)
{
if (colors == 1)
for (i = j = 0; i < Xsize; i++)
{
tmp = lines[0][i] ;
mptr[j++] = 0 ; /* X */
mptr[j++] = tmp ; /* B */
mptr[j++] = tmp ; /* G */
mptr[j++] = tmp ; /* R */
}
else
for (i = j = 0; i < Xsize; i++)
{
mptr[j++] = 0 ; /* X */
for (color = 2; color >= 0; color--)
mptr[j++] = lines[color][i] ; /* G, B, R */
}
}
else if (scr_depth == 8)
{
line = ntsc_luma(lines) ;
for (i = 0; i < len; i++) mptr[i] = 255 - line[i] ;
}
else
{
line = ntsc_luma(lines) ;
halftone(line, y) ;
}
image = XCreateImage(dpy, DefaultVisual(dpy, screen),
scr_depth,
(scr_depth > 1) ? ZPixmap : XYPixmap,
0, mptr, Xsize, 1, 8, len) ;
XPutImage(dpy, memarea, pix_gc, image, 0, 0, 0, y,
(unsigned) image->width, (unsigned) image->height) ;
XDestroyImage(image) ;
XSetFunction(dpy, gc, GXcopy) ;
XCopyArea(dpy, memarea, xid, gc, 0, y, Xsize, 1, 0, y) ;
FREE(mptr) ;
NOTIFY_DISPATCH() ;
}
disp_getchar() /* Get next user typed character. */
{
int c ;
if (!tbufptr) (void) gets(ttybuf) ; /* If buffer empty, get next line. */
c = ttybuf[tbufptr++] ;
if (c == '\0') /* Is it end of input buffer? */
{
c = '\n' ;
tbufptr = 0 ; /* Reset to force another read. */
set_cursor(BUSY_CUR) ; /* We will now get busy! */
}
return c ;
}
disp_prompt() /* Display popi prompt and clear input line. */
{
char *prompt = "\r-> " ;
set_cursor(NORMAL_CUR) ;
PRINTF(prompt) ;
FFLUSH(stdout) ;
return(sizeof prompt - 1) ;
}
void
disp_error(errtype, pos) /* Display error message. */
int errtype ;
int pos ;
{
int i ;
if (errtype & ERR_PARSE)
{
for (i = 1; i < pos; ++i) PUTC('-', stderr) ;
PUTC('^', stderr) ;
PUTC('\n', stderr) ;
}
FPRINTF(stderr, "%s\n", ErrBuf) ;
/* We assume errno hasn't been reset by the preceding output */
if (errtype & ERR_SYS)
FPRINTF(stderr, "\t(%s)\n", sys_errlist[errno]) ;
FFLUSH(stderr) ;
}
void
disp_percentdone(percent)
int percent ;
{
if (percent == opercent) return ; /* Same as last time? */
XV_SET(slider, PANEL_VALUE, percent, 0) ;
if (!percent) XV_SET(panel, WIN_SHOW, TRUE, 0) ;
opercent = percent ;
NOTIFY_DISPATCH() ;
}
/*ARGSUSED*/
Notify_value
destroy_proc(client, status)
Notify_client client ;
Destroy_status status ;
{
exit(0) ;
}
load_colors() /* Create and load popi color map. */
{
u_char red[CMAPLEN], green[CMAPLEN], blue[CMAPLEN] ;
int i, numcolors ;
iscolor = 0 ;
if (DisplayCells(dpy, screen) > 2)
{
ccol.flags = DoRed | DoGreen | DoBlue ;
iscolor = 1 ;
numcolors = 0 ;
for (i = 0; i < CMAPLEN; i++)
{
ccol.red = ccol.green =
ccol.blue = (unsigned short) ((255 - i) << 8) ;
if (XAllocColor(dpy, DefaultColormap(dpy, screen), &ccol) == True)
palette[numcolors++] = ccol.pixel ;
}
if (numcolors < 2)
{
iscolor = 0 ;
FPRINTF(stderr, "%s: cannot allocate colors.\n", ProgName) ;
return ;
}
}
}
set_cursor(type)
enum cur_type type ;
{
switch (type)
{
case BUSY_CUR : XV_SET(canvas, WIN_CURSOR, busy_cursor, 0) ;
break ;
case NORMAL_CUR: XV_SET(canvas, WIN_CURSOR, main_cursor, 0) ;
}
}
Funky_Stuff
len=`wc -c < xview.c`
if [ $len != 12966 ] ; then
echo error: xview.c was $len bytes long, should have been 12966
fi
fi # end of overwriting check
exit 0 # Just in case...