home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3027 < prev    next >
Encoding:
Internet Message Format  |  1991-03-09  |  55.6 KB

  1. From: matthew@sunpix.East.Sun.COM (Matthew Stier - Sun Visualization Products)
  2. Newsgroups: alt.sources
  3. Subject: Vue v1.2, A Sunview rasterfile display utility
  4. Message-ID: <553@sunpix.East.Sun.COM>
  5. Date: 8 Mar 91 21:25:49 GMT
  6.  
  7.  
  8. After receiving a few bug notices, I have fixed 'vue', and am reposting
  9. it in its entirety.
  10.  
  11. Note: For those looking for a Sunview 'GIF' display program, this is what
  12. you are looking for.  Matter of fact, 'vue' will display any file format
  13. that there is a whatever_to_ras filter for.
  14.  
  15.  
  16. ---- Cut Here and unpack ----
  17. #!/bin/sh
  18. # shar:    Shell Archiver  (v1.25)
  19. #    Packed Fri Mar  8 16:18:24 EST 1991 by gumbo!matthew
  20. #    from directory /home/matthew/.bin/src/Sunview/Vue
  21. #
  22. #    Run the following text with /bin/sh to create:
  23. #      Makefile
  24. #      hglass.cursor
  25. #      vue.c
  26. #      vue.h
  27. #      vue.icon
  28. #      vue.man
  29. #      gif2ras.c
  30. #      gif2ras.man
  31. #
  32. if test -f Makefile; then echo "File Makefile exists"; else
  33. echo "x - extracting Makefile (Text)"
  34. sed 's/^X//' << 'SHAR_EOF' > Makefile &&
  35. X#
  36. X# Makefile for 'vue'
  37. X#
  38. X# Note: Pre-SunOS 4.x.x machines do not support Frame props.
  39. X#       To compile on Pre-SunOS 4.x.x machines, delete '-DFRAME_PROPS'
  40. X#       from the 'CFLAGS' definition line, or override the 'CFLAGS' 
  41. X#       definition line with a command-line definition.
  42. X#
  43. X
  44. XCFLAGS    = -O -DFRAME_PROPS
  45. XLDFLAGS    = -s
  46. XLDLIBS    = -lsuntool -lsunwindow -lpixrect
  47. X
  48. Xvue:
  49. X
  50. Xgif2ras:
  51. X
  52. Xlint:
  53. X    $(LINT) vue.c $(LDLIBS) 
  54. X
  55. Xclean:
  56. X    $(RM) a.out core *.o
  57. X
  58. Xrealclean: clean
  59. X    $(RM) vue
  60. X
  61. SHAR_EOF
  62. chmod 0777 Makefile || echo "restore of Makefile fails"
  63. fi
  64. if test -f hglass.cursor; then echo "File hglass.cursor exists"; else
  65. echo "x - extracting hglass.cursor (Text)"
  66. sed 's/^X//' << 'SHAR_EOF' > hglass.cursor &&
  67. X/* Format_version=1, Width=16, Height=16, Depth=1, Valid_bits_per_item=16
  68. X */
  69. X    0x7FFE,0x4002,0x200C,0x1A38,0x0FF0,0x07E0,0x03C0,0x0180,
  70. X    0x0180,0x0240,0x0520,0x0810,0x1108,0x23C4,0x47E2,0x7FFE
  71. SHAR_EOF
  72. chmod 0644 hglass.cursor || echo "restore of hglass.cursor fails"
  73. fi
  74. if test -f vue.c; then echo "File vue.c exists"; else
  75. echo "x - extracting vue.c (Text)"
  76. sed 's/^X//' << 'SHAR_EOF' > vue.c &&
  77. X#ifndef lint
  78. Xstatic char author[] = "matthew.stier@east.sun.com";
  79. Xstatic char patchlevel[] = "Vue: Release 1, Patchlevel 2";
  80. X/* 
  81. X** Release 1.2: Fix Patch 1, and enable Sunview command line arguments
  82. X**   Problem(s) noted by jwm@sun4.jhuapl.edu:
  83. X**     Vue does not recognize standard tool arguments
  84. X**   Problem(s) noted by lwv27@CAS.Bitnet
  85. X**     Patch 1 syntax problem
  86. X** Release 1.1: Make 'vue' SunOS 3.5 compatible 
  87. X**   Problem(s) noted by jwm@sun4.jhuapl.edu:
  88. X**     SunOS 3.5 does not support the 'props' option in frame menu.
  89. X**     SunOS 3.5 does not support 'event_action()' macro.
  90. X** Release 1.0: Initial release
  91. X*/
  92. X#endif /* lint */
  93. X
  94. X/* Define general items */
  95. X#define PROGRAMNAME     "vue"
  96. X#define ICON            "vue.icon"
  97. X#define CURSOR          "hglass.cursor"
  98. X#define DEFAULT_LABEL   "(hit right mouse button for menu)"
  99. X
  100. X/* Get #include */
  101. X#include <stdio.h>
  102. X#include <malloc.h>
  103. X#include <strings.h>
  104. X#include <sys/param.h>
  105. X#include <suntool/sunview.h>
  106. X#include <suntool/canvas.h>
  107. X#include <suntool/panel.h>
  108. X#include <suntool/scrollbar.h>
  109. X#include <suntool/expand_name.h>
  110. X#include <sunwindow/cms_mono.h>
  111. X#include "vue.h"
  112. X
  113. X/* Load the icon */
  114. Xstatic short icon_image[] = {
  115. X#include ICON
  116. X};
  117. Xmpr_static(icon_pixrect, 64, 64, 1, icon_image);
  118. X
  119. X/* Load the hour_glass cursor */
  120. Xstatic short cursor_image[] = {
  121. X#include CURSOR
  122. X};
  123. Xmpr_static(cursor_pixrect, 16, 16, 1, cursor_image);
  124. X
  125. X/* Define functions */
  126. Xint main();
  127. Xvoid frame_event();
  128. Xint show();
  129. Xvoid canvas_repaint(); 
  130. Xvoid update_canvas_menu();
  131. Xvoid set_frame_label();
  132. Xchar *basename();
  133. Xvoid create_control_panel();
  134. Xvoid control_panel_proc();
  135. Xvoid control_panel_done();
  136. Xvoid selection_update();
  137. Xvoid filter_update();
  138. XPixrect *load_pixrect();
  139. XPixrect *convert8to1();
  140. XPixrect *convert32to1();
  141. XPixrect *convert32to8();
  142. XPixrect *convert8to32();
  143. Xvoid init_colormap32();
  144. X
  145. X/* Define variables */
  146. Xstatic Icon icon;
  147. Xstatic Cursor hglass_cursor;
  148. Xstatic Frame frame;
  149. Xstatic Frame control_frame;
  150. Xstatic Canvas canvas;
  151. Xstatic Pixwin *pw;
  152. Xstatic Pixrect *pr  = 0;
  153. Xstatic Menu canvas_menu = 0;
  154. Xstatic Panel control_panel;
  155. Xstatic Panel_item fname_item;
  156. Xstatic Panel_item filter_item;
  157. Xstatic Panel_item order_item;
  158. Xstatic int where = 0;
  159. Xstatic int skip  = 0;
  160. Xstatic int nitems;
  161. Xstatic int max_depth;
  162. Xstatic char directory[MAXPATHLEN];
  163. Xstatic char *programname = PROGRAMNAME;
  164. Xstatic char *filter = "";
  165. Xstatic char current_image[MAXPATHLEN + 256];
  166. Xstatic char **filename = 0;
  167. Xstruct namelist *name_list;
  168. X
  169. X/* Define constants */
  170. X#define ERROR_PAUSE  2
  171. X#define ESCAPE_KEY   '\033'
  172. X
  173. Xint
  174. Xmain(argc, argv)
  175. Xint argc;
  176. Xchar *argv[];
  177. X{
  178. X    int getpid();
  179. X    char *getwd();
  180. X    char *sprintf();
  181. X
  182. X    /* Set 'programname' */
  183. X    if ( argc && *basename(argv[0]) != '\0')
  184. X        programname = basename(argv[0]);
  185. X
  186. X    icon = icon_create(ICON_IMAGE, &icon_pixrect,
  187. X        ICON_LABEL,  0,
  188. X        ICON_WIDTH,  icon_pixrect.pr_size.x,
  189. X        ICON_HEIGHT, icon_pixrect.pr_size.y,
  190. X        0);
  191. X
  192. X    /* Create the hourglass cursor */
  193. X    hglass_cursor = cursor_create(CURSOR_IMAGE, &cursor_pixrect, 0);
  194. X
  195. X    /* Create the frame */
  196. X    frame = window_create((Window) 0, FRAME,
  197. X        FRAME_ARGC_PTR_ARGV,     &argc, argv,
  198. X        FRAME_ICON,              icon,
  199. X#ifdef FRAME_PROPS
  200. X        FRAME_PROPS_ACTIVE,      TRUE,
  201. X        FRAME_PROPS_ACTION_PROC, control_panel_proc,
  202. X#endif /* FRAME_PROPS */
  203. X        WIN_ERROR_MSG,            "Couldn't create frame",
  204. X        0);
  205. X
  206. X    /* Exit program if unable to create frame */
  207. X    if (frame == 0) 
  208. X        return(1);
  209. X
  210. X    /* Set frame label to default label */
  211. X    (void) strcpy(current_image, DEFAULT_LABEL);
  212. X    set_frame_label("%s: %s", current_image);
  213. X
  214. X    /* Create the canvas */
  215. X    canvas = window_create(frame, CANVAS,
  216. X        CANVAS_AUTO_EXPAND,       FALSE,
  217. X        CANVAS_AUTO_SHRINK,       FALSE,
  218. X        CANVAS_AUTO_CLEAR,        FALSE,
  219. X        CANVAS_RETAINED,          FALSE,
  220. X        CANVAS_REPAINT_PROC,      canvas_repaint,
  221. X        WIN_EVENT_PROC,           frame_event,
  222. X        WIN_CONSUME_KBD_EVENT,    WIN_ASCII_EVENTS,
  223. X        WIN_ERROR_MSG,            "Couldn't create canvas",
  224. X        WIN_HORIZONTAL_SCROLLBAR, scrollbar_create(SCROLL_LINE_HEIGHT, 1, 0),
  225. X        WIN_VERTICAL_SCROLLBAR,   scrollbar_create(SCROLL_LINE_HEIGHT, 1, 0),
  226. X        0);
  227. X
  228. X    /* Exit program if unable to create canvas */
  229. X    if (canvas == 0)
  230. X        return(1);
  231. X
  232. X    /* Get the pixwin for the canvas */
  233. X    pw = canvas_pixwin(canvas);
  234. X
  235. X    /* determine max depth of the pixwin */
  236. X    max_depth = pw->pw_pixrect->pr_depth;
  237. X
  238. X#ifdef CANVAS_COLOR24 /* If CANVAS_COLOR24 not declared, its not supported */
  239. X    /* Set 24-bit color mode if the frame buffer is deep enough */
  240. X    if (max_depth == 24 || max_depth == 32)
  241. X        window_set(canvas, CANVAS_COLOR24, TRUE, 0);
  242. X#endif /* CANVAS_COLOR24 */
  243. X
  244. X    /* Create a control panel */
  245. X    create_control_panel();
  246. X
  247. X    /* Search command line for options */
  248. X    while (argc > 1 && argv[1][0] == '-') {    
  249. X        switch (argv[1][1]) {
  250. X            case 'f': /* If filter specified, get filter name */
  251. X                if ( argv[1][2] )  {
  252. X                    filter = &argv[1][2];
  253. X                } else {
  254. X                    if ( argc > 2 ) {
  255. X                        filter = argv[2];
  256. X                        argc--;
  257. X                        argv++;
  258. X                    }
  259. X                }
  260. X                    break;
  261. X            default: /* invalid option, complain */
  262. X                (void) fprintf(stderr, 
  263. X                    "Usage: %s [-f filter] [file]....\n", 
  264. X                    programname);
  265. X                return(1);
  266. X        }
  267. X        argc--;
  268. X        argv++;
  269. X    }
  270. X
  271. X    /* Set default fname_item for control panel */
  272. X    if (argc > 1 && basename(argv[1]) != argv[1]) {
  273. X        (void) strcpy(directory, argv[1]);
  274. X        (void) strcpy(basename(directory), "*");
  275. X    } else {
  276. X        (void) getwd(directory);
  277. X        (void) strcat(directory, "/*");
  278. X    }
  279. X        
  280. X    /* Create the icon  */
  281. X    /* Create a selection menu from the remaining items */
  282. X    update_canvas_menu(--argc, ++argv);
  283. X
  284. X    /* Start main program loop */
  285. X    (void) window_main_loop(frame);
  286. X
  287. X    /* Exit program successfully */
  288. X    return(0);
  289. X}
  290. X
  291. Xvoid
  292. Xframe_event(window, event, arg)
  293. X    Window window;
  294. X    Event *event;
  295. X    caddr_t arg;
  296. X{
  297. X
  298. X    int item;
  299. X
  300. X    /* If a mouse button is pressed inside the canvas, do its action */
  301. X    if (event_is_button(event) && event_is_down(event)) {
  302. X        switch(event_id(event)) {
  303. X            case MS_LEFT:   /* Goto previous image */
  304. X                skip  = (skip > 0 ? -1 : skip - 1);
  305. X                item  = (where ? where + skip : 1 + skip);
  306. X                item += (item <      1 ? nitems : 0);
  307. X                break;
  308. X            case MS_MIDDLE: /* Goto next image */
  309. X                skip  = (skip < 0 ?  1 : skip + 1);
  310. X                item  = where + skip;
  311. X                item -= (item > nitems ? nitems : 0);
  312. X                break;
  313. X            case MS_RIGHT:  /* Got to selected image */
  314. X                item = (int) menu_show(canvas_menu, canvas,
  315. X                    canvas_window_event(canvas, event), 0);
  316. X                skip = 0;
  317. X                break;
  318. X            default:
  319. X                break;
  320. X        }
  321. X
  322. X        /* If it is a valid 'item', load the file */
  323. X        if (item > 0 && item <= nitems && item != where ) {
  324. X            /* Announce you are loading a new image */
  325. X            set_frame_label("%s: %s (Loading)", filename[item - 1]);
  326. X            /* Show new file */
  327. X            if (show(filename[item - 1])) {
  328. X                /* Set "where" pointer to image being shown */
  329. X                where = item;
  330. X                /* Zero out the skip_image counter */
  331. X                skip = 0;
  332. X                /* Syncronize MS_RIGHT menu to image being shown */
  333. X                (void) menu_set(canvas_menu, MENU_SELECTED, item, 0);
  334. X                /* Create new title bar */
  335. X                (void) sprintf(current_image, "%s (%d x %d x %d)", 
  336. X                    filename[item - 1],
  337. X                    pr->pr_size.x, pr->pr_size.y, pr->pr_depth);
  338. X            } else {
  339. X                /* Report problem loading image */
  340. X                set_frame_label("%s: Error loading '%s'", filename[item - 1]);
  341. X                /* Pause so people can read it */
  342. X                sleep(ERROR_PAUSE);
  343. X            }
  344. X            /* Update the frame label */
  345. X            set_frame_label("%s: %s", current_image);
  346. X        }
  347. X    } else {
  348. X        /* if the escape key is pressed, open the control panel */
  349. X        if (event_id(event) == ESCAPE_KEY)
  350. X            control_panel_proc();
  351. X        /* handle all other canvas events */
  352. X        (void) window_default_event_proc(window, event, arg); 
  353. X    }
  354. X}
  355. X
  356. Xint
  357. Xshow(name)
  358. X    char *name;
  359. X{
  360. X    /* Define functions */
  361. X    char *sprintf();
  362. X
  363. X    /* Define local variables */
  364. X    Cursor current_cursor;
  365. X    char cmsname[CMS_NAMESIZE];
  366. X    colormap_t cm;
  367. X    Pixrect *new_pr = 0;
  368. X
  369. X    /* Get the current cursor */
  370. X    current_cursor = (Cursor) window_get(canvas,WIN_CURSOR);
  371. X
  372. X    /* Change cursor to hour glass */
  373. X    (void) window_set(canvas,WIN_CURSOR,hglass_cursor,0);
  374. X
  375. X    /* Load image into pixrect */
  376. X    new_pr = load_pixrect(name, &cm);
  377. X
  378. X    /* If an error in reading the file, return cursor to normal and return */
  379. X    if (!new_pr) {
  380. X        (void) window_set(canvas, WIN_CURSOR, current_cursor, 0);
  381. X        return (0);
  382. X    }
  383. X
  384. X    /* Check pixrect depth against canvas depth, process where necessary */
  385. X    switch (max_depth) {
  386. X        case  1:
  387. X            switch (new_pr->pr_depth) {
  388. X                case  1:
  389. X                    break;
  390. X                case  8:
  391. X                    new_pr = convert8to1(new_pr, &cm);
  392. X                    break;
  393. X                case 32:
  394. X                    new_pr = convert32to1(new_pr, &cm);
  395. X                    break;
  396. X                default:
  397. X                    pr_destroy(new_pr);
  398. X                    new_pr = (Pixrect *) 0;
  399. X                    break;
  400. X            }
  401. X            break;
  402. X        case  8:
  403. X            switch (new_pr->pr_depth) {
  404. X                case  1:
  405. X                    break;
  406. X                case  8:
  407. X                    break;
  408. X                case 32:
  409. X                    new_pr = convert32to8(new_pr, &cm);
  410. X                    break;
  411. X                default:
  412. X                    pr_destroy(new_pr);
  413. X                    new_pr = (Pixrect *) 0;
  414. X                    break;
  415. X            }
  416. X            break;
  417. X        case 24:
  418. X            switch (new_pr->pr_depth) {
  419. X                case  1:
  420. X                    pr_destroy(new_pr);
  421. X                    new_pr = (Pixrect *) 0;
  422. X                    break;
  423. X                case  8:
  424. X                    pr_destroy(new_pr);
  425. X                    new_pr = (Pixrect *) 0;
  426. X                    break;
  427. X                case 32:
  428. X                    pr_destroy(new_pr);
  429. X                    new_pr = (Pixrect *) 0;
  430. X                    break;
  431. X                default:
  432. X                    pr_destroy(new_pr);
  433. X                    new_pr = (Pixrect *) 0;
  434. X                    break;
  435. X            }
  436. X            break;
  437. X        case 32:
  438. X            switch (new_pr->pr_depth) {
  439. X                case  1:
  440. X                    break;
  441. X                case  8:
  442. X                    new_pr = convert8to32(new_pr, &cm);
  443. X                    break;
  444. X                case 32:
  445. X                    break;
  446. X                default:
  447. X                    pr_destroy(new_pr);
  448. X                    new_pr = (Pixrect *) 0;
  449. X                    break;
  450. X            }
  451. X            break;
  452. X        default:
  453. X            pr_destroy(new_pr);
  454. X            new_pr = (Pixrect *) 0;
  455. X            break;
  456. X    }
  457. X
  458. X    /* If an error in converting the file, return cursor to normal and return */
  459. X    if (!new_pr) {
  460. X        (void) window_set(canvas, WIN_CURSOR, current_cursor, 0);
  461. X        return (0);
  462. X    }
  463. X
  464. X    /* Set colormaps */
  465. X    switch (new_pr->pr_depth) {
  466. X        case 1:
  467. X            (void) pw_setcmsname(pw, CMS_MONOCHROME); 
  468. X            break;
  469. X        case 8:
  470. X            switch (cm.type) {
  471. X                case RMT_EQUAL_RGB:
  472. X                    (void) sprintf(cmsname, "rs-%05d-%03d", 
  473. X                        getpid(), cm.length);
  474. X                    (void) pw_setcmsname(pw, cmsname); 
  475. X                    (void) pw_putcolormap(pw, 0, cm.length,
  476. X                        cm.map[0], cm.map[1], cm.map[2]);
  477. X                    break;
  478. X                default:
  479. X                    break;
  480. X            }
  481. X        case 32:
  482. X            break;
  483. X        default:
  484. X            break;
  485. X    }
  486. X
  487. X    /* Blank the canvas */
  488. X    (void) pw_writebackground(pw, 0, 0, 
  489. X        pw->pw_pixrect->pr_size.x, pw->pw_pixrect->pr_size.y, PIX_SRC);
  490. X
  491. X    /* Resize the new canvas */
  492. X    (void) window_set(canvas, 
  493. X        CANVAS_WIDTH,  new_pr->pr_size.x, 
  494. X        CANVAS_HEIGHT, new_pr->pr_size.y, 
  495. X        0);
  496. X    
  497. X    /* Write the image to the canvas */
  498. X    (void) pw_write(pw, 0, 0, 
  499. X        new_pr->pr_size.x, new_pr->pr_size.y, PIX_SRC, new_pr, 0, 0);
  500. X
  501. X    /* All finished. Clean up and return success */
  502. X    if (pr)
  503. X        pr_destroy(pr);
  504. X    pr = new_pr;
  505. X    (void) window_set(canvas, WIN_CURSOR, current_cursor, 0);
  506. X    return(1);
  507. X}
  508. X
  509. X/*ARGSUSED*/
  510. Xvoid
  511. Xcanvas_repaint(canvas, pw, area)
  512. XCanvas canvas;
  513. XPixwin *pw;
  514. XRectlist *area;
  515. X{
  516. X    if (pr) {
  517. X        /* Repaint the image */
  518. X        (void) pw_write(pw, 0, 0, 
  519. X            pr->pr_size.x, pr->pr_size.y, PIX_SRC, pr, 0, 0);
  520. X    } else {
  521. X        /* Blank the canvas */
  522. X        (void) pw_writebackground(pw, 0, 0, 
  523. X            pw->pw_pixrect->pr_size.x, pw->pw_pixrect->pr_size.y, PIX_SRC);
  524. X    }
  525. X}
  526. X
  527. Xvoid
  528. Xupdate_canvas_menu(argc, argv)
  529. Xint argc;
  530. Xchar **argv;
  531. X{
  532. X    int index;
  533. X
  534. X    /* Destroy the old menu */    
  535. X    if (canvas_menu != 0)
  536. X        menu_destroy(canvas_menu);
  537. X    
  538. X    /* Create a new one     */
  539. X    canvas_menu = menu_create(0);
  540. X
  541. X    /* and fill it in       */
  542. X    for (index = 0; index < argc; index++)
  543. X        (void) menu_set(canvas_menu, MENU_STRING_ITEM, 
  544. X            argv[index], index + 1, 0);
  545. X
  546. X    /* and set some variables for frame_event() */
  547. X    skip =0;
  548. X    where = 0;
  549. X    nitems = argc;
  550. X    filename = argv;
  551. X}
  552. X
  553. Xvoid
  554. Xset_frame_label(format, filename)
  555. Xchar *format;
  556. Xchar *filename;
  557. X{
  558. X    char *sprintf();
  559. X    char *title[MAXPATHLEN];
  560. X
  561. X    /* create the label */
  562. X    (void) sprintf(title, format, programname, filename);
  563. X    /* send it to the frame */
  564. X    (void) window_set(frame, FRAME_LABEL, title, 0);
  565. X}
  566. X
  567. Xchar *
  568. Xbasename(pn)
  569. Xchar *pn;      /* pointer to pathname */
  570. X{
  571. X    char *sp;  /* search pointer */
  572. X    
  573. X    /* set search pointer to the start of pathname */
  574. X    sp = pn;
  575. X
  576. X    /* search pathname for last delimeter */
  577. X    while ( *sp != '\0' ) {
  578. X        if ( *sp++ == '/' )
  579. X            pn = sp; 
  580. X    }
  581. X
  582. X    /* return the basename */
  583. X    return(pn);
  584. X}
  585. X
  586. Xvoid
  587. Xcreate_control_panel()
  588. X{
  589. X
  590. X    control_frame = window_create(frame, FRAME, 
  591. X        FRAME_LABEL,      programname,
  592. X        FRAME_SHOW_LABEL, TRUE,
  593. X        WIN_SHOW,         FALSE, 
  594. X        0);
  595. X
  596. X    control_panel = window_create(control_frame, PANEL, 0); 
  597. X
  598. X    fname_item = panel_create_item(control_panel, PANEL_TEXT,
  599. X        PANEL_LABEL_Y,              ATTR_ROW(0),
  600. X        PANEL_LABEL_X,              ATTR_COL(0),
  601. X        PANEL_VALUE_DISPLAY_LENGTH, 32,
  602. X        PANEL_LABEL_STRING,         "File:  ",
  603. X        PANEL_VALUE,                directory,
  604. X        0);
  605. X
  606. X    (void) panel_create_item(control_panel, PANEL_BUTTON,
  607. X        PANEL_LABEL_X,              ATTR_COL(42),
  608. X        PANEL_LABEL_IMAGE, panel_button_image(control_panel, 
  609. X            "Update Menu", 15, (Pixfont *) 0),
  610. X        PANEL_NOTIFY_PROC, selection_update,
  611. X        0);
  612. X
  613. X    filter_item = panel_create_item(control_panel, PANEL_TEXT,
  614. X        PANEL_LABEL_Y,              ATTR_ROW(1),
  615. X        PANEL_LABEL_X,              ATTR_COL(0),
  616. X        PANEL_VALUE_DISPLAY_LENGTH, 32,
  617. X        PANEL_LABEL_STRING,         "Filter:",
  618. X        PANEL_VALUE,                filter,
  619. X        0);
  620. X
  621. X    (void) panel_create_item(control_panel, PANEL_BUTTON,
  622. X        PANEL_LABEL_X,              ATTR_COL(42),
  623. X        PANEL_LABEL_IMAGE,          panel_button_image(control_panel, 
  624. X                                        "Update filter", 15, (Pixfont *) 0),
  625. X        PANEL_NOTIFY_PROC,          filter_update,
  626. X        0);
  627. X
  628. X    order_item = panel_create_item(control_panel, PANEL_CYCLE,
  629. X        PANEL_LABEL_Y,              ATTR_ROW(2),
  630. X        PANEL_LABEL_X,              ATTR_COL(0),
  631. X        PANEL_LABEL_STRING,         "Color ordering:",
  632. X        PANEL_CHOICE_STRINGS,       "rgb", "bgr", 0,
  633. X        0);
  634. X
  635. X    (void) panel_create_item(control_panel, PANEL_BUTTON,
  636. X        PANEL_LABEL_X,              ATTR_COL(42),
  637. X        PANEL_LABEL_IMAGE,          panel_button_image(control_panel, 
  638. X                                       "Done", 15, (Pixfont *) 0),
  639. X        PANEL_NOTIFY_PROC,          control_panel_done,
  640. X        0);
  641. X
  642. X    (void) window_set(control_panel, PANEL_CARET_ITEM, fname_item, 0);
  643. X
  644. X    (void) window_fit(control_panel);
  645. X    (void) window_fit(control_frame);
  646. X
  647. X}
  648. X
  649. Xvoid
  650. Xcontrol_panel_proc()
  651. X{
  652. X    window_set(control_frame, 
  653. X        WIN_X,    50, 
  654. X        WIN_Y,    50, 
  655. X        WIN_SHOW, TRUE,
  656. X        0);
  657. X}
  658. X
  659. Xvoid
  660. Xcontrol_panel_done()
  661. X{
  662. X    window_set(control_frame, WIN_SHOW, FALSE, 0);
  663. X}
  664. X
  665. Xvoid
  666. Xselection_update()
  667. X{
  668. X    static char previous_dir[MAXPATHLEN];
  669. X    char current_dir[MAXPATHLEN];
  670. X    char fname[MAXPATHLEN];
  671. X
  672. X    /* Get a copy of fname_item */
  673. X    (void) strcpy(current_dir, panel_get_value(fname_item));
  674. X    (void) strcpy(fname, current_dir);
  675. X
  676. X    /* Truncate current_dir to the directory component */
  677. X    (void) strcpy(basename(current_dir), "");
  678. X
  679. X    /* Truncate fname to filename only */
  680. X    /* If no filename specified, assume wildcard of '*' */
  681. X    if (!strlen(basename(fname))) {
  682. X        (void) strcat(fname, "*");
  683. X        (void) panel_set_value(fname_item, (caddr_t) fname); 
  684. X    }
  685. X
  686. X    /* Change directories to match fname_item */
  687. X    if (strcmp(previous_dir, current_dir)) {
  688. X        (void) chdir(current_dir);
  689. X        (void) strcpy(previous_dir, current_dir);
  690. X    }
  691. X
  692. X    /* Convert filename to list of files */
  693. X    name_list = expand_name(basename(fname));
  694. X
  695. X    /* Convert the expanded filename to a canvas menu */
  696. X    update_canvas_menu((int) name_list->count, name_list->names);
  697. X}
  698. X
  699. Xvoid
  700. Xfilter_update()
  701. X{
  702. X    /* Get the filter_item value from the control panel */
  703. X    filter = (char *) panel_get_value(filter_item);
  704. X
  705. X    /* Skip leading whitespace */
  706. X    while ( *filter == ' ' || *filter == '\t' ) 
  707. X        filter++; 
  708. X}
  709. X
  710. XPixrect *
  711. Xload_pixrect(name, cm)
  712. Xchar *name;
  713. Xcolormap_t *cm;
  714. X{
  715. X    FILE *inf;
  716. X    Pixrect *tpr;
  717. X    char *cmd;
  718. X    char *cmdfmt = "(%s) < %s";
  719. X
  720. X    /* Load image into pixrect */
  721. X    if (*filter) {
  722. X        /* Allocate enough space to create commandline */
  723. X        cmd = (char *) malloc((unsigned) 
  724. X            (strlen(cmdfmt) + strlen(filter) + strlen(name)));
  725. X        /* Verify allocation of commandline space */
  726. X        if (cmd) {
  727. X            /* Load image by piping the file thru a filter */
  728. X            (void) sprintf(cmd, cmdfmt, filter, name);
  729. X            if (!(inf = popen(cmd, "r")))
  730. X                return((Pixrect *) 0);
  731. X            tpr = pr_load(inf, cm);
  732. X            if (pclose(inf))
  733. X                tpr = (Pixrect *) 0;
  734. X            (void) free(cmd);
  735. X        } else {
  736. X            (void) fprintf(stderr, 
  737. X                "Error allocating space for filter commandline");
  738. X        }
  739. X    } else {
  740. X        if (!(inf = fopen(name, "r")))
  741. X            return((Pixrect *) 0);
  742. X        tpr = pr_load(inf, cm);
  743. X        if (fclose(inf))
  744. X            tpr = (Pixrect *) 0;
  745. X    }
  746. X
  747. X    /* And return */
  748. X    return(tpr);
  749. X}
  750. X
  751. XPixrect *
  752. Xconvert8to1(pr8, cm)
  753. XPixrect *pr8;
  754. Xcolormap_t *cm;
  755. X{
  756. X    /* Define function variables */
  757. X    Pixrect *pr1;
  758. X    unsigned char *cm1 = 0;
  759. X    int x, y, pixel8, pixel1;
  760. X    unsigned long avg = 0;
  761. X
  762. X    /* Create an 1-bit pixrect */
  763. X    pr1 = mem_create(pr8->pr_size.x, pr8->pr_size.y, 1);
  764. X
  765. X    /* Verify creation of mem_rect */
  766. X    if (!pr1) {
  767. X        pr_destroy(pr8);
  768. X        return((Pixrect *) 0);
  769. X    }
  770. X
  771. X    /* Convert the 8-bit pixrect to an 1-bit pixrect */
  772. X    for (y = 0; y < pr8->pr_size.y; y++) {
  773. X        for (x = 0; x < pr8->pr_size.x; x++) {
  774. X            pixel8 = pr_get(pr8, x, y);
  775. X            pixel1 = (ntscr[cm->map[0][pixel8]] + 
  776. X                      ntscg[cm->map[1][pixel8]] + 
  777. X                      ntscb[cm->map[2][pixel8]])/256;
  778. X            pixel1 = pixel1 <= dither_table[y%16][x%16];
  779. X            pr_put(pr1, x, y, pixel1);
  780. X        }
  781. X    }
  782. X
  783. X    /* Destroy the old pixrect, and return the new */
  784. X    pr_destroy(pr8);
  785. X    return(pr1);
  786. X}
  787. X
  788. XPixrect *
  789. Xconvert32to1(pr32, cm)
  790. XPixrect *pr32;
  791. Xcolormap_t *cm;
  792. X{
  793. X    /* Define function variables */
  794. X    Pixrect *pr1;
  795. X    unsigned char *cm1 = 0;
  796. X    int x, y, blu_shift, grn_shift, red_shift, pixel32, pixel1;
  797. X
  798. X    /* Create an 1-bit pixrect */
  799. X    pr1 = mem_create(pr32->pr_size.x, pr32->pr_size.y, 1);
  800. X
  801. X    /* Verify creation of mem_rect */
  802. X    if (!pr1) {
  803. X        pr_destroy(pr32);
  804. X        return((Pixrect *) 0);
  805. X    }
  806. X
  807. X    /* Set pixel shift value in accordance with the panel selection */
  808. X    switch ((int) panel_get_value(order_item)) {
  809. X        case 0: /* rgb */
  810. X            blu_shift =  0;
  811. X            grn_shift =  8;
  812. X            red_shift = 16;
  813. X            break;
  814. X        case 1: /* bgr */
  815. X            blu_shift = 16;
  816. X            grn_shift =  8;
  817. X            red_shift =  0;
  818. X            break;
  819. X        default: /* rgb */
  820. X            blu_shift =  0;
  821. X            grn_shift =  8;
  822. X            red_shift = 16;
  823. X            break;
  824. X    }
  825. X
  826. X    /* Convert the 32-bit pixrect to an 1-bit pixrect */
  827. X    for (y = 0; y < pr32->pr_size.y; y++) {
  828. X        for (x = 0; x < pr32->pr_size.x; x++) {
  829. X            pixel32 = pr_get(pr32, x, y);
  830. X            pixel1 = (ntscb[((pixel32 >> blu_shift) & 0xff)] + 
  831. X                      ntscg[((pixel32 >> grn_shift) & 0xff)] + 
  832. X                      ntscr[((pixel32 >> red_shift) & 0xff)])/256;
  833. X            pixel1 = pixel1 <= dither_table[y%16][x%16];
  834. X            pr_put(pr1, x, y, pixel1);
  835. X        }
  836. X    }
  837. X
  838. X    /* Destroy the old pixrect, and return the new */
  839. X    pr_destroy(pr32);
  840. X    return(pr1);
  841. X}
  842. X
  843. XPixrect *
  844. Xconvert32to8(pr32, cm)
  845. XPixrect *pr32;
  846. Xcolormap_t *cm;
  847. X{
  848. X
  849. X#undef  CM_SIZE
  850. X#define CM_SIZE 256
  851. X#define MAX_BLU   4
  852. X#define BLU_STEP 85    
  853. X#define MAX_GRN   8
  854. X#define GRN_STEP 36    
  855. X#define MAX_RED   8
  856. X#define RED_STEP 36    
  857. X
  858. X    /* Define function variables */
  859. X    int blu_index, grn_index, red_index, cm_index = 0;
  860. X    Pixrect *pr8 = 0;
  861. X    unsigned char *cm8 = 0;
  862. X    int x, y, pixel32, pixel8;
  863. X    int order, blu_shift, grn_shift, red_shift;
  864. X
  865. X    /* Get the space for a colormap */
  866. X    cm8 = (unsigned char *) malloc(CM_SIZE * 3);
  867. X
  868. X    /* Verify allocation of colormap space */
  869. X    if (!cm) {
  870. X        pr_destroy(pr32);
  871. X        return((Pixrect *) 0);
  872. X    }
  873. X
  874. X    /* Create a colormap table */
  875. X    cm->type = RMT_EQUAL_RGB;
  876. X    cm->length = CM_SIZE;
  877. X    cm->map[0] = cm8;
  878. X    cm->map[1] = cm->map[0] + CM_SIZE;
  879. X    cm->map[2] = cm->map[1] + CM_SIZE;
  880. X
  881. X    /* Fill-in the colormap */
  882. X    for (blu_index = 0; blu_index < MAX_BLU; blu_index++) {
  883. X        for (grn_index = 0; grn_index < MAX_GRN; grn_index++) {
  884. X            for (red_index = 0; red_index < MAX_RED; red_index++) {
  885. X                cm->map[0][cm_index] = red_index * RED_STEP;
  886. X                cm->map[1][cm_index] = grn_index * GRN_STEP;
  887. X                cm->map[2][cm_index] = blu_index * BLU_STEP;
  888. X                cm_index++;
  889. X            }
  890. X        }
  891. X    }
  892. X
  893. X    /* Create an 8-bit pixrect */
  894. X    pr8 = mem_create(pr32->pr_size.x, pr32->pr_size.y, 8);
  895. X
  896. X    /* Verify creation of mem_rect */
  897. X    if (!pr8) {
  898. X        pr_destroy(pr32);
  899. X        return((Pixrect *) 0);
  900. X    }
  901. X
  902. X    /* Set pixel shift value in accordance with the panel selection */
  903. X    switch ((int) panel_get_value(order_item)) {
  904. X        case 0: /* rgb */
  905. X            blu_shift =  0;
  906. X            grn_shift = 10;
  907. X            red_shift = 21;
  908. X            break;
  909. X        case 1: /* bgr */
  910. X            blu_shift = 16;
  911. X            grn_shift = 10;
  912. X            red_shift =  5;
  913. X            break;
  914. X        default: /* rgb */
  915. X            blu_shift =  0;
  916. X            grn_shift = 10;
  917. X            red_shift = 21;
  918. X            break;
  919. X    }
  920. X
  921. X    /* Convert the 32-bit pixrect to an 8-bit pixrect */
  922. X    for (y = 0; y < pr32->pr_size.y; y++) {
  923. X        for (x = 0; x < pr32->pr_size.x; x++) {
  924. X            pixel32 = pr_get(pr32, x, y);
  925. X            pixel8 = ((pixel32 >> blu_shift) & 0xc0) | 
  926. X                     ((pixel32 >> grn_shift) & 0x38) |
  927. X                     ((pixel32 >> red_shift) & 0x07);
  928. X            pr_put(pr8, x, y, pixel8);
  929. X        }
  930. X    }
  931. X    /* Destroy the old pixrect, and return the new */
  932. X    pr_destroy(pr32);
  933. X    return(pr8);
  934. X}
  935. X
  936. XPixrect *
  937. Xconvert8to32(pr8, cm)
  938. XPixrect *pr8;
  939. Xcolormap_t *cm;
  940. X{
  941. X    /* Define function variables */
  942. X    Pixrect *pr32 = 0;
  943. X    int x, y, pixel32, pixel8;
  944. X    int order, blu_shift, grn_shift, red_shift;
  945. X
  946. X    /* Create an 32-bit pixrect */
  947. X    pr32 = mem_create(pr8->pr_size.x, pr8->pr_size.y, 32);
  948. X
  949. X    /* Verify creation of mem_rect */
  950. X    if (!pr32) {
  951. X        pr_destroy(pr8);
  952. X        return((Pixrect *) 0);
  953. X    }
  954. X
  955. X    /* Set pixel shift value in accordance with the panel selection */
  956. X    switch ((int) panel_get_value(order_item)) {
  957. X        case 0: /* rgb */
  958. X            blu_shift =  0;
  959. X            grn_shift =  8;
  960. X            red_shift = 16;
  961. X            break;
  962. X        case 1: /* bgr */
  963. X            blu_shift = 16;
  964. X            grn_shift =  8;
  965. X            red_shift =  0;
  966. X            break;
  967. X        default: /* rgb */
  968. X            blu_shift =  0;
  969. X            grn_shift =  8;
  970. X            red_shift = 16;
  971. X            break;
  972. X    }
  973. X
  974. X    /* Convert the 8-bit pixrect to an 32-bit pixrect */
  975. X    for (y = 0; y < pr8->pr_size.y; y++) {
  976. X        for (x = 0; x < pr8->pr_size.x; x++) {
  977. X            pixel8  = pr_get(pr8, x, y);
  978. X            pixel32 = cm->map[2][pixel8] << blu_shift |
  979. X                      cm->map[1][pixel8] << grn_shift |
  980. X                      cm->map[0][pixel8] << red_shift;
  981. X            pr_put(pr32, x, y, pixel32);
  982. X        }
  983. X    }
  984. X    /* Destroy the old pixrect, and return the new */
  985. X    pr_destroy(pr8);
  986. X    return(pr32);
  987. X}
  988. X
  989. SHAR_EOF
  990. chmod 0777 vue.c || echo "restore of vue.c fails"
  991. fi
  992. if test -f vue.h; then echo "File vue.h exists"; else
  993. echo "x - extracting vue.h (Text)"
  994. sed 's/^X//' << 'SHAR_EOF' > vue.h &&
  995. Xstatic unsigned int ntscr[] = {
  996. X        0,   77,  153,  230,  306,  383,  459,  536,
  997. X      612,  689,  765,  842,  919,  995, 1072, 1148,
  998. X     1225, 1301, 1378, 1454, 1531, 1607, 1684, 1761,
  999. X     1837, 1914, 1990, 2067, 2143, 2220, 2296, 2373,
  1000. X     2449, 2526, 2602, 2679, 2756, 2832, 2909, 2985,
  1001. X     3062, 3138, 3215, 3291, 3368, 3444, 3521, 3598,
  1002. X     3674, 3751, 3827, 3904, 3980, 4057, 4133, 4210,
  1003. X     4286, 4363, 4440, 4516, 4593, 4669, 4746, 4822,
  1004. X     4899, 4975, 5052, 5128, 5205, 5282, 5358, 5435,
  1005. X     5511, 5588, 5664, 5741, 5817, 5894, 5970, 6047,
  1006. X     6124, 6200, 6277, 6353, 6430, 6506, 6583, 6659,
  1007. X     6736, 6812, 6889, 6966, 7042, 7119, 7195, 7272,
  1008. X     7348, 7425, 7501, 7578, 7654, 7731, 7807, 7884,
  1009. X     7961, 8037, 8114, 8190, 8267, 8343, 8420, 8496,
  1010. X     8573, 8649, 8726, 8803, 8879, 8956, 9032, 9109,
  1011. X     9185, 9262, 9338, 9415, 9491, 9568, 9645, 9721,
  1012. X     9798, 9874, 9951,10027,10104,10180,10257,10333,
  1013. X    10410,10487,10563,10640,10716,10793,10869,10946,
  1014. X    11022,11099,11175,11252,11329,11405,11482,11558,
  1015. X    11635,11711,11788,11864,11941,12017,12094,12170,
  1016. X    12247,12324,12400,12477,12553,12630,12706,12783,
  1017. X    12859,12936,13012,13089,13166,13242,13319,13395,
  1018. X    13472,13548,13625,13701,13778,13854,13931,14008,
  1019. X    14084,14161,14237,14314,14390,14467,14543,14620,
  1020. X    14696,14773,14850,14926,15003,15079,15156,15232,
  1021. X    15309,15385,15462,15538,15615,15692,15768,15845,
  1022. X    15921,15998,16074,16151,16227,16304,16380,16457,
  1023. X    16534,16610,16687,16763,16840,16916,16993,17069,
  1024. X    17146,17222,17299,17375,17452,17529,17605,17682,
  1025. X    17758,17835,17911,17988,18064,18141,18217,18294,
  1026. X    18371,18447,18524,18600,18677,18753,18830,18906,
  1027. X    18983,19059,19136,19213,19289,19366,19442,19519};
  1028. X
  1029. Xstatic unsigned int ntscg[] = {
  1030. X        0,  150,  301,  451,  601,  751,  902, 1052,
  1031. X     1202, 1352, 1503, 1653, 1803, 1954, 2104, 2254,
  1032. X     2404, 2555, 2705, 2855, 3005, 3156, 3306, 3456,
  1033. X     3607, 3757, 3907, 4057, 4208, 4358, 4508, 4658,
  1034. X     4809, 4959, 5109, 5260, 5410, 5560, 5710, 5861,
  1035. X     6011, 6161, 6311, 6462, 6612, 6762, 6913, 7063,
  1036. X     7213, 7363, 7514, 7664, 7814, 7964, 8115, 8265,
  1037. X     8415, 8566, 8716, 8866, 9016, 9167, 9317, 9467,
  1038. X     9617, 9768, 9918,10068,10218,10369,10519,10669,
  1039. X    10820,10970,11120,11270,11421,11571,11721,11871,
  1040. X    12022,12172,12322,12473,12623,12773,12923,13074,
  1041. X    13224,13374,13524,13675,13825,13975,14126,14276,
  1042. X    14426,14576,14727,14877,15027,15177,15328,15478,
  1043. X    15628,15779,15929,16079,16229,16380,16530,16680,
  1044. X    16830,16981,17131,17281,17432,17582,17732,17882,
  1045. X    18033,18183,18333,18483,18634,18784,18934,19085,
  1046. X    19235,19385,19535,19686,19836,19986,20136,20287,
  1047. X    20437,20587,20738,20888,21038,21188,21339,21489,
  1048. X    21639,21789,21940,22090,22240,22391,22541,22691,
  1049. X    22841,22992,23142,23292,23442,23593,23743,23893,
  1050. X    24044,24194,24344,24494,24645,24795,24945,25095,
  1051. X    25246,25396,25546,25697,25847,25997,26147,26298,
  1052. X    26448,26598,26748,26899,27049,27199,27350,27500,
  1053. X    27650,27800,27951,28101,28251,28401,28552,28702,
  1054. X    28852,29002,29153,29303,29453,29604,29754,29904,
  1055. X    30054,30205,30355,30505,30655,30806,30956,31106,
  1056. X    31257,31407,31557,31707,31858,32008,32158,32308,
  1057. X    32459,32609,32759,32910,33060,33210,33360,33511,
  1058. X    33661,33811,33961,34112,34262,34412,34563,34713,
  1059. X    34863,35013,35164,35314,35464,35614,35765,35915,
  1060. X    36065,36216,36366,36516,36666,36817,36967,37117,
  1061. X    37267,37418,37568,37718,37869,38019,38169,38319};
  1062. X
  1063. Xstatic unsigned int ntscb[] = {
  1064. X        0,   29,   58,   88,  117,  146,  175,  204,
  1065. X      233,  263,  292,  321,  350,  379,  409,  438,
  1066. X      467,  496,  525,  554,  584,  613,  642,  671,
  1067. X      700,  730,  759,  788,  817,  846,  876,  905,
  1068. X      934,  963,  992, 1021, 1051, 1080, 1109, 1138,
  1069. X     1167, 1197, 1226, 1255, 1284, 1313, 1342, 1372,
  1070. X     1401, 1430, 1459, 1488, 1518, 1547, 1576, 1605,
  1071. X     1634, 1663, 1693, 1722, 1751, 1780, 1809, 1839,
  1072. X     1868, 1897, 1926, 1955, 1985, 2014, 2043, 2072,
  1073. X     2101, 2130, 2160, 2189, 2218, 2247, 2276, 2306,
  1074. X     2335, 2364, 2393, 2422, 2451, 2481, 2510, 2539,
  1075. X     2568, 2597, 2627, 2656, 2685, 2714, 2743, 2772,
  1076. X     2802, 2831, 2860, 2889, 2918, 2948, 2977, 3006,
  1077. X     3035, 3064, 3094, 3123, 3152, 3181, 3210, 3239,
  1078. X     3269, 3298, 3327, 3356, 3385, 3415, 3444, 3473,
  1079. X     3502, 3531, 3560, 3590, 3619, 3648, 3677, 3706,
  1080. X     3736, 3765, 3794, 3823, 3852, 3881, 3911, 3940,
  1081. X     3969, 3998, 4027, 4057, 4086, 4115, 4144, 4173,
  1082. X     4202, 4232, 4261, 4290, 4319, 4348, 4378, 4407,
  1083. X     4436, 4465, 4494, 4524, 4553, 4582, 4611, 4640,
  1084. X     4669, 4699, 4728, 4757, 4786, 4815, 4845, 4874,
  1085. X     4903, 4932, 4961, 4990, 5020, 5049, 5078, 5107,
  1086. X     5136, 5166, 5195, 5224, 5253, 5282, 5311, 5341,
  1087. X     5370, 5399, 5428, 5457, 5487, 5516, 5545, 5574,
  1088. X     5603, 5633, 5662, 5691, 5720, 5749, 5778, 5808,
  1089. X     5837, 5866, 5895, 5924, 5954, 5983, 6012, 6041,
  1090. X     6070, 6099, 6129, 6158, 6187, 6216, 6245, 6275,
  1091. X     6304, 6333, 6362, 6391, 6420, 6450, 6479, 6508,
  1092. X     6537, 6566, 6596, 6625, 6654, 6683, 6712, 6742,
  1093. X     6771, 6800, 6829, 6858, 6887, 6917, 6946, 6975,
  1094. X     7004, 7033, 7063, 7092, 7121, 7150, 7179, 7208,
  1095. X     7238, 7267, 7296, 7325, 7354, 7384, 7413, 7442};
  1096. X
  1097. Xstatic int dither_table[16][16] = {
  1098. X    {  0,192, 48,240, 12,204, 60,252,  3,195, 51,243, 15,207, 63,254},
  1099. X    {128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127},
  1100. X    { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223},
  1101. X    {160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95},
  1102. X    {  8,200, 56,248,  4,196, 52,244, 11,203, 59,251,  7,199, 55,247},
  1103. X    {136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119},
  1104. X    { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215},
  1105. X    {168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87},
  1106. X    {  2,194, 50,242, 14,206, 62,254,  1,193, 49,241, 13,205, 61,253},
  1107. X    {130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125},
  1108. X    { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221},
  1109. X    {162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93},
  1110. X    { 10,202, 58,250,  6,198, 54,246,  9,201, 57,249,  5,197, 53,245},
  1111. X    {138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117},
  1112. X    { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213},
  1113. X    {170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85}};
  1114. X
  1115. SHAR_EOF
  1116. chmod 0644 vue.h || echo "restore of vue.h fails"
  1117. fi
  1118. if test -f vue.icon; then echo "File vue.icon exists"; else
  1119. echo "x - extracting vue.icon (Text)"
  1120. sed 's/^X//' << 'SHAR_EOF' > vue.icon &&
  1121. X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
  1122. X */
  1123. X    0x3FFF,0xFFFF,0xFFFF,0xFFFC,0x7FFF,0xFFFF,0xFFFF,0xFFFE,
  1124. X    0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xE083,0x5555,0x5591,0x1107,
  1125. X    0xE092,0xAAAA,0xAA88,0x8927,0xE0BB,0x5555,0x55A2,0x2377,
  1126. X    0xE092,0xAAAA,0xAAC4,0x4527,0xE083,0x5555,0x5591,0x1107,
  1127. X    0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xE080,0x0000,0x0000,0x0007,
  1128. X    0xE480,0x0000,0x0000,0x0007,0xEE80,0x0000,0x0000,0x0007,
  1129. X    0xE480,0x0000,0x0000,0x0007,0xE080,0x0000,0x0000,0x0007,
  1130. X    0xFF80,0x0000,0x0000,0x0007,0xF580,0x0000,0x0000,0x0007,
  1131. X    0xEA80,0x0000,0x0000,0x0007,0xF59C,0x1C00,0x0000,0x0007,
  1132. X    0xEA8C,0x0800,0x0000,0x0007,0xF586,0x1000,0x0000,0x0007,
  1133. X    0xEA86,0x1000,0x0000,0x0007,0xF586,0x10F3,0xC1E0,0x0007,
  1134. X    0xEA83,0x2061,0x8618,0x0007,0xF583,0x2061,0x8C0C,0x0007,
  1135. X    0xEA83,0x2061,0x8C0C,0x0007,0xF581,0x8061,0x8FFC,0x0007,
  1136. X    0xEA81,0xC061,0x8C00,0x0007,0xF581,0xC061,0x8C00,0x0007,
  1137. X    0xEA80,0x8061,0x8600,0x0007,0xF580,0x8073,0x830C,0x0007,
  1138. X    0xEA80,0x803C,0xC1F0,0x0007,0xFF80,0x0000,0x0000,0x0007,
  1139. X    0xE880,0x0000,0x0000,0x0007,0xE280,0x0000,0x0000,0x0007,
  1140. X    0xE480,0x0000,0x0000,0x0007,0xF180,0x0000,0x0000,0x0007,
  1141. X    0xE880,0x0000,0x0000,0x0007,0xE280,0x0000,0x0000,0x0007,
  1142. X    0xE480,0x0000,0x0000,0x0007,0xF180,0x0000,0x0000,0x0007,
  1143. X    0xE880,0x0000,0x0000,0x0007,0xE280,0x0000,0x0000,0x0007,
  1144. X    0xE480,0x0000,0x0000,0x0007,0xF180,0x0000,0x0000,0x0007,
  1145. X    0xE880,0x0000,0x0000,0x0007,0xE280,0x0000,0x0000,0x0007,
  1146. X    0xE480,0x0000,0x0000,0x0007,0xF180,0x0000,0x0000,0x0007,
  1147. X    0xE880,0x0000,0x0000,0x0007,0xE280,0x0000,0x0000,0x0007,
  1148. X    0xE480,0x0000,0x0000,0x0007,0xF180,0x0000,0x0000,0x0007,
  1149. X    0xE880,0x0000,0x0000,0x0007,0xE280,0x0000,0x0000,0x0007,
  1150. X    0xE480,0x0000,0x0000,0x0007,0xFF80,0x0000,0x0000,0x0007,
  1151. X    0xE080,0x0000,0x0000,0x0007,0xE480,0x0000,0x0000,0x0007,
  1152. X    0xEE80,0x0000,0x0000,0x0007,0xE480,0x0000,0x0000,0x0007,
  1153. X    0xE080,0x0000,0x0000,0x0007,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  1154. X    0x7FFF,0xFFFF,0xFFFF,0xFFFE,0x3FFF,0xFFFF,0xFFFF,0xFFFC
  1155. SHAR_EOF
  1156. chmod 0777 vue.icon || echo "restore of vue.icon fails"
  1157. fi
  1158. if test -f vue.man; then echo "File vue.man exists"; else
  1159. echo "x - extracting vue.man (Text)"
  1160. sed 's/^X//' << 'SHAR_EOF' > vue.man &&
  1161. X.TH VUE L
  1162. X.SH NAME
  1163. Xvue \- a Sunview rasterfile display program
  1164. X.SH SYNOPSIS
  1165. X\fBvue\fP [ \fB-f filter\fP ] [ \fBfilename... \fP]
  1166. X.SH DESCRIPTION
  1167. XVue is a Sunview tool to display images in a scrollable Sunview 
  1168. Xwindow. Vue can be used with or without a filter. Without a filter
  1169. Xvue can be used to display ordinary rasterfiles. With a user 
  1170. Xsupplied filter, vue can display whatever filetype the supplied 
  1171. Xfilter works with.
  1172. X
  1173. XFile selection within vue is very easy. 
  1174. XWhile the mouse cursor is inside the display area, 
  1175. Xa new file may selected using any of the three mouse buttons. 
  1176. XPressing the right mouse button will display a menu of available files.
  1177. XTo select a new file, simply high-lighting the desired file, 
  1178. Xand release the button.
  1179. XSingle stepping thru the file menu is accomplished by clicking 
  1180. Xthe left and middle mouse buttons. 
  1181. XClicking the left mouse button to go up the list. 
  1182. XClicking the middle mouse button to go down the list. 
  1183. XVue will "roll-over" upon reaching either end of the list. 
  1184. XVue will also "step over" files it cannot load 
  1185. X(simply press the same mouse button again).
  1186. X
  1187. XVue uses the frame's label bar to display program status messages,
  1188. Xand the name of the file being displayed.
  1189. X
  1190. XAccess to vue's control panel can be obtain by selecting [props] from
  1191. Xvue's frame menu, or by pressing the [esc] key while the mouse cursor 
  1192. Xis inside the display area. The selection menu can be updated by 
  1193. Xentering a new filename on the 'File:' line and pressing the [Update_Menu] 
  1194. Xbutton. Changing the filter or updating the filter options used can be 
  1195. Xdone by editing the 'Filter:' line and pressing the [Update_filter] button.
  1196. X(These lines many contain shell wildcard characters.)  
  1197. X.SH OPTIONS
  1198. X.TP
  1199. X\fB-f\fP \fIfilter\fP
  1200. XSpecify a filter vue is to pipe the selected file thru before
  1201. Xdisplaying it. Using 'zcat' as a filter, vue can display the contents 
  1202. Xof compressed rasterfiles. Using Patrick J. Naughton's gif2ras program, 
  1203. Xvue can be used to display GIF files.
  1204. X.SH AUTHOR
  1205. X.nf
  1206. XMatthew Lee Stier
  1207. XSun Microsystems
  1208. X2000 Aerial Center, Suite 110
  1209. XMorrisville, NC 27560
  1210. X(919) 469-8300
  1211. X.fi
  1212. X.SH CREDITS
  1213. XVue was developed from a program publically called rastershow.
  1214. XRastershow's author is: David DiGiacomo, also an employee of Sun Microsystems
  1215. X.SH NOTES
  1216. XVue expects filters to accept input via stdin, and output the rasterfile 
  1217. Xvia stdout. If the filter you intend to use requires command-line option, 
  1218. Xthese need to included with the filter argument by enclosing it in single quotes. 
  1219. X
  1220. X    vue -f 'filter -options' filename filename....
  1221. X
  1222. XAny filter you specify must be reachable using your $PATH enviromental variable, 
  1223. Xor you must specify the the filters full path/filename.
  1224. X
  1225. XVue does do rudimentary dithering. This is to permit the viewing of color images
  1226. Xon monochrome workstations, and 24-bit images on 8-bit color displays.
  1227. SHAR_EOF
  1228. chmod 0777 vue.man || echo "restore of vue.man fails"
  1229. fi
  1230. if test -f gif2ras.c; then echo "File gif2ras.c exists"; else
  1231. echo "x - extracting gif2ras.c (Text)"
  1232. sed 's/^X//' << 'SHAR_EOF' > gif2ras.c &&
  1233. X#ifndef lint
  1234. Xstatic char sccsid[] = "@(#)gif2ras.c 1.1 89/01/17";
  1235. X#endif
  1236. X/*-
  1237. X * gif2ras.c - Converts from a Compuserve GIF (tm) image to a Sun Raster image.
  1238. X *
  1239. X * Copyright (c) 1988, 1989 by Patrick J. Naughton
  1240. X *
  1241. X * Author: Patrick J. Naughton
  1242. X * naughton@wind.sun.com
  1243. X *
  1244. X * Permission to use, copy, modify, and distribute this software and its
  1245. X * documentation for any purpose and without fee is hereby granted,
  1246. X * provided that the above copyright notice appear in all copies and that
  1247. X * both that copyright notice and this permission notice appear in
  1248. X * supporting documentation.
  1249. X *
  1250. X * This file is provided AS IS with no warranties of any kind.  The author
  1251. X * shall have no liability with respect to the infringement of copyrights,
  1252. X * trade secrets or any patents by this file or any part thereof.  In no
  1253. X * event will the author be liable for any lost revenue or profits or
  1254. X * other special, indirect and consequential damages.
  1255. X *
  1256. X * Comments and additions should be sent to the author:
  1257. X *
  1258. X *                     Patrick J. Naughton
  1259. X *                     Sun Microsystems
  1260. X *                     2550 Garcia Ave, MS 14-40
  1261. X *                     Mountain View, CA 94043
  1262. X *                     (415) 336-1080
  1263. X *
  1264. X * Revision History:
  1265. X * 01-Jan-89: Added error checking and removed NEXTSHORT.
  1266. X * 07-Sep-88: Added BytesPerScanline fix.
  1267. X * 30-Aug-88: Allow stdin/stdout. Restructured argument parser.
  1268. X * 27-Jul-88: Updated to use libpixrect to fix 386i byteswapping problems.
  1269. X * 11-Apr-88: Converted to C and changed to write Sun rasterfiles.
  1270. X * 19-Jan-88: GIFSLOW.PAS posted to comp.graphics by Jim Briebel,
  1271. X *            a Turbo Pascal 4.0 program to painfully slowly display
  1272. X *            GIF images on an EGA equipped IBM-PC.
  1273. X *
  1274. X * Description:
  1275. X *   This program takes a Compuserve "Graphics Interchange Format" or "GIF"
  1276. X * file as input and writes a file known as a Sun rasterfile.  This datafile
  1277. X * can be loaded by the NeWS "readcanvas" operator and is of the same format
  1278. X * as the files in /usr/NeWS/smi/*.  Under X11R2 there is a program called
  1279. X * xraster to display these files.
  1280. X *
  1281. X * Portability:
  1282. X *   To make this program convert to some image format other than Sun's
  1283. X * Rasterfile format simply seach for the tag "SS:" in the source and
  1284. X * replace these simple mechanisms with the appropriate ones for the
  1285. X * other output format.  I have marked all (six) Sun Specific pieces
  1286. X * of code with this comment.
  1287. X *
  1288. X * SS: compile with "cc -o gif2ras -O gif2ras.c -lpixrect"
  1289. X */
  1290. X
  1291. X#include <stdio.h>
  1292. X#include <pixrect/pixrect_hs.h> /* SS: main Pixrect header file */
  1293. X
  1294. Xtypedef int boolean;
  1295. X#define True (1)
  1296. X#define False (0)
  1297. X
  1298. X#define NEXTBYTE (*ptr++)
  1299. X#define IMAGESEP 0x2c
  1300. X#define INTERLACEMASK 0x40
  1301. X#define COLORMAPMASK 0x80
  1302. X
  1303. XFILE *fp;
  1304. X
  1305. Xint BitOffset = 0,        /* Bit Offset of next code */
  1306. X    XC = 0, YC = 0,        /* Output X and Y coords of current pixel */
  1307. X    Pass = 0,            /* Used by output routine if interlaced pic */
  1308. X    OutCount = 0,        /* Decompressor output 'stack count' */
  1309. X    RWidth, RHeight,        /* screen dimensions */
  1310. X    Width, Height,        /* image dimensions */
  1311. X    LeftOfs, TopOfs,        /* image offset */
  1312. X    BitsPerPixel,        /* Bits per pixel, read from GIF header */
  1313. X    BytesPerScanline,        /* bytes per scanline in output raster */
  1314. X    ColorMapSize,        /* number of colors */
  1315. X    CodeSize,            /* Code size, read from GIF header */
  1316. X    InitCodeSize,        /* Starting code size, used during Clear */
  1317. X    Code,            /* Value returned by ReadCode */
  1318. X    MaxCode,            /* limiting value for current code size */
  1319. X    ClearCode,            /* GIF clear code */
  1320. X    EOFCode,            /* GIF end-of-information code */
  1321. X    CurCode, OldCode, InCode,    /* Decompressor variables */
  1322. X    FirstFree,            /* First free code, generated per GIF spec */
  1323. X    FreeCode,            /* Decompressor, next free slot in hash table */
  1324. X    FinChar,            /* Decompressor variable */
  1325. X    BitMask,            /* AND mask for data size */
  1326. X    ReadMask;            /* Code AND mask for current code size */
  1327. X
  1328. Xboolean Interlace, HasColormap;
  1329. Xboolean Verbose = False;
  1330. X
  1331. X/* SS: defined in pixrect/pixrect_hs.h */
  1332. XPixrect *Output;        /* The Sun Pixrect */
  1333. Xcolormap_t Colormap;        /* The Pixrect Colormap */
  1334. X
  1335. Xu_char *Image;            /* The result array */
  1336. Xu_char *RawGIF;            /* The heap array to hold it, raw */
  1337. Xu_char *Raster;            /* The raster data stream, unblocked */
  1338. X
  1339. X    /* The hash table used by the decompressor */
  1340. Xint Prefix[4096];
  1341. Xint Suffix[4096];
  1342. X
  1343. X    /* An output array used by the decompressor */
  1344. Xint OutCode[1025];
  1345. X
  1346. X    /* The color map, read from the GIF header */
  1347. Xu_char Red[256], Green[256], Blue[256];
  1348. X
  1349. Xchar *id = "GIF87a";
  1350. X
  1351. Xchar *pname;            /* program name (used for error messages) */
  1352. Xvoid
  1353. Xerror(s1, s2)
  1354. Xchar *s1, *s2;
  1355. X{
  1356. X    fprintf(stderr, s1, pname, s2);
  1357. X    exit(1);
  1358. X}
  1359. X
  1360. Xvoid
  1361. Xusage()
  1362. X{
  1363. X    error("usage: %s -[vq] [-|GIFfile] [rasterfile]\n", NULL);
  1364. X}
  1365. X
  1366. X
  1367. Xmain(argc, argv)
  1368. Xint argc;
  1369. Xchar *argv[];
  1370. X{
  1371. Xchar *inf = NULL;
  1372. Xchar *outf = NULL;
  1373. Xint filesize;
  1374. Xregister u_char ch, ch1;
  1375. Xregister u_char *ptr, *ptr1;
  1376. Xregister int i;
  1377. X
  1378. X    setbuf(stderr, NULL);
  1379. X    pname = argv[0];
  1380. X
  1381. X    while (--argc)
  1382. X    if ((++argv)[0][0] == '-')
  1383. X        switch (argv[0][1]) {
  1384. X        case 'v':
  1385. X        Verbose = True;
  1386. X        break;
  1387. X        case 'q':
  1388. X        usage();
  1389. X        case '\0':
  1390. X        if (inf == NULL)
  1391. X            inf = "Standard Input";
  1392. X        else if (outf == NULL)
  1393. X            outf = "Standard Output";
  1394. X        else
  1395. X            usage();
  1396. X        break;
  1397. X        default:
  1398. X        fprintf(stderr, "%s: illegal option -%c.\n", pname,
  1399. X            argv[0][1]);
  1400. X        exit(1);
  1401. X        }
  1402. X    else if (inf == NULL)
  1403. X        inf = argv[0];
  1404. X    else if (outf == NULL)
  1405. X        outf = argv[0];
  1406. X    else
  1407. X        usage();
  1408. X
  1409. X    if (inf == NULL || strcmp(inf, "Standard Input") == 0) {
  1410. X    inf = "Standard Input";
  1411. X    fp = stdin;
  1412. X    } else if (!(fp = fopen(inf, "r")))
  1413. X    error("%s: %s not found.\n", inf);
  1414. X
  1415. X    /* find the size of the file */
  1416. X    fseek(fp, 0L, 2);
  1417. X    filesize = ftell(fp);
  1418. X    fseek(fp, 0L, 0);
  1419. X
  1420. X    if (!(ptr = RawGIF = (u_char *) malloc(filesize)))
  1421. X    error("%s: not enough memory to read gif file.\n", NULL);
  1422. X
  1423. X    if (!(Raster = (u_char *) malloc(filesize)))
  1424. X    error("%s: not enough memory to read gif file.\n", NULL);
  1425. X
  1426. X    if (fread(ptr, filesize, 1, fp) != 1)
  1427. X    error("%s: GIF data read failed\n", NULL);
  1428. X
  1429. X    if (strncmp(ptr, id, 6))
  1430. X    error("%s: %s is not a GIF file.\n", inf);
  1431. X    ptr += 6;
  1432. X
  1433. X/* Get variables from the GIF screen descriptor */
  1434. X
  1435. X    ch = NEXTBYTE;
  1436. X    RWidth = ch + 0x100 * NEXTBYTE;    /* screen dimensions... not used. */
  1437. X    ch = NEXTBYTE;
  1438. X    RHeight = ch + 0x100 * NEXTBYTE;
  1439. X
  1440. X    if (Verbose)
  1441. X    fprintf(stderr, "screen dims: %dx%d.\n", RWidth, RHeight);
  1442. X
  1443. X    ch = NEXTBYTE;
  1444. X    HasColormap = ((ch & COLORMAPMASK) ? True : False);
  1445. X
  1446. X    BitsPerPixel = (ch & 7) + 1;
  1447. X    ColorMapSize = 1 << BitsPerPixel;
  1448. X    BitMask = ColorMapSize - 1;
  1449. X
  1450. X    ch = NEXTBYTE;        /* background color... not used. */
  1451. X
  1452. X    if (NEXTBYTE)        /* supposed to be NULL */
  1453. X    error("%s: %s is a corrupt GIF file (nonull).\n", inf);
  1454. X
  1455. X/* Read in global colormap. */
  1456. X
  1457. X    if (HasColormap) {
  1458. X    if (Verbose)
  1459. X        fprintf(stderr, "%s is %d bits per pixel, (%d colors).\n",
  1460. X        inf, BitsPerPixel, ColorMapSize);
  1461. X    for (i = 0; i < ColorMapSize; i++) {
  1462. X        Red[i] = NEXTBYTE;
  1463. X        Green[i] = NEXTBYTE;
  1464. X        Blue[i] = NEXTBYTE;
  1465. X    }
  1466. X
  1467. X/* SS: Fill in the Pixrect colormap struct */
  1468. X    Colormap.type = RMT_EQUAL_RGB;
  1469. X    Colormap.length = ColorMapSize;
  1470. X    Colormap.map[0] = Red;
  1471. X    Colormap.map[1] = Green;
  1472. X    Colormap.map[2] = Blue;
  1473. X    }
  1474. X    else error("%s: %s does not have a colormap.\n", inf);
  1475. X
  1476. X
  1477. X/* Check for image seperator */
  1478. X
  1479. X    if (NEXTBYTE != IMAGESEP)
  1480. X    error("%s: %s is a corrupt GIF file (nosep).\n", inf);
  1481. X
  1482. X/* Now read in values from the image descriptor */
  1483. X
  1484. X    ch = NEXTBYTE;
  1485. X    LeftOfs = ch + 0x100 * NEXTBYTE;
  1486. X    ch = NEXTBYTE;
  1487. X    TopOfs = ch + 0x100 * NEXTBYTE;
  1488. X    ch = NEXTBYTE;
  1489. X    Width = ch + 0x100 * NEXTBYTE;
  1490. X    ch = NEXTBYTE;
  1491. X    Height = ch + 0x100 * NEXTBYTE;
  1492. X    Interlace = ((NEXTBYTE & INTERLACEMASK) ? True : False);
  1493. X
  1494. X    if (Verbose)
  1495. X    fprintf(stderr, "Reading a %d by %d %sinterlaced image...",
  1496. X        Width, Height, (Interlace) ? "" : "non-");
  1497. X    
  1498. X
  1499. X/* Note that I ignore the possible existence of a local color map.
  1500. X * I'm told there aren't many files around that use them, and the spec
  1501. X * says it's defined for future use.  This could lead to an error
  1502. X * reading some files. 
  1503. X */
  1504. X
  1505. X/* Start reading the raster data. First we get the intial code size
  1506. X * and compute decompressor constant values, based on this code size.
  1507. X */
  1508. X
  1509. X    CodeSize = NEXTBYTE;
  1510. X    ClearCode = (1 << CodeSize);
  1511. X    EOFCode = ClearCode + 1;
  1512. X    FreeCode = FirstFree = ClearCode + 2;
  1513. X
  1514. X/* The GIF spec has it that the code size is the code size used to
  1515. X * compute the above values is the code size given in the file, but the
  1516. X * code size used in compression/decompression is the code size given in
  1517. X * the file plus one. (thus the ++).
  1518. X */
  1519. X
  1520. X    CodeSize++;
  1521. X    InitCodeSize = CodeSize;
  1522. X    MaxCode = (1 << CodeSize);
  1523. X    ReadMask = MaxCode - 1;
  1524. X
  1525. X/* Read the raster data.  Here we just transpose it from the GIF array
  1526. X * to the Raster array, turning it from a series of blocks into one long
  1527. X * data stream, which makes life much easier for ReadCode().
  1528. X */
  1529. X
  1530. X    ptr1 = Raster;
  1531. X    do {
  1532. X    ch = ch1 = NEXTBYTE;
  1533. X    while (ch--) *ptr1++ = NEXTBYTE;
  1534. X    if ((ptr1 - Raster ) > filesize)
  1535. X        error("%s: %s is a corrupt GIF file (unblock).\n", inf);
  1536. X    } while(ch1);
  1537. X
  1538. X    free(RawGIF);        /* We're done with the raw data now... */
  1539. X
  1540. X    if (Verbose) {
  1541. X    fprintf(stderr, "done.\n");
  1542. X    fprintf(stderr, "Decompressing...");
  1543. X    }
  1544. X
  1545. X
  1546. X/* SS: Allocate the Sun Pixrect and make "Image" point to the image data. */
  1547. X    Output = mem_create(Width, Height, 8);
  1548. X    if (Output == (Pixrect *) NULL)
  1549. X    error("%s: not enough memory for output data.\n", NULL);
  1550. X    Image = (u_char *) mpr_d(Output)->md_image;
  1551. X    BytesPerScanline = mpr_d(Output)->md_linebytes;
  1552. X
  1553. X
  1554. X/* Decompress the file, continuing until you see the GIF EOF code.
  1555. X * One obvious enhancement is to add checking for corrupt files here.
  1556. X */
  1557. X
  1558. X    Code = ReadCode();
  1559. X    while (Code != EOFCode) {
  1560. X
  1561. X/* Clear code sets everything back to its initial value, then reads the
  1562. X * immediately subsequent code as uncompressed data.
  1563. X */
  1564. X
  1565. X    if (Code == ClearCode) {
  1566. X        CodeSize = InitCodeSize;
  1567. X        MaxCode = (1 << CodeSize);
  1568. X        ReadMask = MaxCode - 1;
  1569. X        FreeCode = FirstFree;
  1570. X        CurCode = OldCode = Code = ReadCode();
  1571. X        FinChar = CurCode & BitMask;
  1572. X        AddToPixel(FinChar);
  1573. X    }
  1574. X    else {
  1575. X
  1576. X/* If not a clear code, then must be data: save same as CurCode and InCode */
  1577. X
  1578. X        CurCode = InCode = Code;
  1579. X
  1580. X/* If greater or equal to FreeCode, not in the hash table yet;
  1581. X * repeat the last character decoded
  1582. X */
  1583. X
  1584. X        if (CurCode >= FreeCode) {
  1585. X        CurCode = OldCode;
  1586. X        OutCode[OutCount++] = FinChar;
  1587. X        }
  1588. X
  1589. X/* Unless this code is raw data, pursue the chain pointed to by CurCode
  1590. X * through the hash table to its end; each code in the chain puts its
  1591. X * associated output code on the output queue.
  1592. X */
  1593. X
  1594. X        while (CurCode > BitMask) {
  1595. X        if (OutCount > 1024)
  1596. X            error("%s: %s is a corrupt GIF file (OutCount).\n", inf);
  1597. X        OutCode[OutCount++] = Suffix[CurCode];
  1598. X        CurCode = Prefix[CurCode];
  1599. X        }
  1600. X
  1601. X/* The last code in the chain is treated as raw data. */
  1602. X
  1603. X        FinChar = CurCode & BitMask;
  1604. X        OutCode[OutCount++] = FinChar;
  1605. X
  1606. X/* Now we put the data out to the Output routine.
  1607. X * It's been stacked LIFO, so deal with it that way...
  1608. X */
  1609. X
  1610. X        for (i = OutCount - 1; i >= 0; i--)
  1611. X        AddToPixel(OutCode[i]);
  1612. X        OutCount = 0;
  1613. X
  1614. X/* Build the hash table on-the-fly. No table is stored in the file. */
  1615. X
  1616. X        Prefix[FreeCode] = OldCode;
  1617. X        Suffix[FreeCode] = FinChar;
  1618. X        OldCode = InCode;
  1619. X
  1620. X/* Point to the next slot in the table.  If we exceed the current
  1621. X * MaxCode value, increment the code size unless it's already 12.  If it
  1622. X * is, do nothing: the next code decompressed better be CLEAR
  1623. X */
  1624. X
  1625. X        FreeCode++;
  1626. X        if (FreeCode >= MaxCode) {
  1627. X        if (CodeSize < 12) {
  1628. X            CodeSize++;
  1629. X            MaxCode *= 2;
  1630. X            ReadMask = (1 << CodeSize) - 1;
  1631. X        }
  1632. X        }
  1633. X    }
  1634. X    Code = ReadCode();
  1635. X    }
  1636. X
  1637. X    free(Raster);
  1638. X
  1639. X    if (Verbose)
  1640. X    fprintf(stderr, "done.\n");
  1641. X
  1642. X    if (fp != stdin)
  1643. X    fclose(fp);
  1644. X
  1645. X    if (outf == NULL || strcmp(outf, "Standard Output") == 0) {
  1646. X    outf = "Standard Output";
  1647. X    fp = stdout;
  1648. X    }
  1649. X    else {
  1650. X    if (!(fp = fopen(outf, "w")))
  1651. X        error("%s: %s couldn't be opened for writing.\n", outf);
  1652. X    }
  1653. X
  1654. X    if (Verbose)
  1655. X    fprintf(stderr, "Writing rasterfile in %s...", outf);
  1656. X
  1657. X/* SS: Pixrect Rasterfile output code. */
  1658. X    if (pr_dump(Output, fp, &Colormap, RT_STANDARD, 0) == PIX_ERR)
  1659. X    error("%s: error writing Sun Rasterfile: %s\n", outf);
  1660. X
  1661. X    if (Verbose)
  1662. X    fprintf(stderr, "done.\n");
  1663. X
  1664. X    pr_destroy(Output);
  1665. X
  1666. X    if (fp != stdout)
  1667. X    fclose(fp);
  1668. X
  1669. X    exit(0);
  1670. X}
  1671. X
  1672. X
  1673. X/* Fetch the next code from the raster data stream.  The codes can be
  1674. X * any length from 3 to 12 bits, packed into 8-bit bytes, so we have to
  1675. X * maintain our location in the Raster array as a BIT Offset.  We compute
  1676. X * the byte Offset into the raster array by dividing this by 8, pick up
  1677. X * three bytes, compute the bit Offset into our 24-bit chunk, shift to
  1678. X * bring the desired code to the bottom, then mask it off and return it. 
  1679. X */
  1680. XReadCode()
  1681. X{
  1682. Xint RawCode, ByteOffset;
  1683. X
  1684. X    ByteOffset = BitOffset / 8;
  1685. X    RawCode = Raster[ByteOffset] + (0x100 * Raster[ByteOffset + 1]);
  1686. X    if (CodeSize >= 8)
  1687. X    RawCode += (0x10000 * Raster[ByteOffset + 2]);
  1688. X    RawCode >>= (BitOffset % 8);
  1689. X    BitOffset += CodeSize;
  1690. X    return(RawCode & ReadMask);
  1691. X}
  1692. X
  1693. X
  1694. XAddToPixel(Index)
  1695. Xu_char Index;
  1696. X{
  1697. X    *(Image + YC * BytesPerScanline + XC) = Index;
  1698. X
  1699. X/* Update the X-coordinate, and if it overflows, update the Y-coordinate */
  1700. X
  1701. X    if (++XC == Width) {
  1702. X
  1703. X/* If a non-interlaced picture, just increment YC to the next scan line. 
  1704. X * If it's interlaced, deal with the interlace as described in the GIF
  1705. X * spec.  Put the decoded scan line out to the screen if we haven't gone
  1706. X * past the bottom of it
  1707. X */
  1708. X
  1709. X    XC = 0;
  1710. X    if (!Interlace) YC++;
  1711. X    else {
  1712. X        switch (Pass) {
  1713. X        case 0:
  1714. X            YC += 8;
  1715. X            if (YC >= Height) {
  1716. X            Pass++;
  1717. X            YC = 4;
  1718. X            }
  1719. X        break;
  1720. X        case 1:
  1721. X            YC += 8;
  1722. X            if (YC >= Height) {
  1723. X            Pass++;
  1724. X            YC = 2;
  1725. X            }
  1726. X        break;
  1727. X        case 2:
  1728. X            YC += 4;
  1729. X            if (YC >= Height) {
  1730. X            Pass++;
  1731. X            YC = 1;
  1732. X            }
  1733. X        break;
  1734. X        case 3:
  1735. X            YC += 2;
  1736. X        break;
  1737. X        default:
  1738. X        break;
  1739. X        }
  1740. X    }
  1741. X    }
  1742. X}
  1743. SHAR_EOF
  1744. chmod 0644 gif2ras.c || echo "restore of gif2ras.c fails"
  1745. fi
  1746. if test -f gif2ras.man; then echo "File gif2ras.man exists"; else
  1747. echo "x - extracting gif2ras.man (Text)"
  1748. sed 's/^X//' << 'SHAR_EOF' > gif2ras.man &&
  1749. X.TH GIF2SUN L
  1750. X.SH NAME
  1751. Xgif2sun \- GIF to Sun rasterfile filter
  1752. X.SH SYNOPSIS
  1753. X\fBgif2sun\fP [\fB-v\fP] [\fB-q\fP] [\fB-\fP|\fBGIFfile\fP] [\fBrasterfile\fP]
  1754. X.SH DESCRIPTION
  1755. XGenerate the rasterfile equivalent of a GIF image.
  1756. X.SH OPTIONS
  1757. X.TP
  1758. X.nf
  1759. X\fB-v\fP
  1760. XSet verbose mode. 
  1761. X(Reports status of program via stderr.)
  1762. X.fi
  1763. X.TP
  1764. X.nf
  1765. X\fB-q\fP
  1766. XDisplay help message. 
  1767. X(Usage prompt.)
  1768. X.fi
  1769. X.TP
  1770. X.nf
  1771. X\fB-\fP
  1772. XForce sourcing of GIF file from stdin. 
  1773. X(Only needed when sourcing the GIF file from \fBstdin\fP and 
  1774. Xspecifying the output rasterfile on the command line.)
  1775. X.fi
  1776. X.SH DIAGNOSTICS
  1777. XSee verbose mode above.
  1778. X.SH AUTHOR
  1779. X.nf
  1780. XPatrick J. Naughton
  1781. XSun Microsystems
  1782. X2550 Garcia Ave, MS 14-40
  1783. XMountain View, CA 94043
  1784. X(415) 336-1080
  1785. X.fi
  1786. SHAR_EOF
  1787. chmod 0644 gif2ras.man || echo "restore of gif2ras.man fails"
  1788. fi
  1789. exit 0
  1790.  
  1791. -- 
  1792. Matthew Lee Stier    (mstier@east.Sun.COM)   |
  1793. Sun Microsystems ---  RTP, NC  27709-3447    |     "Wisconsin   Escapee"
  1794. uucp:  sun!mstier or mcnc!rti!sunpix!matthew |
  1795. phone: (919) 469-8300 fax: (919) 460-8355    |
  1796.