Skip to content

Commit 88fa8a4

Browse files
committed
Add BC7_SRGB format support
Tracked alongside regular BC7 for the most part, with simple conversion from/to external BC7 UNORM/SRGB format enums. No actual SRGB↔linear colorspace conversion is introduced. Fixes #277
1 parent 32269b4 commit 88fa8a4

File tree

15 files changed

+45
-7
lines changed

15 files changed

+45
-7
lines changed

applications/_plugins/cimage/dds/dds_dx10.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,14 @@ TC_PluginError LoadDDS_DX10(FILE* pFile, DDSD2* pDDSD, MipSet* pMipSet) {
234234

235235
case DXGI_FORMAT_BC7_TYPELESS:
236236
case DXGI_FORMAT_BC7_UNORM:
237-
case DXGI_FORMAT_BC7_UNORM_SRGB:
238237
pMipSet->m_compressed = true;
239238
pMipSet->m_format = CMP_FORMAT_BC7;
240239
err = LoadDDS_DX10_FourCC(pFile, pDDSD, pMipSet, CMP_FOURCC_DX10);
240+
241+
case DXGI_FORMAT_BC7_UNORM_SRGB:
242+
pMipSet->m_compressed = true;
243+
pMipSet->m_format = CMP_FORMAT_BC7_SRGB;
244+
err = LoadDDS_DX10_FourCC(pFile, pDDSD, pMipSet, CMP_FOURCC_DX10);
241245
break;
242246

243247
// case DXGI_FORMAT_???:
@@ -371,6 +375,8 @@ DXGI_FORMAT GetDXGIFormat(const MipSet* pMipSet) {
371375
return DXGI_FORMAT_BC5_UNORM;
372376
case CMP_FORMAT_BC7:
373377
return DXGI_FORMAT_BC7_UNORM;
378+
case CMP_FORMAT_BC7_SRGB:
379+
return DXGI_FORMAT_BC7_UNORM_SRGB;
374380
// case CMP_FORMAT_ASTC: return DXGI_FORMAT_????; Not yet supported as of Jun 24 2015
375381
}
376382
} else
@@ -444,6 +450,7 @@ TC_PluginError SaveDDS_DX10(FILE* pFile, const MipSet* pMipSet) {
444450
ddsd2.lPitch = ddsd2.dwWidth * 4;
445451
break;
446452
case CMP_FORMAT_BC7:
453+
case CMP_FORMAT_BC7_SRGB:
447454
default:
448455
ddsd2.lPitch = ddsd2.dwWidth * 4;
449456
break;

applications/_plugins/cimage/ktx/ktx1.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,7 @@ int Plugin_KTX::TC_PluginFileSaveTexture(const char* pszFilename, MipSet* pMipSe
10681068
case CMP_FORMAT_BC6H:
10691069
case CMP_FORMAT_BC6H_SF:
10701070
case CMP_FORMAT_BC7 :
1071+
case CMP_FORMAT_BC7_SRGB :
10711072
case CMP_FORMAT_DXT1 :
10721073
case CMP_FORMAT_DXT3 :
10731074
case CMP_FORMAT_DXT5 :

applications/_plugins/cimage/ktx2/ktx2.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ int Plugin_KTX2::TC_PluginFileLoadTexture(const char* pszFilename, MipSet* pMipS
218218
case VK_FORMAT_BC7_UNORM_BLOCK:
219219
pMipSet->m_format = CMP_FORMAT_BC7;
220220
break;
221+
case VK_FORMAT_BC7_SRGB_BLOCK:
222+
pMipSet->m_format = CMP_FORMAT_BC7_SRGB;
223+
break;
221224
case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
222225
pMipSet->m_format = CMP_FORMAT_ETC2_RGB; // Skip ETC as ETC2 is backward comp
223226
break;
@@ -857,6 +860,10 @@ int Plugin_KTX2::TC_PluginFileSaveTexture(const char* pszFilename, MipSet* pMipS
857860
// RGB_BP_UNorm;
858861
textureCreateInfo.vkFormat = VK_FORMAT_BC7_UNORM_BLOCK;
859862
break;
863+
case CMP_FORMAT_BC7_SRGB:
864+
// RGB_BP_UNorm;
865+
textureCreateInfo.vkFormat = VK_FORMAT_BC7_SRGB_BLOCK;
866+
break;
860867
//case CMP_FORMAT_ATI1N:
861868
// // COMPRESSED_FORMAT_ATI1N_UNorm_TMP;
862869
// textureCreateInfo.vkFormat = VK_FORMAT_BC4_UNORM_BLOCK;

applications/_plugins/common/atiformats.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ CMP_FormatDesc g_FormatDesc[] = {
103103
{CMP_FORMAT_BC6H, "BC6H"},
104104
{CMP_FORMAT_BC6H_SF, "BC6H_SF" },
105105
{CMP_FORMAT_BC7, "BC7"},
106+
{CMP_FORMAT_BC7_SRGB, "BC7_SRGB"},
106107

107108

108109
{CMP_FORMAT_DXT1, "DXT1"},
@@ -323,6 +324,9 @@ void CMP_API CMP_Format2FourCC(CMP_FORMAT format, MipSet *pMipSet) {
323324
case CMP_FORMAT_BC7:
324325
pMipSet->m_dwFourCC = CMP_FOURCC_DX10;
325326
break;
327+
case CMP_FORMAT_BC7_SRGB:
328+
pMipSet->m_dwFourCC = CMP_FOURCC_DX10;
329+
break;
326330
#if (OPTION_BUILD_ASTC == 1)
327331
case CMP_FORMAT_ASTC:
328332
pMipSet->m_dwFourCC = CMP_FOURCC_DX10;
@@ -470,6 +474,7 @@ CMP_BOOL CMP_API CMP_IsCompressedFormat(CMP_FORMAT format) {
470474
case CMP_FORMAT_BC6H:
471475
case CMP_FORMAT_BC6H_SF:
472476
case CMP_FORMAT_BC7:
477+
case CMP_FORMAT_BC7_SRGB:
473478
case CMP_FORMAT_DXT1:
474479
case CMP_FORMAT_DXT3:
475480
case CMP_FORMAT_DXT5:
@@ -609,6 +614,7 @@ CMP_BOOL CMP_API CMP_IsValidFormat(CMP_FORMAT InFormat)
609614
case CMP_FORMAT_BC6H :
610615
case CMP_FORMAT_BC6H_SF :
611616
case CMP_FORMAT_BC7 :
617+
case CMP_FORMAT_BC7_SRGB :
612618
case CMP_FORMAT_ATI1N :
613619
case CMP_FORMAT_ATI2N :
614620
case CMP_FORMAT_ATI2N_XY :
@@ -765,6 +771,7 @@ static CMP_FORMAT GetFormat(CMP_DWORD dwFourCC) {
765771
case CMP_FOURCC_BC5S: return CMP_FORMAT_BC5_S;
766772
case CMP_FOURCC_BC6H: return CMP_FORMAT_BC6H;
767773
case CMP_FOURCC_BC7: return CMP_FORMAT_BC7;
774+
case CMP_FOURCC_BC7_SRGB: return CMP_FORMAT_BC7_SRGB;
768775
#if (OPTION_BUILD_ASTC == 1)
769776
case CMP_FOURCC_ASTC: return CMP_FORMAT_ASTC;
770777
#endif

applications/_plugins/common/cmdline.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,6 +2076,7 @@ bool SVMInitCodec(KernelOptions* options)
20762076
case CMP_FORMAT_BC1:
20772077
case CMP_FORMAT_DXT1:
20782078
case CMP_FORMAT_BC7:
2079+
case CMP_FORMAT_BC7_SRGB:
20792080
#if (OPTION_BUILD_ASTC == 1)
20802081
case CMP_FORMAT_ASTC:
20812082
#endif
@@ -3089,7 +3090,7 @@ int ProcessCMDLine(CMP_Feedback_Proc pFeedbackProc, MipSet* p_userMipSetIn)
30893090
if ((g_CmdPrams.CompressOptions.fquality > 0.00f) && (g_CmdPrams.CompressOptions.fquality < 0.01f))
30903091
{
30913092
// set default max quality for fast processing codecs
3092-
if ((destFormat != CMP_FORMAT_BC7) && (destFormat != CMP_FORMAT_BC6H) && (destFormat != CMP_FORMAT_BC6H_SF))
3093+
if ((destFormat != CMP_FORMAT_BC7_SRGB) && (destFormat != CMP_FORMAT_BC7) && (destFormat != CMP_FORMAT_BC6H) && (destFormat != CMP_FORMAT_BC6H_SF))
30933094
{
30943095
g_CmdPrams.CompressOptions.fquality = 1.0f;
30953096
}
@@ -3282,12 +3283,13 @@ int ProcessCMDLine(CMP_Feedback_Proc pFeedbackProc, MipSet* p_userMipSetIn)
32823283
g_MipSetIn.m_format == CMP_FORMAT_BC3 || g_MipSetIn.m_format == CMP_FORMAT_BC4 ||
32833284
g_MipSetIn.m_format == CMP_FORMAT_BC4_S || g_MipSetIn.m_format == CMP_FORMAT_BC5 ||
32843285
g_MipSetIn.m_format == CMP_FORMAT_BC5_S || g_MipSetIn.m_format == CMP_FORMAT_BC6H ||
3285-
g_MipSetIn.m_format == CMP_FORMAT_BC6H_SF || g_MipSetIn.m_format == CMP_FORMAT_BC7;
3286+
g_MipSetIn.m_format == CMP_FORMAT_BC6H_SF || g_MipSetIn.m_format == CMP_FORMAT_BC7 ||
3287+
g_MipSetIn.m_format == CMP_FORMAT_BC7_SRGB;
32863288

32873289
bool DestFormatIsBCN = destFormat == CMP_FORMAT_BC1 || destFormat == CMP_FORMAT_BC2 || destFormat == CMP_FORMAT_BC3 ||
32883290
destFormat == CMP_FORMAT_BC4 || destFormat == CMP_FORMAT_BC4_S || destFormat == CMP_FORMAT_BC5 ||
32893291
destFormat == CMP_FORMAT_BC5_S || destFormat == CMP_FORMAT_BC6H || destFormat == CMP_FORMAT_BC6H_SF ||
3290-
destFormat == CMP_FORMAT_BC7;
3292+
destFormat == CMP_FORMAT_BC7 || destFormat == CMP_FORMAT_BC7_SRGB;
32913293

32923294
if (SourceFormatIsBCN && DestFormatIsBCN && (g_MipSetIn.m_format != destFormat))
32933295
{

applications/_plugins/common/texture.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ extern "C" {
107107

108108
#define CMP_FOURCC_BC6H CMP_MAKEFOURCC('B', 'C', '6', 'H')
109109
#define CMP_FOURCC_BC7 CMP_MAKEFOURCC('B', 'C', '7', 'x')
110+
#define CMP_FOURCC_BC7_SRGB CMP_MAKEFOURCC('B', 'C', '7', 's')
110111
#if (OPTION_BUILD_ASTC == 1)
111112
#define CMP_FOURCC_ASTC CMP_MAKEFOURCC('A', 'S', 'T', 'C')
112113
#endif

applications/_plugins/common/textureio.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ int AMDSaveMIPSTextureImage(const char *DestFile, MipSet *MipSetIn, bool use_OCV
721721
case CMP_FORMAT_ASTC:
722722
#endif
723723
case CMP_FORMAT_BC7:
724+
case CMP_FORMAT_BC7_SRGB:
724725
case CMP_FORMAT_BC6H:
725726
case CMP_FORMAT_BC6H_SF:
726727
case CMP_FORMAT_ETC_RGB:

cmp_compressonatorlib/bc7/codec_bc7.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ unsigned int BC7ThreadProcEncode(void* param) {
8181
// Construction/Destruction
8282
//////////////////////////////////////////////////////////////////////////////
8383

84-
CCodec_BC7::CCodec_BC7() : CCodec_DXTC(CT_BC7) {
84+
CCodec_BC7::CCodec_BC7(CodecType codecType) : CCodec_DXTC(codecType) {
8585
m_LibraryInitialized = false;
8686

8787
m_Use_MultiThreading = true;

cmp_compressonatorlib/bc7/codec_bc7.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct BC7EncodeThreadParam {
5454

5555
class CCodec_BC7 : public CCodec_DXTC {
5656
public:
57-
CCodec_BC7();
57+
CCodec_BC7(CodecType codecType);
5858
~CCodec_BC7();
5959

6060
virtual bool SetParameter(const CMP_CHAR* pszParamName, CMP_CHAR* sValue);

cmp_compressonatorlib/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ typedef enum _CodecType
252252
CT_BC6H,
253253
CT_BC6H_SF,
254254
CT_BC7,
255+
CT_BC7_SRGB,
255256
#if (OPTION_BUILD_ASTC == 1)
256257
CT_ASTC,
257258
#endif

cmp_compressonatorlib/common/codec.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ CCodec* CreateCodec(CodecType nCodecType) {
211211
case CT_BC6H_SF:
212212
return new CCodec_BC6H(nCodecType);
213213
case CT_BC7:
214-
return new CCodec_BC7;
214+
case CT_BC7_SRGB:
215+
return new CCodec_BC7(nCodecType);
215216
#if (OPTION_BUILD_ASTC == 1)
216217
case CT_ASTC:
217218
return new CCodec_ASTC;
@@ -320,6 +321,7 @@ CMP_DWORD CalcBufferSize(CodecType nCodecType, CMP_DWORD dwWidth, CMP_DWORD dwHe
320321

321322
// Block size is 4x4 and 128 bits per block
322323
case CT_BC7:
324+
case CT_BC7_SRGB:
323325
dwWidth = ((dwWidth + 3) / 4) * 4;
324326
dwHeight = ((dwHeight + 3) / 4) * 4;
325327
buffsize = dwWidth * dwHeight;

cmp_compressonatorlib/compress.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ CodecType GetCodecType(CMP_FORMAT format) {
151151
return CT_BC6H_SF;
152152
case CMP_FORMAT_BC7:
153153
return CT_BC7;
154+
case CMP_FORMAT_BC7_SRGB:
155+
return CT_BC7_SRGB;
154156
#if (OPTION_BUILD_ASTC == 1)
155157
case CMP_FORMAT_ASTC:
156158
return CT_ASTC;
@@ -326,6 +328,7 @@ CMP_ERROR CompressTexture(const CMP_Texture* pSourceTexture, CMP_Texture* pDestT
326328

327329
switch(destType) {
328330
case CT_BC7:
331+
case CT_BC7_SRGB:
329332
pCodec->SetParameter("MultiThreading", (CMP_DWORD) !pOptions->bDisableMultiThreading);
330333

331334
if (!pOptions->bDisableMultiThreading)
@@ -477,6 +480,7 @@ void ThreadedCompressProc(void *lpParameter) {
477480
CMP_ERROR ThreadedCompressTexture(const CMP_Texture* pSourceTexture, CMP_Texture* pDestTexture, const CMP_CompressOptions* pOptions, CMP_Feedback_Proc pFeedbackProc, CodecType destType) {
478481
// Note function should not be called for the following Codecs....
479482
if (destType == CT_BC7) return CMP_ABORTED;
483+
if (destType == CT_BC7_SRGB) return CMP_ABORTED;
480484
#ifdef USE_APC
481485
if (destType == CT_APC)
482486
return CMP_ABORTED;

cmp_compressonatorlib/compressonator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ CMP_ERROR CMP_API CMP_ConvertTexture(CMP_Texture* pSourceTexture,
589589
(destType != CT_ASTC) &&
590590
#endif
591591
(destType != CT_BC7) &&
592+
(destType != CT_BC7_SRGB) &&
592593
(destType != CT_BC6H) && (destType != CT_BC6H_SF)
593594
#ifdef USE_APC
594595
&& (destType != CT_APC)

cmp_compressonatorlib/compressonator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ typedef enum {
152152
CMP_FORMAT_BC6H = 0x0061, // DXGI_FORMAT_BC6H_UF16 VK_FORMAT_BC6H_UFLOAT_BLOCK GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT BC6H compressed texture format (UF)
153153
CMP_FORMAT_BC6H_SF = 0x1061, // DXGI_FORMAT_BC6H_SF16 VK_FORMAT_BC6H_SFLOAT_BLOCK GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT BC6H compressed texture format (SF)
154154
CMP_FORMAT_BC7 = 0x0071, // DXGI_FORMAT_BC7_UNORM VK_FORMAT_BC7_UNORM_BLOCK GL_COMPRESSED_RGBA_BPTC_UNORM BC7 compressed texture format
155+
CMP_FORMAT_BC7_SRGB = 0x0072, // DXGI_FORMAT_BC7_UNORM_SRGB VK_FORMAT_BC7_SRGB_BLOCK GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM BC7 compressed texture format
155156

156157
CMP_FORMAT_ATI1N = 0x0141, // DXGI_FORMAT_BC4_UNORM VK_FORMAT_BC4_UNORM_BLOCK GL_COMPRESSED_RED_RGTC1 Single component compression format using the same technique as DXT5 alpha. Four bits per pixel.
157158
CMP_FORMAT_ATI2N = 0x0151, // DXGI_FORMAT_BC5_UNORM VK_FORMAT_BC5_UNORM_BLOCK GL_COMPRESSED_RG_RGTC2 Two component compression format using the same technique as DXT5 alpha. Designed for compression of tangent space normal maps. Eight bits per pixel.

cmp_framework/compute_base.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ CodecType GetCodecType2(CMP_FORMAT format) {
445445
return CT_BC6H_SF;
446446
case CMP_FORMAT_BC7:
447447
return CT_BC7;
448+
case CMP_FORMAT_BC7_SRGB:
449+
return CT_BC7_SRGB;
448450
#if (OPTION_BUILD_ASTC == 1)
449451
case CMP_FORMAT_ASTC:
450452
return CT_ASTC;
@@ -567,6 +569,7 @@ CMP_DWORD CalcBufferSizeCT(CodecType nCodecType, CMP_DWORD dwWidth, CMP_DWORD dw
567569

568570
// Block size is 4x4 and 128 bits per block
569571
case CT_BC7:
572+
case CT_BC7_SRGB:
570573
dwWidth = ((dwWidth + 3) / 4) * 4;
571574
dwHeight = ((dwHeight + 3) / 4) * 4;
572575
buffsize = dwWidth * dwHeight;

0 commit comments

Comments
 (0)