2 static char sccsid[] =
"@(#)gettaac.c 1.2 7/5/90 Copyright (c) 1989, 1990\
3 by Southwest Research Institute, San Antonio, Texas";
31 #include <suntool/sunview.h>
32 #include <suntool/panel.h>
33 #include <suntool/canvas.h>
34 #include <sunwindow/win_cursor.h>
35 #include <sunwindow/notify.h>
36 #include <sys/types.h>
42 #include <taac1/taio.h>
44 #define MAX_FILE_NAME 1024
45 #define FONT "/usr/lib/fonts/fixedwidthfonts/serif.r.14"
58 static void init_panel();
64 static void read_file();
65 static void format_select();
66 static void make_new_name();
69 static void init_color_map();
70 static void bw_init_colors();
71 static void init_canvas();
74 static struct pixfont *pixfont;
79 #include "gettaac.icon"
82 DEFINE_ICON_FROM_IMAGE(gettaac_icon, icon_image);
93 static void read_file_rgb();
94 static void read_file_gray();
95 static void read_file_bw();
100 static Notify_value taac_interposer();
108 struct pixrect *screen;
112 pixfont = pf_open(
FONT);
114 if (pixfont == NULL) {
115 fprintf(stderr,
"Can't open the font %s\n",
FONT);
120 if((tahandle = ta_open(0))==NULL){
121 fprintf(stderr,
"ta_open failed.\n");
125 if (ta_init(tahandle) == TA_FAILURE) {
126 fprintf(stderr,
"error initializing taac\n");
130 ta_set_video(tahandle,TA_VIDEO_MIXEDTAAC,TA_SYNC_EXTERNAL);
134 base_frame = window_create(0, FRAME,
135 FRAME_ICON, &gettaac_icon,
136 FRAME_ARGC_PTR_ARGV, &argc, argv,
139 init_panel(base_frame);
142 canvas = window_create(base_frame, CANVAS,
145 CANVAS_AUTO_SHRINK, FALSE,
148 window_fit(base_frame);
150 ta_taac_canvas(tahandle, base_frame, canvas);
152 window_main_loop(base_frame);
159 init_panel(base_frame)
163 panel = window_create(base_frame, PANEL,
165 PANEL_LABEL_BOLD, TRUE,
168 panel_create_item(panel, PANEL_BUTTON,
169 PANEL_ITEM_X, ATTR_COL(1),
170 PANEL_ITEM_Y, ATTR_ROW(0) + 4,
171 PANEL_LABEL_IMAGE, panel_button_image(panel,
"EXIT", 4, 0),
172 PANEL_NOTIFY_PROC, doexit,
175 panel_create_item(panel, PANEL_BUTTON,
176 PANEL_ITEM_X, ATTR_COL(8),
177 PANEL_ITEM_Y, ATTR_ROW(0) + 4,
178 PANEL_LABEL_IMAGE, panel_button_image(panel,
"LOAD", 4, 0),
179 PANEL_NOTIFY_PROC, read_file,
182 panel_create_item(panel, PANEL_CHOICE,
183 PANEL_ITEM_X, ATTR_COL(15),
184 PANEL_ITEM_Y, ATTR_ROW(0) + 4,
185 PANEL_CHOICE_STRINGS,
"RGB",
"Gray", 0,
186 PANEL_NOTIFY_PROC, format_select,
189 gamma_item = panel_create_item(panel, PANEL_TEXT,
190 PANEL_ITEM_X, ATTR_COL(30),
191 PANEL_ITEM_Y, ATTR_ROW(0) + 8,
192 PANEL_VALUE_DISPLAY_LENGTH, 4,
193 PANEL_LABEL_STRING,
"Gamma:",
197 file_name = panel_create_item(panel, PANEL_TEXT,
198 PANEL_ITEM_X, ATTR_COL(42),
199 PANEL_ITEM_Y, ATTR_ROW(0) + 8,
200 PANEL_LABEL_STRING,
"File:",
202 PANEL_NOTIFY_PROC, make_new_name,
204 PANEL_NOTIFY_STRING,
"\033\t\r",
205 PANEL_VALUE_DISPLAY_LENGTH, 14,
208 window_set(panel, PANEL_CARET_ITEM, file_name, 0);
236 filename = (
char *)panel_get_value(file_name);
238 rle_names( &hdr, my_name, filename );
240 if (*filename ==
'\0') {
243 get_full_path(filename, full_path);
244 if ((fp = fopen(full_path,
"r")) == NULL) {
245 fprintf(stderr,
"Can't open file ->%s<-\n", full_path);
256 read_file_gray(&hdr);
268 unsigned char *scan[3];
269 register unsigned char *r, *g, *b;
271 unsigned char *rmap, *gmap, *bmap;
283 for (i = 0; i < 3; i++)
284 scan[i] = (
unsigned char *) malloc(x_size);
289 if (sscanf((
char *)panel_get_value(gamma_item),
"%lf", &gamma) != 1)
294 rmap = &(in_cmap[0][0]);
295 gmap = &(in_cmap[1][0]);
296 bmap = &(in_cmap[2][0]);
304 ta_write2d(tahandle, erase,
X_PIXELS, 1, 0, i);
307 for(x = 0, r = scan[0], g = scan[1], b = scan[2];
308 x < x_size; x++, r++, g++, b++) {
312 ta_write2d(tahandle, scan_line_buffer, min(x_size, 1024), 1, 0, y_size - y);
317 for (i = 0; i < 3; i++)
326 unsigned char *scan[3];
327 register unsigned char *r, *g, *b;
328 register int x, value;
332 int x_size, y_size, y;
342 for (i = 0; i < 3; i++)
343 scan[i] = (
unsigned char *) malloc(x_size);
348 if (sscanf((
char *)panel_get_value(gamma_item),
"%lf", &gamma) != 1)
353 map = &(in_cmap[0][0]);
359 ta_write2d(tahandle, erase,
X_PIXELS, 1, 0, i);
362 for(x = 0, r = scan[0], g = scan[1], b = scan[2];
363 x < x_size; x++, r++, g++, b++) {
364 value = (35*(*r)+55*(*g)+10*(*b)) / 100;
369 ta_write2d(tahandle, scan_line_buffer, min(x_size, 1024), 1, 0, y_size - y);
375 for (i = 0; i < 3; i++)
380 format_select(item, value, event)
430 make_new_name(item, event)
437 strcpy(filename,(
char*)panel_get_value(file_name));
438 if (complete(filename))
440 panel_set(file_name,PANEL_VALUE,filename,0);
450 int complete(template)
461 char twiddleUserCompletion;
463 struct direct *nameEntry;
465 struct passwd *pwdEntry;
471 twiddleUserCompletion= 0;
472 prefix= template+strlen(template);
473 while (*(--prefix) !=
'/' && prefix >= template);
478 if (prefix < template) {
483 if (template[0] ==
'~') {
485 twiddleUserCompletion= 1;
488 strcpy(dirName,
".");
491 else if (prefix == template) {
496 strcpy(dirName,
"/");
504 if (template[0] ==
'~') {
509 if (template[1] ==
'/') {
510 strcpy(dirName, getenv(
"HOME"));
511 if ( &template[1] != prefix )
513 p= dirName+strlen(dirName);
531 for (p= dirName, q= &template[1];
535 if (!(pwdEntry= getpwnam(dirName))) {
538 strcpy(dirName, pwdEntry->pw_dir);
539 p= dirName+strlen(dirName);
551 strncpy(dirName, template, prefix-template);
552 dirName[prefix-template]= 0;
564 pref_len= strlen(prefix);
565 suffix= template + strlen(template);
570 if (!twiddleUserCompletion) {
575 if ((dirChan= opendir(dirName)) == 0) {
582 if (!(nameEntry= readdir(dirChan))) {
585 if (!strncmp(prefix, nameEntry->d_name, pref_len)) {
594 strcpy(suffix, nameEntry->d_name+pref_len);
599 q= nameEntry->d_name+pref_len;
628 if (!(pwdEntry= getpwent())) {
631 if (!strncmp(prefix, pwdEntry->pw_name, pref_len)) {
640 strcpy(suffix, pwdEntry->pw_name+pref_len);
644 q= pwdEntry->pw_name+pref_len;
681 else if (nonUnique) {
694 get_full_path(template,full_path)
699 struct passwd *pwdEntry;
705 if (template[0] ==
'~') {
710 if (template[1] ==
'/') {
711 strcpy(full_path, getenv(
"HOME"));
712 strcat(full_path,&template[1]);
724 for (p= full_path, q= &template[1];
728 if (!(pwdEntry= getpwnam(full_path))) {
731 strcpy(full_path, pwdEntry->pw_dir);
736 strcpy(full_path,template);
static Panel_item gamma_item
char * cmd_name(char **argv)
void main(int argc, char **argv)
int rle_getrow(rle_hdr *the_hdr, scanline)
rle_pixel ** buildmap(rle_hdr *the_hdr, int minmap, double orig_gamma, double new_gamma)
static unsigned char green[256]
static unsigned int * scan_line_buffer
static unsigned char blue[256]
void rle_get_setup_ok(rle_hdr *the_hdr, const char *prog_name, const char *file_name)
static Panel_item file_name
#define RLE_CLR_BIT(glob, bit)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
static short icon_image[]
static unsigned char red[256]