| | 1233 | |
| | 1234 | The PNG specification sets no limit on the number of ancillary chunks |
| | 1235 | allowed in a PNG datastream. You can impose a limit on the total number |
| | 1236 | of sPLT, tEXt, iTXt, zTXt, and unknown chunks that will be stored, with |
| | 1237 | |
| | 1238 | png_set_chunk_cache_max(png_ptr, user_chunk_cache_max); |
| | 1239 | |
| | 1240 | where 0x7fffffffL means unlimited. You can retrieve this limit with |
| | 1241 | |
| | 1242 | chunk_cache_max = png_get_chunk_cache_max(png_ptr); |
| | 1243 | |
| | 1244 | This limit also applies to the number of buffers that can be allocated |
| | 1245 | by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks. |
| 1373 | | channels = png_get_channels(png_ptr, info_ptr); |
| 1374 | | channels - number of channels of info for the |
| 1375 | | color type (valid values are 1 (GRAY, |
| 1376 | | PALETTE), 2 (GRAY_ALPHA), 3 (RGB), |
| 1377 | | 4 (RGB_ALPHA or RGB + filler byte)) |
| 1378 | | rowbytes = png_get_rowbytes(png_ptr, info_ptr); |
| 1379 | | rowbytes - number of bytes needed to hold a row |
| 1380 | | |
| 1381 | | signature = png_get_signature(png_ptr, info_ptr); |
| 1382 | | signature - holds the signature read from the |
| 1383 | | file (if any). The data is kept in |
| 1384 | | the same offset it would be if the |
| 1385 | | whole signature were read (i.e. if an |
| 1386 | | application had already read in 4 |
| 1387 | | bytes of signature before starting |
| 1388 | | libpng, the remaining 4 bytes would |
| 1389 | | be in signature[4] through signature[7] |
| 1390 | | (see png_set_sig_bytes())). |
| 1391 | | |
| | 1389 | Note that png_get_IHDR() returns 32-bit data into |
| | 1390 | the application's width and height variables. |
| | 1391 | This is an unsafe situation if these are 16-bit |
| | 1392 | variables. In such situations, the |
| | 1393 | png_get_image_width() and png_get_image_height() |
| | 1394 | functions described below are safer. |
| | 1411 | channels = png_get_channels(png_ptr, info_ptr); |
| | 1412 | channels - number of channels of info for the |
| | 1413 | color type (valid values are 1 (GRAY, |
| | 1414 | PALETTE), 2 (GRAY_ALPHA), 3 (RGB), |
| | 1415 | 4 (RGB_ALPHA or RGB + filler byte)) |
| | 1416 | rowbytes = png_get_rowbytes(png_ptr, info_ptr); |
| | 1417 | rowbytes - number of bytes needed to hold a row |
| | 1418 | |
| | 1419 | signature = png_get_signature(png_ptr, info_ptr); |
| | 1420 | signature - holds the signature read from the |
| | 1421 | file (if any). The data is kept in |
| | 1422 | the same offset it would be if the |
| | 1423 | whole signature were read (i.e. if an |
| | 1424 | application had already read in 4 |
| | 1425 | bytes of signature before starting |
| | 1426 | libpng, the remaining 4 bytes would |
| | 1427 | be in signature[4] through signature[7] |
| | 1428 | (see png_set_sig_bytes())). |
| | 1702 | As of libpng version 1.2.42, not all possible expansions are supported. |
| | 1703 | |
| | 1704 | In the following table, the 01 means grayscale with depth<8, 31 means |
| | 1705 | indexed with depth<8, other numerals represent the color type, "T" means |
| | 1706 | the tRNS chunk is present, A means an alpha channel is present, and O |
| | 1707 | means tRNS or alpha is present but all pixels in the image are opaque. |
| | 1708 | |
| | 1709 | FROM 01 31 0 0T 0O 2 2T 2O 3 3T 3O 4A 4O 6A 6O |
| | 1710 | TO |
| | 1711 | 01 - |
| | 1712 | 31 - |
| | 1713 | 0 1 - |
| | 1714 | 0T - |
| | 1715 | 0O - |
| | 1716 | 2 GX - |
| | 1717 | 2T - |
| | 1718 | 2O - |
| | 1719 | 3 1 - |
| | 1720 | 3T - |
| | 1721 | 3O - |
| | 1722 | 4A T - |
| | 1723 | 4O - |
| | 1724 | 6A GX TX TX - |
| | 1725 | 6O GX TX - |
| | 1726 | |
| | 1727 | Within the matrix, |
| | 1728 | "-" means the transformation is not supported. |
| | 1729 | "X" means the transformation is obtained by png_set_expand(). |
| | 1730 | "1" means the transformation is obtained by |
| | 1731 | png_set_expand_gray_1_2_4_to_8 |
| | 1732 | "G" means the transformation is obtained by |
| | 1733 | png_set_gray_to_rgb(). |
| | 1734 | "P" means the transformation is obtained by |
| | 1735 | png_set_expand_palette_to_rgb(). |
| | 1736 | "T" means the transformation is obtained by |
| | 1737 | png_set_tRNS_to_alpha(). |
| | 1738 | |
| 1710 | | higher possible bit depth (e.g. from 5 bits/sample in the range [0,31] to |
| 1711 | | 8 bits/sample in the range [0, 255]). However, it is also possible to |
| 1712 | | convert the PNG pixel data back to the original bit depth of the image. |
| 1713 | | This call reduces the pixels back down to the original bit depth: |
| | 1781 | higher possible bit depth (e.g. from 5 bits/sample in the range [0,31] |
| | 1782 | to 8 bits/sample in the range [0, 255]). However, it is also possible |
| | 1783 | to convert the PNG pixel data back to the original bit depth of the |
| | 1784 | image. This call reduces the pixels back down to the original bit depth: |
| 2160 | | by the user and not by libpng, and will in those |
| 2161 | | cases do nothing. The "seq" parameter is ignored if only one item |
| 2162 | | of the selected data type, such as PLTE, is allowed. If "seq" is not |
| 2163 | | -1, and multiple items are allowed for the data type identified in |
| 2164 | | the mask, such as text or sPLT, only the n'th item in the structure |
| 2165 | | is freed, where n is "seq". |
| | 2231 | by the user and not by libpng, and will in those cases do nothing. |
| | 2232 | The "seq" parameter is ignored if only one item of the selected data |
| | 2233 | type, such as PLTE, is allowed. If "seq" is not -1, and multiple items |
| | 2234 | are allowed for the data type identified in the mask, such as text or |
| | 2235 | sPLT, only the n'th item in the structure is freed, where n is "seq". |
| 2930 | | level of opacity. If your data is supplied as a level of |
| 2931 | | transparency, you can invert the alpha channel before you write it, so |
| 2932 | | that 0 is fully transparent and 255 (in 8-bit or paletted images) or |
| 2933 | | 65535 (in 16-bit images) is fully opaque, with |
| | 3004 | level of opacity. If your data is supplied as a level of transparency, |
| | 3005 | you can invert the alpha channel before you write it, so that 0 is |
| | 3006 | fully transparent and 255 (in 8-bit or paletted images) or 65535 |
| | 3007 | (in 16-bit images) is fully opaque, with |
| 3120 | | When the file is interlaced, things can get a good deal more |
| 3121 | | complicated. The only currently (as of the PNG Specification |
| 3122 | | version 1.2, dated July 1999) defined interlacing scheme for PNG files |
| 3123 | | is the "Adam7" interlace scheme, that breaks down an |
| 3124 | | image into seven smaller images of varying size. libpng will build |
| 3125 | | these images for you, or you can do them yourself. If you want to |
| 3126 | | build them yourself, see the PNG specification for details of which |
| 3127 | | pixels to write when. |
| | 3194 | When the file is interlaced, things can get a good deal more complicated. |
| | 3195 | The only currently (as of the PNG Specification version 1.2, dated July |
| | 3196 | 1999) defined interlacing scheme for PNG files is the "Adam7" interlace |
| | 3197 | scheme, that breaks down an image into seven smaller images of varying |
| | 3198 | size. libpng will build these images for you, or you can do them |
| | 3199 | yourself. If you want to build them yourself, see the PNG specification |
| | 3200 | for details of which pixels to write when. |
| 3147 | | As some of these rows are not used, and thus return immediately, |
| 3148 | | you may want to read about interlacing in the PNG specification, |
| 3149 | | and only update the rows that are actually used. |
| | 3220 | As some of these rows are not used, and thus return immediately, you may |
| | 3221 | want to read about interlacing in the PNG specification, and only update |
| | 3222 | the rows that are actually used. |
| 3182 | | by the user and not by libpng, and will in those |
| 3183 | | cases do nothing. The "seq" parameter is ignored if only one item |
| 3184 | | of the selected data type, such as PLTE, is allowed. If "seq" is not |
| 3185 | | -1, and multiple items are allowed for the data type identified in |
| 3186 | | the mask, such as text or sPLT, only the n'th item in the structure |
| 3187 | | is freed, where n is "seq". |
| 3188 | | |
| 3189 | | If you allocated data such as a palette that you passed |
| 3190 | | in to libpng with png_set_*, you must not free it until just before the call to |
| | 3255 | by the user and not by libpng, and will in those cases do nothing. |
| | 3256 | The "seq" parameter is ignored if only one item of the selected data |
| | 3257 | type, such as PLTE, is allowed. If "seq" is not -1, and multiple items |
| | 3258 | are allowed for the data type identified in the mask, such as text or |
| | 3259 | sPLT, only the n'th item in the structure is freed, where n is "seq". |
| | 3260 | |
| | 3261 | If you allocated data such as a palette that you passed in to libpng |
| | 3262 | with png_set_*, you must not free it until just before the call to |
| 3256 | | Memory allocation is done through the functions png_malloc() |
| 3257 | | and png_free(). These currently just call the standard C functions. If |
| 3258 | | your pointers can't access more then 64K at a time, you will want to set |
| 3259 | | MAXSEG_64K in zlib.h. Since it is unlikely that the method of handling |
| 3260 | | memory allocation on a platform will change between applications, these |
| 3261 | | functions must be modified in the library at compile time. If you prefer |
| 3262 | | to use a different method of allocating and freeing data, you can use |
| 3263 | | png_create_read_struct_2() or png_create_write_struct_2() to register |
| 3264 | | your own functions as described above. |
| 3265 | | These functions also provide a void pointer that can be retrieved via |
| | 3328 | Memory allocation is done through the functions png_malloc(), png_calloc(), |
| | 3329 | and png_free(). These currently just call the standard C functions. |
| | 3330 | png_calloc() calls png_malloc() and then png_memset() to clear the newly |
| | 3331 | allocated memory to zero. If your pointers can't access more then 64K |
| | 3332 | at a time, you will want to set MAXSEG_64K in zlib.h. Since it is |
| | 3333 | unlikely that the method of handling memory allocation on a platform |
| | 3334 | will change between applications, these functions must be modified in |
| | 3335 | the library at compile time. If you prefer to use a different method |
| | 3336 | of allocating and freeing data, you can use png_create_read_struct_2() or |
| | 3337 | png_create_write_struct_2() to register your own functions as described |
| | 3338 | above. These functions also provide a void pointer that can be retrieved |
| | 3339 | via |
| 3357 | | after a longjmp, so the user may want to be careful about doing anything after |
| 3358 | | setjmp returns non-zero besides returning itself. Consult your compiler |
| 3359 | | documentation for more details. For an alternative approach, you may wish |
| 3360 | | to use the "cexcept" facility (see http://cexcept.sourceforge.net). |
| | 3431 | after a longjmp, so the user may want to be careful about doing anything |
| | 3432 | after setjmp returns non-zero besides returning itself. Consult your |
| | 3433 | compiler documentation for more details. For an alternative approach, you |
| | 3434 | may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net). |
| 3372 | | specification. Acquire a first level of |
| 3373 | | understanding of how it works. Pay particular attention to the |
| 3374 | | sections that describe chunk names, and look at how other chunks were |
| 3375 | | designed, so you can do things similarly. Second, check out the |
| 3376 | | sections of libpng that read and write chunks. Try to find a chunk |
| 3377 | | that is similar to yours and use it as a template. More details can |
| 3378 | | be found in the comments inside the code. It is best to handle unknown |
| 3379 | | chunks in a generic method, via callback functions, instead of by |
| 3380 | | modifying libpng functions. |
| | 3446 | specification. Acquire a first level of understanding of how it works. |
| | 3447 | Pay particular attention to the sections that describe chunk names, |
| | 3448 | and look at how other chunks were designed, so you can do things |
| | 3449 | similarly. Second, check out the sections of libpng that read and |
| | 3450 | write chunks. Try to find a chunk that is similar to yours and use |
| | 3451 | it as a template. More details can be found in the comments inside |
| | 3452 | the code. It is best to handle unknown chunks in a generic method, |
| | 3453 | via callback functions, instead of by modifying libpng functions. |
| 3557 | | want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable |
| 3558 | | the extra transformations but still leave the library fully capable of reading |
| 3559 | | and writing PNG files with all known public chunks |
| 3560 | | Use of the PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive |
| 3561 | | produces a library that is incapable of reading or writing ancillary chunks. |
| 3562 | | If you are not using the progressive reading capability, you can |
| 3563 | | turn that off with PNG_NO_PROGRESSIVE_READ (don't confuse |
| 3564 | | this with the INTERLACING capability, which you'll still have). |
| | 3630 | want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the extra |
| | 3631 | transformations but still leave the library fully capable of reading |
| | 3632 | and writing PNG files with all known public chunks. Use of the |
| | 3633 | PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library |
| | 3634 | that is incapable of reading or writing ancillary chunks. If you are |
| | 3635 | not using the progressive reading capability, you can turn that off |
| | 3636 | with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING |
| | 3637 | capability, which you'll still have). |
| | 3829 | These macros are deprecated: |
| | 3830 | |
| | 3831 | PNG_READ_TRANSFORMS_NOT_SUPPORTED |
| | 3832 | PNG_PROGRESSIVE_READ_NOT_SUPPORTED |
| | 3833 | PNG_NO_SEQUENTIAL_READ_SUPPORTED |
| | 3834 | PNG_WRITE_TRANSFORMS_NOT_SUPPORTED |
| | 3835 | PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED |
| | 3836 | PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED |
| | 3837 | |
| | 3838 | They have been replaced, respectively, by: |
| | 3839 | |
| | 3840 | PNG_NO_READ_TRANSFORMS |
| | 3841 | PNG_NO_PROGRESSIVE_READ |
| | 3842 | PNG_NO_SEQUENTIAL_READ |
| | 3843 | PNG_NO_WRITE_TRANSFORMS |
| | 3844 | PNG_NO_READ_ANCILLARY_CHUNKS |
| | 3845 | PNG_NO_WRITE_ANCILLARY_CHUNKS |
| | 3846 | |
| | 3847 | PNG_MAX_UINT was replaced with PNG_UINT_31_MAX. It has been |
| | 3848 | deprecated since libpng-1.0.16 and libpng-1.2.6. |
| | 3849 | |
| | 3850 | The function |
| | 3851 | png_check_sig(sig, num) |
| | 3852 | was replaced with |
| | 3853 | !png_sig_cmp(sig, 0, num) |
| | 3854 | It has been deprecated since libpng-0.90. |
| | 3855 | |
| | 3856 | The function |
| | 3857 | png_set_gray_1_2_4_to_8() |
| | 3858 | which also expands tRNS to alpha was replaced with |
| | 3859 | png_set_expand_gray_1_2_4_to_8() |
| | 3860 | which does not. It has been deprecated since libpng-1.0.18 and 1.2.9. |
| | 3861 | |
| | 4292 | 1.0.50 10 10050 10.so.0.50[.0] |
| | 4293 | 1.2.41beta01-18 13 10241 12.so.0.41[.0] |
| | 4294 | 1.0.51rc01 10 10051 10.so.0.51[.0] |
| | 4295 | 1.2.41rc01-03 13 10241 12.so.0.41[.0] |
| | 4296 | 1.0.51 10 10051 10.so.0.51[.0] |
| | 4297 | 1.2.41 13 10241 12.so.0.41[.0] |
| | 4298 | 1.2.42beta01-02 13 10242 12.so.0.42[.0] |
| | 4299 | 1.2.42rc01-05 13 10242 12.so.0.42[.0] |
| | 4300 | 1.0.52 10 10052 10.so.0.52[.0] |
| | 4301 | 1.2.42 13 10242 12.so.0.42[.0] |