mirror of
https://github.com/storytold/lightcraft.git
synced 2026-11-21 20:38:15 +00:00
Merge branch 'main' into fix/keyword-names-no-trailing-asterisk
This commit is contained in:
Generated
+137
-3
@@ -1226,6 +1226,14 @@ dependencies = [
|
||||
"rayon",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-dds"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=a9efd722b49924588448fba5c59f36d3aee3f4c6#a9efd722b49924588448fba5c59f36d3aee3f4c6"
|
||||
dependencies = [
|
||||
"rayon",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-docpath"
|
||||
version = "0.1.0"
|
||||
@@ -1319,7 +1327,7 @@ name = "craft-image-codecs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=5ef5134ccc28db3a3aaba1e1a0c189340c5d277c#5ef5134ccc28db3a3aaba1e1a0c189340c5d277c"
|
||||
dependencies = [
|
||||
"craft-dds",
|
||||
"craft-dds 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5ef5134ccc28db3a3aaba1e1a0c189340c5d277c)",
|
||||
"craft-jpeg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5ef5134ccc28db3a3aaba1e1a0c189340c5d277c)",
|
||||
"craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5ef5134ccc28db3a3aaba1e1a0c189340c5d277c)",
|
||||
"craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5ef5134ccc28db3a3aaba1e1a0c189340c5d277c)",
|
||||
@@ -1341,6 +1349,33 @@ dependencies = [
|
||||
"zune-jpegxl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-image-codecs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=a9efd722b49924588448fba5c59f36d3aee3f4c6#a9efd722b49924588448fba5c59f36d3aee3f4c6"
|
||||
dependencies = [
|
||||
"craft-dds 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a9efd722b49924588448fba5c59f36d3aee3f4c6)",
|
||||
"craft-jpeg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a9efd722b49924588448fba5c59f36d3aee3f4c6)",
|
||||
"craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a9efd722b49924588448fba5c59f36d3aee3f4c6)",
|
||||
"craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a9efd722b49924588448fba5c59f36d3aee3f4c6)",
|
||||
"crc32fast",
|
||||
"exr",
|
||||
"flate2",
|
||||
"half",
|
||||
"hayro-jpeg2000",
|
||||
"image",
|
||||
"image-webp",
|
||||
"jpeg-encoder 0.6.1",
|
||||
"png",
|
||||
"rayon",
|
||||
"serde_json",
|
||||
"thiserror 2.0.21",
|
||||
"tiff",
|
||||
"zune-core",
|
||||
"zune-jpeg",
|
||||
"zune-jpegxl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-image-codecs"
|
||||
version = "0.1.0"
|
||||
@@ -1368,6 +1403,31 @@ dependencies = [
|
||||
"zune-jpegxl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-image-codecs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=cae7c1d8a6fec9a9ee136169918c5dd20ca509a0#cae7c1d8a6fec9a9ee136169918c5dd20ca509a0"
|
||||
dependencies = [
|
||||
"craft-jpeg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cae7c1d8a6fec9a9ee136169918c5dd20ca509a0)",
|
||||
"craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cae7c1d8a6fec9a9ee136169918c5dd20ca509a0)",
|
||||
"crc32fast",
|
||||
"exr",
|
||||
"flate2",
|
||||
"half",
|
||||
"hayro-jpeg2000",
|
||||
"image",
|
||||
"image-webp",
|
||||
"jpeg-encoder 0.6.1",
|
||||
"png",
|
||||
"rayon",
|
||||
"serde_json",
|
||||
"thiserror 2.0.21",
|
||||
"tiff",
|
||||
"zune-core",
|
||||
"zune-jpeg",
|
||||
"zune-jpegxl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-jpeg"
|
||||
version = "0.1.0"
|
||||
@@ -1393,6 +1453,14 @@ dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-jpeg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=a9efd722b49924588448fba5c59f36d3aee3f4c6#a9efd722b49924588448fba5c59f36d3aee3f4c6"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-jpeg"
|
||||
version = "0.1.0"
|
||||
@@ -1401,6 +1469,14 @@ dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-jpeg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=cae7c1d8a6fec9a9ee136169918c5dd20ca509a0#cae7c1d8a6fec9a9ee136169918c5dd20ca509a0"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-jxl"
|
||||
version = "0.1.0"
|
||||
@@ -1460,6 +1536,18 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-metadata"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=a9efd722b49924588448fba5c59f36d3aee3f4c6#a9efd722b49924588448fba5c59f36d3aee3f4c6"
|
||||
dependencies = [
|
||||
"brotli-decompressor 6.0.1",
|
||||
"chrono",
|
||||
"craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a9efd722b49924588448fba5c59f36d3aee3f4c6)",
|
||||
"quick-xml 0.41.0",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-metadata"
|
||||
version = "0.1.0"
|
||||
@@ -1472,6 +1560,18 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-metadata"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=cae7c1d8a6fec9a9ee136169918c5dd20ca509a0#cae7c1d8a6fec9a9ee136169918c5dd20ca509a0"
|
||||
dependencies = [
|
||||
"brotli-decompressor 6.0.1",
|
||||
"chrono",
|
||||
"craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cae7c1d8a6fec9a9ee136169918c5dd20ca509a0)",
|
||||
"quick-xml 0.41.0",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-mime"
|
||||
version = "0.1.0"
|
||||
@@ -1555,6 +1655,15 @@ dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-tiff"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=a9efd722b49924588448fba5c59f36d3aee3f4c6#a9efd722b49924588448fba5c59f36d3aee3f4c6"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-tiff"
|
||||
version = "0.1.0"
|
||||
@@ -1564,6 +1673,15 @@ dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-tiff"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=cae7c1d8a6fec9a9ee136169918c5dd20ca509a0#cae7c1d8a6fec9a9ee136169918c5dd20ca509a0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-ui"
|
||||
version = "0.1.0"
|
||||
@@ -1646,10 +1764,9 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-xml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=2d4b8b8ecd79f87c847961901c40305e7f448d6f#2d4b8b8ecd79f87c847961901c40305e7f448d6f"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18#f0f4758c01581d79577b9bf5046c06f4e77b1f18"
|
||||
dependencies = [
|
||||
"quick-xml 0.41.0",
|
||||
"serde",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
@@ -4080,7 +4197,9 @@ dependencies = [
|
||||
"craft-heif",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5ac7c9664c8d54aaf69d1bb826e187686c1a4e1a)",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=5ef5134ccc28db3a3aaba1e1a0c189340c5d277c)",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a9efd722b49924588448fba5c59f36d3aee3f4c6)",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c28356d400aed7575b04ec1551b4665107cfe845)",
|
||||
"craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=cae7c1d8a6fec9a9ee136169918c5dd20ca509a0)",
|
||||
"craft-jpeg 0.1.0 (git+https://github.com/storytold/craft-libs?rev=478c50560d3c6fad3d613af2a30b35c3bc9f4c0f)",
|
||||
"craft-jxl",
|
||||
"craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=3a6613f058e355a4fd8d196b2f385260bd4b4a8e)",
|
||||
@@ -8748,3 +8867,18 @@ dependencies = [
|
||||
"syn 3.0.6",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[patch.unused]]
|
||||
name = "egui_demo_lib"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=6d518fc799681571963842f95b55a6b68431b15a#6d518fc799681571963842f95b55a6b68431b15a"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "egui_inspection"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=6d518fc799681571963842f95b55a6b68431b15a#6d518fc799681571963842f95b55a6b68431b15a"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "egui_system_font_provider"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=6d518fc799681571963842f95b55a6b68431b15a#6d518fc799681571963842f95b55a6b68431b15a"
|
||||
|
||||
+5
-2
@@ -17,7 +17,7 @@ craft-pdf-print = { package = "craft-pdf", git = "https://github.com/storytold/c
|
||||
craft-ui = { git = "https://github.com/storytold/craft-libs", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7", features = ["serde"] }
|
||||
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7" }
|
||||
# Canon CRW decoder shared with the other Craft apps
|
||||
craft-crw = { git = "https://github.com/storytold/craft-libs", rev = "2d4b8b8ecd79f87c847961901c40305e7f448d6f" }
|
||||
craft-crw = { git = "https://github.com/storytold/craft-libs", rev = "e7c96161ddaf860a9fa7f8fd21f935620e553022" }
|
||||
craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "7f30d664695cd5ce14fc30659d36c3e32f234247" }
|
||||
craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18", version = "0.1.0" }
|
||||
craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f30bb10de10d8436ca9b39fe94e3bb67", features = ["frames"] }
|
||||
@@ -30,7 +30,7 @@ craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "c
|
||||
craft-video = { git = "https://github.com/storytold/craft-libs", rev = "5c91598ccc86537a779f438d520fa6406c26efe6", features = ["av1", "av1-large-encode", "threads"] }
|
||||
# Isolate AVIF threading from the existing PNG/TIFF/WebP shared revision.
|
||||
craft-avif-encode = { package = "craft-image-codecs", git = "https://github.com/storytold/craft-libs", rev = "5ac7c9664c8d54aaf69d1bb826e187686c1a4e1a", default-features = false, features = ["avif", "threads"] }
|
||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "2d4b8b8ecd79f87c847961901c40305e7f448d6f" }
|
||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" }
|
||||
# craft-update: app-specific pretend versions apply to startup and manual checks.
|
||||
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "6e03f65bf45181db77ba6229716e6624db9eb25b", features = ["egui"] }
|
||||
craft-window = { git = "https://github.com/storytold/craft-libs", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7", features = ["egui"] }
|
||||
@@ -207,5 +207,8 @@ egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "6d518fc79968
|
||||
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
egui_system_font_provider = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
eframe = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
winit = { git = "https://github.com/storytold/winit.git", rev = "a517b3846ee8457d84ee4975110bfda6797c44dc" }
|
||||
|
||||
@@ -17,6 +17,9 @@ craft-cms = { workspace = true }
|
||||
craft-jpeg = { workspace = true }
|
||||
craft-image-codecs = { workspace = true }
|
||||
craft-webp-header = { workspace = true }
|
||||
# Isolate BMP routing until the shared prerequisite lands; other codec pins stay unchanged.
|
||||
craft-bmp-header = { package = "craft-image-codecs", git = "https://github.com/storytold/craft-libs", rev = "a9efd722b49924588448fba5c59f36d3aee3f4c6", default-features = false }
|
||||
craft-image-codecs-sef = { package = "craft-image-codecs", git = "https://github.com/storytold/craft-libs", rev = "cae7c1d8a6fec9a9ee136169918c5dd20ca509a0" }
|
||||
craft-metadata = { workspace = true }
|
||||
craft-tiff = { workspace = true }
|
||||
craft-gif = { workspace = true }
|
||||
|
||||
+37
-111
@@ -3,6 +3,7 @@
|
||||
|
||||
use crate::convert::{Buf, Meta, Model, Raw, check_size, finish};
|
||||
use crate::{DecodeOptions, Decoded, Error, Format, Result, Thumbnail, ThumbnailSource, exif};
|
||||
use craft_image_codecs_sef::jpeg_sef::{reaches_eoi, repair as without_sef_trailer};
|
||||
|
||||
const F: Format = Format::Jpeg;
|
||||
|
||||
@@ -42,88 +43,6 @@ pub(crate) fn header(bytes: &[u8]) -> Result<(u32, u32, u16)> {
|
||||
Ok((m.width, m.height, orientation))
|
||||
}
|
||||
|
||||
/// Whether the markers after SOI, followed through every segment and scan, reach an EOI marker
|
||||
/// (the first one: the primary image's, ahead of any MPF images appended to the file). Segments
|
||||
/// are skipped by their length; in scan data `FF 00` (stuffing), `FF FF` (fill) and RSTn are not
|
||||
/// markers that end it.
|
||||
fn reaches_eoi(b: &[u8]) -> bool {
|
||||
let mut p = 2usize;
|
||||
loop {
|
||||
// entropy-coded data (or garbage between segments, as `parse_markers` tolerates it)
|
||||
let Some(skip) = b.get(p..).and_then(find_ff) else { return false };
|
||||
p = p.saturating_add(skip);
|
||||
let Some(&marker) = b.get(p.saturating_add(1)) else { return false };
|
||||
p = match marker {
|
||||
0xD9 => return true,
|
||||
0xFF => p.saturating_add(1),
|
||||
0x00 | 0x01 | 0xD0..=0xD8 => p.saturating_add(2),
|
||||
_ => {
|
||||
let Some(len) = b.get(p.saturating_add(2)..p.saturating_add(4)).map(|l| u16::from_be_bytes([l[0], l[1]]) as usize) else {
|
||||
return false;
|
||||
};
|
||||
if len < 2 {
|
||||
return false;
|
||||
}
|
||||
p.saturating_add(2).saturating_add(len)
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// A Samsung panorama whose scan runs straight into its SEF trailer, with no EOI marker (issue
|
||||
/// #3350), as the file it stands for: the bytes before the trailer's earliest data block plus an
|
||||
/// EOI. Every other file, a genuinely truncated one included, is borrowed unchanged.
|
||||
fn without_sef_trailer(bytes: &[u8]) -> std::borrow::Cow<'_, [u8]> {
|
||||
use std::borrow::Cow;
|
||||
// The trailer is checked first: it reads only the file's last bytes, not the scan data.
|
||||
let Some(image) = sef_image_end(bytes).and_then(|end| bytes.get(..end)) else { return Cow::Borrowed(bytes) };
|
||||
// the image before the trailer: an FF D9 inside the SEF data doesn't end the scan
|
||||
if reaches_eoi(image) {
|
||||
return Cow::Borrowed(bytes);
|
||||
}
|
||||
let mut fixed = Vec::with_capacity(image.len().saturating_add(2));
|
||||
fixed.extend_from_slice(image);
|
||||
fixed.extend_from_slice(&[0xFF, 0xD9]);
|
||||
// The cut must leave the scan data, not a segment or anything before the first scan, open.
|
||||
let in_scan = parse_markers(&fixed).is_some_and(|m| m.first_scan_components > 0) && reaches_eoi(&fixed);
|
||||
if in_scan { Cow::Owned(fixed) } else { Cow::Borrowed(bytes) }
|
||||
}
|
||||
|
||||
/// Where the image ends in a file carrying a Samsung SEF trailer: the start of its earliest data
|
||||
/// block. The trailer is the file's last bytes: `SEFH`, a u32 LE version and entry count, 12-byte
|
||||
/// entries (u16 padding, u16 type, u32 LE offset of the block back from `SEFH`, u32 LE length),
|
||||
/// then the u32 LE length of that directory and `SEFT`. Each block starts with the same padding
|
||||
/// and type as its entry. `None` unless every entry's block is nonempty, starts with its entry's
|
||||
/// type and lies inside the file, before `SEFH`.
|
||||
fn sef_image_end(b: &[u8]) -> Option<usize> {
|
||||
let le32 = |at: usize| b.get(at..at.checked_add(4)?)?.try_into().ok().map(|v| u32::from_le_bytes(v) as usize);
|
||||
let tail = b.len().checked_sub(8)?;
|
||||
if b.get(tail.checked_add(4)?..)? != b"SEFT" {
|
||||
return None;
|
||||
}
|
||||
let dir = tail.checked_sub(le32(tail)?)?;
|
||||
if b.get(dir..dir.checked_add(4)?)? != b"SEFH" {
|
||||
return None;
|
||||
}
|
||||
let count = le32(dir.checked_add(8)?)?;
|
||||
let entries = dir.checked_add(12)?;
|
||||
if count == 0 || count > tail.checked_sub(entries)? / 12 {
|
||||
return None;
|
||||
}
|
||||
let mut start = dir;
|
||||
for i in 0..count {
|
||||
let entry = entries.checked_add(i.checked_mul(12)?)?;
|
||||
let block = dir.checked_sub(le32(entry.checked_add(4)?)?)?;
|
||||
let len = le32(entry.checked_add(8)?)?;
|
||||
let kind = |at: usize| b.get(at.checked_add(2)?..at.checked_add(4)?);
|
||||
if len < 4 || block.checked_add(len)? > dir || kind(block)? != kind(entry)? {
|
||||
return None;
|
||||
}
|
||||
start = start.min(block);
|
||||
}
|
||||
Some(start)
|
||||
}
|
||||
|
||||
pub(crate) fn decode_with_fallback(bytes: &[u8], opts: &DecodeOptions, fallback: Option<crate::NamedSpace>) -> Result<Decoded> {
|
||||
let bytes = &*without_sef_trailer(bytes);
|
||||
let m = parse_markers(bytes).ok_or_else(|| Error::Malformed(F, "missing SOI".into()))?;
|
||||
@@ -179,21 +98,6 @@ fn decode_via_craft_codecs(bytes: &[u8], budget: &DecodeOptions) -> Result<Raw>
|
||||
Ok(Raw { width: w, height: h, model, alpha: false, premultiplied: false, buf, bit_depth })
|
||||
}
|
||||
|
||||
/// The first `0xFF` byte, eight bytes at a time (scan data has one every few hundred bytes: this
|
||||
/// is most of [`header`]'s time).
|
||||
fn find_ff(b: &[u8]) -> Option<usize> {
|
||||
const ONES: u64 = 0x0101_0101_0101_0101;
|
||||
let (words, tail) = b.as_chunks::<8>();
|
||||
for (i, w) in words.iter().enumerate() {
|
||||
// a zero byte in !w is an 0xFF byte in w
|
||||
let x = !u64::from_ne_bytes(*w);
|
||||
if x.wrapping_sub(ONES) & !x & (ONES << 7) != 0 {
|
||||
return w.iter().position(|&v| v == 0xFF).map(|j| i * 8 + j);
|
||||
}
|
||||
}
|
||||
tail.iter().position(|&v| v == 0xFF).map(|j| words.len() * 8 + j)
|
||||
}
|
||||
|
||||
/// Fast path: an embedded JPEG preview (EXIF IFD1 thumbnail, or the largest MPF preview) whose long
|
||||
/// edge is ≥ `max_edge`, decoded with DCT scaling and fitted.
|
||||
pub(crate) fn embedded_thumbnail(bytes: &[u8], max_edge: u32, min_edge: u32) -> Option<Thumbnail> {
|
||||
@@ -275,6 +179,42 @@ pub(crate) fn decode_codes8(bytes: &[u8]) -> Result<(usize, usize, usize, Vec<u8
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn shared_eoi_walk_matches_previous_on_mutated_streams() {
|
||||
fn previous(b: &[u8]) -> bool {
|
||||
let mut p = 2usize;
|
||||
loop {
|
||||
let Some(skip) = b.get(p..).and_then(|s| s.iter().position(|&v| v == 0xff)) else { return false };
|
||||
p = p.saturating_add(skip);
|
||||
let Some(&marker) = b.get(p.saturating_add(1)) else { return false };
|
||||
p = match marker {
|
||||
0xd9 => return true,
|
||||
0xff => p.saturating_add(1),
|
||||
0x00 | 0x01 | 0xd0..=0xd8 => p.saturating_add(2),
|
||||
_ => {
|
||||
let Some(len) = b.get(p.saturating_add(2)..p.saturating_add(4)).map(|s| u16::from_be_bytes([s[0], s[1]]) as usize) else {
|
||||
return false;
|
||||
};
|
||||
if len < 2 {
|
||||
return false;
|
||||
}
|
||||
p.saturating_add(2).saturating_add(len)
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
let base = [0xff, 0xd8, 0xff, 0xe1, 0, 4, 1, 2, 0xff, 0xda, 0, 3, 1, 1, 0xff, 0, 3, 0xff, 0xd0, 4, 0xff, 0xd9];
|
||||
for end in 0..=base.len() {
|
||||
for at in 0..end {
|
||||
for value in [0, 1, 0xff, 0xd9] {
|
||||
let mut bytes = base[..end].to_vec();
|
||||
bytes[at] = value;
|
||||
assert_eq!(reaches_eoi(&bytes), previous(&bytes), "end {end}, at {at}, value {value}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mpf_shared_matches_previous_reader_on_mutated_indices() {
|
||||
fn previous(base: usize, data: &[u8]) -> Vec<craft_metadata::mpf::MpfImage> {
|
||||
@@ -453,20 +393,6 @@ mod tests {
|
||||
assert!(markers.icc_invalid);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_ff_matches_a_plain_search() {
|
||||
let mut b: Vec<u8> = (0..300u32).map(|i| (i * 7 % 255) as u8).collect();
|
||||
for at in [None, Some(0), Some(7), Some(8), Some(15), Some(203), Some(296), Some(299)] {
|
||||
if let Some(i) = at {
|
||||
b[i] = 0xFF;
|
||||
}
|
||||
for start in [0, 1, 5, 9, 290, 299, 300] {
|
||||
let s = &b[start..];
|
||||
assert_eq!(find_ff(s), s.iter().position(|&v| v == 0xFF), "{at:?} from {start}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unbounded_fit_box_decodes_at_full_size() {
|
||||
// a full-size load asks for the largest box (`usize::MAX` saturated to `u32::MAX`): no DCT scaling,
|
||||
|
||||
@@ -132,11 +132,8 @@ pub fn sniff(b: &[u8]) -> Option<Format> {
|
||||
if b.starts_with(b"II+\0") || b.starts_with(b"MM\0+") {
|
||||
return Some(Format::Tiff);
|
||||
}
|
||||
if b.len() >= 26 && b.starts_with(b"BM") {
|
||||
let dib = u32::from_le_bytes([b[14], b[15], b[16], b[17]]);
|
||||
if matches!(dib, 12 | 16 | 40 | 52 | 56 | 64 | 108 | 124) {
|
||||
return Some(Format::Bmp);
|
||||
}
|
||||
if craft_bmp_header::bmp_probe::is_supported_header(b) {
|
||||
return Some(Format::Bmp);
|
||||
}
|
||||
None
|
||||
}
|
||||
@@ -224,6 +221,21 @@ fn tiff_is_raw(b: &[u8]) -> bool {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn bmp_routing_retains_supported_dib_and_truncation_rules() {
|
||||
let mut b = [0_u8; 26];
|
||||
b[..2].copy_from_slice(b"BM");
|
||||
for dib in [12_u32, 16, 40, 52, 56, 64, 108, 124] {
|
||||
b[14..18].copy_from_slice(&dib.to_le_bytes());
|
||||
assert_eq!(sniff(&b), Some(Format::Bmp));
|
||||
assert_eq!(sniff(&b[..25]), None);
|
||||
}
|
||||
for dib in [0_u32, 13, 39, 125, u32::MAX] {
|
||||
b[14..18].copy_from_slice(&dib.to_le_bytes());
|
||||
assert_eq!(sniff(&b), None);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raw_tiff_classifier_matches_legacy_on_mutations() {
|
||||
let fixtures: &[&[u8]] = &[
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::convert::{from_craft, to_craft};
|
||||
use crate::{Metadata, Orientation};
|
||||
use craft_tiff::{ParseOptions, Tiff, TiffError, tags as t};
|
||||
use craft_tiff::{ParseOptions, Tiff, TiffError};
|
||||
|
||||
pub fn strip_exif_header(b: &[u8]) -> &[u8] {
|
||||
craft_metadata::strip_exif_header(b)
|
||||
@@ -27,8 +27,7 @@ pub fn write_exif(meta: &Metadata) -> Vec<u8> {
|
||||
}
|
||||
|
||||
pub(crate) fn ifd0_orientation(bytes: &[u8]) -> Option<Orientation> {
|
||||
let tiff = Tiff::parse(strip_exif_header(bytes)).ok()?;
|
||||
tiff.ifds.first()?.u16(t::ORIENTATION).map(Orientation::from_exif)
|
||||
craft_metadata::ifd0_orientation_compat(bytes).map(crate::convert::orientation_from_craft)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -1038,9 +1038,6 @@ fn malformed_semantic_masks_are_skipped() {
|
||||
let mut short = mask_ifd(4, 4, "short strip", vec![200; 3]);
|
||||
short.set(t::MASK_SUB_AREA, Value::Long(vec![u32::MAX, u32::MAX, u32::MAX, u32::MAX]));
|
||||
ifd0.add_sub_ifd(short);
|
||||
let mut overflow = mask_ifd(2, 2, "overflow sub area", vec![255; 4]);
|
||||
overflow.set(t::MASK_SUB_AREA, Value::Long(vec![u32::MAX, u32::MAX, u32::MAX, u32::MAX]));
|
||||
ifd0.add_sub_ifd(overflow);
|
||||
let mut outside = mask_ifd(2, 2, "sub area too small", vec![255; 4]);
|
||||
outside.set(t::MASK_SUB_AREA, Value::Long(vec![3, 0, 2, 4]));
|
||||
ifd0.add_sub_ifd(outside);
|
||||
@@ -1050,8 +1047,8 @@ fn malformed_semantic_masks_are_skipped() {
|
||||
let names: Vec<&str> = masks.iter().map(|m| m.name.as_str()).collect();
|
||||
// A 4×4, 8-bit uncompressed mask needs 16 bytes: the three-byte strip
|
||||
// is truncated, not a valid mask with zero-filled missing pixels. Keep the
|
||||
// separate complete masks to test invalid and overflowing MaskSubArea handling.
|
||||
assert_eq!(names, ["overflow sub area", "sub area too small"]);
|
||||
// separate complete mask to test invalid MaskSubArea handling.
|
||||
assert_eq!(names, ["sub area too small"]);
|
||||
assert!(masks.iter().all(|m| m.sub_area.is_none()), "sub areas the mask doesn't fit are ignored");
|
||||
for m in &masks {
|
||||
let d = m.developed(Rect::new(0, 0, 8, 6), Rect::new(0, 0, 8, 6)).unwrap();
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user