📄 colorconversion.h
字号:
//-----------------------------------------------------------------------------
// (c) 2002 by Basler Vision Technologies
// Section: Vision Components
// Project: BCAM
// $Header: ColorConversion.h, 5, 10/9/02 7:13:31 PM, Nebelung, H.$
//-----------------------------------------------------------------------------
/**
\file ColorConversion.h
*
* \brief Utility class CColorConversion ( YUV -> RGB and Bayer8 -> RGB conversion)
*
*/
//-----------------------------------------------------------------------------
/*
YUV <-> RGB
range : 0 to 255 for Y, R, G, B
-128 to 127 for U and V
R = Y + 1.4022 V
G = Y - 0.3457 U - 0.7144 V
B = Y + 1.7710 U
Y = 0.2989 R + 0.5866 G + 0.1145 B
U = - 0.1688 R - 0.3312 G + 0.5 B
V = 0.5 R - 0.5184 G - 0.0817 B
*/
#pragma once
//------------------------------------------------------------------------------
// class CColorConversion
//------------------------------------------------------------------------------
/**
* \brief Perform the color conversion of Bayer8 or YUV images to RGB images
*
*/
//------------------------------------------------------------------------------
class CColorConversion
{
public:
/// Convert YUV422 to RGB
static void ConvertYUV422ToRGB(PBYTE pDest, const PBYTE pSource, const CSize& Size);
enum PatternOrigin_t
{
poGB = 1,
poGR,
poB,
poR
};
/// Convert Bayer raw data to RGB
static void ConvertMono8ToRGB(PBYTE pDest, const PBYTE pSource, const CSize& Size, PatternOrigin_t PatternOrigin,
const BYTE pLutR[256], const BYTE pLutG[256], const BYTE pLutB[256]);
private:
static void ProcessGBLines(RGBTRIPLE* pDest, const PBYTE pSource, const CSize& Size, unsigned int lineoffset,
const BYTE pLutR[256], const BYTE pLutG[256], const BYTE pLutB[256]);
static void ProcessRGLines(RGBTRIPLE* pDest, const PBYTE pSource, const CSize& Size, unsigned int lineoffset,
const BYTE pLutR[256], const BYTE pLutG[256], const BYTE pLutB[256]);
static void ProcessBGLines(RGBTRIPLE* pDest, const PBYTE pSource, const CSize& Size, unsigned int lineoffset,
const BYTE pLutR[256], const BYTE pLutG[256], const BYTE pLutB[256]);
static void ProcessGRLines(RGBTRIPLE* pDest, const PBYTE pSource, const CSize& Size, unsigned int lineoffset,
const BYTE pLutR[256], const BYTE pLutG[256], const BYTE pLutB[256]);
};
//------------------------------------------------------------------------------
// void CColorConversion::ConvertYUV422ToRGB(PBYTE pDest, const PBYTE pSource, const CSize& Size)
// Author:
//------------------------------------------------------------------------------
/**
* Conversion of YUV422 pixel data into RGB
*
* \param pDest Pointer to a buffer the RGB data will be written to
* \param pSource Pointer to the pixel data to be converted
* \param Size Size of image
* \return void
*
*/
//------------------------------------------------------------------------------
void CColorConversion::ConvertYUV422ToRGB(PBYTE pDest, const PBYTE pSource, const CSize& Size)
{
static const int LUT_G_U[256] = // ( U - 128 ) * 0.3457 + 0.5
{ -43 , -43 , -43 , -42 , -42 , -42 , -41 , -41 ,
-40 , -40 , -40 , -39 , -39 , -39 , -38 , -38 ,
-38 , -37 , -37 , -37 , -36 , -36 , -36 , -35 ,
-35 , -35 , -34 , -34 , -34 , -33 , -33 , -33 ,
-32 , -32 , -31 , -31 , -31 , -30 , -30 , -30 ,
-29 , -29 , -29 , -28 , -28 , -28 , -27 , -27 ,
-27 , -26 , -26 , -26 , -25 , -25 , -25 , -24 ,
-24 , -24 , -23 , -23 , -23 , -22 , -22 , -21 ,
-21 , -21 , -20 , -20 , -20 , -19 , -19 , -19 ,
-18 , -18 , -18 , -17 , -17 , -17 , -16 , -16 ,
-16 , -15 , -15 , -15 , -14 , -14 , -14 , -13 ,
-13 , -12 , -12 , -12 , -11 , -11 , -11 , -10 ,
-10 , -10 , -9 , -9 , -9 , -8 , -8 , -8 ,
-7 , -7 , -7 , -6 , -6 , -6 , -5 , -5 ,
-5 , -4 , -4 , -3 , -3 , -3 , -2 , -2 ,
-2 , -1 , -1 , -1 , 0 , 0 , 0 , 0 ,
0 , 0 , 1 , 1 , 1 , 2 , 2 , 2 ,
3 , 3 , 3 , 4 , 4 , 4 , 5 , 5 ,
6 , 6 , 6 , 7 , 7 , 7 , 8 , 8 ,
8 , 9 , 9 , 9 , 10 , 10 , 10 , 11 ,
11 , 11 , 12 , 12 , 12 , 13 , 13 , 13 ,
14 , 14 , 15 , 15 , 15 , 16 , 16 , 16 ,
17 , 17 , 17 , 18 , 18 , 18 , 19 , 19 ,
19 , 20 , 20 , 20 , 21 , 21 , 21 , 22 ,
22 , 22 , 23 , 23 , 24 , 24 , 24 , 25 ,
25 , 25 , 26 , 26 , 26 , 27 , 27 , 27 ,
28 , 28 , 28 , 29 , 29 , 29 , 30 , 30 ,
30 , 31 , 31 , 31 , 32 , 32 , 32 , 33 ,
33 , 34 , 34 , 34 , 35 , 35 , 35 , 36 ,
36 , 36 , 37 , 37 , 37 , 38 , 38 , 38 ,
39 , 39 , 39 , 40 , 40 , 40 , 41 , 41 ,
41 , 42 , 42 , 43 , 43 , 43 , 44
};
static const int LUT_G_V[256] = // ( V - 128 ) * 0.7144 + 0.5
{ -90 , -90 , -89 , -88 , -88 , -87 , -86 , -85 ,
-85 , -84 , -83 , -83 , -82 , -81 , -80 , -80 ,
-79 , -78 , -78 , -77 , -76 , -75 , -75 , -74 ,
-73 , -73 , -72 , -71 , -70 , -70 , -69 , -68 ,
-68 , -67 , -66 , -65 , -65 , -64 , -63 , -63 ,
-62 , -61 , -60 , -60 , -59 , -58 , -58 , -57 ,
-56 , -55 , -55 , -54 , -53 , -53 , -52 , -51 ,
-50 , -50 , -49 , -48 , -48 , -47 , -46 , -45 ,
-45 , -44 , -43 , -43 , -42 , -41 , -40 , -40 ,
-39 , -38 , -38 , -37 , -36 , -35 , -35 , -34 ,
-33 , -33 , -32 , -31 , -30 , -30 , -29 , -28 ,
-28 , -27 , -26 , -25 , -25 , -24 , -23 , -23 ,
-22 , -21 , -20 , -20 , -19 , -18 , -18 , -17 ,
-16 , -15 , -15 , -14 , -13 , -13 , -12 , -11 ,
-10 , -10 , -9 , -8 , -8 , -7 , -6 , -5 ,
-5 , -4 , -3 , -3 , -2 , -1 , 0 , 0 ,
0 , 1 , 1 , 2 , 3 , 4 , 4 , 5 ,
6 , 6 , 7 , 8 , 9 , 9 , 10 , 11 ,
11 , 12 , 13 , 14 , 14 , 15 , 16 , 16 ,
17 , 18 , 19 , 19 , 20 , 21 , 21 , 22 ,
23 , 24 , 24 , 25 , 26 , 26 , 27 , 28 ,
29 , 29 , 30 , 31 , 31 , 32 , 33 , 34 ,
34 , 35 , 36 , 36 , 37 , 38 , 39 , 39 ,
40 , 41 , 41 , 42 , 43 , 44 , 44 , 45 ,
46 , 46 , 47 , 48 , 49 , 49 , 50 , 51 ,
51 , 52 , 53 , 54 , 54 , 55 , 56 , 56 ,
57 , 58 , 59 , 59 , 60 , 61 , 61 , 62 ,
63 , 64 , 64 , 65 , 66 , 66 , 67 , 68 ,
69 , 69 , 70 , 71 , 71 , 72 , 73 , 74 ,
74 , 75 , 76 , 76 , 77 , 78 , 79 , 79 ,
80 , 81 , 81 , 82 , 83 , 84 , 84 , 85 ,
86 , 86 , 87 , 88 , 89 , 89 , 90
};
static const int LUT_B_U[256] = // ( V - 128 ) * 1.7710 + 0.5
{
-226 , -224 , -222 , -220 , -219 , -217 , -215 , -213 ,
-212 , -210 , -208 , -206 , -204 , -203 , -201 , -199 ,
-197 , -196 , -194 , -192 , -190 , -188 , -187 , -185 ,
-183 , -181 , -180 , -178 , -176 , -174 , -173 , -171 ,
-169 , -167 , -165 , -164 , -162 , -160 , -158 , -157 ,
-155 , -153 , -151 , -150 , -148 , -146 , -144 , -142 ,
-141 , -139 , -137 , -135 , -134 , -132 , -130 , -128 ,
-127 , -125 , -123 , -121 , -119 , -118 , -116 , -114 ,
-112 , -111 , -109 , -107 , -105 , -103 , -102 , -100 ,
-98 , -96 , -95 , -93 , -91 , -89 , -88 , -86 ,
-84 , -82 , -80 , -79 , -77 , -75 , -73 , -72 ,
-70 , -68 , -66 , -65 , -63 , -61 , -59 , -57 ,
-56 , -54 , -52 , -50 , -49 , -47 , -45 , -43 ,
-42 , -40 , -38 , -36 , -34 , -33 , -31 , -29 ,
-27 , -26 , -24 , -22 , -20 , -18 , -17 , -15 ,
-13 , -11 , -10 , -8 , -6 , -4 , -3 , -1 ,
0 , 2 , 4 , 5 , 7 , 9 , 11 , 12 ,
14 , 16 , 18 , 19 , 21 , 23 , 25 , 27 ,
28 , 30 , 32 , 34 , 35 , 37 , 39 , 41 ,
43 , 44 , 46 , 48 , 50 , 51 , 53 , 55 ,
57 , 58 , 60 , 62 , 64 , 66 , 67 , 69 ,
71 , 73 , 74 , 76 , 78 , 80 , 81 , 83 ,
85 , 87 , 89 , 90 , 92 , 94 , 96 , 97 ,
99 , 101 , 103 , 104 , 106 , 108 , 110 , 112 ,
113 , 115 , 117 , 119 , 120 , 122 , 124 , 126 ,
128 , 129 , 131 , 133 , 135 , 136 , 138 , 140 ,
142 , 143 , 145 , 147 , 149 , 151 , 152 , 154 ,
156 , 158 , 159 , 161 , 163 , 165 , 166 , 168 ,
170 , 172 , 174 , 175 , 177 , 179 , 181 , 182 ,
184 , 186 , 188 , 189 , 191 , 193 , 195 , 197 ,
198 , 200 , 202 , 204 , 205 , 207 , 209 , 211 ,
213 , 214 , 216 , 218 , 220 , 221 , 223
};
static const int LUT_R_V[256] = // ( V - 128 ) * 1.4022 + 0.5
{
-178 , -177 , -176 , -174 , -173 , -171 , -170 , -169 ,
-167 , -166 , -164 , -163 , -162 , -160 , -159 , -157 ,
-156 , -155 , -153 , -152 , -150 , -149 , -148 , -146 ,
-145 , -143 , -142 , -141 , -139 , -138 , -136 , -135 ,
-134 , -132 , -131 , -129 , -128 , -127 , -125 , -124 ,
-122 , -121 , -120 , -118 , -117 , -115 , -114 , -113 ,
-111 , -110 , -108 , -107 , -106 , -104 , -103 , -101 ,
-100 , -99 , -97 , -96 , -94 , -93 , -92 , -90 ,
-89 , -87 , -86 , -85 , -83 , -82 , -80 , -79 ,
-78 , -76 , -75 , -73 , -72 , -71 , -69 , -68 ,
-66 , -65 , -64 , -62 , -61 , -59 , -58 , -56 ,
-55 , -54 , -52 , -51 , -49 , -48 , -47 , -45 ,
-44 , -42 , -41 , -40 , -38 , -37 , -35 , -34 ,
-33 , -31 , -30 , -28 , -27 , -26 , -24 , -23 ,
-21 , -20 , -19 , -17 , -16 , -14 , -13 , -12 ,
-10 , -9 , -7 , -6 , -5 , -3 , -2 , 0 ,
0 , 1 , 3 , 4 , 6 , 7 , 8 , 10 ,
11 , 13 , 14 , 15 , 17 , 18 , 20 , 21 ,
22 , 24 , 25 , 27 , 28 , 29 , 31 , 32 ,
34 , 35 , 36 , 38 , 39 , 41 , 42 , 43 ,
45 , 46 , 48 , 49 , 50 , 52 , 53 , 55 ,
56 , 57 , 59 , 60 , 62 , 63 , 65 , 66 ,
67 , 69 , 70 , 72 , 73 , 74 , 76 , 77 ,
79 , 80 , 81 , 83 , 84 , 86 , 87 , 88 ,
90 , 91 , 93 , 94 , 95 , 97 , 98 , 100 ,
101 , 102 , 104 , 105 , 107 , 108 , 109 , 111 ,
112 , 114 , 115 , 116 , 118 , 119 , 121 , 122 ,
123 , 125 , 126 , 128 , 129 , 130 , 132 , 133 ,
135 , 136 , 137 , 139 , 140 , 142 , 143 , 144 ,
146 , 147 , 149 , 150 , 151 , 153 , 154 , 156 ,
157 , 158 , 160 , 161 , 163 , 164 , 165 , 167 ,
168 , 170 , 171 , 172 , 174 , 175 , 177
};
int Y, U, V;
int R, G, B;
int deltaG, deltaB, deltaR;
int i, j, i2, m, n;
unsigned char* pData;
unsigned char* pRaw;
for (i=0; i<Size.cy; i++)
{
i2 = Size.cy - i - 1;
m = 3*i*Size.cx;
n = 2*i2*Size.cx;
pData = pDest + m;
pRaw = (unsigned char*) pSource + n;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -