| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, Google Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> | 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> |
| 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
| 8 * met: | 8 * met: |
| 9 * | 9 * |
| 10 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect, bl
ink::WebBlendMode blendMode, const IntSize& repeatSpacing) | 213 const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect, bl
ink::WebBlendMode blendMode, const IntSize& repeatSpacing) |
| 214 { | 214 { |
| 215 if (!isValid()) | 215 if (!isValid()) |
| 216 return; | 216 return; |
| 217 | 217 |
| 218 const SkBitmap& bitmap = m_surface->bitmap(); | 218 const SkBitmap& bitmap = m_surface->bitmap(); |
| 219 RefPtr<Image> image = BitmapImage::create(NativeImageSkia::create(drawNeedsC
opy(m_context.get(), context) ? deepSkBitmapCopy(bitmap) : bitmap)); | 219 RefPtr<Image> image = BitmapImage::create(NativeImageSkia::create(drawNeedsC
opy(m_context.get(), context) ? deepSkBitmapCopy(bitmap) : bitmap)); |
| 220 image->drawPattern(context, srcRect, scale, phase, op, destRect, blendMode,
repeatSpacing); | 220 image->drawPattern(context, srcRect, scale, phase, op, destRect, blendMode,
repeatSpacing); |
| 221 } | 221 } |
| 222 | 222 |
| 223 static const Vector<uint8_t>& getLinearRgbLUT() | |
| 224 { | |
| 225 DEFINE_STATIC_LOCAL(Vector<uint8_t>, linearRgbLUT, ()); | |
| 226 if (linearRgbLUT.isEmpty()) { | |
| 227 linearRgbLUT.reserveCapacity(256); | |
| 228 for (unsigned i = 0; i < 256; i++) { | |
| 229 float color = i / 255.0f; | |
| 230 color = (color <= 0.04045f ? color / 12.92f : pow((color + 0.055f) /
1.055f, 2.4f)); | |
| 231 color = std::max(0.0f, color); | |
| 232 color = std::min(1.0f, color); | |
| 233 linearRgbLUT.append(static_cast<uint8_t>(round(color * 255))); | |
| 234 } | |
| 235 } | |
| 236 return linearRgbLUT; | |
| 237 } | |
| 238 | |
| 239 static const Vector<uint8_t>& getDeviceRgbLUT() | |
| 240 { | |
| 241 DEFINE_STATIC_LOCAL(Vector<uint8_t>, deviceRgbLUT, ()); | |
| 242 if (deviceRgbLUT.isEmpty()) { | |
| 243 deviceRgbLUT.reserveCapacity(256); | |
| 244 for (unsigned i = 0; i < 256; i++) { | |
| 245 float color = i / 255.0f; | |
| 246 color = (powf(color, 1.0f / 2.4f) * 1.055f) - 0.055f; | |
| 247 color = std::max(0.0f, color); | |
| 248 color = std::min(1.0f, color); | |
| 249 deviceRgbLUT.append(static_cast<uint8_t>(round(color * 255))); | |
| 250 } | |
| 251 } | |
| 252 return deviceRgbLUT; | |
| 253 } | |
| 254 | |
| 255 void ImageBuffer::transformColorSpace(ColorSpace srcColorSpace, ColorSpace dstCo
lorSpace) | 223 void ImageBuffer::transformColorSpace(ColorSpace srcColorSpace, ColorSpace dstCo
lorSpace) |
| 256 { | 224 { |
| 257 if (srcColorSpace == dstColorSpace) | 225 const uint8_t* lookUpTable = ColorSpaceUtilities::getConversionLUT(dstColorS
pace, srcColorSpace); |
| 258 return; | 226 if (!lookUpTable) |
| 259 | |
| 260 // only sRGB <-> linearRGB are supported at the moment | |
| 261 if ((srcColorSpace != ColorSpaceLinearRGB && srcColorSpace != ColorSpaceDevi
ceRGB) | |
| 262 || (dstColorSpace != ColorSpaceLinearRGB && dstColorSpace != ColorSpaceD
eviceRGB)) | |
| 263 return; | 227 return; |
| 264 | 228 |
| 265 // FIXME: Disable color space conversions on accelerated canvases (for now). | 229 // FIXME: Disable color space conversions on accelerated canvases (for now). |
| 266 if (context()->isAccelerated() || !isValid()) | 230 if (context()->isAccelerated() || !isValid()) |
| 267 return; | 231 return; |
| 268 | 232 |
| 269 const SkBitmap& bitmap = m_surface->bitmap(); | 233 const SkBitmap& bitmap = m_surface->bitmap(); |
| 270 if (bitmap.isNull()) | 234 if (bitmap.isNull()) |
| 271 return; | 235 return; |
| 272 | 236 |
| 273 const Vector<uint8_t>& lookUpTable = dstColorSpace == ColorSpaceLinearRGB ? | |
| 274 getLinearRgbLUT() : getDeviceRgbLUT(); | |
| 275 | |
| 276 ASSERT(bitmap.config() == SkBitmap::kARGB_8888_Config); | 237 ASSERT(bitmap.config() == SkBitmap::kARGB_8888_Config); |
| 277 IntSize size = m_surface->size(); | 238 IntSize size = m_surface->size(); |
| 278 SkAutoLockPixels bitmapLock(bitmap); | 239 SkAutoLockPixels bitmapLock(bitmap); |
| 279 for (int y = 0; y < size.height(); ++y) { | 240 for (int y = 0; y < size.height(); ++y) { |
| 280 uint32_t* srcRow = bitmap.getAddr32(0, y); | 241 uint32_t* srcRow = bitmap.getAddr32(0, y); |
| 281 for (int x = 0; x < size.width(); ++x) { | 242 for (int x = 0; x < size.width(); ++x) { |
| 282 SkColor color = SkPMColorToColor(srcRow[x]); | 243 SkColor color = SkPMColorToColor(srcRow[x]); |
| 283 srcRow[x] = SkPreMultiplyARGB( | 244 srcRow[x] = SkPreMultiplyARGB( |
| 284 SkColorGetA(color), | 245 SkColorGetA(color), |
| 285 lookUpTable[SkColorGetR(color)], | 246 lookUpTable[SkColorGetR(color)], |
| 286 lookUpTable[SkColorGetG(color)], | 247 lookUpTable[SkColorGetG(color)], |
| 287 lookUpTable[SkColorGetB(color)]); | 248 lookUpTable[SkColorGetB(color)]); |
| 288 } | 249 } |
| 289 } | 250 } |
| 290 } | 251 } |
| 291 | 252 |
| 292 PassRefPtr<SkColorFilter> ImageBuffer::createColorSpaceFilter(ColorSpace srcColo
rSpace, | 253 PassRefPtr<SkColorFilter> ImageBuffer::createColorSpaceFilter(ColorSpace srcColo
rSpace, |
| 293 ColorSpace dstColorSpace) | 254 ColorSpace dstColorSpace) |
| 294 { | 255 { |
| 295 if ((srcColorSpace == dstColorSpace) | 256 const uint8_t* lut = ColorSpaceUtilities::getConversionLUT(dstColorSpace, sr
cColorSpace); |
| 296 || (srcColorSpace != ColorSpaceLinearRGB && srcColorSpace != ColorSpaceD
eviceRGB) | 257 if (!lut) |
| 297 || (dstColorSpace != ColorSpaceLinearRGB && dstColorSpace != ColorSpaceD
eviceRGB)) | |
| 298 return 0; | |
| 299 | |
| 300 const uint8_t* lut = 0; | |
| 301 if (dstColorSpace == ColorSpaceLinearRGB) | |
| 302 lut = &getLinearRgbLUT()[0]; | |
| 303 else if (dstColorSpace == ColorSpaceDeviceRGB) | |
| 304 lut = &getDeviceRgbLUT()[0]; | |
| 305 else | |
| 306 return 0; | 258 return 0; |
| 307 | 259 |
| 308 return adoptRef(SkTableColorFilter::CreateARGB(0, lut, lut, lut)); | 260 return adoptRef(SkTableColorFilter::CreateARGB(0, lut, lut, lut)); |
| 309 } | 261 } |
| 310 | 262 |
| 311 template <Multiply multiplied> | 263 template <Multiply multiplied> |
| 312 PassRefPtr<Uint8ClampedArray> getImageData(const IntRect& rect, GraphicsContext*
context, const IntSize& size) | 264 PassRefPtr<Uint8ClampedArray> getImageData(const IntRect& rect, GraphicsContext*
context, const IntSize& size) |
| 313 { | 265 { |
| 314 float area = 4.0f * rect.width() * rect.height(); | 266 float area = 4.0f * rect.width() * rect.height(); |
| 315 if (area > static_cast<float>(std::numeric_limits<int>::max())) | 267 if (area > static_cast<float>(std::numeric_limits<int>::max())) |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) | 398 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) |
| 447 return "data:,"; | 399 return "data:,"; |
| 448 | 400 |
| 449 Vector<char> base64Data; | 401 Vector<char> base64Data; |
| 450 base64Encode(encodedImage, base64Data); | 402 base64Encode(encodedImage, base64Data); |
| 451 | 403 |
| 452 return "data:" + mimeType + ";base64," + base64Data; | 404 return "data:" + mimeType + ";base64," + base64Data; |
| 453 } | 405 } |
| 454 | 406 |
| 455 } // namespace WebCore | 407 } // namespace WebCore |
| OLD | NEW |