Flutter Engine
The Flutter Engine
Macros | Functions
SkDistanceFieldGen.h File Reference
#include "include/core/SkTypes.h"
#include <cstddef>

Go to the source code of this file.

Macros

#define SK_DistanceFieldMagnitude   4
 
#define SK_DistanceFieldPad   4
 
#define SK_DistanceFieldInset   2
 
#define SK_DistanceFieldMultiplier   "7.96875"
 
#define SK_DistanceFieldThreshold   "0.50196078431"
 

Functions

bool SkGenerateDistanceFieldFromA8Image (unsigned char *distanceField, const unsigned char *image, int w, int h, size_t rowBytes)
 
bool SkGenerateDistanceFieldFromLCD16Mask (unsigned char *distanceField, const unsigned char *image, int w, int h, size_t rowBytes)
 
bool SkGenerateDistanceFieldFromBWImage (unsigned char *distanceField, const unsigned char *image, int w, int h, size_t rowBytes)
 
size_t SkComputeDistanceFieldSize (int w, int h)
 

Macro Definition Documentation

◆ SK_DistanceFieldInset

#define SK_DistanceFieldInset   2

Definition at line 23 of file SkDistanceFieldGen.h.

◆ SK_DistanceFieldMagnitude

#define SK_DistanceFieldMagnitude   4

Definition at line 18 of file SkDistanceFieldGen.h.

◆ SK_DistanceFieldMultiplier

#define SK_DistanceFieldMultiplier   "7.96875"

Definition at line 29 of file SkDistanceFieldGen.h.

◆ SK_DistanceFieldPad

#define SK_DistanceFieldPad   4

Definition at line 21 of file SkDistanceFieldGen.h.

◆ SK_DistanceFieldThreshold

#define SK_DistanceFieldThreshold   "0.50196078431"

Definition at line 30 of file SkDistanceFieldGen.h.

Function Documentation

◆ SkComputeDistanceFieldSize()

size_t SkComputeDistanceFieldSize ( int  w,
int  h 
)
inline

Given width and height of original image, return size (in bytes) of distance field

Parameters
wWidth of the original image.
hHeight of the original image.

Definition at line 75 of file SkDistanceFieldGen.h.

75 {
76 return (w + 2*SK_DistanceFieldPad) * (h + 2*SK_DistanceFieldPad) * sizeof(unsigned char);
77}
#define SK_DistanceFieldPad
SkScalar w
SkScalar h

◆ SkGenerateDistanceFieldFromA8Image()

bool SkGenerateDistanceFieldFromA8Image ( unsigned char *  distanceField,
const unsigned char *  image,
int  w,
int  h,
size_t  rowBytes 
)

Given 8-bit mask data, generate the associated distance field

Parameters
distanceFieldThe distance field to be generated. Should already be allocated by the client with the padding above.
image8-bit mask we're using to generate the distance field.
wWidth of the original image.
hHeight of the original image.
rowBytesSize of each row in the image, in bytes

Definition at line 479 of file SkDistanceFieldGen.cpp.

481 {
482 SkASSERT(distanceField);
484
485 // create temp data
486 SkAutoSMalloc<1024> copyStorage((width+2)*(height+2)*sizeof(char));
487 unsigned char* copyPtr = (unsigned char*) copyStorage.get();
488
489 // we copy our source image into a padded copy to ensure we catch edge transitions
490 // around the outside
491 const unsigned char* currSrcScanLine = image;
492 sk_bzero(copyPtr, (width+2)*sizeof(char));
493 unsigned char* currDestPtr = copyPtr + width + 2;
494 for (int i = 0; i < height; ++i) {
495 *currDestPtr++ = 0;
496 memcpy(currDestPtr, currSrcScanLine, width);
497 currSrcScanLine += rowBytes;
498 currDestPtr += width;
499 *currDestPtr++ = 0;
500 }
501 sk_bzero(currDestPtr, (width+2)*sizeof(char));
502
503 return generate_distance_field_from_image(distanceField, copyPtr, width, height);
504}
sk_bzero(glyphs, sizeof(glyphs))
#define SkASSERT(cond)
Definition: SkAssert.h:116
static bool generate_distance_field_from_image(unsigned char *distanceField, const unsigned char *copyPtr, int width, int height)
sk_sp< const SkImage > image
Definition: SkRecords.h:269
int32_t height
int32_t width

