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 | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame^] | 4 | * libpng 1.0.5c - November 27, 1999 |
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 |
| 6 | * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. |
| 7 | * Copyright (c) 1996, 1997 Andreas Dilger |
Glenn Randers-Pehrson | c944229 | 1999-01-06 21:50:16 -0600 | [diff] [blame] | 8 | * Copyright (c) 1998, 1999 Glenn Randers-Pehrson |
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" |
| 14 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 15 | /* Writes all the PNG information. This is the suggested way to use the |
| 16 | * library. If you have a new chunk to add, make a function to write it, |
| 17 | * 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] | 18 | * 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] | 19 | * you to supply a PNG_INFO_ flag, and check info_ptr->valid before writing |
| 20 | * the chunk, as that will keep the code from breaking if you want to just |
| 21 | * write a plain PNG file. If you have long comments, I suggest writing |
| 22 | * them in png_write_end(), and compressing them. |
| 23 | */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 24 | void |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame^] | 25 | 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] | 26 | { |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame^] | 27 | png_debug(1, "in png_write_info_before_PLTE\n"); |
| 28 | if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) |
| 29 | { |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 30 | png_write_sig(png_ptr); /* write PNG signature */ |
| 31 | /* write IHDR information. */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 32 | png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height, |
| 33 | 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] | 34 | info_ptr->filter_type, |
| 35 | #if defined(PNG_WRITE_INTERLACING_SUPPORTED) |
| 36 | info_ptr->interlace_type); |
| 37 | #else |
| 38 | 0); |
| 39 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 40 | /* the rest of these check to see if the valid field has the appropriate |
| 41 | flag set, and if it does, writes the chunk. */ |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 42 | #if defined(PNG_WRITE_gAMA_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 43 | if (info_ptr->valid & PNG_INFO_gAMA) |
| 44 | png_write_gAMA(png_ptr, info_ptr->gamma); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 45 | #endif |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 46 | #if defined(PNG_WRITE_sRGB_SUPPORTED) |
| 47 | if (info_ptr->valid & PNG_INFO_sRGB) |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 48 | png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent); |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 49 | #endif |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 50 | #if defined(PNG_WRITE_sBIT_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 51 | if (info_ptr->valid & PNG_INFO_sBIT) |
| 52 | 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] | 53 | #endif |
| 54 | #if defined(PNG_WRITE_cHRM_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 55 | if (info_ptr->valid & PNG_INFO_cHRM) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 56 | png_write_cHRM(png_ptr, |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 57 | info_ptr->x_white, info_ptr->y_white, |
| 58 | info_ptr->x_red, info_ptr->y_red, |
| 59 | info_ptr->x_green, info_ptr->y_green, |
| 60 | info_ptr->x_blue, info_ptr->y_blue); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 61 | #endif |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame^] | 62 | png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | void |
| 67 | png_write_info(png_structp png_ptr, png_infop info_ptr) |
| 68 | { |
| 69 | #if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED) |
| 70 | int i; |
| 71 | #endif |
| 72 | |
| 73 | png_debug(1, "in png_write_info\n"); |
| 74 | |
| 75 | png_write_info_before_PLTE(png_ptr, info_ptr); |
| 76 | |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 77 | if (info_ptr->valid & PNG_INFO_PLTE) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 78 | png_write_PLTE(png_ptr, info_ptr->palette, |
| 79 | (png_uint_32)info_ptr->num_palette); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 80 | else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 81 | png_error(png_ptr, "Valid palette required for paletted images\n"); |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 82 | |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 83 | #if defined(PNG_WRITE_tRNS_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 84 | if (info_ptr->valid & PNG_INFO_tRNS) |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 85 | { |
| 86 | #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) |
| 87 | /* invert the alpha channel (in tRNS) */ |
| 88 | if (png_ptr->transformations & PNG_INVERT_ALPHA && |
| 89 | info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
| 90 | { |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 91 | int j; |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 92 | for (j=0; j<(int)info_ptr->num_trans; j++) |
Glenn Randers-Pehrson | 860ab2b | 1999-10-14 07:43:10 -0500 | [diff] [blame] | 93 | info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]); |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 94 | } |
| 95 | #endif |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 96 | png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values), |
| 97 | info_ptr->num_trans, info_ptr->color_type); |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 98 | } |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 99 | #endif |
| 100 | #if defined(PNG_WRITE_bKGD_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 101 | if (info_ptr->valid & PNG_INFO_bKGD) |
| 102 | png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 103 | #endif |
| 104 | #if defined(PNG_WRITE_hIST_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 105 | if (info_ptr->valid & PNG_INFO_hIST) |
| 106 | png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 107 | #endif |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 108 | #if defined(PNG_WRITE_oFFs_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 109 | if (info_ptr->valid & PNG_INFO_oFFs) |
| 110 | png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset, |
| 111 | info_ptr->offset_unit_type); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 112 | #endif |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 113 | #if defined(PNG_WRITE_pCAL_SUPPORTED) |
| 114 | if (info_ptr->valid & PNG_INFO_pCAL) |
| 115 | png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0, |
| 116 | info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams, |
| 117 | info_ptr->pcal_units, info_ptr->pcal_params); |
| 118 | #endif |
| 119 | #if defined(PNG_WRITE_pHYs_SUPPORTED) |
| 120 | if (info_ptr->valid & PNG_INFO_pHYs) |
| 121 | png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit, |
| 122 | info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type); |
| 123 | #endif |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 124 | #if defined(PNG_WRITE_tIME_SUPPORTED) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 125 | if (info_ptr->valid & PNG_INFO_tIME) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 126 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 127 | png_write_tIME(png_ptr, &(info_ptr->mod_time)); |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame^] | 128 | png_ptr->mode |= PNG_WROTE_tIME; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 129 | } |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 130 | #endif |
| 131 | #if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 132 | /* Check to see if we need to write text chunks */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 133 | for (i = 0; i < info_ptr->num_text; i++) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 134 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 135 | png_debug2(2, "Writing header text chunk %d, type %d\n", i, |
| 136 | info_ptr->text[i].compression); |
| 137 | /* If we want a compressed text chunk */ |
| 138 | if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt) |
| 139 | { |
| 140 | #if defined(PNG_WRITE_zTXt_SUPPORTED) |
| 141 | /* write compressed chunk */ |
| 142 | png_write_zTXt(png_ptr, info_ptr->text[i].key, |
| 143 | info_ptr->text[i].text, info_ptr->text[i].text_length, |
| 144 | info_ptr->text[i].compression); |
| 145 | #else |
| 146 | png_warning(png_ptr, "Unable to write compressed text\n"); |
| 147 | #endif |
| 148 | /* Mark this chunk as written */ |
| 149 | info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; |
| 150 | } |
| 151 | else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) |
| 152 | { |
| 153 | #if defined(PNG_WRITE_tEXt_SUPPORTED) |
| 154 | /* write uncompressed chunk */ |
| 155 | png_write_tEXt(png_ptr, info_ptr->text[i].key, |
| 156 | info_ptr->text[i].text, info_ptr->text[i].text_length); |
| 157 | #else |
| 158 | png_warning(png_ptr, "Unable to write uncompressed text\n"); |
| 159 | #endif |
| 160 | /* Mark this chunk as written */ |
| 161 | info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; |
| 162 | } |
| 163 | } |
| 164 | #endif |
| 165 | } |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 166 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 167 | /* 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] | 168 | * time information, you can pass NULL for info. If you already wrote these |
| 169 | * in png_write_info(), do not write them again here. If you have long |
| 170 | * comments, I suggest writing them here, and compressing them. |
| 171 | */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 172 | void |
| 173 | png_write_end(png_structp png_ptr, png_infop info_ptr) |
| 174 | { |
| 175 | png_debug(1, "in png_write_end\n"); |
| 176 | if (!(png_ptr->mode & PNG_HAVE_IDAT)) |
| 177 | png_error(png_ptr, "No IDATs written into file"); |
| 178 | |
| 179 | /* see if user wants us to write information chunks */ |
| 180 | if (info_ptr != NULL) |
| 181 | { |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 182 | #if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 183 | int i; /* local index variable */ |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 184 | #endif |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 185 | #if defined(PNG_WRITE_tIME_SUPPORTED) |
| 186 | /* check to see if user has supplied a time chunk */ |
| 187 | if (info_ptr->valid & PNG_INFO_tIME && |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame^] | 188 | !(png_ptr->mode & PNG_WROTE_tIME)) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 189 | png_write_tIME(png_ptr, &(info_ptr->mod_time)); |
| 190 | #endif |
| 191 | #if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED) |
| 192 | /* loop through comment chunks */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 193 | for (i = 0; i < info_ptr->num_text; i++) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 194 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 195 | png_debug2(2, "Writing trailer text chunk %d, type %d\n", i, |
| 196 | info_ptr->text[i].compression); |
| 197 | if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 198 | { |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 199 | #if defined(PNG_WRITE_zTXt_SUPPORTED) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 200 | /* write compressed chunk */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 201 | png_write_zTXt(png_ptr, info_ptr->text[i].key, |
| 202 | info_ptr->text[i].text, info_ptr->text[i].text_length, |
| 203 | info_ptr->text[i].compression); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 204 | #else |
| 205 | png_warning(png_ptr, "Unable to write compressed text\n"); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 206 | #endif |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 207 | /* Mark this chunk as written */ |
| 208 | info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 209 | } |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 210 | else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 211 | { |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 212 | #if defined(PNG_WRITE_tEXt_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 213 | /* write uncompressed chunk */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 214 | png_write_tEXt(png_ptr, info_ptr->text[i].key, |
| 215 | info_ptr->text[i].text, info_ptr->text[i].text_length); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 216 | #else |
| 217 | png_warning(png_ptr, "Unable to write uncompressed text\n"); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 218 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 219 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 220 | /* Mark this chunk as written */ |
| 221 | info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 222 | } |
| 223 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 224 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 225 | } |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 226 | |
| 227 | png_ptr->mode |= PNG_AFTER_IDAT; |
| 228 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 229 | /* write end of PNG file */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 230 | png_write_IEND(png_ptr); |
| 231 | } |
| 232 | |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 233 | #if defined(PNG_WRITE_tIME_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 234 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 235 | png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 236 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 237 | png_debug(1, "in png_convert_from_struct_tm\n"); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 238 | ptime->year = (png_uint_16)(1900 + ttime->tm_year); |
| 239 | ptime->month = (png_byte)(ttime->tm_mon + 1); |
| 240 | ptime->day = (png_byte)ttime->tm_mday; |
| 241 | ptime->hour = (png_byte)ttime->tm_hour; |
| 242 | ptime->minute = (png_byte)ttime->tm_min; |
| 243 | ptime->second = (png_byte)ttime->tm_sec; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 247 | png_convert_from_time_t(png_timep ptime, time_t ttime) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 248 | { |
| 249 | struct tm *tbuf; |
| 250 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 251 | png_debug(1, "in png_convert_from_time_t\n"); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 252 | tbuf = gmtime(&ttime); |
| 253 | png_convert_from_struct_tm(ptime, tbuf); |
| 254 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 255 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 256 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 257 | /* Initialize png_ptr structure, and allocate any memory needed */ |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 258 | png_structp |
Glenn Randers-Pehrson | d0dce40 | 1998-05-09 10:02:29 -0500 | [diff] [blame] | 259 | 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] | 260 | png_error_ptr error_fn, png_error_ptr warn_fn) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 261 | { |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 262 | #ifdef PNG_USER_MEM_SUPPORTED |
| 263 | return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn, |
| 264 | warn_fn, NULL, NULL, NULL)); |
| 265 | } |
| 266 | |
| 267 | /* Alternate initialize png_ptr structure, and allocate any memory needed */ |
| 268 | png_structp |
| 269 | png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, |
| 270 | png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, |
| 271 | png_malloc_ptr malloc_fn, png_free_ptr free_fn) |
| 272 | { |
| 273 | #endif /* PNG_USER_MEM_SUPPORTED */ |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 274 | png_structp png_ptr; |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 275 | #ifdef USE_FAR_KEYWORD |
| 276 | jmp_buf jmpbuf; |
| 277 | #endif |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 278 | png_debug(1, "in png_create_write_struct\n"); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 279 | #ifdef PNG_USER_MEM_SUPPORTED |
| 280 | if ((png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, |
| 281 | (png_malloc_ptr)malloc_fn)) == NULL) |
| 282 | #else |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 283 | if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL) |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 284 | #endif /* PNG_USER_MEM_SUPPORTED */ |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 285 | { |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 286 | return ((png_structp)NULL); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 287 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 288 | #ifdef USE_FAR_KEYWORD |
| 289 | if (setjmp(jmpbuf)) |
| 290 | #else |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 291 | if (setjmp(png_ptr->jmpbuf)) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 292 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 293 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 294 | png_free(png_ptr, png_ptr->zbuf); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 295 | png_destroy_struct(png_ptr); |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 296 | return ((png_structp)NULL); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 297 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 298 | #ifdef USE_FAR_KEYWORD |
| 299 | png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf)); |
| 300 | #endif |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 301 | #ifdef PNG_USER_MEM_SUPPORTED |
| 302 | png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); |
| 303 | #endif /* PNG_USER_MEM_SUPPORTED */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 304 | png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 305 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 306 | /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so |
| 307 | * we must recompile any applications that use any older library version. |
| 308 | * For versions after libpng 1.0, we will be compatible, so we need |
| 309 | * only check the first digit. |
| 310 | */ |
| 311 | if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] || |
| 312 | (png_libpng_ver[0] == '0' && user_png_ver[2] < '9')) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 313 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 314 | png_error(png_ptr, |
| 315 | "Incompatible libpng version in application and library"); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 316 | } |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 317 | |
| 318 | /* initialize zbuf - compression buffer */ |
| 319 | png_ptr->zbuf_size = PNG_ZBUF_SIZE; |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 320 | png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, |
| 321 | (png_uint_32)png_ptr->zbuf_size); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 322 | |
| 323 | png_set_write_fn(png_ptr, NULL, NULL, NULL); |
| 324 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 325 | #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) |
| 326 | png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, |
| 327 | 1, NULL, NULL); |
| 328 | #endif |
| 329 | |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 330 | return ((png_structp)png_ptr); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 331 | } |
| 332 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 333 | /* Initialize png_ptr structure, and allocate any memory needed */ |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 334 | void |
| 335 | png_write_init(png_structp png_ptr) |
| 336 | { |
| 337 | jmp_buf tmp_jmp; /* to save current jump buffer */ |
| 338 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 339 | png_debug(1, "in png_write_init\n"); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 340 | /* save jump buffer and error functions */ |
| 341 | png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf)); |
| 342 | |
| 343 | /* reset all variables to 0 */ |
| 344 | png_memset(png_ptr, 0, sizeof (png_struct)); |
| 345 | |
| 346 | /* restore jump buffer */ |
| 347 | png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf)); |
| 348 | |
| 349 | /* initialize zbuf - compression buffer */ |
| 350 | png_ptr->zbuf_size = PNG_ZBUF_SIZE; |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 351 | png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, |
| 352 | (png_uint_32)png_ptr->zbuf_size); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 353 | png_set_write_fn(png_ptr, NULL, NULL, NULL); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 354 | |
| 355 | #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) |
| 356 | png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, |
| 357 | 1, NULL, NULL); |
| 358 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 359 | } |
| 360 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 361 | /* Write a few rows of image data. If the image is interlaced, |
| 362 | * either you will have to write the 7 sub images, or, if you |
| 363 | * have called png_set_interlace_handling(), you will have to |
| 364 | * "write" the image seven times. |
| 365 | */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 366 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 367 | png_write_rows(png_structp png_ptr, png_bytepp row, |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 368 | png_uint_32 num_rows) |
| 369 | { |
| 370 | png_uint_32 i; /* row counter */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 371 | png_bytepp rp; /* row pointer */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 372 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 373 | png_debug(1, "in png_write_rows\n"); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 374 | /* loop through the rows */ |
| 375 | for (i = 0, rp = row; i < num_rows; i++, rp++) |
| 376 | { |
| 377 | png_write_row(png_ptr, *rp); |
| 378 | } |
| 379 | } |
| 380 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 381 | /* Write the image. You only need to call this function once, even |
| 382 | * if you are writing an interlaced image. |
| 383 | */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 384 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 385 | png_write_image(png_structp png_ptr, png_bytepp image) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 386 | { |
| 387 | png_uint_32 i; /* row index */ |
| 388 | int pass, num_pass; /* pass variables */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 389 | png_bytepp rp; /* points to current row */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 390 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 391 | png_debug(1, "in png_write_image\n"); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 392 | #if defined(PNG_WRITE_INTERLACING_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 393 | /* intialize interlace handling. If image is not interlaced, |
| 394 | this will set pass to 1 */ |
| 395 | num_pass = png_set_interlace_handling(png_ptr); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 396 | #else |
| 397 | num_pass = 1; |
| 398 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 399 | /* loop through passes */ |
| 400 | for (pass = 0; pass < num_pass; pass++) |
| 401 | { |
| 402 | /* loop through image */ |
| 403 | for (i = 0, rp = image; i < png_ptr->height; i++, rp++) |
| 404 | { |
| 405 | png_write_row(png_ptr, *rp); |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 410 | /* called by user to write a row of image data */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 411 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 412 | png_write_row(png_structp png_ptr, png_bytep row) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 413 | { |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 414 | png_debug2(1, "in png_write_row (row %ld, pass %d)\n", |
| 415 | png_ptr->row_number, png_ptr->pass); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 416 | /* initialize transformations and other stuff if first time */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 417 | if (png_ptr->row_number == 0 && png_ptr->pass == 0) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 418 | { |
Glenn Randers-Pehrson | 1d96361 | 1998-05-02 12:52:25 -0500 | [diff] [blame] | 419 | /* check for transforms that have been set but were defined out */ |
| 420 | #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED) |
| 421 | if (png_ptr->transformations & PNG_INVERT_MONO) |
| 422 | png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined."); |
| 423 | #endif |
| 424 | #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED) |
| 425 | if (png_ptr->transformations & PNG_FILLER) |
| 426 | png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined."); |
| 427 | #endif |
| 428 | #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED) |
| 429 | if (png_ptr->transformations & PNG_PACKSWAP) |
| 430 | png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined."); |
| 431 | #endif |
| 432 | #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED) |
| 433 | if (png_ptr->transformations & PNG_PACK) |
| 434 | png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined."); |
| 435 | #endif |
| 436 | #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED) |
| 437 | if (png_ptr->transformations & PNG_SHIFT) |
| 438 | png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined."); |
| 439 | #endif |
| 440 | #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED) |
| 441 | if (png_ptr->transformations & PNG_BGR) |
| 442 | png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined."); |
| 443 | #endif |
| 444 | #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED) |
| 445 | if (png_ptr->transformations & PNG_SWAP_BYTES) |
| 446 | png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined."); |
| 447 | #endif |
| 448 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 449 | png_write_start_row(png_ptr); |
| 450 | } |
| 451 | |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 452 | #if defined(PNG_WRITE_INTERLACING_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 453 | /* if interlaced and not interested in row, return */ |
| 454 | if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) |
| 455 | { |
| 456 | switch (png_ptr->pass) |
| 457 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 458 | case 0: |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 459 | if (png_ptr->row_number & 7) |
| 460 | { |
| 461 | png_write_finish_row(png_ptr); |
| 462 | return; |
| 463 | } |
| 464 | break; |
| 465 | case 1: |
| 466 | if ((png_ptr->row_number & 7) || png_ptr->width < 5) |
| 467 | { |
| 468 | png_write_finish_row(png_ptr); |
| 469 | return; |
| 470 | } |
| 471 | break; |
| 472 | case 2: |
| 473 | if ((png_ptr->row_number & 7) != 4) |
| 474 | { |
| 475 | png_write_finish_row(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 476 | return; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 477 | } |
| 478 | break; |
| 479 | case 3: |
| 480 | if ((png_ptr->row_number & 3) || png_ptr->width < 3) |
| 481 | { |
| 482 | png_write_finish_row(png_ptr); |
| 483 | return; |
| 484 | } |
| 485 | break; |
| 486 | case 4: |
| 487 | if ((png_ptr->row_number & 3) != 2) |
| 488 | { |
| 489 | png_write_finish_row(png_ptr); |
| 490 | return; |
| 491 | } |
| 492 | break; |
| 493 | case 5: |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 494 | if ((png_ptr->row_number & 1) || png_ptr->width < 2) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 495 | { |
| 496 | png_write_finish_row(png_ptr); |
| 497 | return; |
| 498 | } |
| 499 | break; |
| 500 | case 6: |
| 501 | if (!(png_ptr->row_number & 1)) |
| 502 | { |
| 503 | png_write_finish_row(png_ptr); |
| 504 | return; |
| 505 | } |
| 506 | break; |
| 507 | } |
| 508 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 509 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 510 | |
| 511 | /* set up row info for transformations */ |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 512 | png_ptr->row_info.color_type = png_ptr->color_type; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 513 | png_ptr->row_info.width = png_ptr->usr_width; |
| 514 | png_ptr->row_info.channels = png_ptr->usr_channels; |
| 515 | png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 516 | png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth * |
| 517 | png_ptr->row_info.channels); |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 518 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 519 | png_ptr->row_info.rowbytes = ((png_ptr->row_info.width * |
| 520 | (png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3); |
| 521 | |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 522 | png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type); |
| 523 | png_debug1(3, "row_info->width = %d\n", png_ptr->row_info.width); |
| 524 | png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels); |
| 525 | png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth); |
| 526 | png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth); |
| 527 | png_debug1(3, "row_info->rowbytes = %d\n", png_ptr->row_info.rowbytes); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 528 | |
| 529 | /* Copy user's row into buffer, leaving room for filter byte. */ |
Glenn Randers-Pehrson | a357b99 | 1998-02-08 20:56:40 -0600 | [diff] [blame] | 530 | png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 531 | png_ptr->row_info.rowbytes); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 532 | |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 533 | #if defined(PNG_WRITE_INTERLACING_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 534 | /* handle interlacing */ |
| 535 | if (png_ptr->interlaced && png_ptr->pass < 6 && |
| 536 | (png_ptr->transformations & PNG_INTERLACE)) |
| 537 | { |
| 538 | png_do_write_interlace(&(png_ptr->row_info), |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 539 | png_ptr->row_buf + 1, png_ptr->pass); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 540 | /* this should always get caught above, but still ... */ |
| 541 | if (!(png_ptr->row_info.width)) |
| 542 | { |
| 543 | png_write_finish_row(png_ptr); |
| 544 | return; |
| 545 | } |
| 546 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 547 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 548 | |
| 549 | /* handle other transformations */ |
| 550 | if (png_ptr->transformations) |
| 551 | png_do_write_transformations(png_ptr); |
| 552 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 553 | /* Find a filter if necessary, filter the row and write it out. */ |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 554 | png_write_find_filter(png_ptr, &(png_ptr->row_info)); |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 555 | |
| 556 | if (png_ptr->write_row_fn != NULL) |
| 557 | (*(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] | 558 | } |
| 559 | |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 560 | #if defined(PNG_WRITE_FLUSH_SUPPORTED) |
| 561 | /* Set the automatic flush interval or 0 to turn flushing off */ |
| 562 | void |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 563 | png_set_flush(png_structp png_ptr, int nrows) |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 564 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 565 | png_debug(1, "in png_set_flush\n"); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 566 | png_ptr->flush_dist = (nrows < 0 ? 0 : nrows); |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | /* flush the current output buffers now */ |
| 570 | void |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 571 | png_write_flush(png_structp png_ptr) |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 572 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 573 | int wrote_IDAT; |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 574 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 575 | png_debug(1, "in png_write_flush\n"); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 576 | /* We have already written out all of the data */ |
| 577 | if (png_ptr->row_number >= png_ptr->num_rows) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 578 | return; |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 579 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 580 | do |
| 581 | { |
| 582 | int ret; |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 583 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 584 | /* compress the data */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 585 | ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 586 | wrote_IDAT = 0; |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 587 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 588 | /* check for compression errors */ |
| 589 | if (ret != Z_OK) |
| 590 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 591 | if (png_ptr->zstream.msg != NULL) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 592 | png_error(png_ptr, png_ptr->zstream.msg); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 593 | else |
| 594 | png_error(png_ptr, "zlib error"); |
| 595 | } |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 596 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 597 | if (!(png_ptr->zstream.avail_out)) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 598 | { |
| 599 | /* write the IDAT and reset the zlib output buffer */ |
| 600 | png_write_IDAT(png_ptr, png_ptr->zbuf, |
| 601 | png_ptr->zbuf_size); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 602 | png_ptr->zstream.next_out = png_ptr->zbuf; |
| 603 | png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 604 | wrote_IDAT = 1; |
| 605 | } |
| 606 | } while(wrote_IDAT == 1); |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 607 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 608 | /* 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] | 609 | if (png_ptr->zbuf_size != png_ptr->zstream.avail_out) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 610 | { |
| 611 | /* write the IDAT and reset the zlib output buffer */ |
| 612 | png_write_IDAT(png_ptr, png_ptr->zbuf, |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 613 | png_ptr->zbuf_size - png_ptr->zstream.avail_out); |
| 614 | png_ptr->zstream.next_out = png_ptr->zbuf; |
| 615 | png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 616 | } |
| 617 | png_ptr->flush_rows = 0; |
| 618 | png_flush(png_ptr); |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 619 | } |
| 620 | #endif /* PNG_WRITE_FLUSH_SUPPORTED */ |
| 621 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 622 | /* free all memory used by the write */ |
| 623 | void |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 624 | 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] | 625 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 626 | png_structp png_ptr = NULL; |
| 627 | png_infop info_ptr = NULL; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 628 | #ifdef PNG_USER_MEM_SUPPORTED |
| 629 | png_free_ptr free_fn = NULL; |
| 630 | #endif |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 631 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 632 | png_debug(1, "in png_destroy_write_struct\n"); |
| 633 | if (png_ptr_ptr != NULL) |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 634 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 635 | png_ptr = *png_ptr_ptr; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 636 | #ifdef PNG_USER_MEM_SUPPORTED |
| 637 | free_fn = png_ptr->free_fn; |
| 638 | #endif |
| 639 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 640 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 641 | if (info_ptr_ptr != NULL) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 642 | info_ptr = *info_ptr_ptr; |
| 643 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 644 | if (info_ptr != NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 645 | { |
Glenn Randers-Pehrson | 6d8f3b0 | 1999-10-23 08:39:18 -0500 | [diff] [blame] | 646 | #if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED) |
| 647 | png_debug(1, "in png_info_destroy\n"); |
| 648 | if (info_ptr->text != NULL) |
| 649 | { |
| 650 | int i; |
| 651 | for (i = 0; i < info_ptr->num_text; i++) |
| 652 | { |
| 653 | if(info_ptr->text[i].key != NULL) |
| 654 | { |
| 655 | png_free(png_ptr, info_ptr->text[i].key); |
| 656 | info_ptr->text[i].key = NULL; |
| 657 | } |
| 658 | } |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 659 | png_free(png_ptr, info_ptr->text); |
Glenn Randers-Pehrson | 6d8f3b0 | 1999-10-23 08:39:18 -0500 | [diff] [blame] | 660 | info_ptr->text = NULL; |
| 661 | } |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 662 | #endif |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 663 | #if defined(PNG_READ_pCAL_SUPPORTED) |
| 664 | png_free(png_ptr, info_ptr->pcal_purpose); |
| 665 | png_free(png_ptr, info_ptr->pcal_units); |
| 666 | if (info_ptr->pcal_params != NULL) |
| 667 | { |
| 668 | int i; |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 669 | for (i = 0; i < (int)info_ptr->pcal_nparams; i++) |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 670 | { |
| 671 | png_free(png_ptr, info_ptr->pcal_params[i]); |
| 672 | } |
| 673 | png_free(png_ptr, info_ptr->pcal_params); |
| 674 | } |
| 675 | #endif |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 676 | #ifdef PNG_USER_MEM_SUPPORTED |
| 677 | png_destroy_struct_2((png_voidp)info_ptr, free_fn); |
| 678 | #else |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 679 | png_destroy_struct((png_voidp)info_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 680 | #endif |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 681 | *info_ptr_ptr = (png_infop)NULL; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 682 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 683 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 684 | if (png_ptr != NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 685 | { |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 686 | png_write_destroy(png_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 687 | #ifdef PNG_USER_MEM_SUPPORTED |
| 688 | png_destroy_struct_2((png_voidp)png_ptr, free_fn); |
| 689 | #else |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 690 | png_destroy_struct((png_voidp)png_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 691 | #endif |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 692 | *png_ptr_ptr = (png_structp)NULL; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 693 | } |
| 694 | } |
| 695 | |
| 696 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 697 | /* Free any memory used in png_ptr struct (old method) */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 698 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 699 | png_write_destroy(png_structp png_ptr) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 700 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 701 | jmp_buf tmp_jmp; /* save jump buffer */ |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 702 | png_error_ptr error_fn; |
| 703 | png_error_ptr warning_fn; |
| 704 | png_voidp error_ptr; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 705 | #ifdef PNG_USER_MEM_SUPPORTED |
| 706 | png_free_ptr free_fn; |
| 707 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 708 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 709 | png_debug(1, "in png_write_destroy\n"); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 710 | /* free any memory zlib uses */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 711 | deflateEnd(&png_ptr->zstream); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 712 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 713 | /* free our memory. png_free checks NULL for us. */ |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 714 | png_free(png_ptr, png_ptr->zbuf); |
| 715 | png_free(png_ptr, png_ptr->row_buf); |
| 716 | png_free(png_ptr, png_ptr->prev_row); |
| 717 | png_free(png_ptr, png_ptr->sub_row); |
| 718 | png_free(png_ptr, png_ptr->up_row); |
| 719 | png_free(png_ptr, png_ptr->avg_row); |
| 720 | png_free(png_ptr, png_ptr->paeth_row); |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 721 | #if defined(PNG_TIME_RFC1123_SUPPORTED) |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 722 | png_free(png_ptr, png_ptr->time_buffer); |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 723 | #endif /* PNG_TIME_RFC1123_SUPPORTED */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 724 | #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) |
| 725 | png_free(png_ptr, png_ptr->prev_filters); |
| 726 | png_free(png_ptr, png_ptr->filter_weights); |
| 727 | png_free(png_ptr, png_ptr->inv_filter_weights); |
| 728 | png_free(png_ptr, png_ptr->filter_costs); |
| 729 | png_free(png_ptr, png_ptr->inv_filter_costs); |
| 730 | #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */ |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 731 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 732 | /* reset structure */ |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 733 | png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf)); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 734 | |
| 735 | error_fn = png_ptr->error_fn; |
| 736 | warning_fn = png_ptr->warning_fn; |
| 737 | error_ptr = png_ptr->error_ptr; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 738 | #ifdef PNG_USER_MEM_SUPPORTED |
| 739 | free_fn = png_ptr->free_fn; |
| 740 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 741 | |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 742 | png_memset(png_ptr, 0, sizeof (png_struct)); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 743 | |
| 744 | png_ptr->error_fn = error_fn; |
| 745 | png_ptr->warning_fn = warning_fn; |
| 746 | png_ptr->error_ptr = error_ptr; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 747 | #ifdef PNG_USER_MEM_SUPPORTED |
| 748 | png_ptr->free_fn = free_fn; |
| 749 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 750 | |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 751 | png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf)); |
| 752 | } |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 753 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 754 | /* Allow the application to select one or more row filters to use. */ |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 755 | void |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 756 | png_set_filter(png_structp png_ptr, int method, int filters) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 757 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 758 | png_debug(1, "in png_set_filter\n"); |
| 759 | /* We allow 'method' only for future expansion of the base filter method. */ |
| 760 | if (method == PNG_FILTER_TYPE_BASE) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 761 | { |
| 762 | switch (filters & (PNG_ALL_FILTERS | 0x07)) |
| 763 | { |
| 764 | case 5: |
| 765 | case 6: |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 766 | case 7: png_warning(png_ptr, "Unknown row filter for method 0"); |
| 767 | case PNG_FILTER_VALUE_NONE: png_ptr->do_filter=PNG_FILTER_NONE; break; |
| 768 | case PNG_FILTER_VALUE_SUB: png_ptr->do_filter=PNG_FILTER_SUB; break; |
| 769 | case PNG_FILTER_VALUE_UP: png_ptr->do_filter=PNG_FILTER_UP; break; |
| 770 | case PNG_FILTER_VALUE_AVG: png_ptr->do_filter=PNG_FILTER_AVG; break; |
| 771 | 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] | 772 | default: png_ptr->do_filter = (png_byte)filters; break; |
| 773 | } |
| 774 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 775 | /* If we have allocated the row_buf, this means we have already started |
| 776 | * with the image and we should have allocated all of the filter buffers |
| 777 | * that have been selected. If prev_row isn't already allocated, then |
| 778 | * it is too late to start using the filters that need it, since we |
| 779 | * will be missing the data in the previous row. If an application |
| 780 | * wants to start and stop using particular filters during compression, |
| 781 | * it should start out with all of the filters, and then add and |
| 782 | * remove them after the start of compression. |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 783 | */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 784 | if (png_ptr->row_buf != NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 785 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 786 | 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] | 787 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 788 | png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 789 | (png_ptr->rowbytes + 1)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 790 | png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 791 | } |
| 792 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 793 | 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] | 794 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 795 | if (png_ptr->prev_row == NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 796 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 797 | png_warning(png_ptr, "Can't add Up filter after starting"); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 798 | png_ptr->do_filter &= ~PNG_FILTER_UP; |
| 799 | } |
| 800 | else |
| 801 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 802 | png_ptr->up_row = (png_bytep)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 803 | (png_ptr->rowbytes + 1)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 804 | png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 805 | } |
| 806 | } |
| 807 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 808 | 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] | 809 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 810 | if (png_ptr->prev_row == NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 811 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 812 | png_warning(png_ptr, "Can't add Average filter after starting"); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 813 | png_ptr->do_filter &= ~PNG_FILTER_AVG; |
| 814 | } |
| 815 | else |
| 816 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 817 | png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 818 | (png_ptr->rowbytes + 1)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 819 | png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 820 | } |
| 821 | } |
| 822 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 823 | if (png_ptr->do_filter & PNG_FILTER_PAETH && |
| 824 | png_ptr->paeth_row == NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 825 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 826 | if (png_ptr->prev_row == NULL) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 827 | { |
| 828 | png_warning(png_ptr, "Can't add Paeth filter after starting"); |
Glenn Randers-Pehrson | 860ab2b | 1999-10-14 07:43:10 -0500 | [diff] [blame] | 829 | png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 830 | } |
| 831 | else |
| 832 | { |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 833 | png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 834 | (png_ptr->rowbytes + 1)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 835 | png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 836 | } |
| 837 | } |
| 838 | |
| 839 | if (png_ptr->do_filter == PNG_NO_FILTERS) |
| 840 | png_ptr->do_filter = PNG_FILTER_NONE; |
| 841 | } |
| 842 | } |
| 843 | else |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 844 | png_error(png_ptr, "Unknown custom filter method"); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 845 | } |
| 846 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 847 | /* This allows us to influence the way in which libpng chooses the "best" |
| 848 | * filter for the current scanline. While the "minimum-sum-of-absolute- |
| 849 | * differences metric is relatively fast and effective, there is some |
| 850 | * question as to whether it can be improved upon by trying to keep the |
| 851 | * filtered data going to zlib more consistent, hopefully resulting in |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 852 | * better compression. |
| 853 | */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 854 | #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */ |
| 855 | void |
| 856 | png_set_filter_heuristics(png_structp png_ptr, int heuristic_method, |
| 857 | int num_weights, png_doublep filter_weights, |
| 858 | png_doublep filter_costs) |
| 859 | { |
| 860 | int i; |
| 861 | |
| 862 | png_debug(1, "in png_set_filter_heuristics\n"); |
| 863 | if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST) |
| 864 | { |
| 865 | png_warning(png_ptr, "Unknown filter heuristic method"); |
| 866 | return; |
| 867 | } |
| 868 | |
| 869 | if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT) |
| 870 | { |
| 871 | heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED; |
| 872 | } |
| 873 | |
| 874 | if (num_weights < 0 || filter_weights == NULL || |
| 875 | heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED) |
| 876 | { |
| 877 | num_weights = 0; |
| 878 | } |
| 879 | |
Glenn Randers-Pehrson | 860ab2b | 1999-10-14 07:43:10 -0500 | [diff] [blame] | 880 | png_ptr->num_prev_filters = (png_byte)num_weights; |
| 881 | png_ptr->heuristic_method = (png_byte)heuristic_method; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 882 | |
| 883 | if (num_weights > 0) |
| 884 | { |
| 885 | if (png_ptr->prev_filters == NULL) |
| 886 | { |
| 887 | png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 888 | (png_uint_32)(sizeof(png_byte) * num_weights)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 889 | |
| 890 | /* To make sure that the weighting starts out fairly */ |
| 891 | for (i = 0; i < num_weights; i++) |
| 892 | { |
| 893 | png_ptr->prev_filters[i] = 255; |
| 894 | } |
| 895 | } |
| 896 | |
| 897 | if (png_ptr->filter_weights == NULL) |
| 898 | { |
Glenn Randers-Pehrson | 983ec16 | 1998-03-07 11:24:03 -0600 | [diff] [blame] | 899 | png_ptr->filter_weights = (png_uint_16p) png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 900 | (png_uint_32)(sizeof(png_uint_16) * num_weights)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 901 | |
Glenn Randers-Pehrson | 983ec16 | 1998-03-07 11:24:03 -0600 | [diff] [blame] | 902 | 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] | 903 | (png_uint_32)(sizeof(png_uint_16) * num_weights)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 904 | |
| 905 | for (i = 0; i < num_weights; i++) |
| 906 | { |
| 907 | png_ptr->inv_filter_weights[i] = |
| 908 | png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR; |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | for (i = 0; i < num_weights; i++) |
| 913 | { |
| 914 | if (filter_weights[i] < 0.0) |
| 915 | { |
| 916 | png_ptr->inv_filter_weights[i] = |
| 917 | png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR; |
| 918 | } |
| 919 | else |
| 920 | { |
| 921 | png_ptr->inv_filter_weights[i] = |
| 922 | (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5); |
| 923 | png_ptr->filter_weights[i] = |
| 924 | (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5); |
| 925 | } |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | /* If, in the future, there are other filter methods, this would |
| 930 | * need to be based on png_ptr->filter. |
| 931 | */ |
| 932 | if (png_ptr->filter_costs == NULL) |
| 933 | { |
Glenn Randers-Pehrson | 983ec16 | 1998-03-07 11:24:03 -0600 | [diff] [blame] | 934 | png_ptr->filter_costs = (png_uint_16p) png_malloc(png_ptr, |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 935 | (png_uint_32)(sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 936 | |
Glenn Randers-Pehrson | 983ec16 | 1998-03-07 11:24:03 -0600 | [diff] [blame] | 937 | 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] | 938 | (png_uint_32)(sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST)); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 939 | |
| 940 | for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) |
| 941 | { |
| 942 | png_ptr->inv_filter_costs[i] = |
| 943 | png_ptr->filter_costs[i] = PNG_COST_FACTOR; |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | /* Here is where we set the relative costs of the different filters. We |
| 948 | * should take the desired compression level into account when setting |
| 949 | * the costs, so that Paeth, for instance, has a high relative cost at low |
| 950 | * compression levels, while it has a lower relative cost at higher |
| 951 | * compression settings. The filter types are in order of increasing |
| 952 | * relative cost, so it would be possible to do this with an algorithm. |
| 953 | */ |
| 954 | for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) |
| 955 | { |
| 956 | if (filter_costs == NULL || filter_costs[i] < 0.0) |
| 957 | { |
| 958 | png_ptr->inv_filter_costs[i] = |
| 959 | png_ptr->filter_costs[i] = PNG_COST_FACTOR; |
| 960 | } |
| 961 | else if (filter_costs[i] >= 1.0) |
| 962 | { |
| 963 | png_ptr->inv_filter_costs[i] = |
| 964 | (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5); |
| 965 | png_ptr->filter_costs[i] = |
| 966 | (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5); |
| 967 | } |
| 968 | } |
| 969 | } |
| 970 | #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */ |
| 971 | |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 972 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 973 | png_set_compression_level(png_structp png_ptr, int level) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 974 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 975 | png_debug(1, "in png_set_compression_level\n"); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 976 | png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 977 | png_ptr->zlib_level = level; |
| 978 | } |
| 979 | |
| 980 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 981 | png_set_compression_mem_level(png_structp png_ptr, int mem_level) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 982 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 983 | png_debug(1, "in png_set_compression_mem_level\n"); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 984 | png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 985 | png_ptr->zlib_mem_level = mem_level; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 989 | png_set_compression_strategy(png_structp png_ptr, int strategy) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 990 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 991 | png_debug(1, "in png_set_compression_strategy\n"); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 992 | png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 993 | png_ptr->zlib_strategy = strategy; |
| 994 | } |
| 995 | |
| 996 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 997 | png_set_compression_window_bits(png_structp png_ptr, int window_bits) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 998 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 999 | if (window_bits > 15) |
| 1000 | png_warning(png_ptr, "Only compression windows <= 32k supported by PNG"); |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 1001 | else if (window_bits < 8) |
| 1002 | png_warning(png_ptr, "Only compression windows >= 256 supported by PNG"); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1003 | png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1004 | png_ptr->zlib_window_bits = window_bits; |
| 1005 | } |
| 1006 | |
| 1007 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 1008 | png_set_compression_method(png_structp png_ptr, int method) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1009 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1010 | png_debug(1, "in png_set_compression_method\n"); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1011 | if (method != 8) |
| 1012 | png_warning(png_ptr, "Only compression method 8 is supported by PNG"); |
| 1013 | png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1014 | png_ptr->zlib_method = method; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1015 | } |
| 1016 | |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1017 | void |
| 1018 | png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn) |
| 1019 | { |
| 1020 | png_ptr->write_row_fn = write_row_fn; |
| 1021 | } |
| 1022 | |
| 1023 | #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) |
| 1024 | void |
| 1025 | png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr |
| 1026 | write_user_transform_fn) |
| 1027 | { |
| 1028 | png_debug(1, "in png_set_write_user_transform_fn\n"); |
| 1029 | png_ptr->transformations |= PNG_USER_TRANSFORM; |
| 1030 | png_ptr->write_user_transform_fn = write_user_transform_fn; |
| 1031 | } |
| 1032 | #endif |