#include #include #define WMAX 256 #define HMAX 256 #define RL32(arr, ofs) (arr[ofs] + (arr[ofs+1] << 8) + (arr[ofs+2] << 16) + (arr[ofs+3] << 24)) int main(int argc, char **argv) { uint8_t header[54], image[HMAX][WMAX]; int x, y, w, h, bpp; FILE *f; /* read 8-bit images as they are, RGB images as grayscale */ if (!(f = fopen(argv[1], "rb"))) { fprintf(stderr, "failed to open %s\n" , argv[1]); return 1; } fread(header, 54, 1, f); w = RL32(header, 18); h = RL32(header, 22); bpp = header[28] + (header[29] << 8); fseek(f, RL32(header, 10), SEEK_SET); fprintf(stderr, "%ix%i %i bpp\n", w, h, bpp); if (w > WMAX || h > HMAX) { fprintf(stderr, "image too large\n"); return -1; } for (y = h-1; y >= 0; y--) { switch(bpp) { case 8: fread(image[y], w, 1, f); break; case 24: case 32: for (x = 0; x < w; x++) { int temp = getc(f) + getc(f) + getc(f); if (bpp == 32) getc(f); image[y][x] = temp / 3; } break; default: fprintf(stderr, "can't handle %i-bit BMPs\n", bpp); } /* align */ if (w*(bpp/8) & 3) fseek(f, 4 - (w*(bpp/8) & 3), SEEK_CUR); } fclose(f); printf("SVLOGOLINES equ %i\n", h); printf("\tMAC LOGO_PF0PF1\n"); printf("SVLogoPF0PF1\n"); for (y = h-1; y >= 0; y--) printf("\tbyte %%%i%i%i%i%i%i%i%i\n", image[y][15] < 128, image[y][14] < 128, image[y][13] < 128, image[y][12] < 128, image[y][0] < 128, image[y][1] < 128, image[y][2] < 128, image[y][3] < 128); printf(" CHECK_ALIGN SVLogoPF0PF1\n"); printf("\tENDM\n"); printf("\tMAC LOGO_PF2\n"); printf("SVLogoPF2\n"); for (y = h-1; y >= 0; y--) printf("\tbyte %%%i%i%i%i%i%i%i%i\n", image[y][11] < 128, image[y][10] < 128, image[y][9] < 128, image[y][8] < 128, image[y][7] < 128, image[y][6] < 128, image[y][5] < 128, image[y][4] < 128); printf(" CHECK_ALIGN SVLogoPF2\n"); printf("\tENDM\n"); printf("\tMAC LOGO_PF1\n"); printf("SVLogoPF1\n"); for (y = h-1; y >= 0; y--) printf("\tbyte %%%i%i%i%i%i%i%i%i\n", image[y][16] < 128, image[y][17] < 128, image[y][18] < 128, image[y][19] < 128, image[y][20] < 128, image[y][21] < 128, image[y][22] < 128, image[y][23] < 128); printf(" CHECK_ALIGN SVLogoPF1\n"); printf("\tENDM\n"); return 0; }