Skip to content

Commit

Permalink
Added: Ability to export original extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Sep 29, 2022
1 parent ee1c632 commit f1a9938
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions source/Reloaded.Mod.Launcher.Lib/Utility/JxlImageConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static JxlImageConverter()
}

/// <inheritdoc />
public MemoryStream Convert(Span<byte> source, out string extension)
public MemoryStream Convert(Span<byte> source, string extension, out string newExtension)
{
var settings = new ProcessImageSettings();
settings.TrySetEncoderFormat(ImageMimeTypes.Jxl);
Expand All @@ -26,7 +26,7 @@ public MemoryStream Convert(Span<byte> source, out string extension)
MagicImageProcessor.ProcessImage(source, output, settings);

output.Position = 0;
extension = ".jxl";
newExtension = extension;
return output;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

public class DummyImageConverter : IImageConverter
{
public MemoryStream Convert(Span<byte> source, out string extension)
public MemoryStream Convert(Span<byte> source, string extension, out string newExtension)
{
extension = ".org";
newExtension = extension;
return new MemoryStream(source.ToArray());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public interface IImageConverter
/// Converts the image to new format.
/// </summary>
/// <param name="source">Span containing the source image to be converted.</param>
/// <param name="extension">The extension for the image.</param>
/// <param name="originalExtension">Original extension for this format.</param>
/// <param name="newExtension">The extension for the image.</param>
/// <returns>The converted image in a stream. Stream should have position 0 and end at end of file.</returns>
public MemoryStream Convert(Span<byte> source, out string extension);
public MemoryStream Convert(Span<byte> source, string originalExtension, out string newExtension);
}
2 changes: 1 addition & 1 deletion source/Reloaded.Mod.Loader.Update/Packs/AutoPackCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static async Task<ReloadedPackBuilder> CreateAsync(IEnumerable<ModConfig>
foreach (var image in bestPkg.images)
{
var file = await imageDownloader.GetOrDownloadFileFromUrl(image.Uri, imageDownloader.ModPreviewExpiration, false, token);
var converted = imageConverter.Convert(file, out string ext);
var converted = imageConverter.Convert(file, Path.GetExtension(image.Uri.ToString()), out string ext);
itemBuilder.AddImage(converted, ext, image.Caption);
}
}
Expand Down

0 comments on commit f1a9938

Please sign in to comment.