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

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

Issue 1643143002: Generate Signed Distance Field directly from vector path (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Remove get direction and add text SDF support Created 4 years, 10 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 | « src/core/SkDistanceFieldGen.h ('k') | src/gpu/GrDistanceFieldGenFromVector.h » ('j') | 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 curr->fDistSq = distSq; 310 curr->fDistSq = distSq;
311 curr->fDistVector = distVec; 311 curr->fDistVector = distVec;
312 } 312 }
313 } 313 }
314 314
315 // enable this to output edge data rather than the distance field 315 // enable this to output edge data rather than the distance field
316 #define DUMP_EDGE 0 316 #define DUMP_EDGE 0
317 317
318 #if !DUMP_EDGE 318 #if !DUMP_EDGE
319 static unsigned char pack_distance_field_val(float dist, float distanceMagnitude ) { 319 static unsigned char pack_distance_field_val(float dist, float distanceMagnitude ) {
320 if (dist <= -distanceMagnitude) { 320 // The distance field is constructed as unsigned char values, so that the ze ro value is at 128,
jvanverth1 2016/02/19 23:36:46 I was looking at this to understand it a little be
Joel.Liang 2016/02/22 07:34:00 Yes, to do that we could add SkScalarRoundToInt to
321 return 255; 321 // Beside 128, we have 128 values in range [0, 128), but only 127 values in range (128, 255].
322 } else if (dist > distanceMagnitude) { 322 // So we multiply distanceMagnitude by 127/128 at the latter range to avoid overflow.
323 return 0; 323 dist = SkScalarPin(-dist, -distanceMagnitude, distanceMagnitude * 127.0f / 1 28.0f);
324 } else { 324
325 return (unsigned char)((distanceMagnitude-dist)*128.0f/distanceMagnitude ); 325 // Scale into the positive range for unsigned distance
326 } 326 dist += distanceMagnitude;
327
328 // Scale into unsigned char range
329 return (unsigned char)(dist / (2 * distanceMagnitude) * 256.0f);
327 } 330 }
328 #endif 331 #endif
329 332
330 // assumes a padded 8-bit image and distance field 333 // assumes a padded 8-bit image and distance field
331 // width and height are the original width and height of the image 334 // width and height are the original width and height of the image
332 static bool generate_distance_field_from_image(unsigned char* distanceField, 335 static bool generate_distance_field_from_image(unsigned char* distanceField,
333 const unsigned char* copyPtr, 336 const unsigned char* copyPtr,
334 int width, int height) { 337 int width, int height) {
335 SkASSERT(distanceField); 338 SkASSERT(distanceField);
336 SkASSERT(copyPtr); 339 SkASSERT(copyPtr);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 *currDestPtr++ = (mask & (1 << i)) ? 0xff : 0; 510 *currDestPtr++ = (mask & (1 << i)) ? 0xff : 0;
508 } 511 }
509 } 512 }
510 currSrcScanLine += rowBytes; 513 currSrcScanLine += rowBytes;
511 *currDestPtr++ = 0; 514 *currDestPtr++ = 0;
512 } 515 }
513 sk_bzero(currDestPtr, (width+2)*sizeof(char)); 516 sk_bzero(currDestPtr, (width+2)*sizeof(char));
514 517
515 return generate_distance_field_from_image(distanceField, copyPtr, width, hei ght); 518 return generate_distance_field_from_image(distanceField, copyPtr, width, hei ght);
516 } 519 }
OLDNEW
« no previous file with comments | « src/core/SkDistanceFieldGen.h ('k') | src/gpu/GrDistanceFieldGenFromVector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698