Skip to content

Commit d57df4d

Browse files
fix(clipboard-manager): read_image wrongly set the image rgba data with binary PNG data. (#1986)
* fix(clipboard-manager): `read_image` wrongly set the image rgba data with binary PNG data. * remove depencency of `image` crate; add patch file
1 parent 1f649c7 commit d57df4d

File tree

4 files changed

+8
-13
lines changed

4 files changed

+8
-13
lines changed

.changes/fix-1985.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"clipboard-manager": patch
3+
---
4+
5+
Fix that `read_image` wrongly set the image rgba data with binary PNG data.

plugins/clipboard-manager/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,3 @@ tauri = { workspace = true, features = ["wry"] }
3737

3838
[target."cfg(any(target_os = \"macos\", windows, target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
3939
arboard = "3"
40-
image = "0.25"

plugins/clipboard-manager/src/desktop.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// SPDX-License-Identifier: MIT
44

55
use arboard::ImageData;
6-
use image::ImageEncoder;
76
use serde::de::DeserializeOwned;
87
use tauri::{image::Image, plugin::PluginApi, AppHandle, Runtime};
98

@@ -85,16 +84,11 @@ impl<R: Runtime> Clipboard<R> {
8584
match &self.clipboard {
8685
Ok(clipboard) => {
8786
let image = clipboard.lock().unwrap().get_image()?;
88-
89-
let mut buffer: Vec<u8> = Vec::new();
90-
image::codecs::png::PngEncoder::new(&mut buffer).write_image(
91-
&image.bytes,
87+
let image = Image::new_owned(
88+
image.bytes.to_vec(),
9289
image.width as u32,
9390
image.height as u32,
94-
image::ExtendedColorType::Rgba8,
95-
)?;
96-
97-
let image = Image::new_owned(buffer, image.width as u32, image.height as u32);
91+
);
9892
Ok(image)
9993
}
10094
Err(e) => Err(crate::Error::Clipboard(e.to_string())),

plugins/clipboard-manager/src/error.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ pub enum Error {
1515
Clipboard(String),
1616
#[error(transparent)]
1717
Tauri(#[from] tauri::Error),
18-
#[cfg(desktop)]
19-
#[error("invalid image: {0}")]
20-
Image(#[from] image::ImageError),
2118
}
2219

2320
impl Serialize for Error {

0 commit comments

Comments
 (0)