| 1311 | |
| 1312 | |
| 1313 | EG_IMAGE * egDecodePNG(IN UINT8 *FileData, IN UINTN FileDataLength, IN BOOLEAN WantAlpha) |
| 1314 | { |
| 1315 | EG_IMAGE *NewImage; |
| 1316 | PNG_INFO *info; |
| 1317 | EFI_UGA_PIXEL *Pixel; |
| 1318 | UINT8 *Data; |
| 1319 | INTN x, y; |
| 1320 | |
| 1321 | // read and check header |
| 1322 | info = PNG_decode(FileData, (UINT32)FileDataLength); |
| 1323 | if (info == NULL) { |
| 1324 | return NULL; |
| 1325 | } |
| 1326 | |
| 1327 | NewImage = egCreateImage((INTN)info->width, (INTN)info->height, WantAlpha); |
| 1328 | if (NewImage == NULL) { |
| 1329 | return NULL; |
| 1330 | } |
| 1331 | |
| 1332 | //CopyMem(NewImage->PixelData, info->image->data, info->image->size); |
| 1333 | Data = (UINT8*)info->image->data; |
| 1334 | Pixel = (EFI_UGA_PIXEL*)NewImage->PixelData; |
| 1335 | for (y = 0; y < NewImage->Height; y++) { |
| 1336 | for (x = 0; x < NewImage->Width; x++) { |
| 1337 | /* UINT8 Temp; |
| 1338 | Temp = Pixel->Blue; |
| 1339 | Pixel->Blue = Pixel->Red; |
| 1340 | Pixel->Red = Temp; */ |
| 1341 | // It seems 0 is opaque and 255 is fully transparent |
| 1342 | // Pixel->Reserved = 255 - Pixel->Reserved; */ |
| 1343 | Pixel->Red = *Data++; |
| 1344 | Pixel->Green = *Data++; |
| 1345 | Pixel->Blue = *Data++; |
| 1346 | Pixel->Reserved = 255 - *Data++; |
| 1347 | Pixel++; |
| 1348 | // PixelD++; |
| 1349 | } |
| 1350 | } |
| 1351 | png_alloc_free_all(); |
| 1352 | return NewImage; |
| 1353 | } |
| 1354 | |
| 1355 |
no test coverage detected