ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
conversion.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef GRAPHICS_CONVERSION_H
23 #define GRAPHICS_CONVERSION_H
24 
25 #include "common/util.h"
26 
27 namespace Graphics {
28 
39 inline static void YUV2RGB(byte y, byte u, byte v, byte &r, byte &g, byte &b) {
40  r = CLIP<int>(y + ((1357 * (v - 128)) >> 10), 0, 255);
41  g = CLIP<int>(y - (( 691 * (v - 128)) >> 10) - ((333 * (u - 128)) >> 10), 0, 255);
42  b = CLIP<int>(y + ((1715 * (u - 128)) >> 10), 0, 255);
43 }
44 
46 inline static void RGB2YUV(byte r, byte g, byte b, byte &y, byte &u, byte &v) {
47  y = CLIP<int>( ((r * 306) >> 10) + ((g * 601) >> 10) + ((b * 117) >> 10) , 0, 255);
48  u = CLIP<int>(-((r * 172) >> 10) - ((g * 340) >> 10) + ((b * 512) >> 10) + 128, 0, 255);
49  v = CLIP<int>( ((r * 512) >> 10) - ((g * 429) >> 10) - ((b * 83) >> 10) + 128, 0, 255);
50 }
51 
53 } // End of namespace Graphics
54 
55 #endif // GRAPHICS_CONVERSION_H
Definition: formatinfo.h:28