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>
136 lines
7.3 KiB
C#
136 lines
7.3 KiB
C#
using Chronos.Core.Codecs.Jpeg;
|
|
using Chronos.Core.Imaging;
|
|
using Chronos.Core.Metadata;
|
|
|
|
namespace Chronos.Core.Archiving;
|
|
|
|
/// <summary>A JPEG made from a frame.</summary>
|
|
public sealed record EncodedImage(byte[] Jpeg, int Width, int Height, DecodeTier Tier);
|
|
|
|
/// <summary>
|
|
/// Makes thumbnails and proxies of frames (BRIEF §8.5): the managed JPEG decoder, or for thumbnails an embedded preview
|
|
/// at least 320 px long, first, then the host's decode providers (WIC on Windows); orientation applied, resampled in
|
|
/// linear light, encoded in-house. <see cref="EncodedImage.Tier"/> says how the pixels were obtained.
|
|
/// </summary>
|
|
public sealed class FrameImageRenderer(ImageDecoder decoder)
|
|
{
|
|
public const int ThumbnailLongEdge = 320;
|
|
public const int ThumbnailQuality = 80;
|
|
|
|
/// <summary>A 320 px q80 thumbnail, or null when no decoder can read the frame.</summary>
|
|
public EncodedImage? Thumbnail(SequencePaths sequence, SidecarFrame frame, CancellationToken cancellationToken = default) =>
|
|
Thumbnail(sequence, frame, new ThumbnailPolicy(), cancellationToken);
|
|
|
|
/// <summary>A thumbnail at the policy's long edge and quality (the archive's, BRIEF §8.5), or null when no decoder can read the frame.</summary>
|
|
/// <param name="companion">Where a GPR's JPEG is kept when it is not beside it (<see cref="DecodeRequest.Companion"/>).</param>
|
|
public EncodedImage? Thumbnail(SequencePaths sequence, SidecarFrame frame, ThumbnailPolicy policy, CancellationToken cancellationToken = default,
|
|
string? companion = null)
|
|
{
|
|
using var decoded = Decode(sequence.File(frame.File), frame, policy.LongEdge, DecodePurpose.Thumbnail, preferPreview: true, companion, cancellationToken);
|
|
if (decoded is null) return null;
|
|
using var small = Resampler.Thumbnail(decoded.Pixels, policy.LongEdge);
|
|
return Encode(small, new JpegEncodeOptions { Quality = policy.Quality }, decoded.Tier);
|
|
}
|
|
|
|
/// <summary>A proxy at the policy's long edge and quality with capture time and camera in its Exif; null when undecodable.</summary>
|
|
/// <param name="companion">Where a GPR's JPEG is kept when it is not beside it (<see cref="DecodeRequest.Companion"/>).</param>
|
|
public EncodedImage? Proxy(SequencePaths sequence, SidecarFrame frame, SidecarCamera? camera, ProxyPolicy policy, CancellationToken cancellationToken = default,
|
|
string? companion = null)
|
|
{
|
|
if (policy.LongEdge == ProxyPolicy.Disabled) throw new InvalidOperationException("Proxies are disabled for this archive.");
|
|
using var decoded = Decode(sequence.File(frame.File), frame, policy.LongEdge, DecodePurpose.Proxy, preferPreview: false, companion, cancellationToken);
|
|
if (decoded is null) return null;
|
|
var source = decoded.Pixels;
|
|
var (w, h) = policy.LongEdge == ProxyPolicy.FullSize ? (source.Width, source.Height) : Resampler.FitWithin(source.Width, source.Height, policy.LongEdge);
|
|
using var resized = Resampler.Resize(source, w, h);
|
|
var exif = ExifWriter.BuildJpegApp1(new FrameMetadata
|
|
{
|
|
Make = camera?.Make,
|
|
Model = camera?.Model,
|
|
BodySerial = camera?.Serial,
|
|
CapturedAt = frame.CapturedAt,
|
|
UtcOffsetMinutes = frame.UtcOffset,
|
|
ExposureTime = frame.Exposure,
|
|
FNumber = frame.FNumber,
|
|
Iso = frame.Iso,
|
|
FocalLength = frame.Focal,
|
|
ExposureBias = frame.Bias,
|
|
Software = "Chronos",
|
|
});
|
|
// The encoder takes the APP1 payload; ExifWriter returns the whole segment (marker and length first).
|
|
return Encode(resized, new JpegEncodeOptions { Quality = policy.Quality, App1Segments = [exif[4..]] }, decoded.Tier);
|
|
}
|
|
|
|
private static EncodedImage Encode(ImageBuffer pixels, JpegEncodeOptions options, DecodeTier tier) =>
|
|
new(JpegEncoder.Encode(pixels, options), pixels.Width, pixels.Height, tier);
|
|
|
|
/// <summary>
|
|
/// The frame's pixels: a JPEG through the managed decoder, the stored embedded preview when <paramref name="preferPreview"/>
|
|
/// and it reaches <paramref name="maxLongEdge"/> (a smaller one would be upscaled or leave the thumbnail short), then
|
|
/// the host's decoders (with the GPR's <paramref name="companion"/>), and the stored preview as the last resort. Null
|
|
/// when nothing decodes.
|
|
/// </summary>
|
|
/// <exception cref="IOException">The file could not be read.</exception>
|
|
private DecodedFrame? Decode(string path, SidecarFrame frame, int maxLongEdge, DecodePurpose purpose, bool preferPreview, string? companion,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
if (frame.Format == ImageFileFormat.Jpeg && DecodeJpeg(File.ReadAllBytes(path), maxLongEdge, frame.Orientation, DecodeTier.Native) is { } jpeg) return jpeg;
|
|
byte[]? preview = null;
|
|
if (preferPreview && (preview = ReadPreview(path, frame)) is not null && Reaches(preview, maxLongEdge)
|
|
&& DecodeJpeg(preview, maxLongEdge, frame.Orientation, DecodeTier.EmbeddedPreview) is { } fast)
|
|
return fast;
|
|
var request = new DecodeRequest(path, System.Math.Max(0, maxLongEdge), purpose, ApplyOrientation: true, AllowPreview: true, Companion: companion);
|
|
if (decoder.Decode(request, cancellationToken) is { } decoded) return new DecodedFrame(decoded.Pixels, decoded.Tier);
|
|
return (preview ?? ReadPreview(path, frame)) is { } fallback ? DecodeJpeg(fallback, maxLongEdge, frame.Orientation, DecodeTier.EmbeddedPreview) : null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Whether the stored preview's long edge reaches <paramref name="maxLongEdge"/>, from the JPEG's own header: the
|
|
/// sidecar's preview size may be a GPR companion's, larger than the preview embedded in the file.
|
|
/// </summary>
|
|
private static bool Reaches(byte[] preview, int maxLongEdge)
|
|
{
|
|
if (maxLongEdge <= 0) return true;
|
|
try
|
|
{
|
|
var info = JpegDecoder.ReadInfo(preview);
|
|
return int.Max(info.Width, info.Height) >= maxLongEdge;
|
|
}
|
|
catch (InvalidDataException)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private static DecodedFrame? DecodeJpeg(byte[] data, int maxLongEdge, int orientation, DecodeTier tier)
|
|
{
|
|
ImageBuffer decoded;
|
|
try
|
|
{
|
|
decoded = JpegDecoder.DecodeToLinear(data, new JpegDecodeOptions { MaxLongEdge = System.Math.Max(0, maxLongEdge) }, expandGray: true);
|
|
}
|
|
catch (InvalidDataException)
|
|
{
|
|
return null;
|
|
}
|
|
if (orientation is <= 1 or > 8) return new DecodedFrame(decoded, tier);
|
|
using (decoded) return new DecodedFrame(PixelConvert.ApplyOrientation(decoded, orientation), tier);
|
|
}
|
|
|
|
private static byte[]? ReadPreview(string path, SidecarFrame frame)
|
|
{
|
|
if (frame.PreviewOffset is not { } offset || frame.PreviewLength is not ({ } length and > 0 and < int.MaxValue)) return null;
|
|
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete, 4096, FileOptions.RandomAccess);
|
|
if (offset < 0 || offset + length > stream.Length) return null;
|
|
var data = new byte[length];
|
|
stream.Position = offset;
|
|
stream.ReadExactly(data);
|
|
return data;
|
|
}
|
|
|
|
private sealed record DecodedFrame(ImageBuffer Pixels, DecodeTier Tier) : IDisposable
|
|
{
|
|
public void Dispose() => Pixels.Dispose();
|
|
}
|
|
}
|