Commit 5a1fae15a90e220e98b69ad88ee9b927aeb9c608

Werner Lemberg 2002-06-03T20:01:23

Add 8bpp support. * src/bdf/bdflib.c (_bdf_parse_start): Handle 8bpp. * src/bdf/bdfdrivr.c (BDF_Glyph_Load): Ditto. * src/bdf/README: Updated.

diff --git a/ChangeLog b/ChangeLog
index 1c4a625..db3dc9f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2002-06-03  Werner Lemberg  <wl@gnu.org>
+
+	Add 8bpp support.
+
+	* src/bdf/bdflib.c (_bdf_parse_start): Handle 8bpp.
+	* src/bdf/bdfdrivr.c (BDF_Glyph_Load): Ditto.
+	* src/bdf/README: Updated.
+
 2002-06-02  Detlef Würkner  <TetiSoft@apg.lahn.de>
 
 	* src/pfr/pfrload.c (pfr_phy_font_done): Free `blue_values' array.
diff --git a/src/bdf/README b/src/bdf/README
index bb1a5c0..d45e4fb 100644
--- a/src/bdf/README
+++ b/src/bdf/README
@@ -62,9 +62,9 @@ xmbdfed bitmap font editor.  Microsoft's SBIT tool expects bitmap fonts in
 that format for adding anti-aliased them to TrueType fonts.  It introduces a
 fourth field to the `SIZE' keyword which gives the bpp value (bits per
 pixel) of the glyph data in the font.  Possible values are 1 (the default),
-2 (four gray levels), and 4 (16 gray levels).  The driver returns either a
-bitmap with 1 bit per pixel or a pixmap with 8bits per pixel (using 4 and 16
-gray levels, respectively).
+2 (four gray levels), 4 (16 gray levels), and 8 (256 gray levels).  The
+driver returns either a bitmap with 1 bit per pixel or a pixmap with 8bits
+per pixel (using 4, 16, and 256 gray levels, respectively).
 
 
 Known problems
diff --git a/src/bdf/bdfdrivr.c b/src/bdf/bdfdrivr.c
index 8e5dd62..c29a916 100644
--- a/src/bdf/bdfdrivr.c
+++ b/src/bdf/bdfdrivr.c
@@ -432,6 +432,13 @@ THE SOFTWARE.
           p += glyph.bpr;
         }
         break;
+
+      case 8:
+        bitmap->num_grays = 256;
+
+        FT_MEM_COPY( bitmap->buffer, glyph.bitmap,
+                     bitmap->rows * bitmap->pitch );
+        break;
       }
     }
 
diff --git a/src/bdf/bdflib.c b/src/bdf/bdflib.c
index dde4e85..debfdea 100644
--- a/src/bdf/bdflib.c
+++ b/src/bdf/bdflib.c
@@ -2150,20 +2150,28 @@
       /* Check for the bits per pixel field. */
       if ( p->list.used == 5 )
       {
-        p->font->bpp = _bdf_atos( p->list.field[4], 0, 10 );
-        if ( p->font->bpp > 1 && ( p->font->bpp & 1 ) )
+        unsigned short bitcount, i, shift;
+
+
+        p->font->bpp = (unsigned short)_bdf_atos( p->list.field[4], 0, 10 );
+
+        /* Only values 1, 2, 4, 8 are allowed. */
+        shift = p->font->bpp;
+        bitcount = 0;
+        for ( i = 0; shift > 0; i++ )
         {
-          /* Move up to the next bits per pixel value if an odd number */
-          /* is encountered.                                           */
-          p->font->bpp++;
-          if ( p->font->bpp <= 4 )
-            FT_TRACE2(( "_bdf_parse_start: " ACMSG11, p->font->bpp ));
+          if ( shift & 1 )
+            bitcount = i;
+          shift >>= 1;
         }
 
-        if ( p->font->bpp > 4 )
+        shift = ( bitcount > 3 ) ? 8 : ( 1 << bitcount );
+
+        if ( p->font->bpp > shift || p->font->bpp != shift )
         {
+          /* select next higher value */
+          p->font->bpp = shift << 1;
           FT_TRACE2(( "_bdf_parse_start: " ACMSG11, p->font->bpp ));
-          p->font->bpp = 4;
         }
       }
       else