From 5f63a9339c334fff998f4c7664e7d671fa5d23e4 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Fri, 24 Sep 2021 04:20:10 +0800 Subject: [PATCH] fix yuv420_to_jpeg: thumbnail_width & thumbnail_height must be aliged with 16 pixel. (#22287) * aligned by 16px * make buf big enough * comment * add comment * comment old-commit-hash: ae9305e7ff1bdba7afb94feb5e661ab2472321de --- selfdrive/camerad/cameras/camera_common.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/selfdrive/camerad/cameras/camera_common.cc b/selfdrive/camerad/cameras/camera_common.cc index 9c895c0a23..313d71c60b 100644 --- a/selfdrive/camerad/cameras/camera_common.cc +++ b/selfdrive/camerad/cameras/camera_common.cc @@ -217,7 +217,8 @@ kj::Array get_frame_image(const CameraBuf *b) { } static kj::Array yuv420_to_jpeg(const CameraBuf *b, int thumbnail_width, int thumbnail_height) { - std::unique_ptr buf(new uint8_t[(thumbnail_width * thumbnail_height * 3) / 2]); + // make the buffer big enough. jpeg_write_raw_data requires 16-pixels aligned height to be used. + std::unique_ptr buf(new uint8_t[(thumbnail_width * ((thumbnail_height + 15) & ~15) * 3) / 2]); uint8_t *y_plane = buf.get(); uint8_t *u_plane = y_plane + thumbnail_width * thumbnail_height; uint8_t *v_plane = u_plane + (thumbnail_width * thumbnail_height) / 4;