March 06, 2008

Update to BMPToBDF (bmp2bdf) Tool v1.0.1

Posted at March 6, 2008 01:30 AM in Software .

   Introduction to the BMPToBDF tool. This is a command line tool (useful for calling from command prompt or from makefile), a windows application, and a DLL that you can incorporate into your project for conversion of BMP into BDF.

Download it Here

Changes since v1.0
Feature Additions
- Add support for all paletted bitmap depths (1,2,4, and 8)bpp
- If generating a font with a space character, there was no way to do that well. Now it can be specified by including in the range of the start value and having enough bitmap glyphs that can encompass the value 0x20 or 32. Input controllable width of this space character.

Bug Fixes
- Fixed BDF Parameter DWIDTH, it was lacking a 2nd value
- 1st pixel from bitmap was lost, due to 0 init and check
- Overall BDF Parameter BBX height was not accurate. Base on overall height, not tallest char.
- Fix BDF Parameter PROPERTIES:FONT_ASCENT, related to the above.
- BDF Parameter ENDFONT was missing. Added in now.
- Fix problem when black is not the 1st palette entry of the bitmap.


BMP is a windows bitmap, you can find these all over the place. BDF is a bitmapped font file format, commonly used in UNIX/LINUX XWindows, but also used in the Rockbox environment. Scalable fonts logic occupies a lot of space and processing, so bitmapped fonts are common in the world of embedded devices. Maybe you have some other use for BDF and for this tool.

More info after the link.

The usage instructions for the windows application follow below. The command line application acts in much the same manner and you can download the package to see the instructions for its usage.

Since there are two executables there are two separate ways to describe ultimate usage, however they share a common theme by achieving the same functionality and this section aims to cover that. For specifics on either the windows application or the windows console application, see the relevant section below.

The input BMP is a Windows BMP format. It must be a a paletted bitmap at 1bpp, 2bpp, 4bpp, or 8bpp bit depths. It must have the relevant and true bitmap header information, a color palette containing at least one black entry, and the pixel bits.

Within the pixel bits, are the pixels that make up glyphs. Within a single glyph there are representations of the color black and non-black. There is no distinguishing between non-black pixels, they are all treated as data that is not to be drawn. Black pixels indicate a point in the glyph that is to be drawn.

The glyphs are all arranged with a spacing between them of non-black pixels and occupy only one row. They must be adjacent and the value of the next glyph must be the value of the previous glyph plus one. That is, you would arrange the character A to the left of the character B with some spacing between the end of the A and beginning of the B.

Special case, the space character should not be represented in the bitmap since it will be overlooked as an empty gap. Use the start character parameter in conjunction with the quantity of glyphs you need to ensure that there is a space character accounted for. For instance, your start value may be 0x20 or 32 and if you have more than one glyph it will insert a space character for you. The width of the space character is automatically calibrated to be the same width as the
fattest glyph in the supplied bitmap. If you want to override this behavior then you need to specify the number of pixels for the space character's sizing in the input parameters. If it is a fixed width font, then the parameter is also ignored.

To create this bitmap, you can use your favorite image editor. From MS Paint (free in windows) to more elaborate tools such as Adobe Photoshop, just ensure you're working with a paletted bitmap. A visible representation of what the bitmap should look like is given as an ascii representation below. It makes sense only when viewed in a fixed width font. A # represents a filled pixel and a blank
space represents a non-filled space. Above the pixels is a ruler guide and must not be used in your actual bitmap. It is for simple counting of columns in this illustration.

0123456789012345
   ##   ######  
  # #         # 
    #         # 
    #         # 
    #    #####  
    #   #       
    #   #       
 ######  ###### 

That's a two glyph bitmap pictured above. The value fed to the starting char would be Decimal 49 or the ascii representation of the character '1'. Other parameters are also required for describing your bitmap that don't fit well within the constraints of the bitmap that will be explained as follows.

