Path: blob/master/thirdparty/basis_universal/encoder/pvpngreader.h
9902 views
// pngreader.h - Public Domain - see unlicense at bottom of pvpngreader.cpp1#pragma once2#include <stdint.h>34namespace pv_png5{6// PNG color types7enum8{9PNG_COLOR_TYPE_GREYSCALE = 0,10PNG_COLOR_TYPE_TRUECOLOR = 2,11PNG_COLOR_TYPE_PALETTIZED = 3,12PNG_COLOR_TYPE_GREYSCALE_ALPHA = 4,13PNG_COLOR_TYPE_TRUECOLOR_ALPHA = 614};1516// PNG file description17struct png_info18{19uint32_t m_width;20uint32_t m_height;2122uint32_t m_num_chans; // The number of channels, factoring in transparency. Ranges from [1-4].2324uint32_t m_bit_depth; // PNG ihdr bit depth: 1, 2, 4, 8 or 1625uint32_t m_color_type; // PNG ihdr color type, PNG_COLOR_TYPE_GRAYSCALE etc.2627bool m_has_gamma; // true if the PNG file had a GAMA chunk28uint32_t m_gamma_value; // PNG GAMA chunk value, scaled by 1000002930bool m_has_trns; // true if the PNG file used colorkey transparency31};3233// Retrieved information about the PNG file.34// Returns false on any errors.35bool get_png_info(const void* pImage_buf, size_t buf_size, png_info& info);3637// Input parameters:38// pImage_buf, buf_size - pointer to PNG image data39// desired_chans - desired number of output channels. 0=auto, 1=grayscale, 2=grayscale alpha, 3=24bpp RGB, 4=32bpp RGBA40//41// Output parameters:42// width, height - PNG image resolution43// num_chans - actual number of channels in PNG, from [1,4] (factoring in transparency)44//45// Returns nullptr on any errors.46void* load_png(const void* pImage_buf, size_t buf_size, uint32_t desired_chans, uint32_t &width, uint32_t &height, uint32_t& num_chans);47}484950