FireBirdLib - Topfield TMS PVR TAP Programming Library
INIGetRGB8.c
Go to the documentation of this file.
1#include <string.h>
2#include <stdlib.h>
3#include <ctype.h>
4#include "FBLib_ini.h"
5#include "libFireBird.h"
6
7//Expects 8 bit RGB values
8
9bool INIGetRGB8(char *Key, byte *Red, byte *Green, byte *Blue, dword DefaultValue)
10{
11 TRACEENTER();
12
13 char *i = NULL, *j = NULL, *k;
14 char TempKey[80];
15 dword l, x;
16 size_t plen;
17
18 if(!Key)
19 {
20 TRACEEXIT();
21 return FALSE;
22 }
23
24 strncpy(TempKey, Key, sizeof(TempKey) - 2);
25 TempKey[sizeof(TempKey) - 2] = '\0';
26 strcat(TempKey, "=");
27 l = strlen(TempKey);
28
29 INIFindStartEnd(TempKey, &i, &j, l + 14);
30
31 if(!i || !j || (j < i + l)) x = DefaultValue;
32 else
33 {
34 k = i + l;
35 x = 0;
36
37 // red
38 if((k = ParseLine(k, &plen, ',')) && (plen > 0 && k + plen < j))
39 {
40 x |= (strtoul(k, NULL, (plen > 2 && tolower(*(k + 1)) == 'x' ? 16 : 10)) & 0xff) << 16;
41 k += plen;
42
43 // green
44 if((k = ParseLine(k, &plen, ',')) && (plen > 0 && k + plen < j))
45 {
46 x |= (strtoul(k, NULL, (plen > 2 && tolower(*(k + 1)) == 'x' ? 16 : 10)) & 0xff) << 8;
47 k += plen;
48
49 // blue
50 if(*k == ',') k++;
51 x |= strtoul(k, NULL, (j - k > 2 && tolower(*(k + 1)) == 'x' ? 16 : 10)) & 0xff;
52 }
53 else x = DefaultValue;
54 }
55 else x = DefaultValue;
56 }
57
58 if(Red) *Red = (x >> 16) & 0xff;
59 if(Green) *Green = (x >> 8) & 0xff;
60 if(Blue) *Blue = x & 0xff;
61
62 TRACEEXIT();
63 return TRUE;
64}
void INIFindStartEnd(char *, char **, char **, dword)
bool INIGetRGB8(char *Key, byte *Red, byte *Green, byte *Blue, dword DefaultValue)
Definition: INIGetRGB8.c:9
char * ParseLine(const char *zeile, size_t *n, char delim)
Definition: ParseLine.c:4
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define TRACEENTER()
Definition: libFireBird.h:1243