nuclear@14: nuclear@14: /* pngpread.c - read a png file in push mode nuclear@14: * nuclear@14: * Last changed in libpng 1.2.32 [September 18, 2008] nuclear@14: * For conditions of distribution and use, see copyright notice in png.h nuclear@14: * Copyright (c) 1998-2008 Glenn Randers-Pehrson nuclear@14: * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) nuclear@14: * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) nuclear@14: */ nuclear@14: nuclear@14: #define PNG_INTERNAL nuclear@14: #include "png.h" nuclear@14: #ifdef PNG_PROGRESSIVE_READ_SUPPORTED nuclear@14: nuclear@14: /* push model modes */ nuclear@14: #define PNG_READ_SIG_MODE 0 nuclear@14: #define PNG_READ_CHUNK_MODE 1 nuclear@14: #define PNG_READ_IDAT_MODE 2 nuclear@14: #define PNG_SKIP_MODE 3 nuclear@14: #define PNG_READ_tEXt_MODE 4 nuclear@14: #define PNG_READ_zTXt_MODE 5 nuclear@14: #define PNG_READ_DONE_MODE 6 nuclear@14: #define PNG_READ_iTXt_MODE 7 nuclear@14: #define PNG_ERROR_MODE 8 nuclear@14: nuclear@14: void PNGAPI nuclear@14: png_process_data(png_structp png_ptr, png_infop info_ptr, nuclear@14: png_bytep buffer, png_size_t buffer_size) nuclear@14: { nuclear@14: if (png_ptr == NULL || info_ptr == NULL) return; nuclear@14: png_push_restore_buffer(png_ptr, buffer, buffer_size); nuclear@14: nuclear@14: while (png_ptr->buffer_size) nuclear@14: { nuclear@14: png_process_some_data(png_ptr, info_ptr); nuclear@14: } nuclear@14: } nuclear@14: nuclear@14: /* What we do with the incoming data depends on what we were previously nuclear@14: * doing before we ran out of data... nuclear@14: */ nuclear@14: void /* PRIVATE */ nuclear@14: png_process_some_data(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr == NULL) return; nuclear@14: switch (png_ptr->process_mode) nuclear@14: { nuclear@14: case PNG_READ_SIG_MODE: nuclear@14: { nuclear@14: png_push_read_sig(png_ptr, info_ptr); nuclear@14: break; nuclear@14: } nuclear@14: case PNG_READ_CHUNK_MODE: nuclear@14: { nuclear@14: png_push_read_chunk(png_ptr, info_ptr); nuclear@14: break; nuclear@14: } nuclear@14: case PNG_READ_IDAT_MODE: nuclear@14: { nuclear@14: png_push_read_IDAT(png_ptr); nuclear@14: break; nuclear@14: } nuclear@14: #if defined(PNG_READ_tEXt_SUPPORTED) nuclear@14: case PNG_READ_tEXt_MODE: nuclear@14: { nuclear@14: png_push_read_tEXt(png_ptr, info_ptr); nuclear@14: break; nuclear@14: } nuclear@14: #endif nuclear@14: #if defined(PNG_READ_zTXt_SUPPORTED) nuclear@14: case PNG_READ_zTXt_MODE: nuclear@14: { nuclear@14: png_push_read_zTXt(png_ptr, info_ptr); nuclear@14: break; nuclear@14: } nuclear@14: #endif nuclear@14: #if defined(PNG_READ_iTXt_SUPPORTED) nuclear@14: case PNG_READ_iTXt_MODE: nuclear@14: { nuclear@14: png_push_read_iTXt(png_ptr, info_ptr); nuclear@14: break; nuclear@14: } nuclear@14: #endif nuclear@14: case PNG_SKIP_MODE: nuclear@14: { nuclear@14: png_push_crc_finish(png_ptr); nuclear@14: break; nuclear@14: } nuclear@14: default: nuclear@14: { nuclear@14: png_ptr->buffer_size = 0; nuclear@14: break; nuclear@14: } nuclear@14: } nuclear@14: } nuclear@14: nuclear@14: /* Read any remaining signature bytes from the stream and compare them with nuclear@14: * the correct PNG signature. It is possible that this routine is called nuclear@14: * with bytes already read from the signature, either because they have been nuclear@14: * checked by the calling application, or because of multiple calls to this nuclear@14: * routine. nuclear@14: */ nuclear@14: void /* PRIVATE */ nuclear@14: png_push_read_sig(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: png_size_t num_checked = png_ptr->sig_bytes, nuclear@14: num_to_check = 8 - num_checked; nuclear@14: nuclear@14: if (png_ptr->buffer_size < num_to_check) nuclear@14: { nuclear@14: num_to_check = png_ptr->buffer_size; nuclear@14: } nuclear@14: nuclear@14: png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]), nuclear@14: num_to_check); nuclear@14: png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes + num_to_check); nuclear@14: nuclear@14: if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check)) nuclear@14: { nuclear@14: if (num_checked < 4 && nuclear@14: png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4)) nuclear@14: png_error(png_ptr, "Not a PNG file"); nuclear@14: else nuclear@14: png_error(png_ptr, "PNG file corrupted by ASCII conversion"); nuclear@14: } nuclear@14: else nuclear@14: { nuclear@14: if (png_ptr->sig_bytes >= 8) nuclear@14: { nuclear@14: png_ptr->process_mode = PNG_READ_CHUNK_MODE; nuclear@14: } nuclear@14: } nuclear@14: } nuclear@14: nuclear@14: void /* PRIVATE */ nuclear@14: png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: #ifdef PNG_USE_LOCAL_ARRAYS nuclear@14: PNG_CONST PNG_IHDR; nuclear@14: PNG_CONST PNG_IDAT; nuclear@14: PNG_CONST PNG_IEND; nuclear@14: PNG_CONST PNG_PLTE; nuclear@14: #if defined(PNG_READ_bKGD_SUPPORTED) nuclear@14: PNG_CONST PNG_bKGD; nuclear@14: #endif nuclear@14: #if defined(PNG_READ_cHRM_SUPPORTED) nuclear@14: PNG_CONST PNG_cHRM; nuclear@14: #endif nuclear@14: #if defined(PNG_READ_gAMA_SUPPORTED) nuclear@14: PNG_CONST PNG_gAMA; nuclear@14: #endif nuclear@14: #if defined(PNG_READ_hIST_SUPPORTED) nuclear@14: PNG_CONST PNG_hIST; nuclear@14: #endif nuclear@14: #if defined(PNG_READ_iCCP_SUPPORTED) nuclear@14: PNG_CONST PNG_iCCP; nuclear@14: #endif nuclear@14: #if defined(PNG_READ_iTXt_SUPPORTED) nuclear@14: PNG_CONST PNG_iTXt; nuclear@14: #endif nuclear@14: #if defined(PNG_READ_oFFs_SUPPORTED) nuclear@14: PNG_CONST PNG_oFFs; nuclear@14: #endif nuclear@14: #if defined(PNG_READ_pCAL_SUPPORTED) nuclear@14: PNG_CONST PNG_pCAL; nuclear@14: #endif nuclear@14: #if defined(PNG_READ_pHYs_SUPPORTED) nuclear@14: PNG_CONST PNG_pHYs; nuclear@14: #endif nuclear@14: #if defined(PNG_READ_sBIT_SUPPORTED) nuclear@14: PNG_CONST PNG_sBIT; nuclear@14: #endif nuclear@14: #if defined(PNG_READ_sCAL_SUPPORTED) nuclear@14: PNG_CONST PNG_sCAL; nuclear@14: #endif nuclear@14: #if defined(PNG_READ_sRGB_SUPPORTED) nuclear@14: PNG_CONST PNG_sRGB; nuclear@14: #endif nuclear@14: #if defined(PNG_READ_sPLT_SUPPORTED) nuclear@14: PNG_CONST PNG_sPLT; nuclear@14: #endif nuclear@14: #if defined(PNG_READ_tEXt_SUPPORTED) nuclear@14: PNG_CONST PNG_tEXt; nuclear@14: #endif nuclear@14: #if defined(PNG_READ_tIME_SUPPORTED) nuclear@14: PNG_CONST PNG_tIME; nuclear@14: #endif nuclear@14: #if defined(PNG_READ_tRNS_SUPPORTED) nuclear@14: PNG_CONST PNG_tRNS; nuclear@14: #endif nuclear@14: #if defined(PNG_READ_zTXt_SUPPORTED) nuclear@14: PNG_CONST PNG_zTXt; nuclear@14: #endif nuclear@14: #endif /* PNG_USE_LOCAL_ARRAYS */ nuclear@14: /* First we make sure we have enough data for the 4 byte chunk name nuclear@14: * and the 4 byte chunk length before proceeding with decoding the nuclear@14: * chunk data. To fully decode each of these chunks, we also make nuclear@14: * sure we have enough data in the buffer for the 4 byte CRC at the nuclear@14: * end of every chunk (except IDAT, which is handled separately). nuclear@14: */ nuclear@14: if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) nuclear@14: { nuclear@14: png_byte chunk_length[4]; nuclear@14: nuclear@14: if (png_ptr->buffer_size < 8) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: nuclear@14: png_push_fill_buffer(png_ptr, chunk_length, 4); nuclear@14: png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length); nuclear@14: png_reset_crc(png_ptr); nuclear@14: png_crc_read(png_ptr, png_ptr->chunk_name, 4); nuclear@14: png_check_chunk_name(png_ptr, png_ptr->chunk_name); nuclear@14: png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; nuclear@14: } nuclear@14: nuclear@14: if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) nuclear@14: if (png_ptr->mode & PNG_AFTER_IDAT) nuclear@14: png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; nuclear@14: nuclear@14: if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4)) nuclear@14: { nuclear@14: if (png_ptr->push_length != 13) nuclear@14: png_error(png_ptr, "Invalid IHDR length"); nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: } nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4)) nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: nuclear@14: png_ptr->process_mode = PNG_READ_DONE_MODE; nuclear@14: png_push_have_end(png_ptr, info_ptr); nuclear@14: } nuclear@14: #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED nuclear@14: else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name)) nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) nuclear@14: png_ptr->mode |= PNG_HAVE_IDAT; nuclear@14: png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) nuclear@14: png_ptr->mode |= PNG_HAVE_PLTE; nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) nuclear@14: { nuclear@14: if (!(png_ptr->mode & PNG_HAVE_IHDR)) nuclear@14: png_error(png_ptr, "Missing IHDR before IDAT"); nuclear@14: else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && nuclear@14: !(png_ptr->mode & PNG_HAVE_PLTE)) nuclear@14: png_error(png_ptr, "Missing PLTE before IDAT"); nuclear@14: } nuclear@14: } nuclear@14: #endif nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: } nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) nuclear@14: { nuclear@14: /* If we reach an IDAT chunk, this means we have read all of the nuclear@14: * header chunks, and we can start reading the image (or if this nuclear@14: * is called after the image has been read - we have an error). nuclear@14: */ nuclear@14: if (!(png_ptr->mode & PNG_HAVE_IHDR)) nuclear@14: png_error(png_ptr, "Missing IHDR before IDAT"); nuclear@14: else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && nuclear@14: !(png_ptr->mode & PNG_HAVE_PLTE)) nuclear@14: png_error(png_ptr, "Missing PLTE before IDAT"); nuclear@14: nuclear@14: if (png_ptr->mode & PNG_HAVE_IDAT) nuclear@14: { nuclear@14: if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) nuclear@14: if (png_ptr->push_length == 0) nuclear@14: return; nuclear@14: nuclear@14: if (png_ptr->mode & PNG_AFTER_IDAT) nuclear@14: png_error(png_ptr, "Too many IDAT's found"); nuclear@14: } nuclear@14: nuclear@14: png_ptr->idat_size = png_ptr->push_length; nuclear@14: png_ptr->mode |= PNG_HAVE_IDAT; nuclear@14: png_ptr->process_mode = PNG_READ_IDAT_MODE; nuclear@14: png_push_have_info(png_ptr, info_ptr); nuclear@14: png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes; nuclear@14: png_ptr->zstream.next_out = png_ptr->row_buf; nuclear@14: return; nuclear@14: } nuclear@14: #if defined(PNG_READ_gAMA_SUPPORTED) nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4)) nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: } nuclear@14: #endif nuclear@14: #if defined(PNG_READ_sBIT_SUPPORTED) nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4)) nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: } nuclear@14: #endif nuclear@14: #if defined(PNG_READ_cHRM_SUPPORTED) nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4)) nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: } nuclear@14: #endif nuclear@14: #if defined(PNG_READ_sRGB_SUPPORTED) nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4)) nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: } nuclear@14: #endif nuclear@14: #if defined(PNG_READ_iCCP_SUPPORTED) nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4)) nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: } nuclear@14: #endif nuclear@14: #if defined(PNG_READ_sPLT_SUPPORTED) nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4)) nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: } nuclear@14: #endif nuclear@14: #if defined(PNG_READ_tRNS_SUPPORTED) nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4)) nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: } nuclear@14: #endif nuclear@14: #if defined(PNG_READ_bKGD_SUPPORTED) nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4)) nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: } nuclear@14: #endif nuclear@14: #if defined(PNG_READ_hIST_SUPPORTED) nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4)) nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: } nuclear@14: #endif nuclear@14: #if defined(PNG_READ_pHYs_SUPPORTED) nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4)) nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: } nuclear@14: #endif nuclear@14: #if defined(PNG_READ_oFFs_SUPPORTED) nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4)) nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: } nuclear@14: #endif nuclear@14: #if defined(PNG_READ_pCAL_SUPPORTED) nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4)) nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: } nuclear@14: #endif nuclear@14: #if defined(PNG_READ_sCAL_SUPPORTED) nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4)) nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: } nuclear@14: #endif nuclear@14: #if defined(PNG_READ_tIME_SUPPORTED) nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4)) nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: } nuclear@14: #endif nuclear@14: #if defined(PNG_READ_tEXt_SUPPORTED) nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4)) nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: } nuclear@14: #endif nuclear@14: #if defined(PNG_READ_zTXt_SUPPORTED) nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4)) nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: } nuclear@14: #endif nuclear@14: #if defined(PNG_READ_iTXt_SUPPORTED) nuclear@14: else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4)) nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: } nuclear@14: #endif nuclear@14: else nuclear@14: { nuclear@14: if (png_ptr->push_length + 4 > png_ptr->buffer_size) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length); nuclear@14: } nuclear@14: nuclear@14: png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; nuclear@14: } nuclear@14: nuclear@14: void /* PRIVATE */ nuclear@14: png_push_crc_skip(png_structp png_ptr, png_uint_32 skip) nuclear@14: { nuclear@14: png_ptr->process_mode = PNG_SKIP_MODE; nuclear@14: png_ptr->skip_length = skip; nuclear@14: } nuclear@14: nuclear@14: void /* PRIVATE */ nuclear@14: png_push_crc_finish(png_structp png_ptr) nuclear@14: { nuclear@14: if (png_ptr->skip_length && png_ptr->save_buffer_size) nuclear@14: { nuclear@14: png_size_t save_size; nuclear@14: nuclear@14: if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size) nuclear@14: save_size = (png_size_t)png_ptr->skip_length; nuclear@14: else nuclear@14: save_size = png_ptr->save_buffer_size; nuclear@14: nuclear@14: png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size); nuclear@14: nuclear@14: png_ptr->skip_length -= save_size; nuclear@14: png_ptr->buffer_size -= save_size; nuclear@14: png_ptr->save_buffer_size -= save_size; nuclear@14: png_ptr->save_buffer_ptr += save_size; nuclear@14: } nuclear@14: if (png_ptr->skip_length && png_ptr->current_buffer_size) nuclear@14: { nuclear@14: png_size_t save_size; nuclear@14: nuclear@14: if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size) nuclear@14: save_size = (png_size_t)png_ptr->skip_length; nuclear@14: else nuclear@14: save_size = png_ptr->current_buffer_size; nuclear@14: nuclear@14: png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); nuclear@14: nuclear@14: png_ptr->skip_length -= save_size; nuclear@14: png_ptr->buffer_size -= save_size; nuclear@14: png_ptr->current_buffer_size -= save_size; nuclear@14: png_ptr->current_buffer_ptr += save_size; nuclear@14: } nuclear@14: if (!png_ptr->skip_length) nuclear@14: { nuclear@14: if (png_ptr->buffer_size < 4) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: nuclear@14: png_crc_finish(png_ptr, 0); nuclear@14: png_ptr->process_mode = PNG_READ_CHUNK_MODE; nuclear@14: } nuclear@14: } nuclear@14: nuclear@14: void PNGAPI nuclear@14: png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length) nuclear@14: { nuclear@14: png_bytep ptr; nuclear@14: nuclear@14: if (png_ptr == NULL) return; nuclear@14: ptr = buffer; nuclear@14: if (png_ptr->save_buffer_size) nuclear@14: { nuclear@14: png_size_t save_size; nuclear@14: nuclear@14: if (length < png_ptr->save_buffer_size) nuclear@14: save_size = length; nuclear@14: else nuclear@14: save_size = png_ptr->save_buffer_size; nuclear@14: nuclear@14: png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size); nuclear@14: length -= save_size; nuclear@14: ptr += save_size; nuclear@14: png_ptr->buffer_size -= save_size; nuclear@14: png_ptr->save_buffer_size -= save_size; nuclear@14: png_ptr->save_buffer_ptr += save_size; nuclear@14: } nuclear@14: if (length && png_ptr->current_buffer_size) nuclear@14: { nuclear@14: png_size_t save_size; nuclear@14: nuclear@14: if (length < png_ptr->current_buffer_size) nuclear@14: save_size = length; nuclear@14: else nuclear@14: save_size = png_ptr->current_buffer_size; nuclear@14: nuclear@14: png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size); nuclear@14: png_ptr->buffer_size -= save_size; nuclear@14: png_ptr->current_buffer_size -= save_size; nuclear@14: png_ptr->current_buffer_ptr += save_size; nuclear@14: } nuclear@14: } nuclear@14: nuclear@14: void /* PRIVATE */ nuclear@14: png_push_save_buffer(png_structp png_ptr) nuclear@14: { nuclear@14: if (png_ptr->save_buffer_size) nuclear@14: { nuclear@14: if (png_ptr->save_buffer_ptr != png_ptr->save_buffer) nuclear@14: { nuclear@14: png_size_t i, istop; nuclear@14: png_bytep sp; nuclear@14: png_bytep dp; nuclear@14: nuclear@14: istop = png_ptr->save_buffer_size; nuclear@14: for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer; nuclear@14: i < istop; i++, sp++, dp++) nuclear@14: { nuclear@14: *dp = *sp; nuclear@14: } nuclear@14: } nuclear@14: } nuclear@14: if (png_ptr->save_buffer_size + png_ptr->current_buffer_size > nuclear@14: png_ptr->save_buffer_max) nuclear@14: { nuclear@14: png_size_t new_max; nuclear@14: png_bytep old_buffer; nuclear@14: nuclear@14: if (png_ptr->save_buffer_size > PNG_SIZE_MAX - nuclear@14: (png_ptr->current_buffer_size + 256)) nuclear@14: { nuclear@14: png_error(png_ptr, "Potential overflow of save_buffer"); nuclear@14: } nuclear@14: new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256; nuclear@14: old_buffer = png_ptr->save_buffer; nuclear@14: png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr, nuclear@14: (png_uint_32)new_max); nuclear@14: png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size); nuclear@14: png_free(png_ptr, old_buffer); nuclear@14: png_ptr->save_buffer_max = new_max; nuclear@14: } nuclear@14: if (png_ptr->current_buffer_size) nuclear@14: { nuclear@14: png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size, nuclear@14: png_ptr->current_buffer_ptr, png_ptr->current_buffer_size); nuclear@14: png_ptr->save_buffer_size += png_ptr->current_buffer_size; nuclear@14: png_ptr->current_buffer_size = 0; nuclear@14: } nuclear@14: png_ptr->save_buffer_ptr = png_ptr->save_buffer; nuclear@14: png_ptr->buffer_size = 0; nuclear@14: } nuclear@14: nuclear@14: void /* PRIVATE */ nuclear@14: png_push_restore_buffer(png_structp png_ptr, png_bytep buffer, nuclear@14: png_size_t buffer_length) nuclear@14: { nuclear@14: png_ptr->current_buffer = buffer; nuclear@14: png_ptr->current_buffer_size = buffer_length; nuclear@14: png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size; nuclear@14: png_ptr->current_buffer_ptr = png_ptr->current_buffer; nuclear@14: } nuclear@14: nuclear@14: void /* PRIVATE */ nuclear@14: png_push_read_IDAT(png_structp png_ptr) nuclear@14: { nuclear@14: #ifdef PNG_USE_LOCAL_ARRAYS nuclear@14: PNG_CONST PNG_IDAT; nuclear@14: #endif nuclear@14: if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER)) nuclear@14: { nuclear@14: png_byte chunk_length[4]; nuclear@14: nuclear@14: if (png_ptr->buffer_size < 8) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: nuclear@14: png_push_fill_buffer(png_ptr, chunk_length, 4); nuclear@14: png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length); nuclear@14: png_reset_crc(png_ptr); nuclear@14: png_crc_read(png_ptr, png_ptr->chunk_name, 4); nuclear@14: png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; nuclear@14: nuclear@14: if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) nuclear@14: { nuclear@14: png_ptr->process_mode = PNG_READ_CHUNK_MODE; nuclear@14: if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) nuclear@14: png_error(png_ptr, "Not enough compressed data"); nuclear@14: return; nuclear@14: } nuclear@14: nuclear@14: png_ptr->idat_size = png_ptr->push_length; nuclear@14: } nuclear@14: if (png_ptr->idat_size && png_ptr->save_buffer_size) nuclear@14: { nuclear@14: png_size_t save_size; nuclear@14: nuclear@14: if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size) nuclear@14: { nuclear@14: save_size = (png_size_t)png_ptr->idat_size; nuclear@14: /* check for overflow */ nuclear@14: if ((png_uint_32)save_size != png_ptr->idat_size) nuclear@14: png_error(png_ptr, "save_size overflowed in pngpread"); nuclear@14: } nuclear@14: else nuclear@14: save_size = png_ptr->save_buffer_size; nuclear@14: nuclear@14: png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size); nuclear@14: if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) nuclear@14: png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size); nuclear@14: png_ptr->idat_size -= save_size; nuclear@14: png_ptr->buffer_size -= save_size; nuclear@14: png_ptr->save_buffer_size -= save_size; nuclear@14: png_ptr->save_buffer_ptr += save_size; nuclear@14: } nuclear@14: if (png_ptr->idat_size && png_ptr->current_buffer_size) nuclear@14: { nuclear@14: png_size_t save_size; nuclear@14: nuclear@14: if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size) nuclear@14: { nuclear@14: save_size = (png_size_t)png_ptr->idat_size; nuclear@14: /* check for overflow */ nuclear@14: if ((png_uint_32)save_size != png_ptr->idat_size) nuclear@14: png_error(png_ptr, "save_size overflowed in pngpread"); nuclear@14: } nuclear@14: else nuclear@14: save_size = png_ptr->current_buffer_size; nuclear@14: nuclear@14: png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); nuclear@14: if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) nuclear@14: png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size); nuclear@14: nuclear@14: png_ptr->idat_size -= save_size; nuclear@14: png_ptr->buffer_size -= save_size; nuclear@14: png_ptr->current_buffer_size -= save_size; nuclear@14: png_ptr->current_buffer_ptr += save_size; nuclear@14: } nuclear@14: if (!png_ptr->idat_size) nuclear@14: { nuclear@14: if (png_ptr->buffer_size < 4) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: nuclear@14: png_crc_finish(png_ptr, 0); nuclear@14: png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; nuclear@14: png_ptr->mode |= PNG_AFTER_IDAT; nuclear@14: } nuclear@14: } nuclear@14: nuclear@14: void /* PRIVATE */ nuclear@14: png_process_IDAT_data(png_structp png_ptr, png_bytep buffer, nuclear@14: png_size_t buffer_length) nuclear@14: { nuclear@14: int ret; nuclear@14: nuclear@14: if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length) nuclear@14: png_error(png_ptr, "Extra compression data"); nuclear@14: nuclear@14: png_ptr->zstream.next_in = buffer; nuclear@14: png_ptr->zstream.avail_in = (uInt)buffer_length; nuclear@14: for (;;) nuclear@14: { nuclear@14: ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); nuclear@14: if (ret != Z_OK) nuclear@14: { nuclear@14: if (ret == Z_STREAM_END) nuclear@14: { nuclear@14: if (png_ptr->zstream.avail_in) nuclear@14: png_error(png_ptr, "Extra compressed data"); nuclear@14: if (!(png_ptr->zstream.avail_out)) nuclear@14: { nuclear@14: png_push_process_row(png_ptr); nuclear@14: } nuclear@14: nuclear@14: png_ptr->mode |= PNG_AFTER_IDAT; nuclear@14: png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; nuclear@14: break; nuclear@14: } nuclear@14: else if (ret == Z_BUF_ERROR) nuclear@14: break; nuclear@14: else nuclear@14: png_error(png_ptr, "Decompression Error"); nuclear@14: } nuclear@14: if (!(png_ptr->zstream.avail_out)) nuclear@14: { nuclear@14: if (( nuclear@14: #if defined(PNG_READ_INTERLACING_SUPPORTED) nuclear@14: png_ptr->interlaced && png_ptr->pass > 6) || nuclear@14: (!png_ptr->interlaced && nuclear@14: #endif nuclear@14: png_ptr->row_number == png_ptr->num_rows)) nuclear@14: { nuclear@14: if (png_ptr->zstream.avail_in) nuclear@14: png_warning(png_ptr, "Too much data in IDAT chunks"); nuclear@14: png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; nuclear@14: break; nuclear@14: } nuclear@14: png_push_process_row(png_ptr); nuclear@14: png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes; nuclear@14: png_ptr->zstream.next_out = png_ptr->row_buf; nuclear@14: } nuclear@14: else nuclear@14: break; nuclear@14: } nuclear@14: } nuclear@14: nuclear@14: void /* PRIVATE */ nuclear@14: png_push_process_row(png_structp png_ptr) nuclear@14: { nuclear@14: png_ptr->row_info.color_type = png_ptr->color_type; nuclear@14: png_ptr->row_info.width = png_ptr->iwidth; nuclear@14: png_ptr->row_info.channels = png_ptr->channels; nuclear@14: png_ptr->row_info.bit_depth = png_ptr->bit_depth; nuclear@14: png_ptr->row_info.pixel_depth = png_ptr->pixel_depth; nuclear@14: nuclear@14: png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, nuclear@14: png_ptr->row_info.width); nuclear@14: nuclear@14: png_read_filter_row(png_ptr, &(png_ptr->row_info), nuclear@14: png_ptr->row_buf + 1, png_ptr->prev_row + 1, nuclear@14: (int)(png_ptr->row_buf[0])); nuclear@14: nuclear@14: png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf, nuclear@14: png_ptr->rowbytes + 1); nuclear@14: nuclear@14: if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA)) nuclear@14: png_do_read_transformations(png_ptr); nuclear@14: nuclear@14: #if defined(PNG_READ_INTERLACING_SUPPORTED) nuclear@14: /* blow up interlaced rows to full size */ nuclear@14: if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) nuclear@14: { nuclear@14: if (png_ptr->pass < 6) nuclear@14: /* old interface (pre-1.0.9): nuclear@14: png_do_read_interlace(&(png_ptr->row_info), nuclear@14: png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations); nuclear@14: */ nuclear@14: png_do_read_interlace(png_ptr); nuclear@14: nuclear@14: switch (png_ptr->pass) nuclear@14: { nuclear@14: case 0: nuclear@14: { nuclear@14: int i; nuclear@14: for (i = 0; i < 8 && png_ptr->pass == 0; i++) nuclear@14: { nuclear@14: png_push_have_row(png_ptr, png_ptr->row_buf + 1); nuclear@14: png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */ nuclear@14: } nuclear@14: if (png_ptr->pass == 2) /* pass 1 might be empty */ nuclear@14: { nuclear@14: for (i = 0; i < 4 && png_ptr->pass == 2; i++) nuclear@14: { nuclear@14: png_push_have_row(png_ptr, png_bytep_NULL); nuclear@14: png_read_push_finish_row(png_ptr); nuclear@14: } nuclear@14: } nuclear@14: if (png_ptr->pass == 4 && png_ptr->height <= 4) nuclear@14: { nuclear@14: for (i = 0; i < 2 && png_ptr->pass == 4; i++) nuclear@14: { nuclear@14: png_push_have_row(png_ptr, png_bytep_NULL); nuclear@14: png_read_push_finish_row(png_ptr); nuclear@14: } nuclear@14: } nuclear@14: if (png_ptr->pass == 6 && png_ptr->height <= 4) nuclear@14: { nuclear@14: png_push_have_row(png_ptr, png_bytep_NULL); nuclear@14: png_read_push_finish_row(png_ptr); nuclear@14: } nuclear@14: break; nuclear@14: } nuclear@14: case 1: nuclear@14: { nuclear@14: int i; nuclear@14: for (i = 0; i < 8 && png_ptr->pass == 1; i++) nuclear@14: { nuclear@14: png_push_have_row(png_ptr, png_ptr->row_buf + 1); nuclear@14: png_read_push_finish_row(png_ptr); nuclear@14: } nuclear@14: if (png_ptr->pass == 2) /* skip top 4 generated rows */ nuclear@14: { nuclear@14: for (i = 0; i < 4 && png_ptr->pass == 2; i++) nuclear@14: { nuclear@14: png_push_have_row(png_ptr, png_bytep_NULL); nuclear@14: png_read_push_finish_row(png_ptr); nuclear@14: } nuclear@14: } nuclear@14: break; nuclear@14: } nuclear@14: case 2: nuclear@14: { nuclear@14: int i; nuclear@14: for (i = 0; i < 4 && png_ptr->pass == 2; i++) nuclear@14: { nuclear@14: png_push_have_row(png_ptr, png_ptr->row_buf + 1); nuclear@14: png_read_push_finish_row(png_ptr); nuclear@14: } nuclear@14: for (i = 0; i < 4 && png_ptr->pass == 2; i++) nuclear@14: { nuclear@14: png_push_have_row(png_ptr, png_bytep_NULL); nuclear@14: png_read_push_finish_row(png_ptr); nuclear@14: } nuclear@14: if (png_ptr->pass == 4) /* pass 3 might be empty */ nuclear@14: { nuclear@14: for (i = 0; i < 2 && png_ptr->pass == 4; i++) nuclear@14: { nuclear@14: png_push_have_row(png_ptr, png_bytep_NULL); nuclear@14: png_read_push_finish_row(png_ptr); nuclear@14: } nuclear@14: } nuclear@14: break; nuclear@14: } nuclear@14: case 3: nuclear@14: { nuclear@14: int i; nuclear@14: for (i = 0; i < 4 && png_ptr->pass == 3; i++) nuclear@14: { nuclear@14: png_push_have_row(png_ptr, png_ptr->row_buf + 1); nuclear@14: png_read_push_finish_row(png_ptr); nuclear@14: } nuclear@14: if (png_ptr->pass == 4) /* skip top two generated rows */ nuclear@14: { nuclear@14: for (i = 0; i < 2 && png_ptr->pass == 4; i++) nuclear@14: { nuclear@14: png_push_have_row(png_ptr, png_bytep_NULL); nuclear@14: png_read_push_finish_row(png_ptr); nuclear@14: } nuclear@14: } nuclear@14: break; nuclear@14: } nuclear@14: case 4: nuclear@14: { nuclear@14: int i; nuclear@14: for (i = 0; i < 2 && png_ptr->pass == 4; i++) nuclear@14: { nuclear@14: png_push_have_row(png_ptr, png_ptr->row_buf + 1); nuclear@14: png_read_push_finish_row(png_ptr); nuclear@14: } nuclear@14: for (i = 0; i < 2 && png_ptr->pass == 4; i++) nuclear@14: { nuclear@14: png_push_have_row(png_ptr, png_bytep_NULL); nuclear@14: png_read_push_finish_row(png_ptr); nuclear@14: } nuclear@14: if (png_ptr->pass == 6) /* pass 5 might be empty */ nuclear@14: { nuclear@14: png_push_have_row(png_ptr, png_bytep_NULL); nuclear@14: png_read_push_finish_row(png_ptr); nuclear@14: } nuclear@14: break; nuclear@14: } nuclear@14: case 5: nuclear@14: { nuclear@14: int i; nuclear@14: for (i = 0; i < 2 && png_ptr->pass == 5; i++) nuclear@14: { nuclear@14: png_push_have_row(png_ptr, png_ptr->row_buf + 1); nuclear@14: png_read_push_finish_row(png_ptr); nuclear@14: } nuclear@14: if (png_ptr->pass == 6) /* skip top generated row */ nuclear@14: { nuclear@14: png_push_have_row(png_ptr, png_bytep_NULL); nuclear@14: png_read_push_finish_row(png_ptr); nuclear@14: } nuclear@14: break; nuclear@14: } nuclear@14: case 6: nuclear@14: { nuclear@14: png_push_have_row(png_ptr, png_ptr->row_buf + 1); nuclear@14: png_read_push_finish_row(png_ptr); nuclear@14: if (png_ptr->pass != 6) nuclear@14: break; nuclear@14: png_push_have_row(png_ptr, png_bytep_NULL); nuclear@14: png_read_push_finish_row(png_ptr); nuclear@14: } nuclear@14: } nuclear@14: } nuclear@14: else nuclear@14: #endif nuclear@14: { nuclear@14: png_push_have_row(png_ptr, png_ptr->row_buf + 1); nuclear@14: png_read_push_finish_row(png_ptr); nuclear@14: } nuclear@14: } nuclear@14: nuclear@14: void /* PRIVATE */ nuclear@14: png_read_push_finish_row(png_structp png_ptr) nuclear@14: { nuclear@14: #ifdef PNG_USE_LOCAL_ARRAYS nuclear@14: /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ nuclear@14: nuclear@14: /* start of interlace block */ nuclear@14: PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; nuclear@14: nuclear@14: /* offset to next interlace block */ nuclear@14: PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; nuclear@14: nuclear@14: /* start of interlace block in the y direction */ nuclear@14: PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; nuclear@14: nuclear@14: /* offset to next interlace block in the y direction */ nuclear@14: PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; nuclear@14: nuclear@14: /* Height of interlace block. This is not currently used - if you need nuclear@14: * it, uncomment it here and in png.h nuclear@14: PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; nuclear@14: */ nuclear@14: #endif nuclear@14: nuclear@14: png_ptr->row_number++; nuclear@14: if (png_ptr->row_number < png_ptr->num_rows) nuclear@14: return; nuclear@14: nuclear@14: if (png_ptr->interlaced) nuclear@14: { nuclear@14: png_ptr->row_number = 0; nuclear@14: png_memset_check(png_ptr, png_ptr->prev_row, 0, nuclear@14: png_ptr->rowbytes + 1); nuclear@14: do nuclear@14: { nuclear@14: png_ptr->pass++; nuclear@14: if ((png_ptr->pass == 1 && png_ptr->width < 5) || nuclear@14: (png_ptr->pass == 3 && png_ptr->width < 3) || nuclear@14: (png_ptr->pass == 5 && png_ptr->width < 2)) nuclear@14: png_ptr->pass++; nuclear@14: nuclear@14: if (png_ptr->pass > 7) nuclear@14: png_ptr->pass--; nuclear@14: if (png_ptr->pass >= 7) nuclear@14: break; nuclear@14: nuclear@14: png_ptr->iwidth = (png_ptr->width + nuclear@14: png_pass_inc[png_ptr->pass] - 1 - nuclear@14: png_pass_start[png_ptr->pass]) / nuclear@14: png_pass_inc[png_ptr->pass]; nuclear@14: nuclear@14: png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, nuclear@14: png_ptr->iwidth) + 1; nuclear@14: nuclear@14: if (png_ptr->transformations & PNG_INTERLACE) nuclear@14: break; nuclear@14: nuclear@14: png_ptr->num_rows = (png_ptr->height + nuclear@14: png_pass_yinc[png_ptr->pass] - 1 - nuclear@14: png_pass_ystart[png_ptr->pass]) / nuclear@14: png_pass_yinc[png_ptr->pass]; nuclear@14: nuclear@14: } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0); nuclear@14: } nuclear@14: } nuclear@14: nuclear@14: #if defined(PNG_READ_tEXt_SUPPORTED) nuclear@14: void /* PRIVATE */ nuclear@14: png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 nuclear@14: length) nuclear@14: { nuclear@14: if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) nuclear@14: { nuclear@14: png_error(png_ptr, "Out of place tEXt"); nuclear@14: info_ptr = info_ptr; /* to quiet some compiler warnings */ nuclear@14: } nuclear@14: nuclear@14: #ifdef PNG_MAX_MALLOC_64K nuclear@14: png_ptr->skip_length = 0; /* This may not be necessary */ nuclear@14: nuclear@14: if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */ nuclear@14: { nuclear@14: png_warning(png_ptr, "tEXt chunk too large to fit in memory"); nuclear@14: png_ptr->skip_length = length - (png_uint_32)65535L; nuclear@14: length = (png_uint_32)65535L; nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: png_ptr->current_text = (png_charp)png_malloc(png_ptr, nuclear@14: (png_uint_32)(length + 1)); nuclear@14: png_ptr->current_text[length] = '\0'; nuclear@14: png_ptr->current_text_ptr = png_ptr->current_text; nuclear@14: png_ptr->current_text_size = (png_size_t)length; nuclear@14: png_ptr->current_text_left = (png_size_t)length; nuclear@14: png_ptr->process_mode = PNG_READ_tEXt_MODE; nuclear@14: } nuclear@14: nuclear@14: void /* PRIVATE */ nuclear@14: png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr->buffer_size && png_ptr->current_text_left) nuclear@14: { nuclear@14: png_size_t text_size; nuclear@14: nuclear@14: if (png_ptr->buffer_size < png_ptr->current_text_left) nuclear@14: text_size = png_ptr->buffer_size; nuclear@14: else nuclear@14: text_size = png_ptr->current_text_left; nuclear@14: png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size); nuclear@14: png_ptr->current_text_left -= text_size; nuclear@14: png_ptr->current_text_ptr += text_size; nuclear@14: } nuclear@14: if (!(png_ptr->current_text_left)) nuclear@14: { nuclear@14: png_textp text_ptr; nuclear@14: png_charp text; nuclear@14: png_charp key; nuclear@14: int ret; nuclear@14: nuclear@14: if (png_ptr->buffer_size < 4) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: nuclear@14: png_push_crc_finish(png_ptr); nuclear@14: nuclear@14: #if defined(PNG_MAX_MALLOC_64K) nuclear@14: if (png_ptr->skip_length) nuclear@14: return; nuclear@14: #endif nuclear@14: nuclear@14: key = png_ptr->current_text; nuclear@14: nuclear@14: for (text = key; *text; text++) nuclear@14: /* empty loop */ ; nuclear@14: nuclear@14: if (text < key + png_ptr->current_text_size) nuclear@14: text++; nuclear@14: nuclear@14: text_ptr = (png_textp)png_malloc(png_ptr, nuclear@14: (png_uint_32)png_sizeof(png_text)); nuclear@14: text_ptr->compression = PNG_TEXT_COMPRESSION_NONE; nuclear@14: text_ptr->key = key; nuclear@14: #ifdef PNG_iTXt_SUPPORTED nuclear@14: text_ptr->lang = NULL; nuclear@14: text_ptr->lang_key = NULL; nuclear@14: #endif nuclear@14: text_ptr->text = text; nuclear@14: nuclear@14: ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); nuclear@14: nuclear@14: png_free(png_ptr, key); nuclear@14: png_free(png_ptr, text_ptr); nuclear@14: png_ptr->current_text = NULL; nuclear@14: nuclear@14: if (ret) nuclear@14: png_warning(png_ptr, "Insufficient memory to store text chunk."); nuclear@14: } nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: #if defined(PNG_READ_zTXt_SUPPORTED) nuclear@14: void /* PRIVATE */ nuclear@14: png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 nuclear@14: length) nuclear@14: { nuclear@14: if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) nuclear@14: { nuclear@14: png_error(png_ptr, "Out of place zTXt"); nuclear@14: info_ptr = info_ptr; /* to quiet some compiler warnings */ nuclear@14: } nuclear@14: nuclear@14: #ifdef PNG_MAX_MALLOC_64K nuclear@14: /* We can't handle zTXt chunks > 64K, since we don't have enough space nuclear@14: * to be able to store the uncompressed data. Actually, the threshold nuclear@14: * is probably around 32K, but it isn't as definite as 64K is. nuclear@14: */ nuclear@14: if (length > (png_uint_32)65535L) nuclear@14: { nuclear@14: png_warning(png_ptr, "zTXt chunk too large to fit in memory"); nuclear@14: png_push_crc_skip(png_ptr, length); nuclear@14: return; nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: png_ptr->current_text = (png_charp)png_malloc(png_ptr, nuclear@14: (png_uint_32)(length + 1)); nuclear@14: png_ptr->current_text[length] = '\0'; nuclear@14: png_ptr->current_text_ptr = png_ptr->current_text; nuclear@14: png_ptr->current_text_size = (png_size_t)length; nuclear@14: png_ptr->current_text_left = (png_size_t)length; nuclear@14: png_ptr->process_mode = PNG_READ_zTXt_MODE; nuclear@14: } nuclear@14: nuclear@14: void /* PRIVATE */ nuclear@14: png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr->buffer_size && png_ptr->current_text_left) nuclear@14: { nuclear@14: png_size_t text_size; nuclear@14: nuclear@14: if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left) nuclear@14: text_size = png_ptr->buffer_size; nuclear@14: else nuclear@14: text_size = png_ptr->current_text_left; nuclear@14: png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size); nuclear@14: png_ptr->current_text_left -= text_size; nuclear@14: png_ptr->current_text_ptr += text_size; nuclear@14: } nuclear@14: if (!(png_ptr->current_text_left)) nuclear@14: { nuclear@14: png_textp text_ptr; nuclear@14: png_charp text; nuclear@14: png_charp key; nuclear@14: int ret; nuclear@14: png_size_t text_size, key_size; nuclear@14: nuclear@14: if (png_ptr->buffer_size < 4) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: nuclear@14: png_push_crc_finish(png_ptr); nuclear@14: nuclear@14: key = png_ptr->current_text; nuclear@14: nuclear@14: for (text = key; *text; text++) nuclear@14: /* empty loop */ ; nuclear@14: nuclear@14: /* zTXt can't have zero text */ nuclear@14: if (text >= key + png_ptr->current_text_size) nuclear@14: { nuclear@14: png_ptr->current_text = NULL; nuclear@14: png_free(png_ptr, key); nuclear@14: return; nuclear@14: } nuclear@14: nuclear@14: text++; nuclear@14: nuclear@14: if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */ nuclear@14: { nuclear@14: png_ptr->current_text = NULL; nuclear@14: png_free(png_ptr, key); nuclear@14: return; nuclear@14: } nuclear@14: nuclear@14: text++; nuclear@14: nuclear@14: png_ptr->zstream.next_in = (png_bytep )text; nuclear@14: png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size - nuclear@14: (text - key)); nuclear@14: png_ptr->zstream.next_out = png_ptr->zbuf; nuclear@14: png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; nuclear@14: nuclear@14: key_size = text - key; nuclear@14: text_size = 0; nuclear@14: text = NULL; nuclear@14: ret = Z_STREAM_END; nuclear@14: nuclear@14: while (png_ptr->zstream.avail_in) nuclear@14: { nuclear@14: ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); nuclear@14: if (ret != Z_OK && ret != Z_STREAM_END) nuclear@14: { nuclear@14: inflateReset(&png_ptr->zstream); nuclear@14: png_ptr->zstream.avail_in = 0; nuclear@14: png_ptr->current_text = NULL; nuclear@14: png_free(png_ptr, key); nuclear@14: png_free(png_ptr, text); nuclear@14: return; nuclear@14: } nuclear@14: if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END) nuclear@14: { nuclear@14: if (text == NULL) nuclear@14: { nuclear@14: text = (png_charp)png_malloc(png_ptr, nuclear@14: (png_uint_32)(png_ptr->zbuf_size nuclear@14: - png_ptr->zstream.avail_out + key_size + 1)); nuclear@14: png_memcpy(text + key_size, png_ptr->zbuf, nuclear@14: png_ptr->zbuf_size - png_ptr->zstream.avail_out); nuclear@14: png_memcpy(text, key, key_size); nuclear@14: text_size = key_size + png_ptr->zbuf_size - nuclear@14: png_ptr->zstream.avail_out; nuclear@14: *(text + text_size) = '\0'; nuclear@14: } nuclear@14: else nuclear@14: { nuclear@14: png_charp tmp; nuclear@14: nuclear@14: tmp = text; nuclear@14: text = (png_charp)png_malloc(png_ptr, text_size + nuclear@14: (png_uint_32)(png_ptr->zbuf_size nuclear@14: - png_ptr->zstream.avail_out + 1)); nuclear@14: png_memcpy(text, tmp, text_size); nuclear@14: png_free(png_ptr, tmp); nuclear@14: png_memcpy(text + text_size, png_ptr->zbuf, nuclear@14: png_ptr->zbuf_size - png_ptr->zstream.avail_out); nuclear@14: text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out; nuclear@14: *(text + text_size) = '\0'; nuclear@14: } nuclear@14: if (ret != Z_STREAM_END) nuclear@14: { nuclear@14: png_ptr->zstream.next_out = png_ptr->zbuf; nuclear@14: png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; nuclear@14: } nuclear@14: } nuclear@14: else nuclear@14: { nuclear@14: break; nuclear@14: } nuclear@14: nuclear@14: if (ret == Z_STREAM_END) nuclear@14: break; nuclear@14: } nuclear@14: nuclear@14: inflateReset(&png_ptr->zstream); nuclear@14: png_ptr->zstream.avail_in = 0; nuclear@14: nuclear@14: if (ret != Z_STREAM_END) nuclear@14: { nuclear@14: png_ptr->current_text = NULL; nuclear@14: png_free(png_ptr, key); nuclear@14: png_free(png_ptr, text); nuclear@14: return; nuclear@14: } nuclear@14: nuclear@14: png_ptr->current_text = NULL; nuclear@14: png_free(png_ptr, key); nuclear@14: key = text; nuclear@14: text += key_size; nuclear@14: nuclear@14: text_ptr = (png_textp)png_malloc(png_ptr, nuclear@14: (png_uint_32)png_sizeof(png_text)); nuclear@14: text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt; nuclear@14: text_ptr->key = key; nuclear@14: #ifdef PNG_iTXt_SUPPORTED nuclear@14: text_ptr->lang = NULL; nuclear@14: text_ptr->lang_key = NULL; nuclear@14: #endif nuclear@14: text_ptr->text = text; nuclear@14: nuclear@14: ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); nuclear@14: nuclear@14: png_free(png_ptr, key); nuclear@14: png_free(png_ptr, text_ptr); nuclear@14: nuclear@14: if (ret) nuclear@14: png_warning(png_ptr, "Insufficient memory to store text chunk."); nuclear@14: } nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: #if defined(PNG_READ_iTXt_SUPPORTED) nuclear@14: void /* PRIVATE */ nuclear@14: png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 nuclear@14: length) nuclear@14: { nuclear@14: if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) nuclear@14: { nuclear@14: png_error(png_ptr, "Out of place iTXt"); nuclear@14: info_ptr = info_ptr; /* to quiet some compiler warnings */ nuclear@14: } nuclear@14: nuclear@14: #ifdef PNG_MAX_MALLOC_64K nuclear@14: png_ptr->skip_length = 0; /* This may not be necessary */ nuclear@14: nuclear@14: if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */ nuclear@14: { nuclear@14: png_warning(png_ptr, "iTXt chunk too large to fit in memory"); nuclear@14: png_ptr->skip_length = length - (png_uint_32)65535L; nuclear@14: length = (png_uint_32)65535L; nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: png_ptr->current_text = (png_charp)png_malloc(png_ptr, nuclear@14: (png_uint_32)(length + 1)); nuclear@14: png_ptr->current_text[length] = '\0'; nuclear@14: png_ptr->current_text_ptr = png_ptr->current_text; nuclear@14: png_ptr->current_text_size = (png_size_t)length; nuclear@14: png_ptr->current_text_left = (png_size_t)length; nuclear@14: png_ptr->process_mode = PNG_READ_iTXt_MODE; nuclear@14: } nuclear@14: nuclear@14: void /* PRIVATE */ nuclear@14: png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: nuclear@14: if (png_ptr->buffer_size && png_ptr->current_text_left) nuclear@14: { nuclear@14: png_size_t text_size; nuclear@14: nuclear@14: if (png_ptr->buffer_size < png_ptr->current_text_left) nuclear@14: text_size = png_ptr->buffer_size; nuclear@14: else nuclear@14: text_size = png_ptr->current_text_left; nuclear@14: png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size); nuclear@14: png_ptr->current_text_left -= text_size; nuclear@14: png_ptr->current_text_ptr += text_size; nuclear@14: } nuclear@14: if (!(png_ptr->current_text_left)) nuclear@14: { nuclear@14: png_textp text_ptr; nuclear@14: png_charp key; nuclear@14: int comp_flag; nuclear@14: png_charp lang; nuclear@14: png_charp lang_key; nuclear@14: png_charp text; nuclear@14: int ret; nuclear@14: nuclear@14: if (png_ptr->buffer_size < 4) nuclear@14: { nuclear@14: png_push_save_buffer(png_ptr); nuclear@14: return; nuclear@14: } nuclear@14: nuclear@14: png_push_crc_finish(png_ptr); nuclear@14: nuclear@14: #if defined(PNG_MAX_MALLOC_64K) nuclear@14: if (png_ptr->skip_length) nuclear@14: return; nuclear@14: #endif nuclear@14: nuclear@14: key = png_ptr->current_text; nuclear@14: nuclear@14: for (lang = key; *lang; lang++) nuclear@14: /* empty loop */ ; nuclear@14: nuclear@14: if (lang < key + png_ptr->current_text_size - 3) nuclear@14: lang++; nuclear@14: nuclear@14: comp_flag = *lang++; nuclear@14: lang++; /* skip comp_type, always zero */ nuclear@14: nuclear@14: for (lang_key = lang; *lang_key; lang_key++) nuclear@14: /* empty loop */ ; nuclear@14: lang_key++; /* skip NUL separator */ nuclear@14: nuclear@14: text=lang_key; nuclear@14: if (lang_key < key + png_ptr->current_text_size - 1) nuclear@14: { nuclear@14: for (; *text; text++) nuclear@14: /* empty loop */ ; nuclear@14: } nuclear@14: nuclear@14: if (text < key + png_ptr->current_text_size) nuclear@14: text++; nuclear@14: nuclear@14: text_ptr = (png_textp)png_malloc(png_ptr, nuclear@14: (png_uint_32)png_sizeof(png_text)); nuclear@14: text_ptr->compression = comp_flag + 2; nuclear@14: text_ptr->key = key; nuclear@14: text_ptr->lang = lang; nuclear@14: text_ptr->lang_key = lang_key; nuclear@14: text_ptr->text = text; nuclear@14: text_ptr->text_length = 0; nuclear@14: text_ptr->itxt_length = png_strlen(text); nuclear@14: nuclear@14: ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); nuclear@14: nuclear@14: png_ptr->current_text = NULL; nuclear@14: nuclear@14: png_free(png_ptr, text_ptr); nuclear@14: if (ret) nuclear@14: png_warning(png_ptr, "Insufficient memory to store iTXt chunk."); nuclear@14: } nuclear@14: } nuclear@14: #endif nuclear@14: nuclear@14: /* This function is called when we haven't found a handler for this nuclear@14: * chunk. If there isn't a problem with the chunk itself (ie a bad chunk nuclear@14: * name or a critical chunk), the chunk is (currently) silently ignored. nuclear@14: */ nuclear@14: void /* PRIVATE */ nuclear@14: png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 nuclear@14: length) nuclear@14: { nuclear@14: png_uint_32 skip = 0; nuclear@14: nuclear@14: if (!(png_ptr->chunk_name[0] & 0x20)) nuclear@14: { nuclear@14: #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) nuclear@14: if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != nuclear@14: PNG_HANDLE_CHUNK_ALWAYS nuclear@14: #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) nuclear@14: && png_ptr->read_user_chunk_fn == NULL nuclear@14: #endif nuclear@14: ) nuclear@14: #endif nuclear@14: png_chunk_error(png_ptr, "unknown critical chunk"); nuclear@14: nuclear@14: info_ptr = info_ptr; /* to quiet some compiler warnings */ nuclear@14: } nuclear@14: nuclear@14: #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) nuclear@14: if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) nuclear@14: { nuclear@14: #ifdef PNG_MAX_MALLOC_64K nuclear@14: if (length > (png_uint_32)65535L) nuclear@14: { nuclear@14: png_warning(png_ptr, "unknown chunk too large to fit in memory"); nuclear@14: skip = length - (png_uint_32)65535L; nuclear@14: length = (png_uint_32)65535L; nuclear@14: } nuclear@14: #endif nuclear@14: png_memcpy((png_charp)png_ptr->unknown_chunk.name, nuclear@14: (png_charp)png_ptr->chunk_name, nuclear@14: png_sizeof(png_ptr->unknown_chunk.name)); nuclear@14: png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name) - 1] nuclear@14: = '\0'; nuclear@14: nuclear@14: png_ptr->unknown_chunk.size = (png_size_t)length; nuclear@14: if (length == 0) nuclear@14: png_ptr->unknown_chunk.data = NULL; nuclear@14: else nuclear@14: { nuclear@14: png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, nuclear@14: (png_uint_32)length); nuclear@14: png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length); nuclear@14: } nuclear@14: #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) nuclear@14: if (png_ptr->read_user_chunk_fn != NULL) nuclear@14: { nuclear@14: /* callback to user unknown chunk handler */ nuclear@14: int ret; nuclear@14: ret = (*(png_ptr->read_user_chunk_fn)) nuclear@14: (png_ptr, &png_ptr->unknown_chunk); nuclear@14: if (ret < 0) nuclear@14: png_chunk_error(png_ptr, "error in user chunk"); nuclear@14: if (ret == 0) nuclear@14: { nuclear@14: if (!(png_ptr->chunk_name[0] & 0x20)) nuclear@14: if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != nuclear@14: PNG_HANDLE_CHUNK_ALWAYS) nuclear@14: png_chunk_error(png_ptr, "unknown critical chunk"); nuclear@14: png_set_unknown_chunks(png_ptr, info_ptr, nuclear@14: &png_ptr->unknown_chunk, 1); nuclear@14: } nuclear@14: } nuclear@14: else nuclear@14: #endif nuclear@14: png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1); nuclear@14: png_free(png_ptr, png_ptr->unknown_chunk.data); nuclear@14: png_ptr->unknown_chunk.data = NULL; nuclear@14: } nuclear@14: else nuclear@14: #endif nuclear@14: skip=length; nuclear@14: png_push_crc_skip(png_ptr, skip); nuclear@14: } nuclear@14: nuclear@14: void /* PRIVATE */ nuclear@14: png_push_have_info(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr->info_fn != NULL) nuclear@14: (*(png_ptr->info_fn))(png_ptr, info_ptr); nuclear@14: } nuclear@14: nuclear@14: void /* PRIVATE */ nuclear@14: png_push_have_end(png_structp png_ptr, png_infop info_ptr) nuclear@14: { nuclear@14: if (png_ptr->end_fn != NULL) nuclear@14: (*(png_ptr->end_fn))(png_ptr, info_ptr); nuclear@14: } nuclear@14: nuclear@14: void /* PRIVATE */ nuclear@14: png_push_have_row(png_structp png_ptr, png_bytep row) nuclear@14: { nuclear@14: if (png_ptr->row_fn != NULL) nuclear@14: (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number, nuclear@14: (int)png_ptr->pass); nuclear@14: } nuclear@14: nuclear@14: void PNGAPI nuclear@14: png_progressive_combine_row (png_structp png_ptr, nuclear@14: png_bytep old_row, png_bytep new_row) nuclear@14: { nuclear@14: #ifdef PNG_USE_LOCAL_ARRAYS nuclear@14: PNG_CONST int FARDATA png_pass_dsp_mask[7] = nuclear@14: {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; nuclear@14: #endif nuclear@14: if (png_ptr == NULL) return; nuclear@14: if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */ nuclear@14: png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]); nuclear@14: } nuclear@14: nuclear@14: void PNGAPI nuclear@14: png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr, nuclear@14: png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, nuclear@14: png_progressive_end_ptr end_fn) nuclear@14: { nuclear@14: if (png_ptr == NULL) return; nuclear@14: png_ptr->info_fn = info_fn; nuclear@14: png_ptr->row_fn = row_fn; nuclear@14: png_ptr->end_fn = end_fn; nuclear@14: nuclear@14: png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer); nuclear@14: } nuclear@14: nuclear@14: png_voidp PNGAPI nuclear@14: png_get_progressive_ptr(png_structp png_ptr) nuclear@14: { nuclear@14: if (png_ptr == NULL) return (NULL); nuclear@14: return png_ptr->io_ptr; nuclear@14: } nuclear@14: #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */