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

Linux Cross Reference
Tina4/src/X11/color.c

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

  1 /**@(#)Color handling in a tv_screen (X11 version)
  2   **/
  3 #include <stdio.h>
  4 #include <string.h>
  5 #include <math.h>
  6 #include <signal.h>
  7 #include <limits.h>
  8 #include <tina/sys.h>
  9 #include <tina/sysfuncs.h>
 10 #include <tina/math.h>
 11 #include <tina/vision.h>
 12 #include <tina/visionfuncs.h>
 13 #include <tina/tv.h>
 14 #include <tina/toolsfuncs.h>
 15 #include <tina/tv_screen.h>
 16 #include <tina/X11funcs.h>
 17 
 18 
 19 /* Set the background color of a tv_screen to X pixel given */
 20 void    tv_screen_background_set(Tv_screen * tv_screen, long unsigned int color)
 21 {
 22     if (tv_screen)
 23     {
 24         XSetWindowBackground(tv_screen->display, tv_screen->window, color);
 25     }
 26 }
 27 
 28 
 29 /* Set the foreground color of a tv_screen to X pixel given */
 30 void    tv_screen_color_set(Tv_screen * tv_screen, long unsigned int color)
 31 {
 32     if (tv_screen)
 33     {
 34         XSetForeground(tv_screen->display, tv_screen->gc, color);
 35     }
 36 }
 37 
 38 /* Reset the color cell 'pixel' (in the X colormap) to given rgb's
 39  * (0-255) */
 40 void    tv_screen_alloc_color(Tv_screen * tv_screen, long unsigned int *pixel, int red, int green, int blue)
 41 {
 42     unsigned char r = red;
 43     unsigned char g = green;
 44     unsigned char b = blue;
 45     XColor  color;
 46 
 47     if (tv_screen)
 48     {
 49         color.pixel = *pixel;
 50         color.red = r << 8;
 51         color.green = g << 8;
 52         color.blue = b << 8;
 53         color.flags = DoRed | DoGreen | DoBlue;
 54         XAllocColor(tv_screen->display, tv_screen->colormap, &color);
 55         *pixel = color.pixel;
 56     }
 57 }
 58 
 59 void    tv_screen_reset_color(Tv_screen * tv_screen, long unsigned int pixel, int red, int green, int blue)
 60 {
 61     unsigned char r = red;
 62     unsigned char g = green;
 63     unsigned char b = blue;
 64     XColor  color;
 65 
 66     if (tv_screen)
 67     {
 68         color.pixel = pixel;
 69         color.red = r << 8;
 70         color.green = g << 8;
 71         color.blue = b << 8;
 72         color.flags = DoRed | DoGreen | DoBlue;
 73         XStoreColor(tv_screen->display, tv_screen->colormap, &color);
 74     }
 75 }
 76 
 77 
 78 
 79 /* Reset the color cell 'pixel' (in the X colormap) to rgb's of the
 80  * given color_name.  NB if color_name not found does nowt */
 81 void    tv_screen_reset_named_color(Tv_screen * tv_screen, long unsigned int pixel, char *color_name)
 82 {
 83     if (tv_screen)
 84     {
 85         XColor  color, exact;
 86 
 87         if (XLookupColor(tv_screen->display, tv_screen->colormap, color_name,
 88                          &color, &exact))
 89         {
 90 
 91             color.pixel = pixel;/* Do flags set by XLookupColor */
 92             XStoreColor(tv_screen->display, tv_screen->colormap, &color);
 93         } else
 94         {
 95             format("tv_screen_reset_named_color: %s not found\n", color_name);
 96         }
 97 
 98     }
 99 }
100 
101 
102 
103 /* X Window specific pixel returned (NOT Tina_pixel) */
104 unsigned long tv_screen_get_pixel(Tv_screen * tv_screen, Ipos pos)
105 {
106     unsigned long pixel = 0;
107     XImage *ximage;
108 
109     if (tv_screen)
110     {
111 
112         /** must be a better way! **/
113         ximage = XGetImage(tv_screen->display, tv_screen->window,
114                            pos.x, pos.y, 1, 1, AllPlanes, ZPixmap);
115         /* HP warns: 'Argument #1 is not the correct type' */
116         /* But ximage IS correct for XGetPixel & XDestroyImage */
117         pixel = XGetPixel(ximage, 0, 0);
118         XDestroyImage(ximage);
119     }
120     return (pixel);
121 }
122 

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