Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1 | |
| 2 | /* pngwrite.c - general routines to write a png file |
| 3 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 4 | libpng 1.0 beta 3 - version 0.89 |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 5 | For conditions of distribution and use, see copyright notice in png.h |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 6 | Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 7 | May 25, 1996 |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | /* get internal access to png.h */ |
| 11 | #define PNG_INTERNAL |
| 12 | #include "png.h" |
| 13 | |
| 14 | /* Writes all the png information. This is the suggested way to use |
| 15 | the library. If you have a new chunk to add, make a function to |
| 16 | write it, and put it in the correct location here. If you want |
| 17 | the chunk written after the image data, put it in png_write_end(). |
| 18 | I strongly encurage you to supply a PNG_INFO_ flag, and check |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 19 | info->valid before writing the chunk, as that will keep the code |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 20 | from breaking if you want to just write a plain png file. |
| 21 | If you have long comments, I suggest writing them in png_write_end(), |
| 22 | and compressing them. */ |
| 23 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 24 | png_write_info(png_structp png_ptr, png_infop info) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 25 | { |
| 26 | png_write_sig(png_ptr); /* write PNG signature */ |
| 27 | /* write IHDR information. */ |
| 28 | png_write_IHDR(png_ptr, info->width, info->height, info->bit_depth, |
| 29 | info->color_type, info->compression_type, info->filter_type, |
| 30 | info->interlace_type); |
| 31 | /* the rest of these check to see if the valid field has the appropriate |
| 32 | flag set, and if it does, writes the chunk. */ |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 33 | #if defined(PNG_WRITE_gAMA_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 34 | if (info->valid & PNG_INFO_gAMA) |
| 35 | png_write_gAMA(png_ptr, info->gamma); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 36 | #endif |
| 37 | #if defined(PNG_WRITE_sBIT_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 38 | if (info->valid & PNG_INFO_sBIT) |
| 39 | png_write_sBIT(png_ptr, &(info->sig_bit), info->color_type); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 40 | #endif |
| 41 | #if defined(PNG_WRITE_cHRM_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 42 | if (info->valid & PNG_INFO_cHRM) |
| 43 | png_write_cHRM(png_ptr, |
| 44 | info->x_white, info->y_white, |
| 45 | info->x_red, info->y_red, |
| 46 | info->x_green, info->y_green, |
| 47 | info->x_blue, info->y_blue); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 48 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 49 | if (info->valid & PNG_INFO_PLTE) |
| 50 | png_write_PLTE(png_ptr, info->palette, info->num_palette); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 51 | else if (info->color_type == PNG_COLOR_TYPE_PALETTE) |
| 52 | png_error(png_ptr, "Valid palette required for paletted images\n"); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 53 | #if defined(PNG_WRITE_tRNS_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 54 | if (info->valid & PNG_INFO_tRNS) |
| 55 | png_write_tRNS(png_ptr, info->trans, &(info->trans_values), |
| 56 | info->num_trans, info->color_type); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 57 | #endif |
| 58 | #if defined(PNG_WRITE_bKGD_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 59 | if (info->valid & PNG_INFO_bKGD) |
| 60 | png_write_bKGD(png_ptr, &(info->background), info->color_type); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 61 | #endif |
| 62 | #if defined(PNG_WRITE_hIST_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 63 | if (info->valid & PNG_INFO_hIST) |
| 64 | png_write_hIST(png_ptr, info->hist, info->num_palette); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 65 | #endif |
| 66 | #if defined(PNG_WRITE_pHYs_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 67 | if (info->valid & PNG_INFO_pHYs) |
| 68 | png_write_pHYs(png_ptr, info->x_pixels_per_unit, |
| 69 | info->y_pixels_per_unit, info->phys_unit_type); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 70 | #endif |
| 71 | #if defined(PNG_WRITE_oFFs_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 72 | if (info->valid & PNG_INFO_oFFs) |
| 73 | png_write_oFFs(png_ptr, info->x_offset, info->y_offset, |
| 74 | info->offset_unit_type); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 75 | #endif |
| 76 | #if defined(PNG_WRITE_tIME_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 77 | if (info->valid & PNG_INFO_tIME) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 78 | { |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 79 | png_write_tIME(png_ptr, &(info->mod_time)); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 80 | png_ptr->flags |= PNG_FLAG_WROTE_tIME; |
| 81 | } |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 82 | #endif |
| 83 | #if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 84 | /* Check to see if we need to write text chunks */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 85 | if (info->num_text) |
| 86 | { |
| 87 | int i; /* local counter */ |
| 88 | |
| 89 | /* loop through the text chunks */ |
| 90 | for (i = 0; i < info->num_text; i++) |
| 91 | { |
| 92 | /* if chunk is compressed */ |
| 93 | if (info->text[i].compression >= 0) |
| 94 | { |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 95 | #if defined(PNG_WRITE_zTXt_SUPPORTED) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 96 | /* write compressed chunk */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 97 | png_write_zTXt(png_ptr, info->text[i].key, |
| 98 | info->text[i].text, info->text[i].text_length, |
| 99 | info->text[i].compression); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 100 | #else |
| 101 | png_warning(png_ptr, "Unable to write compressed text\n"); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 102 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 103 | } |
| 104 | else |
| 105 | { |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 106 | #if defined(PNG_WRITE_tEXt_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 107 | /* write uncompressed chunk */ |
| 108 | png_write_tEXt(png_ptr, info->text[i].key, |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 109 | info->text[i].text, info->text[i].text_length); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 110 | #else |
| 111 | png_warning(png_ptr, "Unable to write uncompressed text\n"); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 112 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 116 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /* writes the end of the png file. If you don't want to write comments or |
| 120 | time information, you can pass NULL for info. If you already wrote these |
| 121 | in png_write_info(), do not write them again here. If you have long |
| 122 | comments, I suggest writing them here, and compressing them. */ |
| 123 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 124 | png_write_end(png_structp png_ptr, png_infop info) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 125 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 126 | if (!(png_ptr->mode & PNG_HAVE_IDAT)) |
| 127 | png_error(png_ptr, "No IDATs written into file"); |
| 128 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 129 | /* see if user wants us to write information chunks */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 130 | if (info) |
| 131 | { |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 132 | #if defined(PNG_WRITE_tIME_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 133 | /* check to see if user has supplied a time chunk */ |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 134 | if (info->valid & PNG_INFO_tIME && |
| 135 | !(png_ptr->flags & PNG_FLAG_WROTE_tIME)) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 136 | png_write_tIME(png_ptr, &(info->mod_time)); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 137 | #endif |
| 138 | #if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 139 | /* check to see if we need to write comment chunks */ |
| 140 | if (info->num_text) |
| 141 | { |
| 142 | int i; /* local index variable */ |
| 143 | |
| 144 | /* loop through comment chunks */ |
| 145 | for (i = 0; i < info->num_text; i++) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 146 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 147 | #if defined(PNG_WRITE_zTXt_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 148 | /* check to see if comment is to be compressed */ |
| 149 | if (info->text[i].compression >= 0) |
| 150 | { |
| 151 | /* write compressed chunk */ |
| 152 | png_write_zTXt(png_ptr, info->text[i].key, |
| 153 | info->text[i].text, info->text[i].text_length, |
| 154 | info->text[i].compression); |
| 155 | } |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 156 | #if defined(PNG_WRITE_tEXt_SUPPORTED) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 157 | else |
| 158 | #endif |
| 159 | #endif |
| 160 | #if defined(PNG_WRITE_tEXt_SUPPORTED) |
| 161 | { |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 162 | /* write uncompressed chunk */ |
| 163 | png_write_tEXt(png_ptr, info->text[i].key, |
| 164 | info->text[i].text, info->text[i].text_length); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 165 | } |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 166 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 167 | } |
| 168 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 169 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 170 | } |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 171 | |
| 172 | png_ptr->mode |= PNG_AFTER_IDAT; |
| 173 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 174 | /* write end of png file */ |
| 175 | png_write_IEND(png_ptr); |
| 176 | } |
| 177 | |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 178 | #if defined(PNG_WRITE_tIME_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 179 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 180 | png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 181 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 182 | ptime->year = (png_uint_16)(1900 + ttime->tm_year); |
| 183 | ptime->month = (png_byte)(ttime->tm_mon + 1); |
| 184 | ptime->day = (png_byte)ttime->tm_mday; |
| 185 | ptime->hour = (png_byte)ttime->tm_hour; |
| 186 | ptime->minute = (png_byte)ttime->tm_min; |
| 187 | ptime->second = (png_byte)ttime->tm_sec; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 191 | png_convert_from_time_t(png_timep ptime, time_t ttime) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 192 | { |
| 193 | struct tm *tbuf; |
| 194 | |
| 195 | tbuf = gmtime(&ttime); |
| 196 | png_convert_from_struct_tm(ptime, tbuf); |
| 197 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 198 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 199 | |
| 200 | /* initialize png structure, and allocate any memory needed */ |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 201 | png_structp |
| 202 | png_create_write_struct(png_const_charp user_png_ver, voidp error_ptr, |
| 203 | png_error_ptr warn_fn, png_error_ptr error_fn) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 204 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 205 | png_structp png_ptr; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 206 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 207 | if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL) |
| 208 | { |
| 209 | return (png_structp)NULL; |
| 210 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 211 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 212 | if (setjmp(png_ptr->jmpbuf)) |
| 213 | { |
| 214 | png_large_free(png_ptr, png_ptr->zbuf); |
| 215 | png_free(png_ptr, png_ptr->zstream); |
| 216 | png_destroy_struct(png_ptr); |
| 217 | return (png_structp)NULL; |
| 218 | } |
| 219 | |
| 220 | png_set_error_fn(png_ptr, error_ptr, warn_fn, error_fn); |
| 221 | |
| 222 | if (user_png_ver == NULL || strcmp(user_png_ver, png_libpng_ver)) |
| 223 | { |
| 224 | if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0]) |
| 225 | { |
| 226 | png_error(png_ptr, "Incompatible libpng versions"); |
| 227 | } |
| 228 | else |
| 229 | { |
| 230 | png_warning(png_ptr, "Different libpng versions"); |
| 231 | } |
| 232 | } |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 233 | |
| 234 | /* initialize zbuf - compression buffer */ |
| 235 | png_ptr->zbuf_size = PNG_ZBUF_SIZE; |
| 236 | png_ptr->zbuf = png_large_malloc(png_ptr, png_ptr->zbuf_size); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 237 | |
| 238 | png_set_write_fn(png_ptr, NULL, NULL, NULL); |
| 239 | |
| 240 | png_ptr->do_free |= PNG_FREE_STRUCT; |
| 241 | |
| 242 | return (png_ptr); |
| 243 | } |
| 244 | |
| 245 | |
| 246 | /* initialize png structure, and allocate any memory needed */ |
| 247 | void |
| 248 | png_write_init(png_structp png_ptr) |
| 249 | { |
| 250 | jmp_buf tmp_jmp; /* to save current jump buffer */ |
| 251 | |
| 252 | /* save jump buffer and error functions */ |
| 253 | png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf)); |
| 254 | |
| 255 | /* reset all variables to 0 */ |
| 256 | png_memset(png_ptr, 0, sizeof (png_struct)); |
| 257 | |
| 258 | /* restore jump buffer */ |
| 259 | png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf)); |
| 260 | |
| 261 | /* initialize zbuf - compression buffer */ |
| 262 | png_ptr->zbuf_size = PNG_ZBUF_SIZE; |
| 263 | png_ptr->zbuf = png_large_malloc(png_ptr, png_ptr->zbuf_size); |
| 264 | png_set_write_fn(png_ptr, NULL, NULL, NULL); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /* write a few rows of image data. If the image is interlaced, |
| 268 | either you will have to write the 7 sub images, or, if you |
| 269 | have called png_set_interlace_handling(), you will have to |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 270 | "write" the image seven times */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 271 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 272 | png_write_rows(png_structp png_ptr, png_bytepp row, |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 273 | png_uint_32 num_rows) |
| 274 | { |
| 275 | png_uint_32 i; /* row counter */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 276 | png_bytepp rp; /* row pointer */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 277 | |
| 278 | /* loop through the rows */ |
| 279 | for (i = 0, rp = row; i < num_rows; i++, rp++) |
| 280 | { |
| 281 | png_write_row(png_ptr, *rp); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | /* write the image. You only need to call this function once, even |
| 286 | if you are writing an interlaced image. */ |
| 287 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 288 | png_write_image(png_structp png_ptr, png_bytepp image) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 289 | { |
| 290 | png_uint_32 i; /* row index */ |
| 291 | int pass, num_pass; /* pass variables */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 292 | png_bytepp rp; /* points to current row */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 293 | |
| 294 | /* intialize interlace handling. If image is not interlaced, |
| 295 | this will set pass to 1 */ |
| 296 | num_pass = png_set_interlace_handling(png_ptr); |
| 297 | /* loop through passes */ |
| 298 | for (pass = 0; pass < num_pass; pass++) |
| 299 | { |
| 300 | /* loop through image */ |
| 301 | for (i = 0, rp = image; i < png_ptr->height; i++, rp++) |
| 302 | { |
| 303 | png_write_row(png_ptr, *rp); |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 308 | /* called by user to write a row of image data */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 309 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 310 | png_write_row(png_structp png_ptr, png_bytep row) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 311 | { |
| 312 | /* initialize transformations and other stuff if first time */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 313 | if (png_ptr->row_number == 0 && png_ptr->pass == 0) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 314 | { |
| 315 | png_write_start_row(png_ptr); |
| 316 | } |
| 317 | |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 318 | #if defined(PNG_WRITE_INTERLACING_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 319 | /* if interlaced and not interested in row, return */ |
| 320 | if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) |
| 321 | { |
| 322 | switch (png_ptr->pass) |
| 323 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 324 | case 0: |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 325 | if (png_ptr->row_number & 7) |
| 326 | { |
| 327 | png_write_finish_row(png_ptr); |
| 328 | return; |
| 329 | } |
| 330 | break; |
| 331 | case 1: |
| 332 | if ((png_ptr->row_number & 7) || png_ptr->width < 5) |
| 333 | { |
| 334 | png_write_finish_row(png_ptr); |
| 335 | return; |
| 336 | } |
| 337 | break; |
| 338 | case 2: |
| 339 | if ((png_ptr->row_number & 7) != 4) |
| 340 | { |
| 341 | png_write_finish_row(png_ptr); |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 342 | return; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 343 | } |
| 344 | break; |
| 345 | case 3: |
| 346 | if ((png_ptr->row_number & 3) || png_ptr->width < 3) |
| 347 | { |
| 348 | png_write_finish_row(png_ptr); |
| 349 | return; |
| 350 | } |
| 351 | break; |
| 352 | case 4: |
| 353 | if ((png_ptr->row_number & 3) != 2) |
| 354 | { |
| 355 | png_write_finish_row(png_ptr); |
| 356 | return; |
| 357 | } |
| 358 | break; |
| 359 | case 5: |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 360 | if ((png_ptr->row_number & 1) || png_ptr->width < 2) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 361 | { |
| 362 | png_write_finish_row(png_ptr); |
| 363 | return; |
| 364 | } |
| 365 | break; |
| 366 | case 6: |
| 367 | if (!(png_ptr->row_number & 1)) |
| 368 | { |
| 369 | png_write_finish_row(png_ptr); |
| 370 | return; |
| 371 | } |
| 372 | break; |
| 373 | } |
| 374 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 375 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 376 | |
| 377 | /* set up row info for transformations */ |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 378 | png_ptr->row_info.color_type = png_ptr->color_type; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 379 | png_ptr->row_info.width = png_ptr->usr_width; |
| 380 | png_ptr->row_info.channels = png_ptr->usr_channels; |
| 381 | png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 382 | png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth * |
| 383 | png_ptr->row_info.channels); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 384 | png_ptr->row_info.rowbytes = ((png_ptr->row_info.width * |
| 385 | (png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3); |
| 386 | |
| 387 | /* copy users row into buffer, leaving room for filter byte */ |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 388 | png_memcpy(png_ptr->row_buf + 1, row, (png_size_t)png_ptr->row_info.rowbytes); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 389 | |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 390 | #if defined(PNG_WRITE_INTERLACING_SUPPORTED) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 391 | /* handle interlacing */ |
| 392 | if (png_ptr->interlaced && png_ptr->pass < 6 && |
| 393 | (png_ptr->transformations & PNG_INTERLACE)) |
| 394 | { |
| 395 | png_do_write_interlace(&(png_ptr->row_info), |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 396 | png_ptr->row_buf + 1, png_ptr->pass); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 397 | /* this should always get caught above, but still ... */ |
| 398 | if (!(png_ptr->row_info.width)) |
| 399 | { |
| 400 | png_write_finish_row(png_ptr); |
| 401 | return; |
| 402 | } |
| 403 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 404 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 405 | |
| 406 | /* handle other transformations */ |
| 407 | if (png_ptr->transformations) |
| 408 | png_do_write_transformations(png_ptr); |
| 409 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 410 | /* find a filter if necessary, filter the row and write it out */ |
| 411 | png_write_find_filter(png_ptr, &(png_ptr->row_info)); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 412 | } |
| 413 | |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 414 | #if defined(PNG_WRITE_FLUSH_SUPPORTED) |
| 415 | /* Set the automatic flush interval or 0 to turn flushing off */ |
| 416 | void |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 417 | png_set_flush(png_structp png_ptr, int nrows) |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 418 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 419 | png_ptr->flush_dist = (nrows < 0 ? 0 : nrows); |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /* flush the current output buffers now */ |
| 423 | void |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 424 | png_write_flush(png_structp png_ptr) |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 425 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 426 | int wrote_IDAT; |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 427 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 428 | /* We have already written out all of the data */ |
| 429 | if (png_ptr->row_number >= png_ptr->num_rows) |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 430 | return; |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 431 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 432 | do |
| 433 | { |
| 434 | int ret; |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 435 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 436 | /* compress the data */ |
| 437 | ret = deflate(png_ptr->zstream, Z_SYNC_FLUSH); |
| 438 | wrote_IDAT = 0; |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 439 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 440 | /* check for compression errors */ |
| 441 | if (ret != Z_OK) |
| 442 | { |
| 443 | if (png_ptr->zstream->msg) |
| 444 | png_error(png_ptr, png_ptr->zstream->msg); |
| 445 | else |
| 446 | png_error(png_ptr, "zlib error"); |
| 447 | } |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 448 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 449 | if (!png_ptr->zstream->avail_out) |
| 450 | { |
| 451 | /* write the IDAT and reset the zlib output buffer */ |
| 452 | png_write_IDAT(png_ptr, png_ptr->zbuf, |
| 453 | png_ptr->zbuf_size); |
| 454 | png_ptr->zstream->next_out = png_ptr->zbuf; |
| 455 | png_ptr->zstream->avail_out = (uInt)png_ptr->zbuf_size; |
| 456 | wrote_IDAT = 1; |
| 457 | } |
| 458 | } while(wrote_IDAT == 1); |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 459 | |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 460 | /* If there is any data left to be output, write it into a new IDAT */ |
| 461 | if (png_ptr->zbuf_size != png_ptr->zstream->avail_out) |
| 462 | { |
| 463 | /* write the IDAT and reset the zlib output buffer */ |
| 464 | png_write_IDAT(png_ptr, png_ptr->zbuf, |
| 465 | png_ptr->zbuf_size - png_ptr->zstream->avail_out); |
| 466 | png_ptr->zstream->next_out = png_ptr->zbuf; |
| 467 | png_ptr->zstream->avail_out = (uInt)png_ptr->zbuf_size; |
| 468 | } |
| 469 | png_ptr->flush_rows = 0; |
| 470 | png_flush(png_ptr); |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 471 | } |
| 472 | #endif /* PNG_WRITE_FLUSH_SUPPORTED */ |
| 473 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 474 | /* free all memory used by the write */ |
| 475 | void |
| 476 | png_destroy_write_struct(png_structpp png_ptr, png_infopp info_ptr) |
| 477 | { |
| 478 | if (info_ptr && *info_ptr) |
| 479 | { |
| 480 | png_destroy_struct((voidp)*info_ptr); |
| 481 | *info_ptr = (png_infop)NULL; |
| 482 | } |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 483 | |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 484 | if (png_ptr && *png_ptr) |
| 485 | { |
| 486 | png_write_destroy(*png_ptr); |
| 487 | png_destroy_struct((voidp)*png_ptr); |
| 488 | *png_ptr = (png_structp)NULL; |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | |
| 493 | /* free any memory used in png struct (old) */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 494 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 495 | png_write_destroy(png_structp png_ptr) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 496 | { |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 497 | jmp_buf tmp_jmp; /* save jump buffer */ |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 498 | png_error_ptr error_fn; |
| 499 | png_error_ptr warning_fn; |
| 500 | png_voidp error_ptr; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 501 | |
| 502 | /* free any memory zlib uses */ |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 503 | deflateEnd(png_ptr->zstream); |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 504 | png_free(png_ptr, png_ptr->zstream); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 505 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 506 | /* free our memory. png_free checks NULL for us. */ |
| 507 | png_large_free(png_ptr, png_ptr->zbuf); |
| 508 | png_large_free(png_ptr, png_ptr->row_buf); |
| 509 | png_large_free(png_ptr, png_ptr->prev_row); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 510 | png_large_free(png_ptr, png_ptr->sub_row); |
| 511 | png_large_free(png_ptr, png_ptr->up_row); |
| 512 | png_large_free(png_ptr, png_ptr->avg_row); |
| 513 | png_large_free(png_ptr, png_ptr->paeth_row); |
| 514 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 515 | /* reset structure */ |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 516 | png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf)); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 517 | |
| 518 | error_fn = png_ptr->error_fn; |
| 519 | warning_fn = png_ptr->warning_fn; |
| 520 | error_ptr = png_ptr->error_ptr; |
| 521 | |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 522 | png_memset(png_ptr, 0, sizeof (png_struct)); |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 523 | |
| 524 | png_ptr->error_fn = error_fn; |
| 525 | png_ptr->warning_fn = warning_fn; |
| 526 | png_ptr->error_ptr = error_ptr; |
| 527 | |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 528 | png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf)); |
| 529 | } |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 530 | |
| 531 | /* Allow the application to select one or more filters to use */ |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 532 | void |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 533 | png_set_filter(png_structp png_ptr, int method, int filters) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 534 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 535 | /* We allow 'method' only for future expansion of the base filter method */ |
| 536 | if (method == 0) |
| 537 | { |
| 538 | switch (filters & (PNG_ALL_FILTERS | 0x07)) |
| 539 | { |
| 540 | case 5: |
| 541 | case 6: |
| 542 | case 7: png_warning(png_ptr, "Unknown custom row filter for method 0"); |
| 543 | case 0: png_ptr->do_filter = PNG_FILTER_NONE; break; |
| 544 | case 1: png_ptr->do_filter = PNG_FILTER_SUB; break; |
| 545 | case 2: png_ptr->do_filter = PNG_FILTER_UP; break; |
| 546 | case 3: png_ptr->do_filter = PNG_FILTER_AVG; break; |
| 547 | case 4: png_ptr->do_filter = PNG_FILTER_PAETH; break; |
| 548 | default: png_ptr->do_filter = (png_byte)filters; break; |
| 549 | } |
| 550 | |
| 551 | /* If we have allocated the row_buf, then we should have also allocated |
| 552 | * all of the filter buffers that have been selected. |
| 553 | */ |
| 554 | if (png_ptr->row_buf) |
| 555 | { |
| 556 | if (png_ptr->do_filter & PNG_FILTER_SUB && !(png_ptr->sub_row)) |
| 557 | { |
| 558 | png_ptr->sub_row = (png_bytep )png_large_malloc(png_ptr, |
| 559 | png_ptr->rowbytes + 1); |
| 560 | png_ptr->sub_row[0] = 1; /* Set the row filter type */ |
| 561 | } |
| 562 | |
| 563 | if (png_ptr->do_filter & PNG_FILTER_UP && !(png_ptr->up_row)) |
| 564 | { |
| 565 | if (!(png_ptr->prev_row)) |
| 566 | { |
| 567 | png_warning(png_ptr, "Can't to add up filter after starting"); |
| 568 | png_ptr->do_filter &= ~PNG_FILTER_UP; |
| 569 | } |
| 570 | else |
| 571 | { |
| 572 | png_ptr->up_row = (png_bytep )png_large_malloc(png_ptr, |
| 573 | png_ptr->rowbytes + 1); |
| 574 | png_ptr->up_row[0] = 2; /* Set the row filter type */ |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | if (png_ptr->do_filter & PNG_FILTER_AVG && !(png_ptr->avg_row)) |
| 579 | { |
| 580 | if (!(png_ptr->prev_row)) |
| 581 | { |
| 582 | png_warning(png_ptr, "Can't add average filter after starting"); |
| 583 | png_ptr->do_filter &= ~PNG_FILTER_AVG; |
| 584 | } |
| 585 | else |
| 586 | { |
| 587 | png_ptr->up_row = (png_bytep )png_large_malloc(png_ptr, |
| 588 | png_ptr->rowbytes + 1); |
| 589 | png_ptr->up_row[0] = 3; /* Set the row filter type */ |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | if (png_ptr->do_filter & PNG_FILTER_PAETH && !(png_ptr->paeth_row)) |
| 594 | { |
| 595 | if (!(png_ptr->prev_row)) |
| 596 | { |
| 597 | png_warning(png_ptr, "Can't add Paeth filter after starting"); |
| 598 | png_ptr->do_filter &= ~PNG_FILTER_PAETH; |
| 599 | } |
| 600 | else |
| 601 | { |
| 602 | png_ptr->paeth_row = (png_bytep )png_large_malloc(png_ptr, |
| 603 | png_ptr->rowbytes + 1); |
| 604 | png_ptr->paeth_row[0] = 4; /* Set the row filter type */ |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | if (png_ptr->do_filter == PNG_NO_FILTERS) |
| 609 | png_ptr->do_filter = PNG_FILTER_NONE; |
| 610 | } |
| 611 | } |
| 612 | else |
| 613 | png_error(png_ptr, "Unknown custom filter method"); |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 617 | png_set_compression_level(png_structp png_ptr, int level) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 618 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 619 | png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 620 | png_ptr->zlib_level = level; |
| 621 | } |
| 622 | |
| 623 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 624 | png_set_compression_mem_level(png_structp png_ptr, int mem_level) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 625 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 626 | png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL; |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 627 | png_ptr->zlib_mem_level = mem_level; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 631 | png_set_compression_strategy(png_structp png_ptr, int strategy) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 632 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 633 | png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 634 | png_ptr->zlib_strategy = strategy; |
| 635 | } |
| 636 | |
| 637 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 638 | png_set_compression_window_bits(png_structp png_ptr, int window_bits) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 639 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 640 | if (window_bits > 15) |
| 641 | png_warning(png_ptr, "Only compression windows <= 32k supported by PNG"); |
| 642 | png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 643 | png_ptr->zlib_window_bits = window_bits; |
| 644 | } |
| 645 | |
| 646 | void |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 647 | png_set_compression_method(png_structp png_ptr, int method) |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 648 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 649 | if (method != 8) |
| 650 | png_warning(png_ptr, "Only compression method 8 is supported by PNG"); |
| 651 | png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD; |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 652 | png_ptr->zlib_method = method; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 653 | } |
| 654 | |