1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-09-18 23:14:50 +00:00
QB64-PE/internal/c/parts/video/image/decode/png/src.c
2022-05-06 13:20:30 -04:00

41 lines
No EOL
999 B
C

#ifdef QB64_BACKSLASH_FILESYSTEM
# include "src\\lodepng.cpp"
#else
# include "src/lodepng.cpp"
#endif
uint8 *image_decode_png(uint8 *content, int32 bytes, int32 *result, int32 *x, int32 *y) {
// Result:bit 1=Success,bit 2=32bit[BGRA]
*result = 0;
static unsigned char *png;
static unsigned width, height;
if (lodepng_decode32(&png, &width, &height, (unsigned char *)content, bytes))
return NULL; // RGBA
static uint8 *si;
si = (uint8 *)png;
static int32 w, h;
w = width;
h = height;
static uint8 *di;
di = (uint8 *)malloc(w * h * 4);
// RGBA->BGRA
static int32 c;
c = w * h;
while (c--) {
di[c * 4 + 2] = si[c * 4]; // red
di[c * 4 + 1] = si[c * 4 + 1]; // green
di[c * 4] = si[c * 4 + 2]; // blue
di[c * 4 + 3] = si[c * 4 + 3]; // alpha
}
// Cleanup
free(si);
*result = 1 + 2;
*x = w;
*y = h;
return di;
}