Changeset 46956 in webkit
- Timestamp:
- Aug 8, 2009 12:11:35 PM (15 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 1 added
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r46955 r46956 1 2009-08-08 Dirk Schulze <krit@webkit.org> 2 3 Reviewed by Oliver Hunt. 4 5 This is an initial implementation for linearRGB and sRGB support for all 6 platforms. Some platforms like Cg support different color spaces 7 natively, others like Qt, Cairo and Skia do not. This patch uses the 8 native implementation of platforms if possible and offers a common version 9 if not. 10 11 Different color spaces are used in SVG Filters. Nearly every Filter test 12 case is a test for this patch and will be enabled, once Filters are enabled. 13 14 * GNUmakefile.am: 15 * WebCore.pro: 16 * html/canvas/CanvasRenderingContext2D.cpp: 17 (WebCore::CanvasRenderingContext2D::drawTextInternal): 18 * html/HTMLCanvasElement.cpp: 19 (WebCore::HTMLCanvasElement::createImageBuffer): 20 * platform/graphics/GeneratedImage.cpp: 21 (WebCore::GeneratedImage::drawPattern): 22 * platform/graphics/ImageBuffer.cpp: Added. 23 (WebCore::ImageBuffer::transformColorSpace): 24 * platform/graphics/ImageBuffer.h: 25 (WebCore::): 26 (WebCore::ImageBuffer::create): 27 * platform/graphics/cairo/ImageBufferCairo.cpp: 28 (WebCore::ImageBuffer::ImageBuffer): 29 (WebCore::ImageBuffer::platformTransformColorSpace): 30 * platform/graphics/cairo/ImageCairo.cpp: 31 (WebCore::Image::drawPattern): 32 * platform/graphics/cg/ImageBufferCG.cpp: 33 (WebCore::ImageBuffer::ImageBuffer): 34 * platform/graphics/chromium/TransparencyWin.cpp: 35 (WebCore::TransparencyWin::OwnedBuffers::OwnedBuffers): 36 * platform/graphics/filters/FilterEffect.cpp: 37 (WebCore::FilterEffect::getEffectContext): 38 * platform/graphics/qt/ImageBufferQt.cpp: 39 (WebCore::ImageBuffer::ImageBuffer): 40 (WebCore::ImageBuffer::platformTransformColorSpace): 41 * platform/graphics/qt/PathQt.cpp: 42 (WebCore::Path::strokeContains): 43 (WebCore::Path::strokeBoundingRect): 44 * platform/graphics/skia/ImageBufferSkia.cpp: 45 (WebCore::ImageBuffer::ImageBuffer): 46 (WebCore::ImageBuffer::platformTransformColorSpace): 47 * platform/graphics/skia/SkiaUtils.cpp: 48 (WebCore::scratchContext): 49 * platform/graphics/wx/ImageBufferWx.cpp: 50 (WebCore::ImageBuffer::ImageBuffer): 51 * platform/mac/ScrollbarThemeMac.mm: 52 (WebCore::ScrollbarThemeMac::paint): 53 * rendering/RenderBoxModelObject.cpp: 54 (WebCore::RenderBoxModelObject::paintFillLayerExtended): 55 * svg/SVGMaskElement.cpp: 56 (WebCore::SVGMaskElement::drawMaskerContent): 57 * svg/SVGPatternElement.cpp: 58 (WebCore::SVGPatternElement::buildPattern): 59 * svg/graphics/SVGImage.cpp: 60 (WebCore::SVGImage::nativeImageForCurrentFrame): 61 * svg/graphics/SVGPaintServerGradient.cpp: 62 (WebCore::createMaskAndSwapContextForTextGradient): 63 * svg/graphics/SVGPaintServerPattern.cpp: 64 (WebCore::SVGPaintServerPattern::setup): 65 * svg/graphics/SVGResourceFilter.cpp: 66 (WebCore::SVGResourceFilter::prepareFilter): 67 (WebCore::SVGResourceFilter::applyFilter): 68 * svg/graphics/SVGResourceMasker.cpp: 69 (WebCore::SVGResourceMasker::applyMask): 70 * svg/graphics/filters/SVGFETile.cpp: 71 (WebCore::FETile::apply): 72 1 73 2009-08-08 Xan Lopez <xlopez@igalia.com> 2 74 -
trunk/WebCore/GNUmakefile.am
r46951 r46956 1464 1464 WebCore/platform/graphics/Image.cpp \ 1465 1465 WebCore/platform/graphics/Image.h \ 1466 WebCore/platform/graphics/ImageBuffer.cpp \ 1466 1467 WebCore/platform/graphics/ImageBuffer.h \ 1467 1468 WebCore/platform/graphics/ImageObserver.h \ -
trunk/WebCore/WebCore.pro
r46940 r46956 1132 1132 platform/graphics/GraphicsTypes.cpp \ 1133 1133 platform/graphics/Image.cpp \ 1134 platform/graphics/ImageBuffer.cpp \ 1134 1135 platform/graphics/IntRect.cpp \ 1135 1136 platform/graphics/Path.cpp \ -
trunk/WebCore/html/HTMLCanvasElement.cpp
r46815 r46956 261 261 return; 262 262 263 m_imageBuffer = ImageBuffer::create(size , false);263 m_imageBuffer = ImageBuffer::create(size); 264 264 // The convertLogicalToDevice MaxCanvasArea check should prevent common cases 265 265 // where ImageBuffer::create() returns NULL, however we could still be low on memory. -
trunk/WebCore/html/canvas/CanvasRenderingContext2D.cpp
r46937 r46956 1527 1527 IntRect maskRect = enclosingIntRect(textRect); 1528 1528 1529 OwnPtr<ImageBuffer> maskImage = ImageBuffer::create(maskRect.size() , false);1529 OwnPtr<ImageBuffer> maskImage = ImageBuffer::create(maskRect.size()); 1530 1530 1531 1531 GraphicsContext* maskImageContext = maskImage->context(); -
trunk/WebCore/platform/graphics/GeneratedImage.cpp
r44096 r46956 52 52 { 53 53 // Create a BitmapImage and call drawPattern on it. 54 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(m_size , false);54 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(m_size); 55 55 ASSERT(imageBuffer.get()); 56 56 -
trunk/WebCore/platform/graphics/ImageBuffer.h
r45891 r46956 44 44 class String; 45 45 46 enum ImageColorSpace { 47 Unknown, 48 DeviceRGB, // like sRGB 49 GrayScale, 50 LinearRGB 51 }; 52 46 53 class ImageBuffer : public Noncopyable { 47 54 public: 48 55 // Will return a null pointer on allocation failure. 49 static PassOwnPtr<ImageBuffer> create(const IntSize& size, bool grayScale)56 static PassOwnPtr<ImageBuffer> create(const IntSize& size, ImageColorSpace colorSpace = DeviceRGB) 50 57 { 51 58 bool success = false; 52 OwnPtr<ImageBuffer> buf(new ImageBuffer(size, grayScale, success));59 OwnPtr<ImageBuffer> buf(new ImageBuffer(size, colorSpace, success)); 53 60 if (success) 54 61 return buf.release(); … … 71 78 #if !PLATFORM(CG) 72 79 TransformationMatrix baseTransform() const { return TransformationMatrix(); } 80 void transformColorSpace(ImageColorSpace srcColorSpace, ImageColorSpace dstColorSpace); 81 void platformTransformColorSpace(const Vector<int>&); 73 82 #else 74 83 TransformationMatrix baseTransform() const { return TransformationMatrix(1, 0, 0, -1, 0, m_size.height()); } … … 81 90 mutable RefPtr<Image> m_image; 82 91 92 #if !PLATFORM(CG) 93 Vector<int> m_linearRgbLUT; 94 Vector<int> m_deviceRgbLUT; 95 #endif 96 83 97 // This constructor will place its success into the given out-variable 84 98 // so that create() knows when it should return failure. 85 ImageBuffer(const IntSize&, bool grayScale, bool& success);99 ImageBuffer(const IntSize&, ImageColorSpace colorSpace, bool& success); 86 100 }; 87 101 -
trunk/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
r46258 r46956 40 40 #include <cairo.h> 41 41 #include <wtf/Vector.h> 42 #include <math.h> 42 43 43 44 using namespace std; … … 69 70 } 70 71 71 ImageBuffer::ImageBuffer(const IntSize& size, bool grayScale, bool& success)72 ImageBuffer::ImageBuffer(const IntSize& size, ImageColorSpace imageColorSpace, bool& success) 72 73 : m_data(size) 73 74 , m_size(size) … … 116 117 } 117 118 return m_image.get(); 119 } 120 121 void ImageBuffer::platformTransformColorSpace(const Vector<int>& lookUpTable) 122 { 123 ASSERT(cairo_surface_get_type(m_data.m_surface) == CAIRO_SURFACE_TYPE_IMAGE); 124 125 unsigned char* dataSrc = cairo_image_surface_get_data(m_data.m_surface); 126 int stride = cairo_image_surface_get_stride(m_data.m_surface); 127 for (int y = 0; y < m_size.height(); ++y) { 128 unsigned* row = reinterpret_cast<unsigned*>(dataSrc + stride * y); 129 for (int x = 0; x < m_size.width(); x++) { 130 unsigned* pixel = row + x; 131 Color pixelColor = colorFromPremultipliedARGB(*pixel); 132 pixelColor = Color(lookUpTable[pixelColor.red()], 133 lookUpTable[pixelColor.green()], 134 lookUpTable[pixelColor.blue()], 135 lookUpTable[pixelColor.alpha()]); 136 *pixel = premultipliedARGBFromColor(pixelColor); 137 } 138 } 118 139 } 119 140 -
trunk/WebCore/platform/graphics/cairo/ImageCairo.cpp
r44771 r46956 166 166 167 167 IntRect imageSize = enclosingIntRect(tileRect); 168 OwnPtr<ImageBuffer> imageSurface = ImageBuffer::create(imageSize.size() , false);168 OwnPtr<ImageBuffer> imageSurface = ImageBuffer::create(imageSize.size()); 169 169 170 170 if (!imageSurface) -
trunk/WebCore/platform/graphics/cg/ImageBufferCG.cpp
r46180 r46956 39 39 #include <wtf/OwnArrayPtr.h> 40 40 #include <wtf/RetainPtr.h> 41 #include <math.h> 41 42 42 43 using namespace std; … … 49 50 } 50 51 51 ImageBuffer::ImageBuffer(const IntSize& size, bool grayScale, bool& success)52 ImageBuffer::ImageBuffer(const IntSize& size, ImageColorSpace imageColorSpace, bool& success) 52 53 : m_data(size) 53 54 , m_size(size) … … 58 59 return; 59 60 bytesPerRow = size.width(); 60 if ( !grayScale) {61 if (imageColorSpace != GrayScale) { 61 62 // Protect against overflow 62 63 if (bytesPerRow > 0x3FFFFFFF) … … 68 69 ASSERT((reinterpret_cast<size_t>(m_data.m_data) & 2) == 0); 69 70 70 CGColorSpaceRef colorSpace = grayScale ? CGColorSpaceCreateDeviceGray() : CGColorSpaceCreateDeviceRGB(); 71 CGColorSpaceRef colorSpace; 72 switch(imageColorSpace) { 73 case DeviceRGB: 74 colorSpace = CGColorSpaceCreateDeviceRGB(); 75 break; 76 case GrayScale: 77 colorSpace = CGColorSpaceCreateDeviceGray(); 78 break; 79 case LinearRGB: 80 colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGBLinear); 81 break; 82 default: 83 colorSpace = CGColorSpaceCreateDeviceRGB(); 84 break; 85 } 86 71 87 CGContextRef cgContext = CGBitmapContextCreate(m_data.m_data, size.width(), size.height(), 8, bytesPerRow, 72 colorSpace, grayScale? kCGImageAlphaNone : kCGImageAlphaPremultipliedLast);88 colorSpace, (imageColorSpace == GrayScale) ? kCGImageAlphaNone : kCGImageAlphaPremultipliedLast); 73 89 CGColorSpaceRelease(colorSpace); 74 90 if (!cgContext) -
trunk/WebCore/platform/graphics/chromium/TransparencyWin.cpp
r45922 r46956 110 110 OwnedBuffers(const IntSize& size, bool needReferenceBuffer) 111 111 { 112 m_destBitmap = ImageBuffer::create(size , false);112 m_destBitmap = ImageBuffer::create(size); 113 113 114 114 if (needReferenceBuffer) { -
trunk/WebCore/platform/graphics/filters/FilterEffect.cpp
r44810 r46956 70 70 { 71 71 IntRect bufferRect = enclosingIntRect(subRegion()); 72 m_effectBuffer = ImageBuffer::create(bufferRect.size(), false);72 m_effectBuffer = ImageBuffer::create(bufferRect.size(), LinearRGB); 73 73 return m_effectBuffer->context(); 74 74 } -
trunk/WebCore/platform/graphics/qt/ImageBufferQt.cpp
r42996 r46956 41 41 #include <QPainter> 42 42 #include <QPixmap> 43 #include <math.h> 43 44 44 45 namespace WebCore { … … 68 69 } 69 70 70 ImageBuffer::ImageBuffer(const IntSize& size, bool grayScale, bool& success)71 ImageBuffer::ImageBuffer(const IntSize& size, ImageColorSpace imageColorSpace, bool& success) 71 72 : m_data(size) 72 73 , m_size(size) … … 97 98 98 99 return m_image.get(); 100 } 101 102 void ImageBuffer::platformTransformColorSpace(const Vector<int>& lookUpTable) 103 { 104 bool isPainting = m_data.m_painter->isActive(); 105 if (isPainting) 106 m_data.m_painter->end(); 107 108 QImage image = m_data.m_pixmap.toImage().convertToFormat(QImage::Format_ARGB32); 109 ASSERT(!image.isNull()); 110 111 for (int y = 0; y < m_size.height(); ++y) { 112 for (int x = 0; x < m_size.width(); x++) { 113 QRgb value = image.pixel(x, y); 114 value = qRgba(lookUpTable[qRed(value)], 115 lookUpTable[qGreen(value)], 116 lookUpTable[qBlue(value)], 117 lookUpTable[qAlpha(value)]); 118 image.setPixel(x, y, value); 119 } 120 } 121 122 m_data.m_pixmap = QPixmap::fromImage(image); 123 124 if (isPainting) 125 m_data.m_painter->begin(&m_data.m_pixmap); 99 126 } 100 127 -
trunk/WebCore/platform/graphics/qt/PathQt.cpp
r46170 r46956 93 93 // FIXME: We should try to use a 'shared Context' instead of creating a new ImageBuffer 94 94 // on each call. 95 OwnPtr<ImageBuffer> scratchImage = ImageBuffer::create(IntSize(1, 1) , false);95 OwnPtr<ImageBuffer> scratchImage = ImageBuffer::create(IntSize(1, 1)); 96 96 GraphicsContext* gc = scratchImage->context(); 97 97 QPainterPathStroker stroke; … … 125 125 // FIXME: We should try to use a 'shared Context' instead of creating a new ImageBuffer 126 126 // on each call. 127 OwnPtr<ImageBuffer> scratchImage = ImageBuffer::create(IntSize(1, 1) , false);127 OwnPtr<ImageBuffer> scratchImage = ImageBuffer::create(IntSize(1, 1)); 128 128 GraphicsContext* gc = scratchImage->context(); 129 129 QPainterPathStroker stroke; -
trunk/WebCore/platform/graphics/skia/ImageBufferSkia.cpp
r45103 r46956 1 1 /* 2 2 * Copyright (c) 2008, Google Inc. All rights reserved. 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 54 55 } 55 56 56 ImageBuffer::ImageBuffer(const IntSize& size, bool grayScale, bool& success)57 ImageBuffer::ImageBuffer(const IntSize& size, ImageColorSpace imageColorSpace, bool& success) 57 58 : m_data(size) 58 59 , m_size(size) … … 99 100 } 100 101 return m_image.get(); 102 } 103 104 void ImageBuffer::platformTransformColorSpace(const Vector<int>& lookUpTable) 105 { 106 const SkBitmap& bitmap = *context()->platformContext()->bitmap(); 107 ASSERT(bitmap.config() == SkBitmap::kARGB_8888_Config); 108 SkAutoLockPixels bitmapLock(bitmap); 109 for (int y = 0; y < m_size.height(); ++y) { 110 uint32_t* srcRow = bitmap.getAddr32(0, y); 111 for (int x = 0; x < m_size.width(); ++x) { 112 SkColor color = SkPMColorToColor(srcRow[x]); 113 srcRow[x] = SkPreMultiplyARGB(lookUpTable[SkColorGetA(color)], 114 lookUpTable[SkColorGetR(color)], 115 lookUpTable[SkColorGetG(color)], 116 lookUpTable[SkColorGetB(color)]); 117 } 118 } 101 119 } 102 120 -
trunk/WebCore/platform/graphics/skia/SkiaUtils.cpp
r45103 r46956 190 190 static ImageBuffer* scratch = 0; 191 191 if (!scratch) 192 scratch = ImageBuffer::create(IntSize(1, 1) , false).release();192 scratch = ImageBuffer::create(IntSize(1, 1)).release(); 193 193 // We don't bother checking for failure creating the ImageBuffer, since our 194 194 // ImageBuffer initializer won't fail. -
trunk/WebCore/platform/graphics/wx/ImageBufferWx.cpp
r37976 r46956 37 37 } 38 38 39 ImageBuffer::ImageBuffer(const IntSize&, bool grayScale, bool& success) :39 ImageBuffer::ImageBuffer(const IntSize&, ImageColorSpace imageColorSpace, bool& success) : 40 40 m_data(IntSize()) 41 41 { -
trunk/WebCore/platform/mac/ScrollbarThemeMac.mm
r44416 r46956 392 392 bufferRect.move(-scrollbar->frameRect().x(), -scrollbar->frameRect().y()); 393 393 394 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(bufferRect.size() , false);394 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(bufferRect.size()); 395 395 if (!imageBuffer) 396 396 return true; -
trunk/WebCore/rendering/RenderBoxModelObject.cpp
r46295 r46956 359 359 360 360 // Now create the mask. 361 OwnPtr<ImageBuffer> maskImage = ImageBuffer::create(maskRect.size() , false);361 OwnPtr<ImageBuffer> maskImage = ImageBuffer::create(maskRect.size()); 362 362 if (!maskImage) 363 363 return; -
trunk/WebCore/svg/SVGMaskElement.cpp
r44096 r46956 155 155 heightValue = imageSize.height(); 156 156 157 OwnPtr<ImageBuffer> maskImage = ImageBuffer::create(imageSize , false);157 OwnPtr<ImageBuffer> maskImage = ImageBuffer::create(imageSize); 158 158 if (!maskImage) 159 159 return 0; -
trunk/WebCore/svg/SVGPatternElement.cpp
r44096 r46956 215 215 clampImageBufferSizeToViewport(document()->view(), imageSize); 216 216 217 OwnPtr<ImageBuffer> patternImage = ImageBuffer::create(imageSize , false);217 OwnPtr<ImageBuffer> patternImage = ImageBuffer::create(imageSize); 218 218 219 219 if (!patternImage) -
trunk/WebCore/svg/graphics/SVGImage.cpp
r45780 r46956 212 212 if (!m_page) 213 213 return 0; 214 m_frameCache = ImageBuffer::create(size() , false);214 m_frameCache = ImageBuffer::create(size()); 215 215 if (!m_frameCache) // failed to allocate image 216 216 return 0; -
trunk/WebCore/svg/graphics/SVGPaintServerGradient.cpp
r44096 r46956 138 138 clampImageBufferSizeToViewport(object->view()->frameView(), maskSize); 139 139 140 OwnPtr<ImageBuffer> maskImage = ImageBuffer::create(maskSize , false);140 OwnPtr<ImageBuffer> maskImage = ImageBuffer::create(maskSize); 141 141 142 142 if (!maskImage) -
trunk/WebCore/svg/graphics/SVGPaintServerPattern.cpp
r44096 r46956 119 119 int tileWidth = static_cast<int>(patternBoundaries().width() + 0.5f); 120 120 int tileHeight = static_cast<int>(patternBoundaries().height() + 0.5f); 121 OwnPtr<ImageBuffer> tileImage = ImageBuffer::create(IntSize(tileWidth, tileHeight) , false);121 OwnPtr<ImageBuffer> tileImage = ImageBuffer::create(IntSize(tileWidth, tileHeight)); 122 122 123 123 GraphicsContext* tileImageContext = tileImage->context(); -
trunk/WebCore/svg/graphics/SVGResourceFilter.cpp
r44655 r46956 86 86 // The size of the SourceGraphic is clipped to the size of the filterRegion. 87 87 IntRect bufferRect = enclosingIntRect(clippedSourceRect); 88 OwnPtr<ImageBuffer> sourceGraphic(ImageBuffer::create(bufferRect.size(), false));88 OwnPtr<ImageBuffer> sourceGraphic(ImageBuffer::create(bufferRect.size(), LinearRGB)); 89 89 90 90 if (!sourceGraphic.get()) … … 107 107 context = m_savedContext; 108 108 m_savedContext = 0; 109 #if !PLATFORM(CG) 110 m_sourceGraphicBuffer->transformColorSpace(DeviceRGB, LinearRGB); 111 #endif 109 112 110 113 FilterEffect* lastEffect = m_filterBuilder->lastEffect(); … … 114 117 lastEffect->apply(m_filter.get()); 115 118 116 if (lastEffect->resultImage()) 117 context->drawImage(lastEffect->resultImage()->image(), lastEffect->subRegion()); 119 ImageBuffer* resultImage = lastEffect->resultImage(); 120 if (resultImage) { 121 #if !PLATFORM(CG) 122 resultImage->transformColorSpace(LinearRGB, DeviceRGB); 123 #endif 124 context->drawImage(resultImage->image(), lastEffect->subRegion()); 125 } 118 126 } 119 127 -
trunk/WebCore/svg/graphics/SVGResourceMasker.cpp
r44096 r46956 73 73 74 74 // Create new ImageBuffer to apply luminance 75 OwnPtr<ImageBuffer> luminancedImage = ImageBuffer::create(imageSize , false);75 OwnPtr<ImageBuffer> luminancedImage = ImageBuffer::create(imageSize); 76 76 if (!luminancedImage) 77 77 return; -
trunk/WebCore/svg/graphics/filters/SVGFETile.cpp
r44840 r46956 66 66 tileRect = enclosingIntRect(filter->filterRegion()); 67 67 68 OwnPtr<ImageBuffer> tileImage = ImageBuffer::create(tileRect.size() , false);68 OwnPtr<ImageBuffer> tileImage = ImageBuffer::create(tileRect.size()); 69 69 GraphicsContext* tileImageContext = tileImage->context(); 70 70 tileImageContext->drawImage(m_in->resultImage()->image(), IntPoint());
Note: See TracChangeset
for help on using the changeset viewer.