Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rohoog/bmp reading #109

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RaspberryPi&JetsonNano/c/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/
epd
9 changes: 5 additions & 4 deletions RaspberryPi_JetsonNano/c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ DEBUG = -D DEBUG
USELIB_RPI = USE_WIRINGPI_LIB
# USELIB_RPI = USE_DEV_LIB

LIB_RPI=-Wl,--gc-sections
ifeq ($(USELIB_RPI), USE_BCM2835_LIB)
LIB_RPI = -lbcm2835 -lm
LIB_RPI += -lbcm2835 -lm
else ifeq ($(USELIB_RPI), USE_WIRINGPI_LIB)
LIB_RPI = -lwiringPi -lm
LIB_RPI += -lwiringPi -lm
else ifeq ($(USELIB_RPI), USE_DEV_LIB)
LIB_RPI = -lm
LIB_RPI += -lm
endif
DEBUG_RPI = -D $(USELIB_RPI) -D RPI

Expand All @@ -42,7 +43,7 @@ JETSON: JETSON_DEV JETSON_epd

TARGET = epd
CC = gcc
MSG = -g -O0 -Wall
MSG = -g -O -ffunction-sections -fdata-sections -Wall
CFLAGS += $(MSG)

RPI_epd:${OBJ_O}
Expand Down
55 changes: 22 additions & 33 deletions RaspberryPi_JetsonNano/c/lib/GUI/GUI_BMPfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,18 @@ UBYTE GUI_ReadBmp(const char *path, UWORD Xstart, UWORD Ystart)

// Binary file open
if((fp = fopen(path, "rb")) == NULL) {
Debug("Cann't open the file!\n");
Debug("Can't open the file!\n");
exit(0);
}

// Set the file pointer from the beginning
fseek(fp, 0, SEEK_SET);
fread(&bmpFileHeader, sizeof(BMPFILEHEADER), 1, fp); //sizeof(BMPFILEHEADER) must be 14
fread(&bmpInfoHeader, sizeof(BMPINFOHEADER), 1, fp); //sizeof(BMPFILEHEADER) must be 50
fread(&bmpInfoHeader, sizeof(BMPINFOHEADER), 1, fp); //sizeof(BMPINFOHEADER) must be 50
printf("pixel = %d * %d\r\n", bmpInfoHeader.biWidth, bmpInfoHeader.biHeight);

UWORD Image_Width_Byte = (bmpInfoHeader.biWidth % 8 == 0)? (bmpInfoHeader.biWidth / 8): (bmpInfoHeader.biWidth / 8 + 1);
UWORD Bmp_Width_Byte = (Image_Width_Byte % 4 == 0) ? Image_Width_Byte: ((Image_Width_Byte / 4 + 1) * 4);
UBYTE Image[Image_Width_Byte * bmpInfoHeader.biHeight];
memset(Image, 0xFF, Image_Width_Byte * bmpInfoHeader.biHeight);
UWORD Image_Width_Byte = (bmpInfoHeader.biWidth + 7) / 8;
UWORD Bmp_Width_Byte = (Image_Width_Byte + 3) & ~3;

// Determine if it is a monochrome bitmap
int readbyte = bmpInfoHeader.biBitCount;
Expand All @@ -85,16 +83,11 @@ UBYTE GUI_ReadBmp(const char *path, UWORD Xstart, UWORD Ystart)
}

// Determine black and white based on the palette
UWORD i;
UWORD Bcolor, Wcolor;
UWORD bmprgbquadsize = pow(2, bmpInfoHeader.biBitCount);// 2^1 = 2
BMPRGBQUAD bmprgbquad[bmprgbquadsize]; //palette
// BMPRGBQUAD bmprgbquad[2]; //palette

for(i = 0; i < bmprgbquadsize; i++){
// for(i = 0; i < 2; i++) {
fread(&bmprgbquad[i], sizeof(BMPRGBQUAD), 1, fp);
}
fread(bmprgbquad, sizeof(BMPRGBQUAD), bmprgbquadsize, fp);
if(bmprgbquad[0].rgbBlue == 0xff && bmprgbquad[0].rgbGreen == 0xff && bmprgbquad[0].rgbRed == 0xff) {
Bcolor = BLACK;
Wcolor = WHITE;
Expand All @@ -103,36 +96,32 @@ UBYTE GUI_ReadBmp(const char *path, UWORD Xstart, UWORD Ystart)
Wcolor = BLACK;
}

// Read image data into the cache
UWORD x, y;
UBYTE Rdata;
// Read image data and paint the pixels
UWORD x, xb, y, yp;
UDOUBLE Rdata[1];
UBYTE color;
fseek(fp, bmpFileHeader.bOffset, SEEK_SET);
for(y = 0; y < bmpInfoHeader.biHeight; y++) {//Total display column
for(x = 0; x < Bmp_Width_Byte; x++) {//Show a line in the line
if(fread((char *)&Rdata, 1, readbyte, fp) != readbyte) {
for(xb = 0; xb < Bmp_Width_Byte; xb+=sizeof Rdata) {//Show a line in the line
readbyte = sizeof Rdata;
if (Bmp_Width_Byte-xb < readbyte) readbyte=Bmp_Width_Byte-xb;
if(fread(Rdata, 1, readbyte, fp) != readbyte) {
perror("get bmpdata:\r\n");
break;
}
if(x < Image_Width_Byte) { //bmp
Image[x + (bmpInfoHeader.biHeight - y - 1) * Image_Width_Byte] = Rdata;
// printf("rdata = %d\r\n", Rdata);
}
UDOUBLE temp=be32toh(Rdata[0]);
yp = (bmpInfoHeader.biHeight - y - 1);
if (Ystart + yp >= Paint.Height) continue;
for (x=xb*8; x<(xb+sizeof Rdata)*8; x++) {
if(Xstart + x >= Paint.Width) break;
color = (temp & (1<<(sizeof Rdata*8-1))) ?Bcolor:Wcolor;
temp <<= 1;
Paint_SetPixel(Xstart + x, Ystart + yp, color);
}
}
}
fclose(fp);

// Refresh the image to the display buffer based on the displayed orientation
UBYTE color, temp;
for(y = 0; y < bmpInfoHeader.biHeight; y++) {
for(x = 0; x < bmpInfoHeader.biWidth; x++) {
if(x > Paint.Width || y > Paint.Height) {
break;
}
temp = Image[(x / 8) + (y * Image_Width_Byte)];
color = (((temp << (x%8)) & 0x80) == 0x80) ?Bcolor:Wcolor;
Paint_SetPixel(Xstart + x, Ystart + y, color);
}
}
return 0;
}
/*************************************************************************
Expand Down