-
Notifications
You must be signed in to change notification settings - Fork 5
Added support for bc6h format #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
bdb9b34
43e552a
3ddae1e
1c0563a
1a91251
96c5591
3c5e0b4
b1e59a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,21 +61,35 @@ endif() | |
| # Link against compressonator libs & set runtime lib | ||
| if (UNIX) | ||
| if (VTFLIB_SHARED) | ||
| target_link_directories(vtflib PUBLIC thirdparty/lib/x64) | ||
| target_link_libraries(vtflib PUBLIC CMP_Compressonator pthread) | ||
| target_link_directories(vtflib PUBLIC thirdparty/lib/linux_x86_64) | ||
| target_link_libraries(vtflib PUBLIC | ||
| Compressonator | ||
| CMP_Core | ||
| CMP_Core_AVX | ||
| CMP_Core_AVX512 | ||
| CMP_Core_SSE | ||
| pthread | ||
| ) | ||
| endif() | ||
| if (VTFLIB_STATIC) | ||
| target_link_directories(vtflib_static PUBLIC thirdparty/lib/x64) | ||
| target_link_libraries(vtflib_static PUBLIC CMP_Compressonator pthread) | ||
| target_link_directories(vtflib_static PUBLIC thirdparty/lib/linux_x86_64) | ||
| target_link_libraries(vtflib_static PUBLIC | ||
| Compressonator | ||
| CMP_Core | ||
| CMP_Core_AVX | ||
| CMP_Core_AVX512 | ||
| CMP_Core_SSE | ||
| pthread | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
| ) | ||
| endif() | ||
| else() | ||
| if (VTFLIB_SHARED) | ||
| target_link_directories(vtflib PUBLIC thirdparty/lib) | ||
| target_link_directories(vtflib PUBLIC thirdparty/lib/win_x86_64) | ||
| target_link_libraries(vtflib PUBLIC "Compressonator_MT$<$<CONFIG:Debug>:d>") | ||
| endif() | ||
| if (VTFLIB_STATIC) | ||
| target_link_libraries(vtflib_static PUBLIC "Compressonator_MT$<$<CONFIG:Debug>:d>") | ||
| target_link_directories(vtflib_static PUBLIC thirdparty/lib) | ||
| target_link_directories(vtflib_static PUBLIC thirdparty/lib/win_x86_64) | ||
| endif() | ||
| endif() | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -440,6 +440,7 @@ static CMP_FORMAT GetCMPFormat( VTFImageFormat imageFormat, bool bDXT5GA ) | |
| // Swizzle is technically wrong for below but we reverse it in the shader! | ||
| case IMAGE_FORMAT_ATI2N: return CMP_FORMAT_ATI2N; | ||
|
|
||
| case IMAGE_FORMAT_BC6H: return CMP_FORMAT_BC6H; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: should come after BC7 |
||
| case IMAGE_FORMAT_BC7: return CMP_FORMAT_BC7; | ||
|
|
||
| default: return CMP_FORMAT_Unknown; | ||
|
|
@@ -3032,7 +3033,8 @@ static SVTFImageFormatInfo VTFImageFormatInfo[] = | |
| {}, | ||
| {}, | ||
| {}, | ||
| { "BC7", 8, 0, 0, 0, 0, 0, vlTrue, vlTrue } // IMAGE_FORMAT_BC7 | ||
| { "BC7", 8, 0, 0, 0, 0, 0, vlTrue, vlTrue }, // IMAGE_FORMAT_BC7 | ||
| { "BC6H", 8, 0, 0, 0, 0, 0, vlTrue, vlTrue } // IMAGE_FORMAT_BC6H | ||
| }; | ||
|
|
||
| SVTFImageFormatInfo const &CVTFFile::GetImageFormatInfo(VTFImageFormat ImageFormat) | ||
|
|
@@ -3066,6 +3068,7 @@ vlUInt CVTFFile::ComputeImageSize(vlUInt uiWidth, vlUInt uiHeight, vlUInt uiDept | |
| case IMAGE_FORMAT_DXT3: | ||
| case IMAGE_FORMAT_DXT5: | ||
| case IMAGE_FORMAT_ATI2N: | ||
| case IMAGE_FORMAT_BC6H: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: should be after BC7 |
||
| case IMAGE_FORMAT_BC7: | ||
| if(uiWidth < 4 && uiWidth > 0) | ||
| uiWidth = 4; | ||
|
|
@@ -3301,20 +3304,23 @@ vlBool CVTFFile::DecompressBCn(const vlByte *src, vlByte *dst, vlUInt uiWidth, v | |
| return vlTrue; | ||
| } | ||
|
|
||
| // | ||
| //----------------------------------------------------------------------------------------------------- | ||
| // ConvertFromRGBA8888() | ||
| // | ||
| // Convert input image data (lpSource) to output image data (lpDest) of format DestFormat. | ||
| // | ||
| //----------------------------------------------------------------------------------------------------- | ||
| vlBool CVTFFile::ConvertFromRGBA8888(const vlByte *lpSource, vlByte *lpDest, vlUInt uiWidth, vlUInt uiHeight, VTFImageFormat DestFormat) | ||
| { | ||
| return CVTFFile::Convert(lpSource, lpDest, uiWidth, uiHeight, IMAGE_FORMAT_RGBA8888, DestFormat); | ||
| } | ||
|
|
||
| // | ||
| //----------------------------------------------------------------------------------------------------- | ||
| // CompressBCn() | ||
| // | ||
| // Compress input image data (lpSource) to output image data (lpDest) of format DestFormat | ||
| // where DestFormat is of format BCn. Uses Compressonator library. | ||
| // | ||
| // where DestFormat is of format BCn. Uses Compressonator library. | ||
| // --Does not support BC6H | ||
| //----------------------------------------------------------------------------------------------------- | ||
| vlBool CVTFFile::CompressBCn(const vlByte *lpSource, vlByte *lpDest, vlUInt uiWidth, vlUInt uiHeight, VTFImageFormat DestFormat) | ||
| { | ||
| CMP_Texture srcTexture = {0}; | ||
|
|
@@ -3350,6 +3356,74 @@ vlBool CVTFFile::CompressBCn(const vlByte *lpSource, vlByte *lpDest, vlUInt uiWi | |
| return vlTrue; | ||
| } | ||
|
|
||
| //----------------------------------------------------------------------------------------------------- | ||
| // CompressBC6H() | ||
| // | ||
| // Compress input image data (lpSource) to output image data (lpDest) of format DestFormat | ||
| // where DestFormat is of format BC6H. Uses Compressonator library. | ||
| // | ||
| // NOTE: For BC6H conversion, an extra step is needed that puts the source data into a half float | ||
| // format before conversion. Do not use BCn for BC6H compression. -klaxon | ||
| //----------------------------------------------------------------------------------------------------- | ||
| vlBool CVTFFile::CompressBC6H(const vlByte* lpSource, vlByte* lpDest, vlUInt uiWidth, vlUInt uiHeight) | ||
| { | ||
| CMP_Texture srcTexture = { 0 }; | ||
| srcTexture.dwSize = sizeof(srcTexture); | ||
| srcTexture.dwWidth = uiWidth; | ||
| srcTexture.dwHeight = uiHeight; | ||
| srcTexture.dwPitch = 4 * uiWidth; | ||
| srcTexture.format = CMP_FORMAT_RGBA_8888; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the input to this function always assumed to be RGBA8888?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, it was while i was testing things out. ill go ahead and add the SourceFormat param back to make sure an edge case isn't hit.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My issue with this code is less about assuming
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still blocking merge, basically what JJ said |
||
| srcTexture.dwDataSize = uiHeight * srcTexture.dwPitch; | ||
| srcTexture.pData = (CMP_BYTE*)lpSource; | ||
|
|
||
| CMP_CompressOptions options = { 0 }; | ||
| options.dwSize = sizeof(options); | ||
| options.dwnumThreads = 0; | ||
| options.bDXT1UseAlpha = false; | ||
|
|
||
| vlByte* lpMidBuf = new vlByte[CVTFFile::ComputeImageSize(uiWidth, uiHeight, 1, IMAGE_FORMAT_RGBA16161616F)]; | ||
| CMP_Texture midTexture = { 0 }; | ||
| midTexture.dwSize = sizeof(midTexture); | ||
| midTexture.dwWidth = uiWidth; | ||
| midTexture.dwHeight = uiHeight; | ||
| midTexture.dwPitch = 8 * uiWidth; | ||
| midTexture.format = CMP_FORMAT_RGBA_16F; | ||
| midTexture.dwDataSize = CMP_CalculateBufferSize(&midTexture); | ||
| midTexture.pData = (CMP_BYTE*)lpMidBuf; | ||
|
|
||
| CMP_Texture destTexture = { 0 }; | ||
| destTexture.dwSize = sizeof(destTexture); | ||
| destTexture.dwWidth = uiWidth; | ||
| destTexture.dwHeight = uiHeight; | ||
| destTexture.dwPitch = 0; | ||
| destTexture.format = CMP_FORMAT_BC6H; | ||
| destTexture.dwDataSize = CMP_CalculateBufferSize(&destTexture); | ||
| destTexture.pData = (CMP_BYTE*)lpDest; | ||
|
|
||
| // convert to the mid texture first (to pass a half-float format for bc6h) | ||
| CMP_ERROR cmp_status = CMP_ConvertTexture(&srcTexture, &midTexture, &options, NULL); | ||
| if (cmp_status != CMP_OK) | ||
| { | ||
| delete[] lpMidBuf; | ||
|
|
||
| LastError.Set(GetCMPErrorString(cmp_status)); | ||
| return vlFalse; | ||
| } | ||
|
|
||
| cmp_status = CMP_ConvertTexture(&midTexture, &destTexture, &options, NULL); | ||
| if (cmp_status != CMP_OK) | ||
| { | ||
| delete[] lpMidBuf; | ||
|
|
||
| LastError.Set(GetCMPErrorString(cmp_status)); | ||
| return vlFalse; | ||
| } | ||
|
|
||
| delete[] lpMidBuf; | ||
|
|
||
| return vlTrue; | ||
| } | ||
|
|
||
| typedef vlVoid (*TransformProc)(vlUInt16& R, vlUInt16& G, vlUInt16& B, vlUInt16& A); | ||
|
|
||
| vlVoid ToLuminance(vlUInt16& R, vlUInt16& G, vlUInt16& B, vlUInt16& A) | ||
|
|
@@ -3558,6 +3632,7 @@ static SVTFImageConvertInfo VTFImageConvertInfo[IMAGE_FORMAT_COUNT] = | |
| {}, | ||
| {}, | ||
| { 8, 0, 0, 0, 0, 0, -1, -1, -1, -1, vlTrue, vlTrue, NULL, NULL, IMAGE_FORMAT_BC7}, | ||
| { 8, 0, 0, 0, 0, 0, -1, -1, -1, -1, vlTrue, vlTrue, NULL, NULL, IMAGE_FORMAT_BC6H} | ||
| }; | ||
|
|
||
| // Get each channels shift and mask (for encoding and decoding). | ||
|
|
@@ -3857,6 +3932,7 @@ vlBool CVTFFile::Convert(const vlByte *lpSource, vlByte *lpDest, vlUInt uiWidth, | |
| case IMAGE_FORMAT_DXT5: | ||
| case IMAGE_FORMAT_ATI2N: | ||
| case IMAGE_FORMAT_ATI1N: | ||
| case IMAGE_FORMAT_BC6H: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: should be below.. yeah you get the idea |
||
| case IMAGE_FORMAT_BC7: | ||
| bResult = CVTFFile::DecompressBCn(lpSource, lpConvBuf, uiWidth, uiHeight, SourceFormat); | ||
| break; | ||
|
|
@@ -3879,6 +3955,9 @@ vlBool CVTFFile::Convert(const vlByte *lpSource, vlByte *lpDest, vlUInt uiWidth, | |
| case IMAGE_FORMAT_BC7: | ||
| bResult = CVTFFile::CompressBCn(lpConvBuf ? lpConvBuf : lpSource, lpDest, uiWidth, uiHeight, DestFormat); | ||
| break; | ||
| case IMAGE_FORMAT_BC6H: | ||
| bResult = CVTFFile::CompressBC6H(lpConvBuf ? lpConvBuf : lpSource, lpDest, uiWidth, uiHeight); | ||
| break; | ||
| default: | ||
| bResult = CVTFFile::Convert(lpConvBuf ? lpConvBuf : lpSource, lpDest, uiWidth, uiHeight, IMAGE_FORMAT_RGBA8888, DestFormat); | ||
| break; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,8 +94,9 @@ typedef enum tagVTFImageFormat | |
|
|
||
| IMAGE_FORMAT_ATI2N, //!< = Red, Green BC5 compressed format - 8 bpp | ||
| IMAGE_FORMAT_ATI1N, //!< = Red BC4 compressed format - 4 bpp | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: extra space |
||
| IMAGE_FORMAT_BC7 = 70, //!< = Red, Green, Blue, Alpha BC7 compressed format - 8 bpp | ||
| IMAGE_FORMAT_BC6H, //!< = Red, Green, Blue, BC6H (signed) compressed format - 8 bpp | ||
| /* | ||
| XBox: | ||
| IMAGE_FORMAT_X360_DST16, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use cmake's
Threads::Threadstarget instead ofpthreadfrom stackoverflow:
also, is this actually required? i cant remember any vtflib code that uses pthreads or any threading stuff in
std