FireBirdLib - Topfield TMS PVR TAP Programming Library
INIGetARGB.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
7bool INIGetARGB(char *Key, byte *Alpha, byte *Red, byte *Green, byte *Blue, dword DefaultValue)
8{
10
11 char *i = NULL, *j = NULL, *k;
12 char TempKey[80];
13 dword l, x;
14 size_t plen;
15
16 if(!Key)
17 {
18 TRACEEXIT();
19 return FALSE;
20 }
21
22 strncpy(TempKey, Key, sizeof(TempKey) - 2);
23 TempKey[sizeof(TempKey) - 2] = '\0';
24 strcat(TempKey, "=");
25 l = strlen(TempKey);
26
27 INIFindStartEnd(TempKey, &i, &j, l + 19);
28
29 if(!i || !j || (j < i + l)) x = DefaultValue;
30 else
31 {
32 k = strchr(i + l, ',');
33
34 if(!k || (k > j))
35 {
36 // old style
37 x = (dword) strtoul(i + l, NULL, 16);
38
39 }
40 else
41 {
42 // new style
43 k = i + l;
44 x = 0;
45
46 // alpha
47 if((k = ParseLine(k, &plen, ',')) && (plen > 0 && k + plen < j))
48 {
49 x |= (strtoul(k, NULL, (plen > 2 && tolower(*(k + 1)) == 'x' ? 16 : 10)) & 1) << 15;
50 k += plen;
51
52 // red
53 if((k = ParseLine(k, &plen, ',')) && (plen > 0 && k + plen < j))
54 {
55 x |= (strtoul(k, NULL, (plen > 2 && tolower(*(k + 1)) == 'x' ? 16 : 10)) & 0x1f) << 10;
56 k += plen;
57
58 // green
59 if((k = ParseLine(k, &plen, ',')) && (plen > 0 && k + plen < j))
60 {
61 x |= (strtoul(k, NULL, (plen > 2 && tolower(*(k + 1)) == 'x' ? 16 : 10)) & 0x1f) << 5;
62 k += plen;
63
64 // blue
65 if(*k == ',') k++;
66 x |= strtoul(k, NULL, (j - k > 2 && tolower(*(k + 1)) == 'x' ? 16 : 10)) & 0x1f;
67 }
68 else x = DefaultValue;
69 }
70 else x = DefaultValue;
71 }
72 else x = DefaultValue;
73 }
74 }
75
76 if(Alpha) *Alpha = A1555(x);
77 if(Red) *Red = R1555(x);
78 if(Green) *Green = G1555(x);
79 if(Blue) *Blue = B1555(x);
80
81 TRACEEXIT();
82 return TRUE;
83}
void INIFindStartEnd(char *, char **, char **, dword)
bool INIGetARGB(char *Key, byte *Alpha, byte *Red, byte *Green, byte *Blue, dword DefaultValue)
Definition: INIGetARGB.c:7
#define B1555(x)
Definition: libFireBird.h:238
char * ParseLine(const char *zeile, size_t *n, char delim)
Definition: ParseLine.c:4
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define A1555(x)
Definition: libFireBird.h:235
#define TRACEENTER()
Definition: libFireBird.h:1243
#define R1555(x)
Definition: libFireBird.h:236
#define G1555(x)
Definition: libFireBird.h:237