Skip to content

Commit acd474d

Browse files
committed
updated the image viewer for Linux
1 parent 8dfcadb commit acd474d

1 file changed

Lines changed: 21 additions & 19 deletions

File tree

examples/Linux/show_img/main.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
#include <sys/ioctl.h>
3131
#define SHOW_DETAILS
3232

33+
// BCM GPIO numbers for the RPI HAT
34+
#define IT8951_CS 8
35+
#define IT8951_SPI 0
36+
#define IT8951_RST 17
37+
#define IT8951_BUSY 24
38+
#define IT8951_ITE_EN -1
39+
#define IT8951_EN -1
40+
3341
FASTEPD bbep;
3442
int iPanel1Bit, iMode;
3543
int iInvert = 0; // assume not inverted
@@ -50,6 +58,7 @@ const char *szPanels[] = {
5058
"BBEP_DISPLAY_ED103TC2",
5159
"BBEP_DISPLAY_ED052TC4",
5260
"BBEP_DISPLAY_ED1150C1",
61+
"BBEP_DISPLAY_ED078KC2",
5362
NULL // must be last entry
5463
};
5564

@@ -86,24 +95,16 @@ int i = 0;
8695
return i;
8796
} /* FindItemName() */
8897
//
89-
// The user passed a file which has 2 or more bits per pixel
90-
// convert it to 1 or 2-bpp grayscale
98+
// The user passed a file which has more than 4bits per pixel
99+
// convert it to 4-bpp grayscale
91100
//
92101
int ConvertBpp(uint8_t *pBMP, int w, int h, int iBpp, uint8_t *palette)
93102
{
94103
int gray, r=0, g=0, b=0, x, y, iDelta, iPitch, iDestPitch, iDestBpp;
95104
uint8_t *s, *d, *pPal, u8, count;
96105

97-
// if (iPanel2Bit == -1) { // only 1 bit panel available
98-
iDestBpp = 1;
99-
// } else {
100-
// iDestBpp = 2;
101-
// }
102-
if (iDestBpp == 1) {
103-
iDestPitch = (w+7)/8;
104-
} else {
105-
iDestPitch = (w+3)/4;
106-
}
106+
iDestBpp = 4;
107+
iDestPitch = (w+1)/2;
107108
// The bits per pixel info from PNG files is per color channel
108109
// Convert the value into a true bits per pixel
109110
switch (iPixelType) {
@@ -356,17 +357,15 @@ void PrepareImage(void)
356357
uint8_t *s, *d, uc=0;
357358
s = pBitmap;
358359
d = (uint8_t *)bbep.currentBuffer();
359-
iDestPitch = (bbep.width()+7)/8;
360360
// Convert the source bitmap to 1 or 2-bit grayscale
361-
if (iBpp >= 2) {
361+
if (iBpp > 4) {
362362
iBpp = ConvertBpp(s, iWidth, iHeight, iBpp, pPalette);
363+
bbep.setMode(BB_MODE_4BPP);
364+
iDestPitch = (bbep.width()+1)/2;
363365
}
364-
iSrcPitch = (iWidth+7)/8;
366+
iSrcPitch = (iWidth+1)/2;
365367
for (y=0; y<iHeight; y++) {
366368
memcpy(d, s, iSrcPitch);
367-
if (iWidth & 7) { // fill partial byte with white
368-
d[iWidth>>3] |= (0xff >> (iWidth & 7));
369-
}
370369
s += iSrcPitch;
371370
d += iDestPitch;
372371
}
@@ -484,17 +483,20 @@ char szFile[256];
484483
strcpy(szFile, pValue);
485484
} else if (strcmp(pName, "panel_1bit") == 0) {
486485
iPanel1Bit = FindItemName(szPanels, pValue, "1-bit panel");
486+
printf("found panel: %d\n", iPanel1Bit);
487487
} else if (strcmp(pName, "invert") == 0) {
488488
iInvert = !strcmp(pValue, "true");
489489
}
490490
}
491491
if (szFile[0] == 0 || iMode == -1 || iPanel1Bit == -1) { // print instructions
492+
printf("file: %s, mode: %d, panel: %d\n", szFile, iMode, iPanel1Bit);
492493
ShowHelp();
493494
return -1;
494495
}
495496

496497
if (iStretch < 0) iStretch = STRETCH_ASPECTFILL; // default
497-
bbep.initPanel(BB_PANEL_RPI);
498+
// bbep.initPanel(BB_PANEL_RPI);
499+
bbep.initIT8951(IT8951_SPI, 0, 0, IT8951_CS, IT8951_BUSY, IT8951_RST, IT8951_EN, IT8951_ITE_EN);
498500
bbep.setPanelSize(iPanel1Bit);
499501
bbep.fillScreen(BBEP_WHITE);
500502
#ifdef SHOW_DETAILS

0 commit comments

Comments
 (0)