@@ -60,7 +60,8 @@ JPEGDEC jpeg;
60
60
// EXPERIMENTAL: If JPEG_CPY_FRAMEBUFFER is true the JPG is decoded directly in EPD framebuffer
61
61
// On true it looses rotation. Experimental, does not work alright yet. Hint:
62
62
// 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
64
65
65
66
// Dither space allocation
66
67
uint8_t * dither_space;
@@ -157,7 +158,6 @@ int JPEGDraw4Bits(JPEGDRAW* pDraw) {
157
158
for (int16_t xx = 0 ; xx < pDraw->iWidth ; xx += 4 ) {
158
159
for (int16_t yy = 0 ; yy < pDraw->iHeight ; yy++) {
159
160
uint16_t col = pDraw->pPixels [(xx + (yy * pDraw->iWidth )) >> 2 ];
160
-
161
161
uint8_t col1 = col & 0xf ;
162
162
uint8_t col2 = (col >> 4 ) & 0xf ;
163
163
uint8_t col3 = (col >> 8 ) & 0xf ;
@@ -166,7 +166,6 @@ int JPEGDraw4Bits(JPEGDRAW* pDraw) {
166
166
epd_draw_pixel (pDraw->x + xx + 1 , pDraw->y + yy, gamme_curve[col2 * 16 ], fb);
167
167
epd_draw_pixel (pDraw->x + xx + 2 , pDraw->y + yy, gamme_curve[col3 * 16 ], fb);
168
168
epd_draw_pixel (pDraw->x + xx + 3 , pDraw->y + yy, gamme_curve[col4 * 16 ], fb);
169
-
170
169
/* if (yy==0 && mcu_count==0) {
171
170
printf("1.%d %d %d %d ",col1,col2,col3,col4);
172
171
} */
@@ -179,6 +178,23 @@ int JPEGDraw4Bits(JPEGDRAW* pDraw) {
179
178
return 1 ;
180
179
}
181
180
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
+
182
198
void deepsleep () {
183
199
esp_deep_sleep (1000000LL * 60 * DEEPSLEEP_MINUTES_AFTER_RENDER);
184
200
}
@@ -189,21 +205,40 @@ void deepsleep() {
189
205
int decodeJpeg (uint8_t * source_buf, int xpos, int ypos) {
190
206
uint32_t decode_start = esp_timer_get_time ();
191
207
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
+ }
194
221
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
- );
201
222
} else {
202
- ESP_LOGE (" jpeg.decode " , " Failed with error: %d" , jpeg.getLastError ());
223
+ ESP_LOGE (" jpeg.openRAM " , " Failed with error: %d" , jpeg.getLastError ());
203
224
}
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);
204
228
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
+ }
207
242
}
208
243
jpeg.close ();
209
244
@@ -433,14 +468,19 @@ void wifi_init_sta(void) {
433
468
void app_main () {
434
469
enum EpdInitOptions init_options = EPD_LUT_64K;
435
470
436
- epd_init (&DEMO_BOARD , &ED097TC2, init_options );
471
+ epd_init (&epd_board_v7 , &GDEW101C01, EPD_LUT_64K );
437
472
// Set VCOM for boards that allow to set this in software (in mV).
438
473
// This will print an error if unsupported. In this case,
439
474
// set VCOM using the hardware potentiometer and delete this line.
440
- epd_set_vcom (1560 );
475
+ epd_set_vcom (2560 );
441
476
hl = epd_hl_init (WAVEFORM);
442
477
fb = epd_hl_get_framebuffer (&hl);
443
478
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
+
444
484
printf (" JPGDEC version @bitbank2\n " );
445
485
dither_space = (uint8_t *)heap_caps_malloc (epd_width () * 16 , MALLOC_CAP_SPIRAM);
446
486
if (dither_space == NULL ) {
0 commit comments