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

Side by Side Diff: src/core/SkDistanceFieldGen.cpp

Issue 1603953005: Revert of 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, 11 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)
113 float dx = direction.fX; 110 float dx = direction.fX;
114 float dy = direction.fY; 111 float dy = direction.fY;
115 float distance; 112 float distance;
116 if (SkScalarNearlyZero(dx) || SkScalarNearlyZero(dy)) { 113 if (SkScalarNearlyZero(dx) || SkScalarNearlyZero(dy)) {
117 distance = 0.5f - alpha; 114 distance = 0.5f - alpha;
118 } else { 115 } else {
119 // this is easier if we treat the direction as being in the first octant 116 // this is easier if we treat the direction as being in the first octant
120 // (other octants are symmetrical) 117 // (other octants are symmetrical)
121 dx = SkScalarAbs(dx); 118 dx = SkScalarAbs(dx);
122 dy = SkScalarAbs(dy); 119 dy = SkScalarAbs(dy);
(...skipping 16 matching lines...) Expand all
139 } else if (alpha*dx < (dx - a1num)) { 136 } else if (alpha*dx < (dx - a1num)) {
140 distance = (0.5f - alpha)*dx; 137 distance = (0.5f - alpha)*dx;
141 // if 1 - a1 < alpha <= 1 138 // if 1 - a1 < alpha <= 1
142 } else { 139 } else {
143 // TODO: find a way to do this without square roots? 140 // TODO: find a way to do this without square roots?
144 distance = -0.5f*(dx + dy) + SkScalarSqrt(2.0f*dx*dy*(1.0f - alpha)) ; 141 distance = -0.5f*(dx + dy) + SkScalarSqrt(2.0f*dx*dy*(1.0f - alpha)) ;
145 } 142 }
146 } 143 }
147 144
148 return distance; 145 return distance;
149 #endif
150 } 146 }
151 147
152 static void init_distances(DFData* data, unsigned char* edges, int width, int he ight) { 148 static void init_distances(DFData* data, unsigned char* edges, int width, int he ight) {
153 // skip one pixel border 149 // skip one pixel border
154 DFData* currData = data; 150 DFData* currData = data;
155 DFData* prevData = data - width; 151 DFData* prevData = data - width;
156 DFData* nextData = data + width; 152 DFData* nextData = data + width;
157 153
158 for (int j = 0; j < height; ++j) { 154 for (int j = 0; j < height; ++j) {
159 for (int i = 0; i < width; ++i) { 155 for (int i = 0; i < width; ++i) {
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 *currDestPtr++ = (mask & (1 << i)) ? 0xff : 0; 512 *currDestPtr++ = (mask & (1 << i)) ? 0xff : 0;
517 } 513 }
518 } 514 }
519 currSrcScanLine += rowBytes; 515 currSrcScanLine += rowBytes;
520 *currDestPtr++ = 0; 516 *currDestPtr++ = 0;
521 } 517 }
522 sk_bzero(currDestPtr, (width+2)*sizeof(char)); 518 sk_bzero(currDestPtr, (width+2)*sizeof(char));
523 519
524 return generate_distance_field_from_image(distanceField, copyPtr, width, hei ght); 520 return generate_distance_field_from_image(distanceField, copyPtr, width, hei ght);
525 } 521 }
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