Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 1 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 2 | /* pngwrite.c - general routines to write a PNG file |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 3 | * |
Glenn Randers-Pehrson | fcbd787 | 2002-04-07 16:35:38 -0500 | [diff] [blame^] | 4 | * libpng 1.2.2rc1 - April 7, 2002 |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 5 | * For conditions of distribution and use, see copyright notice in png.h |
Glenn Randers-Pehrson | c6de22d | 2002-02-23 18:55:25 -0600 | [diff] [blame] | 6 | * Copyright (c) 1998-2002 Glenn Randers-Pehrson |
Glenn Randers-Pehrson | d436672 | 2000-06-04 14:29:29 -0500 | [diff] [blame] | 7 | * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
| 8 | * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 9 | */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 10 | |
| 11 | /* get internal access to png.h */ |
| 12 | #define PNG_INTERNAL |
| 13 | #include "png.h" |
Glenn Randers-Pehrson | 1909560 | 2001-03-14 07:08:39 -0600 | [diff] [blame] | 14 | #ifdef PNG_WRITE_SUPPORTED |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 15 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 16 | /* Writes all the PNG information. This is the suggested way to use the |
| 17 | * library. If you have a new chunk to add, make a function to write it, |
| 18 | * and put it in the correct location here. If you want the chunk written |
Glenn Randers-Pehrson | 345bc27 | 1998-06-14 14:43:31 -0500 | [diff] [blame] | 19 | * after the image data, put it in png_write_end(). I strongly encourage |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 20 | * you to supply a PNG_INFO_ flag, and check info_ptr->valid before writing |
| 21 | * the chunk, as that will keep the code from breaking if you want to just |
| 22 | * write a plain PNG file. If you have long comments, I suggest writing |
| 23 | * them in png_write_end(), and compressing them. |
| 24 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 25 | void PNGAPI |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 26 | png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 27 | { |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 28 | png_debug(1, "in png_write_info_before_PLTE\n"); |
| 29 | if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) |
| 30 | { |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 31 | png_write_sig(png_ptr); /* write PNG signature */ |
Glenn Randers-Pehrson | 408b421 | 2000-12-18 09:33:57 -0600 | [diff] [blame] | 32 | #if defined(PNG_MNG_FEATURES_SUPPORTED) |
| 33 | if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted)) |
| 34 | { |
| 35 | png_warning(png_ptr,"MNG features are not allowed in a PNG datastream\n"); |
| 36 | png_ptr->mng_features_permitted=0; |
| 37 | } |
| 38 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 39 | /* write IHDR information. */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 40 | png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height, |
| 41 | info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type, |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 42 | info_ptr->filter_type, |
| 43 | #if defined(PNG_WRITE_INTERLACING_SUPPORTED) |
| 44 | info_ptr->interlace_type); |
| 45 | #else |
| 46 | 0); |
| 47 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 48 | /* the rest of these check to see if the valid field has the appropriate |
| 49 | flag set, and if it does, writes the chunk. */ |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 50 | #if defined(PNG_WRITE_gAMA_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 51 | if (info_ptr->valid & PNG_INFO_gAMA) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 52 | { |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 53 | # ifdef PNG_FLOATING_POINT_SUPPORTED |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 54 | png_write_gAMA(png_ptr, info_ptr->gamma); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 55 | #else |
| 56 | #ifdef PNG_FIXED_POINT_SUPPORTED |
| 57 | png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 58 | # endif |
| 59 | #endif |
| 60 | } |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 61 | #endif |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 62 | #if defined(PNG_WRITE_sRGB_SUPPORTED) |
| 63 | if (info_ptr->valid & PNG_INFO_sRGB) |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 64 | png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent); |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 65 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 66 | #if defined(PNG_WRITE_iCCP_SUPPORTED) |
| 67 | if (info_ptr->valid & PNG_INFO_iCCP) |
Glenn Randers-Pehrson | 76e5fd6 | 2000-12-28 07:50:05 -0600 | [diff] [blame] | 68 | png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE, |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 69 | info_ptr->iccp_profile, (int)info_ptr->iccp_proflen); |
| 70 | #endif |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 71 | #if defined(PNG_WRITE_sBIT_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 72 | if (info_ptr->valid & PNG_INFO_sBIT) |
| 73 | png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 74 | #endif |
| 75 | #if defined(PNG_WRITE_cHRM_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 76 | if (info_ptr->valid & PNG_INFO_cHRM) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 77 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 78 | #ifdef PNG_FLOATING_POINT_SUPPORTED |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 79 | png_write_cHRM(png_ptr, |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 80 | info_ptr->x_white, info_ptr->y_white, |
| 81 | info_ptr->x_red, info_ptr->y_red, |
| 82 | info_ptr->x_green, info_ptr->y_green, |
| 83 | info_ptr->x_blue, info_ptr->y_blue); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 84 | #else |
| 85 | # ifdef PNG_FIXED_POINT_SUPPORTED |
| 86 | png_write_cHRM_fixed(png_ptr, |
| 87 | info_ptr->int_x_white, info_ptr->int_y_white, |
| 88 | info_ptr->int_x_red, info_ptr->int_y_red, |
| 89 | info_ptr->int_x_green, info_ptr->int_y_green, |
| 90 | info_ptr->int_x_blue, info_ptr->int_y_blue); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 91 | # endif |
| 92 | #endif |
| 93 | } |
| 94 | #endif |
| 95 | #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) |
| 96 | if (info_ptr->unknown_chunks_num) |
| 97 | { |
| 98 | png_unknown_chunk *up; |
| 99 | |
| 100 | png_debug(5, "writing extra chunks\n"); |
| 101 | |
| 102 | for (up = info_ptr->unknown_chunks; |
| 103 | up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; |
| 104 | up++) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 105 | { |
| 106 | int keep=png_handle_as_unknown(png_ptr, up->name); |
| 107 | if (keep != HANDLE_CHUNK_NEVER && |
| 108 | up->location && (!(up->location & PNG_HAVE_PLTE)) && |
| 109 | ((up->name[3] & 0x20) || keep == HANDLE_CHUNK_ALWAYS || |
| 110 | (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) |
| 111 | { |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 112 | png_write_chunk(png_ptr, up->name, up->data, up->size); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 113 | } |
| 114 | } |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 115 | } |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 116 | #endif |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 117 | png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE; |
| 118 | } |
| 119 | } |
| 120 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 121 | void PNGAPI |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 122 | png_write_info(png_structp png_ptr, png_infop info_ptr) |
| 123 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 124 | #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 125 | int i; |
| 126 | #endif |
| 127 | |
| 128 | png_debug(1, "in png_write_info\n"); |
| 129 | |
| 130 | png_write_info_before_PLTE(png_ptr, info_ptr); |
| 131 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 132 | if (info_ptr->valid & PNG_INFO_PLTE) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 133 | png_write_PLTE(png_ptr, info_ptr->palette, |
| 134 | (png_uint_32)info_ptr->num_palette); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 135 | else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 136 | png_error(png_ptr, "Valid palette required for paletted images\n"); |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 137 | |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 138 | #if defined(PNG_WRITE_tRNS_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 139 | if (info_ptr->valid & PNG_INFO_tRNS) |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 140 | { |
| 141 | #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) |
| 142 | /* invert the alpha channel (in tRNS) */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 143 | if ((png_ptr->transformations & PNG_INVERT_ALPHA) && |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 144 | info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
| 145 | { |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 146 | int j; |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 147 | for (j=0; j<(int)info_ptr->num_trans; j++) |
Glenn Randers-Pehrson | 860ab2b | 1999-10-14 07:43:10 -0500 | [diff] [blame] | 148 | info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]); |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 149 | } |
| 150 | #endif |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 151 | png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values), |
| 152 | info_ptr->num_trans, info_ptr->color_type); |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 153 | } |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 154 | #endif |
| 155 | #if defined(PNG_WRITE_bKGD_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 156 | if (info_ptr->valid & PNG_INFO_bKGD) |
| 157 | png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 158 | #endif |
| 159 | #if defined(PNG_WRITE_hIST_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 160 | if (info_ptr->valid & PNG_INFO_hIST) |
| 161 | png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 162 | #endif |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 163 | #if defined(PNG_WRITE_oFFs_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 164 | if (info_ptr->valid & PNG_INFO_oFFs) |
| 165 | png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset, |
| 166 | info_ptr->offset_unit_type); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 167 | #endif |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 168 | #if defined(PNG_WRITE_pCAL_SUPPORTED) |
| 169 | if (info_ptr->valid & PNG_INFO_pCAL) |
| 170 | png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0, |
| 171 | info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams, |
| 172 | info_ptr->pcal_units, info_ptr->pcal_params); |
| 173 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 174 | #if defined(PNG_WRITE_sCAL_SUPPORTED) |
| 175 | if (info_ptr->valid & PNG_INFO_sCAL) |
Glenn Randers-Pehrson | 68ea243 | 2000-04-01 21:10:05 -0600 | [diff] [blame] | 176 | #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 177 | png_write_sCAL(png_ptr, (int)info_ptr->scal_unit, |
| 178 | info_ptr->scal_pixel_width, info_ptr->scal_pixel_height); |
| 179 | #else |
| 180 | #ifdef PNG_FIXED_POINT_SUPPORTED |
| 181 | png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit, |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 182 | info_ptr->scal_s_width, info_ptr->scal_s_height); |
Glenn Randers-Pehrson | 68ea243 | 2000-04-01 21:10:05 -0600 | [diff] [blame] | 183 | #else |
| 184 | png_warning(png_ptr, |
| 185 | "png_write_sCAL not supported; sCAL chunk not written.\n"); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 186 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 187 | #endif |
| 188 | #endif |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 189 | #if defined(PNG_WRITE_pHYs_SUPPORTED) |
| 190 | if (info_ptr->valid & PNG_INFO_pHYs) |
| 191 | png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit, |
| 192 | info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type); |
| 193 | #endif |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 194 | #if defined(PNG_WRITE_tIME_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 195 | if (info_ptr->valid & PNG_INFO_tIME) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 196 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 197 | png_write_tIME(png_ptr, &(info_ptr->mod_time)); |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 198 | png_ptr->mode |= PNG_WROTE_tIME; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 199 | } |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 200 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 201 | #if defined(PNG_WRITE_sPLT_SUPPORTED) |
| 202 | if (info_ptr->valid & PNG_INFO_sPLT) |
| 203 | for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) |
| 204 | png_write_sPLT(png_ptr, info_ptr->splt_palettes + i); |
| 205 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 206 | #if defined(PNG_WRITE_TEXT_SUPPORTED) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 207 | /* Check to see if we need to write text chunks */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 208 | for (i = 0; i < info_ptr->num_text; i++) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 209 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 210 | png_debug2(2, "Writing header text chunk %d, type %d\n", i, |
| 211 | info_ptr->text[i].compression); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 212 | /* an internationalized chunk? */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 213 | if (info_ptr->text[i].compression > 0) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 214 | { |
| 215 | #if defined(PNG_WRITE_iTXt_SUPPORTED) |
| 216 | /* write international chunk */ |
| 217 | png_write_iTXt(png_ptr, |
| 218 | info_ptr->text[i].compression, |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 219 | info_ptr->text[i].key, |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 220 | info_ptr->text[i].lang, |
| 221 | info_ptr->text[i].lang_key, |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 222 | info_ptr->text[i].text); |
| 223 | #else |
| 224 | png_warning(png_ptr, "Unable to write international text\n"); |
| 225 | #endif |
| 226 | /* Mark this chunk as written */ |
| 227 | info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; |
| 228 | } |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 229 | /* If we want a compressed text chunk */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 230 | else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 231 | { |
| 232 | #if defined(PNG_WRITE_zTXt_SUPPORTED) |
| 233 | /* write compressed chunk */ |
| 234 | png_write_zTXt(png_ptr, info_ptr->text[i].key, |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 235 | info_ptr->text[i].text, 0, |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 236 | info_ptr->text[i].compression); |
| 237 | #else |
| 238 | png_warning(png_ptr, "Unable to write compressed text\n"); |
| 239 | #endif |
| 240 | /* Mark this chunk as written */ |
| 241 | info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; |
| 242 | } |
| 243 | else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) |
| 244 | { |
| 245 | #if defined(PNG_WRITE_tEXt_SUPPORTED) |
| 246 | /* write uncompressed chunk */ |
| 247 | png_write_tEXt(png_ptr, info_ptr->text[i].key, |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 248 | info_ptr->text[i].text, |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 249 | 0); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 250 | #else |
| 251 | png_warning(png_ptr, "Unable to write uncompressed text\n"); |
| 252 | #endif |
| 253 | /* Mark this chunk as written */ |
| 254 | info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; |
| 255 | } |
| 256 | } |
| 257 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 258 | #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) |
| 259 | if (info_ptr->unknown_chunks_num) |
| 260 | { |
| 261 | png_unknown_chunk *up; |
| 262 | |
| 263 | png_debug(5, "writing extra chunks\n"); |
| 264 | |
| 265 | for (up = info_ptr->unknown_chunks; |
| 266 | up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; |
| 267 | up++) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 268 | { |
| 269 | int keep=png_handle_as_unknown(png_ptr, up->name); |
| 270 | if (keep != HANDLE_CHUNK_NEVER && |
| 271 | up->location && (up->location & PNG_HAVE_PLTE) && |
| 272 | !(up->location & PNG_HAVE_IDAT) && |
| 273 | ((up->name[3] & 0x20) || keep == HANDLE_CHUNK_ALWAYS || |
| 274 | (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) |
| 275 | { |
| 276 | png_write_chunk(png_ptr, up->name, up->data, up->size); |
| 277 | } |
| 278 | } |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 279 | } |
| 280 | #endif |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 281 | } |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 282 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 283 | /* Writes the end of the PNG file. If you don't want to write comments or |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 284 | * time information, you can pass NULL for info. If you already wrote these |
| 285 | * in png_write_info(), do not write them again here. If you have long |
| 286 | * comments, I suggest writing them here, and compressing them. |
| 287 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 288 | void PNGAPI |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 289 | png_write_end(png_structp png_ptr, png_infop info_ptr) |
| 290 | { |
| 291 | png_debug(1, "in png_write_end\n"); |
| 292 | if (!(png_ptr->mode & PNG_HAVE_IDAT)) |
| 293 | png_error(png_ptr, "No IDATs written into file"); |
| 294 | |
| 295 | /* see if user wants us to write information chunks */ |
| 296 | if (info_ptr != NULL) |
| 297 | { |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 298 | #if defined(PNG_WRITE_TEXT_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 299 | int i; /* local index variable */ |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 300 | #endif |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 301 | #if defined(PNG_WRITE_tIME_SUPPORTED) |
| 302 | /* check to see if user has supplied a time chunk */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 303 | if ((info_ptr->valid & PNG_INFO_tIME) && |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 304 | !(png_ptr->mode & PNG_WROTE_tIME)) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 305 | png_write_tIME(png_ptr, &(info_ptr->mod_time)); |
| 306 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 307 | #if defined(PNG_WRITE_TEXT_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 308 | /* loop through comment chunks */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 309 | for (i = 0; i < info_ptr->num_text; i++) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 310 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 311 | png_debug2(2, "Writing trailer text chunk %d, type %d\n", i, |
| 312 | info_ptr->text[i].compression); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 313 | /* an internationalized chunk? */ |
| 314 | if (info_ptr->text[i].compression > 0) |
| 315 | { |
| 316 | #if defined(PNG_WRITE_iTXt_SUPPORTED) |
| 317 | /* write international chunk */ |
| 318 | png_write_iTXt(png_ptr, |
| 319 | info_ptr->text[i].compression, |
| 320 | info_ptr->text[i].key, |
| 321 | info_ptr->text[i].lang, |
| 322 | info_ptr->text[i].lang_key, |
| 323 | info_ptr->text[i].text); |
| 324 | #else |
| 325 | png_warning(png_ptr, "Unable to write international text\n"); |
| 326 | #endif |
| 327 | /* Mark this chunk as written */ |
| 328 | info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; |
| 329 | } |
| 330 | else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 331 | { |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 332 | #if defined(PNG_WRITE_zTXt_SUPPORTED) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 333 | /* write compressed chunk */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 334 | png_write_zTXt(png_ptr, info_ptr->text[i].key, |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 335 | info_ptr->text[i].text, 0, |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 336 | info_ptr->text[i].compression); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 337 | #else |
| 338 | png_warning(png_ptr, "Unable to write compressed text\n"); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 339 | #endif |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 340 | /* Mark this chunk as written */ |
| 341 | info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 342 | } |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 343 | else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 344 | { |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 345 | #if defined(PNG_WRITE_tEXt_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 346 | /* write uncompressed chunk */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 347 | png_write_tEXt(png_ptr, info_ptr->text[i].key, |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 348 | info_ptr->text[i].text, 0); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 349 | #else |
| 350 | png_warning(png_ptr, "Unable to write uncompressed text\n"); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 351 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 352 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 353 | /* Mark this chunk as written */ |
| 354 | info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 355 | } |
| 356 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 357 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 358 | #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) |
| 359 | if (info_ptr->unknown_chunks_num) |
| 360 | { |
| 361 | png_unknown_chunk *up; |
| 362 | |
| 363 | png_debug(5, "writing extra chunks\n"); |
| 364 | |
| 365 | for (up = info_ptr->unknown_chunks; |
| 366 | up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; |
| 367 | up++) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 368 | { |
| 369 | int keep=png_handle_as_unknown(png_ptr, up->name); |
| 370 | if (keep != HANDLE_CHUNK_NEVER && |
| 371 | up->location && (up->location & PNG_AFTER_IDAT) && |
| 372 | ((up->name[3] & 0x20) || keep == HANDLE_CHUNK_ALWAYS || |
| 373 | (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) |
| 374 | { |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 375 | png_write_chunk(png_ptr, up->name, up->data, up->size); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 376 | } |
| 377 | } |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 378 | } |
| 379 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 380 | } |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 381 | |
| 382 | png_ptr->mode |= PNG_AFTER_IDAT; |
| 383 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 384 | /* write end of PNG file */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 385 | png_write_IEND(png_ptr); |
Glenn Randers-Pehrson | d56aca7 | 2000-11-23 11:51:42 -0600 | [diff] [blame] | 386 | #if 0 |
| 387 | /* This flush, added in libpng-1.0.8, causes some applications to crash |
| 388 | because they do not set png_ptr->output_flush_fn */ |
Glenn Randers-Pehrson | 32fc5ce | 2000-07-24 06:34:14 -0500 | [diff] [blame] | 389 | png_flush(png_ptr); |
Glenn Randers-Pehrson | d56aca7 | 2000-11-23 11:51:42 -0600 | [diff] [blame] | 390 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 391 | } |
| 392 | |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 393 | #if defined(PNG_WRITE_tIME_SUPPORTED) |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 394 | #if !defined(_WIN32_WCE) |
| 395 | /* "time.h" functions are not supported on WindowsCE */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 396 | void PNGAPI |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 397 | png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 398 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 399 | png_debug(1, "in png_convert_from_struct_tm\n"); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 400 | ptime->year = (png_uint_16)(1900 + ttime->tm_year); |
| 401 | ptime->month = (png_byte)(ttime->tm_mon + 1); |
| 402 | ptime->day = (png_byte)ttime->tm_mday; |
| 403 | ptime->hour = (png_byte)ttime->tm_hour; |
| 404 | ptime->minute = (png_byte)ttime->tm_min; |
| 405 | ptime->second = (png_byte)ttime->tm_sec; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 406 | } |
| 407 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 408 | void PNGAPI |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 409 | png_convert_from_time_t(png_timep ptime, time_t ttime) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 410 | { |
| 411 | struct tm *tbuf; |
| 412 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 413 | png_debug(1, "in png_convert_from_time_t\n"); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 414 | tbuf = gmtime(&ttime); |
| 415 | png_convert_from_struct_tm(ptime, tbuf); |
| 416 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 417 | #endif |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 418 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 419 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 420 | /* Initialize png_ptr structure, and allocate any memory needed */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 421 | png_structp PNGAPI |
Glenn Randers-Pehrson | d0dce40 | 1998-05-09 10:02:29 -0500 | [diff] [blame] | 422 | png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr, |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 423 | png_error_ptr error_fn, png_error_ptr warn_fn) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 424 | { |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 425 | #ifdef PNG_USER_MEM_SUPPORTED |
| 426 | return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn, |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 427 | warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL)); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | /* Alternate initialize png_ptr structure, and allocate any memory needed */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 431 | png_structp PNGAPI |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 432 | png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, |
| 433 | png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, |
| 434 | png_malloc_ptr malloc_fn, png_free_ptr free_fn) |
| 435 | { |
| 436 | #endif /* PNG_USER_MEM_SUPPORTED */ |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 437 | png_structp png_ptr; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 438 | #ifdef PNG_SETJMP_SUPPORTED |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 439 | #ifdef USE_FAR_KEYWORD |
| 440 | jmp_buf jmpbuf; |
| 441 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 442 | #endif |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 443 | int i; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 444 | png_debug(1, "in png_create_write_struct\n"); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 445 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 9c0f094 | 2002-02-21 23:14:23 -0600 | [diff] [blame] | 446 | png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, |
| 447 | (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 448 | #else |
Glenn Randers-Pehrson | 9c0f094 | 2002-02-21 23:14:23 -0600 | [diff] [blame] | 449 | png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 450 | #endif /* PNG_USER_MEM_SUPPORTED */ |
Glenn Randers-Pehrson | 9c0f094 | 2002-02-21 23:14:23 -0600 | [diff] [blame] | 451 | if (png_ptr == NULL) |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 452 | return (NULL); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 453 | |
Glenn Randers-Pehrson | 73d57cb | 2002-03-25 18:49:08 -0600 | [diff] [blame] | 454 | #if !defined(PNG_1_0_X) |
Glenn Randers-Pehrson | 1fd5fb3 | 2001-05-06 05:34:26 -0500 | [diff] [blame] | 455 | #ifdef PNG_ASSEMBLER_CODE_SUPPORTED |
| 456 | png_init_mmx_flags(png_ptr); /* 1.2.0 addition */ |
| 457 | #endif |
Glenn Randers-Pehrson | 73d57cb | 2002-03-25 18:49:08 -0600 | [diff] [blame] | 458 | #endif /* PNG_1_0_X */ |
Glenn Randers-Pehrson | 1fd5fb3 | 2001-05-06 05:34:26 -0500 | [diff] [blame] | 459 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 460 | #ifdef PNG_SETJMP_SUPPORTED |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 461 | #ifdef USE_FAR_KEYWORD |
| 462 | if (setjmp(jmpbuf)) |
| 463 | #else |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 464 | if (setjmp(png_ptr->jmpbuf)) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 465 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 466 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 467 | png_free(png_ptr, png_ptr->zbuf); |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 468 | png_ptr->zbuf=NULL; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 469 | png_destroy_struct(png_ptr); |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 470 | return (NULL); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 471 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 472 | #ifdef USE_FAR_KEYWORD |
| 473 | png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf)); |
| 474 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 475 | #endif |
| 476 | |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 477 | #ifdef PNG_USER_MEM_SUPPORTED |
| 478 | png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); |
| 479 | #endif /* PNG_USER_MEM_SUPPORTED */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 480 | png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 481 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 482 | i=0; |
| 483 | do |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 484 | { |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 485 | if(user_png_ver[i] != png_libpng_ver[i]) |
| 486 | png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; |
| 487 | } while (png_libpng_ver[i++]); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 488 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 489 | if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) |
Glenn Randers-Pehrson | 98c9d73 | 2000-05-03 21:06:11 -0500 | [diff] [blame] | 490 | { |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 491 | /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so |
| 492 | * we must recompile any applications that use any older library version. |
| 493 | * For versions after libpng 1.0, we will be compatible, so we need |
| 494 | * only check the first digit. |
| 495 | */ |
| 496 | if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] || |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 497 | (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) || |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 498 | (user_png_ver[0] == '0' && user_png_ver[2] < '9')) |
| 499 | { |
Glenn Randers-Pehrson | b182893 | 2001-06-23 08:03:17 -0500 | [diff] [blame] | 500 | #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) |
| 501 | char msg[80]; |
| 502 | if (user_png_ver) |
| 503 | { |
| 504 | sprintf(msg, "Application was compiled with png.h from libpng-%.20s", |
| 505 | user_png_ver); |
| 506 | png_warning(png_ptr, msg); |
| 507 | } |
Glenn Randers-Pehrson | 5cded0b | 2001-11-07 07:10:08 -0600 | [diff] [blame] | 508 | sprintf(msg, "Application is running with png.c from libpng-%.20s", |
Glenn Randers-Pehrson | b182893 | 2001-06-23 08:03:17 -0500 | [diff] [blame] | 509 | png_libpng_ver); |
| 510 | png_warning(png_ptr, msg); |
| 511 | #endif |
| 512 | #ifdef PNG_ERROR_NUMBERS_SUPPORTED |
| 513 | png_ptr->flags=0; |
| 514 | #endif |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 515 | png_error(png_ptr, |
| 516 | "Incompatible libpng version in application and library"); |
| 517 | } |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 518 | } |
Glenn Randers-Pehrson | 98c9d73 | 2000-05-03 21:06:11 -0500 | [diff] [blame] | 519 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 520 | /* initialize zbuf - compression buffer */ |
| 521 | png_ptr->zbuf_size = PNG_ZBUF_SIZE; |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 522 | png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, |
| 523 | (png_uint_32)png_ptr->zbuf_size); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 524 | |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 525 | png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL, |
| 526 | png_flush_ptr_NULL); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 527 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 528 | #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) |
| 529 | png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 530 | 1, png_doublep_NULL, png_doublep_NULL); |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 531 | #endif |
| 532 | |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 533 | return ((png_structp)png_ptr); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 534 | } |
| 535 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 536 | /* Initialize png_ptr structure, and allocate any memory needed */ |
Glenn Randers-Pehrson | 98c9d73 | 2000-05-03 21:06:11 -0500 | [diff] [blame] | 537 | #undef png_write_init |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 538 | void PNGAPI |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 539 | png_write_init(png_structp png_ptr) |
| 540 | { |
Glenn Randers-Pehrson | 98c9d73 | 2000-05-03 21:06:11 -0500 | [diff] [blame] | 541 | /* We only come here via pre-1.0.7-compiled applications */ |
Glenn Randers-Pehrson | b182893 | 2001-06-23 08:03:17 -0500 | [diff] [blame] | 542 | png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0); |
Glenn Randers-Pehrson | 98c9d73 | 2000-05-03 21:06:11 -0500 | [diff] [blame] | 543 | } |
| 544 | |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 545 | #undef png_write_init_2 |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 546 | void PNGAPI |
Glenn Randers-Pehrson | 98c9d73 | 2000-05-03 21:06:11 -0500 | [diff] [blame] | 547 | png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver, |
| 548 | png_size_t png_struct_size, png_size_t png_info_size) |
| 549 | { |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 550 | /* We only come here via pre-1.0.12-compiled applications */ |
Glenn Randers-Pehrson | b182893 | 2001-06-23 08:03:17 -0500 | [diff] [blame] | 551 | #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) |
| 552 | if(sizeof(png_struct) > png_struct_size || sizeof(png_info) > png_info_size) |
| 553 | { |
| 554 | char msg[80]; |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 555 | png_ptr->warning_fn=NULL; |
Glenn Randers-Pehrson | b182893 | 2001-06-23 08:03:17 -0500 | [diff] [blame] | 556 | if (user_png_ver) |
| 557 | { |
| 558 | sprintf(msg, "Application was compiled with png.h from libpng-%.20s", |
| 559 | user_png_ver); |
| 560 | png_warning(png_ptr, msg); |
| 561 | } |
Glenn Randers-Pehrson | 5cded0b | 2001-11-07 07:10:08 -0600 | [diff] [blame] | 562 | sprintf(msg, "Application is running with png.c from libpng-%.20s", |
Glenn Randers-Pehrson | b182893 | 2001-06-23 08:03:17 -0500 | [diff] [blame] | 563 | png_libpng_ver); |
| 564 | png_warning(png_ptr, msg); |
| 565 | } |
| 566 | #endif |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 567 | if(sizeof(png_struct) > png_struct_size) |
| 568 | { |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 569 | png_ptr->error_fn=NULL; |
Glenn Randers-Pehrson | b182893 | 2001-06-23 08:03:17 -0500 | [diff] [blame] | 570 | #ifdef PNG_ERROR_NUMBERS_SUPPORTED |
| 571 | png_ptr->flags=0; |
| 572 | #endif |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 573 | png_error(png_ptr, |
Glenn Randers-Pehrson | b182893 | 2001-06-23 08:03:17 -0500 | [diff] [blame] | 574 | "The png struct allocated by the application for writing is too small."); |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 575 | } |
| 576 | if(sizeof(png_info) > png_info_size) |
| 577 | { |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 578 | png_ptr->error_fn=NULL; |
Glenn Randers-Pehrson | b182893 | 2001-06-23 08:03:17 -0500 | [diff] [blame] | 579 | #ifdef PNG_ERROR_NUMBERS_SUPPORTED |
| 580 | png_ptr->flags=0; |
| 581 | #endif |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 582 | png_error(png_ptr, |
Glenn Randers-Pehrson | b182893 | 2001-06-23 08:03:17 -0500 | [diff] [blame] | 583 | "The info struct allocated by the application for writing is too small."); |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 584 | } |
| 585 | png_write_init_3(&png_ptr, user_png_ver, png_struct_size); |
| 586 | } |
| 587 | |
| 588 | |
| 589 | void PNGAPI |
| 590 | png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, |
| 591 | png_size_t png_struct_size) |
| 592 | { |
| 593 | png_structp png_ptr=*ptr_ptr; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 594 | #ifdef PNG_SETJMP_SUPPORTED |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 595 | jmp_buf tmp_jmp; /* to save current jump buffer */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 596 | #endif |
Glenn Randers-Pehrson | 98c9d73 | 2000-05-03 21:06:11 -0500 | [diff] [blame] | 597 | int i = 0; |
| 598 | do |
| 599 | { |
| 600 | if (user_png_ver[i] != png_libpng_ver[i]) |
| 601 | { |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 602 | #ifdef PNG_LEGACY_SUPPORTED |
| 603 | png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; |
| 604 | #else |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 605 | png_ptr->warning_fn=NULL; |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 606 | png_warning(png_ptr, |
| 607 | "Application uses deprecated png_write_init() and should be recompiled."); |
| 608 | break; |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 609 | #endif |
Glenn Randers-Pehrson | 98c9d73 | 2000-05-03 21:06:11 -0500 | [diff] [blame] | 610 | } |
| 611 | } while (png_libpng_ver[i++]); |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 612 | |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 613 | png_debug(1, "in png_write_init_3\n"); |
Glenn Randers-Pehrson | 98c9d73 | 2000-05-03 21:06:11 -0500 | [diff] [blame] | 614 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 615 | #ifdef PNG_SETJMP_SUPPORTED |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 616 | /* save jump buffer and error functions */ |
| 617 | png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf)); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 618 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 619 | |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 620 | if (sizeof(png_struct) > png_struct_size) |
| 621 | { |
| 622 | png_destroy_struct(png_ptr); |
| 623 | png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); |
| 624 | *ptr_ptr = png_ptr; |
| 625 | } |
| 626 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 627 | /* reset all variables to 0 */ |
| 628 | png_memset(png_ptr, 0, sizeof (png_struct)); |
| 629 | |
Glenn Randers-Pehrson | 73d57cb | 2002-03-25 18:49:08 -0600 | [diff] [blame] | 630 | #if !defined(PNG_1_0_X) |
Glenn Randers-Pehrson | 1fd5fb3 | 2001-05-06 05:34:26 -0500 | [diff] [blame] | 631 | #ifdef PNG_ASSEMBLER_CODE_SUPPORTED |
| 632 | png_init_mmx_flags(png_ptr); /* 1.2.0 addition */ |
| 633 | #endif |
Glenn Randers-Pehrson | 73d57cb | 2002-03-25 18:49:08 -0600 | [diff] [blame] | 634 | #endif /* PNG_1_0_X */ |
Glenn Randers-Pehrson | 1fd5fb3 | 2001-05-06 05:34:26 -0500 | [diff] [blame] | 635 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 636 | #ifdef PNG_SETJMP_SUPPORTED |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 637 | /* restore jump buffer */ |
| 638 | png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf)); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 639 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 640 | |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 641 | png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL, |
| 642 | png_flush_ptr_NULL); |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 643 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 644 | /* initialize zbuf - compression buffer */ |
| 645 | png_ptr->zbuf_size = PNG_ZBUF_SIZE; |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 646 | png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, |
| 647 | (png_uint_32)png_ptr->zbuf_size); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 648 | |
| 649 | #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) |
| 650 | png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 651 | 1, png_doublep_NULL, png_doublep_NULL); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 652 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 653 | } |
| 654 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 655 | /* Write a few rows of image data. If the image is interlaced, |
| 656 | * either you will have to write the 7 sub images, or, if you |
| 657 | * have called png_set_interlace_handling(), you will have to |
| 658 | * "write" the image seven times. |
| 659 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 660 | void PNGAPI |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 661 | png_write_rows(png_structp png_ptr, png_bytepp row, |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 662 | png_uint_32 num_rows) |
| 663 | { |
| 664 | png_uint_32 i; /* row counter */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 665 | png_bytepp rp; /* row pointer */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 666 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 667 | png_debug(1, "in png_write_rows\n"); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 668 | /* loop through the rows */ |
| 669 | for (i = 0, rp = row; i < num_rows; i++, rp++) |
| 670 | { |
| 671 | png_write_row(png_ptr, *rp); |
| 672 | } |
| 673 | } |
| 674 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 675 | /* Write the image. You only need to call this function once, even |
| 676 | * if you are writing an interlaced image. |
| 677 | */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 678 | void PNGAPI |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 679 | png_write_image(png_structp png_ptr, png_bytepp image) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 680 | { |
| 681 | png_uint_32 i; /* row index */ |
| 682 | int pass, num_pass; /* pass variables */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 683 | png_bytepp rp; /* points to current row */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 684 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 685 | png_debug(1, "in png_write_image\n"); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 686 | #if defined(PNG_WRITE_INTERLACING_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 687 | /* intialize interlace handling. If image is not interlaced, |
| 688 | this will set pass to 1 */ |
| 689 | num_pass = png_set_interlace_handling(png_ptr); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 690 | #else |
| 691 | num_pass = 1; |
| 692 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 693 | /* loop through passes */ |
| 694 | for (pass = 0; pass < num_pass; pass++) |
| 695 | { |
| 696 | /* loop through image */ |
| 697 | for (i = 0, rp = image; i < png_ptr->height; i++, rp++) |
| 698 | { |
| 699 | png_write_row(png_ptr, *rp); |
| 700 | } |
| 701 | } |
| 702 | } |
| 703 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 704 | /* called by user to write a row of image data */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 705 | void PNGAPI |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 706 | png_write_row(png_structp png_ptr, png_bytep row) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 707 | { |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 708 | png_debug2(1, "in png_write_row (row %ld, pass %d)\n", |
| 709 | png_ptr->row_number, png_ptr->pass); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 710 | /* initialize transformations and other stuff if first time */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 711 | if (png_ptr->row_number == 0 && png_ptr->pass == 0) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 712 | { |
Glenn Randers-Pehrson | 5cded0b | 2001-11-07 07:10:08 -0600 | [diff] [blame] | 713 | /* make sure we wrote the header info */ |
| 714 | if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) |
| 715 | png_error(png_ptr, |
| 716 | "png_write_info was never called before png_write_row."); |
| 717 | |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 718 | /* check for transforms that have been set but were defined out */ |
| 719 | #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED) |
| 720 | if (png_ptr->transformations & PNG_INVERT_MONO) |
| 721 | png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined."); |
| 722 | #endif |
| 723 | #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED) |
| 724 | if (png_ptr->transformations & PNG_FILLER) |
| 725 | png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined."); |
| 726 | #endif |
| 727 | #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED) |
| 728 | if (png_ptr->transformations & PNG_PACKSWAP) |
| 729 | png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined."); |
| 730 | #endif |
| 731 | #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED) |
| 732 | if (png_ptr->transformations & PNG_PACK) |
| 733 | png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined."); |
| 734 | #endif |
| 735 | #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED) |
| 736 | if (png_ptr->transformations & PNG_SHIFT) |
| 737 | png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined."); |
| 738 | #endif |
| 739 | #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED) |
| 740 | if (png_ptr->transformations & PNG_BGR) |
| 741 | png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined."); |
| 742 | #endif |
| 743 | #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED) |
| 744 | if (png_ptr->transformations & PNG_SWAP_BYTES) |
| 745 | png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined."); |
| 746 | #endif |
| 747 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 748 | png_write_start_row(png_ptr); |
| 749 | } |
| 750 | |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 751 | #if defined(PNG_WRITE_INTERLACING_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 752 | /* if interlaced and not interested in row, return */ |
| 753 | if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) |
| 754 | { |
| 755 | switch (png_ptr->pass) |
| 756 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 757 | case 0: |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 758 | if (png_ptr->row_number & 0x07) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 759 | { |
| 760 | png_write_finish_row(png_ptr); |
| 761 | return; |
| 762 | } |
| 763 | break; |
| 764 | case 1: |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 765 | if ((png_ptr->row_number & 0x07) || png_ptr->width < 5) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 766 | { |
| 767 | png_write_finish_row(png_ptr); |
| 768 | return; |
| 769 | } |
| 770 | break; |
| 771 | case 2: |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 772 | if ((png_ptr->row_number & 0x07) != 4) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 773 | { |
| 774 | png_write_finish_row(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 775 | return; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 776 | } |
| 777 | break; |
| 778 | case 3: |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 779 | if ((png_ptr->row_number & 0x03) || png_ptr->width < 3) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 780 | { |
| 781 | png_write_finish_row(png_ptr); |
| 782 | return; |
| 783 | } |
| 784 | break; |
| 785 | case 4: |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 786 | if ((png_ptr->row_number & 0x03) != 2) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 787 | { |
| 788 | png_write_finish_row(png_ptr); |
| 789 | return; |
| 790 | } |
| 791 | break; |
| 792 | case 5: |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 793 | if ((png_ptr->row_number & 0x01) || png_ptr->width < 2) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 794 | { |
| 795 | png_write_finish_row(png_ptr); |
| 796 | return; |
| 797 | } |
| 798 | break; |
| 799 | case 6: |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 800 | if (!(png_ptr->row_number & 0x01)) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 801 | { |
| 802 | png_write_finish_row(png_ptr); |
| 803 | return; |
| 804 | } |
| 805 | break; |
| 806 | } |
| 807 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 808 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 809 | |
| 810 | /* set up row info for transformations */ |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 811 | png_ptr->row_info.color_type = png_ptr->color_type; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 812 | png_ptr->row_info.width = png_ptr->usr_width; |
| 813 | png_ptr->row_info.channels = png_ptr->usr_channels; |
| 814 | png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 815 | png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth * |
| 816 | png_ptr->row_info.channels); |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 817 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 818 | png_ptr->row_info.rowbytes = ((png_ptr->row_info.width * |
| 819 | (png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3); |
| 820 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 821 | png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type); |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 822 | png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width); |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 823 | png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels); |
| 824 | png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth); |
| 825 | png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth); |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 826 | png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 827 | |
| 828 | /* Copy user's row into buffer, leaving room for filter byte. */ |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 829 | png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 830 | png_ptr->row_info.rowbytes); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 831 | |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 832 | #if defined(PNG_WRITE_INTERLACING_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 833 | /* handle interlacing */ |
| 834 | if (png_ptr->interlaced && png_ptr->pass < 6 && |
| 835 | (png_ptr->transformations & PNG_INTERLACE)) |
| 836 | { |
| 837 | png_do_write_interlace(&(png_ptr->row_info), |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 838 | png_ptr->row_buf + 1, png_ptr->pass); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 839 | /* this should always get caught above, but still ... */ |
| 840 | if (!(png_ptr->row_info.width)) |
| 841 | { |
| 842 | png_write_finish_row(png_ptr); |
| 843 | return; |
| 844 | } |
| 845 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 846 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 847 | |
| 848 | /* handle other transformations */ |
| 849 | if (png_ptr->transformations) |
| 850 | png_do_write_transformations(png_ptr); |
| 851 | |
Glenn Randers-Pehrson | 2ad31ae | 2000-12-15 08:54:42 -0600 | [diff] [blame] | 852 | #if defined(PNG_MNG_FEATURES_SUPPORTED) |
Glenn Randers-Pehrson | 408b421 | 2000-12-18 09:33:57 -0600 | [diff] [blame] | 853 | /* Write filter_method 64 (intrapixel differencing) only if |
| 854 | * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and |
| 855 | * 2. Libpng did not write a PNG signature (this filter_method is only |
| 856 | * used in PNG datastreams that are embedded in MNG datastreams) and |
| 857 | * 3. The application called png_permit_mng_features with a mask that |
| 858 | * included PNG_FLAG_MNG_FILTER_64 and |
| 859 | * 4. The filter_method is 64 and |
| 860 | * 5. The color_type is RGB or RGBA |
| 861 | */ |
Glenn Randers-Pehrson | 2ad31ae | 2000-12-15 08:54:42 -0600 | [diff] [blame] | 862 | if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && |
| 863 | (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) |
| 864 | { |
| 865 | /* Intrapixel differencing */ |
| 866 | png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1); |
| 867 | } |
| 868 | #endif |
| 869 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 870 | /* Find a filter if necessary, filter the row and write it out. */ |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 871 | png_write_find_filter(png_ptr, &(png_ptr->row_info)); |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 872 | |
| 873 | if (png_ptr->write_row_fn != NULL) |
| 874 | (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 875 | } |
| 876 | |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 877 | #if defined(PNG_WRITE_FLUSH_SUPPORTED) |
| 878 | /* Set the automatic flush interval or 0 to turn flushing off */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 879 | void PNGAPI |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 880 | png_set_flush(png_structp png_ptr, int nrows) |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 881 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 882 | png_debug(1, "in png_set_flush\n"); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 883 | png_ptr->flush_dist = (nrows < 0 ? 0 : nrows); |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | /* flush the current output buffers now */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 887 | void PNGAPI |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 888 | png_write_flush(png_structp png_ptr) |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 889 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 890 | int wrote_IDAT; |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 891 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 892 | png_debug(1, "in png_write_flush\n"); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 893 | /* We have already written out all of the data */ |
| 894 | if (png_ptr->row_number >= png_ptr->num_rows) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 895 | return; |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 896 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 897 | do |
| 898 | { |
| 899 | int ret; |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 900 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 901 | /* compress the data */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 902 | ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 903 | wrote_IDAT = 0; |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 904 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 905 | /* check for compression errors */ |
| 906 | if (ret != Z_OK) |
| 907 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 908 | if (png_ptr->zstream.msg != NULL) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 909 | png_error(png_ptr, png_ptr->zstream.msg); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 910 | else |
| 911 | png_error(png_ptr, "zlib error"); |
| 912 | } |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 913 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 914 | if (!(png_ptr->zstream.avail_out)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 915 | { |
| 916 | /* write the IDAT and reset the zlib output buffer */ |
| 917 | png_write_IDAT(png_ptr, png_ptr->zbuf, |
| 918 | png_ptr->zbuf_size); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 919 | png_ptr->zstream.next_out = png_ptr->zbuf; |
| 920 | png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 921 | wrote_IDAT = 1; |
| 922 | } |
| 923 | } while(wrote_IDAT == 1); |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 924 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 925 | /* If there is any data left to be output, write it into a new IDAT */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 926 | if (png_ptr->zbuf_size != png_ptr->zstream.avail_out) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 927 | { |
| 928 | /* write the IDAT and reset the zlib output buffer */ |
| 929 | png_write_IDAT(png_ptr, png_ptr->zbuf, |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 930 | png_ptr->zbuf_size - png_ptr->zstream.avail_out); |
| 931 | png_ptr->zstream.next_out = png_ptr->zbuf; |
| 932 | png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 933 | } |
| 934 | png_ptr->flush_rows = 0; |
| 935 | png_flush(png_ptr); |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 936 | } |
| 937 | #endif /* PNG_WRITE_FLUSH_SUPPORTED */ |
| 938 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 939 | /* free all memory used by the write */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 940 | void PNGAPI |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 941 | png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 942 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 943 | png_structp png_ptr = NULL; |
| 944 | png_infop info_ptr = NULL; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 945 | #ifdef PNG_USER_MEM_SUPPORTED |
| 946 | png_free_ptr free_fn = NULL; |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 947 | png_voidp mem_ptr = NULL; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 948 | #endif |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 949 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 950 | png_debug(1, "in png_destroy_write_struct\n"); |
| 951 | if (png_ptr_ptr != NULL) |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 952 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 953 | png_ptr = *png_ptr_ptr; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 954 | #ifdef PNG_USER_MEM_SUPPORTED |
| 955 | free_fn = png_ptr->free_fn; |
Glenn Randers-Pehrson | fcbd787 | 2002-04-07 16:35:38 -0500 | [diff] [blame^] | 956 | mem_ptr = png_ptr->mem_ptr; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 957 | #endif |
| 958 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 959 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 960 | if (info_ptr_ptr != NULL) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 961 | info_ptr = *info_ptr_ptr; |
| 962 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 963 | if (info_ptr != NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 964 | { |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 965 | png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); |
| 966 | |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 967 | #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 968 | if (png_ptr->num_chunk_list) |
| 969 | { |
| 970 | png_free(png_ptr, png_ptr->chunk_list); |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 971 | png_ptr->chunk_list=NULL; |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 972 | png_ptr->num_chunk_list=0; |
| 973 | } |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 974 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 975 | |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 976 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 977 | png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, |
| 978 | (png_voidp)mem_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 979 | #else |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 980 | png_destroy_struct((png_voidp)info_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 981 | #endif |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 982 | *info_ptr_ptr = NULL; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 983 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 984 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 985 | if (png_ptr != NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 986 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 987 | png_write_destroy(png_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 988 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 989 | png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, |
| 990 | (png_voidp)mem_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 991 | #else |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 992 | png_destroy_struct((png_voidp)png_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 993 | #endif |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 994 | *png_ptr_ptr = NULL; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 995 | } |
| 996 | } |
| 997 | |
| 998 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 999 | /* Free any memory used in png_ptr struct (old method) */ |
Glenn Randers-Pehrson | f64a06f | 2001-04-11 07:38:00 -0500 | [diff] [blame] | 1000 | void /* PRIVATE */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1001 | png_write_destroy(png_structp png_ptr) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1002 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1003 | #ifdef PNG_SETJMP_SUPPORTED |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1004 | jmp_buf tmp_jmp; /* save jump buffer */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1005 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1006 | png_error_ptr error_fn; |
| 1007 | png_error_ptr warning_fn; |
| 1008 | png_voidp error_ptr; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1009 | #ifdef PNG_USER_MEM_SUPPORTED |
| 1010 | png_free_ptr free_fn; |
| 1011 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1012 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1013 | png_debug(1, "in png_write_destroy\n"); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1014 | /* free any memory zlib uses */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1015 | deflateEnd(&png_ptr->zstream); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1016 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1017 | /* free our memory. png_free checks NULL for us. */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1018 | png_free(png_ptr, png_ptr->zbuf); |
| 1019 | png_free(png_ptr, png_ptr->row_buf); |
| 1020 | png_free(png_ptr, png_ptr->prev_row); |
| 1021 | png_free(png_ptr, png_ptr->sub_row); |
| 1022 | png_free(png_ptr, png_ptr->up_row); |
| 1023 | png_free(png_ptr, png_ptr->avg_row); |
| 1024 | png_free(png_ptr, png_ptr->paeth_row); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1025 | |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 1026 | #if defined(PNG_TIME_RFC1123_SUPPORTED) |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 1027 | png_free(png_ptr, png_ptr->time_buffer); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1028 | #endif |
| 1029 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1030 | #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) |
| 1031 | png_free(png_ptr, png_ptr->prev_filters); |
| 1032 | png_free(png_ptr, png_ptr->filter_weights); |
| 1033 | png_free(png_ptr, png_ptr->inv_filter_weights); |
| 1034 | png_free(png_ptr, png_ptr->filter_costs); |
| 1035 | png_free(png_ptr, png_ptr->inv_filter_costs); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1036 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1037 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1038 | #ifdef PNG_SETJMP_SUPPORTED |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1039 | /* reset structure */ |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1040 | png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf)); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1041 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1042 | |
| 1043 | error_fn = png_ptr->error_fn; |
| 1044 | warning_fn = png_ptr->warning_fn; |
| 1045 | error_ptr = png_ptr->error_ptr; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1046 | #ifdef PNG_USER_MEM_SUPPORTED |
| 1047 | free_fn = png_ptr->free_fn; |
| 1048 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1049 | |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1050 | png_memset(png_ptr, 0, sizeof (png_struct)); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1051 | |
| 1052 | png_ptr->error_fn = error_fn; |
| 1053 | png_ptr->warning_fn = warning_fn; |
| 1054 | png_ptr->error_ptr = error_ptr; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1055 | #ifdef PNG_USER_MEM_SUPPORTED |
| 1056 | png_ptr->free_fn = free_fn; |
| 1057 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1058 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1059 | #ifdef PNG_SETJMP_SUPPORTED |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1060 | png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf)); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1061 | #endif |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1062 | } |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1063 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1064 | /* Allow the application to select one or more row filters to use. */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1065 | void PNGAPI |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1066 | png_set_filter(png_structp png_ptr, int method, int filters) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1067 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1068 | png_debug(1, "in png_set_filter\n"); |
Glenn Randers-Pehrson | 408b421 | 2000-12-18 09:33:57 -0600 | [diff] [blame] | 1069 | #if defined(PNG_MNG_FEATURES_SUPPORTED) |
Glenn Randers-Pehrson | f05f803 | 2000-12-23 14:27:39 -0600 | [diff] [blame] | 1070 | if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && |
Glenn Randers-Pehrson | 408b421 | 2000-12-18 09:33:57 -0600 | [diff] [blame] | 1071 | (method == PNG_INTRAPIXEL_DIFFERENCING)) |
| 1072 | method = PNG_FILTER_TYPE_BASE; |
| 1073 | #endif |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1074 | if (method == PNG_FILTER_TYPE_BASE) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1075 | { |
| 1076 | switch (filters & (PNG_ALL_FILTERS | 0x07)) |
| 1077 | { |
| 1078 | case 5: |
| 1079 | case 6: |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1080 | case 7: png_warning(png_ptr, "Unknown row filter for method 0"); |
| 1081 | case PNG_FILTER_VALUE_NONE: png_ptr->do_filter=PNG_FILTER_NONE; break; |
| 1082 | case PNG_FILTER_VALUE_SUB: png_ptr->do_filter=PNG_FILTER_SUB; break; |
| 1083 | case PNG_FILTER_VALUE_UP: png_ptr->do_filter=PNG_FILTER_UP; break; |
| 1084 | case PNG_FILTER_VALUE_AVG: png_ptr->do_filter=PNG_FILTER_AVG; break; |
| 1085 | case PNG_FILTER_VALUE_PAETH: png_ptr->do_filter=PNG_FILTER_PAETH;break; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1086 | default: png_ptr->do_filter = (png_byte)filters; break; |
| 1087 | } |
| 1088 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1089 | /* If we have allocated the row_buf, this means we have already started |
| 1090 | * with the image and we should have allocated all of the filter buffers |
| 1091 | * that have been selected. If prev_row isn't already allocated, then |
| 1092 | * it is too late to start using the filters that need it, since we |
| 1093 | * will be missing the data in the previous row. If an application |
| 1094 | * wants to start and stop using particular filters during compression, |
| 1095 | * it should start out with all of the filters, and then add and |
| 1096 | * remove them after the start of compression. |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1097 | */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1098 | if (png_ptr->row_buf != NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1099 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1100 | if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1101 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1102 | png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1103 | (png_ptr->rowbytes + 1)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1104 | png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1105 | } |
| 1106 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1107 | if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1108 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1109 | if (png_ptr->prev_row == NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1110 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1111 | png_warning(png_ptr, "Can't add Up filter after starting"); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1112 | png_ptr->do_filter &= ~PNG_FILTER_UP; |
| 1113 | } |
| 1114 | else |
| 1115 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1116 | png_ptr->up_row = (png_bytep)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1117 | (png_ptr->rowbytes + 1)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1118 | png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1119 | } |
| 1120 | } |
| 1121 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1122 | if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1123 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1124 | if (png_ptr->prev_row == NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1125 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1126 | png_warning(png_ptr, "Can't add Average filter after starting"); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1127 | png_ptr->do_filter &= ~PNG_FILTER_AVG; |
| 1128 | } |
| 1129 | else |
| 1130 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1131 | png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1132 | (png_ptr->rowbytes + 1)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1133 | png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1134 | } |
| 1135 | } |
| 1136 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1137 | if ((png_ptr->do_filter & PNG_FILTER_PAETH) && |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1138 | png_ptr->paeth_row == NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1139 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1140 | if (png_ptr->prev_row == NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1141 | { |
| 1142 | png_warning(png_ptr, "Can't add Paeth filter after starting"); |
Glenn Randers-Pehrson | 860ab2b | 1999-10-14 07:43:10 -0500 | [diff] [blame] | 1143 | png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1144 | } |
| 1145 | else |
| 1146 | { |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1147 | png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1148 | (png_ptr->rowbytes + 1)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1149 | png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | if (png_ptr->do_filter == PNG_NO_FILTERS) |
| 1154 | png_ptr->do_filter = PNG_FILTER_NONE; |
| 1155 | } |
| 1156 | } |
| 1157 | else |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1158 | png_error(png_ptr, "Unknown custom filter method"); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1159 | } |
| 1160 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1161 | /* This allows us to influence the way in which libpng chooses the "best" |
| 1162 | * filter for the current scanline. While the "minimum-sum-of-absolute- |
| 1163 | * differences metric is relatively fast and effective, there is some |
| 1164 | * question as to whether it can be improved upon by trying to keep the |
| 1165 | * filtered data going to zlib more consistent, hopefully resulting in |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 1166 | * better compression. |
| 1167 | */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1168 | #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */ |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1169 | void PNGAPI |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1170 | png_set_filter_heuristics(png_structp png_ptr, int heuristic_method, |
| 1171 | int num_weights, png_doublep filter_weights, |
| 1172 | png_doublep filter_costs) |
| 1173 | { |
| 1174 | int i; |
| 1175 | |
| 1176 | png_debug(1, "in png_set_filter_heuristics\n"); |
| 1177 | if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST) |
| 1178 | { |
| 1179 | png_warning(png_ptr, "Unknown filter heuristic method"); |
| 1180 | return; |
| 1181 | } |
| 1182 | |
| 1183 | if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT) |
| 1184 | { |
| 1185 | heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED; |
| 1186 | } |
| 1187 | |
| 1188 | if (num_weights < 0 || filter_weights == NULL || |
| 1189 | heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED) |
| 1190 | { |
| 1191 | num_weights = 0; |
| 1192 | } |
| 1193 | |
Glenn Randers-Pehrson | 860ab2b | 1999-10-14 07:43:10 -0500 | [diff] [blame] | 1194 | png_ptr->num_prev_filters = (png_byte)num_weights; |
| 1195 | png_ptr->heuristic_method = (png_byte)heuristic_method; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1196 | |
| 1197 | if (num_weights > 0) |
| 1198 | { |
| 1199 | if (png_ptr->prev_filters == NULL) |
| 1200 | { |
| 1201 | png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1202 | (png_uint_32)(sizeof(png_byte) * num_weights)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1203 | |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 1204 | /* To make sure that the weighting starts out fairly */ |
| 1205 | for (i = 0; i < num_weights; i++) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1206 | { |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 1207 | png_ptr->prev_filters[i] = 255; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | if (png_ptr->filter_weights == NULL) |
| 1212 | { |
Glenn Randers-Pehrson | 87c6bc9 | 2001-04-03 22:43:19 -0500 | [diff] [blame] | 1213 | png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1214 | (png_uint_32)(sizeof(png_uint_16) * num_weights)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1215 | |
Glenn Randers-Pehrson | 87c6bc9 | 2001-04-03 22:43:19 -0500 | [diff] [blame] | 1216 | png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1217 | (png_uint_32)(sizeof(png_uint_16) * num_weights)); |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 1218 | for (i = 0; i < num_weights; i++) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1219 | { |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 1220 | png_ptr->inv_filter_weights[i] = |
| 1221 | png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | for (i = 0; i < num_weights; i++) |
| 1226 | { |
| 1227 | if (filter_weights[i] < 0.0) |
| 1228 | { |
| 1229 | png_ptr->inv_filter_weights[i] = |
| 1230 | png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR; |
| 1231 | } |
| 1232 | else |
| 1233 | { |
| 1234 | png_ptr->inv_filter_weights[i] = |
| 1235 | (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5); |
| 1236 | png_ptr->filter_weights[i] = |
| 1237 | (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5); |
| 1238 | } |
| 1239 | } |
| 1240 | } |
| 1241 | |
| 1242 | /* If, in the future, there are other filter methods, this would |
| 1243 | * need to be based on png_ptr->filter. |
| 1244 | */ |
| 1245 | if (png_ptr->filter_costs == NULL) |
| 1246 | { |
Glenn Randers-Pehrson | 87c6bc9 | 2001-04-03 22:43:19 -0500 | [diff] [blame] | 1247 | png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1248 | (png_uint_32)(sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1249 | |
Glenn Randers-Pehrson | 87c6bc9 | 2001-04-03 22:43:19 -0500 | [diff] [blame] | 1250 | png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1251 | (png_uint_32)(sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1252 | |
| 1253 | for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) |
| 1254 | { |
| 1255 | png_ptr->inv_filter_costs[i] = |
| 1256 | png_ptr->filter_costs[i] = PNG_COST_FACTOR; |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | /* Here is where we set the relative costs of the different filters. We |
| 1261 | * should take the desired compression level into account when setting |
| 1262 | * the costs, so that Paeth, for instance, has a high relative cost at low |
| 1263 | * compression levels, while it has a lower relative cost at higher |
| 1264 | * compression settings. The filter types are in order of increasing |
| 1265 | * relative cost, so it would be possible to do this with an algorithm. |
| 1266 | */ |
| 1267 | for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) |
| 1268 | { |
| 1269 | if (filter_costs == NULL || filter_costs[i] < 0.0) |
| 1270 | { |
| 1271 | png_ptr->inv_filter_costs[i] = |
| 1272 | png_ptr->filter_costs[i] = PNG_COST_FACTOR; |
| 1273 | } |
| 1274 | else if (filter_costs[i] >= 1.0) |
| 1275 | { |
| 1276 | png_ptr->inv_filter_costs[i] = |
| 1277 | (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5); |
| 1278 | png_ptr->filter_costs[i] = |
| 1279 | (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5); |
| 1280 | } |
| 1281 | } |
| 1282 | } |
| 1283 | #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */ |
| 1284 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1285 | void PNGAPI |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1286 | png_set_compression_level(png_structp png_ptr, int level) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1287 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1288 | png_debug(1, "in png_set_compression_level\n"); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1289 | png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1290 | png_ptr->zlib_level = level; |
| 1291 | } |
| 1292 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1293 | void PNGAPI |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1294 | png_set_compression_mem_level(png_structp png_ptr, int mem_level) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1295 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1296 | png_debug(1, "in png_set_compression_mem_level\n"); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1297 | png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 1298 | png_ptr->zlib_mem_level = mem_level; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1299 | } |
| 1300 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1301 | void PNGAPI |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1302 | png_set_compression_strategy(png_structp png_ptr, int strategy) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1303 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1304 | png_debug(1, "in png_set_compression_strategy\n"); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1305 | png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1306 | png_ptr->zlib_strategy = strategy; |
| 1307 | } |
| 1308 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1309 | void PNGAPI |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1310 | png_set_compression_window_bits(png_structp png_ptr, int window_bits) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1311 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1312 | if (window_bits > 15) |
| 1313 | png_warning(png_ptr, "Only compression windows <= 32k supported by PNG"); |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 1314 | else if (window_bits < 8) |
| 1315 | png_warning(png_ptr, "Only compression windows >= 256 supported by PNG"); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1316 | #ifndef WBITS_8_OK |
| 1317 | /* avoid libpng bug with 256-byte windows */ |
| 1318 | if (window_bits == 8) |
| 1319 | { |
| 1320 | png_warning(png_ptr, "Compression window is being reset to 512"); |
| 1321 | window_bits=9; |
| 1322 | } |
| 1323 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1324 | png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1325 | png_ptr->zlib_window_bits = window_bits; |
| 1326 | } |
| 1327 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1328 | void PNGAPI |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1329 | png_set_compression_method(png_structp png_ptr, int method) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1330 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1331 | png_debug(1, "in png_set_compression_method\n"); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1332 | if (method != 8) |
| 1333 | png_warning(png_ptr, "Only compression method 8 is supported by PNG"); |
| 1334 | png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1335 | png_ptr->zlib_method = method; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1336 | } |
| 1337 | |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1338 | void PNGAPI |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1339 | png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn) |
| 1340 | { |
| 1341 | png_ptr->write_row_fn = write_row_fn; |
| 1342 | } |
| 1343 | |
| 1344 | #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1345 | void PNGAPI |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1346 | png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr |
| 1347 | write_user_transform_fn) |
| 1348 | { |
| 1349 | png_debug(1, "in png_set_write_user_transform_fn\n"); |
| 1350 | png_ptr->transformations |= PNG_USER_TRANSFORM; |
| 1351 | png_ptr->write_user_transform_fn = write_user_transform_fn; |
| 1352 | } |
| 1353 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1354 | |
| 1355 | |
| 1356 | #if defined(PNG_INFO_IMAGE_SUPPORTED) |
Glenn Randers-Pehrson | 7529457 | 2000-05-06 14:09:57 -0500 | [diff] [blame] | 1357 | void PNGAPI |
| 1358 | png_write_png(png_structp png_ptr, png_infop info_ptr, |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 1359 | int transforms, voidp params) |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1360 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1361 | #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) |
| 1362 | /* invert the alpha channel from opacity to transparency */ |
| 1363 | if (transforms & PNG_TRANSFORM_INVERT_ALPHA) |
| 1364 | png_set_invert_alpha(png_ptr); |
| 1365 | #endif |
| 1366 | |
| 1367 | /* Write the file header information. */ |
| 1368 | png_write_info(png_ptr, info_ptr); |
| 1369 | |
| 1370 | /* ------ these transformations don't touch the info structure ------- */ |
| 1371 | |
| 1372 | #if defined(PNG_WRITE_INVERT_SUPPORTED) |
| 1373 | /* invert monochrome pixels */ |
| 1374 | if (transforms & PNG_TRANSFORM_INVERT_MONO) |
| 1375 | png_set_invert_mono(png_ptr); |
| 1376 | #endif |
| 1377 | |
| 1378 | #if defined(PNG_WRITE_SHIFT_SUPPORTED) |
| 1379 | /* Shift the pixels up to a legal bit depth and fill in |
| 1380 | * as appropriate to correctly scale the image. |
| 1381 | */ |
| 1382 | if ((transforms & PNG_TRANSFORM_SHIFT) |
| 1383 | && (info_ptr->valid & PNG_INFO_sBIT)) |
| 1384 | png_set_shift(png_ptr, &info_ptr->sig_bit); |
| 1385 | #endif |
| 1386 | |
| 1387 | #if defined(PNG_WRITE_PACK_SUPPORTED) |
| 1388 | /* pack pixels into bytes */ |
| 1389 | if (transforms & PNG_TRANSFORM_PACKING) |
| 1390 | png_set_packing(png_ptr); |
| 1391 | #endif |
| 1392 | |
| 1393 | #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) |
| 1394 | /* swap location of alpha bytes from ARGB to RGBA */ |
| 1395 | if (transforms & PNG_TRANSFORM_SWAP_ALPHA) |
| 1396 | png_set_swap_alpha(png_ptr); |
| 1397 | #endif |
| 1398 | |
| 1399 | #if defined(PNG_WRITE_FILLER_SUPPORTED) |
| 1400 | /* Get rid of filler (OR ALPHA) bytes, pack XRGB/RGBX/ARGB/RGBA into |
| 1401 | * RGB (4 channels -> 3 channels). The second parameter is not used. |
| 1402 | */ |
| 1403 | if (transforms & PNG_TRANSFORM_STRIP_FILLER) |
| 1404 | png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); |
| 1405 | #endif |
| 1406 | |
| 1407 | #if defined(PNG_WRITE_BGR_SUPPORTED) |
| 1408 | /* flip BGR pixels to RGB */ |
| 1409 | if (transforms & PNG_TRANSFORM_BGR) |
| 1410 | png_set_bgr(png_ptr); |
| 1411 | #endif |
| 1412 | |
| 1413 | #if defined(PNG_WRITE_SWAP_SUPPORTED) |
| 1414 | /* swap bytes of 16-bit files to most significant byte first */ |
| 1415 | if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) |
| 1416 | png_set_swap(png_ptr); |
| 1417 | #endif |
| 1418 | |
| 1419 | #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) |
| 1420 | /* swap bits of 1, 2, 4 bit packed pixel formats */ |
| 1421 | if (transforms & PNG_TRANSFORM_PACKSWAP) |
| 1422 | png_set_packswap(png_ptr); |
| 1423 | #endif |
| 1424 | |
| 1425 | /* ----------------------- end of transformations ------------------- */ |
| 1426 | |
| 1427 | /* write the bits */ |
| 1428 | if (info_ptr->valid & PNG_INFO_IDAT) |
| 1429 | png_write_image(png_ptr, info_ptr->row_pointers); |
| 1430 | |
| 1431 | /* It is REQUIRED to call this to finish writing the rest of the file */ |
| 1432 | png_write_end(png_ptr, info_ptr); |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 1433 | |
Glenn Randers-Pehrson | 82ae383 | 2001-04-20 10:32:10 -0500 | [diff] [blame] | 1434 | if(transforms == 0 || params == NULL) |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 1435 | /* quiet compiler warnings */ return; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1436 | } |
| 1437 | #endif |
Glenn Randers-Pehrson | 1909560 | 2001-03-14 07:08:39 -0600 | [diff] [blame] | 1438 | #endif /* PNG_WRITE_SUPPORTED */ |