]>
Dogcows Code - chaz/openbox/blob - color.c
d16bbf0cdd93b8e06cc2eee2664f2f6ea2fe5edf
8 void RrColorAllocateGC(RrColor
*in
)
12 gcv
.foreground
= in
->pixel
;
13 gcv
.cap_style
= CapProjecting
;
14 in
->gc
= XCreateGC(RrDisplay(in
->inst
),
15 RrRootWindow(in
->inst
),
16 GCForeground
| GCCapStyle
, &gcv
);
19 RrColor
*RrColorParse(const RrInstance
*inst
, gchar
*colorname
)
23 g_assert(colorname
!= NULL
);
24 /* get rgb values from colorname */
30 if (!XParseColor(RrDisplay(inst
), RrColormap(inst
), colorname
, &xcol
)) {
31 g_warning("unable to parse color '%s'", colorname
);
34 return RrColorNew(inst
, xcol
.red
>> 8, xcol
.green
>> 8, xcol
.blue
>> 8);
37 RrColor
*RrColorNew(const RrInstance
*inst
, gint r
, gint g
, gint 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(RrDisplay(inst
), RrColormap(inst
), &xcol
)) {
46 out
= g_new(RrColor
, 1);
48 out
->r
= xcol
.red
>> 8;
49 out
->g
= xcol
.green
>> 8;
50 out
->b
= xcol
.blue
>> 8;
52 out
->pixel
= xcol
.pixel
;
57 /*XXX same color could be pointed to twice, this might have to be a refcount*/
59 void RrColorFree(RrColor
*c
)
62 if (c
->gc
) XFreeGC(RrDisplay(c
->inst
), c
->gc
);
67 void RrReduceDepth(const RrInstance
*inst
, RrPixel32
*data
, XImage
*im
)
71 RrPixel32
*p32
= (RrPixel32
*) im
->data
;
72 RrPixel16
*p16
= (RrPixel16
*) im
->data
;
73 unsigned char *p8
= (unsigned char *)im
->data
;
74 switch (im
->bits_per_pixel
) {
76 if ((RrRedOffset(inst
) != RrDefaultRedOffset
) ||
77 (RrBlueOffset(inst
) != RrDefaultBlueOffset
) ||
78 (RrGreenOffset(inst
) != RrDefaultGreenOffset
)) {
79 for (y
= 0; y
< im
->height
; y
++) {
80 for (x
= 0; x
< im
->width
; x
++) {
81 r
= (data
[x
] >> RrDefaultRedOffset
) & 0xFF;
82 g
= (data
[x
] >> RrDefaultGreenOffset
) & 0xFF;
83 b
= (data
[x
] >> RrDefaultBlueOffset
) & 0xFF;
84 p32
[x
] = (r
<< RrRedOffset(inst
))
85 + (g
<< RrGreenOffset(inst
))
86 + (b
<< RrBlueOffset(inst
));
91 } else im
->data
= (char*) data
;
94 for (y
= 0; y
< im
->height
; y
++) {
95 for (x
= 0; x
< im
->width
; x
++) {
96 r
= (data
[x
] >> RrDefaultRedOffset
) & 0xFF;
97 r
= r
>> RrRedShift(inst
);
98 g
= (data
[x
] >> RrDefaultGreenOffset
) & 0xFF;
99 g
= g
>> RrGreenShift(inst
);
100 b
= (data
[x
] >> RrDefaultBlueOffset
) & 0xFF;
101 b
= b
>> RrBlueShift(inst
);
102 p16
[x
] = (r
<< RrRedOffset(inst
))
103 + (g
<< RrGreenOffset(inst
))
104 + (b
<< RrBlueOffset(inst
));
107 p16
+= im
->bytes_per_line
/2;
111 g_assert(RrVisual(inst
)->class != TrueColor
);
112 for (y
= 0; y
< im
->height
; y
++) {
113 for (x
= 0; x
< im
->width
; x
++) {
114 p8
[x
] = RrPickColor(inst
,
115 data
[x
] >> RrDefaultRedOffset
,
116 data
[x
] >> RrDefaultGreenOffset
,
117 data
[x
] >> RrDefaultBlueOffset
)->pixel
;
120 p8
+= im
->bytes_per_line
;
125 g_warning("your bit depth is currently unhandled\n");
129 XColor
*RrPickColor(const RrInstance
*inst
, gint r
, gint g
, gint b
)
131 r
= (r
& 0xff) >> (8-RrPseudoBPC(inst
));
132 g
= (g
& 0xff) >> (8-RrPseudoBPC(inst
));
133 b
= (b
& 0xff) >> (8-RrPseudoBPC(inst
));
134 return &RrPseudoColors(inst
)[(r
<< (2*RrPseudoBPC(inst
))) +
135 (g
<< (1*RrPseudoBPC(inst
))) +
139 static void swap_byte_order(XImage
*im
)
144 for (y
= 0; y
< im
->height
; ++y
) {
145 for (x
= 0; x
< im
->height
; ++x
) {
146 char *c
= &im
->data
[di
+ x
* im
->bits_per_pixel
/ 8];
149 switch (im
->bits_per_pixel
) {
161 g_warning("your bit depth is currently unhandled");
164 di
+= im
->bytes_per_line
;
167 if (im
->byte_order
== LSBFirst
)
168 im
->byte_order
= MSBFirst
;
170 im
->byte_order
= LSBFirst
;
173 void RrIncreaseDepth(const RrInstance
*inst
, RrPixel32
*data
, XImage
*im
)
177 RrPixel32
*p32
= (RrPixel32
*) im
->data
;
178 RrPixel16
*p16
= (RrPixel16
*) im
->data
;
179 unsigned char *p8
= (unsigned char *)im
->data
;
181 if (im
->byte_order
!= LSBFirst
)
184 switch (im
->bits_per_pixel
) {
186 for (y
= 0; y
< im
->height
; y
++) {
187 for (x
= 0; x
< im
->width
; x
++) {
188 r
= (p32
[x
] >> RrRedOffset(inst
)) & 0xff;
189 g
= (p32
[x
] >> RrGreenOffset(inst
)) & 0xff;
190 b
= (p32
[x
] >> RrBlueOffset(inst
)) & 0xff;
191 data
[x
] = (r
<< RrDefaultRedOffset
)
192 + (g
<< RrDefaultGreenOffset
)
193 + (b
<< RrDefaultBlueOffset
)
194 + (0xff << RrDefaultAlphaOffset
);
197 p32
+= im
->bytes_per_line
/4;
201 for (y
= 0; y
< im
->height
; y
++) {
202 for (x
= 0; x
< im
->width
; x
++) {
203 r
= (p16
[x
] & RrRedMask(inst
)) >>
206 g
= (p16
[x
] & RrGreenMask(inst
)) >>
207 RrGreenOffset(inst
) <<
209 b
= (p16
[x
] & RrBlueMask(inst
)) >>
210 RrBlueOffset(inst
) <<
212 data
[x
] = (r
<< RrDefaultRedOffset
)
213 + (g
<< RrDefaultGreenOffset
)
214 + (b
<< RrDefaultBlueOffset
)
215 + (0xff << RrDefaultAlphaOffset
);
218 p16
+= im
->bytes_per_line
/2;
222 g_warning("this image bit depth is currently unhandled");
225 for (y
= 0; y
< im
->height
; y
++) {
226 for (x
= 0; x
< im
->width
; x
++) {
227 if (!(((p8
[x
/ 8]) >> (x
% 8)) & 0x1))
228 data
[x
] = 0xff << RrDefaultAlphaOffset
; /* black */
230 data
[x
] = 0xffffffff; /* white */
233 p8
+= im
->bytes_per_line
;
237 g_warning("this image bit depth is currently unhandled");
241 int RrColorRed(const RrColor
*c
)
246 int RrColorGreen(const RrColor
*c
)
251 int RrColorBlue(const RrColor
*c
)
256 gulong
RrColorPixel(const RrColor
*c
)
This page took 0.044228 seconds and 3 git commands to generate.