Created
July 31, 2018 15:40
-
-
Save tschak909/2de35b3fbeae6db8ee13e6bf156ba7f0 to your computer and use it in GitHub Desktop.
platoterm character set scaling test harness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
// Pulled in typedef from protocol.h | |
typedef short padWord; | |
typedef padWord charData[8]; | |
// const unsigned short word_data[]={0x5555,0xAAAA,0x5555,0xAAAA,0x5555,0xAAAA,0x5555,0xAAAA}; // every other dot. | |
// The example line. This renders well enough with alg A | |
//const unsigned short word_data[]={0x0003, 0x000F, 0x003F, 0x00FF, 0x03FF, 0x0FFF, 0x3FFC, 0xFFF0}; // A sort of line. | |
// Current test data from checkers | |
const unsigned short word_data[]={0XFFFF, 0XE00F, 0XE00F, 0XE67F, 0XE67F, 0XE07F, 0XE07F, 0XFFFF}; | |
static unsigned char char_data[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | |
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; | |
static unsigned char shrunk_char_data[]={0x00,0x00,0x00,0x00,0x00,0x00}; | |
static unsigned char MTAB[]={0x7F,0xBf,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE}; // flip one bit off (AND) | |
static unsigned char BTAB[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; // flip one bit on (OR) | |
static unsigned char BTAB_5[]={0x08,0x10,0x10,0x20,0x20,0x40,0x80,0x80}; // flip one bit on for the 5x6 matrix (OR) | |
static unsigned char TAB_0_5i[]={0x00,0x00,0x00,0x01,0x01,0x01,0x02,0x02,0x03,0x03,0x04,0x04,0x04,0x05,0x05,0x05}; | |
static unsigned char TAB_0_5[]={0x05,0x05,0x05,0x04,0x04,0x04,0x03,0x03,0x02,0x02,0x01,0x01,0x01,0x00,0x00,0x00}; | |
static unsigned char TAB_0_4[]={0x00,0x00,0x01,0x02,0x02,0x03,0x03,0x04}; // return 0..4 given index 0 to 7 | |
static unsigned char PIX_THRESH[]={0x03,0x02,0x03,0x03,0x02, // Pixel threshold table. | |
0x03,0x02,0x03,0x03,0x02, | |
0x02,0x01,0x02,0x02,0x01, | |
0x02,0x01,0x02,0x02,0x01, | |
0x03,0x02,0x03,0x03,0x02, | |
0x03,0x02,0x03,0x03,0x02}; | |
static unsigned char PIX_WEIGHTS[]={0x00,0x00,0x00,0x00,0x00, // Pixel weights | |
0x00,0x00,0x00,0x00,0x00, | |
0x00,0x00,0x00,0x00,0x00, | |
0x00,0x00,0x00,0x00,0x00, | |
0x00,0x00,0x00,0x00,0x00, | |
0x00,0x00,0x00,0x00,0x00}; | |
static unsigned char TAB_0_25[]={0,5,10,15,20,25}; // Given index 0 of 5, return multiple of 5. | |
static unsigned char pix_cnt; | |
static unsigned char LEND; | |
static unsigned char curr_word; | |
static unsigned char u,v,w; | |
static unsigned short temp_word; | |
static unsigned char temp_byte; | |
void printBits(size_t const size, void const * const ptr) | |
{ | |
unsigned char *b = (unsigned char*) ptr; | |
unsigned char byte; | |
int i, j; | |
for (i=size-1;i>=0;i--) | |
{ | |
for (j=7;j>=0;j--) | |
{ | |
byte = (b[i] >> j) & 1; | |
if (byte==1) | |
printf("*"); | |
else | |
printf(" "); | |
} | |
} | |
puts(""); | |
} | |
void | |
main(void) | |
{ | |
/*----------------------------------------------------------------------*/ | |
// Transpose character data. | |
for (curr_word=0;curr_word<8;curr_word++) | |
{ | |
temp_word=word_data[curr_word]; | |
for (u=16; u-->0; ) | |
{ | |
if (temp_word & 1<<u) | |
{ | |
pix_cnt++; | |
PIX_WEIGHTS[TAB_0_25[TAB_0_5[u]]+TAB_0_4[curr_word]]++; | |
char_data[u^0x0F&0x0F]|=BTAB[curr_word]; | |
} | |
} | |
} | |
printf("pix_cnt %d\n",pix_cnt); | |
if ((54 <= pix_cnt) && (pix_cnt < 85)) | |
{ | |
// Algorithm A - approx Half of pixels are set | |
printf("using algorithm A\n\n"); | |
for (v=6; v-->0; ) | |
{ | |
for (w=5; w-->0; ) | |
{ | |
shrunk_char_data[v]&=MTAB[w]; | |
if (PIX_WEIGHTS[TAB_0_25[v]+w] >= PIX_THRESH[TAB_0_25[v]+w]) | |
shrunk_char_data[v]|=BTAB[w]; | |
} | |
} | |
} | |
else if (pix_cnt < 54 || pix_cnt >= 85) | |
{ | |
// Algorithm B - Sparsely or heavily populated bitmaps | |
printf("using algorithm B\n\n"); | |
for (v=16; v-->0; ) | |
{ | |
for (w=8; w-->0; ) | |
{ | |
if (char_data[v] & (1<<w)) | |
{ | |
shrunk_char_data[TAB_0_5i[v]]|=BTAB_5[w]; | |
} | |
} | |
} | |
} | |
/*----------------------------------------------------------------------*/ | |
// 8x16 bit field dump | |
for (u=0; u<16; ++u) | |
{ | |
printBits(sizeof(char_data[u]),&char_data[u]); | |
} | |
// pixel weights table dump | |
printf("-----------\n"); | |
printf("|%d|%d|%d|%d|%d|\n",PIX_WEIGHTS[0],PIX_WEIGHTS[1],PIX_WEIGHTS[2],PIX_WEIGHTS[3],PIX_WEIGHTS[4]); | |
printf("|%d|%d|%d|%d|%d|\n",PIX_WEIGHTS[5],PIX_WEIGHTS[6],PIX_WEIGHTS[7],PIX_WEIGHTS[8],PIX_WEIGHTS[9]); | |
printf("|%d|%d|%d|%d|%d|\n",PIX_WEIGHTS[10],PIX_WEIGHTS[11],PIX_WEIGHTS[12],PIX_WEIGHTS[13],PIX_WEIGHTS[14]); | |
printf("|%d|%d|%d|%d|%d|\n",PIX_WEIGHTS[15],PIX_WEIGHTS[16],PIX_WEIGHTS[17],PIX_WEIGHTS[18],PIX_WEIGHTS[19]); | |
printf("|%d|%d|%d|%d|%d|\n",PIX_WEIGHTS[20],PIX_WEIGHTS[21],PIX_WEIGHTS[22],PIX_WEIGHTS[23],PIX_WEIGHTS[24]); | |
printf("|%d|%d|%d|%d|%d|\n",PIX_WEIGHTS[25],PIX_WEIGHTS[26],PIX_WEIGHTS[27],PIX_WEIGHTS[28],PIX_WEIGHTS[29]); | |
printf("-----------\n"); | |
printf("\n\n"); | |
// 8x16 bit field dump | |
for (u=0; u<6; ++u) | |
{ | |
printBits(sizeof(shrunk_char_data[u]),&shrunk_char_data[u]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment