Codec di casa al posto di SkiaSharp (C1, passo 5)
SkiaSharp e SkiaSharp.NativeAssets.Linux.NoDependencies escono da Directory.Packages.props e da ogni progetto, per la regola «niente componenti esterni». Tutto ciò che leggeva, ridimensionava o disegnava immagini con Skia ora usa codice scritto in casa sulla BCL: - ImageResampler: Lanczos3 separabile o media per area, alfa premoltiplicata, luce lineare facoltativa; ImageGray per l'impronta. - Il lettore JPEG decodifica ridotto a 1/2, 1/4, 1/8; le miniature chiedono almeno il doppio del lato lungo, così l'ultimo passo resta a Lanczos e la miniatura resta uguale alla lettura intera. - ImageOrientation applica l'EXIF in un punto solo (miniature, impronte, anteprime, dimensioni mostrate). - ImageConverter cambia formato fra JPEG, PNG e WebP portando EXIF, ICC, XMP e testi, con l'etichetta d'orientamento e i pixel non ruotati; PngEncoder scrive anche i testi (tEXt o iTXt). - Febe.Core.Drawing: rasterizzatore con antialiasing (tracciati, riempimenti, tratti, gradienti) per icona, immagini dimostrative, riquadro neutro dei video, foto del sito di prova e prove. Febe.ico rigenerata. - ThumbnailStore legge anche i BMP a 24 bit, come quelli del decoder video del ramo funzione/decoder-h264. Le impronte salvate restano confrontabili (390 su 393 campioni identiche, le altre a distanza 2, soglia 6): nessun ricalcolo. Un PNG o JPEG troncato ora non ha miniatura né impronta. Documenti, elenco dei componenti della pagina «Informazioni» e decisioni aggiornati; nuove prove per ridimensionamento, orientamento, lettura ridotta, conversione con metadati, testi PNG e rasterizzatore. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b4383a6110
commit
d6a6a68496
47 files changed
+3391
-562
No files matched your search
@@ -1,12 +1,12 @@
|
||||
using System.Buffers.Binary;
|
||||
using Febe.Core.Codecs.Images;
|
||||
using Febe.Desktop.Core;
|
||||
using Febe.Tests.Desktop.Support;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Febe.Tests.Desktop;
|
||||
|
||||
/// <summary>
|
||||
/// The icon of the Windows application (spec §12, appendix C): the brand mark drawn with SkiaSharp and written by the
|
||||
/// The icon of the Windows application (spec §12, appendix C): the brand mark drawn with Febe's own canvas and written by the
|
||||
/// hand-made ICO writer, at 16, 24, 32, 48, 64, 128 and 256 pixels. The committed <c>src/Febe.Desktop/Febe.ico</c> must be
|
||||
/// what the code draws: <c>FEBE_RIGENERA_ICONA=1 dotnet test --filter IconTests</c> writes it again.
|
||||
/// </summary>
|
||||
@@ -53,28 +53,28 @@ public sealed class IconTests
|
||||
{
|
||||
using var image = IcoWriter.Decode(ico, entry);
|
||||
var s = entry.Size;
|
||||
Assert.AreEqual(0, image.GetPixel(0, 0).Alpha, $"{s}: transparent corner");
|
||||
Assert.AreEqual(0, image.GetPixel(s - 1, s - 1).Alpha, $"{s}: transparent corner");
|
||||
Assert.AreEqual(0, image.GetPixel(0, 0).A, $"{s}: transparent corner");
|
||||
Assert.AreEqual(0, image.GetPixel(s - 1, s - 1).A, $"{s}: transparent corner");
|
||||
|
||||
// Inside the square, away from ring and moon (x=4/32, y=28/32): the accent colour #0F5C8C.
|
||||
var accent = image.GetPixel(Scale(4, s), Scale(28, s));
|
||||
if (s >= 24)
|
||||
{
|
||||
AssertClose(new SKColor(0x0F, 0x5C, 0x8C, 0xFF), accent, 6, $"{s}: accent");
|
||||
AssertClose(Accent, accent, 6, $"{s}: accent");
|
||||
}
|
||||
|
||||
// The centre of the moon (23.2, 8.8) is white.
|
||||
var moon = image.GetPixel(Scale(23.2, s), Scale(8.8, s));
|
||||
if (s >= 32)
|
||||
{
|
||||
AssertClose(SKColors.White, moon, 10, $"{s}: moon");
|
||||
AssertClose(White, moon, 10, $"{s}: moon");
|
||||
}
|
||||
|
||||
// The centre of the ring (14.5, 17.5) is the accent, not white: it is a ring, not a disc.
|
||||
var hole = image.GetPixel(Scale(14.5, s), Scale(17.5, s));
|
||||
if (s >= 32)
|
||||
{
|
||||
AssertClose(new SKColor(0x0F, 0x5C, 0x8C, 0xFF), hole, 6, $"{s}: ring hole");
|
||||
AssertClose(Accent, hole, 6, $"{s}: ring hole");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,8 +82,8 @@ public sealed class IconTests
|
||||
[TestMethod]
|
||||
public void TheWriterRefusesImagesThatAreNotSquareOrTooLarge()
|
||||
{
|
||||
using var wide = new SKBitmap(32, 16);
|
||||
using var huge = new SKBitmap(512, 512);
|
||||
using var wide = new RgbaImage(32, 16);
|
||||
using var huge = new RgbaImage(512, 512);
|
||||
Assert.ThrowsExactly<ArgumentException>(() => IcoWriter.Write([wide]));
|
||||
Assert.ThrowsExactly<ArgumentException>(() => IcoWriter.Write([huge]));
|
||||
Assert.ThrowsExactly<ArgumentException>(() => IcoWriter.Write([]));
|
||||
@@ -106,7 +106,7 @@ public sealed class IconTests
|
||||
var b = IcoWriter.ReadDirectory(fresh);
|
||||
CollectionAssert.AreEqual(b.Select(e => e.Size).ToArray(), a.Select(e => e.Size).ToArray());
|
||||
|
||||
// Pixel by pixel, with a small tolerance (antialiasing may differ by a unit between SkiaSharp builds).
|
||||
// Pixel by pixel, with a small tolerance (the drawing is in floating point).
|
||||
for (var i = 0; i < a.Count; i++)
|
||||
{
|
||||
using var left = IcoWriter.Decode(committed, a[i]);
|
||||
@@ -123,12 +123,16 @@ public sealed class IconTests
|
||||
|
||||
private static int Scale(double coordinate, int size) => Math.Clamp((int)Math.Floor(coordinate * size / 32), 0, size - 1);
|
||||
|
||||
private static void AssertClose(SKColor expected, SKColor actual, int tolerance, string what)
|
||||
private static readonly (byte R, byte G, byte B, byte A) Accent = (0x0F, 0x5C, 0x8C, 0xFF);
|
||||
|
||||
private static readonly (byte R, byte G, byte B, byte A) White = (0xFF, 0xFF, 0xFF, 0xFF);
|
||||
|
||||
private static void AssertClose((byte R, byte G, byte B, byte A) expected, (byte R, byte G, byte B, byte A) actual, int tolerance, string what)
|
||||
{
|
||||
var ok = Math.Abs(expected.Red - actual.Red) <= tolerance
|
||||
&& Math.Abs(expected.Green - actual.Green) <= tolerance
|
||||
&& Math.Abs(expected.Blue - actual.Blue) <= tolerance
|
||||
&& Math.Abs(expected.Alpha - actual.Alpha) <= tolerance;
|
||||
var ok = Math.Abs(expected.R - actual.R) <= tolerance
|
||||
&& Math.Abs(expected.G - actual.G) <= tolerance
|
||||
&& Math.Abs(expected.B - actual.B) <= tolerance
|
||||
&& Math.Abs(expected.A - actual.A) <= tolerance;
|
||||
Assert.IsTrue(ok, $"{what}: atteso {expected}, trovato {actual}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user