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

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

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

  1 /**@(#)Show colormap.  (Tv level)
  2  * (Separate from tv_cmap.c to avoid library order problems)
  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
  5  that. */
  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 
 20 /* EXTERNS */
 21 extern void cmap_store_colors();
 22 extern void named_colors_rgbs_get();
 23 extern Cmap_data_visible *tv_screen_cmap_create();
 24 extern Rgb *cmap_query_colors();
 25 extern void tw_show_tool();
 26 
 27 /* STATICS */
 28 static int cmap_tool_cmap = 0;
 29 static Tina_color *cmap_tool_tina_colors = NULL;
 30 static int cmap_tool_size = 0;
 31 
 32 /* Show cmap as palette (array of color squares). */
 33 void    cmap_show(Cmap_data_visible * cmap_data_visible, Tv*cmap_tv)
 34 {
 35     extern int     cmap_data_cmap_ncells_get(Cmap_data_visible * cmap_data) ;
 36     void   *cmap_data_cmap_get();
 37 
 38     if (cmap_data_visible)
 39     {
 40         int     ncells = cmap_data_cmap_ncells_get(cmap_data_visible);
 41         Tina_color *tina_colors = TINA_COLOR_ARRAY_CREATE(ncells);
 42         int     cmap = (int) cmap_data_cmap_get(cmap_data_visible);
 43 
 44         /* Set window header */
 45         (void) sprintf (cmap_tv->label, "Colormap: %x.", cmap);
 46         tv_set_header (cmap_tv, cmap_tv->label);
 47 
 48         /* Set redraw function to draw colors */
 49         (void) tv_set_fulldraw (cmap_tv, cmap_tool_redraw);
 50 
 51         (void) cmap_query_colors(cmap_data_visible, tina_colors, 0, ncells);
 52 
 53         tina_colors_show(cmap, tina_colors, ncells,cmap_tv);
 54         rfree((void *) tina_colors);
 55     }
 56 }
 57 
 58 /* Repaint cells in a cmap as colored squares in a window on screen,
 59  * overprint with rgb's */
 60 void    cmap_tool_redraw(Tv * tv)
 61 {
 62     if (tv && tv->tv_screen)
 63     {
 64         char    red[3], green[3], blue[3];
 65         int     cols = (int) ceil(sqrt((double) cmap_tool_size));
 66         int     cell_side = tv_get_width(tv) / cols;
 67         int     i;
 68         int     lineht = cell_side / 4;
 69         int     rows = (int) ceil((double) cmap_tool_size / cols);
 70         int     x;
 71         int     y;
 72 
 73         /* Draw colored squares */
 74         for (i = 0; i < cmap_tool_size; i++)
 75         {
 76             x = (i % cols) * cell_side;
 77             y = (i / rows) * cell_side;
 78             tv_color_reset(tv, cmap_tool_tina_colors[i].pixel);
 79             tv_fillrectxy(tv, x, y, x + cell_side, y + cell_side);
 80         }
 81 
 82         /* Overprint with rgb's */
 83         tv_color_set(tv, black);
 84         for (i = 0; i < cmap_tool_size; i++)
 85         {
 86             x = (i % cols) * cell_side;
 87             y = (i / rows) * cell_side;
 88 
 89             (void) sprintf(red, "%02x", cmap_tool_tina_colors[i].red >> 8);
 90             (void) sprintf(green, "%02x", cmap_tool_tina_colors[i].green >> 8);
 91             (void) sprintf(blue, "%02x", cmap_tool_tina_colors[i].blue >> 8);
 92             tv_textxy(tv, red, x, y += lineht);
 93             tv_textxy(tv, green, x, y += lineht);
 94             tv_textxy(tv, blue, x, y += lineht);
 95         }
 96     }
 97 }
 98 
 99 /* Show the cells in a cmap as colored squares in a window on screen,
100  * overprint with rgb's */
101 void    tina_colors_show(int cmap, Tina_color * tina_colors, int size,Tv*cmap_tv)
102 {
103     int     i;
104 
105     if (cmap_tool_tina_colors)
106     {
107         rfree((void *) cmap_tool_tina_colors);
108     }
109     /* Save cmap & size for use by repaints */
110     cmap_tool_cmap = cmap;
111     cmap_tool_size = size;
112 
113     /* Save rgb & pixel arrays for use by repaints */
114     cmap_tool_tina_colors = TINA_COLOR_ARRAY_CREATE(size);
115     for (i = 0; i < size; i++)
116     {
117         cmap_tool_tina_colors[i] = tina_colors[i];
118     }
119 
120     tv_cmap_install(cmap_tv, (void *) cmap);
121     tv_repaint(cmap_tv);
122 }
123 

~ [ 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.