mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Speed up clearing trailing jpeg data
This commit is contained in:
parent
c04b519e38
commit
b0930505d5
@ -1068,6 +1068,7 @@ void bmp_read_pixels(FIL *fp, image_t *img, int n_lines, bmp_read_settings_t *rs
|
|||||||
void bmp_read(image_t *img, const char *path);
|
void bmp_read(image_t *img, const char *path);
|
||||||
void bmp_write_subimg(image_t *img, const char *path, rectangle_t *r);
|
void bmp_write_subimg(image_t *img, const char *path, rectangle_t *r);
|
||||||
bool jpeg_compress(image_t *src, image_t *dst, int quality, bool realloc);
|
bool jpeg_compress(image_t *src, image_t *dst, int quality, bool realloc);
|
||||||
|
int jpeg_clean_trailing_bytes(int bpp, uint8_t *data);
|
||||||
void jpeg_read_geometry(FIL *fp, image_t *img, const char *path, jpg_read_settings_t *rs);
|
void jpeg_read_geometry(FIL *fp, image_t *img, const char *path, jpg_read_settings_t *rs);
|
||||||
void jpeg_read_pixels(FIL *fp, image_t *img);
|
void jpeg_read_pixels(FIL *fp, image_t *img);
|
||||||
void jpeg_read(image_t *img, const char *path);
|
void jpeg_read(image_t *img, const char *path);
|
||||||
|
|||||||
@ -372,21 +372,17 @@ bool jpeg_compress(image_t *src, image_t *dst, int quality, bool realloc)
|
|||||||
// Set output size
|
// Set output size
|
||||||
dst->bpp = jpeg_enc.out_size;
|
dst->bpp = jpeg_enc.out_size;
|
||||||
|
|
||||||
|
if (!jpeg_enc.overflow) {
|
||||||
|
// Clean trailing data after 0xFFD9 at the end of the jpeg byte stream.
|
||||||
|
dst->bpp = jpeg_clean_trailing_bytes(dst->bpp, dst->data);
|
||||||
|
}
|
||||||
|
|
||||||
#if (TIME_JPEG==1)
|
#if (TIME_JPEG==1)
|
||||||
printf("time: %u ms\n", mp_hal_ticks_ms() - start);
|
printf("time: %u ms\n", mp_hal_ticks_ms() - start);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
HAL_JPEG_DeInit(&JPEG_Handle);
|
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;
|
return jpeg_enc.overflow;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1291,6 +1287,15 @@ jpeg_overflow:
|
|||||||
}
|
}
|
||||||
#endif //defined OMV_HARDWARE_JPEG
|
#endif //defined OMV_HARDWARE_JPEG
|
||||||
|
|
||||||
|
int jpeg_clean_trailing_bytes(int bpp, uint8_t *data)
|
||||||
|
{
|
||||||
|
while ((bpp > 1) && ((data[bpp-2] != 0xFF) || (data[bpp-1] != 0xD9))) {
|
||||||
|
bpp -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bpp;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(IMLIB_ENABLE_IMAGE_FILE_IO)
|
#if defined(IMLIB_ENABLE_IMAGE_FILE_IO)
|
||||||
// This function inits the geometry values of an image.
|
// This function inits the geometry values of an image.
|
||||||
void jpeg_read_geometry(FIL *fp, image_t *img, const char *path, jpg_read_settings_t *rs)
|
void jpeg_read_geometry(FIL *fp, image_t *img, const char *path, jpg_read_settings_t *rs)
|
||||||
|
|||||||
@ -1533,12 +1533,8 @@ int sensor_snapshot(sensor_t *sensor, image_t *image, streaming_cb_t streaming_c
|
|||||||
SCB_InvalidateDCache_by_Addr((uint32_t*)MAIN_FB()->pixels, size);
|
SCB_InvalidateDCache_by_Addr((uint32_t*)MAIN_FB()->pixels, size);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
// Clean trailing data.
|
// Clean trailing data after 0xFFD9 at the end of the jpeg byte stream.
|
||||||
while ((MAIN_FB()->bpp >= 2)
|
MAIN_FB()->bpp = jpeg_clean_trailing_bytes(MAIN_FB()->bpp, MAIN_FB()->pixels);
|
||||||
&& ((MAIN_FB()->pixels[MAIN_FB()->bpp-2] != 0xFF)
|
|
||||||
|| (MAIN_FB()->pixels[MAIN_FB()->bpp-1] != 0xD9))) {
|
|
||||||
MAIN_FB()->bpp -= 1;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user