1 /* 2 * Copyright 2014, 2016 Peter Olsson 3 * 4 * This file is part of Brum Brum Rally. 5 * 6 * Brum Brum Rally is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * Brum Brum Rally is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef DCOLOR_H 21 #define DCOLOR_H 22 23 #include "SDL.h" 24 #include <cstddef> 25 26 struct DColor 27 { 28 double r; 29 double g; 30 double b; 31 }; 32 33 struct Scale32 34 { 35 typedef Uint32 PixelType; 36 static const std::size_t pixelSize = 1; readColorsScale3237 static inline void readColors(const Uint32* src, DColor& c) 38 { 39 Uint32 p = *(src); 40 c.r = (p & 0xFF0000) >> 16; 41 c.g = (p & 0x00FF00) >> 8; 42 c.b = (p & 0x0000FF); 43 } writeColorsScale3244 static inline void writeColors(Uint32* dst, const DColor& c) 45 { 46 *dst = (int(c.r) << 16) | (int(c.g) << 8) | int(c.b); 47 } 48 }; 49 50 struct Scale24 51 { 52 typedef Uint8 PixelType; 53 static const std::size_t pixelSize = 3; readColorsScale2454 static inline void readColors(const Uint8* src, DColor& c) 55 { 56 c.r = src[0]; 57 c.g = src[1]; 58 c.b = src[2]; 59 } 60 writeColorsScale2461 static inline void writeColors(Uint8* dst, const DColor& c) 62 { 63 dst[0] = c.r; 64 dst[1] = c.g; 65 dst[2] = c.b; 66 } 67 }; 68 69 #endif 70