Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/lib/tex/tex_dds.cpp
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* | * | ||||
* Permission is hereby granted, free of charge, to any person obtaining | * Permission is hereby granted, free of charge, to any person obtaining | ||||
* a copy of this software and associated documentation files (the | * a copy of this software and associated documentation files (the | ||||
* "Software"), to deal in the Software without restriction, including | * "Software"), to deal in the Software without restriction, including | ||||
* without limitation the rights to use, copy, modify, merge, publish, | * without limitation the rights to use, copy, modify, merge, publish, | ||||
* distribute, sublicense, and/or sell copies of the Software, and to | * distribute, sublicense, and/or sell copies of the Software, and to | ||||
* permit persons to whom the Software is furnished to do so, subject to | * permit persons to whom the Software is furnished to do so, subject to | ||||
* the following conditions: | * the following conditions: | ||||
▲ Show 20 Lines • Show All 289 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
// DDS file format | // DDS file format | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
// bit values and structure definitions taken from | // bit values and structure definitions taken from | ||||
// http://msdn.microsoft.com/en-us/library/ee417785(VS.85).aspx | // https://docs.microsoft.com/en-us/windows/win32/direct3ddds/dx-graphics-dds-reference | ||||
#pragma pack(push, 1) | #pragma pack(push, 1) | ||||
// DDS_PIXELFORMAT.dwFlags | // DDS_PIXELFORMAT.dwFlags | ||||
// This is used to distinguish RGBA from RGB and DXT1a from DXT1. | |||||
// we've seen some DXT3 files that don't have this set (which is nonsense; | // we've seen some DXT3 files that don't have this set (which is nonsense; | ||||
// any image lacking alpha should be stored as DXT1). | // any image lacking alpha should be stored as DXT1). | ||||
#define DDPF_ALPHAPIXELS 0x00000001 | #define DDPF_ALPHAPIXELS 0x00000001 | ||||
// DDPF_ALPHA is used instead of DDPF_ALPHAPIXELS for DXT1a. | // DDPF_ALPHA is used for uncompressed 8bpp greyscale, in which the data | ||||
// is stored in the alpha mask. | |||||
#define DDPF_ALPHA 0x00000002 | #define DDPF_ALPHA 0x00000002 | ||||
#define DDPF_FOURCC 0x00000004 | #define DDPF_FOURCC 0x00000004 | ||||
#define DDPF_RGB 0x00000040 | #define DDPF_RGB 0x00000040 | ||||
struct DDS_PIXELFORMAT | struct DDS_PIXELFORMAT | ||||
{ | { | ||||
u32 dwSize; // size of structure (32) | u32 dwSize; // size of structure (32) | ||||
u32 dwFlags; // indicates which fields are valid | u32 dwFlags; // indicates which fields are valid | ||||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | static Status decode_pf(const DDS_PIXELFORMAT* pf, size_t& bpp, size_t& flags) | ||||
else if(pf_flags & DDPF_FOURCC) | else if(pf_flags & DDPF_FOURCC) | ||||
{ | { | ||||
// set effective bpp and store DXT format in flags & TEX_DXT. | // set effective bpp and store DXT format in flags & TEX_DXT. | ||||
// no endian conversion necessary - FOURCC() takes care of that. | // no endian conversion necessary - FOURCC() takes care of that. | ||||
switch(pf->dwFourCC) | switch(pf->dwFourCC) | ||||
{ | { | ||||
case FOURCC('D','X','T','1'): | case FOURCC('D','X','T','1'): | ||||
bpp = 4; | bpp = 4; | ||||
if(pf_flags & DDPF_ALPHA) | if(pf_flags & DDPF_ALPHAPIXELS) | ||||
flags |= DXT1A | TEX_ALPHA; | flags |= DXT1A | TEX_ALPHA; | ||||
else | else | ||||
flags |= 1; | flags |= 1; | ||||
break; | break; | ||||
case FOURCC('D','X','T','3'): | case FOURCC('D','X','T','3'): | ||||
bpp = 8; | bpp = 8; | ||||
flags |= 3; | flags |= 3; | ||||
flags |= TEX_ALPHA; // see DDPF_ALPHAPIXELS decl | flags |= TEX_ALPHA; // see DDPF_ALPHAPIXELS decl | ||||
▲ Show 20 Lines • Show All 182 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator