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/core/SkDistanceFieldGen.cpp

Issue 1545893003: sdf: use linear edge distance approximation for all gradient directions (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 12 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 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 #include "SkDistanceFieldGen.h" 8 #include "SkDistanceFieldGen.h"
9 #include "SkPoint.h" 9 #include "SkPoint.h"
10 10
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 100 }
101 data += 2*pad; 101 data += 2*pad;
102 edges += 2*pad; 102 edges += 2*pad;
103 } 103 }
104 } 104 }
105 105
106 // from Gustavson (2011) 106 // from Gustavson (2011)
107 // computes the distance to an edge given an edge normal vector and a pixel's al pha value 107 // computes the distance to an edge given an edge normal vector and a pixel's al pha value
108 // assumes that direction has been pre-normalized 108 // assumes that direction has been pre-normalized
109 static float edge_distance(const SkPoint& direction, float alpha) { 109 static float edge_distance(const SkPoint& direction, float alpha) {
110 #if 1 // formula (1)
111 return 0.5f - alpha;
112 #else // formula (4)
110 float dx = direction.fX; 113 float dx = direction.fX;
111 float dy = direction.fY; 114 float dy = direction.fY;
112 float distance; 115 float distance;
113 if (SkScalarNearlyZero(dx) || SkScalarNearlyZero(dy)) { 116 if (SkScalarNearlyZero(dx) || SkScalarNearlyZero(dy)) {
114 distance = 0.5f - alpha; 117 distance = 0.5f - alpha;
115 } else { 118 } else {
116 // this is easier if we treat the direction as being in the first octant 119 // this is easier if we treat the direction as being in the first octant
117 // (other octants are symmetrical) 120 // (other octants are symmetrical)
118 dx = SkScalarAbs(dx); 121 dx = SkScalarAbs(dx);
119 dy = SkScalarAbs(dy); 122 dy = SkScalarAbs(dy);
(...skipping 16 matching lines...) Expand all
136 } else if (alpha*dx < (dx - a1num)) { 139 } else if (alpha*dx < (dx - a1num)) {
137 distance = (0.5f - alpha)*dx; 140 distance = (0.5f - alpha)*dx;
138 // if 1 - a1 < alpha <= 1 141 // if 1 - a1 < alpha <= 1
139 } else { 142 } else {
140 // TODO: find a way to do this without square roots? 143 // TODO: find a way to do this without square roots?
141 distance = -0.5f*(dx + dy) + SkScalarSqrt(2.0f*dx*dy*(1.0f - alpha)) ; 144 distance = -0.5f*(dx + dy) + SkScalarSqrt(2.0f*dx*dy*(1.0f - alpha)) ;
142 } 145 }
143 } 146 }
144 147
145 return distance; 148 return distance;
149 #endif
146 } 150 }
147 151
148 static void init_distances(DFData* data, unsigned char* edges, int width, int he ight) { 152 static void init_distances(DFData* data, unsigned char* edges, int width, int he ight) {
149 // skip one pixel border 153 // skip one pixel border
150 DFData* currData = data; 154 DFData* currData = data;
151 DFData* prevData = data - width; 155 DFData* prevData = data - width;
152 DFData* nextData = data + width; 156 DFData* nextData = data + width;
153 157
154 for (int j = 0; j < height; ++j) { 158 for (int j = 0; j < height; ++j) {
155 for (int i = 0; i < width; ++i) { 159 for (int i = 0; i < width; ++i) {
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 *currDestPtr++ = (mask & (1 << i)) ? 0xff : 0; 516 *currDestPtr++ = (mask & (1 << i)) ? 0xff : 0;
513 } 517 }
514 } 518 }
515 currSrcScanLine += rowBytes; 519 currSrcScanLine += rowBytes;
516 *currDestPtr++ = 0; 520 *currDestPtr++ = 0;
517 } 521 }
518 sk_bzero(currDestPtr, (width+2)*sizeof(char)); 522 sk_bzero(currDestPtr, (width+2)*sizeof(char));
519 523
520 return generate_distance_field_from_image(distanceField, copyPtr, width, hei ght); 524 return generate_distance_field_from_image(distanceField, copyPtr, width, hei ght);
521 } 525 }
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