commit 7645dd7c953a832715a89324e19562355e14a8c0
parent 05f437861e42cc9dadce8082c3163740b847e8d9
Author: Jack Mordaunt <jackmordaunt@gmail.com>
Date: Sat, 7 Mar 2020 16:02:16 +0800
Chore: Upgrade rom method into From trait.
Diffstat:
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/src/encode.rs b/src/encode.rs
@@ -33,21 +33,6 @@ struct IconSet {
const ICONSET_MAGIC: [char; 4] = ['i', 'c', 'n', 's'];
impl IconSet {
- /// Create an IconSet from the provided image.
- /// If width != height, the image will be resized using the largest side
- /// without preserving the aspect ratio.
- fn from(img: &RgbaImage) -> Self {
- let kind = OSType::nearest(max(img.width(), img.height()));
- let icons: Vec<Icon> = kind
- .smaller_variants()
- .par_iter()
- .map(|v| Icon {
- kind: v.clone(),
- image: resize(img, v.size(), v.size(), Lanczos3),
- })
- .collect();
- IconSet { icons }
- }
/// Write the encoded iconset to writer `w`.
fn write_to(self, mut wr: impl Write) -> io::Result<()> {
// Pre-buffer the encoded icons so we can calculate the final size.
@@ -132,3 +117,21 @@ impl<W: Write> PNGEncoder<W> {
writer.write_image_data(data).map_err(|e| e.into())
}
}
+
+/// Create an IconSet from the provided image.
+/// If width != height, the image will be resized using the largest side
+/// without preserving the aspect ratio.
+impl From<&RgbaImage> for IconSet {
+ fn from(img: &RgbaImage) -> Self {
+ let kind = OSType::nearest(max(img.width(), img.height()));
+ let icons: Vec<Icon> = kind
+ .smaller_variants()
+ .par_iter()
+ .map(|v| Icon {
+ kind: v.clone(),
+ image: resize(img, v.size(), v.size(), Lanczos3),
+ })
+ .collect();
+ IconSet { icons }
+ }
+}
+\ No newline at end of file