Exemple #1
0
bool SkPNGImageDecoder::onBuildTileIndex(SkStream* sk_stream, int *width,
        int *height) {
    png_structp png_ptr;
    png_infop   info_ptr;

    this->index = new SkPNGImageIndex();

    if (onDecodeInit(sk_stream, &png_ptr, &info_ptr) == false) {
        return false;
    }

// 2013.02.07, jiseon.kwon, set error handling in onBuildTileIndex [START]
    if (setjmp(png_jmpbuf(png_ptr))) {
        return false;
    }
// 2013.02.07, jiseon.kwon, set error handling in onBuildTileIndex [END]

    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;
}
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;
}