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
This commit is contained in:
Dean Lee
2021-09-24 04:20:10 +08:00
committed by GitHub
parent c0777f89bf
commit 5f63a9339c
+2 -1
View File
@@ -217,7 +217,8 @@ kj::Array<uint8_t> get_frame_image(const CameraBuf *b) {
}
static kj::Array<capnp::byte> yuv420_to_jpeg(const CameraBuf *b, int thumbnail_width, int thumbnail_height) {
std::unique_ptr<uint8[]> 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<uint8[]> 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;