forked from 1b-agent/opencadstudio-upstream
revert: restore thumbnail capture for native saves (#956)
This commit is contained in:
1 parent
edd3faeeae
commit
611ea0696b
4 files changed
+189
-45
No files matched your search
+1
-11
@@ -7,18 +7,12 @@
|
||||
//! the shared [`dwg_thumbnailer`] core crate (also used by the Windows/macOS
|
||||
//! thumbnail handlers).
|
||||
|
||||
#[cfg(any(target_arch = "wasm32", test))]
|
||||
use acadrust::{Preview, PreviewFormat};
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use iced::Rectangle;
|
||||
use image::ImageFormat;
|
||||
#[cfg(any(target_arch = "wasm32", test))]
|
||||
use image::RgbImage;
|
||||
#[cfg(any(target_arch = "wasm32", test))]
|
||||
use image::{ImageFormat, RgbImage};
|
||||
use std::io::Cursor;
|
||||
|
||||
/// Build a preview from the visible drawing area of an Iced window screenshot.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub fn from_screenshot(
|
||||
screenshot: &iced::window::Screenshot,
|
||||
bounds: Rectangle,
|
||||
@@ -65,7 +59,6 @@ pub fn from_screenshot(
|
||||
const MAX_DIM: u32 = 256;
|
||||
|
||||
/// Canvas dimensions for an aspect ratio, longest edge = [`MAX_DIM`].
|
||||
#[cfg(any(target_arch = "wasm32", test))]
|
||||
fn canvas_dims(aspect: f64) -> (u32, u32) {
|
||||
if aspect >= 1.0 {
|
||||
(MAX_DIM, ((MAX_DIM as f64 / aspect).round() as u32).clamp(16, MAX_DIM))
|
||||
@@ -75,7 +68,6 @@ fn canvas_dims(aspect: f64) -> (u32, u32) {
|
||||
}
|
||||
|
||||
/// Encode PNG for R2013+; older targets receive a BMP/DIB.
|
||||
#[cfg(any(target_arch = "wasm32", test))]
|
||||
fn encode(img: RgbImage, png: bool) -> Option<Preview> {
|
||||
if png {
|
||||
let mut buf = Cursor::new(Vec::new());
|
||||
@@ -89,7 +81,6 @@ fn encode(img: RgbImage, png: bool) -> Option<Preview> {
|
||||
|
||||
/// Build an 8-bit palettised, `BI_RLE8`-compressed DIB. `None` when the image
|
||||
/// holds more than 256 distinct colours (the caller then uses 24-bit).
|
||||
#[cfg(any(target_arch = "wasm32", test))]
|
||||
fn rle8_dib(img: &RgbImage) -> Option<Vec<u8>> {
|
||||
let (w, h) = (img.width(), img.height());
|
||||
// Exact palette + per-pixel index (top-to-bottom, left-to-right).
|
||||
@@ -158,7 +149,6 @@ fn rle8_dib(img: &RgbImage) -> Option<Vec<u8>> {
|
||||
}
|
||||
|
||||
/// 24-bit uncompressed DIB (fallback): the `image` BMP minus its file header.
|
||||
#[cfg(any(target_arch = "wasm32", test))]
|
||||
fn bmp24_dib(img: &RgbImage) -> Option<Vec<u8>> {
|
||||
let mut buf = Cursor::new(Vec::new());
|
||||
img.write_to(&mut buf, ImageFormat::Bmp).ok()?;
|
||||
|
||||
Reference in new issue
Block a user