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..e7a29c20cf2fe7ffe685550b61189282e2205a97 100644 |
--- a/third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp |
+++ b/third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp |
@@ -94,7 +94,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 char backgroundIndex, bool backgroundIsTransparent) |
+{ |
+ ASSERT(!width() && !height()); |
+ |
+ SkPMColor ctStorage[256]; |
+ SkPMColor* ctStorageIter(ctStorage); |
+ // Copy color palette and set transparent pixel if set. |
+ Vector<PixelData>::const_iterator colorMapEnd = (colorMap.size() <= 256) ? colorMap.end() : (colorMap.begin() + 256); |
scroggo_chromium
2016/01/06 21:50:40
The style guide seems to recommend using an index
aleksandar.stojiljkovic
2016/01/18 13:58:49
Done.
|
+ for (Vector<PixelData>::const_iterator colorMapIter = colorMap.begin(); colorMapIter != colorMapEnd; ) |
+ *ctStorageIter++ = *colorMapIter++; |
+ if (backgroundIsTransparent) { |
+ ASSERT(backgroundIndex < colorMap.size()); |
+ ctStorage[backgroundIndex] = 0; |
+ } |
+ // Fill with backgroundIndex 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)); |
+ size_t rowBytes = (newWidth + sizeof(size_t) - 1) & (~(sizeof(size_t) - 1)); |
scroggo_chromium
2016/01/06 21:50:40
Why'd you choose this rowBytes? If you use zero, S
aleksandar.stojiljkovic
2016/01/18 13:58:49
I think the 0 makes rowBytes equals to newWidth.
scroggo_chromium
2016/04/29 19:48:14
Will you please add a comment explaining this?
|
+ 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()); |
@@ -103,7 +141,9 @@ bool ImageFrame::setSize(int newWidth, int newHeight) |
if (!m_bitmap.tryAllocPixels(m_allocator, 0)) |
return false; |
- zeroFillPixelData(); |
+ m_bitmap.eraseColor(background); |
+ m_hasAlpha = !((background >> 24) == 0xFF); |
scroggo_chromium
2016/01/06 21:50:40
Why not SkColorGetA(background)?
aleksandar.stojiljkovic
2016/01/18 13:58:49
Done. Thanks, didn't know about it.
|
+ |
return true; |
} |
@@ -145,8 +185,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); |
scroggo_chromium
2016/01/06 21:50:40
As stated before, I'm concerned about setting this
aleksandar.stojiljkovic
2016/01/18 13:58:49
Fixed in new patch...
scroggo_chromium
2016/04/29 19:48:14
It's not obvious to me that it is. See comments in
|
+ } |
+ } else { |
+ m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); |
+ } |
setHasAlpha(true); |
} |