It is much easier to describe with a picture. Let's take the letters A and g to illustrate the point. A # represents a filled pixel, or color of black in the input bitmap. A blank spot represents a blank or a non-black pixel on the bitmap.

              1 ----|    ----- 2
                    |    |
               ---------------------
               |    #              |------------------------------
               |   ###             |                              |
               |   # #       ### # |                              |
               |   #  #     #   ## |                              |
            3 -|  #   #    #     # |- 5                           |- 8 
               |  #    #   #     # |                              | 
               | #######   #     # |                              |
               | #      #  #     # |                              |
               | #      #   #   ## |                              |
               |#        #  #### # |------------------------------
               |                 # |--
               |                #  |  |- 6
             --|            ####   |--
             | ---------------------
      |-------  |        | |      |
      |          --------   ------
      4             |         |
                  width      width2
                  |               |
                   ---------------
                          |
                          7

1. # of leading blank spaces above drawing pixels (shown 0)
2. Spaces between glyphs. In this case if treated 1 or more this will be treated as 1 glyph since there is only 1 space. Realistically, you'd put 0 here.
3. # of leading blank spaces before drawing pixels of next glyph (shown 0)
4. # of trailing blank spaces after drawing pixels. Basically pad below character
before next line starts.
5. # of trailing blank spaces after drawing pixels before starting the next
character (shown 1)
6. Number of pixels to use for descent from the baseline, or characters that can
drop below the horizontal line of origin. (shown 3)
7. Whether to generate Fixed Width font. That is, if the characters do not occupy
the same width of a bounding rectangle, padding will be inserted so they do.
8. Ascent. This is calculated by the tallest character and the descent given. This
is not an input parameter to these programs.

wbmptobdf.exe

This is the windows tool to process a BMP to create a BDF file. The high level usage instructions are to open a compliant BMP File as described in the Usage section and fill in or select the options that you wish to be taken into the BDF File's logic and then click the process button.

The following are the entry fields and they are mapped to the entries as given by the description below the graphic of Ag in the Usage section.

Input BMP File Name[...]
You can type the path or click the "..." to browse to the path of the input BMP File Name.

Output BDF File Name
You can type the path and filename for the output BDF File. Or you can leave this blank and the path from the BMP File Name will be used as well as the base of the file name with the BDF replacing BMP.

Font Name
You can type the name that is set as the FONT parameter of the output BDF File.

1st Glyph Value
Corresponds to the 16 bit value of the first glyph in the bitmap. Can be entered as hexidecimal or decimal format.

Allowed Vertical Blank Pixels In Glyph
Corresponds to #2 in the description below Ag in the usage section.

Space Char Pixel Size (if needed)
No corresponding field in the image above. This is the number of pixels to use if a space character is within the glyph range provided for that space character. If it is at zero, then the fattest glyph will be used. If the font is fixed width then the actual fixed width will be used.

Descent Pixels
Corresponds to #6 in the description below Ag in the usage section.

Fixed Width Font
When checked will generate a fixed width font, when not it will use the actual character spacing of the bitmap characters. Corresponds to #7 in the description below Ag in the usage section.

Upper Blank Pixels
Since the BMP file grabs the limits of each glyph, some padding may be desired. Setting this will put that number of padding pixels above a glyph in the BDF. Corresponds to #1 in the description below Ag in the usage section.

Leading Blank Pixels
Since the BMP file grabs the limits of each glyph, some padding may be desired. Setting this will put that number of padding pixels before a glyph in the BDF. Corresponds to #3 in the description below Ag in the usage section.

Trailing Blank Pixels
Since the BMP file grabs the limits of each glyph, some padding may be desired. Setting this will put that number of padding pixels after a glyph in the BDF. Corresponds to #5 in the description below Ag in the usage section.

Lower Blank Pixels
Since the BMP file grabs the limits of each glyph, some padding may be desired. Setting this will put that number of padding pixels below a glyph in the BDF. Corresponds to #4 in the description below Ag in the usage section.

Comments

Wow, if you going to do something, you might as well do it right the first time. With all of the bug fixes, this might as well be a 4.x.x release.

Posted by at March 6, 2008 12:29 PM
Posting of new comments has been disabled for this post.