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 #ifndef GRAPHICS_CONVERSION_H
24 #define GRAPHICS_CONVERSION_H
25
26 #include "common/util.h"
27
28 namespace Graphics {
29
30 struct PixelFormat;
31
32 /** Converting a color from YUV to RGB colorspace. */
YUV2RGB(byte y,byte u,byte v,byte & r,byte & g,byte & b)33 inline static void YUV2RGB(byte y, byte u, byte v, byte &r, byte &g, byte &b) {
34 r = CLIP<int>(y + ((1357 * (v - 128)) >> 10), 0, 255);
35 g = CLIP<int>(y - (( 691 * (v - 128)) >> 10) - ((333 * (u - 128)) >> 10), 0, 255);
36 b = CLIP<int>(y + ((1715 * (u - 128)) >> 10), 0, 255);
37 }
38
39 /** Converting a color from RGB to YUV colorspace. */
RGB2YUV(byte r,byte g,byte b,byte & y,byte & u,byte & v)40 inline static void RGB2YUV(byte r, byte g, byte b, byte &y, byte &u, byte &v) {
41 y = CLIP<int>( ((r * 306) >> 10) + ((g * 601) >> 10) + ((b * 117) >> 10) , 0, 255);
42 u = CLIP<int>(-((r * 172) >> 10) - ((g * 340) >> 10) + ((b * 512) >> 10) + 128, 0, 255);
43 v = CLIP<int>( ((r * 512) >> 10) - ((g * 429) >> 10) - ((b * 83) >> 10) + 128, 0, 255);
44 }
45
46 // TODO: generic YUV to RGB blit
47
48 /**
49 * Blits a rectangle from one graphical format to another.
50 *
51 * @param dst the buffer which will recieve the converted graphics data
52 * @param src the buffer containing the original graphics data
53 * @param dstPitch width in bytes of one full line of the dest buffer
54 * @param srcPitch width in bytes of one full line of the source buffer
55 * @param w the width of the graphics data
56 * @param h the height of the graphics data
57 * @param dstFmt the desired pixel format
58 * @param srcFmt the original pixel format
59 * @return true if conversion completes successfully,
60 * false if there is an error.
61 *
62 * @note Blitting to a 3Bpp destination is not supported
63 * @note This can convert a surface in place, regardless of the
64 * source and destination format, as long as there is enough
65 * space for the destination. The dstPitch / srcPitch ratio
66 * must at least equal the dstBpp / srcBpp ratio for
67 * dstPitch >= srcPitch and at most dstBpp / srcBpp for
68 * dstPitch < srcPitch though.
69 */
70 bool crossBlit(byte *dst, const byte *src,
71 const uint dstPitch, const uint srcPitch,
72 const uint w, const uint h,
73 const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt);
74
75 } // End of namespace Graphics
76
77 #endif // GRAPHICS_CONVERSION_H
78