Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1073)

Unified Diff: third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.cpp

Issue 1460523002: GIF decoding to Index8, unit tests and misusing unit test as benchmark (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup. tableChanged was wrong - do proper check. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.cpp b/third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.cpp
index b332fd9d54f678d45843a7c906dc1d3ff6805cb7..eb0fa536ca26a98b0e144705e1e5485088b9748a 100644
--- a/third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.cpp
+++ b/third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.cpp
@@ -103,6 +103,7 @@ ImageFrameGenerator::ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<Sha
, m_decodeFailedAndEmpty(false)
, m_decodeCount(0)
, m_frameCount(0)
+ , m_decoderCanDecodeToIndex8(false)
{
setData(data.get(), allDataReceived);
}
@@ -125,7 +126,7 @@ void ImageFrameGenerator::copyData(RefPtr<SharedBuffer>* data, bool* allDataRece
*data = buffer->copy();
}
-bool ImageFrameGenerator::decodeAndScale(const SkImageInfo& info, size_t index, void* pixels, size_t rowBytes)
+bool ImageFrameGenerator::decodeAndScale(const SkImageInfo& info, size_t index, void* pixels, size_t rowBytes, SkPMColor ctable[], int* ctableCount)
{
// This method is called to populate a discardable memory owned by Skia.
@@ -143,7 +144,7 @@ bool ImageFrameGenerator::decodeAndScale(const SkImageInfo& info, size_t index,
m_externalAllocator = adoptPtr(new ExternalMemoryAllocator(info, pixels, rowBytes));
- SkBitmap bitmap = tryToResumeDecode(scaledSize, index);
+ SkBitmap bitmap = tryToResumeDecode(scaledSize, index, info.colorType());
if (bitmap.isNull())
return false;
@@ -154,12 +155,25 @@ bool ImageFrameGenerator::decodeAndScale(const SkImageInfo& info, size_t index,
ASSERT(bitmap.width() == scaledSize.width());
ASSERT(bitmap.height() == scaledSize.height());
+ // If decoder cannot produce requested color type, return false.
+ if (bitmap.colorType() != info.colorType())
+ return false;
+
bool result = true;
SkAutoLockPixels bitmapLock(bitmap);
// Check to see if decoder has written directly to the memory provided
// by Skia. If not make a copy.
if (bitmap.getPixels() != pixels)
result = bitmap.copyPixelsTo(pixels, rowBytes * info.height(), rowBytes);
+ if (bitmap.colorType() == kIndex_8_SkColorType && ctable && bitmap.getColorTable()) {
+ memcpy(ctable, bitmap.getColorTable()->readColors(), bitmap.getColorTable()->count() * sizeof(SkPMColor));
+ }
+ if (ctableCount) {
+ // Based on SkImageGenerator API spec, ctableCount needs to be set ot 0 for other types.
+ *ctableCount = (bitmap.colorType() == kIndex_8_SkColorType && bitmap.getColorTable())
+ ? bitmap.getColorTable()->count()
+ : 0;
+ }
return result;
}
@@ -205,7 +219,7 @@ bool ImageFrameGenerator::decodeToYUV(SkISize componentSizes[3], void* planes[3]
return yuvDecoded;
}
-SkBitmap ImageFrameGenerator::tryToResumeDecode(const SkISize& scaledSize, size_t index)
+SkBitmap ImageFrameGenerator::tryToResumeDecode(const SkISize& scaledSize, size_t index, SkColorType outputColor)
{
TRACE_EVENT1("blink", "ImageFrameGenerator::tryToResumeDecodeAndScale", "index", static_cast<int>(index));
@@ -214,7 +228,7 @@ SkBitmap ImageFrameGenerator::tryToResumeDecode(const SkISize& scaledSize, size_
ASSERT(!resumeDecoding || decoder);
SkBitmap fullSizeImage;
- bool complete = decode(index, &decoder, &fullSizeImage);
+ bool complete = decode(index, &decoder, &fullSizeImage, outputColor);
if (!decoder)
return SkBitmap();
@@ -280,7 +294,7 @@ void ImageFrameGenerator::setHasAlpha(size_t index, bool hasAlpha)
m_hasAlpha[index] = hasAlpha;
}
-bool ImageFrameGenerator::decode(size_t index, ImageDecoder** decoder, SkBitmap* bitmap)
+bool ImageFrameGenerator::decode(size_t index, ImageDecoder** decoder, SkBitmap* bitmap, SkColorType outputColor)
{
TRACE_EVENT2("blink", "ImageFrameGenerator::decode", "width", m_fullSize.width(), "height", m_fullSize.height());
@@ -311,7 +325,7 @@ bool ImageFrameGenerator::decode(size_t index, ImageDecoder** decoder, SkBitmap*
}
(*decoder)->setData(data, allDataReceived);
- ImageFrame* frame = (*decoder)->frameBufferAtIndex(index);
+ ImageFrame* frame = (*decoder)->frameBufferAtIndex(index, static_cast<ImageFrame::ColorType>(outputColor));
// For multi-frame image decoders, we need to know how many frames are
// in that image in order to release the decoder when all frames are
// decoded. frameCount() is reliable only if all data is received and set in
@@ -379,4 +393,11 @@ bool ImageFrameGenerator::getYUVComponentSizes(SkISize componentSizes[3])
return updateYUVComponentSizes(decoder.get(), componentSizes, ImageDecoder::SizeForMemoryAllocation);
}
+bool ImageFrameGenerator::canDecodeTo(size_t index, SkColorType outputType)
+{
+ // Skip decoding to get this information but return default.
+ return (outputType == kIndex_8_SkColorType && m_decoderCanDecodeToIndex8) || outputType == kN32_SkColorType;
+}
+
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698