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) |
scroggo_chromium
2015/12/03 21:47:21
This method is almost identical to the other one.
aleksandar.stojiljkovic
2015/12/04 00:07:35
Again had the same reasoning - as this one is conv
|
+{ |
+ if (this == &other) |
scroggo_chromium
2015/12/03 21:47:21
I wonder if we ever reach this condition, or if it
aleksandar.stojiljkovic
2015/12/04 00:07:34
Yes, that is good point. ASSERT and return false i
|
+ 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)); |
scroggo_chromium
2015/12/03 21:47:21
FWIW, since the alpha is either 255 or zero, this
|
+ if (!m_bitmap.tryAllocPixels(m_allocator, ctable)) |
+ return false; |
+ size_t transparent = 0xFF; |
+ if (indexOfTransparent < colorMap.size()) { |
scroggo_chromium
2015/12/03 21:47:21
Otherwise, we'll just initialize the bitmap to 255
aleksandar.stojiljkovic
2015/12/04 00:07:34
Yes, partially downloaded content in that case wou
|
+ transparent = indexOfTransparent; |
+ } |
+ for (int j = 0; j < newHeight; ++j) { |
+ memset(getAddr8(0, j), transparent, sizeof(uint8_t) * newWidth); |
scroggo_chromium
2015/12/03 21:47:21
I think you could do this for the entire image wit
aleksandar.stojiljkovic
2015/12/04 00:07:34
Acknowledged.
|
+ } |
+ 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); |
scroggo_chromium
2015/12/03 21:47:21
Again, this is going to erase to an arbitrary colo
aleksandar.stojiljkovic
2015/12/04 00:07:34
Colortable returned by this decoder always have 25
scroggo_chromium
2015/12/08 22:24:51
Except that if the image has 256 declared colors,
|
+ } |
+ } else { |
+ m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); |
+ } |
setHasAlpha(true); |
} |