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,13 +1,15 @@
|
||||
using System.Buffers.Binary;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Security.Cryptography;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using SkiaSharp;
|
||||
using Febe.Core.Codecs.Images;
|
||||
using Febe.Core.Drawing;
|
||||
|
||||
namespace Febe.SitoDiProva;
|
||||
|
||||
/// <summary>
|
||||
/// Generates the files the «CDN» serves: JPEG pictures drawn with SkiaSharp from the media key (same key, same
|
||||
/// Generates the files the «CDN» serves: JPEG pictures drawn with Febe's own canvas and JPEG writer from the media key (same key, same
|
||||
/// picture at every size) and short MP4 videos made unique with a trailing «free» box. Results are cached.
|
||||
/// </summary>
|
||||
public sealed class MediaFactory
|
||||
@@ -39,45 +41,34 @@ public sealed class MediaFactory
|
||||
{
|
||||
var seed = BinaryPrimitives.ReadInt32LittleEndian(SHA256.HashData(Encoding.UTF8.GetBytes(key)));
|
||||
var random = new Random(seed);
|
||||
using var bitmap = new SKBitmap(new SKImageInfo(width, height, SKColorType.Rgba8888, SKAlphaType.Premul));
|
||||
using (var canvas = new SKCanvas(bitmap))
|
||||
using var image = new RgbaImage(width, height);
|
||||
using (var canvas = new Canvas(image))
|
||||
{
|
||||
SKColor RandomColor() => new((byte)random.Next(256), (byte)random.Next(256), (byte)random.Next(256));
|
||||
using (var background = new SKPaint())
|
||||
{
|
||||
background.Shader = SKShader.CreateLinearGradient(
|
||||
new SKPoint(0, 0),
|
||||
new SKPoint(width, height),
|
||||
[RandomColor(), RandomColor(), RandomColor()],
|
||||
null,
|
||||
SKShaderTileMode.Clamp);
|
||||
canvas.DrawRect(0, 0, width, height, background);
|
||||
}
|
||||
Color RandomColor() => new((byte)random.Next(256), (byte)random.Next(256), (byte)random.Next(256));
|
||||
var background = new LinearGradientBrush(new Vector2(0, 0), new Vector2(width, height), [RandomColor(), RandomColor(), RandomColor()]);
|
||||
canvas.FillRect(0, 0, width, height, background);
|
||||
|
||||
// Shapes in relative coordinates: every size shows the same picture.
|
||||
using var paint = new SKPaint { IsAntialias = true };
|
||||
var shapes = 8 + random.Next(8);
|
||||
for (var i = 0; i < shapes; i++)
|
||||
{
|
||||
paint.Color = RandomColor().WithAlpha((byte)(150 + random.Next(100)));
|
||||
var color = RandomColor().WithAlpha((byte)(150 + random.Next(100)));
|
||||
var x = (float)(random.NextDouble() * width);
|
||||
var y = (float)(random.NextDouble() * height);
|
||||
var w = (float)((0.08 + (random.NextDouble() * 0.35)) * width);
|
||||
var h = (float)((0.08 + (random.NextDouble() * 0.35)) * height);
|
||||
if (random.Next(2) == 0)
|
||||
{
|
||||
canvas.DrawRect(x - (w / 2), y - (h / 2), w, h, paint);
|
||||
canvas.FillRect(x - (w / 2), y - (h / 2), w, h, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
canvas.DrawOval(new SKRect(x - (w / 2), y - (h / 2), x + (w / 2), y + (h / 2)), paint);
|
||||
canvas.FillEllipse(x, y, w / 2, h / 2, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using var image = SKImage.FromBitmap(bitmap);
|
||||
using var data = image.Encode(SKEncodedImageFormat.Jpeg, 85);
|
||||
return data.ToArray();
|
||||
return JpegEncoder.Encode(image, new JpegEncoderOptions { Quality = 85 });
|
||||
}
|
||||
|
||||
private static byte[] ReadResource(string name)
|
||||
|
||||
Reference in new issue
Block a user