home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / x11 / lib / in_cmap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-22  |  3.5 KB  |  130 lines

  1. /*
  2. * This software is copyrighted as noted below.  It may be freely copied,
  3. * modified, and redistributed, provided that the copyright notices are
  4. * preserved on all copies.
  5. *
  6. * There is no warranty or other guarantee of fitness for this software,
  7. * it is provided solely "as is".  Bug reports or fixes may be sent
  8. * to the author, who may or may not act on them as he desires.
  9. *
  10. * You may not include this software in a program or other software product
  11. * without supplying the source, or without informing the end-user that the
  12. * source is available for no extra charge.
  13. *
  14. * If you modify this software, you should include a notice giving the
  15. * name of the person performing the modification, the date of modification,
  16. * and the reason for such modification.
  17. */
  18.  
  19. /*
  20. * in_cmap.c - Jack with the Input colormap from the rle files.
  21. *
  22. * Author:    Martin R. Friedmann
  23. *         Dept of Electrical Engineering and Computer Science
  24. *        University of Michigan
  25. * Date:    Tue, April 12, 1990
  26. * Copyright (c) 1990, University of Michigan
  27. *
  28. * Modified:    Fri, May 31, 1991
  29. *        Jin, Guojun - Lawrence Berkeley Laboratory
  30. */
  31.  
  32. #include "panel.h"
  33.  
  34. /* uses global command line args (iflag, display_gamma) */
  35. /* sets in_cmap, cmlen, ncmap and mono_color */
  36.  
  37. void
  38. get_dither_colors(img)
  39. register image_information *img;
  40. {
  41. register int    i, j;
  42.  
  43.     /* Get some info. out of the RLE header. */
  44.     img->ncmap = rle_dflt_hdr.ncmap;
  45.     {
  46.     char * v;
  47.     if ( (v = rle_getcom("color_map_length", &rle_dflt_hdr )) != NULL)
  48.         img->cmlen = atoi( v );
  49.     else
  50.         img->cmlen = 1 << rle_dflt_hdr.cmaplen;
  51.  
  52.     /* Protect against bogus information */
  53.     if (img->cmlen < 0)
  54.         img->cmlen = 0;
  55.     if (img->cmlen > 256)
  56.         img->cmlen = 256;
  57.     }
  58.  
  59.     /* Input map, at least 3 channels */
  60.     if (img->sep_colors ||
  61.     (img->img_channels == 1 && img->ncmap == 3 && img->cmlen))
  62.     /* If using color map directly, apply display gamma, too. */
  63.     img->in_cmap = buildmap(&rle_dflt_hdr, 3, img->gamma, display_gamma);
  64.     else
  65.     img->in_cmap = buildmap(&rle_dflt_hdr, 3, img->gamma, 1.0);
  66.  
  67.     for (i=0; i < 3; i++) {
  68.     for (j=0; j < 256; j++)
  69.         if (img->in_cmap[i][j] != j)
  70.         break;
  71.     if (j < 256) break;
  72.     }
  73.     /* if i and j are maxed out, then in_cmap is the identity... */
  74.     if (i == 3 && j == 256)
  75.     free(img->in_cmap[0]),
  76.     free(img->in_cmap),
  77.     img->in_cmap = NULL;
  78.     else
  79.     if (DEBUGANY) for (i=0; i < 3; i++) {
  80.         message("Input image colormap channel %d:\n", i);
  81.         if (i > 0)
  82.             for (j=0; j < img->cmlen; j++)
  83.             if (img->in_cmap[i-1][j] != img->in_cmap[i][j])
  84.                 break;
  85.         if (i > 0 && j == img->cmlen)
  86.             message("\tSame as channel %d\n", i - 1);
  87.         else    for (j=0; j < img->cmlen; j += 16) {
  88.             int    k;
  89.             message("%3d: ", j);
  90.             for (k = 0; k < 16 ; k++)
  91.                 if (j + k < img->cmlen)
  92.                 message("%3d ", img->in_cmap[i][j+k]);
  93.             mesg("\n");
  94.             }
  95.     }
  96.  
  97.     /* The mono_color flag means that a single input channel is being
  98.     * pseudocolored by a multi-channel colormap.
  99.     */
  100.     img->mono_color = (img->img_channels == 1 && img->ncmap == 3 &&
  101.             img->in_cmap && img->cmlen);
  102.  
  103.     /* make colormap monochrome...   Whatahack! */
  104.     if (img->mono_color && !img->color_dpy) {
  105.     for (j = 0; j < 256; j++)
  106.         img->in_cmap[0][j] = (rle_pixel)
  107.         ((30 * img->in_cmap[0][j] + 59 * img->in_cmap[1][j] +
  108.           11 * img->in_cmap[2][j]) / 100);
  109.  
  110.     img->mono_color = False;
  111.     }
  112. }
  113.  
  114. eq_cmap(cm1, len1, cm2, len2)
  115. register rle_pixel **cm1, **cm2;
  116. {
  117. register int    i, j;
  118.  
  119.     if (cm1 && cm2) {
  120.     if (len1 != len2)
  121.         return 0;
  122.     for (i=0; i < 3; i++)
  123.         for (j=0; j < 256; j++)
  124.         if (cm1[i][j] != cm2[i][j])
  125.             return 0;
  126.     } else
  127.     return    !(cm1 || cm2);
  128. return    1;
  129. }
  130.