◆ SkGenerateDistanceFieldFromBWImage()

bool SkGenerateDistanceFieldFromBWImage ( unsigned char *  distanceField,
const unsigned char *  image,
int  w,
int  h,
size_t  rowBytes 
)

Given 1-bit mask data, generate the associated distance field

Parameters
distanceFieldThe distance field to be generated. Should already be allocated by the client with the padding above.
image1-bit mask we're using to generate the distance field.
wWidth of the original image.
hHeight of the original image.
rowBytesSize of each row in the image, in bytes

Definition at line 537 of file SkDistanceFieldGen.cpp.

539 {
540 SkASSERT(distanceField);
542
543 // create temp data
544 SkAutoSMalloc<1024> copyStorage((width+2)*(height+2)*sizeof(char));
545 unsigned char* copyPtr = (unsigned char*) copyStorage.get();
546
547 // we copy our source image into a padded copy to ensure we catch edge transitions
548 // around the outside
549 const unsigned char* currSrcScanLine = image;
550 sk_bzero(copyPtr, (width+2)*sizeof(char));
551 unsigned char* currDestPtr = copyPtr + width + 2;
552 for (int i = 0; i < height; ++i) {
553 *currDestPtr++ = 0;
554
555 int rowWritesLeft = width;
556 const unsigned char *maskPtr = currSrcScanLine;
557 while (rowWritesLeft > 0) {
558 unsigned mask = *maskPtr++;
559 for (int j = 7; j >= 0 && rowWritesLeft; --j, --rowWritesLeft) {
560 *currDestPtr++ = (mask & (1 << j)) ? 0xff : 0;
561 }
562 }
563 currSrcScanLine += rowBytes;
564
565 *currDestPtr++ = 0;
566 }
567 sk_bzero(currDestPtr, (width+2)*sizeof(char));
568
569 return generate_distance_field_from_image(distanceField, copyPtr, width, height);
570}

◆ SkGenerateDistanceFieldFromLCD16Mask()

bool SkGenerateDistanceFieldFromLCD16Mask ( unsigned char *  distanceField,
const unsigned char *  image,
int  w,
int  h,
size_t  rowBytes 
)

Given LCD16 mask data (not a 16-bit image), generate the associated distance field

Parameters
distanceFieldThe distance field to be generated. Should already be allocated by the client with the padding above.
image16-bit LCD data we're using to generate the distance field.
wWidth of the original image.
hHeight of the original image.
rowBytesSize of each row in the image, in bytes

Definition at line 507 of file SkDistanceFieldGen.cpp.

509 {
510 SkASSERT(distanceField);
512
513 // create temp data
514 SkAutoSMalloc<1024> copyStorage((w+2)*(h+2)*sizeof(char));
515 unsigned char* copyPtr = (unsigned char*) copyStorage.get();
516
517 // we copy our source image into a padded copy to ensure we catch edge transitions
518 // around the outside
519 const uint16_t* start = reinterpret_cast<const uint16_t*>(image);
520 auto currSrcScanline = SkMask::AlphaIter<SkMask::kLCD16_Format>(start);
521 auto endSrcScanline = SkMask::AlphaIter<SkMask::kLCD16_Format>(start + w);
522 sk_bzero(copyPtr, (w+2)*sizeof(char));
523 unsigned char* currDestPtr = copyPtr + w + 2;
524 for (int i = 0; i < h; ++i, currSrcScanline >>= rowBytes, endSrcScanline >>= rowBytes) {
525 *currDestPtr++ = 0;
526 for (auto src = currSrcScanline; src < endSrcScanline; ++src) {
527 *currDestPtr++ = *src;
528 }
529 *currDestPtr++ = 0;
530 }
531 sk_bzero(currDestPtr, (w+2)*sizeof(char));
532
533 return generate_distance_field_from_image(distanceField, copyPtr, w, h);
534}