Skip to main content

Module image

Module image 

Source
Expand description

Image file handling with DDS conversion support.

This module provides the Image type for working with image files in Total War PackFiles. It stores raw image data and provides automatic conversion of DDS textures to PNG format for easier viewing and editing.

§Supported Formats

The following image formats are recognized:

  • JPEG (.jpg, .jpeg) - Standard photo compression
  • PNG (.png) - Lossless compressed images with alpha
  • TGA (.tga) - Targa images (common in game assets)
  • DDS (.dds) - DirectDraw Surface textures (Total War’s primary format)
  • GIF (.gif) - Animated or simple images

§DDS Conversion

DDS files are automatically converted to PNG format when decoded to enable easier viewing in standard image viewers and editors. The original DDS data is preserved for re-encoding.

The conversion process handles various DDS formats:

  • Standard DDS formats supported by the image crate
  • BC3_UNORM compressed textures via re-compression
  • RGBA_U8 color formats

§Example

use rpfm_lib::files::{Decodeable, image::Image, DecodeableExtraData};
use std::io::Cursor;

// Read a DDS texture
let dds_data = std::fs::read("texture.dds").unwrap();
let mut reader = Cursor::new(dds_data);
let mut extra = DecodeableExtraData::default();
extra.set_is_dds(true);
let image = Image::decode(&mut reader, &Some(extra)).unwrap();

// Access converted PNG data for viewing
if let Some(png_data) = image.converted_data() {
    // Display in image viewer
}

Structs§

Image
In-memory representation of an image file.

Constants§

EXTENSIONS
Extensions used by Images.