1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-09-19 12:06:07 +08:00

Added original SDK code for Alien Swarm.

This commit is contained in:
Scott Ehlert
2010-07-22 01:46:14 -05:00
commit c0a96ff1e8
3740 changed files with 1243478 additions and 0 deletions

107
public/bitmap/bitmap.h Normal file
View File

@ -0,0 +1,107 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $Header: $
// $NoKeywords: $
//===========================================================================//
#ifndef BITMAP_H
#define BITMAP_H
#ifdef _WIN32
#pragma once
#endif
#include "bitmap/imageformat.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CUtlBuffer;
//-----------------------------------------------------------------------------
// A Bitmap
//-----------------------------------------------------------------------------
struct Bitmap_t
{
Bitmap_t();
~Bitmap_t();
void Init( int nWidth, int nHeight, ImageFormat imageFormat );
unsigned char *GetPixel( int x, int y );
int m_nWidth;
int m_nHeight;
ImageFormat m_ImageFormat;
unsigned char *m_pBits;
};
inline Bitmap_t::Bitmap_t()
{
m_nWidth = 0;
m_nHeight = 0;
m_ImageFormat = IMAGE_FORMAT_UNKNOWN;
m_pBits = NULL;
}
inline Bitmap_t::~Bitmap_t()
{
if ( m_pBits )
{
delete[] m_pBits;
m_pBits = NULL;
}
}
inline void Bitmap_t::Init( int nWidth, int nHeight, ImageFormat imageFormat )
{
if ( m_pBits )
{
delete[] m_pBits;
m_pBits = NULL;
}
m_nWidth = nWidth;
m_nHeight = nHeight;
m_ImageFormat = imageFormat;
m_pBits = new unsigned char[ nWidth * nHeight * ImageLoader::SizeInBytes( m_ImageFormat ) ];
}
inline unsigned char *Bitmap_t::GetPixel( int x, int y )
{
if ( !m_pBits )
return NULL;
int nPixelSize = ImageLoader::SizeInBytes( m_ImageFormat );
return &m_pBits[ ( m_nWidth * y + x ) * nPixelSize ];
}
//-----------------------------------------------------------------------------
// Loads a bitmap from an arbitrary file: could be a TGA, PSD, or PFM.
// LoadBitmap autodetects which type, and returns it
//-----------------------------------------------------------------------------
enum BitmapFileType_t
{
BITMAP_FILE_TYPE_UNKNOWN = -1,
BITMAP_FILE_TYPE_PSD = 0,
BITMAP_FILE_TYPE_TGA,
BITMAP_FILE_TYPE_PFM,
};
BitmapFileType_t LoadBitmapFile( CUtlBuffer &buf, Bitmap_t *pBitmap );
//-----------------------------------------------------------------------------
// PFM file loading related methods
//-----------------------------------------------------------------------------
bool PFMReadFileR32F( CUtlBuffer &fileBuffer, Bitmap_t &bitmap, float pfmScale );
bool PFMReadFileRGB323232F( CUtlBuffer &fileBuffer, Bitmap_t &bitmap, float pfmScale );
bool PFMReadFileRGBA32323232F( CUtlBuffer &fileBuffer, Bitmap_t &bitmap, float pfmScale );
bool PFMGetInfo_AndAdvanceToTextureBits( CUtlBuffer &pfmBuffer, int &nWidth, int &nHeight, ImageFormat &imageFormat );
#endif // BITMAP_H

146
public/bitmap/colorformat.h Normal file
View File

