MHEG5  18.9.0
MHEG5 Documentation
tmcolor.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
3  * Copyright © 2004 Ocean Blue Software Ltd
4  * Copyright © 2000 Koninklijke Philips Electronics N.V
5  *
6  * This file is part of a DTVKit Software Component
7  * You are permitted to copy, modify or distribute this file subject to the terms
8  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
9  *
10  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
11  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
12  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
13  *
14  * If you or your organisation is not a member of DTVKit then you have access
15  * to this source code outside of the terms of the licence agreement
16  * and you are expected to delete this and any associated files immediately.
17  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
18  *******************************************************************************/
28 /*---includes for this file--------------------------------------------------*/
29 #include "mh5profile.h"
30 #include "tmcolor.h"
31 #include "mh5debug.h"
32 #include "mh5memory.h"
33 
34 /*---constant definitions for this file--------------------------------------*/
35 
36 
37 /*---local typedef structs for this file-------------------------------------*/
38 
39 /*---local (static) variable declarations for this file----------------------*/
40 
41 /*---local function definitions----------------------------------------------*/
42 
43 /*---global function definitions---------------------------------------------*/
44 
53 OSDColor OSDgetColour(const char *colour, int len)
54 {
55  unsigned char r, g, b, t;
56 #ifdef _4DOTCOLOR_
57  BYTE i, j;
58 #endif
59 
60 #ifdef _PENGUINCOLOR_
61  if (!strnicmp(colour, "CYAN", len))
62  return RGB(0, 255, 255);
63  if (!strnicmp(colour, "CYAN1", len))
64  return RGB(0, 255, 255);
65  if (!strnicmp(colour, "CYAN2", len))
66  return RGB(0, 238, 238);
67  if (!strnicmp(colour, "CYAN3", len))
68  return RGB(0, 205, 205);
69  if (!strnicmp(colour, "CYAN4", len))
70  return RGB(0, 139, 139);
71  if (!strnicmp(colour, "DARKCYAN", len))
72  return RGB(0, 139, 139);
73  if (!strnicmp(colour, "YELLOW", len))
74  return RGB(255, 255, 0);
75  if (!strnicmp(colour, "YELLOW1", len))
76  return RGB(255, 255, 0);
77  if (!strnicmp(colour, "YELLOW2", len))
78  return RGB(238, 238, 0);
79  if (!strnicmp(colour, "YELLOW3", len))
80  return RGB(205, 205, 0);
81  if (!strnicmp(colour, "YELLOW4", len))
82  return RGB(139, 139, 0);
83  if (!strnicmp(colour, "DARKYELLOW", len))
84  return RGB(139, 139, 0);
85  if (!strnicmp(colour, "MAGENTA", len))
86  return RGB(255, 0, 255);
87  if (!strnicmp(colour, "MAGENTA1", len))
88  return RGB(255, 0, 255);
89  if (!strnicmp(colour, "MAGENTA2", len))
90  return RGB(238, 0, 238);
91  if (!strnicmp(colour, "MAGENTA3", len))
92  return RGB(205, 0, 205);
93  if (!strnicmp(colour, "MAGENTA4", len))
94  return RGB(139, 0, 139);
95  if (!strnicmp(colour, "DARKMAGENTA", len))
96  return RGB(139, 0, 139);
97  if (!strnicmp(colour, "RED", len))
98  return RGB(255, 0, 0);
99  if (!strnicmp(colour, "RED1", len))
100  return RGB(255, 0, 0);
101  if (!strnicmp(colour, "RED2", len))
102  return RGB(238, 0, 0);
103  if (!strnicmp(colour, "RED3", len))
104  return RGB(205, 0, 0);
105  if (!strnicmp(colour, "RED4", len))
106  return RGB(139, 0, 0);
107  if (!strnicmp(colour, "DARKRED", len))
108  return RGB(139, 0, 0);
109  if (!strnicmp(colour, "GREEN", len))
110  return RGB(0, 255, 0);
111  if (!strnicmp(colour, "GREEN1", len))
112  return RGB(0, 255, 0);
113  if (!strnicmp(colour, "GREEN2", len))
114  return RGB(0, 238, 0);
115  if (!strnicmp(colour, "GREEN3", len))
116  return RGB(0, 205, 0);
117  if (!strnicmp(colour, "GREEN4", len))
118  return RGB(0, 139, 0);
119  if (!strnicmp(colour, "DARKGREEN", len))
120  return RGB(0, 139, 0);
121  if (!strnicmp(colour, "BLUE", len))
122  return RGB(0, 0, 255);
123  if (!strnicmp(colour, "BLUE1", len))
124  return RGB(0, 0, 255);
125  if (!strnicmp(colour, "BLUE2", len))
126  return RGB(0, 0, 238);
127  if (!strnicmp(colour, "BLUE3", len))
128  return RGB(0, 0, 205);
129  if (!strnicmp(colour, "BLUE4", len))
130  return RGB(0, 0, 139);
131  if (!strnicmp(colour, "DARKBLUE", len))
132  return RGB(0, 0, 139);
133  if (!strnicmp(colour, "BLACK", len))
134  return RGB(0, 0, 0);
135  if (!strnicmp(colour, "GRAY", len))
136  return RGB(190, 190, 190);
137  if (!strnicmp(colour, "GREY", len))
138  return RGB(190, 190, 190);
139  if (!strnicmp(colour, "WHITE", len))
140  return RGB(255, 255, 255);
141  if (!strnicmp(colour, "TRANSPARENT", len))
142  return TRANSPARENTCOLOR;
143 
144  if ((colour[0] == '#') && (len == 7))
145  {
146  r = (colname[1] > '9' ? (colname[1] - 'A' + 10) : (colname[1] - '0')) * 16 + (colname[2] > '9' ? (colname[2] - 'A' + 10) : (colname[2] - '0'));
147  g = (colname[3] > '9' ? (colname[3] - 'A' + 10) : (colname[3] - '0')) * 16 + (colname[4] > '9' ? (colname[4] - 'A' + 10) : (colname[4] - '0'));
148  b = (colname[5] > '9' ? (colname[5] - 'A' + 10) : (colname[5] - '0')) * 16 + (colname[6] > '9' ? (colname[6] - 'A' + 10) : (colname[6] - '0'));
149  return RGB(r, g, b);
150  }
151 
152 #endif
153 #ifdef _RGBTCOLOR_
154  if (len == 4)
155  {
156  r = (unsigned char)colour[0];
157  g = (unsigned char)colour[1];
158  b = (unsigned char)colour[2];
159  t = (unsigned char)colour[3];
160  return (OSDColor)RGBT(r, g, b, t);
161  }
162 #endif
163 #ifdef _RGBCOLOR_
164  if (len == 3)
165  {
166  r = (BYTE)colour[0];
167  g = (BYTE)colour[1];
168  b = (BYTE)colour[2];
169  t = 0;
170  return (OSDColor)((DWORD)((BYTE) (r) |
171  (((WORD) (BYTE) (g)) << 8) |
172  (((DWORD) (BYTE) (b)) << 16) |
173  (((DWORD) (BYTE) (t)) << 24)));
174  }
175 #endif
176 #ifdef _4DOTCOLOR_
177  j = 0; i = 0;
178  while ((colour[i] <= '9') && (colour[i] >= '0') && (i < len))
179  j = j * 10 + (int) colour[i++] - (int) '0';
180  r = j; i++; j = 0;
181  while ((colour[i] <= '9') && (colour[i] >= '0') && (i < len))
182  j = j * 10 + (int) colour[i++] - (int) '0';
183  g = j; i++; j = 0;
184  while ((colour[i] <= '9') && (colour[i] >= '0') && (i < len))
185  j = j * 10 + (int) colour[i++] - (int) '0';
186  b = j; i++; j = 0;
187  while ((colour[i] <= '9') && (colour[i] >= '0') && (i < len))
188  j = j * 10 + (int) colour[i++] - (int) '0';
189  t = j;
190  return (OSDColor)((DWORD)((BYTE) (r) |
191  (((WORD) (BYTE) (g)) << 8) |
192  (((DWORD) (BYTE) (b)) << 16) |
193  (((DWORD) (BYTE) (t)) << 24)));
194 #endif
195 #ifdef MHEG5LOG
196  MHEG5LogPrintf(MHEG5WARNING, "unknown color encoding ");
197  for (r = 0; r < len; r++)
198  MHEG5LogPrintf(MHEG5WARNING, "%c", colour[r]);
199  MHEG5LogPrintf(MHEG5WARNING, "\n");
200 #endif
201  return 0; /* black */
202 }
203 
211 {
212  MHEG5String retval;
213 
214 #ifdef _RGBTCOLOR_
215  retval.data = MHEG5getMem( 4 );
216  if (retval.data)
217  {
218  retval.len = 4;
219  retval.data[0] = (unsigned char)GetRValue(colour);
220  retval.data[1] = (unsigned char)GetGValue(colour);
221  retval.data[2] = (unsigned char)GetBValue(colour);
222  retval.data[3] = (unsigned char)GetTValue(colour);
223  }
224  else
225  {
226  retval.len = 0;
227  }
228 #else
229 #error OSDsetColor no supported colour type
230 #endif
231 
232  return retval;
233 }
234 
MHEG5String OSDsetColour(OSDColor colour)
Converts an OSDColor type into an MHEG5 colour value For UK1 profile only RGBTCOLOR is defined...
Definition: tmcolor.c:210
#define TRANSPARENTCOLOR
Definition: tmcolor.h:37
#define RGBT(r, g, b, t)
Definition: tmcolor.h:48
U32BIT OSDColor
Definition: osdtypes.h:41
#define MHEG5getMem
Definition: glue_memory.h:93
#define GetRValue(osdcolour)
Definition: tmcolor.h:54
#define GetGValue(osdcolour)
Definition: tmcolor.h:55
This file defines the profile for the MHEG engine.
#define RGB(r, g, b)
Definition: tmcolor.h:47
#define GetTValue(osdcolour)
Definition: tmcolor.h:57
MHEG5Byte * data
Definition: mh5base.h:85
int len
Definition: mh5gate.c:57
Mheg5 logging and debug printing.
redirection include
OSDColor OSDgetColour(const char *colour, int len)
Converts an MHEG5 colour value to an OSDColor type For UK1 profile only RGBTCOLOR is defined...
Definition: tmcolor.c:53
MHEG5Int len
Definition: mh5base.h:84
Definition of colour type for MHEG5 - settings and conversions.
#define GetBValue(osdcolour)
Definition: tmcolor.h:56