< Summary

Information
Class: Anichron.Worker.Ingestion.Proxy.ImageSharpUprightDecoder
Assembly: Anichron.Worker
File(s): /home/runner/work/anichron/anichron/src/Anichron.Worker/Ingestion/Proxy/UprightImageDecoder.cs
Tag: 19_45211875487
Line coverage
100%
Covered lines: 6
Uncovered lines: 0
Coverable lines: 6
Total lines: 43
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
DecodeAsync()100%11100%

File(s)

/home/runner/work/anichron/anichron/src/Anichron.Worker/Ingestion/Proxy/UprightImageDecoder.cs

#LineLine coverage
 1using SixLabors.ImageSharp;
 2using SixLabors.ImageSharp.PixelFormats;
 3using SixLabors.ImageSharp.Processing;
 4
 5namespace Anichron.Worker.Ingestion.Proxy;
 6
 7internal interface IUprightImageDecoder
 8{
 9    Task<Image<Rgb24>> DecodeAsync(byte[] original, CancellationToken ct);
 10}
 11
 12internal sealed class UprightImageDecoder(MagickHeifDecoder heif, ImageSharpUprightDecoder imageSharp) : IUprightImageDe
 13{
 14    public Task<Image<Rgb24>> DecodeAsync(byte[] original, CancellationToken ct)
 15    {
 16        if (IsHeifStill(original))
 17        {
 18            ImageCompleteness.EnsureHeif(original);
 19            return heif.DecodeAsync(original, ct);
 20        }
 21
 22        if (original is [0xFF, 0xD8, ..])
 23            ImageCompleteness.EnsureJpeg(original);
 24        return imageSharp.DecodeAsync(original, ct);
 25    }
 26
 27    private static bool IsHeifStill(byte[] original)
 28        => original is [_, _, _, _, (byte)'f', (byte)'t', (byte)'y', (byte)'p', .. var brand]
 29           && brand is [(byte)'h', (byte)'e', (byte)'i', (byte)'c', ..]
 30               or [(byte)'h', (byte)'e', (byte)'i', (byte)'x', ..]
 31               or [(byte)'m', (byte)'i', (byte)'f', (byte)'1', ..];
 32}
 33
 34internal sealed class ImageSharpUprightDecoder : IUprightImageDecoder
 35{
 36    public async Task<Image<Rgb24>> DecodeAsync(byte[] original, CancellationToken ct)
 5437    {
 5438        await using var ms = new MemoryStream(original);
 5439        var image = await Image.LoadAsync<Rgb24>(ms, ct);
 5040        image.Mutate(x => x.AutoOrient());
 5041        return image;
 5042    }
 43}

Methods/Properties

DecodeAsync()