@ -0,0 +1,146 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#ifndef COLORFORMAT_H
#define COLORFORMAT_H
#ifdef _WIN32
#pragma once
#endif
#include <stdio.h>
#include "mathlib/vector.h"
#include "mathlib/vector2d.h"
#include "mathlib/vector4d.h"
#include "mathlib/vertexcolor.h"
enum ColorFormat_t
{
COLOR_FORMAT_UNKNOWN = 0,
COLOR_FORMAT_R32G32B32A32_TYPELESS = 1,
COLOR_FORMAT_R32G32B32A32_FLOAT = 2,
COLOR_FORMAT_R32G32B32A32_UINT = 3,
COLOR_FORMAT_R32G32B32A32_SINT = 4,
COLOR_FORMAT_R32G32B32_TYPELESS = 5,
COLOR_FORMAT_R32G32B32_FLOAT = 6,
COLOR_FORMAT_R32G32B32_UINT = 7,
COLOR_FORMAT_R32G32B32_SINT = 8,
COLOR_FORMAT_R16G16B16A16_TYPELESS = 9,
COLOR_FORMAT_R16G16B16A16_FLOAT = 10,
COLOR_FORMAT_R16G16B16A16_UNORM = 11,
COLOR_FORMAT_R16G16B16A16_UINT = 12,
COLOR_FORMAT_R16G16B16A16_SNORM = 13,
COLOR_FORMAT_R16G16B16A16_SINT = 14,
COLOR_FORMAT_R32G32_TYPELESS = 15,
COLOR_FORMAT_R32G32_FLOAT = 16,
COLOR_FORMAT_R32G32_UINT = 17,
COLOR_FORMAT_R32G32_SINT = 18,
COLOR_FORMAT_R32G8X24_TYPELESS = 19,
COLOR_FORMAT_D32_FLOAT_S8X24_UINT = 20,
COLOR_FORMAT_R32_FLOAT_X8X24_TYPELESS = 21,
COLOR_FORMAT_X32_TYPELESS_G8X24_UINT = 22,
COLOR_FORMAT_R10G10B10A2_TYPELESS = 23,
COLOR_FORMAT_R10G10B10A2_UNORM = 24,
COLOR_FORMAT_R10G10B10A2_UINT = 25,
COLOR_FORMAT_R11G11B10_FLOAT = 26,
COLOR_FORMAT_R8G8B8A8_TYPELESS = 27,
COLOR_FORMAT_R8G8B8A8_UNORM = 28,
COLOR_FORMAT_R8G8B8A8_UNORM_SRGB = 29,
COLOR_FORMAT_R8G8B8A8_UINT = 30,
COLOR_FORMAT_R8G8B8A8_SNORM = 31,
COLOR_FORMAT_R8G8B8A8_SINT = 32,
COLOR_FORMAT_R16G16_TYPELESS = 33,
COLOR_FORMAT_R16G16_FLOAT = 34,
COLOR_FORMAT_R16G16_UNORM = 35,
COLOR_FORMAT_R16G16_UINT = 36,
COLOR_FORMAT_R16G16_SNORM = 37,
COLOR_FORMAT_R16G16_SINT = 38,
COLOR_FORMAT_R32_TYPELESS = 39,
COLOR_FORMAT_D32_FLOAT = 40,
COLOR_FORMAT_R32_FLOAT = 41,
COLOR_FORMAT_R32_UINT = 42,
COLOR_FORMAT_R32_SINT = 43,
COLOR_FORMAT_R24G8_TYPELESS = 44,
COLOR_FORMAT_D24_UNORM_S8_UINT = 45,
COLOR_FORMAT_R24_UNORM_X8_TYPELESS = 46,
COLOR_FORMAT_X24_TYPELESS_G8_UINT = 47,
COLOR_FORMAT_R8G8_TYPELESS = 48,
COLOR_FORMAT_R8G8_UNORM = 49,
COLOR_FORMAT_R8G8_UINT = 50,
COLOR_FORMAT_R8G8_SNORM = 51,
COLOR_FORMAT_R8G8_SINT = 52,
COLOR_FORMAT_R16_TYPELESS = 53,
COLOR_FORMAT_R16_FLOAT = 54,
COLOR_FORMAT_D16_UNORM = 55,
COLOR_FORMAT_R16_UNORM = 56,
COLOR_FORMAT_R16_UINT = 57,
COLOR_FORMAT_R16_SNORM = 58,
COLOR_FORMAT_R16_SINT = 59,
COLOR_FORMAT_R8_TYPELESS = 60,
COLOR_FORMAT_R8_UNORM = 61,
COLOR_FORMAT_R8_UINT = 62,
COLOR_FORMAT_R8_SNORM = 63,
COLOR_FORMAT_R8_SINT = 64,
COLOR_FORMAT_A8_UNORM = 65,
COLOR_FORMAT_R1_UNORM = 66,
COLOR_FORMAT_R9G9B9E5_SHAREDEXP = 67,
COLOR_FORMAT_R8G8_B8G8_UNORM = 68,
COLOR_FORMAT_G8R8_G8B8_UNORM = 69,
COLOR_FORMAT_BC1_TYPELESS = 70,
COLOR_FORMAT_BC1_UNORM = 71,
COLOR_FORMAT_BC1_UNORM_SRGB = 72,
COLOR_FORMAT_BC2_TYPELESS = 73,
COLOR_FORMAT_BC2_UNORM = 74,
COLOR_FORMAT_BC2_UNORM_SRGB = 75,
COLOR_FORMAT_BC3_TYPELESS = 76,
COLOR_FORMAT_BC3_UNORM = 77,
COLOR_FORMAT_BC3_UNORM_SRGB = 78,
COLOR_FORMAT_BC4_TYPELESS = 79,
COLOR_FORMAT_BC4_UNORM = 80,
COLOR_FORMAT_BC4_SNORM = 81,
COLOR_FORMAT_BC5_TYPELESS = 82,
COLOR_FORMAT_BC5_UNORM = 83,
COLOR_FORMAT_BC5_SNORM = 84,
COLOR_FORMAT_B5G6R5_UNORM = 85,
COLOR_FORMAT_B5G5R5A1_UNORM = 86,
COLOR_FORMAT_B8G8R8A8_UNORM = 87,
COLOR_FORMAT_B8G8R8X8_UNORM = 88,
COLOR_FORMAT_FORCE_UINT = 0xffffffffUL,
};
template < class T > inline ColorFormat_t ComputeColorFormat( T* )
{
return COLOR_FORMAT_UNKNOWN;
}
template <> inline ColorFormat_t ComputeColorFormat( float32* )
{
return COLOR_FORMAT_R32_FLOAT;
}
template <> inline ColorFormat_t ComputeColorFormat( Vector2D* )
{
return COLOR_FORMAT_R32G32_FLOAT;
}
template <> inline ColorFormat_t ComputeColorFormat( Vector* )
{
return COLOR_FORMAT_R32G32B32_FLOAT;
}
template <> inline ColorFormat_t ComputeColorFormat( Vector4D* )
{
return COLOR_FORMAT_R32G32B32A32_FLOAT;
}
template <> inline ColorFormat_t ComputeColorFormat( VertexColor_t* )
{
// FIXME: How to get at SRGB formats?
return COLOR_FORMAT_R8G8B8A8_UNORM;
}
#endif // COLORFORMAT_H

68
public/bitmap/cubemap.h Normal file
View File

@ -0,0 +1,68 @@
//===== Copyright <20> 1996-2007, Valve Corporation, All rights reserved. ======//
//
// Purpose: a class for performing cube-mapped spherical sample lookups.
//
// $Workfile: $
// $Date: $
// $NoKeywords: $
//===========================================================================//
#ifndef CUBEMAP_H
#define CUBEMAP_H
#ifdef _WIN32
#pragma once
#endif
#include "tier0/platform.h"
#include "tier1/utlmemory.h"
#include "mathlib/mathlib.h"
template<class T, int RES> struct CCubeMap
{
T m_Samples[6][RES][RES];
public:
FORCEINLINE void GetCoords( Vector const &vecNormalizedDirection, int &nX, int &nY, int &nFace )
{
// find largest magnitude component
int nLargest = 0;
int nAxis0 = 1;
int nAxis1 = 2;
if ( fabs( vecNormalizedDirection[1] ) > fabs( vecNormalizedDirection[0] ) )
{
nLargest = 1;
nAxis0 = 0;
nAxis1 = 2;
}
if ( fabs( vecNormalizedDirection[2] ) > fabs( vecNormalizedDirection[nLargest] ) )
{
nLargest = 2;
nAxis0 = 0;
nAxis1 = 1;
}
float flZ = vecNormalizedDirection[nLargest];
if ( flZ < 0 )
{
flZ = - flZ;
nLargest += 3;
}
nFace = nLargest;
flZ = 1.0 / flZ;
nX = RemapValClamped( vecNormalizedDirection[nAxis0] * flZ, -1, 1, 0, RES - 1 );
nY = RemapValClamped( vecNormalizedDirection[nAxis1] * flZ, -1, 1, 0, RES - 1 );
}
FORCEINLINE T & GetSample( Vector const &vecNormalizedDirection )
{
int nX, nY, nFace;
GetCoords( vecNormalizedDirection, nX, nY, nFace );
return m_Samples[nFace][nX][nY];
}
};
#endif // CUBEMAP_H

783
public/bitmap/imageformat.h Normal file
View File

