From cccde01c4b4e376e0d1b5f58bdc9b1fe70a9b930 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 8 May 2020 20:08:18 -0400 Subject: Allow specifying each channel's bit depth separately --- src/color/source.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src/color') diff --git a/src/color/source.rs b/src/color/source.rs index bd752d9..00a6326 100644 --- a/src/color/source.rs +++ b/src/color/source.rs @@ -17,20 +17,15 @@ pub trait ColorSource { #[derive(Debug)] pub struct AllColors { dims: [usize; 3], - shifts: [usize; 3], + shifts: [u32; 3], } impl AllColors { - /// Create an AllColors source with the given bit depth. - pub fn new(bits: usize) -> Self { - // Allocate bits from most to least perceptually important - let gbits = (bits + 2) / 3; - let rbits = (bits + 1) / 3; - let bbits = bits / 3; - + /// Create an AllColors source with the given bit depths. + pub fn new(r: u32, g: u32, b: u32) -> Self { Self { - dims: [1 << rbits, 1 << gbits, 1 << bbits], - shifts: [8 - rbits, 8 - gbits, 8 - bbits], + dims: [1 << r, 1 << g, 1 << b], + shifts: [8 - r, 8 - g, 8 - b], } } } -- cgit v1.2.3