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

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

Issue 1344203002: Fix vs2015 build (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 105 }
106 106
107 // Evaluate an AA circle function centered at the origin with 'radius' at (x,y) 107 // Evaluate an AA circle function centered at the origin with 'radius' at (x,y)
108 static inline float disk(float x, float y, float radius) { 108 static inline float disk(float x, float y, float radius) {
109 float distSq = x*x + y*y; 109 float distSq = x*x + y*y;
110 if (distSq <= (radius-0.5f)*(radius-0.5f)) { 110 if (distSq <= (radius-0.5f)*(radius-0.5f)) {
111 return 1.0f; 111 return 1.0f;
112 } else if (distSq >= (radius+0.5f)*(radius+0.5f)) { 112 } else if (distSq >= (radius+0.5f)*(radius+0.5f)) {
113 return 0.0f; 113 return 0.0f;
114 } else { 114 } else {
115 float ramp = radius + 0.5f - sqrt(distSq); 115 float ramp = radius + 0.5f - sqrtf(distSq);
116 SkASSERT(ramp >= 0.0f && ramp <= 1.0f); 116 SkASSERT(ramp >= 0.0f && ramp <= 1.0f);
117 return ramp; 117 return ramp;
118 } 118 }
119 } 119 }
120 120
121 // Create the top half of an even-sized Gaussian kernel 121 // Create the top half of an even-sized Gaussian kernel
122 static void make_half_kernel(float* kernel, int kernelWH, float sigma) { 122 static void make_half_kernel(float* kernel, int kernelWH, float sigma) {
123 SkASSERT(!(kernelWH & 1)); 123 SkASSERT(!(kernelWH & 1));
124 124
125 const float kernelOff = (kernelWH-1)/2.0f; 125 const float kernelOff = (kernelWH-1)/2.0f;
126 126
127 float b = 1.0f / (2.0f * sigma * sigma); 127 float b = 1.0f / (2.0f * sigma * sigma);
128 // omit the scale term since we're just going to renormalize 128 // omit the scale term since we're just going to renormalize
129 129
130 float tot = 0.0f; 130 float tot = 0.0f;
131 for (int y = 0; y < kernelWH/2; ++y) { 131 for (int y = 0; y < kernelWH/2; ++y) {
132 for (int x = 0; x < kernelWH/2; ++x) { 132 for (int x = 0; x < kernelWH/2; ++x) {
133 // TODO: use a cheap approximation of the 2D Guassian? 133 // TODO: use a cheap approximation of the 2D Guassian?
134 float x2 = (x-kernelOff) * (x-kernelOff); 134 float x2 = (x-kernelOff) * (x-kernelOff);
135 float y2 = (y-kernelOff) * (y-kernelOff); 135 float y2 = (y-kernelOff) * (y-kernelOff);
136 // The kernel is symmetric so only compute it once for both sides 136 // The kernel is symmetric so only compute it once for both sides
137 kernel[y*kernelWH+(kernelWH-x-1)] = kernel[y*kernelWH+x] = exp(-(x2 + y2) * b); 137 kernel[y*kernelWH+(kernelWH-x-1)] = kernel[y*kernelWH+x] = expf(-(x2 + y2) * b);
138 tot += 2.0f * kernel[y*kernelWH+x]; 138 tot += 2.0f * kernel[y*kernelWH+x];
139 } 139 }
140 } 140 }
141 // Still normalize the half kernel to 1.0 (rather than 0.5) so we don't 141 // Still normalize the half kernel to 1.0 (rather than 0.5) so we don't
142 // have to scale by 2.0 after convolution. 142 // have to scale by 2.0 after convolution.
143 for (int y = 0; y < kernelWH/2; ++y) { 143 for (int y = 0; y < kernelWH/2; ++y) {
144 for (int x = 0; x < kernelWH; ++x) { 144 for (int x = 0; x < kernelWH; ++x) {
145 kernel[y*kernelWH+x] /= tot; 145 kernel[y*kernelWH+x] /= tot;
146 } 146 }
147 } 147 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrCircleBlurFragmentProcessor); 250 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrCircleBlurFragmentProcessor);
251 251
252 const GrFragmentProcessor* GrCircleBlurFragmentProcessor::TestCreate(GrProcessor TestData* d) { 252 const GrFragmentProcessor* GrCircleBlurFragmentProcessor::TestCreate(GrProcessor TestData* d) {
253 SkScalar wh = d->fRandom->nextRangeScalar(100.f, 1000.f); 253 SkScalar wh = d->fRandom->nextRangeScalar(100.f, 1000.f);
254 SkScalar sigma = d->fRandom->nextRangeF(1.f,10.f); 254 SkScalar sigma = d->fRandom->nextRangeF(1.f,10.f);
255 SkRect circle = SkRect::MakeWH(wh, wh); 255 SkRect circle = SkRect::MakeWH(wh, wh);
256 return GrCircleBlurFragmentProcessor::Create(d->fContext->textureProvider(), circle, sigma); 256 return GrCircleBlurFragmentProcessor::Create(d->fContext->textureProvider(), circle, sigma);
257 } 257 }
258 258
259 #endif 259 #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