Repository navigation
Expand file tree
/
Copy pathtest_media_edit.cpp
More file actions
2761 lines (2315 loc) · 124 KB
/
Copy pathtest_media_edit.cpp
File metadata and controls
2761 lines (2315 loc) · 124 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This file is part of the Diffractor photo and video organizer
// Copyright 2026 Zac Walker
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// Purpose: Media metadata write tests and the image editing model. Verifies metadata, rating, label,
// tag and location updates across containers and sidecars, Windows shell tag interop, and the edit
// operations (perspective, document detection, crop, temperature, preview, ICC/XMP round-trip).
#include "pch.h"
#include "test_fixtures.h"
#include "metadata.h"
#include "view_edit.h"
#include "app_util.h"
#include "app_commands.h"
#include "libfiles/media.h"
#include "libfiles/write.h"
#include <set>
// Writing metadata updates xmp:ModifyDate, and on a file that carried no XMP the toolkit can add an
// xmp:CreateDate too, so neither is stable across a write. The capture time is: a write that moves
// it has destroyed when the photograph was taken (#184, #192). Assert that, then let the rest go.
static void reconcile_write_mutable_dates(prop::item_metadata& expected, const prop::item_metadata& actual,
const std::string_view message)
{
assert_equal(expected.dates.original(), actual.dates.original(), "date original survives a write", message);
expected.dates = actual.dates;
}
#ifdef _WIN32
static uint32_t read_be32(const uint8_t* p)
{
return static_cast<uint32_t>(p[0]) << 24 | static_cast<uint32_t>(p[1]) << 16 | static_cast<uint32_t>(p[2]) << 8 |
p[3];
}
static core::blob find_xtra_entry(const core::file_path path, const std::string_view wanted_name)
{
const auto data = platform::blob_from_file(path);
for (size_t pos = 0; pos + 12 <= data.size(); ++pos)
{
const auto entry_size = read_be32(data.data() + pos);
const auto name_size = read_be32(data.data() + pos + 4);
if (entry_size < 12 || entry_size > data.size() - pos || name_size > entry_size - 12) continue;
const std::string_view name(reinterpret_cast<const char*>(data.data() + pos + 8), name_size);
if (name == wanted_name)
{
return {data.begin() + static_cast<ptrdiff_t>(pos),
data.begin() + static_cast<ptrdiff_t>(pos + entry_size)};
}
}
return {};
}
#endif
static core::cached make_unique_tags(tag_set tags1, const tag_set& tags2)
{
tags1.add(tags2);
tags1.make_unique();
return core::cache(tags1.to_string());
}
static void should_apply_perspective_correction()
{
const auto source = std::make_shared<core::surface>();
source->alloc(16, 12, core::texture_format::RGB);
for (auto y = 0; y < 12; ++y)
{
for (auto x = 0; x < 16; ++x)
{
source->set_pixel(x, y, core::rgba(x * 16, y * 20, 64));
}
}
image_edits edits;
edits.perspective_horizontal(0.4);
edits.perspective_vertical(-0.25);
const auto corrected = apply_image_edits(source, edits);
assert_equal(true, source->dimensions() == corrected->dimensions(), "perspective dimensions");
assert_equal(true, source->pixel_difference(corrected) == core::pixel_difference_result::not_equal,
"perspective changes pixels");
edits.crop_bounds(quadd(source->dimensions()));
const auto valid = edits.perspective_bounds(source->dimensions());
const auto crop = edits.effective_crop_bounds(source->dimensions());
const auto inside = [](const quadd& polygon, const pointd point)
{
auto sign = 0.0;
for (auto edge = 0; edge < 4; ++edge)
{
const auto start = polygon[edge];
const auto end = polygon[(edge + 1) % 4];
const auto cross = (end.X - start.X) * (point.Y - start.Y) - (end.Y - start.Y) * (point.X - start.X);
if (edge == 0) sign = cross;
else if (sign * cross < -0.0001) return false;
}
return true;
};
assert_equal(true, crop.actual_extent().Width < source->width(), "perspective crop narrows invalid edges");
for (auto corner = 0; corner < 4; ++corner)
{
assert_equal(true, inside(valid, crop[corner]), "perspective crop corner is valid");
}
const auto rotated_bounds = quadd(source->dimensions()).rotate(20, quadd(source->dimensions()).center_point());
edits.crop_bounds(rotated_bounds);
const auto rotated_valid = edits.perspective_bounds(source->dimensions());
const auto rotated_crop = edits.effective_crop_bounds(source->dimensions());
for (auto corner = 0; corner < 4; ++corner)
{
assert_equal(true, inside(rotated_valid, rotated_crop[corner]), "rotated perspective crop corner is valid");
}
edits.perspective_horizontal(0);
edits.perspective_vertical(0);
edits.crop_bounds({});
assert_equal(true, apply_image_edits(source, edits).get() == source.get(), "zero perspective preserves surface");
}
static void should_fit_document_correction_to_controls()
{
constexpr sizei extent(400, 300);
constexpr auto horizontal = 0.30;
constexpr auto vertical = -0.18;
// A page filling this rectangle once corrected must have been photographed at these corners.
const quadd page_in_output(60.0, 50.0, 340.0, 250.0);
std::array<pointd, 4> corners{};
for (auto index = 0; index < 4; ++index)
{
const auto nx = page_in_output[index].X / extent.cx - 0.5;
const auto ny = page_in_output[index].Y / extent.cy - 0.5;
const auto denominator = 1.0 + horizontal * nx + vertical * ny;
corners[index] = {(0.5 + nx / denominator) * extent.cx, (0.5 + ny / denominator) * extent.cy};
}
const auto correction = fit_document_correction(corners, extent, core::orientation::top_left);
assert_equal(true, static_cast<bool>(correction), "document correction fits");
assert_equal(true, std::abs(correction.perspective_horizontal - horizontal) < 0.01,
"recovers horizontal perspective");
assert_equal(true, std::abs(correction.perspective_vertical - vertical) < 0.01, "recovers vertical perspective");
assert_equal(true, std::abs(correction.straighten) < 0.5, "rectified page needs no straighten");
// The crop stays a rectangle the user can adjust, and needs no clipping because it is already
// inside the warped image.
image_edits edits;
edits.perspective_horizontal(correction.perspective_horizontal);
edits.perspective_vertical(correction.perspective_vertical);
edits.crop_bounds(correction.crop);
assert_equal(true, std::abs(edits.crop_bounds().angle() - correction.straighten) < 0.5,
"crop angle matches straighten");
const auto effective = edits.effective_crop_bounds(extent);
for (auto corner = 0; corner < 4; ++corner)
{
assert_equal(true, correction.crop[corner].dist(page_in_output[corner]) < 2.0, "crop matches the page");
assert_equal(true, correction.crop[corner].dist(effective[corner]) < 0.5, "crop needs no clipping");
}
}
static void should_detect_only_clear_document_regions()
{
const auto document = std::make_shared<core::surface>();
document->alloc(160, 120, core::texture_format::RGB);
constexpr std::array<pointd, 4> corners = {pointd(24, 18), pointd(140, 12), pointd(132, 108), pointd(18, 100)};
for (auto y = 0; y < 120; ++y)
{
for (auto x = 0; x < 160; ++x)
{
bool inside = true;
for (auto edge = 0; edge < 4; ++edge)
{
const auto& a = corners[edge];
const auto& b = corners[(edge + 1) % 4];
if ((b.X - a.X) * (y + 0.5 - a.Y) - (b.Y - a.Y) * (x + 0.5 - a.X) < 0)
{
inside = false;
break;
}
}
document->set_pixel(x, y, inside ? core::rgba(238, 236, 232) : core::rgba(40, 55, 70));
}
}
const auto detected = detect_document(document, document->dimensions());
assert_equal(true, static_cast<bool>(detected), "detects clear document");
assert_equal(true, detected.extent.cx > 100 && detected.extent.cy > 80, "document extent is plausible");
const auto ambiguous = std::make_shared<core::surface>();
ambiguous->alloc(160, 120, core::texture_format::RGB);
for (auto y = 0; y < 120; ++y)
for (auto x = 0; x < 160; ++x) ambiguous->set_pixel(x, y, core::rgba(220, 220, 220));
assert_equal(true, !detect_document(ambiguous, ambiguous->dimensions()), "rejects borderless bright image");
}
static void should_detect_photographed_document()
{
files loader;
const auto loaded = loader.load(test_files_folder().combine("excluded1").combine_file("document.png"), false);
const auto surface = loaded.to_surface({768, 768});
const auto detected = detect_document(surface, loaded.dimensions());
assert_equal(true, static_cast<bool>(detected), "detects photographed document");
assert_equal(true,
detected.extent.cx > loaded.dimensions().cx / 2 && detected.extent.cy > loaded.dimensions().cy / 2 &&
detected.extent.cx <= loaded.dimensions().cx && detected.extent.cy <= loaded.dimensions().cy,
"photographed document extent is plausible");
assert_equal(true, detected.extent.cy > detected.extent.cx, "photographed document remains portrait");
}
static void should_detect_document_at_image_edge()
{
const auto document = std::make_shared<core::surface>();
document->alloc(160, 120, core::texture_format::RGB);
for (auto y = 0; y < 120; ++y)
{
for (auto x = 0; x < 160; ++x)
{
const auto inside = x < 130 && y < 100;
document->set_pixel(x, y, inside ? core::rgba(238, 236, 232) : core::rgba(40, 55, 70));
}
}
const auto detected = detect_document(document, document->dimensions());
assert_equal(true, static_cast<bool>(detected), "detects document touching image edge");
}
static void should_detect_low_contrast_document()
{
const auto document = std::make_shared<core::surface>();
document->alloc(240, 180, core::texture_format::RGB);
constexpr std::array<pointd, 4> corners = {pointd(34, 22), pointd(210, 30), pointd(202, 160), pointd(26, 152)};
for (auto y = 0; y < 180; ++y)
{
for (auto x = 0; x < 240; ++x)
{
bool inside = true;
for (auto edge = 0; edge < 4; ++edge)
{
const auto& a = corners[edge];
const auto& b = corners[(edge + 1) % 4];
if ((b.X - a.X) * (y + 0.5 - a.Y) - (b.Y - a.Y) * (x + 0.5 - a.X) < 0)
{
inside = false;
break;
}
}
// Lighting ramp overlaps page and surround tones, so no global threshold separates them.
const auto level = core::round((inside ? 148.0 : 120.0) + 70.0 * x / 240.0);
document->set_pixel(x, y, core::rgba(level, level, level));
}
}
const auto detected = detect_document(document, document->dimensions());
assert_equal(true, static_cast<bool>(detected), "detects low contrast document");
assert_equal(true, detected.extent.cx > 140 && detected.extent.cx < 210, "low contrast document width");
assert_equal(true, detected.extent.cy > 100 && detected.extent.cy < 160, "low contrast document height");
}
static void should_crop_without_resampling()
{
const auto source = std::make_shared<core::surface>();
source->alloc(16, 12, core::texture_format::RGB);
for (auto y = 0; y < 12; ++y)
{
for (auto x = 0; x < 16; ++x)
{
// Alternating extremes, so any interpolation shows up immediately as a mid tone.
source->set_pixel(x, y, (x + y) & 1 ? core::rgba(255, 255, 255) : core::rgba(0, 0, 0));
}
}
// A crop dragged in the view lands on fractional source pixels.
image_edits edits;
edits.crop_bounds(quadd(rectd(3.4, 2.6, 8.0, 6.0)));
const auto cropped = apply_image_edits(source, edits);
assert_equal(true, cropped->dimensions() == sizei(8, 6), "crop extent");
for (auto y = 0u; y < cropped->height(); ++y)
{
for (auto x = 0u; x < cropped->width(); ++x)
{
assert_equal(source->get_pixel(3 + x, 3 + y), cropped->get_pixel(x, y), "crop copies source pixels");
}
}
}
static void should_apply_temperature_and_tint()
{
const auto source = std::make_shared<core::surface>();
source->alloc(1, 1, core::texture_format::RGB);
source->set_pixel(0, 0, core::rgba(128, 128, 128));
image_edits edits;
edits.temperature(0.5);
edits.tint(0.25);
const auto adjusted = apply_image_edits(source, edits)->get_pixel(0, 0);
const auto adjusted_red = core::get_b(adjusted);
const auto adjusted_green = core::get_g(adjusted);
const auto adjusted_blue = core::get_r(adjusted);
assert_equal(true, adjusted_red > adjusted_blue, "temperature warms neutral pixel");
assert_equal(true, adjusted_green < adjusted_red, "positive tint reduces green");
}
// Auto colour reads a cast from the near-neutral pixels and asks for the white balance that removes it. It
// once read the first byte - blue, in a packed surface - as red, and so warmed a warm picture further.
static void should_auto_colour_against_a_cast()
{
// A grey ramp under a cast, written byte by byte so the test names each channel itself.
const auto cast_ramp = [](const double red, const double green, const double blue)
{
const auto ramp = std::make_shared<core::surface>();
ramp->alloc(176, 1, core::texture_format::RGB);
auto* const row = ramp->pixels_line(0);
for (auto x = 0; x < 176; ++x)
{
const auto level = 40.0 + x;
row[x * 4 + 0] = static_cast<uint8_t>(std::min(255.0, std::round(level * blue)));
row[x * 4 + 1] = static_cast<uint8_t>(std::min(255.0, std::round(level * green)));
row[x * 4 + 2] = static_cast<uint8_t>(std::min(255.0, std::round(level * red)));
row[x * 4 + 3] = 255;
}
return core::const_surface_ptr(ramp);
};
const auto red_over_blue = [](const core::const_surface_ptr& s)
{
double red = 0;
double blue = 0;
for (auto x = 0u; x < s->width(); ++x)
{
blue += s->pixels_line(0)[x * 4 + 0];
red += s->pixels_line(0)[x * 4 + 2];
}
return red / blue;
};
const auto warm = cast_ramp(1.12, 1.0, 0.85);
const auto settings = analyze_auto_color(warm);
assert_equal(true, settings.has_value(), "a warm picture is measured");
if (!settings) return;
assert_equal(true, settings->temperature < -0.2, "a warm cast asks for a cooler temperature");
render::color_adjust adjust;
adjust.color_params(settings->vibrance, 0, settings->darks, settings->midtones, settings->lights,
settings->contrast, settings->brightness, settings->temperature, settings->tint);
const auto corrected = std::make_shared<core::surface>();
corrected->alloc(warm->dimensions(), warm->format());
adjust.apply(warm, corrected->pixels(), corrected->stride(), {});
assert_equal(true, red_over_blue(corrected) < red_over_blue(warm) - 0.1, "and applying it takes the cast out");
const auto cool = analyze_auto_color(cast_ramp(0.85, 1.0, 1.12));
assert_equal(true, cool && cool->temperature > 0.2, "a cool cast asks for a warmer temperature");
const auto green = analyze_auto_color(cast_ramp(0.95, 1.1, 0.95));
assert_equal(true, green && green->tint > 0.1, "a green cast asks for tint towards magenta");
const auto neutral = analyze_auto_color(cast_ramp(1.0, 1.0, 1.0));
assert_equal(true, neutral && std::abs(neutral->temperature) < 0.01 && std::abs(neutral->tint) < 0.01,
"a neutral picture needs no white balance");
}
static void should_initialize_edit_rotation_from_orientation()
{
constexpr sizei landscape(120, 80);
const auto top_left = edit_view_state::initial_crop(landscape, core::orientation::top_left);
const auto right_top = edit_view_state::initial_crop(landscape, core::orientation::right_top);
const auto bottom_right = edit_view_state::initial_crop(landscape, core::orientation::bottom_right);
const auto left_bottom = edit_view_state::initial_crop(landscape, core::orientation::left_bottom);
assert_equal(0.0, top_left.angle(), "top-left rotation");
assert_equal(-90.0, right_top.angle(), "right-top rotation");
assert_equal(180.0, std::abs(bottom_right.angle()), "bottom-right rotation");
assert_equal(90.0, left_bottom.angle(), "left-bottom rotation");
assert_equal(true, right_top.actual_extent().Height > right_top.actual_extent().Width,
"right-top orientation is portrait");
assert_equal(true, left_bottom.actual_extent().Height > left_bottom.actual_extent().Width,
"left-bottom orientation is portrait");
const auto source = std::make_shared<core::surface>();
source->alloc(3, 2, core::texture_format::RGB);
for (auto y = 0; y < 2; ++y)
{
for (auto x = 0; x < 3; ++x)
{
source->set_pixel(x, y, core::rgba(10 + x + y * 3, 0, 0));
}
}
image_edits edits;
edits.crop_bounds(edit_view_state::initial_crop(source->dimensions(), core::orientation::right_top));
const auto edited = apply_image_edits(source, edits);
const auto displayed = source->transform(to_simple_transform(core::orientation::right_top));
assert_equal(true, displayed->dimensions() == edited->dimensions(), "right-top edit dimensions match image view");
for (auto y = 0u; y < edited->height(); ++y)
{
for (auto x = 0u; x < edited->width(); ++x)
{
assert_equal(displayed->get_pixel(x, y), edited->get_pixel(x, y), "right-top edit pixels match image view");
}
}
}
static void should_rotate_displayed_oriented_pixels_clockwise()
{
const auto assert_orientation = [](const core::orientation orientation, const std::string_view message)
{
const auto source = std::make_shared<core::surface>();
source->alloc(3, 2, core::texture_format::RGB);
for (auto y = 0; y < 2; ++y)
{
for (auto x = 0; x < 3; ++x)
{
source->set_pixel(x, y, core::rgba(10 + x + y * 3, 0, 0));
}
}
image_edits edits;
edits.crop_bounds(
rotate_command_crop_bounds(source->dimensions(), orientation, core::simple_transform::rot_90, true));
const auto actual = apply_image_edits(source, edits);
const auto displayed = source->transform(to_simple_transform(orientation));
const auto expected = displayed->transform(core::simple_transform::rot_270);
assert_equal(true, core::is_valid(actual), message, "actual rotated surface is valid");
assert_equal(true, core::is_valid(expected), message, "expected rotated surface is valid");
assert_equal(true, expected->dimensions() == actual->dimensions(), message, "dimensions");
for (auto y = 0u; y < actual->height(); ++y)
{
for (auto x = 0u; x < actual->width(); ++x)
{
assert_equal(expected->get_pixel(x, y), actual->get_pixel(x, y), message, "pixels");
}
}
};
assert_orientation(core::orientation::right_top, "right_top");
assert_orientation(core::orientation::left_bottom, "left_bottom");
}
static void should_build_rotated_edit_preview_surface()
{
files ff;
const auto loaded = ff.load(test_files_folder().combine_file("Test.jpg"), false);
const auto source_dimensions = loaded.dimensions();
const auto source = loaded.to_surface(core::scale_dimensions(source_dimensions, 192));
image_edits edits;
edits.crop_bounds(quadd(source_dimensions).transform(core::simple_transform::rot_90));
const auto preview = edit_view::build_preview_surface(source, source_dimensions, edits);
const auto expected_dimensions = core::scale_dimensions(sizei(source->height(), source->width()), 128);
assert_equal(true, is_valid(preview), "rotated edit preview is valid");
assert_equal(expected_dimensions.cx, static_cast<int>(preview->width()), "rotated edit preview width");
assert_equal(expected_dimensions.cy, static_cast<int>(preview->height()), "rotated edit preview height");
}
static void should_build_straightened_edit_preview_without_black_corners()
{
constexpr sizei loaded_dimensions(4000, 3000);
const auto source = std::make_shared<core::surface>();
source->alloc(192, 144, core::texture_format::RGB);
source->clear(core::rgba(255, 255, 255));
image_edits edits;
const quadd image_bounds(loaded_dimensions);
edits.crop_bounds(image_bounds.rotate(5.0, image_bounds.center_point()));
const auto preview = edit_view::build_preview_surface(source, loaded_dimensions, edits);
assert_equal(true, is_valid(preview), "straightened edit preview is valid");
assert_equal(true, preview->width() <= 128 && preview->height() <= 128, "straightened edit preview is bounded");
constexpr auto rgb_mask = 0x00ffffffu;
constexpr auto white = 0x00ffffffu;
assert_equal(white, preview->get_pixel(preview->width() / 2, preview->height() / 2) & rgb_mask,
"straightened edit preview center");
assert_equal(white, preview->get_pixel(0, 0) & rgb_mask, "straightened edit preview top-left corner");
assert_equal(white, preview->get_pixel(preview->width() - 1, 0) & rgb_mask,
"straightened edit preview top-right corner");
assert_equal(white, preview->get_pixel(0, preview->height() - 1) & rgb_mask,
"straightened edit preview bottom-left corner");
assert_equal(white, preview->get_pixel(preview->width() - 1, preview->height() - 1) & rgb_mask,
"straightened edit preview bottom-right corner");
}
static void should_not_treat_initial_orientation_as_an_edit()
{
image_edits original_edits;
original_edits.crop_bounds(edit_view_state::initial_crop(sizei(120, 80), core::orientation::right_top));
auto current_edits = original_edits;
assert_equal(false, current_edits != original_edits, "initial EXIF orientation is baseline");
current_edits.crop_bounds(current_edits.crop_bounds().transform(core::simple_transform::rot_90));
assert_equal(true, current_edits != original_edits, "user rotation changes baseline");
}
// Edit draws the stored orientation into the pixels it writes, so a saved edit of an EXIF-rotated
// JPEG kept Orientation=6 over pixels already upright and opened turned a second time.
static void should_save_oriented_edit_upright()
{
assert_equal(false,
edit_view_state::save_metadata_edits(false, core::orientation::right_top).orientation.has_value(),
"no pixel edit leaves the orientation alone");
assert_equal(false, edit_view_state::save_metadata_edits(true, core::orientation::top_left).orientation.has_value(),
"an upright photo needs no orientation change");
files ff;
const auto load_path = test_files_folder().combine_file("exif-rotated.jpg");
const auto save_path = test_temps.next_path(".jpg");
const auto loaded = ff.load(load_path, false);
assert_equal(true, loaded.success, "exif-rotated.jpg loads");
assert_equal(static_cast<int>(core::orientation::right_top), static_cast<int>(loaded.orientation()),
"the fixture is stored turned");
// The same edit state the view builds: the stored orientation as the baseline crop, then a colour
// change, which forces a re-encode rather than a lossless transform.
image_edits edits;
edits.crop_bounds(edit_view_state::initial_crop(loaded.dimensions(), loaded.orientation()));
edits.brightness(0.25);
const auto md_edits = edit_view_state::save_metadata_edits(true, loaded.orientation());
assert_equal(true, ff.update(load_path, save_path, md_edits, edits, {}, false, {}).success(), "edit saves");
const auto saved = ff.load(save_path, false);
assert_equal(loaded.dimensions().cy, saved.dimensions().cx, "the saved pixels are upright");
assert_equal(loaded.dimensions().cx, saved.dimensions().cy, "the saved pixels are upright");
assert_equal(static_cast<int>(core::orientation::top_left), static_cast<int>(saved.orientation()),
"the saved photo is not turned again when shown");
assert_equal(static_cast<int>(core::orientation::top_left),
static_cast<int>(extract_properties(save_path, metadata_type::EXIF)->orientation),
"the saved Exif orientation is upright");
// PNG and WebP write the source Exif they are handed, so the reset has to reach it there too.
const auto png_path = test_temps.next_path(".png");
assert_equal(true, ff.update(load_path, png_path, md_edits, edits, {}, false, {}).success(), "edit saves as PNG");
const auto png = ff.load(png_path, false);
assert_equal(loaded.dimensions().cy, png.dimensions().cx, "the PNG pixels are upright");
assert_equal(static_cast<int>(core::orientation::top_left), static_cast<int>(png.orientation()),
"a PNG saved from the edit is not turned again when shown");
}
// A JPEG libfiles' encoder writes of a picture dark on its left half and bright on its right, one channel
// or three, with the XMP packet given.
static std::vector<uint8_t> half_bright_jpeg(const sizei extent, const bool grey, const std::string_view xmp)
{
const auto channels = grey ? 1 : 4;
std::vector<uint8_t> pixels(static_cast<size_t>(extent.cx) * extent.cy * channels, 255);
for (auto y = 0; y < extent.cy; ++y)
{
for (auto x = 0; x < extent.cx; ++x)
{
const auto level = static_cast<uint8_t>(x < extent.cx / 2 ? 40 : 215);
auto* const pixel = pixels.data() + (static_cast<size_t>(y) * extent.cx + x) * channels;
for (auto c = 0; c < std::min(channels, 3); ++c) pixel[c] = level;
}
}
libfiles::embedded_metadata metadata;
metadata.xmp = std::span(std::bit_cast<const uint8_t*>(xmp.data()), xmp.size());
libfiles::jpeg_options options;
options.quality = 95;
options.grayscale = grey;
libfiles::jpeg_encoder encoder;
return encoder.encode(extent.cx, extent.cy, pixels.data(), static_cast<size_t>(extent.cx) * channels, 1, metadata,
options);
}
// An edited Ultra HDR JPEG keeps its gain map: the same picture as the photo, at a quarter of its size, so
// wherever the photo is plainly dark or bright the gain map at the same place in its frame is too; and the
// photo's XMP gives the gain map's length.
static void assert_gain_map_registers(const core::file_path path, const std::string_view message)
{
const auto saved = platform::blob_from_file(path);
const auto gain_map = libfiles::find_jpeg_gain_map(saved);
assert_equal(true, !gain_map.empty(), message, "the gain map is kept");
if (gain_map.empty()) return;
files ff;
const auto photo = ff.image_to_surface(core::cspan(saved));
const auto map = ff.image_to_surface(core::cspan(gain_map.data(), gain_map.size()));
assert_equal(true, is_valid(photo) && is_valid(map), message, "the photo and its gain map decode");
if (!is_valid(photo) || !is_valid(map)) return;
const auto photo_aspect = static_cast<double>(photo->width()) / photo->height();
const auto map_aspect = static_cast<double>(map->width()) / map->height();
assert_equal(true, std::abs(photo_aspect - map_aspect) < 0.15, message, "the gain map has the photo's shape");
assert_equal(true, map->width() * 3 < photo->width() && map->width() * 5 > photo->width(), message,
"the gain map keeps its scale");
auto compared = 0;
for (auto j = 0; j < 8; ++j)
{
for (auto i = 0; i < 8; ++i)
{
const auto u = (i + 0.5) / 8;
const auto v = (j + 0.5) / 8;
const auto photo_level = core::get_g(
photo->get_pixel(static_cast<int>(u * photo->width()), static_cast<int>(v * photo->height())));
const auto map_level = core::get_g(
map->get_pixel(static_cast<int>(u * map->width()), static_cast<int>(v * map->height())));
// Near the edge between the halves either may be mid grey.
if ((photo_level > 80 && photo_level < 175) || (map_level > 80 && map_level < 175)) continue;
assert_equal(photo_level > 128, map_level > 128, message, "the gain map lies over the photo");
++compared;
}
}
assert_equal(true, compared > 32, message, "most of the picture is compared");
libfiles::reader r(std::span<const uint8_t>(saved.data(), saved.size()));
libfiles::xmp::meta xmp;
xmp.parse(libfiles::read_packet(r).packet);
constexpr std::string_view container = "http://ns.google.com/photos/1.0/container/";
constexpr std::string_view hdrgm = "http://ns.adobe.com/hdr-gain-map/1.0/";
const auto container_prefix = libfiles::xmp::register_namespace(container, "Container");
const auto item_prefix = libfiles::xmp::register_namespace("http://ns.google.com/photos/1.0/container/item/",
"Item");
libfiles::xmp::register_namespace(hdrgm, "hdrgm");
std::string length;
xmp.get_property(container, std::format("Directory[2]/{}Item/{}Length", container_prefix, item_prefix), &length);
assert_equal(std::to_string(gain_map.size()), length, message, "the photo's XMP gives the gain map's length");
assert_equal(true, xmp.exists(hdrgm, "Version"), message, "the photo's XMP says a gain map follows");
}
// An Ultra HDR JPEG's gain map says how much brighter than the photo each part of the scene is shown on an
// HDR display. A re-encode once dropped it and kept the XMP saying it was there.
static void should_keep_a_gain_map_through_an_edit()
{
const auto primary_xmp = std::string(
R"(<x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">)"
R"(<rdf:Description rdf:about="" xmlns:hdrgm="http://ns.adobe.com/hdr-gain-map/1.0/" )"
R"(xmlns:Container="http://ns.google.com/photos/1.0/container/" )"
R"(xmlns:Item="http://ns.google.com/photos/1.0/container/item/" hdrgm:Version="1.0"><Container:Directory><rdf:Seq>)"
R"(<rdf:li rdf:parseType="Resource"><Container:Item Item:Semantic="Primary" Item:Mime="image/jpeg"/></rdf:li>)"
R"(<rdf:li rdf:parseType="Resource"><Container:Item Item:Semantic="GainMap" Item:Mime="image/jpeg" Item:Length="1"/></rdf:li>)"
R"(</rdf:Seq></Container:Directory></rdf:Description></rdf:RDF></x:xmpmeta>)");
const auto gain_map_xmp = std::string(
R"(<x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">)"
R"(<rdf:Description rdf:about="" xmlns:hdrgm="http://ns.adobe.com/hdr-gain-map/1.0/" hdrgm:Version="1.0" )"
R"(hdrgm:GainMapMax="2.5" hdrgm:HDRCapacityMax="2.5"/></rdf:RDF></x:xmpmeta>)");
// The photo's blocks allow a lossless quarter turn either way; the gain map's, a single channel 12 high,
// one way only.
constexpr sizei photo_extent(64, 48);
const auto ultra_hdr = libfiles::attach_jpeg_gain_map(half_bright_jpeg(photo_extent, false, primary_xmp),
half_bright_jpeg({16, 12}, true, gain_map_xmp));
const auto source = test_temps.next_path(".jpg");
assert_equal(true, platform::blob_save_to_file(core::cspan(ultra_hdr.data(), ultra_hdr.size()), source),
"the Ultra HDR JPEG is written");
assert_gain_map_registers(source, "the source");
const auto save = [&](const image_edits& edits, const std::string_view message)
{
files ff;
const auto saved = test_temps.next_path(".jpg");
assert_equal(true, ff.update(source, saved, {}, edits, {}, false, {}).success(), message, "the edit saves");
assert_gain_map_registers(saved, message);
return saved;
};
image_edits cropped;
cropped.crop_bounds(quadd(rectd(0, 0, 48, 48)));
cropped.brightness(0.2);
files ff;
const auto cropped_path = save(cropped, "cropped and brightened");
assert_equal(48, ff.load(cropped_path, false).dimensions().cx, "the photo is cropped");
// A turn one way moves the gain map's partial bottom blocks, which its lossless turn refuses; the other
// way it is lossless.
for (const auto turn : {core::simple_transform::rot_90, core::simple_transform::rot_270})
{
image_edits turned;
turned.crop_bounds(quadd(photo_extent).transform(turn));
const auto turned_path = save(turned, "turned");
assert_equal(48, ff.load(turned_path, false).dimensions().cx, "the photo is turned");
}
image_edits straightened;
const quadd bounds(photo_extent);
straightened.crop_bounds(bounds.rotate(5.0, bounds.center_point()));
straightened.scale(sizei(40, 40));
save(straightened, "straightened and scaled");
}
// A picture a byte a channel cannot tell from flat: neighbouring 16-bit levels, which an edit keeps.
static void should_keep_sixteen_bits_through_an_edit()
{
constexpr sizei extent(256, 4);
const auto ramp = std::make_shared<core::surface>();
ramp->alloc(extent, core::texture_format::RGBX16);
for (auto y = 0; y < extent.cy; ++y)
{
auto* const row = std::bit_cast<uint16_t*>(ramp->pixels_line(y));
for (auto x = 0; x < extent.cx; ++x)
{
row[x * 4 + 0] = static_cast<uint16_t>(30000 + x);
row[x * 4 + 1] = static_cast<uint16_t>(30000 + x);
row[x * 4 + 2] = static_cast<uint16_t>(30000 + x);
row[x * 4 + 3] = 65535;
}
}
const auto source = test_temps.next_path(".png");
const auto png = save_png(ramp, {});
assert_equal(true, is_valid(png) && platform::blob_save_to_file(png->data(), source), "the 16-bit PNG is written");
files ff;
const auto loaded = ff.load(source, false, decode_intent::edit);
assert_equal(static_cast<int>(core::texture_format::RGBX16),
static_cast<int>(loaded.to_surface({}, false, {}, decode_intent::edit)->format()),
"an edit decodes it at sixteen bits");
assert_equal(static_cast<int>(core::texture_format::ARGB), static_cast<int>(loaded.to_surface()->format()),
"the display, at a byte");
image_edits edits;
edits.crop_bounds(quadd(rectd(0, 0, 256, 2)));
edits.brightness(0.1);
const auto saved = test_temps.next_path(".png");
assert_equal(true, ff.update(source, saved, {}, edits, {}, false, {}).success(), "the edit saves");
const auto edited = ff.load(saved, false, decode_intent::edit).to_surface({}, false, {}, decode_intent::edit);
assert_equal(true, is_valid(edited) && edited->format() == core::texture_format::RGBX16,
"the edit is saved at sixteen bits");
if (!is_valid(edited)) return;
std::set<uint16_t> levels;
const auto* const row = std::bit_cast<const uint16_t*>(edited->pixels_line(0));
for (auto x = 0; x < extent.cx; ++x) levels.insert(row[x * 4]);
assert_equal(true, levels.size() > 200, "the levels a byte would merge stay apart");
assert_equal(true, *levels.begin() > 30000, "and are brightened");
}
// A raw file is developed at sixteen bits a channel for an edit, and a byte a channel for the display.
static void should_develop_a_raw_at_sixteen_bits_for_an_edit()
{
const auto path = test_files_folder().combine_file("Gherkin.CR2");
const auto display = load_raw(path, false);
const auto edit = load_raw(path, false, true);
assert_equal(true, display.success && is_valid(display.s) && edit.success && is_valid(edit.s), "both develop");
if (!is_valid(display.s) || !is_valid(edit.s)) return;
assert_equal(static_cast<int>(core::texture_format::RGB), static_cast<int>(display.s->format()), "a byte");
assert_equal(static_cast<int>(core::texture_format::RGBX16), static_cast<int>(edit.s->format()), "sixteen bits");
assert_equal(true, display.s->dimensions() == edit.s->dimensions(), "the same picture");
assert_equal(static_cast<int>(display.s->orientation()), static_cast<int>(edit.s->orientation()), "turned alike");
}
static void should_update_rating(const std::string_view name)
{
files ff;
const auto ext = name.substr(core::find_ext(name));
const auto save_path = test_temps.next_path(ext);
const auto load_path = test_files_folder().combine_file(name);
metadata_edits edits1;
edits1.rating = 3;
auto set_rating = ff.update(load_path, save_path, edits1, {}, {}, false, {}, {}, ff_inspect_rescan(save_path));
{
const auto actual_scanned = ff_scan_after_update(ff, set_rating, save_path, detect_xmp_sidecar(save_path));
const auto ps = actual_scanned.to_props();
assert_equal(3, ps->rating, "rating");
}
metadata_edits edits2;
edits2.remove_rating = true;
auto clear_rating = ff.update(save_path, edits2, {}, {}, false, {}, ff_inspect_rescan(save_path));
{
const auto actual_scanned = ff_scan_after_update(ff, clear_rating, save_path, detect_xmp_sidecar(save_path));
const auto ps = actual_scanned.to_props();
assert_equal(0, ps->rating, "rating");
}
}
static void should_update_label(const std::string_view name)
{
files ff;
const auto ext = name.substr(core::find_ext(name));
const auto save_path = test_temps.next_path(ext);
const auto load_path = test_files_folder().combine_file(name);
metadata_edits set_label;
set_label.label = label_approved_text;
auto label_written = ff.update(load_path, save_path, set_label, {}, {}, false, {}, {},
ff_inspect_rescan(save_path));
{
const auto actual_scanned = ff_scan_after_update(ff, label_written, save_path, detect_xmp_sidecar(save_path));
assert_equal(label_approved_text, actual_scanned.to_props()->label, "label");
}
metadata_edits clear_label;
clear_label.label = std::string{};
auto label_cleared = ff.update(save_path, clear_label, {}, {}, false, {}, ff_inspect_rescan(save_path));
{
const auto actual_scanned = ff_scan_after_update(ff, label_cleared, save_path, detect_xmp_sidecar(save_path));
assert_equal(std::string_view{}, actual_scanned.to_props()->label, "cleared label");
}
}
// Every format diffractor embeds metadata in is libfiles' to write. The packet's own toolkit identifier
// says which wrote it, and a second edit that fits the first packet must leave the file the same size.
static void should_write_packets_with_libfiles(const std::string_view name)
{
files ff;
const auto ext = name.substr(core::find_ext(name));
const auto save_path = test_temps.next_path(ext);
const auto load_path = test_files_folder().combine_file(name);
metadata_edits first;
first.rating = 2;
auto written = ff.update(load_path, save_path, first, {}, {}, false, {}, {}, ff_inspect_rescan(save_path));
assert_equal(true, written.success(), std::format("{} written ({})", name, written.format_error()));
const auto scanned = ff_scan_after_update(ff, written, save_path);
const std::string_view packet(std::bit_cast<const char*>(scanned.metadata.xmp.data()), scanned.metadata.xmp.size());
assert_equal(true, packet.find("libfiles XMP") != std::string_view::npos,
std::format("{} packet from libfiles", name));
assert_equal(2, scanned.to_props()->rating, "rating");
const auto size_before = platform::file_attributes(save_path).size;
metadata_edits second;
second.rating = 4;
auto rewritten = ff.update(save_path, second, {}, {}, false, {}, ff_inspect_rescan(save_path));
assert_equal(true, rewritten.success(), std::format("{} rewritten ({})", name, rewritten.format_error()));
const auto rescanned = ff_scan_after_update(ff, rewritten, save_path);
assert_equal(4, rescanned.to_props()->rating, "second rating");
assert_equal(size_before, platform::file_attributes(save_path).size, "a packet that fits keeps the file size");
}
// A converted file keeps what its source shows, even where the source keeps it somewhere the new format
// has no place for: IPTC, in a JPEG saved as PNG. The toolkit carried it by importing the source's IPTC
// into the packet; the packet now takes it from what the item shows.
static void should_carry_shown_metadata_into_a_converted_file()
{
const auto source = test_temps.next_path(".jpg");
{
const auto fixture = platform::blob_from_file(test_files_folder().combine_file("IMG_9340.JPG"));
const std::vector<uint8_t> bytes(fixture.begin(), fixture.end());
libfiles::reader r(bytes);
libfiles::metadata_update iptc_only;
iptc_only.legacy.title = "Converted title";
iptc_only.legacy.keywords = std::vector<std::string>{"alpha", "beta"};
const auto plan = libfiles::plan_update(r, iptc_only);
assert_equal(true, plan.ok(), "source planned");
libfiles::memory_stream out;
libfiles::write_updated(r, plan, out);
const auto& written = out.bytes();
assert_equal(true, platform::blob_save_to_file({written.data(), written.size()}, source), "source stored");
}
files ff;
const auto before = ff_scan_file(ff, source);
assert_equal(true, before.metadata.xmp.empty(), "source holds no packet");
assert_equal("Converted title"_c, before.to_props()->title, "source shows its IPTC title");
const auto destination = test_temps.next_path(".png");
platform::copy_file(test_files_folder().combine_file("engine.png"), destination, false, false);
metadata_edits edits;
edits.rating = 3;
const auto result = metadata_xmp::update(destination, source, edits, {}, {});
assert_equal(true, result.success, "converted file written");
const auto after = ff_scan_file(ff, destination);
const auto props = after.to_props();
assert_equal("Converted title"_c, props->title, "title carried into the packet");
const auto tags = props->tags.sv();
assert_equal(true, core::contains(tags, "alpha") && core::contains(tags, "beta"), "tags carried");
assert_equal(3, props->rating, "the edit applied");
}
// libfiles writes no packet into a JPEG XL, so a conversion into one puts what the source shows - here
// an IPTC title and keywords, which a JPEG XL has nowhere else to keep - and the edit into the packet it
// is encoded with, beside the source's EXIF.
static void should_carry_shown_metadata_into_a_jxl()
{
const auto source = test_temps.next_path(".jpg");
{
const auto fixture = platform::blob_from_file(test_files_folder().combine_file("IMG_9340.JPG"));
const std::vector<uint8_t> bytes(fixture.begin(), fixture.end());
libfiles::reader r(bytes);
libfiles::metadata_update iptc_only;
iptc_only.legacy.title = "Converted title";
iptc_only.legacy.keywords = std::vector<std::string>{"alpha", "beta"};
const auto plan = libfiles::plan_update(r, iptc_only);
assert_equal(true, plan.ok(), "source planned");
libfiles::memory_stream out;
libfiles::write_updated(r, plan, out);
const auto& written = out.bytes();
assert_equal(true, platform::blob_save_to_file({written.data(), written.size()}, source), "source stored");
}
files ff;
const auto before = ff_scan_file(ff, source);
assert_equal(true, before.metadata.xmp.empty(), "source holds no packet");
const auto destination = test_temps.next_path(".jxl");
metadata_edits edits;
edits.rating = 3;
const auto result = ff.update(source, destination, edits, {}, {}, false, {});
assert_equal(true, result.success(), std::format("converted ({})", result.format_error()));
assert_equal(false, platform::exists(destination.extension(".xmp")), "no sidecar beside a JPEG XL");
const auto after = ff_scan_file(ff, destination);
assert_equal(false, after.metadata.xmp.empty(), "the packet is boxed");
assert_equal(false, after.metadata.exif.empty(), "the EXIF is boxed");
const auto props = after.to_props();
const auto shown = before.to_props();
assert_equal("Converted title"_c, props->title, "title carried into the packet");
const auto tags = props->tags.sv();
assert_equal(true, core::contains(tags, "alpha") && core::contains(tags, "beta"), "tags carried");
assert_equal(3, props->rating, "the edit applied");
assert_equal(shown->camera_model, props->camera_model, "camera carried in the EXIF");
assert_equal(shown->dates.original(), props->dates.original(), "capture date carried");
}
// A JPEG XL takes a metadata edit where it keeps its packet. The fixture is libjxl's, its EXIF and packet
// Brotli-compressed between the two parts of its codestream: read with Diffractor's own Brotli, the first
// edit writes them plain where they stood, and the next, which fits, is patched. The picture never changes.
static void should_rate_and_tag_a_jxl()
{
const auto path = test_temps.next_path(".jxl");
platform::copy_file(test_files_folder().combine_file("zoltan-tasi.jxl"), path, false, false);
files ff;
const auto before = ff_scan_file(ff, path);
const auto pixels_before = ff.load(path, false);
assert_equal(true, before.success && pixels_before.success, "the fixture reads");
metadata_edits first;
first.rating = 4;
first.add_tags = tag_set("harbour");
const auto rated = ff.update(path, first, {}, {}, false, {});
assert_equal(true, rated.success(), std::format("rated ({})", rated.format_error()));
assert_equal(false, platform::exists(path.extension(".xmp")), "no sidecar beside a JPEG XL");
const auto after = ff_scan_file(ff, path);
const auto props = after.to_props();
assert_equal(4, props->rating, "the rating reads back");
assert_equal(true, core::contains(props->tags.sv(), "harbour"), "the tag reads back");
assert_equal(before.width, after.width, "the size is the codestream's still");
assert_equal(before.to_props()->camera_model, props->camera_model, "the EXIF is kept");
metadata_edits second;
second.rating = 2;
const auto again = ff.update(path, second, {}, {}, false, {});
assert_equal(true, again.success(), std::format("rated again ({})", again.format_error()));
assert_equal(false, again.staged, "an edit that fits is patched where it lies");
assert_equal(2, ff_scan_file(ff, path).to_props()->rating, "the second rating reads back");
const auto pixels_after = ff.load(path, false);
assert_equal(true, pixels_after.success, "the picture reads");
assert_equal(true,
pixels_before.to_surface()->pixel_difference(pixels_after.to_surface()) ==
core::pixel_difference_result::equal,
"the picture is unchanged");
}
// A JPEG XL with no metadata is a bare codestream, as Diffractor writes one; its first packet puts it in a
// container, the codestream inside it unchanged.
static void should_rate_a_bare_jxl()
{
files ff;
const auto source = ff.load(test_files_folder().combine_file("Test.jpg"), false);
const auto image = save_jxl(source.to_surface(), {}, {});
assert_equal(true, image != nullptr, "encoded");