@ -0,0 +1,783 @@
//===== Copyright 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#ifndef IMAGEFORMAT_H
#define IMAGEFORMAT_H
#ifdef _WIN32
#pragma once
#endif
#include <stdio.h>
#include "tier0/platform.h"
#include "tier0/dbg.h"
enum NormalDecodeMode_t
{
NORMAL_DECODE_NONE = 0,
NORMAL_DECODE_ATI2N = 1,
NORMAL_DECODE_ATI2N_ALPHA = 2
};
// Forward declaration
#ifdef _WIN32
typedef enum _D3DFORMAT D3DFORMAT;
typedef enum DXGI_FORMAT;
#endif
//-----------------------------------------------------------------------------
// The various image format types
//-----------------------------------------------------------------------------
// don't bitch that inline functions aren't used!!!!
#pragma warning(disable : 4514)
enum ImageFormat
{
IMAGE_FORMAT_UNKNOWN = -1,
IMAGE_FORMAT_RGBA8888 = 0,
IMAGE_FORMAT_ABGR8888,
IMAGE_FORMAT_RGB888,
IMAGE_FORMAT_BGR888,
IMAGE_FORMAT_RGB565,
IMAGE_FORMAT_I8,
IMAGE_FORMAT_IA88,
IMAGE_FORMAT_P8,
IMAGE_FORMAT_A8,
IMAGE_FORMAT_RGB888_BLUESCREEN,
IMAGE_FORMAT_BGR888_BLUESCREEN,
IMAGE_FORMAT_ARGB8888,
IMAGE_FORMAT_BGRA8888,
IMAGE_FORMAT_DXT1,
IMAGE_FORMAT_DXT3,
IMAGE_FORMAT_DXT5,
IMAGE_FORMAT_BGRX8888,
IMAGE_FORMAT_BGR565,
IMAGE_FORMAT_BGRX5551,
IMAGE_FORMAT_BGRA4444,
IMAGE_FORMAT_DXT1_ONEBITALPHA,
IMAGE_FORMAT_BGRA5551,
IMAGE_FORMAT_UV88,
IMAGE_FORMAT_UVWQ8888,
IMAGE_FORMAT_RGBA16161616F,
IMAGE_FORMAT_RGBA16161616,
IMAGE_FORMAT_UVLX8888,
IMAGE_FORMAT_R32F, // Single-channel 32-bit floating point
IMAGE_FORMAT_RGB323232F, // NOTE: D3D9 does not have this format
IMAGE_FORMAT_RGBA32323232F,
IMAGE_FORMAT_RG1616F,
IMAGE_FORMAT_RG3232F,
IMAGE_FORMAT_RGBX8888,
IMAGE_FORMAT_NULL, // Dummy format which takes no video memory
// Compressed normal map formats
IMAGE_FORMAT_ATI2N, // One-surface ATI2N / DXN format
IMAGE_FORMAT_ATI1N, // Two-surface ATI1N format
IMAGE_FORMAT_RGBA1010102, // 10 bit-per component render targets
IMAGE_FORMAT_BGRA1010102,
IMAGE_FORMAT_R16F, // 16 bit FP format
// Depth-stencil texture formats
IMAGE_FORMAT_D16,
IMAGE_FORMAT_D15S1,
IMAGE_FORMAT_D32,
IMAGE_FORMAT_D24S8,
IMAGE_FORMAT_LINEAR_D24S8,
IMAGE_FORMAT_D24X8,
IMAGE_FORMAT_D24X4S4,
IMAGE_FORMAT_D24FS8,
IMAGE_FORMAT_D16_SHADOW, // Specific formats for shadow mapping
IMAGE_FORMAT_D24X8_SHADOW, // Specific formats for shadow mapping
// supporting these specific formats as non-tiled for procedural cpu access (360-specific)
IMAGE_FORMAT_LINEAR_BGRX8888,
IMAGE_FORMAT_LINEAR_RGBA8888,
IMAGE_FORMAT_LINEAR_ABGR8888,
IMAGE_FORMAT_LINEAR_ARGB8888,
IMAGE_FORMAT_LINEAR_BGRA8888,
IMAGE_FORMAT_LINEAR_RGB888,
IMAGE_FORMAT_LINEAR_BGR888,
IMAGE_FORMAT_LINEAR_BGRX5551,
IMAGE_FORMAT_LINEAR_I8,
IMAGE_FORMAT_LINEAR_RGBA16161616,
IMAGE_FORMAT_LE_BGRX8888,
IMAGE_FORMAT_LE_BGRA8888,
NUM_IMAGE_FORMATS
};
#if defined( POSIX ) || defined( DX_TO_GL_ABSTRACTION )
typedef enum _D3DFORMAT
{
D3DFMT_INDEX16,
D3DFMT_D16,
D3DFMT_D24S8,
D3DFMT_A8R8G8B8,
D3DFMT_A4R4G4B4,
D3DFMT_X8R8G8B8,
D3DFMT_R5G6R5,
D3DFMT_X1R5G5B5,
D3DFMT_A1R5G5B5,
D3DFMT_L8,
D3DFMT_A8L8,
D3DFMT_A,
D3DFMT_DXT1,
D3DFMT_DXT3,
D3DFMT_DXT5,
D3DFMT_V8U8,
D3DFMT_Q8W8V8U8,
D3DFMT_X8L8V8U8,
D3DFMT_A16B16G16R16F,
D3DFMT_A16B16G16R16,
D3DFMT_R32F,
D3DFMT_A32B32G32R32F,
D3DFMT_R8G8B8,
D3DFMT_D24X4S4,
D3DFMT_A8,
D3DFMT_R5G6B5,
D3DFMT_D15S1,
D3DFMT_D24X8,
D3DFMT_VERTEXDATA,
D3DFMT_INDEX32,
// adding fake D3D format names for the vendor specific ones (eases debugging/logging)
// NV shadow depth tex
D3DFMT_NV_INTZ = 0x5a544e49, // MAKEFOURCC('I','N','T','Z')
D3DFMT_NV_RAWZ = 0x5a574152, // MAKEFOURCC('R','A','W','Z')
// NV null tex
D3DFMT_NV_NULL = 0x4c4c554e, // MAKEFOURCC('N','U','L','L')
// ATI shadow depth tex
D3DFMT_ATI_D16 = 0x36314644, // MAKEFOURCC('D','F','1','6')
D3DFMT_ATI_D24S8 = 0x34324644, // MAKEFOURCC('D','F','2','4')
// ATI 1N and 2N compressed tex
D3DFMT_ATI_2N = 0x32495441, // MAKEFOURCC('A', 'T', 'I', '2')
D3DFMT_ATI_1N = 0x31495441, // MAKEFOURCC('A', 'T', 'I', '1')
D3DFMT_UNKNOWN
} D3DFORMAT;
#endif
//-----------------------------------------------------------------------------
// Color structures
//-----------------------------------------------------------------------------
#pragma warning ( disable : 4293 )
template< int nBitCount > FORCEINLINE int ConvertTo10Bit( int x )
{
switch ( nBitCount )
{
case 1:
return ( x & 0x1 ) ? 0x3FF : 0;
case 2:
return ( x << 8 ) | ( x << 6 ) | ( x << 4 ) | ( x << 2 ) | x;
case 3:
return ( x << 7 ) | ( x << 4 ) | ( x << 1 ) | ( x >> 2 );
case 4:
return ( x << 6 ) | ( x << 2 ) | ( x >> 2 );
default:
return ( x << ( 10 - nBitCount ) ) | ( x >> ( nBitCount - ( 10 - nBitCount ) ) );
}
}
#pragma warning ( default : 4293 )
template< int nBitCount > FORCEINLINE int ConvertFrom10Bit( int x )
{
return ( x >> ( 10 - nBitCount ) );
}
struct R32F_t
{
float32 r;
};
struct RG3232F_t
{
float32 r;
float32 g;
};
struct RGB323232F_t
{
float32 r;
float32 g;
float32 b;
};
struct RGBA32323232F_t
{
float32 r;
float32 g;
float32 b;
float32 a;
};
struct RGBA1010102_t
{
uint32 r : 10;
uint32 g : 10;
uint32 b : 10;
uint32 a : 2;
inline int RTo10Bit( ) const { return ConvertTo10Bit<10>( r ); }
inline int GTo10Bit( ) const { return ConvertTo10Bit<10>( g ); }
inline int BTo10Bit( ) const { return ConvertTo10Bit<10>( b ); }
inline int ATo10Bit( ) const { return ConvertTo10Bit<2>( a ); }
inline void RFrom10Bit( int r10 ) { r = ConvertFrom10Bit<10>( r10 ); }
inline void GFrom10Bit( int g10 ) { g = ConvertFrom10Bit<10>( g10 ); }
inline void BFrom10Bit( int b10 ) { b = ConvertFrom10Bit<10>( b10 ); }
inline void AFrom10Bit( int a10 ) { a = ConvertFrom10Bit<10>( a10 ); }
};
struct BGRA1010102_t
{
uint32 b : 10;
uint32 g : 10;
uint32 r : 10;
uint32 a : 2;
inline int RTo10Bit( ) const { return ConvertTo10Bit<10>( r ); }
inline int GTo10Bit( ) const { return ConvertTo10Bit<10>( g ); }
inline int BTo10Bit( ) const { return ConvertTo10Bit<10>( b ); }
inline int ATo10Bit( ) const { return ConvertTo10Bit<2>( a ); }
inline void RFrom10Bit( int r10 ) { r = ConvertFrom10Bit<10>( r10 ); }
inline void GFrom10Bit( int g10 ) { g = ConvertFrom10Bit<10>( g10 ); }
inline void BFrom10Bit( int b10 ) { b = ConvertFrom10Bit<10>( b10 ); }
inline void AFrom10Bit( int a10 ) { a = ConvertFrom10Bit<10>( a10 ); }
};
struct BGRA8888_t
{
uint8 b; // change the order of names to change the
uint8 g; // order of the output ARGB or BGRA, etc...
uint8 r; // Last one is MSB, 1st is LSB.
uint8 a;
inline BGRA8888_t& operator=( const BGRA8888_t& in )
{
*( unsigned int * )this = *( unsigned int * )&in;
return *this;
}
inline int RTo10Bit( ) const { return ConvertTo10Bit<8>( r ); }
inline int GTo10Bit( ) const { return ConvertTo10Bit<8>( g ); }
inline int BTo10Bit( ) const { return ConvertTo10Bit<8>( b ); }
inline int ATo10Bit( ) const { return ConvertTo10Bit<8>( a ); }
inline void RFrom10Bit( int r10 ) { r = ConvertFrom10Bit<8>( r10 ); }
inline void GFrom10Bit( int g10 ) { g = ConvertFrom10Bit<8>( g10 ); }
inline void BFrom10Bit( int b10 ) { b = ConvertFrom10Bit<8>( b10 ); }
inline void AFrom10Bit( int a10 ) { a = ConvertFrom10Bit<8>( a10 ); }
};
struct ABGR8888_t
{
uint8 a;
uint8 b; // change the order of names to change the
uint8 g; // order of the output ARGB or BGRA, etc...
uint8 r; // Last one is MSB, 1st is LSB.
inline ABGR8888_t& operator=( const BGRA8888_t& in )
{
r = in.r;
g = in.g;
b = in.b;
a = in.a;
return *this;
}
inline int RTo10Bit( ) const { return ConvertTo10Bit<8>( r ); }
inline int GTo10Bit( ) const { return ConvertTo10Bit<8>( g ); }
inline int BTo10Bit( ) const { return ConvertTo10Bit<8>( b ); }
inline int ATo10Bit( ) const { return ConvertTo10Bit<8>( a ); }
inline void RFrom10Bit( int r10 ) { r = ConvertFrom10Bit<8>( r10 ); }
inline void GFrom10Bit( int g10 ) { g = ConvertFrom10Bit<8>( g10 ); }
inline void BFrom10Bit( int b10 ) { b = ConvertFrom10Bit<8>( b10 ); }
inline void AFrom10Bit( int a10 ) { a = ConvertFrom10Bit<8>( a10 ); }
};
struct RGBA8888_t
{
uint8 r; // change the order of names to change the
uint8 g; // order of the output ARGB or BGRA, etc...
uint8 b; // Last one is MSB, 1st is LSB.
uint8 a;
inline RGBA8888_t& operator=( const BGRA8888_t& in )
{
r = in.r;
g = in.g;
b = in.b;
a = in.a;
return *this;
}
inline int RTo10Bit( ) const { return ConvertTo10Bit<8>( r ); }
inline int GTo10Bit( ) const { return ConvertTo10Bit<8>( g ); }
inline int BTo10Bit( ) const { return ConvertTo10Bit<8>( b ); }
inline int ATo10Bit( ) const { return ConvertTo10Bit<8>( a ); }
inline void RFrom10Bit( int r10 ) { r = ConvertFrom10Bit<8>( r10 ); }
inline void GFrom10Bit( int g10 ) { g = ConvertFrom10Bit<8>( g10 ); }
inline void BFrom10Bit( int b10 ) { b = ConvertFrom10Bit<8>( b10 ); }
inline void AFrom10Bit( int a10 ) { a = ConvertFrom10Bit<8>( a10 ); }
};
struct RGB888_t
{
uint8 r;
uint8 g;
uint8 b;
inline RGB888_t& operator=( const BGRA8888_t& in )
{
r = in.r;
g = in.g;
b = in.b;
return *this;
}
inline bool operator==( const RGB888_t& in ) const
{
return ( r == in.r ) && ( g == in.g ) && ( b == in.b );
}
inline bool operator!=( const RGB888_t& in ) const
{
return ( r != in.r ) || ( g != in.g ) || ( b != in.b );
}
inline int RTo10Bit( ) const { return ConvertTo10Bit<8>( r ); }
inline int GTo10Bit( ) const { return ConvertTo10Bit<8>( g ); }
inline int BTo10Bit( ) const { return ConvertTo10Bit<8>( b ); }
inline void RFrom10Bit( int r10 ) { r = ConvertFrom10Bit<8>( r10 ); }
inline void GFrom10Bit( int g10 ) { g = ConvertFrom10Bit<8>( g10 ); }
inline void BFrom10Bit( int b10 ) { b = ConvertFrom10Bit<8>( b10 ); }
};
struct BGR888_t
{
uint8 b;
uint8 g;
uint8 r;
inline BGR888_t& operator=( const BGRA8888_t& in )
{
r = in.r;
g = in.g;
b = in.b;
return *this;
}
inline int RTo10Bit( ) const { return ConvertTo10Bit<8>( r ); }
inline int GTo10Bit( ) const { return ConvertTo10Bit<8>( g ); }
inline int BTo10Bit( ) const { return ConvertTo10Bit<8>( b ); }
inline void RFrom10Bit( int r10 ) { r = ConvertFrom10Bit<8>( r10 ); }
inline void GFrom10Bit( int g10 ) { g = ConvertFrom10Bit<8>( g10 ); }
inline void BFrom10Bit( int b10 ) { b = ConvertFrom10Bit<8>( b10 ); }
};
struct BGRX8888_t
{
uint8 b;
uint8 g;
uint8 r;
uint8 x;
inline BGRX8888_t& operator=( const BGRA8888_t& in )
{
r = in.r;
g = in.g;
b = in.b;
x = 255;
return *this;
}
inline int RTo10Bit( ) const { return ConvertTo10Bit<8>( r ); }
inline int GTo10Bit( ) const { return ConvertTo10Bit<8>( g ); }
inline int BTo10Bit( ) const { return ConvertTo10Bit<8>( b ); }
inline void RFrom10Bit( int r10 ) { r = ConvertFrom10Bit<8>( r10 ); }
inline void GFrom10Bit( int g10 ) { g = ConvertFrom10Bit<8>( g10 ); }
inline void BFrom10Bit( int b10 ) { b = ConvertFrom10Bit<8>( b10 ); }
};
// 360 uses this structure for x86 dxt decoding
#if defined( _X360 )
#pragma bitfield_order( push, lsb_to_msb )
#endif
struct BGR565_t
{
uint16 b : 5; // order of names changes
uint16 g : 6; // byte order of output to 32 bit
uint16 r : 5;
inline BGR565_t& operator=( const BGRA8888_t& in )
{
r = in.r >> 3;
g = in.g >> 2;
b = in.b >> 3;
return *this;
}
inline BGR565_t &Set( int red, int green, int blue )
{
r = red >> 3;
g = green >> 2;
b = blue >> 3;
return *this;
}
inline int RTo10Bit( ) const { return ConvertTo10Bit<5>( r ); }
inline int GTo10Bit( ) const { return ConvertTo10Bit<6>( g ); }
inline int BTo10Bit( ) const { return ConvertTo10Bit<5>( b ); }
inline void RFrom10Bit( int r10 ) { r = ConvertFrom10Bit<5>( r10 ); }
inline void GFrom10Bit( int g10 ) { g = ConvertFrom10Bit<6>( g10 ); }
inline void BFrom10Bit( int b10 ) { b = ConvertFrom10Bit<5>( b10 ); }
};
#if defined( _X360 )
#pragma bitfield_order( pop )
#endif
struct BGRA5551_t
{
uint16 b : 5; // order of names changes
uint16 g : 5; // byte order of output to 32 bit
uint16 r : 5;
uint16 a : 1;
inline BGRA5551_t& operator=( const BGRA8888_t& in )
{
r = in.r >> 3;
g = in.g >> 3;
b = in.b >> 3;
a = in.a >> 7;
return *this;
}
inline int RTo10Bit( ) const { return ConvertTo10Bit<5>( r ); }
inline int GTo10Bit( ) const { return ConvertTo10Bit<5>( g ); }
inline int BTo10Bit( ) const { return ConvertTo10Bit<5>( b ); }
inline int ATo10Bit( ) const { return ConvertTo10Bit<1>( a ); }
inline void RFrom10Bit( int r10 ) { r = ConvertFrom10Bit<5>( r10 ); }
inline void GFrom10Bit( int g10 ) { g = ConvertFrom10Bit<5>( g10 ); }
inline void BFrom10Bit( int b10 ) { b = ConvertFrom10Bit<5>( b10 ); }
inline void AFrom10Bit( int a10 ) { a = ConvertFrom10Bit<1>( a10 ); }
};
struct BGRA4444_t
{
uint16 b : 4; // order of names changes
uint16 g : 4; // byte order of output to 32 bit
uint16 r : 4;
uint16 a : 4;
inline BGRA4444_t& operator=( const BGRA8888_t& in )
{
r = in.r >> 4;
g = in.g >> 4;
b = in.b >> 4;
a = in.a >> 4;
return *this;
}
inline int RTo10Bit( ) const { return ConvertTo10Bit<4>( r ); }
inline int GTo10Bit( ) const { return ConvertTo10Bit<4>( g ); }
inline int BTo10Bit( ) const { return ConvertTo10Bit<4>( b ); }
inline int ATo10Bit( ) const { return ConvertTo10Bit<4>( a ); }
inline void RFrom10Bit( int r10 ) { r = ConvertFrom10Bit<4>( r10 ); }
inline void GFrom10Bit( int g10 ) { g = ConvertFrom10Bit<4>( g10 ); }
inline void BFrom10Bit( int b10 ) { b = ConvertFrom10Bit<4>( b10 ); }
inline void AFrom10Bit( int a10 ) { a = ConvertFrom10Bit<4>( a10 ); }
};
struct RGBX5551_t
{
uint16 r : 5;
uint16 g : 5;
uint16 b : 5;
uint16 x : 1;
inline RGBX5551_t& operator=( const BGRA8888_t& in )
{
r = in.r >> 3;
g = in.g >> 3;
b = in.b >> 3;
return *this;
}
inline int RTo10Bit( ) const { return ConvertTo10Bit<5>( r ); }
inline int GTo10Bit( ) const { return ConvertTo10Bit<5>( g ); }
inline int BTo10Bit( ) const { return ConvertTo10Bit<5>( b ); }
inline void RFrom10Bit( int r10 ) { r = ConvertFrom10Bit<5>( r10 ); }
inline void GFrom10Bit( int g10 ) { g = ConvertFrom10Bit<5>( g10 ); }
inline void BFrom10Bit( int b10 ) { b = ConvertFrom10Bit<5>( b10 ); }
};
struct UV88_t
{
int8 u;
int8 v;
};
struct UVWQ8888_t
{
int8 u;
int8 v;
int8 w;
int8 q;
};
struct UVLX8888_t
{
int8 u;
int8 v;
uint8 l;
uint8 x;
};
//-----------------------------------------------------------------------------
// some important constants
//-----------------------------------------------------------------------------
#define ARTWORK_GAMMA ( 2.2f )
#define IMAGE_MAX_DIM ( 2048 )
//-----------------------------------------------------------------------------
// information about each image format
//-----------------------------------------------------------------------------
struct ImageFormatInfo_t
{
const char* m_pName;
uint8 m_nNumBytes;
uint8 m_nNumRedBits;
uint8 m_nNumGreenBits;
uint8 m_nNumBlueBits;
uint8 m_nNumAlphaBits;
uint8 m_nNumDepthBits;
uint8 m_nNumStencilBits;
bool m_bIsCompressed:1;
bool m_bIsFloat:1;
bool m_bIsDepthFormat : 1;
};
//-----------------------------------------------------------------------------
// Computes nice filters for a compression ratio
//-----------------------------------------------------------------------------
struct KernelInfo_t
{
float *m_pKernel;
float *m_pInvKernel;
int m_nWidth;
int m_nHeight;
int m_nDepth;
int m_nDiameter;
};
//-----------------------------------------------------------------------------
// Various methods related to pixelmaps and color formats
//-----------------------------------------------------------------------------
namespace ImageLoader
{
bool GetInfo( const char *fileName, int *width, int *height, enum ImageFormat *imageFormat, float *sourceGamma );
// Generates a nice filter kernel
void ComputeNiceFilterKernel( float flWRatio, float flHRatio, float flDRatio, KernelInfo_t *pKernel );
void CleanupNiceFilterKernel( KernelInfo_t *pKernel );
// adjustedheight received the height adjusted for compression (/4 for dxt)
int GetMemRequired( int width, int height, int depth, ImageFormat imageFormat, bool mipmap, int *pAdjustedHeightOut = NULL );
int GetMemRequired( int width, int height, int depth, int nMipmapCount, ImageFormat imageFormat, int *pAdjustedHeightOut = NULL );
// This version is for mipmaps which are stored biggest level to smallest level in memory
int GetMipMapLevelByteOffset( int width, int height, ImageFormat imageFormat, int skipMipLevels, int nDepth = 1 );
// This version is for mipmaps which are stored smallest level to largest level in memory
int GetMipMapLevelByteOffsetReverse( int nWidth, int nHeight, int nDepth, int nTotalMipCount, ImageFormat imageFormat, int nMipLevel );
void GetMipMapLevelDimensions( int *width, int *height, int skipMipLevels );
void GetMipMapLevelDimensions( int &nWidth, int &nHeight, int &nDepth, int nMipLevel );
int GetNumMipMapLevels( int width, int height, int depth = 1 );
bool Load( unsigned char *imageData, const char *fileName, int width, int height, ImageFormat imageFormat, float targetGamma, bool mipmap );
bool Load( unsigned char *imageData, FILE *fp, int width, int height,
enum ImageFormat imageFormat, float targetGamma, bool mipmap );
// convert from any image format to any other image format.
// return false if the conversion cannot be performed.
// Strides denote the number of bytes per each line,
// by default assumes width * # of bytes per pixel
bool ConvertImageFormat( const unsigned char *src, enum ImageFormat srcImageFormat,
unsigned char *dst, enum ImageFormat dstImageFormat,
int width, int height, int srcStride = 0, int dstStride = 0 );
// must be used in conjunction with ConvertImageFormat() to pre-swap and post-swap
void PreConvertSwapImageData( unsigned char *pImageData, int nImageSize, ImageFormat imageFormat, int width = 0, int stride = 0 );
void PostConvertSwapImageData( unsigned char *pImageData, int nImageSize, ImageFormat imageFormat, int width = 0, int stride = 0 );
void ByteSwapImageData( unsigned char *pImageData, int nImageSize, ImageFormat imageFormat, int width = 0, int stride = 0 );
bool IsFormatValidForConversion( ImageFormat fmt );
//-----------------------------------------------------------------------------
// convert back and forth from D3D format to ImageFormat, regardless of
// whether it's supported or not
// FIXME: Move into shaderapidx8/rendersystemdx9
//-----------------------------------------------------------------------------
ImageFormat D3DFormatToImageFormat( D3DFORMAT format );
D3DFORMAT ImageFormatToD3DFormat( ImageFormat format );
// Flags for ResampleRGBA8888
enum
{
RESAMPLE_NORMALMAP = 0x1,
RESAMPLE_ALPHATEST = 0x2,
RESAMPLE_NICE_FILTER = 0x4,
RESAMPLE_CLAMPS = 0x8,
RESAMPLE_CLAMPT = 0x10,
RESAMPLE_CLAMPU = 0x20,
};
struct ResampleInfo_t
{
ResampleInfo_t() : m_nFlags(0), m_flAlphaThreshhold(0.4f), m_flAlphaHiFreqThreshhold(0.4f), m_nSrcDepth(1), m_nDestDepth(1)
{
m_flColorScale[0] = 1.0f, m_flColorScale[1] = 1.0f, m_flColorScale[2] = 1.0f, m_flColorScale[3] = 1.0f;
m_flColorGoal[0] = 0.0f, m_flColorGoal[1] = 0.0f, m_flColorGoal[2] = 0.0f, m_flColorGoal[3] = 0.0f;
}
unsigned char *m_pSrc;
unsigned char *m_pDest;
int m_nSrcWidth;
int m_nSrcHeight;
int m_nSrcDepth;
int m_nDestWidth;
int m_nDestHeight;
int m_nDestDepth;
float m_flSrcGamma;
float m_flDestGamma;
float m_flColorScale[4]; // Color scale factors RGBA
float m_flColorGoal[4]; // Color goal values RGBA DestColor = ColorGoal + scale * (SrcColor - ColorGoal)
float m_flAlphaThreshhold;
float m_flAlphaHiFreqThreshhold;
int m_nFlags;
};
bool ResampleRGBA8888( const ResampleInfo_t &info );
bool ResampleRGBA16161616( const ResampleInfo_t &info );
bool ResampleRGB323232F( const ResampleInfo_t &info );
bool ResampleRGBA32323232F( const ResampleInfo_t &info );
void ConvertNormalMapRGBA8888ToDUDVMapUVLX8888( const unsigned char *src, int width, int height, unsigned char *dst_ );
void ConvertNormalMapRGBA8888ToDUDVMapUVWQ8888( const unsigned char *src, int width, int height, unsigned char *dst_ );
void ConvertNormalMapRGBA8888ToDUDVMapUV88( const unsigned char *src, int width, int height, unsigned char *dst_ );
void ConvertNormalMapARGB8888ToDXT5GA( const unsigned char *src, unsigned char *dst, int width, int height );
void ConvertIA88ImageToNormalMapRGBA8888( const unsigned char *src, int width,
int height, unsigned char *dst,
float bumpScale );
void NormalizeNormalMapRGBA8888( unsigned char *src, int numTexels );
//-----------------------------------------------------------------------------
// Gamma correction
//-----------------------------------------------------------------------------
void GammaCorrectRGBA8888( unsigned char *src, unsigned char* dst,
int width, int height, int depth, float srcGamma, float dstGamma );
//-----------------------------------------------------------------------------
// Makes a gamma table
//-----------------------------------------------------------------------------
void ConstructGammaTable( unsigned char* pTable, float srcGamma, float dstGamma );
//-----------------------------------------------------------------------------
// Gamma corrects using a previously constructed gamma table
//-----------------------------------------------------------------------------
void GammaCorrectRGBA8888( unsigned char* pSrc, unsigned char* pDst,
int width, int height, int depth, unsigned char* pGammaTable );
//-----------------------------------------------------------------------------
// Generates a number of mipmap levels
//-----------------------------------------------------------------------------
void GenerateMipmapLevels( unsigned char* pSrc, unsigned char* pDst, int width,
int height, int depth, ImageFormat imageFormat, float srcGamma, float dstGamma,
int numLevels = 0 );
//-----------------------------------------------------------------------------
// operations on square images (src and dst can be the same)
//-----------------------------------------------------------------------------
bool RotateImageLeft( const unsigned char *src, unsigned char *dst,
int widthHeight, ImageFormat imageFormat );
bool RotateImage180( const unsigned char *src, unsigned char *dst,
int widthHeight, ImageFormat imageFormat );
bool FlipImageVertically( void *pSrc, void *pDst, int nWidth, int nHeight, ImageFormat imageFormat, int nDstStride = 0 );
bool FlipImageHorizontally( void *pSrc, void *pDst, int nWidth, int nHeight, ImageFormat imageFormat, int nDstStride = 0 );
bool SwapAxes( unsigned char *src,
int widthHeight, ImageFormat imageFormat );
//-----------------------------------------------------------------------------
// Returns info about each image format
//-----------------------------------------------------------------------------
const ImageFormatInfo_t &ImageFormatInfo( ImageFormat fmt );
//-----------------------------------------------------------------------------
// Gets the name of the image format
//-----------------------------------------------------------------------------
inline char const* GetName( ImageFormat fmt )
{
return ImageFormatInfo(fmt).m_pName;
}
//-----------------------------------------------------------------------------
// Gets the size of the image format in bytes
//-----------------------------------------------------------------------------
inline int SizeInBytes( ImageFormat fmt )
{
return ImageFormatInfo(fmt).m_nNumBytes;
}
//-----------------------------------------------------------------------------
// Does the image format support transparency?
//-----------------------------------------------------------------------------
inline bool IsTransparent( ImageFormat fmt )
{
return ImageFormatInfo(fmt).m_nNumAlphaBits > 0;
}
//-----------------------------------------------------------------------------
// Is the image format compressed?
//-----------------------------------------------------------------------------
inline bool IsCompressed( ImageFormat fmt )
{
return ImageFormatInfo(fmt).m_bIsCompressed;
}
//-----------------------------------------------------------------------------
// Is the image format compressed?
//-----------------------------------------------------------------------------
inline bool IsDepthFormat( ImageFormat fmt )
{
return ImageFormatInfo(fmt).m_bIsDepthFormat;
}
//-----------------------------------------------------------------------------
// Is any channel > 8 bits?
//-----------------------------------------------------------------------------
inline bool HasChannelLargerThan8Bits( ImageFormat fmt )
{
ImageFormatInfo_t info = ImageFormatInfo(fmt);
return ( info.m_nNumRedBits > 8 || info.m_nNumGreenBits > 8 || info.m_nNumBlueBits > 8 || info.m_nNumAlphaBits > 8 );
}
inline bool IsFloatFormat( ImageFormat fmt )
{
return ( fmt == IMAGE_FORMAT_RGBA16161616F ) ||
( fmt == IMAGE_FORMAT_RG1616F ) ||
( fmt == IMAGE_FORMAT_R32F ) ||
( fmt == IMAGE_FORMAT_RG3232F ) ||
( fmt == IMAGE_FORMAT_RGB323232F ) ||
( fmt == IMAGE_FORMAT_RGBA32323232F );
}
} // end namespace ImageLoader
#endif // IMAGEFORMAT_H

