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

Side by Side Diff: Source/platform/graphics/ColorSpace.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>
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
3 * 5 *
4 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 7 * modification, are permitted provided that the following conditions are
6 * met: 8 * met:
7 * 9 *
8 * * Redistributions of source code must retain the above copyright 10 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 12 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer 13 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 14 * in the documentation and/or other materials provided with the
13 * distribution. 15 * distribution.
14 * * Neither the name of Google Inc. nor the names of its 16 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from 17 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission. 18 * this software without specific prior written permission.
17 * 19 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 31 */
30 32
31 #include "config.h" 33 #include "config.h"
32 #include "core/inspector/ScriptCallStack.h" 34 #include "platform/graphics/ColorSpace.h"
33 35
36 #include "wtf/MathExtras.h"
34 37
35 namespace WebCore { 38 namespace WebCore {
36 39
37 PassRefPtr<ScriptCallStack> ScriptCallStack::create(Vector<ScriptCallFrame>& fra mes) 40 const Vector<uint8_t>& getLinearRgbLUT()
38 { 41 {
39 return adoptRef(new ScriptCallStack(frames)); 42 DEFINE_STATIC_LOCAL(Vector<uint8_t>, linearRgbLUT, ());
43 if (linearRgbLUT.isEmpty()) {
44 linearRgbLUT.reserveCapacity(256);
45 for (unsigned i = 0; i < 256; i++) {
46 float color = i / 255.0f;
47 color = (color <= 0.04045f ? color / 12.92f : pow((color + 0.055f) / 1.055f, 2.4f));
48 color = std::max(0.0f, color);
49 color = std::min(1.0f, color);
50 linearRgbLUT.append(static_cast<uint8_t>(round(color * 255)));
51 }
52 }
53 return linearRgbLUT;
40 } 54 }
41 55
42 ScriptCallStack::ScriptCallStack(Vector<ScriptCallFrame>& frames) 56 const Vector<uint8_t>& getDeviceRgbLUT()
43 { 57 {
44 m_frames.swap(frames); 58 DEFINE_STATIC_LOCAL(Vector<uint8_t>, deviceRgbLUT, ());
45 } 59 if (deviceRgbLUT.isEmpty()) {
46 60 deviceRgbLUT.reserveCapacity(256);
47 ScriptCallStack::~ScriptCallStack() 61 for (unsigned i = 0; i < 256; i++) {
48 { 62 float color = i / 255.0f;
49 } 63 color = (powf(color, 1.0f / 2.4f) * 1.055f) - 0.055f;
50 64 color = std::max(0.0f, color);
51 const ScriptCallFrame &ScriptCallStack::at(size_t index) const 65 color = std::min(1.0f, color);
52 { 66 deviceRgbLUT.append(static_cast<uint8_t>(round(color * 255)));
53 ASSERT(m_frames.size() > index); 67 }
54 return m_frames[index];
55 }
56
57 size_t ScriptCallStack::size() const
58 {
59 return m_frames.size();
60 }
61
62 bool ScriptCallStack::isEqual(ScriptCallStack* o) const
63 {
64 if (!o)
65 return false;
66
67 size_t frameCount = o->m_frames.size();
68 if (frameCount != m_frames.size())
69 return false;
70
71 for (size_t i = 0; i < frameCount; ++i) {
72 if (!m_frames[i].isEqual(o->m_frames[i]))
73 return false;
74 } 68 }
75 69 return deviceRgbLUT;
76 return true;
77 }
78
79 PassRefPtr<TypeBuilder::Array<TypeBuilder::Console::CallFrame> > ScriptCallStack ::buildInspectorArray() const
80 {
81 RefPtr<TypeBuilder::Array<TypeBuilder::Console::CallFrame> > frames = TypeBu ilder::Array<TypeBuilder::Console::CallFrame>::create();
82 for (size_t i = 0; i < m_frames.size(); i++)
83 frames->addItem(m_frames.at(i).buildInspectorObject());
84 return frames;
85 } 70 }
86 71
87 } // namespace WebCore 72 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698