I am curently playing with Dart and especially dart:typed_data. I stumbled across a class where I have no idea what its purpose/speciality is. I speak of Uint8ClampedList. The difference to the Uint8List in the documentation is the sentence
Indexed store clamps the value to range 0..0xFF.
What does that sentence actually mean? Why does this class exist? I am really curious.
"Clamping" means that values below 0 become 0 and values above 0xff become 0xff when stored into the Uint8ClampedList
. Any value in the range 0..0xff can be stored into the list without change.
This differs from other typed lists where the value is instead just truncated to the low 8 (or 16 or 32) bits.
The clamped list (and the name itself) mirrors the Uint8ClampedArray of JavaScript.
One usage of clamping that I have seen is for RGB(A) color images, where really over-saturated colors (e.g., and R value > 255) would be capped at the maximum value instead of wrapping around and becoming dark. It allows you to make some transformations on the values without having to care about handling overflow. See the Uint8ClampedArray specification - it was introduced to have an array type matching the behavior of an existing canvas type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With