]>
Dogcows Code - chaz/openbox/blob - color.c
b485685379c390c427b3900dcadaaf6af2ffaa85
7 void RrColorAllocateGC(RrColor
*in
)
11 gcv
.foreground
= in
->pixel
;
12 gcv
.cap_style
= CapProjecting
;
13 in
->gc
= XCreateGC(RrDisplay(in
->inst
),
14 RrRootWindow(in
->inst
),
15 GCForeground
| GCCapStyle
, &gcv
);
18 RrColor
*RrColorParse(const RrInstance
*inst
, gchar
*colorname
)
22 g_assert(colorname
!= NULL
);
23 /* get rgb values from colorname */
29 if (!XParseColor(RrDisplay(inst
), RrColormap(inst
), colorname
, &xcol
)) {
30 g_warning("unable to parse color '%s'", colorname
);
33 return RrColorNew(inst
, xcol
.red
>> 8, xcol
.green
>> 8, xcol
.blue
>> 8);
36 RrColor
*RrColorNew(const RrInstance
*inst
, gint r
, gint g
, gint b
)
38 /* this should be replaced with something far cooler */
41 xcol
.red
= (r
<< 8) | r
;
42 xcol
.green
= (g
<< 8) | g
;
43 xcol
.blue
= (b
<< 8) | b
;
44 if (XAllocColor(RrDisplay(inst
), RrColormap(inst
), &xcol
)) {
45 out
= g_new(RrColor
, 1);
47 out
->r
= xcol
.red
>> 8;
48 out
->g
= xcol
.green
>> 8;
49 out
->b
= xcol
.blue
>> 8;
51 out
->pixel
= xcol
.pixel
;
56 /*XXX same color could be pointed to twice, this might have to be a refcount*/
58 void RrColorFree(RrColor
*c
)
61 if (c
->gc
) XFreeGC(RrDisplay(c
->inst
), c
->gc
);
66 void RrReduceDepth(const RrInstance
*inst
, RrPixel32
*data
, XImage
*im
)
70 RrPixel32
*p32
= (RrPixel32
*) im
->data
;
71 RrPixel16
*p16
= (RrPixel16
*) im
->data
;
72 unsigned char *p8
= (unsigned char *)im
->data
;
73 switch (im
->bits_per_pixel
) {
75 if ((RrRedOffset(inst
) != RrDefaultRedOffset
) ||
76 (RrBlueOffset(inst
) != RrDefaultBlueOffset
) ||
77 (RrGreenOffset(inst
) != RrDefaultGreenOffset
)) {
78 for (y
= 0; y
< im
->height
; y
++) {
79 for (x
= 0; x
< im
->width
; x
++) {
80 r
= (data
[x
] >> RrDefaultRedOffset
) & 0xFF;
81 g
= (data
[x
] >> RrDefaultGreenOffset
) & 0xFF;
82 b
= (data
[x
] >> RrDefaultBlueOffset
) & 0xFF;
83 p32
[x
] = (r
<< RrRedShift(inst
))
84 + (g
<< RrGreenShift(inst
))
85 + (b
<< RrBlueShift(inst
));
90 } else im
->data
= (char*) data
;
93 for (y
= 0; y
< im
->height
; y
++) {
94 for (x
= 0; x
< im
->width
; x
++) {
95 r
= (data
[x
] >> RrDefaultRedOffset
) & 0xFF;
96 r
= r
>> RrRedShift(inst
);
97 g
= (data
[x
] >> RrDefaultGreenOffset
) & 0xFF;
98 g
= g
>> RrGreenShift(inst
);
99 b
= (data
[x
] >> RrDefaultBlueOffset
) & 0xFF;
100 b
= b
>> RrBlueShift(inst
);
101 p16
[x
] = (r
<< RrRedOffset(inst
))
102 + (g
<< RrGreenOffset(inst
))
103 + (b
<< RrBlueOffset(inst
));
106 p16
+= im
->bytes_per_line
/2;
110 g_assert(RrVisual(inst
)->class != TrueColor
);
111 for (y
= 0; y
< im
->height
; y
++) {
112 for (x
= 0; x
< im
->width
; x
++) {
113 p8
[x
] = RrPickColor(inst
,
114 data
[x
] >> RrDefaultRedOffset
,
115 data
[x
] >> RrDefaultGreenOffset
,
116 data
[x
] >> RrDefaultBlueOffset
)->pixel
;
119 p8
+= im
->bytes_per_line
;
124 g_message("your bit depth is currently unhandled\n");
128 XColor
*RrPickColor(const RrInstance
*inst
, gint r
, gint g
, gint b
)
130 r
= (r
& 0xff) >> (8-RrPseudoBPC(inst
));
131 g
= (g
& 0xff) >> (8-RrPseudoBPC(inst
));
132 b
= (b
& 0xff) >> (8-RrPseudoBPC(inst
));
133 return &RrPseudoColors(inst
)[(r
<< (2*RrPseudoBPC(inst
))) +
134 (g
<< (1*RrPseudoBPC(inst
))) +
138 static void swap_byte_order(XImage
*im
)
142 g_message("SWAPPING BYTE ORDER");
145 for (y
= 0; y
< im
->height
; ++y
) {
146 for (x
= 0; x
< im
->height
; ++x
) {
147 char *c
= &im
->data
[di
+ x
* im
->bits_per_pixel
/ 8];
150 switch (im
->bits_per_pixel
) {
162 g_message("your bit depth is currently unhandled\n");
165 di
+= im
->bytes_per_line
;
168 if (im
->byte_order
== LSBFirst
)
169 im
->byte_order
= MSBFirst
;
171 im
->byte_order
= LSBFirst
;
174 void RrIncreaseDepth(const RrInstance
*inst
, RrPixel32
*data
, XImage
*im
)
178 RrPixel32
*p32
= (RrPixel32
*) im
->data
;
179 RrPixel16
*p16
= (RrPixel16
*) im
->data
;
180 unsigned char *p8
= (unsigned char *)im
->data
;
182 if (im
->byte_order
!= RrEndian
)
185 switch (im
->bits_per_pixel
) {
187 for (y
= 0; y
< im
->height
; y
++) {
188 for (x
= 0; x
< im
->width
; x
++) {
189 r
= (p32
[x
] >> RrRedOffset(inst
)) & 0xff;
190 g
= (p32
[x
] >> RrGreenOffset(inst
)) & 0xff;
191 b
= (p32
[x
] >> RrBlueOffset(inst
)) & 0xff;
192 data
[x
] = (r
<< RrDefaultRedOffset
)
193 + (g
<< RrDefaultGreenOffset
)
194 + (b
<< RrDefaultBlueOffset
)
195 + (0xff << RrDefaultAlphaOffset
);
198 p32
+= im
->bytes_per_line
/4;
202 for (y
= 0; y
< im
->height
; y
++) {
203 for (x
= 0; x
< im
->width
; x
++) {
204 r
= (p16
[x
] & RrRedMask(inst
)) >>
207 g
= (p16
[x
] & RrGreenMask(inst
)) >>
208 RrGreenOffset(inst
) <<
210 b
= (p16
[x
] & RrBlueMask(inst
)) >>
211 RrBlueOffset(inst
) <<
213 data
[x
] = (r
<< RrDefaultRedOffset
)
214 + (g
<< RrDefaultGreenOffset
)
215 + (b
<< RrDefaultBlueOffset
)
216 + (0xff << RrDefaultAlphaOffset
);
219 p16
+= im
->bytes_per_line
/2;
223 g_message("this image bit depth is currently unhandled\n");
226 for (y
= 0; y
< im
->height
; y
++) {
227 for (x
= 0; x
< im
->width
; x
++) {
228 if (!(((p8
[x
/ 8]) >> (x
% 8)) & 0x1))
229 data
[x
] = 0xff << RrDefaultAlphaOffset
; /* black */
231 data
[x
] = 0xffffffff; /* white */
234 p8
+= im
->bytes_per_line
;
238 g_message("this image bit depth is currently unhandled\n");
This page took 0.042162 seconds and 3 git commands to generate.