]>
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_hsb(DATA32
*data
, int w
, int h
, float hu
, 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 r
= (argb
>> 16) & 0xff;
48 g
= (argb
>> 8) & 0xff;
52 cmax
= (r
> g
) ? r
: g
;
53 if (b
> cmax
) cmax
= b
;
54 cmin
= (r
< g
) ? r
: g
;
55 if (b
< cmin
) cmin
= b
;
56 brightness
= ((float)cmax
) / 255.0f
;
58 saturation
= ((float)(cmax
- cmin
)) / ((float)cmax
);
64 redc
= ((float)(cmax
- r
)) / ((float)(cmax
- cmin
));
65 greenc
= ((float)(cmax
- g
)) / ((float)(cmax
- cmin
));
66 bluec
= ((float)(cmax
- b
)) / ((float)(cmax
- cmin
));
70 hue
= 2.0f
+ redc
- bluec
;
72 hue
= 4.0f
+ greenc
- redc
;
80 if (saturation
< 0.0) saturation
= 0.0;
81 if (saturation
> 1.0) saturation
= 1.0;
83 if (brightness
< 0.0) brightness
= 0.0;
84 if (brightness
> 1.0) brightness
= 1.0;
86 if (hue
< 0.0) hue
= 0.0;
87 if (hue
> 1.0) hue
= 1.0;
90 if (saturation
== 0) {
91 r
= g
= b
= (int)(brightness
* 255.0f
+ 0.5f
);
93 h2
= (hue
- (int)hue
) * 6.0f
;
95 p
= brightness
* (1.0f
- saturation
);
96 q
= brightness
* (1.0f
- saturation
* f
);
97 t
= brightness
* (1.0f
- (saturation
* (1.0f
- f
)));
100 r
= (int)(brightness
* 255.0f
+ 0.5f
);
101 g
= (int)(t
* 255.0f
+ 0.5f
);
102 b
= (int)(p
* 255.0f
+ 0.5f
);
105 r
= (int)(q
* 255.0f
+ 0.5f
);
106 g
= (int)(brightness
* 255.0f
+ 0.5f
);
107 b
= (int)(p
* 255.0f
+ 0.5f
);
110 r
= (int)(p
* 255.0f
+ 0.5f
);
111 g
= (int)(brightness
* 255.0f
+ 0.5f
);
112 b
= (int)(t
* 255.0f
+ 0.5f
);
115 r
= (int)(p
* 255.0f
+ 0.5f
);
116 g
= (int)(q
* 255.0f
+ 0.5f
);
117 b
= (int)(brightness
* 255.0f
+ 0.5f
);
120 r
= (int)(t
* 255.0f
+ 0.5f
);
121 g
= (int)(p
* 255.0f
+ 0.5f
);
122 b
= (int)(brightness
* 255.0f
+ 0.5f
);
125 r
= (int)(brightness
* 255.0f
+ 0.5f
);
126 g
= (int)(p
* 255.0f
+ 0.5f
);
127 b
= (int)(q
* 255.0f
+ 0.5f
);
133 argb
= (argb
<< 8) + r
;
134 argb
= (argb
<< 8) + g
;
135 argb
= (argb
<< 8) + b
;
This page took 0.038088 seconds and 4 git commands to generate.