| OLD | NEW |
| 1 | 1 |
| 2 /* pngread.c - read a PNG file | 2 /* pngread.c - read a PNG file |
| 3 * | 3 * |
| 4 * Last changed in libpng 1.2.25 [February 18, 2008] | 4 * Last changed in libpng 1.2.30 [August 15, 2008] |
| 5 * For conditions of distribution and use, see copyright notice in png.h | 5 * For conditions of distribution and use, see copyright notice in png.h |
| 6 * Copyright (c) 1998-2008 Glenn Randers-Pehrson | 6 * Copyright (c) 1998-2008 Glenn Randers-Pehrson |
| 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
| 8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) | 8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
| 9 * | 9 * |
| 10 * This file contains routines that an application calls directly to | 10 * This file contains routines that an application calls directly to |
| 11 * read a PNG file or stream. | 11 * read a PNG file or stream. |
| 12 */ | 12 */ |
| 13 | 13 |
| 14 #define PNG_INTERNAL | 14 #define PNG_INTERNAL |
| 15 #include "png.h" | 15 #include "png.h" |
| 16 | |
| 17 #if defined(PNG_READ_SUPPORTED) | 16 #if defined(PNG_READ_SUPPORTED) |
| 18 | 17 |
| 19 /* Create a PNG structure for reading, and allocate any memory needed. */ | 18 /* Create a PNG structure for reading, and allocate any memory needed. */ |
| 20 png_structp PNGAPI | 19 png_structp PNGAPI |
| 21 png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr, | 20 png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr, |
| 22 png_error_ptr error_fn, png_error_ptr warn_fn) | 21 png_error_ptr error_fn, png_error_ptr warn_fn) |
| 23 { | 22 { |
| 24 | 23 |
| 25 #ifdef PNG_USER_MEM_SUPPORTED | 24 #ifdef PNG_USER_MEM_SUPPORTED |
| 26 return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn, | 25 return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn, |
| 27 warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL)); | 26 warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL)); |
| 28 } | 27 } |
| 29 | 28 |
| 30 /* Alternate create PNG structure for reading, and allocate any memory needed. *
/ | 29 /* Alternate create PNG structure for reading, and allocate any memory needed. *
/ |
| 31 png_structp PNGAPI | 30 png_structp PNGAPI |
| 32 png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, | 31 png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, |
| 33 png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, | 32 png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, |
| 34 png_malloc_ptr malloc_fn, png_free_ptr free_fn) | 33 png_malloc_ptr malloc_fn, png_free_ptr free_fn) |
| 35 { | 34 { |
| 36 #endif /* PNG_USER_MEM_SUPPORTED */ | 35 #endif /* PNG_USER_MEM_SUPPORTED */ |
| 37 | 36 |
| 37 #ifdef PNG_SETJMP_SUPPORTED |
| 38 volatile |
| 39 #endif |
| 38 png_structp png_ptr; | 40 png_structp png_ptr; |
| 39 | 41 |
| 40 #ifdef PNG_SETJMP_SUPPORTED | 42 #ifdef PNG_SETJMP_SUPPORTED |
| 41 #ifdef USE_FAR_KEYWORD | 43 #ifdef USE_FAR_KEYWORD |
| 42 jmp_buf jmpbuf; | 44 jmp_buf jmpbuf; |
| 43 #endif | 45 #endif |
| 44 #endif | 46 #endif |
| 45 | 47 |
| 46 int i; | 48 int i; |
| 47 | 49 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 62 #endif | 64 #endif |
| 63 | 65 |
| 64 #ifdef PNG_SETJMP_SUPPORTED | 66 #ifdef PNG_SETJMP_SUPPORTED |
| 65 #ifdef USE_FAR_KEYWORD | 67 #ifdef USE_FAR_KEYWORD |
| 66 if (setjmp(jmpbuf)) | 68 if (setjmp(jmpbuf)) |
| 67 #else | 69 #else |
| 68 if (setjmp(png_ptr->jmpbuf)) | 70 if (setjmp(png_ptr->jmpbuf)) |
| 69 #endif | 71 #endif |
| 70 { | 72 { |
| 71 png_free(png_ptr, png_ptr->zbuf); | 73 png_free(png_ptr, png_ptr->zbuf); |
| 72 png_ptr->zbuf=NULL; | 74 png_ptr->zbuf = NULL; |
| 73 #ifdef PNG_USER_MEM_SUPPORTED | 75 #ifdef PNG_USER_MEM_SUPPORTED |
| 74 png_destroy_struct_2((png_voidp)png_ptr, | 76 png_destroy_struct_2((png_voidp)png_ptr, |
| 75 (png_free_ptr)free_fn, (png_voidp)mem_ptr); | 77 (png_free_ptr)free_fn, (png_voidp)mem_ptr); |
| 76 #else | 78 #else |
| 77 png_destroy_struct((png_voidp)png_ptr); | 79 png_destroy_struct((png_voidp)png_ptr); |
| 78 #endif | 80 #endif |
| 79 return (NULL); | 81 return (NULL); |
| 80 } | 82 } |
| 81 #ifdef USE_FAR_KEYWORD | 83 #ifdef USE_FAR_KEYWORD |
| 82 png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf)); | 84 png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); |
| 83 #endif | 85 #endif |
| 84 #endif | 86 #endif |
| 85 | 87 |
| 86 #ifdef PNG_USER_MEM_SUPPORTED | 88 #ifdef PNG_USER_MEM_SUPPORTED |
| 87 png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); | 89 png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); |
| 88 #endif | 90 #endif |
| 89 | 91 |
| 90 png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); | 92 png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); |
| 91 | 93 |
| 92 if(user_png_ver) | 94 if (user_png_ver) |
| 93 { | 95 { |
| 94 i=0; | 96 i = 0; |
| 95 do | 97 do |
| 96 { | 98 { |
| 97 if(user_png_ver[i] != png_libpng_ver[i]) | 99 if (user_png_ver[i] != png_libpng_ver[i]) |
| 98 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; | 100 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; |
| 99 } while (png_libpng_ver[i++]); | 101 } while (png_libpng_ver[i++]); |
| 100 } | 102 } |
| 101 else | 103 else |
| 102 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; | 104 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; |
| 103 | 105 |
| 104 | 106 |
| 105 if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) | 107 if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) |
| 106 { | 108 { |
| 107 /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so | 109 /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so |
| (...skipping 13 matching lines...) Expand all Loading... |
| 121 "Application was compiled with png.h from libpng-%.20s", | 123 "Application was compiled with png.h from libpng-%.20s", |
| 122 user_png_ver); | 124 user_png_ver); |
| 123 png_warning(png_ptr, msg); | 125 png_warning(png_ptr, msg); |
| 124 } | 126 } |
| 125 png_snprintf(msg, 80, | 127 png_snprintf(msg, 80, |
| 126 "Application is running with png.c from libpng-%.20s", | 128 "Application is running with png.c from libpng-%.20s", |
| 127 png_libpng_ver); | 129 png_libpng_ver); |
| 128 png_warning(png_ptr, msg); | 130 png_warning(png_ptr, msg); |
| 129 #endif | 131 #endif |
| 130 #ifdef PNG_ERROR_NUMBERS_SUPPORTED | 132 #ifdef PNG_ERROR_NUMBERS_SUPPORTED |
| 131 png_ptr->flags=0; | 133 png_ptr->flags = 0; |
| 132 #endif | 134 #endif |
| 133 png_error(png_ptr, | 135 png_error(png_ptr, |
| 134 "Incompatible libpng version in application and library"); | 136 "Incompatible libpng version in application and library"); |
| 135 } | 137 } |
| 136 } | 138 } |
| 137 | 139 |
| 138 /* initialize zbuf - compression buffer */ | 140 /* initialize zbuf - compression buffer */ |
| 139 png_ptr->zbuf_size = PNG_ZBUF_SIZE; | 141 png_ptr->zbuf_size = PNG_ZBUF_SIZE; |
| 140 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, | 142 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, |
| 141 (png_uint_32)png_ptr->zbuf_size); | 143 (png_uint_32)png_ptr->zbuf_size); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 157 | 159 |
| 158 png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL); | 160 png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL); |
| 159 | 161 |
| 160 #ifdef PNG_SETJMP_SUPPORTED | 162 #ifdef PNG_SETJMP_SUPPORTED |
| 161 /* Applications that neglect to set up their own setjmp() and then encounter | 163 /* Applications that neglect to set up their own setjmp() and then encounter |
| 162 a png_error() will longjmp here. Since the jmpbuf is then meaningless we | 164 a png_error() will longjmp here. Since the jmpbuf is then meaningless we |
| 163 abort instead of returning. */ | 165 abort instead of returning. */ |
| 164 #ifdef USE_FAR_KEYWORD | 166 #ifdef USE_FAR_KEYWORD |
| 165 if (setjmp(jmpbuf)) | 167 if (setjmp(jmpbuf)) |
| 166 PNG_ABORT(); | 168 PNG_ABORT(); |
| 167 png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf)); | 169 png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); |
| 168 #else | 170 #else |
| 169 if (setjmp(png_ptr->jmpbuf)) | 171 if (setjmp(png_ptr->jmpbuf)) |
| 170 PNG_ABORT(); | 172 PNG_ABORT(); |
| 171 #endif | 173 #endif |
| 172 #endif | 174 #endif |
| 173 return (png_ptr); | 175 return (png_ptr); |
| 174 } | 176 } |
| 175 | 177 |
| 176 #if defined(PNG_1_0_X) || defined(PNG_1_2_X) | 178 #if defined(PNG_1_0_X) || defined(PNG_1_2_X) |
| 177 /* Initialize PNG structure for reading, and allocate any memory needed. | 179 /* Initialize PNG structure for reading, and allocate any memory needed. |
| 178 This interface is deprecated in favour of the png_create_read_struct(), | 180 This interface is deprecated in favour of the png_create_read_struct(), |
| 179 and it will disappear as of libpng-1.3.0. */ | 181 and it will disappear as of libpng-1.3.0. */ |
| 180 #undef png_read_init | 182 #undef png_read_init |
| 181 void PNGAPI | 183 void PNGAPI |
| 182 png_read_init(png_structp png_ptr) | 184 png_read_init(png_structp png_ptr) |
| 183 { | 185 { |
| 184 /* We only come here via pre-1.0.7-compiled applications */ | 186 /* We only come here via pre-1.0.7-compiled applications */ |
| 185 png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0); | 187 png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0); |
| 186 } | 188 } |
| 187 | 189 |
| 188 void PNGAPI | 190 void PNGAPI |
| 189 png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver, | 191 png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver, |
| 190 png_size_t png_struct_size, png_size_t png_info_size) | 192 png_size_t png_struct_size, png_size_t png_info_size) |
| 191 { | 193 { |
| 192 /* We only come here via pre-1.0.12-compiled applications */ | 194 /* We only come here via pre-1.0.12-compiled applications */ |
| 193 if(png_ptr == NULL) return; | 195 if (png_ptr == NULL) return; |
| 194 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) | 196 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) |
| 195 if(png_sizeof(png_struct) > png_struct_size || | 197 if (png_sizeof(png_struct) > png_struct_size || |
| 196 png_sizeof(png_info) > png_info_size) | 198 png_sizeof(png_info) > png_info_size) |
| 197 { | 199 { |
| 198 char msg[80]; | 200 char msg[80]; |
| 199 png_ptr->warning_fn=NULL; | 201 png_ptr->warning_fn = NULL; |
| 200 if (user_png_ver) | 202 if (user_png_ver) |
| 201 { | 203 { |
| 202 png_snprintf(msg, 80, | 204 png_snprintf(msg, 80, |
| 203 "Application was compiled with png.h from libpng-%.20s", | 205 "Application was compiled with png.h from libpng-%.20s", |
| 204 user_png_ver); | 206 user_png_ver); |
| 205 png_warning(png_ptr, msg); | 207 png_warning(png_ptr, msg); |
| 206 } | 208 } |
| 207 png_snprintf(msg, 80, | 209 png_snprintf(msg, 80, |
| 208 "Application is running with png.c from libpng-%.20s", | 210 "Application is running with png.c from libpng-%.20s", |
| 209 png_libpng_ver); | 211 png_libpng_ver); |
| 210 png_warning(png_ptr, msg); | 212 png_warning(png_ptr, msg); |
| 211 } | 213 } |
| 212 #endif | 214 #endif |
| 213 if(png_sizeof(png_struct) > png_struct_size) | 215 if (png_sizeof(png_struct) > png_struct_size) |
| 214 { | 216 { |
| 215 png_ptr->error_fn=NULL; | 217 png_ptr->error_fn = NULL; |
| 216 #ifdef PNG_ERROR_NUMBERS_SUPPORTED | 218 #ifdef PNG_ERROR_NUMBERS_SUPPORTED |
| 217 png_ptr->flags=0; | 219 png_ptr->flags = 0; |
| 218 #endif | 220 #endif |
| 219 png_error(png_ptr, | 221 png_error(png_ptr, |
| 220 "The png struct allocated by the application for reading is too small."); | 222 "The png struct allocated by the application for reading is too small."); |
| 221 } | 223 } |
| 222 if(png_sizeof(png_info) > png_info_size) | 224 if (png_sizeof(png_info) > png_info_size) |
| 223 { | 225 { |
| 224 png_ptr->error_fn=NULL; | 226 png_ptr->error_fn = NULL; |
| 225 #ifdef PNG_ERROR_NUMBERS_SUPPORTED | 227 #ifdef PNG_ERROR_NUMBERS_SUPPORTED |
| 226 png_ptr->flags=0; | 228 png_ptr->flags = 0; |
| 227 #endif | 229 #endif |
| 228 png_error(png_ptr, | 230 png_error(png_ptr, |
| 229 "The info struct allocated by application for reading is too small."); | 231 "The info struct allocated by application for reading is too small."); |
| 230 } | 232 } |
| 231 png_read_init_3(&png_ptr, user_png_ver, png_struct_size); | 233 png_read_init_3(&png_ptr, user_png_ver, png_struct_size); |
| 232 } | 234 } |
| 233 #endif /* PNG_1_0_X || PNG_1_2_X */ | 235 #endif /* PNG_1_0_X || PNG_1_2_X */ |
| 234 | 236 |
| 235 void PNGAPI | 237 void PNGAPI |
| 236 png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, | 238 png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, |
| 237 png_size_t png_struct_size) | 239 png_size_t png_struct_size) |
| 238 { | 240 { |
| 239 #ifdef PNG_SETJMP_SUPPORTED | 241 #ifdef PNG_SETJMP_SUPPORTED |
| 240 jmp_buf tmp_jmp; /* to save current jump buffer */ | 242 jmp_buf tmp_jmp; /* to save current jump buffer */ |
| 241 #endif | 243 #endif |
| 242 | 244 |
| 243 int i=0; | 245 int i = 0; |
| 244 | 246 |
| 245 png_structp png_ptr=*ptr_ptr; | 247 png_structp png_ptr=*ptr_ptr; |
| 246 | 248 |
| 247 if(png_ptr == NULL) return; | 249 if (png_ptr == NULL) return; |
| 248 | 250 |
| 249 do | 251 do |
| 250 { | 252 { |
| 251 if(user_png_ver[i] != png_libpng_ver[i]) | 253 if (user_png_ver[i] != png_libpng_ver[i]) |
| 252 { | 254 { |
| 253 #ifdef PNG_LEGACY_SUPPORTED | 255 #ifdef PNG_LEGACY_SUPPORTED |
| 254 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; | 256 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; |
| 255 #else | 257 #else |
| 256 png_ptr->warning_fn=NULL; | 258 png_ptr->warning_fn = NULL; |
| 257 png_warning(png_ptr, | 259 png_warning(png_ptr, |
| 258 "Application uses deprecated png_read_init() and should be recompiled.")
; | 260 "Application uses deprecated png_read_init() and should be recompiled.")
; |
| 259 break; | 261 break; |
| 260 #endif | 262 #endif |
| 261 } | 263 } |
| 262 } while (png_libpng_ver[i++]); | 264 } while (png_libpng_ver[i++]); |
| 263 | 265 |
| 264 png_debug(1, "in png_read_init_3\n"); | 266 png_debug(1, "in png_read_init_3\n"); |
| 265 | 267 |
| 266 #ifdef PNG_SETJMP_SUPPORTED | 268 #ifdef PNG_SETJMP_SUPPORTED |
| 267 /* save jump buffer and error functions */ | 269 /* save jump buffer and error functions */ |
| 268 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf)); | 270 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf)); |
| 269 #endif | 271 #endif |
| 270 | 272 |
| 271 if(png_sizeof(png_struct) > png_struct_size) | 273 if (png_sizeof(png_struct) > png_struct_size) |
| 272 { | 274 { |
| 273 png_destroy_struct(png_ptr); | 275 png_destroy_struct(png_ptr); |
| 274 *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); | 276 *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); |
| 275 png_ptr = *ptr_ptr; | 277 png_ptr = *ptr_ptr; |
| 276 } | 278 } |
| 277 | 279 |
| 278 /* reset all variables to 0 */ | 280 /* reset all variables to 0 */ |
| 279 png_memset(png_ptr, 0, png_sizeof (png_struct)); | 281 png_memset(png_ptr, 0, png_sizeof(png_struct)); |
| 280 | 282 |
| 281 #ifdef PNG_SETJMP_SUPPORTED | 283 #ifdef PNG_SETJMP_SUPPORTED |
| 282 /* restore jump buffer */ | 284 /* restore jump buffer */ |
| 283 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf)); | 285 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf)); |
| 284 #endif | 286 #endif |
| 285 | 287 |
| 286 /* added at libpng-1.2.6 */ | 288 /* added at libpng-1.2.6 */ |
| 287 #ifdef PNG_SET_USER_LIMITS_SUPPORTED | 289 #ifdef PNG_SET_USER_LIMITS_SUPPORTED |
| 288 png_ptr->user_width_max=PNG_USER_WIDTH_MAX; | 290 png_ptr->user_width_max=PNG_USER_WIDTH_MAX; |
| 289 png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; | 291 png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; |
| 290 #endif | 292 #endif |
| 291 | 293 |
| 292 /* initialize zbuf - compression buffer */ | 294 /* initialize zbuf - compression buffer */ |
| 293 png_ptr->zbuf_size = PNG_ZBUF_SIZE; | 295 png_ptr->zbuf_size = PNG_ZBUF_SIZE; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 317 * changed in v0.90 to allow reading a file that already has the magic | 319 * changed in v0.90 to allow reading a file that already has the magic |
| 318 * bytes read from the stream. You can tell libpng how many bytes have | 320 * bytes read from the stream. You can tell libpng how many bytes have |
| 319 * been read from the beginning of the stream (up to the maximum of 8) | 321 * been read from the beginning of the stream (up to the maximum of 8) |
| 320 * via png_set_sig_bytes(), and we will only check the remaining bytes | 322 * via png_set_sig_bytes(), and we will only check the remaining bytes |
| 321 * here. The application can then have access to the signature bytes we | 323 * here. The application can then have access to the signature bytes we |
| 322 * read if it is determined that this isn't a valid PNG file. | 324 * read if it is determined that this isn't a valid PNG file. |
| 323 */ | 325 */ |
| 324 void PNGAPI | 326 void PNGAPI |
| 325 png_read_info(png_structp png_ptr, png_infop info_ptr) | 327 png_read_info(png_structp png_ptr, png_infop info_ptr) |
| 326 { | 328 { |
| 327 if(png_ptr == NULL || info_ptr == NULL) return; | 329 if (png_ptr == NULL || info_ptr == NULL) return; |
| 328 png_debug(1, "in png_read_info\n"); | 330 png_debug(1, "in png_read_info\n"); |
| 329 /* If we haven't checked all of the PNG signature bytes, do so now. */ | 331 /* If we haven't checked all of the PNG signature bytes, do so now. */ |
| 330 if (png_ptr->sig_bytes < 8) | 332 if (png_ptr->sig_bytes < 8) |
| 331 { | 333 { |
| 332 png_size_t num_checked = png_ptr->sig_bytes, | 334 png_size_t num_checked = png_ptr->sig_bytes, |
| 333 num_to_check = 8 - num_checked; | 335 num_to_check = 8 - num_checked; |
| 334 | 336 |
| 335 png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check); | 337 png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check); |
| 336 png_ptr->sig_bytes = 8; | 338 png_ptr->sig_bytes = 8; |
| 337 | 339 |
| 338 if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check)) | 340 if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check)) |
| 339 { | 341 { |
| 340 if (num_checked < 4 && | 342 if (num_checked < 4 && |
| 341 png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4)) | 343 png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4)) |
| 342 png_error(png_ptr, "Not a PNG file"); | 344 png_error(png_ptr, "Not a PNG file"); |
| 343 else | 345 else |
| 344 png_error(png_ptr, "PNG file corrupted by ASCII conversion"); | 346 png_error(png_ptr, "PNG file corrupted by ASCII conversion"); |
| 345 } | 347 } |
| 346 if (num_checked < 3) | 348 if (num_checked < 3) |
| 347 png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; | 349 png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; |
| 348 } | 350 } |
| 349 | 351 |
| 350 for(;;) | 352 for (;;) |
| 351 { | 353 { |
| 352 #ifdef PNG_USE_LOCAL_ARRAYS | 354 #ifdef PNG_USE_LOCAL_ARRAYS |
| 353 PNG_CONST PNG_IHDR; | 355 PNG_CONST PNG_IHDR; |
| 354 PNG_CONST PNG_IDAT; | 356 PNG_CONST PNG_IDAT; |
| 355 PNG_CONST PNG_IEND; | 357 PNG_CONST PNG_IEND; |
| 356 PNG_CONST PNG_PLTE; | 358 PNG_CONST PNG_PLTE; |
| 357 #if defined(PNG_READ_bKGD_SUPPORTED) | 359 #if defined(PNG_READ_bKGD_SUPPORTED) |
| 358 PNG_CONST PNG_bKGD; | 360 PNG_CONST PNG_bKGD; |
| 359 #endif | 361 #endif |
| 360 #if defined(PNG_READ_cHRM_SUPPORTED) | 362 #if defined(PNG_READ_cHRM_SUPPORTED) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 #if defined(PNG_READ_tIME_SUPPORTED) | 401 #if defined(PNG_READ_tIME_SUPPORTED) |
| 400 PNG_CONST PNG_tIME; | 402 PNG_CONST PNG_tIME; |
| 401 #endif | 403 #endif |
| 402 #if defined(PNG_READ_tRNS_SUPPORTED) | 404 #if defined(PNG_READ_tRNS_SUPPORTED) |
| 403 PNG_CONST PNG_tRNS; | 405 PNG_CONST PNG_tRNS; |
| 404 #endif | 406 #endif |
| 405 #if defined(PNG_READ_zTXt_SUPPORTED) | 407 #if defined(PNG_READ_zTXt_SUPPORTED) |
| 406 PNG_CONST PNG_zTXt; | 408 PNG_CONST PNG_zTXt; |
| 407 #endif | 409 #endif |
| 408 #endif /* PNG_USE_LOCAL_ARRAYS */ | 410 #endif /* PNG_USE_LOCAL_ARRAYS */ |
| 409 png_byte chunk_length[4]; | 411 png_uint_32 length = png_read_chunk_header(png_ptr); |
| 410 png_uint_32 length; | 412 PNG_CONST png_bytep chunk_name = png_ptr->chunk_name; |
| 411 | |
| 412 png_read_data(png_ptr, chunk_length, 4); | |
| 413 length = png_get_uint_31(png_ptr,chunk_length); | |
| 414 | |
| 415 png_reset_crc(png_ptr); | |
| 416 png_crc_read(png_ptr, png_ptr->chunk_name, 4); | |
| 417 | |
| 418 png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name, | |
| 419 length); | |
| 420 | 413 |
| 421 /* This should be a binary subdivision search or a hash for | 414 /* This should be a binary subdivision search or a hash for |
| 422 * matching the chunk name rather than a linear search. | 415 * matching the chunk name rather than a linear search. |
| 423 */ | 416 */ |
| 424 if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) | 417 if (!png_memcmp(chunk_name, png_IDAT, 4)) |
| 425 if(png_ptr->mode & PNG_AFTER_IDAT) | 418 if (png_ptr->mode & PNG_AFTER_IDAT) |
| 426 png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; | 419 png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; |
| 427 | 420 |
| 428 if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4)) | 421 if (!png_memcmp(chunk_name, png_IHDR, 4)) |
| 429 png_handle_IHDR(png_ptr, info_ptr, length); | 422 png_handle_IHDR(png_ptr, info_ptr, length); |
| 430 else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4)) | 423 else if (!png_memcmp(chunk_name, png_IEND, 4)) |
| 431 png_handle_IEND(png_ptr, info_ptr, length); | 424 png_handle_IEND(png_ptr, info_ptr, length); |
| 432 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED | 425 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
| 433 else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name)) | 426 else if (png_handle_as_unknown(png_ptr, chunk_name)) |
| 434 { | 427 { |
| 435 if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) | 428 if (!png_memcmp(chunk_name, png_IDAT, 4)) |
| 436 png_ptr->mode |= PNG_HAVE_IDAT; | 429 png_ptr->mode |= PNG_HAVE_IDAT; |
| 437 png_handle_unknown(png_ptr, info_ptr, length); | 430 png_handle_unknown(png_ptr, info_ptr, length); |
| 438 if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) | 431 if (!png_memcmp(chunk_name, png_PLTE, 4)) |
| 439 png_ptr->mode |= PNG_HAVE_PLTE; | 432 png_ptr->mode |= PNG_HAVE_PLTE; |
| 440 else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) | 433 else if (!png_memcmp(chunk_name, png_IDAT, 4)) |
| 441 { | 434 { |
| 442 if (!(png_ptr->mode & PNG_HAVE_IHDR)) | 435 if (!(png_ptr->mode & PNG_HAVE_IHDR)) |
| 443 png_error(png_ptr, "Missing IHDR before IDAT"); | 436 png_error(png_ptr, "Missing IHDR before IDAT"); |
| 444 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && | 437 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && |
| 445 !(png_ptr->mode & PNG_HAVE_PLTE)) | 438 !(png_ptr->mode & PNG_HAVE_PLTE)) |
| 446 png_error(png_ptr, "Missing PLTE before IDAT"); | 439 png_error(png_ptr, "Missing PLTE before IDAT"); |
| 447 break; | 440 break; |
| 448 } | 441 } |
| 449 } | 442 } |
| 450 #endif | 443 #endif |
| 451 else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) | 444 else if (!png_memcmp(chunk_name, png_PLTE, 4)) |
| 452 png_handle_PLTE(png_ptr, info_ptr, length); | 445 png_handle_PLTE(png_ptr, info_ptr, length); |
| 453 else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) | 446 else if (!png_memcmp(chunk_name, png_IDAT, 4)) |
| 454 { | 447 { |
| 455 if (!(png_ptr->mode & PNG_HAVE_IHDR)) | 448 if (!(png_ptr->mode & PNG_HAVE_IHDR)) |
| 456 png_error(png_ptr, "Missing IHDR before IDAT"); | 449 png_error(png_ptr, "Missing IHDR before IDAT"); |
| 457 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && | 450 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && |
| 458 !(png_ptr->mode & PNG_HAVE_PLTE)) | 451 !(png_ptr->mode & PNG_HAVE_PLTE)) |
| 459 png_error(png_ptr, "Missing PLTE before IDAT"); | 452 png_error(png_ptr, "Missing PLTE before IDAT"); |
| 460 | 453 |
| 461 png_ptr->idat_size = length; | 454 png_ptr->idat_size = length; |
| 462 png_ptr->mode |= PNG_HAVE_IDAT; | 455 png_ptr->mode |= PNG_HAVE_IDAT; |
| 463 break; | 456 break; |
| 464 } | 457 } |
| 465 #if defined(PNG_READ_bKGD_SUPPORTED) | 458 #if defined(PNG_READ_bKGD_SUPPORTED) |
| 466 else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4)) | 459 else if (!png_memcmp(chunk_name, png_bKGD, 4)) |
| 467 png_handle_bKGD(png_ptr, info_ptr, length); | 460 png_handle_bKGD(png_ptr, info_ptr, length); |
| 468 #endif | 461 #endif |
| 469 #if defined(PNG_READ_cHRM_SUPPORTED) | 462 #if defined(PNG_READ_cHRM_SUPPORTED) |
| 470 else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4)) | 463 else if (!png_memcmp(chunk_name, png_cHRM, 4)) |
| 471 png_handle_cHRM(png_ptr, info_ptr, length); | 464 png_handle_cHRM(png_ptr, info_ptr, length); |
| 472 #endif | 465 #endif |
| 473 #if defined(PNG_READ_gAMA_SUPPORTED) | 466 #if defined(PNG_READ_gAMA_SUPPORTED) |
| 474 else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4)) | 467 else if (!png_memcmp(chunk_name, png_gAMA, 4)) |
| 475 png_handle_gAMA(png_ptr, info_ptr, length); | 468 png_handle_gAMA(png_ptr, info_ptr, length); |
| 476 #endif | 469 #endif |
| 477 #if defined(PNG_READ_hIST_SUPPORTED) | 470 #if defined(PNG_READ_hIST_SUPPORTED) |
| 478 else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4)) | 471 else if (!png_memcmp(chunk_name, png_hIST, 4)) |
| 479 png_handle_hIST(png_ptr, info_ptr, length); | 472 png_handle_hIST(png_ptr, info_ptr, length); |
| 480 #endif | 473 #endif |
| 481 #if defined(PNG_READ_oFFs_SUPPORTED) | 474 #if defined(PNG_READ_oFFs_SUPPORTED) |
| 482 else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4)) | 475 else if (!png_memcmp(chunk_name, png_oFFs, 4)) |
| 483 png_handle_oFFs(png_ptr, info_ptr, length); | 476 png_handle_oFFs(png_ptr, info_ptr, length); |
| 484 #endif | 477 #endif |
| 485 #if defined(PNG_READ_pCAL_SUPPORTED) | 478 #if defined(PNG_READ_pCAL_SUPPORTED) |
| 486 else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4)) | 479 else if (!png_memcmp(chunk_name, png_pCAL, 4)) |
| 487 png_handle_pCAL(png_ptr, info_ptr, length); | 480 png_handle_pCAL(png_ptr, info_ptr, length); |
| 488 #endif | 481 #endif |
| 489 #if defined(PNG_READ_sCAL_SUPPORTED) | 482 #if defined(PNG_READ_sCAL_SUPPORTED) |
| 490 else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4)) | 483 else if (!png_memcmp(chunk_name, png_sCAL, 4)) |
| 491 png_handle_sCAL(png_ptr, info_ptr, length); | 484 png_handle_sCAL(png_ptr, info_ptr, length); |
| 492 #endif | 485 #endif |
| 493 #if defined(PNG_READ_pHYs_SUPPORTED) | 486 #if defined(PNG_READ_pHYs_SUPPORTED) |
| 494 else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4)) | 487 else if (!png_memcmp(chunk_name, png_pHYs, 4)) |
| 495 png_handle_pHYs(png_ptr, info_ptr, length); | 488 png_handle_pHYs(png_ptr, info_ptr, length); |
| 496 #endif | 489 #endif |
| 497 #if defined(PNG_READ_sBIT_SUPPORTED) | 490 #if defined(PNG_READ_sBIT_SUPPORTED) |
| 498 else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4)) | 491 else if (!png_memcmp(chunk_name, png_sBIT, 4)) |
| 499 png_handle_sBIT(png_ptr, info_ptr, length); | 492 png_handle_sBIT(png_ptr, info_ptr, length); |
| 500 #endif | 493 #endif |
| 501 #if defined(PNG_READ_sRGB_SUPPORTED) | 494 #if defined(PNG_READ_sRGB_SUPPORTED) |
| 502 else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4)) | 495 else if (!png_memcmp(chunk_name, png_sRGB, 4)) |
| 503 png_handle_sRGB(png_ptr, info_ptr, length); | 496 png_handle_sRGB(png_ptr, info_ptr, length); |
| 504 #endif | 497 #endif |
| 505 #if defined(PNG_READ_iCCP_SUPPORTED) | 498 #if defined(PNG_READ_iCCP_SUPPORTED) |
| 506 else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4)) | 499 else if (!png_memcmp(chunk_name, png_iCCP, 4)) |
| 507 png_handle_iCCP(png_ptr, info_ptr, length); | 500 png_handle_iCCP(png_ptr, info_ptr, length); |
| 508 #endif | 501 #endif |
| 509 #if defined(PNG_READ_sPLT_SUPPORTED) | 502 #if defined(PNG_READ_sPLT_SUPPORTED) |
| 510 else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4)) | 503 else if (!png_memcmp(chunk_name, png_sPLT, 4)) |
| 511 png_handle_sPLT(png_ptr, info_ptr, length); | 504 png_handle_sPLT(png_ptr, info_ptr, length); |
| 512 #endif | 505 #endif |
| 513 #if defined(PNG_READ_tEXt_SUPPORTED) | 506 #if defined(PNG_READ_tEXt_SUPPORTED) |
| 514 else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4)) | 507 else if (!png_memcmp(chunk_name, png_tEXt, 4)) |
| 515 png_handle_tEXt(png_ptr, info_ptr, length); | 508 png_handle_tEXt(png_ptr, info_ptr, length); |
| 516 #endif | 509 #endif |
| 517 #if defined(PNG_READ_tIME_SUPPORTED) | 510 #if defined(PNG_READ_tIME_SUPPORTED) |
| 518 else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4)) | 511 else if (!png_memcmp(chunk_name, png_tIME, 4)) |
| 519 png_handle_tIME(png_ptr, info_ptr, length); | 512 png_handle_tIME(png_ptr, info_ptr, length); |
| 520 #endif | 513 #endif |
| 521 #if defined(PNG_READ_tRNS_SUPPORTED) | 514 #if defined(PNG_READ_tRNS_SUPPORTED) |
| 522 else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4)) | 515 else if (!png_memcmp(chunk_name, png_tRNS, 4)) |
| 523 png_handle_tRNS(png_ptr, info_ptr, length); | 516 png_handle_tRNS(png_ptr, info_ptr, length); |
| 524 #endif | 517 #endif |
| 525 #if defined(PNG_READ_zTXt_SUPPORTED) | 518 #if defined(PNG_READ_zTXt_SUPPORTED) |
| 526 else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4)) | 519 else if (!png_memcmp(chunk_name, png_zTXt, 4)) |
| 527 png_handle_zTXt(png_ptr, info_ptr, length); | 520 png_handle_zTXt(png_ptr, info_ptr, length); |
| 528 #endif | 521 #endif |
| 529 #if defined(PNG_READ_iTXt_SUPPORTED) | 522 #if defined(PNG_READ_iTXt_SUPPORTED) |
| 530 else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4)) | 523 else if (!png_memcmp(chunk_name, png_iTXt, 4)) |
| 531 png_handle_iTXt(png_ptr, info_ptr, length); | 524 png_handle_iTXt(png_ptr, info_ptr, length); |
| 532 #endif | 525 #endif |
| 533 else | 526 else |
| 534 png_handle_unknown(png_ptr, info_ptr, length); | 527 png_handle_unknown(png_ptr, info_ptr, length); |
| 535 } | 528 } |
| 536 } | 529 } |
| 537 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ | 530 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ |
| 538 | 531 |
| 539 /* optional call to update the users info_ptr structure */ | 532 /* optional call to update the users info_ptr structure */ |
| 540 void PNGAPI | 533 void PNGAPI |
| 541 png_read_update_info(png_structp png_ptr, png_infop info_ptr) | 534 png_read_update_info(png_structp png_ptr, png_infop info_ptr) |
| 542 { | 535 { |
| 543 png_debug(1, "in png_read_update_info\n"); | 536 png_debug(1, "in png_read_update_info\n"); |
| 544 if(png_ptr == NULL) return; | 537 if (png_ptr == NULL) return; |
| 545 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) | 538 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
| 546 png_read_start_row(png_ptr); | 539 png_read_start_row(png_ptr); |
| 547 else | 540 else |
| 548 png_warning(png_ptr, | 541 png_warning(png_ptr, |
| 549 "Ignoring extra png_read_update_info() call; row buffer not reallocated"); | 542 "Ignoring extra png_read_update_info() call; row buffer not reallocated"); |
| 550 png_read_transform_info(png_ptr, info_ptr); | 543 png_read_transform_info(png_ptr, info_ptr); |
| 551 } | 544 } |
| 552 | 545 |
| 553 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED | 546 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED |
| 554 /* Initialize palette, background, etc, after transformations | 547 /* Initialize palette, background, etc, after transformations |
| 555 * are set, but before any reading takes place. This allows | 548 * are set, but before any reading takes place. This allows |
| 556 * the user to obtain a gamma-corrected palette, for example. | 549 * the user to obtain a gamma-corrected palette, for example. |
| 557 * If the user doesn't call this, we will do it ourselves. | 550 * If the user doesn't call this, we will do it ourselves. |
| 558 */ | 551 */ |
| 559 void PNGAPI | 552 void PNGAPI |
| 560 png_start_read_image(png_structp png_ptr) | 553 png_start_read_image(png_structp png_ptr) |
| 561 { | 554 { |
| 562 png_debug(1, "in png_start_read_image\n"); | 555 png_debug(1, "in png_start_read_image\n"); |
| 563 if(png_ptr == NULL) return; | 556 if (png_ptr == NULL) return; |
| 564 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) | 557 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
| 565 png_read_start_row(png_ptr); | 558 png_read_start_row(png_ptr); |
| 566 } | 559 } |
| 567 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ | 560 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ |
| 568 | 561 |
| 569 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED | 562 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED |
| 570 void PNGAPI | 563 void PNGAPI |
| 571 png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) | 564 png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) |
| 572 { | 565 { |
| 573 #ifdef PNG_USE_LOCAL_ARRAYS | 566 #ifdef PNG_USE_LOCAL_ARRAYS |
| 574 PNG_CONST PNG_IDAT; | 567 PNG_CONST PNG_IDAT; |
| 575 PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, | 568 PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, |
| 576 0xff}; | 569 0xff}; |
| 577 PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; | 570 PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; |
| 578 #endif | 571 #endif |
| 579 int ret; | 572 int ret; |
| 580 if(png_ptr == NULL) return; | 573 if (png_ptr == NULL) return; |
| 581 png_debug2(1, "in png_read_row (row %lu, pass %d)\n", | 574 png_debug2(1, "in png_read_row (row %lu, pass %d)\n", |
| 582 png_ptr->row_number, png_ptr->pass); | 575 png_ptr->row_number, png_ptr->pass); |
| 583 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) | 576 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
| 584 png_read_start_row(png_ptr); | 577 png_read_start_row(png_ptr); |
| 585 if (png_ptr->row_number == 0 && png_ptr->pass == 0) | 578 if (png_ptr->row_number == 0 && png_ptr->pass == 0) |
| 586 { | 579 { |
| 587 /* check for transforms that have been set but were defined out */ | 580 /* check for transforms that have been set but were defined out */ |
| 588 #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED) | 581 #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED) |
| 589 if (png_ptr->transformations & PNG_INVERT_MONO) | 582 if (png_ptr->transformations & PNG_INVERT_MONO) |
| 590 png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined."); | 583 png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined."); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 png_error(png_ptr, "Invalid attempt to read row data"); | 689 png_error(png_ptr, "Invalid attempt to read row data"); |
| 697 | 690 |
| 698 png_ptr->zstream.next_out = png_ptr->row_buf; | 691 png_ptr->zstream.next_out = png_ptr->row_buf; |
| 699 png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes; | 692 png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes; |
| 700 do | 693 do |
| 701 { | 694 { |
| 702 if (!(png_ptr->zstream.avail_in)) | 695 if (!(png_ptr->zstream.avail_in)) |
| 703 { | 696 { |
| 704 while (!png_ptr->idat_size) | 697 while (!png_ptr->idat_size) |
| 705 { | 698 { |
| 706 png_byte chunk_length[4]; | |
| 707 | |
| 708 png_crc_finish(png_ptr, 0); | 699 png_crc_finish(png_ptr, 0); |
| 709 | 700 |
| 710 png_read_data(png_ptr, chunk_length, 4); | 701 png_ptr->idat_size = png_read_chunk_header(png_ptr); |
| 711 png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length); | |
| 712 | |
| 713 png_reset_crc(png_ptr); | |
| 714 png_crc_read(png_ptr, png_ptr->chunk_name, 4); | |
| 715 if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) | 702 if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) |
| 716 png_error(png_ptr, "Not enough image data"); | 703 png_error(png_ptr, "Not enough image data"); |
| 717 } | 704 } |
| 718 png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size; | 705 png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size; |
| 719 png_ptr->zstream.next_in = png_ptr->zbuf; | 706 png_ptr->zstream.next_in = png_ptr->zbuf; |
| 720 if (png_ptr->zbuf_size > png_ptr->idat_size) | 707 if (png_ptr->zbuf_size > png_ptr->idat_size) |
| 721 png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size; | 708 png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size; |
| 722 png_crc_read(png_ptr, png_ptr->zbuf, | 709 png_crc_read(png_ptr, png_ptr->zbuf, |
| 723 (png_size_t)png_ptr->zstream.avail_in); | 710 (png_size_t)png_ptr->zstream.avail_in); |
| 724 png_ptr->idat_size -= png_ptr->zstream.avail_in; | 711 png_ptr->idat_size -= png_ptr->zstream.avail_in; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 740 } while (png_ptr->zstream.avail_out); | 727 } while (png_ptr->zstream.avail_out); |
| 741 | 728 |
| 742 png_ptr->row_info.color_type = png_ptr->color_type; | 729 png_ptr->row_info.color_type = png_ptr->color_type; |
| 743 png_ptr->row_info.width = png_ptr->iwidth; | 730 png_ptr->row_info.width = png_ptr->iwidth; |
| 744 png_ptr->row_info.channels = png_ptr->channels; | 731 png_ptr->row_info.channels = png_ptr->channels; |
| 745 png_ptr->row_info.bit_depth = png_ptr->bit_depth; | 732 png_ptr->row_info.bit_depth = png_ptr->bit_depth; |
| 746 png_ptr->row_info.pixel_depth = png_ptr->pixel_depth; | 733 png_ptr->row_info.pixel_depth = png_ptr->pixel_depth; |
| 747 png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, | 734 png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, |
| 748 png_ptr->row_info.width); | 735 png_ptr->row_info.width); |
| 749 | 736 |
| 750 if(png_ptr->row_buf[0]) | 737 if (png_ptr->row_buf[0]) |
| 751 png_read_filter_row(png_ptr, &(png_ptr->row_info), | 738 png_read_filter_row(png_ptr, &(png_ptr->row_info), |
| 752 png_ptr->row_buf + 1, png_ptr->prev_row + 1, | 739 png_ptr->row_buf + 1, png_ptr->prev_row + 1, |
| 753 (int)(png_ptr->row_buf[0])); | 740 (int)(png_ptr->row_buf[0])); |
| 754 | 741 |
| 755 png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf, | 742 png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf, |
| 756 png_ptr->rowbytes + 1); | 743 png_ptr->rowbytes + 1); |
| 757 | 744 |
| 758 #if defined(PNG_MNG_FEATURES_SUPPORTED) | 745 #if defined(PNG_MNG_FEATURES_SUPPORTED) |
| 759 if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && | 746 if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && |
| 760 (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) | 747 (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) |
| 761 { | 748 { |
| 762 /* Intrapixel differencing */ | 749 /* Intrapixel differencing */ |
| 763 png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1); | 750 png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1); |
| 764 } | 751 } |
| 765 #endif | 752 #endif |
| 766 | 753 |
| 767 | 754 |
| 768 if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA)) | 755 if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA)) |
| 769 png_do_read_transformations(png_ptr); | 756 png_do_read_transformations(png_ptr); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 | 816 |
| 830 void PNGAPI | 817 void PNGAPI |
| 831 png_read_rows(png_structp png_ptr, png_bytepp row, | 818 png_read_rows(png_structp png_ptr, png_bytepp row, |
| 832 png_bytepp display_row, png_uint_32 num_rows) | 819 png_bytepp display_row, png_uint_32 num_rows) |
| 833 { | 820 { |
| 834 png_uint_32 i; | 821 png_uint_32 i; |
| 835 png_bytepp rp; | 822 png_bytepp rp; |
| 836 png_bytepp dp; | 823 png_bytepp dp; |
| 837 | 824 |
| 838 png_debug(1, "in png_read_rows\n"); | 825 png_debug(1, "in png_read_rows\n"); |
| 839 if(png_ptr == NULL) return; | 826 if (png_ptr == NULL) return; |
| 840 rp = row; | 827 rp = row; |
| 841 dp = display_row; | 828 dp = display_row; |
| 842 if (rp != NULL && dp != NULL) | 829 if (rp != NULL && dp != NULL) |
| 843 for (i = 0; i < num_rows; i++) | 830 for (i = 0; i < num_rows; i++) |
| 844 { | 831 { |
| 845 png_bytep rptr = *rp++; | 832 png_bytep rptr = *rp++; |
| 846 png_bytep dptr = *dp++; | 833 png_bytep dptr = *dp++; |
| 847 | 834 |
| 848 png_read_row(png_ptr, rptr, dptr); | 835 png_read_row(png_ptr, rptr, dptr); |
| 849 } | 836 } |
| 850 else if(rp != NULL) | 837 else if (rp != NULL) |
| 851 for (i = 0; i < num_rows; i++) | 838 for (i = 0; i < num_rows; i++) |
| 852 { | 839 { |
| 853 png_bytep rptr = *rp; | 840 png_bytep rptr = *rp; |
| 854 png_read_row(png_ptr, rptr, png_bytep_NULL); | 841 png_read_row(png_ptr, rptr, png_bytep_NULL); |
| 855 rp++; | 842 rp++; |
| 856 } | 843 } |
| 857 else if(dp != NULL) | 844 else if (dp != NULL) |
| 858 for (i = 0; i < num_rows; i++) | 845 for (i = 0; i < num_rows; i++) |
| 859 { | 846 { |
| 860 png_bytep dptr = *dp; | 847 png_bytep dptr = *dp; |
| 861 png_read_row(png_ptr, png_bytep_NULL, dptr); | 848 png_read_row(png_ptr, png_bytep_NULL, dptr); |
| 862 dp++; | 849 dp++; |
| 863 } | 850 } |
| 864 } | 851 } |
| 865 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ | 852 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ |
| 866 | 853 |
| 867 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED | 854 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED |
| 868 /* Read the entire image. If the image has an alpha channel or a tRNS | 855 /* Read the entire image. If the image has an alpha channel or a tRNS |
| 869 * chunk, and you have called png_handle_alpha()[*], you will need to | 856 * chunk, and you have called png_handle_alpha()[*], you will need to |
| 870 * initialize the image to the current image that PNG will be overlaying. | 857 * initialize the image to the current image that PNG will be overlaying. |
| 871 * We set the num_rows again here, in case it was incorrectly set in | 858 * We set the num_rows again here, in case it was incorrectly set in |
| 872 * png_read_start_row() by a call to png_read_update_info() or | 859 * png_read_start_row() by a call to png_read_update_info() or |
| 873 * png_start_read_image() if png_set_interlace_handling() wasn't called | 860 * png_start_read_image() if png_set_interlace_handling() wasn't called |
| 874 * prior to either of these functions like it should have been. You can | 861 * prior to either of these functions like it should have been. You can |
| 875 * only call this function once. If you desire to have an image for | 862 * only call this function once. If you desire to have an image for |
| 876 * each pass of a interlaced image, use png_read_rows() instead. | 863 * each pass of a interlaced image, use png_read_rows() instead. |
| 877 * | 864 * |
| 878 * [*] png_handle_alpha() does not exist yet, as of this version of libpng | 865 * [*] png_handle_alpha() does not exist yet, as of this version of libpng |
| 879 */ | 866 */ |
| 880 void PNGAPI | 867 void PNGAPI |
| 881 png_read_image(png_structp png_ptr, png_bytepp image) | 868 png_read_image(png_structp png_ptr, png_bytepp image) |
| 882 { | 869 { |
| 883 png_uint_32 i,image_height; | 870 png_uint_32 i, image_height; |
| 884 int pass, j; | 871 int pass, j; |
| 885 png_bytepp rp; | 872 png_bytepp rp; |
| 886 | 873 |
| 887 png_debug(1, "in png_read_image\n"); | 874 png_debug(1, "in png_read_image\n"); |
| 888 if(png_ptr == NULL) return; | 875 if (png_ptr == NULL) return; |
| 889 | 876 |
| 890 #ifdef PNG_READ_INTERLACING_SUPPORTED | 877 #ifdef PNG_READ_INTERLACING_SUPPORTED |
| 891 pass = png_set_interlace_handling(png_ptr); | 878 pass = png_set_interlace_handling(png_ptr); |
| 892 #else | 879 #else |
| 893 if (png_ptr->interlaced) | 880 if (png_ptr->interlaced) |
| 894 png_error(png_ptr, | 881 png_error(png_ptr, |
| 895 "Cannot read interlaced image -- interlace handler disabled."); | 882 "Cannot read interlaced image -- interlace handler disabled."); |
| 896 pass = 1; | 883 pass = 1; |
| 897 #endif | 884 #endif |
| 898 | 885 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 913 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ | 900 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ |
| 914 | 901 |
| 915 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED | 902 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED |
| 916 /* Read the end of the PNG file. Will not read past the end of the | 903 /* Read the end of the PNG file. Will not read past the end of the |
| 917 * file, will verify the end is accurate, and will read any comments | 904 * file, will verify the end is accurate, and will read any comments |
| 918 * or time information at the end of the file, if info is not NULL. | 905 * or time information at the end of the file, if info is not NULL. |
| 919 */ | 906 */ |
| 920 void PNGAPI | 907 void PNGAPI |
| 921 png_read_end(png_structp png_ptr, png_infop info_ptr) | 908 png_read_end(png_structp png_ptr, png_infop info_ptr) |
| 922 { | 909 { |
| 923 png_byte chunk_length[4]; | |
| 924 png_uint_32 length; | |
| 925 | |
| 926 png_debug(1, "in png_read_end\n"); | 910 png_debug(1, "in png_read_end\n"); |
| 927 if(png_ptr == NULL) return; | 911 if (png_ptr == NULL) return; |
| 928 png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */ | 912 png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */ |
| 929 | 913 |
| 930 do | 914 do |
| 931 { | 915 { |
| 932 #ifdef PNG_USE_LOCAL_ARRAYS | 916 #ifdef PNG_USE_LOCAL_ARRAYS |
| 933 PNG_CONST PNG_IHDR; | 917 PNG_CONST PNG_IHDR; |
| 934 PNG_CONST PNG_IDAT; | 918 PNG_CONST PNG_IDAT; |
| 935 PNG_CONST PNG_IEND; | 919 PNG_CONST PNG_IEND; |
| 936 PNG_CONST PNG_PLTE; | 920 PNG_CONST PNG_PLTE; |
| 937 #if defined(PNG_READ_bKGD_SUPPORTED) | 921 #if defined(PNG_READ_bKGD_SUPPORTED) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 #if defined(PNG_READ_tIME_SUPPORTED) | 963 #if defined(PNG_READ_tIME_SUPPORTED) |
| 980 PNG_CONST PNG_tIME; | 964 PNG_CONST PNG_tIME; |
| 981 #endif | 965 #endif |
| 982 #if defined(PNG_READ_tRNS_SUPPORTED) | 966 #if defined(PNG_READ_tRNS_SUPPORTED) |
| 983 PNG_CONST PNG_tRNS; | 967 PNG_CONST PNG_tRNS; |
| 984 #endif | 968 #endif |
| 985 #if defined(PNG_READ_zTXt_SUPPORTED) | 969 #if defined(PNG_READ_zTXt_SUPPORTED) |
| 986 PNG_CONST PNG_zTXt; | 970 PNG_CONST PNG_zTXt; |
| 987 #endif | 971 #endif |
| 988 #endif /* PNG_USE_LOCAL_ARRAYS */ | 972 #endif /* PNG_USE_LOCAL_ARRAYS */ |
| 973 png_uint_32 length = png_read_chunk_header(png_ptr); |
| 974 PNG_CONST png_bytep chunk_name = png_ptr->chunk_name; |
| 989 | 975 |
| 990 png_read_data(png_ptr, chunk_length, 4); | 976 if (!png_memcmp(chunk_name, png_IHDR, 4)) |
| 991 length = png_get_uint_31(png_ptr,chunk_length); | |
| 992 | |
| 993 png_reset_crc(png_ptr); | |
| 994 png_crc_read(png_ptr, png_ptr->chunk_name, 4); | |
| 995 | |
| 996 png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name); | |
| 997 | |
| 998 if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4)) | |
| 999 png_handle_IHDR(png_ptr, info_ptr, length); | 977 png_handle_IHDR(png_ptr, info_ptr, length); |
| 1000 else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4)) | 978 else if (!png_memcmp(chunk_name, png_IEND, 4)) |
| 1001 png_handle_IEND(png_ptr, info_ptr, length); | 979 png_handle_IEND(png_ptr, info_ptr, length); |
| 1002 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED | 980 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
| 1003 else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name)) | 981 else if (png_handle_as_unknown(png_ptr, chunk_name)) |
| 1004 { | 982 { |
| 1005 if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) | 983 if (!png_memcmp(chunk_name, png_IDAT, 4)) |
| 1006 { | 984 { |
| 1007 if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) | 985 if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) |
| 1008 png_error(png_ptr, "Too many IDAT's found"); | 986 png_error(png_ptr, "Too many IDAT's found"); |
| 1009 } | 987 } |
| 1010 png_handle_unknown(png_ptr, info_ptr, length); | 988 png_handle_unknown(png_ptr, info_ptr, length); |
| 1011 if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) | 989 if (!png_memcmp(chunk_name, png_PLTE, 4)) |
| 1012 png_ptr->mode |= PNG_HAVE_PLTE; | 990 png_ptr->mode |= PNG_HAVE_PLTE; |
| 1013 } | 991 } |
| 1014 #endif | 992 #endif |
| 1015 else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) | 993 else if (!png_memcmp(chunk_name, png_IDAT, 4)) |
| 1016 { | 994 { |
| 1017 /* Zero length IDATs are legal after the last IDAT has been | 995 /* Zero length IDATs are legal after the last IDAT has been |
| 1018 * read, but not after other chunks have been read. | 996 * read, but not after other chunks have been read. |
| 1019 */ | 997 */ |
| 1020 if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) | 998 if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) |
| 1021 png_error(png_ptr, "Too many IDAT's found"); | 999 png_error(png_ptr, "Too many IDAT's found"); |
| 1022 png_crc_finish(png_ptr, length); | 1000 png_crc_finish(png_ptr, length); |
| 1023 } | 1001 } |
| 1024 else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) | 1002 else if (!png_memcmp(chunk_name, png_PLTE, 4)) |
| 1025 png_handle_PLTE(png_ptr, info_ptr, length); | 1003 png_handle_PLTE(png_ptr, info_ptr, length); |
| 1026 #if defined(PNG_READ_bKGD_SUPPORTED) | 1004 #if defined(PNG_READ_bKGD_SUPPORTED) |
| 1027 else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4)) | 1005 else if (!png_memcmp(chunk_name, png_bKGD, 4)) |
| 1028 png_handle_bKGD(png_ptr, info_ptr, length); | 1006 png_handle_bKGD(png_ptr, info_ptr, length); |
| 1029 #endif | 1007 #endif |
| 1030 #if defined(PNG_READ_cHRM_SUPPORTED) | 1008 #if defined(PNG_READ_cHRM_SUPPORTED) |
| 1031 else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4)) | 1009 else if (!png_memcmp(chunk_name, png_cHRM, 4)) |
| 1032 png_handle_cHRM(png_ptr, info_ptr, length); | 1010 png_handle_cHRM(png_ptr, info_ptr, length); |
| 1033 #endif | 1011 #endif |
| 1034 #if defined(PNG_READ_gAMA_SUPPORTED) | 1012 #if defined(PNG_READ_gAMA_SUPPORTED) |
| 1035 else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4)) | 1013 else if (!png_memcmp(chunk_name, png_gAMA, 4)) |
| 1036 png_handle_gAMA(png_ptr, info_ptr, length); | 1014 png_handle_gAMA(png_ptr, info_ptr, length); |
| 1037 #endif | 1015 #endif |
| 1038 #if defined(PNG_READ_hIST_SUPPORTED) | 1016 #if defined(PNG_READ_hIST_SUPPORTED) |
| 1039 else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4)) | 1017 else if (!png_memcmp(chunk_name, png_hIST, 4)) |
| 1040 png_handle_hIST(png_ptr, info_ptr, length); | 1018 png_handle_hIST(png_ptr, info_ptr, length); |
| 1041 #endif | 1019 #endif |
| 1042 #if defined(PNG_READ_oFFs_SUPPORTED) | 1020 #if defined(PNG_READ_oFFs_SUPPORTED) |
| 1043 else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4)) | 1021 else if (!png_memcmp(chunk_name, png_oFFs, 4)) |
| 1044 png_handle_oFFs(png_ptr, info_ptr, length); | 1022 png_handle_oFFs(png_ptr, info_ptr, length); |
| 1045 #endif | 1023 #endif |
| 1046 #if defined(PNG_READ_pCAL_SUPPORTED) | 1024 #if defined(PNG_READ_pCAL_SUPPORTED) |
| 1047 else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4)) | 1025 else if (!png_memcmp(chunk_name, png_pCAL, 4)) |
| 1048 png_handle_pCAL(png_ptr, info_ptr, length); | 1026 png_handle_pCAL(png_ptr, info_ptr, length); |
| 1049 #endif | 1027 #endif |
| 1050 #if defined(PNG_READ_sCAL_SUPPORTED) | 1028 #if defined(PNG_READ_sCAL_SUPPORTED) |
| 1051 else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4)) | 1029 else if (!png_memcmp(chunk_name, png_sCAL, 4)) |
| 1052 png_handle_sCAL(png_ptr, info_ptr, length); | 1030 png_handle_sCAL(png_ptr, info_ptr, length); |
| 1053 #endif | 1031 #endif |
| 1054 #if defined(PNG_READ_pHYs_SUPPORTED) | 1032 #if defined(PNG_READ_pHYs_SUPPORTED) |
| 1055 else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4)) | 1033 else if (!png_memcmp(chunk_name, png_pHYs, 4)) |
| 1056 png_handle_pHYs(png_ptr, info_ptr, length); | 1034 png_handle_pHYs(png_ptr, info_ptr, length); |
| 1057 #endif | 1035 #endif |
| 1058 #if defined(PNG_READ_sBIT_SUPPORTED) | 1036 #if defined(PNG_READ_sBIT_SUPPORTED) |
| 1059 else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4)) | 1037 else if (!png_memcmp(chunk_name, png_sBIT, 4)) |
| 1060 png_handle_sBIT(png_ptr, info_ptr, length); | 1038 png_handle_sBIT(png_ptr, info_ptr, length); |
| 1061 #endif | 1039 #endif |
| 1062 #if defined(PNG_READ_sRGB_SUPPORTED) | 1040 #if defined(PNG_READ_sRGB_SUPPORTED) |
| 1063 else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4)) | 1041 else if (!png_memcmp(chunk_name, png_sRGB, 4)) |
| 1064 png_handle_sRGB(png_ptr, info_ptr, length); | 1042 png_handle_sRGB(png_ptr, info_ptr, length); |
| 1065 #endif | 1043 #endif |
| 1066 #if defined(PNG_READ_iCCP_SUPPORTED) | 1044 #if defined(PNG_READ_iCCP_SUPPORTED) |
| 1067 else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4)) | 1045 else if (!png_memcmp(chunk_name, png_iCCP, 4)) |
| 1068 png_handle_iCCP(png_ptr, info_ptr, length); | 1046 png_handle_iCCP(png_ptr, info_ptr, length); |
| 1069 #endif | 1047 #endif |
| 1070 #if defined(PNG_READ_sPLT_SUPPORTED) | 1048 #if defined(PNG_READ_sPLT_SUPPORTED) |
| 1071 else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4)) | 1049 else if (!png_memcmp(chunk_name, png_sPLT, 4)) |
| 1072 png_handle_sPLT(png_ptr, info_ptr, length); | 1050 png_handle_sPLT(png_ptr, info_ptr, length); |
| 1073 #endif | 1051 #endif |
| 1074 #if defined(PNG_READ_tEXt_SUPPORTED) | 1052 #if defined(PNG_READ_tEXt_SUPPORTED) |
| 1075 else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4)) | 1053 else if (!png_memcmp(chunk_name, png_tEXt, 4)) |
| 1076 png_handle_tEXt(png_ptr, info_ptr, length); | 1054 png_handle_tEXt(png_ptr, info_ptr, length); |
| 1077 #endif | 1055 #endif |
| 1078 #if defined(PNG_READ_tIME_SUPPORTED) | 1056 #if defined(PNG_READ_tIME_SUPPORTED) |
| 1079 else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4)) | 1057 else if (!png_memcmp(chunk_name, png_tIME, 4)) |
| 1080 png_handle_tIME(png_ptr, info_ptr, length); | 1058 png_handle_tIME(png_ptr, info_ptr, length); |
| 1081 #endif | 1059 #endif |
| 1082 #if defined(PNG_READ_tRNS_SUPPORTED) | 1060 #if defined(PNG_READ_tRNS_SUPPORTED) |
| 1083 else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4)) | 1061 else if (!png_memcmp(chunk_name, png_tRNS, 4)) |
| 1084 png_handle_tRNS(png_ptr, info_ptr, length); | 1062 png_handle_tRNS(png_ptr, info_ptr, length); |
| 1085 #endif | 1063 #endif |
| 1086 #if defined(PNG_READ_zTXt_SUPPORTED) | 1064 #if defined(PNG_READ_zTXt_SUPPORTED) |
| 1087 else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4)) | 1065 else if (!png_memcmp(chunk_name, png_zTXt, 4)) |
| 1088 png_handle_zTXt(png_ptr, info_ptr, length); | 1066 png_handle_zTXt(png_ptr, info_ptr, length); |
| 1089 #endif | 1067 #endif |
| 1090 #if defined(PNG_READ_iTXt_SUPPORTED) | 1068 #if defined(PNG_READ_iTXt_SUPPORTED) |
| 1091 else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4)) | 1069 else if (!png_memcmp(chunk_name, png_iTXt, 4)) |
| 1092 png_handle_iTXt(png_ptr, info_ptr, length); | 1070 png_handle_iTXt(png_ptr, info_ptr, length); |
| 1093 #endif | 1071 #endif |
| 1094 else | 1072 else |
| 1095 png_handle_unknown(png_ptr, info_ptr, length); | 1073 png_handle_unknown(png_ptr, info_ptr, length); |
| 1096 } while (!(png_ptr->mode & PNG_HAVE_IEND)); | 1074 } while (!(png_ptr->mode & PNG_HAVE_IEND)); |
| 1097 } | 1075 } |
| 1098 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ | 1076 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ |
| 1099 | 1077 |
| 1100 /* free all memory used by the read */ | 1078 /* free all memory used by the read */ |
| 1101 void PNGAPI | 1079 void PNGAPI |
| 1102 png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, | 1080 png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, |
| 1103 png_infopp end_info_ptr_ptr) | 1081 png_infopp end_info_ptr_ptr) |
| 1104 { | 1082 { |
| 1105 png_structp png_ptr = NULL; | 1083 png_structp png_ptr = NULL; |
| 1106 png_infop info_ptr = NULL, end_info_ptr = NULL; | 1084 png_infop info_ptr = NULL, end_info_ptr = NULL; |
| 1107 #ifdef PNG_USER_MEM_SUPPORTED | 1085 #ifdef PNG_USER_MEM_SUPPORTED |
| 1108 png_free_ptr free_fn = NULL; | 1086 png_free_ptr free_fn = NULL; |
| 1109 png_voidp mem_ptr = NULL; | 1087 png_voidp mem_ptr = NULL; |
| 1110 #endif | 1088 #endif |
| 1111 | 1089 |
| 1112 png_debug(1, "in png_destroy_read_struct\n"); | 1090 png_debug(1, "in png_destroy_read_struct\n"); |
| 1113 if (png_ptr_ptr != NULL) | 1091 if (png_ptr_ptr != NULL) |
| 1114 { | |
| 1115 png_ptr = *png_ptr_ptr; | 1092 png_ptr = *png_ptr_ptr; |
| 1116 } | |
| 1117 if (png_ptr == NULL) | 1093 if (png_ptr == NULL) |
| 1118 return; | 1094 return; |
| 1119 | 1095 |
| 1120 #ifdef PNG_USER_MEM_SUPPORTED | 1096 #ifdef PNG_USER_MEM_SUPPORTED |
| 1121 free_fn = png_ptr->free_fn; | 1097 free_fn = png_ptr->free_fn; |
| 1122 mem_ptr = png_ptr->mem_ptr; | 1098 mem_ptr = png_ptr->mem_ptr; |
| 1123 #endif | 1099 #endif |
| 1124 | 1100 |
| 1125 if (info_ptr_ptr != NULL) | 1101 if (info_ptr_ptr != NULL) |
| 1126 info_ptr = *info_ptr_ptr; | 1102 info_ptr = *info_ptr_ptr; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1152 #endif | 1128 #endif |
| 1153 #ifdef PNG_USER_MEM_SUPPORTED | 1129 #ifdef PNG_USER_MEM_SUPPORTED |
| 1154 png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn, | 1130 png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn, |
| 1155 (png_voidp)mem_ptr); | 1131 (png_voidp)mem_ptr); |
| 1156 #else | 1132 #else |
| 1157 png_destroy_struct((png_voidp)end_info_ptr); | 1133 png_destroy_struct((png_voidp)end_info_ptr); |
| 1158 #endif | 1134 #endif |
| 1159 *end_info_ptr_ptr = NULL; | 1135 *end_info_ptr_ptr = NULL; |
| 1160 } | 1136 } |
| 1161 | 1137 |
| 1138 if (png_ptr != NULL) |
| 1139 { |
| 1162 #ifdef PNG_USER_MEM_SUPPORTED | 1140 #ifdef PNG_USER_MEM_SUPPORTED |
| 1163 png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, | 1141 png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, |
| 1164 (png_voidp)mem_ptr); | 1142 (png_voidp)mem_ptr); |
| 1165 #else | 1143 #else |
| 1166 png_destroy_struct((png_voidp)png_ptr); | 1144 png_destroy_struct((png_voidp)png_ptr); |
| 1167 #endif | 1145 #endif |
| 1168 *png_ptr_ptr = NULL; | 1146 *png_ptr_ptr = NULL; |
| 1147 } |
| 1169 } | 1148 } |
| 1170 | 1149 |
| 1171 /* free all memory used by the read (old method) */ | 1150 /* free all memory used by the read (old method) */ |
| 1172 void /* PRIVATE */ | 1151 void /* PRIVATE */ |
| 1173 png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
) | 1152 png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
) |
| 1174 { | 1153 { |
| 1175 #ifdef PNG_SETJMP_SUPPORTED | 1154 #ifdef PNG_SETJMP_SUPPORTED |
| 1176 jmp_buf tmp_jmp; | 1155 jmp_buf tmp_jmp; |
| 1177 #endif | 1156 #endif |
| 1178 png_error_ptr error_fn; | 1157 png_error_ptr error_fn; |
| 1179 png_error_ptr warning_fn; | 1158 png_error_ptr warning_fn; |
| 1180 png_voidp error_ptr; | 1159 png_voidp error_ptr; |
| 1181 #ifdef PNG_USER_MEM_SUPPORTED | 1160 #ifdef PNG_USER_MEM_SUPPORTED |
| 1182 png_free_ptr free_fn; | 1161 png_free_ptr free_fn; |
| 1183 #endif | 1162 #endif |
| 1184 | 1163 |
| 1185 png_debug(1, "in png_read_destroy\n"); | 1164 png_debug(1, "in png_read_destroy\n"); |
| 1186 if (info_ptr != NULL) | 1165 if (info_ptr != NULL) |
| 1187 png_info_destroy(png_ptr, info_ptr); | 1166 png_info_destroy(png_ptr, info_ptr); |
| 1188 | 1167 |
| 1189 if (end_info_ptr != NULL) | 1168 if (end_info_ptr != NULL) |
| 1190 png_info_destroy(png_ptr, end_info_ptr); | 1169 png_info_destroy(png_ptr, end_info_ptr); |
| 1191 | 1170 |
| 1192 png_free(png_ptr, png_ptr->zbuf); | 1171 png_free(png_ptr, png_ptr->zbuf); |
| 1193 png_free(png_ptr, png_ptr->big_row_buf); | 1172 png_free(png_ptr, png_ptr->big_row_buf); |
| 1194 png_free(png_ptr, png_ptr->prev_row); | 1173 png_free(png_ptr, png_ptr->prev_row); |
| 1174 png_free(png_ptr, png_ptr->chunkdata); |
| 1195 #if defined(PNG_READ_DITHER_SUPPORTED) | 1175 #if defined(PNG_READ_DITHER_SUPPORTED) |
| 1196 png_free(png_ptr, png_ptr->palette_lookup); | 1176 png_free(png_ptr, png_ptr->palette_lookup); |
| 1197 png_free(png_ptr, png_ptr->dither_index); | 1177 png_free(png_ptr, png_ptr->dither_index); |
| 1198 #endif | 1178 #endif |
| 1199 #if defined(PNG_READ_GAMMA_SUPPORTED) | 1179 #if defined(PNG_READ_GAMMA_SUPPORTED) |
| 1200 png_free(png_ptr, png_ptr->gamma_table); | 1180 png_free(png_ptr, png_ptr->gamma_table); |
| 1201 #endif | 1181 #endif |
| 1202 #if defined(PNG_READ_BACKGROUND_SUPPORTED) | 1182 #if defined(PNG_READ_BACKGROUND_SUPPORTED) |
| 1203 png_free(png_ptr, png_ptr->gamma_from_1); | 1183 png_free(png_ptr, png_ptr->gamma_from_1); |
| 1204 png_free(png_ptr, png_ptr->gamma_to_1); | 1184 png_free(png_ptr, png_ptr->gamma_to_1); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1281 #ifdef PNG_PROGRESSIVE_READ_SUPPORTED | 1261 #ifdef PNG_PROGRESSIVE_READ_SUPPORTED |
| 1282 #ifdef PNG_TEXT_SUPPORTED | 1262 #ifdef PNG_TEXT_SUPPORTED |
| 1283 png_free(png_ptr, png_ptr->current_text); | 1263 png_free(png_ptr, png_ptr->current_text); |
| 1284 #endif /* PNG_TEXT_SUPPORTED */ | 1264 #endif /* PNG_TEXT_SUPPORTED */ |
| 1285 #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ | 1265 #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ |
| 1286 | 1266 |
| 1287 /* Save the important info out of the png_struct, in case it is | 1267 /* Save the important info out of the png_struct, in case it is |
| 1288 * being used again. | 1268 * being used again. |
| 1289 */ | 1269 */ |
| 1290 #ifdef PNG_SETJMP_SUPPORTED | 1270 #ifdef PNG_SETJMP_SUPPORTED |
| 1291 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf)); | 1271 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf)); |
| 1292 #endif | 1272 #endif |
| 1293 | 1273 |
| 1294 error_fn = png_ptr->error_fn; | 1274 error_fn = png_ptr->error_fn; |
| 1295 warning_fn = png_ptr->warning_fn; | 1275 warning_fn = png_ptr->warning_fn; |
| 1296 error_ptr = png_ptr->error_ptr; | 1276 error_ptr = png_ptr->error_ptr; |
| 1297 #ifdef PNG_USER_MEM_SUPPORTED | 1277 #ifdef PNG_USER_MEM_SUPPORTED |
| 1298 free_fn = png_ptr->free_fn; | 1278 free_fn = png_ptr->free_fn; |
| 1299 #endif | 1279 #endif |
| 1300 | 1280 |
| 1301 png_memset(png_ptr, 0, png_sizeof (png_struct)); | 1281 png_memset(png_ptr, 0, png_sizeof(png_struct)); |
| 1302 | 1282 |
| 1303 png_ptr->error_fn = error_fn; | 1283 png_ptr->error_fn = error_fn; |
| 1304 png_ptr->warning_fn = warning_fn; | 1284 png_ptr->warning_fn = warning_fn; |
| 1305 png_ptr->error_ptr = error_ptr; | 1285 png_ptr->error_ptr = error_ptr; |
| 1306 #ifdef PNG_USER_MEM_SUPPORTED | 1286 #ifdef PNG_USER_MEM_SUPPORTED |
| 1307 png_ptr->free_fn = free_fn; | 1287 png_ptr->free_fn = free_fn; |
| 1308 #endif | 1288 #endif |
| 1309 | 1289 |
| 1310 #ifdef PNG_SETJMP_SUPPORTED | 1290 #ifdef PNG_SETJMP_SUPPORTED |
| 1311 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf)); | 1291 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf)); |
| 1312 #endif | 1292 #endif |
| 1313 | 1293 |
| 1314 } | 1294 } |
| 1315 | 1295 |
| 1316 void PNGAPI | 1296 void PNGAPI |
| 1317 png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn) | 1297 png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn) |
| 1318 { | 1298 { |
| 1319 if(png_ptr == NULL) return; | 1299 if (png_ptr == NULL) return; |
| 1320 png_ptr->read_row_fn = read_row_fn; | 1300 png_ptr->read_row_fn = read_row_fn; |
| 1321 } | 1301 } |
| 1322 | 1302 |
| 1323 | 1303 |
| 1324 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED | 1304 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED |
| 1325 #if defined(PNG_INFO_IMAGE_SUPPORTED) | 1305 #if defined(PNG_INFO_IMAGE_SUPPORTED) |
| 1326 void PNGAPI | 1306 void PNGAPI |
| 1327 png_read_png(png_structp png_ptr, png_infop info_ptr, | 1307 png_read_png(png_structp png_ptr, png_infop info_ptr, |
| 1328 int transforms, | 1308 int transforms, |
| 1329 voidp params) | 1309 voidp params) |
| 1330 { | 1310 { |
| 1331 int row; | 1311 int row; |
| 1332 | 1312 |
| 1333 if(png_ptr == NULL) return; | 1313 if (png_ptr == NULL) return; |
| 1334 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) | 1314 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) |
| 1335 /* invert the alpha channel from opacity to transparency | 1315 /* invert the alpha channel from opacity to transparency |
| 1336 */ | 1316 */ |
| 1337 if (transforms & PNG_TRANSFORM_INVERT_ALPHA) | 1317 if (transforms & PNG_TRANSFORM_INVERT_ALPHA) |
| 1338 png_set_invert_alpha(png_ptr); | 1318 png_set_invert_alpha(png_ptr); |
| 1339 #endif | 1319 #endif |
| 1340 | 1320 |
| 1341 /* png_read_info() gives us all of the information from the | 1321 /* png_read_info() gives us all of the information from the |
| 1342 * PNG file before the first IDAT (image data chunk). | 1322 * PNG file before the first IDAT (image data chunk). |
| 1343 */ | 1323 */ |
| 1344 png_read_info(png_ptr, info_ptr); | 1324 png_read_info(png_ptr, info_ptr); |
| 1345 if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep)) | 1325 if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep)) |
| 1346 png_error(png_ptr,"Image is too high to process with png_read_png()"); | 1326 png_error(png_ptr, "Image is too high to process with png_read_png()"); |
| 1347 | 1327 |
| 1348 /* -------------- image transformations start here ------------------- */ | 1328 /* -------------- image transformations start here ------------------- */ |
| 1349 | 1329 |
| 1350 #if defined(PNG_READ_16_TO_8_SUPPORTED) | 1330 #if defined(PNG_READ_16_TO_8_SUPPORTED) |
| 1351 /* tell libpng to strip 16 bit/color files down to 8 bits per color | 1331 /* tell libpng to strip 16 bit/color files down to 8 bits per color |
| 1352 */ | 1332 */ |
| 1353 if (transforms & PNG_TRANSFORM_STRIP_16) | 1333 if (transforms & PNG_TRANSFORM_STRIP_16) |
| 1354 png_set_strip_16(png_ptr); | 1334 png_set_strip_16(png_ptr); |
| 1355 #endif | 1335 #endif |
| 1356 | 1336 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1443 * and update info structure. REQUIRED if you are expecting libpng to | 1423 * and update info structure. REQUIRED if you are expecting libpng to |
| 1444 * update the palette for you (i.e., you selected such a transform above). | 1424 * update the palette for you (i.e., you selected such a transform above). |
| 1445 */ | 1425 */ |
| 1446 png_read_update_info(png_ptr, info_ptr); | 1426 png_read_update_info(png_ptr, info_ptr); |
| 1447 | 1427 |
| 1448 /* -------------- image transformations end here ------------------- */ | 1428 /* -------------- image transformations end here ------------------- */ |
| 1449 | 1429 |
| 1450 #ifdef PNG_FREE_ME_SUPPORTED | 1430 #ifdef PNG_FREE_ME_SUPPORTED |
| 1451 png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); | 1431 png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); |
| 1452 #endif | 1432 #endif |
| 1453 if(info_ptr->row_pointers == NULL) | 1433 if (info_ptr->row_pointers == NULL) |
| 1454 { | 1434 { |
| 1455 info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr, | 1435 info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr, |
| 1456 info_ptr->height * png_sizeof(png_bytep)); | 1436 info_ptr->height * png_sizeof(png_bytep)); |
| 1457 #ifdef PNG_FREE_ME_SUPPORTED | 1437 #ifdef PNG_FREE_ME_SUPPORTED |
| 1458 info_ptr->free_me |= PNG_FREE_ROWS; | 1438 info_ptr->free_me |= PNG_FREE_ROWS; |
| 1459 #endif | 1439 #endif |
| 1460 for (row = 0; row < (int)info_ptr->height; row++) | 1440 for (row = 0; row < (int)info_ptr->height; row++) |
| 1461 { | 1441 { |
| 1462 info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr, | 1442 info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr, |
| 1463 png_get_rowbytes(png_ptr, info_ptr)); | 1443 png_get_rowbytes(png_ptr, info_ptr)); |
| 1464 } | 1444 } |
| 1465 } | 1445 } |
| 1466 | 1446 |
| 1467 png_read_image(png_ptr, info_ptr->row_pointers); | 1447 png_read_image(png_ptr, info_ptr->row_pointers); |
| 1468 info_ptr->valid |= PNG_INFO_IDAT; | 1448 info_ptr->valid |= PNG_INFO_IDAT; |
| 1469 | 1449 |
| 1470 /* read rest of file, and get additional chunks in info_ptr - REQUIRED */ | 1450 /* read rest of file, and get additional chunks in info_ptr - REQUIRED */ |
| 1471 png_read_end(png_ptr, info_ptr); | 1451 png_read_end(png_ptr, info_ptr); |
| 1472 | 1452 |
| 1473 transforms = transforms; /* quiet compiler warnings */ | 1453 transforms = transforms; /* quiet compiler warnings */ |
| 1474 params = params; | 1454 params = params; |
| 1475 | 1455 |
| 1476 } | 1456 } |
| 1477 #endif /* PNG_INFO_IMAGE_SUPPORTED */ | 1457 #endif /* PNG_INFO_IMAGE_SUPPORTED */ |
| 1478 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ | 1458 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ |
| 1479 #endif /* PNG_READ_SUPPORTED */ | 1459 #endif /* PNG_READ_SUPPORTED */ |
| OLD | NEW |