Skip to content

Commit 65ce617

Browse files
committed
fix(jpeg_decoder): Fix jpeg decoder get picture information
1 parent fe3bb07 commit 65ce617

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

components/esp_driver_jpeg/jpeg_decode.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ esp_err_t jpeg_decoder_get_info(const uint8_t *in_buf, uint32_t inbuf_len, jpeg_
145145
uint8_t thischar = 0;
146146
uint8_t lastchar = 0;
147147
uint8_t hivi = 0;
148+
uint8_t nf = 0;
148149

149150
while (header_info->buffer_left) {
150151
lastchar = thischar;
@@ -157,7 +158,8 @@ esp_err_t jpeg_decoder_get_info(const uint8_t *in_buf, uint32_t inbuf_len, jpeg_
157158
height = jpeg_get_bytes(header_info, 2);
158159
width = jpeg_get_bytes(header_info, 2);
159160

160-
jpeg_get_bytes(header_info, 1);
161+
nf = jpeg_get_bytes(header_info, 1);
162+
161163
jpeg_get_bytes(header_info, 1);
162164
hivi = jpeg_get_bytes(header_info, 1);
163165
break;
@@ -172,19 +174,24 @@ esp_err_t jpeg_decoder_get_info(const uint8_t *in_buf, uint32_t inbuf_len, jpeg_
172174
picture_info->height = height;
173175
picture_info->width = width;
174176

175-
switch (hivi) {
176-
case 0x11:
177-
picture_info->sample_method = JPEG_DOWN_SAMPLING_YUV444;
178-
break;
179-
case 0x21:
180-
picture_info->sample_method = JPEG_DOWN_SAMPLING_YUV422;
181-
break;
182-
case 0x22:
183-
picture_info->sample_method = JPEG_DOWN_SAMPLING_YUV420;
184-
break;
185-
default:
186-
ESP_LOGE(TAG, "Sampling factor cannot be recognized");
187-
return ESP_ERR_INVALID_STATE;
177+
if (nf == 3) {
178+
switch (hivi) {
179+
case 0x11:
180+
picture_info->sample_method = JPEG_DOWN_SAMPLING_YUV444;
181+
break;
182+
case 0x21:
183+
picture_info->sample_method = JPEG_DOWN_SAMPLING_YUV422;
184+
break;
185+
case 0x22:
186+
picture_info->sample_method = JPEG_DOWN_SAMPLING_YUV420;
187+
break;
188+
default:
189+
ESP_LOGE(TAG, "Sampling factor cannot be recognized");
190+
return ESP_ERR_INVALID_STATE;
191+
}
192+
}
193+
if (nf == 1) {
194+
picture_info->sample_method = JPEG_DOWN_SAMPLING_GRAY;
188195
}
189196

190197
free(header_info);

0 commit comments

Comments
 (0)