// --- public domain, no warranty. #include #include #include #define XCHAR_SIZE 16 // 文字幅(X) #define YCHAR_SIZE 16 // 文字幅(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 (Y_PIXEL * X_PIXEL / 8) 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; } // 8x8単位のデコード static unsigned char *decode_8x8(unsigned char *c, int dest_y, int dest_x) { int x, y, mask; for (y = 0; y < 8; y++) { for (x = 0, mask = 0x80; x < 8; x++, mask >>= 1) { PixBuf[dest_y + y][dest_x + x] = *c & mask; } c++; } return c; } // 1文字単位のデコード static void decode_char(unsigned char *c, int dest_y, int dest_x) { c = decode_8x8(c, dest_y + 0, dest_x + 0); // 左上 c = decode_8x8(c, dest_y + 0, dest_x + 8); // 右上 c = decode_8x8(c, dest_y + 8, dest_x + 0); // 左下 c = decode_8x8(c, dest_y + 8, dest_x + 8); // 右下 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 * 16, x * 16); } } 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); decode_all(RomBuf); display_result(); // fin1: fclose(fp); fin0: return 0; }