2 * Acess GUI (AxWin) Version 2
3 * By John Hodge (thePowersGang)
5 * Window Manager and Widget Control
13 extern tImage *Image_SIF_Parse(void *Buffer, size_t Size);
16 int UnBase64(uint8_t *Dest, char *Src, int BufSize);
20 * \brief Open an image from a URI
22 tImage *Image_Load(const char *URI)
31 _SysDebug("Image_Load: Unable parse as URI '%s'\n", URI);
35 if( strcmp(uri->Proto, "file") == 0 )
38 fp = fopen(uri->Path, "rb");
40 _SysDebug("Image_Load: Unable to open '%s'\n", uri->Path);
45 fseek(fp, 0, SEEK_END);
47 buf = malloc( filesize );
49 _SysDebug("Image_Load: malloc() failed!\n");
55 fread(buf, filesize, 1, buf);
58 else if( strcmp(uri->Proto, "base64") == 0 )
60 // 4 bytes of base64 = 3 bytes of binary (base 256)
61 filesize = strlen( uri->Path ) * 3 / 4;
62 buf = malloc(filesize);
64 _SysDebug("Image_Load: malloc() failed!\n");
69 filesize = UnBase64(buf, uri->Path, filesize);
73 _SysDebug("Image_Load: Unknow protocol '%s'\n", uri->Proto);
78 img = Image_SIF_Parse(buf, filesize);
82 _SysDebug("Image_Load: Unable to parse SIF from '%s'\n", URI);
90 * \brief Decode a Base64 value
92 int UnBase64(uint8_t *Dest, char *Src, int BufSize)
96 char *start_src = Src;
98 for( i = 0; i+2 < BufSize; i += 3 )
101 for( j = 0; j < 4; j++, Src ++ ) {
102 if('A' <= *Src && *Src <= 'Z')
103 val |= (*Src - 'A') << ((3-j)*6);
104 else if('a' <= *Src && *Src <= 'z')
105 val |= (*Src - 'a' + 26) << ((3-j)*6);
106 else if('0' <= *Src && *Src <= '9')
107 val |= (*Src - '0' + 52) << ((3-j)*6);
109 val |= 62 << ((3-j)*6);
111 val |= 63 << ((3-j)*6);
115 j --; // Ignore invalid characters
117 Dest[i ] = (val >> 16) & 0xFF;
118 Dest[i+1] = (val >> 8) & 0xFF;
119 Dest[i+2] = val & 0xFF;
125 Dest[i] = (val >> 16) & 0xFF;
127 Dest[i+1] = (val >> 8) & 0xFF;
129 return Src - start_src;