Index: src/core/SkDistanceFieldGen.h |
diff --git a/src/core/SkDistanceFieldGen.h b/src/core/SkDistanceFieldGen.h |
index 3d2ec23b75de31460a23290dcc603491b0064da2..756cff14a3be2fd38778578dd48ee5c2d9b62e12 100644 |
--- a/src/core/SkDistanceFieldGen.h |
+++ b/src/core/SkDistanceFieldGen.h |
@@ -7,19 +7,54 @@ |
#ifndef SkDistanceFieldGen_DEFINED |
#define SkDistanceFieldGen_DEFINED |
+#include "SkTypes.h" |
+ |
+// the max magnitude for the distance field |
+// distance values are limited to the range [-SK_DistanceFieldMagnitude, SK_DistanceFieldMagnitude) |
+#define SK_DistanceFieldMagnitude 4 |
+// we need to pad around the original glyph to allow our maximum distance of |
+// SK_DistanceFieldMagnitude texels away from any edge |
+// we add one to this pad to allow for bilerp |
+#define SK_DistanceFieldPad (SK_DistanceFieldMagnitude+1) |
+ |
+// for the fragment shader |
+// The distance field is constructed as unsigned char values, so that the zero value is at 128, |
+// and the range is [-4, 4 - 1/255). Hence our multiplier is 8 - 1/32 and zero threshold is 128/255. |
+#define SK_DistanceFieldMultiplier "7.96875" |
+#define SK_DistanceFieldThreshold "0.50196078431" |
+ |
/** Given 8-bit mask data, generate the associated distance field |
* @param distanceField The distance field to be generated. Should already be allocated |
- * by the client with the padding below. |
+ * by the client with the padding above. |
* @param image 8-bit mask we're using to generate the distance field. |
- * @param w Width of the image. |
- * @param h Height of the image. |
- * @param distanceMagnitude Largest possible absolute value for the distance. The distance field |
- * will be padded to w + 2*distanceMagnitude, h + 2*distanceMagnitude. |
+ * @param w Width of the original image. |
+ * @param h Height of the original image. |
+ * @param rowBytes Size of each row in the image, in bytes |
+ */ |
+bool SkGenerateDistanceFieldFromA8Image(unsigned char* distanceField, |
+ const unsigned char* image, |
+ int w, int h, int rowBytes); |
+ |
+/** Given 1-bit mask data, generate the associated distance field |
+ |
+ * @param distanceField The distance field to be generated. Should already be allocated |
+ * by the client with the padding above. |
+ * @param image 1-bit mask we're using to generate the distance field. |
+ * @param w Width of the original image. |
+ * @param h Height of the original image. |
+ * @param rowBytes Size of each row in the image, in bytes |
+ */ |
+bool SkGenerateDistanceFieldFromBWImage(unsigned char* distanceField, |
+ const unsigned char* image, |
+ int w, int h, int rowBytes); |
+ |
+/** Given width and height of original image, return size (in bytes) of distance field |
+ * @param w Width of the original image. |
+ * @param h Height of the original image. |
*/ |
-bool SkGenerateDistanceFieldFromImage(unsigned char* distanceField, |
- const unsigned char* image, |
- int w, int h, |
- int distanceMagnitude); |
+inline size_t SkComputeDistanceFieldSize(int w, int h) { |
+ return (w + 2*SK_DistanceFieldPad) * (h + 2*SK_DistanceFieldPad) * sizeof(unsigned char); |
+} |
#endif |