| 382 | |
| 383 | template <int N> |
| 384 | void MSDFErrorCorrection::findErrors(const BitmapConstSection<float, N> &sdf) { |
| 385 | stencil.reorient(sdf.yOrientation); |
| 386 | // Compute the expected deltas between values of horizontally, vertically, and diagonally adjacent texels. |
| 387 | double hSpan = minDeviationRatio*transformation.unprojectVector(Vector2(transformation.distanceMapping(DistanceMapping::Delta(1)), 0)).length(); |
| 388 | double vSpan = minDeviationRatio*transformation.unprojectVector(Vector2(0, transformation.distanceMapping(DistanceMapping::Delta(1)))).length(); |
| 389 | double dSpan = minDeviationRatio*transformation.unprojectVector(Vector2(transformation.distanceMapping(DistanceMapping::Delta(1)))).length(); |
| 390 | // Inspect all texels. |
| 391 | for (int y = 0; y < sdf.height; ++y) { |
| 392 | for (int x = 0; x < sdf.width; ++x) { |
| 393 | const float *c = sdf(x, y); |
| 394 | float cm = median(c[0], c[1], c[2]); |
| 395 | bool protectedFlag = (*stencil(x, y)&PROTECTED) != 0; |
| 396 | const float *l = NULL, *b = NULL, *r = NULL, *t = NULL; |
| 397 | // Mark current texel c with the error flag if an artifact occurs when it's interpolated with any of its 8 neighbors. |
| 398 | *stencil(x, y) |= (byte) (ERROR*( |
| 399 | (x > 0 && ((l = sdf(x-1, y)), hasLinearArtifact(BaseArtifactClassifier(hSpan, protectedFlag), cm, c, l))) || |
| 400 | (y > 0 && ((b = sdf(x, y-1)), hasLinearArtifact(BaseArtifactClassifier(vSpan, protectedFlag), cm, c, b))) || |
| 401 | (x < sdf.width-1 && ((r = sdf(x+1, y)), hasLinearArtifact(BaseArtifactClassifier(hSpan, protectedFlag), cm, c, r))) || |
| 402 | (y < sdf.height-1 && ((t = sdf(x, y+1)), hasLinearArtifact(BaseArtifactClassifier(vSpan, protectedFlag), cm, c, t))) || |
| 403 | (x > 0 && y > 0 && hasDiagonalArtifact(BaseArtifactClassifier(dSpan, protectedFlag), cm, c, l, b, sdf(x-1, y-1))) || |
| 404 | (x < sdf.width-1 && y > 0 && hasDiagonalArtifact(BaseArtifactClassifier(dSpan, protectedFlag), cm, c, r, b, sdf(x+1, y-1))) || |
| 405 | (x > 0 && y < sdf.height-1 && hasDiagonalArtifact(BaseArtifactClassifier(dSpan, protectedFlag), cm, c, l, t, sdf(x-1, y+1))) || |
| 406 | (x < sdf.width-1 && y < sdf.height-1 && hasDiagonalArtifact(BaseArtifactClassifier(dSpan, protectedFlag), cm, c, r, t, sdf(x+1, y+1))) |
| 407 | )); |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | template <template <typename> class ContourCombiner, int N> |
| 413 | void MSDFErrorCorrection::findErrors(BitmapConstSection<float, N> sdf, const Shape &shape) { |
nothing calls this directly
no test coverage detected