📄 colorconversion.h
字号:
for (j=0; j<Size.cx; j++)
{
U = *pRaw++;
Y = *pRaw++;
V = *pRaw++;
deltaG = LUT_G_U[U] + LUT_G_V[V];
deltaR = LUT_R_V[V];
deltaB = LUT_B_U[U];
R = Y + deltaR;
G = Y - deltaG;
B = Y + deltaB;
if (R < 0)
R = 0;
else if (R > 255) R = 255;
if (G < 0)
G = 0;
else if (G > 255)
G = 255;
if (B < 0)
B = 0;
else if (B > 255)
B = 255;
*pData++ = (unsigned char) B;
*pData++ = (unsigned char) G;
*pData++ = (unsigned char) R;
j++;
Y = *pRaw++;
R = Y + deltaR;
G = Y - deltaG;
B = Y + deltaB;
if (R < 0)
R = 0;
else if (R > 255) R = 255;
if (G < 0)
G = 0;
else if (G > 255)
G = 255;
if (B < 0)
B = 0;
else if (B > 255)
B = 255;
*pData++ = (unsigned char) B;
*pData++ = (unsigned char) G;
*pData++ = (unsigned char) R;
}
}
}
//------------------------------------------------------------------------------
// void CColorConversion::ConvertMono8ToRGB(PBYTE pDest, const PBYTE pSource, const CSize& Size, const CPoint& PatternOrigin, const BYTE const pLutR, const PBYTE const pLutG, const PBYTE const pLutB)
// Author:
//------------------------------------------------------------------------------
/**
* Conversion of Bayer raw pixel data to RGB. The user has to specify the origin of the Bayer pattern and to provide
* lookup tables for the color channels (e.g. for white balance purposes)
*
* \param pDest Pointer to which the RGB data will be written
* \param pSource Pointer to the raw Bayer pixel data to be converted
* \param Size Size of image
* \param PatternOrigin Spezifies wether the first pixel of the bayer raw data is a red, blue or green one
* ( poGB : green pixel followed by a blue pixel, poGR : green pixel followd by a red pixel,
poR : red pixel, poB : blue pixel )
* \param pLutG Pointer to a lookup table for the green channel
* \param pLutB Pointer to a lookup table for the red channel
* \param pLutR Pointer to a lookup table for the blue channel
* \return
*
* void
*
* \see <delete line if not used>
* \todo
*/
//------------------------------------------------------------------------------
void CColorConversion::ConvertMono8ToRGB(PBYTE pDest, const PBYTE pSource, const CSize& Size, PatternOrigin_t PatternOrigin,
const BYTE pLutR[256], const BYTE pLutG[256], const BYTE pLutB[256])
{
assert ( Size.cx % 2 == 0 && Size.cy % 2 == 0 );//宽度和高度必须是2的倍数,否则产生错误
assert ( Size.cx > 3);//必须大于3
switch ( PatternOrigin)
{
case poGB://GBRG
// Bayer Image starts with a GBGB row
ProcessGBLines((RGBTRIPLE*) pDest, pSource, Size, 0, pLutR, pLutG, pLutB);
ProcessRGLines((RGBTRIPLE*) pDest, pSource, Size, 1, pLutR, pLutG, pLutB);
break;
case poGR://GRBG
// Bayer Image starts with a GRGR row
ProcessGRLines((RGBTRIPLE*) pDest, pSource, Size, 0, pLutR, pLutG, pLutB);
ProcessBGLines((RGBTRIPLE*) pDest, pSource, Size, 1, pLutR, pLutG, pLutB);
break;
case poB://BGGR
// Bayer Image starts with a BGBG row
ProcessBGLines((RGBTRIPLE*) pDest, pSource, Size, 0, pLutR, pLutG, pLutB);
ProcessGRLines((RGBTRIPLE*) pDest, pSource, Size, 1, pLutR, pLutG, pLutB);
break;
case poR://RGGB//A312fc
// Bayer Image starts with a RGRG row
ProcessRGLines((RGBTRIPLE*) pDest, pSource, Size, 0, pLutR, pLutG, pLutB);
ProcessGBLines((RGBTRIPLE*) pDest, pSource, Size, 1, pLutR, pLutG, pLutB);
break;
}
// Treatment of the border: Erase the right most column and the last row of the destination image
RGBTRIPLE *pRGB = (RGBTRIPLE*) pDest;
RGBTRIPLE zero = {0, 0, 0};
// set the right most column to zero
int i;
for ( i = 0; i < Size.cy; i++ )
{
pRGB[(i+1) * Size.cx - 1] = zero;
}
// set the last row to zero
for ( i = 0; i < Size.cx; i ++ )
{
pRGB[i] = zero;
}
}
#define REDPIXEL() \
pRGB->rgbtBlue = pLutB[*(pRaw + Size.cx + 1)]; \
pRGB->rgbtGreen = pLutG[(BYTE) ( ( (int) *(pRaw +1) + (int) *(pRaw + Size.cx) ) >> 1 )]; \
pRGB->rgbtRed = pLutR[*pRaw]; \
++pRaw; \
++pRGB;
#define BLUEPIXEL() \
pRGB->rgbtBlue = pLutB[*pRaw]; \
pRGB->rgbtGreen = pLutG[(BYTE) ( ( (int) *( pRaw + 1) + (int) *( pRaw + Size.cx ) ) >> 1 )]; \
pRGB->rgbtRed = pLutR[*(pRaw + Size.cx + 1)]; \
++pRaw; \
++pRGB;
#define GREENPIXEL_R() \
pRGB->rgbtBlue = pLutB[*(pRaw + Size.cx )]; \
pRGB->rgbtGreen = pLutG[*pRaw]; \
pRGB->rgbtRed = pLutR[*(pRaw + 1)]; \
++pRaw; \
++pRGB;
#define GREENPIXEL_B() \
pRGB->rgbtBlue = pLutB[*(pRaw + 1)]; \
pRGB->rgbtGreen = pLutG[*pRaw]; \
pRGB->rgbtRed = pLutR[*(pRaw + Size.cx)]; \
++pRaw; \
++pRGB;
void CColorConversion::ProcessGBLines(RGBTRIPLE* pDest, const PBYTE pSource, const CSize& Size, unsigned int lineoffset,
const BYTE pLutR[256], const BYTE pLutG[256], const BYTE pLutB[256])
{
unsigned char* pLastLine = pSource + Size.cx * ( Size.cy - 1);
unsigned char* pRaw = pSource + lineoffset * Size.cx;
RGBTRIPLE* pRGB = pDest + Size.cx * (Size.cy - lineoffset - 1);
unsigned char* pEnd;
while ( pRaw < pLastLine )
{
pEnd = pRaw + Size.cx - 2; // we skip the last column
while ( pRaw < pEnd )
{
GREENPIXEL_B();
BLUEPIXEL();
}
GREENPIXEL_B();
pRaw += Size.cx + 1;
pRGB -= ( 3 * Size.cx - 1 );
}
}
void CColorConversion::ProcessRGLines(RGBTRIPLE* pDest, const PBYTE pSource, const CSize& Size, unsigned int lineoffset,
const BYTE pLutR[256], const BYTE pLutG[256], const BYTE pLutB[256])
{
unsigned char* pLastLine = pSource + Size.cx * ( Size.cy - 1);
unsigned char* pRaw = pSource + lineoffset * Size.cx;
RGBTRIPLE* pRGB = pDest + Size.cx * (Size.cy - lineoffset - 1);
unsigned char* pEnd;
while ( pRaw < pLastLine )
{
pEnd = pRaw + Size.cx - 2; // we skip the last column
while ( pRaw < pEnd )
{
REDPIXEL();
GREENPIXEL_R();
}
REDPIXEL();
pRaw += Size.cx + 1;
pRGB -= ( 3 * Size.cx - 1 );
}
}
void CColorConversion::ProcessBGLines(RGBTRIPLE* pDest, const PBYTE pSource, const CSize& Size, unsigned int lineoffset,
const BYTE pLutR[256], const BYTE pLutG[256], const BYTE pLutB[256])
{
unsigned char* pLastLine = pSource + Size.cx * ( Size.cy - 1);
unsigned char* pRaw = pSource + lineoffset * Size.cx;
RGBTRIPLE* pRGB = pDest + Size.cx * (Size.cy - lineoffset - 1);
unsigned char* pEnd;
while ( pRaw < pLastLine )
{
pEnd = pRaw + Size.cx - 2; // we skip the last column
while ( pRaw < pEnd )
{
BLUEPIXEL();
GREENPIXEL_B();
}
BLUEPIXEL();
pRaw += Size.cx + 1;
pRGB -= ( 3 * Size.cx - 1 );
}
}
void CColorConversion::ProcessGRLines(RGBTRIPLE* pDest, const PBYTE pSource, const CSize& Size, unsigned int lineoffset,
const BYTE pLutR[256], const BYTE pLutG[256], const BYTE pLutB[256])
{
unsigned char* pLastLine = pSource + Size.cx * ( Size.cy - 1);
unsigned char* pRaw = pSource + lineoffset * Size.cx;
RGBTRIPLE* pRGB = pDest + Size.cx * (Size.cy - lineoffset - 1);
unsigned char* pEnd;
while ( pRaw < pLastLine )
{
pEnd = pRaw + Size.cx - 2; // we skip the last column
while ( pRaw < pEnd )
{
GREENPIXEL_R();
REDPIXEL();
}
GREENPIXEL_R();
pRaw += Size.cx + 1;
pRGB -= ( 3 * Size.cx - 1 );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -