safer PNG handling

This commit is contained in:
dborth 2009-03-17 06:06:01 +00:00
parent c3a00a0c4c
commit 7800bbce74
2 changed files with 29 additions and 10 deletions

View File

@ -24,16 +24,35 @@ GuiImageData::GuiImageData(const u8 * img)
else else
{ {
PNGUPROP imgProp; PNGUPROP imgProp;
IMGCTX ctx; IMGCTX ctx = PNGU_SelectImageFromBuffer(img);
ctx = PNGU_SelectImageFromBuffer(img); if(!ctx)
PNGU_GetImageProperties (ctx, &imgProp); return;
int res = PNGU_GetImageProperties(ctx, &imgProp);
if(res == PNGU_OK)
{
data = (u8 *)memalign (32, imgProp.imgWidth * imgProp.imgHeight * 4);
if(data)
{
res = PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, data, 255);
if(res == PNGU_OK)
{
width = imgProp.imgWidth; width = imgProp.imgWidth;
height = imgProp.imgHeight; height = imgProp.imgHeight;
data = (u8 *)memalign (32, imgProp.imgWidth * imgProp.imgHeight * 4);
PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, data, 255);
int len = imgProp.imgWidth * imgProp.imgHeight * 4; int len = imgProp.imgWidth * imgProp.imgHeight * 4;
DCFlushRange(data, len+len%32); DCFlushRange(data, len+len%32);
}
else
{
free(data);
data = NULL;
}
}
}
PNGU_ReleaseImageContext (ctx); PNGU_ReleaseImageContext (ctx);
} }
} }

View File

@ -3264,7 +3264,7 @@ MainMenu (int menu)
GuiImage logoImgOver(&logoOver); GuiImage logoImgOver(&logoOver);
btnLogo = new GuiButton(logoImg.GetWidth(), logoImg.GetHeight()); btnLogo = new GuiButton(logoImg.GetWidth(), logoImg.GetHeight());
btnLogo->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); btnLogo->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
btnLogo->SetPosition(-50, 30); btnLogo->SetPosition(-30, 30);
btnLogo->SetImage(&logoImg); btnLogo->SetImage(&logoImg);
btnLogo->SetImageOver(&logoImgOver); btnLogo->SetImageOver(&logoImgOver);
btnLogo->SetTrigger(&trigA); btnLogo->SetTrigger(&trigA);