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;
width = imgProp.imgWidth;
height = imgProp.imgHeight; int res = PNGU_GetImageProperties(ctx, &imgProp);
data = (u8 *)memalign (32, imgProp.imgWidth * imgProp.imgHeight * 4);
PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, data, 255); if(res == PNGU_OK)
int len = imgProp.imgWidth * imgProp.imgHeight * 4; {
DCFlushRange(data, len+len%32); 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;
height = imgProp.imgHeight;
int len = imgProp.imgWidth * imgProp.imgHeight * 4;
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);