diff --git a/crates/doc/src/pixels.rs b/crates/doc/src/pixels.rs index 64ff0752d2..b2d8e569f9 100644 --- a/crates/doc/src/pixels.rs +++ b/crates/doc/src/pixels.rs @@ -34,7 +34,27 @@ pub fn header_size(bytes: &[u8]) -> Option<(u32, u32)> { // A GIF frame may be larger than the logical screen the image crate gave as its size. return craft_image_codecs::probe_size(bytes).ok(); } - craft_image_codecs::probe_allocation_size(bytes).ok().or_else(|| craft_image_codecs::probe_size(bytes).ok()) + craft_image_codecs::probe_allocation_size(bytes) + .ok() + .or_else(|| craft_image_codecs::probe_size(bytes).ok()) + // A BMP whose pixel data does not match its header (a truncated file, or a header that + // declares more pixels than the file holds) is refused by the image crate decoder the + // probes use. The BITMAPINFOHEADER still names the size, which Place, Paste and Open + // need so they can say the image is too large to draw instead of that its size can't + // be read. + .or_else(|| bmp_header_size(bytes)) +} + +/// Width and height from a BMP file's BITMAPINFOHEADER, without opening it as a decoder would. +/// Height may be negative (top-down storage); the stored magnitude is the size. +fn bmp_header_size(bytes: &[u8]) -> Option<(u32, u32)> { + if bytes.get(..2) != Some(b"BM") { + return None; + } + let dim = |at: usize| -> Option { Some(i32::from_le_bytes(bytes.get(at..at + 4)?.try_into().ok()?)) }; + let width = u32::try_from(dim(18)?).ok().filter(|&n| n > 0)?; + let height = dim(22)?.unsigned_abs(); + (height > 0).then_some((width, height)) } impl ImageBlob { @@ -626,4 +646,17 @@ mod tests { } assert!(checked >= 20, "{checked}"); } + + /// A BMP header that declares 30,000 × 30,000 pixels, with only one pixel of data, still + /// reports that size: Paste and Place can then say the image is too large to draw. + #[test] + fn a_truncated_bmp_header_still_gives_its_declared_size() { + let mut bmp = vec![]; + image::RgbImage::from_pixel(1, 1, image::Rgb([200, 40, 40])).write_to(&mut Cursor::new(&mut bmp), image::ImageFormat::Bmp).unwrap(); + bmp[18..22].copy_from_slice(&30_000i32.to_le_bytes()); + bmp[22..26].copy_from_slice(&30_000i32.to_le_bytes()); + assert_eq!(header_size(&bmp), Some((30_000, 30_000))); + let (w, h, _) = crate::decode::decoded_layout(&bmp, craft_image_codecs::Format::Bmp).expect("layout from the header"); + assert_eq!((w, h), (30_000, 30_000)); + } } diff --git a/crates/trace/src/tests.rs b/crates/trace/src/tests.rs index 8715686c3e..7e037c8b70 100644 --- a/crates/trace/src/tests.rs +++ b/crates/trace/src/tests.rs @@ -2203,9 +2203,10 @@ fn small_accents_of_other_colors_leave_a_tinted_photo_continuous_tone() { /// `a_jpegs_blocks_are_not_traced_as_steps` measures block artifacts, which differ by encoder. fn through_jpeg(img: &Raster, quality: u8) -> Raster { let rgb: Vec = img.rgba.chunks(4).flat_map(|p| [p[0], p[1], p[2]]).collect(); - let encoded = craft_image_codecs::Image::from_u8(img.width, img.height, craft_image_codecs::ChannelLayout::Rgb, rgb).unwrap(); - let opts = craft_image_codecs::EncodeOptions { jpeg_quality: quality, ..Default::default() }; - let bytes = craft_image_codecs::encode(&encoded, craft_image_codecs::Format::Jpeg, &opts).unwrap(); + let mut bytes = vec![]; + image::codecs::jpeg::JpegEncoder::new_with_quality(&mut bytes, quality) + .encode(&rgb, img.width, img.height, image::ExtendedColorType::Rgb8) + .unwrap(); Raster::decode(&bytes).unwrap() } diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index 8af602785b..1cff1c8ad0 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -7464,9 +7464,9 @@ breakText Glyphs Glyphes @msg a selected path has no area un tracé sélectionné n’a pas de surface @msg a selected path has more than 10000 segments un tracé sélectionné a plus de 10000 segments @msg the two paths have the same outline les deux tracés ont le même contour -@msg One path lies inside the other, so they have no common tangents Un tracé se trouve à l’intérieur de l’autre : ils n’ont donc aucune tangente commune -@msg The paths overlap, so they have no internal tangents Les tracés se chevauchent : ils n’ont donc aucune tangente interne -@msg One path lies inside the other, so they have no internal tangents Un tracé se trouve à l’intérieur de l’autre : ils n’ont donc aucune tangente interne +@msg One path lies inside the other, so they have no common tangents Un tracé se trouve à l’intérieur de l’autre : ils n’ont donc aucune tangente commune +@msg The paths overlap, so they have no internal tangents Les tracés se chevauchent : ils n’ont donc aucune tangente interne +@msg One path lies inside the other, so they have no internal tangents Un tracé se trouve à l’intérieur de l’autre : ils n’ont donc aucune tangente interne # Path Precision Tools add-on: Expand Dashes into Paths. Expand Dashes into Paths Décomposer les tirets en tracés @msg select paths with dashed strokes to expand sélectionnez des tracés à contour pointillé à décomposer