Skip to content

Commit

Permalink
[librptexture] DirectDrawSurface: Re-arrange some variables to reduce…
Browse files Browse the repository at this point in the history
… padding.

On 64-bit, DirectDrawSurfacePrivate goes down from 352 bytes to 344 bytes.

Also, un-indent DirectDrawSurfacePrivate.
  • Loading branch information
GerbilSoft committed Jan 28, 2025
1 parent 9d19c28 commit 654cb48
Showing 1 changed file with 101 additions and 101 deletions.
202 changes: 101 additions & 101 deletions src/librptexture/fileformat/DirectDrawSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,107 +39,107 @@ namespace LibRpTexture {

class DirectDrawSurfacePrivate final : public FileFormatPrivate
{
public:
DirectDrawSurfacePrivate(DirectDrawSurface *q, const IRpFilePtr &file);

private:
typedef FileFormatPrivate super;
RP_DISABLE_COPY(DirectDrawSurfacePrivate)

public:
/** TextureInfo **/
static const array<const char*, 1+1> exts;
static const array<const char*, 2+1> mimeTypes;
static const TextureInfo textureInfo;

public:
// DDS header
DDS_HEADER ddsHeader;
DDS_HEADER_DXT10 dxt10Header;
DDS_HEADER_XBOX xb1Header;

// Texture data start address
unsigned int texDataStartAddr;

// Decoded mipmaps
// Mipmap 0 is the full image.
vector<rp_image_ptr> mipmaps;

// Pixel format message
// NOTE: Used for both valid and invalid pixel formats
// due to various bit specifications.
mutable string pixel_format;

/**
* Calculate the expected image size.
*
* Width/height must be specified here for mipmap support.
* Other values are determined from the DDS header.
*
* @param width [in]
* @param height [in]
* @param mip [in] Mipmap level (for stride calculation)
* @param pStride [out] Stride (for uncompressed formats)
* @return Expected image size, or 0 on error
*/
unsigned int calcExpectedSize(int width, int height, int mip, unsigned int *pStride);

/**
* Load the image.
* @param mip Mipmap number. (0 == full image)
* @return Image, or nullptr on error.
*/
rp_image_const_ptr loadImage(int mip);

public:
// Supported uncompressed RGB formats.
struct RGB_Format_Table_t {
uint32_t Rmask;
uint32_t Gmask;
uint32_t Bmask;
uint32_t Amask;
char desc[15];
ImageDecoder::PixelFormat px_format; // ImageDecoder::PixelFormat
};
ASSERT_STRUCT(RGB_Format_Table_t, sizeof(uint32_t)*4 + 15 + 1);

static const array<RGB_Format_Table_t, 1> rgb_fmt_tbl_8; // 8-bit RGB
static const array<RGB_Format_Table_t, 17> rgb_fmt_tbl_16; // 16-bit RGB
static const array<RGB_Format_Table_t, 2> rgb_fmt_tbl_24; // 24-bit RGB
static const array<RGB_Format_Table_t, 11> rgb_fmt_tbl_32; // 32-bit RGB
static const array<RGB_Format_Table_t, 9> rgb_fmt_tbl_luma; // Luminance
static const array<RGB_Format_Table_t, 1> rgb_fmt_tbl_alpha; // Alpha

/**
* Get an RGB_Format_Table_t entry from an RGB format table.
* @param ddspf DirectDraw Surface pixel format
* @return Pointer to RGB_Format_Table_t, or nullptr if not found.
*/
static const RGB_Format_Table_t *getRGBFormatTableEntry(const DDS_PIXELFORMAT &ddspf);

// Image format identifiers.
ImageDecoder::PixelFormat pxf_uncomp; // Pixel format for uncompressed images. (If 0, compressed.)
uint8_t bytespp; // Bytes per pixel. (Uncompressed only; set to 0 for compressed.)
uint8_t dxgi_format; // DXGI_FORMAT for compressed images. (If 0, uncompressed.)
uint8_t dxgi_alpha; // DDS_DXT10_MISC_FLAGS2 - alpha format.

/**
* Get the format name of an uncompressed DirectDraw surface pixel format.
* @param ddspf DDS_PIXELFORMAT
* @return Format name, or nullptr if not supported.
*/
static inline const char *getPixelFormatName(const DDS_PIXELFORMAT &ddspf);

/**
* Get the pixel formats of the DDS texture.
* DDS texture headers must have been loaded.
*
* If uncompressed, this sets pxf_uncomp and bytespp.
* If compressed, this sets dxgi_format.
*
* @return 0 on success; negative POSIX error code on error.
*/
int updatePixelFormat(void);
public:
DirectDrawSurfacePrivate(DirectDrawSurface *q, const IRpFilePtr &file);

private:
typedef FileFormatPrivate super;
RP_DISABLE_COPY(DirectDrawSurfacePrivate)

public:
/** TextureInfo **/
static const array<const char*, 1+1> exts;
static const array<const char*, 2+1> mimeTypes;
static const TextureInfo textureInfo;

public:
// DDS header
DDS_HEADER ddsHeader;
DDS_HEADER_DXT10 dxt10Header;
DDS_HEADER_XBOX xb1Header;

// Texture data start address
unsigned int texDataStartAddr;

// Image format identifiers
ImageDecoder::PixelFormat pxf_uncomp; // Pixel format for uncompressed images. (If 0, compressed.)
uint8_t bytespp; // Bytes per pixel. (Uncompressed only; set to 0 for compressed.)
uint8_t dxgi_format; // DXGI_FORMAT for compressed images. (If 0, uncompressed.)
uint8_t dxgi_alpha; // DDS_DXT10_MISC_FLAGS2 - alpha format.

// Decoded mipmaps
// Mipmap 0 is the full image.
vector<rp_image_ptr> mipmaps;

// Pixel format message
// NOTE: Used for both valid and invalid pixel formats
// due to various bit specifications.
mutable string pixel_format;

/**
* Calculate the expected image size.
*
* Width/height must be specified here for mipmap support.
* Other values are determined from the DDS header.
*
* @param width [in]
* @param height [in]
* @param mip [in] Mipmap level (for stride calculation)
* @param pStride [out] Stride (for uncompressed formats)
* @return Expected image size, or 0 on error
*/
unsigned int calcExpectedSize(int width, int height, int mip, unsigned int *pStride);

/**
* Load the image.
* @param mip Mipmap number. (0 == full image)
* @return Image, or nullptr on error.
*/
rp_image_const_ptr loadImage(int mip);

public:
// Supported uncompressed RGB formats.
struct RGB_Format_Table_t {
uint32_t Rmask;
uint32_t Gmask;
uint32_t Bmask;
uint32_t Amask;
char desc[15];
ImageDecoder::PixelFormat px_format; // ImageDecoder::PixelFormat
};
ASSERT_STRUCT(RGB_Format_Table_t, sizeof(uint32_t)*4 + 15 + 1);

static const array<RGB_Format_Table_t, 1> rgb_fmt_tbl_8; // 8-bit RGB
static const array<RGB_Format_Table_t, 17> rgb_fmt_tbl_16; // 16-bit RGB
static const array<RGB_Format_Table_t, 2> rgb_fmt_tbl_24; // 24-bit RGB
static const array<RGB_Format_Table_t, 11> rgb_fmt_tbl_32; // 32-bit RGB
static const array<RGB_Format_Table_t, 9> rgb_fmt_tbl_luma; // Luminance
static const array<RGB_Format_Table_t, 1> rgb_fmt_tbl_alpha; // Alpha

/**
* Get an RGB_Format_Table_t entry from an RGB format table.
* @param ddspf DirectDraw Surface pixel format
* @return Pointer to RGB_Format_Table_t, or nullptr if not found.
*/
static const RGB_Format_Table_t *getRGBFormatTableEntry(const DDS_PIXELFORMAT &ddspf);

/**
* Get the format name of an uncompressed DirectDraw surface pixel format.
* @param ddspf DDS_PIXELFORMAT
* @return Format name, or nullptr if not supported.
*/
static inline const char *getPixelFormatName(const DDS_PIXELFORMAT &ddspf);

/**
* Get the pixel formats of the DDS texture.
* DDS texture headers must have been loaded.
*
* If uncompressed, this sets pxf_uncomp and bytespp.
* If compressed, this sets dxgi_format.
*
* @return 0 on success; negative POSIX error code on error.
*/
int updatePixelFormat(void);
};

FILEFORMAT_IMPL(DirectDrawSurface)
Expand Down

0 comments on commit 654cb48

Please sign in to comment.