diff options
author | 2023-07-28 21:26:53 +0530 | |
---|---|---|
committer | 2023-07-28 16:43:57 +0000 | |
commit | c85c0d6cbe6626797fb84907d50d7b3a6c9768f0 (patch) | |
tree | 2821ec7c1e8804cb3c42667eb0090abf1da3d830 | |
parent | e57a61af12176d109194068cde22f610b67a38d3 (diff) |
ultrahdr: fix visual artifacts in api-1 due to overflows
Bug:
Test: ./ultrahdr_unit_test
Change-Id: If31016ece14372579aa14c1007806258384f30ab
-rw-r--r-- | libs/ultrahdr/gainmapmath.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/libs/ultrahdr/gainmapmath.cpp b/libs/ultrahdr/gainmapmath.cpp index ee15363b69..8015a4ebeb 100644 --- a/libs/ultrahdr/gainmapmath.cpp +++ b/libs/ultrahdr/gainmapmath.cpp @@ -547,13 +547,13 @@ void transformYuv420(jr_uncompressed_ptr image, size_t x_chroma, size_t y_chroma uint8_t& u_uint = reinterpret_cast<uint8_t*>(image->data)[pixel_count + pixel_uv_idx]; uint8_t& v_uint = reinterpret_cast<uint8_t*>(image->data)[pixel_count * 5 / 4 + pixel_uv_idx]; - y1_uint = static_cast<uint8_t>(floor(yuv1.y * 255.0f + 0.5f)); - y2_uint = static_cast<uint8_t>(floor(yuv2.y * 255.0f + 0.5f)); - y3_uint = static_cast<uint8_t>(floor(yuv3.y * 255.0f + 0.5f)); - y4_uint = static_cast<uint8_t>(floor(yuv4.y * 255.0f + 0.5f)); + y1_uint = static_cast<uint8_t>(CLIP3((yuv1.y * 255.0f + 0.5f), 0, 255)); + y2_uint = static_cast<uint8_t>(CLIP3((yuv2.y * 255.0f + 0.5f), 0, 255)); + y3_uint = static_cast<uint8_t>(CLIP3((yuv3.y * 255.0f + 0.5f), 0, 255)); + y4_uint = static_cast<uint8_t>(CLIP3((yuv4.y * 255.0f + 0.5f), 0, 255)); - u_uint = static_cast<uint8_t>(floor(new_uv.u * 255.0f + 128.0f + 0.5f)); - v_uint = static_cast<uint8_t>(floor(new_uv.v * 255.0f + 128.0f + 0.5f)); + u_uint = static_cast<uint8_t>(CLIP3((new_uv.u * 255.0f + 128.0f + 0.5f), 0, 255)); + v_uint = static_cast<uint8_t>(CLIP3((new_uv.v * 255.0f + 128.0f + 0.5f), 0, 255)); } //////////////////////////////////////////////////////////////////////////////// |