< Summary

Information
Class: Anichron.Worker.Ingestion.Proxy.UprightImageDecoder
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: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 43
Line coverage: 100%
Branch coverage
100%
Covered branches: 46
Total branches: 46
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
DecodeAsync(...)100%1010100%
IsHeifStill(...)100%3636100%

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
 7212internal sealed class UprightImageDecoder(MagickHeifDecoder heif, ImageSharpUprightDecoder imageSharp) : IUprightImageDe
 13{
 14    public Task<Image<Rgb24>> DecodeAsync(byte[] original, CancellationToken ct)
 6515    {
 6516        if (IsHeifStill(original))
 1217        {
 1218            ImageCompleteness.EnsureHeif(original);
 919            return heif.DecodeAsync(original, ct);
 20        }
 21
 5322        if (original is [0xFF, 0xD8, ..])
 2723            ImageCompleteness.EnsureJpeg(original);
 5124        return imageSharp.DecodeAsync(original, ct);
 6025    }
 26
 27    private static bool IsHeifStill(byte[] original)
 6528        => original is [_, _, _, _, (byte)'f', (byte)'t', (byte)'y', (byte)'p', .. var brand]
 6529           && brand is [(byte)'h', (byte)'e', (byte)'i', (byte)'c', ..]
 6530               or [(byte)'h', (byte)'e', (byte)'i', (byte)'x', ..]
 6531               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)
 37    {
 38        await using var ms = new MemoryStream(original);
 39        var image = await Image.LoadAsync<Rgb24>(ms, ct);
 40        image.Mutate(x => x.AutoOrient());
 41        return image;
 42    }
 43}