]>
Dogcows Code - chaz/openbox/blob - render/color.c
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 g_message("CONVERSION %d->%d %d->%d %d->%d",
79 RrDefaultRedOffset
, RrRedOffset(inst
),
80 RrDefaultBlueOffset
, RrGreenOffset(inst
),
81 RrDefaultGreenOffset
, RrBlueOffset(inst
));
82 for (y
= 0; y
< im
->height
; y
++) {
83 for (x
= 0; x
< im
->width
; x
++) {
84 r
= (data
[x
] >> RrDefaultRedOffset
) & 0xFF;
85 g
= (data
[x
] >> RrDefaultGreenOffset
) & 0xFF;
86 b
= (data
[x
] >> RrDefaultBlueOffset
) & 0xFF;
87 p32
[x
] = (r
<< RrRedOffset(inst
))
88 + (g
<< RrGreenOffset(inst
))
89 + (b
<< RrBlueOffset(inst
));
94 } else im
->data
= (char*) data
;
97 for (y
= 0; y
< im
->height
; y
++) {
98 for (x
= 0; x
< im
->width
; x
++) {
99 r
= (data
[x
] >> RrDefaultRedOffset
) & 0xFF;
100 r
= r
>> RrRedShift(inst
);
101 g
= (data
[x
] >> RrDefaultGreenOffset
) & 0xFF;
102 g
= g
>> RrGreenShift(inst
);
103 b
= (data
[x
] >> RrDefaultBlueOffset
) & 0xFF;
104 b
= b
>> RrBlueShift(inst
);
105 p16
[x
] = (r
<< RrRedOffset(inst
))
106 + (g
<< RrGreenOffset(inst
))
107 + (b
<< RrBlueOffset(inst
));
110 p16
+= im
->bytes_per_line
/2;
114 g_assert(RrVisual(inst
)->class != TrueColor
);
115 for (y
= 0; y
< im
->height
; y
++) {
116 for (x
= 0; x
< im
->width
; x
++) {
117 p8
[x
] = RrPickColor(inst
,
118 data
[x
] >> RrDefaultRedOffset
,
119 data
[x
] >> RrDefaultGreenOffset
,
120 data
[x
] >> RrDefaultBlueOffset
)->pixel
;
123 p8
+= im
->bytes_per_line
;
128 g_message("your bit depth is currently unhandled\n");
132 XColor
*RrPickColor(const RrInstance
*inst
, gint r
, gint g
, gint b
)
134 r
= (r
& 0xff) >> (8-RrPseudoBPC(inst
));
135 g
= (g
& 0xff) >> (8-RrPseudoBPC(inst
));
136 b
= (b
& 0xff) >> (8-RrPseudoBPC(inst
));
137 return &RrPseudoColors(inst
)[(r
<< (2*RrPseudoBPC(inst
))) +
138 (g
<< (1*RrPseudoBPC(inst
))) +
142 static void swap_byte_order(XImage
*im
)
146 g_message("SWAPPING BYTE ORDER");
149 for (y
= 0; y
< im
->height
; ++y
) {
150 for (x
= 0; x
< im
->height
; ++x
) {
151 char *c
= &im
->data
[di
+ x
* im
->bits_per_pixel
/ 8];
154 switch (im
->bits_per_pixel
) {
166 g_message("your bit depth is currently unhandled\n");
169 di
+= im
->bytes_per_line
;
172 if (im
->byte_order
== LSBFirst
)
173 im
->byte_order
= MSBFirst
;
175 im
->byte_order
= LSBFirst
;
178 void RrIncreaseDepth(const RrInstance
*inst
, RrPixel32
*data
, XImage
*im
)
182 RrPixel32
*p32
= (RrPixel32
*) im
->data
;
183 RrPixel16
*p16
= (RrPixel16
*) im
->data
;
184 unsigned char *p8
= (unsigned char *)im
->data
;
186 if (im
->byte_order
!= RrEndian
)
189 switch (im
->bits_per_pixel
) {
191 for (y
= 0; y
< im
->height
; y
++) {
192 for (x
= 0; x
< im
->width
; x
++) {
193 r
= (p32
[x
] >> RrRedOffset(inst
)) & 0xff;
194 g
= (p32
[x
] >> RrGreenOffset(inst
)) & 0xff;
195 b
= (p32
[x
] >> RrBlueOffset(inst
)) & 0xff;
196 data
[x
] = (r
<< RrDefaultRedOffset
)
197 + (g
<< RrDefaultGreenOffset
)
198 + (b
<< RrDefaultBlueOffset
)
199 + (0xff << RrDefaultAlphaOffset
);
202 p32
+= im
->bytes_per_line
/4;
206 for (y
= 0; y
< im
->height
; y
++) {
207 for (x
= 0; x
< im
->width
; x
++) {
208 r
= (p16
[x
] & RrRedMask(inst
)) >>
211 g
= (p16
[x
] & RrGreenMask(inst
)) >>
212 RrGreenOffset(inst
) <<
214 b
= (p16
[x
] & RrBlueMask(inst
)) >>
215 RrBlueOffset(inst
) <<
217 data
[x
] = (r
<< RrDefaultRedOffset
)
218 + (g
<< RrDefaultGreenOffset
)
219 + (b
<< RrDefaultBlueOffset
)
220 + (0xff << RrDefaultAlphaOffset
);
223 p16
+= im
->bytes_per_line
/2;
227 g_message("this image bit depth is currently unhandled\n");
230 for (y
= 0; y
< im
->height
; y
++) {
231 for (x
= 0; x
< im
->width
; x
++) {
232 if (!(((p8
[x
/ 8]) >> (x
% 8)) & 0x1))
233 data
[x
] = 0xff << RrDefaultAlphaOffset
; /* black */
235 data
[x
] = 0xffffffff; /* white */
238 p8
+= im
->bytes_per_line
;
242 g_message("this image bit depth is currently unhandled\n");
This page took 0.048946 seconds and 5 git commands to generate.