coastline 0.0.4
Loading...
Searching...
No Matches
texture.h File Reference

The pixel formats of the textures of Direct3D, the conversion of images into them, and the image files of RGBA 5551. More...

#include <windows.h>
#include <ddraw.h>
#include "common/textureworkspace.h"
Include dependency graph for texture.h:

Go to the source code of this file.

Classes

struct  TexturePixelFormat
 A pixel format of textures the game requests by its identifier. More...

Macros

#define TEXTURE_PIXEL_FORMAT_COUNT   5
 The number of entries of g_aTexturePixelFormats.

Functions

DDPIXELFORMAT * LookupPixelFormatById (int nId)
 Find a pixel format of textures by its identifier.
int CountBitWidth (unsigned nMask)
 Count the bits up to and including the highest set bit of a mask.
int CountTrailingZeroBits32 (unsigned nMask)
 Count the clear bits below the lowest set bit of a mask.
int PopCount32 (unsigned nMask)
 Count the set bits of a mask.
HRESULT CALLBACK EnumTextureFormatsCallback_MatchPreset (DDSURFACEDESC *pDesc, void *pContext)
 Store a texture format of the device in an entry of g_aTexturePixelFormats when it suits the entry better than the format the entry has.
void UnpackRgba5551ToRgba8 (unsigned char *pDest, const unsigned short *pSrc, int nCount)
 Unpack pixels of RGBA 5551 to RGBA 8888.
unsigned ConvertN64Rgba5551ToRgba8 (unsigned nColor)
 Convert a host-loaded N64 RGBA 5551 word to four RGBA bytes.
int ConvertRGBAToPixelFormat (void *pDest, const void *pSrc, int nSize, int nPixelFormatId)
 Convert pixels of RGBA 8888 to a pixel format of the device.
int ConvertRGBAToPixelFormatWithColorKey (void *pDest, const void *pSrc, int nSize, int nPixelFormatId, unsigned *pColorKey)
 Convert RGBA pixels, replacing alpha below 128 with the lowest green bit of the device format.
void * LoadRgba5551ImageFile (const char *pszPath, unsigned nAdlerExpected, int *pnWidth, int *pnHeight)
 Load an image file of RGBA 5551 pixels and convert it to pixel format 0xb.

Detailed Description

The pixel formats of the textures of Direct3D, the conversion of images into them, and the image files of RGBA 5551.

Macro Definition Documentation

◆ TEXTURE_PIXEL_FORMAT_COUNT

#define TEXTURE_PIXEL_FORMAT_COUNT   5

The number of entries of g_aTexturePixelFormats.

Function Documentation

◆ LookupPixelFormatById()

DDPIXELFORMAT * LookupPixelFormatById ( int nId)

Find a pixel format of textures by its identifier.

Parameters
nIdThe identifier.
Returns
The format of the device, or null for an identifier that is not known.
Ghidra address:
BRD3D: 0x10009830

◆ CountBitWidth()

int CountBitWidth ( unsigned nMask)

Count the bits up to and including the highest set bit of a mask.

Parameters
nMaskThe mask.
Returns
The index of the highest set bit plus one, or 0 for an empty mask.
Ghidra address:
BRD3D: 0x10009880

◆ CountTrailingZeroBits32()

int CountTrailingZeroBits32 ( unsigned nMask)

Count the clear bits below the lowest set bit of a mask.

An empty mask does not return.

Parameters
nMaskThe mask.
Returns
The index of the lowest set bit.
Ghidra address:
BRD3D: 0x10009860

◆ PopCount32()

int PopCount32 ( unsigned nMask)

Count the set bits of a mask.

Parameters
nMaskThe mask.
Returns
The number of set bits.
Ghidra address:
BRD3D: 0x10009640

◆ EnumTextureFormatsCallback_MatchPreset()

HRESULT CALLBACK EnumTextureFormatsCallback_MatchPreset ( DDSURFACEDESC * pDesc,
void * pContext )

Store a texture format of the device in an entry of g_aTexturePixelFormats when it suits the entry better than the format the entry has.

A format with more bits a pixel than wMaxBitCount of the entry is skipped, and an empty entry takes the first format of its rule. The rule depends on the identifier of the entry. 2 wants the most alpha bits up to 8, 3 wants RGB with three channels of one width up to 8, 4 and 0xc want RGB with the most alpha bits, and 0xb wants RGB with the fewest alpha bits above none.

Parameters
pDescThe surface description of the format.
pContextThe entry of g_aTexturePixelFormats.
Returns
Always D3DENUMRET_OK, to continue the enumeration.
Ghidra address:
BRD3D: 0x10009360

◆ UnpackRgba5551ToRgba8()

void UnpackRgba5551ToRgba8 ( unsigned char * pDest,
const unsigned short * pSrc,
int nCount )

Unpack pixels of RGBA 5551 to RGBA 8888.

The low bits of each channel repeat bits of the channel, and an alpha bit becomes 0 or 0xff.

Parameters
pDestReceives four bytes for each pixel.
pSrcThe pixels to unpack.
nCountThe number of pixels.
Ghidra address:
BRD3D: 0x10009a50

◆ ConvertN64Rgba5551ToRgba8()

unsigned ConvertN64Rgba5551ToRgba8 ( unsigned nColor)

Convert a host-loaded N64 RGBA 5551 word to four RGBA bytes.

Parameters
nColorThe word loaded from the big-endian image bytes.
Returns
RGBA channels from the least to the most significant byte.
Ghidra address:
BRD3D: 0x10027b10

◆ ConvertRGBAToPixelFormat()

int ConvertRGBAToPixelFormat ( void * pDest,
const void * pSrc,
int nSize,
int nPixelFormatId )

Convert pixels of RGBA 8888 to a pixel format of the device.

Parameters
pDestReceives the pixels.
pSrcThe pixels to convert.
nSizeThe size of the source in bytes.
nPixelFormatIdThe pixel format.
Returns
The number of bytes written. A format of three bytes for each pixel writes none.
Ghidra address:
BRD3D: 0x100098a0

◆ ConvertRGBAToPixelFormatWithColorKey()

int ConvertRGBAToPixelFormatWithColorKey ( void * pDest,
const void * pSrc,
int nSize,
int nPixelFormatId,
unsigned * pColorKey )

Convert RGBA pixels, replacing alpha below 128 with the lowest green bit of the device format.

Parameters
pDestReceives the pixels.
pSrcThe source pixels.
nSizeThe source byte count.
nPixelFormatIdThe device format identifier.
pColorKeyReceives the transparent pixel value, even when the source byte count is zero.
Returns
The output byte count.
Ghidra address:
BRD3D: 0x10009660

◆ LoadRgba5551ImageFile()

void * LoadRgba5551ImageFile ( const char * pszPath,
unsigned nAdlerExpected,
int * pnWidth,
int * pnHeight )

Load an image file of RGBA 5551 pixels and convert it to pixel format 0xb.

The file has the width, the height, a word that is not read, and the pixels. A checksum that does not match ends the process.

Parameters
pszPathThe path of the image.
nAdlerExpectedThe Adler-32 checksum of the pixels, or 0 to skip the check.
pnWidthReceives the width of the image.
pnHeightReceives the height of the image.
Returns
The converted pixels in the shared decoding workspace.
Ghidra address:
BRD3D: 0x10009ad0