Browse Source

Implement CelGetFrame (CEL decoder helper)

This implements the first of the inlined CEL decoder helper functions
that are still visable in the Mac port code.

Functions are still bin exact
pull/292/head
Anders Jenbo 7 years ago
parent
commit
ce6fc51b50
  1. 8
      Source/control.cpp
  2. 50
      Source/engine.cpp
  3. 2
      Source/engine.h
  4. 12
      defs.h

8
Source/control.cpp

@ -726,14 +726,12 @@ void CPrintString(int nOffset, int nCel, char col)
labret:
}
#else
int i;
int i, nDataSize;
BYTE width, pix;
BYTE *src, *dst, *end;
DWORD *pFrameTable;
pFrameTable = (DWORD *)&pPanelText[4 * nCel];
src = &pPanelText[pFrameTable[0]];
end = &src[pFrameTable[1] - pFrameTable[0]];
src = CelGetFrame(pPanelText, nCel, &nDataSize);
end = &src[nDataSize];
dst = &gpBuffer[nOffset];
switch (col) {

50
Source/engine.cpp

@ -19,6 +19,18 @@ BOOL gbNotInView; // valid - if x/y are in bounds
const int RndInc = 1;
const int RndMult = 0x015A4E35;
__FINLINE BYTE *CelGetFrame(BYTE *pCelBuff, int nCel, int *nDataSize)
{
DWORD *pFrameTable;
DWORD nCellStart;
pFrameTable = (DWORD *)pCelBuff;
nCellStart = SwapLE32(pFrameTable[nCel]);
*nDataSize = SwapLE32(pFrameTable[nCel + 1]) - nCellStart;
return pCelBuff + nCellStart;
}
void CelDrawDatOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth)
{
int w;
@ -120,7 +132,8 @@ void CelDrawDatOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth)
void CelDecodeOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth)
{
DWORD *pFrameTable;
int nDataSize;
BYTE *pRLEBytes;
/// ASSERT: assert(gpBuffer);
if (!gpBuffer)
@ -129,18 +142,14 @@ void CelDecodeOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth)
if (!pCelBuff)
return;
pFrameTable = (DWORD *)pCelBuff;
CelDrawDatOnly(
&gpBuffer[sx + PitchTbl[sy]],
&pCelBuff[pFrameTable[nCel]],
pFrameTable[nCel + 1] - pFrameTable[nCel],
nWidth);
pRLEBytes = CelGetFrame(pCelBuff, nCel, &nDataSize);
CelDrawDatOnly(&gpBuffer[sx + PitchTbl[sy]], pRLEBytes, nDataSize, nWidth);
}
void CelDecDatOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth)
{
DWORD *pFrameTable;
int nDataSize;
BYTE *pRLEBytes;
/// ASSERT: assert(pCelBuff != NULL);
if (!pCelBuff)
@ -149,13 +158,8 @@ void CelDecDatOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth)
if (!pBuff)
return;
pFrameTable = (DWORD *)pCelBuff;
CelDrawDatOnly(
pBuff,
&pCelBuff[pFrameTable[nCel]],
pFrameTable[nCel + 1] - pFrameTable[nCel],
nWidth);
pRLEBytes = CelGetFrame(pCelBuff, nCel, &nDataSize);
CelDrawDatOnly(pBuff, pRLEBytes, nDataSize, nWidth);
}
/**
@ -580,7 +584,6 @@ void CelDecodeLightOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth)
{
int nDataSize;
BYTE *pDecodeTo, *pRLEBytes;
DWORD *pFrameTable;
/// ASSERT: assert(gpBuffer);
if (!gpBuffer)
@ -589,10 +592,7 @@ void CelDecodeLightOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth)
if (!pCelBuff)
return;
pFrameTable = (DWORD *)pCelBuff;
nDataSize = pFrameTable[nCel + 1] - pFrameTable[nCel];
pRLEBytes = &pCelBuff[pFrameTable[nCel]];
pRLEBytes = CelGetFrame(pCelBuff, nCel, &nDataSize);
pDecodeTo = &gpBuffer[sx + PitchTbl[sy]];
if (light_table_index)
@ -1643,13 +1643,11 @@ void CelDecodeRect(BYTE *pBuff, int CelSkip, int hgt, int wdt, BYTE *pCelBuff, i
jnz label1
}
#else
int i;
int i, nDataSize;
BYTE width;
DWORD *pFrameTable;
pFrameTable = (DWORD *)&pCelBuff[4 * nCel];
pRLEBytes = &pCelBuff[pFrameTable[0]];
end = &pRLEBytes[pFrameTable[1] - pFrameTable[0]];
pRLEBytes = CelGetFrame(pCelBuff, nCel, &nDataSize);
end = &pRLEBytes[nDataSize];
dst = &pBuff[hgt * wdt + CelSkip];
for (; pRLEBytes != end; dst -= wdt + nWidth) {

2
Source/engine.h

@ -11,6 +11,8 @@ extern int orgseed;
extern int SeedCount;
extern BOOL gbNotInView; // valid - if x/y are in bounds
__FINLINE BYTE *CelGetFrame(BYTE *pCelBuff, int nCel, int *nDataSize);
void CelDrawDatOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth);
void CelDecodeOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth);
void CelDecDatOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth);

12
defs.h

@ -173,3 +173,15 @@ typedef void (*_PVFV)(void);
#else
#define ALIGN_BY_1
#endif
#if (_MSC_VER == 1200)
#define __FINLINE __forceinline
#else
#define __FINLINE
#endif
#ifndef _BIG_ENDIAN_
#define SwapLE32
#else
#define SwapLE32(value) (value << 24 | (value & 0xFF00) << 8 | (value & 0xFF0000) >> 8 | value >> 24);
#endif

Loading…
Cancel
Save