Skip to content

Instantly share code, notes, and snippets.

@Nukem9
Created July 15, 2024 10:41
Show Gist options
  • Save Nukem9/28407a4ace60e27ca0c3225311f57740 to your computer and use it in GitHub Desktop.
Save Nukem9/28407a4ace60e27ca0c3225311f57740 to your computer and use it in GitHub Desktop.
DDS conversion tool for legacy GLI B5G6R5 formats captured with RTX Remix.
import struct
import argparse
def main(inputFilePath, outputFilePath):
with open(inputFilePath, 'rb') as file:
binaryData = bytearray(file.read())
ddsHeaderMagic = struct.unpack('>L', binaryData[0x0:0x4])[0]
ddsHeaderLength = struct.unpack('L', binaryData[0x4:0x8])[0]
if (ddsHeaderMagic != 0x44445320 or # 'DDS '
ddsHeaderLength != 0x7C):
print('DDS header magic or length didn\'t match')
return
ddsFourCC = struct.unpack('>L', binaryData[0x54:0x58])[0] # DDS_PIXELFORMAT.dwFourCC
ddsBitsPerPixel = struct.unpack('L', binaryData[0x58:0x5C])[0] # DDS_PIXELFORMAT.dwRGBBitCount
ddsChannelMasks = struct.unpack('LLLL', binaryData[0x5C:0x6C]) # DDS_PIXELFORMAT.dwRGBABitMask
if ddsFourCC != 0x474C4931: # 'GLI1'
print('DDS doesn\'t use GLI1 extension')
return
if (ddsBitsPerPixel != 16 or
ddsChannelMasks[0] != 0x1F or # 5 bits R
ddsChannelMasks[1] != 0x7E0 or # 6 bits G
ddsChannelMasks[2] != 0xF800 or # 5 bits B
ddsChannelMasks[3] != 0x0): # 0 bits A
print('DDS not a 16-bit B5G6R5 format')
return
struct.pack_into('>L', binaryData, 0x54, 0x44583130) # 'DX10'
struct.pack_into('L', binaryData, 0x80, 0x55) # DDS_HEADER_DXT10.dxgiFormat = DXGI_FORMAT_B5G6R5_UNORM
with open(outputFilePath, 'wb') as outFile:
outFile.write(binaryData)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="DDS conversion tool for legacy GLI formats captured from RTX Remix.")
parser.add_argument("input_file", help="Path to the input DDS/GLI file.")
parser.add_argument("output_file", help="Path to the output DDS file.")
args = parser.parse_args()
main(args.input_file, args.output_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment