source: trunk/src/testing/app/hd-video-player/YUV.h @ 4

Revision 4, 4.1 KB checked in by ajaworski, 13 years ago (diff)

Added modified SAGE sources

Line 
1/******************************************************************************
2 * SAGE - Scalable Adaptive Graphics Environment
3 *
4 * Copyright (C) 2004 Electronic Visualization Laboratory,
5 * University of Illinois at Chicago
6 *
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above
15 *    copyright notice, this list of conditions and the following disclaimer
16 *    in the documentation and/or other materials provided with the distribution.
17 *  * Neither the name of the University of Illinois at Chicago nor
18 *    the names of its contributors may be used to endorse or promote
19 *    products derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 * Direct questions, comments etc about SAGE to http://www.evl.uic.edu/cavern/forum/
34 *
35 *****************************************************************************/
36
37#ifndef _YUV_H
38#define _YUV_H
39
40#include <windows.h>
41#include "stdafx.h"
42
43#define YUV422  422
44#define YUV420  420
45
46class CYUVTable
47{
48public :
49        // Static methods
50        static BYTE GetY(const BYTE p_nR, const BYTE p_nG, const BYTE p_nB)
51        {
52                int y = (int)(0.299 * p_nR + 0.587 * p_nG + 0.114 * p_nB);
53                return max(0, min(y, 255));
54        };
55        static BYTE GetU(const BYTE p_nR, const BYTE p_nG, const BYTE p_nB)
56        {
57                int u = (int)(-0.169 * p_nR - 0.311 * p_nG + 0.500 * p_nB) + 128;
58                return max(0, min(u, 255));
59        };
60        static BYTE GetV(const BYTE p_nR, const BYTE p_nG, const BYTE p_nB)
61        {
62                int v = (int)(0.500 * p_nR - 0.419 * p_nG - 0.081 * p_nB) + 128;
63                return max(0, min(v, 255));
64        };
65
66//              pbRGB[i*3] = Y+0.956U+0.621V
67//              pbRGB[i*3+1] = Y+0.272U+0.647V
68//              pbRGB[i*3+2] = Y+1.1061U+1.703V
69
70        static BYTE GetR(const int p_nY, const int p_nU, const int p_nV)
71        {
72                int r = (int)(p_nY - 0.001 * (p_nU - 128) + 1.402 * (p_nV - 128));
73                return max(0, min(r, 255));
74        };
75        static BYTE GetG(const int p_nY, const int p_nU, const int p_nV)
76        {
77                int g = (int)(p_nY - 0.344 * (p_nU - 128) - 0.714 * (p_nV - 128));
78                return max(0, min(g, 255));
79        };
80        static BYTE GetB(const int p_nY, const int p_nU, const int p_nV)
81        {
82                int b = (int)(p_nY + 1.772 * (p_nU - 128) + 0.001 * (p_nV - 128));
83                return max(0, min(b, 255));
84        };
85};
86
87
88class CYUVtoRGB24 {
89
90        int m_width, m_height;
91
92        int m_yuv_len;
93        int m_rgb_len;
94        int m_yuv_type;
95
96        unsigned char *m_rgb_buff;
97        unsigned char *m_yuv_buff;
98
99private :
100
101        void YUV422UYVY_ToRGB24(unsigned char *m_pbYUV, unsigned char *m_pbRGB, int m_yuv_len);
102        void YUV422YUY2_ToRGB24(unsigned char *m_pbYUV, unsigned char *m_pbRGB, int m_yuv_len);
103        void YUV420ToRGB24(unsigned char *m_pbYUV, unsigned char *m_pbRGB, int m_width, int m_height);
104        void YUV422UYVY_ToRGB24(BYTE *pbYUV, BYTE *pbRGB, int width, int height, int Stride);
105
106public :
107
108        CYUVtoRGB24();
109        ~CYUVtoRGB24();
110
111        // copy image data to yuv_buff
112        int SetYuvImage(unsigned char *buff, int len, int width, int height, int type);
113
114        // Conversion yuv data to RGB32 as defined yuv_type
115        int YUVtoRGB(void);
116
117        // return rgb image data
118        unsigned char* GetRgbImage(void);
119
120}; // class C_YUVtoRGB32
121
122#endif
Note: See TracBrowser for help on using the repository browser.