Merge pull request #822 from kwagyeman/kwabena/clean_jpeg_trailing

Cleanup trailing data on jpeg images
This commit is contained in:
Ibrahim Abd Elkader 2020-06-03 23:33:23 +02:00 committed by GitHub
commit 9f9270e40f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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;