bool SkPNGImageDecoder::buildTileIndex(SkStream* sk_stream, int *width, int *height, bool isShareable) { png_structp png_ptr; png_infop info_ptr; this->index = new SkPNGImageIndex(); if (!isShareable) { size_t len, inputLen = 0; size_t bufferSize = 4096; void *tmp = sk_malloc_throw(bufferSize); while ((len = sk_stream->read((char*) tmp + inputLen, bufferSize - inputLen)) != 0) { inputLen += len; if (inputLen == bufferSize) { bufferSize *= 2; tmp = sk_realloc_throw(tmp, bufferSize); } } tmp = sk_realloc_throw(tmp, inputLen); SkMemoryStream *mem_stream = new SkMemoryStream(tmp, inputLen, true); this->index->inputStream = mem_stream; sk_stream = mem_stream; } if (onDecodeInit(sk_stream, &png_ptr, &info_ptr) == false) { return false; } int bit_depth, color_type, interlace_type; png_uint_32 origWidth, origHeight; png_get_IHDR(png_ptr, info_ptr, &origWidth, &origHeight, &bit_depth, &color_type, &interlace_type, int_p_NULL, int_p_NULL); *width = origWidth; *height = origHeight; png_build_index(png_ptr); this->index->png_ptr = png_ptr; this->index->info_ptr = info_ptr; return true; }
static SkMemoryStream* adaptor_to_mem_stream(SkStream* stream) { SkASSERT(stream != NULL); size_t bufferSize = 4096; size_t streamLen = 0; size_t len; char* data = (char*)sk_malloc_throw(bufferSize); while ((len = stream->read(data + streamLen, bufferSize - streamLen)) != 0) { streamLen += len; if (streamLen == bufferSize) { bufferSize *= 2; data = (char*)sk_realloc_throw(data, bufferSize); } } data = (char*)sk_realloc_throw(data, streamLen); SkMemoryStream* streamMem = new SkMemoryStream(); streamMem->setMemoryOwned(data, streamLen); return streamMem; }
static void set(char* array[256], int index, SkStream& s, int data) { SkASSERT((unsigned)index <= 255); size_t size = rdata(s, data); if (array[index] == NULL) array[index] = (char*)sk_malloc_throw(size + 1); else { if (strlen(array[index]) < size) array[index] = (char*)sk_realloc_throw(array[index], size + 1); } s.read(array[index], size); array[index][size] = 0; }
static void* pdf_realloc(FPDFEMB_MEMMGR*, void* addr, unsigned int size) { void* newaddr = sk_realloc_throw(addr, size); // SkDebugf("---- pdf_realloc %p %d %p\n", addr, size, newaddr); return newaddr; }
void* sk_realloc_throw(void* buffer, size_t count, size_t elemSize) { return sk_realloc_throw(buffer, SkSafeMath::Mul(count, elemSize)); }