本文整理汇总了C++中png_set_filler函数的典型用法代码示例。如果您正苦于以下问题:C++ png_set_filler函数的具体用法?C++ png_set_filler怎么用?C++ png_set_filler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了png_set_filler函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set_filler
void set_filler(uint_32 filler, filler_type type) const
{
TRACE_IO_TRANSFORM("png_set_filler: filler=%08x, type=%d\n",
filler, type);
png_set_filler(m_png, filler, type);
}
示例2: RageSurface_Save_PNG
/* Since libpng forces us to use longjmp, this function shouldn't create any C++
* objects, and needs to watch out for memleaks. */
static bool RageSurface_Save_PNG( RageFile &f, char szErrorbuf[1024], RageSurface *pImgIn )
{
bool bAlpha = pImgIn->format->Amask != 0;
RageSurface *pImg;
bool bDeleteImg = RageSurfaceUtils::ConvertSurface( pImgIn, pImg, pImgIn->w, pImgIn->h, 32,
Swap32BE( 0xFF000000 ),
Swap32BE( 0x00FF0000 ),
Swap32BE( 0x0000FF00 ),
Swap32BE( 0x000000FF ) );
if( !bDeleteImg )
pImg = pImgIn;
error_info error;
error.szErr = szErrorbuf;
png_struct *pPng = png_create_write_struct( PNG_LIBPNG_VER_STRING, &error, PNG_Error, PNG_Warning );
if( pPng == NULL )
{
sprintf( szErrorbuf, "creating png_create_write_struct failed");
return false;
}
png_info *pInfo = png_create_info_struct(pPng);
if( pInfo == NULL )
{
png_destroy_read_struct( &pPng, NULL, NULL );
if( bDeleteImg )
delete pImg;
sprintf( szErrorbuf, "creating png_create_info_struct failed");
return false;
}
if( setjmp(png_jmpbuf(pPng)) )
{
png_destroy_read_struct( &pPng, &pInfo, NULL );
return false;
}
png_set_write_fn( pPng, &f, RageFile_png_write, RageFile_png_flush );
png_set_compression_level( pPng, 1 );
png_set_IHDR( pPng, pInfo, pImg->w, pImg->h, 8, bAlpha? PNG_COLOR_TYPE_RGBA:PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE );
png_write_info( pPng, pInfo );
png_set_filler( pPng, 0, PNG_FILLER_AFTER );
png_byte *pixels = (png_byte *) pImg->pixels;
for( int y = 0; y < pImg->h; y++ )
png_write_row( pPng, pixels + pImg->pitch*y );
png_write_end( pPng, pInfo );
png_destroy_write_struct( &pPng, &pInfo );
/* Free the converted image. */
if( bDeleteImg )
delete pImg;
return true;
}
示例3: png_set_add_alpha
/* Added to libpng-1.2.7 */
void PNGAPI
png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
{
png_debug(1, "in png_set_add_alpha\n");
png_set_filler(png_ptr, filler, filler_loc);
png_ptr->transformations |= PNG_ADD_ALPHA;
}
示例4: writePNG
void writePNG(const QImage& image)
{
#ifndef QT_LSB
// LSB disallows accessing the info_ptr directly. LSB's png_set_IHDR sets
// the channels anyways, so just comment it out for LSB usage
info_ptr->channels = 4;
#endif
png_set_sig_bytes(png_ptr, 8); // Pretend we already wrote the sig
png_set_IHDR(png_ptr, info_ptr, image.width(), image.height(),
8, image.hasAlphaChannel()
? PNG_COLOR_TYPE_RGB_ALPHA : PNG_COLOR_TYPE_RGB,
0, 0, 0);
png_write_info(png_ptr, info_ptr);
if (!image.hasAlphaChannel())
png_set_filler(png_ptr, 0,
QSysInfo::ByteOrder == QSysInfo::BigEndian ?
PNG_FILLER_BEFORE : PNG_FILLER_AFTER);
//if ( QImage::systemByteOrder() == QImage::BigEndian ) {
//png_set_swap_alpha(png_ptr);
//}
if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) {
png_set_bgr(png_ptr);
}
int height = image.height();
png_bytep *row_pointers = new png_bytep[height];
for (int i = 0; i < height; ++i)
row_pointers[i] = (png_bytep)image.scanLine(i);
png_write_image(png_ptr, row_pointers);
delete [] row_pointers;
png_write_end(png_ptr, info_ptr);
end_png();
begin_png();
}
示例5: _mapcache_imageio_png_encode
/**
* \brief encode an image to RGB(A) PNG format
* \private \memberof mapcache_image_format_png
* \sa mapcache_image_format::write()
*/
mapcache_buffer* _mapcache_imageio_png_encode(mapcache_context *ctx, mapcache_image *img, mapcache_image_format *format) {
png_infop info_ptr;
int color_type;
size_t row;
mapcache_buffer *buffer = NULL;
int compression = ((mapcache_image_format_png*)format)->compression_level;
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,NULL,NULL);
if (!png_ptr) {
ctx->set_error(ctx, 500, "failed to allocate png_struct structure");
return NULL;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_write_struct(&png_ptr,
(png_infopp)NULL);
ctx->set_error(ctx, 500, "failed to allocate png_info structure");
return NULL;
}
if (setjmp(png_jmpbuf(png_ptr)))
{
ctx->set_error(ctx, 500, "failed to setjmp(png_jmpbuf(png_ptr))");
png_destroy_write_struct(&png_ptr, &info_ptr);
return NULL;
}
buffer = mapcache_buffer_create(5000,ctx->pool);
png_set_write_fn(png_ptr, buffer, _mapcache_imageio_png_write_func, _mapcache_imageio_png_flush_func);
if(mapcache_image_has_alpha(img))
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
else
color_type = PNG_COLOR_TYPE_RGB;
png_set_IHDR(png_ptr, info_ptr, img->w, img->h,
8, color_type, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
if(compression == MAPCACHE_COMPRESSION_BEST)
png_set_compression_level (png_ptr, Z_BEST_COMPRESSION);
else if(compression == MAPCACHE_COMPRESSION_FAST)
png_set_compression_level (png_ptr, Z_BEST_SPEED);
png_write_info(png_ptr, info_ptr);
if(color_type == PNG_COLOR_TYPE_RGB)
png_set_filler(png_ptr, 255, PNG_FILLER_AFTER);
png_bytep rowptr = img->data;
for(row=0;row<img->h;row++) {
png_write_row(png_ptr,rowptr);
rowptr += img->stride;
}
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, &info_ptr);
return buffer;
}
示例6: read_png_file
void read_png_file(char *filename) {
FILE *fp = fopen(filename, "rb");
png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if(!png) abort();
png_infop info = png_create_info_struct(png);
if(!info) abort();
if(setjmp(png_jmpbuf(png))) abort();
png_init_io(png, fp);
png_read_info(png, info);
width = png_get_image_width(png, info);
height = png_get_image_height(png, info);
color_type = png_get_color_type(png, info);
bit_depth = png_get_bit_depth(png, info);
// Read any color_type into 8bit depth, RGBA format.
// See http://www.libpng.org/pub/png/libpng-manual.txt
if(bit_depth == 16)
png_set_strip_16(png);
if(color_type == PNG_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb(png);
// PNG_COLOR_TYPE_GRAY_ALPHA is always 8 or 16bit depth.
if(color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
png_set_expand_gray_1_2_4_to_8(png);
if(png_get_valid(png, info, PNG_INFO_tRNS))
png_set_tRNS_to_alpha(png);
// These color_type don't have an alpha channel then fill it with 0xff.
if(color_type == PNG_COLOR_TYPE_RGB ||
color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_PALETTE)
png_set_filler(png, 0xFF, PNG_FILLER_AFTER);
if(color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png);
png_read_update_info(png, info);
row_pointers = (png_bytep*)malloc(sizeof(png_bytep) * height);
int y ;
for( y = 0; y < height; y++) {
row_pointers[y] = (png_byte*)malloc(png_get_rowbytes(png,info));
}
png_read_image(png, row_pointers);
fclose(fp);
}
示例7: nspng_setup_transforms
static void nspng_setup_transforms(png_structp png_ptr, png_infop info_ptr)
{
int bit_depth, color_type;
#if 0
int intent;
double gamma;
#endif
bit_depth = png_get_bit_depth(png_ptr, info_ptr);
color_type = png_get_color_type(png_ptr, info_ptr);
/* Set up our transformations */
if (color_type == PNG_COLOR_TYPE_PALETTE) {
png_set_palette_to_rgb(png_ptr);
}
if ((color_type == PNG_COLOR_TYPE_GRAY) && (bit_depth < 8)) {
png_set_expand_gray_1_2_4_to_8(png_ptr);
}
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
png_set_tRNS_to_alpha(png_ptr);
}
if (bit_depth == 16) {
png_set_strip_16(png_ptr);
}
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
png_set_gray_to_rgb(png_ptr);
}
if (!(color_type & PNG_COLOR_MASK_ALPHA)) {
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
}
#if 0
/* gamma correction - we use 2.2 as our screen gamma
* this appears to be correct (at least in respect to !Browse)
* see http://www.w3.org/Graphics/PNG/all_seven.html for a test case
*/
if (png_get_sRGB(png_ptr, info_ptr, &intent)) {
png_set_gamma(png_ptr, 2.2, 0.45455);
} else {
if (png_get_gAMA(png_ptr, info_ptr, &gamma)) {
png_set_gamma(png_ptr, 2.2, gamma);
} else {
png_set_gamma(png_ptr, 2.2, 0.45455);
}
}
#endif
png_read_update_info(png_ptr, info_ptr);
}
示例8: cog_frame_new_from_png
static CogFrame *
cog_frame_new_from_png (void *data, int size)
{
struct png_data_struct s = { 0 };
png_structp png_ptr;
png_infop info_ptr;
png_bytep *rows;
CogFrame *frame;
guchar *frame_data;
int j;
int width, height;
int color_type;
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
info_ptr = png_create_info_struct (png_ptr);
s.data = data;
s.size = size;
png_set_read_fn (png_ptr, (void *) &s, read_data);
png_read_info (png_ptr, info_ptr);
width = png_get_image_width (png_ptr, info_ptr);
height = png_get_image_height (png_ptr, info_ptr);
color_type = png_get_color_type (png_ptr, info_ptr);
GST_DEBUG ("PNG size %dx%d color_type %d", width, height, color_type);
png_set_strip_16 (png_ptr);
png_set_packing (png_ptr);
if (color_type == PNG_COLOR_TYPE_RGB) {
png_set_filler (png_ptr, 0xff, PNG_FILLER_BEFORE);
}
if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
png_set_swap_alpha (png_ptr);
}
frame_data = g_malloc (width * height * 4);
frame = cog_frame_new_from_data_ARGB (frame_data, width, height);
frame->regions[0] = frame_data;
rows = (png_bytep *) g_malloc (sizeof (png_bytep) * height);
for (j = 0; j < height; j++) {
rows[j] = COG_FRAME_DATA_GET_LINE (frame->components + 0, j);
}
png_read_image (png_ptr, rows);
g_free (rows);
png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp) NULL);
return frame;
}
示例9: npng_info
/**
* @brief Initializes the npng.
*/
static int npng_info( npng_t *npng )
{
png_uint_32 width, height;
int bit_depth, color_type, interlace_type;
/*double display_exponent, gamma;*/
/* Read information. */
png_read_info( npng->png_ptr, npng->info_ptr );
/* Read header stuff. */
png_get_IHDR( npng->png_ptr, npng->info_ptr, &width, &height,
&bit_depth, &color_type, &interlace_type, NULL, NULL );
/* Set Interlace handling if necessary. */
if (interlace_type != PNG_INTERLACE_NONE)
png_set_interlace_handling( npng->png_ptr );
/* Strip down from 16 bit to 8 bit. */
png_set_strip_16( npng->png_ptr );
/* Extract small bits into separate bytes. */
png_set_packing( npng->png_ptr );
/* Expand palette to RGB. */
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_expand( npng->png_ptr );
/* Expand low bit grayscale to 8 bit. */
if ((color_type == PNG_COLOR_TYPE_GRAY) && (bit_depth < 8))
png_set_expand( npng->png_ptr );
/* Expand tRNS data to alpha channel. */
if (png_get_valid( npng->png_ptr, npng->info_ptr, PNG_INFO_tRNS) )
png_set_expand( npng->png_ptr );
/* Set grayscale to 8 bits. */
if ((color_type == PNG_COLOR_TYPE_GRAY) ||
(color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
png_set_gray_to_rgb( npng->png_ptr );
/* Set gamma. */
/*if (png_get_gAMA( npng->png_ptr, info_ptr, &gamma) )
png_set_gamma( npng->png_ptr, display_exponent, gamma );*/
/* Fill alpha. */
png_set_filler( npng->png_ptr, 0xff, PNG_FILLER_AFTER );
/* Update information. */
png_read_update_info( npng->png_ptr, npng->info_ptr );
/* Success. */
return 0;
}
示例10: SavePNG
/* Since libpng forces us to use longjmp, this function shouldn't create any C++
* objects, and needs to watch out for memleaks. */
bool SavePNG( FILE *f, char szErrorbuf[1024], const Surface *pSurf )
{
/* RageSurfaceUtils::ConvertSurface( pImgIn, pImg, pImgIn->w, pImgIn->h, 32,
Swap32BE( 0xFF000000 ),
Swap32BE( 0x00FF0000 ),
Swap32BE( 0x0000FF00 ),
Swap32BE( 0x000000FF ) );
*/
error_info error;
error.szErr = szErrorbuf;
png_struct *pPng = png_create_write_struct( PNG_LIBPNG_VER_STRING, &error, PNG_Error, PNG_Warning );
if( pPng == NULL )
{
sprintf( szErrorbuf, "creating png_create_write_struct failed");
return false;
}
png_info *pInfo = png_create_info_struct(pPng);
if( pInfo == NULL )
{
png_destroy_read_struct( &pPng, NULL, NULL );
sprintf( szErrorbuf, "creating png_create_info_struct failed");
return false;
}
if( setjmp(pPng->jmpbuf) )
{
png_destroy_read_struct( &pPng, &pInfo, png_infopp_NULL );
return false;
}
png_set_write_fn( pPng, f, File_png_write, File_png_flush );
png_set_compression_level( pPng, 1 );
png_set_IHDR( pPng, pInfo, pSurf->iWidth, pSurf->iHeight, 8, PNG_COLOR_TYPE_RGBA,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE );
png_write_info( pPng, pInfo );
png_set_filler( pPng, 0, PNG_FILLER_AFTER );
png_byte *pixels = (png_byte *) pSurf->pRGBA;
for( int y = 0; y < pSurf->iHeight; y++ )
png_write_row( pPng, pixels + pSurf->iPitch*y );
png_write_end( pPng, pInfo );
png_destroy_write_struct( &pPng, &pInfo );
return true;
}
示例11: info_callback
static void
info_callback(png_structp png, png_infop info)
{
int bit_depth, color_type, interlace, intent;
double gamma;
png_uint_32 width, height;
/* Read the PNG details */
png_get_IHDR(png, info, &width, &height, &bit_depth,
&color_type, &interlace, 0, 0);
/* Set up our transformations */
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb(png);
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
png_set_expand_gray_1_2_4_to_8(png);
if (png_get_valid(png, info, PNG_INFO_tRNS))
png_set_tRNS_to_alpha(png);
if (bit_depth == 16)
png_set_strip_16(png);
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png);
if (!(color_type & PNG_COLOR_MASK_ALPHA))
png_set_filler(png, 0xff, PNG_FILLER_AFTER);
/* gamma correction - we use 2.2 as our screen gamma
* this appears to be correct (at least in respect to !Browse)
* see http://www.w3.org/Graphics/PNG/all_seven.html for a test case
*/
if (png_get_sRGB(png, info, &intent))
png_set_gamma(png, 2.2, 0.45455);
else {
if (png_get_gAMA(png, info, &gamma))
png_set_gamma(png, 2.2, gamma);
else
png_set_gamma(png, 2.2, 0.45455);
}
png_read_update_info(png, info);
rowbytes = png_get_rowbytes(png, info);
interlace = (interlace == PNG_INTERLACE_ADAM7);
raw_width = width;
raw_height = height;
rowstride = raw_width * 4;
bitmap_data = malloc(rowstride * raw_height);
}
示例12: png_write_info
bool SkPngEncoderMgr::writeInfo(const SkImageInfo& srcInfo) {
if (setjmp(png_jmpbuf(fPngPtr))) {
return false;
}
png_write_info(fPngPtr, fInfoPtr);
if (kRGBA_F16_SkColorType == srcInfo.colorType() &&
kOpaque_SkAlphaType == srcInfo.alphaType())
{
// For kOpaque, kRGBA_F16, we will keep the row as RGBA and tell libpng
// to skip the alpha channel.
png_set_filler(fPngPtr, 0, PNG_FILLER_AFTER);
}
return true;
}
示例13: _gTexLoadPNG
void _gTexLoadPNG(FILE* fp, gImage* tex)
{
png_structp png_ptr;
png_infop info_ptr;
unsigned int sig_read = 0;
png_uint_32 width, height;
int bit_depth, color_type, interlace_type, x, y;
u32* line;
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL);
png_set_error_fn(png_ptr,NULL,NULL,NULL);
info_ptr = png_create_info_struct(png_ptr);
png_init_io(png_ptr,fp);
png_set_sig_bytes(png_ptr,sig_read);
png_read_info(png_ptr,info_ptr);
png_get_IHDR(png_ptr,info_ptr,&width,&height,&bit_depth,&color_type,
&interlace_type,NULL,NULL);
png_set_strip_16(png_ptr);
png_set_packing(png_ptr);
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
png_set_gray_1_2_4_to_8(png_ptr);
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
png_set_tRNS_to_alpha(png_ptr);
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
tex->w = width;
tex->h = height;
tex->tw = _getNextPower2(width);
tex->th = _getNextPower2(height);
tex->ratio = (float)width / height;
tex->data = memalign(16, tex->tw * tex->th * sizeof(gColor));
line = malloc(width * 4);
for (y = 0; y < height; y++) {
png_read_row(png_ptr, (u8*) line, png_bytep_NULL);
for (x = 0; x < width; x++) {
u32 color = line[x];
tex->data[x + y * tex->tw] = color;
}
}
free(line);
png_read_end(png_ptr, info_ptr);
png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
}
示例14: info_callback
/* This function is called (as set by png_set_progressive_read_fn() above) when enough data has been supplied so all of the header has been read. */
void info_callback(png_structp png_ptr, png_infop info) {
file_end=0;
width = png_get_image_width(png_ptr,info);
height = png_get_image_height(png_ptr,info);
pixel_depth = png_get_bit_depth(png_ptr,info);
channels = png_get_channels(png_ptr,info);
color_type = png_get_color_type(png_ptr,info);
if(color_type == PNG_COLOR_TYPE_GRAY) {}
if(color_type == PNG_COLOR_TYPE_GRAY_ALPHA){}
if(color_type == PNG_COLOR_TYPE_RGB) {}
if(color_type == PNG_COLOR_TYPE_RGB_ALPHA) {}
if(color_type == PNG_COLOR_TYPE_PALETTE ) {
int r = png_get_PLTE(png_ptr,info,&palette,&num_palette);
if(r == 0) {
}
png_uint_16p histogram = NULL;
png_get_hIST(png_ptr, info, &histogram);
png_set_expand(png_ptr);
png_set_filler(png_ptr, 0xFF, PNG_FILLER_AFTER);
png_read_update_info(png_ptr, info);
pixel_depth = 8;
}
int row_bytes = png_get_rowbytes(png_ptr,info);
row_pointers = malloc(sizeof(png_bytep *) * height);
for(size_t n=0;n<height;n++) {
row_pointers[n] = malloc(row_bytes);
}
png_start_read_image(png_ptr);
}
示例15: LoadPNGBuffer
void LoadPNGBuffer(byte * data, byte ** pic, int *width, int *height)
{
int bit_depth;
int color_type;
png_uint_32 w;
png_uint_32 h;
unsigned int row;
size_t rowbytes;
png_infop info;
png_structp png;
png_bytep *row_pointers;
byte *out;
int size;
byte alphaByte = 255;
// load png
// size = ri.FS_ReadFile(name, (void **)&data);
if(!data)
return;
//png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
png = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp) NULL, png_user_error_fn, png_user_warning_fn);
if(!png)
{
Sys_FPrintf(SYS_WRN, "LoadPNGBuffer: png_create_write_struct() failed\n");
//free(data);
return;
}
// allocate/initialize the memory for image information. REQUIRED
info = png_create_info_struct(png);
if(!info)
{
Sys_FPrintf(SYS_WRN, "LoadPNGBuffer: png_create_info_struct() failed\n");
//free(data);
png_destroy_read_struct(&png, (png_infopp) NULL, (png_infopp) NULL);
return;
}
//
// Set error handling if you are using the setjmp/longjmp method (this is
// the normal method of doing things with libpng). REQUIRED unless you
// set up your own error handlers in the png_create_read_struct() earlier.
//
if(setjmp(png_jmpbuf(png)))
{
// if we get here, we had a problem reading the file
Sys_FPrintf(SYS_WRN, "LoadPNGBuffer: first exception handler called\n");
//free(data);
png_destroy_read_struct(&png, (png_infopp) & info, (png_infopp) NULL);
return;
}
//png_set_write_fn(png, buffer, png_write_data, png_flush_data);
png_set_read_fn(png, data, png_read_data);
png_set_sig_bytes(png, 0);
// The call to png_read_info() gives us all of the information from the
// PNG file before the first IDAT (image data chunk). REQUIRED
png_read_info(png, info);
// get picture info
png_get_IHDR(png, info, (png_uint_32 *) & w, (png_uint_32 *) & h, &bit_depth, &color_type, NULL, NULL, NULL);
// tell libpng to strip 16 bit/color files down to 8 bits/color
png_set_strip_16(png);
// expand paletted images to RGB triplets
if(color_type & PNG_COLOR_MASK_PALETTE)
png_set_expand(png);
// expand gray-scaled images to RGB triplets
if(!(color_type & PNG_COLOR_MASK_COLOR))
png_set_gray_to_rgb(png);
// expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel
//if(color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
// png_set_gray_1_2_4_to_8(png);
// expand paletted or RGB images with transparency to full alpha channels
// so the data will be available as RGBA quartets
if(png_get_valid(png, info, PNG_INFO_tRNS))
png_set_tRNS_to_alpha(png);
// if there is no alpha information, fill with alphaByte
if(!(color_type & PNG_COLOR_MASK_ALPHA))
png_set_filler(png, alphaByte, PNG_FILLER_AFTER);
// expand pictures with less than 8bpp to 8bpp
if(bit_depth < 8)
png_set_packing(png);
// update structure with the above settings
png_read_update_info(png, info);
// allocate the memory to hold the image
*width = w;
//.........这里部分代码省略.........