Skip to content

Commit

Permalink
Modernise and C++-ify definitions in ddslib.{h,cpp}
Browse files Browse the repository at this point in the history
Remove "extern C" wrapper, convert "typedef struct" to "struct", switch to
uint32_t instead of unsigned int for certain fields which require a
precisely-defined size.
  • Loading branch information
Matthew Mott committed Jul 7, 2020
1 parent 49f11ac commit 83645a8
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 190 deletions.
11 changes: 3 additions & 8 deletions radiant/image/ddslib.cpp
Expand Up @@ -35,15 +35,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------------- */



/* marker */
#define DDSLIB_C


#include "ddslib.h"

/* dependencies */
#include "ddslib.h"
#include <stdio.h>
#include <memory.h>

#if !defined(_MSC_VER)
#include <stdint.h> // greebo: This isn't needed in VC++ 2005
Expand Down Expand Up @@ -879,4 +875,3 @@ int DDSDecompress( const DDSHeader* header, const unsigned char* buffer, unsigne
/* return to sender */
return r;
}

320 changes: 138 additions & 182 deletions radiant/image/ddslib.h
Expand Up @@ -35,48 +35,29 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------------- */

#pragma once


/* marker */
#ifndef DDSLIB_H
#define DDSLIB_H



/* dependencies */
#include <stdio.h>
#include <memory.h>



/* c++ marker */
#ifdef __cplusplus
extern "C"
{
#endif


#include <cstdint>

/* dds definition */
typedef enum
enum ddsPF_t
{
DDS_PF_ARGB8888,
DDS_PF_DXT1,
DDS_PF_DXT2,
DDS_PF_DXT3,
DDS_PF_DXT4,
DDS_PF_DXT5,
DDS_PF_DXT5_RXGB, /* Doom 3's swizzled format */
DDS_PF_UNKNOWN
}
ddsPF_t;
DDS_PF_ARGB8888,
DDS_PF_DXT1,
DDS_PF_DXT2,
DDS_PF_DXT3,
DDS_PF_DXT4,
DDS_PF_DXT5,
DDS_PF_DXT5_RXGB, /* Doom 3's swizzled format */
DDS_PF_UNKNOWN
};

// greebo: General parameters which depend on the DDS format
/*struct DDSLoadInfo
{
unsigned int divSize = 4;
unsigned int blockBytes;
GLenum internalFormat;
unsigned int divSize = 4;
unsigned int blockBytes;
GLenum internalFormat;
};
DDSLoadInfo loadInfoDXT1 = {
Expand All @@ -90,89 +71,82 @@ DdsLoadInfo loadInfoDXT5 = {
};*/

/* 16bpp stuff */
#define DDS_LOW_5 0x001F;
#define DDS_MID_6 0x07E0;
#define DDS_HIGH_5 0xF800;
#define DDS_MID_555 0x03E0;
#define DDS_HI_555 0x7C00;
#define DDS_LOW_5 0x001F;
#define DDS_MID_6 0x07E0;
#define DDS_HIGH_5 0xF800;
#define DDS_MID_555 0x03E0;
#define DDS_HI_555 0x7C00;


/* structures */
typedef struct ddsColorKey_s
struct ddsColorKey_t
{
unsigned int colorSpaceLowValue;
unsigned int colorSpaceHighValue;
}
ddsColorKey_t;

unsigned int colorSpaceLowValue;
unsigned int colorSpaceHighValue;
};

typedef struct ddsCaps_s
struct ddsCaps_t
{
unsigned int caps1;
unsigned int caps2;
unsigned int caps3;
unsigned int caps4;
}
ddsCaps_t;

unsigned int caps1;
unsigned int caps2;
unsigned int caps3;
unsigned int caps4;
};

typedef struct ddsMultiSampleCaps_s
struct ddsMultiSampleCaps_t
{
unsigned short flipMSTypes;
unsigned short bltMSTypes;
}
ddsMultiSampleCaps_t;

unsigned short flipMSTypes;
unsigned short bltMSTypes;
};

typedef struct ddsPixelFormat_s
struct ddsPixelFormat_t
{
unsigned int size;
unsigned int flags;
unsigned char fourCC[4];
union
{
unsigned int rgbBitCount;
unsigned int yuvBitCount;
unsigned int zBufferBitDepth;
unsigned int alphaBitDepth;
unsigned int luminanceBitCount;
unsigned int bumpBitCount;
unsigned int privateFormatBitCount;
};
union
{
unsigned int rBitMask;
unsigned int yBitMask;
unsigned int stencilBitDepth;
unsigned int luminanceBitMask;
unsigned int bumpDuBitMask;
unsigned int operations;
};
union
{
unsigned int gBitMask;
unsigned int uBitMask;
unsigned int zBitMask;
unsigned int bumpDvBitMask;
ddsMultiSampleCaps_t multiSampleCaps;
};
union
{
unsigned int bBitMask;
unsigned int vBitMask;
unsigned int stencilBitMask;
unsigned int bumpLuminanceBitMask;
};
union
{
unsigned int rgbAlphaBitMask;
unsigned int yuvAlphaBitMask;
unsigned int luminanceAlphaBitMask;
unsigned int rgbZBitMask;
unsigned int yuvZBitMask;
};
}
ddsPixelFormat_t;
unsigned int size;
unsigned int flags;
unsigned char fourCC[4];
union
{
unsigned int rgbBitCount;
unsigned int yuvBitCount;
unsigned int zBufferBitDepth;
unsigned int alphaBitDepth;
unsigned int luminanceBitCount;
unsigned int bumpBitCount;
unsigned int privateFormatBitCount;
};
union
{
unsigned int rBitMask;
unsigned int yBitMask;
unsigned int stencilBitDepth;
unsigned int luminanceBitMask;
unsigned int bumpDuBitMask;
unsigned int operations;
};
union
{
unsigned int gBitMask;
unsigned int uBitMask;
unsigned int zBitMask;
unsigned int bumpDvBitMask;
ddsMultiSampleCaps_t multiSampleCaps;
};
union
{
unsigned int bBitMask;
unsigned int vBitMask;
unsigned int stencilBitMask;
unsigned int bumpLuminanceBitMask;
};
union
{
unsigned int rgbAlphaBitMask;
unsigned int yuvAlphaBitMask;
unsigned int luminanceAlphaBitMask;
unsigned int rgbZBitMask;
unsigned int yuvZBitMask;
};
};

