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) 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; |
|
pdr.
2014/03/26 00:00:13
Curious: Why int? Can this be changed to unsigned
Savago
2014/03/26 00:12:24
IntSize.setWidth/setHeight() operates on integers.
| |
| 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(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(0, 0); |
| 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, float stdX, float st dY) |
| 251 { | 252 { |
| 252 stdX = filter->applyHorizontalScale(stdX); | 253 stdX = filter->applyHorizontalScale(stdX); |
| 253 stdY = filter->applyVerticalScale(stdY); | 254 stdY = filter->applyVerticalScale(stdY); |
| 254 | 255 |
| 255 calculateUnscaledKernelSize(kernelSizeX, kernelSizeY, stdX, stdY); | 256 return calculateUnscaledKernelSize(FloatPoint(stdX, stdY)); |
| 256 } | 257 } |
| 257 | 258 |
| 258 FloatRect FEGaussianBlur::mapRect(const FloatRect& rect, bool) | 259 FloatRect FEGaussianBlur::mapRect(const FloatRect& rect, bool) |
| 259 { | 260 { |
| 260 FloatRect result = rect; | 261 FloatRect result = rect; |
| 261 unsigned kernelSizeX = 0; | 262 IntSize kernelSize(0, 0); |
|
Stephen White
2014/03/26 00:22:21
No point in explicitly initializing this if you're
| |
| 262 unsigned kernelSizeY = 0; | 263 kernelSize = calculateKernelSize(filter(), m_stdX, m_stdY); |
| 263 calculateKernelSize(filter(), kernelSizeX, kernelSizeY, m_stdX, m_stdY); | |
| 264 | 264 |
| 265 // We take the half kernel size and multiply it with three, because we run b ox blur three times. | 265 // 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); | 266 result.inflateX(3 * kernelSize.width() * 0.5f); |
| 267 result.inflateY(3 * kernelSizeY * 0.5f); | 267 result.inflateY(3 * kernelSize.height() * 0.5f); |
| 268 return result; | 268 return result; |
| 269 } | 269 } |
| 270 | 270 |
| 271 FloatRect FEGaussianBlur::determineAbsolutePaintRect(const FloatRect& originalRe questedRect) | 271 FloatRect FEGaussianBlur::determineAbsolutePaintRect(const FloatRect& originalRe questedRect) |
| 272 { | 272 { |
| 273 FloatRect requestedRect = originalRequestedRect; | 273 FloatRect requestedRect = originalRequestedRect; |
| 274 if (clipsToBounds()) | 274 if (clipsToBounds()) |
| 275 requestedRect.intersect(maxEffectRect()); | 275 requestedRect.intersect(maxEffectRect()); |
| 276 | 276 |
| 277 FilterEffect* input = inputEffect(0); | 277 FilterEffect* input = inputEffect(0); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 297 return; | 297 return; |
| 298 | 298 |
| 299 setIsAlphaImage(in->isAlphaImage()); | 299 setIsAlphaImage(in->isAlphaImage()); |
| 300 | 300 |
| 301 IntRect effectDrawingRect = requestedRegionOfInputImageData(in->absolutePain tRect()); | 301 IntRect effectDrawingRect = requestedRegionOfInputImageData(in->absolutePain tRect()); |
| 302 in->copyPremultipliedImage(srcPixelArray, effectDrawingRect); | 302 in->copyPremultipliedImage(srcPixelArray, effectDrawingRect); |
| 303 | 303 |
| 304 if (!m_stdX && !m_stdY) | 304 if (!m_stdX && !m_stdY) |
| 305 return; | 305 return; |
| 306 | 306 |
| 307 unsigned kernelSizeX = 0; | 307 IntSize kernelSize(0, 0); |
|
pdr.
2014/03/26 00:00:13
Is this needed?
Stephen White
2014/03/26 00:22:21
Same here.
| |
| 308 unsigned kernelSizeY = 0; | 308 kernelSize = calculateKernelSize(filter(), m_stdX, m_stdY); |
| 309 calculateKernelSize(filter(), kernelSizeX, kernelSizeY, m_stdX, m_stdY); | |
| 310 | 309 |
| 311 IntSize paintSize = absolutePaintRect().size(); | 310 IntSize paintSize = absolutePaintRect().size(); |
| 312 RefPtr<Uint8ClampedArray> tmpImageData = Uint8ClampedArray::createUninitiali zed(paintSize.width() * paintSize.height() * 4); | 311 RefPtr<Uint8ClampedArray> tmpImageData = Uint8ClampedArray::createUninitiali zed(paintSize.width() * paintSize.height() * 4); |
| 313 Uint8ClampedArray* tmpPixelArray = tmpImageData.get(); | 312 Uint8ClampedArray* tmpPixelArray = tmpImageData.get(); |
| 314 | 313 |
| 315 platformApply(srcPixelArray, tmpPixelArray, kernelSizeX, kernelSizeY, paintS ize); | 314 platformApply(srcPixelArray, tmpPixelArray, kernelSize.width(), kernelSize.h eight(), paintSize); |
| 316 } | 315 } |
| 317 | 316 |
| 318 bool FEGaussianBlur::applySkia() | 317 bool FEGaussianBlur::applySkia() |
| 319 { | 318 { |
| 320 ImageBuffer* resultImage = createImageBufferResult(); | 319 ImageBuffer* resultImage = createImageBufferResult(); |
| 321 if (!resultImage) | 320 if (!resultImage) |
| 322 return false; | 321 return false; |
| 323 | 322 |
| 324 FilterEffect* in = inputEffect(0); | 323 FilterEffect* in = inputEffect(0); |
| 325 | 324 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 356 { | 355 { |
| 357 writeIndent(ts, indent); | 356 writeIndent(ts, indent); |
| 358 ts << "[feGaussianBlur"; | 357 ts << "[feGaussianBlur"; |
| 359 FilterEffect::externalRepresentation(ts); | 358 FilterEffect::externalRepresentation(ts); |
| 360 ts << " stdDeviation=\"" << m_stdX << ", " << m_stdY << "\"]\n"; | 359 ts << " stdDeviation=\"" << m_stdX << ", " << m_stdY << "\"]\n"; |
| 361 inputEffect(0)->externalRepresentation(ts, indent + 1); | 360 inputEffect(0)->externalRepresentation(ts, indent + 1); |
| 362 return ts; | 361 return ts; |
| 363 } | 362 } |
| 364 | 363 |
| 365 } // namespace WebCore | 364 } // namespace WebCore |
| OLD | NEW |