Prove adattate all'unione: HEIC come RgbaImage, facciata dei codec che legge HEIF
Dopo l'unione le foto HEIC escono dalla facciata dei codec di C1 come RgbaImage (pixel R, G, B, A) e non più come bitmap di SkiaSharp: la prova dell'angolo ruotato legge R, G, B. La facciata ora decodifica HEIF, quindi la prova dei formati lo mette fra quelli letti e tiene AVIF fra quelli no. Una prova nuova guarda la facciata su un HEIC (formato, orientamento da irot, pixel, limite di misura) e la misura di un HEIC più grande dei byte che ImageDecoding legge per primi, presa dai soli box. Un HEIC senza immagine non si dice danneggiato: il suo decodificatore non distingue un file rovinato da uno che non gestisce (commento e messaggio corretti). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
14920afebf
commit
7e5eccd1ec
4 files changed
+31
-4
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using Febe.Core.Codecs.H265;
|
||||
using Febe.Core.Codecs.Images;
|
||||
using Febe.Core.Codecs.Heif;
|
||||
using Febe.Core.Import;
|
||||
using Febe.Core.Library;
|
||||
@@ -143,7 +144,7 @@ public sealed class HeifDecoderTests
|
||||
Assert.IsNotNull(bitmap);
|
||||
Assert.AreEqual((picture.Frame.Height, picture.Frame.Width), (bitmap.Width, bitmap.Height));
|
||||
var corner = bitmap.GetPixel(bitmap.Width - 1, 0);
|
||||
Assert.AreEqual((rgba[0], rgba[1], rgba[2]), (corner.Red, corner.Green, corner.Blue));
|
||||
Assert.AreEqual((rgba[0], rgba[1], rgba[2]), (corner.R, corner.G, corner.B));
|
||||
|
||||
using var temp = new TempFolder("miniatura-heic");
|
||||
var store = new ThumbnailStore(temp.Combine("miniature"));
|
||||
@@ -153,6 +154,31 @@ public sealed class HeifDecoderTests
|
||||
Assert.IsNotNull(PerceptualHash.Compute(new MemoryStream(file)), "impronta visiva di un HEIC");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TheImageFacadeReadsAHeicAsAnyOtherPhoto()
|
||||
{
|
||||
// irot 1: a quarter turn anticlockwise. The facade gives the pixels as stored and the turn as the orientation.
|
||||
var picture = CodedPicture.First(Tiles[0]);
|
||||
var builder = new HeifBuilder();
|
||||
var hvcC = builder.Property(HeifBuilder.HvcCProperty(picture.HvcC));
|
||||
var ispe = builder.Property(HeifBuilder.Ispe(picture.Frame.Width, picture.Frame.Height));
|
||||
builder.Item(1, "hvc1", picture.Data, -hvcC, ispe, -builder.Property(HeifBuilder.Irot(1)));
|
||||
var file = builder.Build();
|
||||
var info = ImageDecoder.Identify(file);
|
||||
Assert.AreEqual(ImageFormat.Heif, info.Format);
|
||||
Assert.AreEqual((picture.Frame.Width, picture.Frame.Height, 8), (info.Width, info.Height, info.Metadata.Orientation));
|
||||
using var image = ImageDecoder.Decode(file, out var decoded);
|
||||
CollectionAssert.AreEqual(Rgba(picture.Frame), image.ToArray());
|
||||
Assert.AreEqual(8, decoded.Metadata.Orientation);
|
||||
Assert.ThrowsExactly<ImageLimitException>(() => ImageDecoder.Decode(file, ImageLimits.Default with { MaxPixels = 1000 }));
|
||||
|
||||
// Past the bytes ImageDecoding reads first, the size still comes from the boxes alone.
|
||||
byte[] large = [.. file, 0, 4, 0x93, 0xE0, .. "free"u8, .. new byte[300_000 - 8]];
|
||||
Assert.IsGreaterThan(ImageDecoding.HeaderBytes, large.Length);
|
||||
using var stream = new MemoryStream(large);
|
||||
Assert.AreEqual((picture.Frame.Height, picture.Frame.Width), ImageDecoding.ReadSize(stream));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TheCleanApertureCutsThePicture()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user