40 static char rcsid[] =
"$Header: /l/spencer/src/urt/get/RCS/getsun.c,v 3.0.1.2 1992/04/30 14:05:10 spencer Exp $";
48 #include <suntool/sunview.h>
49 #include <suntool/canvas.h>
135 "% Ww%- D%- f%- l%-levels!d Ii%-gamma!F g%-gamma!F file%s",
145 fprintf(stderr,
"Level must be in the range [2,6]; %d is invalid!\n",
levels);
152 if ( infile == stdin )
153 infname =
"Standard Input";
155 if ( !forkflg && fork() != 0 )
157 get_pic( infile, infname);
158 if ( infname != NULL) fclose( infile);
167 window_main_loop(frame);
185 get_pic( infile, infname, cmdname )
187 char * infname, * cmdname;
192 unsigned char *scan[3];
235 for (i = 0; i < 3; i++)
236 scan[i] = (
unsigned char *) malloc(
nrow);
254 else if ( (v =
rle_getcom( "display_gamma", &hdr
)) != NULL )
276 if (
bwflag && ncolors > 1 )
283 for ( i = 0; i <
nrow; i++ )
284 scan[0][i] =
in_cmap[0][scan[0][i]];
286 for (i = 2; i >= ncolors; i--)
287 bcopy(scan[0], scan[i],
nrow);
296 for (i = 0; i < 3; i++)
315 create_window( width, height, name)
321 sprintf(buf,
"\"%s\": %d X %d",
322 name, height, width);
323 frame = window_create(0, FRAME,
324 FRAME_SHOW_LABEL, TRUE,
326 FRAME_NO_CONFIRM, TRUE,
328 canvas = window_create(frame, CANVAS,
333 if ((pw = canvas_pixwin(canvas)) == NULL) {
334 perror(
"Cannot create pixwin");
337 if (pw->pw_pixrect->pr_depth == 1) bwflag=2;
357 #define DMAP(v,x,y) (modN[v]>dm16[x][y] ? divN[v] + 1
: divN[v])
360 unsigned char *rgb[3], *
line;
363 register int i, col, row;
367 register unsigned char *r, *g, *b;
368 for ( row = y % 16, col = 0, i = 0, r = rgb[0], g = rgb[1], b = rgb[2];
369 i < n; i++, r+=s, g+=s, b+=s, col = ((col + 1) & 15) )
376 register unsigned char *r;
378 for ( row = y % 16, col = 0, i = 0, r = rgb[0];
379 i < n; i++, r+=s, col = ((col + 1) & 15) )
380 line[i] =
DMAP(*r, col, row);
384 register unsigned short *l = (
unsigned short *)line;
385 register unsigned char * r;
387 for ( row = y % 16, col = 0, i = 0, r = rgb[0], *l = 0;
388 i < n; r+=s, col = ((col + 1) & 15) )
390 *l |= (*r >
dm16[col][row] ? 0 : 1) << (15-(i % 16));
391 if ( (++i % 16) == 0 )
412 put_scanline( scan, width, x, y )
418 if ((pix = mem_point(width,1,pw->pw_pixrect->pr_depth,scan)) == NULL) {
419 perror(
"Unable to allocate pixrect");
423 pw_write(pw, x, y, width, 1, PIX_SRC, pix, 0, 0);
457 for (x=0; x<rowlen; x++)
461 bw = .35*map[0][red_row[x]] + .55*map[1][green_row[x]] +
462 .10*map[2][blue_row[x]];
480 int rgbmap[256][3], bwmap[256];
481 unsigned char colormap[3][256];
502 colormap[0][i] = (u_char)rgbmap[i][0]&0xff;
503 colormap[1][i] = (u_char)rgbmap[i][1]&0xff;
504 colormap[2][i] = (u_char)rgbmap[i][2]&0xff;
506 sprintf(buf,
"getsun.c%1d",
levels);
507 pw_setcmsname(pw, buf);
508 pw_putcolormap(pw, 0, 4<<levels,colormap[0],colormap[1],colormap[2]);
525 for ( i = 0; i <
levelsc; i++ )
527 colormap[0][i] = (u_char)bwmap[i]&0xff;
528 colormap[1][i] = (u_char)bwmap[i]&0xff;
529 colormap[2][i] = (u_char)bwmap[i]&0xff;
531 sprintf(buf,
"getsun.g%1d",
levels);
532 pw_setcmsname(pw, buf);
533 pw_putcolormap(pw, 0,4<<levels, colormap[0],colormap[1],colormap[2]);
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_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
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)
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)
void bwdithermap(int levels, double gamma, bwmap, divN, modN, magic)
#define RLE_CHECK_ALLOC(pgm, ptr, name)