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

Side by Side Diff: Source/platform/graphics/ImageBuffer.cpp

Issue 134733016: Add support for converting Colors to linear RGB; Fix relevant filters (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 11 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 unified diff | Download patch
OLDNEW
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
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 if (srcColorSpace == dstColorSpace)
258 return; 226 return;
259 227
260 // only sRGB <-> linearRGB are supported at the moment 228 // only sRGB <-> linearRGB are supported at the moment
261 if ((srcColorSpace != ColorSpaceLinearRGB && srcColorSpace != ColorSpaceDevi ceRGB) 229 if ((srcColorSpace != ColorSpaceLinearRGB && srcColorSpace != ColorSpaceDevi ceRGB)
262 || (dstColorSpace != ColorSpaceLinearRGB && dstColorSpace != ColorSpaceD eviceRGB)) 230 || (dstColorSpace != ColorSpaceLinearRGB && dstColorSpace != ColorSpaceD eviceRGB))
263 return; 231 return;
264 232
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) 414 if (!encodeImage(imageData, mimeType, quality, &encodedImage))
447 return "data:,"; 415 return "data:,";
448 416
449 Vector<char> base64Data; 417 Vector<char> base64Data;
450 base64Encode(encodedImage, base64Data); 418 base64Encode(encodedImage, base64Data);
451 419
452 return "data:" + mimeType + ";base64," + base64Data; 420 return "data:" + mimeType + ";base64," + base64Data;
453 } 421 }
454 422
455 } // namespace WebCore 423 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698