本文整理汇总了C++中png_get_channels函数的典型用法代码示例。如果您正苦于以下问题:C++ png_get_channels函数的具体用法?C++ png_get_channels怎么用?C++ png_get_channels使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了png_get_channels函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ReadHeightmapPNG
/**
* Reads the heightmap and/or size of the heightmap from a PNG file.
* If map == NULL only the size of the PNG is read, otherwise a map
* with grayscale pixels is allocated and assigned to *map.
*/
static bool ReadHeightmapPNG(char *filename, uint *x, uint *y, byte **map)
{
FILE *fp;
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
fp = FioFOpenFile(filename, "rb");
if (fp == NULL) {
ShowErrorMessage(STR_ERROR_PNGMAP, STR_ERROR_PNGMAP_FILE_NOT_FOUND, WL_ERROR);
return false;
}
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) {
ShowErrorMessage(STR_ERROR_PNGMAP, STR_ERROR_PNGMAP_MISC, WL_ERROR);
fclose(fp);
return false;
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL || setjmp(png_jmpbuf(png_ptr))) {
ShowErrorMessage(STR_ERROR_PNGMAP, STR_ERROR_PNGMAP_MISC, WL_ERROR);
fclose(fp);
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return false;
}
png_init_io(png_ptr, fp);
/* Allocate memory and read image, without alpha or 16-bit samples
* (result is either 8-bit indexed/grayscale or 24-bit RGB) */
png_set_packing(png_ptr);
png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_PACKING | PNG_TRANSFORM_STRIP_ALPHA | PNG_TRANSFORM_STRIP_16, NULL);
/* Maps of wrong colour-depth are not used.
* (this should have been taken care of by stripping alpha and 16-bit samples on load) */
if ((png_get_channels(png_ptr, info_ptr) != 1) && (png_get_channels(png_ptr, info_ptr) != 3) && (png_get_bit_depth(png_ptr, info_ptr) != 8)) {
ShowErrorMessage(STR_ERROR_PNGMAP, STR_ERROR_PNGMAP_IMAGE_TYPE, WL_ERROR);
fclose(fp);
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return false;
}
if (map != NULL) {
*map = MallocT<byte>(png_get_image_width(png_ptr, info_ptr) * png_get_image_height(png_ptr, info_ptr));
ReadHeightmapPNGImageData(*map, png_ptr, info_ptr);
}
*x = png_get_image_width(png_ptr, info_ptr);
*y = png_get_image_height(png_ptr, info_ptr);
fclose(fp);
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return true;
}
开发者ID:jemmyw,项目名称:openttd,代码行数:60,代码来源:heightmap.cpp
示例2: ReadHeightmapPNGImageData
/**
* The PNG Heightmap loader.
*/
static void ReadHeightmapPNGImageData(byte *map, png_structp png_ptr, png_infop info_ptr)
{
uint x, y;
byte gray_palette[256];
png_bytep *row_pointers = NULL;
/* Get palette and convert it to grayscale */
if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
int i;
int palette_size;
png_color *palette;
bool all_gray = true;
png_get_PLTE(png_ptr, info_ptr, &palette, &palette_size);
for (i = 0; i < palette_size && (palette_size != 16 || all_gray); i++) {
all_gray &= palette[i].red == palette[i].green && palette[i].red == palette[i].blue;
gray_palette[i] = RGBToGrayscale(palette[i].red, palette[i].green, palette[i].blue);
}
/**
* For a non-gray palette of size 16 we assume that
* the order of the palette determines the height;
* the first entry is the sea (level 0), the second one
* level 1, etc.
*/
if (palette_size == 16 && !all_gray) {
for (i = 0; i < palette_size; i++) {
gray_palette[i] = 256 * i / palette_size;
}
}
}
row_pointers = png_get_rows(png_ptr, info_ptr);
/* Read the raw image data and convert in 8-bit grayscale */
for (x = 0; x < png_get_image_width(png_ptr, info_ptr); x++) {
for (y = 0; y < png_get_image_height(png_ptr, info_ptr); y++) {
byte *pixel = &map[y * png_get_image_width(png_ptr, info_ptr) + x];
uint x_offset = x * png_get_channels(png_ptr, info_ptr);
if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE) {
*pixel = gray_palette[row_pointers[y][x_offset]];
} else if (png_get_channels(png_ptr, info_ptr) == 3) {
*pixel = RGBToGrayscale(row_pointers[y][x_offset + 0],
row_pointers[y][x_offset + 1], row_pointers[y][x_offset + 2]);
} else {
*pixel = row_pointers[y][x_offset];
}
}
}
}
开发者ID:jemmyw,项目名称:openttd,代码行数:54,代码来源:heightmap.cpp
示例3: 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;
}
开发者ID:project-cabal,项目名称:cabal,代码行数:30,代码来源:png_loader.cpp
示例4: npng_readImage
/**
* @brief Reads the png data as 32 bit format.
*/
png_bytep npng_readImage( npng_t *npng, png_bytep **rows, int *channels, int *pitch )
{
png_bytep image_data;
png_uint_32 width, height;
png_bytep *row_pointers;
png_uint_32 i, rowbytes;
/* Get info. */
npng_dim( npng, &width, &height );
rowbytes = npng_pitch( npng );
/* Create the array of pointers to image data */
image_data = malloc( rowbytes * height );
if (image_data == NULL)
ERR( "Out of Memory" );
row_pointers = malloc( sizeof(png_bytep) * height );
if (row_pointers == NULL)
ERR( "Out of Memory" );
for (i=0; i<height; i++)
row_pointers[i] = image_data + i*rowbytes;
/* Return data. */
if (channels != NULL)
*channels = png_get_channels( npng->png_ptr, npng->info_ptr );
if (pitch != NULL)
*pitch = rowbytes;
if (rows != NULL)
*rows = row_pointers;
else
free( row_pointers );
return image_data;
}
开发者ID:Crockadavin,项目名称:naev,代码行数:35,代码来源:npng.c
示例5: each_interlace_none
static VALUE each_interlace_none(struct each_args *args)
{
struct readerdata *reader;
unsigned char *inwidthbuf, *outwidthbuf, *yinbuf;
struct xscaler *xs;
struct yscaler *ys;
uint32_t i, scaley;
int cmp;
reader = args->reader;
xs = &args->xs;
inwidthbuf = xscaler_psl_pos0(xs);
outwidthbuf = args->outwidthbuf;
ys = &args->ys;
scaley = reader->scale_height;
cmp = png_get_channels(reader->png, reader->info);
png_write_info(args->wpng, args->winfo);
for(i=0; i<scaley; i++) {
while ((yinbuf = yscaler_next(ys))) {
png_read_row(reader->png, inwidthbuf, NULL);
xscaler_scale(xs, yinbuf);
}
yscaler_scale(ys, outwidthbuf, i, cmp, 0);
png_write_row(args->wpng, outwidthbuf);
}
png_write_end(args->wpng, args->winfo);
return Qnil;
}
开发者ID:ender672,项目名称:oil,代码行数:31,代码来源:png.c
示例6: each_interlace
static VALUE each_interlace(struct each_args *args)
{
struct readerdata *reader;
unsigned char *inwidthbuf, *outwidthbuf;
uint32_t i, width, height, scaley;
int cmp;
struct xscaler *xs;
reader = args->reader;
xs = &args->xs;
inwidthbuf = xscaler_psl_pos0(xs);
outwidthbuf = args->outwidthbuf;
scaley = reader->scale_height;
cmp = png_get_channels(reader->png, reader->info);
width = png_get_image_width(reader->png, reader->info);
height = png_get_image_height(reader->png, reader->info);
png_write_info(args->wpng, args->winfo);
png_read_image(args->reader->png, (png_bytepp)args->scanlines);
for (i=0; i<scaley; i++) {
yscaler_prealloc_scale(height, scaley,
(uint8_t **)args->scanlines, (uint8_t *)inwidthbuf,
i, width, cmp, 0);
xscaler_scale(xs, outwidthbuf);
png_write_row(args->wpng, outwidthbuf);
}
png_write_end(args->wpng, args->winfo);
return Qnil;
}
开发者ID:ender672,项目名称:oil,代码行数:30,代码来源:png.c
示例7: png_read_png
//
////////////////////////////////////////////////////
//
// Image* readPNGIntoImage()
//
////////////////////////////////////////////////////
//
Image* PNGCodec::readPNGIntoImage(png_structp &png, png_infop &pngInfo)
{
uint8 **buf;
int y;
png_uint_32 iWidth, iHeight, iRowLength;
png_byte iColourType, iBitsPerChannel, iNumChannels;
png_bytepp pngRows;
Image* imgPNG;
png_read_png(png, pngInfo, PNG_TRANSFORM_BGR | PNG_TRANSFORM_STRIP_ALPHA, png_voidp_NULL);
// pixels are in info_ptr->row_pointers
// where row_pointers is:
// png_bytep row_pointers[height];
// and is probably not contiguous
iColourType = png_get_color_type(png, pngInfo);
// if (iColourType != PNG_COLOR_TYPE_RGB_ALPHA)
if (iColourType != PNG_COLOR_TYPE_RGB)
throw new std::runtime_error("Colour type not supported - RGB only, PNGCodec::readPNGIntoImage()");
iBitsPerChannel = png_get_bit_depth(png, pngInfo);
iNumChannels = png_get_channels(png, pngInfo);
iHeight = png_get_image_height(png, pngInfo);
iWidth = png_get_image_width(png, pngInfo);
iRowLength = iWidth * (iBitsPerChannel * iNumChannels) / 8; // Should be same as iWidth
// 07-Jul-2009: Directly load the PNG into a pre-created image's
// buffer. Otherwise ImageRGB24 will make a copy of the buf, which
// is a waste of space (and problematic for very large PNGs!)
imgPNG = new Image;
imgPNG->width = iWidth;
imgPNG->height = iHeight;
imgPNG->data = new unsigned char*[iHeight];
for (y = 0; y < iHeight; y++) {
imgPNG->data[y] = new unsigned char[iRowLength];
}
buf = imgPNG->data;
pngRows = png_get_rows(png, pngInfo);
for (y = 0; y < iHeight; y++) {
// for (x = 0; x < iWidth; x++) {
// This assumes BGR order, in readiness for the ImageRGB24 constructor
// It also assumes 24-bit, no alpha
// Yes, this is not good...
memcpy(buf[y], pngRows[y], iRowLength);
//memcpy((buf + (y * iRowLength)), pngRows[y], iRowLength);
}
// Clean up
png_destroy_read_struct(&png, &pngInfo, png_infopp_NULL);
return imgPNG;
}
开发者ID:Redezem,项目名称:PGM-PNGCodec,代码行数:66,代码来源:PNGCodec.cpp
示例8: each
static VALUE each(int argc, VALUE *argv, VALUE self)
{
struct readerdata *reader;
png_infop winfo;
png_structp wpng;
VALUE opts;
int cmp, state, ret;
struct each_args args;
png_byte ctype;
rb_scan_args(argc, argv, "01", &opts);
Data_Get_Struct(self, struct readerdata, reader);
raise_if_locked(reader);
reader->locked = 1;
cmp = png_get_channels(reader->png, reader->info);
ctype = png_get_color_type(reader->png, reader->info);
wpng = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,
(png_error_ptr)error, (png_error_ptr)warning);
winfo = png_create_info_struct(wpng);
png_set_write_fn(wpng, 0, write_data_fn, flush_data_fn);
png_set_IHDR(wpng, winfo, reader->scale_width, reader->scale_height, 8,
ctype, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
args.reader = reader;
args.wpng = wpng;
args.winfo = winfo;
args.outwidthbuf = malloc(reader->scale_width * cmp);
if (!args.outwidthbuf) {
rb_raise(rb_eRuntimeError, "Unable to allocate memory.");
}
ret = oil_libpng_init(&args.ol, reader->png, reader->info,
reader->scale_width, reader->scale_height);
if (ret!=0) {
free(args.outwidthbuf);
rb_raise(rb_eRuntimeError, "Unable to allocate memory.");
}
rb_protect((VALUE(*)(VALUE))each2, (VALUE)&args, &state);
oil_libpng_free(&args.ol);
free(args.outwidthbuf);
png_destroy_write_struct(&wpng, &winfo);
if (state) {
rb_jump_tag(state);
}
return self;
}
开发者ID:ender672,项目名称:oil,代码行数:56,代码来源:png.c
示例9: png_read_update_info
// Read out the image meta-data
void LLPngWrapper::updateMetaData()
{
png_read_update_info(mReadPngPtr, mReadInfoPtr);
mWidth = png_get_image_width(mReadPngPtr, mReadInfoPtr);
mHeight = png_get_image_height(mReadPngPtr, mReadInfoPtr);
mBitDepth = png_get_bit_depth(mReadPngPtr, mReadInfoPtr);
mColorType = png_get_color_type(mReadPngPtr, mReadInfoPtr);
mChannels = png_get_channels(mReadPngPtr, mReadInfoPtr);
mHasBKGD = png_get_bKGD(mReadPngPtr, mReadInfoPtr, &mBackgroundColor);
}
开发者ID:Boy,项目名称:netbook,代码行数:11,代码来源:llpngwrapper.cpp
示例10: pngSetHeader
void pngSetHeader(PngStream* stream)
{
stream->info.imageWidth = png_get_image_width(stream->png_ptr, stream->info_ptr);
stream->info.imageHeight = png_get_image_height(stream->png_ptr, stream->info_ptr);
stream->info.numComponents = png_get_channels(stream->png_ptr, stream->info_ptr);
stream->info.colorSpace = getPngDecColourType(png_get_color_type(stream->png_ptr, stream->info_ptr));
stream->info.bitDepth = png_get_bit_depth(stream->png_ptr, stream->info_ptr);
stream->info.interlaceMethod = png_get_interlace_type(stream->png_ptr, stream->info_ptr);
stream->info.chunkInformation = pngDecGetChunkInformation(stream);
}
开发者ID:AniLeo,项目名称:rpcs3,代码行数:10,代码来源:cellPngDec.cpp
示例11: png_set_interlace_handling
// Read out the image meta-data
void LLPngWrapper::updateMetaData()
{
png_set_interlace_handling(mReadPngPtr); // <alchemy/>
png_read_update_info(mReadPngPtr, mReadInfoPtr);
mWidth = png_get_image_width(mReadPngPtr, mReadInfoPtr);
mHeight = png_get_image_height(mReadPngPtr, mReadInfoPtr);
mBitDepth = png_get_bit_depth(mReadPngPtr, mReadInfoPtr);
mColorType = png_get_color_type(mReadPngPtr, mReadInfoPtr);
mChannels = png_get_channels(mReadPngPtr, mReadInfoPtr);
}
开发者ID:AlchemyDev,项目名称:Carbon,代码行数:11,代码来源:llpngwrapper.cpp
示例12: panic
PngImage::PngImage(const ByteBuffer &compressed_bytes) {
if (png_sig_cmp((png_bytep)compressed_bytes.raw(), 0, 8))
panic("not png file");
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr)
panic("unable to create png read struct");
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
panic("unable to create png info struct");
// don't call any png_* functions outside of this function D:
if (setjmp(png_jmpbuf(png_ptr)))
panic("libpng has jumped the shark");
png_set_sig_bytes(png_ptr, 8);
PngIo png_io = {8, (unsigned char *)compressed_bytes.raw(), compressed_bytes.length()};
png_set_read_fn(png_ptr, &png_io, read_png_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);
if (_width <= 0 || _height <= 0)
panic("spritesheet image has no pixels");
// bits per channel (not per pixel)
int bits_per_channel = png_get_bit_depth(png_ptr, info_ptr);
if (bits_per_channel != 8)
panic("expected 8 bits per channel");
int channel_count = png_get_channels(png_ptr, info_ptr);
if (channel_count != 4)
panic("expected 4 channels");
int color_type = png_get_color_type(png_ptr, info_ptr);
if (color_type != PNG_COLOR_TYPE_RGBA)
panic("expected RGBA");
_pitch = _width * bits_per_channel * channel_count / 8;
_image_data.resize(_height * _pitch);
png_bytep *row_ptrs = ok_mem(allocate_zero<png_bytep>(_height));
for (int i = 0; i < _height; i++) {
png_uint_32 q = (_height - i - 1) * _pitch;
row_ptrs[i] = (png_bytep)_image_data.raw() + q;
}
png_read_image(png_ptr, row_ptrs);
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
destroy(row_ptrs, _height);
}
开发者ID:EQ4,项目名称:genesis,代码行数:55,代码来源:png_image.cpp
示例13: png_set_read_fn
void ogl::texture::load_png(const void *buf, size_t len, std::vector<GLubyte>& p)
{
// Initialize all PNG import data structures.
png_structp rp = 0;
png_infop ip = 0;
png_bytep *bp = 0;
if (!(rp = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0)))
throw std::runtime_error("Failure creating PNG read structure");
if (!(ip = png_create_info_struct(rp)))
throw std::runtime_error("Failure creating PNG info structure");
// Initialize the user-defined IO structure.
struct png_user_io user;
user.buf = (png_bytep) buf;
user.len = (png_size_t) len;
png_set_read_fn(rp, &user, png_user_read);
// Enable the default PNG error handler.
if (setjmp(png_jmpbuf(rp)) == 0)
{
// Read the PNG header.
png_read_png(rp, ip, PNG_TRANSFORM_EXPAND |
PNG_TRANSFORM_PACKING |
PNG_TRANSFORM_STRIP_16 |
PNG_TRANSFORM_SWAP_ENDIAN, 0);
// Extract image properties.
w = GLsizei(png_get_image_width (rp, ip));
h = GLsizei(png_get_image_height(rp, ip));
c = GLsizei(png_get_channels (rp, ip));
p.resize(w * h * c);
// Read the pixel data.
if ((bp = png_get_rows(rp, ip)))
for (GLsizei i = 0, j = h - 1; i < h; ++i, --j)
memcpy(&p[w * c * i], bp[j], (w * c));
}
// Release all resources.
png_destroy_read_struct(&rp, &ip, 0);
}
开发者ID:rlk,项目名称:thumb,代码行数:54,代码来源:ogl-texture.cpp
示例14: grf_image_read_png
GrfArray* grf_image_read_png(const char* filename){
png_structp png_ptr;
png_infop info_ptr;
unsigned char header[8];
FILE* infile = fopen(filename, "rb");
if(!infile)
abort_("[read_png_file] File %s could not be opened for reading", filename);
fread(header, 1, 8, infile);
if(png_sig_cmp(header, 0, 8))
abort_("[read_png_file] File %s is not recognized as a PNG file", filename);
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if(!png_ptr)
abort_("[read_png_file] png_create_read_struct failed");
info_ptr = png_create_info_struct(png_ptr);
if(!info_ptr)
abort_("[read_png_file] png_create_info_struct failed");
if(setjmp(png_jmpbuf(png_ptr)))
abort_("[read_png_file] Error during init_io");
png_init_io(png_ptr, infile);
png_set_sig_bytes(png_ptr, 8);
png_read_info(png_ptr, info_ptr);
uint32_t* size = malloc(sizeof(uint32_t) * 3);
size[0] = png_get_image_height(png_ptr, info_ptr);
size[1] = png_get_image_width(png_ptr, info_ptr);
size[2] = png_get_channels(png_ptr, info_ptr);
uint8_t bit_depth = png_get_bit_depth(png_ptr, info_ptr);
GrfDataType type;
switch (bit_depth) {
case 16:
type = GRF_UINT16; break;
default:
type = GRF_UINT8; break;
}
GrfArray* array = grf_array_new_with_size_type(3, size, type);
png_read_update_info(png_ptr, info_ptr);
// Read file
if(setjmp(png_jmpbuf(png_ptr))) abort_("[read_png_file] Error during read_image");
uint8_t**buffer = (uint8_t**)malloc(sizeof(uint8_t*) * size[0]);
size_t row_stride = png_get_rowbytes(png_ptr, info_ptr);
uint32_t i;
for(i = 0; i < size[0]; i++) buffer[i] = array->data_uint8 + row_stride * i;
png_read_image(png_ptr, buffer);
fclose(infile);
free(buffer);
return array;
}
开发者ID:grafeo,项目名称:grafeo,代码行数:53,代码来源:image.c
示例15: image_from_png
struct image* image_from_png(const unsigned char* data, size_t sz) {
/* Check file data header */
if (png_sig_cmp(data, 0, 8)) {
set_last_asset_load_error("Incorrect png header");
return 0;
}
/* Allocate needed structures */
png_struct* png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
png_info* info = png_create_info_struct(png);
png_info* end_info = png_create_info_struct(png);
/* Register custom reader function */
struct png_read_callback_data cbdata;
cbdata.src_buf = (unsigned char*)data;
cbdata.sz = sz;
png_set_read_fn(png, (void*)&cbdata, png_read_callback_fn);
/* Read image info */
png_set_sig_bytes(png, 0);
png_read_info(png, info);
/* Gather image info */
int width = png_get_image_width(png, info);
int height = png_get_image_height(png, info);
/* Bits per CHANNEL not per pixel */
/* int bit_depth = png_get_bit_depth(png, info); */
int channels = png_get_channels(png, info);
/* Image to be returned */
struct image* im = image_blank(width, height, channels);
/* Read by row */
png_byte** row_ptrs = malloc(height * sizeof(png_byte*));
const size_t stride = png_get_rowbytes(png, info);
for (int i = 0; i < height; ++i) {
int q = (height - i - 1) * stride;
row_ptrs[i] = im->data + q;
}
png_read_image(png, row_ptrs);
free(row_ptrs);
/* Free allocated structures */
png_destroy_read_struct(0, 0, &end_info);
png_destroy_read_struct(0, &info, 0);
png_destroy_read_struct(&png, 0, 0);
/* Return read image */
return im;
}
开发者ID:ScaryBoxStudios,项目名称:TheRoom,代码行数:50,代码来源:pngload.c
示例16: png_create_read_struct
struct image *read_png(char *s, int len) {
png_structp png_ptr;
png_infop info_ptr;
struct read_state state;
state.base = s;
state.off = 0;
state.len = len;
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, fail, fail, fail);
if (png_ptr == NULL) {
fprintf(stderr, "PNG init failed\n");
exit(EXIT_FAILURE);
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
fprintf(stderr, "PNG init failed\n");
exit(EXIT_FAILURE);
}
png_set_read_fn(png_ptr, &state, user_read_data);
png_set_sig_bytes(png_ptr, 0);
png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_EXPAND, NULL);
png_uint_32 width, height;
int bit_depth;
int color_type, interlace_type;
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL);
struct image *i = malloc(sizeof(struct image));
i->width = width;
i->height = height;
i->depth = png_get_channels(png_ptr, info_ptr);
i->buf = malloc(i->width * i->height * i->depth);
unsigned int row_bytes = png_get_rowbytes(png_ptr, info_ptr);
png_bytepp row_pointers = png_get_rows(png_ptr, info_ptr);
int n;
for (n = 0; n < i->height; n++) {
memcpy(i->buf + row_bytes * n, row_pointers[n], row_bytes);
}
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return i;
}
开发者ID:ericfischer,项目名称:colorwheel,代码行数:49,代码来源:simulate.c
示例17: image_png_read_header
int image_png_read_header(MediaScanImage *i, MediaScanResult *r) {
int x;
PNGData *p = malloc(sizeof(PNGData));
i->_png = (void *)p;
LOG_MEM("new PNGData @ %p\n", i->_png);
p->buf = (Buffer *)r->_buf;
p->fp = r->_fp;
p->path = r->path;
p->png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp) p, image_png_error, image_png_warning);
if (!p->png_ptr)
FATAL("Could not initialize libpng\n");
p->info_ptr = png_create_info_struct(p->png_ptr);
if (!p->info_ptr) {
png_destroy_read_struct(&p->png_ptr, (png_infopp) NULL, (png_infopp) NULL);
FATAL("Could not initialize libpng\n");
}
if (setjmp(png_jmpbuf(p->png_ptr))) {
image_png_destroy(i);
return 0;
}
png_set_read_fn(p->png_ptr, p, image_png_read_buf);
png_read_info(p->png_ptr, p->info_ptr);
i->width = png_get_image_width(p->png_ptr, p->info_ptr);
i->height = png_get_image_height(p->png_ptr, p->info_ptr);
i->channels = png_get_channels(p->png_ptr, p->info_ptr);
i->has_alpha = 1;
r->mime_type = MIME_IMAGE_PNG;
// Match with DLNA profile
// DLNA does not support interlaced images
if (png_get_interlace_type(p->png_ptr, p->info_ptr) == PNG_INTERLACE_NONE) {
for (x = 0; png_profiles_mapping[x].profile; x++) {
if (i->width <= png_profiles_mapping[x].max_width && i->height <= png_profiles_mapping[x].max_height) {
r->dlna_profile = png_profiles_mapping[x].profile->id;
break;
}
}
}
return 1;
}
开发者ID:chincheta0815,项目名称:libmediascan,代码行数:48,代码来源:image_png.c
示例18: write_scanline
static VALUE
write_scanline(VALUE scan_line, png_structp png_ptr, png_infop info_ptr)
{
png_uint_32 width;
png_byte components;
if (TYPE(scan_line) != T_STRING)
scan_line = rb_obj_as_string(scan_line);
width = png_get_image_width(png_ptr, info_ptr);
components = png_get_channels(png_ptr, info_ptr);
if ((png_uint_32)RSTRING_LEN(scan_line) != width * components)
rb_raise(rb_eRuntimeError, "Scanline has a bad size. Expected %d * %d but got %d.",
(int)width, (int)components, (int)RSTRING_LEN(scan_line));
png_write_row(png_ptr, (png_bytep)RSTRING_PTR(scan_line));
return Qnil;
}
开发者ID:ender672,项目名称:axon,代码行数:18,代码来源:png.c
示例19: png_get_IHDR
QImage::Format QPngHandlerPrivate::readImageFormat()
{
QImage::Format format = QImage::Format_Invalid;
png_uint_32 width, height;
int bit_depth, color_type;
png_colorp palette;
int num_palette;
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0);
if (color_type == PNG_COLOR_TYPE_GRAY) {
// Black & White or 8-bit grayscale
if (bit_depth == 1 && png_get_channels(png_ptr, info_ptr) == 1) {
format = QImage::Format_Mono;
} else if (bit_depth == 16 && png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
format = QImage::Format_ARGB32;
} else {
format = QImage::Format_Indexed8;
}
} else if (color_type == PNG_COLOR_TYPE_PALETTE
&& png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette)
&& num_palette <= 256)
{
// 1-bit and 8-bit color
if (bit_depth != 1)
png_set_packing(png_ptr);
png_read_update_info(png_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0);
format = bit_depth == 1 ? QImage::Format_Mono : QImage::Format_Indexed8;
} else {
// 32-bit
if (bit_depth == 16)
png_set_strip_16(png_ptr);
format = QImage::Format_ARGB32;
// Only add filler if no alpha, or we can get 5 channel data.
if (!(color_type & PNG_COLOR_MASK_ALPHA)
&& !png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
// We want 4 bytes, but it isn't an alpha channel
format = QImage::Format_RGB32;
}
}
return format;
}
开发者ID:ghjinlei,项目名称:qt5,代码行数:43,代码来源:qpnghandler.cpp
示例20: setformat_rgba8
void setformat_rgba8(
png_structp png, png_infop info,
int bitdepth, int colortype )
{
double gamma;
if( png_get_gAMA( png, info, &gamma ) )
{
png_set_gamma( png, 2.2, gamma );
}
else
{
png_set_gamma( png, 2.2, 0.45455 );
}
if( colortype == PNG_COLOR_TYPE_PALETTE )
{
png_set_palette_to_rgb( png );
}
if( colortype == PNG_COLOR_TYPE_GRAY && bitdepth < 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 );
}
else
{
int channels = png_get_channels( png, info );
if( channels == 1 || channels == 3 )
{
png_set_add_alpha( png, 255, PNG_FILLER_AFTER );
}
}
if( colortype == PNG_COLOR_TYPE_GRAY ||
colortype == PNG_COLOR_TYPE_GRAY_ALPHA )
{
png_set_gray_to_rgb( png );
}
if( bitdepth == 16 )
{
png_set_scale_16( png );
}
}
开发者ID:delfigamer,项目名称:mist,代码行数:43,代码来源:pngreader.cpp
注:本文中的png_get_channels函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论