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" | 10 #include "SkTypes.h" |
11 | 11 |
12 // the max magnitude for the distance field | 12 // the max magnitude for the distance field |
13 // distance values are limited to the range [-SK_DistanceFieldMagnitude, SK_Dist
anceFieldMagnitude) | 13 // distance values are limited to the range [-SK_DistanceFieldMagnitude, SK_Dist
anceFieldMagnitude) |
14 #define SK_DistanceFieldMagnitude 4 | 14 #define SK_DistanceFieldMagnitude 4 |
15 // we need to pad around the original glyph to allow our maximum distance of | 15 // we need to pad around the original glyph to allow our maximum distance of |
16 // SK_DistanceFieldMagnitude texels away from any edge | 16 // SK_DistanceFieldMagnitude texels away from any edge |
17 // we add one to this pad to allow for bilerp | 17 #define SK_DistanceFieldPad 4 |
18 #define SK_DistanceFieldPad (SK_DistanceFieldMagnitude+1) | 18 // the rect we render with is inset from the distance field glyph size to allow
for bilerp |
| 19 #define SK_DistanceFieldInset 2 |
19 | 20 |
20 // for the fragment shader | 21 // for the fragment shader |
21 // The distance field is constructed as unsigned char values, so that the zero v
alue is at 128, | 22 // 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 // 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_DistanceFieldMultiplier "7.96875" |
24 #define SK_DistanceFieldThreshold "0.50196078431" | 25 #define SK_DistanceFieldThreshold "0.50196078431" |
25 | 26 |
26 /** Given 8-bit mask data, generate the associated distance field | 27 /** Given 8-bit mask data, generate the associated distance field |
27 | 28 |
28 * @param distanceField The distance field to be generated. Should already
be allocated | 29 * @param distanceField The distance field to be generated. Should already
be allocated |
(...skipping 22 matching lines...) Expand all Loading... |
51 | 52 |
52 /** Given width and height of original image, return size (in bytes) of distance
field | 53 /** Given width and height of original image, return size (in bytes) of distance
field |
53 * @param w Width of the original image. | 54 * @param w Width of the original image. |
54 * @param h Height of the original image. | 55 * @param h Height of the original image. |
55 */ | 56 */ |
56 inline size_t SkComputeDistanceFieldSize(int w, int h) { | 57 inline size_t SkComputeDistanceFieldSize(int w, int h) { |
57 return (w + 2*SK_DistanceFieldPad) * (h + 2*SK_DistanceFieldPad) * sizeof(un
signed char); | 58 return (w + 2*SK_DistanceFieldPad) * (h + 2*SK_DistanceFieldPad) * sizeof(un
signed char); |
58 } | 59 } |
59 | 60 |
60 #endif | 61 #endif |
OLD | NEW |