本文整理汇总了C++中png_set_error_fn函数的典型用法代码示例。如果您正苦于以下问题:C++ png_set_error_fn函数的具体用法?C++ png_set_error_fn怎么用?C++ png_set_error_fn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了png_set_error_fn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DEBUG_ENTER_FUNC
bool PngLoader::basicImageLoad() {
DEBUG_ENTER_FUNC();
_pngPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!_pngPtr)
return false;
png_set_error_fn(_pngPtr, (png_voidp) NULL, (png_error_ptr) NULL, warningFn);
_infoPtr = png_create_info_struct(_pngPtr);
if (!_infoPtr) {
png_destroy_read_struct(&_pngPtr, png_infopp_NULL, png_infopp_NULL);
return false;
}
// Set the png lib to use our read function
png_set_read_fn(_pngPtr, &_file, libReadFunc);
unsigned int sig_read = 0;
png_set_sig_bytes(_pngPtr, sig_read);
png_read_info(_pngPtr, _infoPtr);
int interlaceType;
png_get_IHDR(_pngPtr, _infoPtr, (png_uint_32 *)&_width, (png_uint_32 *)&_height, &_bitDepth,
&_colorType, &interlaceType, int_p_NULL, int_p_NULL);
_channels = png_get_channels(_pngPtr, _infoPtr);
if (_colorType & PNG_COLOR_MASK_PALETTE)
_paletteSize = _infoPtr->num_palette;
return true;
}
示例2: input_
decoder::decoder(std::streambuf *sbuf, info &i)
: input_(sbuf),
png_(png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0)),
info_(png_create_info_struct(png_)),
end_(png_create_info_struct(png_))
{
png_byte header[magic_];
input_->sgetn((char*)header, magic_);
if (png_sig_cmp(header, 0, magic_)) throw std::runtime_error("Not a PNG file");
png_set_sig_bytes(png_, magic_);
png_set_read_fn(png_, input_, decoder_read);
png_set_error_fn(png_, input_, decoder_error, decoder_warning);
png_set_read_status_fn(png_, 0);
png_read_info(png_, info_);
png_uint_32 w, h;
int d, c, in, co, f;
png_get_IHDR(png_, info_, &w, &h, &d, &c, &in, &co, &f);
i.width = w;
i.height = h;
i.rowbytes = png_get_rowbytes(png_, info_);
i.depth = d;
i.colortype = static_cast<color_type>(c);
i.compression = co;
i.filter = f;
i.interlace = static_cast<interlace_type>(in);
}
示例3: ALLEGRO_ASSERT
/* Load a PNG file from disk, doing colour coversion if required.
*/
ALLEGRO_BITMAP *_al_load_png_f(ALLEGRO_FILE *fp, int flags)
{
jmp_buf jmpbuf;
ALLEGRO_BITMAP *bmp;
png_structp png_ptr;
png_infop info_ptr;
ALLEGRO_ASSERT(fp);
if (!check_if_png(fp)) {
ALLEGRO_ERROR("Not a png.\n");
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.
*/
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
(void *)NULL, NULL, NULL);
if (!png_ptr) {
ALLEGRO_ERROR("png_ptr == NULL\n");
return NULL;
}
/* Allocate/initialize the memory for image information. */
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL);
ALLEGRO_ERROR("png_create_info_struct failed\n");
return NULL;
}
/* Set error handling. */
if (setjmp(jmpbuf)) {
/* 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 */
ALLEGRO_ERROR("Error reading PNG file\n");
return NULL;
}
png_set_error_fn(png_ptr, jmpbuf, user_error_fn, NULL);
/* Use Allegro packfile routines. */
png_set_read_fn(png_ptr, fp, (png_rw_ptr) read_data);
/* We have already read some of the signature. */
png_set_sig_bytes(png_ptr, PNG_BYTES_TO_CHECK);
/* Really load the image now. */
bmp = really_load_png(png_ptr, info_ptr, flags);
/* Clean up after the read, and free any memory allocated. */
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
return bmp;
}
示例4: png_create
static bool png_create(Fl_IO &png_io, uint8 *&data, Fl_PixelFormat &fmt, int &w, int &h)
{
w=0, h=0;
png_structp png_ptr = 0;
png_infop info_ptr = 0, end_info_ptr = 0;
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if(!png_ptr) { return_error(); }
info_ptr = png_create_info_struct(png_ptr);
if(!info_ptr) { return_error(); }
end_info_ptr = png_create_info_struct(png_ptr);
if(!end_info_ptr) { return_error(); }
png_bytepp rows = 0;
if(setjmp(png_ptr->jmpbuf)) {
if(rows) free(rows);
if(png_ptr) png_destroy_read_struct (&png_ptr, &info_ptr, &end_info_ptr);
fputs((const char *)png_last_error, stderr);
return false;
}
int ctype = 0;
int pitch=0, bitspp=0;
int ckey = -1;
int i=0;
uint32 Rmask=0, Gmask=0, Bmask=0, Amask=0;
png_color_16 *transv=0;
Fl_Colormap *palette=0;
png_set_error_fn(png_ptr, (png_voidp)0, my_png_error, my_png_warning);
png_set_read_fn(png_ptr, (png_voidp)&png_io, read_data_fn);
png_read_info(png_ptr, info_ptr);
if(!setup_png_transformations(png_ptr, info_ptr, transv, ctype, ckey, bitspp, w, h))
goto error;
if(ctype != PNG_COLOR_TYPE_PALETTE) {
#if !WORDS_BIGENDIAN
Rmask = 0x000000FF;
Gmask = 0x0000FF00;
Bmask = 0x00FF0000;
Amask = (info_ptr->channels == 4) ? 0xFF000000 : 0;
#else
int s = (info_ptr->channels == 4) ? 0 : 8;
Rmask = 0xFF000000 >> s;
Gmask = 0x00FF0000 >> s;
Bmask = 0x0000FF00 >> s;
Amask = 0x000000FF >> s;
#endif
if(info_ptr->channels == 4)
fmt.masktype = FL_MASK_ALPHA;
}
示例5: output_
encoder::encoder(std::streambuf *sb, info const &i)
: output_(sb),
png_(png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0)),
info_(png_create_info_struct(png_))
{
png_set_write_fn(png_, output_, encoder_write, encoder_flush);
png_set_error_fn(png_, output_, encoder_error, encoder_warning);
png_set_write_status_fn(png_, 0);
png_set_IHDR(png_, info_,
i.width, i.height, i.depth, i.colortype,
i.interlace, i.compression, i.filter);
}
示例6: NEX_THROW_FatalError
void PNGImageCodec::Save(OutputStreamPtr& file, const ImageParams& params,
const ImageData& data) {
OutputStream* writr = file.GetPtr();
if (data.format != PixelFormat::BGRA8 && data.format != PixelFormat::RGBA8)
// todo support formats like rgba16 etc.
NEX_THROW_FatalError(EXCEPT_NOT_IMPLEMENTED);
png_structp pngPtr = nullptr;
png_infop infoPtr = nullptr;
png_byte ** rowPointers = nullptr;
// todo Fix for 64
uint32 bitDepth = 32;
size_t rowStride = data.width * bitDepth;
bool flip = (data.format == PixelFormat::BGRA8);
pngPtr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (pngPtr == nullptr)
goto failed;
infoPtr = png_create_info_struct(pngPtr);
if (infoPtr == nullptr)
goto failed;
png_set_error_fn(pngPtr, (void *) (writr), PngWarn, PngWarn);
png_set_write_fn(pngPtr, (void *) (writr), PngWriteFile, PngFlushFile);
png_set_IHDR(pngPtr, infoPtr, data.width, data.height, bitDepth, // assumed
PNG_COLOR_TYPE_RGB_ALPHA,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
rowPointers = (png_byte**) NEX_ALLOC(sizeof(png_byte*) * data.height,
MEMCAT_GENERAL);
for (uint32 i = 0; i < data.height; ++i) {
rowPointers[i] = (static_cast<uint8*>(data.data)) + i * rowStride;
}
png_set_rows(pngPtr, infoPtr, rowPointers);
png_write_png(pngPtr, infoPtr,
flip ? PNG_TRANSFORM_BGR : PNG_TRANSFORM_IDENTITY, NULL);
failed: if (rowPointers)
NEX_FREE(rowPointers, MEMCAT_GENERAL);
if (pngPtr)
png_destroy_write_struct(&pngPtr, &infoPtr);
}
示例7: _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);
}
示例8: png_create_read_struct
bool Q_INTERNAL_WIN_NO_THROW QPngHandlerPrivate::readPngHeader()
{
state = Error;
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,0);
if (!png_ptr)
return false;
png_set_error_fn(png_ptr, 0, 0, qt_png_warning);
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_read_struct(&png_ptr, 0, 0);
png_ptr = 0;
return false;
}
end_info = png_create_info_struct(png_ptr);
if (!end_info) {
png_destroy_read_struct(&png_ptr, &info_ptr, 0);
png_ptr = 0;
return false;
}
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
png_ptr = 0;
return false;
}
png_set_read_fn(png_ptr, this, iod_read_fn);
png_read_info(png_ptr, info_ptr);
readPngTexts(info_ptr);
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA)) {
double file_gamma = 0.0;
png_get_gAMA(png_ptr, info_ptr, &file_gamma);
fileGamma = file_gamma;
}
state = ReadHeader;
return true;
}
示例9: image_reader_exception
void png_reader<T>::init()
{
png_byte header[8];
std::memset(header,0,8);
stream_.read(reinterpret_cast<char*>(header),8);
if ( stream_.gcount() != 8)
{
throw image_reader_exception("PNG reader: Could not read image");
}
int is_png=!png_sig_cmp(header,0,8);
if (!is_png)
{
throw image_reader_exception("File or stream is not a png");
}
png_structp png_ptr = png_create_read_struct
(PNG_LIBPNG_VER_STRING,0,0,0);
if (!png_ptr)
{
throw image_reader_exception("failed to allocate png_ptr");
}
// catch errors in a custom way to avoid the need for setjmp
png_set_error_fn(png_ptr, png_get_error_ptr(png_ptr), user_error_fn, user_warning_fn);
png_infop info_ptr;
png_struct_guard sguard(&png_ptr,&info_ptr);
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) throw image_reader_exception("failed to create info_ptr");
png_set_read_fn(png_ptr, (png_voidp)&stream_, png_read_data);
png_set_sig_bytes(png_ptr,8);
png_read_info(png_ptr, info_ptr);
png_uint_32 width, height;
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth_, &color_type_,0,0,0);
has_alpha_ = (color_type_ & PNG_COLOR_MASK_ALPHA) || png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS);
width_=width;
height_=height;
MAPNIK_LOG_DEBUG(png_reader) << "png_reader: bit_depth=" << bit_depth_ << ",color_type=" << color_type_;
}
示例10: nspng_create_png_data
static nserror nspng_create_png_data(nspng_content *png_c)
{
union content_msg_data msg_data;
png_c->bitmap = NULL;
png_c->png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
if (png_c->png == NULL) {
msg_data.error = messages_get("NoMemory");
content_broadcast(&png_c->base, CONTENT_MSG_ERROR, msg_data);
warn_user("NoMemory", 0);
return NSERROR_NOMEM;
}
png_set_error_fn(png_c->png, NULL, nspng_error, nspng_warning);
png_c->info = png_create_info_struct(png_c->png);
if (png_c->info == NULL) {
png_destroy_read_struct(&png_c->png, &png_c->info, 0);
msg_data.error = messages_get("NoMemory");
content_broadcast(&png_c->base, CONTENT_MSG_ERROR, msg_data);
warn_user("NoMemory", 0);
return NSERROR_NOMEM;
}
if (setjmp(png_jmpbuf(png_c->png))) {
png_destroy_read_struct(&png_c->png, &png_c->info, 0);
LOG(("Failed to set callbacks"));
png_c->png = NULL;
png_c->info = NULL;
msg_data.error = messages_get("PNGError");
content_broadcast(&png_c->base, CONTENT_MSG_ERROR, msg_data);
return NSERROR_NOMEM;
}
png_set_progressive_read_fn(png_c->png, png_c,
info_callback, row_callback, end_callback);
return NSERROR_OK;
}
示例11: sizeof
FXPNG_Context* CCodec_PngModule::Start(void* pModule) {
FXPNG_Context* p = (FXPNG_Context*)FX_Alloc(uint8_t, sizeof(FXPNG_Context));
if (!p)
return nullptr;
p->m_AllocFunc = _png_alloc_func;
p->m_FreeFunc = _png_free_func;
p->png_ptr = nullptr;
p->info_ptr = nullptr;
p->parent_ptr = (void*)this;
p->child_ptr = pModule;
p->png_ptr =
png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
if (!p->png_ptr) {
FX_Free(p);
return nullptr;
}
p->info_ptr = png_create_info_struct(p->png_ptr);
if (!p->info_ptr) {
png_destroy_read_struct(&(p->png_ptr), nullptr, nullptr);
FX_Free(p);
return nullptr;
}
if (setjmp(png_jmpbuf(p->png_ptr))) {
if (p) {
png_destroy_read_struct(&(p->png_ptr), &(p->info_ptr), nullptr);
FX_Free(p);
}
return nullptr;
}
png_set_progressive_read_fn(p->png_ptr, p, _png_get_header_func,
_png_get_row_func, _png_get_end_func);
png_set_error_fn(p->png_ptr, m_szLastError, (png_error_ptr)_png_error_data,
(png_error_ptr)_png_warning_data);
return p;
}
示例12: png_create_read_struct_2
/* Alternate create PNG structure for reading, and allocate any memory needed. */
png_structp PNGAPI
png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
png_malloc_ptr malloc_fn, png_free_ptr free_fn)
{
#endif /* PNG_USER_MEM_SUPPORTED */
png_structp png_ptr;
#ifdef PNG_SETJMP_SUPPORTED
#ifdef USE_FAR_KEYWORD
jmp_buf jmpbuf;
#endif
#endif
int i;
png_debug(1, "in png_create_read_struct\n");
#ifdef PNG_USER_MEM_SUPPORTED
png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
(png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
#else
png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
#endif
if (png_ptr == NULL)
return (NULL);
#if !defined(PNG_1_0_X)
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
png_init_mmx_flags(png_ptr); /* 1.2.0 addition */
#endif
#endif /* PNG_1_0_X */
/* added at libpng-1.2.6 */
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
#endif
#ifdef PNG_SETJMP_SUPPORTED
#ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf))
#else
if (setjmp(png_ptr->jmpbuf))
#endif
{
png_free(png_ptr, png_ptr->zbuf);
png_ptr->zbuf=NULL;
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)png_ptr,
(png_free_ptr)free_fn, (png_voidp)mem_ptr);
#else
png_destroy_struct((png_voidp)png_ptr);
#endif
return (NULL);
}
#ifdef USE_FAR_KEYWORD
png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
#endif
#endif
#ifdef PNG_USER_MEM_SUPPORTED
png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
#endif
png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
i=0;
do
{
if(user_png_ver[i] != png_libpng_ver[i])
png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
} while (png_libpng_ver[i++]);
if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
{
/* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
* we must recompile any applications that use any older library version.
* For versions after libpng 1.0, we will be compatible, so we need
* only check the first digit.
*/
if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
(user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
(user_png_ver[0] == '0' && user_png_ver[2] < '9'))
{
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
char msg[80];
if (user_png_ver)
{
sprintf(msg, "Application was compiled with png.h from libpng-%.20s",
user_png_ver);
png_warning(png_ptr, msg);
}
sprintf(msg, "Application is running with png.c from libpng-%.20s",
png_libpng_ver);
png_warning(png_ptr, msg);
#endif
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
png_ptr->flags=0;
//.........这里部分代码省略.........
示例13: destroy
bool PNGDecoder::loadStream(Common::SeekableReadStream &stream) {
#ifdef USE_PNG
destroy();
// First, check the PNG signature (if not set to skip it)
if (!_skipSignature) {
if (stream.readUint32BE() != MKTAG(0x89, 'P', 'N', 'G')) {
return false;
}
if (stream.readUint32BE() != MKTAG(0x0d, 0x0a, 0x1a, 0x0a)) {
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) {
return false;
}
png_infop infoPtr = png_create_info_struct(pngPtr);
if (!infoPtr) {
png_destroy_read_struct(&pngPtr, NULL, NULL);
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:
#ifdef SCUMM_LITTLE_ENDIAN
png_set_bgr(pngPtr);
png_set_swap_alpha(pngPtr);
if (colorType != PNG_COLOR_TYPE_RGB_ALPHA)
png_set_filler(pngPtr, 0xff, PNG_FILLER_BEFORE);
#else
if (colorType != PNG_COLOR_TYPE_RGB_ALPHA)
png_set_filler(pngPtr, 0xff, PNG_FILLER_AFTER);
#endif
//.........这里部分代码省略.........
示例14: png_create_read_struct
s_screen *pngToScreen(const void *data)
{
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, y;
u32 *line;
s_screen *image;
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if(png_ptr == NULL)
{
goto error;
}
png_set_error_fn(png_ptr, (png_voidp) NULL, (png_error_ptr) NULL, png_warning_fn);
info_ptr = png_create_info_struct(png_ptr);
if(info_ptr == NULL)
{
goto error2;
}
if(setjmp(png_jmpbuf(png_ptr)))
{
goto error2;
}
png_set_read_fn(png_ptr, &data, png_read_fn);
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_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 WII
png_set_filler(png_ptr, 0xff, PNG_FILLER_BEFORE);
#else
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
#endif
image = allocscreen(width, height, PIXEL_32);
if(image == NULL)
{
goto error2;
}
line = (u32 *)image->data;
for(y = 0; y < height; y++)
{
png_read_row(png_ptr, (u8 *) line, NULL);
line += width;
}
png_read_end(png_ptr, info_ptr);
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return image;
error2:
png_destroy_read_struct(&png_ptr, NULL, NULL);
error:
return NULL;
}
示例15: block_Alloc
/*
* EncodeBlock
*/
static block_t *EncodeBlock(encoder_t *p_enc, picture_t *p_pic)
{
encoder_sys_t *p_sys = p_enc->p_sys;
if( unlikely( !p_pic ) )
{
return NULL;
}
block_t *p_block = block_Alloc( p_sys->i_blocksize );
if( p_block == NULL )
{
return NULL;
}
png_structp p_png = png_create_write_struct( PNG_LIBPNG_VER_STRING, 0, 0, 0 );
if( p_png == NULL )
{
block_Release( p_block );
return NULL;
}
/* save buffer start */
uint8_t *p_start = p_block->p_buffer;
size_t i_start = p_block->i_buffer;
p_sys->b_error = false;
png_infop p_info = NULL;
/* libpng longjmp's there in case of error */
if( setjmp( png_jmpbuf( p_png ) ) )
goto error;
png_set_write_fn( p_png, p_block, user_write, user_flush );
png_set_error_fn( p_png, p_enc, user_error, user_warning );
p_info = png_create_info_struct( p_png );
if( p_info == NULL )
goto error;
png_infop p_end_info = png_create_info_struct( p_png );
if( p_end_info == NULL ) goto error;
const unsigned i_width = p_enc->fmt_in.video.i_visible_width;
const unsigned i_height = p_enc->fmt_in.video.i_visible_height;
png_set_IHDR( p_png, p_info,
i_width,
i_height,
8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT );
if( p_sys->b_error ) goto error;
png_write_info( p_png, p_info );
if( p_sys->b_error ) goto error;
/* Encode picture */
for( unsigned i = 0; i < i_height; i++ )
{
png_write_row( p_png, p_pic->p->p_pixels + (i_width * i * 3));
if( p_sys->b_error ) goto error;
}
png_write_end( p_png, p_end_info );
if( p_sys->b_error ) goto error;
png_destroy_write_struct( &p_png, &p_info );
/* restore original buffer position */
p_block->p_buffer = p_start;
p_block->i_buffer = i_start - p_block->i_buffer;
p_block->i_dts = p_block->i_pts = p_pic->date;
return p_block;
error:
png_destroy_write_struct( &p_png, p_info ? &p_info : NULL );
block_Release(p_block);
return NULL;
}