fix(jpeg_decoder): Fix jpeg decoder get picture information

This commit is contained in:
C.S.M
2024-11-19 11:46:55 +08:00
parent 286bf6b096
commit 1a1fb67b7f

View File

@ -145,6 +145,7 @@ esp_err_t jpeg_decoder_get_info(const uint8_t *in_buf, uint32_t inbuf_len, jpeg_
uint8_t thischar = 0; uint8_t thischar = 0;
uint8_t lastchar = 0; uint8_t lastchar = 0;
uint8_t hivi = 0; uint8_t hivi = 0;
uint8_t nf = 0;
while (header_info->buffer_left) { while (header_info->buffer_left) {
lastchar = thischar; lastchar = thischar;
@ -157,7 +158,8 @@ esp_err_t jpeg_decoder_get_info(const uint8_t *in_buf, uint32_t inbuf_len, jpeg_
height = jpeg_get_bytes(header_info, 2); height = jpeg_get_bytes(header_info, 2);
width = jpeg_get_bytes(header_info, 2); width = jpeg_get_bytes(header_info, 2);
jpeg_get_bytes(header_info, 1); nf = jpeg_get_bytes(header_info, 1);
jpeg_get_bytes(header_info, 1); jpeg_get_bytes(header_info, 1);
hivi = jpeg_get_bytes(header_info, 1); hivi = jpeg_get_bytes(header_info, 1);
break; break;
@ -172,6 +174,7 @@ esp_err_t jpeg_decoder_get_info(const uint8_t *in_buf, uint32_t inbuf_len, jpeg_
picture_info->height = height; picture_info->height = height;
picture_info->width = width; picture_info->width = width;
if (nf == 3) {
switch (hivi) { switch (hivi) {
case 0x11: case 0x11:
picture_info->sample_method = JPEG_DOWN_SAMPLING_YUV444; picture_info->sample_method = JPEG_DOWN_SAMPLING_YUV444;
@ -186,6 +189,10 @@ esp_err_t jpeg_decoder_get_info(const uint8_t *in_buf, uint32_t inbuf_len, jpeg_
ESP_LOGE(TAG, "Sampling factor cannot be recognized"); ESP_LOGE(TAG, "Sampling factor cannot be recognized");
return ESP_ERR_INVALID_STATE; return ESP_ERR_INVALID_STATE;
} }
}
if (nf == 1) {
picture_info->sample_method = JPEG_DOWN_SAMPLING_GRAY;
}
free(header_info); free(header_info);
return ESP_OK; return ESP_OK;