| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> | 2 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> |
| 3 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 #include "core/platform/graphics/ImageBuffer.h" | 28 #include "core/platform/graphics/ImageBuffer.h" |
| 29 | 29 |
| 30 #include "core/platform/PlatformMemoryInstrumentation.h" | 30 #include "core/platform/PlatformMemoryInstrumentation.h" |
| 31 #include "core/platform/graphics/IntRect.h" | 31 #include "core/platform/graphics/IntRect.h" |
| 32 #include <wtf/MathExtras.h> | 32 #include <wtf/MathExtras.h> |
| 33 | 33 |
| 34 namespace WebCore { | 34 namespace WebCore { |
| 35 | 35 |
| 36 const Vector<uint8_t>& ImageBuffer::getLinearRgbLUT() |
| 37 { |
| 38 DEFINE_STATIC_LOCAL(Vector<uint8_t>, linearRgbLUT, ()); |
| 39 if (linearRgbLUT.isEmpty()) { |
| 40 for (unsigned i = 0; i < 256; i++) { |
| 41 float color = i / 255.0f; |
| 42 color = (color <= 0.04045f ? color / 12.92f : pow((color + 0.055f) /
1.055f, 2.4f)); |
| 43 color = std::max(0.0f, color); |
| 44 color = std::min(1.0f, color); |
| 45 linearRgbLUT.append(static_cast<uint8_t>(round(color * 255))); |
| 46 } |
| 47 } |
| 48 return linearRgbLUT; |
| 49 } |
| 50 |
| 51 const Vector<uint8_t>& ImageBuffer::getDeviceRgbLUT() |
| 52 { |
| 53 DEFINE_STATIC_LOCAL(Vector<uint8_t>, deviceRgbLUT, ()); |
| 54 if (deviceRgbLUT.isEmpty()) { |
| 55 for (unsigned i = 0; i < 256; i++) { |
| 56 float color = i / 255.0f; |
| 57 color = (powf(color, 1.0f / 2.4f) * 1.055f) - 0.055f; |
| 58 color = std::max(0.0f, color); |
| 59 color = std::min(1.0f, color); |
| 60 deviceRgbLUT.append(static_cast<uint8_t>(round(color * 255))); |
| 61 } |
| 62 } |
| 63 return deviceRgbLUT; |
| 64 } |
| 65 |
| 36 void ImageBuffer::transformColorSpace(ColorSpace srcColorSpace, ColorSpace dstCo
lorSpace) | 66 void ImageBuffer::transformColorSpace(ColorSpace srcColorSpace, ColorSpace dstCo
lorSpace) |
| 37 { | 67 { |
| 38 DEFINE_STATIC_LOCAL(Vector<int>, deviceRgbLUT, ()); | |
| 39 DEFINE_STATIC_LOCAL(Vector<int>, linearRgbLUT, ()); | |
| 40 | |
| 41 if (srcColorSpace == dstColorSpace) | 68 if (srcColorSpace == dstColorSpace) |
| 42 return; | 69 return; |
| 43 | 70 |
| 44 // only sRGB <-> linearRGB are supported at the moment | 71 // only sRGB <-> linearRGB are supported at the moment |
| 45 if ((srcColorSpace != ColorSpaceLinearRGB && srcColorSpace != ColorSpaceDevi
ceRGB) | 72 if ((srcColorSpace != ColorSpaceLinearRGB && srcColorSpace != ColorSpaceDevi
ceRGB) |
| 46 || (dstColorSpace != ColorSpaceLinearRGB && dstColorSpace != ColorSpaceD
eviceRGB)) | 73 || (dstColorSpace != ColorSpaceLinearRGB && dstColorSpace != ColorSpaceD
eviceRGB)) |
| 47 return; | 74 return; |
| 48 | 75 |
| 49 if (dstColorSpace == ColorSpaceLinearRGB) { | 76 if (dstColorSpace == ColorSpaceLinearRGB) { |
| 50 if (linearRgbLUT.isEmpty()) { | 77 platformTransformColorSpace(getLinearRgbLUT()); |
| 51 for (unsigned i = 0; i < 256; i++) { | |
| 52 float color = i / 255.0f; | |
| 53 color = (color <= 0.04045f ? color / 12.92f : pow((color + 0.055
f) / 1.055f, 2.4f)); | |
| 54 color = std::max(0.0f, color); | |
| 55 color = std::min(1.0f, color); | |
| 56 linearRgbLUT.append(static_cast<int>(round(color * 255))); | |
| 57 } | |
| 58 } | |
| 59 platformTransformColorSpace(linearRgbLUT); | |
| 60 } else if (dstColorSpace == ColorSpaceDeviceRGB) { | 78 } else if (dstColorSpace == ColorSpaceDeviceRGB) { |
| 61 if (deviceRgbLUT.isEmpty()) { | 79 platformTransformColorSpace(getDeviceRgbLUT()); |
| 62 for (unsigned i = 0; i < 256; i++) { | |
| 63 float color = i / 255.0f; | |
| 64 color = (powf(color, 1.0f / 2.4f) * 1.055f) - 0.055f; | |
| 65 color = std::max(0.0f, color); | |
| 66 color = std::min(1.0f, color); | |
| 67 deviceRgbLUT.append(static_cast<int>(round(color * 255))); | |
| 68 } | |
| 69 } | |
| 70 platformTransformColorSpace(deviceRgbLUT); | |
| 71 } | 80 } |
| 72 } | 81 } |
| 73 | 82 |
| 74 inline void ImageBuffer::genericConvertToLuminanceMask() | 83 inline void ImageBuffer::genericConvertToLuminanceMask() |
| 75 { | 84 { |
| 76 IntRect luminanceRect(IntPoint(), internalSize()); | 85 IntRect luminanceRect(IntPoint(), internalSize()); |
| 77 RefPtr<Uint8ClampedArray> srcPixelArray = getUnmultipliedImageData(luminance
Rect); | 86 RefPtr<Uint8ClampedArray> srcPixelArray = getUnmultipliedImageData(luminance
Rect); |
| 78 | 87 |
| 79 unsigned pixelArrayLength = srcPixelArray->length(); | 88 unsigned pixelArrayLength = srcPixelArray->length(); |
| 80 for (unsigned pixelOffset = 0; pixelOffset < pixelArrayLength; pixelOffset +
= 4) { | 89 for (unsigned pixelOffset = 0; pixelOffset < pixelArrayLength; pixelOffset +
= 4) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 98 } | 107 } |
| 99 | 108 |
| 100 void ImageBuffer::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const | 109 void ImageBuffer::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const |
| 101 { | 110 { |
| 102 MemoryClassInfo info(memoryObjectInfo, this, PlatformMemoryTypes::Image); | 111 MemoryClassInfo info(memoryObjectInfo, this, PlatformMemoryTypes::Image); |
| 103 info.addMember(m_data, "data"); | 112 info.addMember(m_data, "data"); |
| 104 info.addMember(m_context, "context"); | 113 info.addMember(m_context, "context"); |
| 105 } | 114 } |
| 106 | 115 |
| 107 } | 116 } |
| OLD | NEW |