105
public/bitmap/psd.h Normal file
View File

@ -0,0 +1,105 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: Methods relating to saving + loading PSD files (photoshop)
//
// $NoKeywords: $
//===========================================================================//
#ifndef PSD_H
#define PSD_H
#ifdef _WIN32
#pragma once
#endif
#include "bitmap/imageformat.h" //ImageFormat enum definition
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CUtlBuffer;
struct Bitmap_t;
class PSDImageResources
{
public:
enum Resource {
eResFileInfo = 0x0404
};
struct ResElement {
Resource m_eType;
// unsigned char m_pReserved[4];
unsigned short m_numBytes;
unsigned char const *m_pvData;
};
public:
explicit PSDImageResources( unsigned int numBytes, unsigned char const *pvBuffer ) : m_numBytes( numBytes ), m_pvBuffer( pvBuffer ) {}
public:
ResElement FindElement( Resource eType ) const;
protected:
unsigned int m_numBytes;
unsigned char const * m_pvBuffer;
};
class PSDResFileInfo
{
public:
enum ResFileInfo {
eTitle = 0x05,
eAuthor = 0x50,
eAuthorTitle = 0x55,
eDescription = 0x78,
eDescriptionWriter = 0x7A,
eKeywords = 0x19,
eCopyrightNotice = 0x74
};
struct ResFileInfoElement {
ResFileInfo m_eType;
unsigned short m_numBytes;
unsigned char const *m_pvData;
};
public:
explicit PSDResFileInfo( PSDImageResources::ResElement res ) : m_res( res ) {}
public:
ResFileInfoElement FindElement( ResFileInfo eType ) const;
protected:
PSDImageResources::ResElement m_res;
};
//-----------------------------------------------------------------------------
// Is a file a PSD file?
//-----------------------------------------------------------------------------
bool IsPSDFile( const char *pFileName, const char *pPathID );
bool IsPSDFile( CUtlBuffer &buf );
//-----------------------------------------------------------------------------
// Returns information about the PSD file
//-----------------------------------------------------------------------------
bool PSDGetInfo( const char *pFileName, const char *pPathID, int *pWidth, int *pHeight, ImageFormat *pImageFormat, float *pSourceGamma );
bool PSDGetInfo( CUtlBuffer &buf, int *pWidth, int *pHeight, ImageFormat *pImageFormat, float *pSourceGamma );
//-----------------------------------------------------------------------------
// Get PSD file image resources, pointers refer into the utlbuffer
//-----------------------------------------------------------------------------
PSDImageResources PSDGetImageResources( CUtlBuffer &buf );
//-----------------------------------------------------------------------------
// Reads the PSD file into the specified buffer
//-----------------------------------------------------------------------------
bool PSDReadFileRGBA8888( CUtlBuffer &buf, Bitmap_t &bitmap );
bool PSDReadFileRGBA8888( const char *pFileName, const char *pPathID, Bitmap_t &bitmap );
#endif // PSD_H

