Example #1
0
    def from_dds(cls, file_path):
        dds = DDS(file_path=file_path)
        mipmap_count = dds.header.dwMipMapCount
        width = dds.header.dwWidth
        height = dds.header.dwHeight
        compression_format = dds.header.pixelfmt_dwFourCC
        fixed_size_of_header = 40
        start_offset = fixed_size_of_header + (mipmap_count * 4)
        mipmap_offsets = cls.calculate_mipmap_offsets(mipmap_count, width,
                                                      height,
                                                      compression_format,
                                                      start_offset)
        assert len(mipmap_offsets) == mipmap_count
        mipmap_offsets = (c_uint * len(mipmap_offsets))(*mipmap_offsets)
        dds_data = (c_byte * len(dds.data)).from_buffer(dds.data)

        # TODO: Don't hardcode uknown floats (seem to be brightness values)
        tex = cls(id_magic=cls.ID_MAGIC,
                  version=112,
                  revision=34,
                  mipmap_count=mipmap_count,
                  unk_byte_1=1,
                  unk_byte_2=0,
                  unk_byte_3=0,
                  width=width,
                  height=height,
                  compression_format=compression_format,
                  unk_float_1=0.76,
                  unk_float_2=0.76,
                  tex_unk_float_3=0.76,
                  unk_float_4=0,
                  mipmap_offsets=mipmap_offsets,
                  dds_data=dds_data)

        return tex
Example #2
0
 def to_dds(self):
     header = DDSHeader(dwHeight=self.height,
                        dwWidth=self.width,
                        dwMipMapCount=self.mipmap_count,
                        pixelfmt_dwFourCC=self.compression_format)
     dds = DDS(header=header, data=self.dds_data)
     dds.set_constants()
     dds.set_variables()
     return dds