summaryrefslogtreecommitdiff
path: root/src/lib/image.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-05-25 00:32:39 +0200
committerCarl Hetherington <cth@carlh.net>2021-05-25 21:35:12 +0200
commit71f3520ea315fb65ff151c99aa0b64fc8dccdb1d (patch)
treea09a8200a7ca14cada2e4b72ff40a1adb0b44f32 /src/lib/image.cc
parentb26f4e4cfa0a3b6df794f3207b420a413c52e773 (diff)
Clamp results correctly when shifting video levels, and account for that in tests.
Diffstat (limited to 'src/lib/image.cc')
-rw-r--r--src/lib/image.cc4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/lib/image.cc b/src/lib/image.cc
index 4859ebe14..eff53a2aa 100644
--- a/src/lib/image.cc
+++ b/src/lib/image.cc
@@ -1433,7 +1433,7 @@ Image::video_range_to_full_range ()
for (int y = 0; y < lines; ++y) {
uint8_t* q = p;
for (int x = 0; x < line_size()[0]; ++x) {
- *q = int((*q - 16) * factor);
+ *q = clamp(lrintf((*q - 16) * factor), 0L, 255L);
++q;
}
p += stride()[0];
@@ -1450,7 +1450,7 @@ Image::video_range_to_full_range ()
uint16_t* q = p;
int const line_size_pixels = line_size()[c] / 2;
for (int x = 0; x < line_size_pixels; ++x) {
- *q = int((*q - 256) * factor);
+ *q = clamp(lrintf((*q - 256) * factor), 0L, 4095L);
++q;
}
}