本文整理汇总了C++中png_free_data函数的典型用法代码示例。如果您正苦于以下问题:C++ png_free_data函数的具体用法?C++ png_free_data怎么用?C++ png_free_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了png_free_data函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: png_set_rows
void PNGAPI
png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
{
png_debug1(1, "in %s storage function\n", "rows");
if (png_ptr == NULL || info_ptr == NULL)
return;
if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
info_ptr->row_pointers = row_pointers;
if(row_pointers)
info_ptr->valid |= PNG_INFO_IDAT;
}
开发者ID:AlexOteiza,项目名称:n64ios,代码行数:14,代码来源:pngset.c
示例2: png_write_end
bool PNGWriter::write_end()
{
if (setjmp(png_jmpbuf(png_ptr)))
return false;
png_write_end(png_ptr, NULL);
// cleanup heap allocation
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
fclose(fp);
return true;
}
开发者ID:chrisyeshi,项目名称:ExMage,代码行数:14,代码来源:PNGWriter.cpp
示例3: fopen
void PNGImage::saveImage(const char* outpath) {
int error_code = 0;
FILE* file_descriptor = nullptr;
png_structp png_ptr = nullptr;
png_infop info_ptr = nullptr;
png_bytep row = nullptr;
file_descriptor = fopen(outpath, "wb");
if (file_descriptor == nullptr) { error_code = 101; goto ERROR_PNG_write; }
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
if (png_ptr == nullptr) { error_code = 10; goto ERROR_PNG_write; }
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == nullptr) { error_code = 5; goto ERROR_PNG_write; }
if (setjmp(png_jmpbuf(png_ptr))) { error_code = 6; goto ERROR_PNG_write; }
png_init_io(png_ptr, file_descriptor);
// Write header (8 bit colour depth)
png_set_IHDR(png_ptr, info_ptr, m_width, m_height,
8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_write_info(png_ptr, info_ptr);
// Allocate memory for one row (3 bytes per pixel - RGB)
row = (png_bytep) malloc(3 * m_width * sizeof(png_byte));
for (int y = 0; y < m_height; ++y) {
for (int x = 0; x < m_width; ++x) {
setRGB(&(row[x * 3]), m_buffer[y * m_width + x]);
}
png_write_row(png_ptr, row);
}
png_write_end(png_ptr, nullptr);
ERROR_PNG_write:
if (error_code != 0) {
m_error_code = error_code;
ERR("Error while writing PNG file: %s, code %i", outpath, m_error_code);
}
if (file_descriptor != nullptr) fclose(file_descriptor);
if (info_ptr != nullptr) png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
if (png_ptr != nullptr) png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
if (row != nullptr) free(row);
}
开发者ID:duplyakin,项目名称:CppCourse,代码行数:48,代码来源:image.cpp
示例4: png_set_iCCP
void PNGAPI
png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
png_const_charp name, int compression_type,
png_const_bytep profile, png_uint_32 proflen)
{
png_charp new_iccp_name;
png_bytep new_iccp_profile;
png_size_t length;
png_debug1(1, "in %s storage function", "iCCP");
if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
return;
length = png_strlen(name)+1;
new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length);
if (new_iccp_name == NULL)
{
png_warning(png_ptr, "Insufficient memory to process iCCP chunk");
return;
}
png_memcpy(new_iccp_name, name, length);
new_iccp_profile = (png_bytep)png_malloc_warn(png_ptr, proflen);
if (new_iccp_profile == NULL)
{
png_free (png_ptr, new_iccp_name);
png_warning(png_ptr,
"Insufficient memory to process iCCP profile");
return;
}
png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
info_ptr->iccp_proflen = proflen;
info_ptr->iccp_name = new_iccp_name;
info_ptr->iccp_profile = new_iccp_profile;
/* Compression is always zero but is here so the API and info structure
* does not have to change if we introduce multiple compression types
*/
info_ptr->iccp_compression = (png_byte)compression_type;
info_ptr->free_me |= PNG_FREE_ICCP;
info_ptr->valid |= PNG_INFO_iCCP;
}
开发者ID:robn,项目名称:pioneer-thirdparty,代码行数:48,代码来源:pngset.c
示例5: write_png
static void write_png(const char *filename, bitmap_t bitmap)
{
int j;
FILE *png;
png_structp png_ptr;
png_infop info_ptr;
png = open_binary_write(filename, "write_png");
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL)
{
fprintf(stderr, "write_png(): can't create write structure\n");
exit(1);
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
{
fprintf(stderr, "write_png(): can't create info structure\n");
exit (1);
}
if (setjmp(png_jmpbuf(png_ptr)))
{
fprintf(stderr, "write_png(): can't create png\n");
exit (1);
}
png_init_io(png_ptr, png);
png_set_IHDR(png_ptr, info_ptr, bitmap.width, bitmap.height,
8, PNG_COLOR_TYPE_GRAY, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
/* --- write png */
png_write_info(png_ptr, info_ptr);
for ( j = 0; j < bitmap.height; j++ )
png_write_row(png_ptr, bitmap.data[j]);
png_write_end(png_ptr, NULL);
/* --- */
fclose(png);
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
return;
}
开发者ID:pgajdos,项目名称:fontinfo,代码行数:48,代码来源:img_png.c
示例6: png_info_destroy
/* This is an internal routine to free any memory that the info struct is
* pointing to before re-using it or freeing the struct itself. Recall
* that png_free() checks for NULL pointers for us.
*/
void
png_info_destroy(png_structp png_ptr, png_infop info_ptr)
{
png_debug(1, "in png_info_destroy\n");
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
if (png_ptr->num_chunk_list)
{
png_free(png_ptr, png_ptr->chunk_list);
png_ptr->num_chunk_list=0;
}
#endif
png_info_init(info_ptr);
}
开发者ID:svn2github,项目名称:htmldoc,代码行数:21,代码来源:png.c
示例7: create_directory
void MapEditor::finalise_lightmap() {
delete compile_thread;
compile_thread = 0;
/* write PNG */
create_directory("maps", home_workdir);
std::string filename = home_workdir + dir_separator +
"maps" + dir_separator + wmap->get_name() + ".lmp";
FILE *f = fopen(filename.c_str(), "wb");
if (!f) {
show_messagebox(Gui::MessageBoxIconError, "Light Map",
"Saving failed: " + std::string(strerror(errno)));
return;
}
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
png_infop info_ptr = png_create_info_struct(png_ptr);
png_init_io(png_ptr, f);
png_set_IHDR(png_ptr, info_ptr, lightmap_w, lightmap_h, 8, PNG_COLOR_TYPE_RGB_ALPHA,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_write_info(png_ptr, info_ptr);
/* delete image after writing each row */
for (int y = 0; y < lightmap_h; y++) {
png_write_row(png_ptr, lightmap[y]);
delete[] lightmap[y];
}
delete[] lightmap;
/* close file */
png_write_end(png_ptr, 0);
if (info_ptr) {
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
}
if (png_ptr) {
png_destroy_write_struct(&png_ptr, &info_ptr);
}
fclose(f);
if (wmap) {
wmap->create_lightmap();
}
pop_window();
}
开发者ID:SuperNascher,项目名称:goatattack,代码行数:46,代码来源:MapEditorLightmap.cpp
示例8: png_info_destroy
/* This is an internal routine to free any memory that the info struct is
* pointing to before re-using it or freeing the struct itself. Recall
* that png_free() checks for NULL pointers for us.
*/
void /* PRIVATE */
png_info_destroy(png_structp png_ptr, png_infop info_ptr)
{
png_debug(1, "in png_info_destroy\n");
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
if (png_ptr->num_chunk_list)
{
png_free(png_ptr, png_ptr->chunk_list);
png_ptr->chunk_list=NULL;
png_ptr->num_chunk_list=0;
}
#endif
png_info_init_3(&info_ptr, png_sizeof(png_info));
}
开发者ID:bubbg,项目名称:lambdanative,代码行数:22,代码来源:png.c
示例9: png_set_PLTE
void PNGAPI
png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
png_const_colorp palette, int num_palette)
{
png_debug1(1, "in %s storage function", "PLTE");
if (png_ptr == NULL || info_ptr == NULL)
return;
if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
{
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
png_error(png_ptr, "Invalid palette length");
else
{
png_warning(png_ptr, "Invalid palette length");
return;
}
}
/* It may not actually be necessary to set png_ptr->palette here;
* we do it for backward compatibility with the way the png_handle_tRNS
* function used to do the allocation.
*/
png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
/* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
* of num_palette entries, in case of an invalid PNG file that has
* too-large sample values.
*/
png_ptr->palette = (png_colorp)png_calloc(png_ptr,
PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
info_ptr->palette = png_ptr->palette;
info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
info_ptr->free_me |= PNG_FREE_PLTE;
info_ptr->valid |= PNG_INFO_PLTE;
}
开发者ID:robn,项目名称:pioneer-thirdparty,代码行数:43,代码来源:pngset.c
示例10: png_set_hIST
void PNGAPI
png_set_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
png_const_uint_16p hist)
{
int i;
png_debug1(1, "in %s storage function", "hIST");
if (png_ptr == NULL || info_ptr == NULL)
return;
if (info_ptr->num_palette == 0 || info_ptr->num_palette
> PNG_MAX_PALETTE_LENGTH)
{
png_warning(png_ptr,
"Invalid palette size, hIST allocation skipped");
return;
}
png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
/* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in
* version 1.2.1
*/
info_ptr->hist = png_voidcast(png_uint_16p, png_malloc_warn(png_ptr,
PNG_MAX_PALETTE_LENGTH * (sizeof (png_uint_16))));
if (info_ptr->hist == NULL)
{
png_warning(png_ptr, "Insufficient memory for hIST chunk data");
return;
}
info_ptr->free_me |= PNG_FREE_HIST;
for (i = 0; i < info_ptr->num_palette; i++)
info_ptr->hist[i] = hist[i];
info_ptr->valid |= PNG_INFO_hIST;
}
开发者ID:15521054523,项目名称:fis3,代码行数:42,代码来源:pngset.c
示例11: pngstdout
static void
pngstdout(XImage *img)
{
png_structp png_struct_p;
png_infop png_info_p;
void (*convert)(unsigned char *, unsigned char *, XImage *);
unsigned char *drow = NULL, *srow;
int h;
png_struct_p = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL,
NULL);
png_info_p = png_create_info_struct(png_struct_p);
if(!png_struct_p || !png_info_p || setjmp(png_jmpbuf(png_struct_p)))
die("failed to initialize libpng");
png_init_io(png_struct_p, stdout);
png_set_IHDR(png_struct_p, png_info_p, img->width, img->height, 8,
PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_write_info(png_struct_p, png_info_p);
srow = (unsigned char *)img->data;
drow = calloc(1, img->width * 4); /* output RGBA */
if(!drow)
die("Can't calloc");
if(img->byte_order == LSBFirst)
convert = convertrow_lsb;
else
convert = convertrow_msb;
for(h = 0; h < img->height; h++) {
convert(drow, srow, img);
srow += img->bytes_per_line;
png_write_row(png_struct_p, drow);
}
png_write_end(png_struct_p, NULL);
free(drow);
png_free_data(png_struct_p, png_info_p, PNG_FREE_ALL, -1);
png_destroy_write_struct(&png_struct_p, NULL);
}
开发者ID:josudoey,项目名称:c,代码行数:42,代码来源:x11shot2.c
示例12: png_set_tRNS
void PNGAPI
png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
png_bytep trans, int num_trans, png_color_16p trans_values)
{
png_debug1(1, "in %s storage function\n", "tRNS");
if (png_ptr == NULL || info_ptr == NULL)
return;
if (trans != NULL)
{
/*
* It may not actually be necessary to set png_ptr->trans here;
* we do it for backward compatibility with the way the png_handle_tRNS
* function used to do the allocation.
*/
#ifdef PNG_FREE_ME_SUPPORTED
png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
#endif
/* Changed from num_trans to 256 in version 1.2.1 */
png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
(png_uint_32)256);
png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_TRNS;
#else
png_ptr->flags |= PNG_FLAG_FREE_TRNS;
#endif
}
if (trans_values != NULL)
{
png_memcpy(&(info_ptr->trans_values), trans_values,
sizeof(png_color_16));
if (num_trans == 0)
num_trans = 1;
}
info_ptr->num_trans = (png_uint_16)num_trans;
info_ptr->valid |= PNG_INFO_tRNS;
}
开发者ID:AlexOteiza,项目名称:n64ios,代码行数:39,代码来源:pngset.c
示例13: png_set_hIST
void PNGAPI
png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
{
int i;
png_debug1(1, "in %s storage function\n", "hIST");
if (png_ptr == NULL || info_ptr == NULL)
return;
if (info_ptr->num_palette == 0)
{
png_warning(png_ptr,
"Palette size 0, hIST allocation skipped.");
return;
}
#ifdef PNG_FREE_ME_SUPPORTED
png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
#endif
/* Changed from info->num_palette to 256 in version 1.2.1 */
png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
(png_uint_32)(256 * sizeof (png_uint_16)));
if (png_ptr->hist == NULL)
{
png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
return;
}
for (i = 0; i < info_ptr->num_palette; i++)
png_ptr->hist[i] = hist[i];
info_ptr->hist = png_ptr->hist;
info_ptr->valid |= PNG_INFO_hIST;
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_HIST;
#else
png_ptr->flags |= PNG_FLAG_FREE_HIST;
#endif
}
开发者ID:AlexOteiza,项目名称:n64ios,代码行数:38,代码来源:pngset.c
示例14: get_text
void
get_text(struct PNGImage *png)
{
png_text *text;
int i, numtxts, numremoved;
png_get_text(png->png, png->info, &text, &numtxts);
for (i = 0; i < numtxts; i++) {
if (strcmp(text[i].key, "h") == 0 && !*text[i].text) {
png->horizontal = true;
png_free_data(png->png, png->info, PNG_FREE_TEXT, i);
} else if (strcmp(text[i].key, "x") == 0) {
png->trim = strtoul(text[i].text, NULL, 0);
png_free_data(png->png, png->info, PNG_FREE_TEXT, i);
} else if (strcmp(text[i].key, "t") == 0) {
png->mapfile = text[i].text;
png_free_data(png->png, png->info, PNG_FREE_TEXT, i);
} else if (strcmp(text[i].key, "T") == 0 && !*text[i].text) {
png->mapout = true;
png_free_data(png->png, png->info, PNG_FREE_TEXT, i);
} else if (strcmp(text[i].key, "p") == 0) {
png->palfile = text[i].text;
png_free_data(png->png, png->info, PNG_FREE_TEXT, i);
} else if (strcmp(text[i].key, "P") == 0 && !*text[i].text) {
png->palout = true;
png_free_data(png->png, png->info, PNG_FREE_TEXT, i);
}
}
/* TODO: Remove this and simply change the warning function not to warn instead. */
for (i = 0, numremoved = 0; i < numtxts; i++) {
if (text[i].key == NULL) {
numremoved++;
}
text[i].key = text[i + numremoved].key;
text[i].text = text[i + numremoved].text;
text[i].compression = text[i + numremoved].compression;
}
png_set_text(png->png, png->info, text, numtxts - numremoved);
}
开发者ID:kmeisthax,项目名称:rgbds,代码行数:40,代码来源:makepng.c
示例15: 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
示例16: png_free_data
void PNGAPI
png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
int num)
{
png_debug(1, "in png_free_data\n");
if (png_ptr == NULL || info_ptr == NULL)
return;
#if defined(PNG_TEXT_SUPPORTED)
/* free text item num or (if num == -1) all text items */
#ifdef PNG_FREE_ME_SUPPORTED
if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
#else
if (mask & PNG_FREE_TEXT)
#endif
{
if (num != -1)
{
if (info_ptr->text && info_ptr->text[num].key)
{
png_free(png_ptr, info_ptr->text[num].key);
info_ptr->text[num].key = NULL;
}
}
else
{
int i;
for (i = 0; i < info_ptr->num_text; i++)
png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
png_free(png_ptr, info_ptr->text);
info_ptr->text = NULL;
info_ptr->num_text=0;
}
}
#endif
#if defined(PNG_tRNS_SUPPORTED)
/* free any tRNS entry */
#ifdef PNG_FREE_ME_SUPPORTED
if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
#else
if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
#endif
{
png_free(png_ptr, info_ptr->trans);
info_ptr->valid &= ~PNG_INFO_tRNS;
#ifndef PNG_FREE_ME_SUPPORTED
png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
#endif
info_ptr->trans = NULL;
}
#endif
#if defined(PNG_sCAL_SUPPORTED)
/* free any sCAL entry */
#ifdef PNG_FREE_ME_SUPPORTED
if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
#else
if (mask & PNG_FREE_SCAL)
#endif
{
#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
png_free(png_ptr, info_ptr->scal_s_width);
png_free(png_ptr, info_ptr->scal_s_height);
info_ptr->scal_s_width = NULL;
info_ptr->scal_s_height = NULL;
#endif
info_ptr->valid &= ~PNG_INFO_sCAL;
}
#endif
#if defined(PNG_pCAL_SUPPORTED)
/* free any pCAL entry */
#ifdef PNG_FREE_ME_SUPPORTED
if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
#else
if (mask & PNG_FREE_PCAL)
#endif
{
png_free(png_ptr, info_ptr->pcal_purpose);
png_free(png_ptr, info_ptr->pcal_units);
info_ptr->pcal_purpose = NULL;
info_ptr->pcal_units = NULL;
if (info_ptr->pcal_params != NULL)
{
int i;
for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
{
png_free(png_ptr, info_ptr->pcal_params[i]);
info_ptr->pcal_params[i]=NULL;
}
png_free(png_ptr, info_ptr->pcal_params);
info_ptr->pcal_params = NULL;
}
info_ptr->valid &= ~PNG_INFO_pCAL;
}
#endif
#if defined(PNG_iCCP_SUPPORTED)
/* free any iCCP entry */
//.........这里部分代码省略.........
开发者ID:bubbg,项目名称:lambdanative,代码行数:101,代码来源:png.c
示例17: SavePng
void SavePng(const Image<unsigned char>& image, const pangolin::PixelFormat& fmt, const std::string& filename, bool top_line_first)
{
PANGOLIN_UNUSED(image);
PANGOLIN_UNUSED(filename);
PANGOLIN_UNUSED(top_line_first);
// Check image has supported bit depth
for(unsigned int i=1; i < fmt.channels; ++i) {
if( fmt.channel_bits[i] != fmt.channel_bits[0] ) {
throw std::runtime_error("PNG Saving only supported for images where each channel has the same bit depth.");
}
}
#ifdef HAVE_PNG
FILE *fp;
png_structp png_ptr;
png_infop info_ptr;
// Open file for writing (binary mode)
fp = fopen(filename.c_str(), "wb");
if (fp == NULL) {
throw std::runtime_error( "PNG Error: Could not open file '" + filename + "' for writing" );
}
// Initialize write structure
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) {
fclose(fp);
throw std::runtime_error( "PNG Error: Could not allocate write struct." );
}
// Initialize info structure
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
fclose(fp);
throw std::runtime_error( "PNG Error: Could not allocate info struct." );
}
// Setup Exception handling
if (setjmp(png_jmpbuf(png_ptr))) {
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
fclose(fp);
throw std::runtime_error( "PNG Error: Error during png creation." );
}
png_init_io(png_ptr, fp);
const int bit_depth = fmt.channel_bits[0];
int colour_type;
switch (fmt.channels) {
case 1: colour_type = PNG_COLOR_TYPE_GRAY; break;
case 2: colour_type = PNG_COLOR_TYPE_GRAY_ALPHA; break;
case 3: colour_type = PNG_COLOR_TYPE_RGB; break;
case 4: colour_type = PNG_COLOR_TYPE_RGBA; break;
default:
throw std::runtime_error( "PNG Error: unexpected image channel number");
}
// Write header
png_set_IHDR(
png_ptr, info_ptr, (png_uint_32)image.w, (png_uint_32)image.h, bit_depth, colour_type,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT
);
// Setup rows to write:
std::vector<png_bytep> rows(image.h);
if(top_line_first) {
for (unsigned int y = 0; y< image.h; y++) {
rows[y] = image.ptr + y*image.pitch;
}
}else{
for (unsigned int y = 0; y< image.h; y++) {
rows[y] = image.ptr + (image.h-1-y)*image.pitch;
}
}
png_set_rows(png_ptr,info_ptr, &rows[0]);
// Write image data: switch to little-endian byte order, to match host.
png_write_png(png_ptr,info_ptr, PNG_TRANSFORM_SWAP_ENDIAN, 0);
// Free resources
fclose(fp);
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
#else
throw std::runtime_error("PNG Support not enabled. Please rebuild Pangolin.");
#endif
}
开发者ID:amarburg,项目名称:Pangolin,代码行数:92,代码来源:image_io.cpp
示例18: export_png_rgb_16
int
export_png_rgb_16(image *i, output *output)
{
const char *fn;
int shouldclose;
png_structp png_ptr;
png_infop info_ptr;
png_uint_32 n, x, y, pi;
pixelref src;
colour rgb;
png_bytep pp;
uint16_t *bp;
FILE *fp;
pixel_converter_fn converter;
converter = convert_pixels(i->format, PF_RGB, 16);
if(!converter)
{
fprintf(stderr, "cannot locate a suitable format converter for RGB-16\n");
return -1;
}
fn = output_filename(output, i, &shouldclose);
fp = fopen(fn, "wb");
if(!fp)
{
return -1;
}
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if(!png_ptr)
{
return -1;
}
info_ptr = png_create_info_struct(png_ptr);
if(!info_ptr)
{
return -1;
}
png_init_io(png_ptr, fp);
png_set_IHDR(png_ptr, info_ptr, i->width, i->height, 16, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_write_info(png_ptr, info_ptr);
pp = (png_bytep) malloc(i->width * 3 * sizeof(uint16_t));
bp = (uint16_t *) pp;
src.pixel[0] = i->pixels[0];
src.pixel[1] = i->pixels[1];
src.pixel[2] = i->pixels[2];
for(y = 0, pi = 0; y < i->height; y++)
{
for(n = 0, x = 0; x < i->width; x++, pi++)
{
converter(src, &rgb);
src.pixel[0]++;
src.pixel[1]++;
src.pixel[2]++;
bp[n] = htons(rgb.p.rgb.r);
n++;
bp[n] = htons(rgb.p.rgb.g);
n++;
bp[n] = htons(rgb.p.rgb.b);
n++;
}
png_write_row(png_ptr, pp);
}
png_write_end(png_ptr, NULL);
free(pp);
fclose(fp);
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
png_destroy_write_struct(&png_ptr, NULL);
return 0;
}
开发者ID:nevali,项目名称:tcg,代码行数:70,代码来源:png_rgb_16.c
示例19: opng_reduce_bits
//.........这里部分代码省略.........
src_ptr += src_sample_size;
dest_ptr += dest_sample_size;
}
}
#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
/* Update the ancillary chunk info. */
if (info_ptr->valid & PNG_INFO_bKGD)
{
png_color_16p background = &info_ptr->background;
if (reductions & OPNG_REDUCE_16_TO_8)
{
background->red &= 255;
background->green &= 255;
background->blue &= 255;
background->gray &= 255;
}
if (reductions & OPNG_REDUCE_RGB_TO_GRAY)
background->gray = background->red;
}
#endif
#if defined(PNG_sBIT_SUPPORTED)
if (info_ptr->valid & PNG_INFO_sBIT)
{
png_color_8p sig_bits = &info_ptr->sig_bit;
if (reductions & OPNG_REDUCE_16_TO_8)
{
if (sig_bits->red > 8)
png_ptr->sig_bit.red = sig_bits->red = 8;
if (sig_bits->green > 8)
png_ptr->sig_bit.green = sig_bits->green = 8;
if (sig_bits->blue > 8)
png_ptr->sig_bit.blue = sig_bits->blue = 8;
if (sig_bits->gray > 8)
png_ptr->sig_bit.gray = sig_bits->gray = 8;
if (sig_bits->alpha > 8)
png_ptr->sig_bit.alpha = sig_bits->alpha = 8;
}
if (reductions & OPNG_REDUCE_RGB_TO_GRAY)
{
png_byte max_sig_bit = sig_bits->red;
if (max_sig_bit < sig_bits->green)
max_sig_bit = sig_bits->green;
if (max_sig_bit < sig_bits->blue)
max_sig_bit = sig_bits->blue;
png_ptr->sig_bit.gray = sig_bits->gray = max_sig_bit;
}
}
#endif
if (info_ptr->valid & PNG_INFO_tRNS)
{
png_color_16p trans_color = &info_ptr->trans_color;
if (reductions & OPNG_REDUCE_16_TO_8)
{
if (trans_color->red % 257 == 0 &&
trans_color->green % 257 == 0 &&
trans_color->blue % 257 == 0 &&
trans_color->gray % 257 == 0)
{
trans_color->red &= 255;
trans_color->green &= 255;
trans_color->blue &= 255;
trans_color->gray &= 255;
}
else
{
/* 16-bit tRNS in 8-bit samples: all pixels are 100% opaque. */
png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, -1);
info_ptr->valid &= ~PNG_INFO_tRNS;
}
}
if (reductions & OPNG_REDUCE_RGB_TO_GRAY)
{
if (trans_color->red == trans_color->green ||
trans_color->red == trans_color->blue)
trans_color->gray = trans_color->red;
else
{
/* Non-gray tRNS in grayscale image: all pixels are 100% opaque. */
png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, -1);
info_ptr->valid &= ~PNG_INFO_tRNS;
}
}
}
/* Update the image info. */
png_ptr->rowbytes = info_ptr->rowbytes = 0;
png_ptr->bit_depth = info_ptr->bit_depth = (png_byte)dest_bit_depth;
png_ptr->color_type = info_ptr->color_type = (png_byte)dest_color_type;
png_ptr->channels = info_ptr->channels = (png_byte)dest_channels;
png_ptr->pixel_depth = info_ptr->pixel_depth = (png_byte)dest_pixel_depth;
if (reductions & OPNG_REDUCE_STRIP_ALPHA)
{
png_ptr->transformations &= ~PNG_FILLER;
if (png_ptr->usr_channels > 0)
--png_ptr->usr_channels;
}
return reductions;
}
开发者ID:is00hcw,项目名称:page-speed,代码行数:101,代码来源:opngreduc.c
示例20: opng_reduce_palette
//.........这里部分代码省略.........
last_trans_value = trans_alpha[last_trans_index];
for (k = 0; k <= last_color_index; ++k)
{
if (!is_used[k])
continue;
if (k <= last_trans_index)
{
crt_trans_value = trans_alpha[k];
/* Cannot reduce if different colors have transparency. */
if (crt_trans_value < 255 && palette[k].red != gray_trans.gray)
{
is_gray = 0;
break;
}
}
else
crt_trans_value = 255;
/* Cannot reduce if same color has multiple transparency levels. */
if (palette[k].red == gray_trans.gray &&
crt_trans_value != last_trans_value)
{
is_gray = 0;
break;
}
}
}
/* Initialize result value. */
result = OPNG_REDUCE_NONE;
/* Remove tRNS if possible. */
if ((info_ptr->valid & PNG_INFO_tRNS) && num_trans == 0)
{
png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, -1);
info_ptr->valid &= ~PNG_INFO_tRNS;
result = OPNG_REDUCE_PALETTE_FAST;
}
if (reductions & OPNG_REDUCE_PALETTE_FAST)
{
if (num_palette != last_color_index + 1)
{
/* Reduce PLTE. */
/* hIST is reduced automatically. */
info_ptr->num_palette = (png_uint_16)(last_color_index + 1);
result = OPNG_REDUCE_PALETTE_FAST;
}
if ((info_ptr->valid & PNG_INFO_tRNS) &&
(int)info_ptr->num_trans != num_trans)
{
/* Reduce tRNS. */
info_ptr->num_trans = (png_uint_16)num_trans;
result = OPNG_REDUCE_PALETTE_FAST;
}
}
if (reductions & OPNG_REDUCE_8_TO_4_2_1)
result |= opng_reduce_palette_bits(png_ptr, info_ptr, reductions);
if (info_ptr->bit_depth < 8 || !is_gray)
return result;
/* Reduce palette -> grayscale. */
for (i = 0; i < height; ++i)
for (j = 0; j < width; ++j)
rows[i][j] = palette[rows[i][j]].red;
开发者ID:is00hcw,项目名称:page-speed,代码行数:67,代码来源:opngreduc.c
注:本文中的png_free_data函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论