~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/tv/tv_cmap.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)Colormap handling.  (Tv level)
  2  * cmap_print: prints values of colormap to stdout.
  3  * cmap_show: creates a Colormap Tool & fills with colored squares, overprinted
  4  * by the rgb's. Both fill an array with the rgb's then display values in that.
  5  * tv_screen_cmap_show: show's the colormap of a tv_screen. */
  6 
  7 #include <stdio.h>
  8 #include <string.h>
  9 #include <math.h>
 10 #include <limits.h>
 11 #include <tina/sys.h>
 12 #include <tina/sysfuncs.h>
 13 #include <tina/math.h>
 14 #include <tina/vision.h>
 15 #include <tina/visionfuncs.h>
 16 #include <tina/tv.h>
 17 #include <tina/tvfuncs.h>
 18 #include <tina/toolsfuncs.h>
 19 #include <tina/tw_Xfuncs.h>
 20 
 21 #define FULL_OFF 0
 22 #define FULL_ON 0xff
 23 
 24 /* STATIC GLOBALS */
 25 static Rgb tina_std_colors[] =
 26 {
 27     { /* bkgrnd */ Rgb_id, 255, 255, 255},
 28     { /* black */ Rgb_id, 0, 0, 0},
 29     { /* blue */ Rgb_id, 0, 0, 255},
 30     { /* red */ Rgb_id, 255, 0, 0},
 31     { /* yellow */ Rgb_id, 255, 255, 0},
 32     { /* green */ Rgb_id, 0, 255, 0},
 33     { /* white */ Rgb_id, 255, 255, 255},
 34     { /* aubergine */ Rgb_id, 47, 125, 62},
 35     { /* avocado */ Rgb_id, 137, 184, 137},
 36     { /* baby_blue */ Rgb_id, 160, 199, 255},
 37     { /* baby_pink */ Rgb_id, 255, 176, 176},
 38     { /* brown */ Rgb_id, 165, 42, 42},
 39     { /* chocolate */ Rgb_id, 121, 82, 35},
 40     { /* coffee */ Rgb_id, 156, 117, 39},
 41     { /* cyan */ Rgb_id, 0, 255, 255},
 42     { /* dark_green */ Rgb_id, 0, 100, 0},
 43     { /* dark_slate */ Rgb_id, 47, 79, 79},
 44     { /* gold */ Rgb_id, 234, 195, 78},
 45     { /* heliotrope */ Rgb_id, 234, 160, 164},
 46     { /* indian_red */ Rgb_id, 205, 92, 92},
 47     { /* ivory */ Rgb_id, 227, 227, 215},
 48     { /* magenta */ Rgb_id, 255, 0, 255},
 49     { /* orange */ Rgb_id, 255, 156, 4},
 50     { /* pale_green */ Rgb_id, 152, 251, 152},
 51     { /* plum */ Rgb_id, 176, 4, 156},
 52     { /* salmon */ Rgb_id, 255, 158, 150},
 53     { /* slate */ Rgb_id, 117, 117, 117},
 54     { /* violet */ Rgb_id, 195, 156, 195},
 55     { /* wheat */ Rgb_id, 245, 222, 179},
 56 };                              /* Comments ease sorting */
 57 static int ntina_std_colors = sizeof(tina_std_colors) / sizeof(Rgb);
 58 static int ndefault_colors = 48;/* NB ARBITRARY */
 59 
 60 /* STATIC */
 61 static Bool bespoke_overlay = true;
 62 static int bespoke_ncolors = 32;
 63 static int bespoke_ngreys = 128;
 64 
 65 /* Fill colormap (from cell 'base') with nlevels of red/green colors.
 66  * Also fill cmap_data_visible ->std_lut (lookup table) (starting at
 67  * CMAPLOOKUPGREYSBASE). Green = left = hi nibble. Red = right = lo
 68  * nibble. */
 69 void    cmap_data_anag_fill(Cmap_data_visible * cmap_data_visible, int nlevels, int ngreys, int ncolors, int base)
 70 {
 71     Tina_color *tina_colors = NULL;
 72     int     i;
 73     int     ngreen = (int) sqrt((double) nlevels);
 74     int     nred = ngreen;
 75     int     red, grn;
 76     float   green_step = (float)((ngreen > 1 ? (float) 255 / (ngreen - 1) : 0.0));
 77     float   red_step = (float)((nred > 1 ? (float) 255 / (nred - 1) : 0.0));
 78     if (cmap_data_visible )
 79     {
 80 
 81         tina_colors = TINA_COLOR_ARRAY_CREATE(nred * ngreen);
 82 
 83         /* Fill cmap with rgb's defined in tina_colors */
 84         for (grn = 0; grn < ngreen; grn++)
 85         {                       /* green = left = hi nibble */
 86             for (red = 0; red < nred; red++)
 87             {                   /* red = right = lo nibble */
 88                 tina_colors[(grn * nred + red)].red =
 89                     (unsigned short) (red * red_step) << 8;
 90                 tina_colors[(grn * nred + red)].green =
 91                     (unsigned short) (grn * green_step) << 8;
 92                 tina_colors[(grn * nred + red)].blue =
 93                     (unsigned short) (red * red_step) << 8;
 94             }
 95         }
 96         cmap_store_colors(cmap_data_visible, tina_colors, base+ngreys+ncolors, nred * ngreen);
 97 
 98         /* Store pixels (filled in by cmap_store_colors) in std_lut */
 99         for (i = 0; i < CMAPLOOKUPNUMBEROFGREYS; i++)
100         {
101             int     green_index = (((i >> 4) * ngreen) / 16) * nred;
102             int     red_index = (((i & 0xf) * nred) / 16);
103 
104             cmap_data_visible->std_lut[CMAPLOOKUPGREYSBASE + i ] =
105                 tina_colors[red_index + green_index].pixel;
106         }
107         rfree((void *) tina_colors);
108     }
109 }
110 
111 static double ramp_func(double x)
112 {
113    x = x - 2.0*(floor(x/2.0));
114    if (x<1.0)
115      return(x);
116    else
117      return(2.0-x);
118 }
119 
120 void    cmap_data_false_fill(Cmap_data_visible * cmap_data_visible, int nlevels, int base)
121 {
122     Tina_color *tina_colors = NULL;
123     int     i;
124     int     nblue =  nlevels/2;
125     int     nred = nlevels - nblue;
126     int     index;
127     float   step = 1.0/ (float)nlevels;
128     int     red, blue;
129     float   red_step = (float)((nred > 1 ? (float) 255 / nred  : 0.0));
130     float   blue_step = (float)((nblue > 1 ? (float) 255 / nblue  : 0.0));
131     if (cmap_data_visible )
132     {
133 
134         tina_colors = TINA_COLOR_ARRAY_CREATE(nlevels);
135 
136         /* Fill cmap with rgb's defined in tina_colors */
137         for (index=0; index<nlevels ; index++)
138         {
139             if (index*6.0*step>5.0)
140                tina_colors[index].blue = (unsigned short)
141                                  (255*(1.0-ramp_func(index*step*6.0))) <<8; 
142             else if (index*6.0*step>3.0)
143                tina_colors[index].blue = (unsigned short)  
144                                  (225*(1.0-ramp_func(index*step*6.0))) <<8;
145             else if (index*6.0*step<2.0)
146                tina_colors[index].blue = (unsigned short)
147                                  (200*ramp_func(index*step*6.0)) <<8;
148             else
149                tina_colors[index].blue = 0.0;
150 
151             if (index*6.0*step>5.0)
152                tina_colors[index].green = 255 <<8; 
153             else if (index*6.0*step>4.0)
154                tina_colors[index].green = (unsigned short)
155                                  (255*(ramp_func(index*step*6.0))) <<8;
156             else if (index*6.0*step>3.0)
157                tina_colors[index].green = 0.0;
158             else if (index*6.0*step>1.0)
159                tina_colors[index].green = (unsigned short)
160                                  (225*(1.0-ramp_func(index*step*6.0))) <<8;
161             else
162                tina_colors[index].green = 0.0;
163 
164             if (index*6.0*step>3.0)
165                tina_colors[index].red = 255 <<8; 
166             else if (index*6.0*step>2.0)
167                tina_colors[index].red = (unsigned short)
168                                  (255*ramp_func(index*step*6.0)) <<8;
169             else
170                tina_colors[index].red = 0.0;
171 
172 
173         } 
174         
175         cmap_store_colors(cmap_data_visible, tina_colors, base, nlevels);
176 
177         /* Store pixels (filled in by cmap_store_colors) in std_lut */
178         step = CMAPLOOKUPNUMBEROFGREYS/(float)nlevels;
179         for (i = 0; i < CMAPLOOKUPNUMBEROFGREYS; i++)
180         {
181             cmap_data_visible->std_lut[CMAPLOOKUPGREYSBASE + i] =
182                 tina_colors[(int) (i / (step+0.01))].pixel;
183         }
184         rfree((void *) tina_colors);
185     }
186 }
187 
188 
189 /* Fill colormap (from cell 'base') with 'ncolors' colors, whose rgb's
190  * are in 'rgbs' (range: 0 - 0XFF).  Also fill cmap_data_visible
191  * ->std_lut (lookup table) (starting at CMAPLOOKUPCOLORSBASE). */
192 void    cmap_data_color_fill(Cmap_data_visible * cmap_data_visible, Rgb * rgbs, int ncolors, int base)
193 {
194     if (cmap_data_visible)
195     {
196         Tina_color *tina_colors = TINA_COLOR_ARRAY_CREATE(ncolors);
197         int     i;
198 
199         for (i = 0; i < ncolors; i++)
200         {
201             tina_colors[i].red = rgbs[i].red << 8;
202             tina_colors[i].green = rgbs[i].green << 8;
203             tina_colors[i].blue = rgbs[i].blue << 8;
204         }
205         cmap_store_colors(cmap_data_visible, tina_colors, base, ncolors);
206 
207         /* Ensure sensible tina named colors.  If colors are set in
208          * colormap then fill cmap_lookup cells with their pixels
209          * otherwise leave cells as black. */
210         if (ncolors)
211         {
212             int     i;
213 
214             for (i = 0; i < ncolors; i++)
215             {
216                 cmap_data_visible->std_lut[CMAPLOOKUPCOLORSBASE + i] =
217                     tina_colors[i].pixel;
218             }
219         }
220         rfree((void *) tina_colors);
221     }
222 }
223 
224 static double gam = 1.0;
225 
226 int tv_cmap_gamma_get(Tv *tv)
227 {
228     return((int)gam);
229 }
230 
231 void tv_cmap_gamma_set(Tv *tv, double newgam)
232 {
233     gam = newgam;
234 }
235 
236 /* Fill colormap (from cell 'base') with 'ngreys' greys.  Also fill
237  * cmap_data_visible ->std_lut (lookup table) (starting at
238  * TINA_CMAPGREYSBASE). */
239 void    cmap_data_grey_fill(Cmap_data_visible * cmap_data_visible, int ngreys, int base)
240 {
241     if (cmap_data_visible)
242     {
243         Tina_color *tina_colors;
244         int     i;
245         float   grey_step = (float)(1.0 / (float) (ngreys > 1 ? ngreys - 1 : 1));
246 
247         tina_colors = TINA_COLOR_ARRAY_CREATE(ngreys);
248         for (i = 0; i < ngreys; i++)
249         {
250             double g = 255.0*pow(i*grey_step, gam);
251             tina_colors[i].red = tina_colors[i].green = tina_colors[i].blue =
252                 ((unsigned short) g) << 8;
253         }
254         cmap_store_colors(cmap_data_visible, tina_colors, base, ngreys);
255 
256         /* Store pixels & rgb's in cmap_lookup */
257         grey_step *= (float)(CMAPLOOKUPNUMBEROFGREYS-1);
258         for (i = 0; i < CMAPLOOKUPNUMBEROFGREYS; i++)
259         {
260             cmap_data_visible->std_lut[CMAPLOOKUPGREYSBASE + i] =
261                 tina_colors[(int) (i / grey_step)].pixel;
262         }
263         rfree((void *) tina_colors);
264     }
265 }
266 
267 
268 /* Fill colormap (from cell 'base') with 'ncolors' NAMED colors.  Also
269  * fill cmap_data_visible ->std_lut (lookup table) (starting at
270  * CMAPLOOKUPCOLORSBASE). */
271 void    cmap_data_named_color_fill(Cmap_data_visible * cmap_data_visible, char **color_names, int ncolors, int base)
272 {
273     if (cmap_data_visible)
274     {
275         Rgb    *rgbs = RGB_ARRAY_CREATE(ncolors);
276 
277         named_colors_rgbs_get(cmap_data_visible, color_names, ncolors, rgbs);
278         cmap_data_color_fill(cmap_data_visible, rgbs, ncolors, base);
279         rfree((void *) rgbs);
280     }
281 }
282 
283 /* Fill top half of colormap  with overlay (red). Set
284  * cmap_data_visible->overlay_mask, which when xor'ed with a pixel
285  * (lower in the cmap) gives overlay. Eg for 8 bit pseudocolor screen,
286  * this is 0x80.  */
287 void    cmap_data_overlay_fill(Cmap_data_visible * cmap_data_visible, int noverlays)
288 {
289     if (cmap_data_visible )
290     {
291         Tina_color *tina_colors;
292         int     i;
293         int     ncells = cmap_data_cmap_ncells_get(cmap_data_visible);
294         int     overlay_base = (ncells - noverlays);
295 
296         tina_colors = TINA_COLOR_ARRAY_CREATE(noverlays);
297         for (i = 0; i < noverlays; i++)
298         {
299             tina_colors[i].red = 0xff00;
300             tina_colors[i].green = 0;
301             tina_colors[i].blue = 0;
302         }
303         cmap_store_colors(cmap_data_visible, tina_colors, overlay_base, noverlays);
304         cmap_data_visible->overlay_mask = 0x80;
305         rfree((void *) tina_colors);
306     }
307 }
308 
309 /* Show cmap_array as palette (array of color squares). Print the pixel
310  * (in decimal) & rgb values (in hexadecimal) in the elements of a
311  * cmap. */
312 void    cmap_print(Cmap_data_visible * cmap_data_visible)
313 {
314     if (cmap_data_visible)
315     {
316         int     ncells = cmap_data_cmap_ncells_get(cmap_data_visible);
317         Tina_color *tina_colors = TINA_COLOR_ARRAY_CREATE(ncells);
318 
319         cmap_query_colors(cmap_data_visible, tina_colors, 0, ncells);
320         tina_colors_print(tina_colors, ncells);
321         rfree((void *) tina_colors);
322     }
323 }
324 
325 /* Set the number of colors copied from default colormap. Returns old
326  * value. */
327 int     ndefault_colors_set(int ndefault_colors_val)
328 {
329     int     ndefault_colors_old = ndefault_colors;
330 
331     ndefault_colors = ndefault_colors_val;
332     return ndefault_colors_old;
333 }
334 
335 /* Get the number of colors copied from default colormap. */
336 int     ndefault_colors_get(void)
337 {
338     return ndefault_colors;
339 }
340 
341 /* Return number of tina colors given constraint of colormap model &
342  * nplanes */
343 int     number_of_tina_colors(Cmap_model model, int nplanes)
344 {
345     int     ncolors;
346 
347     switch (model)
348     {
349     case cmap_model_gs:
350         ncolors = 0;
351         break;
352     case cmap_model_col:
353         ncolors = 2 << (nplanes - 2);   /* TEST ONLY  */
354         break;
355     case cmap_model_rgb:
356         ncolors = 20;           /* TEST ONLY  */
357         break;
358     default:
359         (void) printf("number_of_tina_colors: unknown model %d\n", model);
360         break;
361     }
362     return ncolors;
363 }
364 
365 /* Print the pixel (in decimal) & rgb values (in hexadecimal) in the
366  * elements of a tina_color array. */
367 void    tina_colors_print(Tina_color * tina_colors, int size)
368 {
369     int     i;
370 
371     for (i = 0; i < size; i++)
372     {
373         {
374             if (i % 4 == 0)
375                 puts("");
376             (void) printf("%9d %02X %02X %02X", tina_colors[i].pixel,
377                           tina_colors[i].red >> 8,
378                           tina_colors[i].green >> 8,
379                           tina_colors[i].blue >> 8);
380         }
381     }
382     puts("");
383 }
384 
385 /* Ensure sensible tina named colors.  If fewer colors are available
386  * than ntina_colors, then map excess ones onto lower ones. Eg if 6
387  * colors are avalable (and ntina_colors is 29), then set every 6th
388  * entry int the lut to the same as the 0th entry etc */
389 void    tina_colors_set(Cmap_data_visible * cmap_data_visible, int ncolors)
390 {
391     int     i;
392 
393     for (i = 0; i < ncolors; i++)
394     {
395         cmap_data_visible->std_lut[CMAPLOOKUPCOLORSBASE + i] =
396             cmap_data_visible->std_lut[CMAPLOOKUPCOLORSBASE + (i % ncolors)];
397     }
398 }
399 
400 /* Fill a standard tina colormap (does not deal with RGB case). */
401 Cmap_data_visible *tv_generic_cmap_create(Tv * tv, int base, int ngreys, int anaglyph, Rgb * rgbs, int ncolors, int noverlay)
402 {
403     Cmap_data_visible *cmap_data_visible = tv->cmap_data_visible;
404 
405     if (tv && tv->tv_screen)
406     {
407         /* Create a colormap & fill fields in cmap_data_visible (BUT
408          * NOT look up tables) */
409 
410         /* Was colormap was created? (colormap simple enough!) */
411         if (cmap_data_visible)
412         {
413             if (((cmap_data_visible->model == cmap_model_col) ||
414                  (cmap_data_visible->model == cmap_model_rgb) || 
415                  (cmap_data_visible->model == cmap_model_gs)) 
416 /*
417             &&  cmap_data_visible->type == cmap_type_dynamic
418 */
419                )
420             {                   /* colormap writable */
421                 if (ngreys > 0)
422                 {
423                     /* Fill GREYS in colormap & lut */
424                     cmap_data_grey_fill(cmap_data_visible, ngreys, base);
425                 }
426                 if (ngreys < 0)
427                 {
428                    ngreys *= -1;
429                    /* Fill false colors in cmap lut */
430                     cmap_data_false_fill(cmap_data_visible, ngreys, base);
431                 }
432                 if (ncolors && rgbs)
433                 {
434                    /* Fill COLORS in colormap & lut */
435                    cmap_data_color_fill(cmap_data_visible, rgbs, ncolors,
436                          base + ngreys);
437                 }
438                 if (anaglyph > 0)
439                 {
440                     /* Fill ANAGLYPH in colormap & lut */
441                     cmap_data_anag_fill(cmap_data_visible, anaglyph,
442                                         ngreys,ncolors, base);
443                 }
444                 if (noverlay>0 &&  cmap_data_visible->type == cmap_type_dynamic)
445                 {
446                  /* Fill red OVERLAY in colormap & lut */
447                     cmap_data_overlay_fill(cmap_data_visible,noverlay);
448                 } else
449                 {
450                  /* just use something different */
451                     cmap_data_visible->overlay_mask = 0x7fff;
452                 }
453             } else
454             {
455                 errorf(non_fatal, "tv_generic_cmap_create: can't create colormap"
456                        "cmap model: %d\n" "cmap type: %d\n",
457                        cmap_data_visible->model,
458                        cmap_data_visible->type);
459             }
460         } else
461         {
462             errorf(non_fatal, "tv_generic_cmap_create: can't create colormap"
463                    "cmap_data_visible: %p\n", cmap_data_visible);
464 
465         }
466     }
467     return cmap_data_visible;
468 }
469 
470 /* Create & fill an ANAGLYPH tina colormap (does not deal with RGB
471  * case). */
472 Bool    tv_anag_cmap_create(Tv * tv, int base)
473 {
474     Bool    cmap_ok = false;
475 
476     if (tv && tv->tv_screen)
477     {
478         int    anaglyph;
479         Rgb    *rgbs = tina_std_colors;
480         int     ncells =0;
481         int     ngreys = 0;
482         int     noverlays=0;
483         int     nrgbs = 0;
484 
485         tv->cmap_data_visible = tv_screen_cmap_create(tv->tv_screen, base);
486         ncells = cmap_data_cmap_ncells_get(tv->cmap_data_visible);
487         if (tv->cmap_data_visible->type == cmap_type_static)
488         {
489            base = 0;
490            ngreys = 0;
491         }
492         else
493         {
494            base = MIN(base, ncells / 2);   /* Limit cmap cells */
495            ngreys = MAX(32, ncells/2 - base - ntina_std_colors); 
496         }
497 /*        nrgbs = MIN(ntina_std_colors,ncells - base - ngreys -anaglyph);
498 */
499         nrgbs = 6;
500         anaglyph = ncells - base - ngreys - nrgbs;
501 
502         if (ngreys >= 0)
503         {
504             cmap_ok = true;
505             tv->cmap_data_visible = tv_generic_cmap_create(tv, base,
506                                     ngreys, anaglyph,rgbs, nrgbs, noverlays);
507             tina_colors_set(tv->cmap_data_visible, nrgbs);
508 
509         } else
510         {
511             format("tv_anag_cmap_create: not enough cmap cells.\n");
512         }
513     }
514     return cmap_ok;
515 }
516 
517 /* Create & fill an EMPTY colormap. (No default colors.) */
518 Bool    tv_cmap_create(Tv * tv)
519 {
520     Bool    cmap_ok = false;
521 
522     if (tv && tv->tv_screen)
523     {
524         cmap_ok = true;
525         tv->cmap_data_visible = tv_screen_cmap_create(tv->tv_screen, 0);
526     }
527     return cmap_ok;
528 }
529 
530 /* Create & fill a GREYSCALE tina colormap (does not deal with RGB
531  * case). */
532 Bool    tv_grey_cmap_create(Tv * tv, int base)
533 {
534     Bool    cmap_ok = false;
535 
536     if (tv && tv->tv_screen)
537     {
538         int    anaglyph = 0;
539         Bool    overlay = false;
540         Rgb    *rgbs = tina_std_colors;
541         int     ncells = 0;
542         int     ngreys = 0;
543         int     noverlays=0;
544         int     nrgbs = ntina_std_colors;
545 
546         tv->cmap_data_visible = tv_screen_cmap_create(tv->tv_screen, base);
547         ncells = cmap_data_cmap_ncells_get(tv->cmap_data_visible);
548         if (tv->cmap_data_visible->type == cmap_type_static) base = 0;
549         base = MIN(base, ncells / 2);   /* Limit cmap cells */
550         ngreys = MAX(32, ncells - base - ntina_std_colors);
551         nrgbs = MIN(ntina_std_colors,ncells - base - ngreys);
552 
553         if (nrgbs >= 0)
554         {
555             cmap_ok = true;
556             tv->cmap_data_visible = tv_generic_cmap_create(tv, base, ngreys, anaglyph,
557                                                 rgbs, nrgbs, noverlays);
558             tina_colors_set(tv->cmap_data_visible, nrgbs);
559         } else
560         {
561             format("tv_grey_cmap_create: not enough cmap cells.\n");
562         }
563     }
564     return cmap_ok;
565 }
566 
567 /* Create & fill a STANDARD tina colormap (does not deal with RGB
568  * case). */
569 Bool    tv_standard_cmap_create(Tv * tv, int base)
570 {
571     Bool    cmap_ok = false;
572 
573     if (tv && tv->tv_screen)
574     {
575         int    anaglyph = 0;
576         Rgb    *rgbs = tina_std_colors;
577         int     ncells = 0;
578         int     ngreys = 0;
579         int     noverlays;
580         int     nrgbs = 0;
581 
582         tv->cmap_data_visible = tv_screen_cmap_create(tv->tv_screen, base);
583         ncells = cmap_data_cmap_ncells_get(tv->cmap_data_visible);
584         if (tv->cmap_data_visible->type == cmap_type_static) base = 0;
585         base = MIN(base, ncells / 2);   /* Limit cmap cells */
586         noverlays = ncells / 2 - base;
587         ngreys = MAX(32, ncells/2 - base - ntina_std_colors); 
588         nrgbs = MIN(ntina_std_colors,ncells - base - ngreys - noverlays); 
589         noverlays = MIN(ncells / 2, ncells - base - ngreys - nrgbs);
590 
591         if (nrgbs >= 0)
592         {
593             cmap_ok = true;
594             tv->cmap_data_visible = tv_generic_cmap_create(tv, base, ngreys, anaglyph,
595                                                 rgbs, nrgbs, noverlays);
596             tina_colors_set(tv->cmap_data_visible, nrgbs);
597         } else
598         {
599             format("tv_etandard_cmap_create: not enough cmap cells.\n");
600         }
601     }
602     return cmap_ok;
603 }
604 
605 Bool    tv_false_cmap_create(Tv * tv, int base)
606 {
607     Bool    cmap_ok = false;
608 
609     if (tv && tv->tv_screen)
610     {
611         int    anaglyph = 0;
612         Rgb    *rgbs = tina_std_colors;
613         int     ncells = 0;
614         int     ngreys = 0;
615         int     noverlays;
616         int     nrgbs = 0;
617 
618         tv->cmap_data_visible = tv_screen_cmap_create(tv->tv_screen, base);
619         ncells = cmap_data_cmap_ncells_get(tv->cmap_data_visible);
620         if (tv->cmap_data_visible->type == cmap_type_static) base = 0;
621         base = MIN(base, ncells / 2);   /* Limit cmap cells */
622         noverlays = ncells / 2 - base;
623         ngreys = MAX(32, ncells/2 - base - ntina_std_colors);
624         nrgbs = MIN(ntina_std_colors,ncells - base - ngreys - noverlays);
625         noverlays = MIN(ncells / 2, ncells - base - ngreys - nrgbs);
626 
627         if (nrgbs >= 0)
628         {
629             cmap_ok = true;
630             ngreys *= -1;
631             tv->cmap_data_visible = tv_generic_cmap_create(tv, base, ngreys, anaglyph,
632                                                 rgbs, nrgbs, noverlays);
633             tina_colors_set(tv->cmap_data_visible, nrgbs);
634         } else
635         {
636             format("tv_etandard_cmap_create: not enough cmap cells.\n");
637         }
638     }
639     return cmap_ok;
640 }
641 
642 
643 /* Set cmap_create_fn (and set colormap to None) in tv.  So that
644  * reinstalling the tv or calling
645  * tv_screen_cmap_find_and_install(tv_screen, tv_cmap_data) will
646  * install in the tv_screen  a colormap created with the
647  * cmap_create_fn. */
648 void    tv_cmap_create_fn_set(Tv * tv, Bool(*cmap_create_fn) ( /* ??? */ ))
649 {
650     extern void cmap_data_cmap_set();
651 
652     if (tv)
653     {
654         tv->cmap_create_fn = cmap_create_fn;
655         cmap_data_cmap_set(tv->cmap_data_visible, 0);   /* Zero colormap  */
656     }
657 }
658 
659 void    tv_cmap_install(Tv * tv, void *cmap)
660 {
661     void    tv_screen_cmap_install();
662 
663     if (tv)
664     {
665         tv_screen_cmap_install(tv->tv_screen, cmap);
666     }
667 }
668 
669 
670 
671 /* Get the number of cells in the colormap of a tv's tv_screen. */
672 /*
673 int     tv_cmap_ncells_get(Tv * tv)
674 {
675     int     ncells = 0;
676 
677     if (tv)
678     {
679         ncells = tv_screen_cmap_ncells_get(tv->tv_screen);
680     }
681     return ncells;
682 }
683 */
684 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.