Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1177)

Unified Diff: Source/core/platform/graphics/ImageBuffer.cpp

Issue 23643003: ImageBuffer-less SVG masking and clipping. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Removed Linux rebaselines. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..d945b5cf168d8fe53ef983e8aaf78a7255968520 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,36 @@ 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, ());
pdr. 2013/08/28 03:32:36 Since you know the final size already, can you ini
f(malita) 2013/08/28 19:54:38 Good idea. Simply passing a constructor size argu
+ 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;
+}
+
+static const Vector<uint8_t>& 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;
+}
+
void ImageBuffer::transformColorSpace(ColorSpace srcColorSpace, ColorSpace dstColorSpace)
{
if (srcColorSpace == dstColorSpace)
@@ -301,36 +333,24 @@ void ImageBuffer::transformColorSpace(ColorSpace srcColorSpace, ColorSpace dstCo
}
}
-const Vector<uint8_t>& ImageBuffer::getLinearRgbLUT()
+PassRefPtr<SkColorFilter> ImageBuffer::createColorSpaceFilter(ColorSpace srcColorSpace,
Stephen White 2013/08/28 14:11:10 Maybe at some point we can use this in place of Im
f(malita) 2013/08/28 19:54:38 Makes sense. The only transformColorSpace() user l
+ 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 +443,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)
{

Powered by Google App Engine
This is Rietveld 408576698