Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to open an XMP XML file generated by darktable #234

Closed
tlhunter opened this issue Jul 30, 2024 · 4 comments
Closed

Unable to open an XMP XML file generated by darktable #234

tlhunter opened this issue Jul 30, 2024 · 4 comments

Comments

@tlhunter
Copy link

I'm attempting to open a darktable-generated XMP file. Of course it's not generated by an Adobe product so it might be a fool's errand. I'm not positive if darktable is generating a valid XMP file so I've included a copy.

Expected Behaviour

    let meta = XmpMeta::from_file("/path/to/TLH00526.ARW.xmp").unwrap();
    println!("{:?}", meta); // prints metadata

Actual Behaviour

Upon doing so I get an error that the XMP (XML) file doesn't contain XMP information:

XmpError { error_type: Unavailable, debug_message: "No XMP in file" }

Reproduce Scenario (including but not limited to)

Here's a copy of a darktable xmp file:

<?xml version="1.0" encoding="UTF-8"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.4.0-Exiv2">
 <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/"
    xmlns:xmp="http://ns.adobe.com/xap/1.0/"
    xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
    xmlns:darktable="http://darktable.sf.net/"
   exif:DateTimeOriginal="2023:12:20 17:33:41"
   xmp:Rating="1"
   xmpMM:DerivedFrom="TLH00526.ARW"
   darktable:import_timestamp="1703217015"
   darktable:change_timestamp="-1"
   darktable:export_timestamp="-1"
   darktable:print_timestamp="-1"
   darktable:xmp_version="4"
   darktable:raw_params="0"
   darktable:auto_presets_applied="1"
   darktable:history_end="11"
   darktable:iop_order_version="2"
   darktable:history_auto_hash="8a088e6e7936bc1d4f38d5c39b3c83fc"
   darktable:history_current_hash="8a088e6e7936bc1d4f38d5c39b3c83fc">
   <darktable:masks_history>
    <rdf:Seq/>
   </darktable:masks_history>
   <darktable:history>
    <rdf:Seq>
     <rdf:li
      darktable:num="0"
      darktable:operation="rawprepare"
      darktable:enabled="1"
      darktable:modversion="1"
      darktable:params="00000000000000001a000000000000000002000200020002ac3f0000"
      darktable:multi_name=""
      darktable:multi_priority="0"
      darktable:blendop_version="11"
      darktable:blendop_params="gz14eJxjYIAACQYYOOHEgAZY0QVwggZ7CB6pfNoAAE8gGQg="/>
    </rdf:Seq>
   </darktable:history>
  </rdf:Description>
 </rdf:RDF>
</x:xmpmeta>

Steps to Reproduce

    let meta = XmpMeta::from_file("/path/to/TLH00526.ARW.xmp").unwrap();
    println!("{:?}", meta); // prints metadata

Platform and Version

  • Linux
  • Library v1.9.0

Sample Code that illustrates the problem

Logs taken while reproducing problem

---- metadata::tests::xmp_rating_sony stdout ----
thread 'metadata::tests::xmp_rating_sony' panicked at src/metadata.rs:100:41:
called `Result::unwrap()` on an `Err` value: XmpError { error_type: Unavailable, debug_message: "No XMP in file" }
stack backtrace:
   0: rust_begin_unwind
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:652:5
   1: core::panicking::panic_fmt
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/result.rs:1654:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/result.rs:1077:23
   4: photolib::metadata::PhotoLibXmp::new
             at ./src/metadata.rs:100:16
   5: photolib::metadata::tests::xmp_rating_sony
             at ./src/metadata.rs:151:22
   6: photolib::metadata::tests::xmp_rating_sony::{{closure}}
             at ./src/metadata.rs:150:23
   7: core::ops::function::FnOnce::call_once
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ops/function.rs:250:5
   8: core::ops::function::FnOnce::call_once
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.


failures:
    metadata::tests::xmp_rating_sony

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 3 filtered out; finished in 0.18s
scouten-adobe added a commit that referenced this issue Jul 31, 2024
@scouten-adobe
Copy link
Member

@tlhunter thank you for the clear bug report.

In principle, any compliant XMP should be read by this toolkit, regardless of source. At a quick glance there are no obvious flaws with this file.

I've added your test file as a test case in PR #235 and will investigate and add a fix there once I understand what's happening.

@scouten-adobe
Copy link
Member

@tlhunter as a quick workaround, I've found the following code reads your sample file correctly:

let raw_xmp = std::fs::read("/path/to/TLH00526.ARW.xmp").unwrap();
let raw_xmp = String::from_utf8(raw_xmp).unwrap();
let meta = XmpMeta::from_str(&raw_xmp).unwrap();
println!("{:?}", meta); // prints metadata

I'll do some more digging to see if it's an intended use case for the C++ code underlying XmpMeta::from_file to read a file containing only XMP or if the code above is preferred for some reason. Either way, expect a bug report or a doc update. 🙂

@tlhunter
Copy link
Author

Worked like a charm. Feel free to close this issue or keep it around.

Perhaps there's some sort of marker in binary files with an offset for where the XMP is located which is missing for a pure text file?

@scouten-adobe
Copy link
Member

@tlhunter dug into this a bit more. It looks like this was an intentional design decision in the underlying C++ XMP Toolkit.

The call to XmpMeta::from_file eventually works through a list of file-format handlers which is initialized here: https://github.com/adobe/XMP-Toolkit-SDK/blob/5f6fe44f19842ae43dedc3da3fd5d5dafb29e501/XMPFiles/source/HandlerRegistry.cpp#L116-L174

There does not appear to be inherent support for raw .xmp files, so I'll be closing this as "as designed."

Glad to hear the workaround I proposed above is viable for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants