|
|
1.1 ! root 1: /* Program to display images on uVax II/GPX under the X window system. ! 2: * ! 3: * Bill Wyatt and Jim Gettys, Feb. 12 1986 et. seq. ! 4: * ! 5: * 4/23/86 WFW ! 6: * Added FITS file reading capability, selected via -fits option. ! 7: * ! 8: * 7/86 WFW ! 9: * Added disk fits format via -dfits option, for not swapping bytes, ! 10: * but file otherwise in disk format. ! 11: * ! 12: * 7/86 WFW ! 13: * Added palette subwindow, zoomx4 window, independently resizeable. ! 14: * ! 15: * 8/11/86 WFW ! 16: * If the palette window needs to be independent instead of a subwindow, ! 17: * then compile with PALWIND defined. ! 18: * ! 19: * 8/13/86 WFW ! 20: * Added ifdef support from Eric Mandel for ROSAT & Einstein images ! 21: */ ! 22: ! 23: #include <stdio.h> ! 24: #include <sys/file.h> ! 25: #include <X/Xlib.h> ! 26: #include <X/XMenu.h> ! 27: #include <X/Xkeyboard.h> ! 28: ! 29: #ifdef MC68000 ! 30: #include <sys/types.h> ! 31: #endif ! 32: ! 33: #include "show.icon.ic" ! 34: ! 35: #include "shimg.h" ! 36: #include "shopt.h" ! 37: ! 38: #define TESTDEFAULT "=512x512+100+134" ! 39: #define PICTDEFAULT "+50+100" ! 40: #define TESTNROWS 512 ! 41: ! 42: #define MIN(a,b) (((a) < (b)) ? (a) : (b)) ! 43: #define MAX(a,b) (((a) > (b)) ? (a) : (b)) ! 44: ! 45: main(argc, argv) ! 46: int argc; ! 47: char **argv; ! 48: { ! 49: struct windmain maininfo; ! 50: struct colorwind colorinfo; ! 51: struct imagewind imageinfo; ! 52: ! 53: Window wind, subwind, palwind, wzoom; ! 54: Window iconwindow, iconwzoom; ! 55: #ifdef PALWIND ! 56: Window iconpalwind; /* palette window is independent, needs icon */ ! 57: #endif ! 58: WindowInfo winfo, palwinfo, wzoominfo; ! 59: ! 60: ! 61: Cursor imcursor, pancursor, printcursor, zoom2cursor, zoom4cursor; ! 62: Cursor palcursor; ! 63: int xcenter = -1; ! 64: int ycenter = -1; /* nominal center of displayed image */ ! 65: int xtempzero, ytempzero; ! 66: int xzoomsize = 124, yzoomsize = 124; ! 67: XMenu *showmenu, *menusetup(); ! 68: int XMenuSetFreeze(), XMenuActivate(); ! 69: int *currentflags; ! 70: int pane = 0, sel = 0; ! 71: int lastpane = 0, lastsel = 0; ! 72: unsigned char palette[2048]; /* palette window array */ ! 73: short *readheader(), *readpict(); ! 74: int scalepict(); ! 75: int zoomfactor = 0; /* replication factor for pixel display */ ! 76: int oldzoomfactor = 0; ! 77: int fd, open(), close(), ipow(); ! 78: int w_mapped = 1; ! 79: int rshift = 0; ! 80: int keycode = 0; ! 81: int xbut, ybut; ! 82: char *malloc(); ! 83: char *keystring; ! 84: int j, k, l; ! 85: ! 86: XEvent event, peekevent; ! 87: XExposeEvent *expw = (XExposeEvent *)&event; ! 88: register XKeyOrButtonEvent *but = (XButtonEvent *)&event; ! 89: register XMouseMovedEvent *mouse = (XMouseMovedEvent *)&event; ! 90: ! 91: register int downbutton = -1; /* mouse button flag */ ! 92: register int xzero, yzero; /* image coordinates of window(0,0) */ ! 93: register int i; ! 94: ! 95: ! 96: /* **** MAIN EXECUTION CODE STARTS HERE **** */ ! 97: ! 98: maininfo.display = NULL; ! 99: colorinfo.nplanes = -1; ! 100: imageinfo.pmin = 70000; ! 101: imageinfo.pmax = -3000; ! 102: imageinfo.headskip = 0; ! 103: imageinfo.calibration = 0; ! 104: imageinfo.fitsflag = 0; ! 105: ! 106: #ifdef XRAY ! 107: imageinfo.ein = 0; ! 108: imageinfo.ros = 0; ! 109: #endif ! 110: ! 111: imageinfo.VOP_Flags = VOP_GrayScale | VOP_Initialize; ! 112: imageinfo.SOP_Flags = SOP_Linear; ! 113: imageinfo.COP_Flags = 0; ! 114: imageinfo.FOP_Flags = 0; ! 115: ! 116: shgetopt(argc, argv, &maininfo, &colorinfo, &imageinfo); ! 117: ! 118: /* create the cursors */ ! 119: make_cursors(&imcursor,&pancursor,&printcursor, ! 120: &zoom2cursor, &zoom4cursor, &palcursor); ! 121: ! 122: /* try for 8 planes (probably only gets 6) */ ! 123: if (colorinfo.nplanes < 0) ! 124: colorinfo.nplanes = MAX(DisplayPlanes()-4,8); ! 125: ! 126: /* iterate until cells allocated. Check if enough */ ! 127: if (XGetColorCells(1, 1, colorinfo.nplanes, ! 128: &colorinfo.planes, &(colorinfo.pixels[0])) == 0) ! 129: { ! 130: while(--colorinfo.nplanes > 2) ! 131: if(XGetColorCells(1,1,colorinfo.nplanes, ! 132: &colorinfo.planes, ! 133: &(colorinfo.pixels[0])) != 0) break; ! 134: if(colorinfo.nplanes <= 2) { ! 135: fprintf(stderr,"Insufficient color planes resource!\n"); ! 136: exit(1); ! 137: } ! 138: if(colorinfo.nplanes < 6) ! 139: fprintf(stderr, "Allocated %d planes\n",colorinfo.nplanes); ! 140: } ! 141: ! 142: colorinfo.ncolors = ipow(2, colorinfo.nplanes); ! 143: ! 144: /* figure out how many bits we have to left shift the pixels */ ! 145: colorinfo.shift = 0; ! 146: i = colorinfo.pixels[0] | colorinfo.planes; ! 147: while (((i >>= 1) & 1) == 0) colorinfo.shift++; ! 148: ! 149: /* get the menu selections ready */ ! 150: showmenu = menusetup(argv[0]); ! 151: ! 152: if(imageinfo.calibration) { /** GENERATE TEST SCREEN */ ! 153: imageinfo.ncols = imageinfo.nrows = TESTNROWS; ! 154: rshift = DisplayPlanes() - colorinfo.nplanes - colorinfo.shift; ! 155: if((imageinfo.image = ! 156: (unsigned char *)malloc(imageinfo.nrows*imageinfo.ncols)) ! 157: == NULL) { ! 158: fprintf(stderr,"Can't allocate test image!\n"); ! 159: exit(1); ! 160: } ! 161: for (j = 0; j < imageinfo.nrows; j++) ! 162: for (i = 0; i < imageinfo.ncols; i++) ! 163: *(imageinfo.image + j*imageinfo.ncols + i) = ! 164: ((((i + j)&255) >> rshift) & colorinfo.planes) ! 165: + colorinfo.pixels[0]; ! 166: ! 167: wind = XCreate(argv[0], argv[0], ! 168: maininfo.geometry, TESTDEFAULT, &maininfo.frame, ! 169: 100, 134); ! 170: } ! 171: else { /** READ IN IMAGE **/ ! 172: ! 173: #ifdef XRAY ! 174: /* code and conditional added by egm */ ! 175: ! 176: if( imageinfo.ein == 1 ){ ! 177: eimgopen(imageinfo.ict, imageinfo.filename); ! 178: } ! 179: else if( imageinfo.ros == 1 ){ ! 180: strcpy(imageinfo.poename, imageinfo.filename); ! 181: strcat(imageinfo.poename, ".poe"); ! 182: strcpy(imageinfo.hdrname, imageinfo.filename); ! 183: strcat(imageinfo.hdrname, ".hdr"); ! 184: openpoe(imageinfo.muthict, imageinfo.poename, imageinfo.hdrname); ! 185: } ! 186: else { ! 187: #endif ! 188: ! 189: if((fd = open(imageinfo.filename,O_RDONLY,0)) < 0) { ! 190: fprintf(stderr,"Error opening file %s\n",imageinfo.filename); ! 191: exit(1); ! 192: } ! 193: if((imageinfo.header = ! 194: readheader(fd,imageinfo.headskip, ! 195: &imageinfo.nrows,&imageinfo.ncols, ! 196: imageinfo.fitsflag)) ! 197: == NULL) { ! 198: fprintf(stderr,"Error reading header of file %s\n", ! 199: imageinfo.filename); ! 200: exit(1); ! 201: } ! 202: ! 203: #ifdef PALWIND ! 204: sprintf(maininfo.filegeometry,"=%dx%d%s",imageinfo.ncols, ! 205: imageinfo.nrows, PICTDEFAULT); ! 206: #else ! 207: sprintf(maininfo.filegeometry,"=%dx%d%s",imageinfo.ncols, ! 208: imageinfo.nrows+PALHEIGHT+2*PALBORDER, PICTDEFAULT); ! 209: #endif ! 210: ! 211: #ifdef XRAY ! 212: } /* end of conditional code added by egm */ ! 213: #endif ! 214: ! 215: if((imageinfo.image = ! 216: (unsigned char *)malloc(imageinfo.nrows*imageinfo.ncols)) ! 217: == NULL) { ! 218: fprintf(stderr,"Can't allocate byte image?\n"); ! 219: exit(1); ! 220: } ! 221: ! 222: #ifdef XRAY ! 223: /* conditional added by egm */ ! 224: ! 225: if( imageinfo.ein == 1 ) { /* Einstein XRAY image */ ! 226: if((imageinfo.picture = ! 227: (short *)malloc(imageinfo.nrows*imageinfo.ncols*2)) == NULL) { ! 228: fprintf(stderr,"Can't allocate xray image?\n"); ! 229: exit(1); ! 230: } ! 231: eimgread(imageinfo.ict,imageinfo.picture, ! 232: imageinfo.ncols, imageinfo.nrows, ! 233: imageinfo.iy, imageinfo.iz, ! 234: imageinfo.zoom,imageinfo.zoom, imageinfo.energy); ! 235: } ! 236: else if( imageinfo.ros == 1) { /* ROSAT XRAY image */ ! 237: selectcenter(imageinfo.muthict, imageinfo.iy, imageinfo.iz); ! 238: selectres(imageinfo.muthict, imageinfo.zoom, imageinfo.zoom); ! 239: if((imageinfo.picture = ! 240: (short *)malloc(imageinfo.nrows*imageinfo.ncols*2)) == NULL) { ! 241: fprintf(stderr,"Can't allocate xray image?\n"); ! 242: exit(1); ! 243: } ! 244: readpoe(imageinfo.muthict, imageinfo.picture, ! 245: imageinfo.ncols, imageinfo.nrows); ! 246: } ! 247: else { ! 248: #endif ! 249: /* SAOCCD or FITS image */ ! 250: if((imageinfo.picture = ! 251: readpict(fd,imageinfo.nrows,imageinfo.ncols, ! 252: imageinfo.fitsflag)) == NULL) { ! 253: fprintf(stderr,"Error reading file %s\n",imageinfo.filename); ! 254: exit(1); ! 255: } ! 256: close(fd); ! 257: ! 258: #ifdef XRAY ! 259: } /* end of conditional added by egm */ ! 260: #endif ! 261: ! 262: if(imageinfo.pmin == 70000 && imageinfo.pmax == -3000) ! 263: maxminpict(imageinfo.picture, imageinfo.nrows, imageinfo.ncols, ! 264: &imageinfo.pmax, &imageinfo.pmin); ! 265: scalepict(imageinfo.image, imageinfo.picture, ! 266: imageinfo.pmax, imageinfo.pmin, ! 267: colorinfo.ncolors, colorinfo.pixels[0], colorinfo.shift, ! 268: imageinfo.nrows, imageinfo.ncols, imageinfo.SOP_Flags); ! 269: wind = XCreate(argv[0], argv[0], ! 270: maininfo.geometry, maininfo.filegeometry, ! 271: &maininfo.frame, 100, 100); ! 272: } ! 273: if (wind == 0) { ! 274: fprintf(stderr, "XCreate on root failed\n"); ! 275: exit(1); ! 276: } ! 277: ! 278: /* get current info so as to be ready for subwindow placing */ ! 279: XQueryWindow(wind, &winfo); ! 280: ! 281: if((iconwindow = ! 282: XCreateWindow(RootWindow, 0, 0, ! 283: show_width, show_height, 0, 0, 0)) == 0) ! 284: { ! 285: fprintf(stderr, "XCreateWindow on iconwindow failed\n"); ! 286: exit(1); ! 287: } ! 288: XSetIconWindow(wind, iconwindow); ! 289: ! 290: #ifdef PALWIND ! 291: if((palwind = XCreateWindow(RootWindow, winfo.x, ! 292: winfo.y+winfo.height, ! 293: winfo.width, ! 294: PALHEIGHT, border_width, ! 295: maininfo.frame.border, BlackPixmap)) ! 296: == 0) { ! 297: fprintf(stderr, "XCreateWindow on palwind failed\n"); ! 298: exit(1); ! 299: } ! 300: XStoreName(palwind, argv[0]); ! 301: #else ! 302: if((palwind = XCreateWindow(wind, 0, ! 303: winfo.height-PALHEIGHT-2*PALBORDER, ! 304: winfo.width-2*PALBORDER, ! 305: PALHEIGHT, PALBORDER, ! 306: WhitePixmap, BlackPixmap)) == 0) { ! 307: fprintf(stderr, "XCreateWindow on palwind failed\n"); ! 308: exit(1); ! 309: } ! 310: #endif ! 311: if((wzoom = XCreateWindow(RootWindow, ! 312: winfo.x+winfo.width+ ! 313: maininfo.frame.bdrwidth, ! 314: winfo.y, ! 315: xzoomsize, yzoomsize, ! 316: maininfo.frame.bdrwidth, ! 317: maininfo.frame.border, BlackPixmap)) == 0) ! 318: { ! 319: fprintf(stderr, "XCreateWindow on wzoom failed\n"); ! 320: exit(1); ! 321: } ! 322: XStoreName(wzoom, argv[0]); ! 323: ! 324: if((iconwzoom = XCreateWindow(RootWindow, 0, 0, ! 325: show_width, show_height, 0, 0, 0)) == 0) { ! 326: fprintf(stderr, "XCreateWindow on iconwzoom failed\n"); ! 327: exit(1); ! 328: } ! 329: XSetIconWindow(wzoom, iconwzoom); ! 330: ! 331: #ifdef PALWIND ! 332: if((iconpalwind = XCreateWindow(RootWindow, 0, 0, ! 333: show_width, show_height, 0, 0, 0)) == 0) { ! 334: fprintf(stderr, "XCreateWindow on iconpalwind failed\n"); ! 335: exit(1); ! 336: } ! 337: XSetIconWindow(palwind, iconpalwind); ! 338: #endif ! 339: ! 340: /* define the cursors */ ! 341: XUndefineCursor(wind); ! 342: XDefineCursor(wind,imcursor); ! 343: ! 344: XUndefineCursor(palwind); ! 345: XDefineCursor(palwind,palcursor); ! 346: ! 347: /* assume we display center of image in center of window */ ! 348: if(xcenter < 0) xcenter = imageinfo.ncols>>1; ! 349: if(ycenter < 0) ycenter = imageinfo.nrows>>1; ! 350: ! 351: XSelectInput(wind, ButtonPressed | ButtonReleased | MouseMoved | ! 352: KeyPressed | ! 353: ExposeRegion | ExposeWindow | ExposeCopy | UnmapWindow); ! 354: XSelectInput(iconwindow, ExposeWindow); ! 355: ! 356: XSelectInput(wzoom, ExposeWindow | UnmapWindow); ! 357: XSelectInput(iconwzoom, ExposeWindow); ! 358: ! 359: #ifdef PALWIND ! 360: XSelectInput(palwind, ExposeWindow | UnmapWindow); ! 361: XSelectInput(iconpalwind, ExposeWindow); ! 362: #else ! 363: XSelectInput(palwind, ExposeWindow); ! 364: #endif ! 365: ! 366: XMapWindow(wind); ! 367: XMapWindow(wzoom); ! 368: ! 369: #ifdef PALWIND ! 370: XMapWindow(palwind); ! 371: #else ! 372: XMapSubwindows(wind); ! 373: #endif ! 374: ! 375: XFlush(); ! 376: ! 377: while(1) { ! 378: if(imageinfo.VOP_Flags & VOP_Initialize) { ! 379: initcmap(colorinfo.ncolors,colorinfo.cmap, ! 380: colorinfo.pixels[0],colorinfo.nplanes, ! 381: imageinfo.VOP_Flags); ! 382: XStoreColors(colorinfo.ncolors, colorinfo.cmap); ! 383: imageinfo.VOP_Flags &= ~(VOP_Initialize); ! 384: } ! 385: ! 386: XNextEvent(&event); ! 387: ! 388: #ifdef GLOPEROO ! 389: describe_XEvent(event.type, event.window, but->detail, ! 390: wind, palwind, wzoom); ! 391: #endif ! 392: switch((int)event.type) { ! 393: case KeyPressed: ! 394: ! 395: #ifdef VAX ! 396: keycode = but->detail & 0x00ff; ! 397: if(IsCursorKey(keycode)) { ! 398: XUpdateMouse(wind,&mouse->x,&mouse->y,&subwind); ! 399: i = 1<<zoomfactor; ! 400: if(keycode == KC_CURSOR_UP) mouse->y -= i; ! 401: if(keycode == KC_CURSOR_DOWN) mouse->y += i; ! 402: if(keycode == KC_CURSOR_RIGHT) mouse->x += i; ! 403: if(keycode == KC_CURSOR_LEFT) mouse->x -= i; ! 404: if(mouse->x < 0) mouse->x = 0; ! 405: if(mouse->y < 0) mouse->y = 0; ! 406: if(mouse->x >= winfo.width) mouse->x = winfo.width-1; ! 407: if(mouse->y >= winfo.height-PALHEIGHT-2*PALBORDER) ! 408: mouse->y = winfo.height-PALHEIGHT-2*PALBORDER-1; ! 409: XWarpMouse(wind,(int)mouse->x,(int)mouse->y); ! 410: } ! 411: #else ! 412: keystring = XLookupMapping(but, &j); ! 413: /* ANSI cursor keys are esc. seq. */ ! 414: if(j > 0 && *keystring == '\033') { ! 415: i = 1<<zoomfactor; ! 416: if(strcmp(keystring,"\033[A") == 0) mouse->y -= i; /* up */ ! 417: if(strcmp(keystring,"\033[B") == 0) mouse->y += i; /* down */ ! 418: if(strcmp(keystring,"\033[C") == 0) mouse->x += i; /* right */ ! 419: if(strcmp(keystring,"\033[D") == 0) mouse->x -= i; /* left */ ! 420: if(mouse->x < 0) mouse->x = 0; ! 421: if(mouse->y < 0) mouse->y = 0; ! 422: if(mouse->x >= winfo.width) mouse->x = winfo.width-1; ! 423: if(mouse->y >= winfo.height-PALHEIGHT-2*PALBORDER) ! 424: XWarpMouse(wind,(int)mouse->x,(int)mouse->y); ! 425: } ! 426: #endif ! 427: break; ! 428: ! 429: case ButtonPressed: /* Activate Menu ? */ ! 430: if((but->detail & ! 431: (ControlMask | MetaMask | ShiftMask | ShiftLockMask)) ! 432: == ControlMask) ! 433: { ! 434: XQueryWindow(wind, &winfo); ! 435: XMenuSetFreeze(showmenu); ! 436: pane = lastpane; ! 437: sel = lastsel; ! 438: if(XMenuActivate(showmenu,&pane,&sel, ! 439: but->x + winfo.x, but->y + winfo.y, ! 440: ButtonReleased, ¤tflags) ! 441: == XM_SUCCESS) { /* check out the selection */ ! 442: lastpane = pane; ! 443: lastsel = sel; ! 444: ! 445: switch(*currentflags & PANEMASK) { ! 446: /* EXIT */ ! 447: case 0: ! 448: exit(0); /* normal exit */ ! 449: ! 450: /* Set `viewing mode' - manipulation of color map */ ! 451: case VOP: ! 452: imageinfo.VOP_Flags &= ~(currentflags[1]); ! 453: imageinfo.VOP_Flags |= ! 454: (*currentflags & SELMASK); ! 455: XUndefineCursor(wind); ! 456: XDefineCursor(wind, imcursor); ! 457: imageinfo.COP_Flags = 0; ! 458: break; ! 459: ! 460: /* Set cursor mode - other uses than above */ ! 461: case COP: ! 462: /* if in test mode, disable all but viewing */ ! 463: if(imageinfo.calibration) break; ! 464: imageinfo.COP_Flags &= ~(currentflags[1]); ! 465: imageinfo.COP_Flags |= ! 466: (*currentflags & SELMASK); ! 467: if(imageinfo.COP_Flags & COP_Print) { ! 468: XUndefineCursor(wind); ! 469: XDefineCursor(wind, printcursor); ! 470: } else if(imageinfo.COP_Flags & COP_Pan) { ! 471: XUndefineCursor(wind); ! 472: XDefineCursor(wind, pancursor); ! 473: } else if(imageinfo.COP_Flags & COP_Zoom2) { ! 474: XUndefineCursor(wind); ! 475: XDefineCursor(wind, zoom2cursor); ! 476: } else if(imageinfo.COP_Flags & COP_Zoom4) { ! 477: XUndefineCursor(wind); ! 478: XDefineCursor(wind, zoom4cursor); ! 479: } ! 480: break; ! 481: ! 482: /* set picture scaling mode */ ! 483: case SOP: ! 484: /* if in test mode, disable all but viewing */ ! 485: if(imageinfo.calibration) break; ! 486: /* first, see if any different */ ! 487: if((imageinfo.SOP_Flags & ! 488: (*currentflags & SELMASK)) == 0) ! 489: { ! 490: imageinfo.SOP_Flags &= ! 491: ~(currentflags[1]); ! 492: imageinfo.SOP_Flags |= ! 493: (*currentflags & SELMASK); ! 494: scalepict(imageinfo.image, ! 495: imageinfo.picture, ! 496: imageinfo.pmax, imageinfo.pmin, ! 497: colorinfo.ncolors, ! 498: colorinfo.pixels[0], ! 499: colorinfo.shift, ! 500: imageinfo.nrows, ! 501: imageinfo.ncols, ! 502: imageinfo.SOP_Flags); ! 503: writepix( wind, imageinfo.image, ! 504: imageinfo.ncols, ! 505: imageinfo.nrows, ! 506: zoomfactor, 0, 0, ! 507: winfo.width, winfo.height, ! 508: xzero, yzero, 0, GXcopy, ! 509: AllPlanes); ! 510: } ! 511: break; ! 512: ! 513: case FOP: ! 514: /* if in test mode, disable all but viewing */ ! 515: if(imageinfo.calibration) break; ! 516: break; ! 517: ! 518: default: ! 519: fprintf(stderr,"Unknown menu pane %d\n", ! 520: *currentflags>>16); ! 521: } ! 522: } ! 523: break; ! 524: } ! 525: else if((but->detail & ! 526: (ControlMask | MetaMask | ShiftMask | ! 527: ShiftLockMask)) == 0) ! 528: { ! 529: /* check if viewing or cursor operation selected */ ! 530: if(imageinfo.COP_Flags) break; ! 531: downbutton = but->detail & ! 532: (RightButton | MiddleButton | LeftButton); ! 533: CalcMap(&winfo,colorinfo.cmap,(int)but->x,(int)but->y, ! 534: colorinfo.ncolors, imageinfo.VOP_Flags, ! 535: downbutton); ! 536: XStoreColors(colorinfo.ncolors,colorinfo.cmap); ! 537: break; ! 538: } ! 539: break; ! 540: ! 541: case ButtonReleased: ! 542: /* check if viewing or cursor operation selected */ ! 543: if(imageinfo.COP_Flags) { ! 544: if(imageinfo.COP_Flags & COP_Print) { ! 545: /* print 11x11 picture region */ ! 546: prpict(imageinfo.picture, but->x>>zoomfactor, ! 547: but->y>>zoomfactor, xzero, yzero, ! 548: imageinfo.ncols, imageinfo.nrows, 11, 11); ! 549: } ! 550: /* recenter (pan) on cursor position */ ! 551: if(imageinfo.COP_Flags & ! 552: (COP_Pan | COP_Zoom2 | COP_Zoom4)) { ! 553: ! 554: xcenter = xzero + (but->x >> zoomfactor); ! 555: ycenter = yzero + (but->y >> zoomfactor); ! 556: ! 557: /* alter zoomfactor to reflect new zoom */ ! 558: if(imageinfo.COP_Flags & COP_Pan) zoomfactor = 0; ! 559: if(imageinfo.COP_Flags & COP_Zoom2) zoomfactor = 1; ! 560: if(imageinfo.COP_Flags & COP_Zoom4) zoomfactor = 2; ! 561: ! 562: xtempzero = ! 563: MAX( 0, MIN(imageinfo.ncols - ! 564: (winfo.width>>zoomfactor), ! 565: xcenter - (winfo.width>>(zoomfactor+1)))); ! 566: ! 567: #ifdef PALWIND ! 568: ytempzero = ! 569: MAX( 0, MIN(imageinfo.nrows- ! 570: (winfo.height>>zoomfactor), ! 571: ycenter - (winfo.height>>(zoomfactor+1)))); ! 572: #else ! 573: ytempzero = ! 574: MAX( 0, MIN(imageinfo.nrows- ! 575: ((winfo.height-PALHEIGHT-2*PALBORDER) ! 576: >>zoomfactor), ! 577: ycenter - ((winfo.height- ! 578: PALHEIGHT-2*PALBORDER) ! 579: >>(zoomfactor+1)))); ! 580: #endif ! 581: if(xzero != xtempzero || yzero != ytempzero || ! 582: oldzoomfactor != zoomfactor) ! 583: { ! 584: xzero = xtempzero; ! 585: yzero = ytempzero; ! 586: writepix( wind, imageinfo.image, ! 587: imageinfo.ncols, imageinfo.nrows, ! 588: zoomfactor, 0, 0, ! 589: winfo.width, winfo.height, ! 590: xzero, yzero, 0, GXcopy, AllPlanes); ! 591: XWarpMouse(wind, (xcenter-xzero)<<zoomfactor, ! 592: (ycenter-yzero)<<zoomfactor); ! 593: } ! 594: /* COP_OldFlags = imageinfo.COP_Flags; */ ! 595: oldzoomfactor = zoomfactor; ! 596: } ! 597: break; ! 598: } ! 599: if(downbutton < 0) break; ! 600: CalcMap(&winfo,colorinfo.cmap,(int)but->x,(int)but->y, ! 601: colorinfo.ncolors, imageinfo.VOP_Flags, ! 602: downbutton); ! 603: XStoreColors(colorinfo.ncolors,colorinfo.cmap); ! 604: downbutton = -1; ! 605: break; ! 606: ! 607: case MouseMoved: ! 608: XUpdateMouse(wind, &xbut, &ybut, &subwind); ! 609: XQueryMouseButtons(wind, &xbut, &ybut, ! 610: &subwind, &mouse->detail); ! 611: ! 612: if(subwind == 0 && downbutton >= 0) { ! 613: CalcMap(&winfo,colorinfo.cmap,xbut,ybut, ! 614: colorinfo.ncolors, ! 615: imageinfo.VOP_Flags,downbutton); ! 616: XStoreColors(colorinfo.ncolors,colorinfo.cmap); ! 617: } ! 618: else { ! 619: updatezoom(wzoom, xzoomsize, yzoomsize, ! 620: (xzero + (but->x >> zoomfactor)), ! 621: (yzero + (but->y >> zoomfactor)), ! 622: imageinfo.ncols, imageinfo.nrows, ! 623: imageinfo.image, (1<<zoomfactor)); ! 624: } ! 625: break; ! 626: ! 627: /* On ExposeWindow events, recalculate the image center and ! 628: * coordinates of upper left hand corner of window. ! 629: */ ! 630: case ExposeCopy: ! 631: case ExposeWindow: ! 632: if(QLength() > 0) { ! 633: XPeekEvent(&peekevent); ! 634: if(peekevent.type == ExposeWindow && ! 635: peekevent.window == expw->window) break; ! 636: } ! 637: ! 638: if(expw->window == iconwindow) { ! 639: XBitmapBitsPut(iconwindow, 0, 0, ! 640: show_width, show_height, show_bits, ! 641: WhitePixel, BlackPixel, 0, ! 642: GXcopy, AllPlanes); ! 643: break; ! 644: } ! 645: ! 646: #ifdef PALWIND ! 647: if(expw->window == iconpalwind) { ! 648: XBitmapBitsPut(iconpalwind, 0, 0, ! 649: show_width, show_height, show_bits, ! 650: WhitePixel, BlackPixel, 0, ! 651: GXcopy, AllPlanes); ! 652: break; ! 653: } ! 654: #endif ! 655: if(expw->window == iconwzoom) { ! 656: XBitmapBitsPut(iconwzoom, 0, 0, ! 657: show_width, show_height, show_bits, ! 658: WhitePixel, BlackPixel, 0, ! 659: GXcopy, AllPlanes); ! 660: break; ! 661: } ! 662: ! 663: if(w_mapped == 0) { /* check if to remap windows */ ! 664: #ifdef PALWIND ! 665: if(expw->window != palwind) XMapWindow(palwind); ! 666: #endif ! 667: if(expw->window != wind) XMapWindow(wind); ! 668: if(expw->window != wzoom) XMapWindow(wzoom); ! 669: w_mapped++; ! 670: } ! 671: ! 672: XQueryWindow(wind,&winfo); ! 673: ! 674: if(expw->window == wind) { ! 675: XQueryWindow(palwind,&palwinfo); ! 676: #ifdef PALWIND ! 677: XConfigureWindow(palwind, winfo.x, ! 678: winfo.y+winfo.height+ ! 679: maininfo.frame.bdrwidth, ! 680: winfo.width, PALHEIGHT); ! 681: #else ! 682: XConfigureWindow(palwind, 0, ! 683: winfo.height-PALHEIGHT-2*PALBORDER, ! 684: winfo.width-2*PALBORDER, ! 685: PALHEIGHT); ! 686: #endif ! 687: XQueryWindow(wzoom,&wzoominfo); ! 688: xzoomsize = wzoominfo.width; ! 689: yzoomsize = wzoominfo.height; ! 690: XConfigureWindow(wzoom, ! 691: winfo.x+winfo.width+ ! 692: maininfo.frame.bdrwidth, ! 693: winfo.y, wzoominfo.width, ! 694: wzoominfo.height); ! 695: ! 696: xzero = MAX( 0, ! 697: MIN(imageinfo.ncols-(winfo.width>>zoomfactor), ! 698: xcenter - ! 699: (winfo.width>>(zoomfactor+1)))); ! 700: #ifdef PALWIND ! 701: yzero = MAX( 0, ! 702: MIN(nrows- ! 703: (winfo.height>>zoomfactor), ! 704: ycenter - ! 705: (winfo.height>>(zoomfactor+1)))); ! 706: #else ! 707: yzero = MAX( 0, ! 708: MIN(imageinfo.nrows- ! 709: ((winfo.height-PALHEIGHT-2*PALBORDER) ! 710: >>zoomfactor), ! 711: ycenter - ((winfo.height - ! 712: PALHEIGHT-2*PALBORDER) ! 713: >>(zoomfactor+1)))); ! 714: #endif ! 715: } ! 716: ! 717: if(event.type == ExposeCopy) break; ! 718: ! 719: /* drop through to ExposeRegion to draw the window, and ! 720: * redraw the supporting windows */ ! 721: ! 722: case ExposeRegion: ! 723: if(expw->window == palwind) { ! 724: XQueryWindow(palwind,&palwinfo); ! 725: for(i=0; i<palwinfo.width; i++) ! 726: palette[i] = ! 727: ((colorinfo.ncolors * i)/palwinfo.width) + ! 728: colorinfo.pixels[0]; ! 729: for(i=0; i<palwinfo.height; i++) ! 730: XPixmapBitsPutZ(palwind, 0, i, ! 731: palwinfo.width, 1, ! 732: palette, 0, GXcopy, AllPlanes); ! 733: } ! 734: else if(expw->window == wzoom) { ! 735: XQueryWindow(wzoom,&wzoominfo); ! 736: xzoomsize = wzoominfo.width; ! 737: yzoomsize = wzoominfo.height; ! 738: updatezoom(wzoom, xzoomsize, yzoomsize, ! 739: xcenter, ycenter, ! 740: imageinfo.ncols, imageinfo.nrows, ! 741: imageinfo.image, (1<<zoomfactor)); ! 742: } ! 743: else { ! 744: if( expw->x > imageinfo.ncols<<zoomfactor || ! 745: expw->y > imageinfo.nrows<<zoomfactor) ! 746: break; ! 747: ! 748: writepix( wind, imageinfo.image, ! 749: imageinfo.ncols, imageinfo.nrows, ! 750: zoomfactor, expw->x, expw->y, ! 751: expw->width, expw->height, ! 752: xzero, yzero, 0, GXcopy, AllPlanes); ! 753: } ! 754: break; ! 755: ! 756: /* If any window is unmapped, all three are unmapped */ ! 757: ! 758: case UnmapWindow: ! 759: ! 760: #ifdef PALWIND ! 761: if(event.window != palwind) XUnmapWindow(palwind); ! 762: #endif ! 763: if(event.window != wzoom) XUnmapWindow(wzoom); ! 764: if(event.window != wind) XUnmapWindow(wind); ! 765: w_mapped = 0; ! 766: break; ! 767: } ! 768: } ! 769: } ! 770: ! 771: ! 772: #ifdef GLOPEROO ! 773: describe_XEvent(etype, ewindow, detail, wind, palwind, wzoom) ! 774: unsigned long etype; ! 775: unsigned short detail; ! 776: Window ewindow, wind, palwind, wzoom; ! 777: { ! 778: fprintf(stderr,"Window "); ! 779: if(ewindow == wind) { ! 780: fprintf(stderr,"wind, "); ! 781: } else if(ewindow == palwind) { ! 782: fprintf(stderr,"palwind, "); ! 783: } else if(ewindow == wzoom) { ! 784: fprintf(stderr,"wzoom, "); ! 785: } else { ! 786: fprintf("ERROR %d\n", ewindow); ! 787: } ! 788: switch((int)etype) { ! 789: case KeyPressed: fprintf(stderr,"KeyPressed"); ! 790: fprintf(stderr," detail = %x", detail); ! 791: break; ! 792: case KeyReleased: fprintf(stderr,"KeyReleased"); ! 793: fprintf(stderr," detail = %x", detail); ! 794: break; ! 795: case ButtonPressed: fprintf(stderr,"ButtonPressed"); ! 796: fprintf(stderr," detail = %x", detail); ! 797: break; ! 798: case ButtonReleased: fprintf(stderr,"ButtonReleased"); ! 799: fprintf(stderr," detail = %x", detail); ! 800: break; ! 801: case EnterWindow: fprintf(stderr,"EnterWindow"); ! 802: fprintf(stderr," detail = %x", detail); ! 803: break; ! 804: case LeaveWindow: fprintf(stderr,"LeaveWindow"); ! 805: fprintf(stderr," detail = %x", detail); ! 806: break; ! 807: case MouseMoved: fprintf(stderr,"MouseMoved"); ! 808: fprintf(stderr," detail = %x", detail); ! 809: break; ! 810: case ExposeWindow: fprintf(stderr,"ExposeWindow"); break; ! 811: case ExposeRegion: fprintf(stderr,"ExposeRegion"); break; ! 812: case ExposeCopy: fprintf(stderr,"ExposeCopy"); break; ! 813: case UnmapWindow: fprintf(stderr,"UnmapWindow"); break; ! 814: case FocusChange: fprintf(stderr,"FocusChange"); break; ! 815: default: fprintf(stderr,"ERROR %d", etype); ! 816: } ! 817: fprintf(stderr,"\n"); ! 818: fflush(stderr); ! 819: } ! 820: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.