diff options
author | Mike Reed <reed@google.com> | 2010-03-03 13:25:57 -0500 |
---|---|---|
committer | Mike Reed <reed@google.com> | 2010-03-03 14:03:46 -0500 |
commit | a29ffdbb516356a3d2e27ddddaedac4ffe870a65 (patch) | |
tree | 15457013fabe0bb28ff11809597a6e04af0708ea /WebCore/platform | |
parent | 4acd3ef4a110a488963ca204c9ceac640fa5b113 (diff) | |
download | external_webkit-a29ffdbb516356a3d2e27ddddaedac4ffe870a65.zip external_webkit-a29ffdbb516356a3d2e27ddddaedac4ffe870a65.tar.gz external_webkit-a29ffdbb516356a3d2e27ddddaedac4ffe870a65.tar.bz2 |
add optional preftable to image codecs, for more control over the resulting bitmap config
http://b/issue?id=2267010
Diffstat (limited to 'WebCore/platform')
-rw-r--r-- | WebCore/platform/graphics/android/ImageSourceAndroid.cpp | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/WebCore/platform/graphics/android/ImageSourceAndroid.cpp b/WebCore/platform/graphics/android/ImageSourceAndroid.cpp index b86763a..fa1794c 100644 --- a/WebCore/platform/graphics/android/ImageSourceAndroid.cpp +++ b/WebCore/platform/graphics/android/ImageSourceAndroid.cpp @@ -60,9 +60,29 @@ SkPixelRef* SkCreateRLEPixelRef(const SkBitmap& src); // see dox for computeMaxBitmapSizeForCache() #define MAX_SIZE_BEFORE_SUBSAMPLE (8*1024*1024) + + // preserve quality for 24/32bit src + static const SkBitmap::Config gPrefConfigTable[6] = { + SkBitmap::kIndex8_Config, // src: index, opaque + SkBitmap::kIndex8_Config, // src: index, alpha + SkBitmap::kRGB_565_Config, // src: 16bit, opaque + SkBitmap::kARGB_8888_Config, // src: 16bit, alpha (promote to 32bit) + SkBitmap::kARGB_8888_Config, // src: 32bit, opaque + SkBitmap::kARGB_8888_Config, // src: 32bit, alpha + }; #else #define MIN_RLE_ALLOC_SIZE (2*1024*1024) #define MAX_SIZE_BEFORE_SUBSAMPLE (2*1024*1024) + + // tries to minimize memory usage (i.e. demote opaque 32bit -> 16bit) + static const SkBitmap::Config gPrefConfigTable[6] = { + SkBitmap::kIndex8_Config, // src: index, opaque + SkBitmap::kIndex8_Config, // src: index, alpha + SkBitmap::kRGB_565_Config, // src: 16bit, opaque + SkBitmap::kARGB_8888_Config, // src: 16bit, alpha (promote to 32bit) + SkBitmap::kRGB_565_Config, // src: 32bit, opaque (demote to 16bit) + SkBitmap::kARGB_8888_Config, // src: 32bit, alpha + }; #endif /* Images larger than this should be subsampled. Using ashmem, the decoded @@ -219,12 +239,13 @@ void ImageSource::setData(SharedBuffer* data, bool allDataReceived) SkMemoryStream stream(data->data(), data->size(), false); SkImageDecoder* codec = SkImageDecoder::Factory(&stream); + if (!codec) + return; + SkAutoTDelete<SkImageDecoder> ad(codec); - - if (!codec || !codec->decode(&stream, &tmp, SkBitmap::kNo_Config, - SkImageDecoder::kDecodeBounds_Mode)) { + codec->setPrefConfigTable(gPrefConfigTable); + if (!codec->decode(&stream, &tmp, SkImageDecoder::kDecodeBounds_Mode)) return; - } int origW = tmp.width(); int origH = tmp.height(); @@ -251,8 +272,8 @@ void ImageSource::setData(SharedBuffer* data, bool allDataReceived) if (sampleSize > 1) { codec->setSampleSize(sampleSize); stream.rewind(); - if (!codec->decode(&stream, &tmp, SkBitmap::kNo_Config, - SkImageDecoder::kDecodeBounds_Mode)) { + if (!codec->decode(&stream, &tmp, + SkImageDecoder::kDecodeBounds_Mode)) { return; } } |