Commit c91dfa39e8863318f092b4d38b31e7dca32d5b40

Werner Lemberg 2008-06-21T06:27:53

Improve documentation of gray-level rastering and what to do if you need less than 256 gray levels.

diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h
index b83101a..e2a4e8d 100644
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -2564,10 +2564,12 @@ FT_BEGIN_HEADER
   /*    @FT_GlyphSlotRec structure gives the format of the returned        */
   /*    bitmap.                                                            */
   /*                                                                       */
+  /*    All modes except @FT_RENDER_MODE_MONO use 256 levels of opacity.   */
+  /*                                                                       */
   /* <Values>                                                              */
   /*    FT_RENDER_MODE_NORMAL ::                                           */
   /*      This is the default render mode; it corresponds to 8-bit         */
-  /*      anti-aliased bitmaps, using 256 levels of opacity.               */
+  /*      anti-aliased bitmaps.                                            */
   /*                                                                       */
   /*    FT_RENDER_MODE_LIGHT ::                                            */
   /*      This is equivalent to @FT_RENDER_MODE_NORMAL.  It is only        */
@@ -2576,7 +2578,8 @@ FT_BEGIN_HEADER
   /*      @FT_LOAD_TARGET_XXX for details.                                 */
   /*                                                                       */
   /*    FT_RENDER_MODE_MONO ::                                             */
-  /*      This mode corresponds to 1-bit bitmaps.                          */
+  /*      This mode corresponds to 1-bit bitmaps (with 2 levels of         */
+  /*      opacity).                                                        */
   /*                                                                       */
   /*    FT_RENDER_MODE_LCD ::                                              */
   /*      This mode corresponds to horizontal RGB and BGR sub-pixel        */
diff --git a/include/freetype/ftimage.h b/include/freetype/ftimage.h
index 56acb17..27304ad 100644
--- a/include/freetype/ftimage.h
+++ b/include/freetype/ftimage.h
@@ -129,7 +129,7 @@ FT_BEGIN_HEADER
   /*    FT_PIXEL_MODE_GRAY ::                                              */
   /*      An 8-bit bitmap, generally used to represent anti-aliased glyph  */
   /*      images.  Each pixel is stored in one byte.  Note that the number */
-  /*      of value `gray' levels is stored in the `num_bytes' field of     */
+  /*      of value `gray' levels is stored in the `num_grays' field of     */
   /*      the @FT_Bitmap structure (it generally is 256).                  */
   /*                                                                       */
   /*    FT_PIXEL_MODE_GRAY2 ::                                             */
@@ -819,7 +819,8 @@ FT_BEGIN_HEADER
   /*    @FT_SpanFunc which takes the y-coordinate of the span as a         */
   /*    a parameter.                                                       */
   /*                                                                       */
-  /*    The coverage value is always between 0 and 255.                    */
+  /*    The coverage value is always between 0 and 255.  If you want less  */
+  /*    gray values, the callback function has to reduce them.             */
   /*                                                                       */
   typedef struct  FT_Span_
   {
diff --git a/include/freetype/ftoutln.h b/include/freetype/ftoutln.h
index 873e64b..07af2d9 100644
--- a/include/freetype/ftoutln.h
+++ b/include/freetype/ftoutln.h
@@ -391,10 +391,15 @@ FT_BEGIN_HEADER
   /*                                                                       */
   /* <Note>                                                                */
   /*    This function does NOT CREATE the bitmap, it only renders an       */
-  /*    outline image within the one you pass to it!                       */
+  /*    outline image within the one you pass to it!  Consequently, the    */
+  /*    various fields in `abitmap' should be set accordingly.             */
   /*                                                                       */
   /*    It will use the raster corresponding to the default glyph format.  */
   /*                                                                       */
+  /*    The value of the `num_grays' field in `abitmap' is ignored.  If    */
+  /*    you select the gray-level rasterizer, and you want less than 256   */
+  /*    gray levels, you have to use @FT_Outline_Render directly.          */
+  /*                                                                       */
   FT_EXPORT( FT_Error )
   FT_Outline_Get_Bitmap( FT_Library        library,
                          FT_Outline*       outline,
@@ -432,6 +437,11 @@ FT_BEGIN_HEADER
   /*    converter is called, which means that the value you give to it is  */
   /*    actually ignored.                                                  */
   /*                                                                       */
+  /*    The gray-level rasterizer always uses 256 gray levels.  If you     */
+  /*    want less gray levels, you have to provide your own span callback. */
+  /*    See the @FT_RASTER_FLAG_DIRECT value of the `flags' field in the   */
+  /*    @FT_Raster_Params structure for more details.                      */
+  /*                                                                       */
   FT_EXPORT( FT_Error )
   FT_Outline_Render( FT_Library         library,
                      FT_Outline*        outline,
diff --git a/src/smooth/ftgrays.c b/src/smooth/ftgrays.c
index add1dd2..320e5d8 100644
--- a/src/smooth/ftgrays.c
+++ b/src/smooth/ftgrays.c
@@ -1616,15 +1616,14 @@
 
     volatile int  error = 0;
 
+
     if ( ft_setjmp( ras.jump_buffer ) == 0 )
     {
       error = FT_Outline_Decompose( &ras.outline, &func_interface, &ras );
       gray_record_cell( RAS_VAR );
     }
     else
-    {
       error = ErrRaster_Memory_Overflow;
-    }
 
     return error;
   }
@@ -1678,10 +1677,12 @@
       ras.cubic_level <<= level;
     }
 
-    /* setup vertical bands */
+    /* set up vertical bands */
     num_bands = (int)( ( ras.max_ey - ras.min_ey ) / ras.band_size );
-    if ( num_bands == 0 )  num_bands = 1;
-    if ( num_bands >= 39 ) num_bands = 39;
+    if ( num_bands == 0 )
+      num_bands = 1;
+    if ( num_bands >= 39 )
+      num_bands = 39;
 
     ras.band_shoot = 0;