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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/filters/FEColorMatrix.cpp

Issue 1366903002: Make error-handling for feColorMatrix consistent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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) 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 static void luminanceToAlphaMatrix(SkScalar matrix[kColorMatrixSize]) 114 static void luminanceToAlphaMatrix(SkScalar matrix[kColorMatrixSize])
115 { 115 {
116 memset(matrix, 0, kColorMatrixSize * sizeof(SkScalar)); 116 memset(matrix, 0, kColorMatrixSize * sizeof(SkScalar));
117 matrix[15] = 0.2125f; 117 matrix[15] = 0.2125f;
118 matrix[16] = 0.7154f; 118 matrix[16] = 0.7154f;
119 matrix[17] = 0.0721f; 119 matrix[17] = 0.0721f;
120 } 120 }
121 121
122 static SkColorFilter* createColorFilter(ColorMatrixType type, const Vector<float >& values) 122 static SkColorFilter* createColorFilter(ColorMatrixType type, const Vector<float >& values)
123 { 123 {
124 // Use defaults if values contains too few values. See SVGFEColorMatrixEleme nt::build 124 // Use defaults if values contains too few/many values.
125 SkScalar matrix[kColorMatrixSize]; 125 SkScalar matrix[kColorMatrixSize];
126 memset(matrix, 0, kColorMatrixSize * sizeof(SkScalar)); 126 memset(matrix, 0, kColorMatrixSize * sizeof(SkScalar));
127 matrix[0] = matrix[6] = matrix[12] = matrix[18] = 1; 127 matrix[0] = matrix[6] = matrix[12] = matrix[18] = 1;
128 128
129 switch (type) { 129 switch (type) {
130 case FECOLORMATRIX_TYPE_UNKNOWN: 130 case FECOLORMATRIX_TYPE_UNKNOWN:
131 break; 131 break;
132 case FECOLORMATRIX_TYPE_MATRIX: 132 case FECOLORMATRIX_TYPE_MATRIX:
133 if (values.size() >= kColorMatrixSize) { 133 if (values.size() == kColorMatrixSize) {
134 for (unsigned i = 0; i < kColorMatrixSize; ++i) 134 for (unsigned i = 0; i < kColorMatrixSize; ++i)
135 matrix[i] = values[i]; 135 matrix[i] = values[i];
136 } 136 }
137 matrix[4] *= SkScalar(255); 137 matrix[4] *= SkScalar(255);
138 matrix[9] *= SkScalar(255); 138 matrix[9] *= SkScalar(255);
139 matrix[14] *= SkScalar(255); 139 matrix[14] *= SkScalar(255);
140 matrix[19] *= SkScalar(255); 140 matrix[19] *= SkScalar(255);
141 break; 141 break;
142 case FECOLORMATRIX_TYPE_SATURATE: 142 case FECOLORMATRIX_TYPE_SATURATE:
143 if (values.size()) 143 if (values.size() == 1)
144 saturateMatrix(values[0], matrix); 144 saturateMatrix(values[0], matrix);
145 break; 145 break;
146 case FECOLORMATRIX_TYPE_HUEROTATE: 146 case FECOLORMATRIX_TYPE_HUEROTATE:
147 if (values.size()) 147 if (values.size() == 1)
148 hueRotateMatrix(values[0], matrix); 148 hueRotateMatrix(values[0], matrix);
149 break; 149 break;
150 case FECOLORMATRIX_TYPE_LUMINANCETOALPHA: 150 case FECOLORMATRIX_TYPE_LUMINANCETOALPHA:
151 luminanceToAlphaMatrix(matrix); 151 luminanceToAlphaMatrix(matrix);
152 break; 152 break;
153 } 153 }
154 return SkColorMatrixFilter::Create(matrix); 154 return SkColorMatrixFilter::Create(matrix);
155 } 155 }
156 156
157 bool FEColorMatrix::affectsTransparentPixels() 157 bool FEColorMatrix::affectsTransparentPixels()
(...skipping 26 matching lines...) Expand all
184 case FECOLORMATRIX_TYPE_HUEROTATE: 184 case FECOLORMATRIX_TYPE_HUEROTATE:
185 ts << "HUEROTATE"; 185 ts << "HUEROTATE";
186 break; 186 break;
187 case FECOLORMATRIX_TYPE_LUMINANCETOALPHA: 187 case FECOLORMATRIX_TYPE_LUMINANCETOALPHA:
188 ts << "LUMINANCETOALPHA"; 188 ts << "LUMINANCETOALPHA";
189 break; 189 break;
190 } 190 }
191 return ts; 191 return ts;
192 } 192 }
193 193
194 static bool valuesIsValidForType(ColorMatrixType type, const Vector<float>& valu es)
195 {
196 switch (type) {
197 case FECOLORMATRIX_TYPE_MATRIX:
198 return values.size() == kColorMatrixSize;
199 case FECOLORMATRIX_TYPE_SATURATE:
200 case FECOLORMATRIX_TYPE_HUEROTATE:
201 return values.size() == 1;
202 case FECOLORMATRIX_TYPE_LUMINANCETOALPHA:
203 return values.size() == 0;
204 case FECOLORMATRIX_TYPE_UNKNOWN:
205 break;
206 }
207 ASSERT_NOT_REACHED();
208 return false;
209 }
210
194 TextStream& FEColorMatrix::externalRepresentation(TextStream& ts, int indent) co nst 211 TextStream& FEColorMatrix::externalRepresentation(TextStream& ts, int indent) co nst
195 { 212 {
196 writeIndent(ts, indent); 213 writeIndent(ts, indent);
197 ts << "[feColorMatrix"; 214 ts << "[feColorMatrix";
198 FilterEffect::externalRepresentation(ts); 215 FilterEffect::externalRepresentation(ts);
199 ts << " type=\"" << m_type << "\""; 216 ts << " type=\"" << m_type << "\"";
200 if (!m_values.isEmpty()) { 217 if (!m_values.isEmpty() && valuesIsValidForType(m_type, m_values)) {
201 ts << " values=\""; 218 ts << " values=\"";
202 Vector<float>::const_iterator ptr = m_values.begin(); 219 Vector<float>::const_iterator ptr = m_values.begin();
203 const Vector<float>::const_iterator end = m_values.end(); 220 const Vector<float>::const_iterator end = m_values.end();
204 while (ptr < end) { 221 while (ptr < end) {
205 ts << *ptr; 222 ts << *ptr;
206 ++ptr; 223 ++ptr;
207 if (ptr < end) 224 if (ptr < end)
208 ts << " "; 225 ts << " ";
209 } 226 }
210 ts << "\""; 227 ts << "\"";
211 } 228 }
212 ts << "]\n"; 229 ts << "]\n";
213 inputEffect(0)->externalRepresentation(ts, indent + 1); 230 inputEffect(0)->externalRepresentation(ts, indent + 1);
214 return ts; 231 return ts;
215 } 232 }
216 233
217 } // namespace blink 234 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698