OLD | NEW |
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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 | 329 |
330 // assumes an 8-bit image and distance field | 330 // assumes an 8-bit image and distance field |
331 bool SkGenerateDistanceFieldFromImage(unsigned char* distanceField, | 331 bool SkGenerateDistanceFieldFromImage(unsigned char* distanceField, |
332 const unsigned char* image, | 332 const unsigned char* image, |
333 int width, int height, | 333 int width, int height, |
334 int distanceMagnitude) { | 334 int distanceMagnitude) { |
335 SkASSERT(NULL != distanceField); | 335 SkASSERT(NULL != distanceField); |
336 SkASSERT(NULL != image); | 336 SkASSERT(NULL != image); |
337 | 337 |
338 // the final distance field will have additional texels on each side to hand
le | 338 // the final distance field will have additional texels on each side to hand
le |
339 // the maximum distance + 1 for bilerp | 339 // the maximum distance |
340 // we expand our temp data by one more on each side to simplify | 340 // we expand our temp data by one more on each side to simplify |
341 // the scanning code -- will always be treated as infinitely far away | 341 // the scanning code -- will always be treated as infinitely far away |
342 int pad = distanceMagnitude+2; | 342 int pad = distanceMagnitude+1; |
343 | 343 |
344 // set params for distance field data | 344 // set params for distance field data |
345 int dataWidth = width + 2*pad; | 345 int dataWidth = width + 2*pad; |
346 int dataHeight = height + 2*pad; | 346 int dataHeight = height + 2*pad; |
347 | 347 |
348 // create temp data | 348 // create temp data |
349 size_t dataSize = dataWidth*dataHeight*sizeof(DFData); | 349 size_t dataSize = dataWidth*dataHeight*sizeof(DFData); |
350 SkAutoSMalloc<1024> dfStorage(dataSize); | 350 SkAutoSMalloc<1024> dfStorage(dataSize); |
351 DFData* dataPtr = (DFData*) dfStorage.get(); | 351 DFData* dataPtr = (DFData*) dfStorage.get(); |
352 sk_bzero(dataPtr, dataSize); | 352 sk_bzero(dataPtr, dataSize); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 #endif | 469 #endif |
470 ++currData; | 470 ++currData; |
471 ++currEdge; | 471 ++currEdge; |
472 } | 472 } |
473 currData += 2; | 473 currData += 2; |
474 currEdge += 2; | 474 currEdge += 2; |
475 } | 475 } |
476 | 476 |
477 return true; | 477 return true; |
478 } | 478 } |
OLD | NEW |