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