mirror of
https://github.com/1dot13/source.git
synced 2026-07-22 13:40:22 +02:00
Merged New Inventory Project into main branch
git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@1871 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
+41
-39
@@ -31,11 +31,11 @@ BOOLEAN ConvertToETRLE( UINT8 ** ppDest, UINT32 * puiDestLen, UINT8 ** ppSubImag
|
||||
#define CONVERT_ETRLE_FLIC_NAME 0x0800
|
||||
#define CONVERT_TO_8_BIT 0x1000
|
||||
#define CONVERT_TO_16_BIT 0x2000
|
||||
// NB 18-bit is actually 24 bit but with only 6 bits used in each byte. I implemented
|
||||
// NB 18-bit is actually 24 bit but with only 6 bits used in each byte. I implemented
|
||||
// it to see how well such images would compress with ZLIB.
|
||||
#define CONVERT_TO_18_BIT 0x4000
|
||||
|
||||
// Defines for inserting red/green/blue values into a 16-bit pixel.
|
||||
// Defines for inserting red/green/blue values into a 16-bit pixel.
|
||||
// MASK is the mask to use to get the proper bits out of a byte (part of a 24-bit pixel)
|
||||
// use SHIFT_RIGHT to move the masked bits to the lowest bits of the byte
|
||||
// use SHIFT_LEFT to put the bits in their proper place in the 16-bit pixel
|
||||
@@ -78,7 +78,7 @@ void ConvertRGBDistribution555To565( UINT16 * p16BPPData, UINT32 uiNumberOfPixel
|
||||
{
|
||||
UINT16 * pPixel;
|
||||
UINT32 uiLoop;
|
||||
|
||||
|
||||
SplitUINT32 Pixel;
|
||||
|
||||
pPixel = p16BPPData;
|
||||
@@ -99,7 +99,7 @@ void ConvertRGBDistribution555To565( UINT16 * p16BPPData, UINT32 uiNumberOfPixel
|
||||
}
|
||||
}
|
||||
|
||||
void WriteSTIFile( INT8 *pData, SGPPaletteEntry *pPalette, INT16 sWidth, INT16 sHeight, STR cOutputName, UINT32 fFlags, UINT32 uiAppDataSize )
|
||||
void WriteSTIFile( INT8 *pData, SGPPaletteEntry *pPalette, INT16 sWidth, INT16 sHeight, STR cOutputName, UINT32 fFlags, UINT32 uiAppDataSize )
|
||||
{
|
||||
|
||||
FILE * pOutput;
|
||||
@@ -120,10 +120,10 @@ void WriteSTIFile( INT8 *pData, SGPPaletteEntry *pPalette, INT16 sWidth, INT16 s
|
||||
UINT32 uiSubImageBufferSize=0;
|
||||
|
||||
//UINT16 usLoop;
|
||||
|
||||
|
||||
memset( &Header, 0, STCI_HEADER_SIZE );
|
||||
memset( &Image, 0, sizeof( image_type ));
|
||||
|
||||
|
||||
|
||||
uiOriginalSize = sWidth * sHeight * (8 / 8);
|
||||
|
||||
@@ -169,7 +169,7 @@ void WriteSTIFile( INT8 *pData, SGPPaletteEntry *pPalette, INT16 sWidth, INT16 s
|
||||
{
|
||||
return;
|
||||
}
|
||||
// write header
|
||||
// write header
|
||||
fwrite( &Header, STCI_HEADER_SIZE, 1, pOutput );
|
||||
// write palette and subimage structs, if any
|
||||
if (Header.fFlags & STCI_INDEXED)
|
||||
@@ -261,7 +261,6 @@ BOOLEAN ConvertToETRLE( UINT8 ** ppDest, UINT32 * puiDestLen, UINT8 ** ppSubImag
|
||||
BOOLEAN fNextExists;
|
||||
STCISubImage * pCurrSubImage;
|
||||
STCISubImage TempSubImage;
|
||||
UINT32 uiCompressedSize = 0;
|
||||
UINT32 uiSubImageCompressedSize;
|
||||
UINT32 uiSpaceLeft;
|
||||
|
||||
@@ -270,7 +269,7 @@ BOOLEAN ConvertToETRLE( UINT8 ** ppDest, UINT32 * puiDestLen, UINT8 ** ppSubImag
|
||||
*ppDest = (UINT8 *) MemAlloc( uiSpaceLeft );
|
||||
CHECKF( *ppDest );
|
||||
*puiDestLen = uiSpaceLeft;
|
||||
|
||||
|
||||
pOutputNext = *ppDest;
|
||||
|
||||
if (fFlags & CONVERT_ETRLE_COMPRESS_SINGLE)
|
||||
@@ -297,7 +296,7 @@ BOOLEAN ConvertToETRLE( UINT8 ** ppDest, UINT32 * puiDestLen, UINT8 ** ppSubImag
|
||||
if (!(DetermineSubImageUsedSize( p8BPPBuffer, usWidth, usHeight, pCurrSubImage )))
|
||||
{
|
||||
MemFree( *ppDest );
|
||||
return( FALSE );
|
||||
return( FALSE );
|
||||
}
|
||||
}
|
||||
uiSubImageCompressedSize = ETRLECompressSubImage( pOutputNext, uiSpaceLeft, p8BPPBuffer, usWidth, usHeight, pCurrSubImage );
|
||||
@@ -324,7 +323,7 @@ BOOLEAN ConvertToETRLE( UINT8 ** ppDest, UINT32 * puiDestLen, UINT8 ** ppSubImag
|
||||
}
|
||||
*ppSubImageBuffer = NULL;
|
||||
*pusNumberOfSubImages = 0;
|
||||
|
||||
|
||||
while (fContinue)
|
||||
{
|
||||
// allocate more memory for SubImage structures, and set the current pointer to the last one
|
||||
@@ -339,9 +338,9 @@ BOOLEAN ConvertToETRLE( UINT8 ** ppDest, UINT32 * puiDestLen, UINT8 ** ppSubImag
|
||||
*ppSubImageBuffer = pTemp;
|
||||
}
|
||||
pCurrSubImage = (STCISubImage *) (*ppSubImageBuffer + (*pusNumberOfSubImages) * STCI_SUBIMAGE_SIZE);
|
||||
|
||||
|
||||
pCurrSubImage->sOffsetX = sCurrX;
|
||||
pCurrSubImage->sOffsetY = sCurrY;
|
||||
pCurrSubImage->sOffsetY = sCurrY;
|
||||
// determine the subimage's full size
|
||||
if (!DetermineSubImageSize( p8BPPBuffer, usWidth, usHeight, pCurrSubImage ))
|
||||
{
|
||||
@@ -352,7 +351,7 @@ BOOLEAN ConvertToETRLE( UINT8 ** ppDest, UINT32 * puiDestLen, UINT8 ** ppSubImag
|
||||
{
|
||||
printf( "\tWarning: no walls (subimage delimiters) found.\n" );
|
||||
}
|
||||
|
||||
|
||||
memcpy( &TempSubImage, pCurrSubImage, STCI_SUBIMAGE_SIZE );
|
||||
if (DetermineSubImageUsedSize( p8BPPBuffer, usWidth, usHeight, &TempSubImage))
|
||||
{
|
||||
@@ -368,7 +367,7 @@ BOOLEAN ConvertToETRLE( UINT8 ** ppDest, UINT32 * puiDestLen, UINT8 ** ppSubImag
|
||||
// image is transparent; we will store it if there is another subimage
|
||||
// to the right of it on the same line
|
||||
// find the next subimage
|
||||
fNextExists = GoToNextSubImage( &sNextX, &sNextY, p8BPPBuffer, usWidth, usHeight, sCurrX, sCurrY );
|
||||
fNextExists = GoToNextSubImage( &sNextX, &sNextY, p8BPPBuffer, usWidth, usHeight, sCurrX, sCurrY );
|
||||
if (fNextExists && sNextY == sCurrY )
|
||||
{
|
||||
fStore = TRUE;
|
||||
@@ -397,7 +396,7 @@ BOOLEAN ConvertToETRLE( UINT8 ** ppDest, UINT32 * puiDestLen, UINT8 ** ppSubImag
|
||||
pCurrSubImage->uiDataOffset = (*puiDestLen - uiSpaceLeft);
|
||||
pCurrSubImage->uiDataLength = uiSubImageCompressedSize;
|
||||
// this is a cheap hack; the sOffsetX and sOffsetY values have been used
|
||||
// to store the location of the subimage within the whole image. Now
|
||||
// to store the location of the subimage within the whole image. Now
|
||||
// we want the offset within the subimage, so, we subtract the coordatines
|
||||
// for the upper-left corner of the subimage.
|
||||
pCurrSubImage->sOffsetX -= sCurrX;
|
||||
@@ -454,14 +453,15 @@ UINT32 ETRLECompressSubImage( UINT8 * pDest, UINT32 uiDestLen, UINT8 * p8BPPBuff
|
||||
}
|
||||
|
||||
UINT32 ETRLECompress( UINT8 * pDest, UINT32 uiDestLen, UINT8 * pSource, UINT32 uiSourceLen )
|
||||
{ // Compress a buffer (a scanline) into ETRLE format, which is a series of runs.
|
||||
// Each run starts with a byte whose high bit is 1 if the run is compressed, 0 otherwise.
|
||||
{
|
||||
// Compress a buffer (a scanline) into ETRLE format, which is a series of runs.
|
||||
// Each run starts with a byte whose high bit is 1 if the run is compressed, 0 otherwise.
|
||||
// The lower seven bits of that byte indicate the length of the run
|
||||
|
||||
|
||||
// ETRLECompress returns the number of bytes used by the compressed buffer, or 0 if an error
|
||||
// occurred
|
||||
|
||||
// uiSourceLoc keeps track of our current position in the
|
||||
// uiSourceLoc keeps track of our current position in the
|
||||
// source
|
||||
UINT32 uiSourceLoc = 0;
|
||||
// uiCurrentSourceLoc is used to look ahead in the source to
|
||||
@@ -469,21 +469,21 @@ UINT32 ETRLECompress( UINT8 * pDest, UINT32 uiDestLen, UINT8 * pSource, UINT32 u
|
||||
UINT32 uiCurrentSourceLoc = 0;
|
||||
UINT32 uiDestLoc = 0;
|
||||
UINT8 ubLength = 0;
|
||||
|
||||
|
||||
|
||||
while (uiSourceLoc < uiSourceLen && uiDestLoc < uiDestLen)
|
||||
{
|
||||
if (pSource[uiSourceLoc] == TCI)
|
||||
{ // transparent run - determine its length
|
||||
do
|
||||
{
|
||||
{
|
||||
uiCurrentSourceLoc++;
|
||||
ubLength++;
|
||||
}
|
||||
while ((uiCurrentSourceLoc < uiSourceLen) && pSource[uiCurrentSourceLoc] == TCI && (ubLength < COMPRESS_RUN_LIMIT));
|
||||
// output run-byte
|
||||
pDest[uiDestLoc] = ubLength | COMPRESS_TRANSPARENT;
|
||||
|
||||
|
||||
// update location
|
||||
uiSourceLoc += ubLength;
|
||||
uiDestLoc += 1;
|
||||
@@ -500,7 +500,7 @@ UINT32 ETRLECompress( UINT8 * pDest, UINT32 uiDestLen, UINT8 * pSource, UINT32 u
|
||||
{
|
||||
// output run-byte
|
||||
pDest[uiDestLoc++] = ubLength | COMPRESS_NON_TRANSPARENT;
|
||||
|
||||
|
||||
// output run (and update location)
|
||||
memcpy( pDest + uiDestLoc, pSource + uiSourceLoc, ubLength );
|
||||
uiSourceLoc += ubLength;
|
||||
@@ -509,7 +509,7 @@ UINT32 ETRLECompress( UINT8 * pDest, UINT32 uiDestLen, UINT8 * pSource, UINT32 u
|
||||
else
|
||||
{ // not enough room in dest buffer to copy the run!
|
||||
return( 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
uiCurrentSourceLoc = uiSourceLoc;
|
||||
ubLength = 0;
|
||||
@@ -518,7 +518,7 @@ UINT32 ETRLECompress( UINT8 * pDest, UINT32 uiDestLen, UINT8 * pSource, UINT32 u
|
||||
{
|
||||
return( 0 );
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
// end with a run of 0 length (which might as well be non-transparent,
|
||||
// giving a 0-byte
|
||||
@@ -537,7 +537,7 @@ BOOLEAN DetermineOffset( UINT32 * puiOffset, UINT16 usWidth, UINT16 usHeight, IN
|
||||
if (*puiOffset >= (UINT32) usWidth * (UINT32) usHeight)
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
}
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
@@ -559,7 +559,7 @@ BOOLEAN GoPastWall( INT16 * psNewX, INT16 * psNewY, UINT16 usWidth, UINT16 usHei
|
||||
return( FALSE );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*psNewX = sCurrX;
|
||||
*psNewY = sCurrY;
|
||||
@@ -567,14 +567,15 @@ BOOLEAN GoPastWall( INT16 * psNewX, INT16 * psNewY, UINT16 usWidth, UINT16 usHei
|
||||
}
|
||||
|
||||
BOOLEAN GoToNextSubImage( INT16 * psNewX, INT16 * psNewY, UINT8 * p8BPPBuffer, UINT16 usWidth, UINT16 usHeight, INT16 sOrigX, INT16 sOrigY )
|
||||
{ // return the coordinates of the next subimage in the image
|
||||
{
|
||||
// return the coordinates of the next subimage in the image
|
||||
// (either to the right, or the first of the next row down
|
||||
INT16 sCurrX = sOrigX;
|
||||
INT16 sCurrY = sOrigY;
|
||||
UINT32 uiOffset;
|
||||
UINT8 * pCurrent;
|
||||
BOOLEAN fFound = TRUE;
|
||||
|
||||
|
||||
CHECKF( DetermineOffset( &uiOffset, usWidth, usHeight, sCurrX, sCurrY ) )
|
||||
pCurrent = p8BPPBuffer + uiOffset;
|
||||
|
||||
@@ -582,13 +583,13 @@ BOOLEAN GoToNextSubImage( INT16 * psNewX, INT16 * psNewY, UINT8 * p8BPPBuffer, U
|
||||
{
|
||||
return( GoPastWall( psNewX, psNewY, usWidth, usHeight, pCurrent, sCurrX, sCurrY ) );
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
// The current pixel is not a wall. We scan right past all non-wall data to skip to
|
||||
// The current pixel is not a wall. We scan right past all non-wall data to skip to
|
||||
// the right-hand end of the subimage, then right past all wall data to skip a vertical
|
||||
// wall, and should find ourselves at another subimage.
|
||||
|
||||
// If we hit the right edge of the image, we back up to our start point, go DOWN to
|
||||
// If we hit the right edge of the image, we back up to our start point, go DOWN to
|
||||
// the bottom of the image to the horizontal wall, and then recurse to go along it
|
||||
// to the right place on the next scanline
|
||||
|
||||
@@ -601,7 +602,7 @@ BOOLEAN GoToNextSubImage( INT16 * psNewX, INT16 * psNewY, UINT8 * p8BPPBuffer, U
|
||||
fFound = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sCurrX < usWidth)
|
||||
{
|
||||
// skip all wall data to the right, starting at the new current position
|
||||
@@ -617,9 +618,9 @@ BOOLEAN GoToNextSubImage( INT16 * psNewX, INT16 * psNewY, UINT8 * p8BPPBuffer, U
|
||||
}
|
||||
}
|
||||
if (fFound)
|
||||
{
|
||||
{
|
||||
*psNewX = sCurrX;
|
||||
*psNewY = sCurrY;
|
||||
*psNewY = sCurrY;
|
||||
return( TRUE );
|
||||
}
|
||||
else
|
||||
@@ -627,7 +628,7 @@ BOOLEAN GoToNextSubImage( INT16 * psNewX, INT16 * psNewY, UINT8 * p8BPPBuffer, U
|
||||
// go back to the beginning of the subimage and scan down
|
||||
sCurrX = sOrigX;
|
||||
pCurrent = p8BPPBuffer + uiOffset;
|
||||
|
||||
|
||||
// skip all non-wall data below, starting at the current position
|
||||
while (*pCurrent != WI)
|
||||
{
|
||||
@@ -655,7 +656,7 @@ BOOLEAN DetermineSubImageSize( UINT8 * p8BPPBuffer, UINT16 usWidth, UINT16 usHei
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
|
||||
// determine width
|
||||
pCurrent = p8BPPBuffer + uiOffset;
|
||||
do
|
||||
@@ -726,7 +727,7 @@ BOOLEAN DetermineSubImageUsedSize( UINT8 * p8BPPBuffer, UINT16 usWidth, UINT16 u
|
||||
pSubImage->sOffsetX = usNewX;
|
||||
pSubImage->sOffsetY = usNewY;
|
||||
pSubImage->usHeight = usNewHeight;
|
||||
pSubImage->usWidth = usNewWidth;
|
||||
pSubImage->usWidth = usNewWidth;
|
||||
return( TRUE );
|
||||
}
|
||||
|
||||
@@ -829,3 +830,4 @@ UINT8 * CheckForDataInRowOrColumn( UINT8 * pPixel, UINT16 usIncrement, UINT16 us
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user