blob: 4a51c31e2151eb5eeba613e5c02eff7182922a8b [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Copyright 2016 Joe Wilm, The Alacritty Project Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use std::ops::Mul;
#[derive(Debug, Eq, PartialEq, Copy, Clone, Default)]
pub struct Rgb {
pub r: u8,
pub g: u8,
pub b: u8,
}
// a multiply function for Rgb, as the default dim is just *2/3
impl Mul<f32> for Rgb {
type Output = Rgb;
fn mul(self, rhs: f32) -> Rgb {
let result = Rgb {
r: (f32::from(self.r) * rhs).max(0.0).min(255.0) as u8,
g: (f32::from(self.g) * rhs).max(0.0).min(255.0) as u8,
b: (f32::from(self.b) * rhs).max(0.0).min(255.0) as u8
};
trace!("Scaling RGB by {} from {:?} to {:?}", rhs, self, result);
result
}
}