// // main.c // Group5 // // Created by Larry Bank on 8/19/24. // #include #include "../../../src/g5enc.inl" // // Read a Windows BMP file into memory // uint8_t * ReadBMP(const char *fname, int *width, int *height, int *bpp, unsigned char *pPal) { int y, w, h, bits, offset; uint8_t *s, *d, *pTemp, *pBitmap; int pitch, bytewidth; int iSize, iDelta; FILE *infile; infile = fopen(fname, "r+b"); if (infile == NULL) { printf("Error opening input file %s\n", fname); return NULL; } // Read the bitmap into RAM fseek(infile, 0, SEEK_END); iSize = (int)ftell(infile); fseek(infile, 0, SEEK_SET); pBitmap = (uint8_t *)malloc(iSize); pTemp = (uint8_t *)malloc(iSize); fread(pTemp, 1, iSize, infile); fclose(infile); if (pTemp[0] != 'B' || pTemp[1] != 'M' || pTemp[14] < 0x28) { free(pBitmap); free(pTemp); printf("Not a Windows BMP file!\n"); return NULL; } w = *(int32_t *)&pTemp[18]; h = *(int32_t *)&pTemp[22]; bits = *(int16_t *)&pTemp[26] * *(int16_t *)&pTemp[28]; if (bits <= 8 && pPal != NULL) { // it has a palette, copy it uint8_t *p = pPal; for (int i=0; i<(1<> 3; } else { bytewidth = (w * bits) >> 3; } pitch = (bytewidth + 3) & 0xfffc; // DWORD aligned // move up the pixels d = pBitmap; s = &pTemp[offset]; iDelta = pitch; if (h > 0) { iDelta = -pitch; s = &pTemp[offset + (h-1) * pitch]; } else { h = -h; } for (y=0; y \n"); return -1; } 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(OUTSIZE); rc = g5_encode_init(&g5enc, w, h, pOut, OUTSIZE); for (y=0; y