diff options
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/lib/SOURCES | 1 | ||||
-rw-r--r-- | apps/plugins/lib/rgb_hsv.c | 129 | ||||
-rw-r--r-- | apps/plugins/lib/rgb_hsv.h | 35 |
3 files changed, 165 insertions, 0 deletions
diff --git a/apps/plugins/lib/SOURCES b/apps/plugins/lib/SOURCES index 81cdc8c944..f0e9ebce63 100644 --- a/apps/plugins/lib/SOURCES +++ b/apps/plugins/lib/SOURCES | |||
@@ -1,5 +1,6 @@ | |||
1 | configfile.c | 1 | configfile.c |
2 | playback_control.c | 2 | playback_control.c |
3 | rgb_hsv.c | ||
3 | #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4) && (CONFIG_LCD != LCD_IPOD2BPP) | 4 | #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4) && (CONFIG_LCD != LCD_IPOD2BPP) |
4 | gray_core.c | 5 | gray_core.c |
5 | gray_draw.c | 6 | gray_draw.c |
diff --git a/apps/plugins/lib/rgb_hsv.c b/apps/plugins/lib/rgb_hsv.c new file mode 100644 index 0000000000..0d424b9149 --- /dev/null +++ b/apps/plugins/lib/rgb_hsv.c | |||
@@ -0,0 +1,129 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 Antoine Cellerier <dionoea -at- videolan -dot- org> | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "rgb_hsv.h" | ||
21 | |||
22 | /*********************************************************************** | ||
23 | * Colorspace transformations | ||
24 | *********************************************************************** | ||
25 | * r, g and b range from 0 to 255 | ||
26 | * h ranges from 0 to 3599 (which in fact means 0.0 to 359.9). | ||
27 | * 360 is the same as 0 (it loops) | ||
28 | * s and v range from 0 to 255 (which in fact means 0.00 to 1.00) | ||
29 | ***********************************************************************/ | ||
30 | |||
31 | void rgb2hsv( int r, int g, int b, int *h, int *s, int *v ) | ||
32 | { | ||
33 | int max; | ||
34 | int min; | ||
35 | |||
36 | max = r > g ? r : g; | ||
37 | if( b > max ) max = b; | ||
38 | |||
39 | min = r < g ? r : g; | ||
40 | if( b < min ) min = b; | ||
41 | |||
42 | if( max == 0 ) | ||
43 | { | ||
44 | *v = 0; | ||
45 | *h = 0; *s = 0; /* Random since it's black */ | ||
46 | return; | ||
47 | } | ||
48 | else if( max == min ) | ||
49 | { | ||
50 | *h = 0; /* Random since it's gray */ | ||
51 | } | ||
52 | else if( max == r && g >= b ) | ||
53 | { | ||
54 | *h = ( 10 * 60 * ( g - b )/( max - min ) ); | ||
55 | } | ||
56 | else if( max == r && g < b ) | ||
57 | { | ||
58 | *h = ( 10 * ( 60 * ( g - b )/( max - min ) + 360 )); | ||
59 | } | ||
60 | else if( max == g ) | ||
61 | { | ||
62 | *h = ( 10 * ( 60 * ( b - r )/( max - min ) + 120 )); | ||
63 | } | ||
64 | else// if( max == b ) | ||
65 | { | ||
66 | *h = ( 10 * ( 60 * ( r - g )/( max - min ) + 240 )); | ||
67 | } | ||
68 | |||
69 | /* Just in case ? */ | ||
70 | while( *h < 0 ) *h += 3600; | ||
71 | while( *h >= 3600 ) *h-= 3600; | ||
72 | |||
73 | *s = (( max - min )*255)/max; | ||
74 | *v = max; | ||
75 | } | ||
76 | |||
77 | void hsv2rgb( int h, int s, int v, int *r, int *g, int *b ) | ||
78 | { | ||
79 | int f, p, q, t; | ||
80 | while( h < 0 ) h += 3600; | ||
81 | while( h >= 3600 ) h-= 3600; | ||
82 | f = h%600; | ||
83 | p = ( v * ( 255 - s ) ) / ( 255 ); | ||
84 | q = ( v * ( 600*255 - f*s ) ) / ( 255 * 600 ); | ||
85 | t = ( v * ( 600*255 - ( 600 - f ) * s ) ) / ( 255 * 600 ); | ||
86 | |||
87 | |||
88 | if( s == 0 ) /* gray */ | ||
89 | { | ||
90 | *r = v; | ||
91 | *g = *r; | ||
92 | *b = *r; | ||
93 | return; | ||
94 | } | ||
95 | |||
96 | switch( h/600 ) | ||
97 | { | ||
98 | case 0: | ||
99 | *r = v; | ||
100 | *g = t; | ||
101 | *b = p; | ||
102 | break; | ||
103 | case 1: | ||
104 | *r = q; | ||
105 | *g = v; | ||
106 | *b = p; | ||
107 | break; | ||
108 | case 2: | ||
109 | *r = p; | ||
110 | *g = v; | ||
111 | *b = t; | ||
112 | break; | ||
113 | case 3: | ||
114 | *r = p; | ||
115 | *g = q; | ||
116 | *b = v; | ||
117 | break; | ||
118 | case 4: | ||
119 | *r = t; | ||
120 | *g = p; | ||
121 | *b = v; | ||
122 | break; | ||
123 | case 5: | ||
124 | *r = v; | ||
125 | *g = p; | ||
126 | *b = q; | ||
127 | break; | ||
128 | } | ||
129 | } | ||
diff --git a/apps/plugins/lib/rgb_hsv.h b/apps/plugins/lib/rgb_hsv.h new file mode 100644 index 0000000000..30bb206df1 --- /dev/null +++ b/apps/plugins/lib/rgb_hsv.h | |||
@@ -0,0 +1,35 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 Antoine Cellerier <dionoea -at- videolan -dot- org> | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #ifndef LIB_HSV_RGB_H | ||
21 | #define LIB_HSV_RGB_H | ||
22 | |||
23 | /*********************************************************************** | ||
24 | * Colorspace transformations | ||
25 | *********************************************************************** | ||
26 | * r, g and b range from 0 to 255 | ||
27 | * h ranges from 0 to 3599 (which in fact means 0.0 to 359.9). | ||
28 | * 360 is the same as 0 (it loops) | ||
29 | * s and v range from 0 to 255 (which in fact means 0.00 to 1.00) | ||
30 | ***********************************************************************/ | ||
31 | |||
32 | void rgb2hsv( int r, int g, int b, int *h, int *s, int *v ); | ||
33 | void hsv2rgb( int h, int s, int v, int *r, int *g, int *b ); | ||
34 | |||
35 | #endif | ||