Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error handling for esp_jpg_decode #714

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions conversions/esp_jpg_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,17 @@ esp_err_t esp_jpg_decode(size_t len, jpg_scale_t scale, jpg_reader_cb reader, jp
uint16_t output_height = decoder.height / (1 << (uint8_t)(jpeg.scale));

//output start
writer(arg, 0, 0, output_width, output_height, NULL);
if (!writer(arg, 0, 0, output_width, output_height, NULL)) {
ESP_LOGE(TAG, "JPG Writer Start Failed!");
return ESP_FAIL;
}
//output write
jres = jd_decomp(&decoder, _jpg_write, (uint8_t)jpeg.scale);
//output end
writer(arg, output_width, output_height, output_width, output_height, NULL);
if (!writer(arg, output_width, output_height, output_width, output_height, NULL)) {
ESP_LOGE(TAG, "JPG Writer End Failed!");
return ESP_FAIL;
}

if (jres != JDR_OK) {
ESP_LOGE(TAG, "JPG Decompression Failed! %s", jd_errors[jres]);
Expand Down
8 changes: 6 additions & 2 deletions conversions/to_bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ static bool _rgb_write(void * arg, uint16_t x, uint16_t y, uint16_t w, uint16_t
jpeg->height = h;
//if output is null, this is BMP
if(!jpeg->output){
jpeg->output = (uint8_t *)_malloc((w*h*3)+jpeg->data_offset);
size_t out_size = (w*h*3)+jpeg->data_offset;
jpeg->output = (uint8_t *)_malloc(out_size);
if(!jpeg->output){
ESP_LOGE(TAG, "_malloc failed! %zu", out_size);
return false;
}
}
Expand Down Expand Up @@ -121,8 +123,10 @@ static bool _rgb565_write(void * arg, uint16_t x, uint16_t y, uint16_t w, uint16
jpeg->height = h;
//if output is null, this is BMP
if(!jpeg->output){
jpeg->output = (uint8_t *)_malloc((w*h*3)+jpeg->data_offset);
size_t out_size = (w*h*3)+jpeg->data_offset;
jpeg->output = (uint8_t *)_malloc(out_size);
if(!jpeg->output){
ESP_LOGE(TAG, "_malloc failed! %zu", out_size);
return false;
}
}
Expand Down