Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38e6e77419 | ||
|
|
81fdf8aca1 | ||
|
|
68ea243ca3 | ||
|
|
520a764cd7 | ||
|
|
a77ef625a6 | ||
|
|
61c32d9e66 | ||
|
|
166c5a397e | ||
|
|
074af5e9ca | ||
|
|
5379b24536 | ||
|
|
6d8f3b080a | ||
|
|
860ab2b1c0 | ||
|
|
ad5dd1f0fb | ||
|
|
33b25bf1a8 | ||
|
|
18c415f5b5 |
106
ANNOUNCE
@@ -1,88 +1,36 @@
|
||||
|
||||
Libpng 1.0.4d - October 6, 1999
|
||||
Libpng 1.0.6e - April 10, 2000
|
||||
|
||||
This is not intended to be a public release. It will be replaced
|
||||
within a few weeks by a public version or by another test version.
|
||||
|
||||
Changes since the last public release (1.0.3):
|
||||
Changes since the last public release (1.0.6):
|
||||
|
||||
version 1.0.3a [August 12, 1999]
|
||||
Added check for PNG_READ_INTERLACE_SUPPORTED in pngread.c; issue a warning
|
||||
if an attempt is made to read an interlaced image when it's not supported.
|
||||
Added check if png_ptr->trans is defined before free'ing it in pngread.c
|
||||
Modified the Y2K statement to include versions back to version 0.71
|
||||
Fixed a bug in the check for valid IHDR bit_depth/color_types in pngrutil.c
|
||||
Modified makefile.wat (added -zp8 flag, ".symbolic", changed some comments)
|
||||
Replaced leading blanks with tab characters in makefile.hux
|
||||
Changed "dworkin.wustl.edu" to "ccrc.wustl.edu" in various documents.
|
||||
Changed (float)red and (float)green to (double)red, (double)green
|
||||
in png_set_rgb_to_gray() to avoid "promotion" problems in AIX.
|
||||
Fixed a bug in pngconf.h that omitted <stdio.h> when PNG_DEBUG==0 (K Bracey).
|
||||
Reformatted libpng.3 and libpngpf.3 with proper fonts (script by J. vanZandt).
|
||||
Updated documentation to refer to the PNG-1.2 specification.
|
||||
Removed ansi2knr.c and left pointers to the latest source for ansi2knr.c
|
||||
in makefile.knr, INSTALL, and README (L. Peter Deutsch)
|
||||
Fixed bugs in calculation of the length of rowbytes when adding alpha
|
||||
channels to 16-bit images, in pngrtran.c (Chris Nokleberg)
|
||||
Added function png_set_user_transform_info() to store user_transform_ptr,
|
||||
user_depth, and user_channels into the png_struct, and a function
|
||||
png_get_user_transform_ptr() to retrieve the pointer (Chris Nokleberg)
|
||||
Added function png_set_empty_plte_permitted() to make libpng useable
|
||||
in MNG applications.
|
||||
Corrected the typedef for png_free_ptr in png.h (Jesse Jones).
|
||||
Correct gamma with srgb is 45455 instead of 45000 in pngrutil.c, to be
|
||||
consistent with PNG-1.2, and allow variance of 500 before complaining.
|
||||
Added assembler code contributed by Intel in file pngvcrd.c and modified
|
||||
makefile.w32 to use it (Nirav Chhatrapati, INTEL Corporation, Gilles Vollant)
|
||||
Changed "ln -s -f" to "ln -f -s" in the makefiles to make Solaris happy.
|
||||
Added some aliases for png_set_expand() in pngrtran.c, namely
|
||||
png_set_expand_PLTE(), png_set_expand_depth(), and png_set_expand_tRNS()
|
||||
(Greg Roelofs, in "PNG: The Definitive Guide").
|
||||
Added makefile.beo for BEOS on X86, contributed by Sander Stok.
|
||||
version 1.0.3b [August 26, 1999]
|
||||
Replaced 2147483647L several places with PNG_MAX_UINT macro, defined in png.h
|
||||
Changed leading blanks to tabs in all makefiles.
|
||||
Define PNG_USE_PNGVCRD in makefile.w32, to get MMX assembler code.
|
||||
Made alternate versions of png_set_expand() in pngrtran.c, namely
|
||||
png_set_gray_1_2_4_to_8, png_set_palette_to_rgb, and png_set_tRNS_to_alpha
|
||||
(Greg Roelofs, in "PNG: The Definitive Guide"). Deleted the 1.0.3a aliases.
|
||||
Relocated start of 'extern "C"' block in png.h so it doesn't include pngconf.h
|
||||
Revised calculation of num_blocks in pngmem.c to avoid a potentially
|
||||
negative shift distance, whose results are undefined in the C language.
|
||||
Added a check in pngset.c to prevent writing multiple tIME chunks.
|
||||
Added a check in pngwrite.c to detect invalid small window_bits sizes.
|
||||
version 1.0.3d [September 4, 1999]
|
||||
Fixed type casting of igamma in pngrutil.c
|
||||
Added new png_expand functions to scripts/pngdef.pas and pngos2.def
|
||||
Added a demo read_user_transform_fn that examines the row filters in pngtest.c
|
||||
version 1.0.4 [September 24, 1999]
|
||||
Define PNG_ALWAYS_EXTERN in pngconf.h if __STDC__ is defined
|
||||
Delete #define PNG_INTERNAL and include "png.h" from pngasmrd.h
|
||||
Made several minor corrections to pngtest.c
|
||||
Changed "hptr += 16L" to "hptr = hptr + 16L" in pngmem.c for Turbo 3.0
|
||||
Renamed the makefiles with longer but more user friendly extensions.
|
||||
Copied the PNG copyright and license to a separate LICENSE file.
|
||||
Revised documentation, png.h, and example.c to remove reference to
|
||||
"viewing_gamma" which no longer appears in the PNG specification.
|
||||
Revised pngvcrd.c to use MMX code for interlacing only on the final pass.
|
||||
Updated pngvcrd.c to use the faster C filter algorithms from libpng-1.0.1a
|
||||
Split makefile.win32vc into two versions, makefile.vcawin32 (uses MMX
|
||||
assembler code) and makefile.vcwin32 (doesn't).
|
||||
Added a CPU timing report to pngtest.c (enabled by defining PNGTEST_TIMING)
|
||||
Added a copy of pngnow.png to the distribution.
|
||||
version 1.0.4a September 25, 1999
|
||||
Increase max_pixel_depth in pngrutil.c if a user transform needs it.
|
||||
Changed several division operations to right-shifts in pngvcrd.c
|
||||
version 1.0.4b September 30, 1999
|
||||
Added parentheses in line 3732 of pngvcrd.c
|
||||
Added a comment in makefile.linux warning about buggy -O3 in pgcc 2.95.1
|
||||
Added a "png_check_version" function in png.c and pngtest.c that will generate
|
||||
a helpful compiler error if an old png.h is found in the search path.
|
||||
version 1.0.4c October 1, 1999
|
||||
Changed type of png_user_transform_depth|channels from int to png_byte.
|
||||
version 1.0.4d [October 6, 1999]
|
||||
Changed 0.45 to 0.45455 in png_set_sRGB()
|
||||
Removed unused PLTE entries from pngnow.png
|
||||
version 1.0.6d [April 8, 2000]
|
||||
Changed sprintf() to strcpy() in png_write_sCAL_s() to work without STDIO
|
||||
Added data_length parameter to png_decompress_chunk() function
|
||||
Revised documentation to remove reference to abandoned png_free_chnk functions
|
||||
Fixed an error in png_rgb_to_gray_fixed()
|
||||
Revised example.c, usage of png_destroy_write_struct().
|
||||
Renamed makefile.ibmvac3 to makefile.ibmc, added libpng.icc IBM project file
|
||||
Added a check for info_ptr->free_me&PNG_FREE_TEXT when free'ing text in png.c
|
||||
Simplify png_sig_bytes() function to remove use of non-ISO-C strdup().
|
||||
version 1.0.6e [April 10, 2000]
|
||||
Added png_data_freer() function.
|
||||
In the code that checks for over-length tRNS chunks, added check of
|
||||
info_ptr->num_trans as well as png_ptr->num_trans (Matthias Benckmann)
|
||||
Minor revisions of libpng.txt/libpng.3.
|
||||
Check for existing data and free it if the free_me flag is set, in png_set_*()
|
||||
and png_handle_*().
|
||||
Only define PNG_WEIGHTED_FILTERS_SUPPORTED when PNG_FLOATING_POINT_SUPPORTED
|
||||
is defined.
|
||||
Changed several instances of PNG_NO_CONSOLE_ID to PNG_NO_STDIO in pngrutil.c
|
||||
and mentioned the purposes of the two macros in libpng.txt/libpng.3.
|
||||
|
||||
Send comments/corrections/commendations to
|
||||
png-implement@ccrc.wustl.edu or to randeg@alum.rpi.edu
|
||||
|
||||
Glenn R-P
|
||||
|
||||
Send comments/corrections/commendations to
|
||||
png-implement@ccrc.wustl.edu or to randeg@alum.rpi.edu
|
||||
|
||||
224
CHANGES
@@ -459,7 +459,229 @@ version 1.0.4b [September 30, 1999]
|
||||
version 1.0.4c [October 1, 1999]
|
||||
Added a "png_check_version" function in png.c and pngtest.c that will generate
|
||||
a helpful compiler error if an old png.h is found in the search path.
|
||||
version 1.0.4d [October 6, 1999]
|
||||
Changed type of png_user_transform_depth|channels from int to png_byte.
|
||||
version 1.0.4d [October 6, 1999]
|
||||
Changed 0.45 to 0.45455 in png_set_sRGB()
|
||||
Removed unused PLTE entries from pngnow.png
|
||||
Re-enabled some parts of pngvcrd.c (png_combine_row) that work properly.
|
||||
version 1.0.4e [October 10, 1999]
|
||||
Fixed sign error in pngvcrd.c (Greg Roelofs)
|
||||
Replaced some instances of memcpy with simple assignments in pngvcrd (GR-P)
|
||||
version 1.0.4f [October 15, 1999]
|
||||
Surrounded example.c code with #if 0 .. #endif to prevent people from
|
||||
inadvertently trying to compile it.
|
||||
Changed png_get_header_version() from a function to a macro in png.h
|
||||
Added type casting mostly in pngrtran.c and pngwtran.c
|
||||
Removed some pointless "ptr = NULL" in pngmem.c
|
||||
Added a "contrib" directory containing the source code from Greg's book.
|
||||
version 1.0.5 [October 15, 1999]
|
||||
Minor editing of the INSTALL and README files.
|
||||
version 1.0.5a [October 23, 1999]
|
||||
Added contrib/pngsuite and contrib/pngminus (Willem van Schaik)
|
||||
Fixed a typo in the png_set_sRGB() function call in example.c (Jan Nijtmans)
|
||||
Further optimization and bugfix of pngvcrd.c
|
||||
Revised pngset.c so that it does not allocate or free memory in the user's
|
||||
text_ptr structure. Instead, it makes its own copy.
|
||||
Created separate write_end_info_struct in pngtest.c for a more severe test.
|
||||
Added code in pngwrite.c to free info_ptr->text[i].key to stop a memory leak.
|
||||
version 1.0.5b [November 23, 1999]
|
||||
Moved PNG_FLAG_HAVE_CHUNK_HEADER, PNG_FLAG_BACKGROUND_IS_GRAY and
|
||||
PNG_FLAG_WROTE_tIME from flags to mode.
|
||||
Added png_write_info_before_PLTE() function.
|
||||
Fixed some typecasting in contrib/gregbook/*.c
|
||||
Updated scripts/makevms.com and added makevms.com to contrib/gregbook
|
||||
and contrib/pngminus (Martin Zinser)
|
||||
version 1.0.5c [November 26, 1999]
|
||||
Moved png_get_header_version from png.h to png.c, to accomodate ansi2knr.
|
||||
Removed all global arrays (according to PNG_NO_GLOBAL_ARRAYS macro), to
|
||||
accomodate making DLL's: Moved usr_png_ver from global variable to function
|
||||
png_get_header_ver() in png.c. Moved png_sig to png_sig_bytes in png.c and
|
||||
eliminated use of png_sig in pngwutil.c. Moved the various png_CHNK arrays
|
||||
into pngtypes.h. Eliminated use of global png_pass arrays. Declared the
|
||||
png_CHNK and png_pass arrays to be "const". Made the global arrays
|
||||
available to applications (although none are used in libpng itself) when
|
||||
PNG_NO_GLOBAL_ARRAYS is not defined or when PNG_GLOBAL_ARRAYS is defined.
|
||||
Removed some extraneous "-I" from contrib/pngminus/makefile.std
|
||||
Changed the PNG_sRGB_INTENT macros in png.h to be consistent with PNG-1.2.
|
||||
Change PNG_SRGB_INTENT to PNG_sRGB_INTENT in libpng.txt and libpng.3
|
||||
version 1.0.5d [November 29, 1999]
|
||||
Add type cast (png_const_charp) two places in png.c
|
||||
Eliminated pngtypes.h; use macros instead to declare PNG_CHNK arrays.
|
||||
Renamed "PNG_GLOBAL_ARRAYS" to "PNG_USE_GLOBAL_ARRAYS" and made available
|
||||
to applications a macro "PNG_USE_LOCAL_ARRAYS".
|
||||
#ifdef out all the new declarations when PNG_USE_GLOBAL_ARRAYS is defined.
|
||||
Added PNG_EXPORT_VAR macro to accommodate making DLL's.
|
||||
version 1.0.5e [November 30, 1999]
|
||||
Added iCCP, iTXt, and sPLT support; added "lang" member to the png_text
|
||||
structure; refactored the inflate/deflate support to make adding new chunks
|
||||
with trailing compressed parts easier in the future, and added new functions
|
||||
png_free_iCCP, png_free_pCAL, png_free_sPLT, png_free_text, png_get_iCCP,
|
||||
png_get_spalettes, png_set_iCCP, png_set_spalettes (Eric S. Raymond).
|
||||
NOTE: Applications that write text chunks MUST define png_text->lang
|
||||
before calling png_set_text(). It must be set to NULL if you want to
|
||||
write tEXt or zTXt chunks. If you want your application to be able to
|
||||
run with older versions of libpng, use
|
||||
|
||||
#ifdef PNG_iTXt_SUPPORTED
|
||||
png_text[i].lang = NULL;
|
||||
#endif
|
||||
|
||||
Changed png_get_oFFs() and png_set_oFFs() to use signed rather than unsigned
|
||||
offsets (Eric S. Raymond).
|
||||
Combined PNG_READ_cHNK_SUPPORTED and PNG_WRITE_cHNK_SUPPORTED macros into
|
||||
PNG_cHNK_SUPPORTED and combined the three types of PNG_text_SUPPORTED
|
||||
macros, leaving the separate macros also available.
|
||||
Removed comments on #endifs at the end of many short, non-nested #if-blocks.
|
||||
version 1.0.5f [December 6, 1999]
|
||||
Changed makefile.solaris to issue a warning about potential problems when
|
||||
the ucb "ld" is in the path ahead of the ccs "ld".
|
||||
Removed "- [date]" from the "synopsis" line in libpng.3 and libpngpf.3.
|
||||
Added sCAL chunk support (Eric S. Raymond).
|
||||
version 1.0.5g [December 7, 1999]
|
||||
Fixed "png_free_spallettes" typo in png.h
|
||||
Added code to handle new chunks in pngpread.c
|
||||
Moved PNG_CHNK string macro definitions outside of PNG_NO_EXTERN block
|
||||
Added "translated_key" to png_text structure and png_write_iTXt().
|
||||
Added code in pngwrite.c to work around a newly discovered zlib bug.
|
||||
version 1.0.5h [December 10, 1999]
|
||||
NOTE: regarding the note for version 1.0.5e, the following must also
|
||||
be included in your code:
|
||||
png_text[i].translated_key = NULL;
|
||||
Unknown chunk handling is now supported.
|
||||
Option to eliminate all floating point support was added. Some new
|
||||
fixed-point functions such as png_set_gAMA_fixed() were added.
|
||||
Expanded tabs and removed trailing blanks in source files.
|
||||
version 1.0.5i [December 13, 1999]
|
||||
Added some type casts to silence compiler warnings.
|
||||
Renamed "png_free_spalette" to "png_free_spalettes" for consistency.
|
||||
Removed leading blanks from a #define in pngvcrd.c
|
||||
Added some parameters to the new png_set_keep_unknown_chunks() function.
|
||||
Added a test for up->location != 0 in the first instance of writing
|
||||
unknown chunks in pngwrite.c
|
||||
Changed "num" to "i" in png_free_spalettes() and png_free_unknowns() to
|
||||
prevent recursion.
|
||||
Added png_free_hIST() function.
|
||||
Various patches to fix bugs in the sCAL and integer cHRM processing,
|
||||
and to add some convenience macros for use with sCAL.
|
||||
version 1.0.5j [December 21, 1999]
|
||||
Changed "unit" parameter of png_write_sCAL from png_byte to int, to work
|
||||
around buggy compilers.
|
||||
Added new type "png_fixed_point" for integers that hold float*100000 values
|
||||
Restored backward compatibility of tEXt/zTXt chunk processing:
|
||||
Restored the first four members of png_text to the same order as v.1.0.5d.
|
||||
Added members "lang_key" and "itxt_length" to png_text struct. Set
|
||||
text_length=0 when "text" contains iTXt data. Use the "compression"
|
||||
member to distinguish among tEXt/zTXt/iTXt types. Added
|
||||
PNG_ITXT_COMPRESSION_NONE (1) and PNG_ITXT_COMPRESSION_zTXt(2) macros.
|
||||
The "Note" above, about backward incompatibility of libpng-1.0.5e, no
|
||||
longer applies.
|
||||
Fixed png_read|write_iTXt() to read|write parameters in the right order,
|
||||
and to write the iTXt chunk after IDAT if it appears in the end_ptr.
|
||||
Added pnggccrd.c, version of pngvcrd.c Intel assembler for gcc (Greg Roelofs)
|
||||
Reversed the order of trying to write floating-point and fixed-point gAMA.
|
||||
version 1.0.5k [December 27, 1999]
|
||||
Added many parentheses, e.g., "if (a && b & c)" becomes "if (a && (b & c))"
|
||||
Added png_handle_as_unknown() function (Glenn)
|
||||
Added png_free_chunk_list() function and chunk_list and num_chunk_list members
|
||||
of png_ptr.
|
||||
Eliminated erroneous warnings about multiple sPLT chunks and sPLT-after-PLTE.
|
||||
Fixed a libpng-1.0.5h bug in pngrutil.c that was issuing erroneous warnings
|
||||
about ignoring incorrect gAMA with sRGB (gAMA was in fact not ignored)
|
||||
Added png_free_tRNS(); png_set_tRNS() now malloc's its own trans array (ESR).
|
||||
Define png_get_int_32 when oFFs chunk is supported as well as when pCAL is.
|
||||
Changed type of proflen from png_int_32 to png_uint_32 in png_get_iCCP().
|
||||
version 1.0.5l [January 1, 2000]
|
||||
Added functions png_set_read_user_chunk_fn() and png_get_user_chunk_ptr()
|
||||
for setting a callback function to handle unknown chunks and for
|
||||
retrieving the associated user pointer (Glenn).
|
||||
version 1.0.5m [January 7, 2000]
|
||||
Added high-level functions png_read_png(), png_write_png(), png_free_pixels().
|
||||
version 1.0.5n [January 9, 2000]
|
||||
Added png_free_PLTE() function, and modified png_set_PLTE() to malloc its
|
||||
own memory for info_ptr->palette. This makes it safe for the calling
|
||||
application to free its copy of the palette any time after it calls
|
||||
png_set_PLTE().
|
||||
version 1.0.5o [January 20, 2000]
|
||||
Cosmetic changes only (removed some trailing blanks and TABs)
|
||||
version 1.0.5p [January 31, 2000]
|
||||
Renamed pngdll.mak to makefile.bd32
|
||||
Cosmetic changes in pngtest.c
|
||||
version 1.0.5q [February 5, 2000]
|
||||
Relocated the makefile.solaris warning about PATH problems.
|
||||
Fixed pngvcrd.c bug by pushing/popping registers in mmxsupport (Bruce Oberg)
|
||||
Revised makefile.gcmmx
|
||||
Added PNG_SETJMP_SUPPORTED, PNG_SETJMP_NOT_SUPPORTED, and PNG_ABORT() macros
|
||||
version 1.0.5r [February 7, 2000]
|
||||
Removed superfluous prototype for png_get_itxt from png.h
|
||||
Fixed a bug in pngrtran.c that improperly expanded the background color.
|
||||
Return *num_text=0 from png_get_text() when appropriate, and fix documentation
|
||||
of png_get_text() in libpng.txt/libpng.3.
|
||||
version 1.0.5s [February 18, 2000]
|
||||
Added "png_jmp_env()" macro to pngconf.h, to help people migrate to the
|
||||
new error handler that's planned for the next libpng release, and changed
|
||||
example.c, pngtest.c, and contrib programs to use this macro.
|
||||
Revised some of the DLL-export macros in pngconf.h (Greg Roelofs)
|
||||
Fixed a bug in png_read_png() that caused it to fail to expand some images
|
||||
that it should have expanded.
|
||||
Fixed some mistakes in the unused and undocumented INCH_CONVERSIONS functions
|
||||
in pngget.c
|
||||
Changed the allocation of palette, history, and trans arrays back to
|
||||
the version 1.0.5 method (linking instead of copying) which restores
|
||||
backward compatibility with version 1.0.5. Added some remarks about
|
||||
that in example.c. Added "free_me" member to info_ptr and png_ptr
|
||||
and added png_free_data() function.
|
||||
Updated makefile.linux and makefile.gccmmx to make directories conditionally.
|
||||
Made cosmetic changes to pngasmrd.h
|
||||
Added png_set_rows() and png_get_rows(), for use with png_read|write_png().
|
||||
Modified png_read_png() to allocate info_ptr->row_pointers only if it
|
||||
hasn't already been allocated.
|
||||
version 1.0.5t [March 4, 2000]
|
||||
Changed png_jmp_env() migration aiding macro to png_jmpbuf().
|
||||
Fixed "interlace" typo (should be "interlaced") in contrib/gregbook/read2-x.c
|
||||
Fixed bug with use of PNG_BEFORE_IHDR bit in png_ptr->mode, introduced when
|
||||
PNG_FLAG_HAVE_CHUNK_HEADER was moved into png_ptr->mode in version 1.0.5b
|
||||
Files in contrib/gregbook were revised to use png_jmpbuf() and to select
|
||||
a 24-bit visual if one is available, and to allow abbreviated options.
|
||||
Files in contrib/pngminus were revised to use the png_jmpbuf() macro.
|
||||
Removed spaces in makefile.linux and makefile.gcmmx, introduced in 1.0.5s
|
||||
version 1.0.5u [March 5, 2000]
|
||||
Simplified the code that detects old png.h in png.c and pngtest.c
|
||||
Renamed png_spalette (_p, _pp) to png_sPLT_t (_tp, _tpp)
|
||||
Increased precision of rgb_to_gray calculations from 8 to 15 bits and
|
||||
added png_set_rgb_to_gray_fixed() function.
|
||||
Added makefile.bc32 (32-bit Borland C++, C mode)
|
||||
version 1.0.5v [March 11, 2000]
|
||||
Added some parentheses to the png_jmpbuf macro definition.
|
||||
Updated references to the zlib home page, which has moved to freesoftware.com.
|
||||
Corrected bugs in documentation regarding png_read_row() and png_write_row().
|
||||
Updated documentation of png_rgb_to_gray calculations in libpng.3/libpng.txt.
|
||||
Renamed makefile.borland,turboc3 back to makefile.bor,tc3 as in version 1.0.3,
|
||||
revised borland makefiles; added makefile.ibmvac3 and makefile.gcc (Cosmin)
|
||||
version 1.0.6 [March 20, 2000]
|
||||
Minor revisions of makefile.bor, libpng.txt, and gregbook/rpng2-win.c
|
||||
Added makefile.sggcc (SGI IRIX with gcc)
|
||||
version 1.0.6d [April 7, 2000]
|
||||
Changed sprintf() to strcpy() in png_write_sCAL_s() to work without STDIO
|
||||
Added data_length parameter to png_decompress_chunk() function
|
||||
Revised documentation to remove reference to abandoned png_free_chnk functions
|
||||
Fixed an error in png_rgb_to_gray_fixed()
|
||||
Revised example.c, usage of png_destroy_write_struct().
|
||||
Renamed makefile.ibmvac3 to makefile.ibmc, added libpng.icc IBM project file
|
||||
Added a check for info_ptr->free_me&PNG_FREE_TEXT when free'ing text in png.c
|
||||
Simplify png_sig_bytes() function to remove use of non-ISO-C strdup().
|
||||
version 1.0.6e [April 10, 2000]
|
||||
Added png_data_freer() function.
|
||||
In the code that checks for over-length tRNS chunks, added check of
|
||||
info_ptr->num_trans as well as png_ptr->num_trans (Matthias Benckmann)
|
||||
Minor revisions of libpng.txt/libpng.3.
|
||||
Check for existing data and free it if the free_me flag is set, in png_set_*()
|
||||
and png_handle_*().
|
||||
Only define PNG_WEIGHTED_FILTERS_SUPPORTED when PNG_FLOATING_POINT_SUPPORTED
|
||||
is defined.
|
||||
Changed several instances of PNG_NO_CONSOLE_ID to PNG_NO_STDIO in pngrutil.c
|
||||
and mentioned the purposes of the two macros in libpng.txt/libpng.3.
|
||||
|
||||
Send comments/corrections/commendations to
|
||||
png-implement@ccrc.wustl.edu or to randeg@alum.rpi.edu
|
||||
|
||||
Glenn R-P
|
||||
|
||||
105
INSTALL
@@ -1,5 +1,5 @@
|
||||
|
||||
Installing libpng version 1.0.4d - October 6, 1999
|
||||
Installing libpng version 1.0.6e - April 10, 2000
|
||||
|
||||
Before installing libpng, you must first install zlib. zlib
|
||||
can usually be found wherever you got libpng. zlib can be
|
||||
@@ -10,7 +10,7 @@ zlib.h and zconf.h include files that correspond to the
|
||||
version of zlib that's installed.
|
||||
|
||||
You can rename the directories that you downloaded (they
|
||||
might be called "libpng-1.0.4d" or "lpng103" and "zlib-1.1.3"
|
||||
might be called "libpng-1.0.6e" or "lpng106" and "zlib-1.1.3"
|
||||
or "zlib113") so that you have directories called "zlib" and "libpng".
|
||||
|
||||
Your directory structure should look like this:
|
||||
@@ -21,6 +21,10 @@ Your directory structure should look like this:
|
||||
README
|
||||
*.h
|
||||
*.c
|
||||
contrib
|
||||
gregbook
|
||||
pngminus
|
||||
pngsuite
|
||||
scripts
|
||||
makefile.*
|
||||
pngtest.png
|
||||
@@ -32,52 +36,62 @@ Your directory structure should look like this:
|
||||
contrib
|
||||
etc.
|
||||
|
||||
First enter the zlib directory and follow the instructions
|
||||
in zlib/README. Then come back here and choose the
|
||||
appropriate makefile.sys in the scripts directory.
|
||||
If the line endings in the files look funny, you may wish to get the other
|
||||
distribution of libpng. It is available in both tar.gz (UNIX style line
|
||||
endings) and zip (DOS style line endings) formats.
|
||||
|
||||
First enter the zlib directory and follow the instructions in zlib/README.
|
||||
Then come back here and choose the appropriate makefile.sys in the scripts
|
||||
directory.
|
||||
The files that are presently available in the scripts directory
|
||||
include
|
||||
|
||||
descrip.mms => VMS makefile for MMS or MMK
|
||||
makefile.std => Generic UNIX makefile
|
||||
makefile.knr => Archaic UNIX Makefile that converts files with
|
||||
ansi2knr (Requires ansi2knr.c from
|
||||
ftp://ftp.cs.wisc.edu/ghost)
|
||||
makefile.dec => DEC Alpha UNIX makefile
|
||||
makefile.hpux => HPUX (10.20 and 11.00) makefile
|
||||
makefile.sgi => Silicon Graphics IRIX makefile
|
||||
makefile.sunos => Sun makefile
|
||||
makefile.solaris => Solaris 2.X makefile (gcc, creates libpng.so.2.1.0.4d)
|
||||
makefile.linux => Linux/ELF makefile (gcc, creates libpng.so.2.1.0.4d)
|
||||
makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc
|
||||
makefile.mips => MIPS makefile
|
||||
makefile.acorn => Acorn makefile
|
||||
makefile.amiga => Amiga makefile
|
||||
smakefile.ppc => AMIGA smakefile for SAS C V6.58/7.00 PPC compiler
|
||||
(Requires SCOPTIONS, copied from scripts/SCOPTIONS.ppc)
|
||||
makefile.atari => Atari makefile
|
||||
makefile.beos => BEOS makefile for X86
|
||||
makefile.borland => Borland makefile
|
||||
build.bat => MS-DOS batch file for Borland compiler
|
||||
makefile.dj2 => DJGPP 2 makefile
|
||||
makefile.msc => Microsoft C makefile
|
||||
makefile.vcawin32 => makefile for Microsoft Visual C++ 5.0 and later (uses
|
||||
assembler code)
|
||||
makefile.vcwin32 => makefile for Microsoft Visual C++ 4.0 and later (does not
|
||||
use assembler code)
|
||||
makefile.turboc3 => Turbo C 3.0 makefile
|
||||
makefile.os2 => OS/2 Makefile (gcc and emx, requires pngos2.def)
|
||||
pngos2.def => OS/2 module definition file used by makefile.os2
|
||||
makefile.watcom => Watcom 10a+ Makefile, 32-bit flat memory model
|
||||
makevms.com => VMS build script
|
||||
pngdll.mak => To make a png32bd.dll with Borland C++ 4.5
|
||||
pngdef.pas => Defines for a png32bd.dll with Borland C++ 4.5
|
||||
SCOPTIONS.ppc => Used with smakefile.ppc
|
||||
makefile.std => Generic UNIX makefile (cc, creates static libpng.a)
|
||||
makefile.linux => Linux/ELF makefile (gcc, creates libpng.so.2.1.0.6e)
|
||||
makefile.gcmmx => Linux/ELF makefile (gcc, creates libpng.so.2.1.0.6e,
|
||||
uses assembler code tuned for Intel MMX platform)
|
||||
makefile.gcc => Generic makefile (gcc, creates static libpng.a)
|
||||
makefile.knr => Archaic UNIX Makefile that converts files with
|
||||
ansi2knr (Requires ansi2knr.c from
|
||||
ftp://ftp.cs.wisc.edu/ghost)
|
||||
makefile.dec => DEC Alpha UNIX makefile
|
||||
makefile.hpux => HPUX (10.20 and 11.00) makefile
|
||||
makefile.ibmc => IBM C/C++ version 3.x for Win32 and OS/2 (static)
|
||||
libpng.icc => Project file for IBM VisualAge/C++ version 4.0 or later
|
||||
makefile.sgi => Silicon Graphics IRIX makefile (cc, creates static lib)
|
||||
makefile.sggcc => Silicon Graphics (gcc, creates libpng.so.2.1.0.6e)
|
||||
makefile.sunos => Sun makefile
|
||||
makefile.solaris => Solaris 2.X makefile (gcc, creates libpng.so.2.1.0.6e)
|
||||
makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc
|
||||
makefile.mips => MIPS makefile
|
||||
makefile.acorn => Acorn makefile
|
||||
makefile.amiga => Amiga makefile
|
||||
smakefile.ppc => AMIGA smakefile for SAS C V6.58/7.00 PPC compiler
|
||||
(Requires SCOPTIONS, copied from scripts/SCOPTIONS.ppc)
|
||||
makefile.atari => Atari makefile
|
||||
makefile.beos => BEOS makefile for X86
|
||||
makefile.bor => Borland makefile (uses bcc)
|
||||
makefile.bc32 => 32-bit Borland C++ (all modules compiled in C mode)
|
||||
makefile.bd32 => To make a png32bd.dll with Borland C++ 4.5
|
||||
makefile.tc3 => Turbo C 3.0 makefile
|
||||
makefile.dj2 => DJGPP 2 makefile
|
||||
makefile.msc => Microsoft C makefile
|
||||
makefile.vcawin32 => makefile for Microsoft Visual C++ 5.0 and later (uses
|
||||
assembler code tuned for Intel MMX platform)
|
||||
makefile.vcwin32 => makefile for Microsoft Visual C++ 4.0 and later (does
|
||||
not use assembler code)
|
||||
makefile.os2 => OS/2 Makefile (gcc and emx, requires pngos2.def)
|
||||
pngos2.def => OS/2 module definition file used by makefile.os2
|
||||
makefile.watcom => Watcom 10a+ Makefile, 32-bit flat memory model
|
||||
makevms.com => VMS build script
|
||||
descrip.mms => VMS makefile for MMS or MMK
|
||||
pngdef.pas => Defines for a png32bd.dll with Borland C++ 4.5
|
||||
SCOPTIONS.ppc => Used with smakefile.ppc
|
||||
|
||||
Copy the file (or files) that you need from the
|
||||
scripts directory into this directory, for example
|
||||
|
||||
MSDOS example: copy scripts\makefile.msd makefile
|
||||
MSDOS example: copy scripts\makefile.msc makefile
|
||||
UNIX example: cp scripts/makefile.std makefile
|
||||
|
||||
Read the makefile to see if you need to change any source or
|
||||
@@ -89,11 +103,16 @@ changes.
|
||||
Then just run "make test" which will create the libpng library in
|
||||
this directory and run a quick test that reads the "pngtest.png"
|
||||
file and writes a "pngout.png" file that should be identical to it.
|
||||
Look for "9782 zero samples" in the output of the test. For more
|
||||
confidence, you can run another test by typing "pngtest pngnow.png"
|
||||
and looking for "289 zero samples" in the output. Also, you can
|
||||
run "pngtest -m *.png" in the "contrib/pngsuite" directory and compare
|
||||
your output with the result shown in contrib/pngsuite/README.
|
||||
|
||||
Most of the makefiles will allow you to run "make install" to
|
||||
put the library in its final resting place (if you want to
|
||||
do that, run "make install" in the zlib directory first if necessary).
|
||||
|
||||
Further information can be found in the README and libpng.txt
|
||||
files, in the individual makefiles, and in png.h, and the manual
|
||||
pages libpng.3 and png.5.
|
||||
files, in the individual makefiles, in png.h, and the manual pages
|
||||
libpng.3 and png.5.
|
||||
|
||||
72
KNOWNBUG
@@ -1,8 +1,47 @@
|
||||
|
||||
Known bugs and suggested enhancements in libpng-1.0.4
|
||||
Known bugs and suggested enhancements in libpng-1.0.6
|
||||
|
||||
1. April 1, 2000 -- BUG
|
||||
|
||||
1. March 15, 1998 -- OPTIMIZATION -- Kevin Bracey
|
||||
Under some circumstances old applications that make direct access to
|
||||
the info_ptr->text and its members might free the same memory that
|
||||
is also free'ed by libpng during the png_destroy_struct process.
|
||||
|
||||
Fixed in libpng-1.0.6-patch-03 and libpng-1.0.6d. The PNG_FREE_TEXT flag
|
||||
bit in info_ptr->free_me is now checked to make sure libpng is responsible
|
||||
for freeing the memory.
|
||||
|
||||
2. April 1, 2000 -- BUG
|
||||
|
||||
The non-ISO-C "strdup()" function is used in png.c
|
||||
|
||||
STATUS: The function has been simplified and no longer uses strdup()
|
||||
in libpng-1.0.6-patch-03 and libpng-1.0.6d.
|
||||
|
||||
3. March 24, 2000 -- BUG
|
||||
|
||||
The png_set_rgb_to_gray_fixed() function is setting incorrect weighting
|
||||
factors.
|
||||
|
||||
STATUS: Fixed in libpng-1.0.6-patch-02 and libpng-1.0.6d.
|
||||
|
||||
4. March 22, 2000 -- BUG
|
||||
|
||||
There are some printf() and fprintf() statements active in pngwutil.c
|
||||
when PNG_NO_STDIO and PNG_sCAL_SUPPORTED are both defined.
|
||||
|
||||
STATUS: Fixed in libpng-1.0.6-patch-01 and libpng-1.0.6d. The strcpy()
|
||||
function is used instead.
|
||||
|
||||
5. March 22, 2000 -- BUG
|
||||
|
||||
The length of the iCCP chunk data is calculated incorrectly; because
|
||||
it can contain zeroes, strlen() doesn't work.
|
||||
|
||||
STATUS: Fixed in libpng-1.0.6-patch-01 and libpng-1.0.6d by adding a
|
||||
data_length parameter to the png_decompress_chunk() function.
|
||||
|
||||
6. March 15, 1998 -- OPTIMIZATION -- Kevin Bracey
|
||||
|
||||
Loops need to be optimized everywhere
|
||||
|
||||
@@ -14,10 +53,10 @@ Known bugs and suggested enhancements in libpng-1.0.4
|
||||
Question whether i-- or --i is better.
|
||||
|
||||
STATUS: Under investigation, postponed until after
|
||||
libpng-1.0.5. About 160 loops will be turned around
|
||||
in libpng-1.0.Nn, for testing.
|
||||
libpng-1.1.0. About 160 loops will be turned around
|
||||
in libpng-1.1.Nn, for testing.
|
||||
|
||||
2. July 4, 1998 -- ENHANCEMENT -- Glenn R-P
|
||||
7. July 4, 1998 -- ENHANCEMENT -- Glenn R-P
|
||||
|
||||
libpng-1.0.5 and earlier transform colors to gamma=1.0 space for
|
||||
merging with background, and then back to the image's gamma. The
|
||||
@@ -29,30 +68,15 @@ Known bugs and suggested enhancements in libpng-1.0.4
|
||||
|
||||
STATUS: under development.
|
||||
|
||||
3. September 1999 -- ENHANCEMENT --
|
||||
8. September 1999 -- ENHANCEMENT --
|
||||
|
||||
It should be possible to use libpng without floating-point aritmetic.
|
||||
|
||||
STATUS: Under investigation, implementation postponed until after
|
||||
libpng-1.0.5. The application interface will change because replacements
|
||||
libpng-1.0.6. The application interface will change because replacements
|
||||
for the png_set_gAMA(), png_set_cHRM(), and corresponding png_get_()
|
||||
functions will be needed.
|
||||
|
||||
4. September 1999 -- BUG [FIXED] --
|
||||
Much of this was completed in libpng-1.0.6, but gamma compensation
|
||||
is not yet done in fixed-point arithmetic.
|
||||
|
||||
Portions of the new MMX code in pngvcrd.c were ifdef'd out because they
|
||||
didn't work properly, but the bug appears to have been found and fixed.
|
||||
As a result, all parts of the code are once again enabled. If you think
|
||||
there's still a problem, you can recompile with one of the following two
|
||||
macros defined and see if the problem goes away:
|
||||
|
||||
DISABLE_PNGVCRD_COMBINE
|
||||
DISABLE_PNGVCRD_INTERLACE
|
||||
|
||||
The second one is in the function where the bug was; as far as we are
|
||||
aware, there was never any bug in the other function. Please notify us
|
||||
if you find any problems in libpng, regardless of whether the two macros
|
||||
make any difference: png-implement@ccrc.wustl.edu
|
||||
|
||||
Again, we believe the MMX code in pngvcrd.c is 100% correct, but it has
|
||||
not yet been tested extensively.
|
||||
|
||||
18
LICENSE
@@ -4,8 +4,8 @@ Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
(libpng versions 0.5, May 1995, through 0.89c, May 1996)
|
||||
Copyright (c) 1996, 1997 Andreas Dilger
|
||||
(libpng versions 0.90, December 1996, through 0.96, May 1997)
|
||||
Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
(libpng versions 0.97, January 1998, through 1.0.4d, October 6, 1999)
|
||||
Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
(libpng versions 0.97, January 1998, through 1.0.6e, April 10, 2000)
|
||||
|
||||
For the purposes of this copyright and license, "Contributing Authors"
|
||||
is defined as the following set of individuals:
|
||||
@@ -18,6 +18,7 @@ is defined as the following set of individuals:
|
||||
Tom Lane
|
||||
Dave Martindale
|
||||
Glenn Randers-Pehrson
|
||||
Eric S. Raymond
|
||||
Greg Roelofs
|
||||
Guy Eric Schalnat
|
||||
Paul Schmidt
|
||||
@@ -54,6 +55,17 @@ supporting the PNG file format in commercial products. If you use this
|
||||
source code in a product, acknowledgment is not required but would be
|
||||
appreciated.
|
||||
|
||||
A "png_get_copyright" function is available, for convenient use in "about"
|
||||
boxes and the like:
|
||||
|
||||
printf("%s",png_get_copyright(NULL));
|
||||
|
||||
Also, the PNG logo (in PNG format, of course) is supplied in the
|
||||
file "pngnow.png".
|
||||
|
||||
Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a
|
||||
certification mark of the Open Source Initiative.
|
||||
|
||||
Glenn Randers-Pehrson
|
||||
randeg@alum.rpi.edu
|
||||
October 6, 1999
|
||||
April 10, 2000
|
||||
|
||||
68
README
@@ -1,14 +1,19 @@
|
||||
README for libpng 1.0.4d - October 6, 1999 (shared library 2.1)
|
||||
README for libpng 1.0.6e - April 10, 2000 (shared library 2.1)
|
||||
See the note about version numbers near the top of png.h
|
||||
|
||||
See INSTALL for instructions on how to install libpng.
|
||||
|
||||
This is the first official release of libpng. Don't let the fact that
|
||||
it's the first release fool you. The libpng library has been in
|
||||
extensive use and testing for about two and a half years. However, it's
|
||||
finally gotten to the stage where there haven't been significant
|
||||
Libpng comes in two distribution formats. Get libpng-*.tar.gz if you
|
||||
want UNIX-style line endings in the text files, or lpng*.zip if you want
|
||||
DOS-style line endings.
|
||||
|
||||
Version 0.89 was the first official release of libpng. Don't let the
|
||||
fact that it's the first release fool you. The libpng library has been in
|
||||
extensive use and testing since mid-1995. By late 1997 it had
|
||||
finally gotten to the stage where there hadn't been significant
|
||||
changes to the API in some time, and people have a bad feeling about
|
||||
libraries with versions < 1.0.
|
||||
libraries with versions < 1.0. Version 1.0.0 was released in
|
||||
March 1998.
|
||||
|
||||
****
|
||||
Note that some of the changes to the png_info structure render this
|
||||
@@ -28,8 +33,8 @@ directly, to avoid such problems in the future.
|
||||
It is important to note that the APIs do not make current programs
|
||||
that access the info struct directly incompatible with the new
|
||||
library. However, it is strongly suggested that new programs use
|
||||
the new APIs (as shown in example.c), and older programs be converted
|
||||
to the new format, to facilitate upgrades in the future.
|
||||
the new APIs (as shown in example.c and pngtest.c), and older programs
|
||||
be converted to the new format, to facilitate upgrades in the future.
|
||||
****
|
||||
|
||||
Additions since 0.90 include the ability to compile libpng as a
|
||||
@@ -50,7 +55,8 @@ critical or an ancillary chunk.
|
||||
|
||||
The changes made to the library, and bugs fixed are based on discussions
|
||||
on the PNG implementation mailing list <png-implement@ccrc.wustl.edu>
|
||||
and not on material submitted to Guy.
|
||||
and not on material submitted privately to Guy, Andreas, or Glenn. They will
|
||||
forward any good suggestions to the list.
|
||||
|
||||
For a detailed description on using libpng, read libpng.txt. For
|
||||
examples of libpng in a program, see example.c and pngtest.c. For usage
|
||||
@@ -123,22 +129,26 @@ gladly listen. Even if your suggestion is not used for version
|
||||
|
||||
Files in this distribution:
|
||||
|
||||
ANNOUNCE => Announcement of this version, with recent changes
|
||||
CHANGES => Description of changes between libpng versions
|
||||
KNOWNBUG => List of known bugs and deficiencies
|
||||
LICENSE => License to use and redistribute libpng
|
||||
README => This file
|
||||
TODO => Things not implemented in the current library
|
||||
build.bat => MS-DOS batch file for Borland compiler
|
||||
descrip.mms => VMS project file
|
||||
Y2KINFO => Statement of Y2K compliance
|
||||
example.c => Example code for using libpng functions
|
||||
libpng.3 => manual page for libpng
|
||||
libpng.3 => manual page for libpng (includes libpng.txt)
|
||||
libpng.txt => Description of libpng and its functions
|
||||
libpngpf.3 => manual page for libpng's private functions
|
||||
png.5 => manual page for the PNG format
|
||||
png.c => Basic interface functions common to library
|
||||
png.h => Library function and interface declarations
|
||||
pngconf.h => System specific library configuration
|
||||
pngasmrd.h => Header file for assembler-coded functions
|
||||
pngerror.c => Error/warning message I/O functions
|
||||
pngget.c => Functions for retrieving info from struct
|
||||
pngmem.c => Memory handling functions
|
||||
pngnow.png => PNG logo
|
||||
pngpread.c => Progressive reading functions
|
||||
pngread.c => Read data/helper high-level functions
|
||||
pngrio.c => Lowest-level data read I/O functions
|
||||
@@ -152,20 +162,33 @@ Files in this distribution:
|
||||
pngwrite.c => High-level write functions
|
||||
pngwtran.c => Write data transformations
|
||||
pngwutil.c => Write utility functions
|
||||
contrib => Contributions
|
||||
gregbook => source code for PNG reading and writing, from
|
||||
Greg Roelofs' "PNG: The Definitive Guide",
|
||||
O'Reilly, 1999
|
||||
pngminus => Simple pnm2png and png2pnm programs
|
||||
pngsuite => Test images
|
||||
scripts => Directory containing scripts for building libpng:
|
||||
descrip.mms => VMS makefile for MMS or MMK
|
||||
makefile.std => Generic UNIX makefile
|
||||
makefile.std => Generic UNIX makefile (cc, creates static libpng.a)
|
||||
makefile.linux => Linux/ELF makefile
|
||||
(gcc, creates libpng.so.2.1.0.6e)
|
||||
makefile.gcmmx => Linux/ELF makefile (gcc, creates
|
||||
libpng.so.2.1.0.6e, uses assembler code
|
||||
tuned for Intel MMX platform)
|
||||
makefile.gcc => Generic makefile (gcc, creates static libpng.a)
|
||||
makefile.knr => Archaic UNIX Makefile that converts files with
|
||||
ansi2knr (Requires ansi2knr.c from
|
||||
ftp://ftp.cs.wisc.edu/ghost)
|
||||
makefile.dec => DEC Alpha UNIX makefile
|
||||
makefile.hpux => HPUX (10.20 and 11.00) makefile
|
||||
makefile.sgi => Silicon Graphics IRIX makefile
|
||||
makefile.ibmc => IBM C/C++ version 3.x for Win32 and OS/2 (static)
|
||||
libpng.icc => Project file, IBM VisualAge/C++ 4.0 or later
|
||||
makefile.sgi => Silicon Graphics IRIX (cc, creates static lib)
|
||||
makefile.sggcc => Silicon Graphics (gcc, creates libpng.so.2.1.0.6e)
|
||||
makefile.sunos => Sun makefile
|
||||
makefile.solaris => Solaris 2.X makefile
|
||||
(gcc, creates libpng.so.2.1.0.4d)
|
||||
makefile.linux => Linux/ELF makefile
|
||||
(gcc, creates libpng.so.2.1.0.4d)
|
||||
(gcc, creates libpng.so.2.1.0.6e)
|
||||
makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc
|
||||
makefile.mips => MIPS makefile
|
||||
makefile.acorn => Acorn makefile
|
||||
@@ -175,20 +198,21 @@ Files in this distribution:
|
||||
scripts/SCOPTIONS.ppc)
|
||||
makefile.atari => Atari makefile
|
||||
makefile.beos => BEOS makefile for X86
|
||||
makefile.borland => Borland makefile
|
||||
build.bat => MS-DOS batch file for Borland compiler
|
||||
makefile.bor => Borland makefile (uses bcc)
|
||||
makefile.bc32 => 32-bit Borland C++ (all modules compiled in C mode)
|
||||
makefile.bd32 => To make a png32bd.dll with Borland C++ 4.5
|
||||
makefile.tc3 => Turbo C 3.0 makefile
|
||||
makefile.dj2 => DJGPP 2 makefile
|
||||
makefile.msc => Microsoft C makefile
|
||||
makefile.vcawin32 => makefile for Microsoft Visual C++ 5.0 and
|
||||
later (uses assembler code)
|
||||
later (uses assembler code tuned for Intel MMX
|
||||
platform)
|
||||
makefile.vcwin32 => makefile for Microsoft Visual C++ 4.0 and
|
||||
later (does not use assembler code)
|
||||
makefile.turboc3 => Turbo C 3.0 makefile
|
||||
makefile.os2 => OS/2 Makefile (gcc and emx, requires pngos2.def)
|
||||
pngos2.def => OS/2 module definition file used by makefile.os2
|
||||
makefile.watcom => Watcom 10a+ Makefile, 32-bit flat memory model
|
||||
makevms.com => VMS build script
|
||||
pngdll.mak => To make a png32bd.dll with Borland C++ 4.5
|
||||
pngdef.pas => Defines for a png32bd.dll with Borland C++ 4.5
|
||||
SCOPTIONS.ppc => Used with smakefile.ppc
|
||||
|
||||
|
||||
9
TODO
@@ -1,14 +1,11 @@
|
||||
TODO - list of things to do for libpng:
|
||||
|
||||
Final bug fixes.
|
||||
Fix problem with C++ and EXTERN "C".
|
||||
Finish work on the no-floating-point version (including gamma compensation)
|
||||
Better C++ wrapper/full C++ implementation?
|
||||
Keep up with public chunks.
|
||||
sPLT chunk handling.
|
||||
Fix problem with C++ and EXTERN "C".
|
||||
cHRM transformation.
|
||||
Support for application-defined chunk handlers.
|
||||
Improve setjmp/longjmp usage or remove it in favor of returning error codes.
|
||||
High-level API for reading images.
|
||||
Add "grayscale->palette" transformation and "palette->grayscale" detection.
|
||||
Improved dithering.
|
||||
Multi-lingual error and warning message support.
|
||||
@@ -17,8 +14,6 @@ Man pages for function calls.
|
||||
Better documentation.
|
||||
Better filter selection
|
||||
(counting huffman bits/precompression? filter inertia? filter costs?).
|
||||
Optional palette (sPLT) creation.
|
||||
Histogram creation.
|
||||
Text conversion between different code pages (Latin-1 -> Mac and DOS).
|
||||
Improve API by hiding the info_ptr.
|
||||
Make a no-floating-point version.
|
||||
|
||||
30
Y2KINFO
@@ -1,29 +1,29 @@
|
||||
Y2K compliance in libpng:
|
||||
=========================
|
||||
|
||||
October 6, 1999
|
||||
|
||||
|
||||
April 10, 2000
|
||||
|
||||
Since the PNG Development group is an ad-hoc body, we can't make
|
||||
an official declaration.
|
||||
|
||||
|
||||
This is your unofficial assurance that libpng from version 0.71 and
|
||||
upward through 1.0.4d are Y2K compliant. It is my belief that earlier
|
||||
upward through 1.0.6e are Y2K compliant. It is my belief that earlier
|
||||
versions were also Y2K compliant.
|
||||
|
||||
|
||||
Libpng only has three year fields. One is a 2-byte unsigned integer
|
||||
that will hold years up to 65535. The other two hold the date in text
|
||||
format, and will hold years up to 9999.
|
||||
|
||||
|
||||
The integer is
|
||||
"png_uint_16 year" in png_time_struct.
|
||||
|
||||
|
||||
The strings are
|
||||
"png_charp time_buffer" in png_struct and
|
||||
"near_time_buffer", which is a local character string in png.c.
|
||||
|
||||
|
||||
There are seven time-related functions:
|
||||
|
||||
png_convert_to_rfc_1123() in png.c
|
||||
png_convert_to_rfc_1123() in png.c
|
||||
(formerly png_convert_to_rfc_1152() in error)
|
||||
png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c
|
||||
png_convert_from_time_t() in pngwrite.c
|
||||
@@ -31,8 +31,8 @@
|
||||
png_handle_tIME() in pngrutil.c, called in pngread.c
|
||||
png_set_tIME() in pngset.c
|
||||
png_write_tIME() in pngwutil.c, called in pngwrite.c
|
||||
|
||||
All appear to handle dates properly in a Y2K environment. The
|
||||
|
||||
All appear to handle dates properly in a Y2K environment. The
|
||||
png_convert_from_time_t() function calls gmtime() to convert from system
|
||||
clock time, which returns (year - 1900), which we properly convert to
|
||||
the full 4-digit year. There is a possibility that applications using
|
||||
@@ -42,14 +42,14 @@
|
||||
but this is not under our control. The libpng documentation has always
|
||||
stated that it works with 4-digit years, and the APIs have been
|
||||
documented as such.
|
||||
|
||||
|
||||
The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
|
||||
integer to hold the year, and can hold years as large as 65535.
|
||||
|
||||
zlib, upon which libpng depends, is also Y2K compliant. It contains
|
||||
no date-related code.
|
||||
|
||||
|
||||
|
||||
|
||||
Glenn Randers-Pehrson
|
||||
libpng maintainer
|
||||
PNG Development Group
|
||||
|
||||
6
configure
vendored
Executable file
@@ -0,0 +1,6 @@
|
||||
echo "
|
||||
There is no \"configure\" script for Libpng-1.0.6e. Instead, please
|
||||
copy the appropriate makefile for your system from the \"scripts\"
|
||||
directory. Read the INSTALL file for more details.
|
||||
"
|
||||
|
||||
26
contrib/gregbook/LICENSE
Normal file
@@ -0,0 +1,26 @@
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1998-2000 Greg Roelofs. All rights reserved.
|
||||
|
||||
This software is provided "as is," without warranty of any kind,
|
||||
express or implied. In no event shall the author or contributors
|
||||
be held liable for any damages arising in any way from the use of
|
||||
this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute
|
||||
it freely, subject to the following restrictions:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, disclaimer, and this list of conditions.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, disclaimer, and this list of conditions in the documenta-
|
||||
tion and/or other materials provided with the distribution.
|
||||
3. All advertising materials mentioning features or use of this
|
||||
software must display the following acknowledgment:
|
||||
|
||||
This product includes software developed by Greg Roelofs
|
||||
and contributors for the book, "PNG: The Definitive Guide,"
|
||||
published by O'Reilly and Associates.
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
104
contrib/gregbook/Makefile.unx
Normal file
@@ -0,0 +1,104 @@
|
||||
# Sample makefile for rpng-x / rpng2-x / wpng using gcc and make.
|
||||
# Greg Roelofs
|
||||
# Last modified: 28 February 2000
|
||||
#
|
||||
# The programs built by this makefile are described in the book,
|
||||
# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and
|
||||
# Associates, 1999). Go buy a copy, eh? Buy some for friends
|
||||
# and family, too. (Not that this is a blatant plug or anything.)
|
||||
#
|
||||
# Invoke this makefile from a shell prompt in the usual way; for example:
|
||||
#
|
||||
# make -f Makefile.unx
|
||||
#
|
||||
# This makefile assumes libpng and zlib have already been built or downloaded
|
||||
# and are both installed in /usr/local/{include,lib} (as indicated by the
|
||||
# PNG* and Z* macros below). Edit as appropriate--choose only ONE each of
|
||||
# the PNGINC, PNGLIB, ZINC and ZLIB lines.
|
||||
#
|
||||
# This makefile builds statically linked executables (against libpng and zlib,
|
||||
# that is), but that can be changed by uncommenting the appropriate PNGLIB and
|
||||
# ZLIB lines.
|
||||
|
||||
|
||||
# macros --------------------------------------------------------------------
|
||||
|
||||
PNGINC = -I/usr/local/include
|
||||
#PNGLIB = -L/usr/local/lib -lpng # dynamically linked against libpng
|
||||
PNGLIB = /usr/local/lib/libpng.a # statically linked against libpng
|
||||
# or:
|
||||
#PNGINC = -I../..
|
||||
#PNGLIB = -L../.. -lpng
|
||||
#PNGLIB = ../../libpng.a
|
||||
|
||||
ZINC = -I/usr/local/include
|
||||
#ZLIB = -L/usr/local/lib -lz # dynamically linked against zlib
|
||||
ZLIB = /usr/local/lib/libz.a # statically linked against zlib
|
||||
#ZINC = -I../zlib
|
||||
#ZLIB = -L../zlib -lz
|
||||
#ZLIB = ../../../zlib/libz.a
|
||||
|
||||
#XINC = -I/usr/include/X11 # old-style, stock X distributions
|
||||
#XLIB = -L/usr/lib/X11 -lX11
|
||||
#XINC = -I/usr/openwin/include/X11 # Sun workstations (OpenWindows)
|
||||
#XLIB = -L/usr/openwin/lib -lX11
|
||||
XINC = -I/usr/X11R6/include # new X distributions (XFree86, etc.)
|
||||
XLIB = -L/usr/X11R6/lib -lX11
|
||||
|
||||
INCS = $(PNGINC) $(ZINC) $(XINC)
|
||||
RLIBS = $(PNGLIB) $(ZLIB) $(XLIB) -lm
|
||||
WLIBS = $(PNGLIB) $(ZLIB)
|
||||
|
||||
CC = gcc
|
||||
LD = gcc
|
||||
RM = rm -f
|
||||
CFLAGS = -O -Wall $(INCS)
|
||||
# [note that -Wall is a gcc-specific compilation flag ("most warnings on")]
|
||||
# [-ansi, -pedantic and -W can also be used]
|
||||
LDFLAGS =
|
||||
O = .o
|
||||
E =
|
||||
|
||||
RPNG = rpng-x
|
||||
RPNG2 = rpng2-x
|
||||
WPNG = wpng
|
||||
|
||||
ROBJS = $(RPNG)$(O) readpng$(O)
|
||||
ROBJS2 = $(RPNG2)$(O) readpng2$(O)
|
||||
WOBJS = $(WPNG)$(O) writepng$(O)
|
||||
|
||||
EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
|
||||
|
||||
|
||||
# implicit make rules -------------------------------------------------------
|
||||
|
||||
.c$(O):
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
|
||||
|
||||
# dependencies --------------------------------------------------------------
|
||||
|
||||
all: $(EXES)
|
||||
|
||||
$(RPNG)$(E): $(ROBJS)
|
||||
$(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBS)
|
||||
|
||||
$(RPNG2)$(E): $(ROBJS2)
|
||||
$(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBS)
|
||||
|
||||
$(WPNG)$(E): $(WOBJS)
|
||||
$(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBS)
|
||||
|
||||
$(RPNG)$(O): $(RPNG).c readpng.h
|
||||
$(RPNG2)$(O): $(RPNG2).c readpng2.h
|
||||
$(WPNG)$(O): $(WPNG).c writepng.h
|
||||
|
||||
readpng$(O): readpng.c readpng.h
|
||||
readpng2$(O): readpng2.c readpng2.h
|
||||
writepng$(O): writepng.c writepng.h
|
||||
|
||||
|
||||
# maintenance ---------------------------------------------------------------
|
||||
|
||||
clean:
|
||||
$(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS)
|
||||
112
contrib/gregbook/Makefile.w32
Normal file
@@ -0,0 +1,112 @@
|
||||
# Sample makefile for rpng-win / rpng2-win / wpng using MSVC and NMAKE.
|
||||
# Greg Roelofs
|
||||
# Last modified: 16 February 1999
|
||||
#
|
||||
# The programs built by this makefile are described in the book,
|
||||
# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and
|
||||
# Associates, 1999). Go buy a copy, eh? Buy some for friends
|
||||
# and family, too. (Not that this is a blatant plug or anything.)
|
||||
#
|
||||
# Invoke this makefile from a DOS prompt window via:
|
||||
#
|
||||
# %devstudio%\vc\bin\vcvars32.bat
|
||||
# nmake -nologo -f Makefile.w32
|
||||
#
|
||||
# where %devstudio% is the installation directory for MSVC / DevStudio. If
|
||||
# you get "environment out of space" errors, create a desktop shortcut with
|
||||
# "c:\windows\command.com /e:4096" as the program command line and set the
|
||||
# working directory to this directory. Then double-click to open the new
|
||||
# DOS-prompt window with a bigger environment and retry the commands above.
|
||||
#
|
||||
# This makefile assumes libpng and zlib have already been built or downloaded
|
||||
# and are in subdirectories at the same level as the current subdirectory
|
||||
# (as indicated by the PNGPATH and ZPATH macros below). Edit as appropriate.
|
||||
#
|
||||
# Note that the names of the dynamic and static libpng and zlib libraries
|
||||
# used below may change in later releases of the libraries. This makefile
|
||||
# builds statically linked executables, but that can be changed by uncom-
|
||||
# menting the appropriate PNGLIB and ZLIB lines.
|
||||
|
||||
!include <ntwin32.mak>
|
||||
|
||||
|
||||
# macros --------------------------------------------------------------------
|
||||
|
||||
PNGPATH = ../..
|
||||
PNGINC = -I$(PNGPATH)
|
||||
#PNGLIB = $(PNGPATH)/pngdll.lib
|
||||
PNGLIB = $(PNGPATH)/libpng.lib
|
||||
|
||||
ZPATH = ../../../zlib
|
||||
ZINC = -I$(ZPATH)
|
||||
#ZLIB = $(ZPATH)/zlibdll.lib
|
||||
ZLIB = $(ZPATH)/zlibstat.lib
|
||||
|
||||
WINLIBS = -defaultlib:user32.lib gdi32.lib
|
||||
# ["real" apps may also need comctl32.lib, comdlg32.lib, winmm.lib, etc.]
|
||||
|
||||
INCS = $(PNGINC) $(ZINC)
|
||||
RLIBS = $(PNGLIB) $(ZLIB) $(WINLIBS)
|
||||
WLIBS = $(PNGLIB) $(ZLIB)
|
||||
|
||||
CC = cl
|
||||
LD = link
|
||||
RM = del
|
||||
CFLAGS = -nologo -O -W3 $(INCS) $(cvars)
|
||||
# [note that -Wall is an MSVC-specific compilation flag ("all warnings on")]
|
||||
# [see %devstudio%\vc\include\win32.mak for cvars macro definition]
|
||||
O = .obj
|
||||
E = .exe
|
||||
|
||||
RLDFLAGS = -nologo -subsystem:windows
|
||||
WLDFLAGS = -nologo
|
||||
|
||||
RPNG = rpng-win
|
||||
RPNG2 = rpng2-win
|
||||
WPNG = wpng
|
||||
|
||||
ROBJS = $(RPNG)$(O) readpng$(O)
|
||||
ROBJS2 = $(RPNG2)$(O) readpng2$(O)
|
||||
WOBJS = $(WPNG)$(O) writepng$(O)
|
||||
|
||||
EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
|
||||
|
||||
|
||||
# implicit make rules -------------------------------------------------------
|
||||
|
||||
.c$(O):
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
|
||||
|
||||
# dependencies --------------------------------------------------------------
|
||||
|
||||
all: $(EXES)
|
||||
|
||||
$(RPNG)$(E): $(ROBJS)
|
||||
$(LD) $(RLDFLAGS) -out:$@ $(ROBJS) $(RLIBS)
|
||||
|
||||
$(RPNG2)$(E): $(ROBJS2)
|
||||
$(LD) $(RLDFLAGS) -out:$@ $(ROBJS2) $(RLIBS)
|
||||
|
||||
$(WPNG)$(E): $(WOBJS)
|
||||
$(LD) $(WLDFLAGS) -out:$@ $(WOBJS) $(WLIBS)
|
||||
|
||||
$(RPNG)$(O): $(RPNG).c readpng.h
|
||||
$(RPNG2)$(O): $(RPNG2).c readpng2.h
|
||||
$(WPNG)$(O): $(WPNG).c writepng.h
|
||||
|
||||
readpng$(O): readpng.c readpng.h
|
||||
readpng2$(O): readpng2.c readpng2.h
|
||||
writepng$(O): writepng.c writepng.h
|
||||
|
||||
|
||||
# maintenance ---------------------------------------------------------------
|
||||
|
||||
clean:
|
||||
# ideally we could just do this:
|
||||
# $(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS)
|
||||
# ...but the Windows "DEL" command is none too bright, so:
|
||||
$(RM) r*$(E)
|
||||
$(RM) w*$(E)
|
||||
$(RM) r*$(O)
|
||||
$(RM) w*$(O)
|
||||
183
contrib/gregbook/README
Normal file
@@ -0,0 +1,183 @@
|
||||
===========================
|
||||
PNG: The Definitive Guide
|
||||
===========================
|
||||
|
||||
Source Code
|
||||
|
||||
Chapters 13, 14 and 15 of "PNG: The Definitive Guide" discuss three free,
|
||||
cross-platform demo programs that show how to use the libpng reference
|
||||
library: rpng, rpng2 and wpng. rpng and rpng2 are viewers; the first is
|
||||
a very simple example that that shows how a standard file-viewer might use
|
||||
libpng, while the second is designed to process streaming data and shows
|
||||
how a web browser might be written. wpng is a simple command-line program
|
||||
that reads binary PGM and PPM files (the ``raw'' grayscale and RGB subsets
|
||||
of PBMPLUS/NetPBM) and converts them to PNG.
|
||||
|
||||
The source code for all three demo programs currently compiles under
|
||||
Unix, OpenVMS, and 32-bit Windows. (Special thanks to Martin Zinser,
|
||||
zinser@decus.de, for making the necessary changes for OpenVMS and for
|
||||
providing an appropriate build script.) Build instructions can be
|
||||
found below.
|
||||
|
||||
Files:
|
||||
|
||||
README this file
|
||||
README.w32 additional Windows-specific information
|
||||
LICENSE terms of distribution and reuse (BSD-like)
|
||||
|
||||
Makefile.unx Unix makefile
|
||||
Makefile.w32 Windows (MSVC) makefile
|
||||
makevms.com OpenVMS build script
|
||||
|
||||
rpng-win.c Windows front end for the basic viewer
|
||||
rpng-x.c X Window System (Unix, OpenVMS) front end
|
||||
readpng.c generic back end for the basic viewer
|
||||
readpng.h header file for the basic viewer
|
||||
|
||||
rpng2-win.c Windows front end for the progressive viewer
|
||||
rpng2-x.c X front end for the progressive viewer
|
||||
readpng2.c generic back end for the progressive viewer
|
||||
readpng2.h header file for the progressive viewer
|
||||
|
||||
wpng.c generic (text) front end for the converter
|
||||
writepng.c generic back end for the converter
|
||||
writepng.h header file for the converter
|
||||
|
||||
toucan.png transparent PNG for testing (by Stefan Schneider)
|
||||
|
||||
Note that the programs are designed to be functional, but their primary
|
||||
purpose is to demonstrate how to use libpng to add PNG support to other
|
||||
programs. As such, their user interfaces are crude and definitely not
|
||||
intended for everyday use.
|
||||
|
||||
Please see http://www.cdrom.com/pub/png/pngbook.html for further infor-
|
||||
mation and links to the latest version of the source code, and Chapters
|
||||
13-15 of the book for detailed discussion of the three programs.
|
||||
|
||||
Greg Roelofs
|
||||
19 March 2000
|
||||
|
||||
|
||||
BUILD INSTRUCTIONS
|
||||
|
||||
- Prerequisites:
|
||||
|
||||
- zlib ftp://ftp.cdrom.com/pub/infozip/zlib/zlib.html
|
||||
- libpng http://www.cdrom.com/pub/png/pngcode.html
|
||||
- pngbook http://www.cdrom.com/pub/png/book/sources.html
|
||||
|
||||
The pngbook demo programs are explicitly designed to demonstrate proper
|
||||
coding techniques for using the libpng reference library. As a result,
|
||||
you need to download and build both zlib (on which libpng depends) and
|
||||
libpng. A common build setup is to place the zlib, libpng and pngbook
|
||||
subdirectory trees ("folders") in the same parent directory. Then the
|
||||
libpng build can refer to files in ../zlib (or ..\zlib or [-.zlib]),
|
||||
and similarly for the pngbook build.
|
||||
|
||||
Note that all three packages are designed to be built from a command
|
||||
line by default; those who wish to use a graphical or other integrated
|
||||
development environments are on their own.
|
||||
|
||||
|
||||
- Unix:
|
||||
|
||||
Unpack the latest pngbook sources (which should correspond to this
|
||||
README file) into a directory and change into that directory.
|
||||
|
||||
Copy Makefile.unx to Makefile and edit the PNG* and Z* variables
|
||||
appropriately (possibly also the X* variables if necessary).
|
||||
|
||||
make
|
||||
|
||||
There is no "install" target, so copy the three executables somewhere
|
||||
in your path or run them from the current directory. All three will
|
||||
print a basic usage screen when run without any command-line arguments;
|
||||
see the book for more details.
|
||||
|
||||
|
||||
- Windows:
|
||||
|
||||
Unpack the latest pngbook sources (which should correspond to this
|
||||
README file) into a folder, open a "DOS shell" or "command prompt"
|
||||
or equivalent command-line window, and cd into the folder where you
|
||||
unpacked the source code.
|
||||
|
||||
For MSVC, set up the necessary environment variables by invoking
|
||||
|
||||
%devstudio%\vc\bin\vcvars32.bat
|
||||
|
||||
where where %devstudio% is the installation directory for MSVC /
|
||||
DevStudio. If you get "environment out of space" errors under 95/98,
|
||||
create a desktop shortcut with "c:\windows\command.com /e:4096" as
|
||||
the program command line and set the working directory to the pngbook
|
||||
directory. Then double-click to open the new DOS-prompt window with
|
||||
a bigger environment and retry the commands above.
|
||||
|
||||
Copy Makefile.w32 to Makefile and edit the PNGPATH and ZPATH variables
|
||||
appropriately (possibly also the "INC" and "LIB" variables if needed).
|
||||
Note that the names of the dynamic and static libpng and zlib libraries
|
||||
used in the makefile may change in later releases of the libraries.
|
||||
Also note that, as of libpng version 1.0.5, MSVC DLL builds do not work.
|
||||
This makefile therefore builds statically linked executables, but if
|
||||
the DLL problems ever get fixed, uncommenting the appropriate PNGLIB
|
||||
and ZLIB lines will build dynamically linked executables instead.
|
||||
|
||||
Do the build by typing
|
||||
|
||||
nmake
|
||||
|
||||
The result should be three executables: rpng-win.exe, rpng2-win.exe,
|
||||
and wpng.exe. Copy them somewhere in your PATH or run them from the
|
||||
current folder. Unlike the Unix versions, the two windowed programs
|
||||
(rpng and rpng2) do not display a usage screen when invoked without
|
||||
command-line arguments; see README.w32 for brief help or the book for
|
||||
details. Note that the programs use the Unix-style "-" character to
|
||||
specify options, instead of the more common DOS/Windows "/" character.
|
||||
|
||||
|
||||
- OpenVMS:
|
||||
|
||||
Unpack the pngbook sources into a subdirectory and change into that
|
||||
subdirectory.
|
||||
|
||||
Edit makevms.com appropriately, specifically the zpath and pngpath
|
||||
variables.
|
||||
|
||||
@makevms
|
||||
|
||||
To run the programs, they probably first need to be set up as "foreign
|
||||
symbols," with "disk" and "dir" set appropriately:
|
||||
|
||||
$ rpng == "$disk:[dir]rpng-x.exe"
|
||||
$ rpng2 == "$disk:[dir]rpng2-x.exe"
|
||||
$ wpng == "$disk:[dir]wpng.exe"
|
||||
|
||||
All three will print a basic usage screen when run without any command-
|
||||
line arguments; see the book for more details. Note that the options
|
||||
style is Unix-like, i.e., preceded by "-" rather than "/".
|
||||
|
||||
|
||||
RUNNING THE PROGRAMS: (VERY) BRIEF INTRO
|
||||
|
||||
rpng is a simple PNG viewer that can display transparent PNGs with a
|
||||
specified background color; for example,
|
||||
|
||||
rpng -bgcolor #ff0000 toucan.png
|
||||
|
||||
would display the image with a red background. rpng2 is a progressive
|
||||
viewer that simulates a web browser in some respects; it can display
|
||||
images against either a background color or a dynamically generated
|
||||
background image. For example:
|
||||
|
||||
rpng2 -bgpat 16 toucan.png
|
||||
|
||||
wpng is a purely command-line image converter from binary PBMPLUS/NetPBM
|
||||
format (.pgm or .ppm) to PNG; for example,
|
||||
|
||||
wpng -time < toucan.ppm > toucan.png
|
||||
|
||||
would convert the specified PPM file (using redirection) to PNG, auto-
|
||||
matically setting the PNG modification-time chunk.
|
||||
|
||||
All options can be abbreviated to the shortest unique value; for example,
|
||||
"-bgc" for -bgcolor (versus "-bgp" for -bgpat), or "-g" for -gamma.
|
||||
53
contrib/gregbook/README.w32
Normal file
@@ -0,0 +1,53 @@
|
||||
See the main README file for basic instructions on compiling and running
|
||||
the programs. See http://www.cdrom.com/pub/png/pngbook.html for further
|
||||
information and links to the source code, and Chapters 13-15 of the book
|
||||
for detailed discussion of the three programs.
|
||||
|
||||
Since the two viewers, rpng and rpng2, are both designed to write infor-
|
||||
mation to the console (i.e., a DOS-window command line) while displaying
|
||||
the image in a graphical window--and since I haven't yet figured out how
|
||||
to do that under Windows--here are the usage screens for the two programs:
|
||||
|
||||
|
||||
rpng-win 1.02 of 19 March 2000: Simple PNG Viewer for Windows
|
||||
Compiled with libpng 1.0.5; using libpng 1.0.5.
|
||||
Compiled with zlib 1.1.3; using zlib 1.1.3.
|
||||
|
||||
Usage: rpng-win [-gamma exp] [-bgcolor bg] file.png
|
||||
exp transfer-function exponent (``gamma'') of the display
|
||||
system in floating-point format (e.g., ``2.2''); equal
|
||||
to the product of the lookup-table exponent (varies)
|
||||
and the CRT exponent (usually 2.2); must be positive
|
||||
bg desired background color in 7-character hex RGB format
|
||||
(e.g., ``#ff7f00'' for orange: same as HTML colors);
|
||||
used with transparent images
|
||||
|
||||
Press Q, Esc or mouse button 1 after image is displayed to quit.
|
||||
|
||||
|
||||
rpng2-win 1.04 of 19 March 2000: Progressive PNG Viewer for Windows
|
||||
Compiled with libpng 1.0.5; using libpng 1.0.5.
|
||||
Compiled with zlib 1.1.3; using zlib 1.1.3.
|
||||
|
||||
Usage: rpng2-win [-gamma exp] [-bgcolor bg | -bgpat pat] [-timing] file.png
|
||||
|
||||
exp transfer-function exponent (``gamma'') of the display
|
||||
system in floating-point format (e.g., ``2.2''); equal
|
||||
to the product of the lookup-table exponent (varies)
|
||||
and the CRT exponent (usually 2.2); must be positive
|
||||
bg desired background color in 7-character hex RGB format
|
||||
(e.g., ``#ff7f00'' for orange: same as HTML colors);
|
||||
used with transparent images; overrides -bgpat
|
||||
pat desired background pattern number (1-16); used with
|
||||
transparent images; overrides -bgcolor
|
||||
-timing enables delay for every block read, to simulate modem
|
||||
download of image (~36 Kbps)
|
||||
|
||||
Press Q, Esc or mouse button 1 after image is displayed to quit.
|
||||
|
||||
|
||||
The usage screen for the third (non-windowed) program, wpng, can be seen
|
||||
simply by invoking it without any parameters (``wpng'').
|
||||
|
||||
Greg Roelofs
|
||||
19 March 2000
|
||||
118
contrib/gregbook/makevms.com
Normal file
@@ -0,0 +1,118 @@
|
||||
$!------------------------------------------------------------------------------
|
||||
$! make "PNG: The Definitive Guide" demo programs (for X) under OpenVMS
|
||||
$!
|
||||
$! Script created by Martin Zinser for libpng; modified by Greg Roelofs
|
||||
$! for standalone pngbook source distribution.
|
||||
$!
|
||||
$!
|
||||
$! Set locations where zlib and libpng sources live.
|
||||
$!
|
||||
$ zpath = "[-.zlib]"
|
||||
$ pngpath = "[-.libpng]"
|
||||
$!
|
||||
$! USE THESE INSTEAD if building from libpng's [.contrib.gregbook] directory:
|
||||
$! zpath = "[---.zlib]"
|
||||
$! pngpath = "[--]"
|
||||
$!
|
||||
$! Look for the compiler used.
|
||||
$!
|
||||
$ ccopt="/include=(''zpath',''pngpath')"
|
||||
$ if f$getsyi("HW_MODEL").ge.1024
|
||||
$ then
|
||||
$ ccopt = "/prefix=all"+ccopt
|
||||
$ comp = "__decc__=1"
|
||||
$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
|
||||
$ else
|
||||
$ if f$search("SYS$SYSTEM:DECC$COMPILER.EXE").eqs.""
|
||||
$ then
|
||||
$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
|
||||
$ if f$search("SYS$SYSTEM:VAXC.EXE").eqs.""
|
||||
$ then
|
||||
$ comp = "__gcc__=1"
|
||||
$ CC :== GCC
|
||||
$ else
|
||||
$ comp = "__vaxc__=1"
|
||||
$ endif
|
||||
$ else
|
||||
$ if f$trnlnm("SYS").eqs."" then define sys decc$library_include:
|
||||
$ ccopt = "/decc/prefix=all"+ccopt
|
||||
$ comp = "__decc__=1"
|
||||
$ endif
|
||||
$ endif
|
||||
$ open/write lopt lib.opt
|
||||
$ write lopt "''pngpath'libpng.olb/lib"
|
||||
$ write lopt "''zpath'libz.olb/lib"
|
||||
$ close lopt
|
||||
$ open/write xopt x11.opt
|
||||
$ write xopt "sys$library:decw$xlibshr.exe/share"
|
||||
$ close xopt
|
||||
$!
|
||||
$! Build 'em.
|
||||
$!
|
||||
$ write sys$output "Compiling PNG book programs ..."
|
||||
$ CALL MAKE readpng.OBJ "cc ''CCOPT' readpng" -
|
||||
readpng.c readpng.h
|
||||
$ CALL MAKE readpng2.OBJ "cc ''CCOPT' readpng2" -
|
||||
readpng2.c readpng2.h
|
||||
$ CALL MAKE writepng.OBJ "cc ''CCOPT' writepng" -
|
||||
writepng.c writepng.h
|
||||
$ write sys$output "Building rpng-x..."
|
||||
$ CALL MAKE rpng-x.OBJ "cc ''CCOPT' rpng-x" -
|
||||
rpng-x.c readpng.h
|
||||
$ call make rpng-x.exe -
|
||||
"LINK rpng-x,readpng,lib.opt/opt,x11.opt/opt" -
|
||||
rpng-x.obj readpng.obj
|
||||
$ write sys$output "Building rpng2-x..."
|
||||
$ CALL MAKE rpng2-x.OBJ "cc ''CCOPT' rpng2-x" -
|
||||
rpng2-x.c readpng2.h
|
||||
$ call make rpng2-x.exe -
|
||||
"LINK rpng2-x,readpng2,lib.opt/opt,x11.opt/opt" -
|
||||
rpng2-x.obj readpng2.obj
|
||||
$ write sys$output "Building wpng..."
|
||||
$ CALL MAKE wpng.OBJ "cc ''CCOPT' wpng" -
|
||||
wpng.c writepng.h
|
||||
$ call make wpng.exe -
|
||||
"LINK wpng,writepng,lib.opt/opt" -
|
||||
wpng.obj writepng.obj
|
||||
$ exit
|
||||
$!
|
||||
$!
|
||||
$MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES
|
||||
$ V = 'F$Verify(0)
|
||||
$! P1 = What we are trying to make
|
||||
$! P2 = Command to make it
|
||||
$! P3 - P8 What it depends on
|
||||
$
|
||||
$ If F$Search(P1) .Eqs. "" Then Goto Makeit
|
||||
$ Time = F$CvTime(F$File(P1,"RDT"))
|
||||
$arg=3
|
||||
$Loop:
|
||||
$ Argument = P'arg
|
||||
$ If Argument .Eqs. "" Then Goto Exit
|
||||
$ El=0
|
||||
$Loop2:
|
||||
$ File = F$Element(El," ",Argument)
|
||||
$ If File .Eqs. " " Then Goto Endl
|
||||
$ AFile = ""
|
||||
$Loop3:
|
||||
$ OFile = AFile
|
||||
$ AFile = F$Search(File)
|
||||
$ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl
|
||||
$ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit
|
||||
$ Goto Loop3
|
||||
$NextEL:
|
||||
$ El = El + 1
|
||||
$ Goto Loop2
|
||||
$EndL:
|
||||
$ arg=arg+1
|
||||
$ If arg .Le. 8 Then Goto Loop
|
||||
$ Goto Exit
|
||||
$
|
||||
$Makeit:
|
||||
$ VV=F$VERIFY(0)
|
||||
$ write sys$output P2
|
||||
$ 'P2
|
||||
$ VV='F$Verify(VV)
|
||||
$Exit:
|
||||
$ If V Then Set Verify
|
||||
$ENDSUBROUTINE
|
||||
280
contrib/gregbook/readpng.c
Normal file
@@ -0,0 +1,280 @@
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
rpng - simple PNG display program readpng.c
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1998-2000 Greg Roelofs. All rights reserved.
|
||||
|
||||
This software is provided "as is," without warranty of any kind,
|
||||
express or implied. In no event shall the author or contributors
|
||||
be held liable for any damages arising in any way from the use of
|
||||
this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute
|
||||
it freely, subject to the following restrictions:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, disclaimer, and this list of conditions.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, disclaimer, and this list of conditions in the documenta-
|
||||
tion and/or other materials provided with the distribution.
|
||||
3. All advertising materials mentioning features or use of this
|
||||
software must display the following acknowledgment:
|
||||
|
||||
This product includes software developed by Greg Roelofs
|
||||
and contributors for the book, "PNG: The Definitive Guide,"
|
||||
published by O'Reilly and Associates.
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "png.h" /* libpng header; includes zlib.h */
|
||||
#include "readpng.h" /* typedefs, common macros, public prototypes */
|
||||
|
||||
/* future versions of libpng will provide this macro: */
|
||||
#ifndef png_jmpbuf
|
||||
# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
|
||||
#endif
|
||||
|
||||
|
||||
static png_structp png_ptr = NULL;
|
||||
static png_infop info_ptr = NULL;
|
||||
|
||||
png_uint_32 width, height;
|
||||
int bit_depth, color_type;
|
||||
uch *image_data = NULL;
|
||||
|
||||
|
||||
void readpng_version_info(void)
|
||||
{
|
||||
fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n",
|
||||
PNG_LIBPNG_VER_STRING, png_libpng_ver);
|
||||
fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n",
|
||||
ZLIB_VERSION, zlib_version);
|
||||
}
|
||||
|
||||
|
||||
/* return value = 0 for success, 1 for bad sig, 2 for bad IHDR, 4 for no mem */
|
||||
|
||||
int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight)
|
||||
{
|
||||
uch sig[8];
|
||||
|
||||
|
||||
/* first do a quick check that the file really is a PNG image; could
|
||||
* have used slightly more general png_sig_cmp() function instead */
|
||||
|
||||
fread(sig, 1, 8, infile);
|
||||
if (!png_check_sig(sig, 8))
|
||||
return 1; /* bad signature */
|
||||
|
||||
|
||||
/* could pass pointers to user-defined error handlers instead of NULLs: */
|
||||
|
||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (!png_ptr)
|
||||
return 4; /* out of memory */
|
||||
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr) {
|
||||
png_destroy_read_struct(&png_ptr, NULL, NULL);
|
||||
return 4; /* out of memory */
|
||||
}
|
||||
|
||||
|
||||
/* we could create a second info struct here (end_info), but it's only
|
||||
* useful if we want to keep pre- and post-IDAT chunk info separated
|
||||
* (mainly for PNG-aware image editors and converters) */
|
||||
|
||||
|
||||
/* setjmp() must be called in every function that calls a PNG-reading
|
||||
* libpng function */
|
||||
|
||||
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
png_init_io(png_ptr, infile);
|
||||
png_set_sig_bytes(png_ptr, 8); /* we already read the 8 signature bytes */
|
||||
|
||||
png_read_info(png_ptr, info_ptr); /* read all PNG info up to image data */
|
||||
|
||||
|
||||
/* alternatively, could make separate calls to png_get_image_width(),
|
||||
* etc., but want bit_depth and color_type for later [don't care about
|
||||
* compression_type and filter_type => NULLs] */
|
||||
|
||||
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
|
||||
NULL, NULL, NULL);
|
||||
*pWidth = width;
|
||||
*pHeight = height;
|
||||
|
||||
|
||||
/* OK, that's all we need for now; return happy */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* returns 0 if succeeds, 1 if fails due to no bKGD chunk, 2 if libpng error;
|
||||
* scales values to 8-bit if necessary */
|
||||
|
||||
int readpng_get_bgcolor(uch *red, uch *green, uch *blue)
|
||||
{
|
||||
png_color_16p pBackground;
|
||||
|
||||
|
||||
/* setjmp() must be called in every function that calls a PNG-reading
|
||||
* libpng function */
|
||||
|
||||
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
if (!png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD))
|
||||
return 1;
|
||||
|
||||
/* it is not obvious from the libpng documentation, but this function
|
||||
* takes a pointer to a pointer, and it always returns valid red, green
|
||||
* and blue values, regardless of color_type: */
|
||||
|
||||
png_get_bKGD(png_ptr, info_ptr, &pBackground);
|
||||
|
||||
|
||||
/* however, it always returns the raw bKGD data, regardless of any
|
||||
* bit-depth transformations, so check depth and adjust if necessary */
|
||||
|
||||
if (bit_depth == 16) {
|
||||
*red = pBackground->red >> 8;
|
||||
*green = pBackground->green >> 8;
|
||||
*blue = pBackground->blue >> 8;
|
||||
} else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
|
||||
if (bit_depth == 1)
|
||||
*red = *green = *blue = pBackground->gray? 255 : 0;
|
||||
else if (bit_depth == 2)
|
||||
*red = *green = *blue = (255/3) * pBackground->gray;
|
||||
else /* bit_depth == 4 */
|
||||
*red = *green = *blue = (255/15) * pBackground->gray;
|
||||
} else {
|
||||
*red = (uch)pBackground->red;
|
||||
*green = (uch)pBackground->green;
|
||||
*blue = (uch)pBackground->blue;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* display_exponent == LUT_exponent * CRT_exponent */
|
||||
|
||||
uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes)
|
||||
{
|
||||
double gamma;
|
||||
png_uint_32 i, rowbytes;
|
||||
png_bytepp row_pointers = NULL;
|
||||
|
||||
|
||||
/* setjmp() must be called in every function that calls a PNG-reading
|
||||
* libpng function */
|
||||
|
||||
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* expand palette images to RGB, low-bit-depth grayscale images to 8 bits,
|
||||
* transparency chunks to full alpha channel; strip 16-bit-per-sample
|
||||
* images to 8 bits per sample; and convert grayscale to RGB[A] */
|
||||
|
||||
if (color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
png_set_expand(png_ptr);
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
|
||||
png_set_expand(png_ptr);
|
||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
|
||||
png_set_expand(png_ptr);
|
||||
if (bit_depth == 16)
|
||||
png_set_strip_16(png_ptr);
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY ||
|
||||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
png_set_gray_to_rgb(png_ptr);
|
||||
|
||||
|
||||
/* unlike the example in the libpng documentation, we have *no* idea where
|
||||
* this file may have come from--so if it doesn't have a file gamma, don't
|
||||
* do any correction ("do no harm") */
|
||||
|
||||
if (png_get_gAMA(png_ptr, info_ptr, &gamma))
|
||||
png_set_gamma(png_ptr, display_exponent, gamma);
|
||||
|
||||
|
||||
/* all transformations have been registered; now update info_ptr data,
|
||||
* get rowbytes and channels, and allocate image memory */
|
||||
|
||||
png_read_update_info(png_ptr, info_ptr);
|
||||
|
||||
*pRowbytes = rowbytes = png_get_rowbytes(png_ptr, info_ptr);
|
||||
*pChannels = (int)png_get_channels(png_ptr, info_ptr);
|
||||
|
||||
if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) {
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
return NULL;
|
||||
}
|
||||
if ((row_pointers = (png_bytepp)malloc(height*sizeof(png_bytep))) == NULL) {
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
free(image_data);
|
||||
image_data = NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Trace((stderr, "readpng_get_image: rowbytes = %ld, height = %ld\n", rowbytes, height));
|
||||
|
||||
|
||||
/* set the individual row_pointers to point at the correct offsets */
|
||||
|
||||
for (i = 0; i < height; ++i)
|
||||
row_pointers[i] = image_data + i*rowbytes;
|
||||
|
||||
|
||||
/* now we can go ahead and just read the whole image */
|
||||
|
||||
png_read_image(png_ptr, row_pointers);
|
||||
|
||||
|
||||
/* and we're done! (png_read_end() can be omitted if no processing of
|
||||
* post-IDAT text/time/etc. is desired) */
|
||||
|
||||
free(row_pointers);
|
||||
row_pointers = NULL;
|
||||
|
||||
png_read_end(png_ptr, NULL);
|
||||
|
||||
return image_data;
|
||||
}
|
||||
|
||||
|
||||
void readpng_cleanup(int free_image_data)
|
||||
{
|
||||
if (free_image_data && image_data) {
|
||||
free(image_data);
|
||||
image_data = NULL;
|
||||
}
|
||||
|
||||
if (png_ptr && info_ptr) {
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
png_ptr = NULL;
|
||||
info_ptr = NULL;
|
||||
}
|
||||
}
|
||||
64
contrib/gregbook/readpng.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
rpng - simple PNG display program readpng.h
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1998-2000 Greg Roelofs. All rights reserved.
|
||||
|
||||
This software is provided "as is," without warranty of any kind,
|
||||
express or implied. In no event shall the author or contributors
|
||||
be held liable for any damages arising in any way from the use of
|
||||
this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute
|
||||
it freely, subject to the following restrictions:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, disclaimer, and this list of conditions.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, disclaimer, and this list of conditions in the documenta-
|
||||
tion and/or other materials provided with the distribution.
|
||||
3. All advertising materials mentioning features or use of this
|
||||
software must display the following acknowledgment:
|
||||
|
||||
This product includes software developed by Greg Roelofs
|
||||
and contributors for the book, "PNG: The Definitive Guide,"
|
||||
published by O'Reilly and Associates.
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef TRUE
|
||||
# define TRUE 1
|
||||
# define FALSE 0
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
# define MAX(a,b) ((a) > (b)? (a) : (b))
|
||||
# define MIN(a,b) ((a) < (b)? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
# define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);}
|
||||
#else
|
||||
# define Trace(x) ;
|
||||
#endif
|
||||
|
||||
typedef unsigned char uch;
|
||||
typedef unsigned short ush;
|
||||
typedef unsigned long ulg;
|
||||
|
||||
|
||||
/* prototypes for public functions in readpng.c */
|
||||
|
||||
void readpng_version_info(void);
|
||||
|
||||
int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight);
|
||||
|
||||
int readpng_get_bgcolor(uch *bg_red, uch *bg_green, uch *bg_blue);
|
||||
|
||||
uch *readpng_get_image(double display_exponent, int *pChannels,
|
||||
ulg *pRowbytes);
|
||||
|
||||
void readpng_cleanup(int free_image_data);
|
||||
424
contrib/gregbook/readpng2.c
Normal file
@@ -0,0 +1,424 @@
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
rpng2 - progressive-model PNG display program readpng2.c
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1998-2000 Greg Roelofs. All rights reserved.
|
||||
|
||||
This software is provided "as is," without warranty of any kind,
|
||||
express or implied. In no event shall the author or contributors
|
||||
be held liable for any damages arising in any way from the use of
|
||||
this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute
|
||||
it freely, subject to the following restrictions:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, disclaimer, and this list of conditions.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, disclaimer, and this list of conditions in the documenta-
|
||||
tion and/or other materials provided with the distribution.
|
||||
3. All advertising materials mentioning features or use of this
|
||||
software must display the following acknowledgment:
|
||||
|
||||
This product includes software developed by Greg Roelofs
|
||||
and contributors for the book, "PNG: The Definitive Guide,"
|
||||
published by O'Reilly and Associates.
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#include <stdlib.h> /* for exit() prototype */
|
||||
|
||||
#include "png.h" /* libpng header; includes zlib.h and setjmp.h */
|
||||
#include "readpng2.h" /* typedefs, common macros, public prototypes */
|
||||
|
||||
|
||||
/* local prototypes */
|
||||
|
||||
static void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr);
|
||||
static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row,
|
||||
png_uint_32 row_num, int pass);
|
||||
static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr);
|
||||
static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg);
|
||||
|
||||
|
||||
|
||||
|
||||
void readpng2_version_info(void)
|
||||
{
|
||||
fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n",
|
||||
PNG_LIBPNG_VER_STRING, png_libpng_ver);
|
||||
fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n",
|
||||
ZLIB_VERSION, zlib_version);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int readpng2_check_sig(uch *sig, int num)
|
||||
{
|
||||
return png_check_sig(sig, num);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* returns 0 for success, 2 for libpng problem, 4 for out of memory */
|
||||
|
||||
int readpng2_init(mainprog_info *mainprog_ptr)
|
||||
{
|
||||
png_structp png_ptr; /* note: temporary variables! */
|
||||
png_infop info_ptr;
|
||||
|
||||
|
||||
/* could also replace libpng warning-handler (final NULL), but no need: */
|
||||
|
||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr,
|
||||
readpng2_error_handler, NULL);
|
||||
if (!png_ptr)
|
||||
return 4; /* out of memory */
|
||||
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr) {
|
||||
png_destroy_read_struct(&png_ptr, NULL, NULL);
|
||||
return 4; /* out of memory */
|
||||
}
|
||||
|
||||
|
||||
/* we could create a second info struct here (end_info), but it's only
|
||||
* useful if we want to keep pre- and post-IDAT chunk info separated
|
||||
* (mainly for PNG-aware image editors and converters) */
|
||||
|
||||
|
||||
/* setjmp() must be called in every function that calls a PNG-reading
|
||||
* libpng function, unless an alternate error handler was installed--
|
||||
* but compatible error handlers must either use longjmp() themselves
|
||||
* (as in this program) or exit immediately, so here we are: */
|
||||
|
||||
if (setjmp(mainprog_ptr->jmpbuf)) {
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
/* instead of doing png_init_io() here, now we set up our callback
|
||||
* functions for progressive decoding */
|
||||
|
||||
png_set_progressive_read_fn(png_ptr, mainprog_ptr,
|
||||
readpng2_info_callback, readpng2_row_callback, readpng2_end_callback);
|
||||
|
||||
|
||||
/* make sure we save our pointers for use in readpng2_decode_data() */
|
||||
|
||||
mainprog_ptr->png_ptr = png_ptr;
|
||||
mainprog_ptr->info_ptr = info_ptr;
|
||||
|
||||
|
||||
/* and that's all there is to initialization */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* returns 0 for success, 2 for libpng (longjmp) problem */
|
||||
|
||||
int readpng2_decode_data(mainprog_info *mainprog_ptr, uch *rawbuf, ulg length)
|
||||
{
|
||||
png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
|
||||
png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
|
||||
|
||||
|
||||
/* setjmp() must be called in every function that calls a PNG-reading
|
||||
* libpng function */
|
||||
|
||||
if (setjmp(mainprog_ptr->jmpbuf)) {
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
mainprog_ptr->png_ptr = NULL;
|
||||
mainprog_ptr->info_ptr = NULL;
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
/* hand off the next chunk of input data to libpng for decoding */
|
||||
|
||||
png_process_data(png_ptr, info_ptr, rawbuf, length);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
mainprog_info *mainprog_ptr;
|
||||
int color_type, bit_depth;
|
||||
double gamma;
|
||||
|
||||
|
||||
/* setjmp() doesn't make sense here, because we'd either have to exit(),
|
||||
* longjmp() ourselves, or return control to libpng, which doesn't want
|
||||
* to see us again. By not doing anything here, libpng will instead jump
|
||||
* to readpng2_decode_data(), which can return an error value to the main
|
||||
* program. */
|
||||
|
||||
|
||||
/* retrieve the pointer to our special-purpose struct, using the png_ptr
|
||||
* that libpng passed back to us (i.e., not a global this time--there's
|
||||
* no real difference for a single image, but for a multithreaded browser
|
||||
* decoding several PNG images at the same time, one needs to avoid mixing
|
||||
* up different images' structs) */
|
||||
|
||||
mainprog_ptr = png_get_progressive_ptr(png_ptr);
|
||||
|
||||
if (mainprog_ptr == NULL) { /* we be hosed */
|
||||
fprintf(stderr,
|
||||
"readpng2 error: main struct not recoverable in info_callback.\n");
|
||||
fflush(stderr);
|
||||
return;
|
||||
/*
|
||||
* Alternatively, we could call our error-handler just like libpng
|
||||
* does, which would effectively terminate the program. Since this
|
||||
* can only happen if png_ptr gets redirected somewhere odd or the
|
||||
* main PNG struct gets wiped, we're probably toast anyway. (If
|
||||
* png_ptr itself is NULL, we would not have been called.)
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/* this is just like in the non-progressive case */
|
||||
|
||||
png_get_IHDR(png_ptr, info_ptr, &mainprog_ptr->width,
|
||||
&mainprog_ptr->height, &bit_depth, &color_type, NULL, NULL, NULL);
|
||||
|
||||
|
||||
/* since we know we've read all of the PNG file's "header" (i.e., up
|
||||
* to IDAT), we can check for a background color here */
|
||||
|
||||
if (mainprog_ptr->need_bgcolor &&
|
||||
png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD))
|
||||
{
|
||||
png_color_16p pBackground;
|
||||
|
||||
/* it is not obvious from the libpng documentation, but this function
|
||||
* takes a pointer to a pointer, and it always returns valid red,
|
||||
* green and blue values, regardless of color_type: */
|
||||
png_get_bKGD(png_ptr, info_ptr, &pBackground);
|
||||
|
||||
/* however, it always returns the raw bKGD data, regardless of any
|
||||
* bit-depth transformations, so check depth and adjust if necessary */
|
||||
if (bit_depth == 16) {
|
||||
mainprog_ptr->bg_red = pBackground->red >> 8;
|
||||
mainprog_ptr->bg_green = pBackground->green >> 8;
|
||||
mainprog_ptr->bg_blue = pBackground->blue >> 8;
|
||||
} else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
|
||||
if (bit_depth == 1)
|
||||
mainprog_ptr->bg_red = mainprog_ptr->bg_green =
|
||||
mainprog_ptr->bg_blue = pBackground->gray? 255 : 0;
|
||||
else if (bit_depth == 2)
|
||||
mainprog_ptr->bg_red = mainprog_ptr->bg_green =
|
||||
mainprog_ptr->bg_blue = (255/3) * pBackground->gray;
|
||||
else /* bit_depth == 4 */
|
||||
mainprog_ptr->bg_red = mainprog_ptr->bg_green =
|
||||
mainprog_ptr->bg_blue = (255/15) * pBackground->gray;
|
||||
} else {
|
||||
mainprog_ptr->bg_red = (uch)pBackground->red;
|
||||
mainprog_ptr->bg_green = (uch)pBackground->green;
|
||||
mainprog_ptr->bg_blue = (uch)pBackground->blue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* as before, let libpng expand palette images to RGB, low-bit-depth
|
||||
* grayscale images to 8 bits, transparency chunks to full alpha channel;
|
||||
* strip 16-bit-per-sample images to 8 bits per sample; and convert
|
||||
* grayscale to RGB[A] */
|
||||
|
||||
if (color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
png_set_expand(png_ptr);
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
|
||||
png_set_expand(png_ptr);
|
||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
|
||||
png_set_expand(png_ptr);
|
||||
if (bit_depth == 16)
|
||||
png_set_strip_16(png_ptr);
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY ||
|
||||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
png_set_gray_to_rgb(png_ptr);
|
||||
|
||||
|
||||
/* Unlike the basic viewer, which was designed to operate on local files,
|
||||
* this program is intended to simulate a web browser--even though we
|
||||
* actually read from a local file, too. But because we are pretending
|
||||
* that most of the images originate on the Internet, we follow the recom-
|
||||
* mendation of the sRGB proposal and treat unlabelled images (no gAMA
|
||||
* chunk) as existing in the sRGB color space. That is, we assume that
|
||||
* such images have a file gamma of 0.45455, which corresponds to a PC-like
|
||||
* display system. This change in assumptions will have no effect on a
|
||||
* PC-like system, but on a Mac, SGI, NeXT or other system with a non-
|
||||
* identity lookup table, it will darken unlabelled images, which effec-
|
||||
* tively favors images from PC-like systems over those originating on
|
||||
* the local platform. Note that mainprog_ptr->display_exponent is the
|
||||
* "gamma" value for the entire display system, i.e., the product of
|
||||
* LUT_exponent and CRT_exponent. */
|
||||
|
||||
if (png_get_gAMA(png_ptr, info_ptr, &gamma))
|
||||
png_set_gamma(png_ptr, mainprog_ptr->display_exponent, gamma);
|
||||
else
|
||||
png_set_gamma(png_ptr, mainprog_ptr->display_exponent, 0.45455);
|
||||
|
||||
|
||||
/* we'll let libpng expand interlaced images, too */
|
||||
|
||||
mainprog_ptr->passes = png_set_interlace_handling(png_ptr);
|
||||
|
||||
|
||||
/* all transformations have been registered; now update info_ptr data and
|
||||
* then get rowbytes and channels */
|
||||
|
||||
png_read_update_info(png_ptr, info_ptr);
|
||||
|
||||
mainprog_ptr->rowbytes = (int)png_get_rowbytes(png_ptr, info_ptr);
|
||||
mainprog_ptr->channels = png_get_channels(png_ptr, info_ptr);
|
||||
|
||||
|
||||
/* Call the main program to allocate memory for the image buffer and
|
||||
* initialize windows and whatnot. (The old-style function-pointer
|
||||
* invocation is used for compatibility with a few supposedly ANSI
|
||||
* compilers that nevertheless barf on "fn_ptr()"-style syntax.) */
|
||||
|
||||
(*mainprog_ptr->mainprog_init)();
|
||||
|
||||
|
||||
/* and that takes care of initialization */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row,
|
||||
png_uint_32 row_num, int pass)
|
||||
{
|
||||
mainprog_info *mainprog_ptr;
|
||||
|
||||
|
||||
/* first check whether the row differs from the previous pass; if not,
|
||||
* nothing to combine or display */
|
||||
|
||||
if (!new_row)
|
||||
return;
|
||||
|
||||
|
||||
/* retrieve the pointer to our special-purpose struct so we can access
|
||||
* the old rows and image-display callback function */
|
||||
|
||||
mainprog_ptr = png_get_progressive_ptr(png_ptr);
|
||||
|
||||
|
||||
/* save the pass number for optional use by the front end */
|
||||
|
||||
mainprog_ptr->pass = pass;
|
||||
|
||||
|
||||
/* have libpng either combine the new row data with the existing row data
|
||||
* from previous passes (if interlaced) or else just copy the new row
|
||||
* into the main program's image buffer */
|
||||
|
||||
png_progressive_combine_row(png_ptr, mainprog_ptr->row_pointers[row_num],
|
||||
new_row);
|
||||
|
||||
|
||||
/* finally, call the display routine in the main program with the number
|
||||
* of the row we just updated */
|
||||
|
||||
(*mainprog_ptr->mainprog_display_row)(row_num);
|
||||
|
||||
|
||||
/* and we're ready for more */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
mainprog_info *mainprog_ptr;
|
||||
|
||||
|
||||
/* retrieve the pointer to our special-purpose struct */
|
||||
|
||||
mainprog_ptr = png_get_progressive_ptr(png_ptr);
|
||||
|
||||
|
||||
/* let the main program know that it should flush any buffered image
|
||||
* data to the display now and set a "done" flag or whatever, but note
|
||||
* that it SHOULD NOT DESTROY THE PNG STRUCTS YET--in other words, do
|
||||
* NOT call readpng2_cleanup() either here or in the finish_display()
|
||||
* routine; wait until control returns to the main program via
|
||||
* readpng2_decode_data() */
|
||||
|
||||
(*mainprog_ptr->mainprog_finish_display)();
|
||||
|
||||
|
||||
/* all done */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void readpng2_cleanup(mainprog_info *mainprog_ptr)
|
||||
{
|
||||
png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
|
||||
png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
|
||||
|
||||
if (png_ptr && info_ptr)
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
|
||||
mainprog_ptr->png_ptr = NULL;
|
||||
mainprog_ptr->info_ptr = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg)
|
||||
{
|
||||
mainprog_info *mainprog_ptr;
|
||||
|
||||
/* This function, aside from the extra step of retrieving the "error
|
||||
* pointer" (below) and the fact that it exists within the application
|
||||
* rather than within libpng, is essentially identical to libpng's
|
||||
* default error handler. The second point is critical: since both
|
||||
* setjmp() and longjmp() are called from the same code, they are
|
||||
* guaranteed to have compatible notions of how big a jmp_buf is,
|
||||
* regardless of whether _BSD_SOURCE or anything else has (or has not)
|
||||
* been defined. */
|
||||
|
||||
fprintf(stderr, "readpng2 libpng error: %s\n", msg);
|
||||
fflush(stderr);
|
||||
|
||||
mainprog_ptr = png_get_error_ptr(png_ptr);
|
||||
if (mainprog_ptr == NULL) { /* we are completely hosed now */
|
||||
fprintf(stderr,
|
||||
"readpng2 severe error: jmpbuf not recoverable; terminating.\n");
|
||||
fflush(stderr);
|
||||
exit(99);
|
||||
}
|
||||
|
||||
longjmp(mainprog_ptr->jmpbuf, 1);
|
||||
}
|
||||
86
contrib/gregbook/readpng2.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
rpng2 - progressive-model PNG display program readpng2.h
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1998-2000 Greg Roelofs. All rights reserved.
|
||||
|
||||
This software is provided "as is," without warranty of any kind,
|
||||
express or implied. In no event shall the author or contributors
|
||||
be held liable for any damages arising in any way from the use of
|
||||
this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute
|
||||
it freely, subject to the following restrictions:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, disclaimer, and this list of conditions.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, disclaimer, and this list of conditions in the documenta-
|
||||
tion and/or other materials provided with the distribution.
|
||||
3. All advertising materials mentioning features or use of this
|
||||
software must display the following acknowledgment:
|
||||
|
||||
This product includes software developed by Greg Roelofs
|
||||
and contributors for the book, "PNG: The Definitive Guide,"
|
||||
published by O'Reilly and Associates.
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef TRUE
|
||||
# define TRUE 1
|
||||
# define FALSE 0
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
# define MAX(a,b) ((a) > (b)? (a) : (b))
|
||||
# define MIN(a,b) ((a) < (b)? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
# define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);}
|
||||
#else
|
||||
# define Trace(x) ;
|
||||
#endif
|
||||
|
||||
typedef unsigned char uch;
|
||||
typedef unsigned short ush;
|
||||
typedef unsigned long ulg;
|
||||
|
||||
typedef struct _mainprog_info {
|
||||
double display_exponent;
|
||||
ulg width;
|
||||
ulg height;
|
||||
void *png_ptr;
|
||||
void *info_ptr;
|
||||
void (*mainprog_init)(void);
|
||||
void (*mainprog_display_row)(ulg row_num);
|
||||
void (*mainprog_finish_display)(void);
|
||||
uch *image_data;
|
||||
uch **row_pointers;
|
||||
jmp_buf jmpbuf;
|
||||
int passes; /* not used */
|
||||
int pass;
|
||||
int rowbytes;
|
||||
int channels;
|
||||
int need_bgcolor;
|
||||
int done;
|
||||
uch bg_red;
|
||||
uch bg_green;
|
||||
uch bg_blue;
|
||||
} mainprog_info;
|
||||
|
||||
|
||||
/* prototypes for public functions in readpng2.c */
|
||||
|
||||
void readpng2_version_info(void);
|
||||
|
||||
int readpng2_check_sig(uch *sig, int num);
|
||||
|
||||
int readpng2_init(mainprog_info *mainprog_ptr);
|
||||
|
||||
int readpng2_decode_data(mainprog_info *mainprog_ptr, uch *rawbuf, ulg length);
|
||||
|
||||
void readpng2_cleanup(mainprog_info *mainprog_ptr);
|
||||
620
contrib/gregbook/rpng-win.c
Normal file
@@ -0,0 +1,620 @@
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
rpng - simple PNG display program rpng-win.c
|
||||
|
||||
This program decodes and displays PNG images, with gamma correction and
|
||||
optionally with a user-specified background color (in case the image has
|
||||
transparency). It is very nearly the most basic PNG viewer possible.
|
||||
This version is for 32-bit Windows; it may compile under 16-bit Windows
|
||||
with a little tweaking (or maybe not).
|
||||
|
||||
to do:
|
||||
- stdout/stderr don't work! need message window (maybe scrollable?)
|
||||
- handle quoted command-line args (especially filenames with spaces)
|
||||
- have minimum window width: oh well
|
||||
- use %.1023s to simplify truncation of title-bar string?
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Changelog:
|
||||
- 1.00: initial public release
|
||||
- 1.01: modified to allow abbreviated options; fixed long/ulong mis-
|
||||
match; switched to png_jmpbuf() macro
|
||||
- 1.02: added extra set of parentheses to png_jmpbuf() macro; fixed
|
||||
command-line parsing bug
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1998-2000 Greg Roelofs. All rights reserved.
|
||||
|
||||
This software is provided "as is," without warranty of any kind,
|
||||
express or implied. In no event shall the author or contributors
|
||||
be held liable for any damages arising in any way from the use of
|
||||
this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute
|
||||
it freely, subject to the following restrictions:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, disclaimer, and this list of conditions.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, disclaimer, and this list of conditions in the documenta-
|
||||
tion and/or other materials provided with the distribution.
|
||||
3. All advertising materials mentioning features or use of this
|
||||
software must display the following acknowledgment:
|
||||
|
||||
This product includes software developed by Greg Roelofs
|
||||
and contributors for the book, "PNG: The Definitive Guide,"
|
||||
published by O'Reilly and Associates.
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
#define PROGNAME "rpng-win"
|
||||
#define LONGNAME "Simple PNG Viewer for Windows"
|
||||
#define VERSION "1.02 of 19 March 2000"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <windows.h>
|
||||
|
||||
/* #define DEBUG : this enables the Trace() macros */
|
||||
|
||||
#include "readpng.h" /* typedefs, common macros, readpng prototypes */
|
||||
|
||||
|
||||
/* could just include png.h, but this macro is the only thing we need
|
||||
* (name and typedefs changed to local versions); note that side effects
|
||||
* only happen with alpha (which could easily be avoided with
|
||||
* "ush acopy = (alpha);") */
|
||||
|
||||
#define alpha_composite(composite, fg, alpha, bg) { \
|
||||
ush temp = ((ush)(fg)*(ush)(alpha) + \
|
||||
(ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \
|
||||
(composite) = (uch)((temp + (temp >> 8)) >> 8); \
|
||||
}
|
||||
|
||||
|
||||
/* local prototypes */
|
||||
static int rpng_win_create_window(HINSTANCE hInst, int showmode);
|
||||
static int rpng_win_display_image(void);
|
||||
static void rpng_win_cleanup(void);
|
||||
LRESULT CALLBACK rpng_win_wndproc(HWND, UINT, WPARAM, LPARAM);
|
||||
|
||||
|
||||
static char titlebar[1024], *window_name = titlebar;
|
||||
static char *progname = PROGNAME;
|
||||
static char *appname = LONGNAME;
|
||||
static char *icon_name = PROGNAME; /* GRR: not (yet) used */
|
||||
static char *filename;
|
||||
static FILE *infile;
|
||||
|
||||
static char *bgstr;
|
||||
static uch bg_red=0, bg_green=0, bg_blue=0;
|
||||
|
||||
static double display_exponent;
|
||||
|
||||
static ulg image_width, image_height, image_rowbytes;
|
||||
static int image_channels;
|
||||
static uch *image_data;
|
||||
|
||||
/* Windows-specific variables */
|
||||
static ulg wimage_rowbytes;
|
||||
static uch *dib;
|
||||
static uch *wimage_data;
|
||||
static BITMAPINFOHEADER *bmih;
|
||||
|
||||
static HWND global_hwnd;
|
||||
|
||||
|
||||
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
|
||||
{
|
||||
char *args[1024]; /* arbitrary limit, but should suffice */
|
||||
char *p, *q, **argv = args;
|
||||
int argc = 0;
|
||||
int rc, alen, flen;
|
||||
int error = 0;
|
||||
int have_bg = FALSE;
|
||||
double LUT_exponent; /* just the lookup table */
|
||||
double CRT_exponent = 2.2; /* just the monitor */
|
||||
double default_display_exponent; /* whole display system */
|
||||
MSG msg;
|
||||
|
||||
|
||||
filename = (char *)NULL;
|
||||
|
||||
|
||||
/* First set the default value for our display-system exponent, i.e.,
|
||||
* the product of the CRT exponent and the exponent corresponding to
|
||||
* the frame-buffer's lookup table (LUT), if any. This is not an
|
||||
* exhaustive list of LUT values (e.g., OpenStep has a lot of weird
|
||||
* ones), but it should cover 99% of the current possibilities. And
|
||||
* yes, these ifdefs are completely wasted in a Windows program... */
|
||||
|
||||
#if defined(NeXT)
|
||||
LUT_exponent = 1.0 / 2.2;
|
||||
/*
|
||||
if (some_next_function_that_returns_gamma(&next_gamma))
|
||||
LUT_exponent = 1.0 / next_gamma;
|
||||
*/
|
||||
#elif defined(sgi)
|
||||
LUT_exponent = 1.0 / 1.7;
|
||||
/* there doesn't seem to be any documented function to get the
|
||||
* "gamma" value, so we do it the hard way */
|
||||
infile = fopen("/etc/config/system.glGammaVal", "r");
|
||||
if (infile) {
|
||||
double sgi_gamma;
|
||||
|
||||
fgets(tmpline, 80, infile);
|
||||
fclose(infile);
|
||||
sgi_gamma = atof(tmpline);
|
||||
if (sgi_gamma > 0.0)
|
||||
LUT_exponent = 1.0 / sgi_gamma;
|
||||
}
|
||||
#elif defined(Macintosh)
|
||||
LUT_exponent = 1.8 / 2.61;
|
||||
/*
|
||||
if (some_mac_function_that_returns_gamma(&mac_gamma))
|
||||
LUT_exponent = mac_gamma / 2.61;
|
||||
*/
|
||||
#else
|
||||
LUT_exponent = 1.0; /* assume no LUT: most PCs */
|
||||
#endif
|
||||
|
||||
/* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */
|
||||
default_display_exponent = LUT_exponent * CRT_exponent;
|
||||
|
||||
|
||||
/* If the user has set the SCREEN_GAMMA environment variable as suggested
|
||||
* (somewhat imprecisely) in the libpng documentation, use that; otherwise
|
||||
* use the default value we just calculated. Either way, the user may
|
||||
* override this via a command-line option. */
|
||||
|
||||
if ((p = getenv("SCREEN_GAMMA")) != NULL)
|
||||
display_exponent = atof(p);
|
||||
else
|
||||
display_exponent = default_display_exponent;
|
||||
|
||||
|
||||
/* Windows really hates command lines, so we have to set up our own argv.
|
||||
* Note that we do NOT bother with quoted arguments here, so don't use
|
||||
* filenames with spaces in 'em! */
|
||||
|
||||
argv[argc++] = PROGNAME;
|
||||
p = cmd;
|
||||
for (;;) {
|
||||
if (*p == ' ')
|
||||
while (*++p == ' ')
|
||||
;
|
||||
/* now p points at the first non-space after some spaces */
|
||||
if (*p == '\0')
|
||||
break; /* nothing after the spaces: done */
|
||||
argv[argc++] = q = p;
|
||||
while (*q && *q != ' ')
|
||||
++q;
|
||||
/* now q points at a space or the end of the string */
|
||||
if (*q == '\0')
|
||||
break; /* last argv already terminated; quit */
|
||||
*q = '\0'; /* change space to terminator */
|
||||
p = q + 1;
|
||||
}
|
||||
argv[argc] = NULL; /* terminate the argv array itself */
|
||||
|
||||
|
||||
/* Now parse the command line for options and the PNG filename. */
|
||||
|
||||
while (*++argv && !error) {
|
||||
if (!strncmp(*argv, "-gamma", 2)) {
|
||||
if (!*++argv)
|
||||
++error;
|
||||
else {
|
||||
display_exponent = atof(*argv);
|
||||
if (display_exponent <= 0.0)
|
||||
++error;
|
||||
}
|
||||
} else if (!strncmp(*argv, "-bgcolor", 2)) {
|
||||
if (!*++argv)
|
||||
++error;
|
||||
else {
|
||||
bgstr = *argv;
|
||||
if (strlen(bgstr) != 7 || bgstr[0] != '#')
|
||||
++error;
|
||||
else
|
||||
have_bg = TRUE;
|
||||
}
|
||||
} else {
|
||||
if (**argv != '-') {
|
||||
filename = *argv;
|
||||
if (argv[1]) /* shouldn't be any more args after filename */
|
||||
++error;
|
||||
} else
|
||||
++error; /* not expecting any other options */
|
||||
}
|
||||
}
|
||||
|
||||
if (!filename) {
|
||||
++error;
|
||||
} else if (!(infile = fopen(filename, "rb"))) {
|
||||
fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename);
|
||||
++error;
|
||||
} else {
|
||||
if ((rc = readpng_init(infile, &image_width, &image_height)) != 0) {
|
||||
switch (rc) {
|
||||
case 1:
|
||||
fprintf(stderr, PROGNAME
|
||||
": [%s] is not a PNG file: incorrect signature\n",
|
||||
filename);
|
||||
break;
|
||||
case 2:
|
||||
fprintf(stderr, PROGNAME
|
||||
": [%s] has bad IHDR (libpng longjmp)\n",
|
||||
filename);
|
||||
break;
|
||||
case 4:
|
||||
fprintf(stderr, PROGNAME ": insufficient memory\n");
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, PROGNAME
|
||||
": unknown readpng_init() error\n");
|
||||
break;
|
||||
}
|
||||
++error;
|
||||
}
|
||||
if (error)
|
||||
fclose(infile);
|
||||
}
|
||||
|
||||
|
||||
/* usage screen */
|
||||
|
||||
if (error) {
|
||||
fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname);
|
||||
readpng_version_info();
|
||||
fprintf(stderr, "\n"
|
||||
"Usage: %s [-gamma exp] [-bgcolor bg] file.png\n"
|
||||
" exp \ttransfer-function exponent (``gamma'') of the display\n"
|
||||
"\t\t system in floating-point format (e.g., ``%.1f''); equal\n"
|
||||
"\t\t to the product of the lookup-table exponent (varies)\n"
|
||||
"\t\t and the CRT exponent (usually 2.2); must be positive\n"
|
||||
" bg \tdesired background color in 7-character hex RGB format\n"
|
||||
"\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n"
|
||||
"\t\t used with transparent images\n"
|
||||
"\nPress Q, Esc or mouse button 1 after image is displayed to quit.\n"
|
||||
"\n", PROGNAME, default_display_exponent);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/* set the title-bar string, but make sure buffer doesn't overflow */
|
||||
|
||||
alen = strlen(appname);
|
||||
flen = strlen(filename);
|
||||
if (alen + flen + 3 > 1023)
|
||||
sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023));
|
||||
else
|
||||
sprintf(titlebar, "%s: %s", appname, filename);
|
||||
|
||||
|
||||
/* if the user didn't specify a background color on the command line,
|
||||
* check for one in the PNG file--if not, the initialized values of 0
|
||||
* (black) will be used */
|
||||
|
||||
if (have_bg)
|
||||
sscanf(bgstr+1, "%2x%2x%2x", &bg_red, &bg_green, &bg_blue);
|
||||
else if (readpng_get_bgcolor(&bg_red, &bg_green, &bg_blue) > 1) {
|
||||
readpng_cleanup(TRUE);
|
||||
fprintf(stderr, PROGNAME
|
||||
": libpng error while checking for background color\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
|
||||
/* do the basic Windows initialization stuff, make the window and fill it
|
||||
* with the background color */
|
||||
|
||||
if (rpng_win_create_window(hInst, showmode))
|
||||
exit(2);
|
||||
|
||||
|
||||
/* decode the image, all at once */
|
||||
|
||||
Trace((stderr, "calling readpng_get_image()\n"))
|
||||
image_data = readpng_get_image(display_exponent, &image_channels,
|
||||
&image_rowbytes);
|
||||
Trace((stderr, "done with readpng_get_image()\n"))
|
||||
|
||||
|
||||
/* done with PNG file, so clean up to minimize memory usage (but do NOT
|
||||
* nuke image_data!) */
|
||||
|
||||
readpng_cleanup(FALSE);
|
||||
fclose(infile);
|
||||
|
||||
if (!image_data) {
|
||||
fprintf(stderr, PROGNAME ": unable to decode PNG image\n");
|
||||
exit(3);
|
||||
}
|
||||
|
||||
|
||||
/* display image (composite with background if requested) */
|
||||
|
||||
Trace((stderr, "calling rpng_win_display_image()\n"))
|
||||
if (rpng_win_display_image()) {
|
||||
free(image_data);
|
||||
exit(4);
|
||||
}
|
||||
Trace((stderr, "done with rpng_win_display_image()\n"))
|
||||
|
||||
|
||||
/* wait for the user to tell us when to quit */
|
||||
|
||||
printf(
|
||||
"Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n");
|
||||
fflush(stdout);
|
||||
|
||||
while (GetMessage(&msg, NULL, 0, 0)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
|
||||
/* OK, we're done: clean up all image and Windows resources and go away */
|
||||
|
||||
rpng_win_cleanup();
|
||||
|
||||
return msg.wParam;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int rpng_win_create_window(HINSTANCE hInst, int showmode)
|
||||
{
|
||||
uch *dest;
|
||||
int extra_width, extra_height;
|
||||
ulg i, j;
|
||||
WNDCLASSEX wndclass;
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
Allocate memory for the display-specific version of the image (round up
|
||||
to multiple of 4 for Windows DIB).
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
wimage_rowbytes = ((3*image_width + 3L) >> 2) << 2;
|
||||
|
||||
if (!(dib = (uch *)malloc(sizeof(BITMAPINFOHEADER) +
|
||||
wimage_rowbytes*image_height)))
|
||||
{
|
||||
return 4; /* fail */
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
Initialize the DIB. Negative height means to use top-down BMP ordering
|
||||
(must be uncompressed, but that's what we want). Bit count of 1, 4 or 8
|
||||
implies a colormap of RGBX quads, but 24-bit BMPs just use B,G,R values
|
||||
directly => wimage_data begins immediately after BMP header.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
memset(dib, 0, sizeof(BITMAPINFOHEADER));
|
||||
bmih = (BITMAPINFOHEADER *)dib;
|
||||
bmih->biSize = sizeof(BITMAPINFOHEADER);
|
||||
bmih->biWidth = image_width;
|
||||
bmih->biHeight = -((long)image_height);
|
||||
bmih->biPlanes = 1;
|
||||
bmih->biBitCount = 24;
|
||||
bmih->biCompression = 0;
|
||||
wimage_data = dib + sizeof(BITMAPINFOHEADER);
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
Fill in background color (black by default); data are in BGR order.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
for (j = 0; j < image_height; ++j) {
|
||||
dest = wimage_data + j*wimage_rowbytes;
|
||||
for (i = image_width; i > 0; --i) {
|
||||
*dest++ = bg_blue;
|
||||
*dest++ = bg_green;
|
||||
*dest++ = bg_red;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
Set the window parameters.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
memset(&wndclass, 0, sizeof(wndclass));
|
||||
|
||||
wndclass.cbSize = sizeof(wndclass);
|
||||
wndclass.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wndclass.lpfnWndProc = rpng_win_wndproc;
|
||||
wndclass.hInstance = hInst;
|
||||
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wndclass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
|
||||
wndclass.lpszMenuName = NULL;
|
||||
wndclass.lpszClassName = progname;
|
||||
wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
|
||||
|
||||
RegisterClassEx(&wndclass);
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
Finally, create the window.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
extra_width = 2*(GetSystemMetrics(SM_CXBORDER) +
|
||||
GetSystemMetrics(SM_CXDLGFRAME));
|
||||
extra_height = 2*(GetSystemMetrics(SM_CYBORDER) +
|
||||
GetSystemMetrics(SM_CYDLGFRAME)) +
|
||||
GetSystemMetrics(SM_CYCAPTION);
|
||||
|
||||
global_hwnd = CreateWindow(progname, titlebar, WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, image_width+extra_width,
|
||||
image_height+extra_height, NULL, NULL, hInst, NULL);
|
||||
|
||||
ShowWindow(global_hwnd, showmode);
|
||||
UpdateWindow(global_hwnd);
|
||||
|
||||
return 0;
|
||||
|
||||
} /* end function rpng_win_create_window() */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int rpng_win_display_image()
|
||||
{
|
||||
uch *src, *dest;
|
||||
uch r, g, b, a;
|
||||
ulg i, row, lastrow;
|
||||
RECT rect;
|
||||
|
||||
|
||||
Trace((stderr, "beginning display loop (image_channels == %d)\n",
|
||||
image_channels))
|
||||
Trace((stderr, "(width = %ld, rowbytes = %ld, wimage_rowbytes = %d)\n",
|
||||
image_width, image_rowbytes, wimage_rowbytes))
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
Blast image data to buffer. This whole routine takes place before the
|
||||
message loop begins, so there's no real point in any pseudo-progressive
|
||||
display...
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
for (lastrow = row = 0; row < image_height; ++row) {
|
||||
src = image_data + row*image_rowbytes;
|
||||
dest = wimage_data + row*wimage_rowbytes;
|
||||
if (image_channels == 3) {
|
||||
for (i = image_width; i > 0; --i) {
|
||||
r = *src++;
|
||||
g = *src++;
|
||||
b = *src++;
|
||||
*dest++ = b;
|
||||
*dest++ = g; /* note reverse order */
|
||||
*dest++ = r;
|
||||
}
|
||||
} else /* if (image_channels == 4) */ {
|
||||
for (i = image_width; i > 0; --i) {
|
||||
r = *src++;
|
||||
g = *src++;
|
||||
b = *src++;
|
||||
a = *src++;
|
||||
if (a == 255) {
|
||||
*dest++ = b;
|
||||
*dest++ = g;
|
||||
*dest++ = r;
|
||||
} else if (a == 0) {
|
||||
*dest++ = bg_blue;
|
||||
*dest++ = bg_green;
|
||||
*dest++ = bg_red;
|
||||
} else {
|
||||
/* this macro (copied from png.h) composites the
|
||||
* foreground and background values and puts the
|
||||
* result into the first argument; there are no
|
||||
* side effects with the first argument */
|
||||
alpha_composite(*dest++, b, a, bg_blue);
|
||||
alpha_composite(*dest++, g, a, bg_green);
|
||||
alpha_composite(*dest++, r, a, bg_red);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* display after every 16 lines */
|
||||
if (((row+1) & 0xf) == 0) {
|
||||
rect.left = 0L;
|
||||
rect.top = (LONG)lastrow;
|
||||
rect.right = (LONG)image_width; /* possibly off by one? */
|
||||
rect.bottom = (LONG)lastrow + 16L; /* possibly off by one? */
|
||||
InvalidateRect(global_hwnd, &rect, FALSE);
|
||||
UpdateWindow(global_hwnd); /* similar to XFlush() */
|
||||
lastrow = row + 1;
|
||||
}
|
||||
}
|
||||
|
||||
Trace((stderr, "calling final image-flush routine\n"))
|
||||
if (lastrow < image_height) {
|
||||
rect.left = 0L;
|
||||
rect.top = (LONG)lastrow;
|
||||
rect.right = (LONG)image_width; /* possibly off by one? */
|
||||
rect.bottom = (LONG)image_height; /* possibly off by one? */
|
||||
InvalidateRect(global_hwnd, &rect, FALSE);
|
||||
UpdateWindow(global_hwnd); /* similar to XFlush() */
|
||||
}
|
||||
|
||||
/*
|
||||
last param determines whether or not background is wiped before paint
|
||||
InvalidateRect(global_hwnd, NULL, TRUE);
|
||||
UpdateWindow(global_hwnd);
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void rpng_win_cleanup()
|
||||
{
|
||||
if (image_data) {
|
||||
free(image_data);
|
||||
image_data = NULL;
|
||||
}
|
||||
|
||||
if (dib) {
|
||||
free(dib);
|
||||
dib = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
LRESULT CALLBACK rpng_win_wndproc(HWND hwnd, UINT iMsg, WPARAM wP, LPARAM lP)
|
||||
{
|
||||
HDC hdc;
|
||||
PAINTSTRUCT ps;
|
||||
int rc;
|
||||
|
||||
switch (iMsg) {
|
||||
case WM_CREATE:
|
||||
/* one-time processing here, if any */
|
||||
return 0;
|
||||
|
||||
case WM_PAINT:
|
||||
hdc = BeginPaint(hwnd, &ps);
|
||||
/* dest */
|
||||
rc = StretchDIBits(hdc, 0, 0, image_width, image_height,
|
||||
/* source */
|
||||
0, 0, image_width, image_height,
|
||||
wimage_data, (BITMAPINFO *)bmih,
|
||||
/* iUsage: no clue */
|
||||
0, SRCCOPY);
|
||||
EndPaint(hwnd, &ps);
|
||||
return 0;
|
||||
|
||||
/* wait for the user to tell us when to quit */
|
||||
case WM_CHAR:
|
||||
switch (wP) { /* only need one, so ignore repeat count */
|
||||
case 'q':
|
||||
case 'Q':
|
||||
case 0x1B: /* Esc key */
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WM_LBUTTONDOWN: /* another way of quitting */
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return DefWindowProc(hwnd, iMsg, wP, lP);
|
||||
}
|
||||
843
contrib/gregbook/rpng-x.c
Normal file
@@ -0,0 +1,843 @@
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
rpng - simple PNG display program rpng-x.c
|
||||
|
||||
This program decodes and displays PNG images, with gamma correction and
|
||||
optionally with a user-specified background color (in case the image has
|
||||
transparency). It is very nearly the most basic PNG viewer possible.
|
||||
This version is for the X Window System (tested by author under Unix and
|
||||
by Martin Zinser under OpenVMS; may work under OS/2 with some tweaking).
|
||||
|
||||
to do:
|
||||
- 8-bit support
|
||||
- use %.1023s to simplify truncation of title-bar string?
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Changelog:
|
||||
- 1.01: initial public release
|
||||
- 1.02: modified to allow abbreviated options; fixed long/ulong mis-
|
||||
match; switched to png_jmpbuf() macro
|
||||
- 1.10: added support for non-default visuals; fixed X pixel-conversion
|
||||
- 1.11: added extra set of parentheses to png_jmpbuf() macro; fixed
|
||||
command-line parsing bug
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1998-2000 Greg Roelofs. All rights reserved.
|
||||
|
||||
This software is provided "as is," without warranty of any kind,
|
||||
express or implied. In no event shall the author or contributors
|
||||
be held liable for any damages arising in any way from the use of
|
||||
this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute
|
||||
it freely, subject to the following restrictions:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, disclaimer, and this list of conditions.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, disclaimer, and this list of conditions in the documenta-
|
||||
tion and/or other materials provided with the distribution.
|
||||
3. All advertising materials mentioning features or use of this
|
||||
software must display the following acknowledgment:
|
||||
|
||||
This product includes software developed by Greg Roelofs
|
||||
and contributors for the book, "PNG: The Definitive Guide,"
|
||||
published by O'Reilly and Associates.
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
#define PROGNAME "rpng-x"
|
||||
#define LONGNAME "Simple PNG Viewer for X"
|
||||
#define VERSION "1.11 of 19 March 2000"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/Xos.h>
|
||||
#include <X11/keysym.h>
|
||||
|
||||
/* #define DEBUG : this enables the Trace() macros */
|
||||
|
||||
#include "readpng.h" /* typedefs, common macros, readpng prototypes */
|
||||
|
||||
|
||||
/* could just include png.h, but this macro is the only thing we need
|
||||
* (name and typedefs changed to local versions); note that side effects
|
||||
* only happen with alpha (which could easily be avoided with
|
||||
* "ush acopy = (alpha);") */
|
||||
|
||||
#define alpha_composite(composite, fg, alpha, bg) { \
|
||||
ush temp = ((ush)(fg)*(ush)(alpha) + \
|
||||
(ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \
|
||||
(composite) = (uch)((temp + (temp >> 8)) >> 8); \
|
||||
}
|
||||
|
||||
|
||||
/* local prototypes */
|
||||
static int rpng_x_create_window(void);
|
||||
static int rpng_x_display_image(void);
|
||||
static void rpng_x_cleanup(void);
|
||||
static int rpng_x_msb(ulg u32val);
|
||||
|
||||
|
||||
static char titlebar[1024], *window_name = titlebar;
|
||||
static char *appname = LONGNAME;
|
||||
static char *icon_name = PROGNAME;
|
||||
static char *filename;
|
||||
static FILE *infile;
|
||||
|
||||
static char *bgstr;
|
||||
static uch bg_red=0, bg_green=0, bg_blue=0;
|
||||
|
||||
static double display_exponent;
|
||||
|
||||
static ulg image_width, image_height, image_rowbytes;
|
||||
static int image_channels;
|
||||
static uch *image_data;
|
||||
|
||||
/* X-specific variables */
|
||||
static char *displayname;
|
||||
static XImage *ximage;
|
||||
static Display *display;
|
||||
static int depth;
|
||||
static Visual *visual;
|
||||
static XVisualInfo *visual_list;
|
||||
static int RShift, GShift, BShift;
|
||||
static ulg RMask, GMask, BMask;
|
||||
static Window window;
|
||||
static GC gc;
|
||||
static Colormap colormap;
|
||||
|
||||
static int have_nondefault_visual = FALSE;
|
||||
static int have_colormap = FALSE;
|
||||
static int have_window = FALSE;
|
||||
/*
|
||||
ulg numcolors=0, pixels[256];
|
||||
ush reds[256], greens[256], blues[256];
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#ifdef sgi
|
||||
char tmpline[80];
|
||||
#endif
|
||||
char *p;
|
||||
int rc, alen, flen;
|
||||
int error = 0;
|
||||
int have_bg = FALSE;
|
||||
double LUT_exponent; /* just the lookup table */
|
||||
double CRT_exponent = 2.2; /* just the monitor */
|
||||
double default_display_exponent; /* whole display system */
|
||||
XEvent e;
|
||||
KeySym k;
|
||||
|
||||
|
||||
displayname = (char *)NULL;
|
||||
filename = (char *)NULL;
|
||||
|
||||
|
||||
/* First set the default value for our display-system exponent, i.e.,
|
||||
* the product of the CRT exponent and the exponent corresponding to
|
||||
* the frame-buffer's lookup table (LUT), if any. This is not an
|
||||
* exhaustive list of LUT values (e.g., OpenStep has a lot of weird
|
||||
* ones), but it should cover 99% of the current possibilities. */
|
||||
|
||||
#if defined(NeXT)
|
||||
LUT_exponent = 1.0 / 2.2;
|
||||
/*
|
||||
if (some_next_function_that_returns_gamma(&next_gamma))
|
||||
LUT_exponent = 1.0 / next_gamma;
|
||||
*/
|
||||
#elif defined(sgi)
|
||||
LUT_exponent = 1.0 / 1.7;
|
||||
/* there doesn't seem to be any documented function to get the
|
||||
* "gamma" value, so we do it the hard way */
|
||||
infile = fopen("/etc/config/system.glGammaVal", "r");
|
||||
if (infile) {
|
||||
double sgi_gamma;
|
||||
|
||||
fgets(tmpline, 80, infile);
|
||||
fclose(infile);
|
||||
sgi_gamma = atof(tmpline);
|
||||
if (sgi_gamma > 0.0)
|
||||
LUT_exponent = 1.0 / sgi_gamma;
|
||||
}
|
||||
#elif defined(Macintosh)
|
||||
LUT_exponent = 1.8 / 2.61;
|
||||
/*
|
||||
if (some_mac_function_that_returns_gamma(&mac_gamma))
|
||||
LUT_exponent = mac_gamma / 2.61;
|
||||
*/
|
||||
#else
|
||||
LUT_exponent = 1.0; /* assume no LUT: most PCs */
|
||||
#endif
|
||||
|
||||
/* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */
|
||||
default_display_exponent = LUT_exponent * CRT_exponent;
|
||||
|
||||
|
||||
/* If the user has set the SCREEN_GAMMA environment variable as suggested
|
||||
* (somewhat imprecisely) in the libpng documentation, use that; otherwise
|
||||
* use the default value we just calculated. Either way, the user may
|
||||
* override this via a command-line option. */
|
||||
|
||||
if ((p = getenv("SCREEN_GAMMA")) != NULL)
|
||||
display_exponent = atof(p);
|
||||
else
|
||||
display_exponent = default_display_exponent;
|
||||
|
||||
|
||||
/* Now parse the command line for options and the PNG filename. */
|
||||
|
||||
while (*++argv && !error) {
|
||||
if (!strncmp(*argv, "-display", 2)) {
|
||||
if (!*++argv)
|
||||
++error;
|
||||
else
|
||||
displayname = *argv;
|
||||
} else if (!strncmp(*argv, "-gamma", 2)) {
|
||||
if (!*++argv)
|
||||
++error;
|
||||
else {
|
||||
display_exponent = atof(*argv);
|
||||
if (display_exponent <= 0.0)
|
||||
++error;
|
||||
}
|
||||
} else if (!strncmp(*argv, "-bgcolor", 2)) {
|
||||
if (!*++argv)
|
||||
++error;
|
||||
else {
|
||||
bgstr = *argv;
|
||||
if (strlen(bgstr) != 7 || bgstr[0] != '#')
|
||||
++error;
|
||||
else
|
||||
have_bg = TRUE;
|
||||
}
|
||||
} else {
|
||||
if (**argv != '-') {
|
||||
filename = *argv;
|
||||
if (argv[1]) /* shouldn't be any more args after filename */
|
||||
++error;
|
||||
} else
|
||||
++error; /* not expecting any other options */
|
||||
}
|
||||
}
|
||||
|
||||
if (!filename) {
|
||||
++error;
|
||||
} else if (!(infile = fopen(filename, "rb"))) {
|
||||
fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename);
|
||||
++error;
|
||||
} else {
|
||||
if ((rc = readpng_init(infile, &image_width, &image_height)) != 0) {
|
||||
switch (rc) {
|
||||
case 1:
|
||||
fprintf(stderr, PROGNAME
|
||||
": [%s] is not a PNG file: incorrect signature\n",
|
||||
filename);
|
||||
break;
|
||||
case 2:
|
||||
fprintf(stderr, PROGNAME
|
||||
": [%s] has bad IHDR (libpng longjmp)\n",
|
||||
filename);
|
||||
break;
|
||||
case 4:
|
||||
fprintf(stderr, PROGNAME ": insufficient memory\n");
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, PROGNAME
|
||||
": unknown readpng_init() error\n");
|
||||
break;
|
||||
}
|
||||
++error;
|
||||
} else {
|
||||
display = XOpenDisplay(displayname);
|
||||
if (!display) {
|
||||
readpng_cleanup(TRUE);
|
||||
fprintf(stderr, PROGNAME ": can't open X display [%s]\n",
|
||||
displayname? displayname : "default");
|
||||
++error;
|
||||
}
|
||||
}
|
||||
if (error)
|
||||
fclose(infile);
|
||||
}
|
||||
|
||||
|
||||
/* usage screen */
|
||||
|
||||
if (error) {
|
||||
fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname);
|
||||
readpng_version_info();
|
||||
fprintf(stderr, "\n"
|
||||
"Usage: %s [-display xdpy] [-gamma exp] [-bgcolor bg] file.png\n"
|
||||
" xdpy\tname of the target X display (e.g., ``hostname:0'')\n"
|
||||
" exp \ttransfer-function exponent (``gamma'') of the display\n"
|
||||
"\t\t system in floating-point format (e.g., ``%.1f''); equal\n"
|
||||
"\t\t to the product of the lookup-table exponent (varies)\n"
|
||||
"\t\t and the CRT exponent (usually 2.2); must be positive\n"
|
||||
" bg \tdesired background color in 7-character hex RGB format\n"
|
||||
"\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n"
|
||||
"\t\t used with transparent images\n"
|
||||
"\nPress Q, Esc or mouse button 1 (within image window, after image\n"
|
||||
"is displayed) to quit.\n"
|
||||
"\n", PROGNAME, default_display_exponent);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/* set the title-bar string, but make sure buffer doesn't overflow */
|
||||
|
||||
alen = strlen(appname);
|
||||
flen = strlen(filename);
|
||||
if (alen + flen + 3 > 1023)
|
||||
sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023));
|
||||
else
|
||||
sprintf(titlebar, "%s: %s", appname, filename);
|
||||
|
||||
|
||||
/* if the user didn't specify a background color on the command line,
|
||||
* check for one in the PNG file--if not, the initialized values of 0
|
||||
* (black) will be used */
|
||||
|
||||
if (have_bg) {
|
||||
unsigned r, g, b; /* this approach quiets compiler warnings */
|
||||
|
||||
sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b);
|
||||
bg_red = (uch)r;
|
||||
bg_green = (uch)g;
|
||||
bg_blue = (uch)b;
|
||||
} else if (readpng_get_bgcolor(&bg_red, &bg_green, &bg_blue) > 1) {
|
||||
readpng_cleanup(TRUE);
|
||||
fprintf(stderr, PROGNAME
|
||||
": libpng error while checking for background color\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
|
||||
/* do the basic X initialization stuff, make the window and fill it
|
||||
* with the background color */
|
||||
|
||||
if (rpng_x_create_window())
|
||||
exit(2);
|
||||
|
||||
|
||||
/* decode the image, all at once */
|
||||
|
||||
Trace((stderr, "calling readpng_get_image()\n"))
|
||||
image_data = readpng_get_image(display_exponent, &image_channels,
|
||||
&image_rowbytes);
|
||||
Trace((stderr, "done with readpng_get_image()\n"))
|
||||
|
||||
|
||||
/* done with PNG file, so clean up to minimize memory usage (but do NOT
|
||||
* nuke image_data!) */
|
||||
|
||||
readpng_cleanup(FALSE);
|
||||
fclose(infile);
|
||||
|
||||
if (!image_data) {
|
||||
fprintf(stderr, PROGNAME ": unable to decode PNG image\n");
|
||||
exit(3);
|
||||
}
|
||||
|
||||
|
||||
/* display image (composite with background if requested) */
|
||||
|
||||
Trace((stderr, "calling rpng_x_display_image()\n"))
|
||||
if (rpng_x_display_image()) {
|
||||
free(image_data);
|
||||
exit(4);
|
||||
}
|
||||
Trace((stderr, "done with rpng_x_display_image()\n"))
|
||||
|
||||
|
||||
/* wait for the user to tell us when to quit */
|
||||
|
||||
printf(
|
||||
"Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n");
|
||||
fflush(stdout);
|
||||
|
||||
do
|
||||
XNextEvent(display, &e);
|
||||
while (!(e.type == ButtonPress && e.xbutton.button == Button1) &&
|
||||
!(e.type == KeyPress && /* v--- or 1 for shifted keys */
|
||||
((k = XLookupKeysym(&e.xkey, 0)) == XK_q || k == XK_Escape) ));
|
||||
|
||||
|
||||
/* OK, we're done: clean up all image and X resources and go away */
|
||||
|
||||
rpng_x_cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int rpng_x_create_window(void)
|
||||
{
|
||||
uch *xdata;
|
||||
int need_colormap = FALSE;
|
||||
int screen, pad;
|
||||
ulg bg_pixel = 0L;
|
||||
ulg attrmask;
|
||||
Window root;
|
||||
XEvent e;
|
||||
XGCValues gcvalues;
|
||||
XSetWindowAttributes attr;
|
||||
XSizeHints *size_hints;
|
||||
XTextProperty windowName, *pWindowName = &windowName;
|
||||
XTextProperty iconName, *pIconName = &iconName;
|
||||
XVisualInfo visual_info;
|
||||
XWMHints *wm_hints;
|
||||
|
||||
|
||||
screen = DefaultScreen(display);
|
||||
depth = DisplayPlanes(display, screen);
|
||||
root = RootWindow(display, screen);
|
||||
|
||||
#ifdef DEBUG
|
||||
XSynchronize(display, True);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
/* GRR: add 8-bit support */
|
||||
if (/* depth != 8 && */ depth != 16 && depth != 24 && depth != 32) {
|
||||
fprintf(stderr,
|
||||
"screen depth %d not supported (only 16-, 24- or 32-bit TrueColor)\n",
|
||||
depth);
|
||||
return 2;
|
||||
}
|
||||
|
||||
XMatchVisualInfo(display, screen, depth,
|
||||
(depth == 8)? PseudoColor : TrueColor, &visual_info);
|
||||
visual = visual_info.visual;
|
||||
#else
|
||||
if (depth != 16 && depth != 24 && depth != 32) {
|
||||
int visuals_matched = 0;
|
||||
|
||||
Trace((stderr, "default depth is %d: checking other visuals\n",
|
||||
depth))
|
||||
|
||||
/* 24-bit first */
|
||||
visual_info.screen = screen;
|
||||
visual_info.depth = 24;
|
||||
visual_list = XGetVisualInfo(display,
|
||||
VisualScreenMask | VisualDepthMask, &visual_info, &visuals_matched);
|
||||
if (visuals_matched == 0) {
|
||||
/* GRR: add 15-, 16- and 32-bit TrueColor visuals (also DirectColor?) */
|
||||
fprintf(stderr, "default screen depth %d not supported, and no"
|
||||
" 24-bit visuals found\n", depth);
|
||||
return 2;
|
||||
}
|
||||
Trace((stderr, "XGetVisualInfo() returned %d 24-bit visuals\n",
|
||||
visuals_matched))
|
||||
visual = visual_list[0].visual;
|
||||
depth = visual_list[0].depth;
|
||||
/*
|
||||
colormap_size = visual_list[0].colormap_size;
|
||||
visual_class = visual->class;
|
||||
visualID = XVisualIDFromVisual(visual);
|
||||
*/
|
||||
have_nondefault_visual = TRUE;
|
||||
need_colormap = TRUE;
|
||||
} else {
|
||||
XMatchVisualInfo(display, screen, depth, TrueColor, &visual_info);
|
||||
visual = visual_info.visual;
|
||||
}
|
||||
#endif
|
||||
|
||||
RMask = visual->red_mask;
|
||||
GMask = visual->green_mask;
|
||||
BMask = visual->blue_mask;
|
||||
|
||||
/* GRR: add/check 8-bit support */
|
||||
if (depth == 8 || need_colormap) {
|
||||
colormap = XCreateColormap(display, root, visual, AllocNone);
|
||||
if (!colormap) {
|
||||
fprintf(stderr, "XCreateColormap() failed\n");
|
||||
return 2;
|
||||
}
|
||||
have_colormap = TRUE;
|
||||
}
|
||||
if (depth == 15 || depth == 16) {
|
||||
RShift = 15 - rpng_x_msb(RMask); /* these are right-shifts */
|
||||
GShift = 15 - rpng_x_msb(GMask);
|
||||
BShift = 15 - rpng_x_msb(BMask);
|
||||
} else if (depth > 16) {
|
||||
#define NO_24BIT_MASKS
|
||||
#ifdef NO_24BIT_MASKS
|
||||
RShift = rpng_x_msb(RMask) - 7; /* these are left-shifts */
|
||||
GShift = rpng_x_msb(GMask) - 7;
|
||||
BShift = rpng_x_msb(BMask) - 7;
|
||||
#else
|
||||
RShift = 7 - rpng_x_msb(RMask); /* these are right-shifts, too */
|
||||
GShift = 7 - rpng_x_msb(GMask);
|
||||
BShift = 7 - rpng_x_msb(BMask);
|
||||
#endif
|
||||
}
|
||||
if (depth >= 15 && (RShift < 0 || GShift < 0 || BShift < 0)) {
|
||||
fprintf(stderr, "rpng internal logic error: negative X shift(s)!\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
Finally, create the window.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
attr.backing_store = Always;
|
||||
attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask;
|
||||
attrmask = CWBackingStore | CWEventMask;
|
||||
if (have_nondefault_visual) {
|
||||
attr.colormap = colormap;
|
||||
attr.background_pixel = 0;
|
||||
attr.border_pixel = 1;
|
||||
attrmask |= CWColormap | CWBackPixel | CWBorderPixel;
|
||||
}
|
||||
|
||||
window = XCreateWindow(display, root, 0, 0, image_width, image_height, 0,
|
||||
depth, InputOutput, visual, attrmask, &attr);
|
||||
|
||||
if (window == None) {
|
||||
fprintf(stderr, "XCreateWindow() failed\n");
|
||||
return 2;
|
||||
} else
|
||||
have_window = TRUE;
|
||||
|
||||
if (depth == 8)
|
||||
XSetWindowColormap(display, window, colormap);
|
||||
|
||||
if (!XStringListToTextProperty(&window_name, 1, pWindowName))
|
||||
pWindowName = NULL;
|
||||
if (!XStringListToTextProperty(&icon_name, 1, pIconName))
|
||||
pIconName = NULL;
|
||||
|
||||
/* OK if either hints allocation fails; XSetWMProperties() allows NULLs */
|
||||
|
||||
if ((size_hints = XAllocSizeHints()) != NULL) {
|
||||
/* window will not be resizable */
|
||||
size_hints->flags = PMinSize | PMaxSize;
|
||||
size_hints->min_width = size_hints->max_width = (int)image_width;
|
||||
size_hints->min_height = size_hints->max_height = (int)image_height;
|
||||
}
|
||||
|
||||
if ((wm_hints = XAllocWMHints()) != NULL) {
|
||||
wm_hints->initial_state = NormalState;
|
||||
wm_hints->input = True;
|
||||
/* wm_hints->icon_pixmap = icon_pixmap; */
|
||||
wm_hints->flags = StateHint | InputHint /* | IconPixmapHint */ ;
|
||||
}
|
||||
|
||||
XSetWMProperties(display, window, pWindowName, pIconName, NULL, 0,
|
||||
size_hints, wm_hints, NULL);
|
||||
|
||||
XMapWindow(display, window);
|
||||
|
||||
gc = XCreateGC(display, window, 0, &gcvalues);
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
Fill window with the specified background color.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
if (depth == 24 || depth == 32) {
|
||||
bg_pixel = ((ulg)bg_red << RShift) |
|
||||
((ulg)bg_green << GShift) |
|
||||
((ulg)bg_blue << BShift);
|
||||
} else if (depth == 16) {
|
||||
bg_pixel = ((((ulg)bg_red << 8) >> RShift) & RMask) |
|
||||
((((ulg)bg_green << 8) >> GShift) & GMask) |
|
||||
((((ulg)bg_blue << 8) >> BShift) & BMask);
|
||||
} else /* depth == 8 */ {
|
||||
|
||||
/* GRR: add 8-bit support */
|
||||
|
||||
}
|
||||
|
||||
XSetForeground(display, gc, bg_pixel);
|
||||
XFillRectangle(display, window, gc, 0, 0, image_width, image_height);
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
Wait for first Expose event to do any drawing, then flush.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
do
|
||||
XNextEvent(display, &e);
|
||||
while (e.type != Expose || e.xexpose.count);
|
||||
|
||||
XFlush(display);
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
Allocate memory for the X- and display-specific version of the image.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
if (depth == 24 || depth == 32) {
|
||||
xdata = (uch *)malloc(4*image_width*image_height);
|
||||
pad = 32;
|
||||
} else if (depth == 16) {
|
||||
xdata = (uch *)malloc(2*image_width*image_height);
|
||||
pad = 16;
|
||||
} else /* depth == 8 */ {
|
||||
xdata = (uch *)malloc(image_width*image_height);
|
||||
pad = 8;
|
||||
}
|
||||
|
||||
if (!xdata) {
|
||||
fprintf(stderr, PROGNAME ": unable to allocate image memory\n");
|
||||
return 4;
|
||||
}
|
||||
|
||||
ximage = XCreateImage(display, visual, depth, ZPixmap, 0,
|
||||
(char *)xdata, image_width, image_height, pad, 0);
|
||||
|
||||
if (!ximage) {
|
||||
fprintf(stderr, PROGNAME ": XCreateImage() failed\n");
|
||||
free(xdata);
|
||||
return 3;
|
||||
}
|
||||
|
||||
/* to avoid testing the byte order every pixel (or doubling the size of
|
||||
* the drawing routine with a giant if-test), we arbitrarily set the byte
|
||||
* order to MSBFirst and let Xlib worry about inverting things on little-
|
||||
* endian machines (like Linux/x86, old VAXen, etc.)--this is not the most
|
||||
* efficient approach (the giant if-test would be better), but in the
|
||||
* interest of clarity, we take the easy way out... */
|
||||
|
||||
ximage->byte_order = MSBFirst;
|
||||
|
||||
return 0;
|
||||
|
||||
} /* end function rpng_x_create_window() */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int rpng_x_display_image(void)
|
||||
{
|
||||
uch *src;
|
||||
char *dest;
|
||||
uch r, g, b, a;
|
||||
ulg i, row, lastrow = 0;
|
||||
ulg pixel;
|
||||
int ximage_rowbytes = ximage->bytes_per_line;
|
||||
/* int bpp = ximage->bits_per_pixel; */
|
||||
|
||||
|
||||
Trace((stderr, "beginning display loop (image_channels == %d)\n",
|
||||
image_channels))
|
||||
Trace((stderr, " (width = %ld, rowbytes = %ld, ximage_rowbytes = %d)\n",
|
||||
image_width, image_rowbytes, ximage_rowbytes))
|
||||
Trace((stderr, " (bpp = %d)\n", ximage->bits_per_pixel))
|
||||
Trace((stderr, " (byte_order = %s)\n", ximage->byte_order == MSBFirst?
|
||||
"MSBFirst" : (ximage->byte_order == LSBFirst? "LSBFirst" : "unknown")))
|
||||
|
||||
if (depth == 24 || depth == 32) {
|
||||
ulg red, green, blue;
|
||||
|
||||
for (lastrow = row = 0; row < image_height; ++row) {
|
||||
src = image_data + row*image_rowbytes;
|
||||
dest = ximage->data + row*ximage_rowbytes;
|
||||
if (image_channels == 3) {
|
||||
for (i = image_width; i > 0; --i) {
|
||||
red = *src++;
|
||||
green = *src++;
|
||||
blue = *src++;
|
||||
#ifdef NO_24BIT_MASKS
|
||||
pixel = (red << RShift) |
|
||||
(green << GShift) |
|
||||
(blue << BShift);
|
||||
/* recall that we set ximage->byte_order = MSBFirst above */
|
||||
/* GRR BUG: this assumes bpp == 32, but may be 24: */
|
||||
*dest++ = (char)((pixel >> 24) & 0xff);
|
||||
*dest++ = (char)((pixel >> 16) & 0xff);
|
||||
*dest++ = (char)((pixel >> 8) & 0xff);
|
||||
*dest++ = (char)( pixel & 0xff);
|
||||
#else
|
||||
red = (RShift < 0)? red << (-RShift) : red >> RShift;
|
||||
green = (GShift < 0)? green << (-GShift) : green >> GShift;
|
||||
blue = (BShift < 0)? blue << (-BShift) : blue >> BShift;
|
||||
pixel = (red & RMask) | (green & GMask) | (blue & BMask);
|
||||
/* recall that we set ximage->byte_order = MSBFirst above */
|
||||
*dest++ = (char)((pixel >> 24) & 0xff);
|
||||
*dest++ = (char)((pixel >> 16) & 0xff);
|
||||
*dest++ = (char)((pixel >> 8) & 0xff);
|
||||
*dest++ = (char)( pixel & 0xff);
|
||||
#endif
|
||||
}
|
||||
} else /* if (image_channels == 4) */ {
|
||||
for (i = image_width; i > 0; --i) {
|
||||
r = *src++;
|
||||
g = *src++;
|
||||
b = *src++;
|
||||
a = *src++;
|
||||
if (a == 255) {
|
||||
red = r;
|
||||
green = g;
|
||||
blue = b;
|
||||
} else if (a == 0) {
|
||||
red = bg_red;
|
||||
green = bg_green;
|
||||
blue = bg_blue;
|
||||
} else {
|
||||
/* this macro (from png.h) composites the foreground
|
||||
* and background values and puts the result into the
|
||||
* first argument */
|
||||
alpha_composite(red, r, a, bg_red);
|
||||
alpha_composite(green, g, a, bg_green);
|
||||
alpha_composite(blue, b, a, bg_blue);
|
||||
}
|
||||
pixel = (red << RShift) |
|
||||
(green << GShift) |
|
||||
(blue << BShift);
|
||||
/* recall that we set ximage->byte_order = MSBFirst above */
|
||||
*dest++ = (char)((pixel >> 24) & 0xff);
|
||||
*dest++ = (char)((pixel >> 16) & 0xff);
|
||||
*dest++ = (char)((pixel >> 8) & 0xff);
|
||||
*dest++ = (char)( pixel & 0xff);
|
||||
}
|
||||
}
|
||||
/* display after every 16 lines */
|
||||
if (((row+1) & 0xf) == 0) {
|
||||
XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,
|
||||
(int)lastrow, image_width, 16);
|
||||
XFlush(display);
|
||||
lastrow = row + 1;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (depth == 16) {
|
||||
ush red, green, blue;
|
||||
|
||||
for (lastrow = row = 0; row < image_height; ++row) {
|
||||
src = image_data + row*image_rowbytes;
|
||||
dest = ximage->data + row*ximage_rowbytes;
|
||||
if (image_channels == 3) {
|
||||
for (i = image_width; i > 0; --i) {
|
||||
red = ((ush)(*src) << 8);
|
||||
++src;
|
||||
green = ((ush)(*src) << 8);
|
||||
++src;
|
||||
blue = ((ush)(*src) << 8);
|
||||
++src;
|
||||
pixel = ((red >> RShift) & RMask) |
|
||||
((green >> GShift) & GMask) |
|
||||
((blue >> BShift) & BMask);
|
||||
/* recall that we set ximage->byte_order = MSBFirst above */
|
||||
*dest++ = (char)((pixel >> 8) & 0xff);
|
||||
*dest++ = (char)( pixel & 0xff);
|
||||
}
|
||||
} else /* if (image_channels == 4) */ {
|
||||
for (i = image_width; i > 0; --i) {
|
||||
r = *src++;
|
||||
g = *src++;
|
||||
b = *src++;
|
||||
a = *src++;
|
||||
if (a == 255) {
|
||||
red = ((ush)r << 8);
|
||||
green = ((ush)g << 8);
|
||||
blue = ((ush)b << 8);
|
||||
} else if (a == 0) {
|
||||
red = ((ush)bg_red << 8);
|
||||
green = ((ush)bg_green << 8);
|
||||
blue = ((ush)bg_blue << 8);
|
||||
} else {
|
||||
/* this macro (from png.h) composites the foreground
|
||||
* and background values and puts the result back into
|
||||
* the first argument (== fg byte here: safe) */
|
||||
alpha_composite(r, r, a, bg_red);
|
||||
alpha_composite(g, g, a, bg_green);
|
||||
alpha_composite(b, b, a, bg_blue);
|
||||
red = ((ush)r << 8);
|
||||
green = ((ush)g << 8);
|
||||
blue = ((ush)b << 8);
|
||||
}
|
||||
pixel = ((red >> RShift) & RMask) |
|
||||
((green >> GShift) & GMask) |
|
||||
((blue >> BShift) & BMask);
|
||||
/* recall that we set ximage->byte_order = MSBFirst above */
|
||||
*dest++ = (char)((pixel >> 8) & 0xff);
|
||||
*dest++ = (char)( pixel & 0xff);
|
||||
}
|
||||
}
|
||||
/* display after every 16 lines */
|
||||
if (((row+1) & 0xf) == 0) {
|
||||
XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,
|
||||
(int)lastrow, image_width, 16);
|
||||
XFlush(display);
|
||||
lastrow = row + 1;
|
||||
}
|
||||
}
|
||||
|
||||
} else /* depth == 8 */ {
|
||||
|
||||
/* GRR: add 8-bit support */
|
||||
|
||||
}
|
||||
|
||||
Trace((stderr, "calling final XPutImage()\n"))
|
||||
if (lastrow < image_height) {
|
||||
XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,
|
||||
(int)lastrow, image_width, image_height-lastrow);
|
||||
XFlush(display);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void rpng_x_cleanup(void)
|
||||
{
|
||||
if (image_data) {
|
||||
free(image_data);
|
||||
image_data = NULL;
|
||||
}
|
||||
|
||||
if (ximage) {
|
||||
if (ximage->data) {
|
||||
free(ximage->data); /* we allocated it, so we free it */
|
||||
ximage->data = (char *)NULL; /* instead of XDestroyImage() */
|
||||
}
|
||||
XDestroyImage(ximage);
|
||||
ximage = NULL;
|
||||
}
|
||||
|
||||
XFreeGC(display, gc);
|
||||
|
||||
if (have_window)
|
||||
XDestroyWindow(display, window);
|
||||
|
||||
if (have_colormap)
|
||||
XFreeColormap(display, colormap);
|
||||
|
||||
if (have_nondefault_visual)
|
||||
XFree(visual_list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int rpng_x_msb(ulg u32val)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 31; i >= 0; --i) {
|
||||
if (u32val & 0x80000000L)
|
||||
break;
|
||||
u32val <<= 1;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
1117
contrib/gregbook/rpng2-win.c
Normal file
1362
contrib/gregbook/rpng2-x.c
Normal file
BIN
contrib/gregbook/toucan.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
816
contrib/gregbook/wpng.c
Normal file
@@ -0,0 +1,816 @@
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
wpng - simple PNG-writing program wpng.c
|
||||
|
||||
This program converts certain NetPBM binary files (grayscale and RGB,
|
||||
maxval = 255) to PNG. Non-interlaced PNGs are written progressively;
|
||||
interlaced PNGs are read and written in one memory-intensive blast.
|
||||
Thanks to Jean-loup Gailly for providing the necessary trick to read
|
||||
interactive text from the keyboard while stdin is redirected.
|
||||
|
||||
NOTE: includes provisional support for PNM type "8" (portable alphamap)
|
||||
images, presumed to be a 32-bit interleaved RGBA format; no pro-
|
||||
vision for possible interleaved grayscale+alpha (16-bit) format.
|
||||
THIS IS UNLIKELY TO BECOME AN OFFICIAL NETPBM ALPHA FORMAT!
|
||||
|
||||
to do:
|
||||
- delete output file if quit before calling any writepng routines
|
||||
- process backspace with -text option under DOS/Win? (currently get ^H)
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Changelog:
|
||||
- 1.01: initial public release
|
||||
- 1.02: modified to allow abbreviated options
|
||||
- 1.03: removed extraneous character from usage screen; fixed bug in
|
||||
command-line parsing
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1998-2000 Greg Roelofs. All rights reserved.
|
||||
|
||||
This software is provided "as is," without warranty of any kind,
|
||||
express or implied. In no event shall the author or contributors
|
||||
be held liable for any damages arising in any way from the use of
|
||||
this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute
|
||||
it freely, subject to the following restrictions:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, disclaimer, and this list of conditions.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, disclaimer, and this list of conditions in the documenta-
|
||||
tion and/or other materials provided with the distribution.
|
||||
3. All advertising materials mentioning features or use of this
|
||||
software must display the following acknowledgment:
|
||||
|
||||
This product includes software developed by Greg Roelofs
|
||||
and contributors for the book, "PNG: The Definitive Guide,"
|
||||
published by O'Reilly and Associates.
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
#define PROGNAME "wpng"
|
||||
#define VERSION "1.03 of 19 March 2000"
|
||||
#define APPNAME "Simple PGM/PPM/PAM to PNG Converter"
|
||||
|
||||
#if defined(__MSDOS__) || defined(__OS2__)
|
||||
# define DOS_OS2_W32
|
||||
#elif defined(_WIN32) || defined(__WIN32__)
|
||||
# define DOS_OS2_W32
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <setjmp.h> /* for jmpbuf declaration in writepng.h */
|
||||
#include <time.h>
|
||||
|
||||
#ifdef DOS_OS2_W32
|
||||
# include <io.h> /* for isatty(), setmode() prototypes */
|
||||
# include <fcntl.h> /* O_BINARY for fdopen() without text translation */
|
||||
# ifdef __EMX__
|
||||
# ifndef getch
|
||||
# define getch() _read_kbd(0, 1, 0) /* need getche() */
|
||||
# endif
|
||||
# else /* !__EMX__ */
|
||||
# ifdef __GO32__
|
||||
# include <pc.h>
|
||||
# define getch() getkey() /* GRR: need getche() */
|
||||
# else
|
||||
# include <conio.h> /* for getche() console input */
|
||||
# endif
|
||||
# endif /* ?__EMX__ */
|
||||
# define FGETS(buf,len,stream) dos_kbd_gets(buf,len)
|
||||
#else
|
||||
# include <unistd.h> /* for isatty() prototype */
|
||||
# define FGETS fgets
|
||||
#endif
|
||||
|
||||
/* #define DEBUG : this enables the Trace() macros */
|
||||
|
||||
/* #define FORBID_LATIN1_CTRL : this requires the user to re-enter any
|
||||
text that includes control characters discouraged by the PNG spec; text
|
||||
that includes an escape character (27) must be re-entered regardless */
|
||||
|
||||
#include "writepng.h" /* typedefs, common macros, writepng prototypes */
|
||||
|
||||
|
||||
|
||||
/* local prototypes */
|
||||
|
||||
static int wpng_isvalid_latin1(uch *p, int len);
|
||||
static void wpng_cleanup(void);
|
||||
|
||||
#ifdef DOS_OS2_W32
|
||||
static char *dos_kbd_gets(char *buf, int len);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
static mainprog_info wpng_info; /* lone global */
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#ifndef DOS_OS2_W32
|
||||
FILE *keybd;
|
||||
#endif
|
||||
#ifdef sgi
|
||||
FILE *tmpfile; /* or we could just use keybd, since no overlap */
|
||||
char tmpline[80];
|
||||
#endif
|
||||
char *inname = NULL, outname[256];
|
||||
char *p, pnmchar, pnmline[256];
|
||||
char *bgstr, *textbuf = NULL;
|
||||
ulg rowbytes;
|
||||
int rc, len = 0;
|
||||
int error = 0;
|
||||
int text = FALSE;
|
||||
int maxval;
|
||||
double LUT_exponent; /* just the lookup table */
|
||||
double CRT_exponent = 2.2; /* just the monitor */
|
||||
double default_display_exponent; /* whole display system */
|
||||
double default_gamma = 0.0;
|
||||
|
||||
|
||||
wpng_info.infile = NULL;
|
||||
wpng_info.outfile = NULL;
|
||||
wpng_info.image_data = NULL;
|
||||
wpng_info.row_pointers = NULL;
|
||||
wpng_info.filter = FALSE;
|
||||
wpng_info.interlaced = FALSE;
|
||||
wpng_info.have_bg = FALSE;
|
||||
wpng_info.have_time = FALSE;
|
||||
wpng_info.have_text = 0;
|
||||
wpng_info.gamma = 0.0;
|
||||
|
||||
|
||||
/* First get the default value for our display-system exponent, i.e.,
|
||||
* the product of the CRT exponent and the exponent corresponding to
|
||||
* the frame-buffer's lookup table (LUT), if any. If the PNM image
|
||||
* looks correct on the user's display system, its file gamma is the
|
||||
* inverse of this value. (Note that this is not an exhaustive list
|
||||
* of LUT values--e.g., OpenStep has a lot of weird ones--but it should
|
||||
* cover 99% of the current possibilities. This section must ensure
|
||||
* that default_display_exponent is positive.) */
|
||||
|
||||
#if defined(NeXT)
|
||||
/* third-party utilities can modify the default LUT exponent */
|
||||
LUT_exponent = 1.0 / 2.2;
|
||||
/*
|
||||
if (some_next_function_that_returns_gamma(&next_gamma))
|
||||
LUT_exponent = 1.0 / next_gamma;
|
||||
*/
|
||||
#elif defined(sgi)
|
||||
LUT_exponent = 1.0 / 1.7;
|
||||
/* there doesn't seem to be any documented function to
|
||||
* get the "gamma" value, so we do it the hard way */
|
||||
tmpfile = fopen("/etc/config/system.glGammaVal", "r");
|
||||
if (tmpfile) {
|
||||
double sgi_gamma;
|
||||
|
||||
fgets(tmpline, 80, tmpfile);
|
||||
fclose(tmpfile);
|
||||
sgi_gamma = atof(tmpline);
|
||||
if (sgi_gamma > 0.0)
|
||||
LUT_exponent = 1.0 / sgi_gamma;
|
||||
}
|
||||
#elif defined(Macintosh)
|
||||
LUT_exponent = 1.8 / 2.61;
|
||||
/*
|
||||
if (some_mac_function_that_returns_gamma(&mac_gamma))
|
||||
LUT_exponent = mac_gamma / 2.61;
|
||||
*/
|
||||
#else
|
||||
LUT_exponent = 1.0; /* assume no LUT: most PCs */
|
||||
#endif
|
||||
|
||||
/* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */
|
||||
default_display_exponent = LUT_exponent * CRT_exponent;
|
||||
|
||||
|
||||
/* If the user has set the SCREEN_GAMMA environment variable as suggested
|
||||
* (somewhat imprecisely) in the libpng documentation, use that; otherwise
|
||||
* use the default value we just calculated. Either way, the user may
|
||||
* override this via a command-line option. */
|
||||
|
||||
if ((p = getenv("SCREEN_GAMMA")) != NULL) {
|
||||
double exponent = atof(p);
|
||||
|
||||
if (exponent > 0.0)
|
||||
default_gamma = 1.0 / exponent;
|
||||
}
|
||||
|
||||
if (default_gamma == 0.0)
|
||||
default_gamma = 1.0 / default_display_exponent;
|
||||
|
||||
|
||||
/* Now parse the command line for options and the PNM filename. */
|
||||
|
||||
while (*++argv && !error) {
|
||||
if (!strncmp(*argv, "-i", 2)) {
|
||||
wpng_info.interlaced = TRUE;
|
||||
} else if (!strncmp(*argv, "-time", 3)) {
|
||||
wpng_info.modtime = time(NULL);
|
||||
wpng_info.have_time = TRUE;
|
||||
} else if (!strncmp(*argv, "-text", 3)) {
|
||||
text = TRUE;
|
||||
} else if (!strncmp(*argv, "-gamma", 2)) {
|
||||
if (!*++argv)
|
||||
++error;
|
||||
else {
|
||||
wpng_info.gamma = atof(*argv);
|
||||
if (wpng_info.gamma <= 0.0)
|
||||
++error;
|
||||
else if (wpng_info.gamma > 1.01)
|
||||
fprintf(stderr, PROGNAME
|
||||
" warning: file gammas are usually less than 1.0\n");
|
||||
}
|
||||
} else if (!strncmp(*argv, "-bgcolor", 4)) {
|
||||
if (!*++argv)
|
||||
++error;
|
||||
else {
|
||||
bgstr = *argv;
|
||||
if (strlen(bgstr) != 7 || bgstr[0] != '#')
|
||||
++error;
|
||||
else {
|
||||
unsigned r, g, b; /* this way quiets compiler warnings */
|
||||
|
||||
sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b);
|
||||
wpng_info.bg_red = (uch)r;
|
||||
wpng_info.bg_green = (uch)g;
|
||||
wpng_info.bg_blue = (uch)b;
|
||||
wpng_info.have_bg = TRUE;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (**argv != '-') {
|
||||
inname = *argv;
|
||||
if (argv[1]) /* shouldn't be any more args after filename */
|
||||
++error;
|
||||
} else
|
||||
++error; /* not expecting any other options */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* open the input and output files, or register an error and abort */
|
||||
|
||||
if (!inname) {
|
||||
if (isatty(0)) {
|
||||
fprintf(stderr, PROGNAME
|
||||
": must give input filename or provide image data via stdin\n");
|
||||
++error;
|
||||
} else {
|
||||
#ifdef DOS_OS2_W32
|
||||
/* some buggy C libraries require BOTH setmode() and fdopen(bin) */
|
||||
setmode(fileno(stdin), O_BINARY);
|
||||
setmode(fileno(stdout), O_BINARY);
|
||||
#endif
|
||||
if ((wpng_info.infile = fdopen(fileno(stdin), "rb")) == NULL) {
|
||||
fprintf(stderr, PROGNAME
|
||||
": unable to reopen stdin in binary mode\n");
|
||||
++error;
|
||||
} else
|
||||
if ((wpng_info.outfile = fdopen(fileno(stdout), "wb")) == NULL) {
|
||||
fprintf(stderr, PROGNAME
|
||||
": unable to reopen stdout in binary mode\n");
|
||||
fclose(wpng_info.infile);
|
||||
++error;
|
||||
} else
|
||||
wpng_info.filter = TRUE;
|
||||
}
|
||||
} else if ((len = strlen(inname)) > 250) {
|
||||
fprintf(stderr, PROGNAME ": input filename is too long [%d chars]\n",
|
||||
len);
|
||||
++error;
|
||||
} else if (!(wpng_info.infile = fopen(inname, "rb"))) {
|
||||
fprintf(stderr, PROGNAME ": can't open input file [%s]\n", inname);
|
||||
++error;
|
||||
}
|
||||
|
||||
if (!error) {
|
||||
fgets(pnmline, 256, wpng_info.infile);
|
||||
if (pnmline[0] != 'P' || ((pnmchar = pnmline[1]) != '5' &&
|
||||
pnmchar != '6' && pnmchar != '8'))
|
||||
{
|
||||
fprintf(stderr, PROGNAME
|
||||
": input file [%s] is not a binary PGM, PPM or PAM file\n",
|
||||
inname);
|
||||
++error;
|
||||
} else {
|
||||
wpng_info.pnmtype = (int)(pnmchar - '0');
|
||||
if (wpng_info.pnmtype != 8)
|
||||
wpng_info.have_bg = FALSE; /* no need for bg if opaque */
|
||||
do {
|
||||
fgets(pnmline, 256, wpng_info.infile); /* lose any comments */
|
||||
} while (pnmline[0] == '#');
|
||||
sscanf(pnmline, "%ld %ld", &wpng_info.width, &wpng_info.height);
|
||||
do {
|
||||
fgets(pnmline, 256, wpng_info.infile); /* more comment lines */
|
||||
} while (pnmline[0] == '#');
|
||||
sscanf(pnmline, "%d", &maxval);
|
||||
if (wpng_info.width <= 0L || wpng_info.height <= 0L ||
|
||||
maxval != 255)
|
||||
{
|
||||
fprintf(stderr, PROGNAME
|
||||
": only positive width/height, maxval == 255 allowed \n");
|
||||
++error;
|
||||
}
|
||||
wpng_info.sample_depth = 8; /* <==> maxval 255 */
|
||||
|
||||
if (!wpng_info.filter) {
|
||||
/* make outname from inname */
|
||||
if ((p = strrchr(inname, '.')) == NULL ||
|
||||
(p - inname) != (len - 4))
|
||||
{
|
||||
strcpy(outname, inname);
|
||||
strcpy(outname+len, ".png");
|
||||
} else {
|
||||
len -= 4;
|
||||
strncpy(outname, inname, len);
|
||||
strcpy(outname+len, ".png");
|
||||
}
|
||||
/* check if outname already exists; if not, open */
|
||||
if ((wpng_info.outfile = fopen(outname, "rb")) != NULL) {
|
||||
fprintf(stderr, PROGNAME ": output file exists [%s]\n",
|
||||
outname);
|
||||
fclose(wpng_info.outfile);
|
||||
++error;
|
||||
} else if (!(wpng_info.outfile = fopen(outname, "wb"))) {
|
||||
fprintf(stderr, PROGNAME ": can't open output file [%s]\n",
|
||||
outname);
|
||||
++error;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (error) {
|
||||
fclose(wpng_info.infile);
|
||||
wpng_info.infile = NULL;
|
||||
if (wpng_info.filter) {
|
||||
fclose(wpng_info.outfile);
|
||||
wpng_info.outfile = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* if we had any errors, print usage and die horrible death...arrr! */
|
||||
|
||||
if (error) {
|
||||
fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, APPNAME);
|
||||
writepng_version_info();
|
||||
fprintf(stderr, "\n"
|
||||
"Usage: %s [-gamma exp] [-bgcolor bg] [-text] [-time] [-interlace] pnmfile\n"
|
||||
"or: ... | %s [-gamma exp] [-bgcolor bg] [-text] [-time] [-interlace] | ...\n"
|
||||
" exp \ttransfer-function exponent (``gamma'') of the image in\n"
|
||||
"\t\t floating-point format (e.g., ``%.5f''); if image looks\n"
|
||||
"\t\t correct on given display system, image gamma is equal to\n"
|
||||
"\t\t inverse of display-system exponent, i.e., 1 / (LUT * CRT)\n"
|
||||
"\t\t (where LUT = lookup-table exponent and CRT = CRT exponent;\n"
|
||||
"\t\t first varies, second is usually 2.2, all are positive)\n"
|
||||
" bg \tdesired background color for alpha-channel images, in\n"
|
||||
"\t\t 7-character hex RGB format (e.g., ``#ff7700'' for orange:\n"
|
||||
"\t\t same as HTML colors)\n"
|
||||
" -text\tprompt interactively for text info (tEXt chunks)\n"
|
||||
" -time\tinclude a tIME chunk (last modification time)\n"
|
||||
" -interlace\twrite interlaced PNG image\n"
|
||||
"\n"
|
||||
"pnmfile or stdin must be a binary PGM (`P5'), PPM (`P6') or (extremely\n"
|
||||
"unofficial and unsupported!) PAM (`P8') file. Currently it is required\n"
|
||||
"to have maxval == 255 (i.e., no scaling). If pnmfile is specified, it\n"
|
||||
"is converted to the corresponding PNG file with the same base name but a\n"
|
||||
"``.png'' extension; files read from stdin are converted and sent to stdout.\n"
|
||||
"The conversion is progressive (low memory usage) unless interlacing is\n"
|
||||
"requested; in that case the whole image will be buffered in memory and\n"
|
||||
"written in one call.\n"
|
||||
"\n", PROGNAME, PROGNAME, default_gamma);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/* prepare the text buffers for libpng's use; note that even though
|
||||
* PNG's png_text struct includes a length field, we don't have to fill
|
||||
* it out */
|
||||
|
||||
if (text &&
|
||||
#ifndef DOS_OS2_W32
|
||||
(keybd = fdopen(fileno(stderr), "r")) != NULL &&
|
||||
#endif
|
||||
(textbuf = (char *)malloc((5 + 9)*75)) != NULL)
|
||||
{
|
||||
int i, valid, result;
|
||||
|
||||
fprintf(stderr,
|
||||
"Enter text info (no more than 72 characters per line);\n");
|
||||
fprintf(stderr, "to skip a field, hit the <Enter> key.\n");
|
||||
/* note: just <Enter> leaves len == 1 */
|
||||
|
||||
do {
|
||||
valid = TRUE;
|
||||
p = textbuf + TEXT_TITLE_OFFSET;
|
||||
fprintf(stderr, " Title: ");
|
||||
fflush(stderr);
|
||||
if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
|
||||
if (p[len-1] == '\n')
|
||||
p[--len] = '\0';
|
||||
wpng_info.title = p;
|
||||
wpng_info.have_text |= TEXT_TITLE;
|
||||
if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
|
||||
fprintf(stderr, " " PROGNAME " warning: character code"
|
||||
" %u is %sdiscouraged by the PNG\n specification "
|
||||
"[first occurrence was at character position #%d]\n",
|
||||
(unsigned)p[result], (p[result] == 27)? "strongly " : "",
|
||||
result+1);
|
||||
fflush(stderr);
|
||||
#ifdef FORBID_LATIN1_CTRL
|
||||
wpng_info.have_text &= ~TEXT_TITLE;
|
||||
valid = FALSE;
|
||||
#else
|
||||
if (p[result] == 27) { /* escape character */
|
||||
wpng_info.have_text &= ~TEXT_TITLE;
|
||||
valid = FALSE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} while (!valid);
|
||||
|
||||
do {
|
||||
valid = TRUE;
|
||||
p = textbuf + TEXT_AUTHOR_OFFSET;
|
||||
fprintf(stderr, " Author: ");
|
||||
fflush(stderr);
|
||||
if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
|
||||
if (p[len-1] == '\n')
|
||||
p[--len] = '\0';
|
||||
wpng_info.author = p;
|
||||
wpng_info.have_text |= TEXT_AUTHOR;
|
||||
if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
|
||||
fprintf(stderr, " " PROGNAME " warning: character code"
|
||||
" %u is %sdiscouraged by the PNG\n specification "
|
||||
"[first occurrence was at character position #%d]\n",
|
||||
(unsigned)p[result], (p[result] == 27)? "strongly " : "",
|
||||
result+1);
|
||||
fflush(stderr);
|
||||
#ifdef FORBID_LATIN1_CTRL
|
||||
wpng_info.have_text &= ~TEXT_AUTHOR;
|
||||
valid = FALSE;
|
||||
#else
|
||||
if (p[result] == 27) { /* escape character */
|
||||
wpng_info.have_text &= ~TEXT_AUTHOR;
|
||||
valid = FALSE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} while (!valid);
|
||||
|
||||
do {
|
||||
valid = TRUE;
|
||||
p = textbuf + TEXT_DESC_OFFSET;
|
||||
fprintf(stderr, " Description (up to 9 lines):\n");
|
||||
for (i = 1; i < 10; ++i) {
|
||||
fprintf(stderr, " [%d] ", i);
|
||||
fflush(stderr);
|
||||
if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1)
|
||||
p += len; /* now points at NULL; char before is newline */
|
||||
else
|
||||
break;
|
||||
}
|
||||
if ((len = p - (textbuf + TEXT_DESC_OFFSET)) > 1) {
|
||||
if (p[-1] == '\n') {
|
||||
p[-1] = '\0';
|
||||
--len;
|
||||
}
|
||||
wpng_info.desc = textbuf + TEXT_DESC_OFFSET;
|
||||
wpng_info.have_text |= TEXT_DESC;
|
||||
p = textbuf + TEXT_DESC_OFFSET;
|
||||
if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
|
||||
fprintf(stderr, " " PROGNAME " warning: character code"
|
||||
" %u is %sdiscouraged by the PNG\n specification "
|
||||
"[first occurrence was at character position #%d]\n",
|
||||
(unsigned)p[result], (p[result] == 27)? "strongly " : "",
|
||||
result+1);
|
||||
fflush(stderr);
|
||||
#ifdef FORBID_LATIN1_CTRL
|
||||
wpng_info.have_text &= ~TEXT_DESC;
|
||||
valid = FALSE;
|
||||
#else
|
||||
if (p[result] == 27) { /* escape character */
|
||||
wpng_info.have_text &= ~TEXT_DESC;
|
||||
valid = FALSE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} while (!valid);
|
||||
|
||||
do {
|
||||
valid = TRUE;
|
||||
p = textbuf + TEXT_COPY_OFFSET;
|
||||
fprintf(stderr, " Copyright: ");
|
||||
fflush(stderr);
|
||||
if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
|
||||
if (p[len-1] == '\n')
|
||||
p[--len] = '\0';
|
||||
wpng_info.copyright = p;
|
||||
wpng_info.have_text |= TEXT_COPY;
|
||||
if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
|
||||
fprintf(stderr, " " PROGNAME " warning: character code"
|
||||
" %u is %sdiscouraged by the PNG\n specification "
|
||||
"[first occurrence was at character position #%d]\n",
|
||||
(unsigned)p[result], (p[result] == 27)? "strongly " : "",
|
||||
result+1);
|
||||
fflush(stderr);
|
||||
#ifdef FORBID_LATIN1_CTRL
|
||||
wpng_info.have_text &= ~TEXT_COPY;
|
||||
valid = FALSE;
|
||||
#else
|
||||
if (p[result] == 27) { /* escape character */
|
||||
wpng_info.have_text &= ~TEXT_COPY;
|
||||
valid = FALSE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} while (!valid);
|
||||
|
||||
do {
|
||||
valid = TRUE;
|
||||
p = textbuf + TEXT_EMAIL_OFFSET;
|
||||
fprintf(stderr, " E-mail: ");
|
||||
fflush(stderr);
|
||||
if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
|
||||
if (p[len-1] == '\n')
|
||||
p[--len] = '\0';
|
||||
wpng_info.email = p;
|
||||
wpng_info.have_text |= TEXT_EMAIL;
|
||||
if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
|
||||
fprintf(stderr, " " PROGNAME " warning: character code"
|
||||
" %u is %sdiscouraged by the PNG\n specification "
|
||||
"[first occurrence was at character position #%d]\n",
|
||||
(unsigned)p[result], (p[result] == 27)? "strongly " : "",
|
||||
result+1);
|
||||
fflush(stderr);
|
||||
#ifdef FORBID_LATIN1_CTRL
|
||||
wpng_info.have_text &= ~TEXT_EMAIL;
|
||||
valid = FALSE;
|
||||
#else
|
||||
if (p[result] == 27) { /* escape character */
|
||||
wpng_info.have_text &= ~TEXT_EMAIL;
|
||||
valid = FALSE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} while (!valid);
|
||||
|
||||
do {
|
||||
valid = TRUE;
|
||||
p = textbuf + TEXT_URL_OFFSET;
|
||||
fprintf(stderr, " URL: ");
|
||||
fflush(stderr);
|
||||
if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
|
||||
if (p[len-1] == '\n')
|
||||
p[--len] = '\0';
|
||||
wpng_info.url = p;
|
||||
wpng_info.have_text |= TEXT_URL;
|
||||
if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
|
||||
fprintf(stderr, " " PROGNAME " warning: character code"
|
||||
" %u is %sdiscouraged by the PNG\n specification "
|
||||
"[first occurrence was at character position #%d]\n",
|
||||
(unsigned)p[result], (p[result] == 27)? "strongly " : "",
|
||||
result+1);
|
||||
fflush(stderr);
|
||||
#ifdef FORBID_LATIN1_CTRL
|
||||
wpng_info.have_text &= ~TEXT_URL;
|
||||
valid = FALSE;
|
||||
#else
|
||||
if (p[result] == 27) { /* escape character */
|
||||
wpng_info.have_text &= ~TEXT_URL;
|
||||
valid = FALSE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} while (!valid);
|
||||
|
||||
#ifndef DOS_OS2_W32
|
||||
fclose(keybd);
|
||||
#endif
|
||||
|
||||
} else if (text) {
|
||||
fprintf(stderr, PROGNAME ": unable to allocate memory for text\n");
|
||||
text = FALSE;
|
||||
wpng_info.have_text = 0;
|
||||
}
|
||||
|
||||
|
||||
/* allocate libpng stuff, initialize transformations, write pre-IDAT data */
|
||||
|
||||
if ((rc = writepng_init(&wpng_info)) != 0) {
|
||||
switch (rc) {
|
||||
case 2:
|
||||
fprintf(stderr, PROGNAME
|
||||
": libpng initialization problem (longjmp)\n");
|
||||
break;
|
||||
case 4:
|
||||
fprintf(stderr, PROGNAME ": insufficient memory\n");
|
||||
break;
|
||||
case 11:
|
||||
fprintf(stderr, PROGNAME
|
||||
": internal logic error (unexpected PNM type)\n");
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, PROGNAME
|
||||
": unknown writepng_init() error\n");
|
||||
break;
|
||||
}
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
|
||||
/* free textbuf, since it's a completely local variable and all text info
|
||||
* has just been written to the PNG file */
|
||||
|
||||
if (text && textbuf) {
|
||||
free(textbuf);
|
||||
textbuf = NULL;
|
||||
}
|
||||
|
||||
|
||||
/* calculate rowbytes on basis of image type; note that this becomes much
|
||||
* more complicated if we choose to support PBM type, ASCII PNM types, or
|
||||
* 16-bit-per-sample binary data [currently not an official NetPBM type] */
|
||||
|
||||
if (wpng_info.pnmtype == 5)
|
||||
rowbytes = wpng_info.width;
|
||||
else if (wpng_info.pnmtype == 6)
|
||||
rowbytes = wpng_info.width * 3;
|
||||
else /* if (wpng_info.pnmtype == 8) */
|
||||
rowbytes = wpng_info.width * 4;
|
||||
|
||||
|
||||
/* read and write the image, either in its entirety (if writing interlaced
|
||||
* PNG) or row by row (if non-interlaced) */
|
||||
|
||||
fprintf(stderr, "Encoding image data...\n");
|
||||
fflush(stderr);
|
||||
|
||||
if (wpng_info.interlaced) {
|
||||
long i;
|
||||
ulg bytes;
|
||||
ulg image_bytes = rowbytes * wpng_info.height; /* overflow? */
|
||||
|
||||
wpng_info.image_data = (uch *)malloc(image_bytes);
|
||||
wpng_info.row_pointers = (uch **)malloc(wpng_info.height*sizeof(uch *));
|
||||
if (wpng_info.image_data == NULL || wpng_info.row_pointers == NULL) {
|
||||
fprintf(stderr, PROGNAME ": insufficient memory for image data\n");
|
||||
writepng_cleanup(&wpng_info);
|
||||
wpng_cleanup();
|
||||
exit(5);
|
||||
}
|
||||
for (i = 0; i < wpng_info.height; ++i)
|
||||
wpng_info.row_pointers[i] = wpng_info.image_data + i*rowbytes;
|
||||
bytes = fread(wpng_info.image_data, 1, image_bytes, wpng_info.infile);
|
||||
if (bytes != image_bytes) {
|
||||
fprintf(stderr, PROGNAME ": expected %lu bytes, got %lu bytes\n",
|
||||
image_bytes, bytes);
|
||||
fprintf(stderr, " (continuing anyway)\n");
|
||||
}
|
||||
if (writepng_encode_image(&wpng_info) != 0) {
|
||||
fprintf(stderr, PROGNAME
|
||||
": libpng problem (longjmp) while writing image data\n");
|
||||
writepng_cleanup(&wpng_info);
|
||||
wpng_cleanup();
|
||||
exit(2);
|
||||
}
|
||||
|
||||
} else /* not interlaced: write progressively (row by row) */ {
|
||||
long j;
|
||||
ulg bytes;
|
||||
|
||||
wpng_info.image_data = (uch *)malloc(rowbytes);
|
||||
if (wpng_info.image_data == NULL) {
|
||||
fprintf(stderr, PROGNAME ": insufficient memory for row data\n");
|
||||
writepng_cleanup(&wpng_info);
|
||||
wpng_cleanup();
|
||||
exit(5);
|
||||
}
|
||||
error = 0;
|
||||
for (j = wpng_info.height; j > 0L; --j) {
|
||||
bytes = fread(wpng_info.image_data, 1, rowbytes, wpng_info.infile);
|
||||
if (bytes != rowbytes) {
|
||||
fprintf(stderr, PROGNAME
|
||||
": expected %lu bytes, got %lu bytes (row %ld)\n", rowbytes,
|
||||
bytes, wpng_info.height-j);
|
||||
++error;
|
||||
break;
|
||||
}
|
||||
if (writepng_encode_row(&wpng_info) != 0) {
|
||||
fprintf(stderr, PROGNAME
|
||||
": libpng problem (longjmp) while writing row %ld\n",
|
||||
wpng_info.height-j);
|
||||
++error;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (error) {
|
||||
writepng_cleanup(&wpng_info);
|
||||
wpng_cleanup();
|
||||
exit(2);
|
||||
}
|
||||
if (writepng_encode_finish(&wpng_info) != 0) {
|
||||
fprintf(stderr, PROGNAME ": error on final libpng call\n");
|
||||
writepng_cleanup(&wpng_info);
|
||||
wpng_cleanup();
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* OK, we're done (successfully): clean up all resources and quit */
|
||||
|
||||
fprintf(stderr, "Done.\n");
|
||||
fflush(stderr);
|
||||
|
||||
writepng_cleanup(&wpng_info);
|
||||
wpng_cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int wpng_isvalid_latin1(uch *p, int len)
|
||||
{
|
||||
int i, result = -1;
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
if (p[i] == 10 || (p[i] > 31 && p[i] < 127) || p[i] > 160)
|
||||
continue; /* character is completely OK */
|
||||
if (result < 0 || (p[result] != 27 && p[i] == 27))
|
||||
result = i; /* mark location of first questionable one */
|
||||
} /* or of first escape character (bad) */
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void wpng_cleanup(void)
|
||||
{
|
||||
if (wpng_info.outfile) {
|
||||
fclose(wpng_info.outfile);
|
||||
wpng_info.outfile = NULL;
|
||||
}
|
||||
|
||||
if (wpng_info.infile) {
|
||||
fclose(wpng_info.infile);
|
||||
wpng_info.infile = NULL;
|
||||
}
|
||||
|
||||
if (wpng_info.image_data) {
|
||||
free(wpng_info.image_data);
|
||||
wpng_info.image_data = NULL;
|
||||
}
|
||||
|
||||
if (wpng_info.row_pointers) {
|
||||
free(wpng_info.row_pointers);
|
||||
wpng_info.row_pointers = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef DOS_OS2_W32
|
||||
|
||||
static char *dos_kbd_gets(char *buf, int len)
|
||||
{
|
||||
int ch, count=0;
|
||||
|
||||
do {
|
||||
buf[count++] = ch = getche();
|
||||
} while (ch != '\r' && count < len-1);
|
||||
|
||||
buf[count--] = '\0'; /* terminate string */
|
||||
if (buf[count] == '\r') /* Enter key makes CR, so change to newline */
|
||||
buf[count] = '\n';
|
||||
|
||||
fprintf(stderr, "\n"); /* Enter key does *not* cause a newline */
|
||||
fflush(stderr);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
#endif /* DOS_OS2_W32 */
|
||||
368
contrib/gregbook/writepng.c
Normal file
@@ -0,0 +1,368 @@
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
wpng - simple PNG-writing program writepng.c
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1998-2000 Greg Roelofs. All rights reserved.
|
||||
|
||||
This software is provided "as is," without warranty of any kind,
|
||||
express or implied. In no event shall the author or contributors
|
||||
be held liable for any damages arising in any way from the use of
|
||||
this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute
|
||||
it freely, subject to the following restrictions:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, disclaimer, and this list of conditions.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, disclaimer, and this list of conditions in the documenta-
|
||||
tion and/or other materials provided with the distribution.
|
||||
3. All advertising materials mentioning features or use of this
|
||||
software must display the following acknowledgment:
|
||||
|
||||
This product includes software developed by Greg Roelofs
|
||||
and contributors for the book, "PNG: The Definitive Guide,"
|
||||
published by O'Reilly and Associates.
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#include <stdlib.h> /* for exit() prototype */
|
||||
|
||||
#include "png.h" /* libpng header; includes zlib.h and setjmp.h */
|
||||
#include "writepng.h" /* typedefs, common macros, public prototypes */
|
||||
|
||||
|
||||
/* local prototype */
|
||||
|
||||
static void writepng_error_handler(png_structp png_ptr, png_const_charp msg);
|
||||
|
||||
|
||||
|
||||
void writepng_version_info(void)
|
||||
{
|
||||
fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n",
|
||||
PNG_LIBPNG_VER_STRING, png_libpng_ver);
|
||||
fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n",
|
||||
ZLIB_VERSION, zlib_version);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* returns 0 for success, 2 for libpng problem, 4 for out of memory, 11 for
|
||||
* unexpected pnmtype; note that outfile might be stdout */
|
||||
|
||||
int writepng_init(mainprog_info *mainprog_ptr)
|
||||
{
|
||||
png_structp png_ptr; /* note: temporary variables! */
|
||||
png_infop info_ptr;
|
||||
int color_type, interlace_type;
|
||||
|
||||
|
||||
/* could also replace libpng warning-handler (final NULL), but no need: */
|
||||
|
||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr,
|
||||
writepng_error_handler, NULL);
|
||||
if (!png_ptr)
|
||||
return 4; /* out of memory */
|
||||
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr) {
|
||||
png_destroy_write_struct(&png_ptr, NULL);
|
||||
return 4; /* out of memory */
|
||||
}
|
||||
|
||||
|
||||
/* setjmp() must be called in every function that calls a PNG-writing
|
||||
* libpng function, unless an alternate error handler was installed--
|
||||
* but compatible error handlers must either use longjmp() themselves
|
||||
* (as in this program) or exit immediately, so here we go: */
|
||||
|
||||
if (setjmp(mainprog_ptr->jmpbuf)) {
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
/* make sure outfile is (re)opened in BINARY mode */
|
||||
|
||||
png_init_io(png_ptr, mainprog_ptr->outfile);
|
||||
|
||||
|
||||
/* set the compression levels--in general, always want to leave filtering
|
||||
* turned on (except for palette images) and allow all of the filters,
|
||||
* which is the default; want 32K zlib window, unless entire image buffer
|
||||
* is 16K or smaller (unknown here)--also the default; usually want max
|
||||
* compression (NOT the default); and remaining compression flags should
|
||||
* be left alone */
|
||||
|
||||
png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
|
||||
/*
|
||||
>> this is default for no filtering; Z_FILTERED is default otherwise:
|
||||
png_set_compression_strategy(png_ptr, Z_DEFAULT_STRATEGY);
|
||||
>> these are all defaults:
|
||||
png_set_compression_mem_level(png_ptr, 8);
|
||||
png_set_compression_window_bits(png_ptr, 15);
|
||||
png_set_compression_method(png_ptr, 8);
|
||||
*/
|
||||
|
||||
|
||||
/* set the image parameters appropriately */
|
||||
|
||||
if (mainprog_ptr->pnmtype == 5)
|
||||
color_type = PNG_COLOR_TYPE_GRAY;
|
||||
else if (mainprog_ptr->pnmtype == 6)
|
||||
color_type = PNG_COLOR_TYPE_RGB;
|
||||
else if (mainprog_ptr->pnmtype == 8)
|
||||
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||
else {
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
return 11;
|
||||
}
|
||||
|
||||
interlace_type = mainprog_ptr->interlaced? PNG_INTERLACE_ADAM7 :
|
||||
PNG_INTERLACE_NONE;
|
||||
|
||||
png_set_IHDR(png_ptr, info_ptr, mainprog_ptr->width, mainprog_ptr->height,
|
||||
mainprog_ptr->sample_depth, color_type, interlace_type,
|
||||
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
||||
|
||||
if (mainprog_ptr->gamma > 0.0)
|
||||
png_set_gAMA(png_ptr, info_ptr, mainprog_ptr->gamma);
|
||||
|
||||
if (mainprog_ptr->have_bg) { /* we know it's RGBA, not gray+alpha */
|
||||
png_color_16 background;
|
||||
|
||||
background.red = mainprog_ptr->bg_red;
|
||||
background.green = mainprog_ptr->bg_green;
|
||||
background.blue = mainprog_ptr->bg_blue;
|
||||
png_set_bKGD(png_ptr, info_ptr, &background);
|
||||
}
|
||||
|
||||
if (mainprog_ptr->have_time) {
|
||||
png_time modtime;
|
||||
|
||||
png_convert_from_time_t(&modtime, mainprog_ptr->modtime);
|
||||
png_set_tIME(png_ptr, info_ptr, &modtime);
|
||||
}
|
||||
|
||||
if (mainprog_ptr->have_text) {
|
||||
png_text text[6];
|
||||
int num_text = 0;
|
||||
|
||||
if (mainprog_ptr->have_text & TEXT_TITLE) {
|
||||
text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
text[num_text].key = "Title";
|
||||
text[num_text].text = mainprog_ptr->title;
|
||||
++num_text;
|
||||
}
|
||||
if (mainprog_ptr->have_text & TEXT_AUTHOR) {
|
||||
text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
text[num_text].key = "Author";
|
||||
text[num_text].text = mainprog_ptr->author;
|
||||
++num_text;
|
||||
}
|
||||
if (mainprog_ptr->have_text & TEXT_DESC) {
|
||||
text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
text[num_text].key = "Description";
|
||||
text[num_text].text = mainprog_ptr->desc;
|
||||
++num_text;
|
||||
}
|
||||
if (mainprog_ptr->have_text & TEXT_COPY) {
|
||||
text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
text[num_text].key = "Copyright";
|
||||
text[num_text].text = mainprog_ptr->copyright;
|
||||
++num_text;
|
||||
}
|
||||
if (mainprog_ptr->have_text & TEXT_EMAIL) {
|
||||
text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
text[num_text].key = "E-mail";
|
||||
text[num_text].text = mainprog_ptr->email;
|
||||
++num_text;
|
||||
}
|
||||
if (mainprog_ptr->have_text & TEXT_URL) {
|
||||
text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
text[num_text].key = "URL";
|
||||
text[num_text].text = mainprog_ptr->url;
|
||||
++num_text;
|
||||
}
|
||||
png_set_text(png_ptr, info_ptr, text, num_text);
|
||||
}
|
||||
|
||||
|
||||
/* write all chunks up to (but not including) first IDAT */
|
||||
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
|
||||
|
||||
/* if we wanted to write any more text info *after* the image data, we
|
||||
* would set up text struct(s) here and call png_set_text() again, with
|
||||
* just the new data; png_set_tIME() could also go here, but it would
|
||||
* have no effect since we already called it above (only one tIME chunk
|
||||
* allowed) */
|
||||
|
||||
|
||||
/* set up the transformations: for now, just pack low-bit-depth pixels
|
||||
* into bytes (one, two or four pixels per byte) */
|
||||
|
||||
png_set_packing(png_ptr);
|
||||
/* png_set_shift(png_ptr, &sig_bit); to scale low-bit-depth values */
|
||||
|
||||
|
||||
/* make sure we save our pointers for use in writepng_encode_image() */
|
||||
|
||||
mainprog_ptr->png_ptr = png_ptr;
|
||||
mainprog_ptr->info_ptr = info_ptr;
|
||||
|
||||
|
||||
/* OK, that's all we need to do for now; return happy */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* returns 0 for success, 2 for libpng (longjmp) problem */
|
||||
|
||||
int writepng_encode_image(mainprog_info *mainprog_ptr)
|
||||
{
|
||||
png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
|
||||
png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
|
||||
|
||||
|
||||
/* as always, setjmp() must be called in every function that calls a
|
||||
* PNG-writing libpng function */
|
||||
|
||||
if (setjmp(mainprog_ptr->jmpbuf)) {
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
mainprog_ptr->png_ptr = NULL;
|
||||
mainprog_ptr->info_ptr = NULL;
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
/* and now we just write the whole image; libpng takes care of interlacing
|
||||
* for us */
|
||||
|
||||
png_write_image(png_ptr, mainprog_ptr->row_pointers);
|
||||
|
||||
|
||||
/* since that's it, we also close out the end of the PNG file now--if we
|
||||
* had any text or time info to write after the IDATs, second argument
|
||||
* would be info_ptr, but we optimize slightly by sending NULL pointer: */
|
||||
|
||||
png_write_end(png_ptr, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* returns 0 if succeeds, 2 if libpng problem */
|
||||
|
||||
int writepng_encode_row(mainprog_info *mainprog_ptr) /* NON-interlaced only! */
|
||||
{
|
||||
png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
|
||||
png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
|
||||
|
||||
|
||||
/* as always, setjmp() must be called in every function that calls a
|
||||
* PNG-writing libpng function */
|
||||
|
||||
if (setjmp(mainprog_ptr->jmpbuf)) {
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
mainprog_ptr->png_ptr = NULL;
|
||||
mainprog_ptr->info_ptr = NULL;
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
/* image_data points at our one row of image data */
|
||||
|
||||
png_write_row(png_ptr, mainprog_ptr->image_data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* returns 0 if succeeds, 2 if libpng problem */
|
||||
|
||||
int writepng_encode_finish(mainprog_info *mainprog_ptr) /* NON-interlaced! */
|
||||
{
|
||||
png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
|
||||
png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
|
||||
|
||||
|
||||
/* as always, setjmp() must be called in every function that calls a
|
||||
* PNG-writing libpng function */
|
||||
|
||||
if (setjmp(mainprog_ptr->jmpbuf)) {
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
mainprog_ptr->png_ptr = NULL;
|
||||
mainprog_ptr->info_ptr = NULL;
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
/* close out PNG file; if we had any text or time info to write after
|
||||
* the IDATs, second argument would be info_ptr: */
|
||||
|
||||
png_write_end(png_ptr, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void writepng_cleanup(mainprog_info *mainprog_ptr)
|
||||
{
|
||||
png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
|
||||
png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
|
||||
|
||||
if (png_ptr && info_ptr)
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void writepng_error_handler(png_structp png_ptr, png_const_charp msg)
|
||||
{
|
||||
mainprog_info *mainprog_ptr;
|
||||
|
||||
/* This function, aside from the extra step of retrieving the "error
|
||||
* pointer" (below) and the fact that it exists within the application
|
||||
* rather than within libpng, is essentially identical to libpng's
|
||||
* default error handler. The second point is critical: since both
|
||||
* setjmp() and longjmp() are called from the same code, they are
|
||||
* guaranteed to have compatible notions of how big a jmp_buf is,
|
||||
* regardless of whether _BSD_SOURCE or anything else has (or has not)
|
||||
* been defined. */
|
||||
|
||||
fprintf(stderr, "writepng libpng error: %s\n", msg);
|
||||
fflush(stderr);
|
||||
|
||||
mainprog_ptr = png_get_error_ptr(png_ptr);
|
||||
if (mainprog_ptr == NULL) { /* we are completely hosed now */
|
||||
fprintf(stderr,
|
||||
"writepng severe error: jmpbuf not recoverable; terminating.\n");
|
||||
fflush(stderr);
|
||||
exit(99);
|
||||
}
|
||||
|
||||
longjmp(mainprog_ptr->jmpbuf, 1);
|
||||
}
|
||||
109
contrib/gregbook/writepng.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/*---------------------------------------------------------------------------
|
||||
|
||||
wpng - simple PNG-writing program writepng.h
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1998-2000 Greg Roelofs. All rights reserved.
|
||||
|
||||
This software is provided "as is," without warranty of any kind,
|
||||
express or implied. In no event shall the author or contributors
|
||||
be held liable for any damages arising in any way from the use of
|
||||
this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute
|
||||
it freely, subject to the following restrictions:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, disclaimer, and this list of conditions.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, disclaimer, and this list of conditions in the documenta-
|
||||
tion and/or other materials provided with the distribution.
|
||||
3. All advertising materials mentioning features or use of this
|
||||
software must display the following acknowledgment:
|
||||
|
||||
This product includes software developed by Greg Roelofs
|
||||
and contributors for the book, "PNG: The Definitive Guide,"
|
||||
published by O'Reilly and Associates.
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef TRUE
|
||||
# define TRUE 1
|
||||
# define FALSE 0
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
# define MAX(a,b) ((a) > (b)? (a) : (b))
|
||||
# define MIN(a,b) ((a) < (b)? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
# define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);}
|
||||
#else
|
||||
# define Trace(x) ;
|
||||
#endif
|
||||
|
||||
#define TEXT_TITLE 0x01
|
||||
#define TEXT_AUTHOR 0x02
|
||||
#define TEXT_DESC 0x04
|
||||
#define TEXT_COPY 0x08
|
||||
#define TEXT_EMAIL 0x10
|
||||
#define TEXT_URL 0x20
|
||||
|
||||
#define TEXT_TITLE_OFFSET 0
|
||||
#define TEXT_AUTHOR_OFFSET 72
|
||||
#define TEXT_COPY_OFFSET (2*72)
|
||||
#define TEXT_EMAIL_OFFSET (3*72)
|
||||
#define TEXT_URL_OFFSET (4*72)
|
||||
#define TEXT_DESC_OFFSET (5*72)
|
||||
|
||||
typedef unsigned char uch;
|
||||
typedef unsigned short ush;
|
||||
typedef unsigned long ulg;
|
||||
|
||||
typedef struct _mainprog_info {
|
||||
double gamma;
|
||||
long width;
|
||||
long height;
|
||||
time_t modtime;
|
||||
FILE *infile;
|
||||
FILE *outfile;
|
||||
void *png_ptr;
|
||||
void *info_ptr;
|
||||
uch *image_data;
|
||||
uch **row_pointers;
|
||||
char *title;
|
||||
char *author;
|
||||
char *desc;
|
||||
char *copyright;
|
||||
char *email;
|
||||
char *url;
|
||||
int filter; /* command-line-filter flag, not PNG row filter! */
|
||||
int pnmtype;
|
||||
int sample_depth;
|
||||
int interlaced;
|
||||
int have_bg;
|
||||
int have_time;
|
||||
int have_text;
|
||||
jmp_buf jmpbuf;
|
||||
uch bg_red;
|
||||
uch bg_green;
|
||||
uch bg_blue;
|
||||
} mainprog_info;
|
||||
|
||||
|
||||
/* prototypes for public functions in writepng.c */
|
||||
|
||||
void writepng_version_info(void);
|
||||
|
||||
int writepng_init(mainprog_info *mainprog_ptr);
|
||||
|
||||
int writepng_encode_image(mainprog_info *mainprog_ptr);
|
||||
|
||||
int writepng_encode_row(mainprog_info *mainprog_ptr);
|
||||
|
||||
int writepng_encode_finish(mainprog_info *mainprog_ptr);
|
||||
|
||||
void writepng_cleanup(mainprog_info *mainprog_ptr);
|
||||
153
contrib/pngminus/README
Normal file
@@ -0,0 +1,153 @@
|
||||
PngMinus
|
||||
--------
|
||||
(copyright Willem van Schaik, 1999)
|
||||
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby granted,
|
||||
provided that the above copyright notice appear in all copies and
|
||||
that both that copyright notice and this permission notice appear in
|
||||
supporting documentation. This software is provided "as is" without
|
||||
express or implied warranty.
|
||||
|
||||
|
||||
Some history
|
||||
------------
|
||||
Soon after the creation of PNG in 1995, the need was felt for a set of
|
||||
pnmtopng / pngtopnm utilities. Independantly Alexander Lehmann and I
|
||||
(Willem van Schaik) started such a project. Luckily we discovered this
|
||||
and merged the two together into pnmtopng.tar.gz, which is available
|
||||
from a/o ftp://swrinde.nde.swri.edu/pub/png/.
|
||||
|
||||
These two utilities have many, many options and make use of most of the
|
||||
features of PNG, like gamma, alpha, sbit, text-chunks, etc. This makes
|
||||
the utilities quite complex and by now not anymore very maintainable.
|
||||
When we wrote these programs, libpng was still in an early stage.
|
||||
Therefore, lots of the functionality that we put in our software can now
|
||||
be done using transform-functions in libpng.
|
||||
|
||||
Finally, to compile these programs, you need to have installed and
|
||||
compiled three libraries: libpng, zlib and netpbm. Especially the latter
|
||||
makes the whole setup a bit bulky. But that's unavoidable given the many
|
||||
features of pnmtopng.
|
||||
|
||||
|
||||
What now
|
||||
--------
|
||||
At this moment libpng is in a very stable state and can do much of the
|
||||
work done in pnmtopng. Also, pnmtopng needs to be upgraded to the new
|
||||
interface of libpng. Hence, it is time for a rewrite from the ground up
|
||||
of pnmtopng and pngtopnm. This will happen in the near future (stay
|
||||
tuned). The new package will get a different name to distinguish it from
|
||||
the old one: PngPlus.
|
||||
|
||||
To experiment a bit with the new interface of libpng, I started off with
|
||||
a small prototype that contains only the basic functionality. It doesn't
|
||||
have any of the options to read or write special chunks and it will do
|
||||
no gamma correction. But this makes it also a simple program that is
|
||||
quite easy to understand and can serve well as a template for other
|
||||
software developments. (By now there are of course a couple of programs,
|
||||
like Greg Roelofs' rpng/wpng, that can be used just as good.)
|
||||
|
||||
|
||||
Can and can not
|
||||
---------------
|
||||
As this is the small brother of the future PngPlus, I called this fellow
|
||||
PngMinus. Because I started this development in good-old Turbo-C, I
|
||||
avoided the use the netpbm library, which requires DOS extenders. Again,
|
||||
another reason to call it PngMinus (minus netpbm :-). So, part of the
|
||||
program are some elementary routines to read / write pgm- and ppm-files.
|
||||
It does not read b&w pbm-files.
|
||||
|
||||
The downside of this approach is that you can not use them on images
|
||||
that require blocks of memory bigger than 64k (the DOS version). For
|
||||
larger images you will get an out-of-memory error.
|
||||
|
||||
As said before, PngMinus doesn't correct for gamma. When reading
|
||||
png-files you can do this just as well by piping the output of png2pnm
|
||||
to pnmgamma, one of the standard PbmPlus tools. This same scenario will
|
||||
most probably also be followed in the full-blown future PngPlus, with
|
||||
the addition of course of the possibility to create gamma-chunks when
|
||||
writing png-files.
|
||||
|
||||
On the other hand it supports alpha-channels. When reading a png-image
|
||||
you can write the alpha-channel into a pgm-file. And when creating an
|
||||
RGB+A png-image, you just combine a ppm-file with a corresponding
|
||||
pgm-file containing the alpha-channel. When reading, transparency chunks
|
||||
are converted into an alpha-channel and from there on treated the same
|
||||
way.
|
||||
|
||||
Finally you can opt for writing ascii or binary pgm- and ppm-files. When
|
||||
the bit-depth is 16, the format will always be ascii.
|
||||
|
||||
|
||||
Using it
|
||||
--------
|
||||
To distinguish them from pnmtopng and PngPlus, the utilities are named
|
||||
png2pnm and pnm2png (2 instead of to). The input- and output-files can
|
||||
be given as parameters or through redirection. Therefore the programs
|
||||
can be part of a pipe.
|
||||
|
||||
To list the options type "png2pnm -h" or "pnm2png -h".
|
||||
|
||||
|
||||
Just like Scandinavian furniture
|
||||
--------------------------------
|
||||
You have to put it together yourself. I did test the software under
|
||||
MS-DOS with Turbo-C 3.0 and under RedHat Linux 4.2 with gcc. In both
|
||||
cases I used libpng-1.0.4 and zlib-1.1.3. Later versions should be OK,
|
||||
however some older libpng versions have a bug in pngmem.c when using
|
||||
Turbo-C 3.0 (see below).
|
||||
|
||||
You can build it using one of the two makefiles (make -f makefile.###)
|
||||
or use the batch/script files pngminus.bat / pngminus.sh. This assumes
|
||||
that you have built the libraries in ../libpng and ../zlib. Using Linux,
|
||||
make sure that you have built libpng with makefile.std and not
|
||||
makefile.linux (also called .lnx in earlier versions of libpng). The
|
||||
latter creates a .so shared-library, while the PngMinus makefile assumes
|
||||
a normal .a static library.
|
||||
|
||||
If you create a ../pngsuite directory and then store the basn####.png
|
||||
files from PngSuite (http://www.schaik.com/pngsuite/) in there, you can
|
||||
test in one go the proper functioning of PngMinus, see png2pnm.bat and
|
||||
pnm2png.bat (or the .sh versions).
|
||||
|
||||
|
||||
Warranty
|
||||
-------
|
||||
Please, remember that this was just a small experiment to learn a few
|
||||
things. It will have many unforeseen features <vbg>. Who said bugs? Use
|
||||
it when you are in need for something simple or when you want to start
|
||||
developing your own stuff.
|
||||
|
||||
|
||||
The Turbo bug
|
||||
-------------
|
||||
** pngmem.old
|
||||
hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
|
||||
hptr += 16L;
|
||||
** pngmem.c
|
||||
hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
|
||||
hptr = hptr + 16L;
|
||||
**
|
||||
|
||||
** pngmem.old
|
||||
png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
|
||||
hptr += (png_uint_32)65536L;
|
||||
** pngmem.c
|
||||
png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
|
||||
hptr = hptr + 65536L;
|
||||
**
|
||||
|
||||
|
||||
The end
|
||||
-------
|
||||
Willem van Schaik
|
||||
mailto:willem@schaik.com
|
||||
http://www.schaik.com/png/
|
||||
-------
|
||||
Oct 1999
|
||||
|
||||
52
contrib/pngminus/makefile
Normal file
@@ -0,0 +1,52 @@
|
||||
# Makefile for PngMinus (png2pnm and pnm2png)
|
||||
# Linux / Unix
|
||||
|
||||
CC=cc -O -n32
|
||||
LD=cc -O -n32
|
||||
#CC=gcc -O
|
||||
#LD=gcc -O
|
||||
LB=ar
|
||||
RM=rm
|
||||
CP=cp
|
||||
|
||||
PNGPATH = /usr/local
|
||||
PNGINC = $(PNGPATH)/include
|
||||
PNGLIB = $(PNGPATH)/lib -lpng
|
||||
# PNGLIB = $(PNGPATH)/libpng.a
|
||||
|
||||
ZPATH = /usr/local
|
||||
ZINC = $(ZPATH)/include
|
||||
ZLIB = $(ZPATH)/lib -lz
|
||||
# ZLIB = $(ZPATH)/libz.a
|
||||
|
||||
CCFLAGS=-I$(PNGINC) -I$(ZINC)
|
||||
LDFLAGS=-L$(PNGLIB) -L$(ZLIB) -lm
|
||||
C=.c
|
||||
O=.o
|
||||
L=.a
|
||||
E=
|
||||
|
||||
# dependencies
|
||||
|
||||
all: png2pnm$(E) pnm2png$(E)
|
||||
|
||||
png2pnm$(O): png2pnm$(C)
|
||||
$(CC) -c $(CCFLAGS) png2pnm$(C)
|
||||
|
||||
png2pnm$(E): png2pnm$(O)
|
||||
$(LD) -o png2pnm$(E) png2pnm$(O) $(LDFLAGS)
|
||||
|
||||
pnm2png$(O): pnm2png$(C)
|
||||
$(CC) -c $(CCFLAGS) pnm2png$(C)
|
||||
|
||||
pnm2png$(E): pnm2png$(O)
|
||||
$(LD) -o pnm2png$(E) pnm2png$(O) $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
$(RM) png2pnm$(O)
|
||||
$(RM) pnm2png$(O)
|
||||
$(RM) png2pnm$(E)
|
||||
$(RM) pnm2png$(E)
|
||||
|
||||
# End of makefile for png2pnm / pnm2png
|
||||
|
||||
52
contrib/pngminus/makefile.std
Normal file
@@ -0,0 +1,52 @@
|
||||
# Makefile for PngMinus (png2pnm and pnm2png)
|
||||
# Linux / Unix
|
||||
|
||||
CC=cc -O
|
||||
LD=cc -O
|
||||
#CC=gcc -O
|
||||
#LD=gcc -O
|
||||
LB=ar
|
||||
RM=rm
|
||||
CP=cp
|
||||
|
||||
PNGPATH = /usr/local
|
||||
PNGINC = $(PNGPATH)/include
|
||||
#PNGLIB = $(PNGPATH)/lib -lpng
|
||||
PNGLIB = $(PNGPATH)/lib/libpng.a
|
||||
|
||||
ZPATH = /usr/local
|
||||
ZINC = $(ZPATH)/include
|
||||
#ZLIB = $(ZPATH)/lib -lz
|
||||
ZLIB = $(ZPATH)/lib/libz.a
|
||||
|
||||
CCFLAGS=-I$(PNGINC) -I$(ZINC)
|
||||
LDFLAGS=-L$(PNGLIB) -L$(ZLIB)
|
||||
C=.c
|
||||
O=.o
|
||||
L=.a
|
||||
E=
|
||||
|
||||
# dependencies
|
||||
|
||||
all: png2pnm$(E) pnm2png$(E)
|
||||
|
||||
png2pnm$(O): png2pnm$(C)
|
||||
$(CC) -c $(CCFLAGS) png2pnm$(C)
|
||||
|
||||
png2pnm$(E): png2pnm$(O)
|
||||
$(LD) -o png2pnm$(E) png2pnm$(O) $(LDFLAGS) -lpng -lz -lm
|
||||
|
||||
pnm2png$(O): pnm2png$(C)
|
||||
$(CC) -c $(CCFLAGS) pnm2png$(C)
|
||||
|
||||
pnm2png$(E): pnm2png$(O)
|
||||
$(LD) -o pnm2png$(E) pnm2png$(O) $(LDFLAGS) -lpng -lz -lm
|
||||
|
||||
clean:
|
||||
$(RM) png2pnm$(O)
|
||||
$(RM) pnm2png$(O)
|
||||
$(RM) png2pnm$(E)
|
||||
$(RM) pnm2png$(E)
|
||||
|
||||
# End of makefile for png2pnm / pnm2png
|
||||
|
||||
38
contrib/pngminus/makefile.tc3
Normal file
@@ -0,0 +1,38 @@
|
||||
# Makefile for PngMinus (png2pnm and pnm2png)
|
||||
# TurboC++ 3.0
|
||||
|
||||
CC=tcc -Ic:\tc3\inc
|
||||
LD=tcc -Lc:\tc3\lib
|
||||
LB=tlib
|
||||
RM=del
|
||||
CP=copy
|
||||
MODEL=l
|
||||
CCFLAGS=-O -m$(MODEL) -I..\libpng -I..\zlib
|
||||
LDFLAGS=-m$(MODEL) -L..\libpng -L..\zlib
|
||||
C=.c
|
||||
O=.obj
|
||||
L=.lib
|
||||
E=.exe
|
||||
|
||||
# dependencies
|
||||
|
||||
all: png2pnm$(E) pnm2png$(E)
|
||||
|
||||
png2pnm$(O): png2pnm$(C)
|
||||
$(CC) -c $(CCFLAGS) png2pnm$(C)
|
||||
|
||||
png2pnm$(E): png2pnm$(O)
|
||||
$(LD) $(LDFLAGS) png2pnm$(O) libpng$(L) zlib$(L)
|
||||
|
||||
pnm2png$(O): pnm2png$(C)
|
||||
$(CC) -c $(CCFLAGS) pnm2png$(C)
|
||||
|
||||
pnm2png$(E): pnm2png$(O)
|
||||
$(LD) $(LDFLAGS) pnm2png$(O) libpng$(L) zlib$(L)
|
||||
|
||||
clean:
|
||||
$(RM) *$(O)
|
||||
$(RM) *$(E)
|
||||
|
||||
# End of makefile for png2pnm / pnm2png
|
||||
|
||||
92
contrib/pngminus/makevms.com
Normal file
@@ -0,0 +1,92 @@
|
||||
$!------------------------------------------------------------------------------
|
||||
$! make Contrib programs of libpng under OpenVMS
|
||||
$!
|
||||
$!
|
||||
$! Look for the compiler used
|
||||
$!
|
||||
$ zlibsrc = "[---.zlib]"
|
||||
$ ccopt="/include=(''zlibsrc',[--])"
|
||||
$ if f$getsyi("HW_MODEL").ge.1024
|
||||
$ then
|
||||
$ ccopt = "/prefix=all"+ccopt
|
||||
$ comp = "__decc__=1"
|
||||
$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
|
||||
$ else
|
||||
$ if f$search("SYS$SYSTEM:DECC$COMPILER.EXE").eqs.""
|
||||
$ then
|
||||
$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
|
||||
$ if f$search("SYS$SYSTEM:VAXC.EXE").eqs.""
|
||||
$ then
|
||||
$ comp = "__gcc__=1"
|
||||
$ CC :== GCC
|
||||
$ else
|
||||
$ comp = "__vaxc__=1"
|
||||
$ endif
|
||||
$ else
|
||||
$ if f$trnlnm("SYS").eqs."" then define sys decc$library_include:
|
||||
$ ccopt = "/decc/prefix=all"+ccopt
|
||||
$ comp = "__decc__=1"
|
||||
$ endif
|
||||
$ endif
|
||||
$ open/write lopt lib.opt
|
||||
$ write lopt "[--]libpng.olb/lib"
|
||||
$ write lopt "''zlibsrc'libz.olb/lib"
|
||||
$ close lopt
|
||||
$ open/write xopt x11.opt
|
||||
$ write xopt "sys$library:decw$xlibshr.exe/share"
|
||||
$ close xopt
|
||||
$ write sys$output "Compiling PNG contrib programs ..."
|
||||
$ write sys$output "Building pnm2png..."
|
||||
$ CALL MAKE pnm2png.OBJ "cc ''CCOPT' pnm2png" -
|
||||
pnm2png.c
|
||||
$ call make pnm2png.exe -
|
||||
"LINK pnm2png,lib.opt/opt" -
|
||||
pnm2png.obj
|
||||
$ write sys$output "Building png2pnm..."
|
||||
$ CALL MAKE png2pnm.OBJ "cc ''CCOPT' png2pnm" -
|
||||
png2pnm.c
|
||||
$ call make pnm2png.exe -
|
||||
"LINK pnm2png,lib.opt/opt" -
|
||||
pnm2png.obj
|
||||
$ exit
|
||||
$!
|
||||
$!
|
||||
$MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES
|
||||
$ V = 'F$Verify(0)
|
||||
$! P1 = What we are trying to make
|
||||
$! P2 = Command to make it
|
||||
$! P3 - P8 What it depends on
|
||||
$
|
||||
$ If F$Search(P1) .Eqs. "" Then Goto Makeit
|
||||
$ Time = F$CvTime(F$File(P1,"RDT"))
|
||||
$arg=3
|
||||
$Loop:
|
||||
$ Argument = P'arg
|
||||
$ If Argument .Eqs. "" Then Goto Exit
|
||||
$ El=0
|
||||
$Loop2:
|
||||
$ File = F$Element(El," ",Argument)
|
||||
$ If File .Eqs. " " Then Goto Endl
|
||||
$ AFile = ""
|
||||
$Loop3:
|
||||
$ OFile = AFile
|
||||
$ AFile = F$Search(File)
|
||||
$ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl
|
||||
$ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit
|
||||
$ Goto Loop3
|
||||
$NextEL:
|
||||
$ El = El + 1
|
||||
$ Goto Loop2
|
||||
$EndL:
|
||||
$ arg=arg+1
|
||||
$ If arg .Le. 8 Then Goto Loop
|
||||
$ Goto Exit
|
||||
$
|
||||
$Makeit:
|
||||
$ VV=F$VERIFY(0)
|
||||
$ write sys$output P2
|
||||
$ 'P2
|
||||
$ VV='F$Verify(VV)
|
||||
$Exit:
|
||||
$ If V Then Set Verify
|
||||
$ENDSUBROUTINE
|
||||
41
contrib/pngminus/png2pnm.bat
Normal file
@@ -0,0 +1,41 @@
|
||||
REM -- grayscale
|
||||
png2pnm.exe -noraw ..\pngsuite\basn0g01.png basn0g01.pgm
|
||||
png2pnm.exe -noraw ..\pngsuite\basn0g02.png basn0g02.pgm
|
||||
png2pnm.exe -noraw ..\pngsuite\basn0g04.png basn0g04.pgm
|
||||
png2pnm.exe -noraw ..\pngsuite\basn0g08.png basn0g08.pgm
|
||||
png2pnm.exe -noraw ..\pngsuite\basn0g16.png basn0g16.pgm
|
||||
REM -- full-color
|
||||
png2pnm.exe -noraw ..\pngsuite\basn2c08.png basn2c08.ppm
|
||||
png2pnm.exe -noraw ..\pngsuite\basn2c16.png basn2c16.ppm
|
||||
REM -- palletted
|
||||
png2pnm.exe -noraw ..\pngsuite\basn3p01.png basn3p01.ppm
|
||||
png2pnm.exe -noraw ..\pngsuite\basn3p02.png basn3p02.ppm
|
||||
png2pnm.exe -noraw ..\pngsuite\basn3p04.png basn3p04.ppm
|
||||
png2pnm.exe -noraw ..\pngsuite\basn3p08.png basn3p08.ppm
|
||||
REM -- gray with alpha-channel
|
||||
png2pnm.exe -noraw ..\pngsuite\basn4a08.png basn4a08.pgm
|
||||
png2pnm.exe -noraw ..\pngsuite\basn4a16.png basn4a16.pgm
|
||||
REM -- color with alpha-channel
|
||||
png2pnm.exe -noraw -alpha basn6a08.pgm ..\pngsuite\basn6a08.png basn6a08.ppm
|
||||
png2pnm.exe -noraw -alpha basn6a16.pgm ..\pngsuite\basn6a16.png basn6a16.ppm
|
||||
REM -- grayscale
|
||||
png2pnm.exe -raw ..\pngsuite\basn0g01.png rawn0g01.pgm
|
||||
png2pnm.exe -raw ..\pngsuite\basn0g02.png rawn0g02.pgm
|
||||
png2pnm.exe -raw ..\pngsuite\basn0g04.png rawn0g04.pgm
|
||||
png2pnm.exe -raw ..\pngsuite\basn0g08.png rawn0g08.pgm
|
||||
png2pnm.exe -raw ..\pngsuite\basn0g16.png rawn0g16.pgm
|
||||
REM -- full-color
|
||||
png2pnm.exe -raw ..\pngsuite\basn2c08.png rawn2c08.ppm
|
||||
png2pnm.exe -raw ..\pngsuite\basn2c16.png rawn2c16.ppm
|
||||
REM -- palletted
|
||||
png2pnm.exe -raw ..\pngsuite\basn3p01.png rawn3p01.ppm
|
||||
png2pnm.exe -raw ..\pngsuite\basn3p02.png rawn3p02.ppm
|
||||
png2pnm.exe -raw ..\pngsuite\basn3p04.png rawn3p04.ppm
|
||||
png2pnm.exe -raw ..\pngsuite\basn3p08.png rawn3p08.ppm
|
||||
REM -- gray with alpha-channel
|
||||
png2pnm.exe -raw ..\pngsuite\basn4a08.png rawn4a08.pgm
|
||||
png2pnm.exe -raw ..\pngsuite\basn4a16.png rawn4a16.pgm
|
||||
REM -- color with alpha-channel
|
||||
png2pnm.exe -noraw -alpha rawn6a08.pgm ..\pngsuite\basn6a08.png rawn6a08.ppm
|
||||
png2pnm.exe -noraw -alpha rawn6a16.pgm ..\pngsuite\basn6a16.png rawn6a16.ppm
|
||||
|
||||
425
contrib/pngminus/png2pnm.c
Normal file
@@ -0,0 +1,425 @@
|
||||
/*
|
||||
* png2pnm.c --- conversion from PNG-file to PGM/PPM-file
|
||||
* copyright (C) 1999 by Willem van Schaik <willem@schaik.com>
|
||||
*
|
||||
* version 1.0 - 1999.10.15 - First version.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and
|
||||
* its documentation for any purpose and without fee is hereby granted,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear in
|
||||
* supporting documentation. This software is provided "as is" without
|
||||
* express or implied warranty.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef __TURBOC__
|
||||
#include <mem.h>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#ifndef BOOL
|
||||
#define BOOL unsigned char
|
||||
#endif
|
||||
#ifndef TRUE
|
||||
#define TRUE (BOOL) 1
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
#define FALSE (BOOL) 0
|
||||
#endif
|
||||
|
||||
#ifdef __TURBOC__
|
||||
#define STDIN 0
|
||||
#define STDOUT 1
|
||||
#define STDERR 2
|
||||
#endif
|
||||
|
||||
/* to make png2pnm verbose so we can find problems (needs to be before png.h) */
|
||||
#ifndef PNG_DEBUG
|
||||
#define PNG_DEBUG 0
|
||||
#endif
|
||||
|
||||
#include "png.h"
|
||||
|
||||
/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
|
||||
#ifndef png_jmpbuf
|
||||
# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
|
||||
#endif
|
||||
|
||||
/* function prototypes */
|
||||
|
||||
int main (int argc, char *argv[]);
|
||||
void usage ();
|
||||
BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw, BOOL alpha);
|
||||
|
||||
/*
|
||||
* main
|
||||
*/
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *fp_rd = stdin;
|
||||
FILE *fp_wr = stdout;
|
||||
FILE *fp_al = NULL;
|
||||
BOOL raw = TRUE;
|
||||
BOOL alpha = FALSE;
|
||||
int argi;
|
||||
|
||||
for (argi = 1; argi < argc; argi++)
|
||||
{
|
||||
if (argv[argi][0] == '-')
|
||||
{
|
||||
switch (argv[argi][1])
|
||||
{
|
||||
case 'n':
|
||||
raw = FALSE;
|
||||
break;
|
||||
case 'r':
|
||||
raw = TRUE;
|
||||
break;
|
||||
case 'a':
|
||||
alpha = TRUE;
|
||||
argi++;
|
||||
if ((fp_al = fopen (argv[argi], "wb")) == NULL)
|
||||
{
|
||||
fprintf (stderr, "PNM2PNG\n");
|
||||
fprintf (stderr, "Error: can not create alpha-channel file %s\n", argv[argi]);
|
||||
exit (1);
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
usage();
|
||||
exit(0);
|
||||
break;
|
||||
default:
|
||||
fprintf (stderr, "PNG2PNM\n");
|
||||
fprintf (stderr, "Error: unknown option %s\n", argv[argi]);
|
||||
usage();
|
||||
exit(1);
|
||||
break;
|
||||
} /* end switch */
|
||||
}
|
||||
else if (fp_rd == stdin)
|
||||
{
|
||||
if ((fp_rd = fopen (argv[argi], "rb")) == NULL)
|
||||
{
|
||||
fprintf (stderr, "PNG2PNM\n");
|
||||
fprintf (stderr, "Error: file %s does not exist\n", argv[argi]);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
else if (fp_wr == stdout)
|
||||
{
|
||||
if ((fp_wr = fopen (argv[argi], "wb")) == NULL)
|
||||
{
|
||||
fprintf (stderr, "PNG2PNM\n");
|
||||
fprintf (stderr, "Error: can not create file %s\n", argv[argi]);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "PNG2PNM\n");
|
||||
fprintf (stderr, "Error: too many parameters\n");
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
} /* end for */
|
||||
|
||||
#ifdef __TURBOC__
|
||||
/* set stdin/stdout if required to binary */
|
||||
if (fp_rd == stdin)
|
||||
{
|
||||
setmode (STDIN, O_BINARY);
|
||||
}
|
||||
if ((raw) && (fp_wr == stdout))
|
||||
{
|
||||
setmode (STDOUT, O_BINARY);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* call the conversion program itself */
|
||||
if (png2pnm (fp_rd, fp_wr, fp_al, raw, alpha) == FALSE)
|
||||
{
|
||||
fprintf (stderr, "PNG2PNM\n");
|
||||
fprintf (stderr, "Error: unsuccessful convertion of PNG-image\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* close input file */
|
||||
fclose (fp_rd);
|
||||
/* close output file */
|
||||
fclose (fp_wr);
|
||||
/* close alpha file */
|
||||
if (alpha)
|
||||
fclose (fp_al);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* usage
|
||||
*/
|
||||
|
||||
void usage()
|
||||
{
|
||||
fprintf (stderr, "PNG2PNM\n");
|
||||
fprintf (stderr, " by Willem van Schaik, 1999\n");
|
||||
#ifdef __TURBOC__
|
||||
fprintf (stderr, " for Turbo-C and Borland-C compilers\n");
|
||||
#else
|
||||
fprintf (stderr, " for Linux (and Unix) compilers\n");
|
||||
#endif
|
||||
fprintf (stderr, "Usage: png2pnm [options] <file>.png [<file>.pnm]\n");
|
||||
fprintf (stderr, " or: ... | png2pnm [options]\n");
|
||||
fprintf (stderr, "Options:\n");
|
||||
fprintf (stderr, " -r[aw] write pnm-file in binary format (P4/P5/P6) (default)\n");
|
||||
fprintf (stderr, " -n[oraw] write pnm-file in ascii format (P1/P2/P3)\n");
|
||||
fprintf (stderr, " -a[lpha] <file>.pgm write PNG alpha channel as pgm-file\n");
|
||||
fprintf (stderr, " -h | -? print this help-information\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* png2pnm
|
||||
*/
|
||||
|
||||
BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw, BOOL alpha)
|
||||
{
|
||||
png_struct *png_ptr = NULL;
|
||||
png_info *info_ptr = NULL;
|
||||
png_byte buf[8];
|
||||
png_byte *png_pixels = NULL;
|
||||
png_byte **row_pointers = NULL;
|
||||
png_byte *pix_ptr = NULL;
|
||||
png_uint_32 row_bytes;
|
||||
|
||||
png_uint_32 width;
|
||||
png_uint_32 height;
|
||||
int bit_depth;
|
||||
int channels;
|
||||
int color_type;
|
||||
int alpha_present;
|
||||
int row, col;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
/* read and check signature in PNG file */
|
||||
ret = fread (buf, 1, 8, png_file);
|
||||
if (ret != 8)
|
||||
return FALSE;
|
||||
|
||||
ret = png_check_sig (buf, 8);
|
||||
if (!ret)
|
||||
return FALSE;
|
||||
|
||||
/* create png and info structures */
|
||||
|
||||
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
|
||||
NULL, NULL, NULL);
|
||||
if (!png_ptr)
|
||||
return FALSE; /* out of memory */
|
||||
|
||||
info_ptr = png_create_info_struct (png_ptr);
|
||||
if (!info_ptr)
|
||||
{
|
||||
png_destroy_read_struct (&png_ptr, NULL, NULL);
|
||||
return FALSE; /* out of memory */
|
||||
}
|
||||
|
||||
if (setjmp (png_jmpbuf(png_ptr)))
|
||||
{
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* set up the input control for C streams */
|
||||
png_init_io (png_ptr, png_file);
|
||||
png_set_sig_bytes (png_ptr, 8); /* we already read the 8 signature bytes */
|
||||
|
||||
/* read the file information */
|
||||
png_read_info (png_ptr, info_ptr);
|
||||
|
||||
/* get size and bit-depth of the PNG-image */
|
||||
png_get_IHDR (png_ptr, info_ptr,
|
||||
&width, &height, &bit_depth, &color_type,
|
||||
NULL, NULL, NULL);
|
||||
|
||||
/* set-up the transformations */
|
||||
|
||||
/* transform paletted images into full-color rgb */
|
||||
if (color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
png_set_expand (png_ptr);
|
||||
/* expand images to bit-depth 8 (only applicable for grayscale images) */
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
|
||||
png_set_expand (png_ptr);
|
||||
/* transform transparency maps into full alpha-channel */
|
||||
if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
|
||||
png_set_expand (png_ptr);
|
||||
|
||||
#ifdef NJET
|
||||
/* downgrade 16-bit images to 8 bit */
|
||||
if (bit_depth == 16)
|
||||
png_set_strip_16 (png_ptr);
|
||||
/* transform grayscale images into full-color */
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY ||
|
||||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
png_set_gray_to_rgb (png_ptr);
|
||||
/* only if file has a file gamma, we do a correction */
|
||||
if (png_get_gAMA (png_ptr, info_ptr, &file_gamma))
|
||||
png_set_gamma (png_ptr, (double) 2.2, file_gamma);
|
||||
#endif
|
||||
|
||||
/* all transformations have been registered; now update info_ptr data,
|
||||
* get rowbytes and channels, and allocate image memory */
|
||||
|
||||
png_read_update_info (png_ptr, info_ptr);
|
||||
|
||||
/* get the new color-type and bit-depth (after expansion/stripping) */
|
||||
png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
|
||||
NULL, NULL, NULL);
|
||||
|
||||
/* check for 16-bit files */
|
||||
if (bit_depth == 16)
|
||||
{
|
||||
raw = FALSE;
|
||||
#ifdef __TURBOC__
|
||||
pnm_file->flags &= ~((unsigned) _F_BIN);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* calculate new number of channels and store alpha-presence */
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY)
|
||||
channels = 1;
|
||||
else if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
channels = 2;
|
||||
else if (color_type == PNG_COLOR_TYPE_RGB)
|
||||
channels = 3;
|
||||
else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
channels = 4;
|
||||
else
|
||||
channels = 0; /* should never happen */
|
||||
alpha_present = (channels - 1) % 2;
|
||||
|
||||
/* check if alpha is expected to be present in file */
|
||||
if (alpha && !alpha_present)
|
||||
{
|
||||
fprintf (stderr, "PNG2PNM\n");
|
||||
fprintf (stderr, "Error: PNG-file doesn't contain alpha channel\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/* row_bytes is the width x number of channels x (bit-depth / 8) */
|
||||
row_bytes = png_get_rowbytes (png_ptr, info_ptr);
|
||||
|
||||
if ((png_pixels = (png_byte *) malloc (row_bytes * height * sizeof (png_byte))) == NULL) {
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((row_pointers = (png_byte **) malloc (height * sizeof (png_bytep))) == NULL)
|
||||
{
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
free (png_pixels);
|
||||
png_pixels = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* set the individual row_pointers to point at the correct offsets */
|
||||
for (i = 0; i < (height); i++)
|
||||
row_pointers[i] = png_pixels + i * row_bytes;
|
||||
|
||||
/* now we can go ahead and just read the whole image */
|
||||
png_read_image (png_ptr, row_pointers);
|
||||
|
||||
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */
|
||||
png_read_end (png_ptr, info_ptr);
|
||||
|
||||
/* clean up after the read, and free any memory allocated - REQUIRED */
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp) NULL);
|
||||
|
||||
/* write header of PNM file */
|
||||
|
||||
if ((color_type == PNG_COLOR_TYPE_GRAY) ||
|
||||
(color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
|
||||
{
|
||||
fprintf (pnm_file, "%s\n", (raw) ? "P5" : "P2");
|
||||
fprintf (pnm_file, "%d %d\n", (int) width, (int) height);
|
||||
fprintf (pnm_file, "%ld\n", ((1L << (int) bit_depth) - 1L));
|
||||
}
|
||||
else if ((color_type == PNG_COLOR_TYPE_RGB) ||
|
||||
(color_type == PNG_COLOR_TYPE_RGB_ALPHA))
|
||||
{
|
||||
fprintf (pnm_file, "%s\n", (raw) ? "P6" : "P3");
|
||||
fprintf (pnm_file, "%d %d\n", (int) width, (int) height);
|
||||
fprintf (pnm_file, "%ld\n", ((1L << (int) bit_depth) - 1L));
|
||||
}
|
||||
|
||||
/* write header of PGM file with alpha channel */
|
||||
|
||||
if ((alpha) &&
|
||||
((color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ||
|
||||
(color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
|
||||
{
|
||||
fprintf (alpha_file, "%s\n", (raw) ? "P5" : "P2");
|
||||
fprintf (alpha_file, "%d %d\n", (int) width, (int) height);
|
||||
fprintf (alpha_file, "%ld\n", ((1L << (int) bit_depth) - 1L));
|
||||
}
|
||||
|
||||
/* write data to PNM file */
|
||||
pix_ptr = png_pixels;
|
||||
|
||||
for (row = 0; row < height; row++)
|
||||
{
|
||||
for (col = 0; col < width; col++)
|
||||
{
|
||||
for (i = 0; i < (channels - alpha_present); i++)
|
||||
{
|
||||
if (raw)
|
||||
fputc ((int) *pix_ptr++ , pnm_file);
|
||||
else
|
||||
if (bit_depth == 16)
|
||||
fprintf (pnm_file, "%ld ", ((long) *pix_ptr++ << 8) + (long) *pix_ptr++);
|
||||
else
|
||||
fprintf (pnm_file, "%ld ", (long) *pix_ptr++);
|
||||
}
|
||||
if (alpha_present)
|
||||
{
|
||||
if (!alpha)
|
||||
{
|
||||
pix_ptr++; /* alpha */
|
||||
if (bit_depth == 16)
|
||||
pix_ptr++;
|
||||
}
|
||||
else /* output alpha-channel as pgm file */
|
||||
{
|
||||
if (raw)
|
||||
fputc ((int) *pix_ptr++ , alpha_file);
|
||||
else
|
||||
if (bit_depth == 16)
|
||||
fprintf (alpha_file, "%ld ", ((long) *pix_ptr++ << 8) + (long) *pix_ptr++);
|
||||
else
|
||||
fprintf (alpha_file, "%ld ", (long) *pix_ptr++);
|
||||
}
|
||||
} /* if alpha_present */
|
||||
|
||||
if (!raw)
|
||||
if (col % 4 == 3)
|
||||
fprintf (pnm_file, "\n");
|
||||
} /* end for col */
|
||||
|
||||
if (!raw)
|
||||
if (col % 4 != 0)
|
||||
fprintf (pnm_file, "\n");
|
||||
} /* end for row */
|
||||
|
||||
if (row_pointers != (unsigned char**) NULL)
|
||||
free (row_pointers);
|
||||
if (png_pixels != (unsigned char*) NULL)
|
||||
free (png_pixels);
|
||||
|
||||
return TRUE;
|
||||
|
||||
} /* end of source */
|
||||
|
||||
41
contrib/pngminus/png2pnm.sh
Executable file
@@ -0,0 +1,41 @@
|
||||
# -- grayscale
|
||||
./png2pnm -noraw ../pngsuite/basn0g01.png basn0g01.pgm
|
||||
./png2pnm -noraw ../pngsuite/basn0g02.png basn0g02.pgm
|
||||
./png2pnm -noraw ../pngsuite/basn0g04.png basn0g04.pgm
|
||||
./png2pnm -noraw ../pngsuite/basn0g08.png basn0g08.pgm
|
||||
./png2pnm -noraw ../pngsuite/basn0g16.png basn0g16.pgm
|
||||
# -- full-color
|
||||
./png2pnm -noraw ../pngsuite/basn2c08.png basn2c08.ppm
|
||||
./png2pnm -noraw ../pngsuite/basn2c16.png basn2c16.ppm
|
||||
# -- palletted
|
||||
./png2pnm -noraw ../pngsuite/basn3p01.png basn3p01.ppm
|
||||
./png2pnm -noraw ../pngsuite/basn3p02.png basn3p02.ppm
|
||||
./png2pnm -noraw ../pngsuite/basn3p04.png basn3p04.ppm
|
||||
./png2pnm -noraw ../pngsuite/basn3p08.png basn3p08.ppm
|
||||
# -- gray with alpha-channel
|
||||
./png2pnm -noraw ../pngsuite/basn4a08.png basn4a08.pgm
|
||||
./png2pnm -noraw ../pngsuite/basn4a16.png basn4a16.pgm
|
||||
# -- color with alpha-channel
|
||||
./png2pnm -noraw -alpha basn6a08.pgm ../pngsuite/basn6a08.png basn6a08.ppm
|
||||
./png2pnm -noraw -alpha basn6a16.pgm ../pngsuite/basn6a16.png basn6a16.ppm
|
||||
# -- grayscale
|
||||
./png2pnm -raw ../pngsuite/basn0g01.png rawn0g01.pgm
|
||||
./png2pnm -raw ../pngsuite/basn0g02.png rawn0g02.pgm
|
||||
./png2pnm -raw ../pngsuite/basn0g04.png rawn0g04.pgm
|
||||
./png2pnm -raw ../pngsuite/basn0g08.png rawn0g08.pgm
|
||||
./png2pnm -raw ../pngsuite/basn0g16.png rawn0g16.pgm
|
||||
# -- full-color
|
||||
./png2pnm -raw ../pngsuite/basn2c08.png rawn2c08.ppm
|
||||
./png2pnm -raw ../pngsuite/basn2c16.png rawn2c16.ppm
|
||||
# -- palletted
|
||||
./png2pnm -raw ../pngsuite/basn3p01.png rawn3p01.ppm
|
||||
./png2pnm -raw ../pngsuite/basn3p02.png rawn3p02.ppm
|
||||
./png2pnm -raw ../pngsuite/basn3p04.png rawn3p04.ppm
|
||||
./png2pnm -raw ../pngsuite/basn3p08.png rawn3p08.ppm
|
||||
# -- gray with alpha-channel
|
||||
./png2pnm -raw ../pngsuite/basn4a08.png rawn4a08.pgm
|
||||
./png2pnm -raw ../pngsuite/basn4a16.png rawn4a16.pgm
|
||||
# -- color with alpha-channel
|
||||
./png2pnm -noraw -alpha rawn6a08.pgm ../pngsuite/basn6a08.png rawn6a08.ppm
|
||||
./png2pnm -noraw -alpha rawn6a16.pgm ../pngsuite/basn6a16.png rawn6a16.ppm
|
||||
|
||||
4
contrib/pngminus/pngminus.bat
Normal file
@@ -0,0 +1,4 @@
|
||||
make -f makefile.tc3
|
||||
call png2pnm.bat
|
||||
call pnm2png.bat
|
||||
|
||||
4
contrib/pngminus/pngminus.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
make -f makefile.std
|
||||
sh png2pnm.sh
|
||||
sh pnm2png.sh
|
||||
|
||||
41
contrib/pngminus/pnm2png.bat
Normal file
@@ -0,0 +1,41 @@
|
||||
REM -- grayscale
|
||||
pnm2png.exe basn0g01.pgm basn0g01.png
|
||||
pnm2png.exe basn0g02.pgm basn0g02.png
|
||||
pnm2png.exe basn0g04.pgm basn0g04.png
|
||||
pnm2png.exe basn0g08.pgm basn0g08.png
|
||||
pnm2png.exe basn0g16.pgm basn0g16.png
|
||||
REM -- full-color
|
||||
pnm2png.exe basn2c08.ppm basn2c08.png
|
||||
pnm2png.exe basn2c16.ppm basn2c16.png
|
||||
REM -- palletted
|
||||
pnm2png.exe basn3p01.ppm basn3p01.png
|
||||
pnm2png.exe basn3p02.ppm basn3p02.png
|
||||
pnm2png.exe basn3p04.ppm basn3p04.png
|
||||
pnm2png.exe basn3p08.ppm basn3p08.png
|
||||
REM -- gray with alpha-channel
|
||||
pnm2png.exe -alpha basn6a08.pgm basn4a08.pgm basn4a08.png
|
||||
pnm2png.exe -alpha basn6a16.pgm basn4a16.pgm basn4a16.png
|
||||
REM -- color with alpha-channel
|
||||
pnm2png.exe -alpha basn6a08.pgm basn6a08.ppm basn6a08.png
|
||||
pnm2png.exe -alpha basn6a16.pgm basn6a16.ppm basn6a16.png
|
||||
REM -- grayscale
|
||||
pnm2png.exe rawn0g01.pgm rawn0g01.png
|
||||
pnm2png.exe rawn0g02.pgm rawn0g02.png
|
||||
pnm2png.exe rawn0g04.pgm rawn0g04.png
|
||||
pnm2png.exe rawn0g08.pgm rawn0g08.png
|
||||
pnm2png.exe rawn0g16.pgm rawn0g16.png
|
||||
REM -- full-color
|
||||
pnm2png.exe rawn2c08.ppm rawn2c08.png
|
||||
pnm2png.exe rawn2c16.ppm rawn2c16.png
|
||||
REM -- palletted
|
||||
pnm2png.exe rawn3p01.ppm rawn3p01.png
|
||||
pnm2png.exe rawn3p02.ppm rawn3p02.png
|
||||
pnm2png.exe rawn3p04.ppm rawn3p04.png
|
||||
pnm2png.exe rawn3p08.ppm rawn3p08.png
|
||||
REM -- gray with alpha-channel
|
||||
pnm2png.exe -alpha rawn6a08.pgm rawn4a08.pgm rawn4a08.png
|
||||
pnm2png.exe -alpha rawn6a16.pgm rawn4a16.pgm rawn4a16.png
|
||||
REM -- color with alpha-channel
|
||||
pnm2png.exe -alpha rawn6a08.pgm rawn6a08.ppm rawn6a08.png
|
||||
pnm2png.exe -alpha rawn6a16.pgm rawn6a16.ppm rawn6a16.png
|
||||
|
||||
533
contrib/pngminus/pnm2png.c
Normal file
@@ -0,0 +1,533 @@
|
||||
/*
|
||||
* pnm2png.c --- conversion from PBM/PGM/PPM-file to PNG-file
|
||||
* copyright (C) 1999 by Willem van Schaik <willem@schaik.com>
|
||||
*
|
||||
* version 1.0 - 1999.10.15 - First version.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and
|
||||
* its documentation for any purpose and without fee is hereby granted,
|
||||
* provided that the above copyright notice appear in all copies and
|
||||
* that both that copyright notice and this permission notice appear in
|
||||
* supporting documentation. This software is provided "as is" without
|
||||
* express or implied warranty.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef __TURBOC__
|
||||
#include <mem.h>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#ifndef BOOL
|
||||
#define BOOL unsigned char
|
||||
#endif
|
||||
#ifndef TRUE
|
||||
#define TRUE (BOOL) 1
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
#define FALSE (BOOL) 0
|
||||
#endif
|
||||
|
||||
#define STDIN 0
|
||||
#define STDOUT 1
|
||||
#define STDERR 2
|
||||
|
||||
/* to make pnm2png verbose so we can find problems (needs to be before png.h) */
|
||||
#ifndef PNG_DEBUG
|
||||
#define PNG_DEBUG 0
|
||||
#endif
|
||||
|
||||
#include "png.h"
|
||||
|
||||
/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
|
||||
#ifndef png_jmpbuf
|
||||
# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
|
||||
#endif
|
||||
|
||||
/* function prototypes */
|
||||
|
||||
int main (int argc, char *argv[]);
|
||||
void usage ();
|
||||
BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, BOOL alpha);
|
||||
void get_token(FILE *pnm_file, char *token);
|
||||
png_uint_32 get_data (FILE *pnm_file, int depth);
|
||||
png_uint_32 get_value (FILE *pnm_file, int depth);
|
||||
|
||||
/*
|
||||
* main
|
||||
*/
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *fp_rd = stdin;
|
||||
FILE *fp_al = NULL;
|
||||
FILE *fp_wr = stdout;
|
||||
BOOL interlace = FALSE;
|
||||
BOOL alpha = FALSE;
|
||||
int argi;
|
||||
|
||||
for (argi = 1; argi < argc; argi++)
|
||||
{
|
||||
if (argv[argi][0] == '-')
|
||||
{
|
||||
switch (argv[argi][1])
|
||||
{
|
||||
case 'i':
|
||||
interlace = TRUE;
|
||||
break;
|
||||
case 'a':
|
||||
alpha = TRUE;
|
||||
argi++;
|
||||
if ((fp_al = fopen (argv[argi], "rb")) == NULL)
|
||||
{
|
||||
fprintf (stderr, "PNM2PNG\n");
|
||||
fprintf (stderr, "Error: alpha-channel file %s does not exist\n",
|
||||
argv[argi]);
|
||||
exit (1);
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
usage();
|
||||
exit(0);
|
||||
break;
|
||||
default:
|
||||
fprintf (stderr, "PNM2PNG\n");
|
||||
fprintf (stderr, "Error: unknown option %s\n", argv[argi]);
|
||||
usage();
|
||||
exit(1);
|
||||
break;
|
||||
} /* end switch */
|
||||
}
|
||||
else if (fp_rd == stdin)
|
||||
{
|
||||
if ((fp_rd = fopen (argv[argi], "rb")) == NULL)
|
||||
{
|
||||
fprintf (stderr, "PNM2PNG\n");
|
||||
fprintf (stderr, "Error: file %s does not exist\n", argv[argi]);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
else if (fp_wr == stdout)
|
||||
{
|
||||
if ((fp_wr = fopen (argv[argi], "wb")) == NULL)
|
||||
{
|
||||
fprintf (stderr, "PNM2PNG\n");
|
||||
fprintf (stderr, "Error: can not create PNG-file %s\n", argv[argi]);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "PNM2PNG\n");
|
||||
fprintf (stderr, "Error: too many parameters\n");
|
||||
usage();
|
||||
exit (1);
|
||||
}
|
||||
} /* end for */
|
||||
|
||||
#ifdef __TURBOC__
|
||||
/* set stdin/stdout to binary, we're reading the PNM always! in binary format */
|
||||
if (fp_rd == stdin)
|
||||
{
|
||||
setmode (STDIN, O_BINARY);
|
||||
}
|
||||
if (fp_wr == stdout)
|
||||
{
|
||||
setmode (STDOUT, O_BINARY);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* call the conversion program itself */
|
||||
if (pnm2png (fp_rd, fp_wr, fp_al, interlace, alpha) == FALSE)
|
||||
{
|
||||
fprintf (stderr, "PNM2PNG\n");
|
||||
fprintf (stderr, "Error: unsuccessful converting to PNG-image\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/* close input file */
|
||||
fclose (fp_rd);
|
||||
/* close output file */
|
||||
fclose (fp_wr);
|
||||
/* close alpha file */
|
||||
if (alpha)
|
||||
fclose (fp_al);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* usage
|
||||
*/
|
||||
|
||||
void usage()
|
||||
{
|
||||
fprintf (stderr, "PNM2PNG\n");
|
||||
fprintf (stderr, " by Willem van Schaik, 1999\n");
|
||||
#ifdef __TURBOC__
|
||||
fprintf (stderr, " for Turbo-C and Borland-C compilers\n");
|
||||
#else
|
||||
fprintf (stderr, " for Linux (and Unix) compilers\n");
|
||||
#endif
|
||||
fprintf (stderr, "Usage: pnm2png [options] <file>.<pnm> [<file>.png]\n");
|
||||
fprintf (stderr, " or: ... | pnm2png [options]\n");
|
||||
fprintf (stderr, "Options:\n");
|
||||
fprintf (stderr, " -i[nterlace] write png-file with interlacing on\n");
|
||||
fprintf (stderr, " -a[lpha] <file>.pgm read PNG alpha channel as pgm-file\n");
|
||||
fprintf (stderr, " -h | -? print this help-information\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* pnm2png
|
||||
*/
|
||||
|
||||
BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, BOOL alpha)
|
||||
{
|
||||
png_struct *png_ptr = NULL;
|
||||
png_info *info_ptr = NULL;
|
||||
png_byte *png_pixels = NULL;
|
||||
png_byte **row_pointers = NULL;
|
||||
png_byte *pix_ptr = NULL;
|
||||
png_uint_32 row_bytes;
|
||||
|
||||
char type_token[16];
|
||||
char width_token[16];
|
||||
char height_token[16];
|
||||
char maxval_token[16];
|
||||
int color_type;
|
||||
png_uint_32 width, alpha_width;
|
||||
png_uint_32 height, alpha_height;
|
||||
png_uint_32 maxval;
|
||||
int bit_depth = 0;
|
||||
int channels;
|
||||
int alpha_depth = 0;
|
||||
int alpha_present;
|
||||
int row, col;
|
||||
BOOL raw, alpha_raw = FALSE;
|
||||
png_uint_32 tmp16;
|
||||
int i;
|
||||
|
||||
/* read header of PNM file */
|
||||
|
||||
get_token(pnm_file, type_token);
|
||||
if (type_token[0] != 'P')
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
else if ((type_token[1] == '1') || (type_token[1] == '4'))
|
||||
{
|
||||
raw = (type_token[1] == '4');
|
||||
color_type = PNG_COLOR_TYPE_GRAY;
|
||||
bit_depth = 1;
|
||||
}
|
||||
else if ((type_token[1] == '2') || (type_token[1] == '5'))
|
||||
{
|
||||
raw = (type_token[1] == '5');
|
||||
color_type = PNG_COLOR_TYPE_GRAY;
|
||||
get_token(pnm_file, width_token);
|
||||
sscanf (width_token, "%lu", &width);
|
||||
get_token(pnm_file, height_token);
|
||||
sscanf (height_token, "%lu", &height);
|
||||
get_token(pnm_file, maxval_token);
|
||||
sscanf (maxval_token, "%lu", &maxval);
|
||||
if (maxval <= 1)
|
||||
bit_depth = 1;
|
||||
else if (maxval <= 3)
|
||||
bit_depth = 2;
|
||||
else if (maxval <= 15)
|
||||
bit_depth = 4;
|
||||
else if (maxval <= 255)
|
||||
bit_depth = 8;
|
||||
else /* if (maxval <= 65535) */
|
||||
bit_depth = 16;
|
||||
}
|
||||
else if ((type_token[1] == '3') || (type_token[1] == '6'))
|
||||
{
|
||||
raw = (type_token[1] == '6');
|
||||
color_type = PNG_COLOR_TYPE_RGB;
|
||||
get_token(pnm_file, width_token);
|
||||
sscanf (width_token, "%lu", &width);
|
||||
get_token(pnm_file, height_token);
|
||||
sscanf (height_token, "%lu", &height);
|
||||
get_token(pnm_file, maxval_token);
|
||||
sscanf (maxval_token, "%lu", &maxval);
|
||||
if (maxval <= 1)
|
||||
bit_depth = 1;
|
||||
else if (maxval <= 3)
|
||||
bit_depth = 2;
|
||||
else if (maxval <= 15)
|
||||
bit_depth = 4;
|
||||
else if (maxval <= 255)
|
||||
bit_depth = 8;
|
||||
else /* if (maxval <= 65535) */
|
||||
bit_depth = 16;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* read header of PGM file with alpha channel */
|
||||
|
||||
if (alpha)
|
||||
{
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY)
|
||||
color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
|
||||
if (color_type == PNG_COLOR_TYPE_RGB)
|
||||
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||
|
||||
get_token(alpha_file, type_token);
|
||||
if (type_token[0] != 'P')
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
else if ((type_token[1] == '2') || (type_token[1] == '5'))
|
||||
{
|
||||
alpha_raw = (type_token[1] == '5');
|
||||
get_token(alpha_file, width_token);
|
||||
sscanf (width_token, "%lu", &alpha_width);
|
||||
if (alpha_width != width)
|
||||
return FALSE;
|
||||
get_token(alpha_file, height_token);
|
||||
sscanf (height_token, "%lu", &alpha_height);
|
||||
if (alpha_height != height)
|
||||
return FALSE;
|
||||
get_token(alpha_file, maxval_token);
|
||||
sscanf (maxval_token, "%lu", &maxval);
|
||||
if (maxval <= 1)
|
||||
alpha_depth = 1;
|
||||
else if (maxval <= 3)
|
||||
alpha_depth = 2;
|
||||
else if (maxval <= 15)
|
||||
alpha_depth = 4;
|
||||
else if (maxval <= 255)
|
||||
alpha_depth = 8;
|
||||
else /* if (maxval <= 65535) */
|
||||
alpha_depth = 16;
|
||||
if (alpha_depth != bit_depth)
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
} /* end if alpha */
|
||||
|
||||
/* calculate the number of channels and store alpha-presence */
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY)
|
||||
channels = 1;
|
||||
else if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
channels = 2;
|
||||
else if (color_type == PNG_COLOR_TYPE_RGB)
|
||||
channels = 3;
|
||||
else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
channels = 4;
|
||||
else
|
||||
channels = 0; /* should not happen */
|
||||
|
||||
alpha_present = (channels - 1) % 2;
|
||||
|
||||
/* row_bytes is the width x number of channels x (bit-depth / 8) */
|
||||
row_bytes = width * channels * ((bit_depth <= 8) ? 1 : 2);
|
||||
|
||||
if ((png_pixels = (png_byte *) malloc (row_bytes * height * sizeof (png_byte))) == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* read data from PNM file */
|
||||
pix_ptr = png_pixels;
|
||||
|
||||
for (row = 0; row < height; row++)
|
||||
{
|
||||
for (col = 0; col < width; col++)
|
||||
{
|
||||
for (i = 0; i < (channels - alpha_present); i++)
|
||||
{
|
||||
if (raw)
|
||||
*pix_ptr++ = get_data (pnm_file, bit_depth);
|
||||
else
|
||||
if (bit_depth <= 8)
|
||||
*pix_ptr++ = get_value (pnm_file, bit_depth);
|
||||
else
|
||||
{
|
||||
tmp16 = get_value (pnm_file, bit_depth);
|
||||
*pix_ptr = (png_byte) ((tmp16 >> 8) & 0xFF);
|
||||
pix_ptr++;
|
||||
*pix_ptr = (png_byte) (tmp16 & 0xFF);
|
||||
pix_ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
if (alpha) /* read alpha-channel from pgm file */
|
||||
{
|
||||
if (alpha_raw)
|
||||
*pix_ptr++ = get_data (alpha_file, alpha_depth);
|
||||
else
|
||||
if (alpha_depth <= 8)
|
||||
*pix_ptr++ = get_value (alpha_file, bit_depth);
|
||||
else
|
||||
{
|
||||
tmp16 = get_value (alpha_file, bit_depth);
|
||||
*pix_ptr++ = (png_byte) ((tmp16 >> 8) & 0xFF);
|
||||
*pix_ptr++ = (png_byte) (tmp16 & 0xFF);
|
||||
}
|
||||
} /* if alpha */
|
||||
|
||||
} /* end for col */
|
||||
} /* end for row */
|
||||
|
||||
/* prepare the standard PNG structures */
|
||||
png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (!png_ptr)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
info_ptr = png_create_info_struct (png_ptr);
|
||||
if (!info_ptr)
|
||||
{
|
||||
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* setjmp() must be called in every function that calls a PNG-reading libpng function */
|
||||
if (setjmp (png_jmpbuf(png_ptr)))
|
||||
{
|
||||
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* initialize the png structure */
|
||||
png_init_io (png_ptr, png_file);
|
||||
|
||||
/* we're going to write more or less the same PNG as the input file */
|
||||
png_set_IHDR (png_ptr, info_ptr, width, height, bit_depth, color_type,
|
||||
(!interlace) ? PNG_INTERLACE_NONE : PNG_INTERLACE_ADAM7,
|
||||
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
|
||||
/* write the file header information */
|
||||
png_write_info (png_ptr, info_ptr);
|
||||
|
||||
/* if needed we will allocate memory for an new array of row-pointers */
|
||||
if (row_pointers == (unsigned char**) NULL)
|
||||
{
|
||||
if ((row_pointers = (png_byte **) malloc (height * sizeof (png_bytep))) == NULL)
|
||||
{
|
||||
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* set the individual row_pointers to point at the correct offsets */
|
||||
for (i = 0; i < (height); i++)
|
||||
row_pointers[i] = png_pixels + i * row_bytes;
|
||||
|
||||
/* write out the entire image data in one call */
|
||||
png_write_image (png_ptr, row_pointers);
|
||||
|
||||
/* write the additional chuncks to the PNG file (not really needed) */
|
||||
png_write_end (png_ptr, info_ptr);
|
||||
|
||||
/* clean up after the write, and free any memory allocated */
|
||||
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
|
||||
|
||||
if (row_pointers != (unsigned char**) NULL)
|
||||
free (row_pointers);
|
||||
if (png_pixels != (unsigned char*) NULL)
|
||||
free (png_pixels);
|
||||
|
||||
return TRUE;
|
||||
} /* end of pnm2png */
|
||||
|
||||
/*
|
||||
* get_token() - gets the first string after whitespace
|
||||
*/
|
||||
|
||||
void get_token(FILE *pnm_file, char *token)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
/* remove white-space */
|
||||
do
|
||||
{
|
||||
token[i] = (unsigned char) fgetc (pnm_file);
|
||||
}
|
||||
while ((token[i] == '\n') || (token[i] == '\r') || (token[i] == ' '));
|
||||
|
||||
/* read string */
|
||||
do
|
||||
{
|
||||
i++;
|
||||
token[i] = (unsigned char) fgetc (pnm_file);
|
||||
}
|
||||
while ((token[i] != '\n') && (token[i] != '\r') && (token[i] != ' '));
|
||||
|
||||
token[i] = '\0';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* get_data() - takes first byte and converts into next pixel value,
|
||||
* taking as much bits as defined by bit-depth and
|
||||
* using the bit-depth to fill up a byte (0Ah -> AAh)
|
||||
*/
|
||||
|
||||
png_uint_32 get_data (FILE *pnm_file, int depth)
|
||||
{
|
||||
static int bits_left = 0;
|
||||
static int old_value = 0;
|
||||
static int mask = 0;
|
||||
int i;
|
||||
png_uint_32 ret_value;
|
||||
|
||||
if (mask == 0)
|
||||
for (i = 0; i < depth; i++)
|
||||
mask = (mask >> 1) | 0x80;
|
||||
|
||||
if (bits_left <= 0)
|
||||
{
|
||||
old_value = fgetc (pnm_file);
|
||||
bits_left = 8;
|
||||
}
|
||||
|
||||
ret_value = old_value & mask;
|
||||
for (i = 1; i < (8 / depth); i++)
|
||||
ret_value = ret_value || (ret_value >> depth);
|
||||
|
||||
old_value = (old_value << depth) & 0xFF;
|
||||
bits_left -= depth;
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
/*
|
||||
* get_value() - takes first (numeric) string and converts into number,
|
||||
* using the bit-depth to fill up a byte (0Ah -> AAh)
|
||||
*/
|
||||
|
||||
png_uint_32 get_value (FILE *pnm_file, int depth)
|
||||
{
|
||||
static png_uint_32 mask = 0;
|
||||
png_byte token[16];
|
||||
png_uint_32 ret_value;
|
||||
int i = 0;
|
||||
|
||||
if (mask == 0)
|
||||
for (i = 0; i < depth; i++)
|
||||
mask = (mask << 1) | 0x01;
|
||||
|
||||
get_token (pnm_file, (char *) token);
|
||||
sscanf ((const char *) token, "%lu", &ret_value);
|
||||
|
||||
ret_value &= mask;
|
||||
|
||||
if (depth < 8)
|
||||
for (i = 0; i < (8 / depth); i++)
|
||||
ret_value = (ret_value << depth) || ret_value;
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
/* end of source */
|
||||
|
||||
41
contrib/pngminus/pnm2png.sh
Executable file
@@ -0,0 +1,41 @@
|
||||
# -- grayscale
|
||||
./pnm2png basn0g01.pgm basn0g01.png
|
||||
./pnm2png basn0g02.pgm basn0g02.png
|
||||
./pnm2png basn0g04.pgm basn0g04.png
|
||||
./pnm2png basn0g08.pgm basn0g08.png
|
||||
./pnm2png basn0g16.pgm basn0g16.png
|
||||
# -- full-color
|
||||
./pnm2png basn2c08.ppm basn2c08.png
|
||||
./pnm2png basn2c16.ppm basn2c16.png
|
||||
# -- palletted
|
||||
./pnm2png basn3p01.ppm basn3p01.png
|
||||
./pnm2png basn3p02.ppm basn3p02.png
|
||||
./pnm2png basn3p04.ppm basn3p04.png
|
||||
./pnm2png basn3p08.ppm basn3p08.png
|
||||
# -- gray with alpha-channel
|
||||
./pnm2png -alpha basn6a08.pgm basn4a08.pgm basn4a08.png
|
||||
./pnm2png -alpha basn6a16.pgm basn4a16.pgm basn4a16.png
|
||||
# -- color with alpha-channel
|
||||
./pnm2png -alpha basn6a08.pgm basn6a08.ppm basn6a08.png
|
||||
./pnm2png -alpha basn6a16.pgm basn6a16.ppm basn6a16.png
|
||||
# -- grayscale
|
||||
./pnm2png rawn0g01.pgm rawn0g01.png
|
||||
./pnm2png rawn0g02.pgm rawn0g02.png
|
||||
./pnm2png rawn0g04.pgm rawn0g04.png
|
||||
./pnm2png rawn0g08.pgm rawn0g08.png
|
||||
./pnm2png rawn0g16.pgm rawn0g16.png
|
||||
# -- full-color
|
||||
./pnm2png rawn2c08.ppm rawn2c08.png
|
||||
./pnm2png rawn2c16.ppm rawn2c16.png
|
||||
# -- palletted
|
||||
./pnm2png rawn3p01.ppm rawn3p01.png
|
||||
./pnm2png rawn3p02.ppm rawn3p02.png
|
||||
./pnm2png rawn3p04.ppm rawn3p04.png
|
||||
./pnm2png rawn3p08.ppm rawn3p08.png
|
||||
# -- gray with alpha-channel
|
||||
./pnm2png -alpha rawn6a08.pgm rawn4a08.pgm rawn4a08.png
|
||||
./pnm2png -alpha rawn6a16.pgm rawn4a16.pgm rawn4a16.png
|
||||
# -- color with alpha-channel
|
||||
./pnm2png -alpha rawn6a08.pgm rawn6a08.ppm rawn6a08.png
|
||||
./pnm2png -alpha rawn6a16.pgm rawn6a16.ppm rawn6a16.png
|
||||
|
||||
85
contrib/pngsuite/README
Normal file
@@ -0,0 +1,85 @@
|
||||
|
||||
pngsuite
|
||||
--------
|
||||
(c) Willem van Schaik, 1999
|
||||
|
||||
Permission to use, copy, and distribute these images for any purpose and
|
||||
without fee is hereby granted.
|
||||
|
||||
These 15 images are part of the much larger PngSuite test-set of
|
||||
images, available for developers of PNG supporting software. The
|
||||
complete set, available at http:/www.schaik.com/pngsuite/, contains
|
||||
a variety of images to test interlacing, gamma settings, ancillary
|
||||
chunks, etc.
|
||||
|
||||
The images in this directory represent the basic PNG color-types:
|
||||
grayscale (1-16 bit deep), full color (8 or 16 bit), paletted
|
||||
(1-8 bit) and grayscale or color images with alpha channel. You
|
||||
can use them to test the proper functioning of PNG software.
|
||||
|
||||
filename depth type
|
||||
------------ ------ --------------
|
||||
basn0g01.png 1-bit grayscale
|
||||
basn0g02.png 2-bit grayscale
|
||||
basn0g04.png 4-bit grayscale
|
||||
basn0g08.png 8-bit grayscale
|
||||
basn0g16.png 16-bit grayscale
|
||||
basn2c08.png 8-bit truecolor
|
||||
basn2c16.png 16-bit truecolor
|
||||
basn3p01.png 1-bit paletted
|
||||
basn3p02.png 2-bit paletted
|
||||
basn3p04.png 4-bit paletted
|
||||
basn3p08.png 8-bit paletted
|
||||
basn4a08.png 8-bit gray with alpha
|
||||
basn4a16.png 16-bit gray with alpha
|
||||
basn6a08.png 8-bit RGBA
|
||||
basn6a16.png 16-bit RGBA
|
||||
|
||||
Here is the correct result of typing "pngtest -m *.png" in
|
||||
this directory:
|
||||
|
||||
Testing basn0g01.png: PASS (524 zero samples)
|
||||
Filter 0 was used 32 times
|
||||
Testing basn0g02.png: PASS (448 zero samples)
|
||||
Filter 0 was used 32 times
|
||||
Testing basn0g04.png: PASS (520 zero samples)
|
||||
Filter 0 was used 32 times
|
||||
Testing basn0g08.png: PASS (3 zero samples)
|
||||
Filter 1 was used 9 times
|
||||
Filter 4 was used 23 times
|
||||
Testing basn0g16.png: PASS (1 zero samples)
|
||||
Filter 1 was used 1 times
|
||||
Filter 2 was used 31 times
|
||||
Testing basn2c08.png: PASS (6 zero samples)
|
||||
Filter 1 was used 5 times
|
||||
Filter 4 was used 27 times
|
||||
Testing basn2c16.png: PASS (592 zero samples)
|
||||
Filter 1 was used 1 times
|
||||
Filter 4 was used 31 times
|
||||
Testing basn3p01.png: PASS (512 zero samples)
|
||||
Filter 0 was used 32 times
|
||||
Testing basn3p02.png: PASS (448 zero samples)
|
||||
Filter 0 was used 32 times
|
||||
Testing basn3p04.png: PASS (544 zero samples)
|
||||
Filter 0 was used 32 times
|
||||
Testing basn3p08.png: PASS (4 zero samples)
|
||||
Filter 0 was used 32 times
|
||||
Testing basn4a08.png: PASS (32 zero samples)
|
||||
Filter 1 was used 1 times
|
||||
Filter 4 was used 31 times
|
||||
Testing basn4a16.png: PASS (64 zero samples)
|
||||
Filter 0 was used 1 times
|
||||
Filter 1 was used 2 times
|
||||
Filter 2 was used 1 times
|
||||
Filter 4 was used 28 times
|
||||
Testing basn6a08.png: PASS (160 zero samples)
|
||||
Filter 1 was used 1 times
|
||||
Filter 4 was used 31 times
|
||||
Testing basn6a16.png: PASS (1072 zero samples)
|
||||
Filter 1 was used 4 times
|
||||
Filter 4 was used 28 times
|
||||
libpng passes test
|
||||
|
||||
Willem van Schaik
|
||||
<willem@schaik.com>
|
||||
October 1999
|
||||
BIN
contrib/pngsuite/basn0g01.png
Normal file
|
After Width: | Height: | Size: 164 B |
BIN
contrib/pngsuite/basn0g02.png
Normal file
|
After Width: | Height: | Size: 104 B |
BIN
contrib/pngsuite/basn0g04.png
Normal file
|
After Width: | Height: | Size: 145 B |
BIN
contrib/pngsuite/basn0g08.png
Normal file
|
After Width: | Height: | Size: 138 B |
BIN
contrib/pngsuite/basn0g16.png
Normal file
|
After Width: | Height: | Size: 167 B |
BIN
contrib/pngsuite/basn2c08.png
Normal file
|
After Width: | Height: | Size: 145 B |
BIN
contrib/pngsuite/basn2c16.png
Normal file
|
After Width: | Height: | Size: 302 B |
BIN
contrib/pngsuite/basn3p01.png
Normal file
|
After Width: | Height: | Size: 112 B |
BIN
contrib/pngsuite/basn3p02.png
Normal file
|
After Width: | Height: | Size: 146 B |
BIN
contrib/pngsuite/basn3p04.png
Normal file
|
After Width: | Height: | Size: 216 B |
BIN
contrib/pngsuite/basn3p08.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
contrib/pngsuite/basn4a08.png
Normal file
|
After Width: | Height: | Size: 126 B |
BIN
contrib/pngsuite/basn4a16.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
contrib/pngsuite/basn6a08.png
Normal file
|
After Width: | Height: | Size: 184 B |
BIN
contrib/pngsuite/basn6a16.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
112
example.c
@@ -1,20 +1,33 @@
|
||||
|
||||
#if 0 /* in case someone actually tries to compile this */
|
||||
|
||||
/* example.c - an example of using libpng */
|
||||
|
||||
/* This is an example of how to use libpng to read and write PNG files.
|
||||
* The file libpng.txt is much more verbose then this. If you have not
|
||||
* read it, do so first. This was designed to be a starting point of an
|
||||
* implementation. This is not officially part of libpng, and therefore
|
||||
* does not require a copyright notice.
|
||||
* implementation. This is not officially part of libpng, is hereby placed
|
||||
* in the public domain, and therefore does not require a copyright notice.
|
||||
*
|
||||
* This file does not currently compile, because it is missing certain
|
||||
* parts, like allocating memory to hold an image. You will have to
|
||||
* supply these parts to get it to compile. For an example of a minimal
|
||||
* working PNG reader/writer, see pngtest.c, included in this distribution.
|
||||
* working PNG reader/writer, see pngtest.c, included in this distribution;
|
||||
* see also the programs in the contrib directory.
|
||||
*/
|
||||
|
||||
#include "png.h"
|
||||
|
||||
/* The png_jmpbuf() macro, used in error handling, became available in
|
||||
* libpng version 1.0.6. If you want to be able to run your code with older
|
||||
* versions of libpng, you must define the macro yourself (but only if it
|
||||
* is not already defined by libpng!).
|
||||
*/
|
||||
|
||||
#ifndef png_jmpbuf
|
||||
# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
|
||||
#endif
|
||||
|
||||
/* Check to see if a file is a PNG file using png_sig_cmp(). png_sig_cmp()
|
||||
* returns zero if the image is a PNG and nonzero if it isn't a PNG.
|
||||
*
|
||||
@@ -41,7 +54,7 @@ int check_if_png(char *file_name, FILE **fp)
|
||||
char buf[PNG_BYTES_TO_CHECK];
|
||||
|
||||
/* Open the prospective PNG file. */
|
||||
if ((*fp = fopen(file_name, "rb")) != NULL);
|
||||
if ((*fp = fopen(file_name, "rb")) == NULL)
|
||||
return 0;
|
||||
|
||||
/* Read in some of the signature bytes */
|
||||
@@ -109,7 +122,8 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
||||
* the normal method of doing things with libpng). REQUIRED unless you
|
||||
* set up your own error handlers in the png_create_read_struct() earlier.
|
||||
*/
|
||||
if (setjmp(png_ptr->jmpbuf))
|
||||
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
{
|
||||
/* Free all of the memory associated with the png_ptr and info_ptr */
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
|
||||
@@ -134,6 +148,19 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
||||
/* If we have already read some of the signature */
|
||||
png_set_sig_bytes(png_ptr, sig_read);
|
||||
|
||||
#ifdef hilevel
|
||||
/*
|
||||
* If you have enough memory to read in the entire image at once,
|
||||
* and you need to specify only transforms that can be controlled
|
||||
* with one of the PNG_TRANSFORM_* bits (this presently excludes
|
||||
* dithering, filling, setting background, and doing gamma
|
||||
* adjustment), then you can read the entire image (including
|
||||
* pixels) into the info structure with this call:
|
||||
*/
|
||||
png_read_png(png_ptr, info_ptr, png_transforms, NULL);
|
||||
#else
|
||||
/* OK, you're doing it the hard way, with the lower-level functions */
|
||||
|
||||
/* The call to png_read_info() gives us all of the information from the
|
||||
* PNG file before the first IDAT (image data chunk). REQUIRED
|
||||
*/
|
||||
@@ -216,7 +243,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
||||
screen_gamma = 1.7 or 1.0; /* A good guess for Mac systems */
|
||||
}
|
||||
|
||||
/* Tell libpng to handle the gamma conversion for you. The second call
|
||||
/* Tell libpng to handle the gamma conversion for you. The final call
|
||||
* is a good guess for PC generated images, but it should be configurable
|
||||
* by the user at run time by the user. It is strongly suggested that
|
||||
* your application support gamma correction.
|
||||
@@ -225,7 +252,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
||||
int intent;
|
||||
|
||||
if (png_get_sRGB(png_ptr, info_ptr, &intent))
|
||||
png_set_sRGB(png_ptr, intent, 0);
|
||||
png_set_gamma(png_ptr, screen_gamma, 0.45455);
|
||||
else
|
||||
{
|
||||
double image_gamma;
|
||||
@@ -273,7 +300,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
||||
*/
|
||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
|
||||
{
|
||||
png_color8p sig_bit;
|
||||
png_color_8p sig_bit;
|
||||
|
||||
png_get_sBIT(png_ptr, info_ptr, &sig_bit);
|
||||
png_set_shift(png_ptr, sig_bit);
|
||||
@@ -348,6 +375,9 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
||||
|
||||
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */
|
||||
png_read_end(png_ptr, info_ptr);
|
||||
#endif hilevel
|
||||
|
||||
/* At this point you have read the entire image */
|
||||
|
||||
/* clean up after the read, and free any memory allocated - REQUIRED */
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
|
||||
@@ -387,7 +417,7 @@ initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (setjmp((*png_ptr)->jmpbuf))
|
||||
if (setjmp(png_jmpbuf((*png_ptr))))
|
||||
{
|
||||
png_destroy_read_struct(png_ptr, info_ptr, (png_infopp)NULL);
|
||||
return ERROR;
|
||||
@@ -415,7 +445,7 @@ int
|
||||
process_data(png_structp *png_ptr, png_infop *info_ptr,
|
||||
png_bytep buffer, png_uint_32 length)
|
||||
{
|
||||
if (setjmp((*png_ptr)->jmpbuf))
|
||||
if (setjmp(png_jmpbuf((*png_ptr))))
|
||||
{
|
||||
/* Free the png_ptr and info_ptr memory on error */
|
||||
png_destroy_read_struct(png_ptr, info_ptr, (png_infopp)NULL);
|
||||
@@ -497,6 +527,7 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
FILE *fp;
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
png_colorp palette;
|
||||
|
||||
/* open the file */
|
||||
fp = fopen(file_name, "wb");
|
||||
@@ -528,13 +559,13 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
}
|
||||
|
||||
/* Set error handling. REQUIRED if you aren't supplying your own
|
||||
* error hadnling functions in the png_create_write_struct() call.
|
||||
* error handling functions in the png_create_write_struct() call.
|
||||
*/
|
||||
if (setjmp(png_ptr->jmpbuf))
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
{
|
||||
/* If we get here, we had a problem reading the file */
|
||||
fclose(fp);
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp)info_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -550,6 +581,15 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
/* where user_io_ptr is a structure you want available to the callbacks */
|
||||
#endif no_streams /* only use one initialization method */
|
||||
|
||||
#ifdef hilevel
|
||||
/* This is the easy way. Use it if you already have all the
|
||||
* image info living info in the structure. You could "|" many
|
||||
* PNG_TRANSFORM flags into the png_transforms integer here.
|
||||
*/
|
||||
png_write_png(png_ptr, info_ptr, png_transforms, NULL);
|
||||
#else
|
||||
/* This is the hard way */
|
||||
|
||||
/* Set the image information here. Width and height are up to 2^31,
|
||||
* bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on
|
||||
* the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY,
|
||||
@@ -565,6 +605,9 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
palette = (png_colorp)png_malloc(png_ptr, 256 * sizeof (png_color));
|
||||
/* ... set palette colors ... */
|
||||
png_set_PLTE(png_ptr, info_ptr, palette, 256);
|
||||
/* You must not free palette here, because png_set_PLTE only makes a link to
|
||||
the palette that you malloced. Wait until you are about to destroy
|
||||
the png structure. */
|
||||
|
||||
/* optional significant bit chunk */
|
||||
/* if we are dealing with a grayscale image then */
|
||||
@@ -593,15 +636,31 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
text_ptr[2].key = "Description";
|
||||
text_ptr[2].text = "<long text>";
|
||||
text_ptr[2].compression = PNG_TEXT_COMPRESSION_zTXt;
|
||||
#ifdef PNG_iTXt_SUPPORTED
|
||||
text_ptr[0].lang = NULL;
|
||||
text_ptr[1].lang = NULL;
|
||||
text_ptr[2].lang = NULL;
|
||||
#endif
|
||||
png_set_text(png_ptr, info_ptr, text_ptr, 3);
|
||||
|
||||
/* other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs, */
|
||||
/* note that if sRGB is present the cHRM chunk must be ignored
|
||||
/* note that if sRGB is present the gAMA and cHRM chunks must be ignored
|
||||
* on read and must be written in accordance with the sRGB profile */
|
||||
|
||||
/* Write the file header information. REQUIRED */
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
|
||||
/* If you want, you can write the info in two steps, in case you need to
|
||||
* write your private chunk ahead of PLTE:
|
||||
*
|
||||
* png_write_info_before_PLTE(write_ptr, write_info_ptr);
|
||||
* write_my_chunk();
|
||||
* png_write_info(png_ptr, info_ptr);
|
||||
*
|
||||
* However, given the level of known- and unknown-chunk support in 1.1.0
|
||||
* and up, this should no longer be necessary.
|
||||
*/
|
||||
|
||||
/* Once we write out the header, the compression type on the text
|
||||
* chunks gets changed to PNG_TEXT_COMPRESSION_NONE_WR or
|
||||
* PNG_TEXT_COMPRESSION_zTXt_WR, so it doesn't get written out again
|
||||
@@ -651,10 +710,10 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
* use the first method if you aren't handling interlacing yourself.
|
||||
*/
|
||||
png_uint_32 k, height, width;
|
||||
png_byte image[height][width];
|
||||
png_byte image[height][width*bytes_per_pixel];
|
||||
png_bytep row_pointers[height];
|
||||
for (k = 0; k < height; k++)
|
||||
row_pointers[k] = image + k*width;
|
||||
row_pointers[k] = image + k*width*bytes_per_pixel;
|
||||
|
||||
/* One of the following output methods is REQUIRED */
|
||||
#ifdef entire /* write out the entire image data in one call */
|
||||
@@ -680,19 +739,29 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
#endif no_entire /* use only one output method */
|
||||
|
||||
/* You can write optional chunks like tEXt, zTXt, and tIME at the end
|
||||
* as well.
|
||||
* as well. Shouldn't be necessary in 1.1.0 and up as all the public
|
||||
* chunks are supported and you can use png_set_unknown_chunks() to
|
||||
* register unknown chunks into the info structure to be written out.
|
||||
*/
|
||||
|
||||
/* It is REQUIRED to call this to finish writing the rest of the file */
|
||||
png_write_end(png_ptr, info_ptr);
|
||||
#endif hilevel
|
||||
|
||||
/* if you malloced the palette, free it here */
|
||||
free(info_ptr->palette);
|
||||
/* If you png_malloced a palette, free it here (don't free info_ptr->palette,
|
||||
as recommended in versions 1.0.5m and earlier of this example; if
|
||||
libpng mallocs info_ptr->palette, libpng will free it). If you
|
||||
allocated it with malloc() instead of png_malloc(), use free() instead
|
||||
of png_free(). */
|
||||
png_free(png_ptr, palette);
|
||||
|
||||
/* if you allocated any text comments, free them here */
|
||||
/* Similarly, if you png_malloced any data that you passed in with
|
||||
png_set_something(), such as a hist or trans array, free it here,
|
||||
when you can be sure that libpng is through with it. */
|
||||
png_free(png_ptr, trans);
|
||||
|
||||
/* clean up after the write, and free any memory allocated */
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp)info_ptr);
|
||||
|
||||
/* close the file */
|
||||
fclose(fp);
|
||||
@@ -701,3 +770,4 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* if 0 */
|
||||
|
||||
718
libpng.txt
58
libpngpf.3
@@ -1,6 +1,6 @@
|
||||
.TH LIBPNGPF 3 October 6, 1999
|
||||
.TH LIBPNGPF 3 April 10, 2000
|
||||
.SH NAME
|
||||
libpng \- Portable Network Graphics (PNG) Reference Library 1.0.4d - October 6, 1999
|
||||
libpng \- Portable Network Graphics (PNG) Reference Library 1.0.6e
|
||||
(private functions)
|
||||
.SH SYNOPSIS
|
||||
\fB#include <png.h>\fP
|
||||
@@ -55,6 +55,10 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.0.4d - October 6,
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBpng_charp png_decompress_chunk (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIcomp_type\fP\fB, png_charp \fP\fIchunkdata\fP\fB, png_size_t \fP\fIchunklength\fP\fB, png_size_t \fP\fIprefix_length\fP\fB, png_size_t \fI*data_length\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_destroy_struct (png_voidp \fIstruct_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
@@ -187,6 +191,10 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.0.4d - October 6,
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBint png_handle_as_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_handle_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
@@ -211,6 +219,14 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.0.4d - October 6,
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_handle_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_handle_iTXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_handle_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
@@ -231,6 +247,14 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.0.4d - October 6,
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_handle_sCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_handle_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_handle_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
@@ -399,6 +423,10 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.0.4d - October 6,
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_cHRM_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIwhite_x\fP\fB, png_uint_32 \fP\fIwhite_y\fP\fB, png_uint_32 \fP\fIred_x\fP\fB, png_uint_32 \fP\fIred_y\fP\fB, png_uint_32 \fP\fIgreen_x\fP\fB, png_uint_32 \fP\fIgreen_y\fP\fB, png_uint_32 \fP\fIblue_x\fP\fB, png_uint_32 \fIblue_y\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
|
||||
|
||||
\fBvoid png_write_filtered_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIfiltered_row\fP\fB);\fP
|
||||
@@ -417,11 +445,15 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.0.4d - October 6,
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_gAMA_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIint_file_gamma\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_uint_16p \fP\fIhist\fP\fB, int \fInum_hist\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_init (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
\fBvoid png_write_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIname\fP\fB, int \fP\fIcompression_type\fP\fB, png_charp \fP\fIprofile\fP\fB, int \fIproflen\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
@@ -437,6 +469,14 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.0.4d - October 6,
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_init (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_iTXt (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIcompression\fP\fB, png_charp \fP\fIkey\fP\fB, png_charp \fP\fIlang\fP\fB, png_charp \fP\fItranslated_key\fP\fB, png_charp \fItext)\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIx_offset\fP\fB, png_uint_32 \fP\fIy_offset\fP\fB, int \fIunit_type\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
@@ -457,6 +497,14 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.0.4d - October 6,
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_sCAL (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIunit\fP\fB, double \fP\fIwidth\fP\fB, double \fIheight\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_sCAL_s (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIunit\fP\fB, png_charp \fP\fIwidth\fP\fB, png_charp \fIheight\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_sig (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
@@ -465,6 +513,10 @@ libpng \- Portable Network Graphics (PNG) Reference Library 1.0.4d - October 6,
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_spalette_p \fIpalette\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBvoid png_write_start_row (png_structp \fIpng_ptr\fP\fB);\fP
|
||||
|
||||
\fI\fB
|
||||
|
||||
8
png.5
@@ -1,4 +1,4 @@
|
||||
.TH PNG 5 "October 6, 1999"
|
||||
.TH PNG 5 "April 10, 2000"
|
||||
.SH NAME
|
||||
png \- Portable Network Graphics (PNG) format
|
||||
.SH DESCRIPTION
|
||||
@@ -20,10 +20,12 @@ platforms.
|
||||
.SH "SEE ALSO"
|
||||
.IR libpng(3), zlib(3), deflate(5), and zlib(5)
|
||||
.LP
|
||||
PNG 1.1 specification, January 1999:
|
||||
PNG 1.2 specification, July 1999:
|
||||
.IP
|
||||
.br
|
||||
http://www.cdrom.com/pub/png
|
||||
http://www.cdrom.com/pub/png (moving to http://www.libpng.org)
|
||||
.br
|
||||
or ftp://ftp.uu.net/graphics/png/documents
|
||||
.LP
|
||||
PNG 1.0 specification, October 1996:
|
||||
.IP
|
||||
|
||||
379
png.c
@@ -1,47 +1,54 @@
|
||||
|
||||
/* png.c - location for general purpose libpng functions
|
||||
*
|
||||
* libpng version 1.0.4d - October 6, 1999
|
||||
* libpng version 1.0.6e - April 10, 2000
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
*
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#define PNG_NO_EXTERN
|
||||
#include <assert.h>
|
||||
#include "png.h"
|
||||
|
||||
/* Generate a compiler error if there is an old png.h in the search path. */
|
||||
typedef version_1_0_6e Your_png_h_is_not_version_1_0_6e;
|
||||
|
||||
/* Version information for C files. This had better match the version
|
||||
* string defined in png.h.
|
||||
*/
|
||||
* string defined in png.h. */
|
||||
|
||||
char png_libpng_ver[12] = "1.0.4d";
|
||||
#ifdef PNG_USE_GLOBAL_ARRAYS
|
||||
/* png_libpng_ver was changed to a function in version 1.0.5c */
|
||||
char png_libpng_ver[12] = "1.0.6e";
|
||||
|
||||
/* png_sig was changed to a function in version 1.0.5c */
|
||||
/* Place to hold the signature string for a PNG file. */
|
||||
png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
|
||||
|
||||
/* Constant strings for known chunk types. If you need to add a chunk,
|
||||
* add a string holding the name here. If you want to make the code
|
||||
* portable to EBCDIC machines, use ASCII numbers, not characters.
|
||||
*/
|
||||
png_byte FARDATA png_IHDR[5] = { 73, 72, 68, 82, '\0'};
|
||||
png_byte FARDATA png_IDAT[5] = { 73, 68, 65, 84, '\0'};
|
||||
png_byte FARDATA png_IEND[5] = { 73, 69, 78, 68, '\0'};
|
||||
png_byte FARDATA png_PLTE[5] = { 80, 76, 84, 69, '\0'};
|
||||
png_byte FARDATA png_bKGD[5] = { 98, 75, 71, 68, '\0'};
|
||||
png_byte FARDATA png_cHRM[5] = { 99, 72, 82, 77, '\0'};
|
||||
png_byte FARDATA png_gAMA[5] = {103, 65, 77, 65, '\0'};
|
||||
png_byte FARDATA png_hIST[5] = {104, 73, 83, 84, '\0'};
|
||||
png_byte FARDATA png_oFFs[5] = {111, 70, 70, 115, '\0'};
|
||||
png_byte FARDATA png_pCAL[5] = {112, 67, 65, 76, '\0'};
|
||||
png_byte FARDATA png_pHYs[5] = {112, 72, 89, 115, '\0'};
|
||||
png_byte FARDATA png_sBIT[5] = {115, 66, 73, 84, '\0'};
|
||||
png_byte FARDATA png_sRGB[5] = {115, 82, 71, 66, '\0'};
|
||||
png_byte FARDATA png_tEXt[5] = {116, 69, 88, 116, '\0'};
|
||||
png_byte FARDATA png_tIME[5] = {116, 73, 77, 69, '\0'};
|
||||
png_byte FARDATA png_tRNS[5] = {116, 82, 78, 83, '\0'};
|
||||
png_byte FARDATA png_zTXt[5] = {122, 84, 88, 116, '\0'};
|
||||
/* Invoke global declarations for constant strings for known chunk types */
|
||||
PNG_IHDR;
|
||||
PNG_IDAT;
|
||||
PNG_IEND;
|
||||
PNG_PLTE;
|
||||
PNG_bKGD;
|
||||
PNG_cHRM;
|
||||
PNG_gAMA;
|
||||
PNG_hIST;
|
||||
PNG_iCCP;
|
||||
PNG_iTXt;
|
||||
PNG_oFFs;
|
||||
PNG_pCAL;
|
||||
PNG_sCAL;
|
||||
PNG_pHYs;
|
||||
PNG_sBIT;
|
||||
PNG_sPLT;
|
||||
PNG_sRGB;
|
||||
PNG_tEXt;
|
||||
PNG_tIME;
|
||||
PNG_tRNS;
|
||||
PNG_zTXt;
|
||||
|
||||
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
@@ -57,10 +64,10 @@ int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
|
||||
/* offset to next interlace block in the y direction */
|
||||
int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
|
||||
|
||||
/* Width of interlace block. This is not currently used - if you need
|
||||
* it, uncomment it here and in png.h
|
||||
/* width of interlace block (used in assembler routines only) */
|
||||
#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
|
||||
int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
|
||||
*/
|
||||
#endif
|
||||
|
||||
/* Height of interlace block. This is not currently used - if you need
|
||||
* it, uncomment it here and in png.h
|
||||
@@ -73,6 +80,8 @@ int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
|
||||
/* Mask to determine which pixels to overwrite while displaying */
|
||||
int FARDATA png_pass_dsp_mask[] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
|
||||
|
||||
#endif
|
||||
|
||||
/* Tells libpng that we have already handled the first "num_bytes" bytes
|
||||
* of the PNG file signature. If the PNG data is embedded into another
|
||||
* stream we can set num_bytes = 8 so that libpng will not attempt to read
|
||||
@@ -86,7 +95,7 @@ png_set_sig_bytes(png_structp png_ptr, int num_bytes)
|
||||
if (num_bytes > 8)
|
||||
png_error(png_ptr, "Too many bytes for PNG signature.");
|
||||
|
||||
png_ptr->sig_bytes = num_bytes < 0 ? 0 : num_bytes;
|
||||
png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
|
||||
}
|
||||
|
||||
/* Checks whether the supplied bytes match the PNG signature. We allow
|
||||
@@ -100,6 +109,7 @@ png_set_sig_bytes(png_structp png_ptr, int num_bytes)
|
||||
int
|
||||
png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
|
||||
{
|
||||
png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
|
||||
if (num_to_check > 8)
|
||||
num_to_check = 8;
|
||||
else if (num_to_check < 1)
|
||||
@@ -111,7 +121,7 @@ png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
|
||||
if (start + num_to_check > 8)
|
||||
num_to_check = 8 - start;
|
||||
|
||||
return ((int)(png_memcmp(&sig[start], &png_sig[start], num_to_check)));
|
||||
return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
|
||||
}
|
||||
|
||||
/* (Obsolete) function to check signature bytes. It does not allow one
|
||||
@@ -251,6 +261,209 @@ png_info_init(png_infop info_ptr)
|
||||
png_memset(info_ptr, 0, sizeof (png_info));
|
||||
}
|
||||
|
||||
void
|
||||
png_data_freer(png_structp png_ptr, png_infop info_ptr,
|
||||
int freer, png_uint_32 mask)
|
||||
{
|
||||
png_debug(1, "in png_data_freer\n");
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
if(freer == PNG_DESTROY_WILL_FREE_DATA)
|
||||
info_ptr->free_me |= mask;
|
||||
else if(freer == PNG_USER_WILL_FREE_DATA)
|
||||
info_ptr->free_me &= ~mask;
|
||||
else
|
||||
png_warning(png_ptr,
|
||||
"Unknown freer parameter in png_data_freer.");
|
||||
}
|
||||
|
||||
void
|
||||
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 */
|
||||
if (mask & info_ptr->free_me & PNG_FREE_TEXT)
|
||||
{
|
||||
if (num != -1)
|
||||
{
|
||||
if (info_ptr->text[num].key)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->text[num].key);
|
||||
info_ptr->text[num].key = NULL;
|
||||
}
|
||||
}
|
||||
else if (info_ptr->text != NULL)
|
||||
{
|
||||
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 */
|
||||
if (mask & PNG_FREE_TRNS)
|
||||
{
|
||||
if (info_ptr->valid & PNG_INFO_tRNS)
|
||||
{
|
||||
if (info_ptr->free_me & PNG_FREE_TRNS)
|
||||
png_free(png_ptr, info_ptr->trans);
|
||||
info_ptr->valid &= ~PNG_INFO_tRNS;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_sCAL_SUPPORTED)
|
||||
/* free any sCAL entry */
|
||||
{
|
||||
if (info_ptr->valid & PNG_INFO_sCAL)
|
||||
{
|
||||
#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);
|
||||
#endif
|
||||
info_ptr->valid &= ~PNG_INFO_sCAL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_pCAL_SUPPORTED)
|
||||
/* free any pCAL entry */
|
||||
{
|
||||
if (info_ptr->valid & PNG_INFO_pCAL)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->pcal_purpose);
|
||||
png_free(png_ptr, info_ptr->pcal_units);
|
||||
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]);
|
||||
}
|
||||
png_free(png_ptr, info_ptr->pcal_params);
|
||||
}
|
||||
info_ptr->valid &= ~PNG_INFO_pCAL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_iCCP_SUPPORTED)
|
||||
/* free any iCCP entry */
|
||||
if (mask & PNG_FREE_ICCP)
|
||||
{
|
||||
if (info_ptr->valid & PNG_INFO_iCCP)
|
||||
{
|
||||
if (info_ptr->free_me & PNG_FREE_ICCP)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->iccp_name);
|
||||
png_free(png_ptr, info_ptr->iccp_profile);
|
||||
}
|
||||
info_ptr->valid &= ~PNG_INFO_iCCP;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_sPLT_SUPPORTED)
|
||||
/* free a given sPLT entry, or (if num == -1) all sPLT entries */
|
||||
if (mask & PNG_FREE_SPLT)
|
||||
{
|
||||
if (num != -1)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->splt_palettes[num].name);
|
||||
png_free(png_ptr, info_ptr->splt_palettes[num].entries);
|
||||
info_ptr->valid &= ~PNG_INFO_sPLT;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(info_ptr->splt_palettes_num)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
|
||||
png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
|
||||
|
||||
png_free(png_ptr, info_ptr->splt_palettes);
|
||||
info_ptr->splt_palettes_num = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
if (mask & PNG_FREE_UNKN)
|
||||
{
|
||||
if (num != -1)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->unknown_chunks[num].data);
|
||||
info_ptr->unknown_chunks[num].data = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
|
||||
if(info_ptr->unknown_chunks_num)
|
||||
{
|
||||
for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
|
||||
png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
|
||||
|
||||
png_free(png_ptr, info_ptr->unknown_chunks);
|
||||
info_ptr->unknown_chunks_num = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_hIST_SUPPORTED)
|
||||
/* free any hIST entry */
|
||||
if (mask & PNG_FREE_HIST)
|
||||
{
|
||||
if (info_ptr->valid & PNG_INFO_hIST)
|
||||
{
|
||||
if (info_ptr->free_me & PNG_FREE_HIST)
|
||||
png_free(png_ptr, info_ptr->hist);
|
||||
info_ptr->valid &= ~PNG_INFO_hIST;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* free any PLTE entry that was internally allocated */
|
||||
if (mask & PNG_FREE_PLTE)
|
||||
{
|
||||
if (info_ptr->valid & PNG_INFO_PLTE)
|
||||
{
|
||||
if (info_ptr->free_me & PNG_FREE_PLTE)
|
||||
png_zfree(png_ptr, info_ptr->palette);
|
||||
info_ptr->valid &= ~(PNG_INFO_PLTE);
|
||||
info_ptr->num_palette = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(PNG_INFO_IMAGE_SUPPORTED)
|
||||
/* free any image bits attached to the info structure */
|
||||
if (mask & PNG_FREE_ROWS)
|
||||
{
|
||||
if (info_ptr->free_me & PNG_FREE_ROWS)
|
||||
{
|
||||
int row;
|
||||
|
||||
for (row = 0; row < (int)info_ptr->height; row++)
|
||||
png_free(png_ptr, info_ptr->row_pointers[row]);
|
||||
png_free(png_ptr, info_ptr->row_pointers);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if(num == -1)
|
||||
info_ptr->free_me &= ~mask;
|
||||
}
|
||||
|
||||
/* 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.
|
||||
@@ -258,29 +471,15 @@ png_info_init(png_infop info_ptr)
|
||||
void
|
||||
png_info_destroy(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
|
||||
png_debug(1, "in png_info_destroy\n");
|
||||
if (info_ptr->text != NULL)
|
||||
|
||||
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
|
||||
|
||||
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
if (png_ptr->num_chunk_list)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < info_ptr->num_text; i++)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->text[i].key);
|
||||
}
|
||||
png_free(png_ptr, info_ptr->text);
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED)
|
||||
png_free(png_ptr, info_ptr->pcal_purpose);
|
||||
png_free(png_ptr, info_ptr->pcal_units);
|
||||
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]);
|
||||
}
|
||||
png_free(png_ptr, info_ptr->pcal_params);
|
||||
png_free(png_ptr, png_ptr->chunk_list);
|
||||
png_ptr->num_chunk_list=0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -300,7 +499,9 @@ png_get_io_ptr(png_structp png_ptr)
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
/* Initialize the default input/output functions for the PNG file. If you
|
||||
* use your own read or write routines, you can call either png_set_read_fn()
|
||||
* or png_set_write_fn() instead of png_init_io().
|
||||
* or png_set_write_fn() instead of png_init_io(). If you have defined
|
||||
* PNG_NO_STDIO, you must use a function of your own because "FILE *" isn't
|
||||
* necessarily available.
|
||||
*/
|
||||
void
|
||||
png_init_io(png_structp png_ptr, FILE *fp)
|
||||
@@ -347,22 +548,72 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
|
||||
}
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
|
||||
#if 0
|
||||
/* Signature string for a PNG file. */
|
||||
png_bytep
|
||||
png_sig_bytes(void)
|
||||
{
|
||||
return ((png_bytep)"\211\120\116\107\015\012\032\012");
|
||||
}
|
||||
#endif
|
||||
|
||||
png_charp
|
||||
png_get_copyright(png_structp png_ptr)
|
||||
{
|
||||
if(png_ptr == NULL)
|
||||
/* silence compiler warning about unused png_ptr */ ;
|
||||
return("\n libpng version 1.0.4d - October 6, 1999\n\
|
||||
if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */
|
||||
return ("\n libpng version 1.0.6e - April 10, 2000\n\
|
||||
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n\
|
||||
Copyright (c) 1996, 1997 Andreas Dilger\n\
|
||||
Copyright (c) 1998, 1999 Glenn Randers-Pehrson\n");
|
||||
Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson\n");
|
||||
return ("");
|
||||
}
|
||||
|
||||
/* Generate a compiler error if there is an old png.h in the search path. */
|
||||
void
|
||||
png_check_version
|
||||
(version_1_0_4d png_h_is_not_version_1_0_4d)
|
||||
/* The following return the library version as a short string in the
|
||||
* format 1.0.0 through 99.99.99zz. To get the version of *.h files used
|
||||
* with your application, print out PNG_LIBPNG_VER_STRING, which is defined
|
||||
* in png.h.
|
||||
*/
|
||||
|
||||
png_charp
|
||||
png_get_libpng_ver(png_structp png_ptr)
|
||||
{
|
||||
if(png_h_is_not_version_1_0_4d == NULL)
|
||||
/* silence compiler warning about unused parameter */ ;
|
||||
/* Version of *.c files used when building libpng */
|
||||
if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
|
||||
return("1.0.6e");
|
||||
return("1.0.6e");
|
||||
}
|
||||
|
||||
png_charp
|
||||
png_get_header_ver(png_structp png_ptr)
|
||||
{
|
||||
/* Version of *.h files used when building libpng */
|
||||
if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
|
||||
return(PNG_LIBPNG_VER_STRING);
|
||||
return(PNG_LIBPNG_VER_STRING);
|
||||
}
|
||||
|
||||
png_charp
|
||||
png_get_header_version(png_structp png_ptr)
|
||||
{
|
||||
/* Returns longer string containing both version and date */
|
||||
if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
|
||||
return(PNG_HEADER_VERSION_STRING);
|
||||
return(PNG_HEADER_VERSION_STRING);
|
||||
}
|
||||
|
||||
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
||||
int
|
||||
png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
|
||||
{
|
||||
/* check chunk_name and return "keep" value if it's on the list, else 0 */
|
||||
int i;
|
||||
png_bytep p;
|
||||
if((png_ptr == NULL && chunk_name == NULL) || png_ptr->num_chunk_list<=0)
|
||||
return 0;
|
||||
p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
|
||||
for (i = png_ptr->num_chunk_list; i; i--, p-=5)
|
||||
if (!png_memcmp(chunk_name, p, 4))
|
||||
return ((int)*(p+4));
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
29
pngasmrd.h
@@ -1,32 +1,35 @@
|
||||
/* pngasmrd.h - assembler version of utilities to read a PNG file
|
||||
*
|
||||
* libpng 1.0.4d - October 6, 1999
|
||||
* libpng 1.0.6e - April 10, 2000
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1999 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1999, 2000 Glenn Randers-Pehrson
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
|
||||
|
||||
/* Set this in the makefile for VC++ on Pentium, not in pngconf.h */
|
||||
#ifdef PNG_USE_PNGVCRD
|
||||
/* Platform must be Pentium. Makefile must assemble and load pngvcrd.c .
|
||||
* MMX will be detected at run time and used if present.
|
||||
*/
|
||||
#define PNG_HAVE_ASSEMBLER_COMBINE_ROW
|
||||
#define PNG_HAVE_ASSEMBLER_READ_INTERLACE
|
||||
#define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
|
||||
#ifdef PNG_USE_PNGVCRD
|
||||
# define PNG_HAVE_ASSEMBLER_COMBINE_ROW
|
||||
# define PNG_HAVE_ASSEMBLER_READ_INTERLACE
|
||||
# define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
|
||||
#endif
|
||||
|
||||
/* Set this in the makefile for gcc on Pentium, not in pngconf.h */
|
||||
#ifdef PNG_USE_PNGGCCRD
|
||||
/* Platform must be Pentium. Makefile must assemble and load pnggccrd.c
|
||||
* (not available in libpng 1.0.4d).
|
||||
/* Set this in the makefile for gcc/as on Pentium, not in pngconf.h */
|
||||
/* Platform must be Pentium. Makefile must assemble and load pnggccrd.c .
|
||||
* MMX will be detected at run time and used if present.
|
||||
*/
|
||||
#define PNG_HAVE_ASSEMBLER_COMBINE_ROW
|
||||
#define PNG_HAVE_ASSEMBLER_READ_INTERLACE
|
||||
#define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
|
||||
#ifdef PNG_USE_PNGGCCRD
|
||||
# define PNG_HAVE_ASSEMBLER_COMBINE_ROW
|
||||
# define PNG_HAVE_ASSEMBLER_READ_INTERLACE
|
||||
# define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
|
||||
#endif
|
||||
/*
|
||||
GRR notes:
|
||||
- see pnggccrd.c for info about what is currently enabled
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
343
pngconf.h
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngconf.h - machine configurable file for libpng
|
||||
*
|
||||
* libpng 1.0.4d - October 6, 1999
|
||||
* libpng 1.0.6e - April 10, 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
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
/* Any machine specific code is near the front of this file, so if you
|
||||
@@ -17,7 +17,6 @@
|
||||
#ifndef PNGCONF_H
|
||||
#define PNGCONF_H
|
||||
|
||||
|
||||
/* This is the size of the compression buffer, and thus the size of
|
||||
* an IDAT chunk. Make this whatever size you feel is best for your
|
||||
* machine. One of these will be allocated per png_struct. When this
|
||||
@@ -112,29 +111,35 @@
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#ifndef PNG_SETJMP_NOT_SUPPORTED
|
||||
# define PNG_SETJMP_SUPPORTED
|
||||
#endif
|
||||
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
/* This is an attempt to force a single setjmp behaviour on Linux. If
|
||||
* the X config stuff didn't define _BSD_SOURCE we wouldn't need this.
|
||||
*/
|
||||
#ifdef __linux__
|
||||
#ifdef _BSD_SOURCE
|
||||
#define _PNG_SAVE_BSD_SOURCE
|
||||
#undef _BSD_SOURCE
|
||||
#endif
|
||||
#ifdef _SETJMP_H
|
||||
__png.h__ already includes setjmp.h
|
||||
__dont__ include it again
|
||||
#endif
|
||||
# ifdef __linux__
|
||||
# ifdef _BSD_SOURCE
|
||||
# define _PNG_SAVE_BSD_SOURCE
|
||||
# undef _BSD_SOURCE
|
||||
# endif
|
||||
# ifdef _SETJMP_H
|
||||
__png.h__ already includes setjmp.h
|
||||
__dont__ include it again
|
||||
# endif
|
||||
#endif /* __linux__ */
|
||||
|
||||
/* include setjmp.h for error handling */
|
||||
#include <setjmp.h>
|
||||
|
||||
#ifdef __linux__
|
||||
#ifdef _PNG_SAVE_BSD_SOURCE
|
||||
#define _BSD_SOURCE
|
||||
#undef _PNG_SAVE_BSD_SOURCE
|
||||
#endif
|
||||
#endif /* __linux__ */
|
||||
# ifdef __linux__
|
||||
# ifdef _PNG_SAVE_BSD_SOURCE
|
||||
# define _BSD_SOURCE
|
||||
# undef _PNG_SAVE_BSD_SOURCE
|
||||
# endif
|
||||
# endif /* __linux__ */
|
||||
#endif /* PNG_SETJMP_SUPPORTED */
|
||||
|
||||
#ifdef BSD
|
||||
#include <strings.h>
|
||||
@@ -159,6 +164,7 @@ __dont__ include it again
|
||||
* them inside an appropriate ifdef/endif pair for portability.
|
||||
*/
|
||||
|
||||
#if !defined(PNG_NO_FLOATING_POINT_SUPPORTED)
|
||||
#if defined(MACOS)
|
||||
/* We need to check that <math.h> hasn't already been included earlier
|
||||
* as it seems it doesn't agree with <fp.h>, yet we should really use
|
||||
@@ -170,6 +176,7 @@ __dont__ include it again
|
||||
#else
|
||||
#include <math.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Codewarrior on NT has linking problems without this. */
|
||||
#if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
|
||||
@@ -248,7 +255,7 @@ __dont__ include it again
|
||||
* things to happen if the library and/or application ever change.
|
||||
*/
|
||||
|
||||
/* Any transformations you will not be using can be undef'ed here */
|
||||
/* Any features you will not be using can be undef'ed here */
|
||||
|
||||
/* GR-P, 0.96a: Set "*TRANSFORMS_SUPPORTED as default but allow user
|
||||
to turn it off with "*TRANSFORMS_NOT_SUPPORTED" or *PNG_NO_*_TRANSFORMS
|
||||
@@ -260,6 +267,13 @@ __dont__ include it again
|
||||
1.0.1c, for consistency)
|
||||
*/
|
||||
|
||||
#ifndef PNG_NO_FLOATING_POINT_SUPPORTED
|
||||
#define PNG_FLOATING_POINT_SUPPORTED
|
||||
#endif
|
||||
|
||||
#ifndef PNG_NO_FIXED_POINT_SUPPORTED
|
||||
#define PNG_FIXED_POINT_SUPPORTED
|
||||
#endif
|
||||
|
||||
#if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
|
||||
!defined(PNG_NO_READ_TRANSFORMS)
|
||||
@@ -379,7 +393,8 @@ __dont__ include it again
|
||||
encoders, but can cause trouble
|
||||
if left undefined */
|
||||
|
||||
#ifndef PNG_NO_WRITE_WEIGHTED_FILTER
|
||||
#if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
|
||||
defined(PNG_FLOATING_POINT_SUPPORTED)
|
||||
#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
#endif
|
||||
|
||||
@@ -415,10 +430,26 @@ __dont__ include it again
|
||||
#define PNG_EASY_ACCESS_SUPPORTED
|
||||
#endif
|
||||
|
||||
#ifndef PNG_NO_ASSEMBLER_CODE
|
||||
#if defined(PNG_USE_PNGVCRD) || defined(PNG_USE_PNGGCCRD) && \
|
||||
!defined(PNG_NO_ASSEMBLER_CODE)
|
||||
#define PNG_ASSEMBLER_CODE_SUPPORTED
|
||||
#endif
|
||||
|
||||
/* Do not use global arrays (helps with building DLL's)
|
||||
* They are no longer used in libpng itself, since version 1.0.5c,
|
||||
* but might be required for some pre-1.0.5c applications.
|
||||
*/
|
||||
#ifdef PNG_NO_GLOBAL_ARRAYS
|
||||
# define PNG_USE_LOCAL_ARRAYS
|
||||
#else
|
||||
# if defined(__GNUC__) && defined(WIN32)
|
||||
# define PNG_NO_GLOBAL_ARRAYS
|
||||
# define PNG_USE_LOCAL_ARRAYS
|
||||
# else
|
||||
# define PNG_USE_GLOBAL_ARRAYS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* These are currently experimental features, define them if you want */
|
||||
|
||||
/* very little testing */
|
||||
@@ -455,95 +486,246 @@ __dont__ include it again
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
|
||||
|
||||
#ifdef PNG_NO_READ_TEXT
|
||||
# define PNG_NO_READ_iTXt
|
||||
# define PNG_NO_READ_tEXt
|
||||
# define PNG_NO_READ_zTXt
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_bKGD
|
||||
#define PNG_READ_bKGD_SUPPORTED
|
||||
# define PNG_READ_bKGD_SUPPORTED
|
||||
# define PNG_bKGD_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_cHRM
|
||||
#define PNG_READ_cHRM_SUPPORTED
|
||||
# define PNG_READ_cHRM_SUPPORTED
|
||||
# define PNG_cHRM_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_gAMA
|
||||
#define PNG_READ_gAMA_SUPPORTED
|
||||
# define PNG_READ_gAMA_SUPPORTED
|
||||
# define PNG_gAMA_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_hIST
|
||||
#define PNG_READ_hIST_SUPPORTED
|
||||
# define PNG_READ_hIST_SUPPORTED
|
||||
# define PNG_hIST_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_iCCP
|
||||
# define PNG_READ_iCCP_SUPPORTED
|
||||
# define PNG_iCCP_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_iTXt
|
||||
# define PNG_READ_iTXt_SUPPORTED
|
||||
# define PNG_iTXt_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_oFFs
|
||||
#define PNG_READ_oFFs_SUPPORTED
|
||||
# define PNG_READ_oFFs_SUPPORTED
|
||||
# define PNG_oFFs_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_pCAL
|
||||
#define PNG_READ_pCAL_SUPPORTED
|
||||
# define PNG_READ_pCAL_SUPPORTED
|
||||
# define PNG_pCAL_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_sCAL
|
||||
# define PNG_READ_sCAL_SUPPORTED
|
||||
# define PNG_sCAL_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_pHYs
|
||||
#define PNG_READ_pHYs_SUPPORTED
|
||||
# define PNG_READ_pHYs_SUPPORTED
|
||||
# define PNG_pHYs_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_sBIT
|
||||
#define PNG_READ_sBIT_SUPPORTED
|
||||
# define PNG_READ_sBIT_SUPPORTED
|
||||
# define PNG_sBIT_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_sPLT
|
||||
# define PNG_READ_sPLT_SUPPORTED
|
||||
# define PNG_sPLT_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_sRGB
|
||||
#define PNG_READ_sRGB_SUPPORTED
|
||||
# define PNG_READ_sRGB_SUPPORTED
|
||||
# define PNG_sRGB_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_tEXt
|
||||
#define PNG_READ_tEXt_SUPPORTED
|
||||
# define PNG_READ_tEXt_SUPPORTED
|
||||
# define PNG_tEXt_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_tIME
|
||||
#define PNG_READ_tIME_SUPPORTED
|
||||
# define PNG_READ_tIME_SUPPORTED
|
||||
# define PNG_tIME_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_tRNS
|
||||
#define PNG_READ_tRNS_SUPPORTED
|
||||
# define PNG_READ_tRNS_SUPPORTED
|
||||
# define PNG_tRNS_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_zTXt
|
||||
#define PNG_READ_zTXt_SUPPORTED
|
||||
# define PNG_READ_zTXt_SUPPORTED
|
||||
# define PNG_zTXt_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_USER_CHUNKS
|
||||
# define PNG_READ_USER_CHUNKS_SUPPORTED
|
||||
# define PNG_USER_CHUNKS_SUPPORTED
|
||||
# ifdef PNG_NO_READ_UNKNOWN_CHUNKS
|
||||
# undef PNG_NO_READ_UNKNOWN_CHUNKS
|
||||
# endif
|
||||
# ifdef PNG_NO_HANDLE_AS_UNKNOWN
|
||||
# undef PNG_NO_HANDLE_AS_UNKNOWN
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_UNKNOWN_CHUNKS
|
||||
# define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
|
||||
# define PNG_UNKNOWN_CHUNKS_SUPPORTED
|
||||
# ifndef PNG_NO_HANDLE_AS_UNKNOWN
|
||||
# define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_OPT_PLTE
|
||||
#define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the optional */
|
||||
#endif /* PLTE chunk in RGB and RGBA images */
|
||||
# define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
|
||||
#endif /* optional PLTE chunk in RGB and RGBA images */
|
||||
#if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
|
||||
defined(PNG_READ_zTXt_SUPPORTED)
|
||||
# define PNG_READ_TEXT_SUPPORTED
|
||||
# define PNG_TEXT_SUPPORTED
|
||||
#endif
|
||||
#endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
|
||||
|
||||
#ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
|
||||
#ifdef PNG_NO_WRITE_TEXT
|
||||
# define PNG_NO_WRITE_iTXt
|
||||
# define PNG_NO_WRITE_tEXt
|
||||
# define PNG_NO_WRITE_zTXt
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_bKGD
|
||||
#define PNG_WRITE_bKGD_SUPPORTED
|
||||
# define PNG_WRITE_bKGD_SUPPORTED
|
||||
# ifndef PNG_bKGD_SUPPORTED
|
||||
# define PNG_bKGD_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_cHRM
|
||||
#define PNG_WRITE_cHRM_SUPPORTED
|
||||
# define PNG_WRITE_cHRM_SUPPORTED
|
||||
# ifndef PNG_cHRM_SUPPORTED
|
||||
# define PNG_cHRM_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_gAMA
|
||||
#define PNG_WRITE_gAMA_SUPPORTED
|
||||
# define PNG_WRITE_gAMA_SUPPORTED
|
||||
# ifndef PNG_gAMA_SUPPORTED
|
||||
# define PNG_gAMA_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_hIST
|
||||
#define PNG_WRITE_hIST_SUPPORTED
|
||||
# define PNG_WRITE_hIST_SUPPORTED
|
||||
# ifndef PNG_hIST_SUPPORTED
|
||||
# define PNG_hIST_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_iCCP
|
||||
# define PNG_WRITE_iCCP_SUPPORTED
|
||||
# ifndef PNG_iCCP_SUPPORTED
|
||||
# define PNG_iCCP_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_iTXt
|
||||
# define PNG_WRITE_iTXt_SUPPORTED
|
||||
# ifndef PNG_iTXt_SUPPORTED
|
||||
# define PNG_iTXt_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_oFFs
|
||||
#define PNG_WRITE_oFFs_SUPPORTED
|
||||
# define PNG_WRITE_oFFs_SUPPORTED
|
||||
# ifndef PNG_oFFs_SUPPORTED
|
||||
# define PNG_oFFs_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_pCAL
|
||||
#define PNG_WRITE_pCAL_SUPPORTED
|
||||
# define PNG_WRITE_pCAL_SUPPORTED
|
||||
# ifndef PNG_pCAL_SUPPORTED
|
||||
# define PNG_pCAL_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_sCAL
|
||||
# define PNG_WRITE_sCAL_SUPPORTED
|
||||
# ifndef PNG_sCAL_SUPPORTED
|
||||
# define PNG_sCAL_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_pHYs
|
||||
#define PNG_WRITE_pHYs_SUPPORTED
|
||||
# define PNG_WRITE_pHYs_SUPPORTED
|
||||
# ifndef PNG_pHYs_SUPPORTED
|
||||
# define PNG_pHYs_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_sBIT
|
||||
#define PNG_WRITE_sBIT_SUPPORTED
|
||||
# define PNG_WRITE_sBIT_SUPPORTED
|
||||
# ifndef PNG_sBIT_SUPPORTED
|
||||
# define PNG_sBIT_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_sPLT
|
||||
# define PNG_WRITE_sPLT_SUPPORTED
|
||||
# ifndef PNG_sPLT_SUPPORTED
|
||||
# define PNG_sPLT_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_sRGB
|
||||
#define PNG_WRITE_sRGB_SUPPORTED
|
||||
# define PNG_WRITE_sRGB_SUPPORTED
|
||||
# ifndef PNG_sRGB_SUPPORTED
|
||||
# define PNG_sRGB_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_tEXt
|
||||
#define PNG_WRITE_tEXt_SUPPORTED
|
||||
# define PNG_WRITE_tEXt_SUPPORTED
|
||||
# ifndef PNG_tEXt_SUPPORTED
|
||||
# define PNG_tEXt_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_tIME
|
||||
#define PNG_WRITE_tIME_SUPPORTED
|
||||
# define PNG_WRITE_tIME_SUPPORTED
|
||||
# ifndef PNG_tIME_SUPPORTED
|
||||
# define PNG_tIME_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_tRNS
|
||||
#define PNG_WRITE_tRNS_SUPPORTED
|
||||
# define PNG_WRITE_tRNS_SUPPORTED
|
||||
# ifndef PNG_tRNS_SUPPORTED
|
||||
# define PNG_tRNS_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_zTXt
|
||||
#define PNG_WRITE_zTXt_SUPPORTED
|
||||
# define PNG_WRITE_zTXt_SUPPORTED
|
||||
# ifndef PNG_zTXt_SUPPORTED
|
||||
# define PNG_zTXt_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
|
||||
# define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
# ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
|
||||
# define PNG_UNKNOWN_CHUNKS_SUPPORTED
|
||||
# endif
|
||||
# ifndef PNG_NO_HANDLE_AS_UNKNOWN
|
||||
# ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
||||
# define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
#if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
|
||||
defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
# define PNG_WRITE_TEXT_SUPPORTED
|
||||
# ifndef PNG_TEXT_SUPPORTED
|
||||
# define PNG_TEXT_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
#endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
|
||||
|
||||
/* Turn this off to disable png_read_png() and
|
||||
* png_write_png() and leave the row_pointers member
|
||||
* out of the info structure.
|
||||
*/
|
||||
#ifndef PNG_NO_INFO_IMAGE
|
||||
# define PNG_INFO_IMAGE_SUPPORTED
|
||||
#endif
|
||||
|
||||
/* need the time information for reading tIME chunks */
|
||||
#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
#include <time.h>
|
||||
#if defined(PNG_tIME_SUPPORTED)
|
||||
# include <time.h>
|
||||
#endif
|
||||
|
||||
/* Some typedefs to get us started. These should be safe on most of the
|
||||
@@ -626,6 +808,10 @@ typedef size_t png_size_t;
|
||||
#define FARDATA
|
||||
#endif
|
||||
|
||||
/* Typedef for floating-point numbers that are converted
|
||||
to fixed-point with a multiple of 100,000, e.g., int_gamma */
|
||||
typedef png_int_32 png_fixed_point;
|
||||
|
||||
/* Add typedefs for pointers */
|
||||
typedef void FAR * png_voidp;
|
||||
typedef png_byte FAR * png_bytep;
|
||||
@@ -635,7 +821,10 @@ typedef png_uint_16 FAR * png_uint_16p;
|
||||
typedef png_int_16 FAR * png_int_16p;
|
||||
typedef PNG_CONST char FAR * png_const_charp;
|
||||
typedef char FAR * png_charp;
|
||||
typedef png_fixed_point FAR * png_fixed_point_p;
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
typedef double FAR * png_doublep;
|
||||
#endif
|
||||
|
||||
/* Pointers to pointers; i.e. arrays */
|
||||
typedef png_byte FAR * FAR * png_bytepp;
|
||||
@@ -645,7 +834,10 @@ typedef png_uint_16 FAR * FAR * png_uint_16pp;
|
||||
typedef png_int_16 FAR * FAR * png_int_16pp;
|
||||
typedef PNG_CONST char FAR * FAR * png_const_charpp;
|
||||
typedef char FAR * FAR * png_charpp;
|
||||
typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
typedef double FAR * FAR * png_doublepp;
|
||||
#endif
|
||||
|
||||
/* Pointers to pointers to pointers; i.e. pointer to array */
|
||||
typedef char FAR * FAR * FAR * png_charppp;
|
||||
@@ -660,8 +852,13 @@ typedef z_stream FAR * png_zstreamp;
|
||||
|
||||
|
||||
#ifndef PNG_EXPORT
|
||||
/* allow for compilation as dll under MS Windows */
|
||||
# ifdef __WIN32DLL__
|
||||
/* GRR 20000206: based on zconf.h and MSVC 5.0 docs */
|
||||
# if defined(_MSC_VER) && defined(_DLL)
|
||||
# define PNG_EXPORT(type,symbol) type __declspec(dllexport) symbol
|
||||
# endif
|
||||
|
||||
/* allow for compilation as a DLL under MS Windows */
|
||||
# ifdef __WIN32DLL__ /* Borland? */
|
||||
# define PNG_EXPORT(type,symbol) __declspec(dllexport) type symbol
|
||||
# endif
|
||||
|
||||
@@ -670,7 +867,7 @@ typedef z_stream FAR * png_zstreamp;
|
||||
# define PNG_EXPORT(type,symbol) type __attribute__((dllexport)) symbol
|
||||
# endif
|
||||
|
||||
/* allow for compilation as dll with Borland C++ 5.0 */
|
||||
/* allow for compilation as a DLL with Borland C++ 5.0 */
|
||||
# if defined(__BORLANDC__) && defined(_Windows) && defined(__DLL__)
|
||||
# define PNG_EXPORT(type,symbol) type _export symbol
|
||||
# endif
|
||||
@@ -685,11 +882,47 @@ typedef z_stream FAR * png_zstreamp;
|
||||
# define PNG_EXPORT(type,symbol) type symbol
|
||||
#endif
|
||||
|
||||
#if defined(__MINGW32__) || defined(__CYGWIN32__)
|
||||
# define PNG_ATTR_DLLIMP
|
||||
#endif
|
||||
|
||||
#ifndef PNG_EXPORT_VAR
|
||||
# if defined(_MSC_VER) && defined(_DLL) /* GRR 20000206 */
|
||||
# define PNG_EXPORT_VAR(type) extern type __declspec(dllexport)
|
||||
# endif
|
||||
# ifdef PNG_DECL_DLLEXP
|
||||
# define PNG_EXPORT_VAR(type) extern __declspec(dllexport) type
|
||||
# endif
|
||||
# ifdef PNG_ATTR_DLLEXP
|
||||
# define PNG_EXPORT_VAR(type) extern type __attribute__((dllexport))
|
||||
# endif
|
||||
# ifdef PNG_DECL_DLLIMP
|
||||
# define PNG_EXPORT_VAR(type) extern __declspec(dllimport) type
|
||||
# endif
|
||||
# ifdef PNG_ATTR_DLLIMP
|
||||
# define PNG_EXPORT_VAR(type) extern type __attribute__((dllimport))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef PNG_EXPORT_VAR
|
||||
# define PNG_EXPORT_VAR(type) extern type
|
||||
#endif
|
||||
|
||||
/* User may want to use these so not in PNG_INTERNAL. Any library functions
|
||||
* that are passed far data must be model independent.
|
||||
*/
|
||||
|
||||
#ifndef PNG_ABORT
|
||||
# define PNG_ABORT() abort()
|
||||
#endif
|
||||
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
|
||||
#else
|
||||
# define png_jmpbuf(png_ptr) \
|
||||
(LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
|
||||
#endif
|
||||
|
||||
#if defined(USE_FAR_KEYWORD) /* memory model independent fns */
|
||||
/* use this to make far-to-near assignments */
|
||||
# define CHECK 1
|
||||
@@ -712,7 +945,7 @@ typedef z_stream FAR * png_zstreamp;
|
||||
#endif
|
||||
/* End of memory model independent support */
|
||||
|
||||
/* Just a double check that someone hasn't tried to define something
|
||||
/* Just a little check that someone hasn't tried to define something
|
||||
* contradictory.
|
||||
*/
|
||||
#if (PNG_ZBUF_SIZE > 65536) && defined(PNG_MAX_MALLOC_64K)
|
||||
|
||||
31
pngerror.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngerror.c - stub functions for i/o and memory allocation
|
||||
*
|
||||
* libpng 1.0.4d - October 6, 1999
|
||||
* libpng 1.0.6e - April 10, 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
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
*
|
||||
* This file provides a location for all error handling. Users who
|
||||
* need special error handling are expected to write replacement functions
|
||||
@@ -67,21 +67,26 @@ png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp message
|
||||
{
|
||||
int iout = 0, iin = 0;
|
||||
|
||||
while (iin < 4) {
|
||||
while (iin < 4)
|
||||
{
|
||||
int c = png_ptr->chunk_name[iin++];
|
||||
if (isnonalpha(c)) {
|
||||
if (isnonalpha(c))
|
||||
{
|
||||
buffer[iout++] = '[';
|
||||
buffer[iout++] = png_digit[(c & 0xf0) >> 4];
|
||||
buffer[iout++] = png_digit[c & 0xf];
|
||||
buffer[iout++] = png_digit[c & 0x0f];
|
||||
buffer[iout++] = ']';
|
||||
} else {
|
||||
buffer[iout++] = c;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[iout++] = (png_byte)c;
|
||||
}
|
||||
}
|
||||
|
||||
if (message == NULL)
|
||||
buffer[iout] = 0;
|
||||
else {
|
||||
else
|
||||
{
|
||||
buffer[iout++] = ':';
|
||||
buffer[iout++] = ' ';
|
||||
png_memcpy(buffer+iout, message, 64);
|
||||
@@ -117,14 +122,20 @@ png_default_error(png_structp png_ptr, png_const_charp message)
|
||||
fprintf(stderr, "libpng error: %s\n", message);
|
||||
#endif
|
||||
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
# ifdef USE_FAR_KEYWORD
|
||||
{
|
||||
jmp_buf jmpbuf;
|
||||
png_memcpy(jmpbuf,png_ptr->jmpbuf,sizeof(jmp_buf));
|
||||
longjmp(jmpbuf, 1);
|
||||
}
|
||||
#else
|
||||
# else
|
||||
longjmp(png_ptr->jmpbuf, 1);
|
||||
# endif
|
||||
#else
|
||||
if (png_ptr == NULL)
|
||||
/* make compiler happy */ ;
|
||||
PNG_ABORT();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
4644
pnggccrd.c
Normal file
217
pngget.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngget.c - retrieval of values from info struct
|
||||
*
|
||||
* libpng 1.0.4d - October 6, 1999
|
||||
* libpng 1.0.6e - April 10, 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
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
@@ -29,6 +29,17 @@ png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
|
||||
return(0);
|
||||
}
|
||||
|
||||
#if defined(PNG_INFO_IMAGE_SUPPORTED)
|
||||
png_bytepp
|
||||
png_get_rows(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
return(info_ptr->row_pointers);
|
||||
else
|
||||
return(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_EASY_ACCESS_SUPPORTED
|
||||
/* easy access to info, added in libpng-0.99 */
|
||||
png_uint_32
|
||||
@@ -104,7 +115,7 @@ png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
|
||||
png_uint_32
|
||||
png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
|
||||
#if defined(PNG_pHYs_SUPPORTED)
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
|
||||
@@ -120,7 +131,7 @@ png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
|
||||
png_uint_32
|
||||
png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
|
||||
#if defined(PNG_pHYs_SUPPORTED)
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
|
||||
@@ -136,7 +147,7 @@ png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
|
||||
png_uint_32
|
||||
png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
|
||||
#if defined(PNG_pHYs_SUPPORTED)
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
|
||||
@@ -150,10 +161,11 @@ png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
|
||||
return (0);
|
||||
}
|
||||
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
float
|
||||
png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
|
||||
#if defined(PNG_pHYs_SUPPORTED)
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
|
||||
@@ -167,11 +179,12 @@ png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
|
||||
#endif
|
||||
return ((float)0.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
png_uint_32
|
||||
png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
|
||||
#if defined(PNG_oFFs_SUPPORTED)
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
|
||||
@@ -187,7 +200,7 @@ png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
|
||||
png_uint_32
|
||||
png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
|
||||
#if defined(PNG_oFFs_SUPPORTED)
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
|
||||
@@ -203,7 +216,7 @@ png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
|
||||
png_uint_32
|
||||
png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
|
||||
#if defined(PNG_oFFs_SUPPORTED)
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
|
||||
@@ -219,7 +232,7 @@ png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
|
||||
png_uint_32
|
||||
png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
|
||||
#if defined(PNG_oFFs_SUPPORTED)
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
|
||||
@@ -232,40 +245,40 @@ png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
|
||||
return (0);
|
||||
}
|
||||
|
||||
#ifdef PNG_INCH_CONVERSIONS
|
||||
#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
|
||||
*.03937 +.5)
|
||||
*.0254 +.5);
|
||||
}
|
||||
|
||||
png_uint_32
|
||||
png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
|
||||
*.03937 +.5)
|
||||
*.0254 +.5);
|
||||
}
|
||||
|
||||
png_uint_32
|
||||
png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
|
||||
*.03937 +.5)
|
||||
*.0254 +.5);
|
||||
}
|
||||
|
||||
float
|
||||
png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
|
||||
*.03937/1000000. +.5)
|
||||
*.00003937);
|
||||
}
|
||||
|
||||
float
|
||||
png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
|
||||
*.03937/1000000. +.5)
|
||||
*.00003937)
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED)
|
||||
@@ -275,7 +288,7 @@ png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
|
||||
{
|
||||
png_uint_32 retval = 0;
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs)
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "pHYs");
|
||||
if (res_x != NULL)
|
||||
@@ -294,15 +307,15 @@ png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
|
||||
retval |= PNG_INFO_pHYs;
|
||||
if(unit_type == 1)
|
||||
{
|
||||
if (res_x != NULL) *res_x = (png_uint_32)(*res_x * 39.37 + .50);
|
||||
if (res_y != NULL) *res_y = (png_uint_32)(*res_y * 39.37 + .50);
|
||||
if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
|
||||
if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (retval);
|
||||
}
|
||||
#endif /* PNG_READ_pHYs_SUPPORTED */
|
||||
#endif /* PNG_INCH_CONVERSIONS */
|
||||
#endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
|
||||
|
||||
/* png_get_channels really belongs in here, too, but it's been around longer */
|
||||
|
||||
@@ -343,6 +356,7 @@ png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED)
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
png_uint_32
|
||||
png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
double *white_x, double *white_y, double *red_x, double *red_y,
|
||||
@@ -372,8 +386,41 @@ png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_uint_32
|
||||
png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
|
||||
png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
|
||||
png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
|
||||
png_fixed_point *blue_x, png_fixed_point *blue_y)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "cHRM");
|
||||
if (white_x != NULL)
|
||||
*white_x = info_ptr->int_x_white;
|
||||
if (white_y != NULL)
|
||||
*white_y = info_ptr->int_y_white;
|
||||
if (red_x != NULL)
|
||||
*red_x = info_ptr->int_x_red;
|
||||
if (red_y != NULL)
|
||||
*red_y = info_ptr->int_y_red;
|
||||
if (green_x != NULL)
|
||||
*green_x = info_ptr->int_x_green;
|
||||
if (green_y != NULL)
|
||||
*green_y = info_ptr->int_y_green;
|
||||
if (blue_x != NULL)
|
||||
*blue_x = info_ptr->int_x_blue;
|
||||
if (blue_y != NULL)
|
||||
*blue_y = info_ptr->int_y_blue;
|
||||
return (PNG_INFO_cHRM);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED)
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
png_uint_32
|
||||
png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
|
||||
{
|
||||
@@ -387,6 +434,20 @@ png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
png_uint_32
|
||||
png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
|
||||
png_fixed_point *int_file_gamma)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
|
||||
&& int_file_gamma != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "gAMA");
|
||||
*int_file_gamma = info_ptr->int_gamma;
|
||||
return (PNG_INFO_gAMA);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
png_uint_32
|
||||
@@ -403,6 +464,39 @@ png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_iCCP_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
|
||||
png_charpp name, int *compression_type,
|
||||
png_charpp profile, png_uint_32 *proflen)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
|
||||
&& name != NULL && profile != NULL && proflen != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "iCCP");
|
||||
*name = info_ptr->iccp_name;
|
||||
*profile = info_ptr->iccp_profile;
|
||||
/* compression_type is a dummy so the API won't have to change
|
||||
if we introduce multiple compression types later. */
|
||||
*proflen = (int)info_ptr->iccp_proflen;
|
||||
*compression_type = (int)info_ptr->iccp_compression;
|
||||
return (PNG_INFO_iCCP);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_sPLT_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
|
||||
png_sPLT_tpp spalettes)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
|
||||
*spalettes = info_ptr->splt_palettes;
|
||||
return ((png_uint_32)info_ptr->splt_palettes_num);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_hIST_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
|
||||
@@ -467,7 +561,7 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 *offset_x, png_uint_32 *offset_y, int *unit_type)
|
||||
png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
|
||||
&& offset_x != NULL && offset_y != NULL && unit_type != NULL)
|
||||
@@ -488,8 +582,8 @@ png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
|
||||
png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
|
||||
png_charp *units, png_charpp *params)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pCAL &&
|
||||
purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
|
||||
&& purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
|
||||
nparams != NULL && units != NULL && params != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "pCAL");
|
||||
@@ -506,6 +600,42 @@ png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
png_uint_32
|
||||
png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
|
||||
int *unit, double *width, double *height)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_sCAL))
|
||||
{
|
||||
*unit = info_ptr->scal_unit;
|
||||
*width = info_ptr->scal_pixel_width;
|
||||
*height = info_ptr->scal_pixel_height;
|
||||
return (PNG_INFO_sCAL);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
#else
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_uint_32
|
||||
png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
|
||||
int *unit, png_charpp width, png_charpp height)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_sCAL))
|
||||
{
|
||||
*unit = info_ptr->scal_unit;
|
||||
*width = info_ptr->scal_s_width;
|
||||
*height = info_ptr->scal_s_height;
|
||||
return (PNG_INFO_sCAL);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
|
||||
@@ -513,7 +643,8 @@ png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
|
||||
{
|
||||
png_uint_32 retval = 0;
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "pHYs");
|
||||
if (res_x != NULL)
|
||||
@@ -540,8 +671,8 @@ png_uint_32
|
||||
png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
|
||||
int *num_palette)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_PLTE &&
|
||||
palette != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
|
||||
&& palette != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "PLTE");
|
||||
*palette = info_ptr->palette;
|
||||
@@ -556,8 +687,8 @@ png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
|
||||
png_uint_32
|
||||
png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_sBIT &&
|
||||
sig_bit != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
|
||||
&& sig_bit != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "sBIT");
|
||||
*sig_bit = &(info_ptr->sig_bit);
|
||||
@@ -567,7 +698,7 @@ png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
|
||||
#if defined(PNG_READ_TEXT_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
|
||||
int *num_text)
|
||||
@@ -583,6 +714,8 @@ png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
|
||||
*num_text = info_ptr->num_text;
|
||||
return ((png_uint_32)info_ptr->num_text);
|
||||
}
|
||||
if (num_text != NULL)
|
||||
*num_text = 0;
|
||||
return(0);
|
||||
}
|
||||
#endif
|
||||
@@ -591,8 +724,8 @@ png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
|
||||
png_uint_32
|
||||
png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_tIME &&
|
||||
mod_time != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
|
||||
&& mod_time != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "tIME");
|
||||
*mod_time = &(info_ptr->mod_time);
|
||||
@@ -608,7 +741,7 @@ png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
|
||||
png_bytep *trans, int *num_trans, png_color_16p *trans_values)
|
||||
{
|
||||
png_uint_32 retval = 0;
|
||||
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS)
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "tRNS");
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
@@ -641,6 +774,17 @@ png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
|
||||
png_unknown_chunkpp unknowns)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
|
||||
*unknowns = info_ptr->unknown_chunks;
|
||||
return ((png_uint_32)info_ptr->unknown_chunks_num);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
|
||||
png_byte
|
||||
png_get_rgb_to_gray_status (png_structp png_ptr)
|
||||
@@ -648,3 +792,12 @@ png_get_rgb_to_gray_status (png_structp png_ptr)
|
||||
return png_ptr->rgb_to_gray_status;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
|
||||
png_voidp
|
||||
png_get_user_chunk_ptr(png_structp png_ptr)
|
||||
{
|
||||
return (png_ptr->user_chunk_ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
19
pngmem.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngmem.c - stub functions for memory allocation
|
||||
*
|
||||
* libpng 1.0.4d - October 6, 1999
|
||||
* libpng 1.0.6e - April 10, 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
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
*
|
||||
* This file provides a location for all memory allocation. Users who
|
||||
* need special memory handling are expected to supply replacement
|
||||
@@ -82,12 +82,10 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
|
||||
png_struct dummy_struct;
|
||||
png_structp png_ptr = &dummy_struct;
|
||||
(*(free_fn))(png_ptr, struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
return;
|
||||
}
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
farfree (struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,7 +234,6 @@ png_free(png_structp png_ptr, png_voidp ptr)
|
||||
if (png_ptr->free_fn != NULL)
|
||||
{
|
||||
(*(png_ptr->free_fn))(png_ptr, ptr);
|
||||
ptr = NULL;
|
||||
return;
|
||||
}
|
||||
else png_free_default(png_ptr, ptr);
|
||||
@@ -272,7 +269,6 @@ png_free_default(png_structp png_ptr, png_voidp ptr)
|
||||
if (ptr != NULL)
|
||||
{
|
||||
farfree(ptr);
|
||||
ptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,20 +348,16 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
|
||||
png_struct dummy_struct;
|
||||
png_structp png_ptr = &dummy_struct;
|
||||
(*(free_fn))(png_ptr, struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
return;
|
||||
}
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||
farfree(struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
#else
|
||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||
hfree(struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
# else
|
||||
free(struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
@@ -434,7 +426,6 @@ png_free(png_structp png_ptr, png_voidp ptr)
|
||||
if (png_ptr->free_fn != NULL)
|
||||
{
|
||||
(*(png_ptr->free_fn))(png_ptr, ptr);
|
||||
ptr = NULL;
|
||||
return;
|
||||
}
|
||||
else png_free_default(png_ptr, ptr);
|
||||
@@ -442,18 +433,18 @@ png_free(png_structp png_ptr, png_voidp ptr)
|
||||
void
|
||||
png_free_default(png_structp png_ptr, png_voidp ptr)
|
||||
{
|
||||
if (png_ptr == NULL || ptr == NULL)
|
||||
return;
|
||||
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||
farfree(ptr);
|
||||
ptr = NULL;
|
||||
#else
|
||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||
hfree(ptr);
|
||||
ptr = NULL;
|
||||
# else
|
||||
free(ptr);
|
||||
ptr = NULL;
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
BIN
pngnow.png
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
349
pngpread.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngpread.c - read a png file in push mode
|
||||
*
|
||||
* libpng 1.0.4d - October 6, 1999
|
||||
* libpng 1.0.6e - April 10, 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
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
@@ -13,6 +13,17 @@
|
||||
|
||||
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
|
||||
|
||||
/* push model modes */
|
||||
#define PNG_READ_SIG_MODE 0
|
||||
#define PNG_READ_CHUNK_MODE 1
|
||||
#define PNG_READ_IDAT_MODE 2
|
||||
#define PNG_SKIP_MODE 3
|
||||
#define PNG_READ_tEXt_MODE 4
|
||||
#define PNG_READ_zTXt_MODE 5
|
||||
#define PNG_READ_DONE_MODE 6
|
||||
#define PNG_READ_iTXt_MODE 7
|
||||
#define PNG_ERROR_MODE 8
|
||||
|
||||
void
|
||||
png_process_data(png_structp png_ptr, png_infop info_ptr,
|
||||
png_bytep buffer, png_size_t buffer_size)
|
||||
@@ -61,6 +72,13 @@ png_process_some_data(png_structp png_ptr, png_infop info_ptr)
|
||||
png_push_read_zTXt(png_ptr, info_ptr);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_iTXt_SUPPORTED)
|
||||
case PNG_READ_iTXt_MODE:
|
||||
{
|
||||
png_push_read_iTXt(png_ptr, info_ptr);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
case PNG_SKIP_MODE:
|
||||
{
|
||||
@@ -94,7 +112,7 @@ png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
|
||||
num_to_check);
|
||||
png_ptr->sig_bytes += num_to_check;
|
||||
png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
|
||||
|
||||
if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
|
||||
{
|
||||
@@ -116,13 +134,70 @@ png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
|
||||
void
|
||||
png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_IHDR;
|
||||
PNG_IDAT;
|
||||
PNG_IEND;
|
||||
PNG_PLTE;
|
||||
#if defined(PNG_READ_bKGD_SUPPORTED)
|
||||
PNG_bKGD;
|
||||
#endif
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED)
|
||||
PNG_cHRM;
|
||||
#endif
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED)
|
||||
PNG_gAMA;
|
||||
#endif
|
||||
#if defined(PNG_READ_hIST_SUPPORTED)
|
||||
PNG_hIST;
|
||||
#endif
|
||||
#if defined(PNG_READ_iCCP_SUPPORTED)
|
||||
PNG_iCCP;
|
||||
#endif
|
||||
#if defined(PNG_READ_iTXt_SUPPORTED)
|
||||
PNG_iTXt;
|
||||
#endif
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED)
|
||||
PNG_oFFs;
|
||||
#endif
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED)
|
||||
PNG_pCAL;
|
||||
#endif
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED)
|
||||
PNG_pHYs;
|
||||
#endif
|
||||
#if defined(PNG_READ_sBIT_SUPPORTED)
|
||||
PNG_sBIT;
|
||||
#endif
|
||||
#if defined(PNG_READ_sCAL_SUPPORTED)
|
||||
PNG_sCAL;
|
||||
#endif
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
PNG_sRGB;
|
||||
#endif
|
||||
#if defined(PNG_READ_sPLT_SUPPORTED)
|
||||
PNG_sPLT;
|
||||
#endif
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED)
|
||||
PNG_tEXt;
|
||||
#endif
|
||||
#if defined(PNG_READ_tIME_SUPPORTED)
|
||||
PNG_tIME;
|
||||
#endif
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED)
|
||||
PNG_tRNS;
|
||||
#endif
|
||||
#if defined(PNG_READ_zTXt_SUPPORTED)
|
||||
PNG_zTXt;
|
||||
#endif
|
||||
#endif /* PNG_USE_LOCAL_ARRAYS */
|
||||
/* First we make sure we have enough data for the 4 byte chunk name
|
||||
* and the 4 byte chunk length before proceeding with decoding the
|
||||
* chunk data. To fully decode each of these chunks, we also make
|
||||
* sure we have enough data in the buffer for the 4 byte CRC at the
|
||||
* end of every chunk (except IDAT, which is handled separately).
|
||||
*/
|
||||
if (!(png_ptr->flags & PNG_FLAG_HAVE_CHUNK_HEADER))
|
||||
if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
|
||||
{
|
||||
png_byte chunk_length[4];
|
||||
|
||||
@@ -136,7 +211,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
png_ptr->push_length = png_get_uint_32(chunk_length);
|
||||
png_reset_crc(png_ptr);
|
||||
png_crc_read(png_ptr, png_ptr->chunk_name, 4);
|
||||
png_ptr->flags |= PNG_FLAG_HAVE_CHUNK_HEADER;
|
||||
png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
|
||||
}
|
||||
|
||||
if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
|
||||
@@ -159,7 +234,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
|
||||
else if (!png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4))
|
||||
{
|
||||
/* If we reach an IDAT chunk, this means we have read all of the
|
||||
* header chunks, and we can start reading the image (or if this
|
||||
@@ -242,6 +317,30 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_iCCP_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_sPLT_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
|
||||
{
|
||||
@@ -314,6 +413,18 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_sCAL_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_tIME_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
|
||||
{
|
||||
@@ -337,13 +448,19 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_iTXt_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
|
||||
{
|
||||
png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
png_ptr->flags &= ~PNG_FLAG_HAVE_CHUNK_HEADER;
|
||||
png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -496,7 +613,10 @@ png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
|
||||
void
|
||||
png_push_read_IDAT(png_structp png_ptr)
|
||||
{
|
||||
if (!(png_ptr->flags & PNG_FLAG_HAVE_CHUNK_HEADER))
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_IDAT;
|
||||
#endif
|
||||
if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
|
||||
{
|
||||
png_byte chunk_length[4];
|
||||
|
||||
@@ -511,9 +631,9 @@ png_push_read_IDAT(png_structp png_ptr)
|
||||
|
||||
png_reset_crc(png_ptr);
|
||||
png_crc_read(png_ptr, png_ptr->chunk_name, 4);
|
||||
png_ptr->flags |= PNG_FLAG_HAVE_CHUNK_HEADER;
|
||||
png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
|
||||
|
||||
if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
|
||||
if (png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4))
|
||||
{
|
||||
png_ptr->process_mode = PNG_READ_CHUNK_MODE;
|
||||
if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
|
||||
@@ -576,7 +696,7 @@ png_push_read_IDAT(png_structp png_ptr)
|
||||
}
|
||||
|
||||
png_crc_finish(png_ptr, 0);
|
||||
png_ptr->flags &= ~PNG_FLAG_HAVE_CHUNK_HEADER;
|
||||
png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -767,6 +887,32 @@ png_push_process_row(png_structp png_ptr)
|
||||
void
|
||||
png_read_push_finish_row(png_structp png_ptr)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
/* start of interlace block */
|
||||
const int png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
|
||||
|
||||
/* offset to next interlace block */
|
||||
const int png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
|
||||
|
||||
/* start of interlace block in the y direction */
|
||||
const int png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
|
||||
|
||||
/* offset to next interlace block in the y direction */
|
||||
const int png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
|
||||
|
||||
/* Width of interlace block. This is not currently used - if you need
|
||||
* it, uncomment it here and in png.h
|
||||
const int png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
|
||||
*/
|
||||
|
||||
/* Height of interlace block. This is not currently used - if you need
|
||||
* it, uncomment it here and in png.h
|
||||
const int png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
|
||||
*/
|
||||
#endif
|
||||
|
||||
png_ptr->row_number++;
|
||||
if (png_ptr->row_number < png_ptr->num_rows)
|
||||
return;
|
||||
@@ -806,7 +952,7 @@ png_read_push_finish_row(png_structp png_ptr)
|
||||
void
|
||||
png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
{
|
||||
if (png_ptr->mode == PNG_BEFORE_IHDR || png_ptr->mode & PNG_HAVE_IEND)
|
||||
if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
|
||||
{
|
||||
png_error(png_ptr, "Out of place tEXt");
|
||||
/* to quiet some compiler warnings */
|
||||
@@ -878,7 +1024,9 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
|
||||
text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
text_ptr->lang = (char *)NULL;
|
||||
text_ptr->key = key;
|
||||
text_ptr->lang_key = (char *)NULL;
|
||||
text_ptr->text = text;
|
||||
|
||||
png_set_text(png_ptr, info_ptr, text_ptr, 1);
|
||||
@@ -892,7 +1040,7 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
|
||||
void
|
||||
png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
{
|
||||
if (png_ptr->mode == PNG_BEFORE_IHDR || png_ptr->mode & PNG_HAVE_IEND)
|
||||
if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
|
||||
{
|
||||
png_error(png_ptr, "Out of place zTXt");
|
||||
/* to quiet some compiler warnings */
|
||||
@@ -1058,6 +1206,8 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
|
||||
text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
|
||||
text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
|
||||
text_ptr->key = key;
|
||||
text_ptr->lang = (char *)NULL;
|
||||
text_ptr->lang_key = (char *)NULL;
|
||||
text_ptr->text = text;
|
||||
|
||||
png_set_text(png_ptr, info_ptr, text_ptr, 1);
|
||||
@@ -1067,26 +1217,178 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_iTXt_SUPPORTED)
|
||||
void
|
||||
png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
{
|
||||
if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
|
||||
{
|
||||
png_error(png_ptr, "Out of place iTXt");
|
||||
/* to quiet some compiler warnings */
|
||||
if(info_ptr == NULL) return;
|
||||
}
|
||||
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
png_ptr->skip_length = 0; /* This may not be necessary */
|
||||
|
||||
if (length > (png_uint_32)65535L) /* Can't hold the entire string in memory */
|
||||
{
|
||||
png_warning(png_ptr, "iTXt chunk too large to fit in memory");
|
||||
png_ptr->skip_length = length - (png_uint_32)65535L;
|
||||
length = (png_uint_32)65535L;
|
||||
}
|
||||
#endif
|
||||
|
||||
png_ptr->current_text = (png_charp)png_malloc(png_ptr,
|
||||
(png_uint_32)(length+1));
|
||||
png_ptr->current_text[length] = '\0';
|
||||
png_ptr->current_text_ptr = png_ptr->current_text;
|
||||
png_ptr->current_text_size = (png_size_t)length;
|
||||
png_ptr->current_text_left = (png_size_t)length;
|
||||
png_ptr->process_mode = PNG_READ_iTXt_MODE;
|
||||
}
|
||||
|
||||
void
|
||||
png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
|
||||
if (png_ptr->buffer_size && png_ptr->current_text_left)
|
||||
{
|
||||
png_size_t text_size;
|
||||
|
||||
if (png_ptr->buffer_size < png_ptr->current_text_left)
|
||||
text_size = png_ptr->buffer_size;
|
||||
else
|
||||
text_size = png_ptr->current_text_left;
|
||||
png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
|
||||
png_ptr->current_text_left -= text_size;
|
||||
png_ptr->current_text_ptr += text_size;
|
||||
}
|
||||
if (!(png_ptr->current_text_left))
|
||||
{
|
||||
png_textp text_ptr;
|
||||
png_charp key;
|
||||
int comp_flag;
|
||||
png_charp lang;
|
||||
png_charp lang_key;
|
||||
png_charp text;
|
||||
|
||||
if (png_ptr->buffer_size < 4)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
png_push_crc_finish(png_ptr);
|
||||
|
||||
#if defined(PNG_MAX_MALLOC_64K)
|
||||
if (png_ptr->skip_length)
|
||||
return;
|
||||
#endif
|
||||
|
||||
key = png_ptr->current_text;
|
||||
png_ptr->current_text = 0;
|
||||
|
||||
for (lang = key; *lang; lang++)
|
||||
/* empty loop */ ;
|
||||
|
||||
if (lang != key + png_ptr->current_text_size)
|
||||
lang++;
|
||||
|
||||
comp_flag = *lang++;
|
||||
lang++; /* skip comp_type, always zero */
|
||||
|
||||
for (lang_key = lang; *lang_key; lang_key++)
|
||||
/* empty loop */ ;
|
||||
lang_key++; /* skip NUL separator */
|
||||
|
||||
for (text = lang_key; *text; text++)
|
||||
/* empty loop */ ;
|
||||
|
||||
if (text != key + png_ptr->current_text_size)
|
||||
text++;
|
||||
|
||||
text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
|
||||
text_ptr->compression = comp_flag + 2;
|
||||
text_ptr->key = key;
|
||||
text_ptr->lang = lang;
|
||||
text_ptr->lang_key = lang_key;
|
||||
text_ptr->text = text;
|
||||
text_ptr->text_length = 0;
|
||||
text_ptr->itxt_length = png_strlen(text);
|
||||
|
||||
png_set_text(png_ptr, info_ptr, text_ptr, 1);
|
||||
|
||||
png_free(png_ptr, text_ptr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This function is called when we haven't found a handler for this
|
||||
* chunk. In the future we will have code here that can handle
|
||||
* user-defined callback functions for unknown chunks before they are
|
||||
* ignored or cause an error. If there isn't a problem with the
|
||||
* chunk itself (ie a bad chunk name or a critical chunk), the chunk
|
||||
* is (currently) silently ignored.
|
||||
* chunk. If there isn't a problem with the chunk itself (ie a bad chunk
|
||||
* name or a critical chunk), the chunk is (currently) silently ignored.
|
||||
*/
|
||||
void
|
||||
png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
{
|
||||
png_uint_32 skip=0;
|
||||
png_check_chunk_name(png_ptr, png_ptr->chunk_name);
|
||||
|
||||
if (!(png_ptr->chunk_name[0] & 0x20))
|
||||
{
|
||||
png_chunk_error(png_ptr, "unknown critical chunk");
|
||||
/* to quiet some compiler warnings */
|
||||
if(info_ptr == NULL) return;
|
||||
if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
|
||||
HANDLE_CHUNK_ALWAYS
|
||||
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
|
||||
&& png_ptr->read_user_chunk_fn == (png_user_chunk_ptr)NULL
|
||||
#endif
|
||||
)
|
||||
png_chunk_error(png_ptr, "unknown critical chunk");
|
||||
|
||||
/* to quiet compiler warnings about unused info_ptr */
|
||||
if (info_ptr == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
png_push_crc_skip(png_ptr, length);
|
||||
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
|
||||
{
|
||||
png_unknown_chunk chunk;
|
||||
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
if (length > (png_uint_32)65535L)
|
||||
{
|
||||
png_warning(png_ptr, "unknown chunk too large to fit in memory");
|
||||
skip = length - (png_uint_32)65535L;
|
||||
length = (png_uint_32)65535L;
|
||||
}
|
||||
#endif
|
||||
|
||||
strcpy((png_charp)chunk.name, (png_charp)png_ptr->chunk_name);
|
||||
chunk.data = (png_bytep)png_malloc(png_ptr, length);
|
||||
png_crc_read(png_ptr, chunk.data, length);
|
||||
chunk.size = length;
|
||||
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
|
||||
if(png_ptr->read_user_chunk_fn != (png_user_chunk_ptr)NULL)
|
||||
{
|
||||
/* callback to user unknown chunk handler */
|
||||
if ((*(png_ptr->read_user_chunk_fn)) (png_ptr, &chunk) <= 0)
|
||||
{
|
||||
if (!(png_ptr->chunk_name[0] & 0x20))
|
||||
if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
|
||||
HANDLE_CHUNK_ALWAYS)
|
||||
png_chunk_error(png_ptr, "unknown critical chunk");
|
||||
}
|
||||
png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
|
||||
png_free(png_ptr, chunk.data);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
skip=length;
|
||||
png_push_crc_skip(png_ptr, skip);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1115,6 +1417,9 @@ void
|
||||
png_progressive_combine_row (png_structp png_ptr,
|
||||
png_bytep old_row, png_bytep new_row)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
const int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
|
||||
#endif
|
||||
if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
|
||||
png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
|
||||
}
|
||||
|
||||
396
pngread.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngread.c - read a PNG file
|
||||
*
|
||||
* libpng 1.0.4d - October 6, 1999
|
||||
* libpng 1.0.6e - April 10, 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
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
*
|
||||
* This file contains routines that an application calls directly to
|
||||
* read a PNG file or stream.
|
||||
@@ -34,9 +34,13 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
png_structp png_ptr;
|
||||
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
jmp_buf jmpbuf;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_create_read_struct\n");
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if ((png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
|
||||
@@ -47,6 +51,8 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
{
|
||||
return (png_structp)NULL;
|
||||
}
|
||||
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
if (setjmp(jmpbuf))
|
||||
#else
|
||||
@@ -60,10 +66,11 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
#endif
|
||||
|
||||
png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
|
||||
|
||||
@@ -110,17 +117,24 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
void
|
||||
png_read_init(png_structp png_ptr)
|
||||
{
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
jmp_buf tmp_jmp; /* to save current jump buffer */
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_read_init\n");
|
||||
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
/* save jump buffer and error functions */
|
||||
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
|
||||
#endif
|
||||
|
||||
/* reset all variables to 0 */
|
||||
png_memset(png_ptr, 0, sizeof (png_struct));
|
||||
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
/* restore jump buffer */
|
||||
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
|
||||
#endif
|
||||
|
||||
/* initialize zbuf - compression buffer */
|
||||
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
|
||||
@@ -179,6 +193,63 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
for(;;)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_IHDR;
|
||||
PNG_IDAT;
|
||||
PNG_IEND;
|
||||
PNG_PLTE;
|
||||
#if defined(PNG_READ_bKGD_SUPPORTED)
|
||||
PNG_bKGD;
|
||||
#endif
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED)
|
||||
PNG_cHRM;
|
||||
#endif
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED)
|
||||
PNG_gAMA;
|
||||
#endif
|
||||
#if defined(PNG_READ_hIST_SUPPORTED)
|
||||
PNG_hIST;
|
||||
#endif
|
||||
#if defined(PNG_READ_iCCP_SUPPORTED)
|
||||
PNG_iCCP;
|
||||
#endif
|
||||
#if defined(PNG_READ_iTXt_SUPPORTED)
|
||||
PNG_iTXt;
|
||||
#endif
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED)
|
||||
PNG_oFFs;
|
||||
#endif
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED)
|
||||
PNG_pCAL;
|
||||
#endif
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED)
|
||||
PNG_pHYs;
|
||||
#endif
|
||||
#if defined(PNG_READ_sBIT_SUPPORTED)
|
||||
PNG_sBIT;
|
||||
#endif
|
||||
#if defined(PNG_READ_sCAL_SUPPORTED)
|
||||
PNG_sCAL;
|
||||
#endif
|
||||
#if defined(PNG_READ_sPLT_SUPPORTED)
|
||||
PNG_sPLT;
|
||||
#endif
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
PNG_sRGB;
|
||||
#endif
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED)
|
||||
PNG_tEXt;
|
||||
#endif
|
||||
#if defined(PNG_READ_tIME_SUPPORTED)
|
||||
PNG_tIME;
|
||||
#endif
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED)
|
||||
PNG_tRNS;
|
||||
#endif
|
||||
#if defined(PNG_READ_zTXt_SUPPORTED)
|
||||
PNG_zTXt;
|
||||
#endif
|
||||
#endif /* PNG_GLOBAL_ARRAYS */
|
||||
png_byte chunk_length[4];
|
||||
png_uint_32 length;
|
||||
|
||||
@@ -196,10 +267,29 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
|
||||
*/
|
||||
if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
|
||||
png_handle_IHDR(png_ptr, info_ptr, length);
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
|
||||
png_handle_PLTE(png_ptr, info_ptr, length);
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
|
||||
png_handle_IEND(png_ptr, info_ptr, length);
|
||||
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
||||
else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
|
||||
{
|
||||
if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
|
||||
png_ptr->mode |= PNG_HAVE_IDAT;
|
||||
png_handle_unknown(png_ptr, info_ptr, length);
|
||||
if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
|
||||
png_ptr->mode |= PNG_HAVE_PLTE;
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
|
||||
{
|
||||
if (!(png_ptr->mode & PNG_HAVE_IHDR))
|
||||
png_error(png_ptr, "Missing IHDR before IDAT");
|
||||
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
|
||||
!(png_ptr->mode & PNG_HAVE_PLTE))
|
||||
png_error(png_ptr, "Missing PLTE before IDAT");
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
|
||||
png_handle_PLTE(png_ptr, info_ptr, length);
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
|
||||
{
|
||||
if (!(png_ptr->mode & PNG_HAVE_IHDR))
|
||||
@@ -236,6 +326,10 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
|
||||
png_handle_pCAL(png_ptr, info_ptr, length);
|
||||
#endif
|
||||
#if defined(PNG_READ_sCAL_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
|
||||
png_handle_sCAL(png_ptr, info_ptr, length);
|
||||
#endif
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
|
||||
png_handle_pHYs(png_ptr, info_ptr, length);
|
||||
@@ -248,6 +342,14 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
|
||||
png_handle_sRGB(png_ptr, info_ptr, length);
|
||||
#endif
|
||||
#if defined(PNG_READ_iCCP_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
|
||||
png_handle_iCCP(png_ptr, info_ptr, length);
|
||||
#endif
|
||||
#if defined(PNG_READ_sPLT_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
|
||||
png_handle_sPLT(png_ptr, info_ptr, length);
|
||||
#endif
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
|
||||
png_handle_tEXt(png_ptr, info_ptr, length);
|
||||
@@ -263,6 +365,10 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
|
||||
#if defined(PNG_READ_zTXt_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
|
||||
png_handle_zTXt(png_ptr, info_ptr, length);
|
||||
#endif
|
||||
#if defined(PNG_READ_iTXt_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
|
||||
png_handle_iTXt(png_ptr, info_ptr, length);
|
||||
#endif
|
||||
else
|
||||
png_handle_unknown(png_ptr, info_ptr, length);
|
||||
@@ -297,6 +403,11 @@ png_start_read_image(png_structp png_ptr)
|
||||
void
|
||||
png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_IDAT;
|
||||
const int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
|
||||
const int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
|
||||
#endif
|
||||
int ret;
|
||||
png_debug2(1, "in png_read_row (row %d, pass %d)\n",
|
||||
png_ptr->row_number, png_ptr->pass);
|
||||
@@ -343,7 +454,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
switch (png_ptr->pass)
|
||||
{
|
||||
case 0:
|
||||
if (png_ptr->row_number & 7)
|
||||
if (png_ptr->row_number & 0x07)
|
||||
{
|
||||
if (dsp_row != NULL)
|
||||
png_combine_row(png_ptr, dsp_row,
|
||||
@@ -353,7 +464,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if ((png_ptr->row_number & 7) || png_ptr->width < 5)
|
||||
if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
|
||||
{
|
||||
if (dsp_row != NULL)
|
||||
png_combine_row(png_ptr, dsp_row,
|
||||
@@ -363,7 +474,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if ((png_ptr->row_number & 7) != 4)
|
||||
if ((png_ptr->row_number & 0x07) != 4)
|
||||
{
|
||||
if (dsp_row != NULL && (png_ptr->row_number & 4))
|
||||
png_combine_row(png_ptr, dsp_row,
|
||||
@@ -465,11 +576,10 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
png_ptr->row_info.channels = png_ptr->channels;
|
||||
png_ptr->row_info.bit_depth = png_ptr->bit_depth;
|
||||
png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
|
||||
{
|
||||
png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
|
||||
(png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
|
||||
}
|
||||
png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
|
||||
(png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
|
||||
|
||||
if(png_ptr->row_buf[0])
|
||||
png_read_filter_row(png_ptr, &(png_ptr->row_info),
|
||||
png_ptr->row_buf + 1, png_ptr->prev_row + 1,
|
||||
(int)(png_ptr->row_buf[0]));
|
||||
@@ -531,7 +641,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
* not called png_set_interlace_handling(), the display_row buffer will
|
||||
* be ignored, so pass NULL to it.
|
||||
*
|
||||
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.4d.
|
||||
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.6e.
|
||||
*/
|
||||
|
||||
void
|
||||
@@ -580,7 +690,7 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
|
||||
* only call this function once. If you desire to have an image for
|
||||
* each pass of a interlaced image, use png_read_rows() instead.
|
||||
*
|
||||
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.4d.
|
||||
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.6e.
|
||||
*/
|
||||
void
|
||||
png_read_image(png_structp png_ptr, png_bytepp image)
|
||||
@@ -632,6 +742,64 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
do
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_IHDR;
|
||||
PNG_IDAT;
|
||||
PNG_IEND;
|
||||
PNG_PLTE;
|
||||
#if defined(PNG_READ_bKGD_SUPPORTED)
|
||||
PNG_bKGD;
|
||||
#endif
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED)
|
||||
PNG_cHRM;
|
||||
#endif
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED)
|
||||
PNG_gAMA;
|
||||
#endif
|
||||
#if defined(PNG_READ_hIST_SUPPORTED)
|
||||
PNG_hIST;
|
||||
#endif
|
||||
#if defined(PNG_READ_iCCP_SUPPORTED)
|
||||
PNG_iCCP;
|
||||
#endif
|
||||
#if defined(PNG_READ_iTXt_SUPPORTED)
|
||||
PNG_iTXt;
|
||||
#endif
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED)
|
||||
PNG_oFFs;
|
||||
#endif
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED)
|
||||
PNG_pCAL;
|
||||
#endif
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED)
|
||||
PNG_pHYs;
|
||||
#endif
|
||||
#if defined(PNG_READ_sBIT_SUPPORTED)
|
||||
PNG_sBIT;
|
||||
#endif
|
||||
#if defined(PNG_READ_sCAL_SUPPORTED)
|
||||
PNG_sCAL;
|
||||
#endif
|
||||
#if defined(PNG_READ_sPLT_SUPPORTED)
|
||||
PNG_sPLT;
|
||||
#endif
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
PNG_sRGB;
|
||||
#endif
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED)
|
||||
PNG_tEXt;
|
||||
#endif
|
||||
#if defined(PNG_READ_tIME_SUPPORTED)
|
||||
PNG_tIME;
|
||||
#endif
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED)
|
||||
PNG_tRNS;
|
||||
#endif
|
||||
#if defined(PNG_READ_zTXt_SUPPORTED)
|
||||
PNG_zTXt;
|
||||
#endif
|
||||
#endif /* PNG_GLOBAL_ARRAYS */
|
||||
|
||||
png_read_data(png_ptr, chunk_length, 4);
|
||||
length = png_get_uint_32(chunk_length);
|
||||
|
||||
@@ -642,6 +810,23 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
|
||||
png_handle_IHDR(png_ptr, info_ptr, length);
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
|
||||
png_handle_IEND(png_ptr, info_ptr, length);
|
||||
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
||||
else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
|
||||
{
|
||||
if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
|
||||
{
|
||||
if (length > 0 || png_ptr->mode & PNG_AFTER_IDAT)
|
||||
png_error(png_ptr, "Too many IDAT's found");
|
||||
}
|
||||
else
|
||||
png_ptr->mode |= PNG_AFTER_IDAT;
|
||||
png_handle_unknown(png_ptr, info_ptr, length);
|
||||
if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
|
||||
png_ptr->mode |= PNG_HAVE_PLTE;
|
||||
}
|
||||
#endif
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
|
||||
{
|
||||
/* Zero length IDATs are legal after the last IDAT has been
|
||||
@@ -654,8 +839,6 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
|
||||
png_handle_PLTE(png_ptr, info_ptr, length);
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
|
||||
png_handle_IEND(png_ptr, info_ptr, length);
|
||||
#if defined(PNG_READ_bKGD_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
|
||||
png_handle_bKGD(png_ptr, info_ptr, length);
|
||||
@@ -680,6 +863,10 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
|
||||
png_handle_pCAL(png_ptr, info_ptr, length);
|
||||
#endif
|
||||
#if defined(PNG_READ_sCAL_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
|
||||
png_handle_sCAL(png_ptr, info_ptr, length);
|
||||
#endif
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
|
||||
png_handle_pHYs(png_ptr, info_ptr, length);
|
||||
@@ -692,6 +879,14 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
|
||||
png_handle_sRGB(png_ptr, info_ptr, length);
|
||||
#endif
|
||||
#if defined(PNG_READ_iCCP_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
|
||||
png_handle_iCCP(png_ptr, info_ptr, length);
|
||||
#endif
|
||||
#if defined(PNG_READ_sPLT_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
|
||||
png_handle_sPLT(png_ptr, info_ptr, length);
|
||||
#endif
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
|
||||
png_handle_tEXt(png_ptr, info_ptr, length);
|
||||
@@ -707,6 +902,10 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
|
||||
#if defined(PNG_READ_zTXt_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
|
||||
png_handle_zTXt(png_ptr, info_ptr, length);
|
||||
#endif
|
||||
#if defined(PNG_READ_iTXt_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
|
||||
png_handle_iTXt(png_ptr, info_ptr, length);
|
||||
#endif
|
||||
else
|
||||
png_handle_unknown(png_ptr, info_ptr, length);
|
||||
@@ -722,7 +921,7 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
|
||||
png_infop info_ptr = NULL, end_info_ptr = NULL;
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_free_ptr free_fn = NULL;
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_destroy_read_struct\n");
|
||||
/* save jump buffer and error functions */
|
||||
@@ -743,8 +942,8 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
|
||||
|
||||
if (info_ptr != NULL)
|
||||
{
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
|
||||
png_free(png_ptr, info_ptr->text);
|
||||
#if defined(PNG_TEXT_SUPPORTED)
|
||||
png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
@@ -757,8 +956,8 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
|
||||
|
||||
if (end_info_ptr != NULL)
|
||||
{
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
|
||||
png_free(png_ptr, end_info_ptr->text);
|
||||
#if defined(PNG_READ_TEXT_SUPPORTED)
|
||||
png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
|
||||
#endif
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_destroy_struct_2((png_voidp)end_info_ptr, free_fn);
|
||||
@@ -783,7 +982,9 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
|
||||
void
|
||||
png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
|
||||
{
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
jmp_buf tmp_jmp;
|
||||
#endif
|
||||
png_error_ptr error_fn;
|
||||
png_error_ptr warning_fn;
|
||||
png_voidp error_ptr;
|
||||
@@ -813,16 +1014,19 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
|
||||
png_free(png_ptr, png_ptr->gamma_from_1);
|
||||
png_free(png_ptr, png_ptr->gamma_to_1);
|
||||
#endif
|
||||
if (png_ptr->flags & PNG_FLAG_FREE_PALETTE)
|
||||
if (png_ptr->free_me & PNG_FREE_PLTE)
|
||||
png_zfree(png_ptr, png_ptr->palette);
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED) || \
|
||||
png_ptr->free_me &= ~PNG_FREE_PLTE;
|
||||
#if defined(PNG_tRNS_SUPPORTED) || \
|
||||
defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
if (png_ptr->flags & PNG_FLAG_FREE_TRANS)
|
||||
if (png_ptr->free_me & PNG_FREE_TRNS)
|
||||
png_free(png_ptr, png_ptr->trans);
|
||||
png_ptr->free_me &= ~PNG_FREE_TRNS;
|
||||
#endif
|
||||
#if defined(PNG_READ_hIST_SUPPORTED)
|
||||
if (png_ptr->flags & PNG_FLAG_FREE_HIST)
|
||||
if (png_ptr->free_me & PNG_FREE_HIST)
|
||||
png_free(png_ptr, png_ptr->hist);
|
||||
png_ptr->free_me &= ~PNG_FREE_HIST;
|
||||
#endif
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED)
|
||||
if (png_ptr->gamma_16_table != NULL)
|
||||
@@ -860,7 +1064,7 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
|
||||
#endif
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
png_free(png_ptr, png_ptr->time_buffer);
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
#endif
|
||||
|
||||
inflateEnd(&png_ptr->zstream);
|
||||
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
|
||||
@@ -870,7 +1074,9 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
|
||||
/* Save the important info out of the png_struct, in case it is
|
||||
* being used again.
|
||||
*/
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
|
||||
#endif
|
||||
|
||||
error_fn = png_ptr->error_fn;
|
||||
warning_fn = png_ptr->warning_fn;
|
||||
@@ -888,7 +1094,10 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
|
||||
png_ptr->free_fn = free_fn;
|
||||
#endif
|
||||
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
@@ -896,3 +1105,138 @@ png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
|
||||
{
|
||||
png_ptr->read_row_fn = read_row_fn;
|
||||
}
|
||||
|
||||
#if defined(PNG_INFO_IMAGE_SUPPORTED)
|
||||
void png_read_png(png_structp png_ptr, png_infop info_ptr,
|
||||
int transforms,
|
||||
voidp params)
|
||||
{
|
||||
int row;
|
||||
|
||||
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
|
||||
/* invert the alpha channel from opacity to transparency */
|
||||
if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
|
||||
png_set_invert_alpha(png_ptr);
|
||||
#endif
|
||||
|
||||
/* The call to png_read_info() gives us all of the information from the
|
||||
* PNG file before the first IDAT (image data chunk).
|
||||
*/
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
|
||||
/* -------------- image transformations start here ------------------- */
|
||||
|
||||
#if defined(PNG_READ_16_TO_8_SUPPORTED)
|
||||
/* tell libpng to strip 16 bit/color files down to 8 bits/color */
|
||||
if (transforms & PNG_TRANSFORM_STRIP_16)
|
||||
png_set_strip_16(png_ptr);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
|
||||
/* Strip alpha bytes from the input data without combining with the
|
||||
* background (not recommended).
|
||||
*/
|
||||
if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
|
||||
png_set_strip_alpha(png_ptr);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
|
||||
/* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
|
||||
* byte into separate bytes (useful for paletted and grayscale images).
|
||||
*/
|
||||
if (transforms & PNG_TRANSFORM_PACKING)
|
||||
png_set_packing(png_ptr);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
|
||||
/* Change the order of packed pixels to least significant bit first
|
||||
* (not useful if you are using png_set_packing). */
|
||||
if (transforms & PNG_TRANSFORM_PACKSWAP)
|
||||
png_set_packswap(png_ptr);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_EXPAND_SUPPORTED)
|
||||
/* Expand paletted colors into true RGB triplets
|
||||
* Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel
|
||||
* Expand paletted or RGB images with transparency to full alpha
|
||||
* channels so the data will be available as RGBA quartets.
|
||||
*/
|
||||
if (transforms & PNG_TRANSFORM_EXPAND)
|
||||
if ((png_ptr->bit_depth < 8) ||
|
||||
(png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
|
||||
(png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
|
||||
png_set_expand(png_ptr);
|
||||
#endif
|
||||
|
||||
/* We don't handle background color or gamma transformation or dithering. */
|
||||
|
||||
#if defined(PNG_READ_INVERT_SUPPORTED)
|
||||
/* invert monochrome files to have 0 as white and 1 as black */
|
||||
if (transforms & PNG_TRANSFORM_INVERT_MONO)
|
||||
png_set_invert_mono(png_ptr);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SHIFT_SUPPORTED)
|
||||
/* If you want to shift the pixel values from the range [0,255] or
|
||||
* [0,65535] to the original [0,7] or [0,31], or whatever range the
|
||||
* colors were originally in:
|
||||
*/
|
||||
if ((transforms & PNG_TRANSFORM_SHIFT)
|
||||
&& png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
|
||||
{
|
||||
png_color_8p sig_bit;
|
||||
|
||||
png_get_sBIT(png_ptr, info_ptr, &sig_bit);
|
||||
png_set_shift(png_ptr, sig_bit);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_BGR_SUPPORTED)
|
||||
/* flip the RGB pixels to BGR (or RGBA to BGRA) */
|
||||
if (transforms & PNG_TRANSFORM_BGR)
|
||||
png_set_bgr(png_ptr);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
|
||||
/* swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
|
||||
if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
|
||||
png_set_swap_alpha(png_ptr);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SWAP_SUPPORTED)
|
||||
/* swap bytes of 16 bit files to least significant byte first */
|
||||
if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
|
||||
png_set_swap(png_ptr);
|
||||
#endif
|
||||
|
||||
/* We don't handle adding filler bytes */
|
||||
|
||||
/* Optional call to gamma correct and add the background to the palette
|
||||
* and update info structure. REQUIRED if you are expecting libpng to
|
||||
* update the palette for you (ie you selected such a transform above).
|
||||
*/
|
||||
png_read_update_info(png_ptr, info_ptr);
|
||||
|
||||
/* -------------- image transformations end here ------------------- */
|
||||
|
||||
if(info_ptr->row_pointers == NULL)
|
||||
{
|
||||
info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
|
||||
info_ptr->height * sizeof(png_bytep));
|
||||
info_ptr->free_me |= PNG_FREE_ROWS;
|
||||
}
|
||||
for (row = 0; row < (int)info_ptr->height; row++)
|
||||
info_ptr->row_pointers[row] = png_malloc(png_ptr,
|
||||
png_get_rowbytes(png_ptr, info_ptr));
|
||||
|
||||
png_read_image(png_ptr, info_ptr->row_pointers);
|
||||
info_ptr->valid |= PNG_INFO_IDAT;
|
||||
|
||||
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */
|
||||
png_read_end(png_ptr, info_ptr);
|
||||
|
||||
if(transforms == 0 || params == (voidp)NULL)
|
||||
/* quiet compiler warnings */ return;
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
6
pngrio.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngrio.c - functions for data input
|
||||
*
|
||||
* libpng 1.0.4d - October 6, 1999
|
||||
* libpng 1.0.6e - April 10, 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
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
*
|
||||
* This file provides a location for all input. Users who need
|
||||
* special handling are expected to write a function that has the same
|
||||
@@ -146,6 +146,6 @@ png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
|
||||
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
png_ptr->output_flush_fn = NULL;
|
||||
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
331
pngrtran.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngrtran.c - transforms the data in a row for PNG readers
|
||||
*
|
||||
* libpng 1.0.4d - October 6, 1999
|
||||
* libpng 1.0.6e - April 10, 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
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
*
|
||||
* This file contains functions optionally called by an application
|
||||
* in order to tell libpng how to handle data when reading a PNG.
|
||||
@@ -69,7 +69,8 @@ png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
|
||||
defined(PNG_FLOATING_POINT_SUPPORTED)
|
||||
/* handle alpha and tRNS via a background color */
|
||||
void
|
||||
png_set_background(png_structp png_ptr,
|
||||
@@ -92,13 +93,13 @@ png_set_background(png_structp png_ptr,
|
||||
/* Note: if need_expand is set and color_type is either RGB or RGB_ALPHA
|
||||
* (in which case need_expand is superfluous anyway), the background color
|
||||
* might actually be gray yet not be flagged as such. This is not a problem
|
||||
* for the current code, which uses PNG_FLAG_BACKGROUND_IS_GRAY only to
|
||||
* for the current code, which uses PNG_BACKGROUND_IS_GRAY only to
|
||||
* decide when to do the png_do_gray_to_rgb() transformation.
|
||||
*/
|
||||
if ((need_expand && !(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) ||
|
||||
(!need_expand && background_color->red == background_color->green &&
|
||||
background_color->red == background_color->blue))
|
||||
png_ptr->flags |= PNG_FLAG_BACKGROUND_IS_GRAY;
|
||||
png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -366,7 +367,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
|
||||
{
|
||||
int j, next_j;
|
||||
|
||||
if (num_new_palette & 1)
|
||||
if (num_new_palette & 0x01)
|
||||
{
|
||||
j = p->left;
|
||||
next_j = p->right;
|
||||
@@ -504,7 +505,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED)
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
|
||||
/* Transform the image from the file_gamma to the screen_gamma. We
|
||||
* only do transformations on images where the file_gamma and screen_gamma
|
||||
* are not close reciprocals, otherwise it slows things down slightly, and
|
||||
@@ -582,12 +583,24 @@ png_set_gray_to_rgb(png_structp png_ptr)
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
|
||||
#if defined(PNG_FLOATING_POINT_SUPPORTED)
|
||||
/* Convert a RGB image to a grayscale of the same width. This allows us,
|
||||
* for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image.
|
||||
*/
|
||||
|
||||
void
|
||||
png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
|
||||
double green)
|
||||
double green)
|
||||
{
|
||||
int red_fixed = (int)((float)red*100000.0 + 0.5);
|
||||
int green_fixed = (int)((float)green*100000.0 + 0.5);
|
||||
png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
|
||||
png_fixed_point red, png_fixed_point green)
|
||||
{
|
||||
png_debug(1, "in png_set_rgb_to_gray\n");
|
||||
switch(error_action)
|
||||
@@ -608,22 +621,26 @@ png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
|
||||
}
|
||||
#endif
|
||||
{
|
||||
png_byte red_byte = (png_byte)((float)red*255.0 + 0.5);
|
||||
png_byte green_byte = (png_byte)((float)green*255.0 + 0.5);
|
||||
if(red < 0.0 || green < 0.0)
|
||||
png_uint_16 red_int, green_int;
|
||||
if(red < 0 || green < 0)
|
||||
{
|
||||
red_byte = 54;
|
||||
green_byte = 183;
|
||||
red_int = 6968; /* .212671 * 32768 + .5 */
|
||||
green_int = 23434; /* .715160 * 32768 + .5 */
|
||||
}
|
||||
else if(red_byte + green_byte > 255)
|
||||
else if(red + green < 100000L)
|
||||
{
|
||||
red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
|
||||
green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
|
||||
}
|
||||
else
|
||||
{
|
||||
png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
|
||||
red_byte = 54;
|
||||
green_byte = 183;
|
||||
red_int = 6968;
|
||||
green_int = 23434;
|
||||
}
|
||||
png_ptr->rgb_to_gray_red_coeff = red_byte;
|
||||
png_ptr->rgb_to_gray_green_coeff = green_byte;
|
||||
png_ptr->rgb_to_gray_blue_coeff = 255 - red_byte - green_byte;
|
||||
png_ptr->rgb_to_gray_red_coeff = red_int;
|
||||
png_ptr->rgb_to_gray_green_coeff = green_int;
|
||||
png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -656,7 +673,8 @@ png_init_read_transformations(png_structp png_ptr)
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_BACKGROUND_EXPAND)
|
||||
if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
|
||||
(png_ptr->transformations & PNG_EXPAND))
|
||||
{
|
||||
if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
|
||||
{
|
||||
@@ -706,7 +724,7 @@ png_init_read_transformations(png_structp png_ptr)
|
||||
int i,istop;
|
||||
istop=(int)png_ptr->num_trans;
|
||||
for (i=0; i<istop; i++)
|
||||
png_ptr->trans[i] = 255 - png_ptr->trans[i];
|
||||
png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -718,7 +736,7 @@ png_init_read_transformations(png_structp png_ptr)
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
png_ptr->background_1 = png_ptr->background;
|
||||
#endif
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED)
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
|
||||
if (png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY))
|
||||
{
|
||||
png_build_gamma_table(png_ptr);
|
||||
@@ -731,7 +749,6 @@ png_init_read_transformations(png_structp png_ptr)
|
||||
png_colorp palette = png_ptr->palette;
|
||||
int num_palette = png_ptr->num_palette;
|
||||
int i;
|
||||
|
||||
if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
|
||||
{
|
||||
back.red = png_ptr->gamma_table[png_ptr->background.red];
|
||||
@@ -789,7 +806,6 @@ png_init_read_transformations(png_structp png_ptr)
|
||||
back_1.blue = (png_byte)(pow(
|
||||
(double)png_ptr->background.blue/255, g) * 255.0 + .5);
|
||||
}
|
||||
|
||||
for (i = 0; i < num_palette; i++)
|
||||
{
|
||||
if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
|
||||
@@ -897,8 +913,8 @@ png_init_read_transformations(png_structp png_ptr)
|
||||
#endif
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
/* No GAMMA transformation */
|
||||
if (png_ptr->transformations & PNG_BACKGROUND &&
|
||||
color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
if ((png_ptr->transformations & PNG_BACKGROUND) &&
|
||||
(color_type == PNG_COLOR_TYPE_PALETTE))
|
||||
{
|
||||
int i;
|
||||
int istop = (int)png_ptr->num_trans;
|
||||
@@ -931,7 +947,7 @@ png_init_read_transformations(png_structp png_ptr)
|
||||
|
||||
#if defined(PNG_READ_SHIFT_SUPPORTED)
|
||||
if ((png_ptr->transformations & PNG_SHIFT) &&
|
||||
color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
(color_type == PNG_COLOR_TYPE_PALETTE))
|
||||
{
|
||||
png_uint_16 i;
|
||||
png_uint_16 istop = png_ptr->num_palette;
|
||||
@@ -998,11 +1014,18 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_GAMMA)
|
||||
{
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
info_ptr->gamma = png_ptr->gamma;
|
||||
#endif
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
info_ptr->int_gamma = png_ptr->int_gamma;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_16_TO_8_SUPPORTED)
|
||||
if ((png_ptr->transformations & PNG_16_TO_8) && info_ptr->bit_depth == 16)
|
||||
if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
|
||||
info_ptr->bit_depth = 8;
|
||||
#endif
|
||||
|
||||
@@ -1019,7 +1042,7 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_PACK_SUPPORTED)
|
||||
if ((png_ptr->transformations & PNG_PACK) && info_ptr->bit_depth < 8)
|
||||
if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
|
||||
info_ptr->bit_depth = 8;
|
||||
#endif
|
||||
|
||||
@@ -1050,10 +1073,10 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
#if defined(PNG_READ_FILLER_SUPPORTED)
|
||||
/* STRIP_ALPHA and FILLER allowed: MASK_ALPHA bit stripped above */
|
||||
if (png_ptr->transformations & PNG_FILLER &&
|
||||
(info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
|
||||
info_ptr->color_type == PNG_COLOR_TYPE_GRAY))
|
||||
++info_ptr->channels;
|
||||
if ((png_ptr->transformations & PNG_FILLER) &&
|
||||
((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
|
||||
(info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
|
||||
info_ptr->channels++;
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
|
||||
@@ -1170,8 +1193,8 @@ From Andreas Dilger e-mail to png-implement, 26 March 1998:
|
||||
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
|
||||
/* if gray -> RGB, do so now only if background is non-gray; else do later
|
||||
* for performance reasons */
|
||||
if (png_ptr->transformations & PNG_GRAY_TO_RGB &&
|
||||
!(png_ptr->flags & PNG_FLAG_BACKGROUND_IS_GRAY))
|
||||
if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
|
||||
!(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
|
||||
png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
@@ -1244,8 +1267,8 @@ From Andreas Dilger e-mail to png-implement, 26 March 1998:
|
||||
|
||||
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
|
||||
/* if gray -> RGB, do so now only if we did not do so above */
|
||||
if (png_ptr->transformations & PNG_GRAY_TO_RGB &&
|
||||
png_ptr->flags & PNG_FLAG_BACKGROUND_IS_GRAY)
|
||||
if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
|
||||
(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
|
||||
png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
@@ -1290,7 +1313,7 @@ From Andreas Dilger e-mail to png-implement, 26 March 1998:
|
||||
png_ptr->row_info.channels = png_ptr->user_transform_channels;
|
||||
png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
|
||||
png_ptr->row_info.channels);
|
||||
png_ptr->row_info.rowbytes = (png_ptr->row_info.width *
|
||||
png_ptr->row_info.rowbytes = (png_ptr->row_info.width *
|
||||
png_ptr->row_info.pixel_depth+7)>>3;
|
||||
}
|
||||
#endif
|
||||
@@ -1323,10 +1346,10 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
|
||||
png_bytep dp = row + (png_size_t)row_width - 1;
|
||||
png_uint_32 shift = 7 - (int)((row_width + 7) & 7);
|
||||
png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
*dp = (png_byte)((*sp >> shift) & 0x1);
|
||||
*dp = (png_byte)((*sp >> shift) & 0x01);
|
||||
if (shift == 7)
|
||||
{
|
||||
shift = 0;
|
||||
@@ -1344,10 +1367,10 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
|
||||
|
||||
png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
|
||||
png_bytep dp = row + (png_size_t)row_width - 1;
|
||||
png_uint_32 shift = (int)((3 - ((row_width + 3) & 3)) << 1);
|
||||
png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
*dp = (png_byte)((*sp >> shift) & 0x3);
|
||||
*dp = (png_byte)((*sp >> shift) & 0x03);
|
||||
if (shift == 6)
|
||||
{
|
||||
shift = 0;
|
||||
@@ -1364,10 +1387,10 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
|
||||
png_bytep dp = row + (png_size_t)row_width - 1;
|
||||
png_uint_32 shift = (int)((1 - ((row_width + 1) & 1)) << 2);
|
||||
png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
*dp = (png_byte)((*sp >> shift) & 0xf);
|
||||
*dp = (png_byte)((*sp >> shift) & 0x0f);
|
||||
if (shift == 4)
|
||||
{
|
||||
shift = 0;
|
||||
@@ -1456,8 +1479,8 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
|
||||
png_bytep bp = row;
|
||||
png_uint_32 i;
|
||||
png_uint_32 istop = row_info->rowbytes;
|
||||
png_byte mask = (png_byte)(((int)0xf0 >> shift[0]) & (int)0xf0) |
|
||||
(png_byte)((int)0xf >> shift[0]);
|
||||
png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
|
||||
(png_byte)((int)0xf >> shift[0]));
|
||||
|
||||
for (i = 0; i < istop; i++)
|
||||
{
|
||||
@@ -1666,10 +1689,16 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
*(--dp) = 255 - *(--sp);
|
||||
*(--dp) = (png_byte)(255 - *(--sp));
|
||||
|
||||
/* This does nothing:
|
||||
*(--dp) = *(--sp);
|
||||
*(--dp) = *(--sp);
|
||||
*(--dp) = *(--sp);
|
||||
We can replace it with:
|
||||
*/
|
||||
sp-=3;
|
||||
dp=sp;
|
||||
}
|
||||
}
|
||||
/* This inverts the alpha channel in RRGGBBAA */
|
||||
@@ -1681,14 +1710,20 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
*(--dp) = 255 - *(--sp);
|
||||
*(--dp) = 255 - *(--sp);
|
||||
*(--dp) = (png_byte)(255 - *(--sp));
|
||||
*(--dp) = (png_byte)(255 - *(--sp));
|
||||
|
||||
/* This does nothing:
|
||||
*(--dp) = *(--sp);
|
||||
*(--dp) = *(--sp);
|
||||
*(--dp) = *(--sp);
|
||||
*(--dp) = *(--sp);
|
||||
*(--dp) = *(--sp);
|
||||
*(--dp) = *(--sp);
|
||||
We can replace it with:
|
||||
*/
|
||||
sp-=6;
|
||||
dp=sp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1703,7 +1738,7 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
*(--dp) = 255 - *(--sp);
|
||||
*(--dp) = (png_byte)(255 - *(--sp));
|
||||
*(--dp) = *(--sp);
|
||||
}
|
||||
}
|
||||
@@ -1716,10 +1751,14 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
*(--dp) = 255 - *(--sp);
|
||||
*(--dp) = 255 - *(--sp);
|
||||
*(--dp) = (png_byte)(255 - *(--sp));
|
||||
*(--dp) = (png_byte)(255 - *(--sp));
|
||||
/*
|
||||
*(--dp) = *(--sp);
|
||||
*(--dp) = *(--sp);
|
||||
*/
|
||||
sp-=2;
|
||||
dp=sp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1988,7 +2027,7 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
|
||||
/* reduce RGB files to grayscale, with or without alpha
|
||||
/* reduce RGB files to grayscale, with or without alpha
|
||||
* using the equation given in Poynton's ColorFAQ at
|
||||
* <http://www.inforamp.net/~poynton/>
|
||||
* Copyright (c) 1998-01-04 Charles Poynton poynton@inforamp.net
|
||||
@@ -1996,12 +2035,12 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
|
||||
* Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
|
||||
*
|
||||
* We approximate this with
|
||||
*
|
||||
* Y = 0.211 * R + 0.715 * G + 0.074 * B
|
||||
*
|
||||
* Y = 0.21268 * R + 0.7151 * G + 0.07217 * B
|
||||
*
|
||||
* which can be expressed with integers as
|
||||
*
|
||||
* Y = (54 * R + 183 * G + 19 * B)/256
|
||||
* Y = (6969 * R + 23434 * G + 2365 * B)/32768
|
||||
*
|
||||
* The calculation is to be done in a linear colorspace.
|
||||
*
|
||||
@@ -2023,9 +2062,9 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
|
||||
#endif
|
||||
(row_info->color_type & PNG_COLOR_MASK_COLOR))
|
||||
{
|
||||
png_byte rc = png_ptr->rgb_to_gray_red_coeff;
|
||||
png_byte gc = png_ptr->rgb_to_gray_green_coeff;
|
||||
png_byte bc = png_ptr->rgb_to_gray_blue_coeff;
|
||||
png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
|
||||
png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
|
||||
png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
|
||||
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
|
||||
{
|
||||
@@ -2046,7 +2085,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
rgb_error |= 1;
|
||||
*(dp++) = png_ptr->gamma_from_1[
|
||||
(rc*red+gc*green+bc*blue)>>8];
|
||||
(rc*red+gc*green+bc*blue)>>15];
|
||||
}
|
||||
else
|
||||
*(dp++) = *(sp-1);
|
||||
@@ -2065,14 +2104,14 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
|
||||
if(red != green || red != blue)
|
||||
{
|
||||
rgb_error |= 1;
|
||||
*(dp++) = (rc*red+gc*green+bc*blue)>>8;
|
||||
*(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
|
||||
}
|
||||
else
|
||||
*(dp++) = *(sp-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
else /* RGB bit_depth == 16 */
|
||||
{
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
@@ -2085,9 +2124,9 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_uint_16 red, green, blue, w;
|
||||
|
||||
red = ((*(sp))<<8) | *(sp+1); sp+=2;
|
||||
green = ((*(sp))<<8) | *(sp+1); sp+=2;
|
||||
blue = ((*(sp))<<8) | *(sp+1); sp+=2;
|
||||
red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
|
||||
green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
|
||||
blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
|
||||
|
||||
if(red == green && red == blue)
|
||||
w = red;
|
||||
@@ -2097,17 +2136,17 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
|
||||
png_ptr->gamma_shift][red>>8];
|
||||
png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
|
||||
png_ptr->gamma_shift][green>>8];
|
||||
png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
|
||||
png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
|
||||
png_ptr->gamma_shift][blue>>8];
|
||||
png_uint_16 gray16 = (rc * red_1 + gc * green_1
|
||||
+ bc * blue_1)>>8;
|
||||
png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
|
||||
+ bc*blue_1)>>15);
|
||||
w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
|
||||
png_ptr->gamma_shift][gray16 >> 8];
|
||||
rgb_error |= 1;
|
||||
}
|
||||
|
||||
*(dp++) = (w>>8) & 0xff;
|
||||
*(dp++) = w & 0xff;
|
||||
|
||||
*(dp++) = (png_byte)((w>>8) & 0xff);
|
||||
*(dp++) = (png_byte)(w & 0xff);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -2119,15 +2158,15 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_uint_16 red, green, blue, gray16;
|
||||
|
||||
red = ((*(sp))<<8) | *(sp+1); sp+=2;
|
||||
green = ((*(sp))<<8) | *(sp+1); sp+=2;
|
||||
blue = ((*(sp))<<8) | *(sp+1); sp+=2;
|
||||
red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
|
||||
green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
|
||||
blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
|
||||
|
||||
if(red != green || red != blue)
|
||||
rgb_error |= 1;
|
||||
gray16 = (rc * red + gc * green + bc * blue)>>8;
|
||||
*(dp++) = (gray16>>8) & 0xff;
|
||||
*(dp++) = gray16 & 0xff;
|
||||
gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
|
||||
*(dp++) = (png_byte)((gray16>>8) & 0xff);
|
||||
*(dp++) = (png_byte)(gray16 & 0xff);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2149,7 +2188,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
|
||||
if(red != green || red != blue)
|
||||
rgb_error |= 1;
|
||||
*(dp++) = png_ptr->gamma_from_1
|
||||
[(rc*red + gc*green + bc*blue)>>8];
|
||||
[(rc*red + gc*green + bc*blue)>>15];
|
||||
*(dp++) = *(sp++); /* alpha */
|
||||
}
|
||||
}
|
||||
@@ -2165,7 +2204,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
|
||||
png_byte blue = *(sp++);
|
||||
if(red != green || red != blue)
|
||||
rgb_error |= 1;
|
||||
*(dp++) = (gc*red + gc*green + bc*blue)>>8;
|
||||
*(dp++) = (png_byte)((gc*red + gc*green + bc*blue)>>8);
|
||||
*(dp++) = *(sp++); /* alpha */
|
||||
}
|
||||
}
|
||||
@@ -2182,9 +2221,9 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_uint_16 red, green, blue, w;
|
||||
|
||||
red = ((*(sp))<<8) | *(sp+1); sp+=2;
|
||||
green = ((*(sp))<<8) | *(sp+1); sp+=2;
|
||||
blue = ((*(sp))<<8) | *(sp+1); sp+=2;
|
||||
red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
|
||||
green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
|
||||
blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
|
||||
|
||||
if(red == green && red == blue)
|
||||
w = red;
|
||||
@@ -2194,17 +2233,17 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
|
||||
png_ptr->gamma_shift][red>>8];
|
||||
png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
|
||||
png_ptr->gamma_shift][green>>8];
|
||||
png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
|
||||
png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
|
||||
png_ptr->gamma_shift][blue>>8];
|
||||
png_uint_16 gray16 = (rc * red_1 + gc * green_1
|
||||
+ bc * blue_1)>>8;
|
||||
png_uint_16 gray16 = (png_uint_16)((rc * red_1
|
||||
+ gc * green_1 + bc * blue_1)>>15);
|
||||
w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
|
||||
png_ptr->gamma_shift][gray16 >> 8];
|
||||
rgb_error |= 1;
|
||||
}
|
||||
|
||||
*(dp++) = (w>>8) & 0xff;
|
||||
*(dp++) = w & 0xff;
|
||||
|
||||
*(dp++) = (png_byte)((w>>8) & 0xff);
|
||||
*(dp++) = (png_byte)(w & 0xff);
|
||||
*(dp++) = *(sp++); /* alpha */
|
||||
*(dp++) = *(sp++);
|
||||
}
|
||||
@@ -2217,14 +2256,14 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
png_uint_16 red, green, blue, gray16;
|
||||
red = (*(sp)<<8) | *(sp+1); sp+=2;
|
||||
green = (*(sp)<<8) | *(sp+1); sp+=2;
|
||||
blue = (*(sp)<<8) | *(sp+1); sp+=2;
|
||||
red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
|
||||
green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
|
||||
blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
|
||||
if(red != green || red != blue)
|
||||
rgb_error |= 1;
|
||||
gray16 = (rc * red + gc * green + bc * blue)>>8;
|
||||
*(dp++) = (gray16>>8) & 0xff;
|
||||
*(dp++) = gray16 & 0xff;
|
||||
gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
|
||||
*(dp++) = (png_byte)((gray16>>8) & 0xff);
|
||||
*(dp++) = (png_byte)(gray16 & 0xff);
|
||||
*(dp++) = *(sp++); /* alpha */
|
||||
*(dp++) = *(sp++);
|
||||
}
|
||||
@@ -2298,7 +2337,8 @@ png_correct_palette(png_structp png_ptr, png_colorp palette,
|
||||
int num_palette)
|
||||
{
|
||||
png_debug(1, "in png_correct_palette\n");
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
|
||||
defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
|
||||
if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
|
||||
{
|
||||
png_color back, back_1;
|
||||
@@ -2510,7 +2550,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
|
||||
shift = 7;
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
if ((png_uint_16)((*sp >> shift) & 0x1)
|
||||
if ((png_uint_16)((*sp >> shift) & 0x01)
|
||||
== trans_values->gray)
|
||||
{
|
||||
*sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
|
||||
@@ -2535,7 +2575,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
|
||||
shift = 6;
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
if ((png_uint_16)((*sp >> shift) & 0x3)
|
||||
if ((png_uint_16)((*sp >> shift) & 0x03)
|
||||
== trans_values->gray)
|
||||
{
|
||||
*sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
|
||||
@@ -2543,9 +2583,9 @@ png_do_background(png_row_infop row_info, png_bytep row,
|
||||
}
|
||||
else
|
||||
{
|
||||
png_byte p = (*sp >> shift) & 0x3;
|
||||
png_byte g = (gamma_table [p | (p << 2) | (p << 4) |
|
||||
(p << 6)] >> 6) & 0x3;
|
||||
png_byte p = (png_byte)((*sp >> shift) & 0x03);
|
||||
png_byte g = (png_byte)((gamma_table [p | (p << 2) |
|
||||
(p << 4) | (p << 6)] >> 6) & 0x03);
|
||||
*sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
|
||||
*sp |= (png_byte)(g << shift);
|
||||
}
|
||||
@@ -2565,7 +2605,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
|
||||
shift = 6;
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
if ((png_uint_16)((*sp >> shift) & 0x3)
|
||||
if ((png_uint_16)((*sp >> shift) & 0x03)
|
||||
== trans_values->gray)
|
||||
{
|
||||
*sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
|
||||
@@ -2591,7 +2631,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
|
||||
shift = 4;
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
if ((png_uint_16)((*sp >> shift) & 0xf)
|
||||
if ((png_uint_16)((*sp >> shift) & 0x0f)
|
||||
== trans_values->gray)
|
||||
{
|
||||
*sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
|
||||
@@ -2599,8 +2639,9 @@ png_do_background(png_row_infop row_info, png_bytep row,
|
||||
}
|
||||
else
|
||||
{
|
||||
png_byte p = (*sp >> shift) & 0xf;
|
||||
png_byte g = (gamma_table[p | (p << 4)] >> 4) & 0xf;
|
||||
png_byte p = (png_byte)((*sp >> shift) & 0x0f);
|
||||
png_byte g = (png_byte)((gamma_table[p |
|
||||
(p << 4)] >> 4) & 0x0f);
|
||||
*sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
|
||||
*sp |= (png_byte)(g << shift);
|
||||
}
|
||||
@@ -2620,7 +2661,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
|
||||
shift = 4;
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
if ((png_uint_16)((*sp >> shift) & 0xf)
|
||||
if ((png_uint_16)((*sp >> shift) & 0x0f)
|
||||
== trans_values->gray)
|
||||
{
|
||||
*sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
|
||||
@@ -2679,7 +2720,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
|
||||
{
|
||||
png_uint_16 v;
|
||||
|
||||
v = ((png_uint_16)(*sp) << 8) + *(sp + 1);
|
||||
v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
|
||||
if (v == trans_values->gray)
|
||||
{
|
||||
/* background is already in screen gamma */
|
||||
@@ -2702,7 +2743,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
|
||||
{
|
||||
png_uint_16 v;
|
||||
|
||||
v = ((png_uint_16)(*sp) << 8) + *(sp + 1);
|
||||
v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
|
||||
if (v == trans_values->gray)
|
||||
{
|
||||
*sp = (png_byte)((background->gray >> 8) & 0xff);
|
||||
@@ -2766,9 +2807,9 @@ png_do_background(png_row_infop row_info, png_bytep row,
|
||||
sp = row;
|
||||
for (i = 0; i < row_width; i++, sp += 6)
|
||||
{
|
||||
png_uint_16 r = ((png_uint_16)(*sp) << 8) + *(sp + 1);
|
||||
png_uint_16 g = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
|
||||
png_uint_16 b = ((png_uint_16)(*(sp + 4)) << 8) + *(sp + 5);
|
||||
png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
|
||||
png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
|
||||
png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
|
||||
if (r == trans_values->red && g == trans_values->green &&
|
||||
b == trans_values->blue)
|
||||
{
|
||||
@@ -2800,9 +2841,9 @@ png_do_background(png_row_infop row_info, png_bytep row,
|
||||
sp = row;
|
||||
for (i = 0; i < row_width; i++, sp += 6)
|
||||
{
|
||||
png_uint_16 r = ((png_uint_16)(*sp) << 8) + *(sp + 1);
|
||||
png_uint_16 g = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
|
||||
png_uint_16 b = ((png_uint_16)(*(sp + 4)) << 8) + *(sp + 5);
|
||||
png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
|
||||
png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
|
||||
png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
|
||||
|
||||
if (r == trans_values->red && g == trans_values->green &&
|
||||
b == trans_values->blue)
|
||||
@@ -2886,7 +2927,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
|
||||
dp = row;
|
||||
for (i = 0; i < row_width; i++, sp += 4, dp += 2)
|
||||
{
|
||||
png_uint_16 a = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
|
||||
png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
|
||||
|
||||
if (a == (png_uint_16)0xffff)
|
||||
{
|
||||
@@ -2921,7 +2962,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
|
||||
dp = row;
|
||||
for (i = 0; i < row_width; i++, sp += 4, dp += 2)
|
||||
{
|
||||
png_uint_16 a = ((png_uint_16)(*(sp + 2)) << 8) + *(sp + 3);
|
||||
png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
|
||||
if (a == (png_uint_16)0xffff)
|
||||
{
|
||||
png_memcpy(dp, sp, 2);
|
||||
@@ -2935,7 +2976,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
|
||||
{
|
||||
png_uint_16 g, v;
|
||||
|
||||
g = ((png_uint_16)(*sp) << 8) + *(sp + 1);
|
||||
g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
|
||||
png_composite_16(v, g, a, background_1->gray);
|
||||
*dp = (png_byte)((v >> 8) & 0xff);
|
||||
*(dp + 1) = (png_byte)(v & 0xff);
|
||||
@@ -3104,11 +3145,11 @@ png_do_background(png_row_infop row_info, png_bytep row,
|
||||
{
|
||||
png_uint_16 v;
|
||||
|
||||
png_uint_16 r = ((png_uint_16)(*sp) << 8) + *(sp + 1);
|
||||
png_uint_16 g = ((png_uint_16)(*(sp + 2)) << 8)
|
||||
+ *(sp + 3);
|
||||
png_uint_16 b = ((png_uint_16)(*(sp + 4)) << 8)
|
||||
+ *(sp + 5);
|
||||
png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
|
||||
png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
|
||||
+ *(sp + 3));
|
||||
png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
|
||||
+ *(sp + 5));
|
||||
|
||||
png_composite_16(v, r, a, background->red);
|
||||
*dp = (png_byte)((v >> 8) & 0xff);
|
||||
@@ -3277,10 +3318,11 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
|
||||
int c = *sp & 0x0c;
|
||||
int d = *sp & 0x03;
|
||||
|
||||
*sp = ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
|
||||
*sp = (png_byte)(
|
||||
((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
|
||||
((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
|
||||
((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
|
||||
((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) );
|
||||
((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
|
||||
sp++;
|
||||
}
|
||||
}
|
||||
@@ -3292,8 +3334,8 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
|
||||
int msb = *sp & 0xf0;
|
||||
int lsb = *sp & 0x0f;
|
||||
|
||||
*sp = (((int)gamma_table[msb | (msb >> 4)]) & 0xf0) |
|
||||
(((int)gamma_table[(lsb << 4) | lsb]) >> 4);
|
||||
*sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
|
||||
| (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
|
||||
sp++;
|
||||
}
|
||||
}
|
||||
@@ -3352,10 +3394,10 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
|
||||
{
|
||||
sp = row + (png_size_t)((row_width - 1) >> 3);
|
||||
dp = row + (png_size_t)row_width - 1;
|
||||
shift = 7 - (int)((row_width + 7) & 7);
|
||||
shift = 7 - (int)((row_width + 7) & 0x07);
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
if ((*sp >> shift) & 0x1)
|
||||
if ((*sp >> shift) & 0x01)
|
||||
*dp = 1;
|
||||
else
|
||||
*dp = 0;
|
||||
@@ -3375,10 +3417,10 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
|
||||
{
|
||||
sp = row + (png_size_t)((row_width - 1) >> 2);
|
||||
dp = row + (png_size_t)row_width - 1;
|
||||
shift = (int)((3 - ((row_width + 3) & 3)) << 1);
|
||||
shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
value = (*sp >> shift) & 0x3;
|
||||
value = (*sp >> shift) & 0x03;
|
||||
*dp = (png_byte)value;
|
||||
if (shift == 6)
|
||||
{
|
||||
@@ -3396,10 +3438,10 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
|
||||
{
|
||||
sp = row + (png_size_t)((row_width - 1) >> 1);
|
||||
dp = row + (png_size_t)row_width - 1;
|
||||
shift = (int)((row_width & 1) << 2);
|
||||
shift = (int)((row_width & 0x01) << 2);
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
value = (*sp >> shift) & 0xf;
|
||||
value = (*sp >> shift) & 0x0f;
|
||||
*dp = (png_byte)value;
|
||||
if (shift == 4)
|
||||
{
|
||||
@@ -3487,7 +3529,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
|
||||
{
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
|
||||
{
|
||||
png_uint_16 gray = trans_value ? trans_value->gray : 0;
|
||||
png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
|
||||
|
||||
if (row_info->bit_depth < 8)
|
||||
{
|
||||
@@ -3495,13 +3537,13 @@ png_do_expand(png_row_infop row_info, png_bytep row,
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
gray *= 0xff;
|
||||
gray = (png_uint_16)(gray*0xff);
|
||||
sp = row + (png_size_t)((row_width - 1) >> 3);
|
||||
dp = row + (png_size_t)row_width - 1;
|
||||
shift = 7 - (int)((row_width + 7) & 7);
|
||||
shift = 7 - (int)((row_width + 7) & 0x07);
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
if ((*sp >> shift) & 0x1)
|
||||
if ((*sp >> shift) & 0x01)
|
||||
*dp = 0xff;
|
||||
else
|
||||
*dp = 0;
|
||||
@@ -3519,13 +3561,13 @@ png_do_expand(png_row_infop row_info, png_bytep row,
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
gray *= 0x55;
|
||||
gray = (png_uint_16)(gray*0x55);
|
||||
sp = row + (png_size_t)((row_width - 1) >> 2);
|
||||
dp = row + (png_size_t)row_width - 1;
|
||||
shift = (int)((3 - ((row_width + 3) & 3)) << 1);
|
||||
shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
value = (*sp >> shift) & 0x3;
|
||||
value = (*sp >> shift) & 0x03;
|
||||
*dp = (png_byte)(value | (value << 2) | (value << 4) |
|
||||
(value << 6));
|
||||
if (shift == 6)
|
||||
@@ -3542,13 +3584,13 @@ png_do_expand(png_row_infop row_info, png_bytep row,
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
gray *= 0x11;
|
||||
gray = (png_uint_16)(gray*0x11);
|
||||
sp = row + (png_size_t)((row_width - 1) >> 1);
|
||||
dp = row + (png_size_t)row_width - 1;
|
||||
shift = (int)((1 - ((row_width + 1) & 1)) << 2);
|
||||
shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
value = (*sp >> shift) & 0xf;
|
||||
value = (*sp >> shift) & 0x0f;
|
||||
*dp = (png_byte)(value | (value << 4));
|
||||
if (shift == 4)
|
||||
{
|
||||
@@ -3762,6 +3804,7 @@ png_do_dither(png_row_infop row_info, png_bytep row,
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED)
|
||||
static int png_gamma_shift[] =
|
||||
{0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0};
|
||||
@@ -3798,7 +3841,7 @@ png_build_gamma_table(png_structp png_ptr)
|
||||
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
|
||||
defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
|
||||
if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
|
||||
if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
|
||||
{
|
||||
|
||||
g = 1.0 / (png_ptr->gamma);
|
||||
@@ -3812,7 +3855,7 @@ png_build_gamma_table(png_structp png_ptr)
|
||||
g) * 255.0 + .5);
|
||||
}
|
||||
|
||||
|
||||
|
||||
png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
|
||||
(png_uint_32)256);
|
||||
|
||||
@@ -3981,4 +4024,6 @@ png_build_gamma_table(png_structp png_ptr)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* To do: install integer version of png_build_gamma_table here */
|
||||
#endif
|
||||
|
||||
|
||||
1033
pngrutil.c
437
pngset.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngset.c - storage of image information into info struct
|
||||
*
|
||||
* libpng 1.0.4d - October 6, 1999
|
||||
* libpng 1.0.6e - April 10, 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
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
*
|
||||
* The functions here are used during reads to store data from the file
|
||||
* into the info struct, and during writes to store application data
|
||||
@@ -16,7 +16,7 @@
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
|
||||
#if defined(PNG_READ_bKGD_SUPPORTED) || defined(PNG_WRITE_bKGD_SUPPORTED)
|
||||
#if defined(PNG_bKGD_SUPPORTED)
|
||||
void
|
||||
png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
|
||||
{
|
||||
@@ -29,7 +29,8 @@ png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
|
||||
#if defined(PNG_cHRM_SUPPORTED)
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
void
|
||||
png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
double white_x, double white_y, double red_x, double red_y,
|
||||
@@ -47,11 +48,55 @@ png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
info_ptr->y_green = (float)green_y;
|
||||
info_ptr->x_blue = (float)blue_x;
|
||||
info_ptr->y_blue = (float)blue_y;
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
|
||||
info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
|
||||
info_ptr->int_x_red = (png_fixed_point)(red_x*100000.+0.5);
|
||||
info_ptr->int_y_red = (png_fixed_point)(red_y*100000.+0.5);
|
||||
info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
|
||||
info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
|
||||
info_ptr->int_x_blue = (png_fixed_point)(blue_x*100000.+0.5);
|
||||
info_ptr->int_y_blue = (png_fixed_point)(blue_y*100000.+0.5);
|
||||
#endif
|
||||
info_ptr->valid |= PNG_INFO_cHRM;
|
||||
}
|
||||
#endif
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
void
|
||||
png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
|
||||
png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
|
||||
png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
|
||||
png_fixed_point blue_x, png_fixed_point blue_y)
|
||||
{
|
||||
png_debug1(1, "in %s storage function\n", "cHRM");
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
|
||||
info_ptr->int_x_white = white_x;
|
||||
info_ptr->int_y_white = white_y;
|
||||
info_ptr->int_x_red = red_x;
|
||||
info_ptr->int_y_red = red_y;
|
||||
info_ptr->int_x_green = green_x;
|
||||
info_ptr->int_y_green = green_y;
|
||||
info_ptr->int_x_blue = blue_x;
|
||||
info_ptr->int_y_blue = blue_y;
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
info_ptr->x_white = (float)(white_x/100000.);
|
||||
info_ptr->y_white = (float)(white_y/100000.);
|
||||
info_ptr->x_red = (float)(red_x/100000.);
|
||||
info_ptr->y_red = (float)(red_y/100000.);
|
||||
info_ptr->x_green = (float)(green_x/100000.);
|
||||
info_ptr->y_green = (float)(green_y/100000.);
|
||||
info_ptr->x_blue = (float)(blue_x/100000.);
|
||||
info_ptr->y_blue = (float)(blue_y/100000.);
|
||||
#endif
|
||||
info_ptr->valid |= PNG_INFO_cHRM;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_gAMA_SUPPORTED)
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
void
|
||||
png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
|
||||
{
|
||||
@@ -60,11 +105,29 @@ png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
|
||||
return;
|
||||
|
||||
info_ptr->gamma = (float)file_gamma;
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
info_ptr->int_gamma = (int)(file_gamma*100000.+.5);
|
||||
#endif
|
||||
info_ptr->valid |= PNG_INFO_gAMA;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
void
|
||||
png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
|
||||
int_gamma)
|
||||
{
|
||||
png_debug1(1, "in %s storage function\n", "gAMA");
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
|
||||
#if defined(PNG_READ_hIST_SUPPORTED) || defined(PNG_WRITE_hIST_SUPPORTED)
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
info_ptr->gamma = (float)(int_gamma/100000.);
|
||||
#endif
|
||||
info_ptr->int_gamma = int_gamma;
|
||||
info_ptr->valid |= PNG_INFO_gAMA;
|
||||
}
|
||||
|
||||
#if defined(PNG_hIST_SUPPORTED)
|
||||
void
|
||||
png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
|
||||
{
|
||||
@@ -117,10 +180,10 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
|
||||
info_ptr->rowbytes = (info_ptr->width * info_ptr->pixel_depth + 7) >> 3;
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
|
||||
#if defined(PNG_oFFs_SUPPORTED)
|
||||
void
|
||||
png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 offset_x, png_uint_32 offset_y, int unit_type)
|
||||
png_int_32 offset_x, png_int_32 offset_y, int unit_type)
|
||||
{
|
||||
png_debug1(1, "in %s storage function\n", "oFFs");
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
@@ -133,7 +196,7 @@ png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED)
|
||||
#if defined(PNG_pCAL_SUPPORTED)
|
||||
void
|
||||
png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
|
||||
png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
|
||||
@@ -178,7 +241,53 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
|
||||
#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
void
|
||||
png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
|
||||
int unit, double width, double height)
|
||||
{
|
||||
png_debug1(1, "in %s storage function\n", "sCAL");
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
|
||||
info_ptr->scal_unit = (png_byte)unit;
|
||||
info_ptr->scal_pixel_width = width;
|
||||
info_ptr->scal_pixel_height = height;
|
||||
|
||||
info_ptr->valid |= PNG_INFO_sCAL;
|
||||
}
|
||||
#else
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
void
|
||||
png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
|
||||
int unit, png_charp swidth, png_charp sheight)
|
||||
{
|
||||
png_uint_32 length;
|
||||
|
||||
png_debug1(1, "in %s storage function\n", "sCAL");
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
|
||||
info_ptr->scal_unit = (png_byte)unit;
|
||||
|
||||
length = png_strlen(swidth) + 1;
|
||||
png_debug1(3, "allocating unit for info (%d bytes)\n", length);
|
||||
info_ptr->scal_s_width = (png_charp)png_malloc(png_ptr, length);
|
||||
png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
|
||||
|
||||
length = png_strlen(sheight) + 1;
|
||||
png_debug1(3, "allocating unit for info (%d bytes)\n", length);
|
||||
info_ptr->scal_s_width = (png_charp)png_malloc(png_ptr, length);
|
||||
png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
|
||||
|
||||
info_ptr->valid |= PNG_INFO_sCAL;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_pHYs_SUPPORTED)
|
||||
void
|
||||
png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 res_x, png_uint_32 res_y, int unit_type)
|
||||
@@ -198,16 +307,18 @@ void
|
||||
png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
|
||||
png_colorp palette, int num_palette)
|
||||
{
|
||||
|
||||
png_debug1(1, "in %s storage function\n", "PLTE");
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
|
||||
info_ptr->palette = palette;
|
||||
|
||||
info_ptr->num_palette = (png_uint_16)num_palette;
|
||||
info_ptr->valid |= PNG_INFO_PLTE;
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_sBIT_SUPPORTED) || defined(PNG_WRITE_sBIT_SUPPORTED)
|
||||
#if defined(PNG_sBIT_SUPPORTED)
|
||||
void
|
||||
png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
|
||||
png_color_8p sig_bit)
|
||||
@@ -221,7 +332,7 @@ png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
|
||||
#if defined(PNG_sRGB_SUPPORTED)
|
||||
void
|
||||
png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
|
||||
{
|
||||
@@ -232,15 +343,27 @@ png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
|
||||
info_ptr->srgb_intent = (png_byte)intent;
|
||||
info_ptr->valid |= PNG_INFO_sRGB;
|
||||
}
|
||||
|
||||
void
|
||||
png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
int intent)
|
||||
{
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
|
||||
#if defined(PNG_gAMA_SUPPORTED)
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
float file_gamma;
|
||||
#endif
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_fixed_point int_file_gamma;
|
||||
#endif
|
||||
#endif
|
||||
#if defined(PNG_cHRM_SUPPORTED)
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
|
||||
#endif
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
|
||||
int_green_y, int_blue_x, int_blue_y;
|
||||
#endif
|
||||
#endif
|
||||
png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
@@ -248,12 +371,33 @@ png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
|
||||
png_set_sRGB(png_ptr, info_ptr, intent);
|
||||
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
|
||||
#if defined(PNG_gAMA_SUPPORTED)
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
file_gamma = (float).45455;
|
||||
png_set_gAMA(png_ptr, info_ptr, file_gamma);
|
||||
#endif
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
int_file_gamma = 45455L;
|
||||
png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
|
||||
#if defined(PNG_cHRM_SUPPORTED)
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
int_white_x = 31270L;
|
||||
int_white_y = 32900L;
|
||||
int_red_x = 64000L;
|
||||
int_red_y = 33000L;
|
||||
int_green_x = 30000L;
|
||||
int_green_y = 60000L;
|
||||
int_blue_x = 15000L;
|
||||
int_blue_y = 6000L;
|
||||
|
||||
png_set_cHRM_fixed(png_ptr, info_ptr,
|
||||
int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
|
||||
int_blue_x, int_blue_y);
|
||||
#endif
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
white_x = (float).3127;
|
||||
white_y = (float).3290;
|
||||
red_x = (float).64;
|
||||
@@ -265,13 +409,37 @@ png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
|
||||
png_set_cHRM(png_ptr, info_ptr,
|
||||
white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
|
||||
defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
|
||||
#if defined(PNG_iCCP_SUPPORTED)
|
||||
void
|
||||
png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
|
||||
png_charp name, int compression_type,
|
||||
png_charp profile, png_uint_32 proflen)
|
||||
{
|
||||
png_debug1(1, "in %s storage function\n", "iCCP");
|
||||
if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
|
||||
return;
|
||||
|
||||
png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
|
||||
info_ptr->iccp_name = png_malloc(png_ptr, png_strlen(name)+1);
|
||||
strcpy(info_ptr->iccp_name, name);
|
||||
info_ptr->iccp_profile = png_malloc(png_ptr, proflen);
|
||||
png_memcpy(info_ptr->iccp_profile, profile, (png_size_t)proflen);
|
||||
info_ptr->iccp_proflen = proflen;
|
||||
/* 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;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_TEXT_SUPPORTED)
|
||||
void
|
||||
png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
|
||||
int num_text)
|
||||
@@ -316,36 +484,100 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
|
||||
|
||||
for (i = 0; i < num_text; i++)
|
||||
{
|
||||
png_size_t text_length,key_len,lang_len,lang_key_len;
|
||||
png_textp textp = &(info_ptr->text[info_ptr->num_text]);
|
||||
|
||||
if (text_ptr[i].text == NULL)
|
||||
text_ptr[i].text = (png_charp)"";
|
||||
if (text_ptr[i].key == (png_charp)NULL)
|
||||
continue;
|
||||
|
||||
if (text_ptr[i].text[0] == '\0')
|
||||
key_len = png_strlen(text_ptr[i].key);
|
||||
|
||||
if(text_ptr[i].compression > 0)
|
||||
{
|
||||
textp->text_length = 0;
|
||||
textp->compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
/* set iTXt data */
|
||||
lang_len = png_strlen(text_ptr[i].lang);
|
||||
lang_key_len = png_strlen(text_ptr[i].lang_key);
|
||||
}
|
||||
else
|
||||
{
|
||||
textp->text_length = png_strlen(text_ptr[i].text);
|
||||
lang_len = 0;
|
||||
lang_key_len = 0;
|
||||
}
|
||||
|
||||
if (text_ptr[i].text[0] == '\0')
|
||||
{
|
||||
text_length = 0;
|
||||
if(text_ptr[i].compression > 0)
|
||||
textp->compression = PNG_ITXT_COMPRESSION_NONE;
|
||||
else
|
||||
textp->compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
text_length = png_strlen(text_ptr[i].text);
|
||||
textp->compression = text_ptr[i].compression;
|
||||
}
|
||||
textp->text = text_ptr[i].text;
|
||||
textp->key = text_ptr[i].key;
|
||||
|
||||
textp->key = (png_charp)png_malloc(png_ptr,
|
||||
(png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4));
|
||||
png_debug2(2, "Allocated %d bytes at %x in png_set_text\n",
|
||||
key_len + lang_len + lang_key_len + text_length + 4, textp->key);
|
||||
|
||||
png_memcpy(textp->key, text_ptr[i].key,
|
||||
(png_size_t)(key_len));
|
||||
*(textp->key+key_len) = '\0';
|
||||
if (text_ptr[i].compression > 0)
|
||||
{
|
||||
textp->lang=textp->key + key_len + 1;
|
||||
png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
|
||||
*(textp->lang+lang_len) = '\0';
|
||||
textp->lang_key=textp->lang + lang_len + 1;
|
||||
png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
|
||||
*(textp->lang_key+lang_key_len) = '\0';
|
||||
textp->text=textp->lang_key + lang_key_len + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
textp->lang=NULL;
|
||||
textp->lang_key=NULL;
|
||||
textp->text=textp->key + key_len + 1;
|
||||
}
|
||||
|
||||
if(text_length)
|
||||
{
|
||||
png_memcpy(textp->text, text_ptr[i].text,
|
||||
(png_size_t)(text_length));
|
||||
*(textp->text+text_length) = '\0';
|
||||
}
|
||||
else
|
||||
textp->text--;
|
||||
|
||||
if(textp->compression > 0)
|
||||
{
|
||||
textp->text_length = 0;
|
||||
textp->itxt_length = text_length;
|
||||
}
|
||||
else
|
||||
{
|
||||
textp->text_length = text_length;
|
||||
textp->itxt_length = 0;
|
||||
}
|
||||
|
||||
info_ptr->text[info_ptr->num_text]= *textp;
|
||||
info_ptr->num_text++;
|
||||
info_ptr->free_me |= PNG_FREE_TEXT;
|
||||
png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
#if defined(PNG_tIME_SUPPORTED)
|
||||
void
|
||||
png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
|
||||
{
|
||||
png_debug1(1, "in %s storage function\n", "tIME");
|
||||
if (png_ptr == NULL || info_ptr == NULL ||
|
||||
(png_ptr->flags & PNG_FLAG_WROTE_tIME))
|
||||
(png_ptr->mode & PNG_WROTE_tIME))
|
||||
return;
|
||||
|
||||
png_memcpy(&(info_ptr->mod_time), mod_time, sizeof (png_time));
|
||||
@@ -353,7 +585,7 @@ png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED)
|
||||
#if defined(PNG_tRNS_SUPPORTED)
|
||||
void
|
||||
png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
|
||||
png_bytep trans, int num_trans, png_color_16p trans_values)
|
||||
@@ -363,9 +595,7 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
|
||||
return;
|
||||
|
||||
if (trans != NULL)
|
||||
{
|
||||
info_ptr->trans = trans;
|
||||
}
|
||||
|
||||
if (trans_values != NULL)
|
||||
{
|
||||
@@ -379,7 +609,85 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED)
|
||||
#if defined(PNG_sPLT_SUPPORTED)
|
||||
void
|
||||
png_set_sPLT(png_structp png_ptr,
|
||||
png_infop info_ptr, png_sPLT_tp entries, int nentries)
|
||||
{
|
||||
png_sPLT_tp np;
|
||||
int i;
|
||||
|
||||
np = (png_sPLT_tp)png_malloc(png_ptr,
|
||||
(info_ptr->splt_palettes_num + nentries) * sizeof(png_sPLT_t));
|
||||
|
||||
png_memcpy(np, info_ptr->splt_palettes,
|
||||
info_ptr->splt_palettes_num * sizeof(png_sPLT_t));
|
||||
png_free(png_ptr, info_ptr->splt_palettes);
|
||||
|
||||
for (i = 0; i < nentries; i++)
|
||||
{
|
||||
png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
|
||||
png_sPLT_tp from = entries + i;
|
||||
|
||||
to->name = (png_charp)png_malloc(png_ptr,
|
||||
png_strlen(from->name) + 1);
|
||||
png_strcpy(to->name, from->name);
|
||||
to->entries = (png_sPLT_entryp)png_malloc(png_ptr,
|
||||
from->nentries * sizeof(png_sPLT_t));
|
||||
png_memcpy(to->entries, from->entries,
|
||||
from->nentries * sizeof(png_sPLT_t));
|
||||
to->nentries = from->nentries;
|
||||
to->depth = from->depth;
|
||||
}
|
||||
|
||||
info_ptr->splt_palettes = np;
|
||||
info_ptr->splt_palettes_num += nentries;
|
||||
info_ptr->valid |= PNG_INFO_sPLT;
|
||||
info_ptr->free_me |= PNG_FREE_SPLT;
|
||||
}
|
||||
#endif /* PNG_sPLT_SUPPORTED */
|
||||
|
||||
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
void
|
||||
png_set_unknown_chunks(png_structp png_ptr,
|
||||
png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
|
||||
{
|
||||
png_unknown_chunkp np;
|
||||
int i;
|
||||
|
||||
if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
|
||||
return;
|
||||
|
||||
np = (png_unknown_chunkp)png_malloc(png_ptr,
|
||||
(info_ptr->unknown_chunks_num + num_unknowns) *
|
||||
sizeof(png_unknown_chunk));
|
||||
|
||||
png_memcpy(np, info_ptr->unknown_chunks,
|
||||
info_ptr->unknown_chunks_num * sizeof(png_unknown_chunk));
|
||||
png_free(png_ptr, info_ptr->unknown_chunks);
|
||||
|
||||
for (i = 0; i < num_unknowns; i++)
|
||||
{
|
||||
png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
|
||||
png_unknown_chunkp from = unknowns + i;
|
||||
|
||||
png_strcpy((png_charp)to->name, (png_charp)from->name);
|
||||
to->data = (png_bytep)png_malloc(png_ptr, from->size);
|
||||
png_memcpy(to->data, from->data, from->size);
|
||||
to->size = from->size;
|
||||
|
||||
/* note our location in the read or write sequence */
|
||||
to->location = (png_byte)(png_ptr->mode & 0xff);
|
||||
}
|
||||
|
||||
info_ptr->unknown_chunks = np;
|
||||
info_ptr->unknown_chunks_num += num_unknowns;
|
||||
info_ptr->free_me |= PNG_FREE_UNKN;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
|
||||
defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
|
||||
void
|
||||
png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
|
||||
{
|
||||
@@ -389,3 +697,66 @@ png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
|
||||
png_ptr->empty_plte_permitted=(png_byte)empty_plte_permitted;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
void
|
||||
png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
|
||||
chunk_list, int num_chunks)
|
||||
{
|
||||
png_bytep new_list, p;
|
||||
int i, old_num_chunks;
|
||||
if (num_chunks == 0)
|
||||
{
|
||||
if(keep == HANDLE_CHUNK_ALWAYS || keep == HANDLE_CHUNK_IF_SAFE)
|
||||
png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
|
||||
else
|
||||
png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
|
||||
|
||||
if(keep == HANDLE_CHUNK_ALWAYS)
|
||||
png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
|
||||
else
|
||||
png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
|
||||
return;
|
||||
}
|
||||
if (chunk_list == NULL)
|
||||
return;
|
||||
old_num_chunks=png_ptr->num_chunk_list;
|
||||
new_list=png_malloc(png_ptr,5*(num_chunks+old_num_chunks));
|
||||
if(png_ptr->chunk_list != (png_bytep)NULL)
|
||||
{
|
||||
png_memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks);
|
||||
png_free(png_ptr, png_ptr->chunk_list);
|
||||
}
|
||||
png_memcpy(new_list+5*old_num_chunks, chunk_list, 5*num_chunks);
|
||||
for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
|
||||
*p=(png_byte)keep;
|
||||
png_ptr->num_chunk_list=old_num_chunks+num_chunks;
|
||||
png_ptr->chunk_list=new_list;
|
||||
png_ptr->free_me |= PNG_FREE_LIST;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
|
||||
void
|
||||
png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
|
||||
png_user_chunk_ptr read_user_chunk_fn)
|
||||
{
|
||||
png_debug(1, "in png_set_read_user_chunk_fn\n");
|
||||
png_ptr->read_user_chunk_fn = read_user_chunk_fn;
|
||||
png_ptr->user_chunk_ptr = user_chunk_ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_INFO_IMAGE_SUPPORTED)
|
||||
void
|
||||
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;
|
||||
|
||||
png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
|
||||
info_ptr->row_pointers = row_pointers;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
335
pngtest.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngtest.c - a simple test program to test libpng
|
||||
*
|
||||
* libpng 1.0.4d - October 6, 1999
|
||||
* libpng 1.0.6e - April 10, 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
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
*
|
||||
* This program reads in a PNG image, writes it out again, and then
|
||||
* compares the two files. If the files are identical, this shows that
|
||||
@@ -15,11 +15,11 @@
|
||||
*
|
||||
* The program will report "FAIL" in certain legitimate cases:
|
||||
* 1) when the compression level or filter selection method is changed.
|
||||
* 2) when the chunk size is not 8K.
|
||||
* 2) when the maximum IDAT size (PNG_ZBUF_SIZE in pngconf.h) is not 8192.
|
||||
* 3) unknown ancillary chunks exist in the input file.
|
||||
* 4) others not listed here...
|
||||
* In these cases, it is best to check with another tool such as "pngcheck"
|
||||
* to see what the differences between the two images are.
|
||||
* to see what the differences between the two files are.
|
||||
*
|
||||
* If a filename is given on the command-line, then this file is used
|
||||
* for the input, rather than the default "pngtest.png". This allows
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
/* Makes pngtest verbose so we can find problems (needs to be before png.h) */
|
||||
#ifndef PNG_DEBUG
|
||||
@@ -39,6 +40,10 @@
|
||||
#define PNGTEST_TIMING
|
||||
*/
|
||||
|
||||
#ifdef PNG_NO_FLOATING_POINT_SUPPORTED
|
||||
#undef PNGTEST_TIMING
|
||||
#endif
|
||||
|
||||
#ifdef PNGTEST_TIMING
|
||||
static float t_start, t_stop, t_decode, t_encode, t_misc;
|
||||
#include <time.h>
|
||||
@@ -46,9 +51,14 @@ static float t_start, t_stop, t_decode, t_encode, t_misc;
|
||||
|
||||
#include "png.h"
|
||||
|
||||
/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
|
||||
#ifndef png_jmpbuf
|
||||
# define png_jmpbuf(png_ptr) png_ptr->jmpbuf
|
||||
#endif
|
||||
|
||||
#ifdef PNGTEST_TIMING
|
||||
static float t_start, t_stop, t_decode, t_encode, t_misc;
|
||||
#if !defined(PNG_READ_tIME_SUPPORTED) && !defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
#if !defined(PNG_tIME_SUPPORTED)
|
||||
#include <time.h>
|
||||
#endif
|
||||
#endif
|
||||
@@ -56,7 +66,7 @@ static float t_start, t_stop, t_decode, t_encode, t_misc;
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
static int tIME_chunk_present=0;
|
||||
static char tIME_string[30] = "no tIME chunk present in file";
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
#endif
|
||||
|
||||
static int verbose = 0;
|
||||
|
||||
@@ -147,7 +157,7 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
|
||||
{
|
||||
if(row_info->bit_depth == 1)
|
||||
{
|
||||
if(((*dp << pos++ )& 0x80) == 0) zero_samples++;
|
||||
if(((*dp << pos++ ) & 0x80) == 0) zero_samples++;
|
||||
if(pos == 8)
|
||||
{
|
||||
pos = 0;
|
||||
@@ -156,7 +166,7 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
|
||||
}
|
||||
if(row_info->bit_depth == 2)
|
||||
{
|
||||
if(((*dp << (pos+=2))& 0xc0) == 0) zero_samples++;
|
||||
if(((*dp << (pos+=2)) & 0xc0) == 0) zero_samples++;
|
||||
if(pos == 8)
|
||||
{
|
||||
pos = 0;
|
||||
@@ -165,7 +175,7 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
|
||||
}
|
||||
if(row_info->bit_depth == 4)
|
||||
{
|
||||
if(((*dp << (pos+=4))& 0xf0) == 0) zero_samples++;
|
||||
if(((*dp << (pos+=4)) & 0xf0) == 0) zero_samples++;
|
||||
if(pos == 8)
|
||||
{
|
||||
pos = 0;
|
||||
@@ -405,7 +415,8 @@ png_default_error(png_structp png_ptr, png_const_charp message)
|
||||
|
||||
This piece of code can be compiled to validate max 64K allocations
|
||||
by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K. */
|
||||
typedef struct memory_information {
|
||||
typedef struct memory_information
|
||||
{
|
||||
png_uint_32 size;
|
||||
png_voidp pointer;
|
||||
struct memory_information FAR *next;
|
||||
@@ -422,7 +433,8 @@ extern PNG_EXPORT(void,png_debug_free) PNGARG((png_structp png_ptr,
|
||||
png_voidp ptr));
|
||||
|
||||
png_voidp
|
||||
png_debug_malloc(png_structp png_ptr, png_uint_32 size) {
|
||||
png_debug_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
|
||||
/* png_malloc has already tested for NULL; png_create_struct calls
|
||||
png_debug_malloc directly, with png_ptr == NULL which is OK */
|
||||
@@ -443,6 +455,11 @@ png_debug_malloc(png_structp png_ptr, png_uint_32 size) {
|
||||
pinformation = pinfo;
|
||||
/* Make sure the caller isn't assuming zeroed memory. */
|
||||
png_memset(pinfo->pointer, 0xdd, pinfo->size);
|
||||
#if PNG_DEBUG
|
||||
if(verbose)
|
||||
printf("png_malloc %d bytes at %x\n",size,pinfo->pointer);
|
||||
#endif
|
||||
assert(pinfo->size != 12345);
|
||||
return (png_voidp)(pinfo->pointer);
|
||||
}
|
||||
}
|
||||
@@ -453,7 +470,8 @@ png_debug_free(png_structp png_ptr, png_voidp ptr)
|
||||
{
|
||||
if (png_ptr == NULL)
|
||||
fprintf(STDERR, "NULL pointer to png_debug_free.\n");
|
||||
if (ptr == 0) {
|
||||
if (ptr == 0)
|
||||
{
|
||||
#if 0 /* This happens all the time. */
|
||||
fprintf(STDERR, "WARNING: freeing NULL pointer\n");
|
||||
#endif
|
||||
@@ -463,9 +481,11 @@ png_debug_free(png_structp png_ptr, png_voidp ptr)
|
||||
/* Unlink the element from the list. */
|
||||
{
|
||||
memory_infop FAR *ppinfo = &pinformation;
|
||||
for (;;) {
|
||||
for (;;)
|
||||
{
|
||||
memory_infop pinfo = *ppinfo;
|
||||
if (pinfo->pointer == ptr) {
|
||||
if (pinfo->pointer == ptr)
|
||||
{
|
||||
*ppinfo = pinfo->next;
|
||||
current_allocation -= pinfo->size;
|
||||
if (current_allocation < 0)
|
||||
@@ -476,7 +496,8 @@ png_debug_free(png_structp png_ptr, png_voidp ptr)
|
||||
png_free_default(png_ptr, pinfo);
|
||||
break;
|
||||
}
|
||||
if (pinfo->next == NULL) {
|
||||
if (pinfo->next == NULL)
|
||||
{
|
||||
fprintf(STDERR, "Pointer %x not found\n", ptr);
|
||||
break;
|
||||
}
|
||||
@@ -485,6 +506,10 @@ png_debug_free(png_structp png_ptr, png_voidp ptr)
|
||||
}
|
||||
|
||||
/* Finally free the data. */
|
||||
#if PNG_DEBUG
|
||||
if(verbose)
|
||||
printf("Freeing %x\n",ptr);
|
||||
#endif
|
||||
png_free_default(png_ptr, ptr);
|
||||
}
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
@@ -496,15 +521,17 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
{
|
||||
static FILE *fpin, *fpout; /* "static" prevents setjmp corruption */
|
||||
png_structp read_ptr, write_ptr;
|
||||
png_infop read_info_ptr, write_info_ptr, end_info_ptr;
|
||||
png_infop read_info_ptr, write_info_ptr, end_info_ptr, write_end_info_ptr;
|
||||
png_bytep row_buf;
|
||||
png_uint_32 y;
|
||||
png_uint_32 width, height;
|
||||
int num_pass, pass;
|
||||
int bit_depth, color_type;
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
jmp_buf jmpbuf;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
char inbuf[256], outbuf[256];
|
||||
|
||||
@@ -552,43 +579,48 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
read_info_ptr = png_create_info_struct(read_ptr);
|
||||
write_info_ptr = png_create_info_struct(write_ptr);
|
||||
end_info_ptr = png_create_info_struct(read_ptr);
|
||||
write_end_info_ptr = png_create_info_struct(write_ptr);
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
#endif
|
||||
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
png_debug(0, "Setting jmpbuf for read struct\n");
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
if (setjmp(jmpbuf))
|
||||
#else
|
||||
if (setjmp(read_ptr->jmpbuf))
|
||||
if (setjmp(png_jmpbuf(read_ptr)))
|
||||
#endif
|
||||
{
|
||||
fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname);
|
||||
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
|
||||
png_destroy_info_struct(write_ptr, &write_end_info_ptr);
|
||||
png_destroy_write_struct(&write_ptr, &write_info_ptr);
|
||||
fclose(fpin);
|
||||
fclose(fpout);
|
||||
return (1);
|
||||
}
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
png_memcpy(read_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
|
||||
png_memcpy(png_jmpbuf(read_ptr),jmpbuf,sizeof(jmp_buf));
|
||||
#endif
|
||||
|
||||
png_debug(0, "Setting jmpbuf for write struct\n");
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
if (setjmp(jmpbuf))
|
||||
#else
|
||||
if (setjmp(write_ptr->jmpbuf))
|
||||
if (setjmp(png_jmpbuf(write_ptr)))
|
||||
#endif
|
||||
{
|
||||
fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname);
|
||||
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
|
||||
png_destroy_info_struct(write_ptr, &write_end_info_ptr);
|
||||
png_destroy_write_struct(&write_ptr, &write_info_ptr);
|
||||
fclose(fpin);
|
||||
fclose(fpout);
|
||||
return (1);
|
||||
}
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
png_memcpy(write_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
|
||||
png_memcpy(png_jmpbuf(write_ptr),jmpbuf,sizeof(jmp_buf));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
png_debug(0, "Initializing input and output streams\n");
|
||||
@@ -628,6 +660,15 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
png_set_write_user_transform_fn(write_ptr, count_zero_samples);
|
||||
#endif
|
||||
|
||||
#define HANDLE_CHUNK_IF_SAFE 2
|
||||
#define HANDLE_CHUNK_ALWAYS 3
|
||||
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
png_set_keep_unknown_chunks(read_ptr, HANDLE_CHUNK_ALWAYS, NULL, 0);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_IF_SAFE, NULL, 0);
|
||||
#endif
|
||||
|
||||
png_debug(0, "Reading info struct\n");
|
||||
png_read_info(read_ptr, read_info_ptr);
|
||||
|
||||
@@ -646,39 +687,45 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#if defined(PNG_READ_bKGD_SUPPORTED) && defined(PNG_WRITE_bKGD_SUPPORTED)
|
||||
#if defined(PNG_cHRM_SUPPORTED)
|
||||
{
|
||||
png_color_16p background;
|
||||
png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
|
||||
blue_y;
|
||||
|
||||
if (png_get_bKGD(read_ptr, read_info_ptr, &background))
|
||||
{
|
||||
png_set_bKGD(write_ptr, write_info_ptr, background);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED) && defined(PNG_WRITE_cHRM_SUPPORTED)
|
||||
{
|
||||
double white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
|
||||
|
||||
if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x,
|
||||
if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y, &red_x,
|
||||
&red_y, &green_x, &green_y, &blue_x, &blue_y))
|
||||
{
|
||||
png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x,
|
||||
png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, red_x,
|
||||
red_y, green_x, green_y, blue_x, blue_y);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_WRITE_gAMA_SUPPORTED)
|
||||
#if defined(PNG_gAMA_SUPPORTED)
|
||||
{
|
||||
double gamma;
|
||||
png_fixed_point gamma;
|
||||
|
||||
if (png_get_gAMA(read_ptr, read_info_ptr, &gamma))
|
||||
if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma))
|
||||
{
|
||||
png_set_gAMA(write_ptr, write_info_ptr, gamma);
|
||||
png_set_gAMA_fixed(write_ptr, write_info_ptr, gamma);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED) && defined(PNG_WRITE_sRGB_SUPPORTED)
|
||||
#if defined(PNG_iCCP_SUPPORTED)
|
||||
{
|
||||
png_charp name;
|
||||
png_charp profile;
|
||||
png_uint_32 proflen;
|
||||
int compression_type;
|
||||
|
||||
if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type,
|
||||
&profile, &proflen))
|
||||
{
|
||||
png_set_iCCP(write_ptr, write_info_ptr, name, compression_type,
|
||||
profile, proflen);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_sRGB_SUPPORTED)
|
||||
{
|
||||
int intent;
|
||||
|
||||
@@ -688,7 +735,26 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_hIST_SUPPORTED) && defined(PNG_WRITE_hIST_SUPPORTED)
|
||||
{
|
||||
png_colorp palette;
|
||||
int num_palette;
|
||||
|
||||
if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette))
|
||||
{
|
||||
png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette);
|
||||
}
|
||||
}
|
||||
#if defined(PNG_bKGD_SUPPORTED)
|
||||
{
|
||||
png_color_16p background;
|
||||
|
||||
if (png_get_bKGD(read_ptr, read_info_ptr, &background))
|
||||
{
|
||||
png_set_bKGD(write_ptr, write_info_ptr, background);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_hIST_SUPPORTED)
|
||||
{
|
||||
png_uint_16p hist;
|
||||
|
||||
@@ -698,9 +764,9 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED) && defined(PNG_WRITE_oFFs_SUPPORTED)
|
||||
#if defined(PNG_oFFs_SUPPORTED)
|
||||
{
|
||||
png_uint_32 offset_x, offset_y;
|
||||
png_int_32 offset_x, offset_y;
|
||||
int unit_type;
|
||||
|
||||
if (png_get_oFFs(read_ptr, read_info_ptr,&offset_x,&offset_y,&unit_type))
|
||||
@@ -709,7 +775,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED) && defined(PNG_WRITE_pCAL_SUPPORTED)
|
||||
#if defined(PNG_pCAL_SUPPORTED)
|
||||
{
|
||||
png_charp purpose, units;
|
||||
png_charpp params;
|
||||
@@ -724,7 +790,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED) && defined(PNG_WRITE_pHYs_SUPPORTED)
|
||||
#if defined(PNG_pHYs_SUPPORTED)
|
||||
{
|
||||
png_uint_32 res_x, res_y;
|
||||
int unit_type;
|
||||
@@ -735,16 +801,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
{
|
||||
png_colorp palette;
|
||||
int num_palette;
|
||||
|
||||
if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette))
|
||||
{
|
||||
png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette);
|
||||
}
|
||||
}
|
||||
#if defined(PNG_READ_sBIT_SUPPORTED) && defined(PNG_WRITE_sBIT_SUPPORTED)
|
||||
#if defined(PNG_sBIT_SUPPORTED)
|
||||
{
|
||||
png_color_8p sig_bit;
|
||||
|
||||
@@ -754,20 +811,44 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if (defined(PNG_READ_tEXt_SUPPORTED) && defined(PNG_WRITE_tEXt_SUPPORTED)) || \
|
||||
(defined(PNG_READ_zTXt_SUPPORTED) && defined(PNG_WRITE_zTXt_SUPPORTED))
|
||||
#if defined(PNG_sCAL_SUPPORTED)
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
{
|
||||
int unit;
|
||||
double width, height;
|
||||
|
||||
if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &width, &height))
|
||||
{
|
||||
png_set_sCAL(write_ptr, write_info_ptr, unit, width, height);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
{
|
||||
int unit;
|
||||
png_charp width, height;
|
||||
|
||||
if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &width, &height))
|
||||
{
|
||||
png_set_sCAL_s(write_ptr, write_info_ptr, unit, width, height);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#if defined(PNG_TEXT_SUPPORTED)
|
||||
{
|
||||
png_textp text_ptr;
|
||||
int num_text;
|
||||
|
||||
if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0)
|
||||
{
|
||||
png_debug1(0, "Handling %d tEXt/zTXt chunks\n", num_text);
|
||||
png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks\n", num_text);
|
||||
png_set_text(write_ptr, write_info_ptr, text_ptr, num_text);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_tIME_SUPPORTED) && defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
#if defined(PNG_tIME_SUPPORTED)
|
||||
{
|
||||
png_timep mod_time;
|
||||
|
||||
@@ -784,7 +865,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED) && defined(PNG_WRITE_tRNS_SUPPORTED)
|
||||
#if defined(PNG_tRNS_SUPPORTED)
|
||||
{
|
||||
png_bytep trans;
|
||||
int num_trans;
|
||||
@@ -798,8 +879,30 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
{
|
||||
png_unknown_chunkp unknowns;
|
||||
int num_unknowns = (int)png_get_unknown_chunks(read_ptr, read_info_ptr,
|
||||
&unknowns);
|
||||
if (num_unknowns)
|
||||
{
|
||||
png_size_t i;
|
||||
png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns,
|
||||
num_unknowns);
|
||||
/* copy the locations from the read_info_ptr. The automatically
|
||||
generated locations in write_info_ptr are wrong because we
|
||||
haven't written anything yet */
|
||||
for (i = 0; i < (png_size_t)num_unknowns; i++)
|
||||
write_info_ptr->unknown_chunks[i].location = unknowns[i].location;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
png_debug(0, "\nWriting info struct\n");
|
||||
|
||||
/* If we wanted, we could write info in two steps:
|
||||
png_write_info_before_PLTE(write_ptr, write_info_ptr);
|
||||
*/
|
||||
png_write_info(write_ptr, write_info_ptr);
|
||||
|
||||
png_debug(0, "\nAllocating row buffer \n");
|
||||
@@ -809,6 +912,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
{
|
||||
fprintf(STDERR, "No memory to allocate row buffer\n");
|
||||
png_destroy_read_struct(&read_ptr, &read_info_ptr, (png_infopp)NULL);
|
||||
png_destroy_info_struct(write_ptr, &write_end_info_ptr);
|
||||
png_destroy_write_struct(&write_ptr, &write_info_ptr);
|
||||
fclose(fpin);
|
||||
fclose(fpout);
|
||||
@@ -849,9 +953,66 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1);
|
||||
#endif
|
||||
|
||||
png_debug(0, "Reading and writing end_info data\n");
|
||||
|
||||
png_read_end(read_ptr, end_info_ptr);
|
||||
png_write_end(write_ptr, end_info_ptr);
|
||||
#if defined(PNG_TEXT_SUPPORTED)
|
||||
{
|
||||
png_textp text_ptr;
|
||||
int num_text;
|
||||
|
||||
if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0)
|
||||
{
|
||||
png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks\n", num_text);
|
||||
png_set_text(write_ptr, write_end_info_ptr, text_ptr, num_text);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_tIME_SUPPORTED)
|
||||
{
|
||||
png_timep mod_time;
|
||||
|
||||
if (png_get_tIME(read_ptr, end_info_ptr, &mod_time))
|
||||
{
|
||||
png_set_tIME(write_ptr, write_end_info_ptr, mod_time);
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
/* we have to use png_strcpy instead of "=" because the string
|
||||
pointed to by png_convert_to_rfc1123() gets free'ed before
|
||||
we use it */
|
||||
png_strcpy(tIME_string,png_convert_to_rfc1123(read_ptr, mod_time));
|
||||
tIME_chunk_present++;
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
{
|
||||
png_unknown_chunkp unknowns;
|
||||
int num_unknowns;
|
||||
num_unknowns = (int)png_get_unknown_chunks(read_ptr, end_info_ptr,
|
||||
&unknowns);
|
||||
if (num_unknowns)
|
||||
{
|
||||
png_size_t i;
|
||||
png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns,
|
||||
num_unknowns);
|
||||
/* copy the locations from the read_info_ptr. The automatically
|
||||
generated locations in write_end_info_ptr are wrong because we
|
||||
haven't written the end_info yet */
|
||||
for (i = 0; i < (png_size_t)num_unknowns; i++)
|
||||
write_end_info_ptr->unknown_chunks[i].location =
|
||||
unknowns[i].location;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
png_write_end(write_ptr, write_end_info_ptr);
|
||||
|
||||
#ifdef PNG_EASY_ACCESS_SUPPORTED
|
||||
if(verbose)
|
||||
@@ -867,6 +1028,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
png_debug(0, "Destroying data structs\n");
|
||||
png_free(read_ptr, row_buf);
|
||||
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
|
||||
png_destroy_info_struct(write_ptr, &write_end_info_ptr);
|
||||
png_destroy_write_struct(&write_ptr, &write_info_ptr);
|
||||
|
||||
fclose(fpin);
|
||||
@@ -895,16 +1057,17 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
|
||||
if (num_in != num_out)
|
||||
{
|
||||
fprintf(STDERR, "Files %s and %s are of a different size\n",
|
||||
fprintf(STDERR, "\nFiles %s and %s are of a different size\n",
|
||||
inname, outname);
|
||||
if(wrote_question == 0)
|
||||
{
|
||||
fprintf(STDERR,
|
||||
" Was %s written with the same chunk size (8k),",inname);
|
||||
" Was %s written with the same maximum IDAT chunk size (%d bytes),",
|
||||
inname,PNG_ZBUF_SIZE);
|
||||
fprintf(STDERR,
|
||||
" filtering\n heuristic (libpng default), compression");
|
||||
"\n filtering heuristic (libpng default), compression");
|
||||
fprintf(STDERR,
|
||||
" level (zlib default)\n and zlib version (%s)?\n\n",
|
||||
" level (zlib default),\n and zlib version (%s)?\n\n",
|
||||
ZLIB_VERSION);
|
||||
wrote_question=1;
|
||||
}
|
||||
@@ -922,11 +1085,12 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
if(wrote_question == 0)
|
||||
{
|
||||
fprintf(STDERR,
|
||||
" Was %s written with the same chunk size (8k),",inname);
|
||||
" Was %s written with the same maximum IDAT chunk size (%d bytes),",
|
||||
inname,PNG_ZBUF_SIZE);
|
||||
fprintf(STDERR,
|
||||
" filtering\n heuristic (libpng default), compression");
|
||||
"\n filtering heuristic (libpng default), compression");
|
||||
fprintf(STDERR,
|
||||
" level (zlib default)\n and zlib version (%s)?\n\n",
|
||||
" level (zlib default),\n and zlib version (%s)?\n\n",
|
||||
ZLIB_VERSION);
|
||||
wrote_question=1;
|
||||
}
|
||||
@@ -960,6 +1124,10 @@ main(int argc, char *argv[])
|
||||
fprintf(STDERR, "Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
|
||||
fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION);
|
||||
fprintf(STDERR,"%s",png_get_copyright(NULL));
|
||||
/* Show the version of libpng used in building the library */
|
||||
fprintf(STDERR," library:%s",png_get_header_version(NULL));
|
||||
/* Show the version of libpng used in building the application */
|
||||
fprintf(STDERR," pngtest:%s",PNG_HEADER_VERSION_STRING);
|
||||
|
||||
/* Do some consistency checking on the memory allocation settings, I'm
|
||||
not sure this matters, but it is nice to know, the first of these
|
||||
@@ -1038,7 +1206,7 @@ main(int argc, char *argv[])
|
||||
if (kerror == 0)
|
||||
{
|
||||
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
fprintf(STDERR, " PASS (%lu zero samples)\n",zero_samples);
|
||||
fprintf(STDERR, "\n PASS (%lu zero samples)\n",zero_samples);
|
||||
#else
|
||||
fprintf(STDERR, " PASS\n");
|
||||
#endif
|
||||
@@ -1063,15 +1231,17 @@ main(int argc, char *argv[])
|
||||
if (allocation_now != current_allocation)
|
||||
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
|
||||
current_allocation-allocation_now);
|
||||
if (current_allocation != 0) {
|
||||
if (current_allocation != 0)
|
||||
{
|
||||
memory_infop pinfo = pinformation;
|
||||
|
||||
fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
|
||||
current_allocation);
|
||||
while (pinfo != NULL) {
|
||||
while (pinfo != NULL)
|
||||
{
|
||||
fprintf(STDERR, " %d bytes at %x\n", pinfo->size, pinfo->pointer);
|
||||
pinfo = pinfo->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1085,7 +1255,8 @@ main(int argc, char *argv[])
|
||||
else
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i) {
|
||||
for (i=0; i<3; ++i)
|
||||
{
|
||||
int kerror;
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
int allocation_now = current_allocation;
|
||||
@@ -1101,7 +1272,7 @@ main(int argc, char *argv[])
|
||||
{
|
||||
int k;
|
||||
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
fprintf(STDERR, " PASS (%lu zero samples)\n",zero_samples);
|
||||
fprintf(STDERR, "\n PASS (%lu zero samples)\n",zero_samples);
|
||||
#else
|
||||
fprintf(STDERR, " PASS\n");
|
||||
#endif
|
||||
@@ -1128,13 +1299,16 @@ main(int argc, char *argv[])
|
||||
if (allocation_now != current_allocation)
|
||||
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
|
||||
current_allocation-allocation_now);
|
||||
if (current_allocation != 0) {
|
||||
if (current_allocation != 0)
|
||||
{
|
||||
memory_infop pinfo = pinformation;
|
||||
|
||||
fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
|
||||
current_allocation);
|
||||
while (pinfo != NULL) {
|
||||
fprintf(STDERR, " %d bytes at %x\n", pinfo->size, pinfo->pointer);
|
||||
while (pinfo != NULL)
|
||||
{
|
||||
fprintf(STDERR," %d bytes at %x\n",
|
||||
pinfo->size, pinfo->pointer);
|
||||
pinfo = pinfo->next;
|
||||
}
|
||||
}
|
||||
@@ -1170,9 +1344,4 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* Generate a compiler error if there is an old png.h in the search path. */
|
||||
void
|
||||
png_check_pngtest_version
|
||||
(version_1_0_4d png_h_is_not_version_1_0_4d)
|
||||
{
|
||||
if(png_h_is_not_version_1_0_4d == NULL) return;
|
||||
}
|
||||
typedef version_1_0_6e your_png_h_is_not_version_1_0_6e;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
|
||||
*
|
||||
* libpng 1.0.4d - October 6, 1999
|
||||
* libpng 1.0.6e - April 10, 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
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
|
||||
4
pngwio.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngwio.c - functions for data output
|
||||
*
|
||||
* libpng 1.0.4d - October 6, 1999
|
||||
* libpng 1.0.6e - April 10, 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
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
*
|
||||
* This file provides a location for all output. Users who need
|
||||
* special handling are expected to write functions that have the same
|
||||
|
||||
368
pngwrite.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngwrite.c - general routines to write a PNG file
|
||||
*
|
||||
* libpng 1.0.4d - October 6, 1999
|
||||
* libpng 1.0.6e - April 10, 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
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
/* get internal access to png.h */
|
||||
@@ -22,13 +22,11 @@
|
||||
* them in png_write_end(), and compressing them.
|
||||
*/
|
||||
void
|
||||
png_write_info(png_structp png_ptr, png_infop info_ptr)
|
||||
png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
int i;
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_write_info\n");
|
||||
png_debug(1, "in png_write_info_before_PLTE\n");
|
||||
if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
|
||||
{
|
||||
png_write_sig(png_ptr); /* write PNG signature */
|
||||
/* write IHDR information. */
|
||||
png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
|
||||
@@ -43,24 +41,86 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
|
||||
flag set, and if it does, writes the chunk. */
|
||||
#if defined(PNG_WRITE_gAMA_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_gAMA)
|
||||
{
|
||||
# ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
png_write_gAMA(png_ptr, info_ptr->gamma);
|
||||
#else
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_WRITE_sRGB_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_sRGB)
|
||||
png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_iCCP_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_iCCP)
|
||||
png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_TEXT_COMPRESSION_NONE,
|
||||
info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_sBIT_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_sBIT)
|
||||
png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_cHRM_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_cHRM)
|
||||
{
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
png_write_cHRM(png_ptr,
|
||||
info_ptr->x_white, info_ptr->y_white,
|
||||
info_ptr->x_red, info_ptr->y_red,
|
||||
info_ptr->x_green, info_ptr->y_green,
|
||||
info_ptr->x_blue, info_ptr->y_blue);
|
||||
#else
|
||||
# ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_write_cHRM_fixed(png_ptr,
|
||||
info_ptr->int_x_white, info_ptr->int_y_white,
|
||||
info_ptr->int_x_red, info_ptr->int_y_red,
|
||||
info_ptr->int_x_green, info_ptr->int_y_green,
|
||||
info_ptr->int_x_blue, info_ptr->int_y_blue);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
if (info_ptr->unknown_chunks_num)
|
||||
{
|
||||
png_unknown_chunk *up;
|
||||
|
||||
png_debug(5, "writing extra chunks\n");
|
||||
|
||||
for (up = info_ptr->unknown_chunks;
|
||||
up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
|
||||
up++)
|
||||
{
|
||||
int keep=png_handle_as_unknown(png_ptr, up->name);
|
||||
if (keep != HANDLE_CHUNK_NEVER &&
|
||||
up->location && (!(up->location & PNG_HAVE_PLTE)) &&
|
||||
((up->name[3] & 0x20) || keep == HANDLE_CHUNK_ALWAYS ||
|
||||
(png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
|
||||
{
|
||||
png_write_chunk(png_ptr, up->name, up->data, up->size);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
png_write_info(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
|
||||
int i;
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_write_info\n");
|
||||
|
||||
png_write_info_before_PLTE(png_ptr, info_ptr);
|
||||
|
||||
if (info_ptr->valid & PNG_INFO_PLTE)
|
||||
png_write_PLTE(png_ptr, info_ptr->palette,
|
||||
(png_uint_32)info_ptr->num_palette);
|
||||
@@ -72,12 +132,12 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
|
||||
/* invert the alpha channel (in tRNS) */
|
||||
if (png_ptr->transformations & PNG_INVERT_ALPHA &&
|
||||
if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
|
||||
info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
int j;
|
||||
for (j=0; j<(int)info_ptr->num_trans; j++)
|
||||
info_ptr->trans[j] = 255 - info_ptr->trans[j];
|
||||
info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
|
||||
}
|
||||
#endif
|
||||
png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
|
||||
@@ -103,6 +163,21 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
|
||||
info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
|
||||
info_ptr->pcal_units, info_ptr->pcal_params);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_sCAL_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_sCAL)
|
||||
#if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
|
||||
png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
|
||||
info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
|
||||
#else
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
|
||||
info_ptr->scal_s_width, info_ptr->scal_s_height);
|
||||
#else
|
||||
png_warning(png_ptr,
|
||||
"png_write_sCAL not supported; sCAL chunk not written.\n");
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#if defined(PNG_WRITE_pHYs_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_pHYs)
|
||||
png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
|
||||
@@ -112,22 +187,44 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
|
||||
if (info_ptr->valid & PNG_INFO_tIME)
|
||||
{
|
||||
png_write_tIME(png_ptr, &(info_ptr->mod_time));
|
||||
png_ptr->flags |= PNG_FLAG_WROTE_tIME;
|
||||
png_ptr->mode |= PNG_WROTE_tIME;
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
#if defined(PNG_WRITE_sPLT_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_sPLT)
|
||||
for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
|
||||
png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_TEXT_SUPPORTED)
|
||||
/* Check to see if we need to write text chunks */
|
||||
for (i = 0; i < info_ptr->num_text; i++)
|
||||
{
|
||||
png_debug2(2, "Writing header text chunk %d, type %d\n", i,
|
||||
info_ptr->text[i].compression);
|
||||
/* an internationalized chunk? */
|
||||
if (info_ptr->text[i].compression > 0)
|
||||
{
|
||||
#if defined(PNG_WRITE_iTXt_SUPPORTED)
|
||||
/* write international chunk */
|
||||
png_write_iTXt(png_ptr,
|
||||
info_ptr->text[i].compression,
|
||||
info_ptr->text[i].key,
|
||||
info_ptr->text[i].lang,
|
||||
info_ptr->text[i].lang_key,
|
||||
info_ptr->text[i].text);
|
||||
#else
|
||||
png_warning(png_ptr, "Unable to write international text\n");
|
||||
#endif
|
||||
/* Mark this chunk as written */
|
||||
info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
|
||||
}
|
||||
/* If we want a compressed text chunk */
|
||||
if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
|
||||
else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
|
||||
{
|
||||
#if defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
/* write compressed chunk */
|
||||
png_write_zTXt(png_ptr, info_ptr->text[i].key,
|
||||
info_ptr->text[i].text, info_ptr->text[i].text_length,
|
||||
info_ptr->text[i].text, 0,
|
||||
info_ptr->text[i].compression);
|
||||
#else
|
||||
png_warning(png_ptr, "Unable to write compressed text\n");
|
||||
@@ -140,7 +237,8 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED)
|
||||
/* write uncompressed chunk */
|
||||
png_write_tEXt(png_ptr, info_ptr->text[i].key,
|
||||
info_ptr->text[i].text, info_ptr->text[i].text_length);
|
||||
info_ptr->text[i].text,
|
||||
0);
|
||||
#else
|
||||
png_warning(png_ptr, "Unable to write uncompressed text\n");
|
||||
#endif
|
||||
@@ -149,6 +247,29 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
if (info_ptr->unknown_chunks_num)
|
||||
{
|
||||
png_unknown_chunk *up;
|
||||
|
||||
png_debug(5, "writing extra chunks\n");
|
||||
|
||||
for (up = info_ptr->unknown_chunks;
|
||||
up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
|
||||
up++)
|
||||
{
|
||||
int keep=png_handle_as_unknown(png_ptr, up->name);
|
||||
if (keep != HANDLE_CHUNK_NEVER &&
|
||||
up->location && (up->location & PNG_HAVE_PLTE) &&
|
||||
!(up->location & PNG_HAVE_IDAT) &&
|
||||
((up->name[3] & 0x20) || keep == HANDLE_CHUNK_ALWAYS ||
|
||||
(png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
|
||||
{
|
||||
png_write_chunk(png_ptr, up->name, up->data, up->size);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Writes the end of the PNG file. If you don't want to write comments or
|
||||
@@ -166,27 +287,44 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
|
||||
/* see if user wants us to write information chunks */
|
||||
if (info_ptr != NULL)
|
||||
{
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
#if defined(PNG_WRITE_TEXT_SUPPORTED)
|
||||
int i; /* local index variable */
|
||||
#endif
|
||||
#if defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
/* check to see if user has supplied a time chunk */
|
||||
if (info_ptr->valid & PNG_INFO_tIME &&
|
||||
!(png_ptr->flags & PNG_FLAG_WROTE_tIME))
|
||||
if ((info_ptr->valid & PNG_INFO_tIME) &&
|
||||
!(png_ptr->mode & PNG_WROTE_tIME))
|
||||
png_write_tIME(png_ptr, &(info_ptr->mod_time));
|
||||
#endif
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
#if defined(PNG_WRITE_TEXT_SUPPORTED)
|
||||
/* loop through comment chunks */
|
||||
for (i = 0; i < info_ptr->num_text; i++)
|
||||
{
|
||||
png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
|
||||
info_ptr->text[i].compression);
|
||||
if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
|
||||
/* an internationalized chunk? */
|
||||
if (info_ptr->text[i].compression > 0)
|
||||
{
|
||||
#if defined(PNG_WRITE_iTXt_SUPPORTED)
|
||||
/* write international chunk */
|
||||
png_write_iTXt(png_ptr,
|
||||
info_ptr->text[i].compression,
|
||||
info_ptr->text[i].key,
|
||||
info_ptr->text[i].lang,
|
||||
info_ptr->text[i].lang_key,
|
||||
info_ptr->text[i].text);
|
||||
#else
|
||||
png_warning(png_ptr, "Unable to write international text\n");
|
||||
#endif
|
||||
/* Mark this chunk as written */
|
||||
info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
|
||||
}
|
||||
else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
|
||||
{
|
||||
#if defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
/* write compressed chunk */
|
||||
png_write_zTXt(png_ptr, info_ptr->text[i].key,
|
||||
info_ptr->text[i].text, info_ptr->text[i].text_length,
|
||||
info_ptr->text[i].text, 0,
|
||||
info_ptr->text[i].compression);
|
||||
#else
|
||||
png_warning(png_ptr, "Unable to write compressed text\n");
|
||||
@@ -199,7 +337,7 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED)
|
||||
/* write uncompressed chunk */
|
||||
png_write_tEXt(png_ptr, info_ptr->text[i].key,
|
||||
info_ptr->text[i].text, info_ptr->text[i].text_length);
|
||||
info_ptr->text[i].text, 0);
|
||||
#else
|
||||
png_warning(png_ptr, "Unable to write uncompressed text\n");
|
||||
#endif
|
||||
@@ -208,6 +346,28 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
|
||||
info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
if (info_ptr->unknown_chunks_num)
|
||||
{
|
||||
png_unknown_chunk *up;
|
||||
|
||||
png_debug(5, "writing extra chunks\n");
|
||||
|
||||
for (up = info_ptr->unknown_chunks;
|
||||
up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
|
||||
up++)
|
||||
{
|
||||
int keep=png_handle_as_unknown(png_ptr, up->name);
|
||||
if (keep != HANDLE_CHUNK_NEVER &&
|
||||
up->location && (up->location & PNG_AFTER_IDAT) &&
|
||||
((up->name[3] & 0x20) || keep == HANDLE_CHUNK_ALWAYS ||
|
||||
(png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
|
||||
{
|
||||
png_write_chunk(png_ptr, up->name, up->data, up->size);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -259,8 +419,10 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
{
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
png_structp png_ptr;
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
jmp_buf jmpbuf;
|
||||
#endif
|
||||
#endif
|
||||
png_debug(1, "in png_create_write_struct\n");
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
@@ -272,6 +434,8 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
{
|
||||
return ((png_structp)NULL);
|
||||
}
|
||||
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
if (setjmp(jmpbuf))
|
||||
#else
|
||||
@@ -285,6 +449,8 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
@@ -321,17 +487,23 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
void
|
||||
png_write_init(png_structp png_ptr)
|
||||
{
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
jmp_buf tmp_jmp; /* to save current jump buffer */
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_write_init\n");
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
/* save jump buffer and error functions */
|
||||
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
|
||||
#endif
|
||||
|
||||
/* reset all variables to 0 */
|
||||
png_memset(png_ptr, 0, sizeof (png_struct));
|
||||
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
/* restore jump buffer */
|
||||
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
|
||||
#endif
|
||||
|
||||
/* initialize zbuf - compression buffer */
|
||||
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
|
||||
@@ -443,49 +615,49 @@ png_write_row(png_structp png_ptr, png_bytep row)
|
||||
switch (png_ptr->pass)
|
||||
{
|
||||
case 0:
|
||||
if (png_ptr->row_number & 7)
|
||||
if (png_ptr->row_number & 0x07)
|
||||
{
|
||||
png_write_finish_row(png_ptr);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if ((png_ptr->row_number & 7) || png_ptr->width < 5)
|
||||
if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
|
||||
{
|
||||
png_write_finish_row(png_ptr);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if ((png_ptr->row_number & 7) != 4)
|
||||
if ((png_ptr->row_number & 0x07) != 4)
|
||||
{
|
||||
png_write_finish_row(png_ptr);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if ((png_ptr->row_number & 3) || png_ptr->width < 3)
|
||||
if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
|
||||
{
|
||||
png_write_finish_row(png_ptr);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if ((png_ptr->row_number & 3) != 2)
|
||||
if ((png_ptr->row_number & 0x03) != 2)
|
||||
{
|
||||
png_write_finish_row(png_ptr);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if ((png_ptr->row_number & 1) || png_ptr->width < 2)
|
||||
if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
|
||||
{
|
||||
png_write_finish_row(png_ptr);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
if (!(png_ptr->row_number & 1))
|
||||
if (!(png_ptr->row_number & 0x01))
|
||||
{
|
||||
png_write_finish_row(png_ptr);
|
||||
return;
|
||||
@@ -630,22 +802,14 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
|
||||
|
||||
if (info_ptr != NULL)
|
||||
{
|
||||
#ifdef PNG_WRITE_tEXt_SUPPORTED
|
||||
png_free(png_ptr, info_ptr->text);
|
||||
#endif
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED)
|
||||
png_free(png_ptr, info_ptr->pcal_purpose);
|
||||
png_free(png_ptr, info_ptr->pcal_units);
|
||||
if (info_ptr->pcal_params != NULL)
|
||||
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
|
||||
|
||||
if (png_ptr->num_chunk_list)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->pcal_params[i]);
|
||||
}
|
||||
png_free(png_ptr, info_ptr->pcal_params);
|
||||
png_free(png_ptr, png_ptr->chunk_list);
|
||||
png_ptr->num_chunk_list=0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_destroy_struct_2((png_voidp)info_ptr, free_fn);
|
||||
#else
|
||||
@@ -671,7 +835,9 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
|
||||
void
|
||||
png_write_destroy(png_structp png_ptr)
|
||||
{
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
jmp_buf tmp_jmp; /* save jump buffer */
|
||||
#endif
|
||||
png_error_ptr error_fn;
|
||||
png_error_ptr warning_fn;
|
||||
png_voidp error_ptr;
|
||||
@@ -691,19 +857,23 @@ png_write_destroy(png_structp png_ptr)
|
||||
png_free(png_ptr, png_ptr->up_row);
|
||||
png_free(png_ptr, png_ptr->avg_row);
|
||||
png_free(png_ptr, png_ptr->paeth_row);
|
||||
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
png_free(png_ptr, png_ptr->time_buffer);
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
png_free(png_ptr, png_ptr->prev_filters);
|
||||
png_free(png_ptr, png_ptr->filter_weights);
|
||||
png_free(png_ptr, png_ptr->inv_filter_weights);
|
||||
png_free(png_ptr, png_ptr->filter_costs);
|
||||
png_free(png_ptr, png_ptr->inv_filter_costs);
|
||||
#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
/* reset structure */
|
||||
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
|
||||
#endif
|
||||
|
||||
error_fn = png_ptr->error_fn;
|
||||
warning_fn = png_ptr->warning_fn;
|
||||
@@ -721,7 +891,9 @@ png_write_destroy(png_structp png_ptr)
|
||||
png_ptr->free_fn = free_fn;
|
||||
#endif
|
||||
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Allow the application to select one or more row filters to use. */
|
||||
@@ -756,14 +928,14 @@ png_set_filter(png_structp png_ptr, int method, int filters)
|
||||
*/
|
||||
if (png_ptr->row_buf != NULL)
|
||||
{
|
||||
if (png_ptr->do_filter & PNG_FILTER_SUB && png_ptr->sub_row == NULL)
|
||||
if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
|
||||
{
|
||||
png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
|
||||
(png_ptr->rowbytes + 1));
|
||||
png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
|
||||
}
|
||||
|
||||
if (png_ptr->do_filter & PNG_FILTER_UP && png_ptr->up_row == NULL)
|
||||
if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
|
||||
{
|
||||
if (png_ptr->prev_row == NULL)
|
||||
{
|
||||
@@ -778,7 +950,7 @@ png_set_filter(png_structp png_ptr, int method, int filters)
|
||||
}
|
||||
}
|
||||
|
||||
if (png_ptr->do_filter & PNG_FILTER_AVG && png_ptr->avg_row == NULL)
|
||||
if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
|
||||
{
|
||||
if (png_ptr->prev_row == NULL)
|
||||
{
|
||||
@@ -793,13 +965,13 @@ png_set_filter(png_structp png_ptr, int method, int filters)
|
||||
}
|
||||
}
|
||||
|
||||
if (png_ptr->do_filter & PNG_FILTER_PAETH &&
|
||||
if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
|
||||
png_ptr->paeth_row == NULL)
|
||||
{
|
||||
if (png_ptr->prev_row == NULL)
|
||||
{
|
||||
png_warning(png_ptr, "Can't add Paeth filter after starting");
|
||||
png_ptr->do_filter &= ~PNG_FILTER_PAETH;
|
||||
png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -850,8 +1022,8 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
|
||||
num_weights = 0;
|
||||
}
|
||||
|
||||
png_ptr->num_prev_filters = num_weights;
|
||||
png_ptr->heuristic_method = heuristic_method;
|
||||
png_ptr->num_prev_filters = (png_byte)num_weights;
|
||||
png_ptr->heuristic_method = (png_byte)heuristic_method;
|
||||
|
||||
if (num_weights > 0)
|
||||
{
|
||||
@@ -973,6 +1145,14 @@ png_set_compression_window_bits(png_structp png_ptr, int window_bits)
|
||||
png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
|
||||
else if (window_bits < 8)
|
||||
png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
|
||||
#ifndef WBITS_8_OK
|
||||
/* avoid libpng bug with 256-byte windows */
|
||||
if (window_bits == 8)
|
||||
{
|
||||
png_warning(png_ptr, "Compression window is being reset to 512");
|
||||
window_bits=9;
|
||||
}
|
||||
#endif
|
||||
png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
|
||||
png_ptr->zlib_window_bits = window_bits;
|
||||
}
|
||||
@@ -1003,3 +1183,87 @@ png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
|
||||
png_ptr->write_user_transform_fn = write_user_transform_fn;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(PNG_INFO_IMAGE_SUPPORTED)
|
||||
void png_write_png(png_structp png_ptr, png_infop info_ptr,
|
||||
int transforms,
|
||||
voidp params)
|
||||
{
|
||||
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
|
||||
/* invert the alpha channel from opacity to transparency */
|
||||
if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
|
||||
png_set_invert_alpha(png_ptr);
|
||||
#endif
|
||||
|
||||
/* Write the file header information. */
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
|
||||
/* ------ these transformations don't touch the info structure ------- */
|
||||
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED)
|
||||
/* invert monochrome pixels */
|
||||
if (transforms & PNG_TRANSFORM_INVERT_MONO)
|
||||
png_set_invert_mono(png_ptr);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||
/* Shift the pixels up to a legal bit depth and fill in
|
||||
* as appropriate to correctly scale the image.
|
||||
*/
|
||||
if ((transforms & PNG_TRANSFORM_SHIFT)
|
||||
&& (info_ptr->valid & PNG_INFO_sBIT))
|
||||
png_set_shift(png_ptr, &info_ptr->sig_bit);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
/* pack pixels into bytes */
|
||||
if (transforms & PNG_TRANSFORM_PACKING)
|
||||
png_set_packing(png_ptr);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
|
||||
/* swap location of alpha bytes from ARGB to RGBA */
|
||||
if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
|
||||
png_set_swap_alpha(png_ptr);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_FILLER_SUPPORTED)
|
||||
/* Get rid of filler (OR ALPHA) bytes, pack XRGB/RGBX/ARGB/RGBA into
|
||||
* RGB (4 channels -> 3 channels). The second parameter is not used.
|
||||
*/
|
||||
if (transforms & PNG_TRANSFORM_STRIP_FILLER)
|
||||
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_BGR_SUPPORTED)
|
||||
/* flip BGR pixels to RGB */
|
||||
if (transforms & PNG_TRANSFORM_BGR)
|
||||
png_set_bgr(png_ptr);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_SWAP_SUPPORTED)
|
||||
/* swap bytes of 16-bit files to most significant byte first */
|
||||
if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
|
||||
png_set_swap(png_ptr);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
|
||||
/* swap bits of 1, 2, 4 bit packed pixel formats */
|
||||
if (transforms & PNG_TRANSFORM_PACKSWAP)
|
||||
png_set_packswap(png_ptr);
|
||||
#endif
|
||||
|
||||
/* ----------------------- end of transformations ------------------- */
|
||||
|
||||
/* write the bits */
|
||||
if (info_ptr->valid & PNG_INFO_IDAT)
|
||||
png_write_image(png_ptr, info_ptr->row_pointers);
|
||||
|
||||
/* It is REQUIRED to call this to finish writing the rest of the file */
|
||||
png_write_end(png_ptr, info_ptr);
|
||||
|
||||
if(transforms == 0 || params == (voidp)NULL)
|
||||
/* quiet compiler warnings */ return;
|
||||
}
|
||||
#endif
|
||||
|
||||
25
pngwtran.c
@@ -1,11 +1,11 @@
|
||||
|
||||
/* pngwtran.c - transforms the data in a row for PNG writers
|
||||
*
|
||||
* libpng 1.0.4d - October 6, 1999
|
||||
* libpng 1.0.6e - April 10, 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
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
@@ -19,6 +19,9 @@ png_do_write_transformations(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_do_write_transformations\n");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_USER_TRANSFORM)
|
||||
if(png_ptr->write_user_transform_fn != NULL)
|
||||
@@ -137,7 +140,7 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
|
||||
{
|
||||
png_byte value;
|
||||
|
||||
value = (png_byte)(*sp & 0x3);
|
||||
value = (png_byte)(*sp & 0x03);
|
||||
v |= (value << shift);
|
||||
if (shift == 0)
|
||||
{
|
||||
@@ -169,7 +172,7 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
|
||||
{
|
||||
png_byte value;
|
||||
|
||||
value = (png_byte)(*sp & 0xf);
|
||||
value = (png_byte)(*sp & 0x0f);
|
||||
v |= (value << shift);
|
||||
|
||||
if (shift == 0)
|
||||
@@ -311,7 +314,7 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
|
||||
png_uint_16 value, v;
|
||||
int j;
|
||||
|
||||
v = ((png_uint_16)(*bp) << 8) + *(bp + 1);
|
||||
v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
|
||||
value = 0;
|
||||
for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
|
||||
{
|
||||
@@ -438,7 +441,7 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = 255 - *(sp++);
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
}
|
||||
}
|
||||
/* This inverts the alpha channel in RRGGBBAA */
|
||||
@@ -456,8 +459,8 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = 255 - *(sp++);
|
||||
*(dp++) = 255 - *(sp++);
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -473,7 +476,7 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
for (i = 0, sp = dp = row; i < row_width; i++)
|
||||
{
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = 255 - *(sp++);
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
}
|
||||
}
|
||||
/* This inverts the alpha channel in GGAA */
|
||||
@@ -487,8 +490,8 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = 255 - *(sp++);
|
||||
*(dp++) = 255 - *(sp++);
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
864
pngwutil.c
@@ -1,2 +0,0 @@
|
||||
make -fmakefile.bor -B -DMODEL=m %1 %2 %3 libpng >buildm.out
|
||||
make -fmakefile.bor -B -DMODEL=l %1 %2 %3 libpng >buildl.out
|
||||
43
scripts/libpng.icc
Normal file
@@ -0,0 +1,43 @@
|
||||
// Project file for libpng (static)
|
||||
// IBM VisualAge/C++ version 4.0 or later
|
||||
// Copyright (C) 2000 Cosmin Truta
|
||||
// Notes:
|
||||
// All modules are compiled in C mode
|
||||
// Tested with IBM VAC++ 4.0 under Win32
|
||||
// Expected to work with IBM VAC++ 4.0 or later under OS/2 and Win32
|
||||
// Can be easily adapted for IBM VAC++ 4.0 or later under AIX
|
||||
// For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
option incl(searchpath, "../zlib"), opt(level, "2"),
|
||||
link(libsearchpath, "../zlib")
|
||||
{
|
||||
target type(lib) "libpng.lib"
|
||||
{
|
||||
source type(c) "png.c"
|
||||
source type(c) "pngerror.c"
|
||||
source type(c) "pngget.c"
|
||||
source type(c) "pngmem.c"
|
||||
source type(c) "pngpread.c"
|
||||
source type(c) "pngread.c"
|
||||
source type(c) "pngrio.c"
|
||||
source type(c) "pngrtran.c"
|
||||
source type(c) "pngrutil.c"
|
||||
source type(c) "pngset.c"
|
||||
source type(c) "pngtrans.c"
|
||||
source type(c) "pngwio.c"
|
||||
source type(c) "pngwrite.c"
|
||||
source type(c) "pngwtran.c"
|
||||
source type(c) "pngwutil.c"
|
||||
}
|
||||
}
|
||||
|
||||
option incl(searchpath, "../zlib"), opt(level, "2"),
|
||||
link(libsearchpath, "../zlib")
|
||||
{
|
||||
target type(exe) "pngtest.exe"
|
||||
{
|
||||
source type(c) "pngtest.c"
|
||||
source type(lib) "libpng.lib"
|
||||
source type(lib) "zlib.lib"
|
||||
}
|
||||
}
|
||||
151
scripts/makefile.bc32
Normal file
@@ -0,0 +1,151 @@
|
||||
# Makefile for libpng
|
||||
# 32-bit Borland C++ (Note: All modules are compiled in C mode)
|
||||
# To build the library, do:
|
||||
# "make -fmakefile.bc32"
|
||||
#
|
||||
# ---------- 32-bit Borland C++ ----------
|
||||
|
||||
### Absolutely necessary for this makefile to work
|
||||
.AUTODEPEND
|
||||
|
||||
## Where zlib.h, zconf.h and zlib.lib are
|
||||
ZLIB_DIR=..\zlib
|
||||
|
||||
|
||||
## Compiler, linker and lib stuff
|
||||
CC=bcc32
|
||||
LD=bcc32
|
||||
LIB=tlib
|
||||
|
||||
#TARGET_CPU=6
|
||||
# 3 = 386, 4 = 486, 5 = Pentium etc.
|
||||
!ifndef TARGET_CPU
|
||||
TARGET_CPU=5
|
||||
!endif
|
||||
|
||||
# Use this if you don't want Borland's fancy exception handling
|
||||
NOEHLIB=noeh32.lib
|
||||
|
||||
!ifdef DEBUG
|
||||
CDEBUG=-v
|
||||
LDEBUG=-v
|
||||
!else
|
||||
CDEBUG=
|
||||
LDEBUG=
|
||||
!endif
|
||||
|
||||
# STACKOFLOW=1
|
||||
!ifdef STACKOFLOW
|
||||
CDEBUG=$(CDEBUG) -N
|
||||
LDEBUG=$(LDEBUG) -N
|
||||
!endif
|
||||
|
||||
# -X- turn on dependency generation in the object file
|
||||
# -w set all warnings on
|
||||
# -O2 optimize for speed
|
||||
# -Z global optimization
|
||||
CFLAGS=-O2 -Z -X- -w -I$(ZLIB_DIR) -$(TARGET_CPU) $(CDEBUG)
|
||||
|
||||
# -M generate map file
|
||||
LDFLAGS=-M -L$(ZLIB_DIR) $(LDEBUG)
|
||||
|
||||
|
||||
## Variables
|
||||
OBJS = \
|
||||
png.obj \
|
||||
pngerror.obj \
|
||||
pngget.obj \
|
||||
pngmem.obj \
|
||||
pngpread.obj \
|
||||
pngread.obj \
|
||||
pngrio.obj \
|
||||
pngrtran.obj \
|
||||
pngrutil.obj \
|
||||
pngset.obj \
|
||||
pngtrans.obj \
|
||||
pngwio.obj \
|
||||
pngwrite.obj \
|
||||
pngwtran.obj \
|
||||
pngwutil.obj
|
||||
|
||||
LIBOBJS = \
|
||||
+png.obj \
|
||||
+pngerror.obj \
|
||||
+pngget.obj \
|
||||
+pngmem.obj \
|
||||
+pngpread.obj \
|
||||
+pngread.obj \
|
||||
+pngrio.obj \
|
||||
+pngrtran.obj \
|
||||
+pngrutil.obj \
|
||||
+pngset.obj \
|
||||
+pngtrans.obj \
|
||||
+pngwio.obj \
|
||||
+pngwrite.obj \
|
||||
+pngwtran.obj \
|
||||
+pngwutil.obj
|
||||
|
||||
LIBNAME=libpng.lib
|
||||
|
||||
|
||||
## Implicit rules
|
||||
# Braces let make "batch" calls to the compiler,
|
||||
# 2 calls instead of 12; space is important.
|
||||
.c.obj:
|
||||
$(CC) $(CFLAGS) -c {$*.c }
|
||||
|
||||
.c.exe:
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $*.c $(LIBNAME) zlib.lib $(NOEHLIB)
|
||||
|
||||
.obj.exe:
|
||||
$(LD) $(LDFLAGS) $*.obj $(LIBNAME) zlib.lib $(NOEHLIB)
|
||||
|
||||
|
||||
## Major targets
|
||||
all: libpng pngtest
|
||||
|
||||
libpng: $(LIBNAME)
|
||||
|
||||
pngtest: pngtest.exe
|
||||
|
||||
test: pngtest.exe
|
||||
pngtest
|
||||
|
||||
|
||||
## Minor Targets
|
||||
|
||||
png.obj: png.c
|
||||
pngerror.obj: pngerror.c
|
||||
pngget.obj: pngget.c
|
||||
pngmem.obj: pngmem.c
|
||||
pngpread.obj: pngpread.c
|
||||
pngread.obj: pngread.c
|
||||
pngrio.obj: pngrio.c
|
||||
pngrtran.obj: pngrtran.c
|
||||
pngrutil.obj: pngrutil.c
|
||||
pngset.obj: pngset.c
|
||||
pngtrans.obj: pngtrans.c
|
||||
pngwio.obj: pngwio.c
|
||||
pngwrite.obj: pngwrite.c
|
||||
pngwtran.obj: pngwtran.c
|
||||
pngwutil.obj: pngwutil.c
|
||||
|
||||
|
||||
$(LIBNAME): $(OBJS)
|
||||
-del $(LIBNAME)
|
||||
$(LIB) $(LIBNAME) @&&|
|
||||
$(LIBOBJS), libpng
|
||||
|
|
||||
|
||||
|
||||
# Clean up anything else you want
|
||||
clean:
|
||||
-del *.obj
|
||||
-del *.exe
|
||||
-del *.lib
|
||||
-del *.lst
|
||||
-del *.map
|
||||
-del *.tds
|
||||
|
||||
|
||||
# End of makefile for libpng
|
||||
@@ -1,5 +1,5 @@
|
||||
# Makefile for png32bd.dll
|
||||
# ------------- Borland C++ 4.5 -------------
|
||||
# ------------- 32-bit Borland C++ -------------
|
||||
|
||||
# This makefile expects to find zlib.h and zlib32bd.lib in the
|
||||
# $(ZLIBDIR) directory.
|
||||
@@ -12,42 +12,65 @@
|
||||
# compress and uncompress functions, nor any of the gz... functions,
|
||||
# since libpng does not call them.
|
||||
|
||||
ZLIBDIR=..\zlib112
|
||||
.AUTODEPEND
|
||||
|
||||
ZLIBDIR=..\zlib
|
||||
ZLIB=zlib32bd.lib
|
||||
PNGDLL=png32bd.dll
|
||||
PNGLIB=png32bd.lib
|
||||
|
||||
CFLAGS= -ps -O2 -C -K -N- -k- -d -3 -r- -w-par -w-aus -WDE -I$(ZLIBDIR)
|
||||
CC=f:\bc45\bin\bcc32
|
||||
LINKFLAGS= -Tpd -aa -c
|
||||
LINK=f:\bc45\bin\tlink32
|
||||
LIBDIR=f:\bc45\lib
|
||||
IMPLIB=f:\bc45\bin\implib
|
||||
CC=bcc32
|
||||
CFLAGS= -ps -O2 -N- -k- -d -r- -w-par -w-aus -I$(ZLIBDIR) \
|
||||
-DPNG_NO_GLOBAL_ARRAYS #-DPNG_DEBUG=5
|
||||
#LINK=tlink32
|
||||
#LINK=ilink32
|
||||
LINK=bcc32
|
||||
#LINKFLAGS= -Tpd -aa -c
|
||||
LINKFLAGS= -WDE
|
||||
IMPLIB=implib
|
||||
|
||||
# Use this if you don't want Borland's fancy exception handling
|
||||
NOEHLIB=noeh32.lib
|
||||
|
||||
.autodepend
|
||||
.c.obj:
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
|
||||
OBJ1=png.obj pngerror.obj pngget.obj pngmem.obj pngpread.obj
|
||||
OBJ2=pngread.obj pngrio.obj pngrtran.obj pngrutil.obj pngset.obj
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
|
||||
.c.exe:
|
||||
$(CC) $(CFLAGS) $< $(PNGLIB) $(NOEHLIB)
|
||||
|
||||
|
||||
OBJ1=png.obj pngerror.obj pngget.obj pngmem.obj pngpread.obj
|
||||
OBJ2=pngread.obj pngrio.obj pngrtran.obj pngrutil.obj pngset.obj
|
||||
OBJ3=pngtrans.obj pngwio.obj pngwrite.obj pngwtran.obj pngwutil.obj
|
||||
|
||||
all: $(PNGDLL)
|
||||
|
||||
test: pngtest.exe
|
||||
pngtest
|
||||
|
||||
|
||||
$(PNGDLL): $(OBJ1) $(OBJ2) $(OBJ3) $(ZLIBDIR)\$(ZLIB)
|
||||
$(LINK) @&&|
|
||||
$(LINKFLAGS) $(LIBDIR)\c0d32 +
|
||||
$(OBJ1) +
|
||||
$(OBJ2) +
|
||||
$(LINK) @&&|
|
||||
$(LINKFLAGS)
|
||||
-e$(PNGDLL)
|
||||
$(OBJ1)
|
||||
$(OBJ2)
|
||||
$(OBJ3)
|
||||
$@
|
||||
-x
|
||||
$(ZLIBDIR)\$(ZLIB) $(LIBDIR)\import32 $(LIBDIR)\cw32
|
||||
|,&&|
|
||||
LIBRARY $(@B)
|
||||
EXETYPE WINDOWS
|
||||
CODE PRELOAD MOVEABLE DISCARDABLE
|
||||
DATA PRELOAD MOVEABLE MULTIPLE
|
||||
$(ZLIBDIR)\$(ZLIB)
|
||||
$(NOEHLIB)
|
||||
|
|
||||
$(IMPLIB) -c $(@R).lib $@
|
||||
$(IMPLIB) -c $(@R).lib $@
|
||||
|
||||
|
||||
# Clean up anything else you want
|
||||
clean:
|
||||
-del *.obj
|
||||
-del *.dll
|
||||
-del *.exe
|
||||
-del *.lib
|
||||
-del *.lst
|
||||
-del *.map
|
||||
-del *.tds
|
||||
|
||||
|
||||
# End of makefile for png32bd.dll
|
||||
@@ -31,7 +31,7 @@ RANLIB=ranlib
|
||||
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not
|
||||
# have to change it.
|
||||
PNGMAJ = 2
|
||||
PNGMIN = 1.0.4d
|
||||
PNGMIN = 1.0.6e
|
||||
PNGVER = $(PNGMAJ).$(PNGMIN)
|
||||
|
||||
# where make install puts libpng.a, libpng.so*, and png.h
|
||||
|
||||
@@ -1,39 +1,38 @@
|
||||
# Makefile for libpng
|
||||
# Borland C++ 4.5 (Note: All modules are compiled in C mode)
|
||||
# Will work with C++ 4.02 also
|
||||
# To build the library, do:
|
||||
# "make -fmakefile.borland -DMODEL=m"
|
||||
# or: "make -fmakefile.borland -DMODEL=l"
|
||||
# 16-bit Borland C++ (Note: All modules are compiled in C mode)
|
||||
# To build the library, do:
|
||||
# "make -fmakefile.bor -DMODEL=c"
|
||||
# or: "make -fmakefile.bor -DMODEL=l"
|
||||
#
|
||||
# ------------- Borland C++ 4.5 -------------
|
||||
# ------------ Borland C++ ------------
|
||||
|
||||
### Absolutely necessary for this makefile to work
|
||||
.AUTODEPEND
|
||||
|
||||
## Useful user options
|
||||
## Where zlib.h, zconf.h and zlib_MODEL.lib are
|
||||
ZLIB_DIR=..\zlib
|
||||
|
||||
# Usually defined in builtins.mak or the environment
|
||||
# Currently unused.
|
||||
!ifndef BCROOT
|
||||
BCROOT=N:\BC45
|
||||
!endif
|
||||
|
||||
# Where zlib.h and zconf.h and zlib.lib are
|
||||
ZLIB_PATH=..\zlib
|
||||
## Compiler, linker and lib stuff
|
||||
CC=bcc
|
||||
LD=bcc
|
||||
LIB=tlib
|
||||
|
||||
!ifndef MODEL
|
||||
MODEL=l
|
||||
!endif
|
||||
|
||||
MODEL_ARG=-m$(MODEL)
|
||||
|
||||
#TARGET_CPU=3
|
||||
# 2 = 286, 3 = 386, etc.
|
||||
!ifndef TARGET_CPU
|
||||
TARGET_CPU=2
|
||||
!endif
|
||||
|
||||
|
||||
# Use this if you don't want Borland's fancy exception handling.
|
||||
NOEHLIB=noeh$(MODEL).lib
|
||||
# Use this if you don't want Borland's fancy exception handling
|
||||
# (for Borland C++ 4.0 or later)
|
||||
#NOEHLIB=noeh$(MODEL).lib
|
||||
|
||||
!ifdef DEBUG
|
||||
CDEBUG=-v
|
||||
@@ -49,59 +48,50 @@ CDEBUG=$(CDEBUG) -N
|
||||
LDEBUG=$(LDEBUG) -N
|
||||
!endif
|
||||
|
||||
|
||||
## Compiler, linker, and lib stuff
|
||||
CC=bcc
|
||||
LD=bcc
|
||||
LIB=tlib
|
||||
|
||||
MODELARG=-m$(MODEL)
|
||||
|
||||
# -X- turns on dependency generation in the object file
|
||||
# -w sets all warnings on
|
||||
# -X- turn on dependency generation in the object file
|
||||
# -w set all warnings on
|
||||
# -O2 optimize for speed
|
||||
# -Z global optimization
|
||||
CFLAGS=-O2 -Z -X- -w -I$(ZLIB_PATH) -$(TARGET_CPU) $(MODELARG) $(CDEBUG)
|
||||
CFLAGS=-O2 -Z -X- -w -I$(ZLIB_DIR) -$(TARGET_CPU) $(MODEL_ARG) $(CDEBUG)
|
||||
|
||||
# -M generate map file
|
||||
LDFLAGS=-M $(LDEBUG)
|
||||
LDFLAGS=-M -L$(ZLIB_DIR) $(MODEL_ARG) $(LDEBUG)
|
||||
|
||||
O=obj
|
||||
|
||||
## variables
|
||||
## Variables
|
||||
OBJS = \
|
||||
png.$(O) \
|
||||
pngerror.$(O) \
|
||||
pngmem.$(O) \
|
||||
pngpread.$(O) \
|
||||
pngset.$(O) \
|
||||
pngget.$(O) \
|
||||
pngread.$(O) \
|
||||
pngrio.$(O) \
|
||||
pngrtran.$(O) \
|
||||
pngrutil.$(O) \
|
||||
pngtrans.$(O) \
|
||||
pngwrite.$(O) \
|
||||
pngwtran.$(O) \
|
||||
pngwio.$(O) \
|
||||
pngwutil.$(O)
|
||||
png.obj \
|
||||
pngerror.obj \
|
||||
pngget.obj \
|
||||
pngmem.obj \
|
||||
pngpread.obj \
|
||||
pngread.obj \
|
||||
pngrio.obj \
|
||||
pngrtran.obj \
|
||||
pngrutil.obj \
|
||||
pngset.obj \
|
||||
pngtrans.obj \
|
||||
pngwio.obj \
|
||||
pngwrite.obj \
|
||||
pngwtran.obj \
|
||||
pngwutil.obj
|
||||
|
||||
LIBOBJS = \
|
||||
+png.$(O) \
|
||||
+pngerror.$(O) \
|
||||
+pngmem.$(O) \
|
||||
+pngpread.$(O) \
|
||||
+pngread.$(O) \
|
||||
+pngset.$(O) \
|
||||
+pngget.$(O) \
|
||||
+pngrio.$(O) \
|
||||
+pngrtran.$(O) \
|
||||
+pngrutil.$(O) \
|
||||
+pngtrans.$(O) \
|
||||
+pngwrite.$(O) \
|
||||
+pngwtran.$(O) \
|
||||
+pngwio.$(O) \
|
||||
+pngwutil.$(O)
|
||||
+png.obj \
|
||||
+pngerror.obj \
|
||||
+pngget.obj \
|
||||
+pngmem.obj \
|
||||
+pngpread.obj \
|
||||
+pngread.obj \
|
||||
+pngrio.obj \
|
||||
+pngrtran.obj \
|
||||
+pngrutil.obj \
|
||||
+pngset.obj \
|
||||
+pngtrans.obj \
|
||||
+pngwio.obj \
|
||||
+pngwrite.obj \
|
||||
+pngwtran.obj \
|
||||
+pngwutil.obj
|
||||
|
||||
LIBNAME=libpng$(MODEL).lib
|
||||
|
||||
@@ -113,10 +103,12 @@ LIBNAME=libpng$(MODEL).lib
|
||||
$(CC) $(CFLAGS) -c {$*.c }
|
||||
|
||||
.c.exe:
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $*.c
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $*.c $(LIBNAME) zlib_$(MODEL).lib $(NOEHLIB)
|
||||
|
||||
|
||||
## Major targets
|
||||
all: libpng pngtest
|
||||
|
||||
libpng: $(LIBNAME)
|
||||
|
||||
pngtest: pngtest$(MODEL).exe
|
||||
@@ -128,17 +120,17 @@ test: pngtest$(MODEL).exe
|
||||
## Minor Targets
|
||||
|
||||
png.obj: png.c
|
||||
pngset.obj: pngset.c
|
||||
pngerror.obj: pngerror.c
|
||||
pngget.obj: pngget.c
|
||||
pngread.obj: pngread.c
|
||||
pngmem.obj: pngmem.c
|
||||
pngpread.obj: pngpread.c
|
||||
pngread.obj: pngread.c
|
||||
pngrio.obj: pngrio.c
|
||||
pngrtran.obj: pngrtran.c
|
||||
pngrutil.obj: pngrutil.c
|
||||
pngerror.obj: pngerror.c
|
||||
pngmem.obj: pngmem.c
|
||||
pngrio.obj: pngrio.c
|
||||
pngwio.obj: pngwio.c
|
||||
pngset.obj: pngset.c
|
||||
pngtrans.obj: pngtrans.c
|
||||
pngwio.obj: pngwio.c
|
||||
pngwrite.obj: pngwrite.c
|
||||
pngwtran.obj: pngwtran.c
|
||||
pngwutil.obj: pngwutil.c
|
||||
@@ -155,14 +147,16 @@ pngtest$(MODEL).obj: pngtest.c
|
||||
$(CC) $(CFLAGS) -opngtest$(MODEL) -c pngtest.c
|
||||
|
||||
pngtest$(MODEL).exe: pngtest$(MODEL).obj
|
||||
$(CC) $(MODELARG) $(LDFLAGS) -L$(ZLIB_PATH) pngtest$(MODEL).obj $(LIBNAME) zlib$(MODEL).lib $(NOEHLIB)
|
||||
$(LD) $(LDFLAGS) pngtest$(MODEL).obj $(LIBNAME) zlib_$(MODEL).lib $(NOEHLIB)
|
||||
|
||||
|
||||
# Clean up anything else you want
|
||||
clean:
|
||||
-del *.obj
|
||||
-del *.exe
|
||||
-del *.lib
|
||||
-del *.lst
|
||||
-del *.map
|
||||
|
||||
|
||||
# End of makefile for libpng
|
||||
@@ -14,7 +14,7 @@ ZLIBINC=../zlib
|
||||
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not
|
||||
# have to change it.
|
||||
PNGMAJ = 2
|
||||
PNGMIN = 1.0.4d
|
||||
PNGMIN = 1.0.6e
|
||||
PNGVER = $(PNGMAJ).$(PNGMIN)
|
||||
|
||||
CC=cc
|
||||
|
||||
66
scripts/makefile.gcc
Normal file
@@ -0,0 +1,66 @@
|
||||
# makefile for libpng using gcc (generic, static library)
|
||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||
# Copyright (C) 2000 Cosmin Truta
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
# Location of the zlib library and include files
|
||||
ZLIBINC = ../zlib
|
||||
ZLIBLIB = ../zlib
|
||||
|
||||
# Compiler, linker, lib and other tools
|
||||
CC = gcc
|
||||
LD = $(CC)
|
||||
AR = ar rcs
|
||||
RANLIB = ranlib
|
||||
RM = rm -f
|
||||
|
||||
CDEBUG = -g -DPNG_DEBUG=5
|
||||
LDDEBUG =
|
||||
CRELEASE = -O2
|
||||
LDRELEASE = -s
|
||||
CFLAGS = -I$(ZLIBINC) -Wall $(CRELEASE)
|
||||
LDFLAGS = -L. -L$(ZLIBLIB) -lpng -lz -lm $(LDRELEASE)
|
||||
|
||||
# File extensions
|
||||
O=.o
|
||||
A=.a
|
||||
E=
|
||||
|
||||
# Variables
|
||||
OBJS = png$(O) pngerror$(O) pngget$(O) pngmem$(O) pngpread$(O) \
|
||||
pngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) pngset$(O) \
|
||||
pngtrans$(O) pngwio$(O) pngwrite$(O) pngwtran$(O) pngwutil$(O)
|
||||
|
||||
# Targets
|
||||
all: libpng$(A) pngtest$(E)
|
||||
|
||||
libpng$(A): $(OBJS)
|
||||
$(AR) $@ $(OBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
test: pngtest$(E)
|
||||
./pngtest$(E)
|
||||
|
||||
pngtest$(E): pngtest$(O) libpng$(A)
|
||||
$(LD) -o $@ pngtest$(O) $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
$(RM) *$(O) libpng$(A) pngtest$(E) pngout.png
|
||||
|
||||
png$(O): png.h pngconf.h
|
||||
pngerror$(O): png.h pngconf.h
|
||||
pngget$(O): png.h pngconf.h
|
||||
pngmem$(O): png.h pngconf.h
|
||||
pngpread$(O): png.h pngconf.h
|
||||
pngread$(O): png.h pngconf.h
|
||||
pngrio$(O): png.h pngconf.h
|
||||
pngrtran$(O): png.h pngconf.h
|
||||
pngrutil$(O): png.h pngconf.h
|
||||
pngset$(O): png.h pngconf.h
|
||||
pngtest$(O): png.h pngconf.h
|
||||
pngtrans$(O): png.h pngconf.h
|
||||
pngwio$(O): png.h pngconf.h
|
||||
pngwrite$(O): png.h pngconf.h
|
||||
pngwtran$(O): png.h pngconf.h
|
||||
pngwutil$(O): png.h pngconf.h
|
||||
|
||||
126
scripts/makefile.gcmmx
Normal file
@@ -0,0 +1,126 @@
|
||||
# makefile for libpng on Linux ELF with gcc using MMX assembler code
|
||||
# Copyright (C) 1996, 1997 Andreas Dilger
|
||||
# Copyright (C) 1998-2000 Greg Roelofs
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
CC=gcc
|
||||
|
||||
# where "make install" puts libpng.a, libpng.so*, png.h and pngconf.h
|
||||
prefix=/usr/local
|
||||
|
||||
# Where the zlib library and include files are located
|
||||
#ZLIBLIB=/usr/local/lib
|
||||
#ZLIBINC=/usr/local/include
|
||||
ZLIBLIB=../zlib
|
||||
ZLIBINC=../zlib
|
||||
|
||||
ALIGN=
|
||||
# for i386:
|
||||
#ALIGN=-malign-loops=2 -malign-functions=2
|
||||
|
||||
WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
|
||||
-Wmissing-declarations -Wtraditional -Wcast-align \
|
||||
-Wstrict-prototypes -Wmissing-prototypes #-Wconversion
|
||||
|
||||
# for pgcc version 2.95.1, -O3 is buggy; don't use it.
|
||||
|
||||
CFLAGS=-DPNG_USE_PNGGCCRD -I$(ZLIBINC) -Wall -O3 $(ALIGN) -funroll-loops \
|
||||
-fomit-frame-pointer # $(WARNMORE) -g -DPNG_DEBUG=5
|
||||
LDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng -lz -lm
|
||||
|
||||
RANLIB=ranlib
|
||||
#RANLIB=echo
|
||||
|
||||
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not
|
||||
# have to change it.
|
||||
PNGMAJ = 2
|
||||
PNGMIN = 1.0.6e
|
||||
PNGVER = $(PNGMAJ).$(PNGMIN)
|
||||
|
||||
INCPATH=$(prefix)/include
|
||||
LIBPATH=$(prefix)/lib
|
||||
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o pnggccrd.o
|
||||
|
||||
OBJSDLL = $(OBJS:.o=.pic.o)
|
||||
|
||||
.SUFFIXES: .c .o .pic.o
|
||||
|
||||
.c.pic.o:
|
||||
$(CC) -c $(CFLAGS) -fPIC -o $@ $*.c
|
||||
|
||||
all: libpng.a libpng.so pngtest
|
||||
|
||||
pnggccrd.o: png.h pngconf.h pngasmrd.h
|
||||
@echo ""
|
||||
@echo ' You can ignore the single "control reaches end of non-void function"'
|
||||
@echo ' warning and multiple "<variable> defined but not used" warnings:'
|
||||
@echo ""
|
||||
$(CC) -c $(CFLAGS) -o $@ $*.c
|
||||
|
||||
pnggccrd.pic.o: png.h pngconf.h pngasmrd.h
|
||||
@echo ""
|
||||
@echo ' You can ignore the single "control reaches end of non-void function"'
|
||||
@echo ' warning and multiple "<variable> defined but not used" warnings:'
|
||||
@echo ""
|
||||
$(CC) -c $(CFLAGS) -fPIC -o $@ pnggccrd.c
|
||||
|
||||
libpng.a: $(OBJS)
|
||||
ar rc $@ $(OBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
libpng.so: libpng.so.$(PNGMAJ)
|
||||
ln -sf libpng.so.$(PNGMAJ) libpng.so
|
||||
|
||||
libpng.so.$(PNGMAJ): libpng.so.$(PNGVER)
|
||||
ln -sf libpng.so.$(PNGVER) libpng.so.$(PNGMAJ)
|
||||
|
||||
libpng.so.$(PNGVER): $(OBJSDLL)
|
||||
$(CC) -shared -Wl,-soname,libpng.so.$(PNGMAJ) -o libpng.so.$(PNGVER) \
|
||||
$(OBJSDLL) -L$(ZLIBLIB) -lz -lm -lc
|
||||
|
||||
pngtest: pngtest.o libpng.so
|
||||
$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
|
||||
|
||||
test: pngtest
|
||||
./pngtest
|
||||
|
||||
install: libpng.a libpng.so.$(PNGVER)
|
||||
-@if [ ! -d $(INCPATH) ]; then mkdir $(INCPATH); fi
|
||||
-@if [ ! -d $(LIBPATH) ]; then mkdir $(LIBPATH); fi
|
||||
cp png.h pngconf.h $(INCPATH)
|
||||
chmod 644 $(INCPATH)/png.h $(INCPATH)/pngconf.h
|
||||
cp libpng.a libpng.so.$(PNGVER) $(LIBPATH)
|
||||
chmod 755 $(LIBPATH)/libpng.so.$(PNGVER)
|
||||
-@/bin/rm -f $(LIBPATH)/libpng.so.$(PNGMAJ) $(LIBPATH)/libpng.so
|
||||
(cd $(LIBPATH); ln -sf libpng.so.$(PNGVER) libpng.so.$(PNGMAJ); \
|
||||
ln -sf libpng.so.$(PNGMAJ) libpng.so)
|
||||
|
||||
clean:
|
||||
/bin/rm -f *.o libpng.a libpng.so* pngtest pngout.png
|
||||
|
||||
DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
|
||||
writelock:
|
||||
chmod a-w *.[ch35] $(DOCS) scripts/*
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
png.o png.pic.o: png.h pngconf.h
|
||||
pngerror.o pngerror.pic.o: png.h pngconf.h
|
||||
pngrio.o pngrio.pic.o: png.h pngconf.h
|
||||
pngwio.o pngwio.pic.o: png.h pngconf.h
|
||||
pngmem.o pngmem.pic.o: png.h pngconf.h
|
||||
pngset.o pngset.pic.o: png.h pngconf.h
|
||||
pngget.o pngget.pic.o: png.h pngconf.h
|
||||
pngread.o pngread.pic.o: png.h pngconf.h
|
||||
pngrtran.o pngrtran.pic.o: png.h pngconf.h
|
||||
pngrutil.o pngrutil.pic.o: png.h pngconf.h
|
||||
pngtrans.o pngtrans.pic.o: png.h pngconf.h
|
||||
pngwrite.o pngwrite.pic.o: png.h pngconf.h
|
||||
pngwtran.o pngwtran.pic.o: png.h pngconf.h
|
||||
pngwutil.o pngwutil.pic.o: png.h pngconf.h
|
||||
pngpread.o pngpread.pic.o: png.h pngconf.h
|
||||
|
||||
pngtest.o: png.h pngconf.h
|
||||
@@ -47,6 +47,10 @@ install: libpng.a
|
||||
clean:
|
||||
rm -f *.o libpng.a pngtest pngout.png
|
||||
|
||||
DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
|
||||
writelock:
|
||||
chmod a-w *.[ch35] $(DOCS) scripts/*
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
png.o: png.h pngconf.h
|
||||
|
||||
71
scripts/makefile.ibmc
Normal file
@@ -0,0 +1,71 @@
|
||||
# Makefile for libpng (static)
|
||||
# IBM C version 3.x for Win32 and OS/2
|
||||
# Copyright (C) 2000 Cosmin Truta
|
||||
# Notes:
|
||||
# Derived from makefile.std
|
||||
# All modules are compiled in C mode
|
||||
# Tested with IBM C 3.6.5 under Win32, expected to work under OS/2 too
|
||||
# Can be easily adapted for IBM VisualAge/C++ for AIX
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
# Location of the zlib library and include files
|
||||
ZLIBINC = ../zlib
|
||||
ZLIBLIB = ../zlib
|
||||
|
||||
# Compiler, linker, lib and other tools
|
||||
CC = icc
|
||||
LD = ilink
|
||||
AR = ilib
|
||||
RM = del
|
||||
|
||||
CFLAGS = -I$(ZLIBINC) -O2 -W3
|
||||
LDFLAGS =
|
||||
|
||||
# File extensions
|
||||
O=.obj
|
||||
A=.lib
|
||||
E=.exe
|
||||
|
||||
# Variables
|
||||
OBJS = png$(O) pngerror$(O) pngget$(O) pngmem$(O) pngpread$(O) \
|
||||
pngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) pngset$(O) \
|
||||
pngtrans$(O) pngwio$(O) pngwrite$(O) pngwtran$(O) pngwutil$(O)
|
||||
|
||||
LIBS = libpng$(A) $(ZLIBLIB)/zlib$(A)
|
||||
|
||||
# Targets
|
||||
all: libpng$(A) pngtest$(E)
|
||||
|
||||
libpng$(A): $(OBJS)
|
||||
$(AR) -out:$@ $(OBJS)
|
||||
|
||||
test: pngtest$(E)
|
||||
pngtest$(E)
|
||||
|
||||
pngtest: pngtest$(E)
|
||||
|
||||
pngtest$(E): pngtest$(O) libpng$(A)
|
||||
$(LD) $(LDFLAGS) pngtest$(O) $(LIBS)
|
||||
|
||||
clean:
|
||||
$(RM) *$(O)
|
||||
$(RM) libpng$(A)
|
||||
$(RM) pngtest$(E)
|
||||
$(RM) pngout.png
|
||||
|
||||
png$(O): png.h pngconf.h
|
||||
pngerror$(O): png.h pngconf.h
|
||||
pngget$(O): png.h pngconf.h
|
||||
pngmem$(O): png.h pngconf.h
|
||||
pngpread$(O): png.h pngconf.h
|
||||
pngread$(O): png.h pngconf.h
|
||||
pngrio$(O): png.h pngconf.h
|
||||
pngrtran$(O): png.h pngconf.h
|
||||
pngrutil$(O): png.h pngconf.h
|
||||
pngset$(O): png.h pngconf.h
|
||||
pngtest$(O): png.h pngconf.h
|
||||
pngtrans$(O): png.h pngconf.h
|
||||
pngwio$(O): png.h pngconf.h
|
||||
pngwrite$(O): png.h pngconf.h
|
||||
pngwtran$(O): png.h pngconf.h
|
||||
pngwutil$(O): png.h pngconf.h
|
||||
@@ -2,7 +2,7 @@
|
||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
# This makefile requires file file ansi2knr.c, which you can get
|
||||
# This makefile requires the file ansi2knr.c, which you can get
|
||||
# from the Ghostscript ftp site at ftp://ftp.cs.wisc.edu/ghost/
|
||||
# If you have libjpeg, you probably already have ansi2knr.c in the jpeg
|
||||
# source distribution.
|
||||
@@ -58,6 +58,10 @@ install: libpng.a
|
||||
clean:
|
||||
rm -f *.o libpng.a pngtest pngout.png ansi2knr
|
||||
|
||||
DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
|
||||
writelock:
|
||||
chmod a-w *.[ch35] $(DOCS) scripts/*
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
png.o: png.h pngconf.h
|
||||
|
||||
@@ -22,7 +22,7 @@ WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
|
||||
-Wmissing-declarations -Wtraditional -Wcast-align \
|
||||
-Wstrict-prototypes -Wmissing-prototypes #-Wconversion
|
||||
|
||||
# for pgcc version 2.95.1, -O3 is buggy; don't us it.
|
||||
# for pgcc version 2.95.1, -O3 is buggy; don't use it.
|
||||
|
||||
CFLAGS=-I$(ZLIBINC) -Wall -O3 -funroll-loops \
|
||||
$(ALIGN) # $(WARNMORE) -g -DPNG_DEBUG=5
|
||||
@@ -34,7 +34,7 @@ RANLIB=ranlib
|
||||
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not
|
||||
# have to change it.
|
||||
PNGMAJ = 2
|
||||
PNGMIN = 1.0.4d
|
||||
PNGMIN = 1.0.6e
|
||||
PNGVER = $(PNGMAJ).$(PNGMIN)
|
||||
|
||||
INCPATH=$(prefix)/include
|
||||
@@ -74,7 +74,8 @@ test: pngtest
|
||||
./pngtest
|
||||
|
||||
install: libpng.a libpng.so.$(PNGVER)
|
||||
-@mkdir $(INCPATH) $(LIBPATH)
|
||||
-@if [ ! -d $(INCPATH) ]; then mkdir $(INCPATH); fi
|
||||
-@if [ ! -d $(LIBPATH) ]; then mkdir $(LIBPATH); fi
|
||||
cp png.h pngconf.h $(INCPATH)
|
||||
chmod 644 $(INCPATH)/png.h $(INCPATH)/pngconf.h
|
||||
cp libpng.a libpng.so.$(PNGVER) $(LIBPATH)
|
||||
@@ -86,6 +87,10 @@ install: libpng.a libpng.so.$(PNGVER)
|
||||
clean:
|
||||
/bin/rm -f *.o libpng.a libpng.so* pngtest pngout.png
|
||||
|
||||
DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
|
||||
writelock:
|
||||
chmod a-w *.[ch35] $(DOCS) scripts/*
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
png.o png.pic.o: png.h pngconf.h
|
||||
|
||||
@@ -42,6 +42,10 @@ install: libpng.a
|
||||
clean:
|
||||
rm -f *.o libpng.a pngtest pngout.png
|
||||
|
||||
DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
|
||||
writelock:
|
||||
chmod a-w *.[ch35] $(DOCS) scripts/*
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
png.o: png.h pngconf.h
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
# Assumes that zlib.lib, zconf.h, and zlib.h have been copied to ..\zlib
|
||||
|
||||
# -------- Microsoft C 5.1 and later, does not use assembler code -----
|
||||
MODEL=-AL
|
||||
CFLAGS=-Oait -Gs -nologo -W3 $(MODEL) -I..\zlib
|
||||
MODEL=L
|
||||
CFLAGS=-Oait -Gs -nologo -W3 -A$(MODEL) -I..\zlib
|
||||
#-Ox generates bad code with MSC 5.1
|
||||
CC=cl
|
||||
LD=link
|
||||
|
||||
@@ -25,7 +25,7 @@ RANLIB=echo
|
||||
# read libpng.txt or png.h to see why PNGMAJ is 2. You should not
|
||||
# have to change it.
|
||||
PNGMAJ = 2
|
||||
PNGMIN = 1.0.4d
|
||||
PNGMIN = 1.0.6e
|
||||
PNGVER = $(PNGMAJ).$(PNGMIN)
|
||||
|
||||
INCPATH=$(prefix)/include
|
||||
@@ -77,6 +77,10 @@ install: libpng.a libpng.so.$(PNGVER)
|
||||
clean:
|
||||
/bin/rm -f *.o libpng.a libpng.so* pngtest pngout.png
|
||||
|
||||
DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
|
||||
writelock:
|
||||
chmod a-w *.[ch35] $(DOCS) scripts/*
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
png.o png.pic.o: png.h pngconf.h
|
||||
|
||||
90
scripts/makefile.sggcc
Normal file
@@ -0,0 +1,90 @@
|
||||
# makefile for libpng, SGI IRIX with gcc
|
||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
# Where the zlib library and include files are located
|
||||
ZLIBLIB=/usr/local/lib32
|
||||
ZLIBINC=/usr/local/include
|
||||
#ZLIBLIB=../zlib
|
||||
#ZLIBINC=../zlib
|
||||
|
||||
CC=gcc
|
||||
|
||||
WARNMORE=
|
||||
CFLAGS=-I$(ZLIBINC) -O2 $(WARNMORE) -fPIC -mabi=n32 # -g -DPNG_DEBUG=5
|
||||
# zlib must also be compiled with n32
|
||||
LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
|
||||
LDSHARED=gcc -shared
|
||||
|
||||
VER=1.0.6e
|
||||
LIBS=libpng.so.1.0.6e
|
||||
SHAREDLIB=libpng.so
|
||||
libdir=$(prefix)/lib32
|
||||
|
||||
RANLIB=echo
|
||||
#RANLIB=ranlib
|
||||
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
|
||||
all: libpng.a $(SHAREDLIB).$(VER) pngtest
|
||||
|
||||
libpng.a: $(OBJS)
|
||||
ar rc $@ $(OBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
$(SHAREDLIB).$(VER): $(OBJS)
|
||||
$(LDSHARED) -o $@ $(OBJS)
|
||||
rm -f $(SHAREDLIB) $(SHAREDLIB).1
|
||||
ln -s $@ $(SHAREDLIB)
|
||||
ln -s $@ $(SHAREDLIB).1
|
||||
|
||||
pngtest: pngtest.o libpng.a
|
||||
$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
|
||||
|
||||
test: pngtest
|
||||
./pngtest
|
||||
|
||||
install: libpng.a
|
||||
-@mkdir $(prefix)/include
|
||||
-@mkdir $(prefix)/lib
|
||||
cp png.h $(prefix)/include
|
||||
cp pngconf.h $(prefix)/include
|
||||
chmod 644 $(prefix)/include/png.h
|
||||
chmod 644 $(prefix)/include/pngconf.h
|
||||
cp libpng.a $(prefix)/lib
|
||||
chmod 644 $(prefix)/lib/libpng.a
|
||||
cp $(SHAREDLIB).$(VER) $(libdir); chmod 755 $(SHAREDLIB).$(VER)
|
||||
cd $(libdir); if test -f $(SHAREDLIB).$(VER); then \
|
||||
rm -f $(SHAREDLIB) $(SHAREDLIB).1; \
|
||||
ln -s $(SHAREDLIB).$(VER) $(SHAREDLIB); \
|
||||
ln -s $(SHAREDLIB).$(VER) $(SHAREDLIB).1; \
|
||||
(ldconfig || true) >/dev/null 2>&1; \
|
||||
fi
|
||||
|
||||
clean:
|
||||
rm -f *.o libpng.a pngtest pngout.png
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
png.o: png.h pngconf.h
|
||||
pngerror.o: png.h pngconf.h
|
||||
pngrio.o: png.h pngconf.h
|
||||
pngwio.o: png.h pngconf.h
|
||||
pngmem.o: png.h pngconf.h
|
||||
pngset.o: png.h pngconf.h
|
||||
pngget.o: png.h pngconf.h
|
||||
pngread.o: png.h pngconf.h
|
||||
pngrtran.o: png.h pngconf.h
|
||||
pngrutil.o: png.h pngconf.h
|
||||
pngtest.o: png.h pngconf.h
|
||||
pngtrans.o: png.h pngconf.h
|
||||
pngwrite.o: png.h pngconf.h
|
||||
pngwtran.o: png.h pngconf.h
|
||||
pngwutil.o: png.h pngconf.h
|
||||
pngpread.o: png.h pngconf.h
|
||||
|
||||