📄 ig_util.cpp
字号:
/*****************************************************************************
******************************************************************************
** **
** Copyright (c) 2005-2006 Videon Central, Inc. **
** All rights reserved. **
** **
** The computer program contained herein contains proprietary information **
** which is the property of Videon Central, Inc. The program may be used **
** and/or copied only with the written permission of Videon Central, Inc. **
** or in accordance with the terms and conditions stipulated in the **
** agreement/contract under which the programs have been supplied. **
** **
******************************************************************************
*****************************************************************************/
/**
* @file ig_util.cpp
*
* $Revision: 1.4 $
*
* IG utility functions
*
*/
#include "vdvd_types.h"
#include "ig_defs.h"
#include "ig_api.h"
#include "ig_util.h"
#define DEBUG_IG_UTIL DBG_ERROR
#define DBG_ON(x) (DEBUG_IG_UTIL >= x)
IG_STATUS IGUtilHalfDecode(BYTE *Input, ULONG InputSize, BYTE *Output, ULONG OutputSize, ULONG Pitch, ULONG OutputWidth);
/**
* IGMakeRGBfromYCrCb601 - color space conversion from YCrCbT to RGB
*
* @param y - y component
* @param cr - cr component
* @param cb - cb component
*
* @return
* int - 32 bit pixel code with byte position in RGB0 format
*/
ULONG IGMakeARGBfromYCrCb601(BYTE y, BYTE cr, BYTE cb, BYTE t)
{
ULONG pixel32;
BYTE *pixel = (BYTE *)&pixel32;
int r, g, b;
r = y + (int)(1.370705 * (cr-128));
g = y - (int)((0.698001 * (cr-128)) - (0.337633 * (cb-128)));
b = y + (int)(1.732446 * (cb-128));
/* pre-multiply alpha */
r = (t * r + 127) / 255;
b = (t * b + 127) / 255;
g = (t * g + 127) / 255;
if (r > 255) r = 255;
if (g > 255) g = 255;
if (b > 255) b = 255;
if (r < 0) r = 0;
if (g < 0) g = 0;
if (b < 0) b = 0;
pixel[0] = t; // A
pixel[1] = r; // R
pixel[2] = g; // G
pixel[3] = b; // B
return pixel32;
}
/**
* IGMakeARGBfromYCrCb709 - color space conversion from YCrCbT ITU-R BT.709 to RGB
*
* @param y - y component
* @param cr - cr component
* @param cb - cb component
*
* @return
* int - 32 bit pixel code with byte position in RGB0 format
*/
ULONG IGMakeARGBfromYCrCb709(BYTE y, BYTE cr, BYTE cb, BYTE t)
{
ULONG pixel32;
BYTE *pixel = (BYTE *)&pixel32;
int r, g, b;
r = y + (int)(1.540 * (cr-128));
g = y - (int)((0.459 * (cr-128)) - (0.183 * (cb-128)));
b = y + (int)(1.816 * (cb-128));
/* pre-multiply alpha */
r = (t * r + 127) / 255;
b = (t * b + 127) / 255;
g = (t * g + 127) / 255;
if (r > 255) r = 255;
if (g > 255) g = 255;
if (b > 255) b = 255;
if (r < 0) r = 0;
if (g < 0) g = 0;
if (b < 0) b = 0;
pixel[0] = t; // A
pixel[1] = r; // R
pixel[2] = g; // G
pixel[3] = b; // B
return pixel32;
}
/**
* IGRleDecode - Decode Run Length Encoded data according to BDROM spec, if the data sizes
* do not match what is expected, return an error
*
* @param BYTE *InData - the data to convert
* @param ULONG InputSize - the size of the input data in bytes
* @param PALETTE *Pal - the palette used for conversion
* @param BYTE *OutData - the output data (24 bit), this is 3/4 the InputSize in length
*
* @return IG_STATUS
*/
IG_STATUS IGRLEDecode(BYTE *Input, ULONG InputSize, BYTE *Output, ULONG OutputSize, ULONG Pitch, ULONG OutputWidth, ULONG HalfWidth)
{
BYTE PixelCode = 0;
ULONG Index = 0;
int RunLength = 0;
ULONG OutputIndex = 0;
ULONG PitchDelta = 0;
ULONG PixelsOutput = 0;
if (HalfWidth)
{
return IGUtilHalfDecode(Input, InputSize, Output, OutputSize, Pitch, OutputWidth);
}
/* check the pitch, if it's greater we have more memory
allocated then needs and need to skip some space*/
if (Pitch >= OutputWidth)
{
PitchDelta = Pitch - OutputWidth;
}
else
{
DbgPrint(("IGRLEDecode(): pitch invalid, pitch = %d, width = %d\n", Pitch, OutputWidth));
return IG_STATUS_RLE_ERROR;
}
/* while we still have data left */
while (Index < InputSize)
{
while (1) /* till we get an end of line */
{
if (Input[Index] != 0)
{
/* if we get a pixel write it out */
PixelCode = Input[Index];
if ((PixelsOutput+1) > OutputSize)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("IGRLEDecode(): rle decode error, output size too big\n"));
return IG_STATUS_RLE_ERROR;
}
Output[OutputIndex++] = PixelCode;
PixelsOutput++;
}
else
{
Index++;
/* check switches */
if (SWITCH_1(Input[Index]) == 0)
{
if (SWITCH_2(Input[Index]) == 0)
{
if (RLZERO(Input[Index]) != 0)
{
/* write out this many zero's */
RunLength = RLZERO(Input[Index]);
if (PixelsOutput + RunLength > OutputSize)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("IGRLEDecode(): rle decode error, output size too big\n"));
return IG_STATUS_RLE_ERROR;
}
memset(&Output[OutputIndex], 0, RunLength);
OutputIndex += RunLength;
PixelsOutput += RunLength;
}
else
{
OutputIndex += PitchDelta;
break; /* got end of line */
}
}
else
{
RunLength = (RL64TO16K_TOP(Input[Index]) << 8) | Input[Index+1];
if ((PixelsOutput + RunLength) > OutputSize)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("IGRLEDecode(): rle decode error, output size too big\n"));
return IG_STATUS_RLE_ERROR;
}
memset(&Output[OutputIndex], 0, RunLength);
OutputIndex += RunLength;
PixelsOutput += RunLength;
Index++;
}
}
else /* non zero pixelcode run */
{
if (SWITCH_2(Input[Index]) == 0)
{
RunLength = RL3TO63(Input[Index]);
Index++;
}
else
{
RunLength = (RL64TO16K_TOP(Input[Index]) << 8) | Input[Index+1];
Index += 2;
}
/* get the next pixel code */
PixelCode = Input[Index];
if ((PixelsOutput + RunLength) > OutputSize)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("IGRLEDecode(): rle decode error, output size too big\n"));
return IG_STATUS_RLE_ERROR;
}
/* write out the current pixel code */
memset(&Output[OutputIndex], PixelCode, RunLength);
OutputIndex += RunLength;
PixelsOutput += RunLength;
}
}
/* move to the next byte */
Index++;
}
/* move to the next byte */
Index++;
}
if (PixelsOutput != OutputSize)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("IGRLEDecode(): incorrect rle decode, data size does not match, %d %d\n", PixelsOutput, OutputSize));
return IG_STATUS_RLE_ERROR;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -