source: roaraudio/libroarlight/colors.c @ 5381:430b1d26e12d

Last change on this file since 5381:430b1d26e12d was 5381:430b1d26e12d, checked in by phi, 12 years ago

updated copyright years

File size: 3.4 KB
Line 
1//colors.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2012
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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include "libroarlight.h"
27
28int roar_color_new        (struct roar_color * c) {
29 if ( c == NULL )
30  return -1;
31
32 memset(c, 0, sizeof(struct roar_color));
33
34 c->system = ROAR_COLORSYSTEM_NONE;
35
36 return 0;
37}
38
39int roar_color_new_gray   (struct roar_color * c, unsigned char k) {
40 if ( roar_color_new(c) == -1 )
41  return -1;
42
43 c->system = ROAR_COLORSYSTEM_GRAY;
44
45 c->color.gray.k = k;
46
47 return 0;
48}
49
50int roar_color_new_rgb    (struct roar_color * c, unsigned char r, unsigned char g, unsigned char b) {
51 if ( roar_color_new(c) == -1 )
52  return -1;
53
54 c->system = ROAR_COLORSYSTEM_RGB;
55
56 c->color.rgb.r = r;
57 c->color.rgb.g = g;
58 c->color.rgb.b = b;
59
60 return 0;
61}
62
63int roar_color_copy       (struct roar_color * dst, struct roar_color * src) {
64 if ( dst == NULL || src == NULL )
65  return -1;
66
67 memcpy(dst, src, sizeof(struct roar_color));
68
69 return 0;
70}
71
72int roar_color_conv       (struct roar_color * c, uint32_t system) {
73 if ( c == NULL )
74  return -1;
75
76 switch (c->system) {
77  case ROAR_COLORSYSTEM_GRAY:
78    return roar_color_conv_gray(c, system);
79   break;
80  case ROAR_COLORSYSTEM_RGB:
81    return roar_color_conv_rgb(c, system);
82   break;
83 }
84
85 return -1;
86}
87
88int roar_color_conv_gray  (struct roar_color * c, uint32_t system) {
89 unsigned char k;
90
91 if ( c == NULL )
92  return -1;
93
94 if ( c->system != ROAR_COLORSYSTEM_GRAY )
95  return -1;
96
97 switch (system) {
98  case ROAR_COLORSYSTEM_RGB:
99    k = c->color.gray.k;
100    c->color.rgb.r = k;
101    c->color.rgb.g = k;
102    c->color.rgb.b = k;
103    c->system = ROAR_COLORSYSTEM_RGB;
104    return 0;
105   break;
106 }
107
108 return -1;
109}
110
111int roar_color_conv_rgb   (struct roar_color * c, uint32_t system) {
112 if ( c == NULL )
113  return -1;
114
115 if ( c->system != ROAR_COLORSYSTEM_GRAY )
116  return -1;
117
118 switch (system) {
119 }
120
121 return -1;
122}
123
124int roar_color_to_string  (struct roar_color * c, char * str, size_t len) {
125 size_t needlen;
126
127 if ( c == NULL || str == NULL || len == 0 )
128  return -1;
129
130 // just to be sure:
131 if ( len >= 1 )
132  *str = 0;
133
134 switch (c->system) {
135  case ROAR_COLORSYSTEM_NONE: needlen = 6; break; // '(none)'
136  case ROAR_COLORSYSTEM_RGB:  needlen = 7; break; // '#RRGGBB'
137  default:
138    return -1;
139 }
140
141 needlen++; // terminating \0
142
143 if ( needlen > len )
144  return -1;
145
146 switch (c->system) {
147  case ROAR_COLORSYSTEM_NONE:
148    strcpy(str, "(none)");
149   break;
150  case ROAR_COLORSYSTEM_RGB:
151    snprintf(str, 8, "#%.2X%.2X%.2X", c->color.rgb.r, c->color.rgb.g, c->color.rgb.b);
152   break;
153 }
154
155 return 0;
156}
157
158int roar_color_to_blob    (struct roar_color * c, char * blob, size_t len);
159int roar_color_from_blob  (struct roar_color * c, char * blob, size_t len);
160
161//ll
Note: See TracBrowser for help on using the repository browser.