📄 pg_util.cpp
字号:
return PG_STATUS_SUCCESS;
}
/**
* PGUtilHalfDecode - Decode the rle data at half resolution
*
* @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
*/
PG_STATUS PGUtilHalfDecode(BYTE *Input, ULONG InputSize, BYTE *Output, ULONG OutputSize, ULONG Pitch, ULONG OutputWidth)
{
BYTE PixelCode = 0;
ULONG Index = 0;
ULONG RunLength = 0;
ULONG OutputIndex = 0;
ULONG PitchDelta = 0;
ULONG PixelsOutput = 0;
int HalfPixel = 0;
if (Pitch != ((OutputWidth+1) >> 1))
{
PitchDelta = Pitch - ((OutputWidth+1) >> 1);
}
/* 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 PG_STATUS_RLE_ERROR;
}
/* if we have a half a pixel already put this one down */
if (HalfPixel == 1)
{
/* put the pixel down */
Output[OutputIndex++] = PixelCode;
PixelsOutput++;
HalfPixel = 0;
}
else
{
HalfPixel = 1;
}
}
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]);
PixelCode = 0;
if (PixelsOutput + RunLength > OutputSize)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PGRLEDecode(): rle decode error, output size too big\n"));
return PG_STATUS_RLE_ERROR;
}
if ((RunLength & 0x01) == 0)
{
/* even run, just put half down, don't touch half pixel value */
RunLength = RunLength >> 1;
memset(&Output[OutputIndex], 0, RunLength);
OutputIndex += RunLength;
PixelsOutput += RunLength;
}
else
{
/* odd run length */
if (HalfPixel == 1)
{
/* odd run with a half pixel, put half the run down
and make half pixel zero */
RunLength = (RunLength+1) >> 1;
memset(&Output[OutputIndex], 0, RunLength);
OutputIndex += RunLength;
PixelsOutput += RunLength;
HalfPixel = 0;
}
else
{
/* odd run with no half pixels, put half the run down and
make halfpixel 1*/
RunLength = RunLength >> 1;
memset(&Output[OutputIndex], 0, RunLength);
OutputIndex += RunLength;
PixelsOutput += RunLength;
HalfPixel = 1;
}
}
}
else
{
/* put the last pixel down if there is one left */
if (HalfPixel == 1)
{
/* write out the pixel code */
Output[OutputIndex] = PixelCode;
OutputIndex++;
}
if (PitchDelta > 0)
{
/* fill the non used space with the clear color from the palette */
memset(&Output[OutputIndex], 0xff, PitchDelta);
OutputIndex += PitchDelta;
}
HalfPixel = 0;
break; /* got end of line */
}
}
else
{
RunLength = (RL64TO16K_TOP(Input[Index]) << 8) | Input[Index+1];
PixelCode = 0;
if ((PixelsOutput + RunLength) > OutputSize)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PGRLEDecode(): rle decode error, output size too big\n"));
return PG_STATUS_RLE_ERROR;
}
if (RunLength > OutputWidth)
{
DbgPrint(("PGHalf: Run longer than image???\n"));
return PG_STATUS_ERROR;
}
if ((RunLength & 0x01) == 0)
{
/* even run, just put half down, don't touch half pixel value */
RunLength = RunLength >> 1;
memset(&Output[OutputIndex], 0, RunLength);
OutputIndex += RunLength;
PixelsOutput += RunLength;
}
else
{
/* odd run length */
if (HalfPixel == 1)
{
/* odd run with a half pixel, put half the run down and make halfpixel 0 */
RunLength = (RunLength+1) >> 1;
memset(&Output[OutputIndex], 0, RunLength);
OutputIndex += RunLength;
PixelsOutput += RunLength;
HalfPixel = 0;
}
else
{
/* odd run with no half pixels, put half the run down and make halfpixel 1 */
RunLength = RunLength >> 1;
memset(&Output[OutputIndex], 0, RunLength);
OutputIndex += RunLength;
PixelsOutput += RunLength;
HalfPixel = 1;
}
}
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;
}
if (RunLength > OutputWidth)
{
DbgPrint(("PGHalf: Run longer than image???\n"));
return PG_STATUS_ERROR;
}
/* get the next pixel code */
PixelCode = Input[Index];
if ((PixelsOutput + RunLength) > OutputSize)
{
DBGPRINT(DBG_ON(DBG_ERROR), ("PGRLEDecode(): rle decode error, output size too big\n"));
return PG_STATUS_RLE_ERROR;
}
if ((RunLength & 0x01) == 0)
{
/* even run, just put half down, don't touch half pixel value */
RunLength = RunLength >> 1;
memset(&Output[OutputIndex], PixelCode, RunLength);
OutputIndex += RunLength;
PixelsOutput += RunLength;
}
else
{
/* odd run length */
if (HalfPixel == 1)
{
/* odd run with a half pixel, put half the run down
and makd half pixel zero*/
RunLength = (RunLength+1) >> 1;
memset(&Output[OutputIndex], PixelCode, RunLength);
OutputIndex += RunLength;
PixelsOutput += RunLength;
HalfPixel = 0;
}
else
{
/* odd run with no half pixels, put half the run down and
make halfpixel 1*/
RunLength = RunLength >> 1;
memset(&Output[OutputIndex], PixelCode, RunLength);
OutputIndex += RunLength;
PixelsOutput += RunLength;
HalfPixel = 1;
}
}
}
}
/* move to the next byte */
Index++;
}
/* move to the next byte */
Index++;
}
return PG_STATUS_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -