refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
The owner renamed the product and moved the repository to the self-hosted Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control, and asked for Actions and a first automatic release with the server package and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md). - Chronos everywhere: a byte-exact rename of contents and paths, then a per-language review of the forms the old name's ending had dictated. - Gitea instead of GitHub: the update check, licence, issue and support links read ChronosReleasesUrl; the update check takes the highest stable version, offers a pre-release build its final release and reports a repository it cannot see as a failed check. EULA, security policy and Gitea issue forms live at the repository root. - Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release, nightly image and performance gates in the .NET SDK container with git checkout and the system SQLite. The release cross-compiles the Windows programs, checks their icon, version and DPI manifest, packs installers and zips, publishes the Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER). - New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the docker-exec script, which Gitea's service containers do not allow; the throw-away server runs without durability) and pe-check. - Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR, 3 on the shared runner; the weekly performance gates keep theirs). BREAKING CHANGE: programs, settings, data folders, file types, environment variables and the Docker image use the new name; nothing is migrated from Titano, which never had a release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #6.
This commit is contained in:
1 parent
c99842cc86
commit
f2b58522b9
1801 files changed
+11804
-10676
No files matched your search
@@ -0,0 +1,290 @@
|
||||
using Chronos.Core.Codecs.Jpeg;
|
||||
using Chronos.Core.Codecs.Png;
|
||||
using Chronos.Core.Codecs.Raw;
|
||||
using Chronos.Core.Codecs.Tiff;
|
||||
using Chronos.Core.Diagnostics;
|
||||
using Chronos.Core.Metadata;
|
||||
|
||||
namespace Chronos.Core.Imaging.Decoders;
|
||||
|
||||
/// <summary>
|
||||
/// The managed decoder (BRIEF §8.2), available on every platform and the only one on the server: JPEG, PNG and TIFF
|
||||
/// natively; DNG and the supported camera RAWs (CR2, NEF, ARW, PEF, RAF) through <see cref="RawDecoder"/>; every other
|
||||
/// RAW, CR3 and HEIF through the largest suitable embedded JPEG preview, and GoPro GPR through the JPEG the camera writes
|
||||
/// with it (beside it, or where <see cref="DecodeRequest.Companion"/> says an import put it) when that is larger
|
||||
/// (BRIEF §8.1; VC-5 is out of scope); nothing for formats without either.
|
||||
/// <see cref="DecodeRequest"/> fast paths: JPEG DCT scaling and RAW CFA binning when <see cref="DecodeRequest.MaxLongEdge"/>
|
||||
/// allows, bilinear demosaicing for thumbnails and analysis, and <see cref="DecodeRequest.ForcePreview"/> to skip native
|
||||
/// RAW development. Results fit within MaxLongEdge (never upscaled) and are always RGB.
|
||||
/// </summary>
|
||||
public sealed class ManagedDecoderProvider : IImageDecoderProvider
|
||||
{
|
||||
private const string LogCategory = "Decode";
|
||||
private const int FileBufferSize = 1 << 16;
|
||||
private const long MaxPreviewBytes = 256L << 20;
|
||||
private static readonly string[] CompanionExtensions = [".JPG", ".jpg", ".JPEG", ".jpeg"];
|
||||
|
||||
public string Name => "managed";
|
||||
|
||||
public DecodeTier? TierFor(ImageFileFormat format)
|
||||
{
|
||||
var info = ImageFormatInfo.Of(format);
|
||||
if (format is ImageFileFormat.Jpeg or ImageFileFormat.Png or ImageFileFormat.Tiff || RawDecoder.Formats.Contains(format)) return DecodeTier.Native;
|
||||
return info.Family is ImageFamily.CameraRaw or ImageFamily.Heif ? DecodeTier.EmbeddedPreview : null;
|
||||
}
|
||||
|
||||
/// <summary>Decodes the file, or returns null when it has no decodable pixels here (no native decoder and no preview).</summary>
|
||||
/// <exception cref="InvalidDataException">A JPEG, PNG or TIFF is malformed.</exception>
|
||||
/// <exception cref="IOException">The file cannot be read.</exception>
|
||||
public DecodedImage? Decode(DecodeRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(request);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
using var stream = Open(request.Path);
|
||||
var format = ImageSignature.Detect(stream, request.Path);
|
||||
var family = ImageFormatInfo.Of(format).Family;
|
||||
var result = family switch
|
||||
{
|
||||
ImageFamily.Jpeg => request.ForcePreview && Preview(stream, request, adequateOnly: true, cancellationToken) is { } p ? p : Jpeg(stream, request),
|
||||
ImageFamily.Png => Png(stream, request),
|
||||
ImageFamily.Tiff => Tiff(stream, request),
|
||||
ImageFamily.Dng or ImageFamily.CameraRaw => Raw(stream, format, request, cancellationToken),
|
||||
ImageFamily.Heif => request.AllowPreview || request.ForcePreview ? Preview(stream, request, adequateOnly: false, cancellationToken) : null,
|
||||
_ => null,
|
||||
};
|
||||
Log.Debug(LogCategory, $"{Path.GetFileName(request.Path)}: {(result is null ? "unavailable" : $"{result.Tier} via {result.Decoder}")}");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The tier for a file whose signature format is already known (the index's): JPEG, PNG and TIFF decode natively
|
||||
/// whatever they hold (damage shows only when decoding), so only RAW and HEIF files are opened.
|
||||
/// </summary>
|
||||
public FileTier Probe(string path, ImageFileFormat format) => Probe(path, format, null);
|
||||
|
||||
/// <inheritdoc cref="Probe(string, ImageFileFormat)"/>
|
||||
/// <param name="companion">Where a GPR's JPEG is kept when it is not beside it (<see cref="DecodeRequest.Companion"/>).</param>
|
||||
public FileTier Probe(string path, ImageFileFormat format, string? companion)
|
||||
{
|
||||
var family = ImageFormatInfo.Of(format).Family;
|
||||
if (family is not (ImageFamily.Jpeg or ImageFamily.Png or ImageFamily.Tiff)) return Probe(path, companion);
|
||||
var decoder = family switch { ImageFamily.Jpeg => "managed-jpeg", ImageFamily.Png => "managed-png", _ => "managed-tiff" };
|
||||
return new FileTier(format, DecodeTier.Native, decoder, null, 0, 0);
|
||||
}
|
||||
|
||||
/// <summary>The tier this provider would use for the file at <paramref name="path"/>, without decoding pixels.</summary>
|
||||
/// <param name="companion">Where a GPR's JPEG is kept when it is not beside it (<see cref="DecodeRequest.Companion"/>).</param>
|
||||
public FileTier Probe(string path, string? companion = null)
|
||||
{
|
||||
using var stream = Open(path);
|
||||
var format = ImageSignature.Detect(stream, path);
|
||||
var family = ImageFormatInfo.Of(format).Family;
|
||||
if (family is ImageFamily.Jpeg or ImageFamily.Png or ImageFamily.Tiff)
|
||||
{
|
||||
var (w, h) = MetadataReader.Read(stream, path).OrientedSize;
|
||||
var decoder = family switch { ImageFamily.Jpeg => "managed-jpeg", ImageFamily.Png => "managed-png", _ => "managed-tiff" };
|
||||
return new FileTier(format, DecodeTier.Native, decoder, null, w, h);
|
||||
}
|
||||
if (family is not (ImageFamily.Dng or ImageFamily.CameraRaw or ImageFamily.Heif))
|
||||
return new FileTier(format, DecodeTier.Unavailable, null, $"no managed decoder for {format}", 0, 0);
|
||||
string reason;
|
||||
if (RawDecoder.Formats.Contains(format))
|
||||
{
|
||||
var probe = RawDecoder.Probe(stream, path);
|
||||
if (probe.Info is { } info) return new FileTier(format, DecodeTier.Native, info.Decoder, null, info.Width, info.Height);
|
||||
reason = probe.Reason ?? "unsupported";
|
||||
}
|
||||
else
|
||||
{
|
||||
reason = $"no managed decoder for {format}";
|
||||
}
|
||||
var metadata = MetadataReader.Read(stream, path);
|
||||
var (pw, ph) = metadata.LargestPreview is { } preview ? PixelConvert.OrientedSize(preview.Width, preview.Height, metadata.Orientation) : (0, 0);
|
||||
if (format == ImageFileFormat.Gpr && CompanionSize(path, companion) is var (cw, ch) && int.Max(cw, ch) > int.Max(pw, ph))
|
||||
return new FileTier(format, DecodeTier.EmbeddedPreview, "managed-sidecar", reason, cw, ch);
|
||||
if (metadata.LargestPreview is null) return new FileTier(format, DecodeTier.Unavailable, null, reason + "; no embedded preview", 0, 0);
|
||||
return new FileTier(format, DecodeTier.EmbeddedPreview, "managed-preview", reason, pw, ph);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The JPEG a GoPro writes with a GPR: <paramref name="companion"/> when the caller found it elsewhere (an import
|
||||
/// keeps it in a sequence of its own) and it is there, else the one beside the GPR (same name, <c>.JPG</c>), or
|
||||
/// null. Only the usual spellings are tried, so a folder of thousands of frames is never listed once per frame.
|
||||
/// </summary>
|
||||
internal static string? CompanionJpeg(string path, string? companion = null)
|
||||
{
|
||||
if (companion is not null && File.Exists(companion)) return companion;
|
||||
var stem = Path.Combine(Path.GetDirectoryName(path) ?? string.Empty, Path.GetFileNameWithoutExtension(path));
|
||||
foreach (var extension in CompanionExtensions)
|
||||
{
|
||||
if (File.Exists(stem + extension)) return stem + extension;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>Oriented size of the GPR's JPEG (see <see cref="CompanionJpeg"/>), or null when there is none.</summary>
|
||||
/// <exception cref="IOException">The JPEG cannot be read.</exception>
|
||||
private static (int Width, int Height)? CompanionSize(string path, string? companion)
|
||||
{
|
||||
if (CompanionJpeg(path, companion) is not { } file) return null;
|
||||
var jpeg = MetadataReader.Read(file);
|
||||
return jpeg.Format == ImageFileFormat.Jpeg ? jpeg.OrientedSize : null;
|
||||
}
|
||||
|
||||
private static FileStream Open(string path) =>
|
||||
new(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete, FileBufferSize, FileOptions.RandomAccess);
|
||||
|
||||
private static DecodedImage Jpeg(Stream stream, DecodeRequest request)
|
||||
{
|
||||
var data = ReadAll(stream);
|
||||
var info = JpegDecoder.ReadInfo(data);
|
||||
var image = JpegDecoder.DecodeToLinear(data, new JpegDecodeOptions { MaxLongEdge = request.MaxLongEdge }, expandGray: true);
|
||||
var orientation = request.ApplyOrientation ? MetadataReader.Read(stream, request.Path).Orientation : 1;
|
||||
return Finish(image, orientation, request, info.Width, info.Height, DecodeTier.Native, "managed-jpeg");
|
||||
}
|
||||
|
||||
private static DecodedImage Png(Stream stream, DecodeRequest request)
|
||||
{
|
||||
var data = ReadAll(stream);
|
||||
var image = PngDecoder.DecodeToLinear(data, expandGray: true);
|
||||
var orientation = request.ApplyOrientation ? MetadataReader.Read(stream, request.Path).Orientation : 1;
|
||||
return Finish(image, orientation, request, image.Width, image.Height, DecodeTier.Native, "managed-png");
|
||||
}
|
||||
|
||||
private static DecodedImage Tiff(Stream stream, DecodeRequest request)
|
||||
{
|
||||
var decoded = TiffImageReader.Decode(stream);
|
||||
var image = decoded;
|
||||
if (decoded.Channels == 1)
|
||||
{
|
||||
image = PixelConvert.GrayToRgb(decoded);
|
||||
decoded.Dispose();
|
||||
}
|
||||
var orientation = request.ApplyOrientation ? MetadataReader.Read(stream, request.Path).Orientation : 1;
|
||||
return Finish(image, orientation, request, image.Width, image.Height, DecodeTier.Native, "managed-tiff");
|
||||
}
|
||||
|
||||
private static DecodedImage? Raw(Stream stream, ImageFileFormat format, DecodeRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (request.PreferPreview && !request.ForcePreview && request.MaxLongEdge > 0 && RawDecoder.Formats.Contains(format)
|
||||
&& Preview(stream, request, adequateOnly: true, cancellationToken) is { } quick)
|
||||
return quick.AsChoice();
|
||||
if (!request.ForcePreview && RawDecoder.Formats.Contains(format))
|
||||
{
|
||||
try
|
||||
{
|
||||
var options = new RawDecodeOptions
|
||||
{
|
||||
Quality = request.Purpose is DecodePurpose.Thumbnail or DecodePurpose.Analysis ? DemosaicQuality.Draft : DemosaicQuality.Best,
|
||||
MaxLongEdge = request.MaxLongEdge,
|
||||
ApplyOrientation = request.ApplyOrientation,
|
||||
};
|
||||
var raw = RawDecoder.Decode(stream, request.Path, options, cancellationToken);
|
||||
foreach (var warning in raw.Warnings) Log.Debug(LogCategory, $"{Path.GetFileName(request.Path)}: {warning}");
|
||||
return Finish(raw.Image, 1, request, raw.Info.Width, raw.Info.Height, DecodeTier.Native, raw.Info.Decoder, oriented: true);
|
||||
}
|
||||
catch (InvalidDataException ex) when (request.AllowPreview)
|
||||
{
|
||||
Log.Debug(LogCategory, $"{Path.GetFileName(request.Path)}: native decode unavailable ({ex.Message}); trying the embedded preview");
|
||||
}
|
||||
}
|
||||
if (!request.AllowPreview && !request.ForcePreview) return null;
|
||||
if (format == ImageFileFormat.Gpr && Companion(stream, request, cancellationToken) is { } companion) return companion;
|
||||
return Preview(stream, request, adequateOnly: false, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GPR's pixel source: the GoPro's own JPEG (<see cref="DecodeRequest.Companion"/>, else beside it) when it is larger
|
||||
/// than every embedded preview (the camera writes it at full size), decoded with DCT scaling and oriented by its own
|
||||
/// Exif; null when there is none.
|
||||
/// </summary>
|
||||
private static DecodedImage? Companion(Stream raw, DecodeRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (CompanionJpeg(request.Path, request.Companion) is not { } path) return null;
|
||||
var previews = MetadataReader.Read(raw, request.Path, cancellationToken: cancellationToken).Previews;
|
||||
var largestPreview = previews.Count > 0 ? int.Max(previews[0].Width, previews[0].Height) : 0;
|
||||
using var stream = Open(path);
|
||||
if (stream.Length > MaxPreviewBytes) return null;
|
||||
var data = ReadAll(stream);
|
||||
JpegInfo info;
|
||||
try
|
||||
{
|
||||
info = JpegDecoder.ReadInfo(data);
|
||||
}
|
||||
catch (InvalidDataException ex)
|
||||
{
|
||||
Log.Debug(LogCategory, $"{Path.GetFileName(path)}: not a usable JPEG ({ex.Message}); using the embedded preview");
|
||||
return null;
|
||||
}
|
||||
if (int.Max(info.Width, info.Height) <= largestPreview) return null;
|
||||
var image = JpegDecoder.DecodeToLinear(data, new JpegDecodeOptions { MaxLongEdge = request.MaxLongEdge }, expandGray: true);
|
||||
var orientation = request.ApplyOrientation ? MetadataReader.Read(stream, path, cancellationToken: cancellationToken).Orientation : 1;
|
||||
return Finish(image, orientation, request, info.Width, info.Height, DecodeTier.EmbeddedPreview, "managed-sidecar");
|
||||
}
|
||||
|
||||
/// <summary>Embedded-preview tier: the smallest preview whose long edge still reaches MaxLongEdge (the largest when none
|
||||
/// does or no limit is set; null then if <paramref name="adequateOnly"/>), decoded with DCT scaling and oriented like the
|
||||
/// main image.</summary>
|
||||
private static DecodedImage? Preview(Stream stream, DecodeRequest request, bool adequateOnly, CancellationToken cancellationToken)
|
||||
{
|
||||
var metadata = MetadataReader.Read(stream, request.Path, cancellationToken: cancellationToken);
|
||||
if (metadata.Previews.Count == 0) return null;
|
||||
EmbeddedPreview? adequate = null;
|
||||
foreach (var p in metadata.Previews)
|
||||
{
|
||||
if (request.MaxLongEdge > 0 && int.Max(p.Width, p.Height) >= request.MaxLongEdge) adequate = p;
|
||||
}
|
||||
if (adequate is null && adequateOnly) return null;
|
||||
var preview = adequate ?? metadata.Previews[0];
|
||||
if (preview.Length > MaxPreviewBytes || preview.Offset < 0 || preview.Offset > stream.Length - preview.Length)
|
||||
throw new InvalidDataException("Preview: embedded JPEG outside the file");
|
||||
var data = new byte[preview.Length];
|
||||
stream.Position = preview.Offset;
|
||||
stream.ReadExactly(data);
|
||||
var image = JpegDecoder.DecodeToLinear(data, new JpegDecodeOptions { MaxLongEdge = request.MaxLongEdge }, expandGray: true);
|
||||
var orientation = request.ApplyOrientation ? metadata.Orientation : 1;
|
||||
return Finish(image, orientation, request, preview.Width, preview.Height, DecodeTier.EmbeddedPreview, "managed-preview");
|
||||
}
|
||||
|
||||
/// <summary>Applies orientation, fits within MaxLongEdge, and wraps the result (takes ownership of <paramref name="image"/>).</summary>
|
||||
private static DecodedImage Finish(ImageBuffer image, int orientation, DecodeRequest request, int sourceWidth, int sourceHeight, DecodeTier tier, string decoder, bool oriented = false)
|
||||
{
|
||||
var current = image;
|
||||
try
|
||||
{
|
||||
if (orientation is >= 2 and <= 8)
|
||||
{
|
||||
var rotated = PixelConvert.ApplyOrientation(current, orientation);
|
||||
current.Dispose();
|
||||
current = rotated;
|
||||
}
|
||||
if (!oriented) (sourceWidth, sourceHeight) = PixelConvert.OrientedSize(sourceWidth, sourceHeight, orientation);
|
||||
if (request.MaxLongEdge > 0)
|
||||
{
|
||||
var (w, h) = Resampler.FitWithin(current.Width, current.Height, request.MaxLongEdge);
|
||||
if (w != current.Width || h != current.Height)
|
||||
{
|
||||
var filter = request.Purpose == DecodePurpose.Thumbnail ? ResampleFilter.Box : ResampleFilter.Auto;
|
||||
var resized = Resampler.Resize(current, w, h, filter);
|
||||
current.Dispose();
|
||||
current = resized;
|
||||
}
|
||||
}
|
||||
return new DecodedImage(current, tier, decoder, sourceWidth, sourceHeight);
|
||||
}
|
||||
catch
|
||||
{
|
||||
current.Dispose();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] ReadAll(Stream stream)
|
||||
{
|
||||
if (stream.Length > int.MaxValue) throw new InvalidDataException("Image file too large");
|
||||
var data = new byte[stream.Length];
|
||||
stream.Position = 0;
|
||||
stream.ReadExactly(data);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user