Skip to content

Commit

Permalink
#256 Add new DISPLAY_COLOR_TYPE (NONE, DES_COLOR) and adapt jpgdec-re…
Browse files Browse the repository at this point in the history
…nder.cpp
  • Loading branch information
martinberlin committed Sep 28, 2023
1 parent a7a9cba commit 5b94f7c
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 22 deletions.
72 changes: 56 additions & 16 deletions examples/www-image/main/jpgdec-render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ JPEGDEC jpeg;
// EXPERIMENTAL: If JPEG_CPY_FRAMEBUFFER is true the JPG is decoded directly in EPD framebuffer
// On true it looses rotation. Experimental, does not work alright yet. Hint:
// Check if an uint16_t buffer can be copied in a uint8_t buffer directly
#define JPEG_CPY_FRAMEBUFFER true
// NO COLOR SUPPORT on true!
#define JPEG_CPY_FRAMEBUFFER false

// Dither space allocation
uint8_t* dither_space;
Expand Down Expand Up @@ -157,7 +158,6 @@ int JPEGDraw4Bits(JPEGDRAW* pDraw) {
for (int16_t xx = 0; xx < pDraw->iWidth; xx += 4) {
for (int16_t yy = 0; yy < pDraw->iHeight; yy++) {
uint16_t col = pDraw->pPixels[(xx + (yy * pDraw->iWidth)) >> 2];

uint8_t col1 = col & 0xf;
uint8_t col2 = (col >> 4) & 0xf;
uint8_t col3 = (col >> 8) & 0xf;
Expand All @@ -166,7 +166,6 @@ int JPEGDraw4Bits(JPEGDRAW* pDraw) {
epd_draw_pixel(pDraw->x + xx + 1, pDraw->y + yy, gamme_curve[col2 * 16], fb);
epd_draw_pixel(pDraw->x + xx + 2, pDraw->y + yy, gamme_curve[col3 * 16], fb);
epd_draw_pixel(pDraw->x + xx + 3, pDraw->y + yy, gamme_curve[col4 * 16], fb);

/* if (yy==0 && mcu_count==0) {
printf("1.%d %d %d %d ",col1,col2,col3,col4);
} */
Expand All @@ -179,6 +178,23 @@ int JPEGDraw4Bits(JPEGDRAW* pDraw) {
return 1;
}

int JPEGDrawRGB(JPEGDRAW* pDraw) {
// pDraw->iWidth, pDraw->iHeight Usually dw:128 dh:16 OR dw:64 dh:16
uint32_t render_start = esp_timer_get_time();
for (int16_t xx = 0; xx < pDraw->iWidth; xx++) {
for (int16_t yy = 0; yy < pDraw->iHeight; yy++) {
uint16_t rgb565_pix = pDraw->pPixels[(xx + (yy * pDraw->iWidth))];
uint8_t r = (rgb565_pix & 0xF800) >> 8; // rrrrr... ........ -> rrrrr000
uint8_t g = (rgb565_pix & 0x07E0) >> 3; // .....ggg ggg..... -> gggggg00
uint8_t b = (rgb565_pix & 0x1F) << 3; // ............bbbbb -> bbbbb000
epd_draw_cpixel(pDraw->x + xx, pDraw->y + yy, r, g, b, fb);
//printf("r:%d g:%d b:%d\n", r, g, b); // debug
}
}
return 1;
}


void deepsleep() {
esp_deep_sleep(1000000LL * 60 * DEEPSLEEP_MINUTES_AFTER_RENDER);
}
Expand All @@ -189,21 +205,40 @@ void deepsleep() {
int decodeJpeg(uint8_t* source_buf, int xpos, int ypos) {
uint32_t decode_start = esp_timer_get_time();

if (jpeg.openRAM(source_buf, img_buf_pos, JPEGDraw4Bits)) {
jpeg.setPixelType(FOUR_BIT_DITHERED);
if (strcmp(DISPLAY_COLOR_TYPE, (char*)"NONE") == 0) {
if (jpeg.openRAM(source_buf, img_buf_pos, JPEGDraw4Bits)) {
jpeg.setPixelType(FOUR_BIT_DITHERED);

if (jpeg.decodeDither(dither_space, 0)) {
time_decomp = (esp_timer_get_time() - decode_start) / 1000 - time_render;
ESP_LOGI(
"decode", "%ld ms - %dx%d image MCUs:%d", time_decomp, (int)jpeg.getWidth(),
(int)jpeg.getHeight(), mcu_count
);
} else {
ESP_LOGE("jpeg.decode", "Failed with error: %d", jpeg.getLastError());
}

if (jpeg.decodeDither(dither_space, 0)) {
time_decomp = (esp_timer_get_time() - decode_start) / 1000 - time_render;
ESP_LOGI(
"decode", "%ld ms - %dx%d image MCUs:%d", time_decomp, (int)jpeg.getWidth(),
(int)jpeg.getHeight(), mcu_count
);
} else {
ESP_LOGE("jpeg.decode", "Failed with error: %d", jpeg.getLastError());
ESP_LOGE("jpeg.openRAM", "Failed with error: %d", jpeg.getLastError());
}
} else if (strcmp(DISPLAY_COLOR_TYPE, (char*)"DES_COLOR") == 0) {
if (jpeg.openRAM(source_buf, img_buf_pos, JPEGDrawRGB)) {
jpeg.setPixelType(RGB565_LITTLE_ENDIAN);

} else {
ESP_LOGE("jpeg.openRAM", "Failed with error: %d", jpeg.getLastError());
if (jpeg.decode(0, 0, 0)) {
time_decomp = (esp_timer_get_time() - decode_start) / 1000 - time_render;
ESP_LOGI(
"decode", "%ld ms - %dx%d image MCUs:%d", time_decomp, (int)jpeg.getWidth(),
(int)jpeg.getHeight(), mcu_count
);
} else {
ESP_LOGE("jpeg.decode", "Failed with error: %d", jpeg.getLastError());
}

} else {
ESP_LOGE("jpeg.openRAM", "Failed with error: %d", jpeg.getLastError());
}
}
jpeg.close();

Expand Down Expand Up @@ -433,14 +468,19 @@ void wifi_init_sta(void) {
void app_main() {
enum EpdInitOptions init_options = EPD_LUT_64K;

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

// For color we use the epdiy built-in gamma_curve:
if (strcmp(DISPLAY_COLOR_TYPE, (char*)"DES_COLOR") == 0) {
epd_set_gamma_curve(gamma_value);
}

printf("JPGDEC version @bitbank2\n");
dither_space = (uint8_t*)heap_caps_malloc(epd_width() * 16, MALLOC_CAP_SPIRAM);
if (dither_space == NULL) {
Expand Down
15 changes: 9 additions & 6 deletions examples/www-image/main/settings.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// WiFi configuration:
#define ESP_WIFI_SSID ""
#define ESP_WIFI_SSID "sagemcom6AE0"
#define ESP_WIFI_PASSWORD ""

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

// Deepsleep configuration
#define MILLIS_DELAY_BEFORE_SLEEP 2000
#define DEEPSLEEP_MINUTES_AFTER_RENDER 6
#define DEEPSLEEP_MINUTES_AFTER_RENDER 60

// Image URL and jpg settings. Make sure to update WIDTH/HEIGHT if using loremflickr
// Note: Only HTTP protocol supported (Check README to use SSL secure URLs) loremflickr
#define IMG_URL ("https://loremflickr.com/1024/768")

//#define IMG_URL ("https://loremflickr.com/2232/1680")
#define IMG_URL ("http://img.cale.es/jpg/fasani/5ef2ee980a4ec")
// idf >= 4.3 needs VALIDATE_SSL_CERTIFICATE set to true for https URLs
// Please check the README to understand how to use an SSL Certificate
// Note: This makes a sntp time sync query for cert validation (It's slower)
// IMPORTANT: idf updated and now when you use Internet requests you need to server cert
// verification
// heading ESP-TLS in
// https://newreleases.io/project/github/espressif/esp-idf/release/v4.3-beta1
#define VALIDATE_SSL_CERTIFICATE true
#define VALIDATE_SSL_CERTIFICATE false
// To make an insecure request please check Readme

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

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

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

Expand Down

0 comments on commit 5b94f7c

Please sign in to comment.