Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
in_cmap.c
Go to the documentation of this file.
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 
29 #include "getx11.h"
30 
31 /* We really want this stuff to happen before find_appropriate_visual */
33 image_information *img;
34 rle_hdr *img_hdr;
35 {
36  /* Get some info out of the RLE header. */
37  img->ncmap = img_hdr->ncmap;
38  {
39  char * v;
40  if ( (v = rle_getcom( "color_map_length", img_hdr )) != NULL )
41  img->cmlen = atoi( v );
42  else
43  img->cmlen = 1 << img_hdr->cmaplen;
44 
45  /* Protect against bogus information */
46  if ( img->cmlen < 0 )
47  img->cmlen = 0;
48  if ( img->cmlen > 256 )
49  img->cmlen = 256;
50  }
51 
52  /* The mono_color flag means that a single input channel is being
53  * pseudocolored by a multi-channel colormap.
54  */
55  img->mono_color = (img->img_channels == 1 && img->ncmap == 3 &&
56  img->cmlen);
57 
58 }
59 
60 /* uses global command line args (iflag, display_gamma) */
61 /* sets in_cmap, cmlen, ncmap and mono_color */
62 
64 register image_information *img;
65 rle_hdr *img_hdr;
66 {
67  register int i, j;
68 
69  /* Input map, at least 3 channels */
70  if ( img->sep_colors ||
71  (img->img_channels == 1 && img->ncmap == 3 && img->cmlen) )
72  /* If using color map directly, apply display gamma, too. */
73  img->in_cmap = buildmap( img_hdr, 3, img->gamma,
75  else
76  img->in_cmap = buildmap( img_hdr, 3, img->gamma, 1.0 );
77 
78  for (i = 0; i < 3; i++ ) {
79  for (j = 0; j < 256; j++)
80  if ( img->in_cmap[i][j] != j )
81  break;
82  if (j < 256) break;
83  }
84  /* if i and j are maxed out, then in_cmap is the identity... */
85  if ( i == 3 && j == 256 && !img->mono_color )
86  img->in_cmap = NULL;
87  else
88  if ( debug_flag && !( i == 3 && j == 256) ) {
89  for (i = 0; i < 3; i++ ) {
90  fprintf(stderr, "Input image colormap channel %d:\n", i);
91  if ( i > 0 )
92  for ( j = 0; j < img->cmlen; j++ )
93  if (img->in_cmap[i-1][j] != img->in_cmap[i][j])
94  break;
95  if ( i > 0 && j == img->cmlen )
96  fprintf( stderr, "\tSame as channel %d\n", i - 1 );
97  else
98  for (j = 0; j < img->cmlen; j += 16) {
99  int k;
100  fprintf (stderr, "%3d: ", j );
101  for (k = 0; k < 16 ; k++ )
102  if ( j + k < img->cmlen )
103  fprintf(stderr, "%3d ", img->in_cmap[i][j+k]);
104  fprintf (stderr, "\n");
105  }
106  }
107  }
108 
109  /* make colormap monochrome... Whatahack! */
110  if ( img->mono_color && !img->color_dpy ) {
111  for (j = 0; j < 256; j++)
112  img->in_cmap[0][j] = (rle_pixel)
113  ((30 * img->in_cmap[0][j] + 59 * img->in_cmap[1][j] +
114  11 * img->in_cmap[2][j]) / 100);
115 
116  img->mono_color = False;
117  }
118 }
119 
121 register rle_pixel **cm1, **cm2;
122 int len1, len2;
123 {
124  register int i, j;
125 
126  if (cm1 && cm2) {
127  if ( len1 != len2 )
128  return 0;
129  for (i = 0; i < 3; i++ )
130  for (j = 0; j < len1; j++)
131  if ( cm1[i][j] != cm2[i][j] )
132  return 0;
133  } else
134  if (cm1 || cm2)
135  return 0;
136  return 1;
137 }
int eq_cmap(register rle_pixel **cm1, int len1, register rle_pixel **cm2, int len2)
void check_mono_color(image_information *img, rle_hdr *img_hdr)
Definition: in_cmap.c:32
Boolean debug_flag
Definition: get_orion.c:79
Boolean mono_color
Definition: getx11.h:168
rle_pixel ** buildmap(rle_hdr *the_hdr, int minmap, double orig_gamma, double new_gamma)
Definition: buildmap.c:56
Boolean color_dpy
Definition: getx11.h:169
char * rle_getcom(char *name, rle_hdr *the_hdr) const
Definition: rle_getcom.c:81
Boolean sep_colors
Definition: getx11.h:167
void get_dither_colors(register image_information *img, rle_hdr *img_hdr)
int ncmap
Definition: rle.h:100
unsigned char rle_pixel
Definition: rle.h:56
int cmaplen
Definition: rle.h:100
rle_pixel ** in_cmap
Definition: getx11.h:171
double display_gamma
Definition: getx11.c:64