summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2020-03-01 16:31:46 +0100
committerLibravatar GitHub <noreply@github.com>2020-03-01 16:31:46 +0100
commit0d4b6addccb10f3665452699ac1d6525e596c45d (patch)
tree28492d24ff7390df6828a774aa6275bd29ededb2 /native
parent96f75eae4d4d19eeff8e55201822388d34445ec6 (diff)
parenteb7e3250d3da495f46480360c99540a8f643d2e6 (diff)
downloadiced-0d4b6addccb10f3665452699ac1d6525e596c45d.tar.gz
iced-0d4b6addccb10f3665452699ac1d6525e596c45d.tar.bz2
iced-0d4b6addccb10f3665452699ac1d6525e596c45d.zip
Merge pull request #211 from mrkgnao/master
Add support for loading already-decoded image pixels
Diffstat (limited to 'native')
-rw-r--r--native/src/widget/image.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs
index 9b92c7f1..fbe38bfc 100644
--- a/native/src/widget/image.rs
+++ b/native/src/widget/image.rs
@@ -125,6 +125,21 @@ impl Handle {
Self::from_data(Data::Path(path.into()))
}
+ /// Creates an image [`Handle`] containing the image pixels directly. This
+ /// function expects the input data to be provided as a `Vec<u8>` of BGRA
+ /// pixels.
+ ///
+ /// This is useful if you have already decoded your image.
+ ///
+ /// [`Handle`]: struct.Handle.html
+ pub fn from_pixels(width: u32, height: u32, pixels: Vec<u8>) -> Handle {
+ Self::from_data(Data::Pixels {
+ width,
+ height,
+ pixels,
+ })
+ }
+
/// Creates an image [`Handle`] containing the image data directly.
///
/// This is useful if you already have your image loaded in-memory, maybe
@@ -188,6 +203,16 @@ pub enum Data {
/// In-memory data
Bytes(Vec<u8>),
+
+ /// Decoded image pixels in BGRA format.
+ Pixels {
+ /// The width of the image.
+ width: u32,
+ /// The height of the image.
+ height: u32,
+ /// The pixels.
+ pixels: Vec<u8>,
+ },
}
impl std::fmt::Debug for Data {
@@ -195,6 +220,9 @@ impl std::fmt::Debug for Data {
match self {
Data::Path(path) => write!(f, "Path({:?})", path),
Data::Bytes(_) => write!(f, "Bytes(...)"),
+ Data::Pixels { width, height, .. } => {
+ write!(f, "Pixels({} * {})", width, height)
+ }
}
}
}