1 | //colors.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009 |
---|
5 | * |
---|
6 | * This file is part of libroardsp a part of RoarAudio, |
---|
7 | * a cross-platform sound system for both, home and professional use. |
---|
8 | * See README for details. |
---|
9 | * |
---|
10 | * This file is free software; you can redistribute it and/or modify |
---|
11 | * it under the terms of the GNU General Public License version 3 |
---|
12 | * as published by the Free Software Foundation. |
---|
13 | * |
---|
14 | * libroardsp is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this software; see the file COPYING. If not, write to |
---|
21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
22 | * |
---|
23 | */ |
---|
24 | |
---|
25 | #include "libroarlight.h" |
---|
26 | |
---|
27 | int roar_color_new (struct roar_color * c) { |
---|
28 | if ( c == NULL ) |
---|
29 | return -1; |
---|
30 | |
---|
31 | memset(c, 0, sizeof(struct roar_color)); |
---|
32 | |
---|
33 | c->system = ROAR_COLORSYSTEM_NONE; |
---|
34 | |
---|
35 | return 0; |
---|
36 | } |
---|
37 | |
---|
38 | int roar_color_new_gray (struct roar_color * c, unsigned char k) { |
---|
39 | if ( roar_color_new(c) == -1 ) |
---|
40 | return -1; |
---|
41 | |
---|
42 | c->system = ROAR_COLORSYSTEM_GRAY; |
---|
43 | |
---|
44 | c->color.gray.k = k; |
---|
45 | |
---|
46 | return 0; |
---|
47 | } |
---|
48 | |
---|
49 | int roar_color_new_rgb (struct roar_color * c, unsigned char r, unsigned char g, unsigned char b) { |
---|
50 | if ( roar_color_new(c) == -1 ) |
---|
51 | return -1; |
---|
52 | |
---|
53 | c->system = ROAR_COLORSYSTEM_RGB; |
---|
54 | |
---|
55 | c->color.rgb.r = r; |
---|
56 | c->color.rgb.g = g; |
---|
57 | c->color.rgb.b = b; |
---|
58 | |
---|
59 | return 0; |
---|
60 | } |
---|
61 | |
---|
62 | int roar_color_copy (struct roar_color * dst, struct roar_color * src) { |
---|
63 | if ( dst == NULL || src == NULL ) |
---|
64 | return -1; |
---|
65 | |
---|
66 | memcpy(dst, src, sizeof(struct roar_color)); |
---|
67 | |
---|
68 | return 0; |
---|
69 | } |
---|
70 | |
---|
71 | int roar_color_conv (struct roar_color * c, uint32_t system) { |
---|
72 | if ( c == NULL ) |
---|
73 | return -1; |
---|
74 | |
---|
75 | switch (c->system) { |
---|
76 | case ROAR_COLORSYSTEM_GRAY: |
---|
77 | return roar_color_conv_gray(c, system); |
---|
78 | break; |
---|
79 | case ROAR_COLORSYSTEM_RGB: |
---|
80 | return roar_color_conv_rgb(c, system); |
---|
81 | break; |
---|
82 | } |
---|
83 | |
---|
84 | return -1; |
---|
85 | } |
---|
86 | |
---|
87 | int roar_color_conv_gray (struct roar_color * c, uint32_t system) { |
---|
88 | unsigned char k; |
---|
89 | |
---|
90 | if ( c == NULL ) |
---|
91 | return -1; |
---|
92 | |
---|
93 | if ( c->system != ROAR_COLORSYSTEM_GRAY ) |
---|
94 | return -1; |
---|
95 | |
---|
96 | switch (system) { |
---|
97 | case ROAR_COLORSYSTEM_RGB: |
---|
98 | k = c->color.gray.k; |
---|
99 | c->color.rgb.r = k; |
---|
100 | c->color.rgb.g = k; |
---|
101 | c->color.rgb.b = k; |
---|
102 | c->system = ROAR_COLORSYSTEM_RGB; |
---|
103 | return 0; |
---|
104 | break; |
---|
105 | } |
---|
106 | |
---|
107 | return -1; |
---|
108 | } |
---|
109 | |
---|
110 | int roar_color_conv_rgb (struct roar_color * c, uint32_t system) { |
---|
111 | if ( c == NULL ) |
---|
112 | return -1; |
---|
113 | |
---|
114 | if ( c->system != ROAR_COLORSYSTEM_GRAY ) |
---|
115 | return -1; |
---|
116 | |
---|
117 | switch (system) { |
---|
118 | } |
---|
119 | |
---|
120 | return -1; |
---|
121 | } |
---|
122 | |
---|
123 | //ll |
---|