Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/write-parity/matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -2253,13 +2253,13 @@
},
"JPEG|EXIF|set": {
"status": "partial",
"reason": "Hand-mapped tags; full writable table and group routing open (serializer-exif spec).",
"reason": "Full standard writable catalog with group routing; add/replace modes and per-tag differential sweep open (serializer-exif spec).",
"fixture": null,
"test": "src/write/jpeg-merge.test.ts"
},
"JPEG|GPS|set": {
"status": "partial",
"reason": "Partial tag map; negative-coordinate synthesis and group routing open.",
"status": "implemented",
"reason": "Full GPS tag table, qualified group routing, negative-coordinate ref synthesis; upstream round-trip tests.",
"fixture": null,
"test": "src/write/jpeg-merge.test.ts"
},
Expand Down Expand Up @@ -2319,13 +2319,13 @@
},
"TIFF|EXIF|set": {
"status": "partial",
"reason": "Plain TIFF subset only; camera RAW write is refused (tiff-raw.ts).",
"reason": "Full standard catalog into plain TIFF; camera RAW/SubIFD files refused (tiff-raw.ts); per-tag differential sweep open.",
"fixture": null,
"test": "src/write/tiff-merge.test.ts"
},
"TIFF|GPS|set": {
"status": "partial",
"reason": "Plain TIFF subset only.",
"reason": "Full GPS catalog into plain TIFF; no dedicated GPS round-trip tests yet.",
"fixture": null,
"test": "src/write/tiff-merge.test.ts"
},
Expand Down
8 changes: 4 additions & 4 deletions scripts/generate-matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ export function parseUpstreamTables(readme: string): { fileTypes: MatrixEntry[];
const PARTIALS: Record<string, CellOverride> = {
'JPEG|Ducky APP12|set': { status: 'partial', reason: 'Quality/Comment/Copyright only; unknown blocks preserved byte-for-byte.', fixture: null, test: 'src/write/writers.test.ts' },
'JPEG|EXIF|delete': { status: 'partial', reason: 'Null deletes one targeted tag; update/add/replace modes open (serializer-exif spec).', fixture: null, test: 'src/write/jpeg-merge.test.ts' },
'JPEG|EXIF|set': { status: 'partial', reason: 'Hand-mapped tags; full writable table and group routing open (serializer-exif spec).', fixture: null, test: 'src/write/jpeg-merge.test.ts' },
'JPEG|GPS|set': { status: 'partial', reason: 'Partial tag map; negative-coordinate synthesis and group routing open.', fixture: null, test: 'src/write/jpeg-merge.test.ts' },
'JPEG|EXIF|set': { status: 'partial', reason: 'Full standard writable catalog with group routing; add/replace modes and per-tag differential sweep open (serializer-exif spec).', fixture: null, test: 'src/write/jpeg-merge.test.ts' },
'JPEG|GPS|set': { status: 'implemented', reason: 'Full GPS tag table, qualified group routing, negative-coordinate ref synthesis; upstream round-trip tests.', fixture: null, test: 'src/write/jpeg-merge.test.ts' },
'JPEG|ICC Profile|set': { status: 'partial', reason: 'Whole-profile set/delete only; ICC tag editing open (serializer-families spec).', fixture: null, test: 'src/write/writers.test.ts' },
'JPEG|IPTC|set': { status: 'partial', reason: 'Generated datasets in APP13 only; multi-container integration open (serializer-iptc spec).', fixture: null, test: 'src/write/iptc.test.ts' },
'JPEG|JFIF|set': { status: 'partial', reason: 'Density set/create only; thumbnails and remaining fields open.', fixture: null, test: 'src/write/writers.test.ts' },
Expand All @@ -102,8 +102,8 @@ const PARTIALS: Record<string, CellOverride> = {
'HEIF|EXIF|set': { status: 'partial', reason: 'Partial EXIF write; item/iloc handling open.', fixture: null, test: 'src/format/avif.test.ts' },
'GIF|XMP|set': { status: 'partial', reason: 'XMP application extension subset; C2PA delete open.', fixture: null, test: 'src/write/gif.test.ts' },
'GIF|ICC Profile|set': { status: 'partial', reason: 'ICC application extension subset.', fixture: null, test: 'src/write/gif.test.ts' },
'TIFF|EXIF|set': { status: 'partial', reason: 'Plain TIFF subset only; camera RAW write is refused (tiff-raw.ts).', fixture: null, test: 'src/write/tiff-merge.test.ts' },
'TIFF|GPS|set': { status: 'partial', reason: 'Plain TIFF subset only.', fixture: null, test: 'src/write/tiff-merge.test.ts' },
'TIFF|EXIF|set': { status: 'partial', reason: 'Full standard catalog into plain TIFF; camera RAW/SubIFD files refused (tiff-raw.ts); per-tag differential sweep open.', fixture: null, test: 'src/write/tiff-merge.test.ts' },
'TIFF|GPS|set': { status: 'partial', reason: 'Full GPS catalog into plain TIFF; no dedicated GPS round-trip tests yet.', fixture: null, test: 'src/write/tiff-merge.test.ts' },
'EXIF|EXIF|set': { status: 'partial', reason: 'Standalone update subset; create semantics open.', fixture: null, test: 'src/format/exif.test.ts' },
'EXV|EXIF|set': { status: 'partial', reason: 'Standalone update subset; create semantics open.', fixture: null, test: 'src/format/exv.test.ts' },
'XMP|XMP|set': { status: 'partial', reason: 'Parser/writer + sidecar subset; namespace/schema parity open.', fixture: null, test: 'src/format/xmp.test.ts' },
Expand Down
48 changes: 48 additions & 0 deletions scripts/generate-tags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { assertEquals } from '../src/test/asserts.js';
import {
assertPinnedExifToolVersion,
assertWritableTypesClassified,
collectWritableExifTags,
collectWritableXmpShapes,
parseExifToolXml,
parseExifToolXmpNamespaces,
Expand Down Expand Up @@ -117,3 +118,50 @@ test('tag generation uses source IDs when XMP display names differ', () => {
{ 'Iptc4xmpExt:RegistryId': 'bag' },
);
});

test('writable EXIF catalog routes by WriteGroup, table WRITE_GROUP, then home group', () => {
const tables = parseExifToolXml([
"<table name='Exif::Main' g0='EXIF' g1='IFD0'>",
" <tag id='11' name='ProcessingSoftware' type='string' writable='true'/>",
" <tag id='37386' name='UserComment' type='string' writable='true' g2='Image'/>",
'</table>',
"<table name='GPS::Main' g0='GPS' g1='GPS'>",
" <tag id='2' name='GPSLatitude' type='rational64u' writable='true'/>",
'</table>',
].join('\n'));
const tableByName = new Map(tables.map((table) => [table.perlName, table]));
const groups = collectWritableExifTags([
// Explicit per-tag WriteGroup wins over the table default.
{ table: 'Exif::Main', id: '11', name: 'ProcessingSoftware', writable: 'string', writeGroup: 'IFD0' },
// No per-tag WriteGroup: falls back to the tag's home group (Groups{1}).
{ table: 'Exif::Main', id: '37386', name: 'UserComment', writable: 'string', groups1: 'ExifIFD' },
// GPS::Main carries no write group at all: the table-level WRITE_GROUP applies.
{ table: 'GPS::Main', id: '2', name: 'GPSLatitude', writable: 'rational64u', tableWriteGroup: 'GPS' },
{ table: 'GPS::Main', id: 'x', name: 'Garbage', writable: 'string' },
], tableByName);
assertEquals(groups.IFD0, [{ id: 11, name: 'ProcessingSoftware', type: 'string', protected: false, conditional: false }]);
assertEquals(groups.ExifIFD, [{ id: 37386, name: 'UserComment', type: 'string', protected: false, conditional: false }]);
assertEquals(groups.GPS, [{ id: 2, name: 'GPSLatitude', type: 'rational64u', protected: false, conditional: false }]);
});

test('writable EXIF catalog keeps conditional flags and joins PrintConv values', () => {
const tables = parseExifToolXml([
"<table name='Exif::Main' g0='EXIF' g1='IFD0'>",
" <tag id='274' name='Orientation' type='int16u' writable='true'>",
' <values>',
" <key id='1'>",
' <val lang=\'en\'>Horizontal (normal)</val>',
" </key>",
' </values>',
' </tag>',
'</table>',
].join('\n'));
const tableByName = new Map(tables.map((table) => [table.perlName, table]));
const groups = collectWritableExifTags([
{ table: 'Exif::Main', id: '274', name: 'Orientation', writable: 'int16u', writeGroup: 'IFD0' },
{ table: 'Exif::Main', id: '37500', name: 'MakerNoteCanon', writable: 'undef', groups1: 'ExifIFD', conditional: true },
], tableByName);
assertEquals(groups.IFD0, [{ id: 274, name: 'Orientation', type: 'int16u', values: { 1: 'Horizontal (normal)' }, protected: false, conditional: false }]);
// Conditional tags stay in the catalog with their flag; the writer refuses them.
assertEquals(groups.ExifIFD, [{ id: 37500, name: 'MakerNoteCanon', type: 'undef', protected: false, conditional: true }]);
});
75 changes: 75 additions & 0 deletions scripts/generate-tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ const OUTPUT_XMP_NAMESPACES = `${ROOT}/src/tags/generated/xmp-namespaces.json`;
const OUTPUT_XMP_SHAPES = `${ROOT}/src/tags/generated/xmp-shapes.json`;
const OUTPUT_XMP_STRUCTS = `${ROOT}/src/tags/generated/xmp-structs.json`;
const OUTPUT_WRITE_METADATA = `${ROOT}/src/tags/generated/write-metadata.json`;
const OUTPUT_WRITABLE_EXIF = `${ROOT}/src/exif/generated/writable-exif.json`;
const EXIF_WRITE_GROUPS = ['IFD0', 'ExifIFD', 'GPS', 'InteropIFD', 'SubIFD', 'IFD1'] as const;

export interface WritableExifTag {
id: number;
name: string;
/** Upstream Perl Writable type, e.g. 'int16u', 'string', 'rational64u'. */
type: string;
values?: Record<string, string>;
protected: boolean;
conditional: boolean;
}
const CLASSIFIED_WRITABLE_TYPES = new Set([
'?', 'GUID', 'Unicode', 'boolean', 'date', 'digits', 'double', 'fixed32s', 'fixed32u',
'float', 'int8s', 'int8u', 'int16s', 'int16u', 'int16uRev', 'int32s', 'int32u',
Expand Down Expand Up @@ -116,6 +128,8 @@ for my $table_name (@ARGV) {
},
writable => defined($writable) ? "$writable" : undef,
writeGroup => defined($info->{WriteGroup}) ? "$info->{WriteGroup}" : undef,
groups1 => defined($info->{Groups}{1}) ? "$info->{Groups}{1}" : undef,
tableWriteGroup => defined($table->{WRITE_GROUP}) ? "$table->{WRITE_GROUP}" : undef,
protected => !!($info->{Protected} || $table->{PROTECTED}),
conditional => !!$info->{Condition},
hasPrintConv => !!$info->{PrintConv},
Expand Down Expand Up @@ -300,6 +314,55 @@ export function collectWritableXmpShapes(
return shapes;
}

/**
* Writable records for the EXIF standard directories (writeGroup
* IFD0/ExifIFD/GPS/InteropIFD/SubIFD/IFD1), joined with the -listx
* PrintConv value tables. Condition-based tags keep their flag so the
* writer can refuse them until a reviewed handler exists.
*/
export function collectWritableExifTags(
records: Array<{
table: string;
id: string;
name: string;
writable?: string;
writeGroup?: string | null;
groups1?: string | null;
tableWriteGroup?: string | null;
protected?: boolean;
conditional?: boolean;
}>,
tableByName: Map<string, TableDef>,
): Record<(typeof EXIF_WRITE_GROUPS)[number], WritableExifTag[]> {
const groups = Object.fromEntries(
EXIF_WRITE_GROUPS.map((group) => [group, [] as WritableExifTag[]]),
) as Record<(typeof EXIF_WRITE_GROUPS)[number], WritableExifTag[]>;
const seen = new Set<string>();
for (const record of records) {
// Per-tag WriteGroup, else the table's WRITE_GROUP default, else the tag's home group.
const writeGroup = record.writeGroup ?? record.tableWriteGroup ?? record.groups1;
if (!record.writable || !writeGroup || !(EXIF_WRITE_GROUPS as readonly string[]).includes(writeGroup)) continue;
const numericId = Number(record.id);
if (!Number.isInteger(numericId) || numericId < 0) continue;
const dedupeKey = `${writeGroup}|${record.name}`;
if (seen.has(dedupeKey)) continue;
seen.add(dedupeKey);
const tag = tableByName.get(record.table)?.tags.find((t) => t.id === record.id && t.name === record.name);
groups[writeGroup as (typeof EXIF_WRITE_GROUPS)[number]].push({
id: numericId,
name: record.name,
type: record.writable,
...(tag?.values ? { values: tag.values } : {}),
protected: !!record.protected,
conditional: !!record.conditional,
});
}
for (const list of Object.values(groups)) {
list.sort((a, b) => a.id - b.id || a.name.localeCompare(b.name));
}
return groups;
}

export function assertWritableTypesClassified(tables: TableDef[]): void {
const unclassified = new Set(
tables.flatMap((table) => table.tags)
Expand Down Expand Up @@ -405,6 +468,7 @@ print JSON::PP->new->canonical->encode(\%shapes);
structSchema?: unknown;
writable?: string;
writeGroup?: string | null;
groups1?: string | null;
protected?: boolean;
conditional?: boolean;
hasPrintConv?: boolean;
Expand All @@ -425,6 +489,7 @@ print JSON::PP->new->canonical->encode(\%shapes);
const prefix = table && resolveXmpTablePrefix(table, xmpNamespaces);
if (prefix && tag) xmpStructs[`${prefix}:${tag.id}`] = record.structSchema;
}
const writableExif = collectWritableExifTags(writeMetadata.records, tableByName);

const totalTags = tables.reduce((s, t) => s + t.tags.length, 0);
const writableEntries = tables.flatMap((table) =>
Expand All @@ -448,6 +513,9 @@ print JSON::PP->new->canonical->encode(\%shapes);
await writeFile(OUTPUT_WRITE_METADATA, writeMetadataOutput);
const xmpStructsOutput = `${JSON.stringify(xmpStructs, null, 2)}\n`;
await writeFile(OUTPUT_XMP_STRUCTS, xmpStructsOutput);
await mkdir(`${ROOT}/src/exif/generated`, { recursive: true });
const writableExifOutput = `${JSON.stringify({ exiftoolVersion: version.trim(), groups: writableExif }, null, 2)}\n`;
await writeFile(OUTPUT_WRITABLE_EXIF, writableExifOutput);
const manifest = {
exiftoolVersion: version.trim(),
exiftoolSourceTreeSha1: sourceTreeSha256,
Expand All @@ -460,6 +528,8 @@ print JSON::PP->new->canonical->encode(\%shapes);
xmpStructsSha256: sha256(xmpStructsOutput),
coreWriteMetadataSha256: sha256(writeMetadataOutput),
coreWriteMetadataRecords: writeMetadata.records.length,
writableExifSha256: sha256(writableExifOutput),
writableExifTagCount: Object.values(writableExif).reduce((sum, tags) => sum + tags.length, 0),
unavailableCoreWriteMetadataTables: writeMetadata.missingTables,
coreWriteMetadataWritableRecords: writeMetadata.records.filter((record) => record.writable).length,
coreWriteGroupsSpecified: writeMetadata.records.filter((record) => record.writeGroup).length,
Expand Down Expand Up @@ -492,6 +562,11 @@ print JSON::PP->new->canonical->encode(\%shapes);
console.error(`Wrote ${OUTPUT_XMP_SHAPES} (${Object.keys(xmpShapes).length} writable list shapes)`);
console.error(`Wrote ${OUTPUT_XMP_STRUCTS} (${Object.keys(xmpStructs).length} struct schemas)`);
console.error(`Wrote ${OUTPUT_WRITE_METADATA} (${writeMetadata.records.length} Perl tag records)`);
console.error(
`Wrote ${OUTPUT_WRITABLE_EXIF} (${
Object.values(writableExif).reduce((sum, tags) => sum + tags.length, 0)
} writable EXIF tags)`,
);
console.error(`Wrote ${OUTPUT_MANIFEST}`);
} catch (error) {
const e = error as { stderr?: string | Buffer; message?: string };
Expand Down
Loading