Open MacroGu opened 5 years ago
Add base64_decode: 120 lines
Add PNG decode: 1330 lines
Add
//parse embedded PNG image
static void parseImage(NSVGparser* p, const char** dict)
{
// NSVGattrib* attr = nsvg__getAttr(p);
NSVGpattern *pt = NULL;
int i;
UINTN len = 0;
float w,h;
const char *href = NULL;
UINT8 *tmpData = NULL;
EG_IMAGE *NewImage = NULL;
for (i = 0; dict[i]; i += 2) {
if (strcmp(dict[i], "width") == 0) {
w = nsvg__parseCoordinate(p, dict[i+1], 0.0f, nsvg__actualWidth(p));
} else if (strcmp(dict[i], "height") == 0) {
h = nsvg__parseCoordinate(p, dict[i+1], 0.0f, nsvg__actualHeight(p));
} else if (strcmp(dict[i], "xlink:href") == 0) {
href = dict[i+1];
} else {
nsvg__parseAttr(p, dict[i], dict[i + 1]);
}
}
if (!href || (strstr(href, "data:image/png;") == NULL)) {
return;
}
href = strstr(href, "base64,") + 7;
if (p->patternFlag) {
pt = p->patterns; //the last one
}
tmpData = (UINT8 *)Base64Decode((char*)href, &len);
if (len == 0) {
DBG("image not decoded from base64\n");
}
NewImage = egDecodePNG(tmpData, len, TRUE);
pt->image = (void *)NewImage;
if (tmpData) {
FreePool(tmpData);
}
}
Then decide how have you use it. I applied the image as pattern to fill the shape which is quirky solution but compatible with nanosvgrast.
thanks, I will try it
would you please afford the egDecodePNG and Base64Decode functions, EG_IMAGE struct. thanks.
See the full project. nanosvg located in rEFIt_UEFI/libeg/ folder little different from original.
would you please give a http link of the full project, where is the refit_uefi/libeg/ folder, I can not find it, thanks.
do you mean the https://github.com/Clover-EFI-Bootloader/clover/tree/master/rEFIt_UEFI/libeg this project ?
Not exactly. github project is older then recent on sf.net. Why my link disappears? Clover
@MacroGu you might be interested in https://github.com/mtyberg/nanosvg/pull/1, I took @SergeySlice 's code and adapted it on top of the "plain" nanosvg.
egg.zip
<image id="Egg" x="0" y="0" width="100" height="100" xlink:href="data:image/png;base64,