--- ray/src/px/x11image.c 1999/07/20 14:07:38 2.55 +++ ray/src/px/x11image.c 2003/07/07 17:21:51 2.62 @@ -1,9 +1,6 @@ -/* Copyright (c) 1999 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id"; #endif - /* * x11image.c - driver for X-windows * @@ -21,20 +18,18 @@ static char SCCSid[] = "$SunId$ SGI"; #include "standard.h" +#include #include #include #include #include #include -#undef NOPROTO -#define NOPROTO 1 #include "color.h" #include "tonemap.h" #include "view.h" #include "x11raster.h" #include "random.h" -#include "resolu.h" #define FONTNAME "8x13" /* text font we'll use */ @@ -109,7 +104,7 @@ unsigned char *ourdata; /* our image data */ struct { int xmin, ymin, xsiz, ysiz; -} box = {0, 0, 0, 0}; /* current box */ +} bbox = {0, 0, 0, 0}; /* current bbox */ char *geometry = NULL; /* geometry specification */ @@ -131,7 +126,7 @@ Atom closedownAtom, wmProtocolsAtom; int sigrecv; -int onsig() { sigrecv++; } +void onsig(int i) { sigrecv++; } main(argc, argv) @@ -543,7 +538,7 @@ getras() /* get raster file */ goto fail; getmono(); } else if (ourvis.class == TrueColor | ourvis.class == DirectColor) { - int datsiz = ourvis.depth>16 ? sizeof(int4) : sizeof(int2); + int datsiz = ourvis.depth>16 ? sizeof(int32) : sizeof(int16); ourdata = (unsigned char *)malloc(datsiz*xmax*ymax); if (ourdata == NULL) goto fail; @@ -631,14 +626,13 @@ getevent() /* process the next event */ traceray(xpos, ypos) /* print requested pixel data */ int xpos, ypos; { - extern char *index(); - FLOAT hv[2]; + RREAL hv[2]; FVECT rorg, rdir; COLOR cval; register char *cp; - box.xmin = xpos; box.xsiz = 1; - box.ymin = ypos; box.ysiz = 1; + bbox.xmin = xpos; bbox.xsiz = 1; + bbox.ymin = ypos; bbox.ysiz = 1; avgbox(cval); scalecolor(cval, 1./exposure); pix2loc(hv, &inpres, xpos-xoff, ypos-yoff); @@ -680,7 +674,7 @@ XKeyPressedEvent *ekey; XColor cvx; int com, n; double comp; - FLOAT hv[2]; + RREAL hv[2]; n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL); if (n == 0) @@ -703,7 +697,7 @@ XKeyPressedEvent *ekey; sprintf(buf, "%.3f", intens(cval)/exposure); break; case 'l': /* luminance */ - sprintf(buf, "%.0fL", luminance(cval)/exposure); + sprintf(buf, "%.1fL", luminance(cval)/exposure); break; case 'c': /* color */ comp = pow(2.0, (double)scale); @@ -714,7 +708,7 @@ XKeyPressedEvent *ekey; break; } XDrawImageString(thedisplay, wind, ourgc, - box.xmin, box.ymin+box.ysiz, buf, strlen(buf)); + bbox.xmin, bbox.ymin+bbox.ysiz, buf, strlen(buf)); return(0); case 'i': /* identify (contour) */ if (ourras->pixels == NULL) @@ -776,9 +770,9 @@ XKeyPressedEvent *ekey; sprintf(buf, "%+d", scale); remap: XDrawImageString(thedisplay, wind, ourgc, - box.xmin, box.ymin+box.ysiz, buf, strlen(buf)); + bbox.xmin, bbox.ymin+bbox.ysiz, buf, strlen(buf)); XFlush(thedisplay); - free(ourdata); + /* free(ourdata); This is done in XDestroyImage()! */ free_raster(ourras); getras(); /* fall through */ @@ -807,7 +801,7 @@ XKeyPressedEvent *ekey; redraw(0, 0, width, height); return(0); case ' ': /* clear */ - redraw(box.xmin, box.ymin, box.xsiz, box.ysiz); + redraw(bbox.xmin, bbox.ymin, bbox.xsiz, bbox.ysiz); return(0); default: XBell(thedisplay, 0); @@ -841,30 +835,30 @@ XButtonPressedEvent *ebut; } -getbox(ebut) /* get new box */ +getbox(ebut) /* get new bbox */ XButtonPressedEvent *ebut; { XEvent e; XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e); while (e.type == MotionNotify) { - revbox(ebut->x, ebut->y, box.xmin = e.xmotion.x, box.ymin = e.xmotion.y); + revbox(ebut->x, ebut->y, bbox.xmin = e.xmotion.x, bbox.ymin = e.xmotion.y); XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e); - revbox(ebut->x, ebut->y, box.xmin, box.ymin); + revbox(ebut->x, ebut->y, bbox.xmin, bbox.ymin); } - box.xmin = e.xbutton.x<0 ? 0 : (e.xbutton.x>=width ? width-1 : e.xbutton.x); - box.ymin = e.xbutton.y<0 ? 0 : (e.xbutton.y>=height ? height-1 : e.xbutton.y); - if (box.xmin > ebut->x) { - box.xsiz = box.xmin - ebut->x + 1; - box.xmin = ebut->x; + bbox.xmin = e.xbutton.x<0 ? 0 : (e.xbutton.x>=width ? width-1 : e.xbutton.x); + bbox.ymin = e.xbutton.y<0 ? 0 : (e.xbutton.y>=height ? height-1 : e.xbutton.y); + if (bbox.xmin > ebut->x) { + bbox.xsiz = bbox.xmin - ebut->x + 1; + bbox.xmin = ebut->x; } else { - box.xsiz = ebut->x - box.xmin + 1; + bbox.xsiz = ebut->x - bbox.xmin + 1; } - if (box.ymin > ebut->y) { - box.ysiz = box.ymin - ebut->y + 1; - box.ymin = ebut->y; + if (bbox.ymin > ebut->y) { + bbox.ysiz = bbox.ymin - ebut->y + 1; + bbox.ymin = ebut->y; } else { - box.ysiz = ebut->y - box.ymin + 1; + bbox.ysiz = ebut->y - bbox.ymin + 1; } } @@ -888,7 +882,7 @@ XButtonPressedEvent *ebut; } -revbox(x0, y0, x1, y1) /* draw box with reversed lines */ +revbox(x0, y0, x1, y1) /* draw bbox with reversed lines */ int x0, y0, x1, y1; { revline(x0, y0, x1, y0); @@ -898,7 +892,7 @@ int x0, y0, x1, y1; } -int +void colavg(scn, n, cavg) register COLR *scn; register int n; @@ -907,14 +901,14 @@ COLOR cavg; COLOR col; while (n--) { - colr_color(col, scn++); + colr_color(col, *scn++); addcolor(cavg, col); } } int -avgbox(cavg) /* average color over current box */ +avgbox(cavg) /* average color over current bbox */ COLOR cavg; { double d; @@ -931,23 +925,23 @@ COLOR cavg; int -dobox(f, p) /* run function over box */ -int (*f)(); /* function to call for each subscan */ +dobox(f, p) /* run function over bbox */ +void (*f)(); /* function to call for each subscan */ char *p; /* pointer to private data */ { int left, right, top, bottom; int y; - left = box.xmin - xoff; - right = left + box.xsiz; + left = bbox.xmin - xoff; + right = left + bbox.xsiz; if (left < 0) left = 0; if (right > xmax) right = xmax; if (left >= right) return(0); - top = box.ymin - yoff; - bottom = top + box.ysiz; + top = bbox.ymin - yoff; + bottom = top + bbox.ysiz; if (top < 0) top = 0; if (bottom > ymax) @@ -963,7 +957,7 @@ char *p; /* pointer to private data */ } -int +void addfix(scn, n) /* add fixation points to histogram */ COLR *scn; int n; @@ -1100,7 +1094,7 @@ getmono() /* get monochrome data */ cerr[x] = err + errp; } } - free((char *)cerr); + free((void *)cerr); } @@ -1143,7 +1137,7 @@ COLR *scan; errp = err; ti = x*xmax/iconwidth; copycolr(clr, scan[ti]); - normcolrs(clr, 1, scale); + normcolrs(&clr, 1, scale); err += normbright(clr) + cerr[x]; if (err > 127) err -= 255; @@ -1159,14 +1153,14 @@ COLR *scan; getfull() /* get full (24-bit) data */ { int y; - register unsigned int4 *dp; - register unsigned int2 *dph; + register uint32 *dp; + register uint16 *dph; register int x; /* initialize tone mapping */ make_tonemap(); /* read and convert file */ - dp = (unsigned int4 *)ourdata; - dph = (unsigned int2 *)ourdata; + dp = (uint32 *)ourdata; + dph = (uint16 *)ourdata; for (y = 0; y < ymax; y++) { getscan(y); add2icon(y, scanline); @@ -1174,15 +1168,15 @@ getfull() /* get full (24-bit) data */ switch (ourras->image->blue_mask) { case 0xff: /* 24-bit RGB */ for (x = 0; x < xmax; x++) - *dp++ = (unsigned int4)scanline[x][RED] << 16 | - (unsigned int4)scanline[x][GRN] << 8 | - (unsigned int4)scanline[x][BLU] ; + *dp++ = (uint32)scanline[x][RED] << 16 | + (uint32)scanline[x][GRN] << 8 | + (uint32)scanline[x][BLU] ; break; case 0xff0000: /* 24-bit BGR */ for (x = 0; x < xmax; x++) - *dp++ = (unsigned int4)scanline[x][RED] | - (unsigned int4)scanline[x][GRN] << 8 | - (unsigned int4)scanline[x][BLU] << 16 ; + *dp++ = (uint32)scanline[x][RED] | + (uint32)scanline[x][GRN] << 8 | + (uint32)scanline[x][BLU] << 16 ; break; #if 0 case 0x1f: /* 15-bit RGB */ @@ -1238,7 +1232,7 @@ getgrey() /* get greyscale data */ tmap_colrs(scanline, xmax); if (maxcolors < 256) for (x = 0; x < xmax; x++) - *dp++ = ((int4)scanline[x][GRN] * + *dp++ = ((int32)scanline[x][GRN] * maxcolors + maxcolors/2) >> 8; else for (x = 0; x < xmax; x++) @@ -1246,7 +1240,7 @@ getgrey() /* get greyscale data */ } for (x = 0; x < maxcolors; x++) clrtab[x][RED] = clrtab[x][GRN] = - clrtab[x][BLU] = ((int4)x*256 + 128)/maxcolors; + clrtab[x][BLU] = ((int32)x*256 + 128)/maxcolors; } @@ -1259,7 +1253,7 @@ getmapped() /* get color-mapped data */ /* initialize tone mapping */ make_tonemap(); /* make histogram */ - if (new_histo((int4)xmax*ymax) == -1) + if (new_histo((int32)xmax*ymax) == -1) quiterr("cannot initialize histogram"); for (y = 0; y < ymax; y++) { if (getscan(y) < 0) @@ -1316,7 +1310,7 @@ int y; static int trunced = -1; /* truncated file? */ skipit: if (trunced >= 0 && y >= trunced) { - bzero(scanline, xmax*sizeof(COLR)); + memset(scanline, '\0', xmax*sizeof(COLR)); return(-1); } if (y != cury) {