Skip to content

Commit 5b94f7c

Browse files
committed
#256 Add new DISPLAY_COLOR_TYPE (NONE, DES_COLOR) and adapt jpgdec-render.cpp
1 parent a7a9cba commit 5b94f7c

File tree

2 files changed

+65
-22
lines changed

2 files changed

+65
-22
lines changed

examples/www-image/main/jpgdec-render.cpp

+56-16
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ JPEGDEC jpeg;
6060
// EXPERIMENTAL: If JPEG_CPY_FRAMEBUFFER is true the JPG is decoded directly in EPD framebuffer
6161
// On true it looses rotation. Experimental, does not work alright yet. Hint:
6262
// Check if an uint16_t buffer can be copied in a uint8_t buffer directly
63-
#define JPEG_CPY_FRAMEBUFFER true
63+
// NO COLOR SUPPORT on true!
64+
#define JPEG_CPY_FRAMEBUFFER false
6465

6566
// Dither space allocation
6667
uint8_t* dither_space;
@@ -157,7 +158,6 @@ int JPEGDraw4Bits(JPEGDRAW* pDraw) {
157158
for (int16_t xx = 0; xx < pDraw->iWidth; xx += 4) {
158159
for (int16_t yy = 0; yy < pDraw->iHeight; yy++) {
159160
uint16_t col = pDraw->pPixels[(xx + (yy * pDraw->iWidth)) >> 2];
160-
161161
uint8_t col1 = col & 0xf;
162162
uint8_t col2 = (col >> 4) & 0xf;
163163
uint8_t col3 = (col >> 8) & 0xf;
@@ -166,7 +166,6 @@ int JPEGDraw4Bits(JPEGDRAW* pDraw) {
166166
epd_draw_pixel(pDraw->x + xx + 1, pDraw->y + yy, gamme_curve[col2 * 16], fb);
167167
epd_draw_pixel(pDraw->x + xx + 2, pDraw->y + yy, gamme_curve[col3 * 16], fb);
168168
epd_draw_pixel(pDraw->x + xx + 3, pDraw->y + yy, gamme_curve[col4 * 16], fb);
169-
170169
/* if (yy==0 && mcu_count==0) {
171170
printf("1.%d %d %d %d ",col1,col2,col3,col4);
172171
} */
@@ -179,6 +178,23 @@ int JPEGDraw4Bits(JPEGDRAW* pDraw) {
179178
return 1;
180179
}
181180

181+
int JPEGDrawRGB(JPEGDRAW* pDraw) {
182+
// pDraw->iWidth, pDraw->iHeight Usually dw:128 dh:16 OR dw:64 dh:16
183+
uint32_t render_start = esp_timer_get_time();
184+
for (int16_t xx = 0; xx < pDraw->iWidth; xx++) {
185+
for (int16_t yy = 0; yy < pDraw->iHeight; yy++) {
186+
uint16_t rgb565_pix = pDraw->pPixels[(xx + (yy * pDraw->iWidth))];
187+
uint8_t r = (rgb565_pix & 0xF800) >> 8; // rrrrr... ........ -> rrrrr000
188+
uint8_t g = (rgb565_pix & 0x07E0) >> 3; // .....ggg ggg..... -> gggggg00
189+
uint8_t b = (rgb565_pix & 0x1F) << 3; // ............bbbbb -> bbbbb000
190+
epd_draw_cpixel(pDraw->x + xx, pDraw->y + yy, r, g, b, fb);
191+
//printf("r:%d g:%d b:%d\n", r, g, b); // debug
192+
}
193+
}
194+
return 1;
195+
}
196+
197+
182198
void deepsleep() {
183199
esp_deep_sleep(1000000LL * 60 * DEEPSLEEP_MINUTES_AFTER_RENDER);
184200
}
@@ -189,21 +205,40 @@ void deepsleep() {
189205
int decodeJpeg(uint8_t* source_buf, int xpos, int ypos) {
190206
uint32_t decode_start = esp_timer_get_time();
191207

192-
if (jpeg.openRAM(source_buf, img_buf_pos, JPEGDraw4Bits)) {
193-
jpeg.setPixelType(FOUR_BIT_DITHERED);
208+
if (strcmp(DISPLAY_COLOR_TYPE, (char*)"NONE") == 0) {
209+
if (jpeg.openRAM(source_buf, img_buf_pos, JPEGDraw4Bits)) {
210+
jpeg.setPixelType(FOUR_BIT_DITHERED);
211+
212+
if (jpeg.decodeDither(dither_space, 0)) {
213+
time_decomp = (esp_timer_get_time() - decode_start) / 1000 - time_render;
214+
ESP_LOGI(
215+
"decode", "%ld ms - %dx%d image MCUs:%d", time_decomp, (int)jpeg.getWidth(),
216+
(int)jpeg.getHeight(), mcu_count
217+
);
218+
} else {
219+
ESP_LOGE("jpeg.decode", "Failed with error: %d", jpeg.getLastError());
220+
}
194221

195-
if (jpeg.decodeDither(dither_space, 0)) {
196-
time_decomp = (esp_timer_get_time() - decode_start) / 1000 - time_render;
197-
ESP_LOGI(
198-
"decode", "%ld ms - %dx%d image MCUs:%d", time_decomp, (int)jpeg.getWidth(),
199-
(int)jpeg.getHeight(), mcu_count
200-
);
201222
} else {
202-
ESP_LOGE("jpeg.decode", "Failed with error: %d", jpeg.getLastError());
223+
ESP_LOGE("jpeg.openRAM", "Failed with error: %d", jpeg.getLastError());
203224
}
225+
} else if (strcmp(DISPLAY_COLOR_TYPE, (char*)"DES_COLOR") == 0) {
226+
if (jpeg.openRAM(source_buf, img_buf_pos, JPEGDrawRGB)) {
227+
jpeg.setPixelType(RGB565_LITTLE_ENDIAN);
204228

205-
} else {
206-
ESP_LOGE("jpeg.openRAM", "Failed with error: %d", jpeg.getLastError());
229+
if (jpeg.decode(0, 0, 0)) {
230+
time_decomp = (esp_timer_get_time() - decode_start) / 1000 - time_render;
231+
ESP_LOGI(
232+
"decode", "%ld ms - %dx%d image MCUs:%d", time_decomp, (int)jpeg.getWidth(),
233+
(int)jpeg.getHeight(), mcu_count
234+
);
235+
} else {
236+
ESP_LOGE("jpeg.decode", "Failed with error: %d", jpeg.getLastError());
237+
}
238+
239+
} else {
240+
ESP_LOGE("jpeg.openRAM", "Failed with error: %d", jpeg.getLastError());
241+
}
207242
}
208243
jpeg.close();
209244

@@ -433,14 +468,19 @@ void wifi_init_sta(void) {
433468
void app_main() {
434469
enum EpdInitOptions init_options = EPD_LUT_64K;
435470

436-
epd_init(&DEMO_BOARD, &ED097TC2, init_options);
471+
epd_init(&epd_board_v7, &GDEW101C01, EPD_LUT_64K);
437472
// Set VCOM for boards that allow to set this in software (in mV).
438473
// This will print an error if unsupported. In this case,
439474
// set VCOM using the hardware potentiometer and delete this line.
440-
epd_set_vcom(1560);
475+
epd_set_vcom(2560);
441476
hl = epd_hl_init(WAVEFORM);
442477
fb = epd_hl_get_framebuffer(&hl);
443478

479+
// For color we use the epdiy built-in gamma_curve:
480+
if (strcmp(DISPLAY_COLOR_TYPE, (char*)"DES_COLOR") == 0) {
481+
epd_set_gamma_curve(gamma_value);
482+
}
483+
444484
printf("JPGDEC version @bitbank2\n");
445485
dither_space = (uint8_t*)heap_caps_malloc(epd_width() * 16, MALLOC_CAP_SPIRAM);
446486
if (dither_space == NULL) {

examples/www-image/main/settings.h

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// WiFi configuration:
2-
#define ESP_WIFI_SSID ""
2+
#define ESP_WIFI_SSID "sagemcom6AE0"
33
#define ESP_WIFI_PASSWORD ""
44

55
// Affects the gamma to calculate gray (lower is darker/higher contrast)
@@ -9,33 +9,36 @@ double gamma_value = 0.7;
99
// - - - - Display configuration - - - - - - - - -
1010
// EPD Waveform should match your EPD for good grayscales
1111
#define WAVEFORM EPD_BUILTIN_WAVEFORM
12-
#define DISPLAY_ROTATION EPD_ROT_LANDSCAPE
12+
#define DISPLAY_ROTATION EPD_ROT_INVERTED_LANDSCAPE
1313
// - - - - end of Display configuration - - - - -
1414

1515
// Deepsleep configuration
1616
#define MILLIS_DELAY_BEFORE_SLEEP 2000
17-
#define DEEPSLEEP_MINUTES_AFTER_RENDER 6
17+
#define DEEPSLEEP_MINUTES_AFTER_RENDER 60
1818

1919
// Image URL and jpg settings. Make sure to update WIDTH/HEIGHT if using loremflickr
2020
// Note: Only HTTP protocol supported (Check README to use SSL secure URLs) loremflickr
21-
#define IMG_URL ("https://loremflickr.com/1024/768")
22-
21+
//#define IMG_URL ("https://loremflickr.com/2232/1680")
22+
#define IMG_URL ("http://img.cale.es/jpg/fasani/5ef2ee980a4ec")
2323
// idf >= 4.3 needs VALIDATE_SSL_CERTIFICATE set to true for https URLs
2424
// Please check the README to understand how to use an SSL Certificate
2525
// Note: This makes a sntp time sync query for cert validation (It's slower)
2626
// IMPORTANT: idf updated and now when you use Internet requests you need to server cert
2727
// verification
2828
// heading ESP-TLS in
2929
// https://newreleases.io/project/github/espressif/esp-idf/release/v4.3-beta1
30-
#define VALIDATE_SSL_CERTIFICATE true
30+
#define VALIDATE_SSL_CERTIFICATE false
3131
// To make an insecure request please check Readme
3232

3333
// Alternative non-https URL:
3434
// #define IMG_URL "http://img.cale.es/jpg/fasani/5e636b0f39aac"
3535

3636
// Jpeg: Adds dithering to image rendering (Makes grayscale smoother on transitions)
37+
// only implemented in jpg-render.c
3738
#define JPG_DITHERING true
3839

40+
// NONE - DES_COLOR (Fabricated by wf-tech.com) applicable to jpgdec-render.cpp
41+
#define DISPLAY_COLOR_TYPE "DES_COLOR"
3942
// As default is 512 without setting buffer_size property in esp_http_client_config_t
4043
#define HTTP_RECEIVE_BUFFER_SIZE 1986
4144

0 commit comments

Comments
 (0)