E3: conversione delle foto, rimux in MP4 e fotogrammi esatti nel nucleo
Prima parte della tappa E3 (formati e fotogrammi), solo nel nucleo: il pianificatore, il copiatore e l'archivio delle esportazioni restano alla parte successiva. - Foto: ImageConverter.Check dice prima che cosa succede (copia identica, conversione, copia così com'è con il motivo: HEIC, AVIF, raw, animazioni, file danneggiati, CMYK e oltre 8 bit verso PNG/WEBP, oltre il limite di pixel); la conversione riporta come note ciò che non può portare invece di fermarsi, e la trasparenza verso JPG diventa bianco. I lettori segnalano animazioni, CMYK e segmenti non letti. VP8L usa un logaritmo in virgola fissa, così lo stesso file dà gli stessi byte su ogni sistema. - Video: i lettori ISO e Matroska leggono elenco dei montaggi, lingue, tipo di AAC, MP3 e i vecchi codici AAC di Matroska; Mp4Writer prepara la disposizione e ne conosce la lunghezza prima di scrivere; il nuovo Mp4Remuxer porta in MP4 senza ricodificare, sempre con gli stessi byte. - Fotogrammi: VideoFrameReader trova il campione mostrato a un istante come lo mostra il lettore, lo decodifica esatto a piena risoluzione e lo raddrizza; ExportFrames calcola istanti, suffissi e etichette. - Nomi: il suffisso del fotogramma non si accorcia mai e la numerazione dei nomi liberi viene dopo di lui; SafeFileWriter scrive anche contenuti prodotti mentre li scrive. - MediaConverter e ConversionThrottle preparano una conversione senza sapere dove andrà, una alla volta in tutto il processo. Nuove prove per determinismo, istanti, rotazione, rimux e nomi; tutte le prove di Febe.Tests passano. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7faf92e667
commit
704c1ed9cf
28 files changed
+2830
-144
No files matched your search
@@ -0,0 +1,90 @@
|
||||
using System.Security.Cryptography;
|
||||
using Febe.Core.Codecs.Images;
|
||||
using static Febe.Tests.Imaging.TestImages;
|
||||
|
||||
namespace Febe.Tests.Imaging;
|
||||
|
||||
/// <summary>
|
||||
/// The photo conversion of tappa E3: what is copied as it is and why (D5, D6), what a conversion reports instead of
|
||||
/// throwing, and that converting the same picture twice gives the same bytes (D9).
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public sealed class ImageConversionTests
|
||||
{
|
||||
private static readonly byte[] Palette4 = [0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255];
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(ImageFormat.Jpeg)]
|
||||
[DataRow(ImageFormat.Png)]
|
||||
[DataRow(ImageFormat.WebP)]
|
||||
public void ConvertingTwiceGivesTheSameBytes(ImageFormat target)
|
||||
{
|
||||
using var picture = Gradient(97, 61, seed: 7);
|
||||
var source = ImageConverter.Encode(picture, target == ImageFormat.Png ? ImageFormat.Jpeg : ImageFormat.Png, null);
|
||||
|
||||
var first = ImageConverter.Convert(source, target);
|
||||
var second = ImageConverter.Convert(source, target);
|
||||
|
||||
Assert.AreEqual(target, ImageFormatSniffer.Detect(first.Data));
|
||||
CollectionAssert.AreEqual(SHA256.HashData(first.Data), SHA256.HashData(second.Data));
|
||||
Assert.AreEqual(target == ImageFormat.Jpeg, first.Lossy);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WebpCostsUseNoFloatingPointLog()
|
||||
{
|
||||
// The fixed-point log2 of the VP8L cost estimates is exact on powers of two and monotonic.
|
||||
var previous = -1L;
|
||||
for (ulong v = 1; v < 70_000; v += 13)
|
||||
{
|
||||
var log = Vp8LEncoder.Log2Fixed(v);
|
||||
Assert.IsGreaterThanOrEqualTo(previous, log);
|
||||
previous = log;
|
||||
}
|
||||
|
||||
Assert.AreEqual(10L << 16, Vp8LEncoder.Log2Fixed(1024));
|
||||
Assert.AreEqual(20L << 16, Vp8LEncoder.Log2Fixed(1UL << 20));
|
||||
Assert.AreEqual(0L, Vp8LEncoder.Log2Fixed(1));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TheSameFormatIsCopiedAsItIs()
|
||||
{
|
||||
using var picture = Gradient(16, 16, seed: 3);
|
||||
var png = ImageConverter.Encode(picture, ImageFormat.Png, null);
|
||||
|
||||
var check = ImageConverter.Check(png, ImageFormat.Png);
|
||||
|
||||
Assert.AreEqual(ImageConversionAction.CopyAsIs, check.Action);
|
||||
Assert.IsNull(check.NoteCode);
|
||||
Assert.AreEqual(ImageConversionAction.Convert, ImageConverter.Check(png, ImageFormat.Jpeg).Action);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AnimationsAndDamagedFilesAreCopiedWithTheirReason()
|
||||
{
|
||||
byte[] indices = [0, 1];
|
||||
var animated = Gif(2, 1, Palette4, GifFrame(0, 0, 2, 1, indices, 2), GifControl(1), GifFrame(0, 0, 2, 1, indices, 2));
|
||||
var still = Gif(2, 1, Palette4, GifFrame(0, 0, 2, 1, indices, 2));
|
||||
|
||||
Assert.AreEqual(ImageConversionLosses.AsIsAnimated, ImageConverter.Check(animated, ImageFormat.Png).NoteCode);
|
||||
Assert.AreEqual(ImageConversionAction.Convert, ImageConverter.Check(still, ImageFormat.Png).Action);
|
||||
var damaged = ImageConverter.Check(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, ImageFormat.Jpeg);
|
||||
Assert.AreEqual(ImageConversionAction.CopyOriginal, damaged.Action);
|
||||
Assert.AreEqual(ImageConversionLosses.AsIsNotDecodable, damaged.NoteCode);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TransparencyToJpgIsAnnouncedAndTheImageIsLeftAlone()
|
||||
{
|
||||
using var picture = Random(8, 8, seed: 11);
|
||||
var before = picture.ToArray();
|
||||
var png = ImageConverter.Encode(picture, ImageFormat.Png, null);
|
||||
|
||||
var result = ImageConverter.Convert(png, ImageFormat.Jpeg);
|
||||
_ = ImageConverter.Encode(picture, ImageFormat.Jpeg, null);
|
||||
|
||||
CollectionAssert.Contains(result.Losses.ToList(), ImageConversionLosses.TransparencyWhite);
|
||||
CollectionAssert.AreEqual(before, picture.ToArray(), "Encode lavora su una copia.");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user