Chromium Code Reviews| 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 8e47908c47ee13170c92c9b8582891dc0242bd59..8e3f5e4344e8b1acc90cbe07a997bb014599191a 100644 |
| --- a/third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp |
| +++ b/third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp |
| @@ -93,7 +93,45 @@ bool ImageFrame::copyBitmapData(const ImageFrame& other) |
| return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); |
| } |
| -bool ImageFrame::setSize(int newWidth, int newHeight) |
| +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, unsigned backgroundIndex, bool backgroundIsTransparent) |
| +{ |
| + ASSERT(!width() && !height()); |
| + |
| + // Copy color palette and set transparent pixel if set. |
| + SkPMColor ctStorage[256]; |
| + ASSERT(colorMap.size() <= 256); |
| + for (size_t i = 0; i < colorMap.size(); ++i) |
| + ctStorage[i] = colorMap[i]; |
| + if (backgroundIsTransparent) { |
| + ASSERT(backgroundIndex < colorMap.size()); |
| + ctStorage[backgroundIndex] = SK_ColorTRANSPARENT; |
| + } |
| + // Fill with transparent to the end. |
| + int remaining = 256 - colorMap.size(); |
| + if (remaining > 0) |
| + memset(ctStorage + 256 - remaining, SK_ColorTRANSPARENT, sizeof(SkPMColor) * remaining); |
| + |
| + SkAutoTUnref<SkColorTable> ctable(new SkColorTable(ctStorage, 256)); |
| + size_t rowBytes = (newWidth + sizeof(size_t) - 1) & (~(sizeof(size_t) - 1)); |
| + m_bitmap.setInfo(SkImageInfo::Make(newWidth, newHeight, kIndex_8_SkColorType, kPremul_SkAlphaType), rowBytes); |
| + if (!m_bitmap.tryAllocPixels(m_allocator, ctable)) |
| + return false; |
| + memset(getAddr8(0, 0), backgroundIndex, rowBytes * newHeight); |
| + m_hasAlpha = backgroundIsTransparent; |
| + return true; |
| +} |
| + |
| +bool ImageFrame::setSize(int newWidth, int newHeight, SkColor background) |
| { |
| // setSize() should only be called once, it leaks memory otherwise. |
| ASSERT(!width() && !height()); |
| @@ -102,7 +140,9 @@ bool ImageFrame::setSize(int newWidth, int newHeight) |
| if (!m_bitmap.tryAllocPixels(m_allocator, 0)) |
| return false; |
| - zeroFillPixelData(); |
| + m_bitmap.eraseColor(background); |
| + m_hasAlpha = !(SkColorGetA(background) == 0xFF); |
| + |
| return true; |
| } |
| @@ -144,9 +184,22 @@ void ImageFrame::zeroFillFrameRect(const IntRect& rect) |
| { |
| if (rect.isEmpty()) |
| return; |
| - |
| m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); |
| setHasAlpha(true); |
| } |
| +void ImageFrame::zeroFillFrameRectIndex8(const IntRect& rect, unsigned char transparentIndex) |
|
scroggo_chromium
2016/04/29 19:48:14
transparentIndex is never used.
|
| +{ |
| + ASSERT(m_bitmap.colorType() == kIndex_8_SkColorType); |
| + |
| + if (rect.isEmpty()) |
| + return; |
| + 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); |
|
scroggo_chromium
2016/04/29 19:48:14
It's not obvious to me that 0xFF in the color tabl
|
| + } |
| + m_hasAlpha = true; |
| +} |
| + |
| } // namespace blink |