]>
Dogcows Code - chaz/openbox/blob - color.c
c25707205256a69e027dd8175e81a4a1c6d99248
5 #include "../kernel/openbox.h"
10 void color_allocate_gc(color_rgb
*in
)
14 gcv
.foreground
= in
->pixel
;
15 gcv
.cap_style
= CapProjecting
;
16 in
->gc
= XCreateGC(ob_display
, ob_root
, GCForeground
| GCCapStyle
, &gcv
);
19 color_rgb
*color_parse(char *colorname
)
23 g_assert(colorname
!= NULL
);
24 /* get rgb values from colorname */
30 if (!XParseColor(ob_display
, render_colormap
, colorname
, &xcol
)) {
31 g_warning("unable to parse color '%s'", colorname
);
34 return color_new(xcol
.red
>> 8, xcol
.green
>> 8, xcol
.blue
>> 8);
37 color_rgb
*color_new(int r
, int g
, int 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(ob_display
, render_colormap
, &xcol
)) {
46 out
= g_new(color_rgb
, 1);
47 out
->r
= xcol
.red
>> 8;
48 out
->g
= xcol
.green
>> 8;
49 out
->b
= xcol
.blue
>> 8;
51 out
->pixel
= xcol
.pixel
;
57 /*XXX same color could be pointed to twice, this might have to be a refcount*/
59 void color_free(color_rgb
*c
)
62 XFreeGC(ob_display
, c
->gc
);
66 void reduce_depth(pixel32
*data
, XImage
*im
)
70 pixel32
*p32
= (pixel32
*) im
->data
;
71 pixel16
*p16
= (pixel16
*) im
->data
;
72 unsigned char *p8
= (unsigned char *)im
->data
;
73 switch (im
->bits_per_pixel
) {
75 if ((render_red_offset
!= default_red_shift
) ||
76 (render_blue_offset
!= default_blue_shift
) ||
77 (render_green_offset
!= default_green_shift
)) {
78 for (y
= 0; y
< im
->height
; y
++) {
79 for (x
= 0; x
< im
->width
; x
++) {
80 r
= (data
[x
] >> default_red_shift
) & 0xFF;
81 g
= (data
[x
] >> default_green_shift
) & 0xFF;
82 b
= (data
[x
] >> default_blue_shift
) & 0xFF;
83 p32
[x
] = (r
<< render_red_offset
)
84 + (g
<< render_green_offset
)
85 + (b
<< render_blue_offset
);
90 } else im
->data
= data
;
93 for (y
= 0; y
< im
->height
; y
++) {
94 for (x
= 0; x
< im
->width
; x
++) {
95 r
= (data
[x
] >> default_red_shift
) & 0xFF;
96 r
= r
>> render_red_shift
;
97 g
= (data
[x
] >> default_green_shift
) & 0xFF;
98 g
= g
>> render_green_shift
;
99 b
= (data
[x
] >> default_blue_shift
) & 0xFF;
100 b
= b
>> render_blue_shift
;
101 p16
[x
] = (r
<< render_red_offset
)
102 + (g
<< render_green_offset
)
103 + (b
<< render_blue_offset
);
106 p16
+= im
->bytes_per_line
/2;
110 g_assert(render_visual
->class != TrueColor
);
111 for (y
= 0; y
< im
->height
; y
++) {
112 for (x
= 0; x
< im
->width
; x
++) {
113 p8
[x
] = pickColor(data
[x
] >> default_red_shift
,
114 data
[x
] >> default_green_shift
,
115 data
[x
] >> default_blue_shift
)->pixel
;
118 p8
+= im
->bytes_per_line
;
123 g_message("your bit depth is currently unhandled\n");
126 XColor
*pickColor(int r
, int g
, int b
)
128 r
= (r
& 0xff) >> (8-pseudo_bpc
);
129 g
= (g
& 0xff) >> (8-pseudo_bpc
);
130 b
= (b
& 0xff) >> (8-pseudo_bpc
);
131 return &pseudo_colors
[(r
<< (2*pseudo_bpc
)) + (g
<< (1*pseudo_bpc
)) + b
];
This page took 0.037978 seconds and 3 git commands to generate.