]>
Dogcows Code - chaz/openbox/blob - color.c
10ad5e3b95cec7657ccd229fa4822dcb2f29448e
5 #include "../kernel/openbox.h"
6 void color_allocate_gc(color_rgb
*in
)
10 gcv
.foreground
= in
->pixel
;
11 gcv
.cap_style
= CapProjecting
;
12 in
->gc
= XCreateGC(ob_display
, ob_root
, GCForeground
| GCCapStyle
, &gcv
);
15 color_rgb
*color_parse(char *colorname
)
19 g_assert(colorname
!= NULL
);
20 // get rgb values from colorname
26 if (!XParseColor(ob_display
, render_colormap
, colorname
, &xcol
)) {
27 g_warning("unable to parse color '%s'", colorname
);
30 return color_new(xcol
.red
>> 8, xcol
.green
>> 8, xcol
.blue
>> 8);
33 color_rgb
*color_new(int r
, int g
, int b
)
35 /* this should be replaced with something far cooler */
38 xcol
.red
= (r
<< 8) | r
;
39 xcol
.green
= (g
<< 8) | g
;
40 xcol
.blue
= (b
<< 8) | b
;
41 if (XAllocColor(ob_display
, render_colormap
, &xcol
)) {
42 out
= g_new(color_rgb
, 1);
43 out
->r
= xcol
.red
>> 8;
44 out
->g
= xcol
.green
>> 8;
45 out
->b
= xcol
.blue
>> 8;
47 out
->pixel
= xcol
.pixel
;
53 //XXX same color could be pointed to twice, this might have to be a refcount
55 void color_free(color_rgb
*c
)
58 XFreeGC(ob_display
, c
->gc
);
62 void reduce_depth(pixel32
*data
, XImage
*im
)
64 // since pixel32 is the largest possible pixel size, we can share the array
67 pixel16
*p
= (pixel16
*) data
;
68 switch (im
->bits_per_pixel
) {
70 if ((render_red_offset
!= default_red_shift
) ||
71 (render_blue_offset
!= default_blue_shift
) ||
72 (render_green_offset
!= default_green_shift
)) {
73 for (y
= 0; y
< im
->height
; y
++) {
74 for (x
= 0; x
< im
->width
; x
++) {
75 r
= (data
[x
] >> default_red_shift
) & 0xFF;
76 g
= (data
[x
] >> default_green_shift
) & 0xFF;
77 b
= (data
[x
] >> default_blue_shift
) & 0xFF;
78 data
[x
] = (r
<< render_red_offset
) + (g
<< render_green_offset
) +
79 (b
<< render_blue_offset
);
86 for (y
= 0; y
< im
->height
; y
++) {
87 for (x
= 0; x
< im
->width
; x
++) {
88 r
= (data
[x
] >> default_red_shift
) & 0xFF;
89 r
= r
>> render_red_shift
;
90 g
= (data
[x
] >> default_green_shift
) & 0xFF;
91 g
= g
>> render_green_shift
;
92 b
= (data
[x
] >> default_blue_shift
) & 0xFF;
93 b
= b
>> render_blue_shift
;
94 p
[x
] = (r
<< render_red_offset
)
95 + (g
<< render_green_offset
)
96 + (b
<< render_blue_offset
);
99 p
+= im
->bytes_per_line
/2;
103 g_message("your bit depth is currently unhandled\n");
This page took 0.042317 seconds and 3 git commands to generate.