Merge pull request #260 from mbartlett21/dithering-3-7
Add a dithered mode to the 3.7 inch display
This commit is contained in:
commit
c76950ac96
7 changed files with 167 additions and 7 deletions
|
|
@ -205,6 +205,86 @@ UBYTE GUI_ReadBmp_4Gray(const char *path, UWORD Xstart, UWORD Ystart)
|
|||
return 0;
|
||||
}
|
||||
|
||||
UBYTE GUI_ReadBmp_16Gray(const char *path, UWORD Xstart, UWORD Ystart)
|
||||
{
|
||||
FILE *fp; //Define a file pointer
|
||||
BMPFILEHEADER bmpFileHeader; //Define a bmp file header structure
|
||||
BMPINFOHEADER bmpInfoHeader; //Define a bmp info header structure
|
||||
|
||||
// Binary file open
|
||||
if((fp = fopen(path, "rb")) == NULL) {
|
||||
Debug("Cann'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
|
||||
printf("pixel = %d * %d\r\n", bmpInfoHeader.biWidth, bmpInfoHeader.biHeight);
|
||||
|
||||
// They are both the same width in bytes
|
||||
// round up to the next byte
|
||||
UWORD Width_Byte = (bmpInfoHeader.biWidth + 1) / 2;
|
||||
UBYTE Image[Width_Byte * bmpInfoHeader.biHeight];
|
||||
memset(Image, 0xFF, Width_Byte * bmpInfoHeader.biHeight);
|
||||
|
||||
// Determine if it is a monochrome bitmap
|
||||
int readbyte = bmpInfoHeader.biBitCount;
|
||||
printf("biBitCount = %d\r\n",readbyte);
|
||||
if(readbyte != 4) {
|
||||
Debug("Bmp image is not a 4-bit bitmap!\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Determine colors based on the palette
|
||||
|
||||
// A map from palette entry to color
|
||||
UBYTE colors[16];
|
||||
UBYTE i;
|
||||
BMPRGBQUAD rgbData;
|
||||
|
||||
for (i = 0; i < 16; i++){
|
||||
fread(&rgbData, sizeof(BMPRGBQUAD), 1, fp);
|
||||
|
||||
// Work out the closest colour
|
||||
// 16 colours over 0-255 => 0-8 => 0, 9-25 => 1 (17), 26-42 => 2 (34), etc
|
||||
|
||||
// Base it on red
|
||||
colors[i] = (rgbData.rgbRed + 8) / 17;
|
||||
}
|
||||
|
||||
// Read image data into the cache
|
||||
UWORD x, y;
|
||||
UBYTE Rdata;
|
||||
fseek(fp, bmpFileHeader.bOffset, SEEK_SET);
|
||||
|
||||
for (y = 0; y < bmpInfoHeader.biHeight; y++) {//Total display column
|
||||
for (x = 0; x < Width_Byte; x++) {//Show a line in the line
|
||||
if (fread((char *) &Rdata, 1, 1, fp) != 1) {
|
||||
perror("get bmpdata:\r\n");
|
||||
break;
|
||||
}
|
||||
Image[x + (bmpInfoHeader.biHeight - y - 1) * Width_Byte] = Rdata;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
// Refresh the image to the display buffer based on the displayed orientation
|
||||
UBYTE coloridx;
|
||||
printf("bmpInfoHeader.biWidth = %d\r\n", bmpInfoHeader.biWidth);
|
||||
printf("bmpInfoHeader.biHeight = %d\r\n", bmpInfoHeader.biHeight);
|
||||
for (y = 0; y < bmpInfoHeader.biHeight; y++) {
|
||||
for (x = 0; x < bmpInfoHeader.biWidth; x++) {
|
||||
if (Xstart + x > Paint.Width || Ystart + y > Paint.Height)
|
||||
break;
|
||||
|
||||
coloridx = (Image[x / 2 + y * Width_Byte] >> ((x % 2) ? 0 : 4)) & 15;
|
||||
Paint_SetPixel(Xstart + x, Ystart + y, colors[coloridx]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
UBYTE GUI_ReadBmp_RGB_7Color(const char *path, UWORD Xstart, UWORD Ystart)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ typedef struct RGB_QUAD {
|
|||
|
||||
UBYTE GUI_ReadBmp(const char *path, UWORD Xstart, UWORD Ystart);
|
||||
UBYTE GUI_ReadBmp_4Gray(const char *path, UWORD Xstart, UWORD Ystart);
|
||||
UBYTE GUI_ReadBmp_16Gray(const char *path, UWORD Xstart, UWORD Ystart);
|
||||
UBYTE GUI_ReadBmp_RGB_4Color(const char *path, UWORD Xstart, UWORD Ystart);
|
||||
UBYTE GUI_ReadBmp_RGB_7Color(const char *path, UWORD Xstart, UWORD Ystart);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -169,12 +169,14 @@ void Paint_SetScale(UBYTE scale)
|
|||
}else if(scale == 4){
|
||||
Paint.Scale = scale;
|
||||
Paint.WidthByte = (Paint.WidthMemory % 4 == 0)? (Paint.WidthMemory / 4 ): (Paint.WidthMemory / 4 + 1);
|
||||
}else if(scale == 7){//Only applicable with 5in65 e-Paper
|
||||
}else if(scale == 7 || scale == 16){
|
||||
/* 7 colours are only applicable with 5in65 e-Paper */
|
||||
/* 16 colours are used for dithering */
|
||||
Paint.Scale = scale;
|
||||
Paint.WidthByte = (Paint.WidthMemory % 2 == 0)? (Paint.WidthMemory / 2 ): (Paint.WidthMemory / 2 + 1);;
|
||||
}else{
|
||||
Debug("Set Scale Input parameter error\r\n");
|
||||
Debug("Scale Only support: 2 4 7\r\n");
|
||||
Debug("Scale Only support: 2 4 7 16\r\n");
|
||||
}
|
||||
}
|
||||
/******************************************************************************
|
||||
|
|
@ -247,7 +249,7 @@ void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color)
|
|||
UBYTE Rdata = Paint.Image[Addr];
|
||||
Rdata = Rdata & (~(0xC0 >> ((X % 4)*2)));//Clear first, then set value
|
||||
Paint.Image[Addr] = Rdata | ((Color << 6) >> ((X % 4)*2));
|
||||
}else if(Paint.Scale == 7){
|
||||
}else if(Paint.Scale == 7 || Paint.Scale == 16){
|
||||
UDOUBLE Addr = X / 2 + Y * Paint.WidthByte;
|
||||
UBYTE Rdata = Paint.Image[Addr];
|
||||
Rdata = Rdata & (~(0xF0 >> ((X % 2)*4)));//Clear first, then set value
|
||||
|
|
@ -277,7 +279,7 @@ void Paint_Clear(UWORD Color)
|
|||
Paint.Image[Addr] = (Color<<6)|(Color<<4)|(Color<<2)|Color;
|
||||
}
|
||||
}
|
||||
}else if(Paint.Scale == 7) {
|
||||
}else if(Paint.Scale == 7 || Paint.Scale == 16) {
|
||||
for (UWORD Y = 0; Y < Paint.HeightByte; Y++) {
|
||||
for (UWORD X = 0; X < Paint.WidthByte; X++ ) {
|
||||
UDOUBLE Addr = X + Y*Paint.WidthByte;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue