Chromium Code Reviews| 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 | |
|
robertphillips
2014/04/11 14:13:00
Is this comment right? Seems like this would be ma
jvanverth1
2014/04/11 17:54:14
Done.
| |
| 12 // the max magnitude for the distance field | |
| 13 #define SK_DistanceFieldRange 4 | |
| 14 // the final distance field needs additional texels on each side to handle | |
| 15 // the maximum distance + 1 for bilerp | |
| 16 #define SK_DistanceFieldPad (SK_DistanceFieldRange+1) | |
| 17 | |
| 18 // for the fragment shader | |
| 19 // The distance field is constructed as unsigned char values, so that the zero v alue is at 128, | |
| 20 // and the range is [-4, 4 - 1/255). Hence our multiplier is 8 - 1/32 and zero t hreshold is 128/255. | |
| 21 #define SK_DistanceFieldMultiplier "7.96875" | |
| 22 #define SK_DistanceFieldThreshold "0.50196078431" | |
| 23 | |
| 10 /** Given 8-bit mask data, generate the associated distance field | 24 /** Given 8-bit mask data, generate the associated distance field |
| 11 | 25 |
| 12 * @param distanceField The distance field to be generated. Should already be allocated | 26 * @param distanceField The distance field to be generated. Should already be allocated |
|
robertphillips
2014/04/11 14:13:00
padding below?
jvanverth1
2014/04/11 17:54:14
Done.
| |
| 13 * by the client with the padding below. | 27 * by the client with the padding below. |
| 14 * @param image 8-bit mask we're using to generate the distance fie ld. | 28 * @param image 8-bit mask we're using to generate the distance fie ld. |
| 15 * @param w Width of the image. | 29 * @param w Width of the image. |
| 16 * @param h Height of the image. | 30 * @param h Height of the image. |
|
robertphillips
2014/04/11 14:13:00
rowBytes?
jvanverth1
2014/04/11 17:54:14
Done.
| |
| 17 * @param distanceMagnitude Largest possible absolute value for the distance. T he distance field | |
| 18 * will be padded to w + 2*distanceMagnitude, h + 2*di stanceMagnitude. | |
| 19 */ | 31 */ |
| 20 bool SkGenerateDistanceFieldFromImage(unsigned char* distanceField, | 32 bool SkGenerateDistanceFieldFromA8Image(unsigned char* distanceField, |
| 21 const unsigned char* image, | 33 const unsigned char* image, |
| 22 int w, int h, | 34 int w, int h, int rowBytes); |
| 23 int distanceMagnitude); | 35 |
| 36 /** Given 1-bit mask data, generate the associated distance field | |
| 37 | |
| 38 * @param distanceField The distance field to be generated. Should already be allocated | |
| 39 * by the client with the padding below. | |
| 40 * @param image 1-bit mask we're using to generate the distance fie ld. | |
| 41 * @param w Width of the image. | |
| 42 * @param h Height of the image. | |
|
robertphillips
2014/04/11 14:13:00
rowBytes?
jvanverth1
2014/04/11 17:54:14
Done.
| |
| 43 */ | |
| 44 bool SkGenerateDistanceFieldFromBWImage(unsigned char* distanceField, | |
| 45 const unsigned char* image, | |
| 46 int w, int h, int rowBytes); | |
| 47 | |
| 48 /** Given width and height of original image, return size (in bytes) of distance field | |
| 49 * @param w Width of the original image. | |
| 50 * @param h Height of the original image. | |
| 51 */ | |
| 52 inline size_t SkComputeDistanceFieldSize(int w, int h) { | |
| 53 return (w + 2*SK_DistanceFieldPad) * (h + 2*SK_DistanceFieldPad) * sizeof(un signed char); | |
| 54 } | |
| 24 | 55 |
| 25 #endif | 56 #endif |
| OLD | NEW |