diff --git a/imageconvert/main.c b/imageconvert/main.c index a39624a..0d747d8 100644 --- a/imageconvert/main.c +++ b/imageconvert/main.c @@ -124,13 +124,74 @@ void AddHexBytes(FILE *f, void *pData, int iLen, int bLast) fprintf(f, "};\n"); } } /* AddHexBytes() */ +// +// The user passed a file with the wrong bit depth (not 1) +// convert to 1-bpp by converting each color to 0 or 1 based on the gray level +// +void ConvertTo1Bpp(uint8_t *pBMP, int w, int h, int iBpp, uint8_t *palette) +{ + int g, x, y, iDelta, iPitch, iDestPitch; + uint8_t *s, *d, *pPal, u8, count; + + iPitch = (w * iBpp)/8; + iPitch = (iPitch + 3) & 0xfffc; + iDestPitch = (w+7)/8; + iDestPitch = (iDestPitch + 3) & 0xfffc; // round to nearest "DWORD" + iDelta = iBpp/8; + for (y=0; y>4) * 4]; + g = (pPal[0] + pPal[1]*2 + pPal[2])/4; + } + break; + } // switch on bpp + if (g >= 128) u8 |= 1; // white + count--; + if (count == 0) { // byte is full, move on + *d++ = u8; + u8 = 0; + count = 8; + } + } // for x + } // for y +} /* ConvertTo1Bpp() */ int main(int argc, const char * argv[]) { - uint8_t *pBMP, *pOut; + uint8_t *s, *pBMP, *pOut; int rc, w, h, y, bpp; int iOutSize, iPitch; G5ENCIMAGE g5enc; BB_BITMAP bbbm; + uint8_t palette[1024]; int bHFile; // flag indicating if the output will be a .H file of hex data printf("Group5 image conversion tool\n"); @@ -141,48 +202,48 @@ int main(int argc, const char * argv[]) { pOut = (uint8_t *)argv[2] + strlen(argv[2]) - 1; bHFile = (pOut[0] == 'H' || pOut[0] == 'h'); // output an H file? - pBMP = ReadBMP(argv[1], &w, &h, &bpp, NULL); - if (bpp == 1) { - uint8_t *s = pBMP; - - printf("bmp size %d x %d\n", w, h); - iPitch = (w+7) >> 3; - pOut = (uint8_t *)malloc(iPitch * h); - rc = g5_encode_init(&g5enc, w, h, pOut, iPitch * h); - for (y=0; y> 3; + pOut = (uint8_t *)malloc(iPitch * h); + rc = g5_encode_init(&g5enc, w, h, pOut, iPitch * h); + for (y=0; y