MCPcopy Create free account
hub / github.com/MyGUI/mygui / protectEdges

Method protectEdges

MyGUIEngine/src/msdfgen/core/MSDFErrorCorrection.cpp:190–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188
189template <int N>
190void MSDFErrorCorrection::protectEdges(const BitmapConstSection<float, N> &sdf) {
191 float radius;
192 stencil.reorient(sdf.yOrientation);
193 // Horizontal texel pairs
194 radius = float(PROTECTION_RADIUS_TOLERANCE*transformation.unprojectVector(Vector2(transformation.distanceMapping(DistanceMapping::Delta(1)), 0)).length());
195 for (int y = 0; y < sdf.height; ++y) {
196 const float *left = sdf(0, y);
197 const float *right = sdf(1, y);
198 for (int x = 0; x < sdf.width-1; ++x) {
199 float lm = median(left[0], left[1], left[2]);
200 float rm = median(right[0], right[1], right[2]);
201 if (fabsf(lm-.5f)+fabsf(rm-.5f) < radius) {
202 int mask = edgeBetweenTexels(left, right);
203 protectExtremeChannels(stencil(x, y), left, lm, mask);
204 protectExtremeChannels(stencil(x+1, y), right, rm, mask);
205 }
206 left += N, right += N;
207 }
208 }
209 // Vertical texel pairs
210 radius = float(PROTECTION_RADIUS_TOLERANCE*transformation.unprojectVector(Vector2(0, transformation.distanceMapping(DistanceMapping::Delta(1)))).length());
211 for (int y = 0; y < sdf.height-1; ++y) {
212 const float *bottom = sdf(0, y);
213 const float *top = sdf(0, y+1);
214 for (int x = 0; x < sdf.width; ++x) {
215 float bm = median(bottom[0], bottom[1], bottom[2]);
216 float tm = median(top[0], top[1], top[2]);
217 if (fabsf(bm-.5f)+fabsf(tm-.5f) < radius) {
218 int mask = edgeBetweenTexels(bottom, top);
219 protectExtremeChannels(stencil(x, y), bottom, bm, mask);
220 protectExtremeChannels(stencil(x, y+1), top, tm, mask);
221 }
222 bottom += N, top += N;
223 }
224 }
225 // Diagonal texel pairs
226 radius = float(PROTECTION_RADIUS_TOLERANCE*transformation.unprojectVector(Vector2(transformation.distanceMapping(DistanceMapping::Delta(1)))).length());
227 for (int y = 0; y < sdf.height-1; ++y) {
228 const float *lb = sdf(0, y);
229 const float *rb = sdf(1, y);
230 const float *lt = sdf(0, y+1);
231 const float *rt = sdf(1, y+1);
232 for (int x = 0; x < sdf.width-1; ++x) {
233 float mlb = median(lb[0], lb[1], lb[2]);
234 float mrb = median(rb[0], rb[1], rb[2]);
235 float mlt = median(lt[0], lt[1], lt[2]);
236 float mrt = median(rt[0], rt[1], rt[2]);
237 if (fabsf(mlb-.5f)+fabsf(mrt-.5f) < radius) {
238 int mask = edgeBetweenTexels(lb, rt);
239 protectExtremeChannels(stencil(x, y), lb, mlb, mask);
240 protectExtremeChannels(stencil(x+1, y+1), rt, mrt, mask);
241 }
242 if (fabsf(mrb-.5f)+fabsf(mlt-.5f) < radius) {
243 int mask = edgeBetweenTexels(rb, lt);
244 protectExtremeChannels(stencil(x+1, y), rb, mrb, mask);
245 protectExtremeChannels(stencil(x, y+1), lt, mlt, mask);
246 }
247 lb += N, rb += N, lt += N, rt += N;

Callers

nothing calls this directly

Calls 8

Vector2Class · 0.85
DeltaClass · 0.85
edgeBetweenTexelsFunction · 0.85
protectExtremeChannelsFunction · 0.85
unprojectVectorMethod · 0.80
medianFunction · 0.70
reorientMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected