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