136
public/bitmap/psheet.h Normal file
View File

@ -0,0 +1,136 @@
//===== Copyright <20> 1996-2006, Valve Corporation, All rights reserved. ======//
//
// Purpose: sheet definitions for particles and other sprite functions
//
//===========================================================================//
#ifndef PSHEET_H
#define PSHEET_H
#ifdef _WIN32
#pragma once
#endif
#include "tier1/utlobjectreference.h"
#include "materialsystem/MaterialSystemUtil.h"
#include "tier1/utlvector.h"
class CUtlBuffer;
// classes for keeping a dictionary of sheet files in memory. A sheet is a bunch of frames packewd
// within one texture. Each sheet has 1 or more frame sequences stored for it.
// for fast lookups to retrieve sequence data, we store the sequence information discretized into
// a fixed # of frames. If this discretenesss is a visual problem, you can lerp the blend values to get it
// perfect.
#define SEQUENCE_SAMPLE_COUNT 1024
#define MAX_IMAGES_PER_FRAME_ON_DISK 4
#define MAX_IMAGES_PER_FRAME_IN_MEMORY 2
struct SequenceSampleTextureCoords_t
{
float m_fLeft_U0;
float m_fTop_V0;
float m_fRight_U0;
float m_fBottom_V0;
float m_fLeft_U1;
float m_fTop_V1;
float m_fRight_U1;
float m_fBottom_V1;
};
struct SheetSequenceSample_t
{
// coordinates of two rectangles (old and next frame coords)
SequenceSampleTextureCoords_t m_TextureCoordData[MAX_IMAGES_PER_FRAME_IN_MEMORY];
float m_fBlendFactor;
void CopyFirstFrameToOthers(void)
{
// for old format files only supporting one image per frame
for(int i=1; i < MAX_IMAGES_PER_FRAME_IN_MEMORY; i++)
{
m_TextureCoordData[i] = m_TextureCoordData[0];
}
}
};
enum SheetSequenceFlags_t
{
SEQ_FLAG_CLAMP = 0x1, // as opposed to loop
SEQ_FLAG_NO_ALPHA = 0x2, // packed as sequence-rgb (alpha channel should be ignored)
SEQ_FLAG_NO_COLOR = 0x4, // packed as sequence-a (color channels should be ignored)
};
class CSheet
{
public:
// read form a .sht file. This is the usual thing to do
CSheet( CUtlBuffer &buf );
CSheet( void );
~CSheet( void );
const SheetSequenceSample_t *GetSampleForSequence( float flAge, float flAgeScale, int nSequence, bool bForceLoop );
// references for smart ptrs
CUtlReferenceList<CSheet> m_References;
struct SheetInfo_t
{
SheetSequenceSample_t *m_pSamples;
uint8 m_SeqFlags;
bool m_bSequenceIsCopyOfAnotherSequence;
int16 m_nNumFrames;
float m_flFrameSpan;
};
CUtlVector< SheetInfo_t > m_SheetInfo;
};
//////////////////////////////////////////////////////////////////////////
class IMesh;
class IMaterial;
// A heavier-weight version of CSheet with more bells and whistles
class CSheetExtended
{
public:
explicit CSheetExtended( IMaterial* pMaterial );
~CSheetExtended();
int GetSheetSequenceCount();
int GetNthSequenceIndex( int nSequenceNumber );
const SheetSequenceSample_t *GetSampleForSequence( float flAge, float flAgeScale, int nSequence, bool bForceLoop );
float GetSequenceTimeSpan( int nSequenceIndex );
void DrawSheet( IMesh *pMesh, const Vector &vCenter, float flRadius, int nSheetSequence, float flAge, float flSheetPreviewSpeed, bool bLoopSheetPreview, int nSecondarySequence=-1, bool bOverrideSpriteCard=false );
bool ValidSheetData();
bool SequenceHasAlphaData( int nSequenceIndex );
bool SequenceHasColorData( int nSequenceIndex );
// Helper
static bool IsMaterialSeparateAlphaColorMaterial( IMaterial* pMat );
static bool IsMaterialDualSequence( IMaterial* pMat );
private:
void LoadFromBuffer( CUtlBuffer& buf );
void LoadFromMaterial( IMaterial* pMaterial );
// TEMP: Store in a CSheet for now - eventually we'll want more data
CSheet* m_pSheetData;
CMaterialReference m_Material;
};
#endif // PSHEET_H

