// --- public domain, no warranty. #include #include #include #define XCHAR_SIZE 12 // 文字幅(X) #define YCHAR_SIZE 8 // 文字幅(Y) #define XCHARS 96 // 並べる文字の数(X) #define YCHARS 96 // 並べる文字の数(Y) #define X_PIXEL (XCHAR_SIZE * XCHARS) // 画素数(X) #define Y_PIXEL (YCHAR_SIZE * YCHARS) // 画素数(Y) #define ROMBUF_SIZE 524288 // XXX static unsigned char PixBuf[Y_PIXEL][X_PIXEL]; static unsigned char RomBuf[ROMBUF_SIZE]; // デコード結果の表示 static void display_result(void) { int x, y; printf("# ImageMagick pixel enumeration: %d,%d,255,RGB\n", X_PIXEL, Y_PIXEL); for (y = 0; y < Y_PIXEL; y++) { for (x = 0; x < X_PIXEL; x++) { printf("%d,%d: ", x, y); if (!PixBuf[y][x]) { puts("(0,0,0)"); } else { puts("(255,255,255)"); } } } return; } /* 2line/24bit(12bit-12bit) -> 2line/32bit(12bit-4bit-12bit-4bit) */ static void zen12_align(char *in, char *out, int line) { int i, ix_i, ix_o; for (i = ix_i = ix_o = 0; i < line / 2; i++, ix_i += 3, ix_o += 4) { out[ix_o + 0] = in[ix_i + 0]; out[ix_o + 1] = in[ix_i + 1] & 0xf0; out[ix_o + 2] = ((in[ix_i + 1] << 4) | ((in[ix_i + 2] >> 4) & 0x0f)); out[ix_o + 3] = in[ix_i + 2] << 4; } return; } // 1文字単位のデコード static void decode_char(unsigned char *c, int dest_y, int dest_x) { unsigned char d[24]; unsigned short n; int i, x, y; zen12_align(c, d, YCHAR_SIZE); for (y = 0; y < YCHAR_SIZE; y++) { n = (d[y * 2] << 8) | d[y * 2 + 1]; for (x = 0; x < XCHAR_SIZE; x++) { PixBuf[dest_y + y][dest_x + x] = (n & (0x8000 >> x)) ? 1 : 0; } } return; } // 全文字のデコード static void decode_all(unsigned char *c) { int x, y, idx; for (y = 0; y < YCHARS; y++) { for (x = 0; x < XCHARS; x++) { idx = y * XCHARS + x; decode_char(c + idx * (XCHAR_SIZE * YCHAR_SIZE / 8), y * YCHAR_SIZE, x * XCHAR_SIZE); } } return; } int main(int argc, char *argv[]) { FILE *fp; if (argc < 2) { printf("usage: %s [filename]\n", argv[0]); goto fin0; } memset(RomBuf, ~0, sizeof(RomBuf)); fp = fopen(argv[1], "rb"); if (fp == NULL) { printf("file open error\n"); goto fin0; } fread(RomBuf, 1, sizeof(RomBuf), fp); // 12×8ドットフォントへのoffsetを加算 decode_all(RomBuf + 0x00024000); display_result(); // fin1: fclose(fp); fin0: return 0; }