Cleanup trailing data on jpeg images

This commit is contained in:
Kwabena W. Agyeman 2020-06-02 23:16:18 -07:00
parent a0bb1726e3
commit c12415d001
2 changed files with 21 additions and 6 deletions

View File

@ -374,6 +374,15 @@ bool jpeg_compress(image_t *src, image_t *dst, int quality, bool realloc)
HAL_JPEG_DeInit(&JPEG_Handle);
if (!jpeg_enc.overflow) {
// Clean trailing data.
while ((dst->bpp >= 2)
&& ((dst->pixels[dst->bpp-2] != 0xFF)
|| (dst->pixels[dst->bpp-1] != 0xD9))) {
dst->bpp -= 1;
}
}
return jpeg_enc.overflow;
}

View File

@ -1478,6 +1478,12 @@ int sensor_snapshot(sensor_t *sensor, image_t *image, streaming_cb_t streaming_c
SCB_InvalidateDCache_by_Addr((uint32_t*)MAIN_FB()->pixels, OMV_RAW_BUF_SIZE);
#endif
}
// Clean trailing data.
while ((MAIN_FB()->bpp >= 2)
&& ((MAIN_FB()->pixels[MAIN_FB()->bpp-2] != 0xFF)
|| (MAIN_FB()->pixels[MAIN_FB()->bpp-1] != 0xD9))) {
MAIN_FB()->bpp -= 1;
}
break;
default:
break;