]>
Dogcows Code - chaz/tint2/blob - src/util/common.c
1 /**************************************************************************
3 * Tint2 : common windows function
5 * Copyright (C) 2007 Pål Staurland (staura@gmail.com)
6 * Modified (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 **************************************************************************/
22 #include <X11/Xutil.h>
23 #include <X11/Xatom.h>
33 void adjust_asb(DATA32
*data
, int w
, int h
, int alpha
, float satur
, float bright
)
36 unsigned int a
, r
, g
, b
, argb
;
40 float hue
, saturation
, brightness
;
41 float redc
, greenc
, bluec
;
43 for(y
= 0; y
< h
; y
++) {
44 for(id
= y
* w
, x
= 0; x
< w
; x
++, id
++) {
46 a
= (argb
>> 24) & 0xff;
47 // transparent => nothing to do.
49 r
= (argb
>> 16) & 0xff;
50 g
= (argb
>> 8) & 0xff;
54 cmax
= (r
> g
) ? r
: g
;
55 if (b
> cmax
) cmax
= b
;
56 cmin
= (r
< g
) ? r
: g
;
57 if (b
< cmin
) cmin
= b
;
58 brightness
= ((float)cmax
) / 255.0f
;
60 saturation
= ((float)(cmax
- cmin
)) / ((float)cmax
);
66 redc
= ((float)(cmax
- r
)) / ((float)(cmax
- cmin
));
67 greenc
= ((float)(cmax
- g
)) / ((float)(cmax
- cmin
));
68 bluec
= ((float)(cmax
- b
)) / ((float)(cmax
- cmin
));
72 hue
= 2.0f
+ redc
- bluec
;
74 hue
= 4.0f
+ greenc
- redc
;
82 if (saturation
< 0.0) saturation
= 0.0;
83 if (saturation
> 1.0) saturation
= 1.0;
85 if (brightness
< 0.0) brightness
= 0.0;
86 if (brightness
> 1.0) brightness
= 1.0;
91 if (saturation
== 0) {
92 r
= g
= b
= (int)(brightness
* 255.0f
+ 0.5f
);
94 h2
= (hue
- (int)hue
) * 6.0f
;
96 p
= brightness
* (1.0f
- saturation
);
97 q
= brightness
* (1.0f
- saturation
* f
);
98 t
= brightness
* (1.0f
- (saturation
* (1.0f
- f
)));
101 r
= (int)(brightness
* 255.0f
+ 0.5f
);
102 g
= (int)(t
* 255.0f
+ 0.5f
);
103 b
= (int)(p
* 255.0f
+ 0.5f
);
106 r
= (int)(q
* 255.0f
+ 0.5f
);
107 g
= (int)(brightness
* 255.0f
+ 0.5f
);
108 b
= (int)(p
* 255.0f
+ 0.5f
);
111 r
= (int)(p
* 255.0f
+ 0.5f
);
112 g
= (int)(brightness
* 255.0f
+ 0.5f
);
113 b
= (int)(t
* 255.0f
+ 0.5f
);
116 r
= (int)(p
* 255.0f
+ 0.5f
);
117 g
= (int)(q
* 255.0f
+ 0.5f
);
118 b
= (int)(brightness
* 255.0f
+ 0.5f
);
121 r
= (int)(t
* 255.0f
+ 0.5f
);
122 g
= (int)(p
* 255.0f
+ 0.5f
);
123 b
= (int)(brightness
* 255.0f
+ 0.5f
);
126 r
= (int)(brightness
* 255.0f
+ 0.5f
);
127 g
= (int)(p
* 255.0f
+ 0.5f
);
128 b
= (int)(q
* 255.0f
+ 0.5f
);
134 argb
= (argb
<< 8) + r
;
135 argb
= (argb
<< 8) + g
;
136 argb
= (argb
<< 8) + b
;
This page took 0.039045 seconds and 4 git commands to generate.