// DDS header flags
#define DDSD_CAPS 0x00000001
Expand All @@ -186,94 +160,76 @@ ddsPixelFormat_t;

struct DDSHeader
{
/* magic: 'dds ' */
char magic[ 4 ];

/* directdraw surface */
unsigned int size;
unsigned int flags;
unsigned int height;
unsigned int width;
union
{
int pitch;
unsigned int linearSize;
};
unsigned int backBufferCount;
union
{
unsigned int mipMapCount;
unsigned int refreshRate;
unsigned int srcVBHandle;
};
unsigned int alphaBitDepth;
unsigned int reserved;
unsigned int surface; // greebo: Changed this to unsigned int for 64-bit compatibility (should be 32 bits wide)
union
{
ddsColorKey_t ckDestOverlay;
unsigned int emptyFaceColor;
};
ddsColorKey_t ckDestBlt;
ddsColorKey_t ckSrcOverlay;
ddsColorKey_t ckSrcBlt;
ddsPixelFormat_t pixelFormat;
ddsCaps_t ddsCaps;
unsigned int textureStage;
/* magic: 'dds ' */
char magic[ 4 ];

/* directdraw surface */
uint32_t size;
uint32_t flags;
uint32_t height;
uint32_t width;
union
{
int32_t pitch;
uint32_t linearSize;
};
uint32_t backBufferCount;
union
{
uint32_t mipMapCount;
uint32_t refreshRate;
uint32_t srcVBHandle;
};
uint32_t alphaBitDepth;
uint32_t reserved;
uint32_t surface;
union
{
ddsColorKey_t ckDestOverlay;
uint32_t emptyFaceColor;
};
ddsColorKey_t ckDestBlt;
ddsColorKey_t ckSrcOverlay;
ddsColorKey_t ckSrcBlt;
ddsPixelFormat_t pixelFormat;
ddsCaps_t ddsCaps;
uint32_t textureStage;
};

typedef struct ddsBuffer_s
struct ddsBuffer_t
{
DDSHeader header;
DDSHeader header;

/* data (Varying size) */
unsigned char data[ 4 ];
}
ddsBuffer_t;
/* data (Varying size) */
unsigned char data[ 4 ];
};

/** greebo: This represents a 64 bit DDS block containing
* either the alpha or the colour data.
* either the alpha or the colour data.
*/
typedef struct ddsColorBlock_s
struct ddsColorBlock_t
{
unsigned short colors[ 2 ];// 32 bit (2 x 16 bit)
unsigned char row[ 4 ]; // 32 bit (4 x 8 bit)
}
ddsColorBlock_t;
unsigned short colors[ 2 ];// 32 bit (2 x 16 bit)
unsigned char row[ 4 ]; // 32 bit (4 x 8 bit)
};

typedef struct ddsAlphaBlockExplicit_s
struct ddsAlphaBlockExplicit_t
{
unsigned short row[ 4 ];
}
ddsAlphaBlockExplicit_t;

unsigned short row[ 4 ];
};

typedef struct ddsAlphaBlock3BitLinear_s
struct ddsAlphaBlock3BitLinear_t
{
unsigned char alpha0;
unsigned char alpha1;
unsigned char stuff[ 6 ];
}
ddsAlphaBlock3BitLinear_t;

unsigned char alpha0;
unsigned char alpha1;
unsigned char stuff[ 6 ];
};

typedef struct ddsColor_s
struct ddsColor_t
{
unsigned char r, g, b, a;
}
ddsColor_t;


unsigned char r, g, b, a;
};

/* public functions */
int DDSGetInfo( const DDSHeader* header, int *width, int *height, ddsPF_t *pf );
int DDSDecompress( const DDSHeader* header, const unsigned char* buffer, unsigned char *pixels );



/* end marker */
#ifdef __cplusplus
}
#endif

#endif
int DDSGetInfo( const DDSHeader* header, int *width, int *height, ddsPF_t *pf );
int DDSDecompress( const DDSHeader* header, const unsigned char* buffer, unsigned char *pixels );

0 comments on commit 83645a8

Please sign in to comment.