
This commit lays the groundwork for a user-configurable image processing pipeline. It has exactly the same behavior as the old ImageProcessor, just modular & compartmentalized. It also adds support for AVIF & JXL encoding, though no code paths call it just yet.
72 lines
No EOL
1.3 KiB
C#
72 lines
No EOL
1.3 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace Iceshrimp.Backend.Core.Services.ImageProcessing;
|
|
|
|
public abstract record ImageFormat(string Extension, string MimeType)
|
|
{
|
|
public record Keep(string Extension, string MimeType) : ImageFormat(Extension, MimeType);
|
|
//TODO: public record StripExifAndIcc(string Extension, string MimeType) : ImageFormat(Extension, MimeType);
|
|
|
|
public record Webp(
|
|
Webp.Compression Mode,
|
|
[Range(0, 100)] int Quality,
|
|
int TargetRes
|
|
) : ImageFormat("webp", "image/webp")
|
|
{
|
|
public enum Compression
|
|
{
|
|
Lossy,
|
|
NearLossless,
|
|
Lossless
|
|
}
|
|
}
|
|
|
|
public record Avif(
|
|
Avif.Compression Mode,
|
|
[Range(0, 100)] int Quality,
|
|
[Range(8, 12)] int? BitDepth,
|
|
int TargetRes
|
|
) : ImageFormat("avif", "image/avif")
|
|
{
|
|
public enum Compression
|
|
{
|
|
Lossy,
|
|
Lossless
|
|
}
|
|
}
|
|
|
|
public record Jxl(
|
|
Jxl.Compression Mode,
|
|
[Range(0, 100)] int Quality,
|
|
[Range(1, 9)] int Effort,
|
|
int TargetRes
|
|
) : ImageFormat("jxl", "image/jxl")
|
|
{
|
|
public enum Compression
|
|
{
|
|
Lossy,
|
|
Lossless
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum ImageFormatEnum
|
|
{
|
|
None,
|
|
Keep,
|
|
Webp,
|
|
Avif,
|
|
Jxl
|
|
}
|
|
|
|
public record ImageVersion(ImageVersion.KeyEnum Key, ImageFormat Format)
|
|
{
|
|
public enum KeyEnum
|
|
{
|
|
Original,
|
|
Thumbnail,
|
|
Public
|
|
}
|
|
|
|
public static ImageVersion Stub => new(KeyEnum.Original, new ImageFormat.Keep("", ""));
|
|
} |