| Index: Source/core/platform/graphics/ImageBuffer.cpp
|
| diff --git a/Source/core/platform/graphics/ImageBuffer.cpp b/Source/core/platform/graphics/ImageBuffer.cpp
|
| index 5e87788df1bbdcc6f12c99e83879b7eab90bdc32..96280d0dcf65ae4654f3d582ace41bb1cc11373f 100644
|
| --- a/Source/core/platform/graphics/ImageBuffer.cpp
|
| +++ b/Source/core/platform/graphics/ImageBuffer.cpp
|
| @@ -50,8 +50,10 @@
|
| #include "public/platform/Platform.h"
|
| #include "skia/ext/platform_canvas.h"
|
| #include "third_party/skia/include/core/SkBitmapDevice.h"
|
| +#include "third_party/skia/include/core/SkColorFilter.h"
|
| #include "third_party/skia/include/core/SkColorPriv.h"
|
| #include "third_party/skia/include/core/SkSurface.h"
|
| +#include "third_party/skia/include/effects/SkTableColorFilter.h"
|
| #include "third_party/skia/include/gpu/GrContext.h"
|
| #include "third_party/skia/include/gpu/SkGpuDevice.h"
|
| #include "wtf/MathExtras.h"
|
| @@ -265,6 +267,38 @@ void ImageBuffer::drawPattern(GraphicsContext* context, const FloatRect& srcRect
|
| image->drawPattern(context, srcRect, scale, phase, op, destRect, blendMode);
|
| }
|
|
|
| +static const Vector<uint8_t>& getLinearRgbLUT()
|
| +{
|
| + DEFINE_STATIC_LOCAL(Vector<uint8_t>, linearRgbLUT, ());
|
| + if (linearRgbLUT.isEmpty()) {
|
| + linearRgbLUT.reserveCapacity(256);
|
| + for (unsigned i = 0; i < 256; i++) {
|
| + float color = i / 255.0f;
|
| + color = (color <= 0.04045f ? color / 12.92f : pow((color + 0.055f) / 1.055f, 2.4f));
|
| + color = std::max(0.0f, color);
|
| + color = std::min(1.0f, color);
|
| + linearRgbLUT.append(static_cast<uint8_t>(round(color * 255)));
|
| + }
|
| + }
|
| + return linearRgbLUT;
|
| +}
|
| +
|
| +static const Vector<uint8_t>& getDeviceRgbLUT()
|
| +{
|
| + DEFINE_STATIC_LOCAL(Vector<uint8_t>, deviceRgbLUT, ());
|
| + if (deviceRgbLUT.isEmpty()) {
|
| + deviceRgbLUT.reserveCapacity(256);
|
| + for (unsigned i = 0; i < 256; i++) {
|
| + float color = i / 255.0f;
|
| + color = (powf(color, 1.0f / 2.4f) * 1.055f) - 0.055f;
|
| + color = std::max(0.0f, color);
|
| + color = std::min(1.0f, color);
|
| + deviceRgbLUT.append(static_cast<uint8_t>(round(color * 255)));
|
| + }
|
| + }
|
| + return deviceRgbLUT;
|
| +}
|
| +
|
| void ImageBuffer::transformColorSpace(ColorSpace srcColorSpace, ColorSpace dstColorSpace)
|
| {
|
| if (srcColorSpace == dstColorSpace)
|
| @@ -301,36 +335,24 @@ void ImageBuffer::transformColorSpace(ColorSpace srcColorSpace, ColorSpace dstCo
|
| }
|
| }
|
|
|
| -const Vector<uint8_t>& ImageBuffer::getLinearRgbLUT()
|
| +PassRefPtr<SkColorFilter> ImageBuffer::createColorSpaceFilter(ColorSpace srcColorSpace,
|
| + ColorSpace dstColorSpace)
|
| {
|
| - DEFINE_STATIC_LOCAL(Vector<uint8_t>, linearRgbLUT, ());
|
| - if (linearRgbLUT.isEmpty()) {
|
| - for (unsigned i = 0; i < 256; i++) {
|
| - float color = i / 255.0f;
|
| - color = (color <= 0.04045f ? color / 12.92f : pow((color + 0.055f) / 1.055f, 2.4f));
|
| - color = std::max(0.0f, color);
|
| - color = std::min(1.0f, color);
|
| - linearRgbLUT.append(static_cast<uint8_t>(round(color * 255)));
|
| - }
|
| - }
|
| - return linearRgbLUT;
|
| -}
|
| + if ((srcColorSpace == dstColorSpace)
|
| + || (srcColorSpace != ColorSpaceLinearRGB && srcColorSpace != ColorSpaceDeviceRGB)
|
| + || (dstColorSpace != ColorSpaceLinearRGB && dstColorSpace != ColorSpaceDeviceRGB))
|
| + return 0;
|
|
|
| -const Vector<uint8_t>& ImageBuffer::getDeviceRgbLUT()
|
| -{
|
| - DEFINE_STATIC_LOCAL(Vector<uint8_t>, deviceRgbLUT, ());
|
| - if (deviceRgbLUT.isEmpty()) {
|
| - for (unsigned i = 0; i < 256; i++) {
|
| - float color = i / 255.0f;
|
| - color = (powf(color, 1.0f / 2.4f) * 1.055f) - 0.055f;
|
| - color = std::max(0.0f, color);
|
| - color = std::min(1.0f, color);
|
| - deviceRgbLUT.append(static_cast<uint8_t>(round(color * 255)));
|
| - }
|
| - }
|
| - return deviceRgbLUT;
|
| -}
|
| + const uint8_t* lut = 0;
|
| + if (dstColorSpace == ColorSpaceLinearRGB)
|
| + lut = &getLinearRgbLUT()[0];
|
| + else if (dstColorSpace == ColorSpaceDeviceRGB)
|
| + lut = &getDeviceRgbLUT()[0];
|
| + else
|
| + return 0;
|
|
|
| + return adoptRef(SkTableColorFilter::CreateARGB(0, lut, lut, lut));
|
| +}
|
|
|
| template <Multiply multiplied>
|
| PassRefPtr<Uint8ClampedArray> getImageData(const IntRect& rect, GraphicsContext* context, const IntSize& size)
|
| @@ -423,26 +445,6 @@ void ImageBuffer::putByteArray(Multiply multiplied, Uint8ClampedArray* source, c
|
| context()->writePixels(srcBitmap, destX, destY, config8888);
|
| }
|
|
|
| -void ImageBuffer::convertToLuminanceMask()
|
| -{
|
| - IntRect luminanceRect(IntPoint(), internalSize());
|
| - RefPtr<Uint8ClampedArray> srcPixelArray = getUnmultipliedImageData(luminanceRect);
|
| -
|
| - unsigned pixelArrayLength = srcPixelArray->length();
|
| - for (unsigned pixelOffset = 0; pixelOffset < pixelArrayLength; pixelOffset += 4) {
|
| - unsigned char a = srcPixelArray->item(pixelOffset + 3);
|
| - if (!a)
|
| - continue;
|
| - unsigned char r = srcPixelArray->item(pixelOffset);
|
| - unsigned char g = srcPixelArray->item(pixelOffset + 1);
|
| - unsigned char b = srcPixelArray->item(pixelOffset + 2);
|
| -
|
| - double luma = (r * 0.2125 + g * 0.7154 + b * 0.0721) * ((double)a / 255.0);
|
| - srcPixelArray->set(pixelOffset + 3, luma);
|
| - }
|
| - putByteArray(Unmultiplied, srcPixelArray.get(), luminanceRect.size(), luminanceRect, IntPoint());
|
| -}
|
| -
|
| template <typename T>
|
| static bool encodeImage(T& source, const String& mimeType, const double* quality, Vector<char>* output)
|
| {
|
|
|