|
Lines 1-5
WebCore/svg/graphics/SVGResourceMasker.cpp_sec1
|
| 1 |
/* |
1 |
/* |
| 2 |
* Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> |
2 |
* Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> |
|
|
3 |
* 2009 Dirk Schulze <krit@webkit.org> |
| 3 |
* |
4 |
* |
| 4 |
* Redistribution and use in source and binary forms, with or without |
5 |
* Redistribution and use in source and binary forms, with or without |
| 5 |
* modification, are permitted provided that the following conditions |
6 |
* modification, are permitted provided that the following conditions |
|
Lines 38-45
WebCore/svg/graphics/SVGResourceMasker.cpp_sec2
|
| 38 |
#include "SVGRenderStyle.h" |
39 |
#include "SVGRenderStyle.h" |
| 39 |
#include "TextStream.h" |
40 |
#include "TextStream.h" |
| 40 |
|
41 |
|
| 41 |
#include <wtf/ByteArray.h> |
|
|
| 42 |
|
| 43 |
using namespace std; |
42 |
using namespace std; |
| 44 |
|
43 |
|
| 45 |
namespace WebCore { |
44 |
namespace WebCore { |
|
Lines 63-101
void SVGResourceMasker::invalidate()
WebCore/svg/graphics/SVGResourceMasker.cpp_sec3
|
| 63 |
void SVGResourceMasker::applyMask(GraphicsContext* context, const FloatRect& boundingBox) |
62 |
void SVGResourceMasker::applyMask(GraphicsContext* context, const FloatRect& boundingBox) |
| 64 |
{ |
63 |
{ |
| 65 |
if (!m_mask) |
64 |
if (!m_mask) |
| 66 |
m_mask = m_ownerElement->drawMaskerContent(boundingBox, m_maskRect); |
65 |
m_mask = m_ownerElement->drawMaskerContent(boundingBox, m_maskRect, m_paintRect); |
| 67 |
|
66 |
|
| 68 |
if (!m_mask) |
67 |
if (!m_mask) |
| 69 |
return; |
68 |
return; |
| 70 |
|
69 |
|
| 71 |
IntSize imageSize(m_mask->size()); |
70 |
if (!m_paintRect.width() || !m_paintRect.height()) { |
| 72 |
IntRect intImageRect(0, 0, imageSize.width(), imageSize.height()); |
71 |
context->clipToImageBuffer(m_maskRect, m_mask.get()); |
| 73 |
|
|
|
| 74 |
// Create new ImageBuffer to apply luminance |
| 75 |
OwnPtr<ImageBuffer> luminancedImage = ImageBuffer::create(imageSize); |
| 76 |
if (!luminancedImage) |
| 77 |
return; |
72 |
return; |
|
|
73 |
} |
| 78 |
|
74 |
|
| 79 |
PassRefPtr<CanvasPixelArray> srcPixelArray(m_mask->getUnmultipliedImageData(intImageRect)->data()); |
75 |
RefPtr<ImageData> imageData(m_mask->getUnmultipliedImageData(m_paintRect)); |
| 80 |
PassRefPtr<ImageData> destImageData(luminancedImage->getUnmultipliedImageData(intImageRect)); |
76 |
CanvasPixelArray* srcPixelArray(imageData->data()); |
| 81 |
|
|
|
| 82 |
for (unsigned pixelOffset = 0; pixelOffset < srcPixelArray->length(); pixelOffset++) { |
| 83 |
unsigned pixelByteOffset = pixelOffset * 4; |
| 84 |
|
77 |
|
| 85 |
unsigned char r = 0, g = 0, b = 0, a = 0; |
78 |
for (unsigned pixelOffset = 0; pixelOffset < srcPixelArray->length(); pixelOffset += 4) { |
| 86 |
srcPixelArray->get(pixelByteOffset, r); |
79 |
unsigned char a = srcPixelArray->get(pixelOffset + 3); |
| 87 |
srcPixelArray->get(pixelByteOffset + 1, g); |
80 |
if (!a) |
| 88 |
srcPixelArray->get(pixelByteOffset + 2, b); |
81 |
continue; |
| 89 |
srcPixelArray->get(pixelByteOffset + 3, a); |
82 |
unsigned char r = srcPixelArray->get(pixelOffset); |
|
|
83 |
unsigned char g = srcPixelArray->get(pixelOffset + 1); |
| 84 |
unsigned char b = srcPixelArray->get(pixelOffset + 2); |
| 90 |
|
85 |
|
| 91 |
double luma = (r * 0.2125 + g * 0.7154 + b * 0.0721) * ((double)a / 255.0); |
86 |
double luma = (r * 0.2125 + g * 0.7154 + b * 0.0721) * ((double)a / 255.0); |
| 92 |
|
87 |
srcPixelArray->set(pixelOffset + 3, luma); |
| 93 |
destImageData->data()->set(pixelByteOffset + 3, luma); |
|
|
| 94 |
} |
88 |
} |
| 95 |
|
89 |
|
| 96 |
luminancedImage->putUnmultipliedImageData(destImageData.get(), intImageRect, IntPoint(0, 0)); |
90 |
m_mask->putUnmultipliedImageData(imageData.get(), IntRect(IntPoint(), m_paintRect.size()), m_paintRect.location()); |
| 97 |
|
91 |
context->clipToImageBuffer(m_maskRect, m_mask.get()); |
| 98 |
context->clipToImageBuffer(m_maskRect, luminancedImage.get()); |
|
|
| 99 |
} |
92 |
} |
| 100 |
|
93 |
|
| 101 |
TextStream& SVGResourceMasker::externalRepresentation(TextStream& ts) const |
94 |
TextStream& SVGResourceMasker::externalRepresentation(TextStream& ts) const |