ultrahdr: fix visual artifacts in api-1 due to overflows
Bug:
Test: ./ultrahdr_unit_test
Change-Id: If31016ece14372579aa14c1007806258384f30ab
diff --git a/libs/ultrahdr/gainmapmath.cpp b/libs/ultrahdr/gainmapmath.cpp
index ee15363..8015a4e 100644
--- a/libs/ultrahdr/gainmapmath.cpp
+++ b/libs/ultrahdr/gainmapmath.cpp
@@ -547,13 +547,13 @@
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));
}
////////////////////////////////////////////////////////////////////////////////