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 30 matching lines...) Expand all Loading... |
41 : FilterEffect(filter), m_stdX(x), m_stdY(y) {} | 41 : FilterEffect(filter), m_stdX(x), m_stdY(y) {} |
42 | 42 |
43 FEGaussianBlur* FEGaussianBlur::create(Filter* filter, float x, float y) { | 43 FEGaussianBlur* FEGaussianBlur::create(Filter* filter, float x, float y) { |
44 return new FEGaussianBlur(filter, x, y); | 44 return new FEGaussianBlur(filter, x, y); |
45 } | 45 } |
46 | 46 |
47 IntSize FEGaussianBlur::calculateUnscaledKernelSize(const FloatPoint& std) { | 47 IntSize FEGaussianBlur::calculateUnscaledKernelSize(const FloatPoint& std) { |
48 ASSERT(std.x() >= 0 && std.y() >= 0); | 48 ASSERT(std.x() >= 0 && std.y() >= 0); |
49 | 49 |
50 IntSize kernelSize; | 50 IntSize kernelSize; |
51 // Limit the kernel size to 1000. A bigger radius won't make a big difference
for the result image but | 51 // Limit the kernel size to 1000. A bigger radius won't make a big difference |
52 // inflates the absolute paint rect to much. This is compatible with Firefox'
behavior. | 52 // for the result image but inflates the absolute paint rect too much. This is |
| 53 // compatible with Firefox' behavior. |
53 if (std.x()) { | 54 if (std.x()) { |
54 int size = std::max<unsigned>( | 55 int size = std::max<unsigned>( |
55 2, | 56 2, |
56 static_cast<unsigned>(floorf(std.x() * gaussianKernelFactor() + 0.5f))); | 57 static_cast<unsigned>(floorf(std.x() * gaussianKernelFactor() + 0.5f))); |
57 kernelSize.setWidth(size); | 58 kernelSize.setWidth(size); |
58 } | 59 } |
59 | 60 |
60 if (std.y()) { | 61 if (std.y()) { |
61 int size = std::max<unsigned>( | 62 int size = std::max<unsigned>( |
62 2, | 63 2, |
63 static_cast<unsigned>(floorf(std.y() * gaussianKernelFactor() + 0.5f))); | 64 static_cast<unsigned>(floorf(std.y() * gaussianKernelFactor() + 0.5f))); |
64 kernelSize.setHeight(size); | 65 kernelSize.setHeight(size); |
65 } | 66 } |
66 | 67 |
67 return kernelSize; | 68 return kernelSize; |
68 } | 69 } |
69 | 70 |
70 IntSize FEGaussianBlur::calculateKernelSize(const Filter* filter, | 71 IntSize FEGaussianBlur::calculateKernelSize(const Filter* filter, |
71 const FloatPoint& std) { | 72 const FloatPoint& std) { |
72 FloatPoint stdError(filter->applyHorizontalScale(std.x()), | 73 FloatPoint stdError(filter->applyHorizontalScale(std.x()), |
73 filter->applyVerticalScale(std.y())); | 74 filter->applyVerticalScale(std.y())); |
74 return calculateUnscaledKernelSize(stdError); | 75 return calculateUnscaledKernelSize(stdError); |
75 } | 76 } |
76 | 77 |
77 FloatRect FEGaussianBlur::mapEffect(const FloatRect& rect) const { | 78 FloatRect FEGaussianBlur::mapEffect(const FloatRect& rect) const { |
78 IntSize kernelSize = | 79 IntSize kernelSize = |
79 calculateKernelSize(getFilter(), FloatPoint(m_stdX, m_stdY)); | 80 calculateKernelSize(getFilter(), FloatPoint(m_stdX, m_stdY)); |
80 | 81 |
81 // We take the half kernel size and multiply it with three, because we run box
blur three times. | 82 // We take the half kernel size and multiply it by three, because we run box |
| 83 // blur three times. |
82 FloatRect result = rect; | 84 FloatRect result = rect; |
83 result.inflateX(3.0f * kernelSize.width() * 0.5f); | 85 result.inflateX(3.0f * kernelSize.width() * 0.5f); |
84 result.inflateY(3.0f * kernelSize.height() * 0.5f); | 86 result.inflateY(3.0f * kernelSize.height() * 0.5f); |
85 return result; | 87 return result; |
86 } | 88 } |
87 | 89 |
88 sk_sp<SkImageFilter> FEGaussianBlur::createImageFilter() { | 90 sk_sp<SkImageFilter> FEGaussianBlur::createImageFilter() { |
89 sk_sp<SkImageFilter> input( | 91 sk_sp<SkImageFilter> input( |
90 SkiaImageFilterBuilder::build(inputEffect(0), operatingColorSpace())); | 92 SkiaImageFilterBuilder::build(inputEffect(0), operatingColorSpace())); |
91 float stdX = getFilter()->applyHorizontalScale(m_stdX); | 93 float stdX = getFilter()->applyHorizontalScale(m_stdX); |
92 float stdY = getFilter()->applyVerticalScale(m_stdY); | 94 float stdY = getFilter()->applyVerticalScale(m_stdY); |
93 SkImageFilter::CropRect rect = getCropRect(); | 95 SkImageFilter::CropRect rect = getCropRect(); |
94 return SkBlurImageFilter::Make(SkFloatToScalar(stdX), SkFloatToScalar(stdY), | 96 return SkBlurImageFilter::Make(SkFloatToScalar(stdX), SkFloatToScalar(stdY), |
95 std::move(input), &rect); | 97 std::move(input), &rect); |
96 } | 98 } |
97 | 99 |
98 TextStream& FEGaussianBlur::externalRepresentation(TextStream& ts, | 100 TextStream& FEGaussianBlur::externalRepresentation(TextStream& ts, |
99 int indent) const { | 101 int indent) const { |
100 writeIndent(ts, indent); | 102 writeIndent(ts, indent); |
101 ts << "[feGaussianBlur"; | 103 ts << "[feGaussianBlur"; |
102 FilterEffect::externalRepresentation(ts); | 104 FilterEffect::externalRepresentation(ts); |
103 ts << " stdDeviation=\"" << m_stdX << ", " << m_stdY << "\"]\n"; | 105 ts << " stdDeviation=\"" << m_stdX << ", " << m_stdY << "\"]\n"; |
104 inputEffect(0)->externalRepresentation(ts, indent + 1); | 106 inputEffect(0)->externalRepresentation(ts, indent + 1); |
105 return ts; | 107 return ts; |
106 } | 108 } |
107 | 109 |
108 } // namespace blink | 110 } // namespace blink |
OLD | NEW |