45
public/bitmap/tgaloader.h Normal file
View File

@ -0,0 +1,45 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $Workfile: $
// $Date: $
// $NoKeywords: $
//===========================================================================//
#ifndef TGALOADER_H
#define TGALOADER_H
#ifdef _WIN32
#pragma once
#endif
#include "bitmap/imageformat.h"
#include "tier1/utlmemory.h"
//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CUtlBuffer;
namespace TGALoader
{
int TGAHeaderSize();
bool GetInfo( const char *fileName, int *width, int *height, ImageFormat *imageFormat, float *sourceGamma );
bool GetInfo( CUtlBuffer &buf, int *width, int *height, ImageFormat *imageFormat, float *sourceGamma );
bool Load( unsigned char *imageData, const char *fileName, int width, int height,
ImageFormat imageFormat, float targetGamma, bool mipmap );
bool Load( unsigned char *imageData, CUtlBuffer &buf, int width, int height,
ImageFormat imageFormat, float targetGamma, bool mipmap );
bool LoadRGBA8888( const char *pFileName, CUtlMemory<unsigned char> &outputData, int &outWidth, int &outHeight );
bool LoadRGBA8888( CUtlBuffer &buf, CUtlMemory<unsigned char> &outputData, int &outWidth, int &outHeight );
} // end namespace TGALoader
#endif // TGALOADER_H

