mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-14 06:22:24 +00:00
Add image document formats to shared registry
This commit is contained in:
1 file changed
+35
@@ -21,6 +21,14 @@ pub enum Format {
|
||||
Tiff,
|
||||
WebP,
|
||||
Heif,
|
||||
Psd,
|
||||
Affinity,
|
||||
Ora,
|
||||
Kra,
|
||||
Xcf,
|
||||
Pdn,
|
||||
Raw,
|
||||
Pcraft,
|
||||
Gcode,
|
||||
Studio,
|
||||
StencilCraft,
|
||||
@@ -37,6 +45,18 @@ pub fn detect(name: &str, bytes: &[u8]) -> Option<Format> {
|
||||
(craft_eps::Kind::PostScript, _) => Format::PostScript,
|
||||
});
|
||||
}
|
||||
if bytes.starts_with(b"8BPS") {
|
||||
return Some(Format::Psd);
|
||||
}
|
||||
if bytes.starts_with(b"PDN3") {
|
||||
return Some(Format::Pdn);
|
||||
}
|
||||
if bytes.starts_with(b"gimp xcf ") || gzipped_xcf(name, bytes) {
|
||||
return Some(Format::Xcf);
|
||||
}
|
||||
if bytes.starts_with(b"\0\xffKA") {
|
||||
return Some(Format::Affinity);
|
||||
}
|
||||
if let Some(raster) = raster_signature(bytes) {
|
||||
return Some(raster);
|
||||
}
|
||||
@@ -75,6 +95,16 @@ pub fn from_extension(ext: &str) -> Option<Format> {
|
||||
"tif" | "tiff" => Some(Format::Tiff),
|
||||
"webp" => Some(Format::WebP),
|
||||
"heic" | "heif" => Some(Format::Heif),
|
||||
"psd" | "psb" => Some(Format::Psd),
|
||||
"afdesign" | "afphoto" | "afpub" => Some(Format::Affinity),
|
||||
"ora" => Some(Format::Ora),
|
||||
"kra" => Some(Format::Kra),
|
||||
"xcf" => Some(Format::Xcf),
|
||||
"pdn" => Some(Format::Pdn),
|
||||
"dng" | "3fr" | "ari" | "arw" | "bay" | "cap" | "cr2" | "cr3" | "dcs" | "dcr" | "drf" | "eip" | "erf" | "fff" | "gpr" | "iiq" | "k25"
|
||||
| "kdc" | "mdc" | "mef" | "mos" | "mrw" | "nef" | "nrw" | "obm" | "orf" | "pef" | "ptx" | "pxn" | "r3d" | "raf" | "raw" | "rwl" | "rw2"
|
||||
| "rwz" | "sr2" | "srf" | "sti" | "x3f" => Some(Format::Raw),
|
||||
"pcraft" => Some(Format::Pcraft),
|
||||
"studio" | "studio3" => Some(Format::Studio),
|
||||
"stencilcraft" => Some(Format::StencilCraft),
|
||||
"gcode" | "nc" => Some(Format::Gcode),
|
||||
@@ -86,6 +116,11 @@ fn extension(name: &str) -> Option<&str> {
|
||||
Some(name.rsplit(['/', '\\']).next()?.rsplit_once('.')?.1)
|
||||
}
|
||||
|
||||
fn gzipped_xcf(name: &str, bytes: &[u8]) -> bool {
|
||||
let lower = name.rsplit(['/', '\\']).next().unwrap_or(name).to_ascii_lowercase();
|
||||
bytes.starts_with(&[0x1f, 0x8b]) && (lower.ends_with(".xcf.gz") || lower.ends_with(".xcfgz"))
|
||||
}
|
||||
|
||||
fn dxf_ascii_prefix(bytes: &[u8]) -> bool {
|
||||
let text = String::from_utf8_lossy(bytes);
|
||||
let mut lines = text.lines().map(str::trim);
|
||||
|
||||
Reference in new issue
Block a user