mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
Imported from libpng-1.0.7beta11.tar
This commit is contained in:
119
pngwrite.c
119
pngwrite.c
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngwrite.c - general routines to write a PNG file
|
||||
*
|
||||
* libpng 1.0.6j - May 4, 2000
|
||||
* libpng 1.0.7beta11 - May 6, 2000
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
@@ -21,7 +21,7 @@
|
||||
* write a plain PNG file. If you have long comments, I suggest writing
|
||||
* them in png_write_end(), and compressing them.
|
||||
*/
|
||||
void
|
||||
void PNGAPI
|
||||
png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
png_debug(1, "in png_write_info_before_PLTE\n");
|
||||
@@ -110,7 +110,7 @@ png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
void PNGAPI
|
||||
png_write_info(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
|
||||
@@ -277,7 +277,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
|
||||
* in png_write_info(), do not write them again here. If you have long
|
||||
* comments, I suggest writing them here, and compressing them.
|
||||
*/
|
||||
void
|
||||
void PNGAPI
|
||||
png_write_end(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
png_debug(1, "in png_write_end\n");
|
||||
@@ -378,7 +378,7 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
void
|
||||
void PNGAPI
|
||||
png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
|
||||
{
|
||||
png_debug(1, "in png_convert_from_struct_tm\n");
|
||||
@@ -390,7 +390,7 @@ png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
|
||||
ptime->second = (png_byte)ttime->tm_sec;
|
||||
}
|
||||
|
||||
void
|
||||
void PNGAPI
|
||||
png_convert_from_time_t(png_timep ptime, time_t ttime)
|
||||
{
|
||||
struct tm *tbuf;
|
||||
@@ -402,7 +402,7 @@ png_convert_from_time_t(png_timep ptime, time_t ttime)
|
||||
#endif
|
||||
|
||||
/* Initialize png_ptr structure, and allocate any memory needed */
|
||||
png_structp
|
||||
png_structp PNGAPI
|
||||
png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
png_error_ptr error_fn, png_error_ptr warn_fn)
|
||||
{
|
||||
@@ -412,7 +412,7 @@ png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
}
|
||||
|
||||
/* Alternate initialize png_ptr structure, and allocate any memory needed */
|
||||
png_structp
|
||||
png_structp PNGAPI
|
||||
png_create_write_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)
|
||||
@@ -424,6 +424,7 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
jmp_buf jmpbuf;
|
||||
#endif
|
||||
#endif
|
||||
int i;
|
||||
png_debug(1, "in png_create_write_struct\n");
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if ((png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
|
||||
@@ -456,30 +457,39 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
|
||||
|
||||
/* 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] ||
|
||||
(png_libpng_ver[0] == '0' && user_png_ver[2] < '9'))
|
||||
i=0;
|
||||
do
|
||||
{
|
||||
png_error(png_ptr,
|
||||
"Incompatible libpng version in application and library");
|
||||
}
|
||||
if(user_png_ver[i] != png_libpng_ver[i])
|
||||
png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
|
||||
} while (png_libpng_ver[i++]);
|
||||
|
||||
/* Libpng 1.0.6 was not binary compatible, due to insertion of the
|
||||
info_ptr->free_me member. Note to maintainer: this test can be
|
||||
removed from version 2.0.0 and beyond because the previous test
|
||||
would have already rejected it. */
|
||||
|
||||
if (user_png_ver[4] == '6' && user_png_ver[2] == '0' &&
|
||||
user_png_ver[0] == '1' && user_png_ver[5] == '\0')
|
||||
if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
|
||||
{
|
||||
png_error(png_ptr,
|
||||
"Application must be recompiled; version 1.0.6 was incompatible");
|
||||
}
|
||||
/* 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] == '0' && user_png_ver[2] < '9'))
|
||||
{
|
||||
png_error(png_ptr,
|
||||
"Incompatible libpng version in application and library");
|
||||
}
|
||||
|
||||
/* Libpng 1.0.6 was not binary compatible, due to insertion of the
|
||||
info_ptr->free_me member. Note to maintainer: this test can be
|
||||
removed from version 2.0.0 and beyond because the previous test
|
||||
would have already rejected it. */
|
||||
|
||||
if (user_png_ver[4] == '6' && user_png_ver[2] == '0' &&
|
||||
user_png_ver[0] == '1' && user_png_ver[5] == '\0')
|
||||
{
|
||||
png_error(png_ptr,
|
||||
"Application must be recompiled; version 1.0.6 was incompatible");
|
||||
}
|
||||
}
|
||||
|
||||
/* initialize zbuf - compression buffer */
|
||||
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
|
||||
@@ -493,39 +503,40 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
1, NULL, NULL);
|
||||
#endif
|
||||
|
||||
png_ptr->mode |= PNG_CREATED_WRITE_STRUCT;
|
||||
|
||||
return ((png_structp)png_ptr);
|
||||
}
|
||||
|
||||
/* Initialize png_ptr structure, and allocate any memory needed */
|
||||
#undef png_write_init
|
||||
void
|
||||
void PNGAPI
|
||||
png_write_init(png_structp png_ptr)
|
||||
{
|
||||
/* We only come here via pre-1.0.7-compiled applications */
|
||||
png_write_init_2(png_ptr, "1.0.0", 10000, 10000);
|
||||
}
|
||||
|
||||
void
|
||||
void PNGAPI
|
||||
png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
|
||||
png_size_t png_struct_size, png_size_t png_info_size)
|
||||
{
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
jmp_buf tmp_jmp; /* to save current jump buffer */
|
||||
#endif
|
||||
#ifndef PNG_LEGACY_SUPPORTED
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
if (user_png_ver[i] != png_libpng_ver[i])
|
||||
{
|
||||
#ifdef PNG_LEGACY_SUPPORTED
|
||||
png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
|
||||
#else
|
||||
png_ptr->error_fn=(png_error_ptr)NULL;
|
||||
png_error(png_ptr,
|
||||
"Application uses deprecated png_write_init() and must be recompiled.");
|
||||
#endif
|
||||
}
|
||||
} while (png_libpng_ver[i++]);
|
||||
#endif
|
||||
|
||||
if (sizeof(png_struct) > png_struct_size ||
|
||||
sizeof(png_info) > png_info_size)
|
||||
{
|
||||
@@ -559,11 +570,6 @@ png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
|
||||
png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
|
||||
1, NULL, NULL);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_LEGACY_SUPPORTED
|
||||
if (user_png_ver)
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Write a few rows of image data. If the image is interlaced,
|
||||
@@ -571,7 +577,7 @@ png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
|
||||
* have called png_set_interlace_handling(), you will have to
|
||||
* "write" the image seven times.
|
||||
*/
|
||||
void
|
||||
void PNGAPI
|
||||
png_write_rows(png_structp png_ptr, png_bytepp row,
|
||||
png_uint_32 num_rows)
|
||||
{
|
||||
@@ -589,7 +595,7 @@ png_write_rows(png_structp png_ptr, png_bytepp row,
|
||||
/* Write the image. You only need to call this function once, even
|
||||
* if you are writing an interlaced image.
|
||||
*/
|
||||
void
|
||||
void PNGAPI
|
||||
png_write_image(png_structp png_ptr, png_bytepp image)
|
||||
{
|
||||
png_uint_32 i; /* row index */
|
||||
@@ -616,7 +622,7 @@ png_write_image(png_structp png_ptr, png_bytepp image)
|
||||
}
|
||||
|
||||
/* called by user to write a row of image data */
|
||||
void
|
||||
void PNGAPI
|
||||
png_write_row(png_structp png_ptr, png_bytep row)
|
||||
{
|
||||
png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
|
||||
@@ -767,7 +773,7 @@ png_write_row(png_structp png_ptr, png_bytep row)
|
||||
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
/* Set the automatic flush interval or 0 to turn flushing off */
|
||||
void
|
||||
void PNGAPI
|
||||
png_set_flush(png_structp png_ptr, int nrows)
|
||||
{
|
||||
png_debug(1, "in png_set_flush\n");
|
||||
@@ -775,7 +781,7 @@ png_set_flush(png_structp png_ptr, int nrows)
|
||||
}
|
||||
|
||||
/* flush the current output buffers now */
|
||||
void
|
||||
void PNGAPI
|
||||
png_write_flush(png_structp png_ptr)
|
||||
{
|
||||
int wrote_IDAT;
|
||||
@@ -828,7 +834,7 @@ png_write_flush(png_structp png_ptr)
|
||||
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
|
||||
|
||||
/* free all memory used by the write */
|
||||
void
|
||||
void PNGAPI
|
||||
png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
|
||||
{
|
||||
png_structp png_ptr = NULL;
|
||||
@@ -883,7 +889,7 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
|
||||
|
||||
|
||||
/* Free any memory used in png_ptr struct (old method) */
|
||||
void
|
||||
void PNGAPI
|
||||
png_write_destroy(png_structp png_ptr)
|
||||
{
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
@@ -948,7 +954,7 @@ png_write_destroy(png_structp png_ptr)
|
||||
}
|
||||
|
||||
/* Allow the application to select one or more row filters to use. */
|
||||
void
|
||||
void PNGAPI
|
||||
png_set_filter(png_structp png_ptr, int method, int filters)
|
||||
{
|
||||
png_debug(1, "in png_set_filter\n");
|
||||
@@ -1048,7 +1054,7 @@ png_set_filter(png_structp png_ptr, int method, int filters)
|
||||
* better compression.
|
||||
*/
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
|
||||
void
|
||||
void PNGAPI
|
||||
png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
|
||||
int num_weights, png_doublep filter_weights,
|
||||
png_doublep filter_costs)
|
||||
@@ -1165,7 +1171,7 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
|
||||
}
|
||||
#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
|
||||
|
||||
void
|
||||
void PNGAPI
|
||||
png_set_compression_level(png_structp png_ptr, int level)
|
||||
{
|
||||
png_debug(1, "in png_set_compression_level\n");
|
||||
@@ -1173,7 +1179,7 @@ png_set_compression_level(png_structp png_ptr, int level)
|
||||
png_ptr->zlib_level = level;
|
||||
}
|
||||
|
||||
void
|
||||
void PNGAPI
|
||||
png_set_compression_mem_level(png_structp png_ptr, int mem_level)
|
||||
{
|
||||
png_debug(1, "in png_set_compression_mem_level\n");
|
||||
@@ -1181,7 +1187,7 @@ png_set_compression_mem_level(png_structp png_ptr, int mem_level)
|
||||
png_ptr->zlib_mem_level = mem_level;
|
||||
}
|
||||
|
||||
void
|
||||
void PNGAPI
|
||||
png_set_compression_strategy(png_structp png_ptr, int strategy)
|
||||
{
|
||||
png_debug(1, "in png_set_compression_strategy\n");
|
||||
@@ -1189,7 +1195,7 @@ png_set_compression_strategy(png_structp png_ptr, int strategy)
|
||||
png_ptr->zlib_strategy = strategy;
|
||||
}
|
||||
|
||||
void
|
||||
void PNGAPI
|
||||
png_set_compression_window_bits(png_structp png_ptr, int window_bits)
|
||||
{
|
||||
if (window_bits > 15)
|
||||
@@ -1208,7 +1214,7 @@ png_set_compression_window_bits(png_structp png_ptr, int window_bits)
|
||||
png_ptr->zlib_window_bits = window_bits;
|
||||
}
|
||||
|
||||
void
|
||||
void PNGAPI
|
||||
png_set_compression_method(png_structp png_ptr, int method)
|
||||
{
|
||||
png_debug(1, "in png_set_compression_method\n");
|
||||
@@ -1218,14 +1224,14 @@ png_set_compression_method(png_structp png_ptr, int method)
|
||||
png_ptr->zlib_method = method;
|
||||
}
|
||||
|
||||
void
|
||||
void PNGAPI
|
||||
png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
|
||||
{
|
||||
png_ptr->write_row_fn = write_row_fn;
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
void
|
||||
void PNGAPI
|
||||
png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
|
||||
write_user_transform_fn)
|
||||
{
|
||||
@@ -1237,7 +1243,8 @@ png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
|
||||
|
||||
|
||||
#if defined(PNG_INFO_IMAGE_SUPPORTED)
|
||||
void png_write_png(png_structp png_ptr, png_infop info_ptr,
|
||||
void PNGAPI
|
||||
png_write_png(png_structp png_ptr, png_infop info_ptr,
|
||||
int transforms,
|
||||
voidp params)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user