mirror of
				https://github.com/sharkdp/bat.git
				synced 2025-11-04 09:01:56 +00:00 
			
		
		
		
	Avoid floating point arithmetic in RGB→8-bit ANSI approximation
This commit is contained in:
		
				
					committed by
					
						
						David Peter
					
				
			
			
				
	
			
			
			
						parent
						
							5b421b455d
						
					
				
				
					commit
					5c95b8803b
				
			@@ -13,14 +13,10 @@ fn rgb2ansi(r: u8, g: u8, b: u8) -> u8 {
 | 
			
		||||
        } else if r > 248 {
 | 
			
		||||
            WHITE
 | 
			
		||||
        } else {
 | 
			
		||||
            let fr = f32::from(r);
 | 
			
		||||
            (((fr - 8.) / 247.) * 24.) as u8 + 232
 | 
			
		||||
            ((r - 8) as u16 * 24 / 247) as u8 + 232
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        let fr = f32::from(r);
 | 
			
		||||
        let fg = f32::from(g);
 | 
			
		||||
        let fb = f32::from(b);
 | 
			
		||||
        16 + (36 * (fr / 255. * 5.) as u8) + (6 * (fg / 255. * 5.) as u8) + (fb / 255. * 5.) as u8
 | 
			
		||||
        36 * (r / 51) + 6 * (g / 51) + (b / 51) + 16
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user