1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "bladerunner/color.h"
24
25 namespace BladeRunner {
26
27 // This array essentially stores the conversion from unsigned 5bit values to 8bit
28 // ie. ((int)i * 255) / 31 (integer division), for i values 0 to 31
29 // Note that just using a multiplier 256/16 (= 8) will not properly
30 // map the color, since eg. value 31 would be mapped to 248 instead of 255.
31 const uint8 Color::map5BitsTo8Bits[] = {0, 8, 16, 24, 32, 41, 49, 57, 65, 74, 82, 90, 98, 106, 115, 123, 131, 139, 148, 156, 164, 172, 180, 189, 197, 205, 213, 222, 230, 238, 246, 255};
32
get8BitColorFrom5Bit(uint8 col5b)33 uint8 Color::get8BitColorFrom5Bit(uint8 col5b) {
34 if (col5b > 31) {
35 // A value larger than 31 is invalid (never going to happen for 5bits)
36 // but still catch the case, since the parameter is 8bits
37 return 255;
38 }
39 return map5BitsTo8Bits[col5b];
40 }
41
42 } // End of namespace BladeRunner