OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. 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 24 matching lines...) Expand all Loading... |
35 #include "platform/graphics/filters/FEColorMatrix.h" | 35 #include "platform/graphics/filters/FEColorMatrix.h" |
36 #include "platform/graphics/filters/FEComponentTransfer.h" | 36 #include "platform/graphics/filters/FEComponentTransfer.h" |
37 #include "platform/graphics/filters/FEDropShadow.h" | 37 #include "platform/graphics/filters/FEDropShadow.h" |
38 #include "platform/graphics/filters/FEGaussianBlur.h" | 38 #include "platform/graphics/filters/FEGaussianBlur.h" |
39 #include "platform/graphics/filters/SourceGraphic.h" | 39 #include "platform/graphics/filters/SourceGraphic.h" |
40 #include "wtf/MathExtras.h" | 40 #include "wtf/MathExtras.h" |
41 #include <algorithm> | 41 #include <algorithm> |
42 | 42 |
43 namespace blink { | 43 namespace blink { |
44 | 44 |
45 static inline void endMatrixRow(Vector<float>& parameters) | 45 namespace { |
| 46 |
| 47 inline void endMatrixRow(Vector<float>& matrix) |
46 { | 48 { |
47 parameters.append(0); | 49 matrix.uncheckedAppend(0); |
48 parameters.append(0); | 50 matrix.uncheckedAppend(0); |
49 } | 51 } |
50 | 52 |
51 static inline void lastMatrixRow(Vector<float>& parameters) | 53 inline void lastMatrixRow(Vector<float>& matrix) |
52 { | 54 { |
53 parameters.append(0); | 55 matrix.uncheckedAppend(0); |
54 parameters.append(0); | 56 matrix.uncheckedAppend(0); |
55 parameters.append(0); | 57 matrix.uncheckedAppend(0); |
56 parameters.append(1); | 58 matrix.uncheckedAppend(1); |
57 parameters.append(0); | 59 matrix.uncheckedAppend(0); |
58 } | 60 } |
59 | 61 |
| 62 Vector<float> grayscaleMatrix(double amount) |
| 63 { |
| 64 double oneMinusAmount = clampTo(1 - amount, 0.0, 1.0); |
| 65 |
| 66 // See https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#grayscale
Equivalent |
| 67 // for information on parameters. |
| 68 Vector<float> matrix; |
| 69 matrix.reserveInitialCapacity(20); |
| 70 |
| 71 matrix.uncheckedAppend(narrowPrecisionToFloat(0.2126 + 0.7874 * oneMinusAmou
nt)); |
| 72 matrix.uncheckedAppend(narrowPrecisionToFloat(0.7152 - 0.7152 * oneMinusAmou
nt)); |
| 73 matrix.uncheckedAppend(narrowPrecisionToFloat(0.0722 - 0.0722 * oneMinusAmou
nt)); |
| 74 endMatrixRow(matrix); |
| 75 |
| 76 matrix.uncheckedAppend(narrowPrecisionToFloat(0.2126 - 0.2126 * oneMinusAmou
nt)); |
| 77 matrix.uncheckedAppend(narrowPrecisionToFloat(0.7152 + 0.2848 * oneMinusAmou
nt)); |
| 78 matrix.uncheckedAppend(narrowPrecisionToFloat(0.0722 - 0.0722 * oneMinusAmou
nt)); |
| 79 endMatrixRow(matrix); |
| 80 |
| 81 matrix.uncheckedAppend(narrowPrecisionToFloat(0.2126 - 0.2126 * oneMinusAmou
nt)); |
| 82 matrix.uncheckedAppend(narrowPrecisionToFloat(0.7152 - 0.7152 * oneMinusAmou
nt)); |
| 83 matrix.uncheckedAppend(narrowPrecisionToFloat(0.0722 + 0.9278 * oneMinusAmou
nt)); |
| 84 endMatrixRow(matrix); |
| 85 |
| 86 lastMatrixRow(matrix); |
| 87 return matrix; |
| 88 } |
| 89 |
| 90 Vector<float> sepiaMatrix(double amount) |
| 91 { |
| 92 double oneMinusAmount = clampTo(1 - amount, 0.0, 1.0); |
| 93 |
| 94 // See https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#sepiaEqui
valent |
| 95 // for information on parameters. |
| 96 Vector<float> matrix; |
| 97 matrix.reserveInitialCapacity(20); |
| 98 |
| 99 matrix.uncheckedAppend(narrowPrecisionToFloat(0.393 + 0.607 * oneMinusAmount
)); |
| 100 matrix.uncheckedAppend(narrowPrecisionToFloat(0.769 - 0.769 * oneMinusAmount
)); |
| 101 matrix.uncheckedAppend(narrowPrecisionToFloat(0.189 - 0.189 * oneMinusAmount
)); |
| 102 endMatrixRow(matrix); |
| 103 |
| 104 matrix.uncheckedAppend(narrowPrecisionToFloat(0.349 - 0.349 * oneMinusAmount
)); |
| 105 matrix.uncheckedAppend(narrowPrecisionToFloat(0.686 + 0.314 * oneMinusAmount
)); |
| 106 matrix.uncheckedAppend(narrowPrecisionToFloat(0.168 - 0.168 * oneMinusAmount
)); |
| 107 endMatrixRow(matrix); |
| 108 |
| 109 matrix.uncheckedAppend(narrowPrecisionToFloat(0.272 - 0.272 * oneMinusAmount
)); |
| 110 matrix.uncheckedAppend(narrowPrecisionToFloat(0.534 - 0.534 * oneMinusAmount
)); |
| 111 matrix.uncheckedAppend(narrowPrecisionToFloat(0.131 + 0.869 * oneMinusAmount
)); |
| 112 endMatrixRow(matrix); |
| 113 |
| 114 lastMatrixRow(matrix); |
| 115 return matrix; |
| 116 } |
| 117 |
| 118 } // namespace |
| 119 |
60 FilterEffectBuilder::FilterEffectBuilder() | 120 FilterEffectBuilder::FilterEffectBuilder() |
61 { | 121 { |
62 } | 122 } |
63 | 123 |
64 FilterEffectBuilder::~FilterEffectBuilder() | 124 FilterEffectBuilder::~FilterEffectBuilder() |
65 { | 125 { |
66 } | 126 } |
67 | 127 |
68 DEFINE_TRACE(FilterEffectBuilder) | 128 DEFINE_TRACE(FilterEffectBuilder) |
69 { | 129 { |
(...skipping 12 matching lines...) Expand all Loading... |
82 switch (filterOperation->type()) { | 142 switch (filterOperation->type()) { |
83 case FilterOperation::REFERENCE: { | 143 case FilterOperation::REFERENCE: { |
84 RefPtrWillBeRawPtr<Filter> referenceFilter = ReferenceFilterBuilder:
:build(zoom, element, previousEffect.get(), toReferenceFilterOperation(*filterOp
eration)); | 144 RefPtrWillBeRawPtr<Filter> referenceFilter = ReferenceFilterBuilder:
:build(zoom, element, previousEffect.get(), toReferenceFilterOperation(*filterOp
eration)); |
85 if (referenceFilter) { | 145 if (referenceFilter) { |
86 effect = referenceFilter->lastEffect(); | 146 effect = referenceFilter->lastEffect(); |
87 m_referenceFilters.append(referenceFilter); | 147 m_referenceFilters.append(referenceFilter); |
88 } | 148 } |
89 break; | 149 break; |
90 } | 150 } |
91 case FilterOperation::GRAYSCALE: { | 151 case FilterOperation::GRAYSCALE: { |
92 Vector<float> inputParameters; | 152 Vector<float> inputParameters = grayscaleMatrix(toBasicColorMatrixFi
lterOperation(filterOperation)->amount()); |
93 double oneMinusAmount = clampTo(1 - toBasicColorMatrixFilterOperatio
n(filterOperation)->amount(), 0.0, 1.0); | |
94 | |
95 // See https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#g
rayscaleEquivalent | |
96 // for information on parameters. | |
97 | |
98 inputParameters.append(narrowPrecisionToFloat(0.2126 + 0.7874 * oneM
inusAmount)); | |
99 inputParameters.append(narrowPrecisionToFloat(0.7152 - 0.7152 * oneM
inusAmount)); | |
100 inputParameters.append(narrowPrecisionToFloat(0.0722 - 0.0722 * oneM
inusAmount)); | |
101 endMatrixRow(inputParameters); | |
102 | |
103 inputParameters.append(narrowPrecisionToFloat(0.2126 - 0.2126 * oneM
inusAmount)); | |
104 inputParameters.append(narrowPrecisionToFloat(0.7152 + 0.2848 * oneM
inusAmount)); | |
105 inputParameters.append(narrowPrecisionToFloat(0.0722 - 0.0722 * oneM
inusAmount)); | |
106 endMatrixRow(inputParameters); | |
107 | |
108 inputParameters.append(narrowPrecisionToFloat(0.2126 - 0.2126 * oneM
inusAmount)); | |
109 inputParameters.append(narrowPrecisionToFloat(0.7152 - 0.7152 * oneM
inusAmount)); | |
110 inputParameters.append(narrowPrecisionToFloat(0.0722 + 0.9278 * oneM
inusAmount)); | |
111 endMatrixRow(inputParameters); | |
112 | |
113 lastMatrixRow(inputParameters); | |
114 | |
115 effect = FEColorMatrix::create(parentFilter.get(), FECOLORMATRIX_TYP
E_MATRIX, inputParameters); | 153 effect = FEColorMatrix::create(parentFilter.get(), FECOLORMATRIX_TYP
E_MATRIX, inputParameters); |
116 break; | 154 break; |
117 } | 155 } |
118 case FilterOperation::SEPIA: { | 156 case FilterOperation::SEPIA: { |
119 Vector<float> inputParameters; | 157 Vector<float> inputParameters = sepiaMatrix(toBasicColorMatrixFilter
Operation(filterOperation)->amount()); |
120 double oneMinusAmount = clampTo(1 - toBasicColorMatrixFilterOperatio
n(filterOperation)->amount(), 0.0, 1.0); | |
121 | |
122 // See https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#s
epiaEquivalent | |
123 // for information on parameters. | |
124 | |
125 inputParameters.append(narrowPrecisionToFloat(0.393 + 0.607 * oneMin
usAmount)); | |
126 inputParameters.append(narrowPrecisionToFloat(0.769 - 0.769 * oneMin
usAmount)); | |
127 inputParameters.append(narrowPrecisionToFloat(0.189 - 0.189 * oneMin
usAmount)); | |
128 endMatrixRow(inputParameters); | |
129 | |
130 inputParameters.append(narrowPrecisionToFloat(0.349 - 0.349 * oneMin
usAmount)); | |
131 inputParameters.append(narrowPrecisionToFloat(0.686 + 0.314 * oneMin
usAmount)); | |
132 inputParameters.append(narrowPrecisionToFloat(0.168 - 0.168 * oneMin
usAmount)); | |
133 endMatrixRow(inputParameters); | |
134 | |
135 inputParameters.append(narrowPrecisionToFloat(0.272 - 0.272 * oneMin
usAmount)); | |
136 inputParameters.append(narrowPrecisionToFloat(0.534 - 0.534 * oneMin
usAmount)); | |
137 inputParameters.append(narrowPrecisionToFloat(0.131 + 0.869 * oneMin
usAmount)); | |
138 endMatrixRow(inputParameters); | |
139 | |
140 lastMatrixRow(inputParameters); | |
141 | |
142 effect = FEColorMatrix::create(parentFilter.get(), FECOLORMATRIX_TYP
E_MATRIX, inputParameters); | 158 effect = FEColorMatrix::create(parentFilter.get(), FECOLORMATRIX_TYP
E_MATRIX, inputParameters); |
143 break; | 159 break; |
144 } | 160 } |
145 case FilterOperation::SATURATE: { | 161 case FilterOperation::SATURATE: { |
146 Vector<float> inputParameters; | 162 Vector<float> inputParameters; |
147 inputParameters.append(narrowPrecisionToFloat(toBasicColorMatrixFilt
erOperation(filterOperation)->amount())); | 163 inputParameters.append(narrowPrecisionToFloat(toBasicColorMatrixFilt
erOperation(filterOperation)->amount())); |
148 effect = FEColorMatrix::create(parentFilter.get(), FECOLORMATRIX_TYP
E_SATURATE, inputParameters); | 164 effect = FEColorMatrix::create(parentFilter.get(), FECOLORMATRIX_TYP
E_SATURATE, inputParameters); |
149 break; | 165 break; |
150 } | 166 } |
151 case FilterOperation::HUE_ROTATE: { | 167 case FilterOperation::HUE_ROTATE: { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 252 |
237 // If we didn't make any effects, tell our caller we are not valid | 253 // If we didn't make any effects, tell our caller we are not valid |
238 if (!m_lastEffect.get()) | 254 if (!m_lastEffect.get()) |
239 return false; | 255 return false; |
240 | 256 |
241 return true; | 257 return true; |
242 } | 258 } |
243 | 259 |
244 } // namespace blink | 260 } // namespace blink |
245 | 261 |
OLD | NEW |