void LoadPng(const char *path) { PngT *png = PngLoadFromFile(path); if (png) { PixBufT *pixbuf; int16_t type; puts("IHDR:"); printf(" width : %d\n", png->ihdr.width); printf(" height : %d\n", png->ihdr.height); printf(" bit depth : %d\n", png->ihdr.bit_depth); printf(" color type : "); if (png->ihdr.colour_type == PNG_GRAYSCALE) { type = PIXBUF_GRAY; puts("gray scale"); } else if (png->ihdr.colour_type == PNG_TRUECOLOR) { type = PIXBUF_RGB; puts("true color"); } else if (png->ihdr.colour_type == PNG_INDEXED) { type = PIXBUF_CLUT; puts("indexed color"); } else if (png->ihdr.colour_type == PNG_GRAYSCALE_ALPHA) { type = PIXBUF_GRAY; puts("gray scale (with alpha)"); } else { type = PIXBUF_RGBA; puts("true color (with alpha)"); } printf(" interlace : %s\n", png->ihdr.interlace_method ? "yes" : "no"); if (png->plte.no_colors) { puts("PLTE:"); printf(" colors : %d\n", png->plte.no_colors); } if (png->trns) { puts("tRNS:"); if (png->ihdr.colour_type == PNG_INDEXED) printf(" color : %d\n", png->trns->type3.alpha[0]); } pixbuf = NewPixBuf(type, png->ihdr.width, png->ihdr.height); PngDecodeImage(png, pixbuf); MemUnref(pixbuf); } puts(""); MemUnref(png); }
static PixBufT *PngToPixBuf(PngT *png) { PixBufT *pixbuf = NULL; if (png->ihdr.bit_depth == 8) { int16_t type; switch (png->ihdr.colour_type) { case PNG_GRAYSCALE: type = PIXBUF_GRAY; break; case PNG_INDEXED: type = PIXBUF_CLUT; break; default: type = -1; break; } if (type >= 0) { pixbuf = NewPixBuf(type, png->ihdr.width, png->ihdr.height); if (!PngDecodeImage(png, pixbuf)) { MemUnref(pixbuf); pixbuf = NULL; } else { PixBufCalculateHistogram(pixbuf); LOG("The image has %d (%d..%d) colors.", (int)pixbuf->lastColor - (int)pixbuf->baseColor + 1, pixbuf->baseColor, pixbuf->lastColor); if (png->trns) { pixbuf->mode = BLIT_TRANSPARENT; pixbuf->baseColor = png->trns->type3.alpha[0]; LOG("The image is transparent (color = %d).", pixbuf->baseColor); } } } } return pixbuf; }