| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
#define PNG_INTERNAL |
| 13 |
#include "png.h" |
| 14 |
#ifdef PNG_WRITE_SUPPORTED |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
void PNGAPI |
| 26 |
png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr) |
| 27 |
{ |
| 28 |
png_debug(1, "in png_write_info_before_PLTE\n"); |
| 29 |
if (png_ptr == NULL || info_ptr == NULL) |
| 30 |
return; |
| 31 |
if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) |
| 32 |
{ |
| 33 |
png_write_sig(png_ptr); |
| 34 |
#if defined(PNG_MNG_FEATURES_SUPPORTED) |
| 35 |
if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted)) |
| 36 |
{ |
| 37 |
png_warning(png_ptr,"MNG features are not allowed in a PNG datastream"); |
| 38 |
png_ptr->mng_features_permitted=0; |
| 39 |
} |
| 40 |
#endif |
| 41 |
|
| 42 |
png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height, |
| 43 |
info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type, |
| 44 |
info_ptr->filter_type, |
| 45 |
#if defined(PNG_WRITE_INTERLACING_SUPPORTED) |
| 46 |
info_ptr->interlace_type); |
| 47 |
#else |
| 48 |
0); |
| 49 |
#endif |
| 50 |
|
| 51 |
|
| 52 |
#if defined(PNG_WRITE_gAMA_SUPPORTED) |
| 53 |
if (info_ptr->valid & PNG_INFO_gAMA) |
| 54 |
{ |
| 55 |
# ifdef PNG_FLOATING_POINT_SUPPORTED |
| 56 |
png_write_gAMA(png_ptr, info_ptr->gamma); |
| 57 |
#else |
| 58 |
#ifdef PNG_FIXED_POINT_SUPPORTED |
| 59 |
png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma); |
| 60 |
# endif |
| 61 |
#endif |
| 62 |
} |
| 63 |
#endif |
| 64 |
#if defined(PNG_WRITE_sRGB_SUPPORTED) |
| 65 |
if (info_ptr->valid & PNG_INFO_sRGB) |
| 66 |
png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent); |
| 67 |
#endif |
| 68 |
#if defined(PNG_WRITE_iCCP_SUPPORTED) |
| 69 |
if (info_ptr->valid & PNG_INFO_iCCP) |
| 70 |
png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE, |
| 71 |
info_ptr->iccp_profile, (int)info_ptr->iccp_proflen); |
| 72 |
#endif |
| 73 |
#if defined(PNG_WRITE_sBIT_SUPPORTED) |
| 74 |
if (info_ptr->valid & PNG_INFO_sBIT) |
| 75 |
png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type); |
| 76 |
#endif |
| 77 |
#if defined(PNG_WRITE_cHRM_SUPPORTED) |
| 78 |
if (info_ptr->valid & PNG_INFO_cHRM) |
| 79 |
{ |
| 80 |
#ifdef PNG_FLOATING_POINT_SUPPORTED |
| 81 |
png_write_cHRM(png_ptr, |
| 82 |
info_ptr->x_white, info_ptr->y_white, |
| 83 |
info_ptr->x_red, info_ptr->y_red, |
| 84 |
info_ptr->x_green, info_ptr->y_green, |
| 85 |
info_ptr->x_blue, info_ptr->y_blue); |
| 86 |
#else |
| 87 |
# ifdef PNG_FIXED_POINT_SUPPORTED |
| 88 |
png_write_cHRM_fixed(png_ptr, |
| 89 |
info_ptr->int_x_white, info_ptr->int_y_white, |
| 90 |
info_ptr->int_x_red, info_ptr->int_y_red, |
| 91 |
info_ptr->int_x_green, info_ptr->int_y_green, |
| 92 |
info_ptr->int_x_blue, info_ptr->int_y_blue); |
| 93 |
# endif |
| 94 |
#endif |
| 95 |
} |
| 96 |
#endif |
| 97 |
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) |
| 98 |
if (info_ptr->unknown_chunks_num) |
| 99 |
{ |
| 100 |
png_unknown_chunk *up; |
| 101 |
|
| 102 |
png_debug(5, "writing extra chunks\n"); |
| 103 |
|
| 104 |
for (up = info_ptr->unknown_chunks; |
| 105 |
up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; |
| 106 |
up++) |
| 107 |
{ |
| 108 |
int keep=png_handle_as_unknown(png_ptr, up->name); |
| 109 |
if (keep != PNG_HANDLE_CHUNK_NEVER && |
| 110 |
up->location && !(up->location & PNG_HAVE_PLTE) && |
| 111 |
!(up->location & PNG_HAVE_IDAT) && |
| 112 |
((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || |
| 113 |
(png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) |
| 114 |
{ |
| 115 |
png_write_chunk(png_ptr, up->name, up->data, up->size); |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
#endif |
| 120 |
png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE; |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
void PNGAPI |
| 125 |
png_write_info(png_structp png_ptr, png_infop info_ptr) |
| 126 |
{ |
| 127 |
#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) |
| 128 |
int i; |
| 129 |
#endif |
| 130 |
|
| 131 |
png_debug(1, "in png_write_info\n"); |
| 132 |
|
| 133 |
if (png_ptr == NULL || info_ptr == NULL) |
| 134 |
return; |
| 135 |
|
| 136 |
png_write_info_before_PLTE(png_ptr, info_ptr); |
| 137 |
|
| 138 |
if (info_ptr->valid & PNG_INFO_PLTE) |
| 139 |
png_write_PLTE(png_ptr, info_ptr->palette, |
| 140 |
(png_uint_32)info_ptr->num_palette); |
| 141 |
else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
| 142 |
png_error(png_ptr, "Valid palette required for paletted images"); |
| 143 |
|
| 144 |
#if defined(PNG_WRITE_tRNS_SUPPORTED) |
| 145 |
if (info_ptr->valid & PNG_INFO_tRNS) |
| 146 |
{ |
| 147 |
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) |
| 148 |
|
| 149 |
if ((png_ptr->transformations & PNG_INVERT_ALPHA) && |
| 150 |
info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
| 151 |
{ |
| 152 |
int j; |
| 153 |
for (j=0; j<(int)info_ptr->num_trans; j++) |
| 154 |
info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]); |
| 155 |
} |
| 156 |
#endif |
| 157 |
png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values), |
| 158 |
info_ptr->num_trans, info_ptr->color_type); |
| 159 |
} |
| 160 |
#endif |
| 161 |
#if defined(PNG_WRITE_bKGD_SUPPORTED) |
| 162 |
if (info_ptr->valid & PNG_INFO_bKGD) |
| 163 |
png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type); |
| 164 |
#endif |
| 165 |
#if defined(PNG_WRITE_hIST_SUPPORTED) |
| 166 |
if (info_ptr->valid & PNG_INFO_hIST) |
| 167 |
png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette); |
| 168 |
#endif |
| 169 |
#if defined(PNG_WRITE_oFFs_SUPPORTED) |
| 170 |
if (info_ptr->valid & PNG_INFO_oFFs) |
| 171 |
png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset, |
| 172 |
info_ptr->offset_unit_type); |
| 173 |
#endif |
| 174 |
#if defined(PNG_WRITE_pCAL_SUPPORTED) |
| 175 |
if (info_ptr->valid & PNG_INFO_pCAL) |
| 176 |
png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0, |
| 177 |
info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams, |
| 178 |
info_ptr->pcal_units, info_ptr->pcal_params); |
| 179 |
#endif |
| 180 |
#if defined(PNG_WRITE_sCAL_SUPPORTED) |
| 181 |
if (info_ptr->valid & PNG_INFO_sCAL) |
| 182 |
#if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO) |
| 183 |
png_write_sCAL(png_ptr, (int)info_ptr->scal_unit, |
| 184 |
info_ptr->scal_pixel_width, info_ptr->scal_pixel_height); |
| 185 |
#else |
| 186 |
#ifdef PNG_FIXED_POINT_SUPPORTED |
| 187 |
png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit, |
| 188 |
info_ptr->scal_s_width, info_ptr->scal_s_height); |
| 189 |
#else |
| 190 |
png_warning(png_ptr, |
| 191 |
"png_write_sCAL not supported; sCAL chunk not written."); |
| 192 |
#endif |
| 193 |
#endif |
| 194 |
#endif |
| 195 |
#if defined(PNG_WRITE_pHYs_SUPPORTED) |
| 196 |
if (info_ptr->valid & PNG_INFO_pHYs) |
| 197 |
png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit, |
| 198 |
info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type); |
| 199 |
#endif |
| 200 |
#if defined(PNG_WRITE_tIME_SUPPORTED) |
| 201 |
if (info_ptr->valid & PNG_INFO_tIME) |
| 202 |
{ |
| 203 |
png_write_tIME(png_ptr, &(info_ptr->mod_time)); |
| 204 |
png_ptr->mode |= PNG_WROTE_tIME; |
| 205 |
} |
| 206 |
#endif |
| 207 |
#if defined(PNG_WRITE_sPLT_SUPPORTED) |
| 208 |
if (info_ptr->valid & PNG_INFO_sPLT) |
| 209 |
for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) |
| 210 |
png_write_sPLT(png_ptr, info_ptr->splt_palettes + i); |
| 211 |
#endif |
| 212 |
#if defined(PNG_WRITE_TEXT_SUPPORTED) |
| 213 |
|
| 214 |
for (i = 0; i < info_ptr->num_text; i++) |
| 215 |
{ |
| 216 |
png_debug2(2, "Writing header text chunk %d, type %d\n", i, |
| 217 |
info_ptr->text[i].compression); |
| 218 |
|
| 219 |
if (info_ptr->text[i].compression > 0) |
| 220 |
{ |
| 221 |
#if defined(PNG_WRITE_iTXt_SUPPORTED) |
| 222 |
|
| 223 |
png_write_iTXt(png_ptr, |
| 224 |
info_ptr->text[i].compression, |
| 225 |
info_ptr->text[i].key, |
| 226 |
info_ptr->text[i].lang, |
| 227 |
info_ptr->text[i].lang_key, |
| 228 |
info_ptr->text[i].text); |
| 229 |
#else |
| 230 |
png_warning(png_ptr, "Unable to write international text"); |
| 231 |
#endif |
| 232 |
|
| 233 |
info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; |
| 234 |
} |
| 235 |
|
| 236 |
else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt) |
| 237 |
{ |
| 238 |
#if defined(PNG_WRITE_zTXt_SUPPORTED) |
| 239 |
|
| 240 |
png_write_zTXt(png_ptr, info_ptr->text[i].key, |
| 241 |
info_ptr->text[i].text, 0, |
| 242 |
info_ptr->text[i].compression); |
| 243 |
#else |
| 244 |
png_warning(png_ptr, "Unable to write compressed text"); |
| 245 |
#endif |
| 246 |
|
| 247 |
info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; |
| 248 |
} |
| 249 |
else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) |
| 250 |
{ |
| 251 |
#if defined(PNG_WRITE_tEXt_SUPPORTED) |
| 252 |
|
| 253 |
png_write_tEXt(png_ptr, info_ptr->text[i].key, |
| 254 |
info_ptr->text[i].text, |
| 255 |
0); |
| 256 |
#else |
| 257 |
png_warning(png_ptr, "Unable to write uncompressed text"); |
| 258 |
#endif |
| 259 |
|
| 260 |
info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; |
| 261 |
} |
| 262 |
} |
| 263 |
#endif |
| 264 |
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) |
| 265 |
if (info_ptr->unknown_chunks_num) |
| 266 |
{ |
| 267 |
png_unknown_chunk *up; |
| 268 |
|
| 269 |
png_debug(5, "writing extra chunks\n"); |
| 270 |
|
| 271 |
for (up = info_ptr->unknown_chunks; |
| 272 |
up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; |
| 273 |
up++) |
| 274 |
{ |
| 275 |
int keep=png_handle_as_unknown(png_ptr, up->name); |
| 276 |
if (keep != PNG_HANDLE_CHUNK_NEVER && |
| 277 |
up->location && (up->location & PNG_HAVE_PLTE) && |
| 278 |
!(up->location & PNG_HAVE_IDAT) && |
| 279 |
((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || |
| 280 |
(png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) |
| 281 |
{ |
| 282 |
png_write_chunk(png_ptr, up->name, up->data, up->size); |
| 283 |
} |
| 284 |
} |
| 285 |
} |
| 286 |
#endif |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
void PNGAPI |
| 295 |
png_write_end(png_structp png_ptr, png_infop info_ptr) |
| 296 |
{ |
| 297 |
png_debug(1, "in png_write_end\n"); |
| 298 |
if (png_ptr == NULL) |
| 299 |
return; |
| 300 |
if (!(png_ptr->mode & PNG_HAVE_IDAT)) |
| 301 |
png_error(png_ptr, "No IDATs written into file"); |
| 302 |
|
| 303 |
|
| 304 |
if (info_ptr != NULL) |
| 305 |
{ |
| 306 |
#if defined(PNG_WRITE_TEXT_SUPPORTED) |
| 307 |
int i; |
| 308 |
#endif |
| 309 |
#if defined(PNG_WRITE_tIME_SUPPORTED) |
| 310 |
|
| 311 |
if ((info_ptr->valid & PNG_INFO_tIME) && |
| 312 |
!(png_ptr->mode & PNG_WROTE_tIME)) |
| 313 |
png_write_tIME(png_ptr, &(info_ptr->mod_time)); |
| 314 |
#endif |
| 315 |
#if defined(PNG_WRITE_TEXT_SUPPORTED) |
| 316 |
|
| 317 |
for (i = 0; i < info_ptr->num_text; i++) |
| 318 |
{ |
| 319 |
png_debug2(2, "Writing trailer text chunk %d, type %d\n", i, |
| 320 |
info_ptr->text[i].compression); |
| 321 |
|
| 322 |
if (info_ptr->text[i].compression > 0) |
| 323 |
{ |
| 324 |
#if defined(PNG_WRITE_iTXt_SUPPORTED) |
| 325 |
|
| 326 |
png_write_iTXt(png_ptr, |
| 327 |
info_ptr->text[i].compression, |
| 328 |
info_ptr->text[i].key, |
| 329 |
info_ptr->text[i].lang, |
| 330 |
info_ptr->text[i].lang_key, |
| 331 |
info_ptr->text[i].text); |
| 332 |
#else |
| 333 |
png_warning(png_ptr, "Unable to write international text"); |
| 334 |
#endif |
| 335 |
|
| 336 |
info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; |
| 337 |
} |
| 338 |
else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt) |
| 339 |
{ |
| 340 |
#if defined(PNG_WRITE_zTXt_SUPPORTED) |
| 341 |
|
| 342 |
png_write_zTXt(png_ptr, info_ptr->text[i].key, |
| 343 |
info_ptr->text[i].text, 0, |
| 344 |
info_ptr->text[i].compression); |
| 345 |
#else |
| 346 |
png_warning(png_ptr, "Unable to write compressed text"); |
| 347 |
#endif |
| 348 |
|
| 349 |
info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; |
| 350 |
} |
| 351 |
else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) |
| 352 |
{ |
| 353 |
#if defined(PNG_WRITE_tEXt_SUPPORTED) |
| 354 |
|
| 355 |
png_write_tEXt(png_ptr, info_ptr->text[i].key, |
| 356 |
info_ptr->text[i].text, 0); |
| 357 |
#else |
| 358 |
png_warning(png_ptr, "Unable to write uncompressed text"); |
| 359 |
#endif |
| 360 |
|
| 361 |
|
| 362 |
info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; |
| 363 |
} |
| 364 |
} |
| 365 |
#endif |
| 366 |
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) |
| 367 |
if (info_ptr->unknown_chunks_num) |
| 368 |
{ |
| 369 |
png_unknown_chunk *up; |
| 370 |
|
| 371 |
png_debug(5, "writing extra chunks\n"); |
| 372 |
|
| 373 |
for (up = info_ptr->unknown_chunks; |
| 374 |
up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; |
| 375 |
up++) |
| 376 |
{ |
| 377 |
int keep=png_handle_as_unknown(png_ptr, up->name); |
| 378 |
if (keep != PNG_HANDLE_CHUNK_NEVER && |
| 379 |
up->location && (up->location & PNG_AFTER_IDAT) && |
| 380 |
((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || |
| 381 |
(png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) |
| 382 |
{ |
| 383 |
png_write_chunk(png_ptr, up->name, up->data, up->size); |
| 384 |
} |
| 385 |
} |
| 386 |
} |
| 387 |
#endif |
| 388 |
} |
| 389 |
|
| 390 |
png_ptr->mode |= PNG_AFTER_IDAT; |
| 391 |
|
| 392 |
|
| 393 |
png_write_IEND(png_ptr); |
| 394 |
#if 0 |
| 395 |
|
| 396 |
|
| 397 |
png_flush(png_ptr); |
| 398 |
#endif |
| 399 |
} |
| 400 |
|
| 401 |
#if defined(PNG_WRITE_tIME_SUPPORTED) |
| 402 |
#if !defined(_WIN32_WCE) |
| 403 |
|
| 404 |
void PNGAPI |
| 405 |
png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime) |
| 406 |
{ |
| 407 |
png_debug(1, "in png_convert_from_struct_tm\n"); |
| 408 |
ptime->year = (png_uint_16)(1900 + ttime->tm_year); |
| 409 |
ptime->month = (png_byte)(ttime->tm_mon + 1); |
| 410 |
ptime->day = (png_byte)ttime->tm_mday; |
| 411 |
ptime->hour = (png_byte)ttime->tm_hour; |
| 412 |
ptime->minute = (png_byte)ttime->tm_min; |
| 413 |
ptime->second = (png_byte)ttime->tm_sec; |
| 414 |
} |
| 415 |
|
| 416 |
void PNGAPI |
| 417 |
png_convert_from_time_t(png_timep ptime, time_t ttime) |
| 418 |
{ |
| 419 |
struct tm *tbuf; |
| 420 |
|
| 421 |
png_debug(1, "in png_convert_from_time_t\n"); |
| 422 |
tbuf = gmtime(&ttime); |
| 423 |
png_convert_from_struct_tm(ptime, tbuf); |
| 424 |
} |
| 425 |
#endif |
| 426 |
#endif |
| 427 |
|
| 428 |
|
| 429 |
png_structp PNGAPI |
| 430 |
png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr, |
| 431 |
png_error_ptr error_fn, png_error_ptr warn_fn) |
| 432 |
{ |
| 433 |
#ifdef PNG_USER_MEM_SUPPORTED |
| 434 |
return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn, |
| 435 |
warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL)); |
| 436 |
} |
| 437 |
|
| 438 |
|
| 439 |
png_structp PNGAPI |
| 440 |
png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, |
| 441 |
png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, |
| 442 |
png_malloc_ptr malloc_fn, png_free_ptr free_fn) |
| 443 |
{ |
| 444 |
#endif |
| 445 |
png_structp png_ptr; |
| 446 |
#ifdef PNG_SETJMP_SUPPORTED |
| 447 |
#ifdef USE_FAR_KEYWORD |
| 448 |
jmp_buf jmpbuf; |
| 449 |
#endif |
| 450 |
#endif |
| 451 |
int i; |
| 452 |
png_debug(1, "in png_create_write_struct\n"); |
| 453 |
#ifdef PNG_USER_MEM_SUPPORTED |
| 454 |
png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, |
| 455 |
(png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr); |
| 456 |
#else |
| 457 |
png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); |
| 458 |
#endif |
| 459 |
if (png_ptr == NULL) |
| 460 |
return (NULL); |
| 461 |
|
| 462 |
#if !defined(PNG_1_0_X) |
| 463 |
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED |
| 464 |
png_init_mmx_flags(png_ptr); |
| 465 |
#endif |
| 466 |
#endif |
| 467 |
|
| 468 |
|
| 469 |
#ifdef PNG_SET_USER_LIMITS_SUPPORTED |
| 470 |
png_ptr->user_width_max=PNG_USER_WIDTH_MAX; |
| 471 |
png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; |
| 472 |
#endif |
| 473 |
|
| 474 |
#ifdef PNG_SETJMP_SUPPORTED |
| 475 |
#ifdef USE_FAR_KEYWORD |
| 476 |
if (setjmp(jmpbuf)) |
| 477 |
#else |
| 478 |
if (setjmp(png_ptr->jmpbuf)) |
| 479 |
#endif |
| 480 |
{ |
| 481 |
png_free(png_ptr, png_ptr->zbuf); |
| 482 |
png_ptr->zbuf=NULL; |
| 483 |
png_destroy_struct(png_ptr); |
| 484 |
return (NULL); |
| 485 |
} |
| 486 |
#ifdef USE_FAR_KEYWORD |
| 487 |
png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf)); |
| 488 |
#endif |
| 489 |
#endif |
| 490 |
|
| 491 |
#ifdef PNG_USER_MEM_SUPPORTED |
| 492 |
png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); |
| 493 |
#endif |
| 494 |
png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); |
| 495 |
|
| 496 |
i=0; |
| 497 |
do |
| 498 |
{ |
| 499 |
if(user_png_ver[i] != png_libpng_ver[i]) |
| 500 |
png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; |
| 501 |
} while (png_libpng_ver[i++]); |
| 502 |
|
| 503 |
if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) |
| 504 |
{ |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] || |
| 511 |
(user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) || |
| 512 |
(user_png_ver[0] == '0' && user_png_ver[2] < '9')) |
| 513 |
{ |
| 514 |
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) |
| 515 |
char msg[80]; |
| 516 |
if (user_png_ver) |
| 517 |
{ |
| 518 |
sprintf(msg, "Application was compiled with png.h from libpng-%.20s", |
| 519 |
user_png_ver); |
| 520 |
png_warning(png_ptr, msg); |
| 521 |
} |
| 522 |
sprintf(msg, "Application is running with png.c from libpng-%.20s", |
| 523 |
png_libpng_ver); |
| 524 |
png_warning(png_ptr, msg); |
| 525 |
#endif |
| 526 |
#ifdef PNG_ERROR_NUMBERS_SUPPORTED |
| 527 |
png_ptr->flags=0; |
| 528 |
#endif |
| 529 |
png_error(png_ptr, |
| 530 |
"Incompatible libpng version in application and library"); |
| 531 |
} |
| 532 |
} |
| 533 |
|
| 534 |
|
| 535 |
png_ptr->zbuf_size = PNG_ZBUF_SIZE; |
| 536 |
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, |
| 537 |
(png_uint_32)png_ptr->zbuf_size); |
| 538 |
|
| 539 |
png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL, |
| 540 |
png_flush_ptr_NULL); |
| 541 |
|
| 542 |
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) |
| 543 |
png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, |
| 544 |
1, png_doublep_NULL, png_doublep_NULL); |
| 545 |
#endif |
| 546 |
|
| 547 |
#ifdef PNG_SETJMP_SUPPORTED |
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
#ifdef USE_FAR_KEYWORD |
| 552 |
if (setjmp(jmpbuf)) |
| 553 |
PNG_ABORT(); |
| 554 |
png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf)); |
| 555 |
#else |
| 556 |
if (setjmp(png_ptr->jmpbuf)) |
| 557 |
PNG_ABORT(); |
| 558 |
#endif |
| 559 |
#endif |
| 560 |
return (png_ptr); |
| 561 |
} |
| 562 |
|
| 563 |
|
| 564 |
#if defined(PNG_1_0_X) || defined(PNG_1_2_X) |
| 565 |
|
| 566 |
#undef png_write_init |
| 567 |
void PNGAPI |
| 568 |
png_write_init(png_structp png_ptr) |
| 569 |
{ |
| 570 |
|
| 571 |
png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0); |
| 572 |
} |
| 573 |
|
| 574 |
void PNGAPI |
| 575 |
png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver, |
| 576 |
png_size_t png_struct_size, png_size_t png_info_size) |
| 577 |
{ |
| 578 |
|
| 579 |
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) |
| 580 |
if(png_sizeof(png_struct) > png_struct_size || |
| 581 |
png_sizeof(png_info) > png_info_size) |
| 582 |
{ |
| 583 |
char msg[80]; |
| 584 |
png_ptr->warning_fn=NULL; |
| 585 |
if (user_png_ver) |
| 586 |
{ |
| 587 |
sprintf(msg, "Application was compiled with png.h from libpng-%.20s", |
| 588 |
user_png_ver); |
| 589 |
png_warning(png_ptr, msg); |
| 590 |
} |
| 591 |
sprintf(msg, "Application is running with png.c from libpng-%.20s", |
| 592 |
png_libpng_ver); |
| 593 |
png_warning(png_ptr, msg); |
| 594 |
} |
| 595 |
#endif |
| 596 |
if(png_sizeof(png_struct) > png_struct_size) |
| 597 |
{ |
| 598 |
png_ptr->error_fn=NULL; |
| 599 |
#ifdef PNG_ERROR_NUMBERS_SUPPORTED |
| 600 |
png_ptr->flags=0; |
| 601 |
#endif |
| 602 |
png_error(png_ptr, |
| 603 |
"The png struct allocated by the application for writing is too small."); |
| 604 |
} |
| 605 |
if(png_sizeof(png_info) > png_info_size) |
| 606 |
{ |
| 607 |
png_ptr->error_fn=NULL; |
| 608 |
#ifdef PNG_ERROR_NUMBERS_SUPPORTED |
| 609 |
png_ptr->flags=0; |
| 610 |
#endif |
| 611 |
png_error(png_ptr, |
| 612 |
"The info struct allocated by the application for writing is too small."); |
| 613 |
} |
| 614 |
png_write_init_3(&png_ptr, user_png_ver, png_struct_size); |
| 615 |
} |
| 616 |
#endif |
| 617 |
|
| 618 |
|
| 619 |
void PNGAPI |
| 620 |
png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, |
| 621 |
png_size_t png_struct_size) |
| 622 |
{ |
| 623 |
png_structp png_ptr=*ptr_ptr; |
| 624 |
#ifdef PNG_SETJMP_SUPPORTED |
| 625 |
jmp_buf tmp_jmp; |
| 626 |
#endif |
| 627 |
|
| 628 |
int i = 0; |
| 629 |
|
| 630 |
if (png_ptr == NULL) |
| 631 |
return; |
| 632 |
|
| 633 |
do |
| 634 |
{ |
| 635 |
if (user_png_ver[i] != png_libpng_ver[i]) |
| 636 |
{ |
| 637 |
#ifdef PNG_LEGACY_SUPPORTED |
| 638 |
png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; |
| 639 |
#else |
| 640 |
png_ptr->warning_fn=NULL; |
| 641 |
png_warning(png_ptr, |
| 642 |
"Application uses deprecated png_write_init() and should be recompiled."); |
| 643 |
break; |
| 644 |
#endif |
| 645 |
} |
| 646 |
} while (png_libpng_ver[i++]); |
| 647 |
|
| 648 |
png_debug(1, "in png_write_init_3\n"); |
| 649 |
|
| 650 |
#ifdef PNG_SETJMP_SUPPORTED |
| 651 |
|
| 652 |
png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf)); |
| 653 |
#endif |
| 654 |
|
| 655 |
if (png_sizeof(png_struct) > png_struct_size) |
| 656 |
{ |
| 657 |
png_destroy_struct(png_ptr); |
| 658 |
png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); |
| 659 |
*ptr_ptr = png_ptr; |
| 660 |
} |
| 661 |
|
| 662 |
|
| 663 |
png_memset(png_ptr, 0, png_sizeof (png_struct)); |
| 664 |
|
| 665 |
|
| 666 |
#ifdef PNG_SET_USER_LIMITS_SUPPORTED |
| 667 |
png_ptr->user_width_max=PNG_USER_WIDTH_MAX; |
| 668 |
png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; |
| 669 |
#endif |
| 670 |
|
| 671 |
#if !defined(PNG_1_0_X) |
| 672 |
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED |
| 673 |
png_init_mmx_flags(png_ptr); |
| 674 |
#endif |
| 675 |
#endif |
| 676 |
|
| 677 |
#ifdef PNG_SETJMP_SUPPORTED |
| 678 |
|
| 679 |
png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf)); |
| 680 |
#endif |
| 681 |
|
| 682 |
png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL, |
| 683 |
png_flush_ptr_NULL); |
| 684 |
|
| 685 |
|
| 686 |
png_ptr->zbuf_size = PNG_ZBUF_SIZE; |
| 687 |
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, |
| 688 |
(png_uint_32)png_ptr->zbuf_size); |
| 689 |
|
| 690 |
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) |
| 691 |
png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, |
| 692 |
1, png_doublep_NULL, png_doublep_NULL); |
| 693 |
#endif |
| 694 |
} |
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
void PNGAPI |
| 702 |
png_write_rows(png_structp png_ptr, png_bytepp row, |
| 703 |
png_uint_32 num_rows) |
| 704 |
{ |
| 705 |
png_uint_32 i; |
| 706 |
png_bytepp rp; |
| 707 |
|
| 708 |
png_debug(1, "in png_write_rows\n"); |
| 709 |
|
| 710 |
if (png_ptr == NULL) |
| 711 |
return; |
| 712 |
|
| 713 |
|
| 714 |
for (i = 0, rp = row; i < num_rows; i++, rp++) |
| 715 |
{ |
| 716 |
png_write_row(png_ptr, *rp); |
| 717 |
} |
| 718 |
} |
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
void PNGAPI |
| 724 |
png_write_image(png_structp png_ptr, png_bytepp image) |
| 725 |
{ |
| 726 |
png_uint_32 i; |
| 727 |
int pass, num_pass; |
| 728 |
png_bytepp rp; |
| 729 |
|
| 730 |
if (png_ptr == NULL) |
| 731 |
return; |
| 732 |
|
| 733 |
png_debug(1, "in png_write_image\n"); |
| 734 |
#if defined(PNG_WRITE_INTERLACING_SUPPORTED) |
| 735 |
|
| 736 |
|
| 737 |
num_pass = png_set_interlace_handling(png_ptr); |
| 738 |
#else |
| 739 |
num_pass = 1; |
| 740 |
#endif |
| 741 |
|
| 742 |
for (pass = 0; pass < num_pass; pass++) |
| 743 |
{ |
| 744 |
|
| 745 |
for (i = 0, rp = image; i < png_ptr->height; i++, rp++) |
| 746 |
{ |
| 747 |
png_write_row(png_ptr, *rp); |
| 748 |
} |
| 749 |
} |
| 750 |
} |
| 751 |
|
| 752 |
|
| 753 |
void PNGAPI |
| 754 |
png_write_row(png_structp png_ptr, png_bytep row) |
| 755 |
{ |
| 756 |
if (png_ptr == NULL) |
| 757 |
return; |
| 758 |
png_debug2(1, "in png_write_row (row %ld, pass %d)\n", |
| 759 |
png_ptr->row_number, png_ptr->pass); |
| 760 |
|
| 761 |
|
| 762 |
if (png_ptr->row_number == 0 && png_ptr->pass == 0) |
| 763 |
{ |
| 764 |
|
| 765 |
if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) |
| 766 |
png_error(png_ptr, |
| 767 |
"png_write_info was never called before png_write_row."); |
| 768 |
|
| 769 |
|
| 770 |
#if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED) |
| 771 |
if (png_ptr->transformations & PNG_INVERT_MONO) |
| 772 |
png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined."); |
| 773 |
#endif |
| 774 |
#if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED) |
| 775 |
if (png_ptr->transformations & PNG_FILLER) |
| 776 |
png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined."); |
| 777 |
#endif |
| 778 |
#if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED) |
| 779 |
if (png_ptr->transformations & PNG_PACKSWAP) |
| 780 |
png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined."); |
| 781 |
#endif |
| 782 |
#if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED) |
| 783 |
if (png_ptr->transformations & PNG_PACK) |
| 784 |
png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined."); |
| 785 |
#endif |
| 786 |
#if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED) |
| 787 |
if (png_ptr->transformations & PNG_SHIFT) |
| 788 |
png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined."); |
| 789 |
#endif |
| 790 |
#if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED) |
| 791 |
if (png_ptr->transformations & PNG_BGR) |
| 792 |
png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined."); |
| 793 |
#endif |
| 794 |
#if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED) |
| 795 |
if (png_ptr->transformations & PNG_SWAP_BYTES) |
| 796 |
png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined."); |
| 797 |
#endif |
| 798 |
|
| 799 |
png_write_start_row(png_ptr); |
| 800 |
} |
| 801 |
|
| 802 |
#if defined(PNG_WRITE_INTERLACING_SUPPORTED) |
| 803 |
|
| 804 |
if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) |
| 805 |
{ |
| 806 |
switch (png_ptr->pass) |
| 807 |
{ |
| 808 |
case 0: |
| 809 |
if (png_ptr->row_number & 0x07) |
| 810 |
{ |
| 811 |
png_write_finish_row(png_ptr); |
| 812 |
return; |
| 813 |
} |
| 814 |
break; |
| 815 |
case 1: |
| 816 |
if ((png_ptr->row_number & 0x07) || png_ptr->width < 5) |
| 817 |
{ |
| 818 |
png_write_finish_row(png_ptr); |
| 819 |
return; |
| 820 |
} |
| 821 |
break; |
| 822 |
case 2: |
| 823 |
if ((png_ptr->row_number & 0x07) != 4) |
| 824 |
{ |
| 825 |
png_write_finish_row(png_ptr); |
| 826 |
return; |
| 827 |
} |
| 828 |
break; |
| 829 |
case 3: |
| 830 |
if ((png_ptr->row_number & 0x03) || png_ptr->width < 3) |
| 831 |
{ |
| 832 |
png_write_finish_row(png_ptr); |
| 833 |
return; |
| 834 |
} |
| 835 |
break; |
| 836 |
case 4: |
| 837 |
if ((png_ptr->row_number & 0x03) != 2) |
| 838 |
{ |
| 839 |
png_write_finish_row(png_ptr); |
| 840 |
return; |
| 841 |
} |
| 842 |
break; |
| 843 |
case 5: |
| 844 |
if ((png_ptr->row_number & 0x01) || png_ptr->width < 2) |
| 845 |
{ |
| 846 |
png_write_finish_row(png_ptr); |
| 847 |
return; |
| 848 |
} |
| 849 |
break; |
| 850 |
case 6: |
| 851 |
if (!(png_ptr->row_number & 0x01)) |
| 852 |
{ |
| 853 |
png_write_finish_row(png_ptr); |
| 854 |
return; |
| 855 |
} |
| 856 |
break; |
| 857 |
} |
| 858 |
} |
| 859 |
#endif |
| 860 |
|
| 861 |
|
| 862 |
png_ptr->row_info.color_type = png_ptr->color_type; |
| 863 |
png_ptr->row_info.width = png_ptr->usr_width; |
| 864 |
png_ptr->row_info.channels = png_ptr->usr_channels; |
| 865 |
png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth; |
| 866 |
png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth * |
| 867 |
png_ptr->row_info.channels); |
| 868 |
|
| 869 |
png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, |
| 870 |
png_ptr->row_info.width); |
| 871 |
|
| 872 |
png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type); |
| 873 |
png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width); |
| 874 |
png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels); |
| 875 |
png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth); |
| 876 |
png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth); |
| 877 |
png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes); |
| 878 |
|
| 879 |
|
| 880 |
png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row, |
| 881 |
png_ptr->row_info.rowbytes); |
| 882 |
|
| 883 |
#if defined(PNG_WRITE_INTERLACING_SUPPORTED) |
| 884 |
|
| 885 |
if (png_ptr->interlaced && png_ptr->pass < 6 && |
| 886 |
(png_ptr->transformations & PNG_INTERLACE)) |
| 887 |
{ |
| 888 |
png_do_write_interlace(&(png_ptr->row_info), |
| 889 |
png_ptr->row_buf + 1, png_ptr->pass); |
| 890 |
|
| 891 |
if (!(png_ptr->row_info.width)) |
| 892 |
{ |
| 893 |
png_write_finish_row(png_ptr); |
| 894 |
return; |
| 895 |
} |
| 896 |
} |
| 897 |
#endif |
| 898 |
|
| 899 |
|
| 900 |
if (png_ptr->transformations) |
| 901 |
png_do_write_transformations(png_ptr); |
| 902 |
|
| 903 |
#if defined(PNG_MNG_FEATURES_SUPPORTED) |
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && |
| 914 |
(png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) |
| 915 |
{ |
| 916 |
|
| 917 |
png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1); |
| 918 |
} |
| 919 |
#endif |
| 920 |
|
| 921 |
|
| 922 |
png_write_find_filter(png_ptr, &(png_ptr->row_info)); |
| 923 |
|
| 924 |
if (png_ptr->write_row_fn != NULL) |
| 925 |
(*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); |
| 926 |
} |
| 927 |
|
| 928 |
#if defined(PNG_WRITE_FLUSH_SUPPORTED) |
| 929 |
|
| 930 |
void PNGAPI |
| 931 |
png_set_flush(png_structp png_ptr, int nrows) |
| 932 |
{ |
| 933 |
png_debug(1, "in png_set_flush\n"); |
| 934 |
if (png_ptr == NULL) |
| 935 |
return; |
| 936 |
png_ptr->flush_dist = (nrows < 0 ? 0 : nrows); |
| 937 |
} |
| 938 |
|
| 939 |
|
| 940 |
void PNGAPI |
| 941 |
png_write_flush(png_structp png_ptr) |
| 942 |
{ |
| 943 |
int wrote_IDAT; |
| 944 |
|
| 945 |
png_debug(1, "in png_write_flush\n"); |
| 946 |
if (png_ptr == NULL) |
| 947 |
return; |
| 948 |
|
| 949 |
if (png_ptr->row_number >= png_ptr->num_rows) |
| 950 |
return; |
| 951 |
|
| 952 |
do |
| 953 |
{ |
| 954 |
int ret; |
| 955 |
|
| 956 |
|
| 957 |
ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH); |
| 958 |
wrote_IDAT = 0; |
| 959 |
|
| 960 |
|
| 961 |
if (ret != Z_OK) |
| 962 |
{ |
| 963 |
if (png_ptr->zstream.msg != NULL) |
| 964 |
png_error(png_ptr, png_ptr->zstream.msg); |
| 965 |
else |
| 966 |
png_error(png_ptr, "zlib error"); |
| 967 |
} |
| 968 |
|
| 969 |
if (!(png_ptr->zstream.avail_out)) |
| 970 |
{ |
| 971 |
|
| 972 |
png_write_IDAT(png_ptr, png_ptr->zbuf, |
| 973 |
png_ptr->zbuf_size); |
| 974 |
png_ptr->zstream.next_out = png_ptr->zbuf; |
| 975 |
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; |
| 976 |
wrote_IDAT = 1; |
| 977 |
} |
| 978 |
} while(wrote_IDAT == 1); |
| 979 |
|
| 980 |
|
| 981 |
if (png_ptr->zbuf_size != png_ptr->zstream.avail_out) |
| 982 |
{ |
| 983 |
|
| 984 |
png_write_IDAT(png_ptr, png_ptr->zbuf, |
| 985 |
png_ptr->zbuf_size - png_ptr->zstream.avail_out); |
| 986 |
png_ptr->zstream.next_out = png_ptr->zbuf; |
| 987 |
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; |
| 988 |
} |
| 989 |
png_ptr->flush_rows = 0; |
| 990 |
png_flush(png_ptr); |
| 991 |
} |
| 992 |
#endif |
| 993 |
|
| 994 |
|
| 995 |
void PNGAPI |
| 996 |
png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) |
| 997 |
{ |
| 998 |
png_structp png_ptr = NULL; |
| 999 |
png_infop info_ptr = NULL; |
| 1000 |
#ifdef PNG_USER_MEM_SUPPORTED |
| 1001 |
png_free_ptr free_fn = NULL; |
| 1002 |
png_voidp mem_ptr = NULL; |
| 1003 |
#endif |
| 1004 |
|
| 1005 |
png_debug(1, "in png_destroy_write_struct\n"); |
| 1006 |
if (png_ptr_ptr != NULL) |
| 1007 |
{ |
| 1008 |
png_ptr = *png_ptr_ptr; |
| 1009 |
#ifdef PNG_USER_MEM_SUPPORTED |
| 1010 |
free_fn = png_ptr->free_fn; |
| 1011 |
mem_ptr = png_ptr->mem_ptr; |
| 1012 |
#endif |
| 1013 |
} |
| 1014 |
|
| 1015 |
if (info_ptr_ptr != NULL) |
| 1016 |
info_ptr = *info_ptr_ptr; |
| 1017 |
|
| 1018 |
if (info_ptr != NULL) |
| 1019 |
{ |
| 1020 |
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); |
| 1021 |
|
| 1022 |
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) |
| 1023 |
if (png_ptr->num_chunk_list) |
| 1024 |
{ |
| 1025 |
png_free(png_ptr, png_ptr->chunk_list); |
| 1026 |
png_ptr->chunk_list=NULL; |
| 1027 |
png_ptr->num_chunk_list=0; |
| 1028 |
} |
| 1029 |
#endif |
| 1030 |
|
| 1031 |
#ifdef PNG_USER_MEM_SUPPORTED |
| 1032 |
png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, |
| 1033 |
(png_voidp)mem_ptr); |
| 1034 |
#else |
| 1035 |
png_destroy_struct((png_voidp)info_ptr); |
| 1036 |
#endif |
| 1037 |
*info_ptr_ptr = NULL; |
| 1038 |
} |
| 1039 |
|
| 1040 |
if (png_ptr != NULL) |
| 1041 |
{ |
| 1042 |
png_write_destroy(png_ptr); |
| 1043 |
#ifdef PNG_USER_MEM_SUPPORTED |
| 1044 |
png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, |
| 1045 |
(png_voidp)mem_ptr); |
| 1046 |
#else |
| 1047 |
png_destroy_struct((png_voidp)png_ptr); |
| 1048 |
#endif |
| 1049 |
*png_ptr_ptr = NULL; |
| 1050 |
} |
| 1051 |
} |
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
void |
| 1056 |
png_write_destroy(png_structp png_ptr) |
| 1057 |
{ |
| 1058 |
#ifdef PNG_SETJMP_SUPPORTED |
| 1059 |
jmp_buf tmp_jmp; |
| 1060 |
#endif |
| 1061 |
png_error_ptr error_fn; |
| 1062 |
png_error_ptr warning_fn; |
| 1063 |
png_voidp error_ptr; |
| 1064 |
#ifdef PNG_USER_MEM_SUPPORTED |
| 1065 |
png_free_ptr free_fn; |
| 1066 |
#endif |
| 1067 |
|
| 1068 |
png_debug(1, "in png_write_destroy\n"); |
| 1069 |
|
| 1070 |
deflateEnd(&png_ptr->zstream); |
| 1071 |
|
| 1072 |
|
| 1073 |
png_free(png_ptr, png_ptr->zbuf); |
| 1074 |
png_free(png_ptr, png_ptr->row_buf); |
| 1075 |
png_free(png_ptr, png_ptr->prev_row); |
| 1076 |
png_free(png_ptr, png_ptr->sub_row); |
| 1077 |
png_free(png_ptr, png_ptr->up_row); |
| 1078 |
png_free(png_ptr, png_ptr->avg_row); |
| 1079 |
png_free(png_ptr, png_ptr->paeth_row); |
| 1080 |
|
| 1081 |
#if defined(PNG_TIME_RFC1123_SUPPORTED) |
| 1082 |
png_free(png_ptr, png_ptr->time_buffer); |
| 1083 |
#endif |
| 1084 |
|
| 1085 |
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) |
| 1086 |
png_free(png_ptr, png_ptr->prev_filters); |
| 1087 |
png_free(png_ptr, png_ptr->filter_weights); |
| 1088 |
png_free(png_ptr, png_ptr->inv_filter_weights); |
| 1089 |
png_free(png_ptr, png_ptr->filter_costs); |
| 1090 |
png_free(png_ptr, png_ptr->inv_filter_costs); |
| 1091 |
#endif |
| 1092 |
|
| 1093 |
#ifdef PNG_SETJMP_SUPPORTED |
| 1094 |
|
| 1095 |
png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf)); |
| 1096 |
#endif |
| 1097 |
|
| 1098 |
error_fn = png_ptr->error_fn; |
| 1099 |
warning_fn = png_ptr->warning_fn; |
| 1100 |
error_ptr = png_ptr->error_ptr; |
| 1101 |
#ifdef PNG_USER_MEM_SUPPORTED |
| 1102 |
free_fn = png_ptr->free_fn; |
| 1103 |
#endif |
| 1104 |
|
| 1105 |
png_memset(png_ptr, 0, png_sizeof (png_struct)); |
| 1106 |
|
| 1107 |
png_ptr->error_fn = error_fn; |
| 1108 |
png_ptr->warning_fn = warning_fn; |
| 1109 |
png_ptr->error_ptr = error_ptr; |
| 1110 |
#ifdef PNG_USER_MEM_SUPPORTED |
| 1111 |
png_ptr->free_fn = free_fn; |
| 1112 |
#endif |
| 1113 |
|
| 1114 |
#ifdef PNG_SETJMP_SUPPORTED |
| 1115 |
png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf)); |
| 1116 |
#endif |
| 1117 |
} |
| 1118 |
|
| 1119 |
|
| 1120 |
void PNGAPI |
| 1121 |
png_set_filter(png_structp png_ptr, int method, int filters) |
| 1122 |
{ |
| 1123 |
png_debug(1, "in png_set_filter\n"); |
| 1124 |
if (png_ptr == NULL) |
| 1125 |
return; |
| 1126 |
#if defined(PNG_MNG_FEATURES_SUPPORTED) |
| 1127 |
if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && |
| 1128 |
(method == PNG_INTRAPIXEL_DIFFERENCING)) |
| 1129 |
method = PNG_FILTER_TYPE_BASE; |
| 1130 |
#endif |
| 1131 |
if (method == PNG_FILTER_TYPE_BASE) |
| 1132 |
{ |
| 1133 |
switch (filters & (PNG_ALL_FILTERS | 0x07)) |
| 1134 |
{ |
| 1135 |
case 5: |
| 1136 |
case 6: |
| 1137 |
case 7: png_warning(png_ptr, "Unknown row filter for method 0"); |
| 1138 |
case PNG_FILTER_VALUE_NONE: png_ptr->do_filter=PNG_FILTER_NONE; break; |
| 1139 |
case PNG_FILTER_VALUE_SUB: png_ptr->do_filter=PNG_FILTER_SUB; break; |
| 1140 |
case PNG_FILTER_VALUE_UP: png_ptr->do_filter=PNG_FILTER_UP; break; |
| 1141 |
case PNG_FILTER_VALUE_AVG: png_ptr->do_filter=PNG_FILTER_AVG; break; |
| 1142 |
case PNG_FILTER_VALUE_PAETH: png_ptr->do_filter=PNG_FILTER_PAETH;break; |
| 1143 |
default: png_ptr->do_filter = (png_byte)filters; break; |
| 1144 |
} |
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
if (png_ptr->row_buf != NULL) |
| 1156 |
{ |
| 1157 |
if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL) |
| 1158 |
{ |
| 1159 |
png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, |
| 1160 |
(png_ptr->rowbytes + 1)); |
| 1161 |
png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; |
| 1162 |
} |
| 1163 |
|
| 1164 |
if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL) |
| 1165 |
{ |
| 1166 |
if (png_ptr->prev_row == NULL) |
| 1167 |
{ |
| 1168 |
png_warning(png_ptr, "Can't add Up filter after starting"); |
| 1169 |
png_ptr->do_filter &= ~PNG_FILTER_UP; |
| 1170 |
} |
| 1171 |
else |
| 1172 |
{ |
| 1173 |
png_ptr->up_row = (png_bytep)png_malloc(png_ptr, |
| 1174 |
(png_ptr->rowbytes + 1)); |
| 1175 |
png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; |
| 1176 |
} |
| 1177 |
} |
| 1178 |
|
| 1179 |
if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL) |
| 1180 |
{ |
| 1181 |
if (png_ptr->prev_row == NULL) |
| 1182 |
{ |
| 1183 |
png_warning(png_ptr, "Can't add Average filter after starting"); |
| 1184 |
png_ptr->do_filter &= ~PNG_FILTER_AVG; |
| 1185 |
} |
| 1186 |
else |
| 1187 |
{ |
| 1188 |
png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, |
| 1189 |
(png_ptr->rowbytes + 1)); |
| 1190 |
png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; |
| 1191 |
} |
| 1192 |
} |
| 1193 |
|
| 1194 |
if ((png_ptr->do_filter & PNG_FILTER_PAETH) && |
| 1195 |
png_ptr->paeth_row == NULL) |
| 1196 |
{ |
| 1197 |
if (png_ptr->prev_row == NULL) |
| 1198 |
{ |
| 1199 |
png_warning(png_ptr, "Can't add Paeth filter after starting"); |
| 1200 |
png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH); |
| 1201 |
} |
| 1202 |
else |
| 1203 |
{ |
| 1204 |
png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, |
| 1205 |
(png_ptr->rowbytes + 1)); |
| 1206 |
png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; |
| 1207 |
} |
| 1208 |
} |
| 1209 |
|
| 1210 |
if (png_ptr->do_filter == PNG_NO_FILTERS) |
| 1211 |
png_ptr->do_filter = PNG_FILTER_NONE; |
| 1212 |
} |
| 1213 |
} |
| 1214 |
else |
| 1215 |
png_error(png_ptr, "Unknown custom filter method"); |
| 1216 |
} |
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) |
| 1226 |
void PNGAPI |
| 1227 |
png_set_filter_heuristics(png_structp png_ptr, int heuristic_method, |
| 1228 |
int num_weights, png_doublep filter_weights, |
| 1229 |
png_doublep filter_costs) |
| 1230 |
{ |
| 1231 |
int i; |
| 1232 |
|
| 1233 |
png_debug(1, "in png_set_filter_heuristics\n"); |
| 1234 |
if (png_ptr == NULL) |
| 1235 |
return; |
| 1236 |
if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST) |
| 1237 |
{ |
| 1238 |
png_warning(png_ptr, "Unknown filter heuristic method"); |
| 1239 |
return; |
| 1240 |
} |
| 1241 |
|
| 1242 |
if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT) |
| 1243 |
{ |
| 1244 |
heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED; |
| 1245 |
} |
| 1246 |
|
| 1247 |
if (num_weights < 0 || filter_weights == NULL || |
| 1248 |
heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED) |
| 1249 |
{ |
| 1250 |
num_weights = 0; |
| 1251 |
} |
| 1252 |
|
| 1253 |
png_ptr->num_prev_filters = (png_byte)num_weights; |
| 1254 |
png_ptr->heuristic_method = (png_byte)heuristic_method; |
| 1255 |
|
| 1256 |
if (num_weights > 0) |
| 1257 |
{ |
| 1258 |
if (png_ptr->prev_filters == NULL) |
| 1259 |
{ |
| 1260 |
png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr, |
| 1261 |
(png_uint_32)(png_sizeof(png_byte) * num_weights)); |
| 1262 |
|
| 1263 |
|
| 1264 |
for (i = 0; i < num_weights; i++) |
| 1265 |
{ |
| 1266 |
png_ptr->prev_filters[i] = 255; |
| 1267 |
} |
| 1268 |
} |
| 1269 |
|
| 1270 |
if (png_ptr->filter_weights == NULL) |
| 1271 |
{ |
| 1272 |
png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr, |
| 1273 |
(png_uint_32)(png_sizeof(png_uint_16) * num_weights)); |
| 1274 |
|
| 1275 |
png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr, |
| 1276 |
(png_uint_32)(png_sizeof(png_uint_16) * num_weights)); |
| 1277 |
for (i = 0; i < num_weights; i++) |
| 1278 |
{ |
| 1279 |
png_ptr->inv_filter_weights[i] = |
| 1280 |
png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR; |
| 1281 |
} |
| 1282 |
} |
| 1283 |
|
| 1284 |
for (i = 0; i < num_weights; i++) |
| 1285 |
{ |
| 1286 |
if (filter_weights[i] < 0.0) |
| 1287 |
{ |
| 1288 |
png_ptr->inv_filter_weights[i] = |
| 1289 |
png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR; |
| 1290 |
} |
| 1291 |
else |
| 1292 |
{ |
| 1293 |
png_ptr->inv_filter_weights[i] = |
| 1294 |
(png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5); |
| 1295 |
png_ptr->filter_weights[i] = |
| 1296 |
(png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5); |
| 1297 |
} |
| 1298 |
} |
| 1299 |
} |
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
if (png_ptr->filter_costs == NULL) |
| 1305 |
{ |
| 1306 |
png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr, |
| 1307 |
(png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST)); |
| 1308 |
|
| 1309 |
png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr, |
| 1310 |
(png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST)); |
| 1311 |
|
| 1312 |
for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) |
| 1313 |
{ |
| 1314 |
png_ptr->inv_filter_costs[i] = |
| 1315 |
png_ptr->filter_costs[i] = PNG_COST_FACTOR; |
| 1316 |
} |
| 1317 |
} |
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) |
| 1327 |
{ |
| 1328 |
if (filter_costs == NULL || filter_costs[i] < 0.0) |
| 1329 |
{ |
| 1330 |
png_ptr->inv_filter_costs[i] = |
| 1331 |
png_ptr->filter_costs[i] = PNG_COST_FACTOR; |
| 1332 |
} |
| 1333 |
else if (filter_costs[i] >= 1.0) |
| 1334 |
{ |
| 1335 |
png_ptr->inv_filter_costs[i] = |
| 1336 |
(png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5); |
| 1337 |
png_ptr->filter_costs[i] = |
| 1338 |
(png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5); |
| 1339 |
} |
| 1340 |
} |
| 1341 |
} |
| 1342 |
#endif |
| 1343 |
|
| 1344 |
void PNGAPI |
| 1345 |
png_set_compression_level(png_structp png_ptr, int level) |
| 1346 |
{ |
| 1347 |
png_debug(1, "in png_set_compression_level\n"); |
| 1348 |
if (png_ptr == NULL) |
| 1349 |
return; |
| 1350 |
png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL; |
| 1351 |
png_ptr->zlib_level = level; |
| 1352 |
} |
| 1353 |
|
| 1354 |
void PNGAPI |
| 1355 |
png_set_compression_mem_level(png_structp png_ptr, int mem_level) |
| 1356 |
{ |
| 1357 |
png_debug(1, "in png_set_compression_mem_level\n"); |
| 1358 |
if (png_ptr == NULL) |
| 1359 |
return; |
| 1360 |
png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL; |
| 1361 |
png_ptr->zlib_mem_level = mem_level; |
| 1362 |
} |
| 1363 |
|
| 1364 |
void PNGAPI |
| 1365 |
png_set_compression_strategy(png_structp png_ptr, int strategy) |
| 1366 |
{ |
| 1367 |
png_debug(1, "in png_set_compression_strategy\n"); |
| 1368 |
if (png_ptr == NULL) |
| 1369 |
return; |
| 1370 |
png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY; |
| 1371 |
png_ptr->zlib_strategy = strategy; |
| 1372 |
} |
| 1373 |
|
| 1374 |
void PNGAPI |
| 1375 |
png_set_compression_window_bits(png_structp png_ptr, int window_bits) |
| 1376 |
{ |
| 1377 |
if (png_ptr == NULL) |
| 1378 |
return; |
| 1379 |
if (window_bits > 15) |
| 1380 |
png_warning(png_ptr, "Only compression windows <= 32k supported by PNG"); |
| 1381 |
else if (window_bits < 8) |
| 1382 |
png_warning(png_ptr, "Only compression windows >= 256 supported by PNG"); |
| 1383 |
#ifndef WBITS_8_OK |
| 1384 |
|
| 1385 |
if (window_bits == 8) |
| 1386 |
{ |
| 1387 |
png_warning(png_ptr, "Compression window is being reset to 512"); |
| 1388 |
window_bits=9; |
| 1389 |
} |
| 1390 |
#endif |
| 1391 |
png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS; |
| 1392 |
png_ptr->zlib_window_bits = window_bits; |
| 1393 |
} |
| 1394 |
|
| 1395 |
void PNGAPI |
| 1396 |
png_set_compression_method(png_structp png_ptr, int method) |
| 1397 |
{ |
| 1398 |
png_debug(1, "in png_set_compression_method\n"); |
| 1399 |
if (png_ptr == NULL) |
| 1400 |
return; |
| 1401 |
if (method != 8) |
| 1402 |
png_warning(png_ptr, "Only compression method 8 is supported by PNG"); |
| 1403 |
png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD; |
| 1404 |
png_ptr->zlib_method = method; |
| 1405 |
} |
| 1406 |
|
| 1407 |
void PNGAPI |
| 1408 |
png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn) |
| 1409 |
{ |
| 1410 |
if (png_ptr == NULL) |
| 1411 |
return; |
| 1412 |
png_ptr->write_row_fn = write_row_fn; |
| 1413 |
} |
| 1414 |
|
| 1415 |
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) |
| 1416 |
void PNGAPI |
| 1417 |
png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr |
| 1418 |
write_user_transform_fn) |
| 1419 |
{ |
| 1420 |
png_debug(1, "in png_set_write_user_transform_fn\n"); |
| 1421 |
if (png_ptr == NULL) |
| 1422 |
return; |
| 1423 |
png_ptr->transformations |= PNG_USER_TRANSFORM; |
| 1424 |
png_ptr->write_user_transform_fn = write_user_transform_fn; |
| 1425 |
} |
| 1426 |
#endif |
| 1427 |
|
| 1428 |
|
| 1429 |
#if defined(PNG_INFO_IMAGE_SUPPORTED) |
| 1430 |
void PNGAPI |
| 1431 |
png_write_png(png_structp png_ptr, png_infop info_ptr, |
| 1432 |
int transforms, voidp params) |
| 1433 |
{ |
| 1434 |
if (png_ptr == NULL || info_ptr == NULL) |
| 1435 |
return; |
| 1436 |
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) |
| 1437 |
|
| 1438 |
if (transforms & PNG_TRANSFORM_INVERT_ALPHA) |
| 1439 |
png_set_invert_alpha(png_ptr); |
| 1440 |
#endif |
| 1441 |
|
| 1442 |
|
| 1443 |
png_write_info(png_ptr, info_ptr); |
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
#if defined(PNG_WRITE_INVERT_SUPPORTED) |
| 1448 |
|
| 1449 |
if (transforms & PNG_TRANSFORM_INVERT_MONO) |
| 1450 |
png_set_invert_mono(png_ptr); |
| 1451 |
#endif |
| 1452 |
|
| 1453 |
#if defined(PNG_WRITE_SHIFT_SUPPORTED) |
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
if ((transforms & PNG_TRANSFORM_SHIFT) |
| 1458 |
&& (info_ptr->valid & PNG_INFO_sBIT)) |
| 1459 |
png_set_shift(png_ptr, &info_ptr->sig_bit); |
| 1460 |
#endif |
| 1461 |
|
| 1462 |
#if defined(PNG_WRITE_PACK_SUPPORTED) |
| 1463 |
|
| 1464 |
if (transforms & PNG_TRANSFORM_PACKING) |
| 1465 |
png_set_packing(png_ptr); |
| 1466 |
#endif |
| 1467 |
|
| 1468 |
#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) |
| 1469 |
|
| 1470 |
if (transforms & PNG_TRANSFORM_SWAP_ALPHA) |
| 1471 |
png_set_swap_alpha(png_ptr); |
| 1472 |
#endif |
| 1473 |
|
| 1474 |
#if defined(PNG_WRITE_FILLER_SUPPORTED) |
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
if (transforms & PNG_TRANSFORM_STRIP_FILLER) |
| 1479 |
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); |
| 1480 |
#endif |
| 1481 |
|
| 1482 |
#if defined(PNG_WRITE_BGR_SUPPORTED) |
| 1483 |
|
| 1484 |
if (transforms & PNG_TRANSFORM_BGR) |
| 1485 |
png_set_bgr(png_ptr); |
| 1486 |
#endif |
| 1487 |
|
| 1488 |
#if defined(PNG_WRITE_SWAP_SUPPORTED) |
| 1489 |
|
| 1490 |
if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) |
| 1491 |
png_set_swap(png_ptr); |
| 1492 |
#endif |
| 1493 |
|
| 1494 |
#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) |
| 1495 |
|
| 1496 |
if (transforms & PNG_TRANSFORM_PACKSWAP) |
| 1497 |
png_set_packswap(png_ptr); |
| 1498 |
#endif |
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
if (info_ptr->valid & PNG_INFO_IDAT) |
| 1504 |
png_write_image(png_ptr, info_ptr->row_pointers); |
| 1505 |
|
| 1506 |
|
| 1507 |
png_write_end(png_ptr, info_ptr); |
| 1508 |
|
| 1509 |
if(transforms == 0 || params == NULL) |
| 1510 |
return; |
| 1511 |
} |
| 1512 |
#endif |
| 1513 |
#endif |