pedrocr / rawloader

rust library to extract the raw data and some metadata from digital camera images
GNU Lesser General Public License v2.1
304 stars 53 forks source link

Minimal EXIF support for DNG and CR2 #37

Closed art-den closed 2 years ago

art-den commented 2 years ago

Hi, I did minimal EXIF support for DNG and CR2 RAW files. First, I did too mach changes in tiff.rs. I'm not sure I didn't break something.

  1. Fixed: TiffIFD::find_ifds_with_tag returned same &TiffIFD twice
  2. Added constants T_* for tag types
  3. Added single functions get_***_entry_val into tiff.rs to convert raw bytes of TiffEntry to values. Functions are used both from tiff.rs and exif.rs
  4. Fixed: getting of rational values worked wrong if integral values were too large (u32 -> f32 conversion loses data for large u32)
  5. Support of FLOAT and DOUBLE tag types
  6. The TiffEntry::get_u32 algorithm has been changed.
  7. New module exif.rs. Contains trait for getting of Exif data + implementation that use get_***_entry_val functions to return values. Only tags listed in NativeExifInfo::new are stored in object and accessible to read
  8. Removed ; from fetch_tag and fetch_ifd macro to get rid of compiler warnings

How to use:

 let raw = rawloader::decode_file(file).unwrap();
 if let Some(exif) = raw.exif {
     let iso = exif.get_uint(rawloader::Tag::ISOSpeed).unwrap();
     println!("ISO = {}", iso);
     let exp_time = exif.get_rational(rawloader::Tag::ExposureTime).unwrap();
     println!("Exposure time = {} seconds", exp_time);

     for tag in exif.get_tags() {
         if let Some(tag_str) = exif.to_string(tag) {
             println!("{:?} = {}", tag, tag_str);
         }
     }
 }