Repository navigation
Expand file tree
/
Copy pathtest_metadata.cpp
More file actions
4362 lines (3742 loc) · 186 KB
/
Copy pathtest_metadata.cpp
File metadata and controls
4362 lines (3742 loc) · 186 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: Metadata tests (metadata_exif, metadata_iptc, metadata_xmp, metadata_icc) -- scanning
// properties from JPEG, TIFF, MP3, MP4, MOV, MKV, AVI, RAW, HEIF, AVIF, WebP, JXL and MOD files, tag
// editing and removal, sidecar merging, metadata presentation blocks and filename token replacement.
#include "pch.h"
#include "metadata.h"
#include "test_fixtures.h"
#include "test_runner.h"
#include "av_format.h"
#include "av_player.h"
#include "libfiles/reader.h"
#include "libfiles/xmp.h"
#include <zlib.h>
#include <jxl/encode.h>
#include <jxl/color_encoding.h>
#define LIBHEIF_STATIC_BUILD 1
#include <libheif/heif.h>
#include <libheif/heif_items.h>
static void should_replace_tokens()
{
files ff;
const auto image_md = ff_scan_file(ff, test_files_folder().combine_file("Test.jpg"));
const auto audio_md = ff_scan_file(ff, test_files_folder().combine_file("Colorblind.mp3"));
const auto md1 = image_md.to_props();
const auto md2 = audio_md.to_props();
assert_equal("2012\\2012-09-14", replace_tokens("{year}\\{created}"s, md1, {}, md1->created()));
assert_equal("2012\\Test.jpg", replace_tokens("{year}\\{name}"s, md1, "Test.jpg", md1->created()));
assert_equal("2012\\09\\14", replace_tokens("{year}\\{month}\\{day}"s, md1, {}, md1->created()));
assert_equal("2012\\september\\14", replace_tokens("{year}\\{month.text}\\{day}"s, md1, {}, md1->created()));
assert_equal("2012\\SEP\\14", replace_tokens("{year}\\{month.short}\\{day}"s, md1, {}, md1->created()));
assert_equal("Counting Crows\\This Desert Life", replace_tokens("{artist}\\{album}"s, md2, {}, md2->created()));
}
static void should_scan_jpeg()
{
const auto load_path = test_files_folder().combine_file("Test.jpg");
prop::item_metadata expected_exif;
expected_exif.camera_manufacturer = "Canon"_c;
expected_exif.camera_model = "Canon EOS 7D"_c;
expected_exif.lens = "EF-S15-85mm f/3.5-5.6 IS USM"_c;
expected_exif.description = "Caption"_c;
expected_exif.coordinate = gps_coordinate(50.08806, 14.42083);
expected_exif.copyright_notice = "Copyright"_c;
expected_exif.f_number = 6.3f;
expected_exif.exposure_time = 1.0f / 100.0f;
expected_exif.iso_speed = 100;
expected_exif.focal_length = 15.0f;
expected_exif.dates.add(prop::date_source::exif_digitized, core::date_t(2012, 9, 14, 19, 21, 14));
expected_exif.dates.add(prop::date_source::exif_original, core::date_t(2012, 9, 14, 19, 21, 14));
expected_exif.dates.add(prop::date_source::exif_datetime, core::date_t(2012, 9, 14, 19, 21, 14));
expected_exif.rating = 0;
assert_metadata(expected_exif, *extract_properties(load_path, metadata_type::EXIF), "EXIF");
prop::item_metadata expected_iptc;
expected_iptc.title = "Title"_c;
expected_iptc.description = "Caption"_c;
expected_iptc.tags = "key1 key2 key3"_c;
expected_iptc.location_place = "Prague"_c;
expected_iptc.location_state = "Hlavní Mesto Praha"_c;
expected_iptc.location_country = "Czech Republic"_c;
expected_iptc.copyright_notice = "Copyright"_c;
expected_iptc.rating = 0;
// 2:55 and 2:60, which agree with the EXIF original this file also carries.
expected_iptc.dates.add(prop::date_source::iptc_created, core::date_t(2012, 9, 14, 19, 21, 14));
assert_metadata(expected_iptc, *extract_properties(load_path, metadata_type::IPTC), "IPTC");
const auto actual_xmp = extract_properties(load_path, metadata_type::XMP);
prop::item_metadata expected_xmp;
expected_xmp.title = "Title"_c;
expected_xmp.description = "Caption"_c;
expected_xmp.tags = "key1 key2 key3"_c;
expected_xmp.location_place = "Prague"_c;
expected_xmp.location_state = "Hlavní Mesto Praha"_c;
expected_xmp.location_country = "Czech Republic"_c;
expected_xmp.lens = "EF-S15-85mm f/3.5-5.6 IS USM"_c;
expected_xmp.copyright_notice = "Copyright"_c;
expected_xmp.rating = 4;
expected_xmp.dates.add(prop::date_source::xmp_exif_digitized, core::date_t(2012, 9, 14, 19, 21, 14));
expected_xmp.dates.add(prop::date_source::xmp_exif_original, core::date_t(2012, 9, 14, 19, 21, 14));
expected_xmp.dates.add(prop::date_source::xmp_modify, core::date_t(2012, 9, 14, 19, 21, 14));
assert_metadata(expected_xmp, *actual_xmp, "XMP");
const auto actual_all = extract_properties(load_path, metadata_type::ALL);
assert_metadata(*expected_test_jpg(), *actual_all, "all");
}
static void should_parse_xmp()
{
const auto load_path = test_files_folder().combine_file("IMG_0604.xmp");
prop::item_metadata actual;
metadata_xmp::parse(actual, load_path);
assert_equal("Flower", actual.title);
assert_equal("Blomst", actual.tags);
assert_equal("Følfod ( Tussilago farfara ) Lægeurt", actual.description);
assert_equal("Frank Aalestrup www.fdaa.dk", actual.copyright_notice);
assert_equal("\"Frank Aalestrup.\nwww.fdaa.dk\"", actual.copyright_creator);
assert_equal("EF100mm f/2.8L Macro IS USM", actual.lens);
assert_equal({56.19283, 9.88415}, actual.coordinate);
assert_equal("Canon", actual.camera_manufacturer);
assert_equal("Canon EOS 50D", actual.camera_model);
assert_equal("IMG_0604.CR2", actual.raw_file_name);
assert_equal("Denmark", actual.location_country);
assert_equal(false, actual.is_panorama(), "an ordinary photograph declares no panorama");
}
// XMP is parsed last, so an array that is simply absent must not erase what EXIF or IPTC supplied.
// An empty array is a different statement: it is the file saying it has no tags, and it is exactly
// what the writer emits when the user clears them. Reading only the non-empty case meant clearing
// every tag and rescanning brought the legacy keywords straight back.
static void should_clear_tags_from_an_empty_xmp_subject()
{
const auto write_sidecar = [](const std::string_view dc_body)
{
const auto path = test_temps.next_path(".xmp");
const auto xml = std::format("<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>"
"<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"><rdf:RDF "
"xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">"
"<rdf:Description rdf:about=\"\" "
"xmlns:dc=\"http://purl.org/dc/elements/1.1/\">{}</rdf:Description>"
"</rdf:RDF></x:xmpmeta><?xpacket end=\"w\"?>",
dc_body);
std::ofstream f(platform::to_stream_path(path), std::ios::binary | std::ios::trunc);
f.write(xml.data(), static_cast<std::streamsize>(xml.size()));
f.close();
return path;
};
{
// What the writer produces for an item whose tags the user removed.
prop::item_metadata md;
md.tags = "Holiday Portugal"_c;
metadata_xmp::parse(md, write_sidecar("<dc:subject><rdf:Bag/></dc:subject>"));
assert_equal(true, core::is_empty(md.tags), "an empty subject array clears the tags it supersedes");
}
{
// No dc:subject at all says nothing about tags, so what EXIF or IPTC gave must survive.
prop::item_metadata md;
md.tags = "Holiday Portugal"_c;
metadata_xmp::parse(md, write_sidecar("<dc:title>Lisbon</dc:title>"));
assert_equal("Holiday Portugal", md.tags, "an absent subject array leaves them alone");
}
{
prop::item_metadata md;
md.tags = "Holiday Portugal"_c;
metadata_xmp::parse(md, write_sidecar("<dc:subject><rdf:Bag><rdf:li>Lisbon</rdf:li></rdf:Bag></dc:subject>"));
assert_equal("Lisbon", md.tags, "and a populated one replaces them");
}
}
// XMP GPS is applied as a pair. A sidecar carrying only one component used to overwrite that half
// while the other stayed at whatever EXIF had already put there, pinning the item to a coordinate
// neither source states - and an item with no EXIF coordinate at all got the zero half, which is
// the Gulf of Guinea.
static void should_apply_xmp_gps_as_a_pair()
{
const auto write_sidecar = [](const std::string_view exif_body)
{
const auto path = test_temps.next_path(".xmp");
const auto xml = std::format("<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>"
"<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"><rdf:RDF "
"xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">"
"<rdf:Description rdf:about=\"\" "
"xmlns:exif=\"http://ns.adobe.com/exif/1.0/\">{}</rdf:Description>"
"</rdf:RDF></x:xmpmeta><?xpacket end=\"w\"?>",
exif_body);
std::ofstream f(platform::to_stream_path(path), std::ios::binary | std::ios::trunc);
f.write(xml.data(), static_cast<std::streamsize>(xml.size()));
f.close();
return path;
};
{
prop::item_metadata md;
metadata_xmp::parse(md, write_sidecar("<exif:GPSLatitude>51,30.852N</exif:GPSLatitude>"
"<exif:GPSLongitude>0,5.910W</exif:GPSLongitude>"));
assert_equal(true, md.coordinate.is_valid(), "a complete pair is read");
assert_equal(true, std::abs(md.coordinate.latitude() - 51.5142) < 0.001, "latitude");
assert_equal(true, std::abs(md.coordinate.longitude() + 0.0985) < 0.001, "longitude");
}
{
// The item already carries an EXIF coordinate, as a scanned photo with a sidecar would.
prop::item_metadata md;
md.coordinate = gps_coordinate(35.68, 139.69);
metadata_xmp::parse(md, write_sidecar("<exif:GPSLatitude>51,30.852N</exif:GPSLatitude>"));
assert_equal(true, std::abs(md.coordinate.latitude() - 35.68) < 0.001, "half a pair changes neither component");
assert_equal(true, std::abs(md.coordinate.longitude() - 139.69) < 0.001,
"so the EXIF coordinate is left whole");
}
{
prop::item_metadata md;
metadata_xmp::parse(md, write_sidecar("<exif:GPSLongitude>0,5.910W</exif:GPSLongitude>"));
assert_equal(false, md.coordinate.is_valid(), "half a pair alone locates nothing");
}
const auto assert_rejected = [&write_sidecar](const std::string_view latitude, const std::string_view longitude,
const std::string_view message)
{
prop::item_metadata md;
md.coordinate = gps_coordinate(35.68, 139.69);
metadata_xmp::parse(md, write_sidecar(std::format("<exif:GPSLatitude>{}</exif:GPSLatitude>"
"<exif:GPSLongitude>{}</exif:GPSLongitude>",
latitude, longitude)));
assert_equal(gps_coordinate(35.68, 139.69), md.coordinate, message);
};
assert_rejected("91,0N", "0,5.910W", "invalid latitude keeps the existing coordinate");
assert_rejected("51,30.852E", "0,5.910W", "wrong latitude hemisphere keeps the existing coordinate");
assert_rejected("51,30.852X", "0,5.910W", "unknown latitude hemisphere keeps the existing coordinate");
assert_rejected("51,30.852N trailing", "0,5.910W", "trailing latitude junk keeps the existing coordinate");
assert_rejected("51,60.0N", "0,5.910W", "invalid latitude minutes keeps the existing coordinate");
assert_rejected("51,30,60N", "0,5.910W", "invalid latitude seconds keeps the existing coordinate");
assert_rejected("51,30.852N", "180,0E", "invalid longitude keeps the existing coordinate");
}
static void should_read_xmp_disc_number()
{
const auto write_sidecar = [](const std::string_view dm_body)
{
const auto path = test_temps.next_path(".xmp");
const auto xml = std::format("<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>"
"<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"><rdf:RDF "
"xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">"
"<rdf:Description rdf:about=\"\" "
"xmlns:xmpDM=\"http://ns.adobe.com/xmp/1.0/DynamicMedia/\">{}</rdf:Description>"
"</rdf:RDF></x:xmpmeta><?xpacket end=\"w\"?>",
dm_body);
std::ofstream f(platform::to_stream_path(path), std::ios::binary | std::ios::trunc);
f.write(xml.data(), static_cast<std::streamsize>(xml.size()));
f.close();
return path;
};
{
prop::item_metadata md;
metadata_xmp::parse(md, write_sidecar("<xmpDM:discNumber>2/3</xmpDM:discNumber>"));
assert_equal(2, static_cast<int>(md.disk.x), "disc number");
assert_equal(3, static_cast<int>(md.disk.y), "disc total");
}
{
prop::item_metadata md;
md.disk = {1, 4};
metadata_xmp::parse(md, write_sidecar("<xmpDM:discNumber>2/3</xmpDM:discNumber>"));
assert_equal(2, static_cast<int>(md.disk.x), "xmp disc number replaces lower priority value");
assert_equal(3, static_cast<int>(md.disk.y), "xmp disc total replaces lower priority value");
}
{
prop::item_metadata md;
metadata_xmp::parse(md, write_sidecar("<xmpDM:discNumber>2</xmpDM:discNumber>"));
assert_equal(2, static_cast<int>(md.disk.x), "single disc number is parsed");
assert_equal(0, static_cast<int>(md.disk.y), "single disc total remains unspecified");
}
}
// Rotating a photo writes a well-formed packet with nothing left in it, and the panel called that
// "not understood". Only a packet the toolkit cannot read is unparsed.
static void should_report_empty_xmp_packet_as_parsed()
{
const std::string empty_packet =
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=""/></rdf:RDF></x:xmpmeta>)";
bool parsed = false;
const auto empty_rows = metadata_xmp::to_info(core::cspan{std::bit_cast<const uint8_t*>(empty_packet.data()),
empty_packet.size()},
parsed);
assert_equal(true, empty_rows.empty(), "an empty packet has no rows");
assert_equal(true, parsed, "an empty packet is understood");
const std::string broken_packet = R"(<x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF><rdf:Description)";
metadata_xmp::to_info(core::cspan{std::bit_cast<const uint8_t*>(broken_packet.data()), broken_packet.size()},
parsed);
assert_equal(false, parsed, "a malformed packet is not understood");
}
// The flag records what the file says about itself, not what its shape suggests: a 2:1 crop of a
// landscape is not a panorama, and a photo sphere that has been cropped square still is one.
static void should_read_the_declared_panorama_projection()
{
const auto write_sidecar = [](const std::string_view gpano_body)
{
const auto path = test_temps.next_path(".xmp");
const auto xml = std::format("<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>"
"<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"><rdf:RDF "
"xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">"
"<rdf:Description rdf:about=\"\" "
"xmlns:GPano=\"http://ns.google.com/photos/1.0/panorama/\">{}</rdf:Description>"
"</rdf:RDF></x:xmpmeta><?xpacket end=\"w\"?>",
gpano_body);
std::ofstream f(platform::to_stream_path(path), std::ios::binary | std::ios::trunc);
f.write(xml.data(), static_cast<std::streamsize>(xml.size()));
f.close();
prop::item_metadata md;
metadata_xmp::parse(md, path);
return md.panorama;
};
assert_equal(static_cast<int>(prop::panorama_projection::equirectangular),
static_cast<int>(write_sidecar("<GPano:ProjectionType>equirectangular</GPano:ProjectionType>")),
"a photo sphere");
assert_equal(static_cast<int>(prop::panorama_projection::cylindrical),
static_cast<int>(write_sidecar("<GPano:ProjectionType>cylindrical</GPano:ProjectionType>")),
"a cylindrical stitch");
// A projection this build does not know still answers the question the flag exists to answer.
assert_equal(static_cast<int>(prop::panorama_projection::unspecified),
static_cast<int>(write_sidecar("<GPano:ProjectionType>mercator</GPano:ProjectionType>")),
"an unrecognised projection is still a panorama");
// Writers that declare a panorama without naming its projection must not be read as ordinary.
assert_equal(static_cast<int>(prop::panorama_projection::unspecified),
static_cast<int>(write_sidecar("<GPano:UsePanoramaViewer>True</GPano:UsePanoramaViewer>")),
"declared without a projection");
assert_equal(static_cast<int>(prop::panorama_projection::unspecified),
static_cast<int>(write_sidecar("<GPano:FullPanoWidthPixels>8192</GPano:FullPanoWidthPixels>")),
"declared by its full extent");
assert_equal(static_cast<int>(prop::panorama_projection::none), static_cast<int>(write_sidecar("")),
"and a file carrying no GPano at all is not a panorama");
// The presence bit is what lets the index reject candidates before it loads them.
prop::item_metadata pano;
pano.panorama = prop::panorama_projection::equirectangular;
assert_equal(true, (pano.calc_search_presence().types & search_presence_mask::panorama) != 0,
"a panorama carries the presence bit");
constexpr prop::item_metadata plain;
assert_equal(false, (plain.calc_search_presence().types & search_presence_mask::panorama) != 0,
"and an ordinary file does not");
}
static void should_scan_tiff_camera_metadata()
{
libfiles::exif_fields fields;
fields.camera_make = "Canon";
fields.camera_model = "EOS R5";
fields.lens = "RF 50mm F1.8";
fields.f_number = 2.8;
fields.exposure_time = 1.0 / 250;
fields.iso_speed = 400;
fields.original = "2024:05:06 07:08:00";
fields.digitized = "2024:05:06 07:08:01";
fields.modified = "2024:05:06 07:08:09";
fields.orientation = 6;
auto bytes = libfiles::make_exif(fields);
libfiles::reader reader(bytes);
const auto ifd0 = reader.le32(4);
const auto count = reader.le16(ifd0);
auto dimensions = 0;
for (auto i = 0u; i < count; ++i)
{
const auto at = ifd0 + 2u + i * 12u;
const auto tag = reader.le16(at);
if (tag != 0x011a && tag != 0x011b) continue;
// Replace the writer's resolution entries with a TIFF image's dimensions.
const uint8_t entry[] = {static_cast<uint8_t>(tag == 0x011a ? 0x00 : 0x01), 0x01, 0x03, 0, 1, 0, 0, 0,
static_cast<uint8_t>(tag == 0x011a ? 64 : 32), 0, 0, 0};
std::copy(std::begin(entry), std::end(entry), bytes.begin() + at);
++dimensions;
}
assert_equal(2, dimensions, "the TIFF fixture declares width and height");
mem_read_stream stream({bytes.data(), bytes.size()});
auto scanned = scan_photo(stream, libfiles::scan_intent::index, false);
assert_equal(true, scanned.success, "TIFF metadata is scanned without decoding pixels");
assert_equal(true, scanned.metadata.exif.empty(), "the image is not copied into an EXIF block");
const auto md = scanned.to_props();
assert_equal("Canon"sv, md->camera_manufacturer.sv(), "TIFF camera make");
assert_equal("EOS R5"sv, md->camera_model.sv(), "TIFF camera model");
assert_equal("RF 50mm F1.8"sv, md->lens.sv(), "TIFF lens");
assert_equal(400, static_cast<int>(md->iso_speed), "TIFF ISO");
assert_equal(true, std::abs(md->f_number - 2.8f) < 0.0001f, "TIFF aperture");
assert_equal(true, std::abs(md->exposure_time - 1.0f / 250) < 0.000001f, "TIFF exposure");
assert_equal(core::date_t(2024, 5, 6, 7, 8, 0), md->dates.original(), "TIFF capture date");
assert_equal(core::date_t(2024, 5, 6, 7, 8, 1), md->dates.created(), "TIFF digitized date");
assert_equal(core::date_t(2024, 5, 6, 7, 8, 9), md->dates.modified(), "TIFF modified date");
assert_equal(core::orientation::right_top, md->orientation, "TIFF orientation");
libfiles::xmp::meta xmp;
xmp.set_property(libfiles::xmp::ns::tiff, "Model", "XMP camera");
const auto packet = xmp.serialize();
scanned.metadata.xmp.assign(packet.begin(), packet.end());
assert_equal("XMP camera"sv, scanned.to_props()->camera_model.sv(), "XMP still overrides native TIFF fields");
}
static std::string panorama_packet(const prop::panorama_geometry& geometry)
{
return std::format("<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"><rdf:RDF "
"xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">"
"<rdf:Description rdf:about=\"\" xmlns:GPano=\"http://ns.google.com/photos/1.0/panorama/\" "
"GPano:ProjectionType=\"equirectangular\" GPano:FullPanoWidthPixels=\"{}\" "
"GPano:FullPanoHeightPixels=\"{}\" GPano:CroppedAreaLeftPixels=\"{}\" "
"GPano:CroppedAreaTopPixels=\"{}\" GPano:CroppedAreaImageWidthPixels=\"{}\" "
"GPano:CroppedAreaImageHeightPixels=\"{}\"/></rdf:RDF></x:xmpmeta>",
geometry.full_width, geometry.full_height, geometry.cropped_left, geometry.cropped_top,
geometry.cropped_width, geometry.cropped_height);
}
static core::file_path write_panorama_fixture(const bool heif, const std::string_view packet, const bool compress)
{
const auto path = test_temps.next_path(heif ? ".heif" : ".jxl");
if (heif)
{
const std::unique_ptr<heif_context, decltype(&heif_context_free)> context(heif_context_alloc(),
heif_context_free);
assert_equal(true, context != nullptr, "HEIF context created");
heif_image* raw_image = nullptr;
assert_equal(heif_error_Ok,
heif_image_create(4, 2, heif_colorspace_RGB, heif_chroma_interleaved_RGB, &raw_image).code,
"HEIF image created");
const std::unique_ptr<heif_image, decltype(&heif_image_release)> image(raw_image, heif_image_release);
assert_equal(heif_error_Ok, heif_image_add_plane(image.get(), heif_channel_interleaved, 4, 2, 8).code,
"HEIF plane allocated");
int stride = 0;
auto* const plane = heif_image_get_plane(image.get(), heif_channel_interleaved, &stride);
assert_equal(true, plane != nullptr && stride >= 12, "HEIF plane is large enough");
std::memset(plane, 64, static_cast<size_t>(stride) * 2);
heif_encoder* raw_encoder = nullptr;
assert_equal(heif_error_Ok,
heif_context_get_encoder_for_format(context.get(), heif_compression_uncompressed, &raw_encoder)
.code,
"HEIF encoder available");
const std::unique_ptr<heif_encoder, decltype(&heif_encoder_release)> encoder(raw_encoder, heif_encoder_release);
heif_image_handle* raw_handle = nullptr;
assert_equal(heif_error_Ok,
heif_context_encode_image(context.get(), image.get(), encoder.get(), nullptr, &raw_handle).code,
"HEIF fixture encoded");
const std::unique_ptr<heif_image_handle, decltype(&heif_image_handle_release)>
handle(raw_handle, heif_image_handle_release);
assert_equal(heif_error_Ok,
heif_context_add_XMP_metadata(context.get(), handle.get(), packet.data(),
static_cast<int>(packet.size()))
.code,
"GPano embedded in HEIF");
assert_equal(heif_error_Ok, heif_context_write_to_file(context.get(), path.str().c_str()).code,
"HEIF fixture written");
}
else
{
const std::unique_ptr<JxlEncoder, decltype(&JxlEncoderDestroy)> encoder(JxlEncoderCreate(nullptr),
JxlEncoderDestroy);
assert_equal(true, encoder != nullptr, "JPEG XL encoder created");
JxlBasicInfo info{};
JxlEncoderInitBasicInfo(&info);
info.xsize = 4;
info.ysize = 2;
info.bits_per_sample = 8;
info.uses_original_profile = JXL_TRUE;
info.num_color_channels = 3;
assert_equal(JXL_ENC_SUCCESS, JxlEncoderSetBasicInfo(encoder.get(), &info), "JPEG XL geometry accepted");
JxlColorEncoding color{};
JxlColorEncodingSetToSRGB(&color, JXL_FALSE);
assert_equal(JXL_ENC_SUCCESS, JxlEncoderSetColorEncoding(encoder.get(), &color), "JPEG XL colour accepted");
assert_equal(JXL_ENC_SUCCESS, JxlEncoderUseContainer(encoder.get(), JXL_TRUE), "JPEG XL container enabled");
assert_equal(JXL_ENC_SUCCESS, JxlEncoderUseBoxes(encoder.get()), "JPEG XL metadata enabled");
assert_equal(JXL_ENC_SUCCESS,
JxlEncoderAddBox(encoder.get(), "xml ", reinterpret_cast<const uint8_t*>(packet.data()),
packet.size(), compress ? JXL_TRUE : JXL_FALSE),
"GPano embedded in JPEG XL");
auto* const settings = JxlEncoderFrameSettingsCreate(encoder.get(), nullptr);
assert_equal(true, settings != nullptr, "JPEG XL frame settings created");
assert_equal(JXL_ENC_SUCCESS, JxlEncoderSetFrameLossless(settings, JXL_TRUE), "lossless JPEG XL fixture");
assert_equal(JXL_ENC_SUCCESS, JxlEncoderFrameSettingsSetOption(settings, JXL_ENC_FRAME_SETTING_EFFORT, 1),
"fast fixture encoding");
const JxlPixelFormat format{3, JXL_TYPE_UINT8, JXL_NATIVE_ENDIAN, 0};
const std::array<uint8_t, 24> pixels{};
assert_equal(JXL_ENC_SUCCESS, JxlEncoderAddImageFrame(settings, &format, pixels.data(), pixels.size()),
"JPEG XL pixels accepted");
JxlEncoderCloseInput(encoder.get());
std::array<uint8_t, 16384> encoded{};
auto* next = encoded.data();
auto available = encoded.size();
assert_equal(JXL_ENC_SUCCESS, JxlEncoderProcessOutput(encoder.get(), &next, &available),
"JPEG XL fixture encoded");
const auto size = encoded.size() - available;
const std::string_view contents(reinterpret_cast<const char*>(encoded.data()), size);
assert_equal(compress, contents.find("brob") != std::string_view::npos,
"the fixture exercises compressed boxes");
std::ofstream file(platform::to_stream_path(path), std::ios::binary);
file.write(reinterpret_cast<const char*>(encoded.data()), static_cast<std::streamsize>(size));
file.close();
assert_equal(true, file.good(), "JPEG XL fixture written");
}
return path;
}
static void should_read_embedded_panorama_geometry()
{
const prop::panorama_geometry embedded{8, 4, 2, 1, 4, 2};
const prop::panorama_geometry sidecar{12, 6, 0, 0, 4, 2};
for (const auto heif : {true, false})
{
for (const auto compress : {false, true})
{
if (heif && compress) continue;
const auto path = write_panorama_fixture(heif, panorama_packet(embedded), compress);
assert_equal(true, metadata_xmp::panorama(path) == embedded, "embedded HEIF/JPEG XL GPano geometry");
const auto sidecar_path = path.extension(".xmp");
std::ofstream file(platform::to_stream_path(sidecar_path), std::ios::binary);
const auto packet = panorama_packet(sidecar);
file.write(packet.data(), static_cast<std::streamsize>(packet.size()));
file.close();
assert_equal(true, file.good(), "sidecar fixture written");
assert_equal(true, metadata_xmp::panorama(path) == embedded, "valid embedded geometry keeps precedence");
auto incomplete = embedded;
incomplete.full_height = 0;
const auto fallback_path = write_panorama_fixture(heif, panorama_packet(incomplete), compress);
assert_equal(false, metadata_xmp::panorama(fallback_path).is_valid(),
"incomplete geometry is not projected");
const auto fallback_sidecar = fallback_path.extension(".xmp");
std::ofstream fallback(platform::to_stream_path(fallback_sidecar), std::ios::binary);
fallback.write(packet.data(), static_cast<std::streamsize>(packet.size()));
fallback.close();
assert_equal(true, fallback.good(), "fallback sidecar written");
assert_equal(true, metadata_xmp::panorama(fallback_path) == sidecar,
"the sidecar replaces the incomplete embedded declaration as a whole");
}
}
}
static void should_merge_xmp_sidecar()
{
const auto cr2_path = test_files_folder().combine_file("Gherkin.CR2");
const auto xmp_path = test_files_folder().combine_file("Gherkin.xmp");
const auto actual = extract_properties(cr2_path);
metadata_xmp::parse(*actual, xmp_path);
assert_equal("Canon", actual->camera_manufacturer);
assert_equal("United Kingdom", actual->location_country);
assert_equal("© Mark Ridgwell", actual->copyright_notice);
assert_equal("\"Mark Ridgwell\"", actual->copyright_creator);
}
static void should_scan_mp3()
{
const auto load_path = test_files_folder().combine_file("Colorblind.mp3");
files ff;
const auto actual = ff_scan_file(ff, load_path);
prop::item_metadata expected;
expected.artist = "Counting Crows"_c;
expected.album_artist = "Counting Crows"_c;
expected.title = "Colorblind"_c;
expected.album = "This Desert Life"_c;
expected.comment = "Comments"_c;
expected.composer = "Adam Duritz/Charlie Gillingham"_c;
expected.publisher = "Interscope"_c;
expected.rating = 5;
expected.genre = "Rock"_c;
expected.duration = 10;
expected.audio_sample_rate = 22050;
expected.audio_channels = 2;
expected.audio_codec = "mp3"_c;
expected.track.x = 7;
expected.year = 1999;
// Its tag gives only the year, which dates the track rather than leaving it to the day it was copied.
expected.dates.add(prop::date_source::container_created, core::date_t(1999, 1, 1, 0, 0, 0));
assert_metadata(expected, *actual.to_props(), "Colorblind.mp3");
const auto load_path2 = test_files_folder().combine_file("Games Without Frontiers.mp3");
const auto actual2 = ff_scan_file(ff, load_path2);
prop::item_metadata expected2;
expected2.artist = "Peter Gabriel"_c;
expected2.album = "Hit"_c;
expected2.title = "Games Without Frontiers"_c;
expected2.year = 2003;
expected2.genre = "Rock"_c;
expected2.duration = 10;
expected2.audio_sample_rate = 44100;
expected2.audio_channels = 2;
expected2.track.x = 5;
expected2.disk.x = 1;
expected2.encoder = "Lavf51.12.1"_c;
expected2.audio_codec = "mp3"_c;
expected2.dates.add(prop::date_source::container_created, core::date_t(2003, 1, 1, 0, 0, 0));
assert_metadata(expected2, *actual2.to_props(), "Games Without Frontiers.mp3");
const auto load_path3 = test_files_folder().combine_file("Is It Any Wonder.mp3");
const auto actual3 = ff_scan_file(ff, load_path3);
prop::item_metadata expected3;
expected3.artist = "Keane"_c;
expected3.album = "Under The Iron Sea"_c;
expected3.title = "Is It Any Wonder?"_c;
expected3.year = 2006;
expected3.genre = "Rock"_c;
expected3.duration = 10;
expected3.audio_sample_rate = 44100;
expected3.audio_channels = 2;
expected3.track.x = 2;
expected3.audio_codec = "mp3"_c;
// TDRC "2006-06-20" names a calendar day, not an instant, so it is the day wherever it is shown.
expected3.dates.add(prop::date_source::container_created, core::date_t(2006, 6, 20, 0, 0, 0));
expected3.publisher = "Interscope"_c;
assert_metadata(expected3, *actual3.to_props(), "Is It Any Wonder.mp3");
}
static void should_scan_mp4()
{
const auto load_path = test_files_folder().combine_file("gizmo.mp4");
files ff;
const auto actual = ff_scan_file(ff, load_path);
prop::item_metadata expected;
expected.title = "Title xxx"_c;
expected.comment = "Comments xxx"_c;
expected.tags = "gadget test"_c;
expected.audio_codec = "aac"_c;
expected.audio_sample_rate = 48000;
expected.audio_channels = 1;
expected.duration = 6;
expected.width = 560;
expected.height = 320;
expected.rating = 4;
expected.dates.add_utc(prop::date_source::container_created, core::date_t(2010, 3, 20, 21, 29, 11));
expected.dates.add_utc(prop::date_source::xmp_modify, core::date_t(2010, 3, 20, 21, 29, 12));
expected.year = 2010;
expected.video_codec = "h264"_c;
expected.encoder = "HandBrake 0.9.4 2009112300"_c;
expected.pixel_format = "yuv420"_c;
assert_metadata(expected, *actual.to_props(), "gizmo.mp4");
const auto load_path2 = test_files_folder().combine_file("This Year's Love.m4a");
const auto actual2 = ff_scan_file(ff, load_path2);
prop::item_metadata expected2;
expected2.title = "This Year's Love"_c;
expected2.artist = "David Gray"_c;
expected2.album_artist = "David Gray"_c;
expected2.composer = "David Gray"_c;
expected2.album = "David Gray: Greatest Hits"_c;
expected2.copyright_notice = "\u2117 2007 Iht Records Ltd under exclusive licence to Warner Music UK Ltd"_c;
expected2.dates.add_utc(prop::date_source::container_created, core::date_t(2007, 11, 9, 8, 0, 0));
expected2.genre = "Pop"_c;
expected2.duration = 10;
expected2.audio_codec = "aac"_c;
expected2.audio_sample_rate = 44100;
expected2.audio_channels = 2;
expected2.track = {7, 0};
expected2.width = 0;
expected2.height = 0;
expected2.disk = {0, 0};
expected2.year = 2007;
expected2.encoder = "Lavf54.63.100"_c;
assert_metadata(expected2, *actual2.to_props(), "This Year's Love.m4a");
assert_equal(true, is_empty(actual2.thumbnail_image), "m4a scan thumbnail");
const auto loaded = ff_scan_and_load_thumb(ff, load_path2);
assert_equal(false, loaded.success && is_valid(loaded.thumbnail_surface), "m4a load thumbnail");
}
static void should_preserve_high_audio_sample_rates()
{
file_scan_result scanned;
scanned.audio_sample_rate = 192000;
scanned.audio_channels = 6;
const auto props = scanned.to_props();
assert_equal(192000u, props->audio_sample_rate, "192 kHz stays exact in indexed metadata");
assert_equal(6, static_cast<int>(props->audio_channels), "channel count still converts beside it");
assert_equal("192kHz", prop::format_audio_sample_rate(props->audio_sample_rate), "high rate formats exactly");
}
// Issue #3 - Cannot remove MP4 tags added in an old version.
// Old versions left tags in the native MP4 'KEYW' atom (surfaced by FFmpeg as the
// "keywords" tag). When a file also carries embedded XMP, dc:subject is the
// authoritative tag list, so a stale container keyword must not resurrect a tag
// that was removed via XMP.
static void should_not_resurrect_container_tags()
{
metadata_edits unrelated_edits;
unrelated_edits.title = "unrelated xmp";
std::string unrelated_xmp;
metadata_xmp::update(unrelated_xmp, unrelated_edits);
file_scan_result absent_subject;
absent_subject.ffmpeg_metadata.emplace_back(core::cache("keywords"), "nativekey");
absent_subject.metadata.xmp.assign(unrelated_xmp.begin(), unrelated_xmp.end());
assert_equal("nativekey"_c, absent_subject.to_props()->tags, "unrelated xmp does not suppress native keywords");
// Serialise an XMP packet whose dc:subject holds only the kept tag - this
// represents the state right after the stuck tag was removed via XMP.
metadata_edits edits;
edits.add_tags = tag_set("keeptag");
std::string xmp_buffer;
metadata_xmp::update(xmp_buffer, edits);
// A scan result carrying the stale container keyword AND the embedded XMP.
file_scan_result sr;
sr.ffmpeg_metadata.emplace_back(core::cache("keywords"), "stucktag");
sr.metadata.xmp.assign(xmp_buffer.begin(), xmp_buffer.end());
const auto md = sr.to_props();
// Only the XMP tag survives; the stale KEYW keyword is not merged back in.
assert_equal("keeptag"_c, md->tags, "xmp authoritative over stale container keyword");
metadata_edits empty_edits;
empty_edits.add_tags = tag_set("temporary");
std::string empty_xmp;
metadata_xmp::update(empty_xmp, empty_edits);
metadata_edits clear_edits;
clear_edits.remove_tags = tag_set("temporary");
metadata_xmp::update(empty_xmp, clear_edits);
file_scan_result empty_subject;
empty_subject.ffmpeg_metadata.emplace_back(core::cache("keywords"), "nativekey");
empty_subject.metadata.xmp.assign(empty_xmp.begin(), empty_xmp.end());
assert_equal(true, empty_subject.to_props()->tags.is_empty(), "empty xmp subject suppresses native keywords");
}
static void should_apply_property_level_windows_metadata_precedence()
{
metadata_edits unrelated_edits;
unrelated_edits.title = "unrelated xmp";
std::string unrelated_xmp;
metadata_xmp::update(unrelated_xmp, unrelated_edits);
file_scan_result fallback;
fallback.ffmpeg_metadata.emplace_back(core::cache("WM/Category"), "WindowsTag");
fallback.ffmpeg_metadata.emplace_back(core::cache("WM/SharedUserRating"), "75");
fallback.metadata.xmp.assign(unrelated_xmp.begin(), unrelated_xmp.end());
const auto fallback_metadata = fallback.to_props();
assert_equal("WindowsTag"_c, fallback_metadata->tags, "unrelated xmp allows windows tags");
assert_equal(4, fallback_metadata->rating, "unrelated xmp allows windows rating");
metadata_edits cleared_edits;
cleared_edits.add_tags = tag_set("temporary");
cleared_edits.rating = 5;
std::string cleared_xmp;
metadata_xmp::update(cleared_xmp, cleared_edits);
metadata_edits remove_edits;
remove_edits.remove_tags = tag_set("temporary");
remove_edits.remove_rating = true;
metadata_xmp::update(cleared_xmp, remove_edits);
file_scan_result cleared;
cleared.ffmpeg_metadata.emplace_back(core::cache("WM/Category"), "StaleTag");
cleared.ffmpeg_metadata.emplace_back(core::cache("WM/SharedUserRating"), "99");
cleared.metadata.xmp.assign(cleared_xmp.begin(), cleared_xmp.end());
const auto cleared_metadata = cleared.to_props();
assert_equal(true, cleared_metadata->tags.is_empty(), "cleared xmp tags suppress stale windows tags");
assert_equal(0, cleared_metadata->rating, "cleared xmp rating suppresses stale windows rating");
}
// Issue #238 - FFmpeg names a Matroska tag in a language other than its default "<key>-<lang>", with no
// plain key beside it, so where FFmpeg reads a file's tags - libfiles could not - a field tagged only
// that way was dropped. A field named in several languages reads the plain key first, then the UI
// language, then any other, whatever order they come in; the suffixed model and comment keys keep
// their own meanings, and a sort key is not a language.
static void should_read_language_suffixed_container_tags()
{
const auto ui_language = setting.language;
const core::scope_exit restore([ui_language] { setting.language = ui_language; });
setting.language = "de";
file_scan_result only_suffixed;
only_suffixed.ffmpeg_metadata.emplace_back(core::cache("TITLE-eng"), "English title");
only_suffixed.ffmpeg_metadata.emplace_back(core::cache("ARTIST-fra"), "Artiste");
const auto suffixed = only_suffixed.to_props();
assert_equal("English title"_c, suffixed->title, "a title tagged only in a language is read");
assert_equal("Artiste"_c, suffixed->artist, "and so is an artist");
file_scan_result several;
several.ffmpeg_metadata.emplace_back(core::cache("TITLE-eng"), "English title");
several.ffmpeg_metadata.emplace_back(core::cache("TITLE-ger"), "Deutscher Titel");
several.ffmpeg_metadata.emplace_back(core::cache("TITLE-fra"), "Titre");
several.ffmpeg_metadata.emplace_back(core::cache("ALBUM-deu"), "Album auf Deutsch");
several.ffmpeg_metadata.emplace_back(core::cache("ALBUM"), "Plain album");
several.ffmpeg_metadata.emplace_back(core::cache("ALBUM-fra"), "Album en francais");
const auto languages = several.to_props();
assert_equal("Deutscher Titel"_c, languages->title, "the UI language is read before the others");
assert_equal("Plain album"_c, languages->album, "and the plain key before any language, whatever the order");
file_scan_result special;
special.ffmpeg_metadata.emplace_back(core::cache("model-eng"), "Camera");
special.ffmpeg_metadata.emplace_back(core::cache("COMMENT-deu"), "Kommentar");
special.ffmpeg_metadata.emplace_back(core::cache("title-sort"), "Sort title");
const auto kept = special.to_props();
assert_equal("Camera"_c, kept->camera_model, "a suffixed model is still the camera model");
assert_equal("Kommentar"_c, kept->comment, "a Matroska comment in a language is read as the comment");
assert_equal(true, prop::is_null(kept->title), "and a sort key is not mistaken for a language");
}
// Matroska stores metadata as EBML SimpleTags, which FFmpeg surfaces verbatim - so the
// upper-case names Matroska specifies (TITLE, RATING, ...) only reach the UI because our
// key matching is case-insensitive. WebM is the same container with a different DocType,
// so it must behave identically. Nothing else in the corpus is EBML.
static void should_scan_matroska(const std::string_view name, const std::string_view video_codec)
{
files ff;
const auto actual = ff_scan_file(ff, test_files_folder().combine_file(name));
prop::item_metadata expected;
expected.title = "Matroska Test Title"_c;
expected.artist = "Matroska Test Artist"_c;
expected.genre = "TestGenre"_c;
expected.comment = "matroska test comment"_c;
expected.tags = "alpha beta"_c;
expected.rating = 4;
expected.width = 16;
expected.height = 16;
expected.duration = 1;
expected.encoder = "diffractor-test"_c; // Matroska MuxingApp
expected.video_codec = core::cache(video_codec);
assert_metadata(expected, *actual.to_props(), name);
}
static void should_scan_mov()
{
const auto load_path = test_files_folder().combine_file("ipod.mov");
files ff;
const auto actual = ff_scan_file(ff, load_path);
prop::item_metadata expected;
expected.title = "iPad Help"_c;
expected.tags = "apple ipad ipod support"_c;
expected.comment = "What to do if you ipad dies"_c;
expected.audio_codec = "aac"_c;
expected.audio_sample_rate = 32000;
expected.audio_channels = 1;
expected.pixel_format = "yuv420"_c;
expected.duration = 86;
expected.width = 640;
expected.height = 480;
expected.rating = 4;
expected.video_codec = "mpeg4"_c;
expected.dates.add_utc(prop::date_source::container_created, core::date_t(2005, 10, 17, 22, 54, 32));
expected.dates.add_utc(prop::date_source::xmp_modify, core::date_t(2005, 10, 17, 22, 56, 39));
expected.year = 2005;
assert_metadata(expected, *actual.to_props(), "ipod.mov");
const auto load_path2 = test_files_folder().combine_file("StPauls.MOV");
const auto actual2 = ff_scan_file(ff, load_path2);
prop::item_metadata expected2;
// Apple's creation date states the offset of the zone it was made in, so it is the time the camera's
// clock showed there, as a photo's EXIF time with its offset is.
expected2.dates.add(prop::date_source::container_created, core::date_t(2011, 3, 13, 15, 13, 49), 0);
expected2.audio_codec = "aac"_c;
// Issue #61: the QuickTime ISO6709 location tag must reach the coordinate, or the world map
// cannot plot the video.
expected2.coordinate = {51.51420, -0.09850};
// StPauls.MOV carries a Windows Explorer 'London' tag (WM/Category, no XMP),
// now surfaced by the FFmpeg 'Xtra' reader. (#123)
expected2.tags = "London"_c;
expected2.width = 640;
expected2.height = 480;
expected2.duration = 10;
expected2.audio_sample_rate = 44100;
expected2.audio_channels = 1;
expected2.video_codec = "h264"_c;
expected2.camera_manufacturer = "Apple"_c;
expected2.camera_model = "iPhone 3GS"_c;
expected2.encoder = "4.3"_c;
expected2.pixel_format = "yuv420"_c;
expected2.year = 2011;
assert_metadata(expected2, *actual2.to_props(), "StPauls.MOV");
}
static void should_scan_avi()
{
const auto load_path = test_files_folder().combine_file("Byzantium.avi");
files ff;
const auto actual = ff_scan_file(ff, load_path);
prop::item_metadata expected;
expected.audio_codec = "wmav2"_c;
expected.title = "Byzantium"_c;
expected.comment =
"John Romer recreates the glory and history of Byzantium. From the Hagia Sophia in present-day Istanbul to the looted treasures of the empire now located in St. Marks in Venice."_c;
expected.audio_sample_rate = 48000;
expected.audio_channels = 2;
expected.duration = 12;
expected.width = 854;
expected.height = 480;
expected.video_codec = "wmv3"_c;
expected.tags = "Byzantium History Turkey"_c;
expected.pixel_format = "yuv420"_c;
assert_metadata(expected, *actual.to_props(), "Byzantium.avi");
}
static void should_scan_raw()
{
const auto load_path = test_files_folder().combine("raw").combine_file("Screws.CR2");
prop::item_metadata expected;
expected.file_name = "Screws.CR2"_c;
expected.copyright_notice = "Copyright"_c;
expected.tags = "Desk Macro Screws"_c;
expected.title = "Screws on Desk"_c;
expected.description = "This is a Description"_c;
expected.comment = "This is a Comment"_c;
expected.rating = 4;
expected.width = 3522;
expected.height = 2348;
expected.f_number = 2.8f;
expected.camera_manufacturer = "Canon"_c;
expected.camera_model = "EOS-1D Mark II"_c;
expected.exposure_time = 1 / 25.0f;
expected.focal_length = 100;
expected.iso_speed = 100;
expected.pixel_format = "RGBG"_c;
expected.dates.add(prop::date_source::embedded_created, core::date_t(2011, 9, 23, 23, 49, 16));
null_async_strategy as;
const location_cache locations;
index_state index(as, locations);
const auto actual = metadata_from_cache(index, load_path);
assert_metadata(expected, *actual, "Screws.CR2");
}
static void should_scan_mod()
{
constexpr auto file_name = "giana.mod";
const auto load_path = test_files_folder().combine("retro").combine_file(file_name);
files ff;
const auto actual = ff_scan_file(ff, load_path);
const auto props = actual.to_props();
assert_equal("giana!"_c, props->title, "title", file_name);
assert_equal("Generic ProTracker or compatible"_c, props->encoder, "encoder", file_name);
assert_equal(48000u, props->audio_sample_rate, "audio_sample_rate", file_name);
}
static std::string png_test_xmp(int rating);
static void should_scan_heic()
{
constexpr auto file_name = "melnik.heic";
const auto load_path = test_files_folder().combine_file(file_name);
files ff;
const auto actual = ff_scan_file(ff, load_path);
const auto props = actual.to_props();
assert_equal(4000, props->width, "width", file_name);
assert_equal(2252, props->height, "height", file_name);
assert_equal("yuv420", props->pixel_format, "pixel_format", file_name);
}
static void should_not_double_apply_heif_rotation()
{
// This asset carries an 'irot' transform property (270 degrees CCW) alongside an Exif
// Orientation tag (6) describing the same quarter turn, which is what phone cameras
// write. libheif applies 'irot' itself: it swaps the dimensions reported by
// heif_image_handle_get_width/height and rotates the decoded pixels. Applying the
// Exif orientation on top of that would rotate the image a second time.
constexpr auto file_name = "melnik-rotated.heic";
const auto load_path = test_files_folder().combine("excluded1").combine_file(file_name);