35
public/bitmap/tgawriter.h Normal file
View File

@ -0,0 +1,35 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//===========================================================================//
#ifndef TGAWRITER_H
#define TGAWRITER_H
#ifdef _WIN32
#pragma once
#endif
#include "tier1/interface.h"
#include "bitmap/imageformat.h" //ImageFormat enum definition
class CUtlBuffer;
namespace TGAWriter
{
bool WriteToBuffer( unsigned char *pImageData, CUtlBuffer &buffer, int width, int height, ImageFormat srcFormat, ImageFormat dstFormat );
// Write out a simple tga file from a memory buffer.
bool WriteTGAFile( const char *fileName, int width, int height, enum ImageFormat srcFormat, uint8 const *srcData, int nStride );
// Routines for writing to files without allocating any memory in the TGA writer
// Useful for very large files such as posters, which are rendered as sub-rects
bool WriteDummyFileNoAlloc( const char *fileName, int width, int height, ImageFormat dstFormat );
bool WriteRectNoAlloc( unsigned char *pImageData, const char *fileName, int nXOrigin, int nYOrigin, int width, int height, int nStride, ImageFormat srcFormat );
bool WriteRectNoAllocFeather( unsigned char *pImageData, const char *fileName, int nXOrigin, int nYOrigin, int width, int height, int nGuardBandWidth, int nGuardBandHeight, int nStride, enum ImageFormat srcFormat );
} // end namespace TGAWriter
#endif // TGAWRITER_H