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

Side by Side Diff: src/effects/GrCircleBlurFragmentProcessor.cpp

Issue 1723383002: Ensure the Gaussian tail of circle blurs goes to zero. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrCircleBlurFragmentProcessor.h" 9 #include "GrCircleBlurFragmentProcessor.h"
10 10
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 179 }
180 180
181 static inline void compute_profile_offset_and_size(float halfWH, float sigma, 181 static inline void compute_profile_offset_and_size(float halfWH, float sigma,
182 float* offset, int* size) { 182 float* offset, int* size) {
183 183
184 if (3*sigma <= halfWH) { 184 if (3*sigma <= halfWH) {
185 // The circle is bigger than the Gaussian. In this case we know the inte rior of the 185 // The circle is bigger than the Gaussian. In this case we know the inte rior of the
186 // blurred circle is solid. 186 // blurred circle is solid.
187 *offset = halfWH - 3 * sigma; // This location maps to 0.5f in the weigh ts texture. 187 *offset = halfWH - 3 * sigma; // This location maps to 0.5f in the weigh ts texture.
188 // It should always be 255. 188 // It should always be 255.
189 *size = SkScalarCeilToInt(6*sigma); 189 *size = SkScalarCeilToInt(6*sigma) + 1;
190 } else { 190 } else {
191 // The Gaussian is bigger than the circle. 191 // The Gaussian is bigger than the circle.
192 *offset = 0.0f; 192 *offset = 0.0f;
193 *size = SkScalarCeilToInt(halfWH + 3*sigma); 193 *size = SkScalarCeilToInt(halfWH + 3*sigma);
194 } 194 }
195 } 195 }
196 196
197 static uint8_t* create_profile(float halfWH, float sigma) { 197 static uint8_t* create_profile(float halfWH, float sigma) {
198 198
199 int kernelWH = SkScalarCeilToInt(6.0f*sigma); 199 int kernelWH = SkScalarCeilToInt(6.0f*sigma);
200 kernelWH = (kernelWH + 1) & ~1; // make it the next even number up 200 kernelWH = (kernelWH + 1) & ~1; // make it the next even number up
201 201
202 SkAutoTArray<float> halfKernel(kernelWH*kernelWH/2); 202 SkAutoTArray<float> halfKernel(kernelWH*kernelWH/2);
203 203
204 make_half_kernel(halfKernel.get(), kernelWH, sigma); 204 make_half_kernel(halfKernel.get(), kernelWH, sigma);
205 205
206 float offset; 206 float offset;
207 int numSteps; 207 int numSteps;
208 208
209 compute_profile_offset_and_size(halfWH, sigma, &offset, &numSteps); 209 compute_profile_offset_and_size(halfWH, sigma, &offset, &numSteps);
210 210
211 uint8_t* weights = new uint8_t[numSteps]; 211 uint8_t* weights = new uint8_t[numSteps];
212 for (int i = 0; i < numSteps; ++i) { 212 for (int i = 0; i < numSteps; ++i) {
213 weights[i] = eval_at(offset+i, halfWH, halfKernel.get(), kernelWH); 213 weights[i] = eval_at(offset+i, halfWH, halfKernel.get(), kernelWH);
214 } 214 }
215 215
robertphillips 2016/02/24 12:52:56 Are we guaranteed that weights[numSteps-1] will al
dogben 2016/02/24 15:31:22 sgtm
216 SkASSERT(weights[numSteps-1] == 0);
216 return weights; 217 return weights;
217 } 218 }
218 219
219 GrTexture* GrCircleBlurFragmentProcessor::CreateCircleBlurProfileTexture( 220 GrTexture* GrCircleBlurFragmentProcessor::CreateCircleBlurProfileTexture(
220 GrTextureProvide r* textureProvider, 221 GrTextureProvide r* textureProvider,
221 const SkRect& ci rcle, 222 const SkRect& ci rcle,
222 float sigma, 223 float sigma,
223 float* offset) { 224 float* offset) {
224 float halfWH = circle.width() / 2.0f; 225 float halfWH = circle.width() / 2.0f;
225 226
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrCircleBlurFragmentProcessor); 258 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrCircleBlurFragmentProcessor);
258 259
259 const GrFragmentProcessor* GrCircleBlurFragmentProcessor::TestCreate(GrProcessor TestData* d) { 260 const GrFragmentProcessor* GrCircleBlurFragmentProcessor::TestCreate(GrProcessor TestData* d) {
260 SkScalar wh = d->fRandom->nextRangeScalar(100.f, 1000.f); 261 SkScalar wh = d->fRandom->nextRangeScalar(100.f, 1000.f);
261 SkScalar sigma = d->fRandom->nextRangeF(1.f,10.f); 262 SkScalar sigma = d->fRandom->nextRangeF(1.f,10.f);
262 SkRect circle = SkRect::MakeWH(wh, wh); 263 SkRect circle = SkRect::MakeWH(wh, wh);
263 return GrCircleBlurFragmentProcessor::Create(d->fContext->textureProvider(), circle, sigma); 264 return GrCircleBlurFragmentProcessor::Create(d->fContext->textureProvider(), circle, sigma);
264 } 265 }
265 266
266 #endif 267 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698