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

Side by Side Diff: src/opts/SkBlurImageFilter_opts.h

Issue 1426583004: SkBlurImageFilter_opt.h: break conditions into separate loops. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update to ToT Created 5 years, 1 month 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 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkBlurImageFilter_opts_DEFINED 8 #ifndef SkBlurImageFilter_opts_DEFINED
9 #define SkBlurImageFilter_opts_DEFINED 9 #define SkBlurImageFilter_opts_DEFINED
10 10
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 sumB -= SkGetPackedB32(c) 167 sumB -= SkGetPackedB32(c)
168 #define STORE_SUMS \ 168 #define STORE_SUMS \
169 *dptr = SkPackARGB32((sumA * scale + half) >> 24, \ 169 *dptr = SkPackARGB32((sumA * scale + half) >> 24, \
170 (sumR * scale + half) >> 24, \ 170 (sumR * scale + half) >> 24, \
171 (sumG * scale + half) >> 24, \ 171 (sumG * scale + half) >> 24, \
172 (sumB * scale + half) >> 24); 172 (sumB * scale + half) >> 24);
173 #define DOUBLE_ROW_OPTIMIZATION 173 #define DOUBLE_ROW_OPTIMIZATION
174 174
175 #endif 175 #endif
176 176
177 #define PREFETCH_RPTR \
178 if (srcDirection == BlurDirection::kY) { \
179 SK_PREFETCH(rptr); \
180 }
181
177 template<BlurDirection srcDirection, BlurDirection dstDirection> 182 template<BlurDirection srcDirection, BlurDirection dstDirection>
178 static void box_blur(const SkPMColor* src, int srcStride, SkPMColor* dst, int ke rnelSize, 183 static void box_blur(const SkPMColor* src, int srcStride, SkPMColor* dst, int ke rnelSize,
179 int leftOffset, int rightOffset, int width, int height) { 184 int leftOffset, int rightOffset, int width, int height) {
180 int rightBorder = SkMin32(rightOffset + 1, width); 185 int incrementStart = SkMax32(-rightOffset - 1, -width);
186 int incrementEnd = SkMax32(width - rightOffset - 1, 0);
187 int decrementStart = SkMin32(leftOffset, width);
181 int srcStrideX = srcDirection == BlurDirection::kX ? 1 : srcStride; 188 int srcStrideX = srcDirection == BlurDirection::kX ? 1 : srcStride;
182 int dstStrideX = dstDirection == BlurDirection::kX ? 1 : height; 189 int dstStrideX = dstDirection == BlurDirection::kX ? 1 : height;
183 int srcStrideY = srcDirection == BlurDirection::kX ? srcStride : 1; 190 int srcStrideY = srcDirection == BlurDirection::kX ? srcStride : 1;
184 int dstStrideY = dstDirection == BlurDirection::kX ? width : 1; 191 int dstStrideY = dstDirection == BlurDirection::kX ? width : 1;
185 INIT_SCALE 192 INIT_SCALE
186 INIT_HALF 193 INIT_HALF
187 194
188 DOUBLE_ROW_OPTIMIZATION 195 DOUBLE_ROW_OPTIMIZATION
189 196
190 for (int y = 0; y < height; ++y) { 197 for (int y = 0; y < height; ++y) {
191 INIT_SUMS 198 INIT_SUMS
192 const SkPMColor* p = src; 199 const SkPMColor* lptr = src;
193 for (int i = 0; i < rightBorder; ++i) { 200 const SkPMColor* rptr = src;
194 INCREMENT_SUMS(*p); 201 SkColor* dptr = dst;
195 p += srcStrideX; 202 int x;
203 for (x = incrementStart; x < 0; ++x) {
204 INCREMENT_SUMS(*rptr);
205 rptr += srcStrideX;
206 PREFETCH_RPTR
196 } 207 }
197 208 for (; x < decrementStart && x < incrementEnd; ++x) {
198 const SkPMColor* sptr = src;
199 SkColor* dptr = dst;
200 for (int x = 0; x < width; ++x) {
201 STORE_SUMS 209 STORE_SUMS
202 if (x >= leftOffset) {
203 SkColor l = *(sptr - leftOffset * srcStrideX);
204 DECREMENT_SUMS(l);
205 }
206 if (x + rightOffset + 1 < width) {
207 SkColor r = *(sptr + (rightOffset + 1) * srcStrideX);
208 INCREMENT_SUMS(r);
209 }
210 sptr += srcStrideX;
211 if (srcDirection == BlurDirection::kY) {
212 SK_PREFETCH(sptr + (rightOffset + 1) * srcStrideX);
213 }
214 dptr += dstStrideX; 210 dptr += dstStrideX;
211 INCREMENT_SUMS(*rptr);
212 rptr += srcStrideX;
213 PREFETCH_RPTR
214 }
215 for (x = decrementStart; x < incrementEnd; ++x) {
216 STORE_SUMS
217 dptr += dstStrideX;
218 INCREMENT_SUMS(*rptr);
219 rptr += srcStrideX;
220 PREFETCH_RPTR
221 DECREMENT_SUMS(*lptr);
222 lptr += srcStrideX;
223 }
224 for (x = incrementEnd; x < decrementStart; ++x) {
225 STORE_SUMS
226 dptr += dstStrideX;
227 }
228 for (; x < width; ++x) {
229 STORE_SUMS
230 dptr += dstStrideX;
231 DECREMENT_SUMS(*lptr);
232 lptr += srcStrideX;
215 } 233 }
216 src += srcStrideY; 234 src += srcStrideY;
217 dst += dstStrideY; 235 dst += dstStrideY;
218 } 236 }
219 } 237 }
220 238
221 static auto box_blur_xx = &box_blur<BlurDirection::kX, BlurDirection::kX>, 239 static auto box_blur_xx = &box_blur<BlurDirection::kX, BlurDirection::kX>,
222 box_blur_xy = &box_blur<BlurDirection::kX, BlurDirection::kY>, 240 box_blur_xy = &box_blur<BlurDirection::kX, BlurDirection::kY>,
223 box_blur_yx = &box_blur<BlurDirection::kY, BlurDirection::kX>; 241 box_blur_yx = &box_blur<BlurDirection::kY, BlurDirection::kX>;
224 242
225 } // namespace SK_OPTS_NS 243 } // namespace SK_OPTS_NS
226 244
227 #endif 245 #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