Skip to content

Commit

Permalink
Merge pull request #714 from bbawj/master
Browse files Browse the repository at this point in the history
Add error handling for esp_jpg_decode
  • Loading branch information
me-no-dev authored Jan 31, 2025
2 parents 6a821a8 + aa15c51 commit 4467667
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
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

0 comments on commit 4467667

Please sign in to comment.