Diff
Modified: trunk/Source/WebCore/ChangeLog (205840 => 205841)
--- trunk/Source/WebCore/ChangeLog 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/ChangeLog 2016-09-12 23:51:57 UTC (rev 205841)
@@ -1,3 +1,133 @@
+2016-09-12 Said Abou-Hallawa <sabouhall...@apple.com>
+
+ Move the pixel data of ImageFrame to a separate class named ImageBackingStore
+ https://bugs.webkit.org/show_bug.cgi?id=159679
+
+ Reviewed by Simon Fraser.
+
+ Move the pixel data manipulation part in ImageFrame into a separate class
+ and allocate it on demand.
+
+ * PlatformEfl.cmake:
+ * PlatformGTK.cmake:
+ * PlatformWinCairo.cmake:
+ * WebCore.xcodeproj/project.pbxproj:
+ Add ImageBackingStoreCairo.cpp and remove ImageDecoderCairo.cpp from the
+ WebKit projects.
+
+ * platform/graphics/Color.cpp:
+ (WebCore::premultipliedChannel): channel = channel * alpha / 255.
+ (WebCore::unpremultipliedChannel): channel = channel * 255 / alpha.
+ (WebCore::makePremultipliedRGBA): Un-premultiplied channels to premultiplied RGBA32.
+ (WebCore::makeUnPremultipliedRGBA): Premultiplied channels to un-premultiplied RGBA32.
+ (WebCore::colorFromPremultipliedARGB): Use makeUnPremultipliedRGBA.
+ (WebCore::premultipliedARGBFromColor): Use makePremultipliedRGBA.
+ * platform/graphics/Color.h:
+ (WebCore::fastMultiplyBy255): x * 255 = x * 256 - x = x << 8 - x.
+
+ * platform/graphics/ImageBackingStore.h: Added.
+ (WebCore::ImageBackingStore::create): Creates a new ImageBackingStore.
+ (WebCore::ImageBackingStore::setSize): Changes the pixels size.
+ (WebCore::ImageBackingStore::setFrameRect): This will always just be the entire buffer except for GIF and PNG frames.
+ (WebCore::ImageBackingStore::size): Returns the pixels size.
+ (WebCore::ImageBackingStore::frameRect): Returns the pixels frame rectangle.
+ (WebCore::ImageBackingStore::clear): Clears the entire image.
+ (WebCore::ImageBackingStore::clearRect): Clears a rectangle in the image.
+ (WebCore::ImageBackingStore::repeatFirstRow): Repeats the first row in a rectangle in the image.
+ (WebCore::ImageBackingStore::pixelAt): Returns a pointer to a pixel data.
+ (WebCore::ImageBackingStore::setPixel): Sets the color of a pixel in the image.
+ (WebCore::ImageBackingStore::blendPixel): Blend a color with a pixel in the image.
+ (WebCore::ImageBackingStore::inBounds): Checks if a rectangle is in the bounds of the image.
+ (WebCore::ImageBackingStore::isOverSize): Checks whether a size could not be allocated for an image.
+ (WebCore::ImageBackingStore::ImageBackingStore):
+
+ * platform/graphics/cg/NativeImageCG.cpp:
+ (WebCore::nativeImageHasAlpha): Implement this function. See comments in https://bugs.webkit.org/show_bug.cgi?id=158684.
+
+ * platform/image-decoders/ImageDecoder.cpp:
+ (WebCore::ImageFrame::operator=): copyBitmapData() now copies the frameRect of the ImageBackingStore.
+ (WebCore::ImageFrame::clearPixelData): The pixels data and the pointer to these pixels are now included in the ImageBackingStore.
+ (WebCore::ImageFrame::zeroFillPixelData): Clearing the image pixels are now in ImageBackingStore::clear().
+ (WebCore::ImageFrame::zeroFillFrameRect): Clearing the image pixels are now in ImageBackingStore::clearRect().
+ (WebCore::ImageFrame::copyBitmapData): We either need to create a new ImageBackingStore or nullify the current one.
+ (WebCore::ImageFrame::setSize): ImageFrame::setSize() is supposed to be called once and to create the ImageBackingStore.
+ (WebCore::ImageFrame::setOriginalFrameRect): Delegate this call to ImageBackingStore::setFrameRect().
+ (WebCore::ImageDecoder::frameBytesAtIndex): ImageFrame::PixelData can be replaced by RGBA32.
+
+ * platform/image-decoders/ImageDecoder.h:
+ (WebCore::ImageFrame::copyRowNTimes): The implementation was moved to ImageBackingStore::repeatFirstRow().
+ (WebCore::ImageFrame::size): Gets the size of an image from its ImageBackingStore.
+ (WebCore::ImageFrame::asNewNativeImage): Gets a NtaiveImagePtr from the ImageBackingStore.
+ (WebCore::ImageFrame::backingStore): Returns a raw pointer to the ImageBackingStore.
+ (WebCore::ImageFrame::hasBackingStore): Returns whether the ImageFrame has an ImageBackingStore.
+ (WebCore::ImageFrame::originalFrameRect): Returns the frameRect of the image from its ImageBackingStore.
+ (WebCore::ImageFrame::pixelAt): Delegates the call to the ImageBackingStore.
+ (WebCore::ImageFrame::setPixel): Delegates the call to the ImageBackingStore.
+ (WebCore::ImageFrame::blendPixel): Delegates the call to the ImageBackingStore.
+
+ (WebCore::ImageDecoder::setSize): setSize() now takes an IntSize.
+ (WebCore::ImageFrame::setOriginalFrameRect): Deleted. Moved to ImageDecoder.cpp.
+ (WebCore::ImageFrame::setRGBA): Deleted. Renamed to ImageFrame::setPixel().
+ (WebCore::ImageFrame::getAddr): Deleted. Renamed to ImageFrame::pixelAt().
+ (WebCore::ImageFrame::hasPixelData): Deleted. Renamed to ImageFrame::hasBackingStore().
+ (WebCore::ImageFrame::fixPointUnsignedMultiply): Deleted.
+ (WebCore::ImageFrame::divide255): Deleted. Replaced by fastDivideBy255() from Color.h.
+ (WebCore::ImageFrame::overRGBA): Deleted. Renamed to ImageFrame::blendPixel().
+ (WebCore::ImageFrame::width): Deleted.
+ (WebCore::ImageFrame::height): Deleted.
+ (WebCore::ImageDecoder::isOverSize): Deleted. Moved to ImageBackingStore::isOverSize().
+
+ * platform/image-decoders/bmp/BMPImageReader.cpp:
+ (WebCore::BMPImageReader::decodeBMP):
+ (WebCore::BMPImageReader::processInfoHeader):
+ (WebCore::BMPImageReader::processNonRLEData):
+ * platform/image-decoders/bmp/BMPImageReader.h:
+ (WebCore::BMPImageReader::setI):
+ (WebCore::BMPImageReader::setPixel):
+ (WebCore::BMPImageReader::fillRGBA):
+ (WebCore::BMPImageReader::setRGBA): Deleted.
+ * platform/image-decoders/cairo/ImageBackingStoreCairo.cpp: Added.
+ (WebCore::ImageBackingStore::image):
+ * platform/image-decoders/cairo/ImageDecoderCairo.cpp: Removed.
+ * platform/image-decoders/gif/GIFImageDecoder.cpp:
+ (WebCore::GIFImageDecoder::setSize):
+ (WebCore::GIFImageDecoder::haveDecodedRow):
+ (WebCore::GIFImageDecoder::initFrameBuffer):
+ * platform/image-decoders/gif/GIFImageDecoder.h:
+ * platform/image-decoders/gif/GIFImageReader.cpp:
+ (GIFImageReader::parse):
+ * platform/image-decoders/ico/ICOImageDecoder.cpp:
+ (WebCore::ICOImageDecoder::setSize):
+ (WebCore::ICOImageDecoder::processDirectoryEntries):
+ * platform/image-decoders/ico/ICOImageDecoder.h:
+ * platform/image-decoders/jpeg/JPEGImageDecoder.cpp:
+ (WebCore::JPEGImageReader::decode):
+ (WebCore::JPEGImageDecoder::setSize):
+ (WebCore::setPixel):
+ (WebCore::JPEGImageDecoder::outputScanlines):
+ * platform/image-decoders/jpeg/JPEGImageDecoder.h:
+ * platform/image-decoders/png/PNGImageDecoder.cpp:
+ (WebCore::PNGImageDecoder::setSize):
+ (WebCore::PNGImageDecoder::headerAvailable):
+ (WebCore::setPixelRGB):
+ (WebCore::setPixelRGBA):
+ (WebCore::setPixelPremultipliedRGBA):
+ (WebCore::PNGImageDecoder::rowAvailable):
+ (WebCore::PNGImageDecoder::initFrameBuffer):
+ (WebCore::PNGImageDecoder::frameComplete):
+ * platform/image-decoders/png/PNGImageDecoder.h:
+ * platform/image-decoders/webp/WEBPImageDecoder.cpp:
+ (WebCore::WEBPImageDecoder::decode):
+ - Send an IntSize to ImageFrame::setSize() and ImageDecoder::setSize().
+ - Replace ImageFrame::PixelData by RGBA32.
+ - No need to call ImageFrame::setOriginalFrameRect() if this sets the
+ frameRect to the entire image rectangle since this is done by default
+ in ImageBackingStore::setSize().
+ - ImageBackingStore::image() now replaces ImageFrame::asNewNativeImage().
+ - ImageFrame::setPixel() now replaces ImageFrame::setRGBA().
+ - ImageFrame::blendPixel() now replaces ImageFrame::overRGBA().
+ - ImageFrame::pixelAt() now replaces ImageFrame::getAddr().
+
2016-09-12 Joseph Pecoraro <pecor...@apple.com>
HTMLButtonElement.prototype.click should be HTMLElement.prototype.click
Modified: trunk/Source/WebCore/PlatformEfl.cmake (205840 => 205841)
--- trunk/Source/WebCore/PlatformEfl.cmake 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/PlatformEfl.cmake 2016-09-12 23:51:57 UTC (rev 205841)
@@ -183,10 +183,9 @@
platform/graphics/x11/PlatformDisplayX11.cpp
platform/graphics/x11/XUniqueResource.cpp
+ platform/image-decoders/cairo/ImageBackingStoreCairo.cpp
platform/image-encoders/JPEGImageEncoder.cpp
- platform/image-decoders/cairo/ImageDecoderCairo.cpp
-
platform/network/efl/NetworkStateNotifierEfl.cpp
platform/network/soup/AuthenticationChallengeSoup.cpp
Modified: trunk/Source/WebCore/PlatformGTK.cmake (205840 => 205841)
--- trunk/Source/WebCore/PlatformGTK.cmake 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/PlatformGTK.cmake 2016-09-12 23:51:57 UTC (rev 205841)
@@ -155,7 +155,7 @@
platform/gtk/TemporaryLinkStubs.cpp
platform/gtk/UserAgentGtk.cpp
- platform/image-decoders/cairo/ImageDecoderCairo.cpp
+ platform/image-decoders/cairo/ImageBackingStoreCairo.cpp
platform/mediastream/gtk/SDPProcessorScriptResourceGtk.cpp
Modified: trunk/Source/WebCore/PlatformWinCairo.cmake (205840 => 205841)
--- trunk/Source/WebCore/PlatformWinCairo.cmake 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/PlatformWinCairo.cmake 2016-09-12 23:51:57 UTC (rev 205841)
@@ -46,7 +46,7 @@
platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp
platform/graphics/win/SimpleFontDataCairoWin.cpp
- platform/image-decoders/cairo/ImageDecoderCairo.cpp
+ platform/image-decoders/cairo/ImageBackingStoreCairo.cpp
platform/network/NetworkStorageSessionStub.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (205840 => 205841)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2016-09-12 23:51:57 UTC (rev 205841)
@@ -2275,6 +2275,7 @@
555B87EC1CAAF0AB00349425 /* ImageDecoderCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 555B87EA1CAAF0AB00349425 /* ImageDecoderCG.cpp */; };
555B87ED1CAAF0AB00349425 /* ImageDecoderCG.h in Headers */ = {isa = PBXBuildFile; fileRef = 555B87EB1CAAF0AB00349425 /* ImageDecoderCG.h */; };
55A336F71D8209F40022C4C7 /* NativeImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 55A336F61D8209F40022C4C7 /* NativeImage.h */; };
+ 55A336F91D821E3C0022C4C7 /* ImageBackingStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 55A336F81D821E3C0022C4C7 /* ImageBackingStore.h */; settings = {ATTRIBUTES = (Private, ); }; };
5709E8CD1D413D47003244AC /* WebKitSubtleCrypto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5709E8CA1D413CE3003244AC /* WebKitSubtleCrypto.cpp */; };
5709E8CE1D413D5B003244AC /* JSWebKitSubtleCryptoCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1FF8F661807460800132674 /* JSWebKitSubtleCryptoCustom.cpp */; };
5709E8CF1D413D9A003244AC /* WebKitSubtleCrypto.h in Headers */ = {isa = PBXBuildFile; fileRef = 5709E8CB1D413CE3003244AC /* WebKitSubtleCrypto.h */; };
@@ -9298,6 +9299,7 @@
555B87EA1CAAF0AB00349425 /* ImageDecoderCG.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ImageDecoderCG.cpp; sourceTree = "<group>"; };
555B87EB1CAAF0AB00349425 /* ImageDecoderCG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageDecoderCG.h; sourceTree = "<group>"; };
55A336F61D8209F40022C4C7 /* NativeImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NativeImage.h; sourceTree = "<group>"; };
+ 55A336F81D821E3C0022C4C7 /* ImageBackingStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageBackingStore.h; sourceTree = "<group>"; };
55D408F71A7C631800C78450 /* SVGImageClients.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGImageClients.h; sourceTree = "<group>"; };
5709E8CA1D413CE3003244AC /* WebKitSubtleCrypto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebKitSubtleCrypto.cpp; sourceTree = "<group>"; };
5709E8CB1D413CE3003244AC /* WebKitSubtleCrypto.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitSubtleCrypto.h; sourceTree = "<group>"; };
@@ -20791,6 +20793,7 @@
379919941200DDF400EA041C /* WOFFFileFormat.cpp */,
379919951200DDF400EA041C /* WOFFFileFormat.h */,
55A336F61D8209F40022C4C7 /* NativeImage.h */,
+ 55A336F81D821E3C0022C4C7 /* ImageBackingStore.h */,
);
path = graphics;
sourceTree = "<group>";
@@ -26364,6 +26367,7 @@
582CB0531A78A14B00AFFCC4 /* SimpleLineLayoutTextFragmentIterator.h in Headers */,
C5A1EA7D152BCF08004D00B6 /* SimplifyMarkupCommand.h in Headers */,
572A7F211C6E5719009C6149 /* SimulatedClick.h in Headers */,
+ 55A336F91D821E3C0022C4C7 /* ImageBackingStore.h in Headers */,
31741AAD16636609008A5B7E /* SimulatedClickOptions.h in Headers */,
FD00D7A514A3F61900734011 /* SincResampler.h in Headers */,
51327D6011A33A2B004F9D65 /* SinkDocument.h in Headers */,
Modified: trunk/Source/WebCore/platform/graphics/Color.cpp (205840 => 205841)
--- trunk/Source/WebCore/platform/graphics/Color.cpp 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/platform/graphics/Color.cpp 2016-09-12 23:51:57 UTC (rev 205841)
@@ -49,6 +49,16 @@
static const RGBA32 lightenedBlack = 0xFF545454;
static const RGBA32 darkenedWhite = 0xFFABABAB;
+static inline unsigned premultipliedChannel(unsigned c, unsigned a)
+{
+ return fastDivideBy255(c * a + 254);
+}
+
+static inline unsigned unpremultipliedChannel(unsigned c, unsigned a)
+{
+ return (fastMultiplyBy255(c) + a - 1) / a;
+}
+
RGBA32 makeRGB(int r, int g, int b)
{
return 0xFF000000 | std::max(0, std::min(r, 255)) << 16 | std::max(0, std::min(g, 255)) << 8 | std::max(0, std::min(b, 255));
@@ -59,6 +69,16 @@
return std::max(0, std::min(a, 255)) << 24 | std::max(0, std::min(r, 255)) << 16 | std::max(0, std::min(g, 255)) << 8 | std::max(0, std::min(b, 255));
}
+RGBA32 makePremultipliedRGBA(int r, int g, int b, int a)
+{
+ return makeRGBA(premultipliedChannel(r, a), premultipliedChannel(g, a), premultipliedChannel(b, a), a);
+}
+
+RGBA32 makeUnPremultipliedRGBA(int r, int g, int b, int a)
+{
+ return makeRGBA(unpremultipliedChannel(r, a), unpremultipliedChannel(g, a), unpremultipliedChannel(b, a), a);
+}
+
static int colorFloatToRGBAByte(float f)
{
// We use lroundf and 255 instead of nextafterf(256, 0) to match CG's rounding
@@ -482,14 +502,9 @@
Color colorFromPremultipliedARGB(RGBA32 pixelColor)
{
int alpha = alphaChannel(pixelColor);
- if (alpha && alpha < 255) {
- return Color::createUnchecked(
- redChannel(pixelColor) * 255 / alpha,
- greenChannel(pixelColor) * 255 / alpha,
- blueChannel(pixelColor) * 255 / alpha,
- alpha);
- } else
- return Color(pixelColor);
+ if (alpha && alpha < 255)
+ pixelColor = makeUnPremultipliedRGBA(redChannel(pixelColor), greenChannel(pixelColor), blueChannel(pixelColor), alpha);
+ return Color(pixelColor);
}
RGBA32 premultipliedARGBFromColor(const Color& color)
@@ -497,14 +512,10 @@
unsigned pixelColor;
unsigned alpha = color.alpha();
- if (alpha < 255) {
- pixelColor = Color::createUnchecked(
- fastDivideBy255(color.red() * alpha + 254),
- fastDivideBy255(color.green() * alpha + 254),
- fastDivideBy255(color.blue() * alpha + 254),
- alpha).rgb();
- } else
- pixelColor = color.rgb();
+ if (alpha < 255)
+ pixelColor = makePremultipliedRGBA(color.red(), color.green(), color.blue(), alpha);
+ else
+ pixelColor = color.rgb();
return pixelColor;
}
Modified: trunk/Source/WebCore/platform/graphics/Color.h (205840 => 205841)
--- trunk/Source/WebCore/platform/graphics/Color.h 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/platform/graphics/Color.h 2016-09-12 23:51:57 UTC (rev 205841)
@@ -55,6 +55,9 @@
WEBCORE_EXPORT RGBA32 makeRGB(int r, int g, int b);
WEBCORE_EXPORT RGBA32 makeRGBA(int r, int g, int b, int a);
+RGBA32 makePremultipliedRGBA(int r, int g, int b, int a);
+RGBA32 makeUnPremultipliedRGBA(int r, int g, int b, int a);
+
WEBCORE_EXPORT RGBA32 colorWithOverrideAlpha(RGBA32 color, float overrideAlpha);
WEBCORE_EXPORT RGBA32 colorWithOverrideAlpha(RGBA32 color, Optional<float> overrideAlpha);
@@ -204,6 +207,7 @@
int differenceSquared(const Color&, const Color&);
+uint16_t fastMultiplyBy255(uint16_t value);
uint16_t fastDivideBy255(uint16_t);
#if USE(CG)
@@ -276,6 +280,11 @@
return std::max(0.f, std::min(255.f, std::round(value)));
}
+inline uint16_t fastMultiplyBy255(uint16_t value)
+{
+ return (value << 8) - value;
+}
+
inline uint16_t fastDivideBy255(uint16_t value)
{
// While this is an approximate algorithm for division by 255, it gives perfectly accurate results for 16-bit values.
Added: trunk/Source/WebCore/platform/graphics/ImageBackingStore.h (0 => 205841)
--- trunk/Source/WebCore/platform/graphics/ImageBackingStore.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/ImageBackingStore.h 2016-09-12 23:51:57 UTC (rev 205841)
@@ -0,0 +1,189 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "Color.h"
+#include "IntRect.h"
+#include "IntSize.h"
+#include "NativeImage.h"
+
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class ImageBackingStore {
+ WTF_MAKE_FAST_ALLOCATED;
+public:
+ static std::unique_ptr<ImageBackingStore> create(const IntSize& size, bool premultiplyAlpha = true)
+ {
+ return std::unique_ptr<ImageBackingStore>(new ImageBackingStore(size, premultiplyAlpha));
+ }
+
+ static std::unique_ptr<ImageBackingStore> create(const ImageBackingStore& other)
+ {
+ return std::unique_ptr<ImageBackingStore>(new ImageBackingStore(other));
+ }
+
+ NativeImagePtr image() const;
+
+ bool setSize(const IntSize& size)
+ {
+ if (size.isEmpty() || !m_pixels.tryReserveCapacity(size.area()))
+ return false;
+
+ m_pixels.resize(size.area());
+ m_pixelsPtr = m_pixels.data();
+ m_size = size;
+ m_frameRect = IntRect(IntPoint(), m_size);
+ clear();
+ return true;
+ }
+
+ void setFrameRect(const IntRect& frameRect)
+ {
+ ASSERT(!m_size.isEmpty());
+ ASSERT(inBounds(frameRect));
+ m_frameRect = frameRect;
+ }
+
+ const IntSize& size() const { return m_size; }
+ const IntRect& frameRect() const { return m_frameRect; }
+
+ void clear()
+ {
+ memset(m_pixelsPtr, 0, m_size.area() * sizeof(RGBA32));
+ }
+
+ void clearRect(const IntRect& rect)
+ {
+ if (rect.isEmpty() || !inBounds(rect))
+ return;
+
+ size_t rowBytes = rect.width() * sizeof(RGBA32);
+ RGBA32* start = pixelAt(rect.x(), rect.y());
+ for (int i = 0; i < rect.height(); ++i) {
+ memset(start, 0, rowBytes);
+ start += m_size.width();
+ }
+ }
+
+ void repeatFirstRow(const IntRect& rect)
+ {
+ if (rect.isEmpty() || !inBounds(rect))
+ return;
+
+ size_t rowBytes = rect.width() * sizeof(RGBA32);
+ RGBA32* src = "" rect.y());
+ RGBA32* dest = src + m_size.width();
+ for (int i = 1; i < rect.height(); ++i) {
+ memcpy(dest, src, rowBytes);
+ dest += m_size.width();
+ }
+ }
+
+ RGBA32* pixelAt(int x, int y) const
+ {
+ return m_pixelsPtr + y * m_size.width() + x;
+ }
+
+ void setPixel(int x, int y, unsigned r, unsigned g, unsigned b, unsigned a)
+ {
+ setPixel(pixelAt(x, y), r, g, b, a);
+ }
+
+ void setPixel(RGBA32* dest, unsigned r, unsigned g, unsigned b, unsigned a)
+ {
+ if (m_premultiplyAlpha && !a)
+ *dest = 0;
+ else if (m_premultiplyAlpha && a < 255)
+ *dest = makePremultipliedRGBA(r, g, b, a);
+ else
+ *dest = makeRGBA(r, g, b, a);
+ }
+
+ void blendPixel(RGBA32* dest, unsigned r, unsigned g, unsigned b, unsigned a)
+ {
+ if (!a)
+ return;
+
+ if (a >= 255 || !alphaChannel(*dest)) {
+ setPixel(dest, r, g, b, a);
+ return;
+ }
+
+ if (!m_premultiplyAlpha)
+ *dest = makePremultipliedRGBA(redChannel(*dest), greenChannel(*dest), blueChannel(*dest), alphaChannel(*dest));
+
+ unsigned d = 255 - a;
+
+ r = fastDivideBy255(r * a + redChannel(*dest) * d);
+ g = fastDivideBy255(g * a + greenChannel(*dest) * d);
+ b = fastDivideBy255(b * a + blueChannel(*dest) * d);
+ a += fastDivideBy255(d * alphaChannel(*dest));
+
+ if (m_premultiplyAlpha)
+ *dest = makeRGBA(r, g, b, a);
+ else
+ *dest = makeUnPremultipliedRGBA(r, g, b, a);
+ }
+
+ bool inBounds(const IntRect& rect) const
+ {
+ return IntRect(IntPoint(), m_size).contains(rect);
+ }
+
+ static bool isOverSize(const IntSize& size)
+ {
+ static unsigned long long MaxPixels = ((1 << 29) - 1);
+ unsigned long long pixels = static_cast<unsigned long long>(size.width()) * static_cast<unsigned long long>(size.height());
+ return pixels > MaxPixels;
+ }
+
+private:
+ ImageBackingStore(const IntSize& size, bool premultiplyAlpha = true)
+ : m_premultiplyAlpha(premultiplyAlpha)
+ {
+ ASSERT(!size.isEmpty() && !isOverSize(size));
+ setSize(size);
+ }
+
+ ImageBackingStore(const ImageBackingStore& other)
+ : m_pixels(other.m_pixels)
+ , m_size(other.m_size)
+ , m_premultiplyAlpha(other.m_premultiplyAlpha)
+ {
+ ASSERT(!m_size.isEmpty() && !isOverSize(m_size));
+ m_pixelsPtr = m_pixels.data();
+ }
+
+ Vector<RGBA32> m_pixels;
+ RGBA32* m_pixelsPtr { nullptr };
+ IntSize m_size;
+ IntRect m_frameRect; // This will always just be the entire buffer except for GIF and PNG frames
+ bool m_premultiplyAlpha { true };
+};
+
+}
Modified: trunk/Source/WebCore/platform/graphics/cg/NativeImageCG.cpp (205840 => 205841)
--- trunk/Source/WebCore/platform/graphics/cg/NativeImageCG.cpp 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/platform/graphics/cg/NativeImageCG.cpp 2016-09-12 23:51:57 UTC (rev 205841)
@@ -47,10 +47,10 @@
return image ? IntSize(CGImageGetWidth(image.get()), CGImageGetHeight(image.get())) : IntSize();
}
-bool nativeImageHasAlpha(const NativeImagePtr&)
+bool nativeImageHasAlpha(const NativeImagePtr& image)
{
- // FIXME: Answer correctly the question: does the CGImageRef have alpha channnel?
- return true;
+ CGImageAlphaInfo info = CGImageGetAlphaInfo(image.get());
+ return (info >= kCGImageAlphaPremultipliedLast) && (info <= kCGImageAlphaFirst);
}
Color nativeImageSinglePixelSolidColor(const NativeImagePtr& image)
Modified: trunk/Source/WebCore/platform/image-decoders/ImageDecoder.cpp (205840 => 205841)
--- trunk/Source/WebCore/platform/image-decoders/ImageDecoder.cpp 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/platform/image-decoders/ImageDecoder.cpp 2016-09-12 23:51:57 UTC (rev 205841)
@@ -142,7 +142,7 @@
return *this;
copyBitmapData(other);
- setOriginalFrameRect(other.originalFrameRect());
+ setHasAlpha(other.m_hasAlpha);
setStatus(other.status());
setDuration(other.duration());
setDisposalMethod(other.disposalMethod());
@@ -152,8 +152,7 @@
void ImageFrame::clearPixelData()
{
- m_backingStore.clear();
- m_bytes = 0;
+ m_backingStore = nullptr;
m_status = FrameEmpty;
// NOTE: Do not reset other members here; clearFrameBufferCache() calls this
// to free the bitmap data, but other functions like initFrameBuffer() and
@@ -163,24 +162,16 @@
void ImageFrame::zeroFillPixelData()
{
- memset(m_bytes, 0, m_size.width() * m_size.height() * sizeof(PixelData));
+ m_backingStore->clear();
m_hasAlpha = true;
}
void ImageFrame::zeroFillFrameRect(const IntRect& rect)
{
- ASSERT(IntRect(IntPoint(), m_size).contains(rect));
-
if (rect.isEmpty())
return;
- size_t rectWidthInBytes = rect.width() * sizeof(PixelData);
- PixelData* start = m_bytes + (rect.y() * width()) + rect.x();
- for (int i = 0; i < rect.height(); ++i) {
- memset(start, 0, rectWidthInBytes);
- start += width();
- }
-
+ m_backingStore->clearRect(rect);
setHasAlpha(true);
}
@@ -189,25 +180,19 @@
if (this == &other)
return true;
- m_backingStore = other.m_backingStore;
- m_bytes = m_backingStore.data();
- m_size = other.m_size;
- setHasAlpha(other.m_hasAlpha);
+ if (other.m_backingStore)
+ m_backingStore = ImageBackingStore::create(*other.m_backingStore.get());
+ else
+ m_backingStore = nullptr;
+
return true;
}
-bool ImageFrame::setSize(int newWidth, int newHeight)
+bool ImageFrame::setSize(const IntSize& size)
{
- ASSERT(!width() && !height());
- size_t backingStoreSize = newWidth * newHeight;
- if (!m_backingStore.tryReserveCapacity(backingStoreSize))
- return false;
- m_backingStore.resize(backingStoreSize);
- m_bytes = m_backingStore.data();
- m_size = IntSize(newWidth, newHeight);
-
- zeroFillPixelData();
- return true;
+ ASSERT(!m_backingStore);
+ m_backingStore = ImageBackingStore::create(size, m_premultiplyAlpha);
+ return m_backingStore != nullptr;
}
bool ImageFrame::hasAlpha() const
@@ -220,6 +205,12 @@
m_hasAlpha = alpha;
}
+void ImageFrame::setOriginalFrameRect(const IntRect& frameRect)
+{
+ if (m_backingStore)
+ m_backingStore->setFrameRect(frameRect);
+}
+
void ImageFrame::setStatus(FrameStatus status)
{
m_status = status;
@@ -286,7 +277,7 @@
if (m_frameBufferCache.size() <= index)
return 0;
// FIXME: Use the dimension of the requested frame.
- return m_size.area() * sizeof(ImageFrame::PixelData);
+ return m_size.area() * sizeof(RGBA32);
}
float ImageDecoder::frameDurationAtIndex(size_t index)
Modified: trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h (205840 => 205841)
--- trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h 2016-09-12 23:51:57 UTC (rev 205841)
@@ -28,8 +28,10 @@
#pragma once
+#include "ImageBackingStore.h"
+#include "ImageSource.h"
#include "IntRect.h"
-#include "ImageSource.h"
+#include "IntSize.h"
#include "PlatformScreen.h"
#include "SharedBuffer.h"
#include <wtf/Assertions.h>
@@ -57,7 +59,6 @@
DisposeOverwritePrevious // Clear frame to previous framebuffer
// contents
};
- typedef unsigned PixelData;
ImageFrame();
@@ -82,28 +83,25 @@
// endY.
void copyRowNTimes(int startX, int endX, int startY, int endY)
{
- ASSERT(startX < width());
- ASSERT(endX <= width());
- ASSERT(startY < height());
- ASSERT(endY <= height());
- const int rowBytes = (endX - startX) * sizeof(PixelData);
- const PixelData* const startAddr = getAddr(startX, startY);
- for (int destY = startY + 1; destY < endY; ++destY)
- memcpy(getAddr(startX, destY), startAddr, rowBytes);
+ m_backingStore->repeatFirstRow(IntRect(startX, startY, endX -startX , endY - startY));
}
// Allocates space for the pixel data. Must be called before any pixels
// are written. Must only be called once. Returns whether allocation
// succeeded.
- bool setSize(int newWidth, int newHeight);
+ bool setSize(const IntSize&);
+ IntSize size() const { return m_backingStore ? m_backingStore->size() : IntSize(); }
// Returns a caller-owned pointer to the underlying native image data.
// (Actual use: This pointer will be owned by BitmapImage and freed in
// FrameData::clear()).
- NativeImagePtr asNewNativeImage() const;
+ NativeImagePtr asNewNativeImage() const { return m_backingStore ? m_backingStore->image() : nullptr; }
+ inline ImageBackingStore* backingStore() const { return m_backingStore ? m_backingStore.get() : nullptr; }
+ inline bool hasBackingStore() const { return backingStore(); }
+
bool hasAlpha() const;
- const IntRect& originalFrameRect() const { return m_originalFrameRect; }
+ IntRect originalFrameRect() const { return m_backingStore ? m_backingStore->frameRect() : IntRect(); }
FrameStatus status() const { return m_status; }
unsigned duration() const { return m_duration; }
FrameDisposalMethod disposalMethod() const { return m_disposalMethod; }
@@ -110,114 +108,41 @@
bool premultiplyAlpha() const { return m_premultiplyAlpha; }
void setHasAlpha(bool alpha);
- void setOriginalFrameRect(const IntRect& r) { m_originalFrameRect = r; }
+ void setOriginalFrameRect(const IntRect&);
void setStatus(FrameStatus status);
void setDuration(unsigned duration) { m_duration = duration; }
void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; }
void setPremultiplyAlpha(bool premultiplyAlpha) { m_premultiplyAlpha = premultiplyAlpha; }
- inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, unsigned a)
+ inline RGBA32* pixelAt(int x, int y)
{
- setRGBA(getAddr(x, y), r, g, b, a);
+ ASSERT(m_backingStore);
+ return m_backingStore->pixelAt(x, y);
}
- inline PixelData* getAddr(int x, int y)
+ inline void setPixel(int x, int y, unsigned r, unsigned g, unsigned b, unsigned a)
{
- return m_bytes + (y * width()) + x;
+ ASSERT(m_backingStore);
+ m_backingStore->setPixel(x, y, r, g, b, a);
}
- inline bool hasPixelData() const
+ inline void setPixel(RGBA32* dest, unsigned r, unsigned g, unsigned b, unsigned a)
{
- return m_bytes;
+ ASSERT(m_backingStore);
+ m_backingStore->setPixel(dest, r, g, b, a);
}
- // Use fix point multiplier instead of integer division or floating point math.
- // This multipler produces exactly the same result for all values in range 0 - 255.
- static const unsigned fixPointShift = 24;
- static const unsigned fixPointMult = static_cast<unsigned>(1.0 / 255.0 * (1 << fixPointShift)) + 1;
- // Multiplies unsigned value by fixpoint value and converts back to unsigned.
- static unsigned fixPointUnsignedMultiply(unsigned fixed, unsigned v)
- {
- return (fixed * v) >> fixPointShift;
- }
-
- inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, unsigned a)
- {
- if (m_premultiplyAlpha && a < 255) {
- if (!a) {
- *dest = 0;
- return;
- }
-
- unsigned alphaMult = a * fixPointMult;
- r = fixPointUnsignedMultiply(r, alphaMult);
- g = fixPointUnsignedMultiply(g, alphaMult);
- b = fixPointUnsignedMultiply(b, alphaMult);
- }
- *dest = (a << 24 | r << 16 | g << 8 | b);
- }
-
#if ENABLE(APNG)
- static inline unsigned divide255(unsigned a)
+ inline void blendPixel(RGBA32* dest, unsigned r, unsigned g, unsigned b, unsigned a)
{
- return (a + (a >> 8) + 1) >> 8;
+ ASSERT(m_backingStore);
+ m_backingStore->blendPixel(dest, r, g, b, a);
}
-
- inline void overRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, unsigned a)
- {
- if (!a)
- return;
-
- if (a < 255) {
- unsigned aDest = ((*dest) >> 24) & 255;
- if (aDest) {
- unsigned rDest = ((*dest) >> 16) & 255;
- unsigned gDest = ((*dest) >> 8) & 255;
- unsigned bDest = (*dest) & 255;
- unsigned aAux = 255 - a;
- if (!m_premultiplyAlpha) {
- rDest = divide255(rDest * aDest);
- gDest = divide255(gDest * aDest);
- bDest = divide255(bDest * aDest);
- }
- r = divide255(r * a + rDest * aAux);
- g = divide255(g * a + gDest * aAux);
- b = divide255(b * a + bDest * aAux);
- a += divide255(aDest * aAux);
- if (!m_premultiplyAlpha) {
- r = (r * 255 + a - 1) / a;
- g = (g * 255 + a - 1) / a;
- b = (b * 255 + a - 1) / a;
- }
- } else if (m_premultiplyAlpha) {
- r = divide255(r * a);
- g = divide255(g * a);
- b = divide255(b * a);
- }
- }
- *dest = (a << 24 | r << 16 | g << 8 | b);
- }
#endif
private:
- int width() const
- {
- return m_size.width();
- }
-
- int height() const
- {
- return m_size.height();
- }
-
- Vector<PixelData> m_backingStore;
- PixelData* m_bytes; // The memory is backed by m_backingStore.
- IntSize m_size;
+ std::unique_ptr<ImageBackingStore> m_backingStore;
bool m_hasAlpha;
- IntRect m_originalFrameRect; // This will always just be the entire
- // buffer except for GIF frames whose
- // original rect was smaller than the
- // overall image size.
FrameStatus m_status;
unsigned m_duration;
FrameDisposalMethod m_disposalMethod;
@@ -287,11 +212,11 @@
// Returns whether the size is legal (i.e. not going to result in
// overflow elsewhere). If not, marks decoding as failed.
- virtual bool setSize(unsigned width, unsigned height)
+ virtual bool setSize(const IntSize& size)
{
- if (isOverSize(width, height))
+ if (ImageBackingStore::isOverSize(size))
return setFailed();
- m_size = IntSize(width, height);
+ m_size = size;
m_sizeAvailable = true;
return true;
}
@@ -386,15 +311,6 @@
ImageOrientation m_orientation;
private:
- // Some code paths compute the size of the image as "width * height * 4"
- // and return it as a (signed) int. Avoid overflow.
- static bool isOverSize(unsigned width, unsigned height)
- {
- unsigned long long total_size = static_cast<unsigned long long>(width)
- * static_cast<unsigned long long>(height);
- return total_size > ((1 << 29) - 1);
- }
-
IntSize m_size;
bool m_sizeAvailable { false };
#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
Modified: trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageReader.cpp (205840 => 205841)
--- trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageReader.cpp 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageReader.cpp 2016-09-12 23:51:57 UTC (rev 205841)
@@ -78,7 +78,7 @@
// Initialize the framebuffer if needed.
ASSERT(m_buffer); // Parent should set this before asking us to decode!
if (m_buffer->status() == ImageFrame::FrameEmpty) {
- if (!m_buffer->setSize(m_parent->size().width(), m_parent->size().height()))
+ if (!m_buffer->setSize(m_parent->size()))
return m_parent->setFailed(); // Unable to allocate.
m_buffer->setStatus(ImageFrame::FramePartial);
// setSize() calls eraseARGB(), which resets the alpha flag, so we force
@@ -86,9 +86,6 @@
// these 0s could actually show through.
m_buffer->setHasAlpha(false);
- // For BMPs, the frame always fills the entire image.
- m_buffer->setOriginalFrameRect(IntRect(IntPoint(), m_parent->size()));
-
if (!m_isTopDown)
m_coord.setY(m_parent->size().height() - 1);
}
@@ -171,7 +168,7 @@
return m_parent->setFailed();
// Set our size.
- if (!m_parent->setSize(m_infoHeader.biWidth, m_infoHeader.biHeight))
+ if (!m_parent->setSize(IntSize(m_infoHeader.biWidth, m_infoHeader.biHeight)))
return false;
// For paletted images, bitmaps can set biClrUsed to 0 to mean "all
@@ -674,7 +671,7 @@
// transparent, on the assumption that most ICOs on the
// web will not be doing a lot of inverting.
if (colorIndex) {
- setRGBA(0, 0, 0, 0);
+ setPixel(0, 0, 0, 0);
m_buffer->setHasAlpha(true);
} else
m_coord.move(1, 0);
@@ -713,7 +710,7 @@
m_buffer->setHasAlpha(true);
}
- setRGBA(getComponent(pixel, 0), getComponent(pixel, 1),
+ setPixel(getComponent(pixel, 0), getComponent(pixel, 1),
getComponent(pixel, 2), alpha);
}
}
Modified: trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageReader.h (205840 => 205841)
--- trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageReader.h 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/platform/image-decoders/bmp/BMPImageReader.h 2016-09-12 23:51:57 UTC (rev 205841)
@@ -239,16 +239,16 @@
// right by one.
inline void setI(size_t colorIndex)
{
- setRGBA(m_colorTable[colorIndex].rgbRed, m_colorTable[colorIndex].rgbGreen, m_colorTable[colorIndex].rgbBlue, 0xff);
+ setPixel(m_colorTable[colorIndex].rgbRed, m_colorTable[colorIndex].rgbGreen, m_colorTable[colorIndex].rgbBlue, 0xff);
}
// Like setI(), but with the individual component values specified.
- inline void setRGBA(unsigned red,
+ inline void setPixel(unsigned red,
unsigned green,
unsigned blue,
unsigned alpha)
{
- m_buffer->setRGBA(m_coord.x(), m_coord.y(), red, green, blue, alpha);
+ m_buffer->setPixel(m_coord.x(), m_coord.y(), red, green, blue, alpha);
m_coord.move(1, 0);
}
@@ -263,7 +263,7 @@
unsigned alpha)
{
while (m_coord.x() < endCoord)
- setRGBA(red, green, blue, alpha);
+ setPixel(red, green, blue, alpha);
}
// Resets the relevant local variables to start drawing at the left edge
Copied: trunk/Source/WebCore/platform/image-decoders/cairo/ImageBackingStoreCairo.cpp (from rev 205839, trunk/Source/WebCore/platform/image-decoders/cairo/ImageDecoderCairo.cpp) (0 => 205841)
--- trunk/Source/WebCore/platform/image-decoders/cairo/ImageBackingStoreCairo.cpp (rev 0)
+++ trunk/Source/WebCore/platform/image-decoders/cairo/ImageBackingStoreCairo.cpp 2016-09-12 23:51:57 UTC (rev 205841)
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ImageBackingStore.h"
+
+#include <cairo.h>
+
+namespace WebCore {
+
+NativeImagePtr ImageBackingStore::image() const
+{
+ return adoptRef(cairo_image_surface_create_for_data(
+ reinterpret_cast<unsigned char*>(const_cast<RGBA32*>(m_pixelsPtr)),
+ CAIRO_FORMAT_ARGB32, size().width(), size().height(), size().width() * sizeof(RGBA32)));
+}
+
+} // namespace WebCore
Deleted: trunk/Source/WebCore/platform/image-decoders/cairo/ImageDecoderCairo.cpp (205840 => 205841)
--- trunk/Source/WebCore/platform/image-decoders/cairo/ImageDecoderCairo.cpp 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/platform/image-decoders/cairo/ImageDecoderCairo.cpp 2016-09-12 23:51:57 UTC (rev 205841)
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2006 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "ImageDecoder.h"
-
-#include <cairo.h>
-
-namespace WebCore {
-
-NativeImagePtr ImageFrame::asNewNativeImage() const
-{
- return adoptRef(cairo_image_surface_create_for_data(
- reinterpret_cast<unsigned char*>(const_cast<PixelData*>(m_bytes)),
- CAIRO_FORMAT_ARGB32, width(), height(), width() * sizeof(PixelData)));
-}
-
-} // namespace WebCore
Modified: trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp (205840 => 205841)
--- trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp 2016-09-12 23:51:57 UTC (rev 205841)
@@ -60,12 +60,12 @@
return ImageDecoder::isSizeAvailable();
}
-bool GIFImageDecoder::setSize(unsigned width, unsigned height)
+bool GIFImageDecoder::setSize(const IntSize& size)
{
- if (ImageDecoder::isSizeAvailable() && size() == IntSize(width, height))
+ if (ImageDecoder::isSizeAvailable() && this->size() == size)
return true;
- if (!ImageDecoder::setSize(width, height))
+ if (!ImageDecoder::setSize(size))
return false;
prepareScaleDataIfNecessary();
@@ -213,16 +213,16 @@
// Initialize the frame if necessary.
ImageFrame& buffer = m_frameBufferCache[frameIndex];
- if (((buffer.status() == ImageFrame::FrameEmpty) && !initFrameBuffer(frameIndex)) || !buffer.hasPixelData())
+ if (((buffer.status() == ImageFrame::FrameEmpty) && !initFrameBuffer(frameIndex)) || !buffer.hasBackingStore())
return false;
- ImageFrame::PixelData* currentAddress = buffer.getAddr(xBegin, yBegin);
+ RGBA32* currentAddress = buffer.pixelAt(xBegin, yBegin);
// Write one row's worth of data into the frame.
for (int x = xBegin; x < xEnd; ++x) {
const unsigned char sourceValue = rowBuffer[(m_scaled ? m_scaledColumns[x] : x) - frameContext->xOffset];
if ((!frameContext->isTransparent || (sourceValue != frameContext->tpixel)) && (sourceValue < colorMapSize)) {
const size_t colorIndex = static_cast<size_t>(sourceValue) * 3;
- buffer.setRGBA(currentAddress, colorMap[colorIndex], colorMap[colorIndex + 1], colorMap[colorIndex + 2], 255);
+ buffer.setPixel(currentAddress, colorMap[colorIndex], colorMap[colorIndex + 1], colorMap[colorIndex + 2], 255);
} else {
m_currentBufferSawAlpha = true;
// We may or may not need to write transparent pixels to the buffer.
@@ -233,7 +233,7 @@
// beyond the first, or the initial passes will "show through" the
// later ones.
if (writeTransparentPixels)
- buffer.setRGBA(currentAddress, 0, 0, 0, 0);
+ buffer.setPixel(currentAddress, 0, 0, 0, 0);
}
++currentAddress;
}
@@ -361,7 +361,7 @@
if (!frameIndex) {
// This is the first frame, so we're not relying on any previous data.
- if (!buffer->setSize(scaledSize().width(), scaledSize().height()))
+ if (!buffer->setSize(scaledSize()))
return setFailed();
} else {
// The starting state for this frame depends on the previous frame's
@@ -387,12 +387,12 @@
} else {
// We want to clear the previous frame to transparent, without
// affecting pixels in the image outside of the frame.
- const IntRect& prevRect = prevBuffer->originalFrameRect();
+ IntRect prevRect = prevBuffer->originalFrameRect();
const IntSize& bufferSize = scaledSize();
if (!frameIndex || prevRect.contains(IntRect(IntPoint(), scaledSize()))) {
// Clearing the first frame, or a frame the size of the whole
// image, results in a completely empty image.
- if (!buffer->setSize(bufferSize.width(), bufferSize.height()))
+ if (!buffer->setSize(bufferSize))
return setFailed();
} else {
// Copy the whole previous buffer, then clear just its frame.
Modified: trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.h (205840 => 205841)
--- trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.h 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.h 2016-09-12 23:51:57 UTC (rev 205841)
@@ -44,7 +44,7 @@
String filenameExtension() const override { return "gif"; }
void setData(SharedBuffer& data, bool allDataReceived) override;
bool isSizeAvailable() override;
- bool setSize(unsigned width, unsigned height) override;
+ bool setSize(const IntSize&) override;
size_t frameCount() override;
int repetitionCount() const override;
ImageFrame* frameBufferAtIndex(size_t index) override;
Modified: trunk/Source/WebCore/platform/image-decoders/gif/GIFImageReader.cpp (205840 => 205841)
--- trunk/Source/WebCore/platform/image-decoders/gif/GIFImageReader.cpp 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/platform/image-decoders/gif/GIFImageReader.cpp 2016-09-12 23:51:57 UTC (rev 205841)
@@ -447,7 +447,7 @@
// CALLBACK: Inform the decoderplugin of our size.
// Note: A subsequent frame might have dimensions larger than the "screen" dimensions.
- if (m_client && !m_client->setSize(m_screenWidth, m_screenHeight))
+ if (m_client && !m_client->setSize(WebCore::IntSize(m_screenWidth, m_screenHeight)))
return false;
m_screenBgcolor = currentComponent[5];
@@ -664,7 +664,7 @@
yOffset = 0;
// CALLBACK: Inform the decoderplugin of our size.
- if (m_client && !m_client->setSize(m_screenWidth, m_screenHeight))
+ if (m_client && !m_client->setSize(WebCore::IntSize(m_screenWidth, m_screenHeight)))
return false;
}
Modified: trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp (205840 => 205841)
--- trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.cpp 2016-09-12 23:51:57 UTC (rev 205841)
@@ -88,11 +88,11 @@
return (index && (index < m_dirEntries.size())) ? m_dirEntries[index].m_size : size();
}
-bool ICOImageDecoder::setSize(unsigned width, unsigned height)
+bool ICOImageDecoder::setSize(const IntSize& size)
{
// The size calculated inside the BMPImageReader had better match the one in
// the icon directory.
- return m_frameSize.isEmpty() ? ImageDecoder::setSize(width, height) : ((IntSize(width, height) == m_frameSize) || setFailed());
+ return m_frameSize.isEmpty() ? ImageDecoder::setSize(size) : ((size == m_frameSize) || setFailed());
}
size_t ICOImageDecoder::frameCount()
@@ -279,7 +279,7 @@
const IconDirectoryEntry& dirEntry = m_dirEntries.first();
// Technically, this next call shouldn't be able to fail, since the width
// and height here are each <= 256, and |m_frameSize| is empty.
- return setSize(dirEntry.m_size.width(), dirEntry.m_size.height());
+ return setSize(dirEntry.m_size);
}
ICOImageDecoder::IconDirectoryEntry ICOImageDecoder::readDirectoryEntry()
Modified: trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.h (205840 => 205841)
--- trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.h 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/platform/image-decoders/ico/ICOImageDecoder.h 2016-09-12 23:51:57 UTC (rev 205841)
@@ -49,7 +49,7 @@
bool isSizeAvailable() override;
IntSize size() override;
IntSize frameSizeAtIndex(size_t, SubsamplingLevel) override;
- bool setSize(unsigned width, unsigned height) override;
+ bool setSize(const IntSize&) override;
size_t frameCount() override;
ImageFrame* frameBufferAtIndex(size_t) override;
// CAUTION: setFailed() deletes all readers and decoders. Be careful to
Modified: trunk/Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp (205840 => 205841)
--- trunk/Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp 2016-09-12 23:51:57 UTC (rev 205841)
@@ -322,7 +322,7 @@
m_state = JPEG_START_DECOMPRESS;
// We can fill in the size now that the header is available.
- if (!m_decoder->setSize(m_info.image_width, m_info.image_height))
+ if (!m_decoder->setSize(IntSize(m_info.image_width, m_info.image_height)))
return false;
m_decoder->setOrientation(readImageOrientation(info()));
@@ -519,9 +519,9 @@
return ImageDecoder::isSizeAvailable();
}
-bool JPEGImageDecoder::setSize(unsigned width, unsigned height)
+bool JPEGImageDecoder::setSize(const IntSize& size)
{
- if (!ImageDecoder::setSize(width, height))
+ if (!ImageDecoder::setSize(size))
return false;
prepareScaleDataIfNecessary();
@@ -551,13 +551,13 @@
}
template <J_COLOR_SPACE colorSpace>
-void setPixel(ImageFrame& buffer, ImageFrame::PixelData* currentAddress, JSAMPARRAY samples, int column)
+void setPixel(ImageFrame& buffer, RGBA32* currentAddress, JSAMPARRAY samples, int column)
{
JSAMPLE* jsample = *samples + column * (colorSpace == JCS_RGB ? 3 : 4);
switch (colorSpace) {
case JCS_RGB:
- buffer.setRGBA(currentAddress, jsample[0], jsample[1], jsample[2], 0xFF);
+ buffer.setPixel(currentAddress, jsample[0], jsample[1], jsample[2], 0xFF);
break;
case JCS_CMYK:
// Source is 'Inverted CMYK', output is RGB.
@@ -570,7 +570,7 @@
// From CMY (0..1) to RGB (0..1):
// R = 1 - C => 1 - (1 - iC*iK) => iC*iK [G and B similar]
unsigned k = jsample[3];
- buffer.setRGBA(currentAddress, jsample[0] * k / 255, jsample[1] * k / 255, jsample[2] * k / 255, 0xFF);
+ buffer.setPixel(currentAddress, jsample[0] * k / 255, jsample[1] * k / 255, jsample[2] * k / 255, 0xFF);
break;
}
}
@@ -594,7 +594,7 @@
if (destY < 0)
continue;
- ImageFrame::PixelData* currentAddress = buffer.getAddr(0, destY);
+ RGBA32* currentAddress = buffer.pixelAt(0, destY);
for (int x = 0; x < width; ++x) {
setPixel<colorSpace>(buffer, currentAddress, samples, isScaled ? m_scaledColumns[x] : x);
++currentAddress;
@@ -617,15 +617,12 @@
// Initialize the framebuffer if needed.
ImageFrame& buffer = m_frameBufferCache[0];
if (buffer.status() == ImageFrame::FrameEmpty) {
- if (!buffer.setSize(scaledSize().width(), scaledSize().height()))
+ if (!buffer.setSize(scaledSize()))
return setFailed();
buffer.setStatus(ImageFrame::FramePartial);
// The buffer is transparent outside the decoded area while the image is
// loading. The completed image will be marked fully opaque in jpegComplete().
buffer.setHasAlpha(true);
-
- // For JPEGs, the frame always fills the entire image.
- buffer.setOriginalFrameRect(IntRect(IntPoint(), size()));
}
jpeg_decompress_struct* info = m_reader->info();
@@ -633,7 +630,7 @@
#if defined(TURBO_JPEG_RGB_SWIZZLE)
if (!m_scaled && turboSwizzled(info->out_color_space)) {
while (info->output_scanline < info->output_height) {
- unsigned char* row = reinterpret_cast<unsigned char*>(buffer.getAddr(0, info->output_scanline));
+ unsigned char* row = reinterpret_cast<unsigned char*>(buffer.pixelAt(0, info->output_scanline));
if (jpeg_read_scanlines(info, &row, 1) != 1)
return false;
}
Modified: trunk/Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h (205840 => 205841)
--- trunk/Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h 2016-09-12 23:51:57 UTC (rev 205841)
@@ -50,7 +50,7 @@
// ImageDecoder
String filenameExtension() const override { return "jpg"; }
bool isSizeAvailable() override;
- bool setSize(unsigned width, unsigned height) override;
+ bool setSize(const IntSize&) override;
ImageFrame* frameBufferAtIndex(size_t index) override;
// CAUTION: setFailed() deletes |m_reader|. Be careful to avoid
// accessing deleted memory, especially when calling this from inside
Modified: trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp (205840 => 205841)
--- trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp 2016-09-12 23:51:57 UTC (rev 205841)
@@ -235,9 +235,9 @@
return ImageDecoder::isSizeAvailable();
}
-bool PNGImageDecoder::setSize(unsigned width, unsigned height)
+bool PNGImageDecoder::setSize(const IntSize& size)
{
- if (!ImageDecoder::setSize(width, height))
+ if (!ImageDecoder::setSize(size))
return false;
prepareScaleDataIfNecessary();
@@ -295,7 +295,7 @@
// will cease to exist. Note that we'll still properly set the failure flag
// in this case as soon as we longjmp().
m_doNothingOnFailure = true;
- bool result = setSize(width, height);
+ bool result = setSize(IntSize(width, height));
m_doNothingOnFailure = false;
if (!result) {
longjmp(JMPBUF(png), 1);
@@ -411,12 +411,12 @@
}
}
-static inline void setPixelRGB(ImageFrame::PixelData* dest, png_bytep pixel)
+static inline void setPixelRGB(RGBA32* dest, png_bytep pixel)
{
*dest = 0xFF000000U | pixel[0] << 16 | pixel[1] << 8 | pixel[2];
}
-static inline void setPixelRGBA(ImageFrame::PixelData* dest, png_bytep pixel, unsigned char& nonTrivialAlphaMask)
+static inline void setPixelRGBA(RGBA32* dest, png_bytep pixel, unsigned char& nonTrivialAlphaMask)
{
unsigned char a = pixel[3];
*dest = a << 24 | pixel[0] << 16 | pixel[1] << 8 | pixel[2];
@@ -423,7 +423,7 @@
nonTrivialAlphaMask |= (255 - a);
}
-static inline void setPixelPremultipliedRGBA(ImageFrame::PixelData* dest, png_bytep pixel, unsigned char& nonTrivialAlphaMask)
+static inline void setPixelPremultipliedRGBA(RGBA32* dest, png_bytep pixel, unsigned char& nonTrivialAlphaMask)
{
unsigned char a = pixel[3];
unsigned char r = fastDivideBy255(pixel[0] * a);
@@ -447,7 +447,7 @@
ImageFrame& buffer = m_frameBufferCache[m_currentFrame];
if (buffer.status() == ImageFrame::FrameEmpty) {
png_structp png = m_reader->pngPtr();
- if (!buffer.setSize(scaledSize().width(), scaledSize().height())) {
+ if (!buffer.setSize(scaledSize())) {
longjmp(JMPBUF(png), 1);
return;
}
@@ -469,10 +469,7 @@
#if ENABLE(APNG)
if (m_currentFrame)
initFrameBuffer(m_currentFrame);
- else
#endif
- // For PNGs, the frame always fills the entire image.
- buffer.setOriginalFrameRect(IntRect(IntPoint(), size()));
}
/* libpng comments (here to explain what follows).
@@ -531,7 +528,7 @@
}
// Write the decoded row pixels to the frame buffer.
- ImageFrame::PixelData* address = buffer.getAddr(0, y);
+ RGBA32* address = buffer.pixelAt(0, y);
int width = scaledSize().width();
unsigned char nonTrivialAlphaMask = 0;
@@ -540,7 +537,7 @@
for (int x = 0; x < width; ++x) {
png_bytep pixel = row + m_scaledColumns[x] * colorChannels;
unsigned alpha = hasAlpha ? pixel[3] : 255;
- buffer.setRGBA(address++, pixel[0], pixel[1], pixel[2], alpha);
+ buffer.setPixel(address++, pixel[0], pixel[1], pixel[2], alpha);
nonTrivialAlphaMask |= (255 - alpha);
}
} else
@@ -820,7 +817,7 @@
} else {
// We want to clear the previous frame to transparent, without
// affecting pixels in the image outside of the frame.
- const IntRect& prevRect = prevBuffer->originalFrameRect();
+ IntRect prevRect = prevBuffer->originalFrameRect();
if (!frameIndex || prevRect.contains(IntRect(IntPoint(), scaledSize()))) {
// Clearing the first frame, or a frame the size of the whole
// image, results in a completely empty image.
@@ -844,7 +841,7 @@
png_bytep interlaceBuffer = m_reader->interlaceBuffer();
if (m_currentFrame && interlaceBuffer) {
- const IntRect& rect = buffer.originalFrameRect();
+ IntRect rect = buffer.originalFrameRect();
bool hasAlpha = m_reader->hasAlpha();
unsigned colorChannels = hasAlpha ? 4 : 3;
bool nonTrivialAlpha = false;
@@ -854,15 +851,15 @@
#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
for (int y = 0; y < rect.maxY() - rect.y(); ++y) {
png_bytep row = interlaceBuffer + (m_scaled ? m_scaledRows[y] : y) * colorChannels * size().width();
- ImageFrame::PixelData* address = buffer.getAddr(rect.x(), y + rect.y());
+ RGBA32* address = buffer.pixelAt(rect.x(), y + rect.y());
for (int x = 0; x < rect.maxX() - rect.x(); ++x) {
png_bytep pixel = row + (m_scaled ? m_scaledColumns[x] : x) * colorChannels;
unsigned alpha = hasAlpha ? pixel[3] : 255;
nonTrivialAlpha |= alpha < 255;
if (!m_blend)
- buffer.setRGBA(address++, pixel[0], pixel[1], pixel[2], alpha);
+ buffer.setPixel(address++, pixel[0], pixel[1], pixel[2], alpha);
else
- buffer.overRGBA(address++, pixel[0], pixel[1], pixel[2], alpha);
+ buffer.blendPixel(address++, pixel[0], pixel[1], pixel[2], alpha);
}
}
#else
@@ -870,14 +867,14 @@
png_bytep row = interlaceBuffer;
for (int y = rect.y(); y < rect.maxY(); ++y, row += colorChannels * size().width()) {
png_bytep pixel = row;
- ImageFrame::PixelData* address = buffer.getAddr(rect.x(), y);
+ RGBA32* address = buffer.pixelAt(rect.x(), y);
for (int x = rect.x(); x < rect.maxX(); ++x, pixel += colorChannels) {
unsigned alpha = hasAlpha ? pixel[3] : 255;
nonTrivialAlpha |= alpha < 255;
if (!m_blend)
- buffer.setRGBA(address++, pixel[0], pixel[1], pixel[2], alpha);
+ buffer.setPixel(address++, pixel[0], pixel[1], pixel[2], alpha);
else
- buffer.overRGBA(address++, pixel[0], pixel[1], pixel[2], alpha);
+ buffer.blendPixel(address++, pixel[0], pixel[1], pixel[2], alpha);
}
}
#endif
Modified: trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.h (205840 => 205841)
--- trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.h 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.h 2016-09-12 23:51:57 UTC (rev 205841)
@@ -48,7 +48,7 @@
int repetitionCount() const override { return m_playCount-1; }
#endif
bool isSizeAvailable() override;
- bool setSize(unsigned width, unsigned height) override;
+ bool setSize(const IntSize&) override;
ImageFrame* frameBufferAtIndex(size_t index) override;
// CAUTION: setFailed() deletes |m_reader|. Be careful to avoid
// accessing deleted memory, especially when calling this from inside
Modified: trunk/Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp (205840 => 205841)
--- trunk/Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp 2016-09-12 23:34:24 UTC (rev 205840)
+++ trunk/Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp 2016-09-12 23:51:57 UTC (rev 205841)
@@ -115,7 +115,7 @@
return setFailed();
m_hasAlpha = false;
#endif
- if (!setSize(width, height))
+ if (!setSize(IntSize(width, height)))
return setFailed();
}
@@ -128,11 +128,10 @@
ASSERT(buffer.status() != ImageFrame::FrameComplete);
if (buffer.status() == ImageFrame::FrameEmpty) {
- if (!buffer.setSize(size().width(), size().height()))
+ if (!buffer.setSize(size()))
return setFailed();
buffer.setStatus(ImageFrame::FramePartial);
buffer.setHasAlpha(m_hasAlpha);
- buffer.setOriginalFrameRect(IntRect(IntPoint(), size()));
}
if (!m_decoder) {
@@ -139,8 +138,8 @@
WEBP_CSP_MODE mode = outputMode(m_hasAlpha);
if (!m_premultiplyAlpha)
mode = outputMode(false);
- int rowStride = size().width() * sizeof(ImageFrame::PixelData);
- uint8_t* output = reinterpret_cast<uint8_t*>(buffer.getAddr(0, 0));
+ int rowStride = size().width() * sizeof(RGBA32);
+ uint8_t* output = reinterpret_cast<uint8_t*>(buffer.pixelAt(0, 0));
int outputSize = size().height() * rowStride;
m_decoder = WebPINewRGB(mode, output, outputSize, rowStride);
if (!m_decoder)