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) 2010 Igalia, S.L. | 6 * Copyright (C) 2010 Igalia, S.L. |
7 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 7 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
8 * Copyright (C) 2013 Google Inc. All rights reserved. | 8 * Copyright (C) 2013 Google Inc. All rights reserved. |
9 * | 9 * |
10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
(...skipping 26 matching lines...) Expand all Loading... | |
37 | 37 |
38 #include "SkBlurImageFilter.h" | 38 #include "SkBlurImageFilter.h" |
39 | 39 |
40 using namespace std; | 40 using namespace std; |
41 | 41 |
42 static inline float gaussianKernelFactor() | 42 static inline float gaussianKernelFactor() |
43 { | 43 { |
44 return 3 / 4.f * sqrtf(twoPiFloat); | 44 return 3 / 4.f * sqrtf(twoPiFloat); |
45 } | 45 } |
46 | 46 |
47 static const unsigned gMaxKernelSize = 1000; | 47 static const int gMaxKernelSize = 1000; |
48 | 48 |
49 namespace WebCore { | 49 namespace WebCore { |
50 | 50 |
51 FEGaussianBlur::FEGaussianBlur(Filter* filter, float x, float y) | 51 FEGaussianBlur::FEGaussianBlur(Filter* filter, float x, float y) |
52 : FilterEffect(filter) | 52 : FilterEffect(filter) |
53 , m_stdX(x) | 53 , m_stdX(x) |
54 , m_stdY(y) | 54 , m_stdY(y) |
55 { | 55 { |
56 } | 56 } |
57 | 57 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 } | 221 } |
222 return; | 222 return; |
223 } | 223 } |
224 // Fallback to single threaded mode. | 224 // Fallback to single threaded mode. |
225 } | 225 } |
226 | 226 |
227 // The selection here eventually should happen dynamically on some platforms . | 227 // The selection here eventually should happen dynamically on some platforms . |
228 platformApplyGeneric(srcPixelArray, tmpPixelArray, kernelSizeX, kernelSizeY, paintSize); | 228 platformApplyGeneric(srcPixelArray, tmpPixelArray, kernelSizeX, kernelSizeY, paintSize); |
229 } | 229 } |
230 | 230 |
231 void FEGaussianBlur::calculateUnscaledKernelSize(unsigned& kernelSizeX, unsigned & kernelSizeY, float stdX, float stdY) | 231 IntSize FEGaussianBlur::calculateUnscaledKernelSize(const FloatPoint& std) |
232 { | 232 { |
233 ASSERT(stdX >= 0 && stdY >= 0); | 233 ASSERT(std.x() >= 0 && std.y() >= 0); |
234 | 234 |
235 kernelSizeX = 0; | 235 IntSize kernelSize; |
236 if (stdX) | |
237 kernelSizeX = max<unsigned>(2, static_cast<unsigned>(floorf(stdX * gauss ianKernelFactor() + 0.5f))); | |
238 kernelSizeY = 0; | |
239 if (stdY) | |
240 kernelSizeY = max<unsigned>(2, static_cast<unsigned>(floorf(stdY * gauss ianKernelFactor() + 0.5f))); | |
241 | |
242 // Limit the kernel size to 1000. A bigger radius won't make a big differenc e for the result image but | 236 // Limit the kernel size to 1000. A bigger radius won't make a big differenc e for the result image but |
243 // inflates the absolute paint rect to much. This is compatible with Firefox ' behavior. | 237 // inflates the absolute paint rect to much. This is compatible with Firefox ' behavior. |
244 if (kernelSizeX > gMaxKernelSize) | 238 if (std.x()) { |
245 kernelSizeX = gMaxKernelSize; | 239 int size = max<unsigned>(2, static_cast<unsigned>(floorf(std.x() * gauss ianKernelFactor() + 0.5f))); |
246 if (kernelSizeY > gMaxKernelSize) | 240 kernelSize.setWidth(min(size, gMaxKernelSize)); |
247 kernelSizeY = gMaxKernelSize; | 241 } |
242 | |
243 if (std.y()) { | |
244 int size = max<unsigned>(2, static_cast<unsigned>(floorf(std.y() * gauss ianKernelFactor() + 0.5f))); | |
245 kernelSize.setHeight(min(size, gMaxKernelSize)); | |
246 } | |
247 | |
248 return kernelSize; | |
248 } | 249 } |
249 | 250 |
250 void FEGaussianBlur::calculateKernelSize(Filter* filter, unsigned& kernelSizeX, unsigned& kernelSizeY, float stdX, float stdY) | 251 IntSize FEGaussianBlur::calculateKernelSize(Filter* filter, const FloatPoint& st d) |
251 { | 252 { |
252 stdX = filter->applyHorizontalScale(stdX); | 253 FloatPoint stdError(filter->applyHorizontalScale(std.x()), filter->applyVert icalScale(std.y())); |
Stephen White
2014/03/27 04:11:53
I wonder if we should just have an applyScale() th
Savago
2014/03/27 04:51:19
I can look on that.
| |
253 stdY = filter->applyVerticalScale(stdY); | |
254 | 254 |
255 calculateUnscaledKernelSize(kernelSizeX, kernelSizeY, stdX, stdY); | 255 return calculateUnscaledKernelSize(stdError); |
256 } | 256 } |
257 | 257 |
258 FloatRect FEGaussianBlur::mapRect(const FloatRect& rect, bool) | 258 FloatRect FEGaussianBlur::mapRect(const FloatRect& rect, bool) |
259 { | 259 { |
260 FloatRect result = rect; | 260 FloatRect result = rect; |
261 unsigned kernelSizeX = 0; | 261 IntSize kernelSize = calculateKernelSize(filter(), FloatPoint(m_stdX, m_stdY )); |
262 unsigned kernelSizeY = 0; | |
263 calculateKernelSize(filter(), kernelSizeX, kernelSizeY, m_stdX, m_stdY); | |
264 | 262 |
265 // We take the half kernel size and multiply it with three, because we run b ox blur three times. | 263 // We take the half kernel size and multiply it with three, because we run b ox blur three times. |
266 result.inflateX(3 * kernelSizeX * 0.5f); | 264 result.inflateX(3 * kernelSize.width() * 0.5f); |
267 result.inflateY(3 * kernelSizeY * 0.5f); | 265 result.inflateY(3 * kernelSize.height() * 0.5f); |
268 return result; | 266 return result; |
269 } | 267 } |
270 | 268 |
271 FloatRect FEGaussianBlur::determineAbsolutePaintRect(const FloatRect& originalRe questedRect) | 269 FloatRect FEGaussianBlur::determineAbsolutePaintRect(const FloatRect& originalRe questedRect) |
272 { | 270 { |
273 FloatRect requestedRect = originalRequestedRect; | 271 FloatRect requestedRect = originalRequestedRect; |
274 if (clipsToBounds()) | 272 if (clipsToBounds()) |
275 requestedRect.intersect(maxEffectRect()); | 273 requestedRect.intersect(maxEffectRect()); |
276 | 274 |
277 FilterEffect* input = inputEffect(0); | 275 FilterEffect* input = inputEffect(0); |
(...skipping 19 matching lines...) Expand all Loading... | |
297 return; | 295 return; |
298 | 296 |
299 setIsAlphaImage(in->isAlphaImage()); | 297 setIsAlphaImage(in->isAlphaImage()); |
300 | 298 |
301 IntRect effectDrawingRect = requestedRegionOfInputImageData(in->absolutePain tRect()); | 299 IntRect effectDrawingRect = requestedRegionOfInputImageData(in->absolutePain tRect()); |
302 in->copyPremultipliedImage(srcPixelArray, effectDrawingRect); | 300 in->copyPremultipliedImage(srcPixelArray, effectDrawingRect); |
303 | 301 |
304 if (!m_stdX && !m_stdY) | 302 if (!m_stdX && !m_stdY) |
305 return; | 303 return; |
306 | 304 |
307 unsigned kernelSizeX = 0; | 305 IntSize kernelSize = calculateKernelSize(filter(), FloatPoint(m_stdX, m_stdY )); |
308 unsigned kernelSizeY = 0; | |
309 calculateKernelSize(filter(), kernelSizeX, kernelSizeY, m_stdX, m_stdY); | |
310 | 306 |
311 IntSize paintSize = absolutePaintRect().size(); | 307 IntSize paintSize = absolutePaintRect().size(); |
312 RefPtr<Uint8ClampedArray> tmpImageData = Uint8ClampedArray::createUninitiali zed(paintSize.width() * paintSize.height() * 4); | 308 RefPtr<Uint8ClampedArray> tmpImageData = Uint8ClampedArray::createUninitiali zed(paintSize.width() * paintSize.height() * 4); |
313 Uint8ClampedArray* tmpPixelArray = tmpImageData.get(); | 309 Uint8ClampedArray* tmpPixelArray = tmpImageData.get(); |
314 | 310 |
315 platformApply(srcPixelArray, tmpPixelArray, kernelSizeX, kernelSizeY, paintS ize); | 311 platformApply(srcPixelArray, tmpPixelArray, kernelSize.width(), kernelSize.h eight(), paintSize); |
316 } | 312 } |
317 | 313 |
318 bool FEGaussianBlur::applySkia() | 314 bool FEGaussianBlur::applySkia() |
319 { | 315 { |
320 ImageBuffer* resultImage = createImageBufferResult(); | 316 ImageBuffer* resultImage = createImageBufferResult(); |
321 if (!resultImage) | 317 if (!resultImage) |
322 return false; | 318 return false; |
323 | 319 |
324 FilterEffect* in = inputEffect(0); | 320 FilterEffect* in = inputEffect(0); |
325 | 321 |
(...skipping 30 matching lines...) Expand all Loading... | |
356 { | 352 { |
357 writeIndent(ts, indent); | 353 writeIndent(ts, indent); |
358 ts << "[feGaussianBlur"; | 354 ts << "[feGaussianBlur"; |
359 FilterEffect::externalRepresentation(ts); | 355 FilterEffect::externalRepresentation(ts); |
360 ts << " stdDeviation=\"" << m_stdX << ", " << m_stdY << "\"]\n"; | 356 ts << " stdDeviation=\"" << m_stdX << ", " << m_stdY << "\"]\n"; |
361 inputEffect(0)->externalRepresentation(ts, indent + 1); | 357 inputEffect(0)->externalRepresentation(ts, indent + 1); |
362 return ts; | 358 return ts; |
363 } | 359 } |
364 | 360 |
365 } // namespace WebCore | 361 } // namespace WebCore |
OLD | NEW |