| Index: third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp
|
| diff --git a/third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp b/third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp
|
| index 3b75b8c146cb4f2e29ea3f220fac0f9797a9cdfd..6d21f3faa32604603993dc584e976a9b0a36d6ef 100644
|
| --- a/third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp
|
| +++ b/third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp
|
| @@ -94,6 +94,48 @@ bool ImageFrame::copyBitmapData(const ImageFrame& other)
|
| return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType());
|
| }
|
|
|
| +bool ImageFrame::copyBitmapData(const ImageFrame& other, ColorType targetType)
|
| +{
|
| + if (this == &other)
|
| + return true;
|
| +
|
| + m_hasAlpha = other.m_hasAlpha;
|
| + m_bitmap.reset();
|
| + return other.m_bitmap.copyTo(&m_bitmap, static_cast<SkColorType>(targetType));
|
| +}
|
| +
|
| +bool ImageFrame::setSizeIndex8(int newWidth, int newHeight, const Vector<PixelData>& colorMap, size_t indexOfTransparent)
|
| +{
|
| + ASSERT(!width() && !height());
|
| +
|
| + SkPMColor ctStorage[256];
|
| + SkPMColor* ctStorageIter(ctStorage);
|
| + // Copy color palette and set transparent pixel.
|
| + Vector<PixelData>::const_iterator colorMapEnd = (colorMap.size() <= 256) ? colorMap.end() : (colorMap.begin() + 256);
|
| + for (Vector<PixelData>::const_iterator colorMapIter = colorMap.begin(); colorMapIter != colorMapEnd; )
|
| + *ctStorageIter++ = *colorMapIter++;
|
| + if (indexOfTransparent < colorMap.size()) {
|
| + ctStorage[indexOfTransparent] = 0;
|
| + }
|
| + // Fill with transparent to the end.
|
| + int remaining = 256 - colorMap.size();
|
| + if (remaining > 0)
|
| + memset(ctStorage + 256 - remaining, 0, sizeof(SkPMColor) * remaining);
|
| + SkAutoTUnref<SkColorTable> ctable(new SkColorTable(ctStorage, 256));
|
| + m_bitmap.setInfo(SkImageInfo::Make(newWidth, newHeight, kIndex_8_SkColorType, kPremul_SkAlphaType));
|
| + if (!m_bitmap.tryAllocPixels(m_allocator, ctable))
|
| + return false;
|
| + size_t transparent = 0xFF;
|
| + if (indexOfTransparent < colorMap.size()) {
|
| + transparent = indexOfTransparent;
|
| + }
|
| + for (int j = 0; j < newHeight; ++j) {
|
| + memset(getAddr8(0, j), transparent, sizeof(uint8_t) * newWidth);
|
| + }
|
| + m_hasAlpha = true;
|
| + return true;
|
| +}
|
| +
|
| bool ImageFrame::setSize(int newWidth, int newHeight)
|
| {
|
| // setSize() should only be called once, it leaks memory otherwise.
|
| @@ -145,8 +187,15 @@ void ImageFrame::zeroFillFrameRect(const IntRect& rect)
|
| {
|
| if (rect.isEmpty())
|
| return;
|
| -
|
| - m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0));
|
| + if (m_bitmap.colorType() == kIndex_8_SkColorType) {
|
| + int ymax = std::min(rect.y() + rect.height(), m_bitmap.height());
|
| + int xcount = std::min(rect.width(), m_bitmap.width() - rect.x());
|
| + for (int j = rect.y(); j < ymax; ++j) {
|
| + memset(m_bitmap.getAddr8(0, j), 0xFF, sizeof(uint8_t) * xcount);
|
| + }
|
| + } else {
|
| + m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0));
|
| + }
|
| setHasAlpha(true);
|
| }
|
|
|
|
|