VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
grcolour16.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Graeme Walker
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 ///
18 /// \file grcolour16.h
19 ///
20 
21 #ifndef GR_COLOUR16__H
22 #define GR_COLOUR16__H
23 
24 #include "gdef.h"
25 
26 namespace Gr
27 {
28  namespace colour16
29  {
30  // generators for the standard sixteen-colour bios palette -- see wikipedia 'bios_color_attributes'
31  //
32  // 0 (0,0,0) black
33  // 1 (0,0,1) dark blue
34  // 2 (0,1,0) dark green
35  // 3 (0,1,1) dark cyan
36  // 4 (1,0,0) dark red
37  // 5 (1,0,1) dark magenta
38  // 6 (1,1,0) dark yellow (brown)
39  // 7 (1,2,2) bright grey-ish
40  // 8 (1,1,1) dark grey
41  // 9 (0,0,2) bright blue
42  // 10 (0,2,0) bright green
43  // 11 (0,2,2) bright cyan
44  // 12 (2,0,0) bright red
45  // 13 (2,0,2) bright magenta
46  // 14 (2,2,0) bright yellow
47  // 15 (2,2,2) white
48  //
49  inline unsigned r( unsigned n ) { return (n==8U) ? 1U : ( (n&4U) ? ((n/8U)+1U) : 0U ) ; }
50  inline unsigned g( unsigned n ) { return (n==7U) ? 2U : ( (n==8U) ? 1U : ( (n&2U) ? ((n/8U)+1U) : 0U ) ) ; }
51  inline unsigned b( unsigned n ) { return ((n&1U) << ((n>8U)?1:0) ) + (n==7U||n==8U) ; }
52  inline unsigned _256( unsigned n ) { return n == 0U ? 0U : ( n == 1U ? 127U : 255U ) ; }
53  inline unsigned r256( unsigned n ) { return _256(r(n)) ; }
54  inline unsigned g256( unsigned n ) { return _256(g(n)) ; }
55  inline unsigned b256( unsigned n ) { return _256(b(n)) ; }
56  } ;
57 }
58 
59 #endif