10 void RrColorAllocateGC(RrColor *in)
14 gcv.foreground = in->pixel;
15 gcv.cap_style = CapProjecting;
16 in->gc = XCreateGC(RrDisplay(in->inst),
17 RrRootWindow(in->inst),
18 GCForeground | GCCapStyle, &gcv);
21 RrColor *RrColorParse(const RrInstance *inst, gchar *colorname)
25 g_assert(colorname != NULL);
26 /* get rgb values from colorname */
32 if (!XParseColor(RrDisplay(inst), RrColormap(inst), colorname, &xcol)) {
33 g_warning("unable to parse color '%s'", colorname);
36 return RrColorNew(inst, xcol.red >> 8, xcol.green >> 8, xcol.blue >> 8);
39 RrColor *RrColorNew(const RrInstance *inst, gint r, gint g, gint b)
41 /* this should be replaced with something far cooler */
44 xcol.red = (r << 8) | r;
45 xcol.green = (g << 8) | g;
46 xcol.blue = (b << 8) | b;
47 if (XAllocColor(RrDisplay(inst), RrColormap(inst), &xcol)) {
48 out = g_new(RrColor, 1);
50 out->r = xcol.red >> 8;
51 out->g = xcol.green >> 8;
52 out->b = xcol.blue >> 8;
54 out->pixel = xcol.pixel;
59 /*XXX same color could be pointed to twice, this might have to be a refcount*/
61 void RrColorFree(RrColor *c)
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 << RrRedShift(inst))
87 + (g << RrGreenShift(inst))
88 + (b << RrBlueShift(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_message("your bit depth is currently unhandled\n");
131 XColor *RrPickColor(const RrInstance *inst, gint r, gint g, gint b)
133 r = (r & 0xff) >> (8-pseudo_bpc);
134 g = (g & 0xff) >> (8-pseudo_bpc);
135 b = (b & 0xff) >> (8-pseudo_bpc);
136 return &RrPseudoColors(inst)[(r << (2*pseudo_bpc)) +
137 (g << (1*pseudo_bpc)) +
141 static void swap_byte_order(XImage *im)
145 g_message("SWAPPING BYTE ORDER");
148 for (y = 0; y < im->height; ++y) {
149 for (x = 0; x < im->height; ++x) {
150 char *c = &im->data[di + x * im->bits_per_pixel / 8];
153 switch (im->bits_per_pixel) {
165 g_message("your bit depth is currently unhandled\n");
168 di += im->bytes_per_line;
171 if (im->byte_order == LSBFirst)
172 im->byte_order = MSBFirst;
174 im->byte_order = LSBFirst;
177 void RrIncreaseDepth(const RrInstance *inst, RrPixel32 *data, XImage *im)
181 RrPixel32 *p32 = (RrPixel32 *) im->data;
182 RrPixel16 *p16 = (RrPixel16 *) im->data;
183 unsigned char *p8 = (unsigned char *)im->data;
185 if (im->byte_order != RrEndian)
188 switch (im->bits_per_pixel) {
190 for (y = 0; y < im->height; y++) {
191 for (x = 0; x < im->width; x++) {
192 r = (p32[x] >> RrRedOffset(inst)) & 0xff;
193 g = (p32[x] >> RrGreenOffset(inst)) & 0xff;
194 b = (p32[x] >> RrBlueOffset(inst)) & 0xff;
195 data[x] = (r << RrDefaultRedOffset)
196 + (g << RrDefaultGreenOffset)
197 + (b << RrDefaultBlueOffset)
198 + (0xff << RrDefaultAlphaOffset);
201 p32 += im->bytes_per_line/4;
205 for (y = 0; y < im->height; y++) {
206 for (x = 0; x < im->width; x++) {
207 r = (p16[x] & RrRedMask(inst)) >>
210 g = (p16[x] & RrGreenMask(inst)) >>
211 RrGreenOffset(inst) <<
213 b = (p16[x] & RrBlueMask(inst)) >>
214 RrBlueOffset(inst) <<
216 data[x] = (r << RrDefaultRedOffset)
217 + (g << RrDefaultGreenOffset)
218 + (b << RrDefaultBlueOffset)
219 + (0xff << RrDefaultAlphaOffset);
222 p16 += im->bytes_per_line/2;
226 g_message("this image bit depth is currently unhandled\n");
229 for (y = 0; y < im->height; y++) {
230 for (x = 0; x < im->width; x++) {
231 if (!(((p8[x / 8]) >> (x % 8)) & 0x1))
232 data[x] = 0xff << RrDefaultAlphaOffset; /* black */
234 data[x] = 0xffffffff; /* white */
237 p8 += im->bytes_per_line;
241 g_message("this image bit depth is currently unhandled\n");