Port of: bool save_dds(const char* pFilename, uint32_t width, uint32_t height, const void* pBlocks, uint32_t pixel_format_bpp, DXGI_FORMAT dxgi_format,
(
self,
filename: str,
width: int,
height: int,
blocks: Union[bytes, bytearray, memoryview],
pixel_format_bpp: int,
dxgi_format: int,
srgb: bool = False,
force_dx10_header: bool = False,
)
| 80 | DDS_MAGIC = b"DDS " # same as fwrite("DDS ", 4, 1, pFile); |
| 81 | |
| 82 | def save_dds( |
| 83 | self, |
| 84 | filename: str, |
| 85 | width: int, |
| 86 | height: int, |
| 87 | blocks: Union[bytes, bytearray, memoryview], |
| 88 | pixel_format_bpp: int, |
| 89 | dxgi_format: int, |
| 90 | srgb: bool = False, |
| 91 | force_dx10_header: bool = False, |
| 92 | ) -> bool: |
| 93 | """ |
| 94 | Port of: |
| 95 | bool save_dds(const char* pFilename, |
| 96 | uint32_t width, uint32_t height, |
| 97 | const void* pBlocks, |
| 98 | uint32_t pixel_format_bpp, |
| 99 | DXGI_FORMAT dxgi_format, |
| 100 | bool srgb, |
| 101 | bool force_dx10_header); |
| 102 | |
| 103 | The 'blocks' buffer is written as-is (up to computed linear size). |
| 104 | """ |
| 105 | |
| 106 | # srgb is intentionally unused in the original C code (commented logic). |
| 107 | _ = srgb |
| 108 | |
| 109 | # Open file like the C code |
| 110 | try: |
| 111 | f = open(filename, "wb") |
| 112 | except OSError: |
| 113 | print(f"Failed creating file {filename}!", file=sys.stderr) |
| 114 | return False |
| 115 | |
| 116 | try: |
| 117 | # Write the "DDS " magic |
| 118 | f.write(self.DDS_MAGIC) |
| 119 | |
| 120 | # ----------------------------------------------------------------- |
| 121 | # Build DDSURFACEDESC2 equivalent |
| 122 | # ----------------------------------------------------------------- |
| 123 | # We'll pack DDSURFACEDESC2 as 31 uint32's (124 bytes) in little-endian: |
| 124 | # struct DDSURFACEDESC2 { |
| 125 | # uint32 dwSize; |
| 126 | # uint32 dwFlags; |
| 127 | # uint32 dwHeight; |
| 128 | # uint32 dwWidth; |
| 129 | # uint32 lPitch_or_dwLinearSize; |
| 130 | # uint32 dwBackBufferCount; |
| 131 | # uint32 dwMipMapCount; |
| 132 | # uint32 dwAlphaBitDepth; |
| 133 | # uint32 dwUnused0; |
| 134 | # uint32 lpSurface; |
| 135 | # DDCOLORKEY unused0; (2 * uint32) |
| 136 | # DDCOLORKEY unused1; (2 * uint32) |
| 137 | # DDCOLORKEY unused2; (2 * uint32) |
| 138 | # DDCOLORKEY unused3; (2 * uint32) |
| 139 | # DDPIXELFORMAT ddpfPixelFormat; (8 * uint32) |
no test coverage detected