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:
Alby96andClaude Opus 5.5 committed 2026-11-18 16:02:03 +01:00
1 parent b4383a6110
commit d6a6a68496
47 files changed
+3391 -562

No files matched your search

+89 -105
View File
@@ -1,4 +1,6 @@
using SkiaSharp;
using System.Numerics;
using Febe.Core.Codecs.Images;
using Febe.Core.Drawing;
namespace Febe.Web.Demo;
@@ -35,8 +37,8 @@ public static class DemoImages
{
ArgumentOutOfRangeException.ThrowIfLessThan(width, 16);
ArgumentOutOfRangeException.ThrowIfLessThan(height, 16);
using var bitmap = new SKBitmap(new SKImageInfo(width, height, SKColorType.Rgba8888, SKAlphaType.Premul));
using (var canvas = new SKCanvas(bitmap))
var image = new RgbaImage(width, height);
using (var canvas = new Canvas(image))
{
var painter = new Painter(canvas, width, height, new Random(seed * 7919 + (int)subject));
switch (subject)
@@ -59,64 +61,54 @@ public static class DemoImages
}
}
using var image = SKImage.FromBitmap(bitmap);
using var data = image.Encode(SKEncodedImageFormat.Jpeg, quality);
return data.ToArray();
return JpegEncoder.Encode(image, new JpegEncoderOptions { Quality = quality });
}
private sealed class Painter(SKCanvas canvas, float w, float h, Random random)
/// <summary>A rectangle by its edges.</summary>
private readonly record struct Box(float Left, float Top, float Right, float Bottom);
private sealed class Painter(Canvas canvas, float w, float h, Random random)
{
private float R(float min, float max) => min + ((float)random.NextDouble() * (max - min));
private T Pick<T>(params T[] items) => items[random.Next(items.Length)];
private static SKColor C(uint rgb) => new((byte)(rgb >> 16), (byte)(rgb >> 8), (byte)rgb);
private static Color C(uint rgb) => Color.FromRgb(rgb);
private static SKColor Mix(SKColor a, SKColor b, float t) => new(
(byte)(a.Red + ((b.Red - a.Red) * t)),
(byte)(a.Green + ((b.Green - a.Green) * t)),
(byte)(a.Blue + ((b.Blue - a.Blue) * t)));
private static Color Mix(Color a, Color b, float t) => a.Mix(b, t).WithAlpha(255);
private void Gradient(SKRect rect, SKColor top, SKColor bottom)
private void Gradient(Box rect, Color top, Color bottom) =>
canvas.FillRect(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top, new LinearGradientBrush(new Vector2(0, rect.Top), new Vector2(0, rect.Bottom), [top, bottom]));
private void Fill(PathBuilder path, Color color) => canvas.Fill(path, color);
private void Circle(float x, float y, float r, Color color) => canvas.FillCircle(x, y, r, color);
private void Oval(float cx, float cy, float rx, float ry, Color color, float rotate = 0)
{
using var paint = new SKPaint { IsAntialias = true };
paint.Shader = SKShader.CreateLinearGradient(new SKPoint(0, rect.Top), new SKPoint(0, rect.Bottom), [top, bottom], null, SKShaderTileMode.Clamp);
canvas.DrawRect(rect, paint);
}
private void Fill(SKPathBuilder builder, SKColor color)
{
using var path = builder.Detach();
using var paint = new SKPaint { IsAntialias = true, Color = color, Style = SKPaintStyle.Fill };
canvas.DrawPath(path, paint);
}
private void Circle(float x, float y, float r, SKColor color)
{
using var paint = new SKPaint { IsAntialias = true, Color = color };
canvas.DrawCircle(x, y, r, paint);
}
private void Oval(float cx, float cy, float rx, float ry, SKColor color, float rotate = 0)
{
using var paint = new SKPaint { IsAntialias = true, Color = color };
canvas.Save();
canvas.Translate(cx, cy);
canvas.RotateDegrees(rotate);
canvas.DrawOval(new SKRect(-rx, -ry, rx, ry), paint);
canvas.Rotate(rotate);
canvas.FillEllipse(0, 0, rx, ry, color);
canvas.Restore();
}
private void Rect(float x, float y, float rw, float rh, SKColor color, float radius = 0)
private void Rect(float x, float y, float rw, float rh, Color color, float radius = 0)
{
using var paint = new SKPaint { IsAntialias = true, Color = color };
canvas.DrawRoundRect(new SKRect(x, y, x + rw, y + rh), radius, radius, paint);
if (radius > 0)
{
canvas.FillRoundRect(x, y, rw, rh, radius, color);
}
else
{
canvas.FillRect(x, y, rw, rh, color);
}
}
/// <summary>A soft ridge across the picture at height <paramref name="baseY"/>, filled down to the bottom.</summary>
private static SKPathBuilder Ridge(float w, float h, float baseY, float amplitude, int bumps, float phase)
private static PathBuilder Ridge(float w, float h, float baseY, float amplitude, int bumps, float phase)
{
var path = new SKPathBuilder();
var path = new PathBuilder();
path.MoveTo(0, h);
const int steps = 48;
for (var i = 0; i <= steps; i++)
@@ -138,23 +130,23 @@ public static class DemoImages
var cx = R(-0.1f, 1.1f) * w;
var cy = R(top, bottom) * h;
var size = R(0.07f, 0.13f) * Math.Max(w, h);
var color = new SKColor(255, 255, 255, (byte)R(200, 240));
var color = new Color(255, 255, 255, (byte)R(200, 240));
Oval(cx, cy, size, size * 0.32f, color);
Oval(cx - (size * 0.35f), cy + (size * 0.05f), size * 0.55f, size * 0.25f, color);
Oval(cx + (size * 0.25f), cy - (size * 0.12f), size * 0.5f, size * 0.3f, new SKColor(255, 255, 255, (byte)R(220, 250)));
Oval(cx + (size * 0.25f), cy - (size * 0.12f), size * 0.5f, size * 0.3f, new Color(255, 255, 255, (byte)R(220, 250)));
}
}
private void Cypress(float x, float baseY, float size, SKColor color)
private void Cypress(float x, float baseY, float size, Color color)
{
Oval(x, baseY - (size * 0.55f), size * 0.22f, size * 0.55f, color);
Rect(x - (size * 0.03f), baseY - (size * 0.08f), size * 0.06f, size * 0.12f, Mix(color, SKColors.Black, 0.3f));
Rect(x - (size * 0.03f), baseY - (size * 0.08f), size * 0.06f, size * 0.12f, Mix(color, Color.Black, 0.3f));
}
public void Hills(bool road)
{
var sky = Pick(C(0x6FA8DC), C(0x7FB3E0), C(0x5E9BD6), C(0x8DBBE3));
Gradient(new SKRect(0, 0, w, h), sky, Mix(sky, SKColors.White, 0.45f));
Gradient(new Box(0, 0, w, h), sky, Mix(sky, Color.White, 0.45f));
Clouds(0.08f, 0.35f, random.Next(2, 5));
var greens = Pick(
new[] { C(0x8DB867), C(0x6E9E4C), C(0x4F8A3E), C(0x3C7232) },
@@ -164,7 +156,7 @@ public static class DemoImages
for (var layer = 0; layer < 4; layer++)
{
var y = baseY + (layer * h * R(0.08f, 0.12f));
using var ridge = Ridge(w, h, y, h * R(0.015f, 0.04f), random.Next(1, 4), R(0, 6));
var ridge = Ridge(w, h, y, h * R(0.015f, 0.04f), random.Next(1, 4), R(0, 6));
Fill(ridge, greens[layer]);
if (!road && layer < 3)
{
@@ -178,7 +170,7 @@ public static class DemoImages
if (road)
{
var horizon = baseY + (h * 0.03f);
using var path = new SKPathBuilder();
var path = new PathBuilder();
path.MoveTo(w * 0.47f, horizon);
path.LineTo(w * 0.53f, horizon);
path.LineTo(w * 0.86f, h);
@@ -208,13 +200,13 @@ public static class DemoImages
public void Mountains()
{
var sky = Pick(C(0x5D8FC8), C(0x6E9BD0), C(0x7FA8D6));
Gradient(new SKRect(0, 0, w, h), sky, Mix(sky, SKColors.White, 0.55f));
Gradient(new Box(0, 0, w, h), sky, Mix(sky, Color.White, 0.55f));
var ranges = new[] { C(0x8C9BB2), C(0x6F7F99), C(0x56647E) };
for (var r = 0; r < 3; r++)
{
var baseY = h * (0.55f + (r * 0.08f));
var peaks = random.Next(2, 4) + r;
using var path = new SKPathBuilder();
var path = new PathBuilder();
path.MoveTo(0, h);
path.LineTo(0, baseY);
var snow = new List<(float X, float Y, float Half)>();
@@ -239,7 +231,7 @@ public static class DemoImages
{
var depth = (baseY - py) * 0.32f;
var ratio = depth / (baseY - py);
using var cap = new SKPathBuilder();
var cap = new PathBuilder();
cap.MoveTo(px, py);
cap.LineTo(px + (half * ratio), py + depth);
cap.LineTo(px + (half * ratio * 0.3f), py + (depth * 0.8f));
@@ -260,7 +252,7 @@ public static class DemoImages
var x = R(0, 1) * w;
var size = h * R(0.06f, 0.11f);
var y = groundY + (h * R(-0.01f, 0.08f));
using var tree = new SKPathBuilder();
var tree = new PathBuilder();
tree.MoveTo(x, y - size);
tree.LineTo(x + (size * 0.28f), y);
tree.LineTo(x - (size * 0.28f), y);
@@ -273,16 +265,16 @@ public static class DemoImages
{
var top = Pick(C(0x3B2A5A), C(0x4A2F63), C(0x2E2350));
var bottom = Pick(C(0xF0784C), C(0xE86A5A), C(0xF29A57));
Gradient(new SKRect(0, 0, w, h * 0.75f), top, bottom);
Gradient(new Box(0, 0, w, h * 0.75f), top, bottom);
var sunX = w * R(0.35f, 0.65f);
var sunY = h * R(0.5f, 0.6f);
var r = Math.Min(w, h) * R(0.09f, 0.13f);
Circle(sunX, sunY, r * 1.8f, new SKColor(255, 220, 170, 60));
Circle(sunX, sunY, r * 1.8f, new Color(255, 220, 170, 60));
Circle(sunX, sunY, r, C(0xFBE3B0));
var hills = new[] { C(0x6B4A73), C(0x4E3A63), C(0x35294D) };
for (var i = 0; i < 3; i++)
{
using var ridge = Ridge(w, h, h * (0.66f + (i * 0.09f)), h * R(0.02f, 0.05f), random.Next(1, 3), R(0, 6));
var ridge = Ridge(w, h, h * (0.66f + (i * 0.09f)), h * R(0.02f, 0.05f), random.Next(1, 3), R(0, 6));
Fill(ridge, hills[i]);
}
}
@@ -291,32 +283,31 @@ public static class DemoImages
{
var sky = Pick(C(0x8CC4E8), C(0x7BB8E2), C(0x9CCDEB));
var horizon = h * R(0.42f, 0.55f);
Gradient(new SKRect(0, 0, w, horizon), Mix(sky, C(0x4F8FC8), 0.3f), Mix(sky, SKColors.White, 0.5f));
Gradient(new Box(0, 0, w, horizon), Mix(sky, C(0x4F8FC8), 0.3f), Mix(sky, Color.White, 0.5f));
Clouds(0.08f, 0.25f, random.Next(0, 3));
var water = Pick(C(0x2AA3C1), C(0x1F8FB3), C(0x31A9BE));
var sand = random.Next(3) == 0;
Gradient(new SKRect(0, horizon, w, h), water, Mix(water, C(0x0B4A6B), 0.55f));
using (var wave = new SKPaint { IsAntialias = true, Color = new SKColor(255, 255, 255, 110), StrokeWidth = Math.Max(2, h * 0.004f), StrokeCap = SKStrokeCap.Round })
Gradient(new Box(0, horizon, w, h), water, Mix(water, C(0x0B4A6B), 0.55f));
var foam = new Color(255, 255, 255, 110);
var waveWidth = Math.Max(2, h * 0.004f);
for (var i = 0; i < 9; i++)
{
for (var i = 0; i < 9; i++)
{
var y = horizon + ((h - horizon) * R(0.1f, 0.9f));
var x = R(0.05f, 0.85f) * w;
canvas.DrawLine(x, y, x + (w * R(0.03f, 0.08f)), y, wave);
}
var y = horizon + ((h - horizon) * R(0.1f, 0.9f));
var x = R(0.05f, 0.85f) * w;
canvas.DrawLine(x, y, x + (w * R(0.03f, 0.08f)), y, waveWidth, foam, LineCap.Round);
}
if (sand)
{
using var shore = Ridge(w, h, h * 0.9f, h * 0.02f, 2, R(0, 6));
var shore = Ridge(w, h, h * 0.9f, h * 0.02f, 2, R(0, 6));
Fill(shore, C(0xE9D8B4));
}
var bx = w * R(0.3f, 0.65f);
var by = horizon + ((h - horizon) * R(0.2f, 0.4f));
var s = Math.Min(w, h) * R(0.06f, 0.09f);
using (var sail = new SKPathBuilder())
{
var sail = new PathBuilder();
sail.MoveTo(bx, by - s);
sail.LineTo(bx + (s * 0.45f), by - (s * 0.1f));
sail.LineTo(bx, by - (s * 0.1f));
@@ -324,8 +315,8 @@ public static class DemoImages
Fill(sail, C(0xF6F6F4));
}
using (var sail2 = new SKPathBuilder())
{
var sail2 = new PathBuilder();
sail2.MoveTo(bx - (s * 0.04f), by - (s * 0.85f));
sail2.LineTo(bx - (s * 0.04f), by - (s * 0.12f));
sail2.LineTo(bx - (s * 0.38f), by - (s * 0.12f));
@@ -333,8 +324,8 @@ public static class DemoImages
Fill(sail2, C(0xE0533F));
}
using (var hull = new SKPathBuilder())
{
var hull = new PathBuilder();
hull.MoveTo(bx - (s * 0.5f), by - (s * 0.05f));
hull.LineTo(bx + (s * 0.55f), by - (s * 0.05f));
hull.LineTo(bx + (s * 0.4f), by + (s * 0.1f));
@@ -346,10 +337,10 @@ public static class DemoImages
public void City()
{
Gradient(new SKRect(0, 0, w, h), C(0x1E1B3A), Pick(C(0x3E2F5C), C(0x4A3566), C(0x2F2A52)));
Gradient(new Box(0, 0, w, h), C(0x1E1B3A), Pick(C(0x3E2F5C), C(0x4A3566), C(0x2F2A52)));
for (var i = 0; i < 70; i++)
{
Circle(R(0, 1) * w, R(0, 0.45f) * h, R(0.6f, 1.8f), new SKColor(255, 255, 255, (byte)R(60, 180)));
Circle(R(0, 1) * w, R(0, 0.45f) * h, R(0.6f, 1.8f), new Color(255, 255, 255, (byte)R(60, 180)));
}
for (var layer = 0; layer < 2; layer++)
@@ -384,7 +375,7 @@ public static class DemoImages
public void Leaves(bool flowers)
{
var dark = Pick(C(0x1F4D33), C(0x24533A), C(0x2B5C3C));
Gradient(new SKRect(0, 0, w, h), Mix(dark, SKColors.Black, 0.1f), dark);
Gradient(new Box(0, 0, w, h), Mix(dark, Color.Black, 0.1f), dark);
var greens = new[] { C(0x3E8C4E), C(0x5AA45A), C(0x2F7A45), C(0x78B861), C(0x4C9A6A), C(0x8BC46A) };
var size = Math.Max(w, h);
for (var i = 0; i < 46; i++)
@@ -395,11 +386,10 @@ public static class DemoImages
var angle = R(0, 360);
var color = greens[random.Next(greens.Length)];
Oval(cx, cy, rx, rx * 0.42f, color, angle);
using var vein = new SKPaint { IsAntialias = true, Color = Mix(color, SKColors.White, 0.25f), StrokeWidth = Math.Max(1.5f, size * 0.003f) };
canvas.Save();
canvas.Translate(cx, cy);
canvas.RotateDegrees(angle);
canvas.DrawLine(-rx * 0.85f, 0, rx * 0.85f, 0, vein);
canvas.Rotate(angle);
canvas.DrawLine(-rx * 0.85f, 0, rx * 0.85f, 0, Math.Max(1.5f, size * 0.003f), Mix(color, Color.White, 0.25f));
canvas.Restore();
}
@@ -426,21 +416,16 @@ public static class DemoImages
{
var table = Pick(C(0xE9E6E1), C(0xEFEBE4), C(0xDCD7CF));
Rect(0, 0, w, h, table);
using (var line = new SKPaint { IsAntialias = true, Color = Mix(table, SKColors.Black, 0.08f), StrokeWidth = Math.Max(2, w * 0.004f) })
var grooves = Mix(table, Color.Black, 0.08f);
for (var y = h * 0.12f; y < h; y += h * 0.16f)
{
for (var y = h * 0.12f; y < h; y += h * 0.16f)
{
canvas.DrawLine(0, y, w, y + (h * 0.01f), line);
}
canvas.DrawLine(0, y, w, y + (h * 0.01f), Math.Max(2, w * 0.004f), grooves);
}
var r = Math.Min(w, h) * R(0.28f, 0.34f);
var cx = w * R(0.42f, 0.55f);
var cy = h * R(0.48f, 0.58f);
using (var shadow = new SKPaint { IsAntialias = true, Color = new SKColor(0, 0, 0, 40), MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, r * 0.06f) })
{
canvas.DrawCircle(cx + (r * 0.04f), cy + (r * 0.06f), r, shadow);
}
canvas.FillBlurredCircle(cx + (r * 0.04f), cy + (r * 0.06f), r, r * 0.06f, new Color(0, 0, 0, 40));
Circle(cx, cy, r, C(0xFAFAF8));
Circle(cx, cy, r * 0.78f, C(0xF0EEEA));
@@ -458,24 +443,23 @@ public static class DemoImages
var cr = Math.Min(w, h) * 0.085f;
Circle(cupX, cupY, cr, C(0xF5F3EF));
Circle(cupX, cupY, cr * 0.75f, C(0x5B3A26));
using var fork = new SKPaint { IsAntialias = true, Color = C(0xC9C6C0), StrokeWidth = Math.Max(3, w * 0.008f), StrokeCap = SKStrokeCap.Round };
canvas.DrawLine(cx + (r * 1.18f), cy - (r * 0.5f), cx + (r * 1.18f), cy + (r * 0.75f), fork);
canvas.DrawLine(cx + (r * 1.18f), cy - (r * 0.5f), cx + (r * 1.18f), cy + (r * 0.75f), Math.Max(3, w * 0.008f), C(0xC9C6C0), LineCap.Round);
}
public void Portrait()
{
var bg = Pick(C(0xB27FC0), C(0xC98F9B), C(0x8FA8C9), C(0xD3A26F), C(0x7FB8A3), C(0xA88FC7));
Gradient(new SKRect(0, 0, w, h), Mix(bg, SKColors.White, 0.15f), Mix(bg, SKColors.Black, 0.12f));
Gradient(new Box(0, 0, w, h), Mix(bg, Color.White, 0.15f), Mix(bg, Color.Black, 0.12f));
var skin = Pick(C(0xD9A27B), C(0xC88A63), C(0xA86F4D), C(0xE8B996), C(0x8D5A3B));
var hair = Pick(C(0x8A4B2A), C(0x3B2A20), C(0xD8B45A), C(0x5A3A22), C(0x1F1B18));
var shirt = Pick(C(0xA8B04A), C(0x5F8F57), C(0xB84A4A), C(0x4F6FA8), C(0xE0C35A));
var cx = w * 0.5f;
var unit = Math.Min(w, h * 0.8f);
Oval(cx, h * 1.02f, unit * 0.42f, h * 0.32f, shirt);
Rect(cx - (unit * 0.06f), h * 0.52f, unit * 0.12f, h * 0.16f, Mix(skin, SKColors.Black, 0.08f));
Rect(cx - (unit * 0.06f), h * 0.52f, unit * 0.12f, h * 0.16f, Mix(skin, Color.Black, 0.08f));
Oval(cx, h * 0.44f, unit * 0.16f, unit * 0.2f, skin);
using var top = new SKPathBuilder();
top.AddArc(new SKRect(cx - (unit * 0.17f), (h * 0.44f) - (unit * 0.22f), cx + (unit * 0.17f), (h * 0.44f) + (unit * 0.04f)), 180, 180);
var top = new PathBuilder();
top.AddArc(cx - (unit * 0.17f), (h * 0.44f) - (unit * 0.22f), cx + (unit * 0.17f), (h * 0.44f) + (unit * 0.04f), 180, 180);
top.Close();
Fill(top, hair);
}
@@ -484,23 +468,23 @@ public static class DemoImages
{
var wall = Pick(C(0xE5DFCF), C(0xE9E2D2), C(0xDCD6C6));
var floorY = h * R(0.68f, 0.74f);
Gradient(new SKRect(0, 0, w, floorY), Mix(wall, SKColors.White, 0.2f), wall);
Gradient(new SKRect(0, floorY, w, h), C(0xC9AE84), C(0xB89A6E));
Gradient(new Box(0, 0, w, floorY), Mix(wall, Color.White, 0.2f), wall);
Gradient(new Box(0, floorY, w, h), C(0xC9AE84), C(0xB89A6E));
var winX = w * R(0.25f, 0.45f);
var winW = w * R(0.26f, 0.34f);
var winY = h * 0.1f;
var winH = h * 0.38f;
Rect(winX - 6, winY - 6, winW + 12, winH + 12, C(0xF7F7F5));
Gradient(new SKRect(winX, winY, winX + winW, winY + winH), C(0x9CCBEB), C(0xC9E4F4));
Gradient(new Box(winX, winY, winX + winW, winY + winH), C(0x9CCBEB), C(0xC9E4F4));
Rect(winX + (winW / 2) - 3, winY, 6, winH, C(0xF7F7F5));
Rect(winX, winY + (winH / 2) - 3, winW, 6, C(0xF7F7F5));
var sofa = Pick(C(0x6E9F7A), C(0x4E8F86), C(0x8A6A9E), C(0xA05A5A));
var sx = w * R(0.05f, 0.15f);
var sw = w * R(0.48f, 0.58f);
Rect(sx, floorY - (h * 0.2f), sw, h * 0.12f, Mix(sofa, SKColors.White, 0.15f), 10);
Rect(sx, floorY - (h * 0.2f), sw, h * 0.12f, Mix(sofa, Color.White, 0.15f), 10);
Rect(sx, floorY - (h * 0.1f), sw, h * 0.12f, sofa, 10);
var px = w * R(0.75f, 0.85f);
using var pot = new SKPathBuilder();
var pot = new PathBuilder();
pot.MoveTo(px - (w * 0.045f), floorY - (h * 0.08f));
pot.LineTo(px + (w * 0.045f), floorY - (h * 0.08f));
pot.LineTo(px + (w * 0.035f), floorY + (h * 0.01f));
@@ -518,34 +502,34 @@ public static class DemoImages
public void Bokeh()
{
Gradient(new SKRect(0, 0, w, h), C(0x1B1530), Pick(C(0x2A1E3A), C(0x1E1A2E)));
Gradient(new Box(0, 0, w, h), C(0x1B1530), Pick(C(0x2A1E3A), C(0x1E1A2E)));
var colors = new[] { C(0xF2B84B), C(0xE0567A), C(0x6BC5E8), C(0xB06BE0), C(0xF08A4B), C(0x7FD38A) };
var size = Math.Max(w, h);
for (var i = 0; i < 40; i++)
{
var color = colors[random.Next(colors.Length)].WithAlpha((byte)R(90, 200));
using var paint = new SKPaint { IsAntialias = true, Color = color, MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, size * R(0.004f, 0.012f)) };
canvas.DrawCircle(R(0, 1) * w, R(0, 1) * h, size * R(0.02f, 0.06f), paint);
var sigma = size * R(0.004f, 0.012f);
var x = R(0, 1) * w;
var y = R(0, 1) * h;
canvas.FillBlurredCircle(x, y, size * R(0.02f, 0.06f), sigma, color);
}
}
public void Concert()
{
Gradient(new SKRect(0, 0, w, h), C(0x14121C), C(0x1E1A2A));
Gradient(new Box(0, 0, w, h), C(0x14121C), C(0x1E1A2A));
var beams = new[] { C(0xE04A5A), C(0xF2C14B), C(0x4A7FE0), C(0xA04AE0), C(0x4AC0E0) };
for (var i = 0; i < 5; i++)
{
var x = w * (0.12f + (i * 0.19f)) + R(-0.04f, 0.04f) * w;
var color = beams[random.Next(beams.Length)];
using var paint = new SKPaint { IsAntialias = true };
paint.Shader = SKShader.CreateLinearGradient(new SKPoint(0, 0), new SKPoint(0, h * 0.75f), [color.WithAlpha(40), color.WithAlpha(190)], null, SKShaderTileMode.Clamp);
using var beam = new SKPathBuilder();
var light = new LinearGradientBrush(new Vector2(0, 0), new Vector2(0, h * 0.75f), [color.WithAlpha(40), color.WithAlpha(190)]);
var beam = new PathBuilder();
beam.MoveTo(x, 0);
beam.LineTo(x + (w * R(-0.12f, 0.12f)) + (w * 0.08f), h * 0.75f);
beam.LineTo(x + (w * R(-0.12f, 0.12f)) - (w * 0.08f), h * 0.75f);
beam.Close();
using var beamPath = beam.Detach();
canvas.DrawPath(beamPath, paint);
canvas.Fill(beam, light);
}
Rect(0, h * 0.72f, w, h * 0.04f, C(0x2B2838));
@@ -560,7 +544,7 @@ public static class DemoImages
public void Houses()
{
var sky = Pick(C(0x8CC4E8), C(0x9CCDEB));
Gradient(new SKRect(0, 0, w, h), sky, Mix(sky, SKColors.White, 0.4f));
Gradient(new Box(0, 0, w, h), sky, Mix(sky, Color.White, 0.4f));
var facades = new[] { C(0xF2C55C), C(0xE88B6A), C(0xF0A3A0), C(0xE5D37A), C(0xD9774F), C(0x9FC7B4), C(0xF4E2B8) };
var x = 0f;
while (x < w)
@@ -569,7 +553,7 @@ public static class DemoImages
var top = h * R(0.12f, 0.4f);
var color = facades[random.Next(facades.Length)];
Rect(x, top, fw, h - top, color);
Rect(x, top, fw, h * 0.02f, Mix(color, SKColors.Black, 0.2f));
Rect(x, top, fw, h * 0.02f, Mix(color, Color.Black, 0.2f));
var cell = fw / 5;
for (var wy = top + (cell * 0.8f); wy < h - cell; wy += cell * 1.4f)
{
+33 -23
View File
@@ -1,6 +1,8 @@
using System.Security.Cryptography;
using Febe.Core.Abstractions;
using Febe.Core.Codecs.Images;
using Febe.Core.Domain;
using Febe.Core.Drawing;
using Febe.Core.Library;
using Febe.Core.Storage;
using Febe.Web.Api;
@@ -8,7 +10,6 @@ using Febe.Web.Connection;
using Febe.Web.Engine;
using Febe.Web.Library;
using Microsoft.AspNetCore.Http;
using SkiaSharp;
namespace Febe.Web.Demo;
@@ -90,18 +91,18 @@ public sealed class DemoBrowserPreview(IHttpContextAccessor accessor, DemoWorld
const int width = 640;
const int height = 360;
using var bitmap = new SKBitmap(new SKImageInfo(width, height, SKColorType.Rgba8888, SKAlphaType.Premul));
using (var canvas = new SKCanvas(bitmap))
using var frame = new RgbaImage(width, height);
using (var canvas = new Canvas(frame))
{
canvas.Clear(new SKColor(0x1A, 0x1A, 0x1A));
canvas.Clear(new Color(0x1A, 0x1A, 0x1A));
var tall = height - 40f;
var wide = tall * 9 / 16;
var gap = 26f;
var left = (width - (3 * wide) - (2 * gap)) / 2;
using var dim = new SKPaint { Color = new SKColor(0, 0, 0, 110) };
var dim = new Color(0, 0, 0, 110);
for (var i = 0; i < files.Count; i++)
{
using var image = SKImage.FromEncodedData(files[i]);
using var image = DecodeOrNull(files[i]);
if (image is null)
{
continue;
@@ -112,18 +113,27 @@ public sealed class DemoBrowserPreview(IHttpContextAccessor accessor, DemoWorld
var h = tall * scale;
var x = left + (i * (wide + gap)) + ((wide - w) / 2);
var y = (height - h) / 2;
var rect = new SKRect(x, y, x + w, y + h);
canvas.DrawImage(image, rect, new SKSamplingOptions(SKCubicResampler.Mitchell));
canvas.DrawImage(image, x, y, w, h);
if (i != 1)
{
canvas.DrawRect(rect, dim);
canvas.FillRect(x, y, w, h, dim);
}
}
}
using var frame = SKImage.FromBitmap(bitmap);
using var encoded = frame.Encode(SKEncodedImageFormat.Jpeg, 80);
return encoded.ToArray();
return JpegEncoder.Encode(frame, new JpegEncoderOptions { Quality = 80 });
}
private static RgbaImage? DecodeOrNull(byte[] bytes)
{
try
{
return ImageDecoder.Decode(bytes);
}
catch (ImageDecodeException)
{
return null;
}
}
}
@@ -270,22 +280,22 @@ internal static class DemoDuplicates
/// <summary>The picture resized by <paramref name="scale"/> and recompressed: the same photo saved again, smaller.</summary>
public static (byte[] Bytes, int Width, int Height)? Variant(byte[] jpeg, double scale, int quality)
{
using var image = SKImage.FromEncodedData(jpeg);
if (image is null)
RgbaImage image;
try
{
image = ImageDecoder.Decode(jpeg);
}
catch (ImageDecodeException)
{
return null;
}
var width = Math.Max(16, (int)Math.Round(image.Width * scale));
var height = Math.Max(16, (int)Math.Round(image.Height * scale));
using var bitmap = new SKBitmap(new SKImageInfo(width, height, SKColorType.Rgba8888, SKAlphaType.Premul));
using (var canvas = new SKCanvas(bitmap))
using (image)
{
canvas.DrawImage(image, new SKRect(0, 0, width, height), new SKSamplingOptions(SKCubicResampler.Mitchell));
var width = Math.Max(16, (int)Math.Round(image.Width * scale));
var height = Math.Max(16, (int)Math.Round(image.Height * scale));
using var resized = ImageResampler.Resize(image, width, height);
return (JpegEncoder.Encode(resized, new JpegEncoderOptions { Quality = quality }), width, height);
}
using var result = SKImage.FromBitmap(bitmap);
using var encoded = result.Encode(SKEncodedImageFormat.Jpeg, quality);
return (encoded.ToArray(), width, height);
}
}
@@ -1,6 +1,6 @@
// Impostazioni, Informazioni: version and shell, where the guide is (the wiki of the repository), the folders, the
// statement on the risk for the account (spec §1, §15 «che cosa la guida deve dire»), the licenses of what Febe
// carries inside (Archivo OFL, Lucide ISC, SQLite, SkiaSharp, .NET, WebView2).
// carries inside (Archivo OFL, Lucide ISC, SQLite, .NET, WebView2). Images (codecs, thumbnails, drawing) are Febe's own code.
import { api } from '../core/api.js';
import { h, icon, fill, brand } from '../core/dom.js';
-1
View File
@@ -817,7 +817,6 @@
{ "nome": "Archivo", "testo": "carattere, SIL Open Font License 1.1", "file": "/caratteri/LICENZA-OFL.txt" },
{ "nome": "Lucide", "testo": "icone, licenza ISC", "file": "/icone/LICENZA-ISC.txt" },
{ "nome": "SQLite e Microsoft.Data.Sqlite", "testo": "database, pubblico dominio e licenza MIT" },
{ "nome": "SkiaSharp", "testo": "miniature e impronte delle immagini, licenza MIT" },
{ "nome": ".NET e ASP.NET Core", "testo": "licenza MIT" },
{ "nome": "WebView2", "testo": "solo versione Windows, licenza Microsoft" }
],