本文整理汇总了C++中png_set_expand函数的典型用法代码示例。如果您正苦于以下问题:C++ png_set_expand函数的具体用法?C++ png_set_expand怎么用?C++ png_set_expand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了png_set_expand函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: destroy
bool PNGDecoder::loadStream(Common::SeekableReadStream &stream) {
#ifdef USE_PNG
destroy();
_stream = &stream;
// First, check the PNG signature
if (_stream->readUint32BE() != MKTAG(0x89, 'P', 'N', 'G')) {
delete _stream;
return false;
}
if (_stream->readUint32BE() != MKTAG(0x0d, 0x0a, 0x1a, 0x0a)) {
delete _stream;
return false;
}
// The following is based on the guide provided in:
//http://www.libpng.org/pub/png/libpng-1.2.5-manual.html#section-3
//http://www.libpng.org/pub/png/libpng-1.4.0-manual.pdf
// along with the png-loading code used in the sword25-engine.
png_structp pngPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!pngPtr) {
delete _stream;
return false;
}
png_infop infoPtr = png_create_info_struct(pngPtr);
if (!infoPtr) {
png_destroy_read_struct(&pngPtr, NULL, NULL);
delete _stream;
return false;
}
png_infop endInfo = png_create_info_struct(pngPtr);
if (!endInfo) {
png_destroy_read_struct(&pngPtr, &infoPtr, NULL);
delete _stream;
return false;
}
png_set_error_fn(pngPtr, NULL, pngError, pngWarning);
// TODO: The manual says errors should be handled via setjmp
png_set_read_fn(pngPtr, _stream, pngReadFromStream);
png_set_crc_action(pngPtr, PNG_CRC_DEFAULT, PNG_CRC_WARN_USE);
// We already verified the PNG-header
png_set_sig_bytes(pngPtr, 8);
// Read PNG header
png_read_info(pngPtr, infoPtr);
// No handling for unknown chunks yet.
int bitDepth, colorType, width, height, interlaceType;
png_uint_32 w, h;
png_get_IHDR(pngPtr, infoPtr, &w, &h, &bitDepth, &colorType, &interlaceType, NULL, NULL);
width = w;
height = h;
// Allocate memory for the final image data.
// To keep memory framentation low this happens before allocating memory for temporary image data.
_outputSurface = new Graphics::Surface();
// Images of all color formats except PNG_COLOR_TYPE_PALETTE
// will be transformed into ARGB images
if (colorType == PNG_COLOR_TYPE_PALETTE && !png_get_valid(pngPtr, infoPtr, PNG_INFO_tRNS)) {
int numPalette = 0;
png_colorp palette = NULL;
uint32 success = png_get_PLTE(pngPtr, infoPtr, &palette, &numPalette);
if (success != PNG_INFO_PLTE) {
png_destroy_read_struct(&pngPtr, &infoPtr, NULL);
return false;
}
_paletteColorCount = numPalette;
_palette = new byte[_paletteColorCount * 3];
for (int i = 0; i < _paletteColorCount; i++) {
_palette[(i * 3)] = palette[i].red;
_palette[(i * 3) + 1] = palette[i].green;
_palette[(i * 3) + 2] = palette[i].blue;
}
_outputSurface->create(width, height, Graphics::PixelFormat::createFormatCLUT8());
png_set_packing(pngPtr);
} else {
bool isAlpha = (colorType & PNG_COLOR_MASK_ALPHA);
if (png_get_valid(pngPtr, infoPtr, PNG_INFO_tRNS)) {
isAlpha = true;
png_set_expand(pngPtr);
}
_outputSurface->create(width, height, Graphics::PixelFormat(4,
8, 8, 8, isAlpha ? 8 : 0, 24, 16, 8, 0));
if (!_outputSurface->getPixels()) {
error("Could not allocate memory for output image.");
}
if (bitDepth == 16)
png_set_strip_16(pngPtr);
if (bitDepth < 8)
png_set_expand(pngPtr);
if (colorType == PNG_COLOR_TYPE_GRAY ||
colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(pngPtr);
// PNGs are Big-Endian:
//.........这里部分代码省略.........
开发者ID:dergunov,项目名称:scummvm,代码行数:101,代码来源:png.cpp
示例2: png_read_png
void PNGAPI
png_read_png(png_structp png_ptr, png_infop info_ptr,
int transforms,
voidp params)
{
int row;
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
/* invert the alpha channel from opacity to transparency */
if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
png_set_invert_alpha(png_ptr);
#endif
/* The call to png_read_info() gives us all of the information from the
* PNG file before the first IDAT (image data chunk).
*/
png_read_info(png_ptr, info_ptr);
if (info_ptr->height > PNG_UINT_32_MAX/sizeof(png_bytep))
png_error(png_ptr,"Image is too high to process with png_read_png()");
/* -------------- image transformations start here ------------------- */
#if defined(PNG_READ_16_TO_8_SUPPORTED)
/* tell libpng to strip 16 bit/color files down to 8 bits/color */
if (transforms & PNG_TRANSFORM_STRIP_16)
png_set_strip_16(png_ptr);
#endif
#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
/* Strip alpha bytes from the input data without combining with the
* background (not recommended).
*/
if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
png_set_strip_alpha(png_ptr);
#endif
#if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
/* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
* byte into separate bytes (useful for paletted and grayscale images).
*/
if (transforms & PNG_TRANSFORM_PACKING)
png_set_packing(png_ptr);
#endif
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
/* Change the order of packed pixels to least significant bit first
* (not useful if you are using png_set_packing). */
if (transforms & PNG_TRANSFORM_PACKSWAP)
png_set_packswap(png_ptr);
#endif
#if defined(PNG_READ_EXPAND_SUPPORTED)
/* Expand paletted colors into true RGB triplets
* Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel
* Expand paletted or RGB images with transparency to full alpha
* channels so the data will be available as RGBA quartets.
*/
if (transforms & PNG_TRANSFORM_EXPAND)
if ((png_ptr->bit_depth < 8) ||
(png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
(png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
png_set_expand(png_ptr);
#endif
/* We don't handle background color or gamma transformation or dithering. */
#if defined(PNG_READ_INVERT_SUPPORTED)
/* invert monochrome files to have 0 as white and 1 as black */
if (transforms & PNG_TRANSFORM_INVERT_MONO)
png_set_invert_mono(png_ptr);
#endif
#if defined(PNG_READ_SHIFT_SUPPORTED)
/* If you want to shift the pixel values from the range [0,255] or
* [0,65535] to the original [0,7] or [0,31], or whatever range the
* colors were originally in:
*/
if ((transforms & PNG_TRANSFORM_SHIFT)
&& png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
{
png_color_8p sig_bit;
png_get_sBIT(png_ptr, info_ptr, &sig_bit);
png_set_shift(png_ptr, sig_bit);
}
#endif
#if defined(PNG_READ_BGR_SUPPORTED)
/* flip the RGB pixels to BGR (or RGBA to BGRA) */
if (transforms & PNG_TRANSFORM_BGR)
png_set_bgr(png_ptr);
#endif
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
/* swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
png_set_swap_alpha(png_ptr);
#endif
//.........这里部分代码省略.........
开发者ID:Miguel-J,项目名称:eneboo-core,代码行数:101,代码来源:pngread.c
示例3: Exception
void __fastcall TPngDecoder::Init(){
pfFile=fopen(FFileName.c_str(),"rb");
if(!pfFile)
throw Exception ( "Can't open file" );
// first check the eight byte PNG signature
fread(pbSig, 1, 8, pfFile);
if (!png_check_sig(pbSig, 8))
throw Exception ( "Bad file format" );
// create the two png(-info) structures
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,
NULL, NULL);
if (!png_ptr)
throw Exception( "Not enough memory" );
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_read_struct(&png_ptr, NULL, NULL);
throw Exception( "Not enough memory" );
}
/*точка возврата после обработки ошибки или предупреждения*/
if (setjmp(png_jmpbuf(png_ptr)))
{
// awp_res=*((long*)png_ptr->error_ptr);
if(row_pointers){
for (i = 0; i < FNumScanLines; i++){
if(row_pointers[i])
free(row_pointers[i]);
}
free(row_pointers);
}
png_destroy_read_struct(&png_ptr, &info_ptr,NULL);
if(pfFile) fclose(pfFile);
throw Exception( "" );;
}
// initialize the input png file
png_init_io(png_ptr, pfFile);
//8 байт сигнатуры уже прочитанно
png_set_sig_bytes(png_ptr, 8);
/* 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_ptr, info_ptr);
unsigned long width, hight;
png_get_IHDR(png_ptr, info_ptr, &width, &hight, &iBitDepth, &iColorType,
NULL, NULL, NULL);
FWidth = width;
FNumScanLines = hight;
/**** Set up the data transformations you want. Note that these are all
**** optional. Only call them if you want/need them. Many of the
**** transformations only work on specific types of images, and many
**** are mutually exclusive.
****/
/* tell libpng to strip 16 bit/color files down to 8 bits/color */
//может это не нужно?
if (iBitDepth == 16)
png_set_strip_16(png_ptr);
if (iBitDepth < 8)
png_set_expand(png_ptr);
/* Expand paletted colors into true RGB triplets */
if (iColorType == PNG_COLOR_TYPE_PALETTE)
png_set_expand(png_ptr);
/* 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_ptr, info_ptr, PNG_INFO_tRNS))
png_set_expand(png_ptr);
/* tell libpng convert grayscale images to true rgd */
if (iColorType == PNG_COLOR_TYPE_GRAY||
iColorType == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr);
/*remove alpha channel instead combine with background*/
if (iColorType & PNG_COLOR_MASK_ALPHA)
png_set_strip_alpha(png_ptr);
/* Set the background color to draw transparent and alpha images over.
* It is possible to set the red, green, and blue components directly
* for paletted images instead of supplying a palette index. Note that
* even if the PNG file supplies a background, you are not required to
* use it - you should use the (solid) application background if it has one.
*/
// set the background color to draw transparent and alpha images over.
if (png_get_bKGD(png_ptr, info_ptr, &pBackground))
png_set_background(png_ptr, pBackground, PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
/* flip the RGB pixels to BGR (or RGBA to BGRA) */
if (iColorType & PNG_COLOR_MASK_COLOR)
png_set_bgr(png_ptr);
//.........这里部分代码省略.........
开发者ID:telnykha,项目名称:VideoA,代码行数:101,代码来源:pnglibio.cpp
示例4: LoadPNG
void LoadPNG(const char *name, byte ** pic, int *width, int *height, byte alphaByte)
{
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 *data;
byte *out;
int size;
// 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)
{
ri.Printf(PRINT_WARNING, "LoadPNG: png_create_write_struct() failed for (%s)\n", name);
ri.FS_FreeFile(data);
return;
}
// allocate/initialize the memory for image information. REQUIRED
info = png_create_info_struct(png);
if(!info)
{
ri.Printf(PRINT_WARNING, "LoadPNG: png_create_info_struct() failed for (%s)\n", name);
ri.FS_FreeFile(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 common 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
ri.Printf(PRINT_WARNING, "LoadPNG: first exception handler called for (%s)\n", name);
ri.FS_FreeFile(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;
//.........这里部分代码省略.........
开发者ID:otty,项目名称:cake3,代码行数:101,代码来源:tr_image_png.c
示例5: png_create_read_struct
bool vtImage::_ReadPNG(const char *filename)
{
FILE *fp = NULL;
uchar header[8];
png_structp png;
png_infop info;
png_infop endinfo;
png_bytep *row_p;
png_uint_32 width, height;
int depth, color;
png_uint_32 i;
png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png)
{
// We compiled against the headers of one version of libpng, but
// linked against the libraries from another version. If you get
// this, fix the paths in your development environment.
return false;
}
info = png_create_info_struct(png);
endinfo = png_create_info_struct(png);
fp = vtFileOpen(filename, "rb");
if (fp && fread(header, 1, 8, fp) && png_check_sig(header, 8))
png_init_io(png, fp);
else
{
png_destroy_read_struct(&png, &info, &endinfo);
return false;
}
png_set_sig_bytes(png, 8);
png_read_info(png, info);
png_get_IHDR(png, info, &width, &height, &depth, &color, NULL, NULL, NULL);
if (color == PNG_COLOR_TYPE_GRAY || color == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png);
// never strip alpha
// {
// png_set_strip_alpha(png);
// color &= ~PNG_COLOR_MASK_ALPHA;
// }
// Always expand paletted images
if (color == PNG_COLOR_TYPE_PALETTE)
png_set_expand(png);
/*--GAMMA--*/
// checkForGammaEnv();
double screenGamma = 2.2 / 1.0;
#if 0
// Getting the gamma from the PNG file is disabled here, since
// PhotoShop writes bizarre gamma values like .227 (PhotoShop 5.0)
// or .45 (newer versions)
double fileGamma;
if (png_get_gAMA(png, info, &fileGamma))
png_set_gamma(png, screenGamma, fileGamma);
else
#endif
png_set_gamma(png, screenGamma, 1.0/2.2);
png_read_update_info(png, info);
m_pPngData = (png_bytep) malloc(png_get_rowbytes(png, info)*height);
row_p = (png_bytep *) malloc(sizeof(png_bytep)*height);
bool StandardOrientation = true;
for (i = 0; i < height; i++) {
if (StandardOrientation)
row_p[height - 1 - i] = &m_pPngData[png_get_rowbytes(png, info)*i];
else
row_p[i] = &m_pPngData[png_get_rowbytes(png, info)*i];
}
png_read_image(png, row_p);
free(row_p);
int iBitCount;
switch (color)
{
case PNG_COLOR_TYPE_GRAY:
case PNG_COLOR_TYPE_RGB:
case PNG_COLOR_TYPE_PALETTE:
iBitCount = 24;
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
case PNG_COLOR_TYPE_RGB_ALPHA:
iBitCount = 32;
break;
default:
return false;
}
//.........这里部分代码省略.........
开发者ID:kalwalt,项目名称:ofxVTerrain,代码行数:101,代码来源:ImageOSG.cpp
示例6: _load_image_RGBA_png
static unsigned char* _load_image_RGBA_png(const char *fileName, int *width, int *height)
{
// open the file
FILE *fp = fopen(fileName, "rb");
if (!fp)
return _load_img_error(width, height);
// read the header
const size_t HEADER_LENGTH = 8;
png_byte header[HEADER_LENGTH];
size_t n = fread(header, 1, HEADER_LENGTH, fp);
if (n != HEADER_LENGTH || png_sig_cmp(header, 0, HEADER_LENGTH))
return _load_img_error(width, height);
// try to create the loading structures
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0,
0);
if (!png_ptr) {
fclose(fp);
return _load_img_error(width, height);
}
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_read_struct(&png_ptr, (png_infopp) 0, (png_infopp) 0);
fclose(fp);
return _load_img_error(width, height);
}
png_infop end_info = png_create_info_struct(png_ptr);
if (!end_info) {
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)0);
fclose(fp);
return _load_img_error(width, height);
}
if (setjmp(png_ptr->jmpbuf)) {
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
fclose(fp);
return _load_img_error(width, height);
}
// start the io
png_init_io(png_ptr, fp);
// indicate that we have already read some of the hearder
png_set_sig_bytes(png_ptr, HEADER_LENGTH);
// read the image info, get some info
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);
int bit_depth = png_get_bit_depth(png_ptr, info_ptr);
png_byte color_type = png_get_color_type(png_ptr, info_ptr);
// force the image into RGBA, 8 bits per channel
if (color_type != PNG_COLOR_TYPE_RGBA)
png_set_expand(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr);
if (bit_depth < 8)
png_set_packing(png_ptr);
else if (bit_depth == 16)
png_set_strip_16(png_ptr);
if (color_type != PNG_COLOR_TYPE_RGBA)
png_set_filler(png_ptr, 255, PNG_FILLER_AFTER);
png_read_update_info(png_ptr, info_ptr);
// make sure we're actually in rgba mode
if ((int)png_get_rowbytes(png_ptr, info_ptr) != ((*width) * 4)) {
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
fclose(fp);
return _load_img_error(width, height);
}
// finally, read the file
unsigned char *buffer = (unsigned char *) malloc((*width) * (*height) * 4);
png_bytep *row_pointers = new png_bytep[*height];
for (int y = 0 ; y < (*height) ; y++) {
row_pointers[y] = (png_byte *) (buffer + ((*height) - 1 - y) *
(*width) * 4);
}
png_read_rows(png_ptr, row_pointers, 0, (long unsigned int) (*height));
// deallocate memory and return
fclose(fp);
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return buffer;
}
开发者ID:dtbinh,项目名称:AnimViewer,代码行数:90,代码来源:imageio.cpp
示例7: png_create_read_struct
bool GR_Win32Image::_convertFromPNG(const UT_ByteBuf* pBB, UT_sint32 iDisplayWidth, UT_sint32 iDisplayHeight)
{
png_structp png_ptr;
png_infop info_ptr;
png_uint_32 width, height;
int bit_depth, color_type, interlace_type;
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (void*) NULL,
NULL, NULL);
if (png_ptr == NULL)
{
return false;
}
/* Allocate/initialize the memory for image information. REQUIRED. */
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
{
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
return false;
}
/* 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_ptr)))
{
/* Free all of the memory associated with the png_ptr and info_ptr */
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
/* If we get here, we had a problem reading the file */
return false;
}
struct _bb myBB;
myBB.pBB = pBB;
myBB.iCurPos = 0;
png_set_read_fn(png_ptr, (void *)&myBB, _png_read);
/* 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_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
&interlace_type, NULL, NULL);
/* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
* byte into separate bytes (useful for paletted and grayscale images).
*/
png_set_packing(png_ptr);
/* Expand paletted colors into true RGB triplets */
png_set_expand(png_ptr);
/* If we've got images with 16 bits per channel, we don't need that
much precision. We'll do fine with 8 bits per channel */
png_set_strip_16(png_ptr);
/* For simplicity, treat grayscale as RGB */
png_set_gray_to_rgb(png_ptr);
/* For simplicity, we'll ignore alpha */
png_set_strip_alpha(png_ptr);
/* We want libpng to deinterlace the image for us */
UT_uint32 iInterlacePasses = png_set_interlace_handling(png_ptr);
/* flip the RGB pixels to BGR (or RGBA to BGRA) */
png_set_bgr(png_ptr);
UT_uint32 iBytesInRow = width * 3;
if (iBytesInRow % 4)
{
iBytesInRow += (4 - (iBytesInRow % 4));
}
m_pDIB = (BITMAPINFO*) g_try_malloc(sizeof(BITMAPINFOHEADER) + height * iBytesInRow);
if (!m_pDIB)
{
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
return false;
}
/*
Note that we do NOT create a DIB of iDisplayWidth,iDisplayHeight, since
DIBs can be stretched automatically by the Win32 API. So we simply remember
the display size for drawing later.
*/
setDisplaySize(iDisplayWidth, iDisplayHeight);
m_pDIB->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
m_pDIB->bmiHeader.biWidth = width;
m_pDIB->bmiHeader.biHeight = height;
m_pDIB->bmiHeader.biPlanes = 1;
m_pDIB->bmiHeader.biBitCount = 24;
//.........这里部分代码省略.........
开发者ID:hfiguiere,项目名称:abiword,代码行数:101,代码来源:gr_Win32Image.cpp
示例8: readPng
void readPng(GImage* pImage, const unsigned char* pData, size_t nDataSize)
{
// Check for the PNG signature
if(nDataSize < 8 || png_sig_cmp((png_bytep)pData, 0, 8) != 0)
throw Ex("not a png file");
// Read all PNG data up until the image data chunk.
GPNGReader reader(pData);
png_set_read_fn(reader.m_pReadStruct, (png_voidp)&reader, (png_rw_ptr)readFunc);
png_read_info(reader.m_pReadStruct, reader.m_pInfoStruct);
// Get the image data
int depth, color;
png_uint_32 width, height;
png_get_IHDR(reader.m_pReadStruct, reader.m_pInfoStruct, &width, &height, &depth, &color, NULL, NULL, NULL);
if(depth != 8)
throw Ex("unexpected depth");
pImage->resize(width, height);
// Set gamma correction
double dGamma;
if (png_get_gAMA(reader.m_pReadStruct, reader.m_pInfoStruct, &dGamma))
png_set_gamma(reader.m_pReadStruct, 2.2, dGamma);
else
png_set_gamma(reader.m_pReadStruct, 2.2, 1.0 / 2.2); // 1.0 = viewing gamma, 2.2 = screen gamma
// Update the 'info' struct with the gamma information
png_read_update_info(reader.m_pReadStruct, reader.m_pInfoStruct);
// Tell it to expand palettes to full channels
png_set_expand(reader.m_pReadStruct);
png_set_gray_to_rgb(reader.m_pReadStruct);
// Allocate the row pointers
unsigned long rowbytes = png_get_rowbytes(reader.m_pReadStruct, reader.m_pInfoStruct);
unsigned long channels = rowbytes / width;
png_bytep pRawData = (png_bytep)new unsigned char[rowbytes * height];
unsigned int i;
{
png_bytep* pRows = (png_bytep*)new unsigned char[sizeof(png_bytep) * height];
for(i = 0; i < height; i++)
pRows[i] = pRawData + i * rowbytes;
png_read_image(reader.m_pReadStruct, pRows);
delete[] pRows;
}
// Copy to the GImage
unsigned long nPixels = width * height;
unsigned int* pRGBQuads = pImage->m_pPixels;
unsigned char *pBytes = pRawData;
if(channels > 3)
{
if(channels != 4)
throw Ex("Unexpected number of channels");
for(i = 0; i < nPixels; i++)
{
*pRGBQuads = gARGB(pBytes[3], pBytes[0], pBytes[1], pBytes[2]);
pBytes += channels;
pRGBQuads++;
}
}
else if(channels == 3)
{
for(i = 0; i < nPixels; i++)
{
*pRGBQuads = gARGB(0xff, pBytes[0], pBytes[1], pBytes[2]);
pBytes += channels;
pRGBQuads++;
}
}
else
{
delete[] pRawData;
throw Ex("Sorry, loading ", to_str(channels), "-channel png files is not yet supported");
}
delete[] pRawData;
// Check for additional tags
png_read_end(reader.m_pReadStruct, reader.m_pEndInfoStruct);
}
开发者ID:admonkey,项目名称:snappybird,代码行数:80,代码来源:image.cpp
示例9: png_create_read_struct
SDL_Surface *TCOD_sys_read_png(const char *filename) {
png_uint_32 png_width,png_height,y;
int png_bit_depth,png_color_type,png_interlace_type;
png_structp png_ptr;
png_infop info_ptr;
FILE *fp;
SDL_Surface *bitmap;
png_bytep *row_pointers;
if ((fp = fopen(filename, "rb")) == NULL)
return NULL;
/* Create and initialize the png_struct with the desired error handler
* functions. If you want to use the default stderr and longjump method,
* you can supply NULL for the last three parameters. We also supply the
* the compiler header file version, so that we know if the application
* was compiled with a compatible version of the library. REQUIRED
*/
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,NULL, NULL, NULL);
if (png_ptr == NULL)
{
fclose(fp);
return NULL;
}
/* Allocate/initialize the memory for image information. REQUIRED. */
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
{
fclose(fp);
png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
return NULL;
}
/* 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_ptr)))
{
/* Free all of the memory associated with the png_ptr and info_ptr */
png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
fclose(fp);
/* If we get here, we had a problem reading the file */
return NULL;
}
png_init_io(png_ptr, fp);
/*
* If you have enough memory to read in the entire image at once,
* and you need to specify only transforms that can be controlled
* with one of the PNG_TRANSFORM_* bits (this presently excludes
* dithering, filling, setting background, and doing gamma
* adjustment), then you can read the entire image (including
* pixels) into the info structure with this call:
*/
//png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, png_voidp_NULL);
// get info about the image
png_read_info(png_ptr,info_ptr);
png_get_IHDR(png_ptr,info_ptr,&png_width,&png_height,&png_bit_depth,&png_color_type,
&png_interlace_type,NULL,NULL);
// convert the image to a format suitable with libtcod
png_set_strip_16(png_ptr); // 16 bits channels => 8 bits channels
png_set_packing(png_ptr); // 1,2,4 bits depth => 24/32 bits depth
if ( png_color_type == PNG_COLOR_TYPE_GRAY ) png_set_expand(png_ptr); // grayscale => color
if ( png_color_type == PNG_COLOR_TYPE_GRAY_ALPHA ) png_set_gray_to_rgb(png_ptr);
// update the image information
png_read_update_info(png_ptr,info_ptr);
png_get_IHDR(png_ptr,info_ptr,&png_width,&png_height,&png_bit_depth,&png_color_type,
&png_interlace_type,NULL,NULL);
// create the SDL surface
bitmap=TCOD_sys_get_surface(png_width,png_height,info_ptr->channels == 4);
// get row data
row_pointers=(png_bytep *)malloc(sizeof(png_bytep)*png_height);
for (y=0; y< png_height; y++ ) {
row_pointers[y]=(png_bytep)(Uint8 *)(bitmap->pixels) + y * bitmap->pitch;
}
// read png data directly into the SDL surface
png_read_image(png_ptr,row_pointers);
/* clean up after the read, and free any memory allocated - REQUIRED */
png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
free(row_pointers);
/* close the file */
fclose(fp);
return bitmap;
}
开发者ID:dennisferron,项目名称:libtcodHello,代码行数:96,代码来源:sys_sdl_img_png.c
示例10: png_get_image_width
void PNGImageDecoder::headerAvailable()
{
png_structp png = m_reader->pngPtr();
png_infop info = m_reader->infoPtr();
png_uint_32 width = png_get_image_width(png, info);
png_uint_32 height = png_get_image_height(png, info);
// Protect against large PNGs. See http://bugzil.la/251381 for more details.
const unsigned long maxPNGSize = 1000000UL;
if (width > maxPNGSize || height > maxPNGSize) {
longjmp(JMPBUF(png), 1);
return;
}
// Set the image size now that the image header is available.
if (!setSize(width, height)) {
longjmp(JMPBUF(png), 1);
return;
}
int bitDepth, colorType, interlaceType, compressionType, filterType, channels;
png_get_IHDR(png, info, &width, &height, &bitDepth, &colorType, &interlaceType, &compressionType, &filterType);
// The options we set here match what Mozilla does.
// Expand to ensure we use 24-bit for RGB and 32-bit for RGBA.
if (colorType == PNG_COLOR_TYPE_PALETTE || (colorType == PNG_COLOR_TYPE_GRAY && bitDepth < 8))
png_set_expand(png);
png_bytep trns = 0;
int trnsCount = 0;
if (png_get_valid(png, info, PNG_INFO_tRNS)) {
png_get_tRNS(png, info, &trns, &trnsCount, 0);
png_set_expand(png);
}
if (bitDepth == 16)
png_set_strip_16(png);
if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png);
#if USE(QCMSLIB)
if ((colorType & PNG_COLOR_MASK_COLOR) && !m_ignoreGammaAndColorProfile) {
// We only support color profiles for color PALETTE and RGB[A] PNG. Supporting
// color profiles for gray-scale images is slightly tricky, at least using the
// CoreGraphics ICC library, because we expand gray-scale images to RGB but we
// do not similarly transform the color profile. We'd either need to transform
// the color profile or we'd need to decode into a gray-scale image buffer and
// hand that to CoreGraphics.
bool sRGB = false;
ColorProfile colorProfile;
getColorProfile(png, info, colorProfile, sRGB);
bool imageHasAlpha = (colorType & PNG_COLOR_MASK_ALPHA) || trnsCount;
m_reader->createColorTransform(colorProfile, imageHasAlpha, sRGB);
m_hasColorProfile = !!m_reader->colorTransform();
}
#endif
if (!m_hasColorProfile) {
// Deal with gamma and keep it under our control.
const double inverseGamma = 0.45455;
const double defaultGamma = 2.2;
double gamma;
if (!m_ignoreGammaAndColorProfile && png_get_gAMA(png, info, &gamma)) {
const double maxGamma = 21474.83;
if ((gamma <= 0.0) || (gamma > maxGamma)) {
gamma = inverseGamma;
png_set_gAMA(png, info, gamma);
}
png_set_gamma(png, defaultGamma, gamma);
} else {
png_set_gamma(png, defaultGamma, inverseGamma);
}
}
// Tell libpng to send us rows for interlaced pngs.
if (interlaceType == PNG_INTERLACE_ADAM7)
png_set_interlace_handling(png);
// Update our info now.
png_read_update_info(png, info);
channels = png_get_channels(png, info);
ASSERT(channels == 3 || channels == 4);
m_reader->setHasAlpha(channels == 4);
if (m_reader->decodingSizeOnly()) {
// If we only needed the size, halt the reader.
#if PNG_LIBPNG_VER_MAJOR > 1 || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR >= 5)
// '0' argument to png_process_data_pause means: Do not cache unprocessed data.
m_reader->setReadOffset(m_reader->currentBufferSize() - png_process_data_pause(png, 0));
#else
m_reader->setReadOffset(m_reader->currentBufferSize() - png->buffer_size);
png->buffer_size = 0;
#endif
}
}
开发者ID:dstockwell,项目名称:blink,代码行数:98,代码来源:PNGImageDecoder.cpp
示例11: png_get_image_height
bool ossimPngReader::initReader()
{
bool result = true;
ossim_uint32 height = png_get_image_height(m_pngReadPtr, m_pngReadInfoPtr);
ossim_uint32 width = png_get_image_width(m_pngReadPtr, m_pngReadInfoPtr);
m_bitDepth = png_get_bit_depth(m_pngReadPtr, m_pngReadInfoPtr);
m_pngColorType = png_get_color_type(m_pngReadPtr, m_pngReadInfoPtr);
m_imageRect = ossimIrect(0, 0, width - 1, height - 1);
if (m_bitDepth == 16)
{
// png_set_strip_16 (m_pngReadPtr);
m_bytePerPixelPerBand = 2;
m_outputScalarType = OSSIM_UINT16;
}
else
{
m_bytePerPixelPerBand = 1;
}
// Set the read mode from scalar and color type.
if (m_outputScalarType == OSSIM_UINT8)
{
if ( (m_pngColorType == PNG_COLOR_TYPE_RGB_ALPHA) ||
(m_pngColorType == PNG_COLOR_TYPE_GRAY_ALPHA) )
{
m_readMode = ossimPngRead8a;
}
else
{
m_readMode = ossimPngRead8;
}
}
else
{
if ( (m_pngColorType == PNG_COLOR_TYPE_RGB_ALPHA) ||
(m_pngColorType == PNG_COLOR_TYPE_GRAY_ALPHA) )
{
m_readMode = ossimPngRead16a;
}
else
{
m_readMode = ossimPngRead16;
}
// Set the swap flag. PNG stores data in network byte order(big endian).
if(ossim::byteOrder() == OSSIM_LITTLE_ENDIAN)
{
m_swapFlag = true;
}
}
//---
// If png_set_expand used:
// Expand data to 24-bit RGB, or 8-bit grayscale,
// with alpha if available.
//---
bool expandFlag = false;
if ( m_pngColorType == PNG_COLOR_TYPE_PALETTE )
{
expandFlag = true;
}
if ( (m_pngColorType == PNG_COLOR_TYPE_GRAY) && (m_bitDepth < 8) )
{
expandFlag = true;
}
if ( png_get_valid(m_pngReadPtr, m_pngReadInfoPtr, PNG_INFO_tRNS) )
{
expandFlag = true;
}
//---
// If png_set_packing used:
// Use 1 byte per pixel in 1, 2, or 4-bit depth files. */
//---
bool packingFlag = false;
if ( (m_bitDepth < 8) && (m_pngColorType == PNG_COLOR_TYPE_GRAY) )
{
packingFlag = true;
}
if (expandFlag)
{
png_set_expand(m_pngReadPtr);
}
if (packingFlag)
{
png_set_packing(m_pngReadPtr);
}
// Gamma correction.
// ossim_float64 gamma;
// if (png_get_gAMA(m_pngReadPtr, m_pngReadInfoPtr, &gamma))
// {
// png_set_gamma(png_ptr, display_exponent, gamma);
// }
//.........这里部分代码省略.........
开发者ID:Dukeke,项目名称:ossim,代码行数:101,代码来源:ossimPngReader.cpp
示例12: png_destroy_read_struct
void ossimPngReader::restart()
{
if ( m_str )
{
// Destroy the existing memory associated with png structs.
if (m_pngReadPtr && m_pngReadInfoPtr)
{
png_destroy_read_struct(&m_pngReadPtr, &m_pngReadInfoPtr, NULL);
}
m_pngReadPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
NULL,
NULL,
NULL);
m_pngReadInfoPtr = png_create_info_struct(m_pngReadPtr);
if ( setjmp( png_jmpbuf(m_pngReadPtr) ) )
{
ossimNotify(ossimNotifyLevel_WARN)
<< "Error while reading. File corrupted? "
<< theImageFile
<< std::endl;
return;
}
// Reset the file pointer.
m_str->seekg( m_restartPosition, std::ios_base::beg );
//---
// Pass the static read method to libpng to allow us to use our
// c++ stream instead of doing "png_init_io (pp, ...);" with
// c stream.
//---
png_set_read_fn( m_pngReadPtr,
(png_voidp)m_str,
(png_rw_ptr)&ossimPngReader::pngReadData );
//---
// Note we won't do png_set_sig_bytes(png_ptr, 8) here because we are not
// rechecking for png signature.
//---
png_read_info(m_pngReadPtr, m_pngReadInfoPtr);
//---
// If png_set_expand used:
// Expand data to 24-bit RGB, or 8-bit grayscale,
// with alpha if available.
//---
bool expandFlag = false;
if ( m_pngColorType == PNG_COLOR_TYPE_PALETTE )
{
expandFlag = true;
}
if ( (m_pngColorType == PNG_COLOR_TYPE_GRAY) && (m_bitDepth < 8) )
{
expandFlag = true;
}
if ( png_get_valid(m_pngReadPtr, m_pngReadInfoPtr, PNG_INFO_tRNS) )
{
expandFlag = true;
}
//---
// If png_set_packing used:
// Use 1 byte per pixel in 1, 2, or 4-bit depth files. */
//---
bool packingFlag = false;
if ( (m_bitDepth < 8) && (m_pngColorType == PNG_COLOR_TYPE_GRAY) )
{
packingFlag = true;
}
if (expandFlag)
{
png_set_expand(m_pngReadPtr);
}
if (packingFlag)
{
png_set_packing(m_pngReadPtr);
}
// Gamma correction.
// ossim_float64 gamma;
// if (png_get_gAMA(m_pngReadPtr, m_pngReadInfoPtr, &gamma))
// {
// png_set_gamma(m_pngReadPtr, display_exponent, gamma);
// }
//---
// Turn on interlace handling... libpng returns just 1 (ie single pass)
// if the image is not interlaced
//---
png_set_interlace_handling (m_pngReadPtr);
//---
// Update the info structures after the transformations take effect
//---
//.........这里部分代码省略.........
开发者ID:Dukeke,项目名称:ossim,代码行数:101,代码来源:ossimPngReader.cpp
示例13: replaceBootImage
void* replaceBootImage(AbstractFile* imageWrapper, const unsigned int* key, const unsigned int* iv, AbstractFile* png, size_t *fileSize) {
AbstractFile* imageFile;
unsigned char header[8];
InfoIBootIM* info;
png_uint_32 i;
png_bytepp row_pointers;
uint8_t* imageBuffer;
void* buffer;
png->read(png, header, 8);
if(png_sig_cmp(header, 0, 8) != 0) {
XLOG(0, "error: not a valid png file\n");
return NULL;
}
png->seek(png, 0);
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, pngError, pngWarn);
if (!png_ptr) {
return NULL;
}
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
return NULL;
}
png_infop end_info = png_create_info_struct(png_ptr);
if (!end_info)
{
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
return NULL;
}
if (setjmp(png_jmpbuf(png_ptr)))
{
XLOG(0, "error reading png\n");
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
free(buffer);
return NULL;
}
png_set_read_fn(png_ptr, png, pngRead);
png_read_info(png_ptr, info_ptr);
if(png_get_bit_depth(png_ptr, info_ptr) > 8) {
XLOG(0, "warning: bit depth per channel is greater than 8 (%d). Attempting to strip, but image quality will be degraded.\n", png_get_bit_depth(png_ptr, info_ptr));
}
if(png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY || png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB) {
XLOG(0, "notice: attempting to add dummy transparency channel\n");
}
if(png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
XLOG(0, "notice: attempting to expand palette into full rgb\n");
}
png_set_expand(png_ptr);
png_set_strip_16(png_ptr);
png_set_bgr(png_ptr);
png_set_add_alpha(png_ptr, 0x0, PNG_FILLER_AFTER);
png_set_invert_alpha(png_ptr);
png_read_update_info(png_ptr, info_ptr);
if(png_get_image_width(png_ptr, info_ptr) > 320 || png_get_image_height(png_ptr, info_ptr) > 480) {
XLOG(0, "error: dimensions out of range, must be within 320x480, not %lux%lu\n", png_get_image_width(png_ptr, info_ptr), png_get_image_height(png_ptr, info_ptr));
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return NULL;
}
if(png_get_bit_depth(png_ptr, info_ptr) != 8) {
XLOG(0, "error: bit depth per channel must be 8 not %d!\n", png_get_bit_depth(png_ptr, info_ptr));
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return NULL;
}
if(png_get_color_type(png_ptr, info_ptr) != PNG_COLOR_TYPE_GRAY_ALPHA && png_get_color_type(png_ptr, info_ptr) != PNG_COLOR_TYPE_RGB_ALPHA) {
XLOG(0, "error: incorrect color type, must be greyscale with alpha, or rgb with alpha\n");
if(png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY || png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB) {
XLOG(0, "It appears you're missing an alpha channel. Add transparency to your image\n");
}
if(png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
XLOG(0, "This PNG is saved with the palette color type rather than ARGB.\n");
}
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return NULL;
}
row_pointers = (png_bytepp) malloc(sizeof(png_bytep) * png_get_image_height(png_ptr, info_ptr));
imageBuffer = malloc(png_get_image_height(png_ptr, info_ptr) * png_get_rowbytes(png_ptr, info_ptr));
for(i = 0; i < png_get_image_height(png_ptr, info_ptr); i++) {
row_pointers[i] = imageBuffer + (png_get_rowbytes(png_ptr, info_ptr) * i);
}
//.........这里部分代码省略.........
开发者ID:jevinskie,项目名称:xpwn,代码行数:101,代码来源:ibootim.c
示例14: loadPngTex
//.........这里部分代码省略.........
// This tells libPNG that we have already read 8 bytes from the start
// of the file (for the header check above).
png_set_sig_bytes(png_ptr, PNG_BYTES_TO_CHECK);
// This reads the PNG file into the read and info structs
/*
* If you have enough memory to read in the entire image at once,
* and you need to specify only transforms that can be controlled
* with one of the PNG_TRANSFORM_* bits (this presently excludes
* dithering, filling, setting background, and doing gamma
* adjustment), then you can read the entire image (including
* pixels) into the info structure with this call:
*/
png_read_info(png_ptr, info_ptr);
// Get some basic infos about the image from png_info structure
// width & height in px, bit depth
// interlace_method, compression_method, & filter_method are ignored
png_get_IHDR(png_ptr, info_ptr, &(pImagePNG->sizeX), &(pImagePNG->sizeY),
&bit_depth, &cType, 0, 0, 0);
// COLOR TYPE read and possible corrections - then reread
// Color type: we handle RGB and RGB_ALPHA (with Alpha)
// GRAY (luminance) and GRAY_ALPHA (luminance with Alpha)
cType = png_get_color_type(png_ptr, info_ptr);
// strip the pixels of a PNG stream with 16 bits per channel to 8 bits per channel
if (bit_depth == 16) {
png_set_strip_16(png_ptr);
}
// set transformation in png_ptr such that paletted images are expanded to RGB,
// grayscale images of bit-depth less than 8 are expanded to 8-bit images
// tRNS chunks are expanded to alpha channels
if (cType == PNG_COLOR_TYPE_PALETTE) {
png_set_expand(png_ptr);
}
if (bit_depth < 8) {
png_set_expand(png_ptr);
}
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
png_set_expand(png_ptr);
}
// if required set gamma conversion
if (png_get_gAMA(png_ptr, info_ptr, &gamma)) {
png_set_gamma(png_ptr, (double) 2.2, gamma);
}
// After the image transformations have been registered update info_ptr data
png_read_update_info(png_ptr, info_ptr);
// Gets again width, height and the new bit-depth and color-type
png_get_IHDR(png_ptr, info_ptr, &(pImagePNG->sizeX), &(pImagePNG->sizeY),
&bit_depth, &cType, 0, 0, 0);
// We now calculate the *bytes* per pixel from the color type and the
// bits per pixel.
if((cType == PNG_COLOR_TYPE_RGB) && (bit_depth == 8)) {
pImagePNG->bytesPerPixel = 3;
*hasAlpha = false;
}
else
|
请发表评论