diff options
author | Hubert Figuière <hub@figuiere.net> | 2024-01-07 23:39:45 -0500 |
---|---|---|
committer | Hubert Figuière <hub@figuiere.net> | 2024-01-09 20:27:50 -0500 |
commit | 589550797b1c1d6351d3394a3ddf96f34ae7f30b (patch) | |
tree | 29bd90542a22a065d5a6f4ba118ea8831b8a85cf | |
parent | 38e760115699a7451a8399f0e1372dba1a8b3ec4 (diff) |
identify: Added mimetypes
- Added Rw type for old Panasonic
Signed-off-by: Hubert Figuière <hub@figuiere.net>
-rw-r--r-- | src/bin/ordiag.rs | 3 | ||||
-rw-r--r-- | src/factory.rs | 3 | ||||
-rw-r--r-- | src/identify.rs | 73 | ||||
-rw-r--r-- | src/lib.rs | 3 | ||||
-rw-r--r-- | src/rawfile.rs | 5 |
5 files changed, 64 insertions, 23 deletions
diff --git a/src/bin/ordiag.rs b/src/bin/ordiag.rs index eb57a3c..27ae7f6 100644 --- a/src/bin/ordiag.rs +++ b/src/bin/ordiag.rs @@ -2,7 +2,7 @@ /* * libopenraw - bin/ordiag.rs * - * Copyright (C) 2022-2023 Hubert Figuière + * Copyright (C) 2022-2024 Hubert Figuière * * This library is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -228,6 +228,7 @@ fn process_file( match rawfile { Ok(ref rawfile) => { println!("Raw type: {:?}", rawfile.type_()); + println!("MIME type: {}", rawfile.mime_type()); println!("Vendor id: {}", rawfile.vendor_id()); println!("Type id: {:?}", rawfile.type_id()); if let Some(make) = rawfile diff --git a/src/factory.rs b/src/factory.rs index dace6b2..1c61657 100644 --- a/src/factory.rs +++ b/src/factory.rs @@ -2,7 +2,7 @@ /* * libopenraw - factory.rs * - * Copyright (C) 2022 Hubert Figuière + * Copyright (C) 2022-2024 Hubert Figuière * * This library is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -57,6 +57,7 @@ lazy_static::lazy_static! { (Type::Orf, OrfFile::factory as RawFileFactory), (Type::Pef, PefFile::factory as RawFileFactory), (Type::Raf, RafFile::factory as RawFileFactory), + (Type::Rw, Rw2File::factory as RawFileFactory), (Type::Rw2, Rw2File::factory as RawFileFactory), ]); } diff --git a/src/identify.rs b/src/identify.rs index f0f378a..76cc484 100644 --- a/src/identify.rs +++ b/src/identify.rs @@ -2,7 +2,7 @@ /* * libopenraw - identify.rs * - * Copyright (C) 2022-2023 Hubert Figuière + * Copyright (C) 2022-2024 Hubert Figuière * * This library is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -30,28 +30,59 @@ use crate::io::View; use crate::tiff; use crate::tiff::{exif, Ifd, IfdType}; +const TYPE_MIME: [(Type, &str); 15] = [ + (Type::Arw, "image/x-sony-arw"), + (Type::Cr2, "image/x-canon-cr2"), + (Type::Cr3, "image/x-canon-cr3"), + (Type::Crw, "image/x-canon-crw"), + (Type::Dng, "image/x-adobe-dng"), + (Type::Erf, "image/x-epson-erf"), + (Type::Mrw, "image/x-minolta-mrw"), + (Type::Nef, "image/x-nikon-nef"), + (Type::Nrw, "image/x-nikon-nrw"), + (Type::Orf, "image/x-olympus-orf"), + (Type::Pef, "image/x-pentax-pef"), + (Type::Raf, "image/x-fuji-raf"), + (Type::Rw, "image/x-panasonic-rw"), + (Type::Rw2, "image/x-panasonic-rw2"), + (Type::Sr2, "image/x-sony-sr2"), +]; + +const EXT_TYPE: [(&str, Type); 17] = [ + // The extension MUST be lowercase + ("arw", Type::Arw), + ("cr2", Type::Cr2), + ("cr3", Type::Cr3), + ("dng", Type::Dng), + ("erf", Type::Erf), + ("jpg", Type::Jpeg), + ("jpeg", Type::Jpeg), + ("gpr", Type::Gpr), + ("nef", Type::Nef), + ("nrw", Type::Nrw), + ("orf", Type::Orf), + ("pef", Type::Pef), + ("raf", Type::Raf), + ("raw", Type::Rw), + ("rw2", Type::Rw2), + ("rwl", Type::Rw2), + ("sr2", Type::Arw), +]; + lazy_static::lazy_static! { /// Mapping of extensions (lowercase) to a `Type`. - pub(crate) static ref EXT_TO_TYPE: HashMap<&'static str, Type> = HashMap::from([ - // The extension MUST be lowercase - ("arw", Type::Arw), - ("cr2", Type::Cr2), - ("cr3", Type::Cr3), - ("dng", Type::Dng), - ("erf", Type::Erf), - ("jpg", Type::Jpeg), - ("jpeg", Type::Jpeg), - ("gpr", Type::Gpr), - ("nef", Type::Nef), - ("nrw", Type::Nrw), - ("orf", Type::Orf), - ("pef", Type::Pef), - ("raf", Type::Raf), - ("raw", Type::Rw2), - ("rw2", Type::Rw2), - ("rwl", Type::Rw2), - ("sr2", Type::Arw), - ]); + pub(crate) static ref EXT_TO_TYPE: HashMap<&'static str, Type> = HashMap::from( + EXT_TYPE + ); + + pub(crate) static ref TYPE_TO_MIME: HashMap<Type, &'static str> = HashMap::from( + TYPE_MIME + ); +} + +/// Get the mime type associated for the file. +pub(crate) fn mime_for_type(type_: Type) -> Option<&'static str> { + TYPE_TO_MIME.get(&type_).copied() } /// Get the type associated to the extension. @@ -227,6 +227,8 @@ pub enum Type { Pef = 8, /// Fujfilm RAW Raf = 13, + /// Panasonic old RAW + Rw = 17, /// Panasonic RAW Rw2 = 12, /// Sony RAW (old) @@ -279,6 +281,7 @@ impl From<Type> for String { Type::Orf => "ORF", Type::Pef => "PEF", Type::Raf => "RAF", + Type::Rw => "RW", Type::Rw2 => "RW2", Type::Sr2 => "SR2", #[cfg(test)] diff --git a/src/rawfile.rs b/src/rawfile.rs index 02f3670..8f8f45b 100644 --- a/src/rawfile.rs +++ b/src/rawfile.rs @@ -174,6 +174,11 @@ pub trait RawFile: RawFileImpl + crate::dump::DumpFile + std::fmt::Debug { self.identify_id() } + /// Return the MIME type for the raw file. + fn mime_type(&self) -> &'static str { + identify::mime_for_type(self.type_()).unwrap_or("application/octet-stream") + } + /// Return the vendor ID fn vendor_id(&self) -> u16 { self.identify_id().0 |