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:
lalien
2008-03-08 15:15:25 +00:00
parent e16d166277
commit 43ca24dda8
649 changed files with 93359 additions and 82507 deletions
+257 -257
View File
@@ -10,22 +10,22 @@
#include "fileman.h"
#endif
// Local typedefs
// Local typedefs
#define PCX_NORMAL 1
#define PCX_RLE 2
#define PCX_256COLOR 4
#define PCX_TRANSPARENT 8
#define PCX_CLIPPED 16
#define PCX_NORMAL 1
#define PCX_RLE 2
#define PCX_256COLOR 4
#define PCX_TRANSPARENT 8
#define PCX_CLIPPED 16
#define PCX_REALIZEPALETTE 32
#define PCX_X_CLIPPING 64
#define PCX_Y_CLIPPING 128
#define PCX_NOTLOADED 256
#define PCX_X_CLIPPING 64
#define PCX_Y_CLIPPING 128
#define PCX_NOTLOADED 256
#define PCX_ERROROPENING 1
#define PCX_INVALIDFORMAT 2
#define PCX_INVALIDLEN 4
#define PCX_OUTOFMEMORY 8
#define PCX_ERROROPENING 1
#define PCX_INVALIDFORMAT 2
#define PCX_INVALIDLEN 4
#define PCX_OUTOFMEMORY 8
BOOLEAN SetPcxPalette( PcxObject *pCurrentPcxObject, HIMAGE hImage );
@@ -68,7 +68,7 @@ BOOLEAN LoadPCXFileToImage( HIMAGE hImage, UINT16 fContents )
{
SetPcxPalette( pPcxObject, hImage );
// Create 16 BPP palette if flags and BPP justify
// Create 16 BPP palette if flags and BPP justify
hImage->pui16BPPPalette = Create16BPPPalette( hImage->pPalette );
}
@@ -82,24 +82,24 @@ BOOLEAN LoadPCXFileToImage( HIMAGE hImage, UINT16 fContents )
PcxObject *LoadPcx(STR8 pFilename)
{
PcxHeader Header;
PcxObject *pCurrentPcxObject;
HWFILE hFileHandle;
UINT32 uiFileSize;
UINT8 *pPcxBuffer;
// Open and read in the file
if ((hFileHandle = FileOpen(pFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE)) == 0)
{ // damn we failed to open the file
return NULL;
}
{
PcxHeader Header;
PcxObject *pCurrentPcxObject;
HWFILE hFileHandle;
UINT32 uiFileSize;
UINT8 *pPcxBuffer;
uiFileSize = FileGetSize(hFileHandle);
if (uiFileSize == 0)
{ // we failed to size up the file
return NULL;
}
// Open and read in the file
if ((hFileHandle = FileOpen(pFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE)) == 0)
{ // damn we failed to open the file
return NULL;
}
uiFileSize = FileGetSize(hFileHandle);
if (uiFileSize == 0)
{ // we failed to size up the file
return NULL;
}
// Create enw pCX object
pCurrentPcxObject = (PcxObject *) MemAlloc( sizeof( PcxObject ) );
@@ -115,241 +115,241 @@ PcxObject *LoadPcx(STR8 pFilename)
{
return( NULL );
}
// Ok we now have a file handle, so let's read in the data
FileRead(hFileHandle, &Header, sizeof(PcxHeader), NULL);
if ((Header.ubManufacturer != 10)||(Header.ubEncoding != 1))
{ // We have an invalid pcx format
// Delete the object
MemFree( pCurrentPcxObject->pPcxBuffer );
// Ok we now have a file handle, so let's read in the data
FileRead(hFileHandle, &Header, sizeof(PcxHeader), NULL);
if ((Header.ubManufacturer != 10)||(Header.ubEncoding != 1))
{ // We have an invalid pcx format
// Delete the object
MemFree( pCurrentPcxObject->pPcxBuffer );
MemFree( pCurrentPcxObject );
return( NULL );
}
return( NULL );
}
if (Header.ubBitsPerPixel == 8)
{
pCurrentPcxObject->usPcxFlags = PCX_256COLOR;
} else
{
pCurrentPcxObject->usPcxFlags = 0;
}
if (Header.ubBitsPerPixel == 8)
{
pCurrentPcxObject->usPcxFlags = PCX_256COLOR;
} else
{
pCurrentPcxObject->usPcxFlags = 0;
}
pCurrentPcxObject->usWidth = 1 + (Header.usRight - Header.usLeft);
pCurrentPcxObject->usHeight = 1 + (Header.usBottom - Header.usTop);
pCurrentPcxObject->uiBufferSize = uiFileSize - 768 - sizeof(PcxHeader);
pCurrentPcxObject->usWidth = 1 + (Header.usRight - Header.usLeft);
pCurrentPcxObject->usHeight = 1 + (Header.usBottom - Header.usTop);
pCurrentPcxObject->uiBufferSize = uiFileSize - 768 - sizeof(PcxHeader);
// We are ready to read in the pcx buffer data. Therefore we must lock the buffer
pPcxBuffer = pCurrentPcxObject->pPcxBuffer;
// We are ready to read in the pcx buffer data. Therefore we must lock the buffer
pPcxBuffer = pCurrentPcxObject->pPcxBuffer;
FileRead(hFileHandle, pPcxBuffer, pCurrentPcxObject->uiBufferSize, NULL);
FileRead(hFileHandle, pPcxBuffer, pCurrentPcxObject->uiBufferSize, NULL);
// Read in the palette
FileRead(hFileHandle, &(pCurrentPcxObject->ubPalette[0]), 768, NULL);
// Read in the palette
FileRead(hFileHandle, &(pCurrentPcxObject->ubPalette[0]), 768, NULL);
// Close file
FileClose( hFileHandle );
return pCurrentPcxObject;
return pCurrentPcxObject;
}
BOOLEAN BlitPcxToBuffer( PcxObject *pCurrentPcxObject, UINT8 *pBuffer, UINT16 usBufferWidth, UINT16 usBufferHeight, UINT16 usX, UINT16 usY, BOOLEAN fTransp)
{
UINT8 *pPcxBuffer;
UINT8 ubRepCount;
UINT16 usMaxX, usMaxY;
UINT32 uiImageSize;
UINT8 ubCurrentByte = 0;
UINT8 ubMode;
UINT16 usCurrentX, usCurrentY;
UINT32 uiOffset, uiIndex;
UINT32 uiNextLineOffset, uiStartOffset, uiCurrentOffset;
{
UINT8 *pPcxBuffer;
UINT8 ubRepCount;
UINT16 usMaxX, usMaxY;
UINT32 uiImageSize;
UINT8 ubCurrentByte = 0;
UINT8 ubMode;
UINT16 usCurrentX, usCurrentY;
UINT32 uiOffset, uiIndex;
UINT32 uiNextLineOffset, uiStartOffset, uiCurrentOffset;
pPcxBuffer = pCurrentPcxObject->pPcxBuffer;
pPcxBuffer = pCurrentPcxObject->pPcxBuffer;
if (((pCurrentPcxObject->usWidth + usX) == usBufferWidth)&&((pCurrentPcxObject->usHeight + usY)== usBufferHeight))
{ // Pre-compute PCX blitting aspects.
uiImageSize = usBufferWidth * usBufferHeight;
ubMode = PCX_NORMAL;
uiOffset = 0;
ubRepCount = 0;
if (((pCurrentPcxObject->usWidth + usX) == usBufferWidth)&&((pCurrentPcxObject->usHeight + usY)== usBufferHeight))
{ // Pre-compute PCX blitting aspects.
uiImageSize = usBufferWidth * usBufferHeight;
ubMode = PCX_NORMAL;
uiOffset = 0;
ubRepCount = 0;
// Blit Pcx object. Two main cases, one for transparency (0's are skipped and for without transparency.
if (fTransp == TRUE)
{
for (uiIndex = 0; uiIndex < uiImageSize; uiIndex++)
{
if (ubMode == PCX_NORMAL)
{
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (ubCurrentByte > 0x0BF)
{
ubRepCount = ubCurrentByte & 0x03F;
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (--ubRepCount > 0)
{
ubMode = PCX_RLE;
}
}
}
else
{
if (--ubRepCount == 0)
{
ubMode = PCX_NORMAL;
}
}
if (ubCurrentByte != 0)
{
*(pBuffer + uiIndex) = ubCurrentByte;
}
}
}
else
{
for (uiIndex = 0; uiIndex < uiImageSize; uiIndex++)
{
if (ubMode == PCX_NORMAL)
{
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (ubCurrentByte > 0x0BF)
{
ubRepCount = ubCurrentByte & 0x03F;
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (--ubRepCount > 0)
{
ubMode = PCX_RLE;
}
}
}
else
{
if (--ubRepCount == 0)
{ ubMode = PCX_NORMAL;
}
}
*(pBuffer + uiIndex) = ubCurrentByte;
}
}
} else
{ // Pre-compute PCX blitting aspects.
if ((pCurrentPcxObject->usWidth + usX) >= usBufferWidth)
{
pCurrentPcxObject->usPcxFlags |= PCX_X_CLIPPING;
usMaxX = usBufferWidth - 1;
}
else
{
usMaxX = pCurrentPcxObject->usWidth + usX;
}
// Blit Pcx object. Two main cases, one for transparency (0's are skipped and for without transparency.
if (fTransp == TRUE)
{
for (uiIndex = 0; uiIndex < uiImageSize; uiIndex++)
{
if (ubMode == PCX_NORMAL)
{
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (ubCurrentByte > 0x0BF)
{
ubRepCount = ubCurrentByte & 0x03F;
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (--ubRepCount > 0)
{
ubMode = PCX_RLE;
}
}
}
else
{
if (--ubRepCount == 0)
{
ubMode = PCX_NORMAL;
}
}
if (ubCurrentByte != 0)
{
*(pBuffer + uiIndex) = ubCurrentByte;
}
}
}
else
{
for (uiIndex = 0; uiIndex < uiImageSize; uiIndex++)
{
if (ubMode == PCX_NORMAL)
{
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (ubCurrentByte > 0x0BF)
{
ubRepCount = ubCurrentByte & 0x03F;
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (--ubRepCount > 0)
{
ubMode = PCX_RLE;
}
}
}
else
{
if (--ubRepCount == 0)
{ ubMode = PCX_NORMAL;
}
}
*(pBuffer + uiIndex) = ubCurrentByte;
}
}
} else
{ // Pre-compute PCX blitting aspects.
if ((pCurrentPcxObject->usWidth + usX) >= usBufferWidth)
{
pCurrentPcxObject->usPcxFlags |= PCX_X_CLIPPING;
usMaxX = usBufferWidth - 1;
}
else
{
usMaxX = pCurrentPcxObject->usWidth + usX;
}
if ((pCurrentPcxObject->usHeight + usY) >= usBufferHeight)
{
pCurrentPcxObject->usPcxFlags |= PCX_Y_CLIPPING;
uiImageSize = pCurrentPcxObject->usWidth * (usBufferHeight - usY);
usMaxY = usBufferHeight - 1;
}
else
{ uiImageSize = pCurrentPcxObject->usWidth * pCurrentPcxObject->usHeight;
usMaxY = pCurrentPcxObject->usHeight + usY;
}
if ((pCurrentPcxObject->usHeight + usY) >= usBufferHeight)
{
pCurrentPcxObject->usPcxFlags |= PCX_Y_CLIPPING;
uiImageSize = pCurrentPcxObject->usWidth * (usBufferHeight - usY);
usMaxY = usBufferHeight - 1;
}
else
{ uiImageSize = pCurrentPcxObject->usWidth * pCurrentPcxObject->usHeight;
usMaxY = pCurrentPcxObject->usHeight + usY;
}
ubMode = PCX_NORMAL;
uiOffset = 0;
ubRepCount = 0;
usCurrentX = usX;
usCurrentY = usY;
ubMode = PCX_NORMAL;
uiOffset = 0;
ubRepCount = 0;
usCurrentX = usX;
usCurrentY = usY;
// Blit Pcx object. Two main cases, one for transparency (0's are skipped and for without transparency.
if (fTransp == TRUE)
{
for (uiIndex = 0; uiIndex < uiImageSize; uiIndex++)
{
if (ubMode == PCX_NORMAL)
{
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (ubCurrentByte > 0x0BF)
{
ubRepCount = ubCurrentByte & 0x03F;
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (--ubRepCount > 0)
{
ubMode = PCX_RLE;
}
}
}
else
{
if (--ubRepCount == 0)
{ ubMode = PCX_NORMAL;
}
}
if (ubCurrentByte != 0)
{ *(pBuffer + (usCurrentY*usBufferWidth) + usCurrentX) = ubCurrentByte;
}
usCurrentX++;
if (usCurrentX > usMaxX)
{
usCurrentX = usX;
usCurrentY++;
}
}
} else
{
uiStartOffset = (usCurrentY*usBufferWidth) + usCurrentX;
uiNextLineOffset = uiStartOffset + usBufferWidth;
uiCurrentOffset = uiStartOffset;
// Blit Pcx object. Two main cases, one for transparency (0's are skipped and for without transparency.
if (fTransp == TRUE)
{
for (uiIndex = 0; uiIndex < uiImageSize; uiIndex++)
{
if (ubMode == PCX_NORMAL)
{
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (ubCurrentByte > 0x0BF)
{
ubRepCount = ubCurrentByte & 0x03F;
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (--ubRepCount > 0)
{
ubMode = PCX_RLE;
}
}
}
else
{
if (--ubRepCount == 0)
{ ubMode = PCX_NORMAL;
}
}
if (ubCurrentByte != 0)
{ *(pBuffer + (usCurrentY*usBufferWidth) + usCurrentX) = ubCurrentByte;
}
usCurrentX++;
if (usCurrentX > usMaxX)
{
usCurrentX = usX;
usCurrentY++;
}
}
} else
{
uiStartOffset = (usCurrentY*usBufferWidth) + usCurrentX;
uiNextLineOffset = uiStartOffset + usBufferWidth;
uiCurrentOffset = uiStartOffset;
for (uiIndex = 0; uiIndex < uiImageSize; uiIndex++)
{
if (ubMode == PCX_NORMAL)
{
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (ubCurrentByte > 0x0BF)
{
ubRepCount = ubCurrentByte & 0x03F;
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (--ubRepCount > 0)
{
ubMode = PCX_RLE;
}
}
}
else
{
if (--ubRepCount == 0)
{
ubMode = PCX_NORMAL;
}
}
for (uiIndex = 0; uiIndex < uiImageSize; uiIndex++)
{
if (usCurrentX < usMaxX)
{ // We are within the visible bounds so we write the byte to buffer
*(pBuffer + uiCurrentOffset) = ubCurrentByte;
uiCurrentOffset++;
usCurrentX++;
}
else
{ if ((uiCurrentOffset + 1)< uiNextLineOffset)
{ // Increment the uiCurrentOffset
uiCurrentOffset++;
}
else
{ // Go to next line
usCurrentX = usX;
usCurrentY++;
if (usCurrentY > usMaxY)
{
break;
}
uiStartOffset = (usCurrentY*usBufferWidth) + usCurrentX;
uiNextLineOffset = uiStartOffset + usBufferWidth;
uiCurrentOffset = uiStartOffset;
}
}
}
}
}
if (ubMode == PCX_NORMAL)
{
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (ubCurrentByte > 0x0BF)
{
ubRepCount = ubCurrentByte & 0x03F;
ubCurrentByte = *(pPcxBuffer + uiOffset++);
if (--ubRepCount > 0)
{
ubMode = PCX_RLE;
}
}
}
else
{
if (--ubRepCount == 0)
{
ubMode = PCX_NORMAL;
}
}
if (usCurrentX < usMaxX)
{ // We are within the visible bounds so we write the byte to buffer
*(pBuffer + uiCurrentOffset) = ubCurrentByte;
uiCurrentOffset++;
usCurrentX++;
}
else
{ if ((uiCurrentOffset + 1)< uiNextLineOffset)
{ // Increment the uiCurrentOffset
uiCurrentOffset++;
}
else
{ // Go to next line
usCurrentX = usX;
usCurrentY++;
if (usCurrentY > usMaxY)
{
break;
}
uiStartOffset = (usCurrentY*usBufferWidth) + usCurrentX;
uiNextLineOffset = uiStartOffset + usBufferWidth;
uiCurrentOffset = uiStartOffset;
}
}
}
}
}
return( TRUE );
}
@@ -357,7 +357,7 @@ BOOLEAN BlitPcxToBuffer( PcxObject *pCurrentPcxObject, UINT8 *pBuffer, UINT16 us
BOOLEAN SetPcxPalette( PcxObject *pCurrentPcxObject, HIMAGE hImage )
{
UINT16 Index;
UINT8 *pubPalette;
UINT8 *pubPalette;
pubPalette = &(pCurrentPcxObject->ubPalette[0]);
@@ -369,14 +369,14 @@ BOOLEAN SetPcxPalette( PcxObject *pCurrentPcxObject, HIMAGE hImage )
return( FALSE );
}
// Initialize the proper palette entries
for (Index = 0; Index < 256; Index++)
{
hImage->pPalette[ Index ].peRed = *(pubPalette+(Index*3));
hImage->pPalette[ Index ].peGreen = *(pubPalette+(Index*3)+1);
hImage->pPalette[ Index ].peBlue = *(pubPalette+(Index*3)+2);
hImage->pPalette[ Index ].peFlags = 0;
}
// Initialize the proper palette entries
for (Index = 0; Index < 256; Index++)
{
hImage->pPalette[ Index ].peRed = *(pubPalette+(Index*3));
hImage->pPalette[ Index ].peGreen = *(pubPalette+(Index*3)+1);
hImage->pPalette[ Index ].peBlue = *(pubPalette+(Index*3)+2);
hImage->pPalette[ Index ].peFlags = 0;
}
return TRUE;
}
return TRUE;
}