~ubuntu-branches/debian/jessie/scummvm/jessie

« back to all changes in this revision

Viewing changes to graphics/conversion.h

  • Committer: Bazaar Package Importer
  • Author(s): Moritz Muehlenhoff
  • Date: 2010-05-07 18:57:09 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20100507185709-34v8yycywjrou5o3
Tags: upstream-1.1.1
ImportĀ upstreamĀ versionĀ 1.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-1-1-1/graphics/conversion.h $
 
22
 * $Id: conversion.h 47541 2010-01-25 01:39:44Z lordhoto $
 
23
 *
 
24
 */
 
25
 
 
26
#ifndef GRAPHICS_CONVERSION_H
 
27
#define GRAPHICS_CONVERSION_H
 
28
 
 
29
#include "common/util.h"
 
30
#include "graphics/pixelformat.h"
 
31
 
 
32
namespace Graphics {
 
33
 
 
34
/** Converting a color from YUV to RGB colorspace. */
 
35
inline static void YUV2RGB(byte y, byte u, byte v, byte &r, byte &g, byte &b) {
 
36
        r = CLIP<int>(y + ((1357 * (v - 128)) >> 10), 0, 255);
 
37
        g = CLIP<int>(y - (( 691 * (v - 128)) >> 10) - ((333 * (u - 128)) >> 10), 0, 255);
 
38
        b = CLIP<int>(y + ((1715 * (u - 128)) >> 10), 0, 255);
 
39
}
 
40
 
 
41
/** Converting a color from RGB to YUV colorspace. */
 
42
inline static void RGB2YUV(byte r, byte g, byte b, byte &y, byte &u, byte &v) {
 
43
        y = CLIP<int>( ((r * 306) >> 10) + ((g * 601) >> 10) + ((b * 117) >> 10)      , 0, 255);
 
44
        u = CLIP<int>(-((r * 172) >> 10) - ((g * 340) >> 10) + ((b * 512) >> 10) + 128, 0, 255);
 
45
        v = CLIP<int>( ((r * 512) >> 10) - ((g * 429) >> 10) - ((b *  83) >> 10) + 128, 0, 255);
 
46
}
 
47
 
 
48
/** Converting a color from YUV to RGB colorspace, Cinepak style. */
 
49
inline static void CPYUV2RGB(byte y, byte u, byte v, byte &r, byte &g, byte &b) {
 
50
        r = CLIP<int>(y + 2 * (v - 128), 0, 255);
 
51
        g = CLIP<int>(y - (u - 128) / 2 - (v - 128), 0, 255);
 
52
        b = CLIP<int>(y + 2 * (u - 128), 0, 255);
 
53
}
 
54
 
 
55
// TODO: generic YUV to RGB blit
 
56
 
 
57
/**
 
58
 * Blits a rectangle from one graphical format to another.
 
59
 *
 
60
 * @param dstbuf        the buffer which will recieve the converted graphics data
 
61
 * @param srcbuf        the buffer containing the original graphics data
 
62
 * @param dstpitch      width in bytes of one full line of the dest buffer
 
63
 * @param srcpitch      width in bytes of one full line of the source buffer
 
64
 * @param w                     the width of the graphics data
 
65
 * @param h                     the height of the graphics data
 
66
 * @param dstFmt        the desired pixel format
 
67
 * @param srcFmt        the original pixel format
 
68
 * @return                      true if conversion completes successfully,
 
69
 *                                      false if there is an error.
 
70
 *
 
71
 * @note This implementation currently arbitrarily requires that the
 
72
 *               destination's format have at least as high a bytedepth as
 
73
 *               the source's.
 
74
 * @note This can convert a rectangle in place, if the source and
 
75
 *               destination format have the same bytedepth.
 
76
 *
 
77
 */
 
78
bool crossBlit(byte *dst, const byte *src, int dstpitch, int srcpitch,
 
79
                                                int w, int h, const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt);
 
80
 
 
81
} // End of namespace Graphics
 
82
 
 
83
#endif // GRAPHICS_CONVERSION_H