#pragma once12#include <cstdint>34#include "Common/BitSet.h"5#include "Common/File/Path.h"67// *image_data_ptr should be deleted with free()8// return value of 1 == success.9int pngLoad(const char *file, int *pwidth,10int *pheight, unsigned char **image_data_ptr);1112int pngLoadPtr(const unsigned char *input_ptr, size_t input_len, int *pwidth,13int *pheight, unsigned char **image_data_ptr);1415// PNG peeker - just read the start of a PNG straight into this struct, in order to16// look at basic parameters like width and height. Note that while PNG is a chunk-based17// format, the IHDR chunk is REQUIRED to be the first one, so this will work.18// Does not handle Apple's weirdo extension CgBI. http://iphonedevwiki.net/index.php/CgBI_file_format19// That should not be an issue.20struct PNGHeaderPeek {21uint32_t magic;22uint32_t ignore0;23uint32_t ignore1;24uint32_t ihdrTag;25uint32_t be_width; // big endian26uint32_t be_height;27uint8_t bitDepth; // bits per channel, can be 1, 2, 4, 8, 1628uint8_t colorType; // really, pixel format. 0 = grayscale, 2 = rgb, 3 = palette index, 4 = gray+alpha, 6 = rgba2930bool IsValidPNGHeader() const;31int Width() const { return swap32(be_width); }32int Height() const { return swap32(be_height); }33};3435bool pngSave(const Path &filename, const void *buffer, int w, int h, int bytesPerPixel);363738