18 #define MAX(i,j) ( (i) > (j) ? (i) : (j) )
19 #define MIN(i,j) ( (i) < (j) ? (i) : (j) )
62 int mapstart, mapflag = 0;
64 FILE * infile = stdin;
67 if (
scanargs( argc
, argv
, "% f%- w%- D%- m%-mapstart!d file%s\n(\
68 \tDisplay a URT image dithered in the window system.\n\
69 \t-f\tKeep program in foreground\n\
70 \t-w\tDisplay in black and white instead of color.\n\
71 \t-m\tStarting point in colormap (uses 512 entries for color).\n\
72 \tLeft mouse pans image, setup key recenters.)",
76 if ( bwflag ) bw_start = mapstart;
else color_start = mapstart;
88 get_pic( infile, infname, cmdname )
90 char * infname, cmdname;
94 unsigned char *scan[3];
113 if ( ncolors == 1 ) bwflag = TRUE;
120 image = (Colorindex *) malloc(x_size * y_size *
sizeof( Colorindex ));
125 for (i = 0; i < 3; i++)
126 scan[i] = (
unsigned char *) malloc(
x_size);
133 if (
bwflag && ncolors > 1 )
139 map_scanline( scan, x_size, y,
140 &image[(y - hdr.ymin) * x_size] );
146 for (i = 0; i < 3; i++)
155 if ( infname ) wintitle( infname );
160 qdevice( LEFTMOUSE );
162 unqdevice( INPUTCHANGE );
167 qenter( REDRAW, window_number );
177 int window_x_size, window_y_size, window_x_origin, window_y_origin;
178 int x_min, x_max, y_min, y_max, x_start, y_start, x_end, y_end, x_len;
179 int x_origin, y_origin, new_x_center, new_y_center;
180 int x_center, y_center, saved_x_center, saved_y_center;
183 register Colorindex *y_ptr;
186 x_center = saved_x_center =
x_size / 2;
187 y_center = saved_y_center =
y_size / 2;
192 event = qread( &data );
194 printf(
"event %d, data %d\n", event, data );
199 winset( window_number );
207 getsize( &window_x_size, &window_y_size );
208 x_min = x_center - window_x_size/2;
209 x_max = x_min + (window_x_size-1);
210 y_min = y_center - window_y_size/2;
211 y_max = y_min + (window_y_size-1);
214 ortho2( x_min - .5, x_max + .5, y_min - .5, y_max + .5 );
217 x_start =
MAX( x_min, 0 );
218 y_start =
MAX( y_min, 0 );
219 x_end =
MIN( x_max, x_size-1 );
220 y_end =
MIN( y_max, y_size-1 );
221 x_len = x_end - x_start + 1;
226 for ( y = y_start, y_ptr = image + y_start*x_size + x_start;
227 y <= y_end && (y%16 != 0 || qtest() != REDRAW);
228 y++, y_ptr += x_size )
230 cmov2i( x_start, y );
231 writepixels( x_len, y_ptr );
242 if ( getbutton(RIGHTSHIFTKEY) || getbutton(LEFTSHIFTKEY) )
244 x_center = saved_x_center;
245 y_center = saved_y_center;
246 qenter( REDRAW, window_number );
248 else if ( getbutton(CTRLKEY) )
250 saved_x_center = x_center;
251 saved_y_center = y_center;
255 x_center = x_size / 2;
256 y_center = y_size / 2;
257 qenter( REDRAW, window_number );
269 getorigin( &x_origin, &y_origin );
270 new_x_center = getvaluator( MOUSEX ) - x_origin + x_min;
271 new_y_center = getvaluator( MOUSEY ) - y_origin + y_min;
272 if ( new_x_center >= x_start &&
273 new_x_center <= x_end &&
274 new_y_center >= y_start &&
275 new_y_center <= y_end )
277 x_center = new_x_center;
278 y_center = new_y_center;
279 qenter( REDRAW, window_number );
300 map_scanline( rgb, n, y, line )
301 unsigned char *rgb[3];
307 # define DMAP(v,x) (modN[v]>row_ptr[x] ? divN[v] + 1
: divN[v])
310 row_ptr = dm16[ row ];
314 register unsigned char *r, *g, *b;
315 for ( col = 0, i = 0, r = rgb[0], g = rgb[1], b = rgb[2];
316 i < n; i++, r++, g++, b++, col = ((col + 1) & 15) )
319 line[i] = color_start +
DMAP(*r, col) + (
DMAP(*g, col)<<3) +
325 register unsigned char *bw;
327 for ( i = 0, bw = rgb[0]; i < n; i++, bw++ )
328 line[i] = bw_start + (*bw>>1);
342 if ((v%51)>d)
return (v/51)+1 ;
else return (v/51) ;
348 int i, j, k, l, planes, pixels[216];
374 register int i, j, v;
375 register int r, g, b, w;
378 planes = getplanes();
382 if (planes > 8 &&
bwflag )
383 for (i=0; i<128; i++) {
384 gammapcolor(i+ bw_start ,i<<1,i<<1,i<<1);
389 if (planes > 9 && !
bwflag )
390 for (i=0; i<512; i++) {
397 gammapcolor(i+ color_start ,r,g,b);
416 float gammacorrect();
417 float ungammacorrect();
428 register int index,r,g,b;
439 mapcolor(
index,r,g,b);
442 static makegamtables()
444 register float gamval;
447 int rbal, gbal, bbal;
450 getcolorbal(&rbal,&gbal,&bbal);
451 for (i=0; i<256; i++) {
452 rgamtable[i] = 255*gammacorrect((rbal*i)/(255.0*255.0),gamval);
453 ggamtable[i] = 255*gammacorrect((gbal*i)/(255.0*255.0),gamval);
454 bgamtable[i] = 255*gammacorrect((bbal*i)/(255.0*255.0),gamval);
459 for (i=0; i<256; i++) {
470 register unsigned char *cptr;
472 register short i, lowval;
484 unsigned short *r, *g, *b;
486 static short firsted;
487 unsigned short tr, tg, tb;
493 getmcolor(
index,&tr,&tg,&tb);
499 float gammacorrect( i, gamma)
502 return pow(i,1.0/gamma);
505 float ungammacorrect( i, gamma)
520 if ((outf = configopen(
".gamtables",
"w")) == 0) {
521 fprintf(stderr,
"couldn't open .gamtables\n");
538 if ((inf = configopen(
".gamtables",
"r")) == 0) {
540 if ((inf = configopen(
".gamtables",
"r")) == 0) {
541 fprintf(stderr,
"couldn't open .gamtables\n");
574 if ((gamfile = configopen(
".gamma",
"r")) ) {
575 if (fscanf(gamfile,
"%f\n",&gam) == 1) {
589 if ((gamfile = configopen(
".gamma",
"w")) == 0) {
590 fprintf(stderr,
"couldn't open .gamma\n");
593 fprintf(gamfile,
"%f\n",gam);
599 unsigned int *r, *g, *b;
603 if ((cbfile = configopen(
".cbal",
"r")) ) {
604 if (fscanf(cbfile,
"%d %d %d\n",r,g,b) == 3) {
627 if ((cbfile = configopen(
".cbal",
"w")) == 0) {
628 fprintf(stderr,
"couldn't open .cbal\n");
631 fprintf(cbfile,
"%d %d %d\n",r,g,b);
636 FILE *configopen( name, mode )
644 cptr = (
char *)getenv(
"HOME");
647 strcpy(homepath,cptr);
648 strcat(homepath,
"/");
649 strcat(homepath,name);
650 return fopen(homepath,mode);
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
void make_square(double N, divN, modN, magic)
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
void rle_debug(int on_off)
char * cmd_name(char **argv)
void main(int argc, char **argv)
static unsigned char gungamtable[256]
int rle_getrow(rle_hdr *the_hdr, scanline)
static unsigned char ggamtable[256]
void rgb_to_bw(rle_pixel *red_row, rle_pixel *green_row, rle_pixel *blue_row, rle_pixel *bw_row, int rowlen)
int scanargs(int argc, char **argv, const char *format,...)
static unsigned char bungamtable[256]
void rle_get_setup_ok(rle_hdr *the_hdr, const char *prog_name, const char *file_name)
#define RLE_CLR_BIT(glob, bit)
static unsigned char rgamtable[256]
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
static unsigned char bgamtable[256]
static unsigned char rungamtable[256]