Exemple #1
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
Exemple #2
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
Exemple #3
0
 def calculate_mipmap_offsets(mipmap_count, width, height, fmt, start_offset):
     offsets = [start_offset]
     current_offset = start_offset
     for i in range(mipmap_count - 1):
         size = DDS.calculate_mipmap_size(width, height, i, fmt)
         current_offset += size
         offsets.append(current_offset)
     return offsets
Exemple #4
0
def test_tex_calculate_mipmap_count(tex_file):
    tex = Tex112(file_path=tex_file)

    mipmap_count_from_file = tex.mipmap_count
    mipmap_calculated = DDS.calculate_mipmap_count(tex.width, tex.height)

    # There might be cases where tex don't have mipmaps?
    assert mipmap_count_from_file == mipmap_calculated
Exemple #5
0
 def calculate_mipmap_offsets(mipmap_count, width, height, fmt,
                              start_offset):
     offsets = [start_offset]
     current_offset = start_offset
     for i in range(mipmap_count - 1):
         size = DDS.calculate_mipmap_size(width, height, i, fmt)
         current_offset += size
         offsets.append(current_offset)
     return offsets
Exemple #6
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