clamp rgb values to 0-255

This commit is contained in:
synth-ruiner 2017-12-27 17:03:27 +00:00
parent 002863b88a
commit c79cca778f
1 changed files with 3 additions and 3 deletions

View File

@ -203,9 +203,9 @@ $(document).ready(function() {
for (var i = 0; i < rawData.length; i += 4) { for (var i = 0; i < rawData.length; i += 4) {
// this brightness adjustment is pretty crude but whatever // this brightness adjustment is pretty crude but whatever
var pixel = { var pixel = {
red: Math.min(rawData[i ] + brightnessAdjustment, 255), red: _.clamp(rawData[i ] + brightnessAdjustment, 0, 255),
green: Math.min(rawData[i + 1] + brightnessAdjustment, 255), green: _.clamp(rawData[i + 1] + brightnessAdjustment, 0, 255),
blue: Math.min(rawData[i + 2] + brightnessAdjustment, 255), blue: _.clamp(rawData[i + 2] + brightnessAdjustment, 0, 255),
}; };
var targetColour = getClosestColour(pixel, palette); var targetColour = getClosestColour(pixel, palette);