more work on pages and ressources.
This commit is contained in:
@@ -67,6 +67,7 @@ static int AQH_Tool_ReadAndDumpBmpFile(const char *fname);
|
||||
static int AQH_Tool_ExportBmpFile(const char *fname);
|
||||
|
||||
static int _exportBmp_1bpp(const BMP_FILE *bf);
|
||||
static int _exportBmp_gray8bpp(const BMP_FILE *bf);
|
||||
|
||||
static BMP_FILEHEADER *_fileHeader_new();
|
||||
static void _fileHeader_free(BMP_FILEHEADER *fh);
|
||||
@@ -166,6 +167,8 @@ int AQH_Tool_ExportBmpFile(const char *fname)
|
||||
_dumpBmpImageHeader(bf->imageHeader);
|
||||
if (bf->imageHeader->bitsPerPixel==1)
|
||||
rv=_exportBmp_1bpp(bf);
|
||||
else if (bf->imageHeader->bitsPerPixel==8)
|
||||
rv=_exportBmp_gray8bpp(bf);
|
||||
else {
|
||||
fprintf(stderr, "Invalid bits per pixel (%d)", bf->imageHeader->bitsPerPixel);
|
||||
rv=2;
|
||||
@@ -220,6 +223,69 @@ int _exportBmp_1bpp(const BMP_FILE *bf)
|
||||
|
||||
|
||||
|
||||
int _exportBmp_gray8bpp(const BMP_FILE *bf)
|
||||
{
|
||||
const uint8_t *ptrBuffer;
|
||||
uint32_t lenBuffer;
|
||||
uint32_t offsPixels;
|
||||
const uint8_t *ptrPixels;
|
||||
int imageWidth;
|
||||
int imageHeight;
|
||||
int rowWidthInBytes;
|
||||
int columns;
|
||||
int y;
|
||||
|
||||
ptrBuffer=(const uint8_t *) GWEN_Buffer_GetStart(bf->buffer);
|
||||
lenBuffer=GWEN_Buffer_GetUsedBytes(bf->buffer);
|
||||
offsPixels=bf->fileHeader->offsPixels;
|
||||
ptrPixels=ptrBuffer+offsPixels;
|
||||
imageWidth=bf->imageHeader->imgWidth;
|
||||
imageHeight=bf->imageHeader->imgHeight;
|
||||
columns=imageWidth;
|
||||
rowWidthInBytes=4*((columns+3)/4); /* BMPs have multiple of 4 bytes per row! */
|
||||
fprintf(stdout, "imgData: \n");
|
||||
fprintf(stdout, " .dw %d, %d\n", imageWidth, imageHeight);
|
||||
|
||||
for (y=imageHeight-1; y>=0; y--) {
|
||||
const uint8_t *rowPtr;
|
||||
int x;
|
||||
uint8_t currentByte=0;
|
||||
int writtenBytes=0;
|
||||
int packedPixels=0;
|
||||
|
||||
fprintf(stdout, " .db ");
|
||||
rowPtr=ptrPixels+(y*rowWidthInBytes);
|
||||
for (x=0; x<columns; x++) {
|
||||
uint8_t pixel;
|
||||
uint8_t newPix;
|
||||
|
||||
pixel=rowPtr[x];
|
||||
switch(pixel) {
|
||||
case 0x00: newPix=0b01; break; /* outline color */
|
||||
case 0x60: newPix=0b10; break; /* color 1 */
|
||||
case 0xc0: newPix=0b11; break; /* color 2 */
|
||||
case 0xff: newPix=0b00; break; /* background color */
|
||||
default: newPix=0b00; break; /* background color */
|
||||
}
|
||||
currentByte<<=2;
|
||||
currentByte|=newPix;
|
||||
packedPixels++;
|
||||
if (packedPixels==4) {
|
||||
if (writtenBytes)
|
||||
fprintf(stdout, ", ");
|
||||
fprintf(stdout, "0x%02x", currentByte);
|
||||
writtenBytes++;
|
||||
packedPixels=0;
|
||||
currentByte=0;
|
||||
}
|
||||
}
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BMP_FILE *BMP_File_new(const char *fname)
|
||||
|
||||
Reference in New Issue
Block a user