/* ______ ___ ___ * /\ _ \ /\_ \ /\_ \ * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___ * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\ * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \ * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/ * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/ * /\____/ * \_/__/ * * * contains a ported binary version of the Allegro 4 internal standard font * and a function to create an Allegro 5 bitmap font from the binary data * for use in environments where no external bitmap font or true type font is available * * also contains an implementation of Monochrome Font Upscaling Algorithm "Tri-add-rem" * as described here: http://www.allegro.cc/forums/thread/610499/958800#target * * By Dennis Busch. * * See readme.txt for copyright information. */ #include "allegro5/allegro.h" #include "allegro5/allegro_font.h" static bool _tar_lut_initialized = false; /* Tri-add-rem rule lookup table initialized flag */ static void _free_tar_lut(void); /* will be called atexit */ /* adapted from Allegro4 "font.c" (removed unncesseray height and width information and packed them all into a single continuous array) */ /* contains the following ranges * * ASCII (0x0020 to 0x007F) * Latin-1 (0x00A1 to 0x00FF) * Extended-A (0x0100 to 0x017F) * Euro (0x20AC) */ static unsigned char _al_rom_font_8x8[] = { /* standard ASCII characters (0x20 to 0x7F) */ /* 0x20 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x21 */ 0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00, /* 0x22 */ 0x6C, 0x6C, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x23 */ 0x6C, 0x6C, 0xFE, 0x6C, 0xFE, 0x6C, 0x6C, 0x00, /* 0x24 */ 0x18, 0x7E, 0xC0, 0x7C, 0x06, 0xFC, 0x18, 0x00, /* 0x25 */ 0x00, 0xC6, 0xCC, 0x18, 0x30, 0x66, 0xC6, 0x00, /* 0x26 */ 0x38, 0x6C, 0x38, 0x76, 0xDC, 0xCC, 0x76, 0x00, /* 0x27 */ 0x30, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28 */ 0x18, 0x30, 0x60, 0x60, 0x60, 0x30, 0x18, 0x00, /* 0x29 */ 0x60, 0x30, 0x18, 0x18, 0x18, 0x30, 0x60, 0x00, /* 0x2A */ 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00, /* 0x2B */ 0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x00, /* 0x2C */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, /* 0x2D */ 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, /* 0x2E */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, /* 0x2F */ 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0x80, 0x00, /* 0x30 */ 0x7C, 0xCE, 0xDE, 0xF6, 0xE6, 0xC6, 0x7C, 0x00, /* 0x31 */ 0x30, 0x70, 0x30, 0x30, 0x30, 0x30, 0xFC, 0x00, /* 0x32 */ 0x78, 0xCC, 0x0C, 0x38, 0x60, 0xCC, 0xFC, 0x00, /* 0x33 */ 0x78, 0xCC, 0x0C, 0x38, 0x0C, 0xCC, 0x78, 0x00, /* 0x34 */ 0x1C, 0x3C, 0x6C, 0xCC, 0xFE, 0x0C, 0x1E, 0x00, /* 0x35 */ 0xFC, 0xC0, 0xF8, 0x0C, 0x0C, 0xCC, 0x78, 0x00, /* 0x36 */ 0x38, 0x60, 0xC0, 0xF8, 0xCC, 0xCC, 0x78, 0x00, /* 0x37 */ 0xFC, 0xCC, 0x0C, 0x18, 0x30, 0x30, 0x30, 0x00, /* 0x38 */ 0x78, 0xCC, 0xCC, 0x78, 0xCC, 0xCC, 0x78, 0x00, /* 0x39 */ 0x78, 0xCC, 0xCC, 0x7C, 0x0C, 0x18, 0x70, 0x00, /* 0x3A */ 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x00, /* 0x3B */ 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x30, /* 0x3C */ 0x18, 0x30, 0x60, 0xC0, 0x60, 0x30, 0x18, 0x00, /* 0x3D */ 0x00, 0x00, 0x7E, 0x00, 0x7E, 0x00, 0x00, 0x00, /* 0x3E */ 0x60, 0x30, 0x18, 0x0C, 0x18, 0x30, 0x60, 0x00, /* 0x3F */ 0x3C, 0x66, 0x0C, 0x18, 0x18, 0x00, 0x18, 0x00, /* 0x40 */ 0x7C, 0xC6, 0xDE, 0xDE, 0xDC, 0xC0, 0x7C, 0x00, /* 0x41 */ 0x30, 0x78, 0xCC, 0xCC, 0xFC, 0xCC, 0xCC, 0x00, /* 0x42 */ 0xFC, 0x66, 0x66, 0x7C, 0x66, 0x66, 0xFC, 0x00, /* 0x43 */ 0x3C, 0x66, 0xC0, 0xC0, 0xC0, 0x66, 0x3C, 0x00, /* 0x44 */ 0xF8, 0x6C, 0x66, 0x66, 0x66, 0x6C, 0xF8, 0x00, /* 0x45 */ 0xFE, 0x62, 0x68, 0x78, 0x68, 0x62, 0xFE, 0x00, /* 0x46 */ 0xFE, 0x62, 0x68, 0x78, 0x68, 0x60, 0xF0, 0x00, /* 0x47 */ 0x3C, 0x66, 0xC0, 0xC0, 0xCE, 0x66, 0x3A, 0x00, /* 0x48 */ 0xCC, 0xCC, 0xCC, 0xFC, 0xCC, 0xCC, 0xCC, 0x00, /* 0x49 */ 0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, /* 0x4A */ 0x1E, 0x0C, 0x0C, 0x0C, 0xCC, 0xCC, 0x78, 0x00, /* 0x4B */ 0xE6, 0x66, 0x6C, 0x78, 0x6C, 0x66, 0xE6, 0x00, /* 0x4C */ 0xF0, 0x60, 0x60, 0x60, 0x62, 0x66, 0xFE, 0x00, /* 0x4D */ 0xC6, 0xEE, 0xFE, 0xFE, 0xD6, 0xC6, 0xC6, 0x00, /* 0x4E */ 0xC6, 0xE6, 0xF6, 0xDE, 0xCE, 0xC6, 0xC6, 0x00, /* 0x4F */ 0x38, 0x6C, 0xC6, 0xC6, 0xC6, 0x6C, 0x38, 0x00, /* 0x50 */ 0xFC, 0x66, 0x66, 0x7C, 0x60, 0x60, 0xF0, 0x00, /* 0x51 */ 0x7C, 0xC6, 0xC6, 0xC6, 0xD6, 0x7C, 0x0E, 0x00, /* 0x52 */ 0xFC, 0x66, 0x66, 0x7C, 0x6C, 0x66, 0xE6, 0x00, /* 0x53 */ 0x7C, 0xC6, 0xE0, 0x78, 0x0E, 0xC6, 0x7C, 0x00, /* 0x54 */ 0xFC, 0xB4, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, /* 0x55 */ 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xFC, 0x00, /* 0x56 */ 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x00, /* 0x57 */ 0xC6, 0xC6, 0xC6, 0xC6, 0xD6, 0xFE, 0x6C, 0x00, /* 0x58 */ 0xC6, 0xC6, 0x6C, 0x38, 0x6C, 0xC6, 0xC6, 0x00, /* 0x59 */ 0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x30, 0x78, 0x00, /* 0x5A */ 0xFE, 0xC6, 0x8C, 0x18, 0x32, 0x66, 0xFE, 0x00, /* 0x5B */ 0x78, 0x60, 0x60, 0x60, 0x60, 0x60, 0x78, 0x00, /* 0x5C */ 0xC0, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x02, 0x00, /* 0x5D */ 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x00, /* 0x5E */ 0x10, 0x38, 0x6C, 0xC6, 0x00, 0x00, 0x00, 0x00, /* 0x5F */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, /* 0x60 */ 0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x61 */ 0x00, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00, /* 0x62 */ 0xE0, 0x60, 0x60, 0x7C, 0x66, 0x66, 0xDC, 0x00, /* 0x63 */ 0x00, 0x00, 0x78, 0xCC, 0xC0, 0xCC, 0x78, 0x00, /* 0x64 */ 0x1C, 0x0C, 0x0C, 0x7C, 0xCC, 0xCC, 0x76, 0x00, /* 0x65 */ 0x00, 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, /* 0x66 */ 0x38, 0x6C, 0x64, 0xF0, 0x60, 0x60, 0xF0, 0x00, /* 0x67 */ 0x00, 0x00, 0x76, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, /* 0x68 */ 0xE0, 0x60, 0x6C, 0x76, 0x66, 0x66, 0xE6, 0x00, /* 0x69 */ 0x30, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, /* 0x6A */ 0x0C, 0x00, 0x1C, 0x0C, 0x0C, 0xCC, 0xCC, 0x78, /* 0x6B */ 0xE0, 0x60, 0x66, 0x6C, 0x78, 0x6C, 0xE6, 0x00, /* 0x6C */ 0x70, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, /* 0x6D */ 0x00, 0x00, 0xCC, 0xFE, 0xFE, 0xD6, 0xD6, 0x00, /* 0x6E */ 0x00, 0x00, 0xB8, 0xCC, 0xCC, 0xCC, 0xCC, 0x00, /* 0x6F */ 0x00, 0x00, 0x78, 0xCC, 0xCC, 0xCC, 0x78, 0x00, /* 0x70 */ 0x00, 0x00, 0xDC, 0x66, 0x66, 0x7C, 0x60, 0xF0, /* 0x71 */ 0x00, 0x00, 0x76, 0xCC, 0xCC, 0x7C, 0x0C, 0x1E, /* 0x72 */ 0x00, 0x00, 0xDC, 0x76, 0x62, 0x60, 0xF0, 0x00, /* 0x73 */ 0x00, 0x00, 0x7C, 0xC0, 0x70, 0x1C, 0xF8, 0x00, /* 0x74 */ 0x10, 0x30, 0xFC, 0x30, 0x30, 0x34, 0x18, 0x00, /* 0x75 */ 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0x76, 0x00, /* 0x76 */ 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x00, /* 0x77 */ 0x00, 0x00, 0xC6, 0xC6, 0xD6, 0xFE, 0x6C, 0x00, /* 0x78 */ 0x00, 0x00, 0xC6, 0x6C, 0x38, 0x6C, 0xC6, 0x00, /* 0x79 */ 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, /* 0x7A */ 0x00, 0x00, 0xFC, 0x98, 0x30, 0x64, 0xFC, 0x00, /* 0x7B */ 0x1C, 0x30, 0x30, 0xE0, 0x30, 0x30, 0x1C, 0x00, /* 0x7C */ 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00, /* 0x7D */ 0xE0, 0x30, 0x30, 0x1C, 0x30, 0x30, 0xE0, 0x00, /* 0x7E */ 0x76, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x7F */ 0x00, 0x10, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0x00, /* ANSI Latin-1 characters (0xA1 to 0xFF) */ /* 0xA1 */ 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, /* 0xA2 */ 0x18, 0x18, 0x7E, 0xC0, 0xC0, 0x7E, 0x18, 0x18, /* 0xA3 */ 0x38, 0x6C, 0x64, 0xF0, 0x60, 0xE6, 0xFC, 0x00, /* 0xA4 */ 0x00, 0xC6, 0x7C, 0xC6, 0xC6, 0x7C, 0xC6, 0x00, /* 0xA5 */ 0xCC, 0xCC, 0x78, 0xFC, 0x30, 0xFC, 0x30, 0x30, /* 0xA6 */ 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00, /* 0xA7 */ 0x3E, 0x61, 0x3C, 0x66, 0x66, 0x3C, 0x86, 0x7C, /* 0xA8 */ 0x00, 0xC6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xA9 */ 0x7E, 0x81, 0x9D, 0xA1, 0xA1, 0x9D, 0x81, 0x7E, /* 0xAA */ 0x3C, 0x6C, 0x6C, 0x3E, 0x00, 0x7E, 0x00, 0x00, /* 0xAB */ 0x00, 0x33, 0x66, 0xCC, 0x66, 0x33, 0x00, 0x00, /* 0xAC */ 0x00, 0x00, 0x00, 0xFC, 0x0C, 0x0C, 0x00, 0x00, /* 0xAD */ 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, /* 0xAE */ 0x7E, 0x81, 0xB9, 0xA5, 0xB9, 0xA5, 0x81, 0x7E, /* 0xAF */ 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xB0 */ 0x38, 0x6C, 0x6C, 0x38, 0x00, 0x00, 0x00, 0x00, /* 0xB1 */ 0x30, 0x30, 0xFC, 0x30, 0x30, 0x00, 0xFC, 0x00, /* 0xB2 */ 0x70, 0x18, 0x30, 0x60, 0x78, 0x00, 0x00, 0x00, /* 0xB3 */ 0x78, 0x0C, 0x38, 0x0C, 0x78, 0x00, 0x00, 0x00, /* 0xB4 */ 0x0C, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xB5 */ 0x00, 0x00, 0x33, 0x33, 0x66, 0x7E, 0xC0, 0x80, /* 0xB6 */ 0x7F, 0xDB, 0xDB, 0x7B, 0x1B, 0x1B, 0x1B, 0x00, /* 0xB7 */ 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, /* 0xB8 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0C, 0x38, /* 0xB9 */ 0x18, 0x38, 0x18, 0x18, 0x3C, 0x00, 0x00, 0x00, /* 0xBA */ 0x38, 0x6C, 0x6C, 0x38, 0x00, 0x7C, 0x00, 0x00, /* 0xBB */ 0x00, 0xCC, 0x66, 0x33, 0x66, 0xCC, 0x00, 0x00, /* 0xBC */ 0xC3, 0xC6, 0xCC, 0xDB, 0x37, 0x6F, 0xCF, 0x03, /* 0xBD */ 0xC3, 0xC6, 0xCC, 0xDE, 0x33, 0x66, 0xCC, 0x0F, /* 0xBE */ 0xE1, 0x32, 0xE4, 0x3A, 0xF6, 0x2A, 0x5F, 0x86, /* 0xBF */ 0x30, 0x00, 0x30, 0x60, 0xC0, 0xCC, 0x78, 0x00, /* 0xC0 */ 0x18, 0x0C, 0x38, 0x6C, 0xC6, 0xFE, 0xC6, 0x00, /* 0xC1 */ 0x30, 0x60, 0x38, 0x6C, 0xC6, 0xFE, 0xC6, 0x00, /* 0xC2 */ 0x7C, 0x82, 0x38, 0x6C, 0xC6, 0xFE, 0xC6, 0x00, /* 0xC3 */ 0x76, 0xDC, 0x38, 0x6C, 0xC6, 0xFE, 0xC6, 0x00, /* 0xC4 */ 0xC6, 0x00, 0x38, 0x6C, 0xC6, 0xFE, 0xC6, 0x00, /* 0xC5 */ 0x10, 0x28, 0x38, 0x6C, 0xC6, 0xFE, 0xC6, 0x00, /* 0xC6 */ 0x3E, 0x6C, 0xCC, 0xFE, 0xCC, 0xCC, 0xCE, 0x00, /* 0xC7 */ 0x78, 0xCC, 0xC0, 0xCC, 0x78, 0x18, 0x0C, 0x78, /* 0xC8 */ 0x30, 0x18, 0xFE, 0xC0, 0xFC, 0xC0, 0xFE, 0x00, /* 0xC9 */ 0x0C, 0x18, 0xFE, 0xC0, 0xFC, 0xC0, 0xFE, 0x00, /* 0xCA */ 0x7C, 0x82, 0xFE, 0xC0, 0xFC, 0xC0, 0xFE, 0x00, /* 0xCB */ 0xC6, 0x00, 0xFE, 0xC0, 0xFC, 0xC0, 0xFE, 0x00, /* 0xCC */ 0x30, 0x18, 0x3C, 0x18, 0x18, 0x18, 0x3C, 0x00, /* 0xCD */ 0x0C, 0x18, 0x3C, 0x18, 0x18, 0x18, 0x3C, 0x00, /* 0xCE */ 0x3C, 0x42, 0x3C, 0x18, 0x18, 0x18, 0x3C, 0x00, /* 0xCF */ 0x66, 0x00, 0x3C, 0x18, 0x18, 0x18, 0x3C, 0x00, /* 0xD0 */ 0xF8, 0x6C, 0x66, 0xF6, 0x66, 0x6C, 0xF8, 0x00, /* 0xD1 */ 0xFC, 0x00, 0xCC, 0xEC, 0xFC, 0xDC, 0xCC, 0x00, /* 0xD2 */ 0x30, 0x18, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, /* 0xD3 */ 0x18, 0x30, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, /* 0xD4 */ 0x7C, 0x82, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, /* 0xD5 */ 0x76, 0xDC, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, /* 0xD6 */ 0xC6, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, /* 0xD7 */ 0x00, 0xC6, 0x6C, 0x38, 0x6C, 0xC6, 0x00, 0x00, /* 0xD8 */ 0x3A, 0x6C, 0xCE, 0xD6, 0xE6, 0x6C, 0xB8, 0x00, /* 0xD9 */ 0x60, 0x30, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, /* 0xDA */ 0x18, 0x30, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, /* 0xDB */ 0x7C, 0x82, 0x00, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, /* 0xDC */ 0xC6, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, /* 0xDD */ 0x0C, 0x18, 0x66, 0x66, 0x3C, 0x18, 0x3C, 0x00, /* 0xDE */ 0xE0, 0x60, 0x7C, 0x66, 0x66, 0x7C, 0x60, 0xF0, /* 0xDF */ 0x78, 0xCC, 0xCC, 0xD8, 0xCC, 0xC6, 0xCC, 0x00, /* 0xE0 */ 0xE0, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x7E, 0x00, /* 0xE1 */ 0x1C, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x7E, 0x00, /* 0xE2 */ 0x7E, 0xC3, 0x3C, 0x06, 0x3E, 0x66, 0x3F, 0x00, /* 0xE3 */ 0x76, 0xDC, 0x78, 0x0C, 0x7C, 0xCC, 0x7E, 0x00, /* 0xE4 */ 0xCC, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x7E, 0x00, /* 0xE5 */ 0x30, 0x30, 0x78, 0x0C, 0x7C, 0xCC, 0x7E, 0x00, /* 0xE6 */ 0x00, 0x00, 0x7F, 0x0C, 0x7F, 0xCC, 0x7F, 0x00, /* 0xE7 */ 0x00, 0x00, 0x78, 0xC0, 0xC0, 0x78, 0x0C, 0x38, /* 0xE8 */ 0xE0, 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, /* 0xE9 */ 0x1C, 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, /* 0xEA */ 0x7E, 0xC3, 0x3C, 0x66, 0x7E, 0x60, 0x3C, 0x00, /* 0xEB */ 0xCC, 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, /* 0xEC */ 0xE0, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, /* 0xED */ 0x38, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, /* 0xEE */ 0x7C, 0xC6, 0x38, 0x18, 0x18, 0x18, 0x3C, 0x00, /* 0xEF */ 0xCC, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, /* 0xF0 */ 0x08, 0x3C, 0x08, 0x7C, 0xCC, 0xCC, 0x78, 0x00, /* 0xF1 */ 0x00, 0xF8, 0x00, 0xF8, 0xCC, 0xCC, 0xCC, 0x00, /* 0xF2 */ 0x00, 0xE0, 0x00, 0x78, 0xCC, 0xCC, 0x78, 0x00, /* 0xF3 */ 0x00, 0x1C, 0x00, 0x78, 0xCC, 0xCC, 0x78, 0x00, /* 0xF4 */ 0x78, 0xCC, 0x00, 0x78, 0xCC, 0xCC, 0x78, 0x00, /* 0xF5 */ 0x76, 0xDC, 0x00, 0x78, 0xCC, 0xCC, 0x78, 0x00, /* 0xF6 */ 0x00, 0xCC, 0x00, 0x78, 0xCC, 0xCC, 0x78, 0x00, /* 0xF7 */ 0x30, 0x30, 0x00, 0xFC, 0x00, 0x30, 0x30, 0x00, /* 0xF8 */ 0x00, 0x02, 0x7C, 0xCE, 0xD6, 0xE6, 0x7C, 0x80, /* 0xF9 */ 0x00, 0xE0, 0x00, 0xCC, 0xCC, 0xCC, 0x7E, 0x00, /* 0xFA */ 0x00, 0x1C, 0x00, 0xCC, 0xCC, 0xCC, 0x7E, 0x00, /* 0xFB */ 0x78, 0xCC, 0x00, 0xCC, 0xCC, 0xCC, 0x7E, 0x00, /* 0xFC */ 0x00, 0xCC, 0x00, 0xCC, 0xCC, 0xCC, 0x7E, 0x00, /* 0xFD */ 0x18, 0x30, 0xCC, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, /* 0xFE */ 0xF0, 0x60, 0x7C, 0x66, 0x7C, 0x60, 0xF0, 0x00, /* 0xFF */ 0x00, 0xCC, 0x00, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, /* Extended-A characters (0x100 to 0x17F) */ /* 0x100 */ 0xFE, 0x00, 0x38, 0x6C, 0xC6, 0xFE, 0xC6, 0x00, /* 0x101 */ 0xFC, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x7E, 0x00, /* 0x102 */ 0x82, 0x7C, 0x38, 0x6C, 0xC6, 0xFE, 0xC6, 0x00, /* 0x103 */ 0xC3, 0x7E, 0x78, 0x0C, 0x7C, 0xCC, 0x7E, 0x00, /* 0x104 */ 0x38, 0x6C, 0xC6, 0xFE, 0xC6, 0x1C, 0x30, 0x1E, /* 0x105 */ 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x7E, 0x30, 0x1C, /* 0x106 */ 0x0C, 0x18, 0x7C, 0xC6, 0xC0, 0xC6, 0x7C, 0x00, /* 0x107 */ 0x1C, 0x00, 0x78, 0xCC, 0xC0, 0xCC, 0x78, 0x00, /* 0x108 */ 0x7C, 0x82, 0x7C, 0xC6, 0xC0, 0xC6, 0x7C, 0x00, /* 0x109 */ 0x7E, 0xC3, 0x78, 0xCC, 0xC0, 0xCC, 0x78, 0x00, /* 0x10A */ 0x10, 0x00, 0x7C, 0xC6, 0xC0, 0xC6, 0x7C, 0x00, /* 0x10B */ 0x10, 0x00, 0x78, 0xCC, 0xC0, 0xCC, 0x78, 0x00, /* 0x10C */ 0x6C, 0x38, 0x7C, 0xC6, 0xC0, 0xC6, 0x7C, 0x00, /* 0x10D */ 0x6C, 0x38, 0x78, 0xCC, 0xC0, 0xCC, 0x78, 0x00, /* 0x10E */ 0x6C, 0x38, 0xF8, 0x66, 0x66, 0x66, 0xF8, 0x00, /* 0x10F */ 0xBC, 0x4C, 0x0C, 0x7C, 0xCC, 0xCC, 0x76, 0x00, /* 0x110 */ 0xF8, 0x6C, 0x66, 0xF6, 0x66, 0x6C, 0xF8, 0x00, /* 0x111 */ 0x08, 0x3C, 0x08, 0x7C, 0xCC, 0xCC, 0x78, 0x00, /* 0x112 */ 0xFE, 0x00, 0xFE, 0xC0, 0xFC, 0xC0, 0xFE, 0x00, /* 0x113 */ 0xFC, 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, /* 0x114 */ 0x6C, 0x38, 0xFE, 0xC0, 0xFC, 0xC0, 0xFE, 0x00, /* 0x115 */ 0x6C, 0x38, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, /* 0x116 */ 0x10, 0x00, 0xFE, 0xC0, 0xFC, 0xC0, 0xFE, 0x00, /* 0x117 */ 0x10, 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, /* 0x118 */ 0xFE, 0xC0, 0xFC, 0xC0, 0xFE, 0x18, 0x30, 0x1C, /* 0x119 */ 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x38, 0x0C, /* 0x11A */ 0x6C, 0x38, 0xFE, 0xC0, 0xFC, 0xC0, 0xFE, 0x00, /* 0x11B */ 0x6C, 0x38, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, /* 0x11C */ 0x7C, 0x82, 0x7C, 0xC6, 0xC0, 0xCE, 0x7E, 0x00, /* 0x11D */ 0x7E, 0xC3, 0x76, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, /* 0x11E */ 0x82, 0x7C, 0x7C, 0xC6, 0xC0, 0xCE, 0x7E, 0x00, /* 0x11F */ 0xC3, 0x7E, 0x76, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, /* 0x120 */ 0x10, 0x00, 0x7C, 0xC6, 0xC0, 0xCE, 0x7E, 0x00, /* 0x121 */ 0x10, 0x00, 0x76, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, /* 0x122 */ 0x7C, 0xC6, 0xC0, 0xCE, 0x7E, 0x18, 0x0C, 0x78, /* 0x123 */ 0x76, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, 0x0C, 0x38, /* 0x124 */ 0x78, 0x84, 0xCC, 0xCC, 0xFC, 0xCC, 0xCC, 0x00, /* 0x125 */ 0xEE, 0x7B, 0x6C, 0x76, 0x66, 0x66, 0xE6, 0x00, /* 0x126 */ 0xCC, 0xFE, 0xCC, 0xFC, 0xCC, 0xCC, 0xCC, 0x00, /* 0x127 */ 0xE0, 0xFE, 0x6C, 0x76, 0x66, 0x66, 0xE6, 0x00, /* 0x128 */ 0x76, 0xDC, 0x78, 0x30, 0x30, 0x30, 0x78, 0x00, /* 0x129 */ 0x76, 0xDC, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, /* 0x12A */ 0x78, 0x00, 0x78, 0x30, 0x30, 0x30, 0x78, 0x00, /* 0x12B */ 0x78, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, /* 0x12C */ 0x84, 0x78, 0x78, 0x30, 0x30, 0x30, 0x78, 0x00, /* 0x12D */ 0xC6, 0x7C, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, /* 0x12E */ 0x78, 0x30, 0x30, 0x30, 0x78, 0x18, 0x30, 0x1E, /* 0x12F */ 0x30, 0x00, 0x70, 0x30, 0x30, 0x78, 0x30, 0x1C, /* 0x130 */ 0x10, 0x00, 0x78, 0x30, 0x30, 0x30, 0x78, 0x00, /* 0x131 */ 0x00, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, /* 0x132 */ 0xEE, 0x42, 0x42, 0x42, 0x52, 0x52, 0xEC, 0x00, /* 0x133 */ 0x42, 0x00, 0xC6, 0x42, 0x42, 0x42, 0xE2, 0x0C, /* 0x134 */ 0x7C, 0x82, 0x0C, 0x0C, 0xCC, 0xCC, 0x78, 0x00, /* 0x135 */ 0x7C, 0xC6, 0x1C, 0x0C, 0x0C, 0xCC, 0xCC, 0x78, /* 0x136 */ 0xE6, 0x6C, 0x78, 0x6C, 0xE6, 0x30, 0x18, 0xF0, /* 0x137 */ 0xE0, 0x66, 0x6C, 0x78, 0x6C, 0xE6, 0x30, 0xE0, /* 0x138 */ 0x00, 0x00, 0xE6, 0x6C, 0x78, 0x6C, 0xE6, 0x00, /* 0x139 */ 0xF3, 0x66, 0x60, 0x60, 0x62, 0x66, 0xFE, 0x00, /* 0x13A */ 0x73, 0x36, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, /* 0x13B */ 0xF0, 0x60, 0x62, 0x66, 0xFE, 0x18, 0x0C, 0x78, /* 0x13C */ 0x70, 0x30, 0x30, 0x30, 0x30, 0x78, 0x0C, 0x38, /* 0x13D */ 0xF5, 0x66, 0x60, 0x60, 0x62, 0x66, 0xFE, 0x00, /* 0x13E */ 0x75, 0x36, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, /* 0x13F */ 0xF0, 0x60, 0x64, 0x60, 0x62, 0x66, 0xFE, 0x00, /* 0x140 */ 0x70, 0x30, 0x30, 0x32, 0x30, 0x30, 0x78, 0x00, /* 0x141 */ 0xF0, 0x60, 0x70, 0x60, 0xE2, 0x66, 0xFE, 0x00, /* 0x142 */ 0x70, 0x30, 0x38, 0x30, 0x70, 0x30, 0x78, 0x00, /* 0x143 */ 0x0C, 0x18, 0xCC, 0xEC, 0xFC, 0xDC, 0xCC, 0x00, /* 0x144 */ 0x1C, 0x00, 0xB8, 0xCC, 0xCC, 0xCC, 0xCC, 0x00, /* 0x145 */ 0xCC, 0xEC, 0xFC, 0xDC, 0xCC, 0x30, 0x18, 0xF0, /* 0x146 */ 0x00, 0xB8, 0xCC, 0xCC, 0xCC, 0xCC, 0x30, 0xE0, /* 0x147 */ 0x6C, 0x38, 0xCC, 0xEC, 0xFC, 0xDC, 0xCC, 0x00, /* 0x148 */ 0x6C, 0x38, 0xB8, 0xCC, 0xCC, 0xCC, 0xCC, 0x00, /* 0x149 */ 0xC0, 0x80, 0x5C, 0x66, 0x66, 0x66, 0x66, 0x00, /* 0x14A */ 0x00, 0xCC, 0xEC, 0xFC, 0xDC, 0xCC, 0x0C, 0x38, /* 0x14B */ 0x00, 0xB8, 0xCC, 0xCC, 0xCC, 0xCC, 0x0C, 0x38, /* 0x14C */ 0xFE, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, /* 0x14D */ 0x00, 0xFC, 0x00, 0x78, 0xCC, 0xCC, 0x78, 0x00, /* 0x14E */ 0x6C, 0x38, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, /* 0x14F */ 0x6C, 0x38, 0x00, 0x78, 0xCC, 0xCC, 0x78, 0x00, /* 0x150 */ 0x36, 0x6C, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, /* 0x151 */ 0x36, 0x6C, 0x00, 0x78, 0xCC, 0xCC, 0x78, 0x00, /* 0x152 */ 0x7E, 0xDA, 0x88, 0x8C, 0x88, 0xDA, 0x7E, 0x00, /* 0x153 */ 0x00, 0x00, 0x6C, 0x92, 0x9E, 0x90, 0x6C, 0x00, /* 0x154 */ 0x0C, 0x18, 0xFC, 0x66, 0x7C, 0x6C, 0xE6, 0x00, /* 0x155 */ 0x0C, 0x18, 0xDC, 0x76, 0x62, 0x60, 0xF0, 0x00, /* 0x156 */ 0xFC, 0x66, 0x7C, 0x6C, 0xE6, 0x30, 0x18, 0xF0, /* 0x157 */ 0x00, 0xDC, 0x76, 0x62, 0x60, 0xF0, 0x30, 0xE0, /* 0x158 */ 0x6C, 0x38, 0xFC, 0x66, 0x7C, 0x6C, 0xE6, 0x00, /* 0x159 */ 0x6C, 0x38, 0xDC, 0x76, 0x62, 0x60, 0xF0, 0x00, /* 0x15A */ 0x0C, 0x18, 0x7C, 0xE0, 0x78, 0x0E, 0x7C, 0x00, /* 0x15B */ 0x0C, 0x18, 0x7C, 0xC0, 0x70, 0x1C, 0xF8, 0x00, /* 0x15C */ 0x7C, 0x82, 0x7C, 0xE0, 0x78, 0x0E, 0x7C, 0x00, /* 0x15D */ 0x7C, 0xC6, 0x7C, 0xC0, 0x70, 0x1C, 0xF8, 0x00, /* 0x15E */ 0x7C, 0xE0, 0x78, 0x0E, 0x7C, 0x18, 0x0C, 0x78, /* 0x15F */ 0x00, 0x7C, 0xC0, 0x70, 0x1C, 0xF8, 0x0C, 0x38, /* 0x160 */ 0x6C, 0x38, 0x7C, 0xE0, 0x78, 0x0E, 0x7C, 0x00, /* 0x161 */ 0x6C, 0x38, 0x7C, 0xC0, 0x70, 0x1C, 0xF8, 0x00, /* 0x162 */ 0xFC, 0x30, 0x30, 0x30, 0x78, 0x18, 0x0C, 0x38, /* 0x163 */ 0x10, 0x30, 0xFC, 0x30, 0x34, 0x18, 0x0C, 0x38, /* 0x164 */ 0x6C, 0x38, 0xFC, 0x30, 0x30, 0x30, 0x78, 0x00, /* 0x165 */ 0x12, 0x3A, 0xFC, 0x30, 0x30, 0x34, 0x18, 0x00, /* 0x166 */ 0xFC, 0xB4, 0x30, 0x30, 0xFC, 0x30, 0x78, 0x00, /* 0x167 */ 0x10, 0x30, 0xFC, 0x30, 0xFC, 0x34, 0x18, 0x00, /* 0x168 */ 0x76, 0xDC, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, /* 0x169 */ 0x76, 0xDC, 0x00, 0xCC, 0xCC, 0xCC, 0x7E, 0x00, /* 0x16A */ 0xFE, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, /* 0x16B */ 0x00, 0xFE, 0x00, 0xCC, 0xCC, 0xCC, 0x7E, 0x00, /* 0x16C */ 0x6C, 0x38, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, /* 0x16D */ 0x6C, 0x38, 0x00, 0xCC, 0xCC, 0xCC, 0x7E, 0x00, /* 0x16E */ 0x38, 0x6C, 0xFE, 0xD6, 0xC6, 0xC6, 0x7C, 0x00, /* 0x16F */ 0x38, 0x6C, 0x38, 0xDC, 0xCC, 0xCC, 0x7E, 0x00, /* 0x170 */ 0x36, 0x6C, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, /* 0x171 */ 0x36, 0x6C, 0x00, 0xCC, 0xCC, 0xCC, 0x7E, 0x00, /* 0x172 */ 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x30, 0x60, 0x3C, /* 0x173 */ 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0x7E, 0x18, 0x0E, /* 0x174 */ 0x7C, 0x82, 0xC6, 0xC6, 0xD6, 0xFE, 0x6C, 0x00, /* 0x175 */ 0x7C, 0xC6, 0x00, 0xC6, 0xD6, 0xFE, 0x6C, 0x00, /* 0x176 */ 0x7C, 0x82, 0xCC, 0xCC, 0x78, 0x30, 0x78, 0x00, /* 0x177 */ 0x7C, 0xC6, 0xCC, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, /* 0x178 */ 0xCC, 0x00, 0xCC, 0xCC, 0x78, 0x30, 0x78, 0x00, /* 0x179 */ 0x0C, 0x18, 0xFE, 0x8C, 0x18, 0x32, 0xFE, 0x00, /* 0x17A */ 0x0C, 0x18, 0xFC, 0x98, 0x30, 0x64, 0xFC, 0x00, /* 0x17B */ 0x10, 0x00, 0xFE, 0x8C, 0x18, 0x32, 0xFE, 0x00, /* 0x17C */ 0x10, 0x00, 0xFC, 0x98, 0x30, 0x64, 0xFC, 0x00, /* 0x17D */ 0x6C, 0x38, 0xFE, 0x8C, 0x18, 0x32, 0xFE, 0x00, /* 0x17E */ 0x6C, 0x38, 0xFC, 0x98, 0x30, 0x64, 0xFC, 0x00, /* 0x17F */ 0x38, 0x6C, 0x64, 0xE0, 0x60, 0x60, 0xE0, 0x00, /* euro character (0x20AC) */ /* 0x20AC*/ 0x3C, 0x62, 0xF8, 0x60, 0xF8, 0x62, 0x3C, 0x00 }; /* range definitions for the above binary data */ static int _al_rom_font_8x8_ranges[] = { 0x00000020, 0x0000007F, 0x000000A1, 0x000000FF, 0x00000100, 0x0000017F, 0x000020AC, 0x000020AC }; /* rule definitions for the Tri-add-rem implementation */ /* each rule has the following bits */ /* efddddba | cccccccc | cccccccc */ struct _tar_rule { uint8_t effect_bits; /* set/unset source bit(e) | want small triangles(f) | triangle bits(dddd) | stop bit(b) | scale factor bit (a) */ uint8_t care_bits; /* surrounding bits expected(cccccccc) */ uint8_t dont_care_bits; /* irrelevant surrounding bits(cccccccc) */ } __tar_rule; /* helper macros for defining binary constants (not all compilers(e.g. msvc) understand the 0b prefix) */ #define _BTOH(i,j,k,l,m,n,o,p) (uint8_t)((i << 7) | (j << 6) | (k << 5) | (l << 4) | (m << 3) | (n << 2) | (o << 1) | p) #define _B(n) _BTOH((0x10000000 & 0x##n ? 1 : 0), (0x01000000 & 0x##n ? 1 : 0), \ (0x00100000 & 0x##n ? 1 : 0), (0x00010000 & 0x##n ? 1 : 0), \ (0x00001000 & 0x##n ? 1 : 0), (0x00000100 & 0x##n ? 1 : 0), \ (0x00000010 & 0x##n ? 1 : 0), (0x00000001 & 0x##n ? 1 : 0)) static struct _tar_rule _tri_add_rem_rules[] = { /* first the exclusive rules */ /* http://www.allegro.cc/forums/thread/610499/958800#target */ /* set/unset source bit(e) | want small triangles(f) | triangle bits(dddd) /* stop bit(b) | scale factor bit (a) */ /* effect bits, care bits, don't care bits */ /* efddddba cccccccc cccccccc */ { _B(11111111), _B(00000000), _B(00000000) }, /* pixel surrounded by nothing */ { _B(01111111), _B(01011010), _B(10100101) }, /* empty surrounded by pixels left,top,right,bottom */ { _B(10000110), _B(01010000), _B(10100100) }, /* se pike */ { _B(10001010), _B(01001000), _B(10100001) }, /* sw pike */ { _B(10100010), _B(00001010), _B(00100101) }, /* nw pike */ { _B(10010010), _B(00010010), _B(10000101) }, /* ne pike */ { _B(00000000), _B(00000000), _B(00000000) }, /* e dent todo */ { _B(00000000), _B(00000000), _B(00000000) }, /* s dent todo */ { _B(00000000), _B(00000000), _B(00000000) }, /* w dent todo */ { _B(00000000), _B(00000000), _B(00000000) }, /* n dent todo */ { _B(11101010), _B(00001000), _B(00000000) }, /* w line ending */ { _B(10101010), _B(00001001), _B(00000000) }, /* ese corner */ { _B(10101010), _B(00101000), _B(00000000) }, /* ene corner */ { _B(11110010), _B(00000010), _B(00000000) }, /* n line ending */ { _B(10110010), _B(00000011), _B(00000000) }, /* sse corner */ { _B(10110010), _B(00000110), _B(00000000) }, /* ssw corner */ { _B(11010110), _B(00010000), _B(00000000) }, /* e line ending */ { _B(10010110), _B(00010100), _B(00000000) }, /* sww corner */ { _B(10010110), _B(10010000), _B(00000000) }, /* nww corner */ { _B(11001110), _B(01000000), _B(00000000) }, /* s line ending */ { _B(10001110), _B(11000000), _B(00000000) }, /* nwn corner */ { _B(10001110), _B(01100000), _B(00000000) }, /* nne corner */ { _B(11111011), _B(00000001), _B(00000000) }, /* nw line ending */ { _B(10110010), _B(00000101), _B(00000010) }, /* n pike */ { _B(10101010), _B(00100001), _B(00001000) }, /* w pike */ { _B(11110111), _B(00000100), _B(00000000) }, /* ne line ending */ { _B(10010110), _B(10000100), _B(00010000) }, /* e pike */ { _B(11011111), _B(10000000), _B(00000000) }, /* se line ending */ { _B(10001110), _B(10100000), _B(01000000) }, /* n pike */ { _B(11101111), _B(00100000), _B(00000000) }, /* sw line ending */ { _B(00000100), _B(00001010), _B(11110101) }, /* se diagonal */ { _B(00010000), _B(01001000), _B(10110111) }, /* ne diagonal */ { _B(00001000), _B(00010010), _B(11101101) }, /* ws diagonal */ { _B(00100000), _B(01010000), _B(10101111) } /* wn diagonal */ /* { _B(00000000), _B(00000000), _B(00000000) }, /* */ }; static int _tar_rules_count = sizeof(_tri_add_rem_rules) / sizeof(__tar_rule); #undef _BTOH #undef _B /* helper macros for getting bits from rules */ #define _RULE_SOURCE_PIXEL_STATE(r_ind) (_tri_add_rem_rules[r_ind].effect_bits & 0x80) #define _RULE_SMALL_TRIANGLE_BIT(r_ind) (_tri_add_rem_rules[r_ind].effect_bits & 0x40) #define _RULE_STOP_BIT(r_ind) (_tri_add_rem_rules[r_ind].effect_bits & 0x02) #define _RULE_SCALE_BIT(r_ind) (_tri_add_rem_rules[r_ind].effect_bits & 0x01) #define _RULE_TRIANGLE_BIT(r_ind, t_ind) (_tri_add_rem_rules[r_ind].effect_bits & (0x01 << (5-t_ind))) #define _RULE_CARE_BITS(r_ind) _tri_add_rem_rules[r_ind].care_bits #define _RULE_DONT_CARE_BITS(r_ind) _tri_add_rem_rules[r_ind].dont_care_bits /* check if a rule matches a given surrounding bits pattern * examples: * 11011101 (found bits = fb) * 00011010 (care bits = cb) * 01100101 (don't care bits = dcb) * fb XOR dcb (flatten uncared for ones and raise uncared for zeroes) * 10111000 = fbxdcb * fb AND fbxdcb (flatten zeroes raised in previos step) * 10011000 != cb so rule does not match pattern * * 01011101 (found bits = fb) * 00011010 (care bits = cb) * 01100101 (don't care bits = dcb) * fb XOR dcb (flatten uncared for ones and raise uncared for zeroes) * 00111000 = fbxdcb * fb AND fbxdcb (flatten zeroes raised in previos step) * 00011000 == cb so rule does match pattern */ static bool _tar_rule_match(uint8_t pattern, uint8_t rule_index) { return ( rule_index <= _tar_rules_count ) && ( ( ( pattern ^ _RULE_DONT_CARE_BITS(rule_index) ) & pattern ) == _RULE_CARE_BITS(rule_index) ); } /* lookup table entry for Tri-add-rem implementation */ struct _tar_entry { uint8_t rule_count_set; /* number of rule indices in the following parameter (for set source pixels) */ uint8_t* rule_indices_set; /* rules to apply to bit pattern (index in table) (for set source pixels) */ uint8_t rule_count_unset; /* same as above but holds rule information for unset source pixels */ uint8_t* rule_indices_unset; } __tar_entry; typedef struct _tar_entry* _p_tar_entry; /* lookup table for Tri-add-rem implementation */ _p_tar_entry _tar_lut = NULL; static int _tar_lut_size = 256; /* one entry per possible 8 bit pattern */ /* add a rule entry to the lookup table */ /* (does nothing if there are already 256 rules for that pattern) */ /* returns true on success */ static bool _add_rule_index_to_tar_lut(uint8_t pattern, uint8_t rule_index) { uint8_t** target_list = NULL; uint8_t* target_count = NULL; uint8_t* new_mem_loc = NULL; if(_tar_lut == NULL) return false; /* determine list and count to modify */ if(_RULE_SOURCE_PIXEL_STATE(rule_index)) { target_list = &(_tar_lut[pattern].rule_indices_set); target_count = &(_tar_lut[pattern].rule_count_set); } else { target_list = &(_tar_lut[pattern].rule_indices_unset); target_count = &(_tar_lut[pattern].rule_count_unset); } if(*target_count < 255) *target_count += 1; else return false; /* prepare memory for new rule index */ if(*target_count == 1) { *target_list = (uint8_t*) malloc(sizeof(uint8_t)); new_mem_loc = *target_list; } else { /* if there is already an exclusive rule, do not add the new one but report no error either */ if(_RULE_STOP_BIT(*target_list[0])) { *target_count--; return true; } new_mem_loc = (uint8_t*) realloc(*target_list, *target_count * sizeof(uint8_t)); *target_list = new_mem_loc; } if(*target_list == NULL) return false; /* write rule index to end of list */ new_mem_loc[*target_count-1] = rule_index; return true; } /* initializes the lookup table for the Tri-add-rem implementation */ static void _init_tar_lut(void) { int pattern; int rule_index; if(!_tar_lut_initialized) { atexit(_free_tar_lut); _tar_lut = (_p_tar_entry) calloc(_tar_lut_size, sizeof(__tar_entry)); /* for each possible 8bit pattern, examine tri-add-rem rules */ /* and add their indices to the lookup table entries if they match */ for(pattern=0; pattern<_tar_lut_size; pattern++) { for(rule_index=0; rule_index<_tar_rules_count; rule_index++) { if(_tar_rule_match(pattern, rule_index)) { if(!_add_rule_index_to_tar_lut(pattern, rule_index)) { _free_tar_lut(); return; } } } } _tar_lut_initialized = true; } } /* frees all memory occupied by the lookup table for the Tri-add-rem implementation */ static void _free_tar_lut(void) { int i; /* free lists in each table entry */ for(i=0; i<_tar_lut_size; i++) { free(_tar_lut[i].rule_indices_set); free(_tar_lut[i].rule_indices_unset); } /* free table itself */ free(_tar_lut); } /* get glyph bit * helps with determining a specific bit from a given * glyph at a given pixel coordinate * (part of the Tri-add-rem implementation) */ static int _al_get_rom_font_8x8_glyph_bit(int glyph_index, int x, int y) { /* out of bounds bits will be reported as unset */ if ( x < 0 || x > 7 || y < 0 || y > 7 || ( glyph_index >= (sizeof(_al_rom_font_8x8) / 8) ) ) return 0; return (_al_rom_font_8x8[glyph_index * 8 + y] & ( 0x01 << (0x07 - x) )) ? 1 : 0; } /* get the bits surrounding a given glyph bit * determines the surrounding bits * 0, 1, 2, * 3, xy, 4, * 5, 6, 7 * of the given pixel coordinate in the given glyph * of the builtin font data * returns them in a byte where the least significant * bit contains surrounding bit 7 and the most significant * one contains bit 0 * (part of the Tri-add-rem implementation) */ static uint8_t _al_get_rom_font_8x8_surround_bits(int glyph_index, int x, int y) { uint8_t r = 0; r += _al_get_rom_font_8x8_glyph_bit(glyph_index, x-1, y-1); r<<=1; r += _al_get_rom_font_8x8_glyph_bit(glyph_index, x, y-1); r<<=1; r += _al_get_rom_font_8x8_glyph_bit(glyph_index, x+1, y-1); r<<=1; r += _al_get_rom_font_8x8_glyph_bit(glyph_index, x-1, y); r<<=1; r |= _al_get_rom_font_8x8_glyph_bit(glyph_index, x+1, y); r<<=1; r |= _al_get_rom_font_8x8_glyph_bit(glyph_index, x-1, y+1); r<<=1; r |= _al_get_rom_font_8x8_glyph_bit(glyph_index, x, y+1); r<<=1; r |= _al_get_rom_font_8x8_glyph_bit(glyph_index, x+1, y+1); return r; } /* special version of 'put_pixel' to really replace the target data with the given color */ static void _place_color_data_8888_le(ALLEGRO_LOCKED_REGION* region, int x, int y, uint32_t* pixel) { void* target = (uint8_t*)region->data + y * region->pitch + x * region->pixel_size; *(uint32_t*)target = *pixel; } /* draw a special case triangle for Tri-add-rem implementation */ static void _draw_tar_triangle(ALLEGRO_LOCKED_REGION* region, uint32_t* pixel, int tx, int ty, int fat_pixel_sidelength, bool small_tri, int t_number) { int r_tx; int r_ty; int step_x; int step_y; int tri_sidelength = fat_pixel_sidelength >> (small_tri ? 2: 1); int cur_line_length; int i,j; int x,y; if(small_tri && tri_sidelength == 0) { tri_sidelength++; } if(tri_sidelength < 1 || t_number > 3) return; /* prepare triangle render settings */ if(t_number == 0 || t_number == 1) { r_ty = ty; step_y = 1; } else { r_ty = ty + fat_pixel_sidelength - 1; step_y = -1; } if(t_number == 0 || t_number == 2) { r_tx = tx; step_x = 1; } else { r_tx = tx + fat_pixel_sidelength - 1; step_x = -1; } /* render triangle pixels */ cur_line_length = tri_sidelength; for(j=0; j 0) ? 1 : 0); int ranges = (sizeof(_al_rom_font_8x8_ranges) / sizeof(int)) / 2; ALLEGRO_BITMAP *bmp_glyphs_mem = NULL; ALLEGRO_LOCKED_REGION *bmp_locked_region = NULL; ALLEGRO_BITMAP *bmp_glyphs_vid = NULL; ALLEGRO_BITMAP *bmp_prev_target = NULL; ALLEGRO_FONT *pRetVal = NULL; int i = 0; int j = 0; int k = 0; bool set = 0; int c_col = 0; int c_row = 0; int tx; int ty; unsigned int x; unsigned int y; uint32_t col_tp = 0x00000000; /* black */ uint32_t col_fg = 0xFFFFFFFF; /* white */ uint32_t* col_t; uint8_t char_line = 0; uint8_t shifted = 0; uint8_t surround_bits = 0; uint32_t* col_tri; bool small_tri = false; bool tri[4]; int t; int rule_index = 0; uint8_t* source_list = NULL; uint8_t source_count = 0; int lind = 0; if(scale == 0) return NULL; al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); /* putting pixels is much faster on a memory bitmap */ /* create large bitmap onto which to render the glyphs */ bmp_glyphs_mem = al_create_bitmap((glyphs_per_row * 8 + glyphs_per_row + 1) * scale, (needed_rows * 8 + needed_rows + 1) * scale); bmp_prev_target = al_get_target_bitmap(); if(bmp_glyphs_mem != NULL) { al_set_target_bitmap(bmp_glyphs_mem); al_clear_to_color(al_map_rgba(255,255,0,255)); bmp_locked_region = al_lock_bitmap(bmp_glyphs_mem, ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE, ALLEGRO_LOCK_READWRITE); for(i=0; i < glyph_count; i++) { /* for each glyph.. */ c_col = i % glyphs_per_row; c_row = i / glyphs_per_row; for(j=0; j<8; j++) { /* for each of the 8 lines per character.. */ char_line = _al_rom_font_8x8[i*8+j]; /* decode and draw(scaled) each of the 8 pixels of the current line.. */ for(k=0; k<8; k++) { shifted = (char_line >> k); set = shifted & 0x01; /* determine upper left corner of "fat-pixel"(square) */ tx = ( (c_col * 9 + 1) + (7 - k) ) * scale; ty = ( (c_row * 9 + 1 + j) ) * scale; col_t = set ? &col_fg : &col_tp; /* draw scaled "fat pixel"(square) */ for(y=0; y 1 && use_tar) { _init_tar_lut(); /* is only calculated once if successful */ col_tri = set ? &col_tp : &col_fg; small_tri = false; for(t=0; t<4; t++) tri[t] = false; surround_bits = _al_get_rom_font_8x8_surround_bits(i, (7 - k), j); /* collect triangles to apply from all relevant rules.. */ if(_tar_lut_initialized) { /* ..lookup table is present, check previously determined rules */ source_count = set ? _tar_lut[surround_bits].rule_count_set : _tar_lut[surround_bits].rule_count_unset; source_list = set ? _tar_lut[surround_bits].rule_indices_set : _tar_lut[surround_bits].rule_indices_unset; for(lind=0; lind