ja2export is not vendored, we own that + fix errors

stop lying about it by keeping it in ext/
fix three errors in clang-cl
This commit is contained in:
Marco Antonio J. Costa
2026-07-27 13:07:29 -03:00
committed by majcosta
parent fc1c1dfe77
commit fd47a422b5
30 changed files with 6 additions and 6 deletions
+243
View File
@@ -0,0 +1,243 @@
#ifndef __STRUCTURE_INTERNAL_H
#define __STRUCTURE_INTERNAL_H
//
// If you wish to use the structure database functions, include
// structure_extern.h, not structure.h!
//
#include "types.h"
#include "himage.h"
// A few words about the overall structure scheme:
//
// Large structures are split into multiple sections,
// one for each tile.
//
// Each section is treated as a separate object,
// except that it does NOT record information about
// hit points, but instead stores a pointer to the
// base object (section).
//
// Each section has a line of sight profile. These
// profiles are split into 5 in each horizontal direction
// and 4 vertically, forming 100 "cubes". In real
// world terms, each section represents a volume
// with a height of 8 feet (and width and length
// of what?)
//
// It is important to note that the vertical
// position of each section is measured in individual
// cubes (rather than, as it were, groups of 4 vertical
// cubes)
#define PROFILE_X_SIZE 5
#define PROFILE_Y_SIZE 5
#define PROFILE_Z_SIZE 4
// these values should be compared for less than rather than less
// than or equal to
#define STRUCTURE_ON_GROUND 0
#define STRUCTURE_ON_ROOF PROFILE_Z_SIZE
#define STRUCTURE_ON_GROUND_MAX PROFILE_Z_SIZE
#define STRUCTURE_ON_ROOF_MAX PROFILE_Z_SIZE * 2
typedef UINT8 PROFILE[PROFILE_X_SIZE][PROFILE_Y_SIZE];
extern UINT8 AtHeight[PROFILE_Z_SIZE];
// MAP_ELEMENT may get later:
// PROFILE * CombinedLOSProfile;
// PROFILE * CombinedProtectionProfile;
//
// LEVELNODE gets a pointer to a STRUCTURE or
// a union between its soldier pointer and a
// STRUCTURE pointer
// if (fFlags & STRUCTURE_BASE_TILE)
// then the structure is the "base" of the object
// and its hitpoint value is the one for the object
//
// vv generic flags for all structures
// vvv type flags
//
// how to handle explodable structures
// NOT used in DB structures!
#define STRUCTURE_BASE_TILE 0x00000001
#define STRUCTURE_OPEN 0x00000002
#define STRUCTURE_OPENABLE 0x00000004
// synonyms for STRUCTURE_OPENABLE
#define STRUCTURE_CLOSEABLE 0x00000004
#define STRUCTURE_SEARCHABLE 0x00000004
#define STRUCTURE_HIDDEN 0x00000008
#define STRUCTURE_MOBILE 0x00000010
// STRUCTURE_PASSABLE is set for each structure instance where
// the tile flag TILE_PASSABLE is set
#define STRUCTURE_PASSABLE 0x00000020
#define STRUCTURE_EXPLOSIVE 0x00000040
#define STRUCTURE_TRANSPARENT 0x00000080
#define STRUCTURE_GENERIC 0x00000100
#define STRUCTURE_TREE 0x00000200
#define STRUCTURE_FENCE 0x00000400
#define STRUCTURE_WIREFENCE 0x00000800
#define STRUCTURE_HASITEMONTOP 0x00001000 // ATE: HASITEM: struct has item on top of it
#define STRUCTURE_SPECIAL 0x00002000
#define STRUCTURE_LIGHTSOURCE 0x00004000
#define STRUCTURE_VEHICLE 0x00008000
#define STRUCTURE_WALL 0x00010000
#define STRUCTURE_WALLNWINDOW 0x00020000
#define STRUCTURE_SLIDINGDOOR 0x00040000
#define STRUCTURE_DOOR 0x00080000
// a "multi" structure (as opposed to multitiled) is composed of multiple graphics & structures
#define STRUCTURE_MULTI 0x00100000
#define STRUCTURE_CAVEWALL 0x00200000
#define STRUCTURE_DDOOR_LEFT 0x00400000
#define STRUCTURE_DDOOR_RIGHT 0x00800000
#define STRUCTURE_NORMAL_ROOF 0x01000000
#define STRUCTURE_SLANTED_ROOF 0x02000000
#define STRUCTURE_TALL_ROOF 0x04000000
#define STRUCTURE_SWITCH 0x08000000
#define STRUCTURE_ON_LEFT_WALL 0x10000000
#define STRUCTURE_ON_RIGHT_WALL 0x20000000
#define STRUCTURE_CORPSE 0x40000000
#define STRUCTURE_PERSON 0x80000000
// COMBINATION FLAGS
#define STRUCTURE_ANYFENCE 0x00000C00
#define STRUCTURE_ANYDOOR 0x00CC0000
#define STRUCTURE_OBSTACLE 0x00008F00
#define STRUCTURE_WALLSTUFF 0x00CF0000
#define STRUCTURE_BLOCKSMOVES 0x00208F00
#define STRUCTURE_TYPE_DEFINED 0x8FEF8F00
#define STRUCTURE_ROOF 0x07000000
#define TILE_ON_ROOF 0x01
#define TILE_PASSABLE 0x02
typedef struct TAG_STRUCTURE_TILE
{
INT16 sPosRelToBase; // "single-axis"
INT8 bXPosRelToBase;
INT8 bYPosRelToBase;
PROFILE Shape; // 25 bytes
UINT8 fFlags;
UINT8 ubVehicleHitLocation;
BYTE bUnused[1];
} DB_STRUCTURE_TILE; // 32 bytes
#define BASE_TILE 0
#define NO_PARTNER_STRUCTURE 0
typedef struct TAG_DB_STRUCTURE
{
UINT8 ubArmour;
UINT8 ubHitPoints;
UINT8 ubDensity;
UINT8 ubNumberOfTiles;
UINT32 fFlags;
UINT16 usStructureNumber;
UINT8 ubWallOrientation;
INT8 bDestructionPartner; // >0 = debris number (bDP - 1), <0 = partner graphic
INT8 bPartnerDelta; // opened/closed version, etc... 0 for unused
INT8 bZTileOffsetX;
INT8 bZTileOffsetY;
BYTE bUnused[1];
} DB_STRUCTURE; // 16 bytes
typedef struct TAG_DB_STRUCTURE_REF
{
DB_STRUCTURE * pDBStructure;
DB_STRUCTURE_TILE ** ppTile; // dynamic array
} DB_STRUCTURE_REF; // 8 bytes
//dnl ch46 031009
typedef struct TAG_STRUCTURE
{
struct TAG_STRUCTURE* pPrev;
struct TAG_STRUCTURE* pNext;
DB_STRUCTURE_REF* pDBStructureRef;
PROFILE* pShape;
UINT32 fFlags;// need to have something to indicate base tile/not
INT32 sGridNo;
union
{
struct
{
UINT8 ubHitPoints;
UINT8 ubLockStrength;
};
INT32 sBaseGridNo;
};
UINT16 usStructureID;
INT16 sCubeOffset;// height of bottom of object in profile "cubes"
UINT8 ubWallOrientation;
UINT8 ubVehicleHitLocation;
UINT8 ubStructureHeight;// if 0, then unset; otherwise stores height of structure when last calculated
UINT8 ubUnused;
}STRUCTURE;// 36 bytes
typedef struct TAG_STRUCTURE_FILE_REF
{
struct TAG_STRUCTURE_FILE_REF * pPrev;
struct TAG_STRUCTURE_FILE_REF * pNext;
AuxObjectData * pAuxData;
RelTileLoc * pTileLocData;
UINT8 * pubStructureData;
DB_STRUCTURE_REF * pDBStructureRef; // dynamic array
UINT16 usNumberOfStructures;
UINT16 usNumberOfStructuresStored;
} STRUCTURE_FILE_REF; // 24 bytes
// IMPORTANT THING TO REMEMBER
//
// Although the number of structures and images about which information
// may be stored in a file, the two are stored very differently.
//
// The structure data stored amounts to a sparse array, with no data
// saved for any structures that are not defined.
//
// For image information, however, an array is stored with every entry
// filled regardless of whether there is non-zero data defined for
// that graphic!
typedef struct TAG_STRUCTURE_FILE_HEADER
{
CHAR8 szId[4];
union
{
//struct
//{
UINT16 usNumberOfStructures;
//};
//struct
//{
UINT16 usNumberOfImages;
//};
};
UINT16 usNumberOfStructuresStored;
UINT16 usStructureDataSize;
UINT8 fFlags;
UINT8 bUnused[3];
UINT16 usNumberOfImageTileLocsStored;
} STRUCTURE_FILE_HEADER; // 16 bytes
// "J2SD" = Jagged 2 Structure Data
#define STRUCTURE_FILE_ID "J2SD"
#define STRUCTURE_FILE_ID_LEN 4
#define STRUCTURE_SCRIPT_FILE_EXTENSION "JSS"
#define STRUCTURE_FILE_EXTENSION "JSD"
#define STRUCTURE_FILE_CONTAINS_AUXIMAGEDATA 0x01
#define STRUCTURE_FILE_CONTAINS_STRUCTUREDATA 0x02
#endif
+175
View File
@@ -0,0 +1,175 @@
#include "XMLWriter.h"
#include <vfs/Core/vfs_file_raii.h>
#include <vfs/Core/File/vfs_file.h>
#include <iostream>
void XMLWriter::addValue(vfs::String const& key)
{
m_ssBuffer << indent() << "<" << key.utf8();
insertAttributesIntoBuffer();
m_ssBuffer << " />\n";
}
void XMLWriter::addComment(vfs::String const& comment)
{
m_ssBuffer << indent() << "<!-- " << comment.utf8() << " -->\n";
}
void XMLWriter::addFlag(UINT32 const& flags, UINT32 const& flag, vfs::String strFlag)
{
if( ( flags & flag) == flag )
{
this->addValue(strFlag);
}
}
void XMLWriter::openNode(vfs::String const& key)
{
std::string utf8key = key.utf8();
m_ssBuffer << indent() << "<" << utf8key;
insertAttributesIntoBuffer();
m_ssBuffer << ">\n";
m_iIndentLevel += 1;
m_stOpenNodes.push(utf8key);
}
bool XMLWriter::closeNode()
{
if(m_iIndentLevel < 1)
{
// there is nothing to close
return false;
}
if(m_stOpenNodes.empty())
{
return false;
}
m_iIndentLevel -= 1;
m_ssBuffer << indent() << "</" << m_stOpenNodes.top() << ">\n";
m_stOpenNodes.pop();
return true;
}
bool XMLWriter::writeToFile(vfs::Path const& sFileName)
{
try
{
vfs::COpenWriteFile file(sFileName,true,true);
return writeToFile( &file.file() );
}
catch(vfs::Exception& ex)
{
std::wcout << ex.getExceptionString() << std::endl;
vfs::CFile file(sFileName);
if(file.openWrite(true,true))
{
return writeToFile(vfs::tWritableFile::cast(&file));
}
}
return false;
}
bool XMLWriter::writeToFile(vfs::tWritableFile* pFile)
{
try
{
vfs::COpenWriteFile file(pFile);
const std::string str = m_ssBuffer.str();
pFile->write(str.c_str(), str.length() * sizeof(std::string::value_type));
return true;
}
catch(vfs::Exception& ex)
{
std::wcout << ex.getLastEntryString() << std::endl;
return false;
}
}
std::string XMLWriter::indent()
{
std::string indent_string;
for(int i=0; i < m_iIndentLevel; ++i)
{
indent_string += "\t";
}
return indent_string;
}
void XMLWriter::insertAttributesIntoBuffer()
{
if(!m_stNextValAttributes.empty())
{
std::vector<attribute_type>::iterator it = m_stNextValAttributes.begin();
for(; it != m_stNextValAttributes.end(); ++it)
{
m_ssBuffer << " " << it->first << "=\"" << it->second << "\"";
}
}
m_stNextValAttributes.clear();
}
std::string XMLWriter::handleSpecialCharacters(std::string const& str)
{
std::stringstream ss;
unsigned int current = 0, old = 0;
while( current < str.length() )
{
char const& c = str.at(current);
if( c == '&' )
{
ss << str.substr(old, current-old) << "&amp;";
old = current + 1;
}
else if( c == '<' )
{
ss << str.substr(old, current-old) << "&lt;";
old = current + 1;
}
else if( c == '>' )
{
ss << str.substr(old, current-old) << "&gt;";
old = current + 1;
}
else if( c == '\"' )
{
ss << str.substr(old, current-old) << "&quot;";
old = current + 1;
}
else if( c == '\'' )
{
ss << str.substr(old, current-old) << "&apos;";
old = current + 1;
}
current++;
}
if(old)
{
ss << str.substr(old, current-old);
return ss.str();
}
return str;
}
void testMXLWriter()
{
//XMLWriter<char> xmlw;
XMLWriter xmlw;
//xmlw.openNode(L"root");
xmlw.openNode("root");
xmlw.addAttributeToNextValue("attr1",10);
xmlw.addAttributeToNextValue("attr2","string");
//xmlw.AddValue(L"val1",10);
xmlw.addValue("val1",10);
xmlw.addAttributeToNextValue("node_attr",17);
xmlw.addComment("bbb -->\n <a> comment</a> <!-- aaa");
xmlw.openNode("test");
//xmlw.addValue(L"val2",10.5);
xmlw.addValue("val2",10.5);
xmlw.closeNode();
xmlw.closeNode();
//xmlw.WriteToFile(WideString("xml_output/test.xml")());
xmlw.writeToFile("xml_output/test.xml");
}
+75
View File
@@ -0,0 +1,75 @@
#ifndef _XMLWRITER_H_
#define _XMLWRITER_H_
#include <vfs/Core/Interface/vfs_file_interface.h>
#include <vfs/Core/vfs_string.h>
#include <stack>
#include <string>
#include <sstream>
#include <vector>
class XMLWriter
{
public:
typedef std::pair<std::string, std::string> attribute_type;
public:
XMLWriter() : m_iIndentLevel(0)
{
m_ssBuffer << "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" ;
};
~XMLWriter()
{};
template<typename ValueType>
void addAttributeToNextValue(vfs::String const& attribute, ValueType const& value)
{
std::stringstream temp_buffer;
temp_buffer << value;
m_stNextValAttributes.push_back( attribute_type(attribute.utf8(),temp_buffer.str()) );
}
template<typename ValueType>
void addValue(vfs::String const& key, ValueType const& value)
{
std::string utf8key = key.utf8();
m_ssBuffer << indent() << "<" << utf8key;
insertAttributesIntoBuffer();
m_ssBuffer << ">" << value << "</" << utf8key << ">\n";
}
template<>
void addValue<std::string>(vfs::String const& key, std::string const& value)
{
std::string utf8key = key.utf8();
m_ssBuffer << indent() << "<" << utf8key;
insertAttributesIntoBuffer();
m_ssBuffer << ">" << handleSpecialCharacters(value) << "</" << utf8key << ">\n";
}
void addValue(vfs::String const& key);
void addComment(vfs::String const& comment);
void addFlag(vfs::UInt32 const& flags, vfs::UInt32 const& flag, vfs::String strFlag);
void openNode(vfs::String const& key);
bool closeNode();
bool writeToFile(vfs::Path const& sFileName);
bool writeToFile(vfs::tWritableFile* pFile);
private:
std::string indent();
std::string handleSpecialCharacters(std::string const& str);
void insertAttributesIntoBuffer();
private:
std::stringstream m_ssBuffer;
std::stack<std::string> m_stOpenNodes;
std::vector<attribute_type> m_stNextValAttributes;
int m_iIndentLevel;
};
void testMXLWriter();
#endif // _XMLWRITER_H_
+217
View File
@@ -0,0 +1,217 @@
#include <cmath>
#include <cstdlib>
#include "types.h"
#include "string.h"
#include "himage.h"
// This is the color substituted to keep a 24bpp->16bpp color
// from going transparent (0x0000) -- DB
#define BLACK_SUBSTITUTE 0x0001
//UINT16 gusAlphaMask = 0;
//UINT16 gusRedMask = 0;
//UINT16 gusGreenMask = 0;
//UINT16 gusBlueMask = 0;
//INT16 gusRedShift = 0;
//INT16 gusBlueShift = 0;
//INT16 gusGreenShift = 0;
UINT16 gusAlphaMask = 0;
UINT16 gusRedMask = 0xF800;
UINT16 gusGreenMask = 0x07E0;
UINT16 gusBlueMask = 0x001F;
INT16 gusRedShift = 8;
INT16 gusBlueShift = -3;
INT16 gusGreenShift = 3;
// this funky union is used for fast 16-bit pixel format conversions
union SplitUINT32
{
struct
{
UINT16 usLower;
UINT16 usHigher;
};
UINT32 uiValue;
};
// Convert from RGB to 16 bit value
UINT16 Get16BPPColor( UINT32 RGBValue )
{
UINT16 r16, g16, b16, usColor = 0;
UINT8 r,g,b;
r = SGPGetRValue( RGBValue );
g = SGPGetGValue( RGBValue );
b = SGPGetBValue( RGBValue );
if(gusRedShift < 0)
r16=((UINT16)r>>abs(gusRedShift));
else
r16=((UINT16)r<<gusRedShift);
if(gusGreenShift < 0)
g16=((UINT16)g>>abs(gusGreenShift));
else
g16=((UINT16)g<<gusGreenShift);
if(gusBlueShift < 0)
b16=((UINT16)b>>abs(gusBlueShift));
else
b16=((UINT16)b<<gusBlueShift);
usColor=(r16&gusRedMask)|(g16&gusGreenMask)|(b16&gusBlueMask);
// if our color worked out to absolute black, and the original wasn't
// absolute black, convert it to a VERY dark grey to avoid transparency
// problems
if(usColor==0)
{
if(RGBValue!=0)
usColor=BLACK_SUBSTITUTE | gusAlphaMask;
}
else
usColor |= gusAlphaMask;
return(usColor);
}
// Convert from 16 BPP to RGBvalue
UINT32 GetRGBColor( UINT16 Value16BPP )
{
UINT16 r16, g16, b16;
UINT32 r,g,b,val;
r16 = Value16BPP & gusRedMask;
g16 = Value16BPP & gusGreenMask;
b16 = Value16BPP & gusBlueMask;
if(gusRedShift < 0)
r=((UINT32)r16<<abs(gusRedShift));
else
r=((UINT32)r16>>gusRedShift);
if(gusGreenShift < 0)
g=((UINT32)g16<<abs(gusGreenShift));
else
g=((UINT32)g16>>gusGreenShift);
if(gusBlueShift < 0)
b=((UINT32)b16<<abs(gusBlueShift));
else
b=((UINT32)b16>>gusBlueShift);
r &= 0x000000ff;
g &= 0x000000ff;
b &= 0x000000ff;
val = FROMRGB(r,g,b);
return(val);
}
void ConvertRGBDistribution565To555( UINT16 * p16BPPData, UINT32 uiNumberOfPixels )
{
UINT16 * pPixel;
UINT32 uiLoop;
SplitUINT32 Pixel;
pPixel = p16BPPData;
for (uiLoop = 0; uiLoop < uiNumberOfPixels; uiLoop++)
{
// If the pixel is completely black, don't bother converting it -- DB
if(*pPixel!=0)
{
// we put the 16 pixel bits in the UPPER word of uiPixel, so that we can
// right shift the blue value (at the bottom) into the LOWER word to protect it
Pixel.usHigher = *pPixel;
Pixel.uiValue >>= 5;
// get rid of the least significant bit of green
Pixel.usHigher >>= 1;
// now shift back into the upper word
Pixel.uiValue <<= 5;
// and copy back
*pPixel = Pixel.usHigher | gusAlphaMask;
}
pPixel++;
}
}
void ConvertRGBDistribution565To655( UINT16 * p16BPPData, UINT32 uiNumberOfPixels )
{
UINT16 * pPixel;
UINT32 uiLoop;
SplitUINT32 Pixel;
pPixel = p16BPPData;
for (uiLoop = 0; uiLoop < uiNumberOfPixels; uiLoop++)
{
// we put the 16 pixel bits in the UPPER word of uiPixel, so that we can
// right shift the blue value (at the bottom) into the LOWER word to protect it
Pixel.usHigher = *pPixel;
Pixel.uiValue >>= 5;
// get rid of the least significant bit of green
Pixel.usHigher >>= 1;
// shift to the right some more...
Pixel.uiValue >>= 5;
// so we can left-shift the red value alone to give it an extra bit
Pixel.usHigher <<= 1;
// now shift back and copy
Pixel.uiValue <<= 10;
*pPixel = Pixel.usHigher;
pPixel++;
}
}
void ConvertRGBDistribution565To556( UINT16 * p16BPPData, UINT32 uiNumberOfPixels )
{
UINT16 * pPixel;
UINT32 uiLoop;
SplitUINT32 Pixel;
pPixel = p16BPPData;
for (uiLoop = 0; uiLoop < uiNumberOfPixels; uiLoop++)
{
// we put the 16 pixel bits in the UPPER word of uiPixel, so that we can
// right shift the blue value (at the bottom) into the LOWER word to protect it
Pixel.usHigher = *pPixel;
Pixel.uiValue >>= 5;
// get rid of the least significant bit of green
Pixel.usHigher >>= 1;
// shift back into the upper word
Pixel.uiValue <<= 5;
// give blue an extra bit (blank in the least significant spot)
Pixel.usHigher <<= 1;
// copy back
*pPixel = Pixel.usHigher;
pPixel++;
}
}
void ConvertRGBDistribution565ToAny( UINT16 * p16BPPData, UINT32 uiNumberOfPixels )
{
UINT16 * pPixel;
UINT32 uiRed, uiGreen, uiBlue, uiTemp, uiLoop;
pPixel = p16BPPData;
for (uiLoop = 0; uiLoop < uiNumberOfPixels; uiLoop++)
{
// put the 565 RGB 16-bit value into a 32-bit RGB value
uiRed = (*pPixel) >> 11;
uiGreen = (*pPixel & 0x07E0) >> 5;
uiBlue = (*pPixel & 0x001F);
uiTemp = FROMRGB(uiRed,uiGreen,uiBlue);
// then convert the 32-bit RGB value to whatever 16 bit format is used
*pPixel = Get16BPPColor( uiTemp );
pPixel++;
}
}
+206
View File
@@ -0,0 +1,206 @@
#ifndef __IMAGE_H
#define __IMAGE_H
#include "imgfmt.h"
#define FROMRGB(r, g ,b) ((UINT32) (((UINT8) (r) | ((UINT16) (g) << 8)) | (((UINT32) (UINT8) (b)) << 16)))
// The HIMAGE module provides a common interface for managing image data. This module
// includes:
// - A set of data structures representing image data. Data can be 8 or 16 bpp and/or
// compressed
// - A set of file loaders which load specific file formats into the internal data format
// - A set of blitters which blt the data to memory
// - A comprehensive automatic blitter which blits the appropriate type based on the
// image header.
// Defines for type of file readers
#define PCX_FILE_READER 0x1
#define TGA_FILE_READER 0x2
#define STCI_FILE_READER 0x4
#define TRLE_FILE_READER 0x8
#define UNKNOWN_FILE_READER 0x200
// Defines for buffer bit depth
#define BUFFER_8BPP 0x1
#define BUFFER_16BPP 0x2
// Defines for image charactoristics
#define IMAGE_COMPRESSED 0x0001
#define IMAGE_TRLECOMPRESSED 0x0002
#define IMAGE_PALETTE 0x0004
#define IMAGE_BITMAPDATA 0x0008
#define IMAGE_APPDATA 0x0010
#define IMAGE_ALLIMAGEDATA 0x000C
#define IMAGE_ALLDATA 0x001C
// Palette structure, mimics that of Win32
typedef struct tagSGPPaletteEntry
{
UINT8 peRed;
UINT8 peGreen;
UINT8 peBlue;
UINT8 peFlags;
} SGPPaletteEntry;
#define AUX_FULL_TILE 0x01
#define AUX_ANIMATED_TILE 0x02
#define AUX_DYNAMIC_TILE 0x04
#define AUX_INTERACTIVE_TILE 0x08
#define AUX_IGNORES_HEIGHT 0x10
#define AUX_USES_LAND_Z 0x20
typedef struct
{
UINT8 ubWallOrientation;
UINT8 ubNumberOfTiles;
UINT16 usTileLocIndex;
UINT8 ubUnused1[3];
UINT8 ubCurrentFrame;
UINT8 ubNumberOfFrames;
UINT8 fFlags;
UINT8 ubUnused[6];
} AuxObjectData;
typedef struct
{
INT8 bTileOffsetX;
INT8 bTileOffsetY;
} RelTileLoc; // relative tile location
// TRLE subimage structure, mirroring that of ST(C)I
typedef struct tagETRLEObject
{
UINT32 uiDataOffset;
UINT32 uiDataLength;
INT16 sOffsetX;
INT16 sOffsetY;
UINT16 usHeight;
UINT16 usWidth;
} ETRLEObject;
typedef struct tagETRLEData
{
PTR pPixData;
UINT32 uiSizePixData;
ETRLEObject * pETRLEObject;
UINT16 usNumberOfObjects;
} ETRLEData;
// Image header structure
typedef struct
{
UINT16 usWidth;
UINT16 usHeight;
UINT8 ubBitDepth;
UINT16 fFlags;
SGPFILENAME ImageFile;
UINT32 iFileLoader;
SGPPaletteEntry * pPalette;
UINT16 * pui16BPPPalette;
UINT8 * pAppData;
UINT32 uiAppDataSize;
// This union is used to describe each data type and is flexible to include the
// data strucutre of the compresssed format, once developed.
union
{
PTR pImageData;
PTR pCompressedImageData;
UINT8* p8BPPData;
UINT16* p16BPPData;
struct
{
UINT8* pPixData8;
UINT32 uiSizePixData;
ETRLEObject* pETRLEObject;
UINT16 usNumberOfObjects;
};
};
} image_type, *HIMAGE;
#define SGPGetRValue(rgb) ((BYTE) (rgb))
#define SGPGetBValue(rgb) ((BYTE) ((rgb) >> 16))
#define SGPGetGValue(rgb) ((BYTE) (((UINT16) (rgb)) >> 8))
// *****************************************************************************
//
// Function prototypes
//
// *****************************************************************************
#ifdef __cplusplus
extern "C" {
#endif
// This function will return NULL if it fails, and call SetLastError() to set
// error information
HIMAGE CreateImage( SGPFILENAME ImageFile, UINT16 fContents );
// This function destroys the HIMAGE structure as well as its contents
BOOLEAN DestroyImage( HIMAGE hImage );
// This function releases data allocated to various parts of the image based
// on the contents flags passed as a parameter. If a contents flag is given
// and the image does not contain that data, no error is raised
BOOLEAN ReleaseImageData( HIMAGE hImage, UINT16 fContents );
// This function will attept to Load data from an existing image object's filename
// In this way, dynamic loading of image data can be done
BOOLEAN LoadImageData( HIMAGE hImage, UINT16 fContents );
// This function will run the appropriate copy function based on the type of HIMAGE object
BOOLEAN CopyImageToBuffer( HIMAGE hImage, UINT32 fBufferType, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
// The following blitters are used by the function above as well as clients
#ifndef NO_ZLIB_COMPRESSION
BOOLEAN Copy8BPPCompressedImageTo8BPPBuffer( HIMAGE hImage, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
BOOLEAN Copy8BPPCompressedImageTo16BPPBuffer( HIMAGE hImage, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
BOOLEAN Copy16BPPCompressedImageTo16BPPBuffer( HIMAGE hImage, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
// This function will extract a compressed image into a non-compressed buffer
BOOLEAN Extract8BPPCompressedImageToBuffer( HIMAGE hImage, BYTE *pDestBuf );
BOOLEAN Extract16BPPCompressedImageToBuffer( HIMAGE hImage, BYTE *pDestBuf );
#endif
BOOLEAN Copy8BPPImageTo8BPPBuffer( HIMAGE hImage, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
BOOLEAN Copy8BPPImageTo16BPPBuffer( HIMAGE hImage, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
BOOLEAN Copy16BPPImageTo16BPPBuffer( HIMAGE hImage, BYTE *pDestBuf, UINT16 usDestWidth, UINT16 usDestHeight, UINT16 usX, UINT16 usY, SGPRect *srcRect );
// This function will create a buffer in memory of ETRLE data, excluding palette
BOOLEAN GetETRLEImageData( HIMAGE hImage, ETRLEData *pBuffer );
// UTILITY FUNCTIONS
// Used to create a 16BPP Palette from an 8 bit palette, found in himage.c
UINT16 *Create16BPPPaletteShaded( SGPPaletteEntry *pPalette, UINT32 rscale, UINT32 gscale, UINT32 bscale, BOOLEAN mono);
UINT16 *Create16BPPPalette( SGPPaletteEntry *pPalette );
UINT16 Get16BPPColor( UINT32 RGBValue );
UINT32 GetRGBColor( UINT16 Value16BPP );
SGPPaletteEntry *ConvertRGBToPaletteEntry(UINT8 sbStart, UINT8 sbEnd, UINT8 *pOldPalette);
extern UINT16 gusAlphaMask;
extern UINT16 gusRedMask;
extern UINT16 gusGreenMask;
extern UINT16 gusBlueMask;
extern INT16 gusRedShift;
extern INT16 gusBlueShift;
extern INT16 gusGreenShift;
// used to convert 565 RGB data into different bit-formats
void ConvertRGBDistribution565To555( UINT16 * p16BPPData, UINT32 uiNumberOfPixels );
void ConvertRGBDistribution565To655( UINT16 * p16BPPData, UINT32 uiNumberOfPixels );
void ConvertRGBDistribution565To556( UINT16 * p16BPPData, UINT32 uiNumberOfPixels );
void ConvertRGBDistribution565ToAny( UINT16 * p16BPPData, UINT32 uiNumberOfPixels );
#ifdef __cplusplus
}
#endif
#endif
+92
View File
@@ -0,0 +1,92 @@
#if !defined( STCI_H )
#define STCI_H
// Sir-Tech's Crazy Image (STCI) file format specifications. Each file is composed of:
// 1 ImageFileHeader, uncompressed
// * Palette (STCI_INDEXED, size = uiNumberOfColours * PALETTE_ELEMENT_SIZE), uncompressed
// * SubRectInfo's (usNumberOfRects > 0, size = usNumberOfSubRects * sizeof(SubRectInfo) ), uncompressed
// * Bytes of image data, possibly compressed
#include "types.h"
#define STCI_ID_STRING "STCI"
#define STCI_ID_LEN 4
#define STCI_ETRLE_COMPRESSED 0x0020
#define STCI_ZLIB_COMPRESSED 0x0010
#define STCI_INDEXED 0x0008
#define STCI_RGB 0x0004
#define STCI_ALPHA 0x0002
#define STCI_TRANSPARENT 0x0001
// ETRLE defines
#define COMPRESS_TRANSPARENT 0x80
#define COMPRESS_NON_TRANSPARENT 0x00
#define COMPRESS_RUN_LIMIT 0x7F
// NB if you're going to change the header definition:
// - make sure that everything in this header is nicely aligned
// - don't exceed the 64-byte maximum
typedef struct
{
UINT8 cID[STCI_ID_LEN];
UINT32 uiOriginalSize;
UINT32 uiStoredSize; // equal to uiOriginalSize if data uncompressed
UINT32 uiTransparentValue;
UINT32 fFlags;
UINT16 usHeight;
UINT16 usWidth;
union
{
struct
{
UINT32 uiRedMask;
UINT32 uiGreenMask;
UINT32 uiBlueMask;
UINT32 uiAlphaMask;
UINT8 ubRedDepth;
UINT8 ubGreenDepth;
UINT8 ubBlueDepth;
UINT8 ubAlphaDepth;
} RGB;
struct
{ // For indexed files, the palette will contain 3 separate bytes for red, green, and blue
UINT32 uiNumberOfColours;
UINT16 usNumberOfSubImages;
UINT8 ubRedDepth;
UINT8 ubGreenDepth;
UINT8 ubBlueDepth;
UINT8 cIndexedUnused[11];
} Indexed;
};
UINT8 ubDepth; // size in bits of one pixel as stored in the file
UINT32 uiAppDataSize;
UINT8 cUnused[15];
} STCIHeader;
#define STCI_HEADER_SIZE 64
typedef struct
{
UINT32 uiDataOffset;
UINT32 uiDataLength;
INT16 sOffsetX;
INT16 sOffsetY;
UINT16 usHeight;
UINT16 usWidth;
} STCISubImage;
#define STCI_SUBIMAGE_SIZE 16
typedef struct
{
UINT8 ubRed;
UINT8 ubGreen;
UINT8 ubBlue;
} STCIPaletteElement;
#define STCI_PALETTE_ELEMENT_SIZE 3
#define STCI_8BIT_PALETTE_SIZE 768
#endif
+83
View File
@@ -0,0 +1,83 @@
#ifndef _SGP_AUTO_MEMORY_H_
#define _SGP_AUTO_MEMORY_H_
namespace sgp
{
/************************************************************/
template<typename T>
class TAutoArray
{
public:
T& operator[](unsigned int index)
{
return _array[index];
}
T* operator()()
{
return _array;
}
T& operator*()
{
return *_array;
}
bool operator!()
{
// NULL == _array
return !_array;
}
T* release()
{
T* tmp = _array;
_array = NULL;
return tmp;
}
protected:
T* _array;
};
/************************************************************/
template<typename T>
class AutoArray : public TAutoArray<T>
{
public:
AutoArray(unsigned int size)
{
_array = new T[size];
}
~AutoArray()
{
if(_array)
{
delete[] _array;
}
}
};
/************************************************************/
template<typename T, typename void*(*Alloc)(size_t) = malloc, typename void(*Dealloc)(void*) = free>
class AutoCArray : public TAutoArray<T>
{
public:
AutoCArray(unsigned int size = 1)
{
_array = (T*)Alloc( size * sizeof(T) );
}
~AutoCArray()
{
if(_array)
{
Dealloc(_array);
}
}
};
/************************************************************/
} // namespace sgp
#endif // _SGP_AUTO_MEMORY_H_
+103
View File
@@ -0,0 +1,103 @@
#ifndef __TYPES_
#define __TYPES_
#include <wchar.h> // for wide-character strings
// *** SIR-TECH TYPE DEFINITIONS ***
// These two types are defined by VC6 and were causing redefinition
// problems, but JA2 is compiled with VC5
// HEY WIZARDRY DUDES, JA2 ISN'T THE ONLY PROGRAM WE COMPILE! :-)
typedef unsigned int UINT32;
typedef signed int INT32;
// integers
typedef unsigned char UINT8;
typedef signed char INT8;
typedef unsigned short UINT16;
typedef signed short INT16;
// floats
typedef float FLOAT;
typedef double DOUBLE;
// strings
typedef char CHAR8;
typedef wchar_t CHAR16;
typedef CHAR8 * STR;
typedef CHAR8 * STR8;
typedef CHAR16 * STR16;
// flags (individual bits used)
typedef unsigned char FLAGS8;
typedef unsigned short FLAGS16;
typedef unsigned long FLAGS32;
// other
typedef unsigned char BOOLEAN;
typedef void * PTR;
typedef unsigned short HNDL;
typedef UINT8 BYTE;
typedef CHAR8 STRING512[512];
typedef UINT32 HWFILE;
#define SGPFILENAME_LEN 100
typedef CHAR8 SGPFILENAME[SGPFILENAME_LEN];
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define BAD_INDEX -1
#define NULL_HANDLE 65535
#define PI 3.1415926
#ifndef NULL
#define NULL 0
#endif
typedef struct
{
INT32 iLeft;
INT32 iTop;
INT32 iRight;
INT32 iBottom;
} SGPRect;
typedef struct
{
INT32 iX;
INT32 iY;
} SGPPoint;
typedef struct
{
INT32 Min;
INT32 Max;
} SGPRange;
typedef FLOAT VECTOR2[2]; // 2d vector (2x1 matrix)
typedef FLOAT VECTOR3[3]; // 3d vector (3x1 matrix)
typedef FLOAT VECTOR4[4]; // 4d vector (4x1 matrix)
typedef INT32 IVECTOR2[2]; // 2d vector (2x1 matrix)
typedef INT32 IVECTOR3[3]; // 3d vector (3x1 matrix)
typedef INT32 IVECTOR4[4]; // 4d vector (4x1 matrix)
typedef VECTOR3 MATRIX3[3]; // 3x3 matrix
typedef VECTOR4 MATRIX4[4]; // 4x4 matrix
//typedef VECTOR3 ANGLE; // angle return array //lal removed
typedef VECTOR4 COLOR; // rgba color array
#endif