Make SkImageDecoder_libpng be compilable with Chromium libpng
Chromium has libpng with pngusr.h that disables certain functionality with defines. Use those defines when compiling SkImageDecoder_libpng.cpp. This makes it possible to use Skia PNG decoder and encoder when compiling dm with Chromium. Skia PNG decoder and encoder of course is not compiled to the skia library, but to dm with Chromium. BUG=skia:2992 Review URL: https://codereview.chromium.org/645883004
This commit is contained in:
parent
468b1815d2
commit
93b255b19e
@ -141,6 +141,7 @@ static void sk_seek_fn(png_structp png_ptr, png_uint_32 offset) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
|
||||
static int sk_read_user_chunk(png_structp png_ptr, png_unknown_chunkp chunk) {
|
||||
SkImageDecoder::Peeker* peeker =
|
||||
(SkImageDecoder::Peeker*)png_get_user_chunk_ptr(png_ptr);
|
||||
@ -148,6 +149,7 @@ static int sk_read_user_chunk(png_structp png_ptr, png_unknown_chunkp chunk) {
|
||||
return peeker->peek((const char*)chunk->name, chunk->data, chunk->size) ?
|
||||
1 : -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void sk_error_fn(png_structp png_ptr, png_const_charp msg) {
|
||||
SkDEBUGF(("------ png error %s\n", msg));
|
||||
@ -266,12 +268,13 @@ bool SkPNGImageDecoder::onDecodeInit(SkStream* sk_stream, png_structp *png_ptrp,
|
||||
/* If we have already read some of the signature */
|
||||
// png_set_sig_bytes(png_ptr, 0 /* sig_read */ );
|
||||
|
||||
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
|
||||
// hookup our peeker so we can see any user-chunks the caller may be interested in
|
||||
png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_ALWAYS, (png_byte*)"", 0);
|
||||
if (this->getPeeker()) {
|
||||
png_set_read_user_chunk_fn(png_ptr, (png_voidp)this->getPeeker(), sk_read_user_chunk);
|
||||
}
|
||||
|
||||
#endif
|
||||
/* The call to png_read_info() gives us all of the information from the
|
||||
* PNG file before the first IDAT (image data chunk). */
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
@ -284,11 +287,13 @@ bool SkPNGImageDecoder::onDecodeInit(SkStream* sk_stream, png_structp *png_ptrp,
|
||||
if (bitDepth == 16) {
|
||||
png_set_strip_16(png_ptr);
|
||||
}
|
||||
#ifdef PNG_READ_PACK_SUPPORTED
|
||||
/* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
|
||||
* byte into separate bytes (useful for paletted and grayscale images). */
|
||||
if (bitDepth < 8) {
|
||||
png_set_packing(png_ptr);
|
||||
}
|
||||
#endif
|
||||
/* Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */
|
||||
if (colorType == PNG_COLOR_TYPE_GRAY && bitDepth < 8) {
|
||||
png_set_expand_gray_1_2_4_to_8(png_ptr);
|
||||
@ -494,6 +499,7 @@ bool SkPNGImageDecoder::getBitmapColorType(png_structp png_ptr, png_infop info_p
|
||||
png_get_IHDR(png_ptr, info_ptr, &origWidth, &origHeight, &bitDepth,
|
||||
&colorType, int_p_NULL, int_p_NULL, int_p_NULL);
|
||||
|
||||
#ifdef PNG_sBIT_SUPPORTED
|
||||
// check for sBIT chunk data, in case we should disable dithering because
|
||||
// our data is not truely 8bits per component
|
||||
png_color_8p sig_bit;
|
||||
@ -509,6 +515,7 @@ bool SkPNGImageDecoder::getBitmapColorType(png_structp png_ptr, png_infop info_p
|
||||
this->setDitherImage(false);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (colorType == PNG_COLOR_TYPE_PALETTE) {
|
||||
bool paletteHasAlpha = hasTransparencyInPalette(png_ptr, info_ptr);
|
||||
@ -1217,8 +1224,9 @@ bool SkPNGImageEncoder::doEncode(SkWStream* stream, const SkBitmap& bitmap,
|
||||
png_set_tRNS(png_ptr, info_ptr, trans, numTrans, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef PNG_sBIT_SUPPORTED
|
||||
png_set_sBIT(png_ptr, info_ptr, &sig_bit);
|
||||
#endif
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
|
||||
const char* srcImage = (const char*)bitmap.getPixels();
|
||||
|
Loading…
Reference in New Issue
Block a user