本文整理汇总了C++中png_get_tRNS函数的典型用法代码示例。如果您正苦于以下问题:C++ png_get_tRNS函数的具体用法?C++ png_get_tRNS怎么用?C++ png_get_tRNS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了png_get_tRNS函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: create_soft_mask
static pdf_obj *
create_soft_mask (png_structp png_ptr, png_infop info_ptr,
png_bytep image_data_ptr, png_uint_32 width, png_uint_32 height)
{
pdf_obj *smask, *dict;
png_bytep smask_data_ptr;
png_bytep trans;
int num_trans;
png_uint_32 i;
if (!png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ||
!png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, NULL)) {
WARN("%s: PNG does not have valid tRNS chunk but tRNS is requested.", PNG_DEBUG_STR);
return NULL;
}
smask = pdf_new_stream(STREAM_COMPRESS);
dict = pdf_stream_dict(smask);
smask_data_ptr = (png_bytep) NEW(width*height, png_byte);
pdf_add_dict(dict, pdf_new_name("Type"), pdf_new_name("XObject"));
pdf_add_dict(dict, pdf_new_name("Subtype"), pdf_new_name("Image"));
pdf_add_dict(dict, pdf_new_name("Width"), pdf_new_number(width));
pdf_add_dict(dict, pdf_new_name("Height"), pdf_new_number(height));
pdf_add_dict(dict, pdf_new_name("ColorSpace"), pdf_new_name("DeviceGray"));
pdf_add_dict(dict, pdf_new_name("BitsPerComponent"), pdf_new_number(8));
for (i = 0; i < width*height; i++) {
png_byte idx = image_data_ptr[i];
smask_data_ptr[i] = (idx < num_trans) ? trans[idx] : 0xff;
}
pdf_add_stream(smask, (char *)smask_data_ptr, width*height);
RELEASE(smask_data_ptr);
return smask;
}
开发者ID:leo-liu,项目名称:ptex-ng,代码行数:34,代码来源:pngimage.c
示例2: _opng_validate_internal
__error__ "PNG_FLAG_FILLER_AFTER" has an unexpected value
#endif
#endif
/*
* Check if it's safe to access libpng's internal structures directly.
* Some fields might have their offsets shifted due to changes in
* libpng's configuration.
*/
static void
_opng_validate_internal(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
png_color_16p background;
#endif
#if defined(PNG_hIST_SUPPORTED)
png_uint_16p hist;
#endif
#if defined(PNG_sBIT_SUPPORTED)
png_color_8p sig_bit;
#endif
png_bytep trans_alpha;
int num_trans;
png_color_16p trans_color;
/* Check info_ptr. */
if (png_get_rows(png_ptr, info_ptr) != info_ptr->row_pointers)
goto error;
#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
if (png_get_bKGD(png_ptr, info_ptr, &background))
if (background != &info_ptr->background)
goto error;
#endif
#if defined(PNG_hIST_SUPPORTED)
if (png_get_hIST(png_ptr, info_ptr, &hist))
if (hist != info_ptr->hist)
goto error;
#endif
#if defined(PNG_sBIT_SUPPORTED)
if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
if (sig_bit != &info_ptr->sig_bit)
goto error;
#endif
if (png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color))
if ((trans_alpha != NULL && (trans_alpha != info_ptr->trans_alpha ||
num_trans != info_ptr->num_trans)) ||
(trans_color != NULL && trans_color != &info_ptr->trans_color))
goto error;
/* Also check png_ptr. It's not much, we're doing what we can... */
if (png_get_compression_buffer_size(png_ptr) != png_ptr->zbuf_size)
goto error;
/* Everything looks okay. */
return;
error:
png_error(png_ptr,
"[internal error] Inconsistent internal structures (incorrect libpng?)");
}
开发者ID:is00hcw,项目名称:page-speed,代码行数:60,代码来源:opngreduc.c
示例3: read
void read()
{
assert(m_png);
assert(m_info);
png_read_info(m_png, m_info);
png_get_IHDR(m_png,
m_info,
& m_width,
& m_height,
reinterpret_cast< int* >(& m_bit_depth),
reinterpret_cast< int* >(& m_color_type),
reinterpret_cast< int* >(& m_interlace_type),
reinterpret_cast< int* >(& m_compression_type),
reinterpret_cast< int* >(& m_filter_type));
if (png_get_valid(m_png, m_info, chunk_PLTE) == chunk_PLTE)
{
png_color* colors = 0;
int count = 0;
png_get_PLTE(m_png, m_info, & colors, & count);
m_palette.assign(colors, colors + count);
}
#ifdef PNG_tRNS_SUPPORTED
if (png_get_valid(m_png, m_info, chunk_tRNS) == chunk_tRNS)
{
if (m_color_type == color_type_palette)
{
int count;
byte* values;
if (png_get_tRNS(m_png, m_info, & values, & count, NULL)
!= PNG_INFO_tRNS)
{
throw error("png_get_tRNS() failed");
}
m_tRNS.assign(values, values + count);
}
}
#endif
#ifdef PNG_gAMA_SUPPORTED
if (png_get_valid(m_png, m_info, chunk_gAMA) == chunk_gAMA)
{
#ifdef PNG_FLOATING_POINT_SUPPORTED
if (png_get_gAMA(m_png, m_info, &m_gamma) != PNG_INFO_gAMA)
{
throw error("png_get_gAMA() failed");
}
#else
png_fixed_point gamma = 0;
if (png_get_gAMA_fixed(m_png, m_info, &gamma) != PNG_INFO_gAMA)
{
throw error("png_get_gAMA_fixed() failed");
}
m_gamma = gamma / 100000.0;
#endif
}
#endif
}
开发者ID:LRacoci,项目名称:ImageEditor,代码行数:60,代码来源:info.hpp
示例4: writeSetup2
void writeSetup2(png_structp png_ptr_write, png_infop info_ptr_write,
png_structp png_ptr_read, png_infop info_ptr_read)
{
/* IHDR */
png_uint_32 width;
png_uint_32 height;
int bit_depth;
int colour_type;
int interlace_method;
int compression_method;
int filter_method;
/* PLTE */
png_colorp palette = NULL;
int palette_size = 0;
/* gAMA */
double gamma;
/* tRNS */
png_bytep trans;
int num_trans;
png_color_16p trans_values;
/* bKGD */
png_color_16p background;
png_get_IHDR(png_ptr_read, info_ptr_read, &width, &height,
&bit_depth, &colour_type, &interlace_method,
&compression_method, &filter_method);
png_set_IHDR(png_ptr_write, info_ptr_write, width, height,
bit_depth, colour_type, interlace_method,
compression_method, filter_method);
if(png_get_valid(png_ptr_read, info_ptr_read, PNG_INFO_PLTE))
{
png_get_PLTE(png_ptr_read, info_ptr_read, &palette, &palette_size);
png_set_PLTE(png_ptr_write, info_ptr_write, palette, palette_size);
}
if(png_get_valid(png_ptr_read, info_ptr_read, PNG_INFO_gAMA))
{
png_get_gAMA(png_ptr_read, info_ptr_read, &gamma);
png_set_gAMA(png_ptr_write, info_ptr_write, gamma);
}
if(png_get_valid(png_ptr_read, info_ptr_read, PNG_INFO_tRNS))
{
png_get_tRNS(png_ptr_read, info_ptr_read, &trans, &num_trans, &trans_values);
png_set_tRNS(png_ptr_write, info_ptr_write, trans, num_trans, trans_values);
}
if(png_get_valid(png_ptr_read, info_ptr_read, PNG_INFO_bKGD))
{
png_get_bKGD(png_ptr_read, info_ptr_read, &background);
png_set_bKGD(png_ptr_write, info_ptr_write, background);
}
}
开发者ID:SorinS,项目名称:fop-miniscribus,代码行数:58,代码来源:InternalFrameStructure.cpp
示例5: png_get_IHDR
bool SkPNGImageDecoder::getBitmapConfig(png_structp png_ptr, png_infop info_ptr,
SkBitmap::Config *configp, bool *hasAlphap, bool *doDitherp,
SkPMColor *theTranspColorp) {
png_uint_32 origWidth, origHeight;
int bit_depth, color_type, interlace_type;
png_get_IHDR(png_ptr, info_ptr, &origWidth, &origHeight, &bit_depth,
&color_type, &interlace_type, int_p_NULL, int_p_NULL);
// check for sBIT chunk data, in case we should disable dithering because
// our data is not truely 8bits per component
if (*doDitherp) {
#if 0
SkDebugf("----- sBIT %d %d %d %d\n", info_ptr->sig_bit.red,
info_ptr->sig_bit.green, info_ptr->sig_bit.blue,
info_ptr->sig_bit.alpha);
#endif
// 0 seems to indicate no information available
if (pos_le(info_ptr->sig_bit.red, SK_R16_BITS) &&
pos_le(info_ptr->sig_bit.green, SK_G16_BITS) &&
pos_le(info_ptr->sig_bit.blue, SK_B16_BITS)) {
*doDitherp = false;
}
}
if (color_type == PNG_COLOR_TYPE_PALETTE) {
bool paletteHasAlpha = hasTransparencyInPalette(png_ptr, info_ptr);
*configp = this->getPrefConfig(kIndex_SrcDepth, paletteHasAlpha);
// now see if we can upscale to their requested config
if (!canUpscalePaletteToConfig(*configp, paletteHasAlpha)) {
*configp = SkBitmap::kIndex8_Config;
}
} else {
png_color_16p transpColor = NULL;
int numTransp = 0;
png_get_tRNS(png_ptr, info_ptr, NULL, &numTransp, &transpColor);
bool valid = png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS);
if (valid && numTransp == 1 && transpColor != NULL) {
/* Compute our transparent color, which we'll match against later.
We don't really handle 16bit components properly here, since we
do our compare *after* the values have been knocked down to 8bit
which means we will find more matches than we should. The real
fix seems to be to see the actual 16bit components, do the
compare, and then knock it down to 8bits ourselves.
*/
if (color_type & PNG_COLOR_MASK_COLOR) {
if (16 == bit_depth) {
*theTranspColorp = SkPackARGB32(0xFF, transpColor->red >> 8,
transpColor->green >> 8, transpColor->blue >> 8);
} else {
*theTranspColorp = SkPackARGB32(0xFF, transpColor->red,
transpColor->green, transpColor->blue);
}
} else { // gray
if (16 == bit_depth) {
开发者ID:ModADroid,项目名称:platform_external_skia,代码行数:57,代码来源:SkImageDecoder_libpng.cpp
示例6: hasTransparencyInPalette
// call only if color_type is PALETTE. Returns true if the ctable has alpha
static bool hasTransparencyInPalette(png_structp png_ptr, png_infop info_ptr) {
png_bytep trans;
int num_trans;
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, NULL);
return num_trans > 0;
}
return false;
}
开发者ID:ModADroid,项目名称:platform_external_skia,代码行数:11,代码来源:SkImageDecoder_libpng.cpp
示例7: opng_realloc_tRNS
/*
* Change the size of the transparency buffer.
* Changing info_ptr->num_trans directly, avoiding reallocation, should
* have been sufficient, but can't be done using the current libpng API.
*/
static void opng_realloc_tRNS(png_structp png_ptr, png_infop info_ptr, int num_trans)
{
png_byte buffer[PNG_MAX_PALETTE_LENGTH];
png_bytep trans_alpha;
int src_num_trans = 0;
png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &src_num_trans, 0);
if (num_trans == src_num_trans)
return;
memcpy(buffer, trans_alpha, (size_t)num_trans);
if (num_trans > src_num_trans)
memset(buffer + src_num_trans, 0, num_trans - src_num_trans);
png_set_tRNS(png_ptr, info_ptr, buffer, num_trans, 0);
}
开发者ID:RamiroCruzo,项目名称:Efficient-Compression-Tool,代码行数:18,代码来源:opngreduc.c
示例8: create_ckey_mask
static pdf_obj *
create_ckey_mask (png_structp png_ptr, png_infop info_ptr)
{
pdf_obj *colorkeys;
png_byte color_type;
png_bytep trans;
int num_trans, i;
png_color_16p colors;
if (!png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ||
!png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, &colors)) {
WARN("%s: PNG does not have valid tRNS chunk!", PNG_DEBUG_STR);
return NULL;
}
colorkeys = pdf_new_array();
color_type = png_get_color_type(png_ptr, info_ptr);
switch (color_type) {
case PNG_COLOR_TYPE_PALETTE:
for (i = 0; i < num_trans; i++) {
if (trans[i] == 0x00) {
pdf_add_array(colorkeys, pdf_new_number(i));
pdf_add_array(colorkeys, pdf_new_number(i));
} else if (trans[i] != 0xff) {
WARN("%s: You found a bug in pngimage.c.", PNG_DEBUG_STR);
}
}
break;
case PNG_COLOR_TYPE_RGB:
pdf_add_array(colorkeys, pdf_new_number(colors->red));
pdf_add_array(colorkeys, pdf_new_number(colors->red));
pdf_add_array(colorkeys, pdf_new_number(colors->green));
pdf_add_array(colorkeys, pdf_new_number(colors->green));
pdf_add_array(colorkeys, pdf_new_number(colors->blue));
pdf_add_array(colorkeys, pdf_new_number(colors->blue));
break;
case PNG_COLOR_TYPE_GRAY:
pdf_add_array(colorkeys, pdf_new_number(colors->gray));
pdf_add_array(colorkeys, pdf_new_number(colors->gray));
break;
default:
WARN("%s: You found a bug in pngimage.c.", PNG_DEBUG_STR);
pdf_release_obj(colorkeys);
colorkeys = NULL;
}
return colorkeys;
}
开发者ID:leo-liu,项目名称:ptex-ng,代码行数:49,代码来源:pngimage.c
示例9: load_png
IMAGE* load_png(int fd)
{
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
png_uint_32 width, height;
int bit_depth, color_type, interlace_type;
png_bytep * row_pointers;
int ckey = -1;
png_color_16 *transv;
IMAGE* image = NULL;
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
NULL,NULL,NULL);
if (png_ptr == NULL) goto err;
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) goto err;
if ( setjmp(png_ptr->jmpbuf)) goto err;
/* Set up the input control */
png_set_read_fn(png_ptr, (void*)fd, png_read_data);
/* Read PNG header info */
png_read_info(png_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
&color_type, &interlace_type, NULL, NULL);
/* tell libpng to strip 16 bit/color files down to 8 bits/color */
png_set_strip_16(png_ptr) ;
/* 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);
/* scale greyscale values to the range 0..255 */
if(color_type == PNG_COLOR_TYPE_GRAY)
png_set_expand(png_ptr);
/* For images with a single "transparent colour", set colour key;
if more than one index has transparency, or if partially transparent
entries exist, use full alpha channel */
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
int num_trans;
unsigned char *trans;
png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,
&transv);
if(color_type == PNG_COLOR_TYPE_PALETTE) {
/* Check if all tRNS entries are opaque except one */
int i, t = -1;
for(i = 0; i < num_trans; i++)
if(trans[i] == 0) {
if(t >= 0)
break;
t = i;
} else if(trans[i] != 255)
break;
if(i == num_trans) {
/* exactly one transparent index */
ckey = t;
} else {
/* more than one transparent index, or translucency */
png_set_expand(png_ptr);
}
} else
ckey = 0; /* actual value will be set later */
}
if ( color_type == PNG_COLOR_TYPE_GRAY_ALPHA )
png_set_gray_to_rgb(png_ptr);
png_read_update_info(png_ptr, info_ptr);
// png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
// &color_type, &interlace_type, NULL, NULL);
image = image_alloc(width,height,bit_depth*info_ptr->channels);
row_pointers = (png_bytep*) alloca(sizeof(png_bytep)*height);
char* p = image->pixels;
int pitch = (width*bit_depth*info_ptr->channels+7)/8;
int i;
for (i = 0; i < height; i++) {
row_pointers[i] = p; p+=pitch;
}
/* Read the entire image in one go */
png_read_image(png_ptr, row_pointers);
if (info_ptr->num_palette > 0) {
COLOR *palette = image->palette;
image->n_palette = info_ptr->num_palette;
for(i=0; i<info_ptr->num_palette; i++) {
palette[i].b = info_ptr->palette[i].blue;
palette[i].g = info_ptr->palette[i].red;
palette[i].r = info_ptr->palette[i].green;
//.........这里部分代码省略.........
开发者ID:BASLQC,项目名称:snes9x-euphoria,代码行数:101,代码来源:imageio.c
示例10: png_create_read_struct_2
Error ImageLoaderPNG::_load_image(void *rf_up,png_rw_ptr p_func,Image *p_image) {
png_structp png;
png_infop info;
//png = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, NULL, NULL);
png = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,_png_error_function,_png_warn_function,(png_voidp)NULL,
_png_malloc_fn,_png_free_fn );
ERR_FAIL_COND_V(!png, ERR_OUT_OF_MEMORY);
info = png_create_info_struct(png);
if (!info) {
png_destroy_read_struct(&png,NULL,NULL);
ERR_PRINT("Out of Memory");
return ERR_OUT_OF_MEMORY;
}
if (setjmp(png_jmpbuf(png))) {
png_destroy_read_struct(&png,NULL,NULL);
ERR_PRINT("PNG Corrupted");
return ERR_FILE_CORRUPT;
}
png_set_read_fn(png,(void*)rf_up,p_func);
png_uint_32 width, height;
int depth, color;
png_read_info(png, info);
png_get_IHDR(png, info, &width, &height, &depth, &color, NULL, NULL, NULL);
png_textp t;
//https://svn.gov.pt/projects/ccidadao/repository/middleware-offline/trunk/_src/eidmw/FreeImagePTEiD/Source/FreeImage/PluginPNG.cpp
//png_get_text(png,info,)
/*
printf("Image width:%i\n", width);
printf("Image Height:%i\n", height);
printf("Bit depth:%i\n", depth);
printf("Color type:%i\n", color);
*/
if (depth<8) { //only bit dept 8 per channel is handled
png_set_packing(png);
};
if (depth > 8) {
png_set_strip_16(png);
png_read_update_info(png, info);
}
int palette_colors = 0;
int palette_components = 0;
int components = 0;
Image::Format fmt;
switch(color) {
case PNG_COLOR_TYPE_GRAY: {
fmt=Image::FORMAT_GRAYSCALE;
components=1;
} break;
case PNG_COLOR_TYPE_GRAY_ALPHA: {
fmt=Image::FORMAT_GRAYSCALE_ALPHA;
components=2;
} break;
case PNG_COLOR_TYPE_RGB: {
fmt=Image::FORMAT_RGB;
components=3;
} break;
case PNG_COLOR_TYPE_RGB_ALPHA: {
fmt=Image::FORMAT_RGBA;
components=4;
} break;
case PNG_COLOR_TYPE_PALETTE: {
int ntrans = 0;
png_get_tRNS(png, info, NULL, &ntrans, NULL);
//printf("transparent colors %i\n", ntrans);
fmt = ntrans > 0 ? Image::FORMAT_INDEXED_ALPHA : Image::FORMAT_INDEXED;
palette_components = ntrans > 0 ? 4 : 3;
components = 1;
png_colorp colors;
png_get_PLTE(png, info, &colors, &palette_colors);
} break;
default: {
//.........这里部分代码省略.........
开发者ID:3miu,项目名称:godot,代码行数:101,代码来源:image_loader_png.cpp
示例11: loadPNG
int loadPNG(ePtr<gPixmap> &result, const char *filename)
{
__u8 header[8];
FILE *fp=fopen(filename, "rb");
if (!fp)
{
// eDebug("couldn't open %s", filename );
return 0;
}
if (!fread(header, 8, 1, fp))
{
eDebug("couldn't read");
fclose(fp);
return 0;
}
if (png_sig_cmp(header, 0, 8))
{
fclose(fp);
return 0;
}
png_structp png_ptr=png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
if (!png_ptr)
{
eDebug("no pngptr");
fclose(fp);
return 0;
}
png_infop info_ptr=png_create_info_struct(png_ptr);
if (!info_ptr)
{
eDebug("no info ptr");
png_destroy_read_struct(&png_ptr, (png_infopp)0, (png_infopp)0);
fclose(fp);
return 0;
}
png_infop end_info = png_create_info_struct(png_ptr);
if (!end_info)
{
eDebug("no end");
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
fclose(fp);
return 0;
}
if (setjmp(png_ptr->jmpbuf))
{
eDebug("das war wohl nix");
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
fclose(fp);
result = 0;
return 0;
}
png_init_io(png_ptr, fp);
png_set_sig_bytes(png_ptr, 8);
png_set_invert_alpha(png_ptr);
png_read_info(png_ptr, info_ptr);
png_uint_32 width, height;
int bit_depth;
int color_type;
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0);
if (color_type == PNG_COLOR_TYPE_GRAY || color_type & PNG_COLOR_MASK_PALETTE)
{
result=new gPixmap(eSize(width, height), bit_depth);
gSurface *surface = result->surface;
png_bytep *rowptr=new png_bytep[height];
for (unsigned int i=0; i<height; i++)
rowptr[i]=((png_byte*)(surface->data))+i*surface->stride;
png_read_rows(png_ptr, rowptr, 0, height);
delete [] rowptr;
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE))
{
png_color *palette;
int num_palette;
png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
if (num_palette)
surface->clut.data=new gRGB[num_palette];
else
surface->clut.data=0;
surface->clut.colors=num_palette;
for (int i=0; i<num_palette; i++)
{
surface->clut.data[i].a=0;
surface->clut.data[i].r=palette[i].red;
surface->clut.data[i].g=palette[i].green;
surface->clut.data[i].b=palette[i].blue;
}
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
{
png_byte *trans;
png_get_tRNS(png_ptr, info_ptr, &trans, &num_palette, 0);
for (int i=0; i<num_palette; i++)
surface->clut.data[i].a=255-trans[i];
//.........这里部分代码省略.........
开发者ID:kakunbsc,项目名称:enigma2.2,代码行数:101,代码来源:epng.cpp
示例12: Load
//.........这里部分代码省略.........
palette[i].rgbBlue = png_palette[i].blue;
}
break;
case PNG_COLOR_TYPE_GRAY:
dib = FreeImage_AllocateHeaderT(header_only, image_type, width, height, pixel_depth);
if(pixel_depth <= 8) {
palette = FreeImage_GetPalette(dib);
palette_entries = 1 << pixel_depth;
for (i = 0; i < palette_entries; i++) {
palette[i].rgbRed =
palette[i].rgbGreen =
palette[i].rgbBlue = (BYTE)((i * 255) / (palette_entries - 1));
}
}
break;
default:
throw FI_MSG_ERROR_UNSUPPORTED_FORMAT;
}
// store the transparency table
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
// array of alpha (transparency) entries for palette
png_bytep trans_alpha = NULL;
// number of transparent entries
int num_trans = 0;
// graylevel or color sample values of the single transparent color for non-paletted images
png_color_16p trans_color = NULL;
png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color);
if((color_type == PNG_COLOR_TYPE_GRAY) && trans_color) {
// single transparent color
if (trans_color->gray < palette_entries) {
BYTE table[256];
memset(table, 0xFF, palette_entries);
table[trans_color->gray] = 0;
FreeImage_SetTransparencyTable(dib, table, palette_entries);
}
} else if((color_type == PNG_COLOR_TYPE_PALETTE) && trans_alpha) {
// transparency table
FreeImage_SetTransparencyTable(dib, (BYTE *)trans_alpha, num_trans);
}
}
// store the background color
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD)) {
// Get the background color to draw transparent and alpha images over.
// 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.
png_color_16p image_background = NULL;
RGBQUAD rgbBkColor;
if (png_get_bKGD(png_ptr, info_ptr, &image_background)) {
rgbBkColor.rgbRed = (BYTE)image_background->red;
rgbBkColor.rgbGreen = (BYTE)image_background->green;
rgbBkColor.rgbBlue = (BYTE)image_background->blue;
rgbBkColor.rgbReserved = 0;
FreeImage_SetBackgroundColor(dib, &rgbBkColor);
开发者ID:elfprince13,项目名称:G3D10,代码行数:67,代码来源:PluginPNG.cpp
示例13: opng_reduce_dirty_alpha
/*Remove RGB components or transparent pixels in RGB+alpha images.
The function returns OPNG_REDUCE_DIRTY_ALPHA if any pixels were cleared.*/
static png_uint_32 opng_reduce_dirty_alpha(png_structp png_ptr, png_infop info_ptr)
{
png_uint_32 result = OPNG_REDUCE_NONE;
png_bytep sample_ptr;
png_uint_32 height, width, j;
int bit_depth, color_type;
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0);
if (bit_depth != 8){
return OPNG_REDUCE_NONE; /* nothing is done in this case */
}
OPNG_ASSERT(!(color_type & PNG_COLOR_MASK_PALETTE));
png_bytepp row_ptr = png_get_rows(png_ptr, info_ptr);
png_byte channels = png_get_channels(png_ptr, info_ptr);
png_bytep alpha_row = (png_bytep)png_malloc(png_ptr, width);
png_row_info row_info;
row_info.width = width;
row_info.rowbytes = 0; /* not used */
row_info.color_type = (png_byte)color_type;
row_info.bit_depth = (png_byte)bit_depth;
row_info.channels = (png_byte)channels;
row_info.pixel_depth = 0; /* not used */
png_color_16p trans_color = 0;
png_get_tRNS(png_ptr, info_ptr, 0, 0, &trans_color);
/* Search for transparent pixels. */
for (unsigned i = 0; i < height; ++i, ++row_ptr)
{
sample_ptr = *row_ptr;
opng_get_alpha_row(&row_info, trans_color, *row_ptr, alpha_row);
//static void opng_get_alpha_row(png_row_infop row_info_ptr, png_color_16p trans_color, png_bytep row, png_bytep alpha_row)
if (color_type & PNG_COLOR_MASK_COLOR)
{
for (j = 0; j < width; ++j, sample_ptr += channels)
{
if (alpha_row[j] == 0)
{
sample_ptr[0] = 0;
sample_ptr[1] = 0;
sample_ptr[2] = 0;
result = OPNG_REDUCE_DIRTY_ALPHA;
}
}
}
else /* grayscale */
{
for (j = 0; j < width; ++j, sample_ptr += channels)
{
if (alpha_row[j] == 0)
{
sample_ptr[0] = 0;
result = OPNG_REDUCE_DIRTY_ALPHA;
}
}
}
}
png_free(png_ptr, alpha_row);
return result;
}
开发者ID:RamiroCruzo,项目名称:Efficient-Compression-Tool,代码行数:68,代码来源:opngreduc.c
示例14: load_png
//.........这里部分代码省略.........
i = !png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK);
if ( i<=0 ) goto fail;
rewind( fp );
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) goto fail;
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
{
png_destroy_read_struct(&png_ptr, NULL, NULL);
goto fail;
}
if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_read_struct(&png_ptr, NULL, NULL);
fclose(fp);
return -1;
}
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, &pwidth, &pheight, &bit_depth, &color_type,
&interlace_type, NULL, NULL);
width = (int) pwidth;
height = (int) pheight;
if ( width > MAX_WIDTH || height > MAX_HEIGHT )
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
fclose(fp);
return TOO_BIG;
}
row_pointers = malloc( sizeof(png_bytep) * height );
if (setjmp(png_jmpbuf(png_ptr))) // If libpng generates an error now, clean up
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
fclose(fp);
free(row_pointers);
return FILE_LIB_ERROR;
}
rgb = NULL;
mess = NULL;
if ( width*height > FILE_PROGRESS ) do_prog = 1;
else do_prog = 0;
if ( stype == 0 )
{
mess = _("Loading PNG image");
rgb = mem_image;
}
if ( stype == 1 )
{
mess = _("Loading clipboard image");
rgb = mem_clipboard;
if ( rgb != NULL ) free( rgb ); // Lose old clipboard
mem_clip_mask_clear(); // Lose old clipboard mask
}
if ( color_type != PNG_COLOR_TYPE_PALETTE || bit_depth>8 ) // RGB PNG file
{
png_set_strip_16(png_ptr);
png_set_gray_1_2_4_to_8(png_ptr);
png_set_palette_to_rgb(png_ptr);
png_set_gray_to_rgb(png_ptr);
if ( stype == 0 )
{
mem_pal_copy( mem_pal, mem_pal_def );
mem_cols = 256;
if ( mem_new( width, height, 3 ) != 0 ) goto file_too_huge;
rgb = mem_image;
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
{
// Image has a transparent index
png_get_tRNS(png_ptr, info_ptr, 0, 0, &trans_rgb);
mem_pal[255].red = trans_rgb->red;
mem_pal[255].green = trans_rgb->green;
mem_pal[255].blue = trans_rgb->blue;
if (color_type == PNG_COLOR_TYPE_GRAY)
{
if ( bit_depth==4 ) i = trans_rgb->gray * 17;
if ( bit_depth==8 ) i = trans_rgb->gray;
if ( bit_depth==16 ) i = trans_rgb->gray >> (bit_depth-8);
mem_pal[255].red = i;
mem_pal[255].green = i;
mem_pal[255].blue = i;
}
mem_xpm_trans = 255;
}
}
开发者ID:guadalinex-archive,项目名称:guadalinex-2005,代码行数:101,代码来源:png.c
示例15: loadPNG
//.........这里部分代码省略.........
png_set_sig_bytes(png_ptr, 8);
png_read_info(png_ptr, info_ptr);
png_uint_32 width, height;
int bit_depth;
int color_type;
int interlace_type;
int channels;
int trns;
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, 0, 0);
channels = png_get_channels(png_ptr, info_ptr);
trns = png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS);
//eDebug("[ePNG] %s: before %dx%dx%dbpcx%dchan coltyp=%d", filename, (int)width, (int)height, bit_depth, channels, color_type);
/*
* gPixmaps use 8 bits per channel. rgb pixmaps are stored as abgr.
* So convert 1,2 and 4 bpc to 8bpc images that enigma can blit
* so add 'empty' alpha channel
* Expand G+tRNS to GA, RGB+tRNS to RGBA
*/
if (bit_depth == 16)
png_set_strip_16(png_ptr);
if (bit_depth < 8)
png_set_packing (png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
png_set_expand_gray_1_2_4_to_8(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY && trns)
png_set_tRNS_to_alpha(png_ptr);
if ((color_type == PNG_COLOR_TYPE_GRAY && trns) || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
png_set_gray_to_rgb(png_ptr);
png_set_bgr(png_ptr);
}
if (color_type == PNG_COLOR_TYPE_RGB) {
if (trns)
png_set_tRNS_to_alpha(png_ptr);
else
png_set_add_alpha(png_ptr, 255, PNG_FILLER_AFTER);
}
if (color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_RGB_ALPHA)
png_set_bgr(png_ptr);
// Update the info structures after the transformations take effect
if (interlace_type != PNG_INTERLACE_NONE)
png_set_interlace_handling(png_ptr); // needed before read_update_info()
png_read_update_info (png_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0);
channels = png_get_channels(png_ptr, info_ptr);
result = new gPixmap(eSize(width, height), bit_depth * channels, accel);
gUnmanagedSurface *surface = result->surface;
png_bytep *rowptr = new png_bytep[height];
for (unsigned int i = 0; i < height; i++)
rowptr[i] = ((png_byte*)(surface->data)) + i * surface->stride;
png_read_image(png_ptr, rowptr);
delete [] rowptr;
int num_palette = -1, num_trans = -1;
if (color_type == PNG_COLOR_TYPE_PALETTE) {
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE)) {
png_color *palette;
png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
if (num_palette)
surface->clut.data = new gRGB[num_palette];
else
surface->clut.data = 0;
surface->clut.colors = num_palette;
for (int i = 0; i < num_palette; i++) {
surface->clut.data[i].a = 0;
surface->clut.data[i].r = palette[i].red;
surface->clut.data[i].g = palette[i].green;
surface->clut.data[i].b = palette[i].blue;
}
if (trns) {
png_byte *trans;
png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, 0);
for (int i = 0; i < num_trans; i++)
surface->clut.data[i].a = 255 - trans[i];
for (int i = num_trans; i < num_palette; i++)
surface->clut.data[i].a = 0;
}
}
else {
surface->clut.data = 0;
surface->clut.colors = 0;
}
surface->clut.start = 0;
}
//eDebug("[ePNG] %s: after %dx%dx%dbpcx%dchan coltyp=%d cols=%d trans=%d", filename, (int)width, (int)height, bit_depth, channels, color_type, num_palette, num_trans);
png_read_end(png_ptr, end_info);
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return 0;
}
开发者ID:hd75hd,项目名称:enigma2,代码行数:101,代码来源:epng.cpp
示例16: input_png_file
void
input_png_file(struct Options opts, struct PNGImage *img)
{
FILE *f;
int i, y, num_trans;
bool has_palette = false;
png_byte *trans_alpha;
png_color_16 *trans_values;
bool *full_alpha;
png_color *palette;
f = fopen(opts.infile, "rb");
if (!f) {
err(1, "Opening input png file '%s' failed", opts.infile);
}
img->png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!img->png) {
errx(1, "Creating png structure failed");
}
img->info = png_create_info_struct(img->png);
if (!img->info) {
errx(1, "Creating png info structure failed");
}
/* Better error handling here? */
if (setjmp(png_jmpbuf(img->png))) {
exit(1);
}
png_init_io(img->png, f);
png_read_info(img->png, img->info);
img->width = png_get_image_width(img->png, img->info);
img->height = png_get_image_height(img->png, img->info);
img->depth = png_get_bit_depth(img->png, img->info);
img->type = png_get_color_type(img->png, img->info);
if (img->type & PNG_COLOR_MASK_ALPHA) {
png_set_strip_alpha(img->png);
}
if (img->depth != depth) {
if (opts.verbose) {
warnx("Image bit depth is not %i (is %i).", depth,
img->depth);
}
}
if (img->type == PNG_COLOR_TYPE_GRAY) {
if (img->depth < 8) {
png_set_expand_gray_1_2_4_to_8(img->png);
}
png_set_gray_to_rgb(img->png);
} else {
if (img->depth < 8) {
png_set_expand_gray_1_2_4_to_8(img->png);
}
has_palette = png_get_PLTE(img->png, img->info, &palette,
&colors);
}
if (png_get_tRNS(img->png, img->info, &trans_alpha, &num_trans,
&trans_values)) {
if (img->type == PNG_COLOR_TYPE_PALETTE) {
full_alpha = malloc(sizeof(bool) * num_trans);
for (i = 0; i < num_trans; i++) {
if (trans_alpha[i] > 0) {
full_alpha[i] = false;
} else {
full_alpha[i] = true;
}
}
for (i = 0; i < num_trans; i++) {
if (full_alpha[i]) {
palette[i].red = 0xFF;
palette[i].green = 0x00;
palette[i].blue = 0xFF;
/*
* Set to the lightest color in the
* palette.
*/
}
}
free(full_alpha);
} else {
/* Set to the lightest color in the image. */
}
png_free_data(img->png, img->info, PNG_FREE_TRNS, -1);
}
if (has_palette) {
/* Make sure palette only has the amount of colors you want. */
} else {
//.........这里部分代码省略.........
开发者ID:kmeisthax,项目名称:rgbds,代码行数:101,代码来源:makepng.c
示例17: OneFrameReader
AFRAMES OneFrameReader(png_structp png_ptr_read, png_infop info_ptr_read,
png_structp png_ptr_write, png_infop info_ptr_write,
png_uint_32 width, png_uint_32 height)
{
/* IHDR */
/* struct data need from background */
AFRAMES pframe;
png_uint_32 garbage;
int bit_depth;
int colour_type;
int interlace_method;
int compression_method;
int filter_method;
/* PLTE */
png_colorp palette = NULL;
int palette_size = 0;
/* gAMA */
double gamma;
/* tRNS */
png_bytep trans;
int num_trans;
png_color_16p trans_values;
/* bKGD */
png_color_16p background;
png_get_IHDR(png_ptr_read, info_ptr_read, &garbage, &garbage,
&bit_depth, &colour_type, &interlace_method,
&compression_method, &filter_method);
png_set_IHDR(png_ptr_write, info_ptr_write, width, height,
bit_depth, colour_type, interlace_method,
compression_method, filter_method);
int r = 0, g = 0, b = 0;
int bpp = bit_depth;
switch (colour_type) {
case PNG_COLOR_TYPE_GRAY : break;
case PNG_COLOR_TYPE_RGB : bpp *= 3; break;
case PNG_COLOR_TYPE_PALETTE : break;
case PNG_COLOR_TYPE_GRAY_ALPHA: bpp *= 2; break;
case PNG_COLOR_TYPE_RGB_ALPHA : bpp *= 4; break;
default:
return pframe;
}
pframe.colortype = colour_type;
pframe.bytedep = bpp;
pframe.pngBG = trans_values;
/////////qDebug() << "### color type " << colour_type << bpp << num_trans;
if(png_get_valid(png_ptr_read, info_ptr_read, PNG_INFO_PLTE))
{
/////////qDebug() << "### PNG_INFO_PLTE";
png_get_PLTE(png_ptr_read, info_ptr_read, &palette, &palette_size);
png_set_PLTE(png_ptr_write, info_ptr_write, palette, palette_size);
}
if(png_get_valid(png_ptr_read, info_ptr_read, PNG_INFO_gAMA))
{
/////////qDebug() << "### PNG_INFO_gAMA";
png_get_gAMA(png_ptr_read, info_ptr_read, &gamma);
png_set_gAMA(png_ptr_write, info_ptr_write, gamma);
}
if(png_get_valid(png_ptr_read, info_ptr_read, PNG_INFO_tRNS))
{
//////////qDebug() << "### PNG_INFO_tRNS";
png_get_tRNS(png_ptr_read, info_ptr_read, &trans, &num_trans, &trans_values);
png_set_tRNS(png_ptr_write, info_ptr_write, trans, num_trans, trans_values);
}
if(png_get_valid(png_ptr_read, info_ptr_read, PNG_INFO_bKGD))
{
////////qDebug() << "### PNG_INFO_bKGD";
png_get_bKGD(png_ptr_read, info_ptr_read, &background);
png_set_bKGD(png_ptr_write, info_ptr_write, background);
png_color_16p bkgd = background;
pframe.pngBG = background;
int r = 0, g = 0, b = 0;
if(colour_type == PNG_COLOR_TYPE_RGB || colour_type == PNG_COLOR_TYPE_RGB_ALPHA) {
r = bkgd->red;
g = bkgd->green;
b = bkgd->blue;
}
//.........这里部分代码省略.........
开发者ID:SorinS,项目名称:fop-miniscribus,代码行数:101,代码来源:apngreader.cpp
示例18: readImage
image_t* readImage(const char* filename)
{
image_t* img;
uint8_t header[8];
size_t cbhead;
FILE* fp;
fp = fopen(filename, "rb");
if (!fp)
{
verbose(1, "Error: Could not open file %s: %s\n",
filename, strerror(errno));
return NULL;
}
cbhead = fread(header, 1, sizeof(header), fp);
if (png_sig_cmp(header, 0, cbhead))
{
verbose(1, "Input file is not a PNG image\n");
fclose(fp);
return NULL;
}
img = malloc(sizeof(*img));
if (!img)
{
verbose(1, "Out of memory reading image\n");
fclose(fp);
return NULL;
}
memset(img, 0, sizeof(*img));
img->png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!img->png_ptr)
{
verbose(1, "png_create_read_struct failed\n");
fclose(fp);
return NULL;
}
img->info_ptr = png_create_info_struct(img->png_ptr);
if (!img->info_ptr)
{
verbose(1, "png_create_info_struct failed\n");
png_destroy_read_struct(&img->png_ptr, NULL, NULL);
fclose(fp);
return NULL;
}
img->end_info = png_create_info_struct(img->png_ptr);
if (!img->end_info)
{
verbose(1, "png_create_info_struct failed\n");
png_destroy_read_struct(&img->png_ptr, &img->info_ptr, NULL);
fclose(fp);
return NULL;
}
if (setjmp(png_jmpbuf(img->png_ptr)))
{
verbose
|
请发表评论