Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scale up doesn't handle IRawTextureData #128

Open
Pathoschild opened this issue May 27, 2022 · 0 comments
Open

Scale up doesn't handle IRawTextureData #128

Pathoschild opened this issue May 27, 2022 · 0 comments

Comments

@Pathoschild
Copy link
Contributor

Pathoschild commented May 27, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant