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 #ifndef SkDistanceFieldGen_DEFINED | 7 #ifndef SkDistanceFieldGen_DEFINED |
8 #define SkDistanceFieldGen_DEFINED | 8 #define SkDistanceFieldGen_DEFINED |
9 | 9 |
| 10 #include "SkTypes.h" |
| 11 |
| 12 // the max magnitude for the distance field |
| 13 // distance values are limited to the range [-SK_DistanceFieldMagnitude, SK_Dist
anceFieldMagnitude) |
| 14 #define SK_DistanceFieldMagnitude 4 |
| 15 // we need to pad around the original glyph to allow our maximum distance of |
| 16 // SK_DistanceFieldMagnitude texels away from any edge |
| 17 // we add one to this pad to allow for bilerp |
| 18 #define SK_DistanceFieldPad (SK_DistanceFieldMagnitude+1) |
| 19 |
| 20 // for the fragment shader |
| 21 // The distance field is constructed as unsigned char values, so that the zero v
alue is at 128, |
| 22 // and the range is [-4, 4 - 1/255). Hence our multiplier is 8 - 1/32 and zero t
hreshold is 128/255. |
| 23 #define SK_DistanceFieldMultiplier "7.96875" |
| 24 #define SK_DistanceFieldThreshold "0.50196078431" |
| 25 |
10 /** Given 8-bit mask data, generate the associated distance field | 26 /** Given 8-bit mask data, generate the associated distance field |
11 | 27 |
12 * @param distanceField The distance field to be generated. Should already
be allocated | 28 * @param distanceField The distance field to be generated. Should already
be allocated |
13 * by the client with the padding below. | 29 * by the client with the padding above. |
14 * @param image 8-bit mask we're using to generate the distance fie
ld. | 30 * @param image 8-bit mask we're using to generate the distance fie
ld. |
15 * @param w Width of the image. | 31 * @param w Width of the original image. |
16 * @param h Height of the image. | 32 * @param h Height of the original image. |
17 * @param distanceMagnitude Largest possible absolute value for the distance. T
he distance field | 33 * @param rowBytes Size of each row in the image, in bytes |
18 * will be padded to w + 2*distanceMagnitude, h + 2*di
stanceMagnitude. | |
19 */ | 34 */ |
20 bool SkGenerateDistanceFieldFromImage(unsigned char* distanceField, | 35 bool SkGenerateDistanceFieldFromA8Image(unsigned char* distanceField, |
21 const unsigned char* image, | 36 const unsigned char* image, |
22 int w, int h, | 37 int w, int h, int rowBytes); |
23 int distanceMagnitude); | 38 |
| 39 /** Given 1-bit mask data, generate the associated distance field |
| 40 |
| 41 * @param distanceField The distance field to be generated. Should already
be allocated |
| 42 * by the client with the padding above. |
| 43 * @param image 1-bit mask we're using to generate the distance fie
ld. |
| 44 * @param w Width of the original image. |
| 45 * @param h Height of the original image. |
| 46 * @param rowBytes Size of each row in the image, in bytes |
| 47 */ |
| 48 bool SkGenerateDistanceFieldFromBWImage(unsigned char* distanceField, |
| 49 const unsigned char* image, |
| 50 int w, int h, int rowBytes); |
| 51 |
| 52 /** Given width and height of original image, return size (in bytes) of distance
field |
| 53 * @param w Width of the original image. |
| 54 * @param h Height of the original image. |
| 55 */ |
| 56 inline size_t SkComputeDistanceFieldSize(int w, int h) { |
| 57 return (w + 2*SK_DistanceFieldPad) * (h + 2*SK_DistanceFieldPad) * sizeof(un
signed char); |
| 58 } |
24 | 59 |
25 #endif | 60 #endif |
OLD | NEW |