diff options
Diffstat (limited to 'WebCore/platform/graphics/skia/ImageBufferSkia.cpp')
-rw-r--r-- | WebCore/platform/graphics/skia/ImageBufferSkia.cpp | 55 |
1 files changed, 17 insertions, 38 deletions
diff --git a/WebCore/platform/graphics/skia/ImageBufferSkia.cpp b/WebCore/platform/graphics/skia/ImageBufferSkia.cpp index c429bcf..7935ff1 100644 --- a/WebCore/platform/graphics/skia/ImageBufferSkia.cpp +++ b/WebCore/platform/graphics/skia/ImageBufferSkia.cpp @@ -118,16 +118,16 @@ void ImageBuffer::platformTransformColorSpace(const Vector<int>& lookUpTable) } } -template <Multiply multiplied> -PassRefPtr<ImageData> getImageData(const IntRect& rect, const SkBitmap& bitmap, - const IntSize& size) +PassRefPtr<ImageData> ImageBuffer::getImageData(const IntRect& rect) const { + ASSERT(context()); + RefPtr<ImageData> result = ImageData::create(rect.width(), rect.height()); unsigned char* data = result->data()->data()->data(); if (rect.x() < 0 || rect.y() < 0 || - (rect.x() + rect.width()) > size.width() || - (rect.y() + rect.height()) > size.height()) + (rect.x() + rect.width()) > m_size.width() || + (rect.y() + rect.height()) > m_size.height()) memset(data, 0, result->data()->length()); int originX = rect.x(); @@ -137,8 +137,8 @@ PassRefPtr<ImageData> getImageData(const IntRect& rect, const SkBitmap& bitmap, originX = 0; } int endX = rect.x() + rect.width(); - if (endX > size.width()) - endX = size.width(); + if (endX > m_size.width()) + endX = m_size.width(); int numColumns = endX - originX; int originY = rect.y(); @@ -148,10 +148,11 @@ PassRefPtr<ImageData> getImageData(const IntRect& rect, const SkBitmap& bitmap, originY = 0; } int endY = rect.y() + rect.height(); - if (endY > size.height()) - endY = size.height(); + if (endY > m_size.height()) + endY = m_size.height(); int numRows = endY - originY; + const SkBitmap& bitmap = *context()->platformContext()->bitmap(); ASSERT(bitmap.config() == SkBitmap::kARGB_8888_Config); SkAutoLockPixels bitmapLock(bitmap); @@ -161,7 +162,6 @@ PassRefPtr<ImageData> getImageData(const IntRect& rect, const SkBitmap& bitmap, for (int y = 0; y < numRows; ++y) { uint32_t* srcRow = bitmap.getAddr32(originX, originY + y); for (int x = 0; x < numColumns; ++x) { - // TODO: Support for premultiplied colors SkColor color = SkPMColorToColor(srcRow[x]); unsigned char* destPixel = &destRow[x * 4]; destPixel[0] = SkColorGetR(color); @@ -175,19 +175,8 @@ PassRefPtr<ImageData> getImageData(const IntRect& rect, const SkBitmap& bitmap, return result; } -PassRefPtr<ImageData> ImageBuffer::getUnmultipliedImageData(const IntRect& rect) const -{ - return getImageData<Unmultiplied>(rect, *context()->platformContext()->bitmap(), m_size); -} - -PassRefPtr<ImageData> ImageBuffer::getPremultipliedImageData(const IntRect& rect) const -{ - return getImageData<Premultiplied>(rect, *context()->platformContext()->bitmap(), m_size); -} - -template <Multiply multiplied> -void putImageData(ImageData*& source, const IntRect& sourceRect, const IntPoint& destPoint, - const SkBitmap& bitmap, const IntSize& size) +void ImageBuffer::putImageData(ImageData* source, const IntRect& sourceRect, + const IntPoint& destPoint) { ASSERT(sourceRect.width() > 0); ASSERT(sourceRect.height() > 0); @@ -195,26 +184,27 @@ void putImageData(ImageData*& source, const IntRect& sourceRect, const IntPoint& int originX = sourceRect.x(); int destX = destPoint.x() + sourceRect.x(); ASSERT(destX >= 0); - ASSERT(destX < size.width()); + ASSERT(destX < m_size.width()); ASSERT(originX >= 0); ASSERT(originX < sourceRect.right()); int endX = destPoint.x() + sourceRect.right(); - ASSERT(endX <= size.width()); + ASSERT(endX <= m_size.width()); int numColumns = endX - destX; int originY = sourceRect.y(); int destY = destPoint.y() + sourceRect.y(); ASSERT(destY >= 0); - ASSERT(destY < size.height()); + ASSERT(destY < m_size.height()); ASSERT(originY >= 0); ASSERT(originY < sourceRect.bottom()); int endY = destPoint.y() + sourceRect.bottom(); - ASSERT(endY <= size.height()); + ASSERT(endY <= m_size.height()); int numRows = endY - destY; + const SkBitmap& bitmap = *context()->platformContext()->bitmap(); ASSERT(bitmap.config() == SkBitmap::kARGB_8888_Config); SkAutoLockPixels bitmapLock(bitmap); @@ -225,7 +215,6 @@ void putImageData(ImageData*& source, const IntRect& sourceRect, const IntPoint& for (int y = 0; y < numRows; ++y) { uint32_t* destRow = bitmap.getAddr32(destX, destY + y); for (int x = 0; x < numColumns; ++x) { - // TODO: Support for premultiplied colors const unsigned char* srcPixel = &srcRow[x * 4]; destRow[x] = SkPreMultiplyARGB(srcPixel[3], srcPixel[0], srcPixel[1], srcPixel[2]); @@ -234,16 +223,6 @@ void putImageData(ImageData*& source, const IntRect& sourceRect, const IntPoint& } } -void ImageBuffer::putUnmultipliedImageData(ImageData* source, const IntRect& sourceRect, const IntPoint& destPoint) -{ - putImageData<Unmultiplied>(source, sourceRect, destPoint, *context()->platformContext()->bitmap(), m_size); -} - -void ImageBuffer::putPremultipliedImageData(ImageData* source, const IntRect& sourceRect, const IntPoint& destPoint) -{ - putImageData<Premultiplied>(source, sourceRect, destPoint, *context()->platformContext()->bitmap(), m_size); -} - String ImageBuffer::toDataURL(const String&) const { // Encode the image into a vector. |