Bitmap Font Encoder

Enter a file here:

Input Data

Select an Image

Output Data

Encoder:

Direction and Grouping:


Metadata:



Output Format:




	  
	  
Decoded result:
Decoded Image
Inspect Characters:
Character

Input File Format

A 2 to 17-color image, containing all the desired glyphs, each with a fiducial marking its width. An example, Lucidia Sans 10pt, characters 32 to 127:

Example Font

Character Details     Ending Detail

The left edge of the image is discarded, up to the first fiducial, which marks the zeroth column of the zeroth character. The next fiducial marks the zeroth column of the next character, and so on. Image height is taken as character height, uniform for the whole font. Make sure to crop the image so that no ascenders or descenders are accidentally cut off—few letters use the full box, check carefully!

The fiducial is any pixel colored with unequal amounts of R, G and B. The red channel is used for that pixel's grayscale value. Red (#ff0000) is recommended for full-white pixels, and blue (#0000ff), green (#00ff00), etc. for full black. Values inbetween (i.e., #[x]00[y] where x ∈ [0, 0xff] and y = 0xff - x) are recommended to represent other levels of grayscale. Red or blue is likely easiest to draw, but this solution is provided for maximum flexibility. The vertical position of the fiducial doesn't matter, nor the number of pixels in the column colored this way. Any alpha channel is ignored. Output supports at least 16 shades of grayscale. (Some codecs may allow more shades; a warning is emitted when fewer colors are used, as a reminder that most codecs are optimized for 16.)

Notes

Encoder: Select from various encoders (codecs). These are listed at the bottom of this file (view source, find the ALL_CODECS declaration).

Direction and Grouping: raster ordering of the graphics sent to the encoder. Rows are drawn left-to-right and columns top-to-bottom, unless labeled otherwise. Individual Rows: each character is effectively sliced into sub-characters of height 1; this may be helpful for certain adapters that can only draw rows of pixels at a time. Downside: such sub-chars compress very poorly, while header/meta data grows significantly.

Metadata: byte packing and other features; any options that are implemented in this tool, that don't fit into a codec's internal header data. (Possible future consideration: store these options in the codec itself, so they aren't limited to just what's implemented here / common to all codecs. Hmm, would be nice to read color limitations this way as well.)

File name: output filename to download. Also used to generate the header label names. (For headers, name is set to uppercase; non-naming characters are set to underscores, including punctuation and extended characters—sorry Unicode users.)

Output Format, Text: Includes statistics on font metrics, encoding efficiency (compression), etc.

C Header: Header contents are #defined. All BYTEs are uint8_t, WORDs are uint16_t, etc.

Only the data header is created; the accompanying C code to use it is as follows (as an avr-gcc ROM declaration). Note that several #defines go unused; they are informational, and should be written into the decoder, whether assumed or asserted by it. Alternately the struct can be expanded to include such data (at expense to storage and code size).

#include "Header_Name.h"

typedef struct font_s {
	uint8_t startChar;
	uint8_t endChar;
	uint8_t height;
	const uint8_t* widths;
	const uint8_t* lengths;
	const uint8_t* data;
} font_t;

const uint8_t FontNameData[HEADER_NAME_DATA_SIZE];
const uint8_t FontNameWidths[HEADER_NAME_WIDTHS_SIZE];
const uint8_t FontNameLengths[HEADER_NAME_LENGTHS_SIZE];
const font_t FontNameHeader;

const uint8_t FontNameData[] PROGMEM = {
	HEADER_NAME_FONT_DATA
};
const uint8_t FontNameWidths[] PROGMEM = {
	HEADER_NAME_CHAR_WIDTHS
};
const uint8_t FontNameLengths[] PROGMEM = {
	HEADER_NAME_DATA_LENGTHS
};
const font_t FontNameHeader PROGMEM = {
	.startChar	= HEADER_NAME_START_CODE,
	.endChar	= HEADER_NAME_END_CODE,
	.height		= HEADER_NAME_HEIGHT,
	.widths		= FontNameWidths,
	.lengths	= FontNameLengths,
	.data		= FontNameData
};

C implementations of these codecs are not available unfortunately.

Binary: No file format is defined as of yet; binary output is not implemented.

Github repository

Calculators | Seven Transistor Labs