Arcade 2048

Arcade 2048

3.4k Downloads

Scale up doesn't handle IRawTextureData

Pathoschild opened this issue ยท 0 comments

commented

PyTK's scale-up feature doesn't handle mod images loaded as IRawTextureData.

Background

With SMAPI 3.15, mods can load raw image data like helper.ModContent.Load<IRawTextureData>("assets/example.png"). That returns a model with this info:

/// <summary>The raw data for an image read from the filesystem.</summary>
public interface IRawTextureData
{
    /// <summary>The image width.</summary>
    int Width { get; }

    /// <summary>The image height.</summary>
    int Height { get; }

    /// <summary>The loaded image data.</summary>
    Color[] Data { get; }
}

Creating a full Texture2D instance is expensive and involves GPU calls, so this optimizes cases where we only need the image data. In particular, Content Patcher 1.27 will migrate to that feature for all of its EditImage patches.

PyTK impact

For PyTK, that probably means adding a separate Harmony patch on ModContentManager.LoadRawImageData and scaling the raw data directly:

/// <summary>Load the raw image data from a file on disk.</summary>
/// <param name="file">The file whose data to load.</param>
/// <param name="forRawData">Whether the data is being loaded for an <see cref="IRawTextureData"/> (true) or <see cref="Texture2D"/> (false) instance.</param>
private IRawTextureData LoadRawImageData(FileInfo file, bool forRawData);

Workaround

For players who want to use PyTK's scale up with SMAPI 3.15:

  1. Open your game folder.
  2. Open smapi-internal/config.json in a text editor (Notepad is fine).
  3. Change the UseRawImageLoading option to false.
  4. Install Content Patcher 1.26.5 (not 1.27.0 or later).

This may increase the performance impact, so you should only disable it if needed.