8 void RrColorAllocateGC(RrColor *in)
12 gcv.foreground = in->pixel;
13 gcv.cap_style = CapProjecting;
14 in->gc = XCreateGC(RrDisplay(in->inst),
15 RrRootWindow(in->inst),
16 GCForeground | GCCapStyle, &gcv);
19 RrColor *RrColorParse(const RrInstance *inst, gchar *colorname)
23 g_assert(colorname != NULL);
24 /* get rgb values from colorname */
30 if (!XParseColor(RrDisplay(inst), RrColormap(inst), colorname, &xcol)) {
31 g_warning("unable to parse color '%s'", colorname);
34 return RrColorNew(inst, xcol.red >> 8, xcol.green >> 8, xcol.blue >> 8);
37 RrColor *RrColorNew(const RrInstance *inst, gint r, gint g, gint b)
39 /* this should be replaced with something far cooler */
42 xcol.red = (r << 8) | r;
43 xcol.green = (g << 8) | g;
44 xcol.blue = (b << 8) | b;
45 if (XAllocColor(RrDisplay(inst), RrColormap(inst), &xcol)) {
46 out = g_new(RrColor, 1);
48 out->r = xcol.red >> 8;
49 out->g = xcol.green >> 8;
50 out->b = xcol.blue >> 8;
52 out->pixel = xcol.pixel;
57 /*XXX same color could be pointed to twice, this might have to be a refcount*/
59 void RrColorFree(RrColor *c)
62 if (c->pixel) XFreeColors(RrDisplay(c->inst), RrColormap(c->inst),
64 if (c->gc) XFreeGC(RrDisplay(c->inst), c->gc);
69 void RrReduceDepth(const RrInstance *inst, RrPixel32 *data, XImage *im)
73 RrPixel32 *p32 = (RrPixel32 *) im->data;
74 RrPixel16 *p16 = (RrPixel16 *) im->data;
75 unsigned char *p8 = (unsigned char *)im->data;
76 switch (im->bits_per_pixel) {
78 if ((RrRedOffset(inst) != RrDefaultRedOffset) ||
79 (RrBlueOffset(inst) != RrDefaultBlueOffset) ||
80 (RrGreenOffset(inst) != RrDefaultGreenOffset)) {
81 for (y = 0; y < im->height; y++) {
82 for (x = 0; x < im->width; x++) {
83 r = (data[x] >> RrDefaultRedOffset) & 0xFF;
84 g = (data[x] >> RrDefaultGreenOffset) & 0xFF;
85 b = (data[x] >> RrDefaultBlueOffset) & 0xFF;
86 p32[x] = (r << RrRedOffset(inst))
87 + (g << RrGreenOffset(inst))
88 + (b << RrBlueOffset(inst));
93 } else im->data = (char*) data;
96 for (y = 0; y < im->height; y++) {
97 for (x = 0; x < im->width; x++) {
98 r = (data[x] >> RrDefaultRedOffset) & 0xFF;
99 r = r >> RrRedShift(inst);
100 g = (data[x] >> RrDefaultGreenOffset) & 0xFF;
101 g = g >> RrGreenShift(inst);
102 b = (data[x] >> RrDefaultBlueOffset) & 0xFF;
103 b = b >> RrBlueShift(inst);
104 p16[x] = (r << RrRedOffset(inst))
105 + (g << RrGreenOffset(inst))
106 + (b << RrBlueOffset(inst));
109 p16 += im->bytes_per_line/2;
113 g_assert(RrVisual(inst)->class != TrueColor);
114 for (y = 0; y < im->height; y++) {
115 for (x = 0; x < im->width; x++) {
116 p8[x] = RrPickColor(inst,
117 data[x] >> RrDefaultRedOffset,
118 data[x] >> RrDefaultGreenOffset,
119 data[x] >> RrDefaultBlueOffset)->pixel;
122 p8 += im->bytes_per_line;
127 g_warning("your bit depth is currently unhandled\n");
131 XColor *RrPickColor(const RrInstance *inst, gint r, gint g, gint b)
133 r = (r & 0xff) >> (8-RrPseudoBPC(inst));
134 g = (g & 0xff) >> (8-RrPseudoBPC(inst));
135 b = (b & 0xff) >> (8-RrPseudoBPC(inst));
136 return &RrPseudoColors(inst)[(r << (2*RrPseudoBPC(inst))) +
137 (g << (1*RrPseudoBPC(inst))) +
141 static void swap_byte_order(XImage *im)
146 for (y = 0; y < im->height; ++y) {
147 for (x = 0; x < im->height; ++x) {
148 char *c = &im->data[di + x * im->bits_per_pixel / 8];
151 switch (im->bits_per_pixel) {
163 g_warning("your bit depth is currently unhandled");
166 di += im->bytes_per_line;
169 if (im->byte_order == LSBFirst)
170 im->byte_order = MSBFirst;
172 im->byte_order = LSBFirst;
175 void RrIncreaseDepth(const RrInstance *inst, RrPixel32 *data, XImage *im)
179 RrPixel32 *p32 = (RrPixel32 *) im->data;
180 RrPixel16 *p16 = (RrPixel16 *) im->data;
181 unsigned char *p8 = (unsigned char *)im->data;
183 if (im->byte_order != LSBFirst)
186 switch (im->bits_per_pixel) {
188 for (y = 0; y < im->height; y++) {
189 for (x = 0; x < im->width; x++) {
190 r = (p32[x] >> RrRedOffset(inst)) & 0xff;
191 g = (p32[x] >> RrGreenOffset(inst)) & 0xff;
192 b = (p32[x] >> RrBlueOffset(inst)) & 0xff;
193 data[x] = (r << RrDefaultRedOffset)
194 + (g << RrDefaultGreenOffset)
195 + (b << RrDefaultBlueOffset)
196 + (0xff << RrDefaultAlphaOffset);
199 p32 += im->bytes_per_line/4;
203 for (y = 0; y < im->height; y++) {
204 for (x = 0; x < im->width; x++) {
205 r = (p16[x] & RrRedMask(inst)) >>
208 g = (p16[x] & RrGreenMask(inst)) >>
209 RrGreenOffset(inst) <<
211 b = (p16[x] & RrBlueMask(inst)) >>
212 RrBlueOffset(inst) <<
214 data[x] = (r << RrDefaultRedOffset)
215 + (g << RrDefaultGreenOffset)
216 + (b << RrDefaultBlueOffset)
217 + (0xff << RrDefaultAlphaOffset);
220 p16 += im->bytes_per_line/2;
224 g_warning("this image bit depth is currently unhandled");
227 for (y = 0; y < im->height; y++) {
228 for (x = 0; x < im->width; x++) {
229 if (!(((p8[x / 8]) >> (x % 8)) & 0x1))
230 data[x] = 0xff << RrDefaultAlphaOffset; /* black */
232 data[x] = 0xffffffff; /* white */
235 p8 += im->bytes_per_line;
239 g_warning("this image bit depth is currently unhandled");
243 int RrColorRed(const RrColor *c)
248 int RrColorGreen(const RrColor *c)
253 int RrColorBlue(const RrColor *c)
258 gulong RrColorPixel(const RrColor *c)
263 GC RrColorGC(RrColor *c) /* XXX make this const RrColor* when the GCs are in
264 a cache.. if possible? */
267 RrColorAllocateGC(c);