Chromium Code Reviews| 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) 2013 Google Inc. All rights reserved. | 6 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 return true; | 56 return true; |
| 57 } | 57 } |
| 58 | 58 |
| 59 const Vector<float>& FEColorMatrix::values() const | 59 const Vector<float>& FEColorMatrix::values() const |
| 60 { | 60 { |
| 61 return m_values; | 61 return m_values; |
| 62 } | 62 } |
| 63 | 63 |
| 64 bool FEColorMatrix::setValues(const Vector<float> &values) | 64 bool FEColorMatrix::setValues(const Vector<float> &values) |
| 65 { | 65 { |
| 66 ASSERT(values.size() == 20); | |
| 67 if (m_values == values) | 66 if (m_values == values) |
| 68 return false; | 67 return false; |
| 69 m_values = values; | 68 m_values = values; |
| 70 return true; | 69 return true; |
| 71 } | 70 } |
| 72 | 71 |
| 73 static void saturateMatrix(float s, SkScalar matrix[20]) | 72 static void saturateMatrix(float s, SkScalar matrix[20]) |
| 74 { | 73 { |
| 75 matrix[0] = 0.213f + 0.787f * s; | 74 matrix[0] = 0.213f + 0.787f * s; |
| 76 matrix[1] = 0.715f - 0.715f * s; | 75 matrix[1] = 0.715f - 0.715f * s; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 } | 110 } |
| 112 | 111 |
| 113 static void luminanceToAlphaMatrix(SkScalar matrix[20]) | 112 static void luminanceToAlphaMatrix(SkScalar matrix[20]) |
| 114 { | 113 { |
| 115 memset(matrix, 0, 20 * sizeof(SkScalar)); | 114 memset(matrix, 0, 20 * sizeof(SkScalar)); |
| 116 matrix[15] = 0.2125f; | 115 matrix[15] = 0.2125f; |
| 117 matrix[16] = 0.7154f; | 116 matrix[16] = 0.7154f; |
| 118 matrix[17] = 0.0721f; | 117 matrix[17] = 0.0721f; |
| 119 } | 118 } |
| 120 | 119 |
| 121 static SkColorFilter* createColorFilter(ColorMatrixType type, const float* value s) | 120 static SkColorFilter* createColorFilter(ColorMatrixType type, const Vector<float >& values) |
| 122 { | 121 { |
| 122 // Use defaults if values contains too few values. See SVGFEColorMatrixEleme nt::build | |
|
fs
2015/04/15 22:07:27
Presumably said method would be made much simpler
| |
| 123 SkScalar matrix[20]; | 123 SkScalar matrix[20]; |
| 124 switch (type) { | 124 switch (type) { |
| 125 case FECOLORMATRIX_TYPE_UNKNOWN: | 125 case FECOLORMATRIX_TYPE_UNKNOWN: |
| 126 break; | 126 break; |
| 127 case FECOLORMATRIX_TYPE_MATRIX: | 127 case FECOLORMATRIX_TYPE_MATRIX: |
| 128 for (int i = 0; i < 20; ++i) | 128 if (values.size() < 20) { |
|
pdr.
2015/04/15 18:34:22
Named constant please :)
fs
2015/04/15 22:07:27
arraysize(matrix)? =)
Stephen Chennney
2015/04/16 18:12:19
The named constant lets us use it everywhere, incl
| |
| 129 matrix[i] = values[i]; | 129 for (size_t i = 0; i < 20; i++) |
|
pdr.
2015/04/15 18:34:22
One of these for loops uses a size_t with i++, the
Stephen Chennney
2015/04/16 18:12:19
Good point. That's what I get for copy-paste.
| |
| 130 | 130 matrix[i] = ((i % 6) ? 0 : 1); |
| 131 } else { | |
| 132 for (int i = 0; i < 20; ++i) | |
| 133 matrix[i] = values[i]; | |
| 134 } | |
| 131 matrix[4] *= SkScalar(255); | 135 matrix[4] *= SkScalar(255); |
| 132 matrix[9] *= SkScalar(255); | 136 matrix[9] *= SkScalar(255); |
| 133 matrix[14] *= SkScalar(255); | 137 matrix[14] *= SkScalar(255); |
| 134 matrix[19] *= SkScalar(255); | 138 matrix[19] *= SkScalar(255); |
| 135 break; | 139 break; |
| 136 case FECOLORMATRIX_TYPE_SATURATE: | 140 case FECOLORMATRIX_TYPE_SATURATE: |
| 137 saturateMatrix(values[0], matrix); | 141 if (values.size() < 1) |
| 142 saturateMatrix(1, matrix); | |
|
fs
2015/04/15 22:07:27
Since all these "error" cases end up generating an
Stephen Chennney
2015/04/16 18:12:19
Done.
| |
| 143 else | |
| 144 saturateMatrix(values[0], matrix); | |
| 138 break; | 145 break; |
| 139 case FECOLORMATRIX_TYPE_HUEROTATE: | 146 case FECOLORMATRIX_TYPE_HUEROTATE: |
| 140 hueRotateMatrix(values[0], matrix); | 147 if (values.size() < 1) |
| 148 hueRotateMatrix(0, matrix); | |
| 149 else | |
| 150 hueRotateMatrix(values[0], matrix); | |
| 141 break; | 151 break; |
| 142 case FECOLORMATRIX_TYPE_LUMINANCETOALPHA: | 152 case FECOLORMATRIX_TYPE_LUMINANCETOALPHA: |
| 143 luminanceToAlphaMatrix(matrix); | 153 luminanceToAlphaMatrix(matrix); |
| 144 break; | 154 break; |
| 145 } | 155 } |
| 146 return SkColorMatrixFilter::Create(matrix); | 156 return SkColorMatrixFilter::Create(matrix); |
| 147 } | 157 } |
| 148 | 158 |
| 149 bool FEColorMatrix::affectsTransparentPixels() | 159 bool FEColorMatrix::affectsTransparentPixels() |
| 150 { | 160 { |
| 151 // Because the input pixels are premultiplied, the only way clear pixels can be | 161 // Because the input pixels are premultiplied, the only way clear pixels can be |
| 152 // painted is if the additive component for the alpha is not 0. | 162 // painted is if the additive component for the alpha is not 0. |
| 153 return m_type == FECOLORMATRIX_TYPE_MATRIX && m_values[19] > 0; | 163 return m_type == FECOLORMATRIX_TYPE_MATRIX && m_values.size() > 19 && m_valu es[19] > 0; |
| 154 } | 164 } |
| 155 | 165 |
| 156 PassRefPtr<SkImageFilter> FEColorMatrix::createImageFilter(SkiaImageFilterBuilde r* builder) | 166 PassRefPtr<SkImageFilter> FEColorMatrix::createImageFilter(SkiaImageFilterBuilde r* builder) |
| 157 { | 167 { |
| 158 RefPtr<SkImageFilter> input(builder->build(inputEffect(0), operatingColorSpa ce())); | 168 RefPtr<SkImageFilter> input(builder->build(inputEffect(0), operatingColorSpa ce())); |
| 159 SkAutoTUnref<SkColorFilter> filter(createColorFilter(m_type, m_values.data() )); | 169 SkAutoTUnref<SkColorFilter> filter(createColorFilter(m_type, m_values)); |
| 160 SkImageFilter::CropRect rect = getCropRect(builder->cropOffset()); | 170 SkImageFilter::CropRect rect = getCropRect(builder->cropOffset()); |
| 161 return adoptRef(SkColorFilterImageFilter::Create(filter, input.get(), &rect) ); | 171 return adoptRef(SkColorFilterImageFilter::Create(filter, input.get(), &rect) ); |
| 162 } | 172 } |
| 163 | 173 |
| 164 static TextStream& operator<<(TextStream& ts, const ColorMatrixType& type) | 174 static TextStream& operator<<(TextStream& ts, const ColorMatrixType& type) |
| 165 { | 175 { |
| 166 switch (type) { | 176 switch (type) { |
| 167 case FECOLORMATRIX_TYPE_UNKNOWN: | 177 case FECOLORMATRIX_TYPE_UNKNOWN: |
| 168 ts << "UNKNOWN"; | 178 ts << "UNKNOWN"; |
| 169 break; | 179 break; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 200 ts << " "; | 210 ts << " "; |
| 201 } | 211 } |
| 202 ts << "\""; | 212 ts << "\""; |
| 203 } | 213 } |
| 204 ts << "]\n"; | 214 ts << "]\n"; |
| 205 inputEffect(0)->externalRepresentation(ts, indent + 1); | 215 inputEffect(0)->externalRepresentation(ts, indent + 1); |
| 206 return ts; | 216 return ts; |
| 207 } | 217 } |
| 208 | 218 |
| 209 } // namespace blink | 219 } // namespace blink |
| OLD | NEW |