fix(convert): keep what the original holds and plan only what converts
Phase 4b review, codec findings. A Replace makes the converted file the photo, so a conversion must not lose what the original held, and the dry run must promise only what the job will do. - Linear DNG from a conversion is scene-referred: the pixels are stored in linear ProPhoto primaries (colours outside sRGB stay positive) and divided by the power of two that brings their peak under the white level (at most 4 stops), with BaselineExposure giving it back and ColorMatrix1/ForwardMatrix1 describing that space. Highlights a RAW develops above 1 and its wide-gamut colours now read back as written. Exports keep the clipped linear-sRGB DNG. - A conversion reads with the managed decoders first for every format they read natively (RAWs developed at float precision, as on the server) and with WIC only for what they cannot. A RAW only WIC's Raw Image Extension develops (8 bits) is refused for TIFF-16 and linear DNG and planned out as "eight_bit"; JPEG still converts it. Providers say so through IImageDecoderProvider.DevelopsRawAt8Bits. - The original's colour space is kept: a JPEG (APP2) or TIFF (tag 34675) carries its ICC profile, with the values unchanged; a linear DNG gets the values converted through a matrix/TRC profile; a gray profile converts to sRGB. Exif Adobe RGB (uncalibrated + R03) and HEIF nclx P3 get an in-house profile. A space nothing here can keep (CMYK, a lookup-table profile into a DNG, uncalibrated without R03, HDR nclx) is planned out as "color_profile". New in-house ICC parser/writer and header reader for JPEG, PNG, TIFF, HEIF/AVIF and WebP. - The planner asks every file, whatever tier was recorded (unknown before the light analysis, or by another host), with the conversion's decoders, headers only and eight at a time; a RAW the server cannot develop is "convert_on_pc" in the plan instead of failing its sequence. Photos a target cannot hold (a JPEG side above 65535, more samples than one buffer) are planned out as "too_large", and an overflow fails its photo rather than the job. - A photo that fails reads in the job log as one catalog sentence by cause (Archive.Convert.Failed.*), the file named once; the exception's English text goes to the diagnostics log only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 0ca1e91ea09946d7a55f45695ee58e1a0ff5f779)
This commit is contained in:
1 parent
341fb77507
commit
f86a151a5d
26 files changed
+1755
-82
No files matched your search
@@ -302,7 +302,8 @@ public sealed class MassConverter
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or InvalidOperationException)
|
||||
{
|
||||
Core.Diagnostics.Log.Warning("archive", $"{row.DisplayTitle}: the converted photos could not take their place", ex);
|
||||
return (new ConvertSequenceResult(row.Id, row.DisplayTitle, ConvertOutcome.Failed, 0, Error: ex.Message), []);
|
||||
var cause = Loc.L(ex is UnauthorizedAccessException ? "Archive.Failed.Access" : "Archive.Failed.Files");
|
||||
return (new ConvertSequenceResult(row.Id, row.DisplayTitle, ConvertOutcome.Failed, 0, Error: Loc.L("Archive.Convert.NotPlaced", cause)), []);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,8 +338,8 @@ public sealed class MassConverter
|
||||
|
||||
/// <summary>
|
||||
/// Stage A: converts the planned frames not staged yet, several at once, each staged file appended to the journal as it
|
||||
/// is consumed (in frame order). Returns the first failure (the file and why); the frames converted meanwhile stay
|
||||
/// staged for a retry.
|
||||
/// is consumed (in frame order). Returns the first failure (the file and why, localised; the exception goes to the
|
||||
/// diagnostics log); the frames converted meanwhile stay staged for a retry.
|
||||
/// </summary>
|
||||
private async Task<string?> StageAsync(Sequence row, SequenceManifest manifest, SequencePaths folder, ConvertSequencePlan planned,
|
||||
Dictionary<Guid, StagedConversion> ready, string staging, ConvertOptions options, StagedLog staged, Progress progress, ConvertCallbacks callbacks,
|
||||
@@ -354,11 +355,16 @@ public sealed class MassConverter
|
||||
var atOnce = DecodeBudget.PhotosAtOnce(_writer.Options.Parallelism(), _writer.Options.MemoryBudget(), largest);
|
||||
var threads = atOnce > 1 ? 1 : -1;
|
||||
string? failure = null;
|
||||
Exception? error = null;
|
||||
await using var work = new OrderedWork<Staged>(atOnce, async result =>
|
||||
{
|
||||
if (result.Conversion is not { } conversion)
|
||||
{
|
||||
failure ??= $"{result.File}: {result.Error?.Message}";
|
||||
if (failure is null)
|
||||
{
|
||||
error = result.Error;
|
||||
failure = Loc.L("Archive.Convert.PhotoFailed", result.File, FrameConverter.FailureText(result.Error!));
|
||||
}
|
||||
return;
|
||||
}
|
||||
staged.Append(row.Id, planned.FramesVersion, conversion);
|
||||
@@ -371,7 +377,7 @@ public sealed class MassConverter
|
||||
await work.AddAsync(token => Stage(frame, manifest, folder, staging, options, decoder, threads, token)).ConfigureAwait(false);
|
||||
}
|
||||
await work.CompleteAsync().ConfigureAwait(false);
|
||||
if (failure is not null) Core.Diagnostics.Log.Warning("archive", $"{row.DisplayTitle}: not converted, {failure}");
|
||||
if (failure is not null) Core.Diagnostics.Log.Warning("archive", $"{row.DisplayTitle}: not converted", error);
|
||||
return failure;
|
||||
}
|
||||
|
||||
@@ -387,7 +393,7 @@ public sealed class MassConverter
|
||||
using (var stream = new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete, 1 << 20, FileOptions.SequentialScan))
|
||||
sha = Convert.ToHexStringLower(SHA256.HashData(stream));
|
||||
if (!string.Equals(sha, frame.Sha256, StringComparison.OrdinalIgnoreCase))
|
||||
throw new ConversionException($"{frame.File} no longer matches its SHA-256; verify the sequence");
|
||||
throw new ConversionException(ConversionFailure.Changed, $"{frame.File} no longer matches its SHA-256; verify the sequence");
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var target = Path.Combine(staging, frame.Id.ToString("N") + options.Extension);
|
||||
var file = FrameConverter.Convert(new ConvertSource(source, frame, manifest.Camera, manifest.Lens), options, decoder, target, threads, cancellationToken);
|
||||
|
||||
Reference in new issue
Block a user