| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> |
| 4 * Copyright (C) 2005 Eric Seidel <eric@webkit.org> | 4 * Copyright (C) 2005 Eric Seidel <eric@webkit.org> |
| 5 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> | 5 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> |
| 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 7 * Copyright (C) 2013 Google Inc. All rights reserved. | 7 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 8 * | 8 * |
| 9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * Boston, MA 02110-1301, USA. | 22 * Boston, MA 02110-1301, USA. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #include "config.h" | 25 #include "config.h" |
| 26 #include "platform/graphics/filters/FEComponentTransfer.h" | 26 #include "platform/graphics/filters/FEComponentTransfer.h" |
| 27 | 27 |
| 28 #include "SkColorFilterImageFilter.h" | 28 #include "SkColorFilterImageFilter.h" |
| 29 #include "SkTableColorFilter.h" | 29 #include "SkTableColorFilter.h" |
| 30 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" | 30 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" |
| 31 #include "platform/text/TextStream.h" | 31 #include "platform/text/TextStream.h" |
| 32 #include "wtf/MathExtras.h" |
| 33 #include <algorithm> |
| 32 | 34 |
| 33 namespace blink { | 35 namespace blink { |
| 34 | 36 |
| 35 typedef void (*TransferType)(unsigned char*, const ComponentTransferFunction&); | 37 typedef void (*TransferType)(unsigned char*, const ComponentTransferFunction&); |
| 36 | 38 |
| 37 FEComponentTransfer::FEComponentTransfer(Filter* filter, const ComponentTransfer
Function& redFunc, const ComponentTransferFunction& greenFunc, | 39 FEComponentTransfer::FEComponentTransfer(Filter* filter, const ComponentTransfer
Function& redFunc, const ComponentTransferFunction& greenFunc, |
| 38 const ComponentTransferFunction& blueFunc, const ComponentTransferFunction&
alphaFunc) | 40 const ComponentTransferFunction& blueFunc, const ComponentTransferFunction&
alphaFunc) |
| 39 : FilterEffect(filter) | 41 : FilterEffect(filter) |
| 40 , m_redFunc(redFunc) | 42 , m_redFunc(redFunc) |
| 41 , m_greenFunc(greenFunc) | 43 , m_greenFunc(greenFunc) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 59 const Vector<float>& tableValues = transferFunction.tableValues; | 61 const Vector<float>& tableValues = transferFunction.tableValues; |
| 60 unsigned n = tableValues.size(); | 62 unsigned n = tableValues.size(); |
| 61 if (n < 1) | 63 if (n < 1) |
| 62 return; | 64 return; |
| 63 for (unsigned i = 0; i < 256; ++i) { | 65 for (unsigned i = 0; i < 256; ++i) { |
| 64 double c = i / 255.0; | 66 double c = i / 255.0; |
| 65 unsigned k = static_cast<unsigned>(c * (n - 1)); | 67 unsigned k = static_cast<unsigned>(c * (n - 1)); |
| 66 double v1 = tableValues[k]; | 68 double v1 = tableValues[k]; |
| 67 double v2 = tableValues[std::min((k + 1), (n - 1))]; | 69 double v2 = tableValues[std::min((k + 1), (n - 1))]; |
| 68 double val = 255.0 * (v1 + (c * (n - 1) - k) * (v2 - v1)); | 70 double val = 255.0 * (v1 + (c * (n - 1) - k) * (v2 - v1)); |
| 69 val = std::max(0.0, std::min(255.0, val)); | 71 val = clampTo(val, 0.0, 255.0); |
| 70 values[i] = static_cast<unsigned char>(val); | 72 values[i] = static_cast<unsigned char>(val); |
| 71 } | 73 } |
| 72 } | 74 } |
| 73 | 75 |
| 74 static void discrete(unsigned char* values, const ComponentTransferFunction& tra
nsferFunction) | 76 static void discrete(unsigned char* values, const ComponentTransferFunction& tra
nsferFunction) |
| 75 { | 77 { |
| 76 const Vector<float>& tableValues = transferFunction.tableValues; | 78 const Vector<float>& tableValues = transferFunction.tableValues; |
| 77 unsigned n = tableValues.size(); | 79 unsigned n = tableValues.size(); |
| 78 if (n < 1) | 80 if (n < 1) |
| 79 return; | 81 return; |
| 80 for (unsigned i = 0; i < 256; ++i) { | 82 for (unsigned i = 0; i < 256; ++i) { |
| 81 unsigned k = static_cast<unsigned>((i * n) / 255.0); | 83 unsigned k = static_cast<unsigned>((i * n) / 255.0); |
| 82 k = std::min(k, n - 1); | 84 k = std::min(k, n - 1); |
| 83 double val = 255 * tableValues[k]; | 85 double val = 255 * tableValues[k]; |
| 84 val = std::max(0.0, std::min(255.0, val)); | 86 val = clampTo(val, 0.0, 255.0); |
| 85 values[i] = static_cast<unsigned char>(val); | 87 values[i] = static_cast<unsigned char>(val); |
| 86 } | 88 } |
| 87 } | 89 } |
| 88 | 90 |
| 89 static void linear(unsigned char* values, const ComponentTransferFunction& trans
ferFunction) | 91 static void linear(unsigned char* values, const ComponentTransferFunction& trans
ferFunction) |
| 90 { | 92 { |
| 91 for (unsigned i = 0; i < 256; ++i) { | 93 for (unsigned i = 0; i < 256; ++i) { |
| 92 double val = transferFunction.slope * i + 255 * transferFunction.interce
pt; | 94 double val = transferFunction.slope * i + 255 * transferFunction.interce
pt; |
| 93 val = std::max(0.0, std::min(255.0, val)); | 95 val = clampTo(val, 0.0, 255.0); |
| 94 values[i] = static_cast<unsigned char>(val); | 96 values[i] = static_cast<unsigned char>(val); |
| 95 } | 97 } |
| 96 } | 98 } |
| 97 | 99 |
| 98 static void gamma(unsigned char* values, const ComponentTransferFunction& transf
erFunction) | 100 static void gamma(unsigned char* values, const ComponentTransferFunction& transf
erFunction) |
| 99 { | 101 { |
| 100 for (unsigned i = 0; i < 256; ++i) { | 102 for (unsigned i = 0; i < 256; ++i) { |
| 101 double exponent = transferFunction.exponent; // RCVT doesn't like passin
g a double and a float to pow, so promote this to double | 103 double exponent = transferFunction.exponent; // RCVT doesn't like passin
g a double and a float to pow, so promote this to double |
| 102 double val = 255.0 * (transferFunction.amplitude * pow((i / 255.0), expo
nent) + transferFunction.offset); | 104 double val = 255.0 * (transferFunction.amplitude * pow((i / 255.0), expo
nent) + transferFunction.offset); |
| 103 val = std::max(0.0, std::min(255.0, val)); | 105 val = clampTo(val, 0.0, 255.0); |
| 104 values[i] = static_cast<unsigned char>(val); | 106 values[i] = static_cast<unsigned char>(val); |
| 105 } | 107 } |
| 106 } | 108 } |
| 107 | 109 |
| 108 bool FEComponentTransfer::affectsTransparentPixels() | 110 bool FEComponentTransfer::affectsTransparentPixels() |
| 109 { | 111 { |
| 110 double intercept = 0; | 112 double intercept = 0; |
| 111 switch (m_alphaFunc.type) { | 113 switch (m_alphaFunc.type) { |
| 112 case FECOMPONENTTRANSFER_TYPE_UNKNOWN: | 114 case FECOMPONENTTRANSFER_TYPE_UNKNOWN: |
| 113 case FECOMPONENTTRANSFER_TYPE_IDENTITY: | 115 case FECOMPONENTTRANSFER_TYPE_IDENTITY: |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 ts << "{green: " << m_greenFunc << "}\n"; | 204 ts << "{green: " << m_greenFunc << "}\n"; |
| 203 writeIndent(ts, indent + 2); | 205 writeIndent(ts, indent + 2); |
| 204 ts << "{blue: " << m_blueFunc << "}\n"; | 206 ts << "{blue: " << m_blueFunc << "}\n"; |
| 205 writeIndent(ts, indent + 2); | 207 writeIndent(ts, indent + 2); |
| 206 ts << "{alpha: " << m_alphaFunc << "}]\n"; | 208 ts << "{alpha: " << m_alphaFunc << "}]\n"; |
| 207 inputEffect(0)->externalRepresentation(ts, indent + 1); | 209 inputEffect(0)->externalRepresentation(ts, indent + 1); |
| 208 return ts; | 210 return ts; |
| 209 } | 211 } |
| 210 | 212 |
| 211 } // namespace blink | 213 } // namespace blink |
| OLD | NEW |