1 /*********
2 * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
3 * University of Manchester, UK. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * . Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * . Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * . Neither the name of the University of Manchester nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 *
32 **********
33 *
34 * Program : TINA
35 * File : $Source: /home/tina/cvs/tina-tools/tinatool/draw/drawTv_cmap.c,v $
36 * Date : $Date: 2005/07/03 23:43:56 $
37 * Version : $Revision: 1.4 $
38 * CVS Id : $Id: drawTv_cmap.c,v 1.4 2005/07/03 23:43:56 paul Exp $
39 *
40 * Author : Legacy TINA
41 *
42 * Notes :
43 * cmap_print: prints values of colormap to stdout.
44 * cmap_show: creates a Colormap Tool & fills with colored squares, overprinted
45 * by the rgb's. Both fill an array with the rgb's then display values in that.
46 * tv_screen_cmap_show: show's the colormap of a tv_screen.
47 *
48 *********
49 */
50
51 #include "drawTv_cmap.h"
52
53 #if HAVE_CONFIG_H
54 #include <config.h>
55 #endif
56
57 #include <stdio.h>
58 #include <string.h>
59 #include <math.h>
60 #include <limits.h>
61 #include <tina/sys/sysDef.h>
62 #include <tina/sys/sysPro.h>
63 #include <tina/math/mathDef.h>
64 #include <tina/geometry/geomDef.h>
65 #include <tina/geometry/geomPro.h>
66 #include <tinatool/draw/draw_TvDef.h>
67 #include <tinatool/draw/draw_TvPro.h>
68 #include <tinatool/gphx/gphxPro.h>
69 #include <tinatool/gphx/gphxDef.h>
70
71 #define FULL_OFF 0
72 #define FULL_ON 0xff
73
74 /* STATIC GLOBALS */
75 static Rgb tina_std_colors[] =
76 {
77 { /* bkgrnd */ Rgb_id, 255, 255, 255},
78 { /* black */ Rgb_id, 0, 0, 0},
79 { /* blue */ Rgb_id, 0, 0, 255},
80 { /* red */ Rgb_id, 255, 0, 0},
81 { /* yellow */ Rgb_id, 255, 255, 0},
82 { /* green */ Rgb_id, 0, 255, 0},
83 { /* white */ Rgb_id, 255, 255, 255},
84 { /* aubergine */ Rgb_id, 47, 125, 62},
85 { /* avocado */ Rgb_id, 137, 184, 137},
86 { /* baby_blue */ Rgb_id, 160, 199, 255},
87 { /* baby_pink */ Rgb_id, 255, 176, 176},
88 { /* brown */ Rgb_id, 165, 42, 42},
89 { /* chocolate */ Rgb_id, 121, 82, 35},
90 { /* coffee */ Rgb_id, 156, 117, 39},
91 { /* cyan */ Rgb_id, 0, 255, 255},
92 { /* dark_green */ Rgb_id, 0, 100, 0},
93 { /* dark_slate */ Rgb_id, 47, 79, 79},
94 { /* gold */ Rgb_id, 234, 195, 78},
95 { /* heliotrope */ Rgb_id, 234, 160, 164},
96 { /* indian_red */ Rgb_id, 205, 92, 92},
97 { /* ivory */ Rgb_id, 227, 227, 215},
98 { /* magenta */ Rgb_id, 255, 0, 255},
99 { /* orange */ Rgb_id, 255, 156, 4},
100 { /* pale_green */ Rgb_id, 152, 251, 152},
101 { /* plum */ Rgb_id, 176, 4, 156},
102 { /* salmon */ Rgb_id, 255, 158, 150},
103 { /* slate */ Rgb_id, 117, 117, 117},
104 { /* violet */ Rgb_id, 195, 156, 195},
105 { /* wheat */ Rgb_id, 245, 222, 179},
106 }; /* Comments ease sorting */
107 static int ntina_std_colors = sizeof(tina_std_colors) / sizeof(Rgb);
108 static int ndefault_colors = 48;/* NB ARBITRARY */
109
110 /* STATIC */
111 static Bool bespoke_overlay = true;
112 static int bespoke_ncolors = 32;
113 static int bespoke_ngreys = 128;
114
115 /* Fill colormap (from cell 'base') with nlevels of red/green colors.
116 * Also fill cmap_data_visible ->std_lut (lookup table) (starting at
117 * CMAPLOOKUPGREYSBASE). Green = left = hi nibble. Red = right = lo
118 * nibble. */
119 void cmap_data_anag_fill(Cmap_data_visible * cmap_data_visible, int nlevels, int ngreys, int ncolors, int base)
120 {
121 Tina_color *tina_colors = NULL;
122 int i;
123 int ngreen = (int) sqrt((double) nlevels);
124 int nred = ngreen;
125 int red, grn;
126 float green_step = (float)((ngreen > 1 ? (float) 255 / (ngreen - 1) : 0.0));
127 float red_step = (float)((nred > 1 ? (float) 255 / (nred - 1) : 0.0));
128 if (cmap_data_visible )
129 {
130
131 tina_colors = TINA_COLOR_ARRAY_CREATE(nred * ngreen);
132
133 /* Fill cmap with rgb's defined in tina_colors */
134 for (grn = 0; grn < ngreen; grn++)
135 { /* green = left = hi nibble */
136 for (red = 0; red < nred; red++)
137 { /* red = right = lo nibble */
138 tina_colors[(grn * nred + red)].red =
139 (unsigned short) (red * red_step) << 8;
140 tina_colors[(grn * nred + red)].green =
141 (unsigned short) (grn * green_step) << 8;
142 tina_colors[(grn * nred + red)].blue =
143 (unsigned short) (red * red_step) << 8;
144 }
145 }
146 cmap_store_colors((Cmap_data *)cmap_data_visible, tina_colors, base+ngreys+ncolors, nred * ngreen);
147
148 /* Store pixels (filled in by cmap_store_colors) in std_lut */
149 for (i = 0; i < CMAPLOOKUPNUMBEROFGREYS; i++)
150 {
151 int green_index = (((i >> 4) * ngreen) / 16) * nred;
152 int red_index = (((i & 0xf) * nred) / 16);
153
154 cmap_data_visible->std_lut[CMAPLOOKUPGREYSBASE + i ] =
155 tina_colors[red_index + green_index].pixel;
156 }
157 rfree((void *) tina_colors);
158 }
159 }
160
161 static double ramp_func(double x)
162 {
163 x = x - 2.0*(floor(x/2.0));
164 if (x<1.0)
165 return(x);
166 else
167 return(2.0-x);
168 }
169
170 void cmap_data_false_fill(Cmap_data_visible * cmap_data_visible, int nlevels, int base)
171 {
172 Tina_color *tina_colors = NULL;
173 int i;
174 int nblue = nlevels/2;
175 int nred = nlevels - nblue;
176 int index;
177 float step = 1.0/ (float)nlevels;
178 int red, blue;
179 float red_step = (float)((nred > 1 ? (float) 255 / nred : 0.0));
180 float blue_step = (float)((nblue > 1 ? (float) 255 / nblue : 0.0));
181 if (cmap_data_visible )
182 {
183
184 tina_colors = TINA_COLOR_ARRAY_CREATE(nlevels);
185
186 /* Fill cmap with rgb's defined in tina_colors */
187 for (index=0; index<nlevels ; index++)
188 {
189 if (index*6.0*step>5.0)
190 tina_colors[index].blue = (unsigned short)
191 (255*(1.0-ramp_func(index*step*6.0))) <<8;
192 else if (index*6.0*step>3.0)
193 tina_colors[index].blue = (unsigned short)
194 (225*(1.0-ramp_func(index*step*6.0))) <<8;
195 else if (index*6.0*step<2.0)
196 tina_colors[index].blue = (unsigned short)
197 (200*ramp_func(index*step*6.0)) <<8;
198 else
199 tina_colors[index].blue = 0.0;
200
201 if (index*6.0*step>5.0)
202 tina_colors[index].green = 255 <<8;
203 else if (index*6.0*step>4.0)
204 tina_colors[index].green = (unsigned short)
205 (255*(ramp_func(index*step*6.0))) <<8;
206 else if (index*6.0*step>3.0)
207 tina_colors[index].green = 0.0;
208 else if (index*6.0*step>1.0)
209 tina_colors[index].green = (unsigned short)
210 (225*(1.0-ramp_func(index*step*6.0))) <<8;
211 else
212 tina_colors[index].green = 0.0;
213
214 if (index*6.0*step>3.0)
215 tina_colors[index].red = 255 <<8;
216 else if (index*6.0*step>2.0)
217 tina_colors[index].red = (unsigned short)
218 (255*ramp_func(index*step*6.0)) <<8;
219 else
220 tina_colors[index].red = 0.0;
221
222
223 }
224
225 cmap_store_colors((Cmap_data *)cmap_data_visible, tina_colors, base, nlevels);
226
227 /* Store pixels (filled in by cmap_store_colors) in std_lut */
228 step = CMAPLOOKUPNUMBEROFGREYS/(float)nlevels;
229 for (i = 0; i < CMAPLOOKUPNUMBEROFGREYS; i++)
230 {
231 cmap_data_visible->std_lut[CMAPLOOKUPGREYSBASE + i] =
232 tina_colors[(int) (i / (step+0.01))].pixel;
233 }
234 rfree((void *) tina_colors);
235 }
236 }
237
238
239 /* Fill colormap (from cell 'base') with 'ncolors' colors, whose rgb's
240 * are in 'rgbs' (range: 0 - 0XFF). Also fill cmap_data_visible
241 * ->std_lut (lookup table) (starting at CMAPLOOKUPCOLORSBASE). */
242 void cmap_data_color_fill(Cmap_data_visible * cmap_data_visible, Rgb * rgbs, int ncolors, int base)
243 {
244 if (cmap_data_visible)
245 {
246 Tina_color *tina_colors = TINA_COLOR_ARRAY_CREATE(ncolors);
247 int i;
248
249 for (i = 0; i < ncolors; i++)
250 {
251 tina_colors[i].red = rgbs[i].red << 8;
252 tina_colors[i].green = rgbs[i].green << 8;
253 tina_colors[i].blue = rgbs[i].blue << 8;
254 }
255 cmap_store_colors((Cmap_data *)cmap_data_visible, tina_colors, base, ncolors);
256
257 /* Ensure sensible tina named colors. If colors are set in
258 * colormap then fill cmap_lookup cells with their pixels
259 * otherwise leave cells as black. */
260 if (ncolors)
261 {
262 int i;
263
264 for (i = 0; i < ncolors; i++)
265 {
266 cmap_data_visible->std_lut[CMAPLOOKUPCOLORSBASE + i] =
267 tina_colors[i].pixel;
268 }
269 }
270 rfree((void *) tina_colors);
271 }
272 }
273
274 static double gam = 1.0;
275
276 int tv_cmap_gamma_get(Tv *tv)
277 {
278 return((int)gam);
279 }
280
281 void tv_cmap_gamma_set(Tv *tv, double newgam)
282 {
283 gam = newgam;
284 }
285
286 /* Fill colormap (from cell 'base') with 'ngreys' greys. Also fill
287 * cmap_data_visible ->std_lut (lookup table) (starting at
288 * TINA_CMAPGREYSBASE). */
289 void cmap_data_grey_fill(Cmap_data_visible * cmap_data_visible, int ngreys, int base)
290 {
291 if (cmap_data_visible)
292 {
293 Tina_color *tina_colors;
294 int i;
295 float grey_step = (float)(1.0 / (float) (ngreys > 1 ? ngreys - 1 : 1));
296
297 tina_colors = TINA_COLOR_ARRAY_CREATE(ngreys);
298 for (i = 0; i < ngreys; i++)
299 {
300 double g = 255.0*pow(i*grey_step, gam);
301 tina_colors[i].red = tina_colors[i].green = tina_colors[i].blue =
302 ((unsigned short) g) << 8;
303 }
304 cmap_store_colors((Cmap_data *)cmap_data_visible, tina_colors, base, ngreys);
305
306 /* Store pixels & rgb's in cmap_lookup */
307 grey_step *= (float)(CMAPLOOKUPNUMBEROFGREYS-1);
308 for (i = 0; i < CMAPLOOKUPNUMBEROFGREYS; i++)
309 {
310 cmap_data_visible->std_lut[CMAPLOOKUPGREYSBASE + i] =
311 tina_colors[(int) (i / grey_step)].pixel;
312 }
313 rfree((void *) tina_colors);
314 }
315 }
316
317
318 /* Fill colormap (from cell 'base') with 'ncolors' NAMED colors. Also
319 * fill cmap_data_visible ->std_lut (lookup table) (starting at
320 * CMAPLOOKUPCOLORSBASE). */
321 void cmap_data_named_color_fill(Cmap_data_visible * cmap_data_visible, char **color_names, int ncolors, int base)
322 {
323 if (cmap_data_visible)
324 {
325 Rgb *rgbs = RGB_ARRAY_CREATE(ncolors);
326
327 named_colors_rgbs_get((Cmap_data *)cmap_data_visible, color_names, ncolors, rgbs);
328 cmap_data_color_fill(cmap_data_visible, rgbs, ncolors, base);
329 rfree((void *) rgbs);
330 }
331 }
332
333 /* Fill top half of colormap with overlay (red). Set
334 * cmap_data_visible->overlay_mask, which when xor'ed with a pixel
335 * (lower in the cmap) gives overlay. Eg for 8 bit pseudocolor screen,
336 * this is 0x80. */
337 void cmap_data_overlay_fill(Cmap_data_visible * cmap_data_visible, int noverlays)
338 {
339 if (cmap_data_visible )
340 {
341 Tina_color *tina_colors;
342 int i;
343 int ncells = cmap_data_cmap_ncells_get((Cmap_data *)cmap_data_visible);
344 int overlay_base = (ncells - noverlays);
345
346 tina_colors = TINA_COLOR_ARRAY_CREATE(noverlays);
347 for (i = 0; i < noverlays; i++)
348 {
349 tina_colors[i].red = 0xff00;
350 tina_colors[i].green = 0;
351 tina_colors[i].blue = 0;
352 }
353 cmap_store_colors((Cmap_data *)cmap_data_visible, tina_colors, overlay_base, noverlays);
354 cmap_data_visible->overlay_mask = 0x80;
355 rfree((void *) tina_colors);
356 }
357 }
358
359 /* Show cmap_array as palette (array of color squares). Print the pixel
360 * (in decimal) & rgb values (in hexadecimal) in the elements of a
361 * cmap. */
362 void cmap_print(Cmap_data_visible * cmap_data_visible)
363 {
364 if (cmap_data_visible)
365 {
366 int ncells = cmap_data_cmap_ncells_get((Cmap_data *)cmap_data_visible);
367 Tina_color *tina_colors = TINA_COLOR_ARRAY_CREATE(ncells);
368
369 cmap_query_colors((Cmap_data *)cmap_data_visible, tina_colors, 0, ncells);
370 tina_colors_print(tina_colors, ncells);
371 rfree((void *) tina_colors);
372 }
373 }
374
375 /* Set the number of colors copied from default colormap. Returns old
376 * value. */
377 int ndefault_colors_set(int ndefault_colors_val)
378 {
379 int ndefault_colors_old = ndefault_colors;
380
381 ndefault_colors = ndefault_colors_val;
382 return ndefault_colors_old;
383 }
384
385 /* Get the number of colors copied from default colormap. */
386 int ndefault_colors_get(void)
387 {
388 return ndefault_colors;
389 }
390
391 /* Return number of tina colors given constraint of colormap model &
392 * nplanes */
393 int number_of_tina_colors(Cmap_model model, int nplanes)
394 {
395 int ncolors;
396
397 switch (model)
398 {
399 case cmap_model_gs:
400 ncolors = 0;
401 break;
402 case cmap_model_col:
403 ncolors = 2 << (nplanes - 2); /* TEST ONLY */
404 break;
405 case cmap_model_rgb:
406 ncolors = 20; /* TEST ONLY */
407 break;
408 default:
409 (void) printf("number_of_tina_colors: unknown model %d\n", model);
410 break;
411 }
412 return ncolors;
413 }
414
415 /* Print the pixel (in decimal) & rgb values (in hexadecimal) in the
416 * elements of a tina_color array. */
417 void tina_colors_print(Tina_color * tina_colors, int size)
418 {
419 int i;
420
421 for (i = 0; i < size; i++)
422 {
423 {
424 if (i % 4 == 0)
425 puts("");
426 (void) printf("%9d %02X %02X %02X", tina_colors[i].pixel,
427 tina_colors[i].red >> 8,
428 tina_colors[i].green >> 8,
429 tina_colors[i].blue >> 8);
430 }
431 }
432 puts("");
433 }
434
435 /* Ensure sensible tina named colors. If fewer colors are available
436 * than ntina_colors, then map excess ones onto lower ones. Eg if 6
437 * colors are avalable (and ntina_colors is 29), then set every 6th
438 * entry int the lut to the same as the 0th entry etc */
439 void tina_colors_set(Cmap_data_visible * cmap_data_visible, int ncolors)
440 {
441 int i;
442
443 for (i = 0; i < ncolors; i++)
444 {
445 cmap_data_visible->std_lut[CMAPLOOKUPCOLORSBASE + i] =
446 cmap_data_visible->std_lut[CMAPLOOKUPCOLORSBASE + (i % ncolors)];
447 }
448 }
449
450 /* Fill a standard tina colormap (does not deal with RGB case). */
451 Cmap_data_visible *tv_generic_cmap_create(Tv * tv, int base, int ngreys, int anaglyph, Rgb * rgbs, int ncolors, int noverlay)
452 {
453 Cmap_data_visible *cmap_data_visible = tv->cmap_data_visible;
454
455 if (tv && tv->tv_screen)
456 {
457 /* Create a colormap & fill fields in cmap_data_visible (BUT
458 * NOT look up tables) */
459
460 /* Was colormap was created? (colormap simple enough!) */
461 if (cmap_data_visible)
462 {
463 if (((cmap_data_visible->model == cmap_model_col) ||
464 (cmap_data_visible->model == cmap_model_rgb) ||
465 (cmap_data_visible->model == cmap_model_gs))
466 /*
467 && cmap_data_visible->type == cmap_type_dynamic
468 */
469 )
470 { /* colormap writable */
471 if (ngreys > 0)
472 {
473 /* Fill GREYS in colormap & lut */
474 cmap_data_grey_fill(cmap_data_visible, ngreys, base);
475 }
476 if (ngreys < 0)
477 {
478 ngreys *= -1;
479 /* Fill false colors in cmap lut */
480 cmap_data_false_fill(cmap_data_visible, ngreys, base);
481 }
482 if (ncolors && rgbs)
483 {
484 /* Fill COLORS in colormap & lut */
485 cmap_data_color_fill(cmap_data_visible, rgbs, ncolors,
486 base + ngreys);
487 }
488 if (anaglyph > 0)
489 {
490 /* Fill ANAGLYPH in colormap & lut */
491 cmap_data_anag_fill(cmap_data_visible, anaglyph,
492 ngreys,ncolors, base);
493 }
494 if (noverlay>0 && cmap_data_visible->type == cmap_type_dynamic)
495 {
496 /* Fill red OVERLAY in colormap & lut */
497 cmap_data_overlay_fill(cmap_data_visible,noverlay);
498 } else
499 {
500 /* just use something different */
501 cmap_data_visible->overlay_mask = 0x7fff;
502 }
503 } else
504 {
505 errorf(non_fatal, "tv_generic_cmap_create: can't create colormap"
506 "cmap model: %d\n" "cmap type: %d\n",
507 cmap_data_visible->model,
508 cmap_data_visible->type);
509 }
510 } else
511 {
512 errorf(non_fatal, "tv_generic_cmap_create: can't create colormap"
513 "cmap_data_visible: %p\n", cmap_data_visible);
514
515 }
516 }
517 return cmap_data_visible;
518 }
519
520 /* Create & fill an ANAGLYPH tina colormap (does not deal with RGB
521 * case). */
522 Bool tv_anag_cmap_create(Tv * tv, int base)
523 {
524 Bool cmap_ok = false;
525
526 if (tv && tv->tv_screen)
527 {
528 int anaglyph;
529 Rgb *rgbs = tina_std_colors;
530 int ncells =0;
531 int ngreys = 0;
532 int noverlays=0;
533 int nrgbs = 0;
534
535 tv->cmap_data_visible = (Cmap_data_visible *)tv_screen_cmap_create(tv->tv_screen, base);
536 ncells = cmap_data_cmap_ncells_get((Cmap_data *)(tv->cmap_data_visible));
537 if (tv->cmap_data_visible->type == cmap_type_static)
538 {
539 base = 0;
540 ngreys = 0;
541 }
542 else
543 {
544 base = MIN(base, ncells / 2); /* Limit cmap cells */
545 ngreys = MAX(32, ncells/2 - base - ntina_std_colors);
546 }
547 /* nrgbs = MIN(ntina_std_colors,ncells - base - ngreys -anaglyph);
548 */
549 nrgbs = 6;
550 anaglyph = ncells - base - ngreys - nrgbs;
551
552 if (ngreys >= 0)
553 {
554 cmap_ok = true;
555 tv->cmap_data_visible = tv_generic_cmap_create(tv, base,
556 ngreys, anaglyph,rgbs, nrgbs, noverlays);
557 tina_colors_set(tv->cmap_data_visible, nrgbs);
558
559 } else
560 {
561 format("tv_anag_cmap_create: not enough cmap cells.\n");
562 }
563 }
564 return cmap_ok;
565 }
566
567 /* Create & fill an EMPTY colormap. (No default colors.) */
568 Bool tv_cmap_create(Tv * tv)
569 {
570 Bool cmap_ok = false;
571
572 if (tv && tv->tv_screen)
573 {
574 cmap_ok = true;
575 tv->cmap_data_visible = (Cmap_data_visible *)tv_screen_cmap_create(tv->tv_screen, 0);
576 }
577 return cmap_ok;
578 }
579
580 /* Create & fill a GREYSCALE tina colormap (does not deal with RGB
581 * case). */
582 Bool tv_grey_cmap_create(Tv * tv, int base)
583 {
584 Bool cmap_ok = false;
585
586 if (tv && tv->tv_screen)
587 {
588 int anaglyph = 0;
589 Bool overlay = false;
590 Rgb *rgbs = tina_std_colors;
591 int ncells = 0;
592 int ngreys = 0;
593 int noverlays=0;
594 int nrgbs = ntina_std_colors;
595
596 tv->cmap_data_visible = (Cmap_data_visible *)tv_screen_cmap_create(tv->tv_screen, base);
597 ncells = cmap_data_cmap_ncells_get((Cmap_data *)(tv->cmap_data_visible));
598 if (tv->cmap_data_visible->type == cmap_type_static) base = 0;
599 base = MIN(base, ncells / 2); /* Limit cmap cells */
600 ngreys = MAX(32, ncells - base - ntina_std_colors);
601 nrgbs = MIN(ntina_std_colors,ncells - base - ngreys);
602
603 if (nrgbs >= 0)
604 {
605 cmap_ok = true;
606 tv->cmap_data_visible = tv_generic_cmap_create(tv, base, ngreys, anaglyph,
607 rgbs, nrgbs, noverlays);
608 tina_colors_set(tv->cmap_data_visible, nrgbs);
609 } else
610 {
611 format("tv_grey_cmap_create: not enough cmap cells.\n");
612 }
613 }
614 return cmap_ok;
615 }
616
617 /* Create & fill a STANDARD tina colormap (does not deal with RGB
618 * case). */
619 Bool tv_standard_cmap_create(Tv * tv, int base)
620 {
621 Bool cmap_ok = false;
622
623 if (tv && tv->tv_screen)
624 {
625 int anaglyph = 0;
626 Rgb *rgbs = tina_std_colors;
627 int ncells = 0;
628 int ngreys = 0;
629 int noverlays;
630 int nrgbs = 0;
631
632 tv->cmap_data_visible = (Cmap_data_visible *)tv_screen_cmap_create(tv->tv_screen, base);
633 ncells = cmap_data_cmap_ncells_get((Cmap_data *)(tv->cmap_data_visible));
634 if (tv->cmap_data_visible->type == cmap_type_static) base = 0;
635 base = MIN(base, ncells / 2); /* Limit cmap cells */
636 noverlays = ncells / 2 - base;
637 ngreys = MAX(32, ncells/2 - base - ntina_std_colors);
638 nrgbs = MIN(ntina_std_colors,ncells - base - ngreys - noverlays);
639 noverlays = MIN(ncells / 2, ncells - base - ngreys - nrgbs);
640
641 if (nrgbs >= 0)
642 {
643 cmap_ok = true;
644 tv->cmap_data_visible = tv_generic_cmap_create(tv, base, ngreys, anaglyph,
645 rgbs, nrgbs, noverlays);
646 tina_colors_set(tv->cmap_data_visible, nrgbs);
647 } else
648 {
649 format("tv_etandard_cmap_create: not enough cmap cells.\n");
650 }
651 }
652 return cmap_ok;
653 }
654
655 Bool tv_false_cmap_create(Tv * tv, int base)
656 {
657 Bool cmap_ok = false;
658
659 if (tv && tv->tv_screen)
660 {
661 int anaglyph = 0;
662 Rgb *rgbs = tina_std_colors;
663 int ncells = 0;
664 int ngreys = 0;
665 int noverlays;
666 int nrgbs = 0;
667
668 tv->cmap_data_visible = (Cmap_data_visible *)tv_screen_cmap_create(tv->tv_screen, base);
669 ncells = cmap_data_cmap_ncells_get((Cmap_data *)(tv->cmap_data_visible));
670 if (tv->cmap_data_visible->type == cmap_type_static) base = 0;
671 base = MIN(base, ncells / 2); /* Limit cmap cells */
672 noverlays = ncells / 2 - base;
673 ngreys = MAX(32, ncells/2 - base - ntina_std_colors);
674 nrgbs = MIN(ntina_std_colors,ncells - base - ngreys - noverlays);
675 noverlays = MIN(ncells / 2, ncells - base - ngreys - nrgbs);
676
677 if (nrgbs >= 0)
678 {
679 cmap_ok = true;
680 ngreys *= -1;
681 tv->cmap_data_visible = tv_generic_cmap_create(tv, base, ngreys, anaglyph,
682 rgbs, nrgbs, noverlays);
683 tina_colors_set(tv->cmap_data_visible, nrgbs);
684 } else
685 {
686 format("tv_etandard_cmap_create: not enough cmap cells.\n");
687 }
688 }
689 return cmap_ok;
690 }
691
692
693 /* Set cmap_create_fn (and set colormap to None) in tv. So that
694 * reinstalling the tv or calling
695 * tv_screen_cmap_find_and_install(tv_screen, tv_cmap_data) will
696 * install in the tv_screen a colormap created with the
697 * cmap_create_fn. */
698 void tv_cmap_create_fn_set(Tv * tv, Bool(*cmap_create_fn) ( /* ??? */ ))
699 {
700 if (tv)
701 {
702 tv->cmap_create_fn = cmap_create_fn;
703 cmap_data_cmap_set((Cmap_data *)(tv->cmap_data_visible), 0); /* Zero colormap */
704 }
705 }
706
707 void tv_cmap_install(Tv * tv, void *cmap)
708 {
709 if (tv)
710 {
711 tv_screen_cmap_install(tv->tv_screen, (Colormap)cmap);
712 }
713 }
714
715
716
717 /* Get the number of cells in the colormap of a tv's tv_screen. */
718 /*
719 int tv_cmap_ncells_get(Tv * tv)
720 {
721 int ncells = 0;
722
723 if (tv)
724 {
725 ncells = tv_screen_cmap_ncells_get(tv->tv_screen);
726 }
727 return ncells;
728 }
729 */
730
731 void tv_cmap_lookup_print(Tv * tv)
732 {
733 if (tv)
734 {
735 int i;
736
737
738 for (i = 0; i < CMAPLOOKUPSIZE; i++)
739 {
740 switch (i)
741 {
742 case CMAPLOOKUPGREYSBASE:
743 (void) format("\nGreys");
744 break;
745
746 case CMAPLOOKUPCOLORSBASE:
747 (void) format("\nColors");
748 break;
749 }
750
751 if (i % 8 == 0)
752 {
753 (void) format("\n%8x", i);
754 }
755 (void) format("%8x", (unsigned long) tv->cmap_data_visible->std_lut[i]);
756 }
757 (void) format("\noverlay_mask: %8x\n",
758 (unsigned long) tv->cmap_data_visible->overlay_mask);
759 }
760 }
761
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.