29 static char rcs_ident[] =
"$Id: getx10.c,v 3.0.1.1 1992/01/28 18:12:35 spencer Exp $";
46 #define arrow_width 16
47 #define arrow_height 16
51 0x0000, 0x0010, 0x0030, 0x0070,
52 0x00f0, 0x01f0, 0x03f0, 0x07f0,
53 0x0ff0, 0x01f0, 0x03b0, 0x0310,
54 0x0700, 0x0600, 0x0600, 0x0000};
55 #define arrow_mask_width 16
56 #define arrow_mask_height 16
58 0x0018, 0x0038, 0x0078, 0x00f8,
59 0x01f8, 0x03f8, 0x07f8, 0x0ff8,
60 0x1ff8, 0x1ff8, 0x07f8, 0x07b8,
61 0x0f98, 0x0f00, 0x0f00, 0x0f00};
161 char ** infnames = NULL, *infname = NULL, *display_name = NULL,
162 * window_geometry = NULL;
163 FILE * infile = stdin;
164 int nfile = 0, use_pix = 0,
165 dflag = 0, gflag = 0, wflag = 0;
168 "% Bb%- m%- f%- p%- cWw%- D%- n%-levels!d d%-display!s \n\
169 \t=%-window-geometry!s Ii%-gamma!F g%-gamma!F z%- file%s",
172 &dflag
, &display_name
,
173 &wflag
, &window_geometry
,
181 rle_names( &hdr, cmd_name( argv ), infname );
184 if (
setbg & !use_pix )
186 fprintf( stderr,
"Can't specify -p with -b, -p ignored\n" );
204 if ( infname != NULL )
217 get_pic( infile, *infnames, display_name,
224 get_pic( stdin, NULL, display_name,
237 update_pic( use_pix );
243 update_pic( use_pix );
245 }
while ( nfile > 0 );
253 get_pic( infile, infname, display_name, window_geometry )
257 char * window_geometry;
263 unsigned char *scan[3];
286 dpy = XOpenDisplay(display_name);
289 fprintf(stderr,
"%s: Can't open display %s\n",
290 hdr.cmd, display_name ?
"" : display_name);
293 if ( DisplayPlanes() == 1 )
372 for (i = 0; i < 3; i++)
373 scan[i] = (
unsigned char *) malloc(
nrow);
382 create_window(
nrow,
nscan, window_geometry);
389 if (
bwflag && ncolors > 1 )
391 map_rgb_to_bw( scan[0], scan[1], scan[ncolors - 1], scan[0],
396 for ( i = 0; i <
nrow; i++ )
397 scan[0][i] =
in_cmap[0][scan[0][i]];
399 for (i = 2; i >= ncolors; i--)
400 bcopy(scan[0], scan[i],
nrow);
401 map_scanline(scan,
nrow, 1, y,
416 for (i = 0; i < 3; i++)
425 update_pic( use_pix )
437 int zoom_x_press, zoom_y_press;
457 pixsize = pixscan *
nbyte;
458 lastscan =
nscan % pixscan;
460 pix = (Pixmap(*)[]) malloc(npix *
sizeof(Pixmap));
461 for (i = 0; i < npix; i++)
463 (*pix)[i] = XStorePixmapZ(nrow,
464 (i == npix - 1) ? lastscan : pixscan,
465 &buffer[i * nrow * pixscan]);
468 bm = XStoreBitmap(nrow,
469 (i == npix - 1) ? lastscan : pixscan,
470 &buffer[i * nbyte * pixscan]);
471 (*pix)[i] = XMakePixmap( bm, 1, 0 );
478 XChangeBackground( RootWindow, (*pix)[0] );
479 XClear( RootWindow );
492 if (rep.type == ButtonPressed)
494 xkey = *(XButtonEvent *) &rep;
495 if (zoomflg && (xkey.window == fbwin))
497 zoom_x_press = xkey.x;
498 zoom_y_press = xkey.y;
501 else if (rep.type == ButtonReleased)
503 xkey = *(XButtonEvent *) &rep;
504 if ( xkey.detail & ShiftMask )
506 if (zoomflg && (xkey.window == zoomwin))
509 XDestroyWindow(zoomwin);
518 if (zoomflg && (xkey.window == fbwin))
520 zoom_x_center = xkey.x;
521 zoom_y_center = xkey.y;
522 if ((zoom_x_center != zoom_x_press) &&
523 (zoom_y_center != zoom_y_press))
526 if (zoom_x_press < zoom_x_center)
528 zoom_x_dim = (zoom_x_center - zoom_x_press);
529 zoom_x_center = zoom_x_press + (zoom_x_dim / 2);
533 zoom_x_dim = (zoom_x_press - zoom_x_center);
534 zoom_x_center = zoom_x_center + (zoom_x_dim / 2);
536 if (zoom_y_press < zoom_y_center)
538 zoom_y_dim = (zoom_y_center - zoom_y_press);
539 zoom_y_center = zoom_y_press + (zoom_y_dim / 2);
543 zoom_y_dim = (zoom_y_press - zoom_y_center);
544 zoom_y_center = zoom_y_center + (zoom_y_dim / 2);
546 XChangeWindow(zoomwin, zoomfact * zoom_x_dim,
547 zoomfact * zoom_y_dim);
548 XSetResizeHint( zoomwin, 0, 0, zoomfact, zoomfact );
552 else if (zoomflg && (xkey.window == zoomwin))
554 if (xkey.detail & RightMask)
558 XChangeWindow(zoomwin, zoomfact * zoom_x_dim,
559 zoomfact * zoom_y_dim);
560 XSetResizeHint( zoomwin, 0, 0, zoomfact, zoomfact );
562 else if (xkey.detail & LeftMask)
568 XChangeWindow(zoomwin, zoomfact * zoom_x_dim,
569 zoomfact * zoom_y_dim);
570 XSetResizeHint( zoomwin, 0, 0, zoomfact, zoomfact );
573 else if (xkey.detail & MiddleMask)
578 fprintf(stderr,
"Position: (%d, %d)\n",
580 xkey.x / zoomfact + (zoom_x_center
584 - (zoom_y_center - (zoom_y_dim / 2))));
585 fprintf(stderr,
"Image crop: (%d, %d) to (%d, %d)\n",
588 fprintf(stderr,
"Zoom crop: (%d, %d) to (%d, %d)\n",
590 (zoom_x_center - (zoom_x_dim / 2)),
591 (hdr.ymax - (zoom_y_dim - 1)
592 - (zoom_y_center - (zoom_y_dim / 2))),
593 hdr.xmin + (zoom_x_dim - 1)
594 + (zoom_x_center - (zoom_x_dim / 2)),
596 - (zoom_y_center - (zoom_y_dim / 2))));
603 else if (rep.type == ExposeWindow || rep.type == ExposeRegion)
605 xex = *((XExposeEvent *) & rep);
610 if (xex.window == iconwin)
612 XPixmapBitsPutZ(iconwin, 0, 0, iconrow, iconscan,
613 iconbuf, 0, GXcopy, AllPlanes);
615 XBitmapBitsPut(iconwin, 0, 0, iconrow, iconscan,
616 iconbuf, 1, 0, 0, GXcopy, AllPlanes);
617 else if (zoomflg && (xex.window == zoomwin))
619 resize_zoom_window();
628 if (xex.y + xex.height >= nscan)
629 xex.height = nscan - xex.y;
636 xex.x = (xex.x / 16) * 16;
639 if (xex.x + xex.width >= nrow)
640 xex.width = nrow - xex.x;
646 for (i = xex.y; i < xex.y + xex.height; i++)
647 put_scanline( &buffer[i * nbyte + xex.x / 8],
648 xex.width, xex.x, i );
650 for (i = xex.y; i < xex.y + xex.height; i++)
651 put_scanline( &buffer[i * nbyte + xex.x],
652 xex.width, xex.x, i );
659 int start = xex.y / pixscan,
660 end = (xex.y + xex.height) / pixscan,
665 for (i = start; i <= end; i++)
667 ytop = (i == end) ? xex.y + xex.height
674 XPixmapPut(fbwin, xex.x, y - i * pixscan,
676 xex.width, ytop - y, (*pix)[i],
680 for (j = y; j < ytop; j++)
681 put_scanline( &buffer[j * nbyte +
683 xex.width, xex.x, j );
685 for (j = y; j < ytop; j++)
686 put_scanline( &buffer[j * nbyte + xex.x],
687 xex.width, xex.x, j );
693 else if ( rep.type != ButtonPressed )
694 fprintf(stderr,
"%s: Event type %x?\n", hdr.cmd, rep.type);
700 XDestroyWindow(fbwin);
701 if (zoomflg) XDestroyWindow(zoomwin);
706 unsigned char the_pix;
711 int zoom_x_corner, zoom_y_corner;
718 for (j=y_bottom; j<=y_top; j++)
720 zoom_y_corner = (j - y_bottom) *
zoomfact;
721 if ((j < 0) || (j >=
nscan))
724 XPixSet( zoomwin, 0, zoom_y_corner, zoomfact * zoom_x_dim,
725 zoomfact, colmap[0].pixel );
729 for ( i= x_bottom; i<=x_top; i++)
731 zoom_x_corner = (i - x_bottom) *
zoomfact;
732 if ((i < 0) || (i >=
nrow))
735 XPixSet( zoomwin, zoom_x_corner, zoom_y_corner,
736 zoomfact, zoomfact, colmap[0].pixel );
743 the_pix =
buffer[j *
nbyte + i/8] & (1 << (i % 8)) ?
745 XPixSet( zoomwin, zoom_x_corner, zoom_y_corner,
746 zoomfact, zoomfact, the_pix );
756 create_window( width, height, window_geometry )
760 int zoomwidth, zoomheight;
765 sprintf( geometry,
"=%dx%d+0+0",
nrow,
nscan );
767 frame.border = WhitePixmap;
768 frame.background = BlackPixmap;
769 if ( (fbwin = XCreate( hdr.cmd, hdr.cmd, window_geometry, geometry,
770 &frame, nrow, nscan )) == NULL )
772 fprintf( stderr,
"%s: Window Create failed\n", hdr.cmd );
776 XGetHardwareColor( &colmap[0] );
777 XPixSet( fbwin, 0, 0, width, height, colmap[0].pixel );
778 XSetResizeHint( fbwin, width, height, 1, 1 );
779 XSelectInput( fbwin, ButtonPressed|ButtonReleased|ExposeRegion );
785 BlackPixel, WhitePixel, GXcopy);
786 XDefineCursor(fbwin,arrow_curs);
789 iconwin = XCreateWindow( RootWindow, 1, 1,
790 width / iconfact, height / iconfact, 0, 0, 0 );
791 XTileRelative( iconwin );
792 XSetIconWindow( fbwin, iconwin );
793 XSelectInput( iconwin, ButtonPressed|ButtonReleased|ExposeWindow );
799 sprintf( geometry,
"=%dx%d+0+0", zoomwidth, zoomheight );
801 frame.border = WhitePixmap;
802 frame.background = BlackPixmap;
803 if ( (zoomwin = XCreate(
"getx10 zoom", hdr.cmd, window_geometry,
805 &frame, zoomwidth, zoomheight )) == NULL )
807 fprintf( stderr,
"%s: Zoom window Create failed\n", hdr.cmd );
810 resize_zoom_window();
811 XMapWindow( zoomwin );
812 XPixSet( zoomwin, 0, 0, zoomfact * zoom_x_dim, zoomfact * zoom_y_dim,
814 XSetResizeHint( zoomwin, 0, 0, zoomfact, zoomfact );
815 XSelectInput( zoomwin, ButtonPressed|ButtonReleased|ExposeRegion );
816 XDefineCursor(zoomwin,arrow_curs);
831 #define DMAP(v,x,y) (modN[v]>dm16[x][y] ? divN[v] + 1
: divN[v])
834 unsigned char *rgb[3], *line;
836 register int i, col, row;
840 register unsigned char *r;
842 for ( r = rgb[0], i = 0; i < n; i++, r += s )
843 line[i] = colmap[*r].pixel;
847 register unsigned char *r, *g, *b;
848 for ( row = y % 16, col = 0, i = 0, r = rgb[0], g = rgb[1], b = rgb[2];
849 i < n; i++, r+=s, g+=s, b+=s, col = ((col + 1) & 15) )
850 line[i] = colmap[
DMAP(in_cmap[0][*r], col, row) +
851 DMAP(in_cmap[1][*g], col, row) * levels +
852 DMAP(in_cmap[2][*b], col, row) * levelsq].pixel;
856 register unsigned char *r;
858 for ( row = y % 16, col = 0, i = 0, r = rgb[0];
859 i < n; i++, r+=s, col = ((col + 1) & 15) )
860 line[i] = colmap[
DMAP(*r, col, row)].pixel;
864 register unsigned short *l = (
unsigned short *)line;
865 register unsigned char * r;
867 for ( row = y % 16, col = 0, i = 0, r = rgb[0], *l = 0;
868 i < n; r+=s, col = ((col + 1) & 15) )
870 *l |= (*r >
dm16[col][row] ? 1 : 0) << (i % 16);
871 if ( (++i % 16) == 0 && i < n )
877 put_scanline( scan, width, x, y )
881 XPixmapBitsPutZ( fbwin, x, y, width, 1, scan, 0, GXcopy, AllPlanes );
883 XBitmapBitsPut( fbwin, x, y, width, 1, scan, 1, 0, 0, GXcopy,
912 for (x=0; x<rowlen; x++)
916 bw = .35*map[0][red_row[x]] + .55*map[1][green_row[x]] +
917 .10*map[2][blue_row[x]];
937 int i, rgbmap[256][3], bwmap[256];
955 "%s: This display doesn't have enough color resolution.\
956 \nWill produce black and white image instead.\n",
hdr.cmd);
977 colmap[i].red = rgbmap[i][0] << 8;
978 colmap[i].green = rgbmap[i][1] << 8;
979 colmap[i].blue = rgbmap[i][2] << 8;
983 for ( i = 0; i <
levelsc; i++ )
985 if ( XGetHardwareColor( &colmap[i] ) == 0 )
994 for ( i--; i >= 0; i-- )
995 XFreeColors( &colmap[i].pixel, 1, 0 );
1003 "%s: Sorry, not enough color map entries are available.\
1004 \nWill make black & white image instead.\n",
hdr.cmd);
1015 if ( DisplayCells() > 16 )
1016 levels = DisplayCells() / 2;
1018 levels = DisplayCells() - 4;
1027 for ( i = 0; i <
levels; i++ )
1029 colmap[i].pixel = 0;
1030 colmap[i].red = bwmap[i] << 8;
1031 colmap[i].green = colmap[i].red;
1032 colmap[i].blue = colmap[i].red;
1036 for ( i = 0; i <
levels; i++ )
1038 if ( XGetHardwareColor( &colmap[i] ) == 0 )
1046 for ( i--; i >= 0; i-- )
1047 XFreeColors( &colmap[i].pixel, 1, 0 );
1067 printf(
"Magic square for %d levels:\n", levels );
1068 for ( i = 0; i < 16; i++ )
1070 for ( j = 0; j < 16; j++ )
1071 printf(
"%4d", dm16[i][j] );
1074 printf(
"divN array:\n" );
1075 for ( i = 0; i < 256; i++ )
1076 printf(
"%4d%s", divN[i], i % 16 == 15 ?
"\n" :
"" );
1077 printf(
"modN array:\n" );
1078 for ( i = 0; i < 256; i++ )
1079 printf(
"%4d%s", modN[i], i % 16 == 15 ?
"\n" :
"" );
1107 nmap = atoi( mapcom );
1112 for ( i = 0; i < 256; i++ )
1113 gammamap[i] = (
int)(0.5 + 255 * pow( i / 255.0, 1.0/
disp_gam ));
1115 for ( i = 0; i < nmap; i++ )
1116 for ( j = 0; j < 3; j++ )
1123 for(i = 0; i < nmap; i++) {
1124 colmap[i].pixel = 0;
1125 colmap[i].red = in_cmap[0][i] << 8;
1126 colmap[i].green = in_cmap[1][i] << 8;
1127 colmap[i].blue = in_cmap[2][i] << 8;
1128 if ( XGetHardwareColor( &colmap[i] ) == 0 )
1131 "%s: Sorry, need at least %d color map entries, only got %d.\n\
1132 Will display image anyway.\n",
1137 for ( ; i < 256; i++ )
1138 colmap[i].pixel = 0;
1141 resize_zoom_window()
1146 XQueryWindow( zoomwin, &info );
1149 xs = zoomfact * ( info.width / zoomfact );
1150 ys = zoomfact * ( info.height / zoomfact );
1152 if ( xs != info.width || ys != info.height )
1153 XChangeWindow( zoomwin, xs, ys );
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
void map_scanline(rgb, int n, int y,*line)
void make_square(double N, divN, modN, magic)
void rle_debug(int on_off)
void main(int argc, char **argv)
int rle_getrow(rle_hdr *the_hdr, scanline)
int scanargs(int argc, char **argv, const char *format,...)
void dithermap(int levels, double gamma, rgbmap, divN, modN, magic)
void init_color(register image_information *img)
rle_pixel ** buildmap(rle_hdr *the_hdr, int minmap, double orig_gamma, double new_gamma)
void rle_get_setup_ok(rle_hdr *the_hdr, const char *prog_name, const char *file_name)
char * rle_getcom(char *name, rle_hdr *the_hdr) const
#define RLE_CLR_BIT(glob, bit)
static short arrow_bits[]
void map_rgb_to_bw(image_information *img, rle_pixel **rows, register rle_pixel *bw_row)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
static short arrow_mask_bits[]
void bwdithermap(int levels, double gamma, bwmap, divN, modN, magic)