diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..b5399af --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,17 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "cargo" + directory: "/" + schedule: + interval: "weekly" + +# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot#example-dependabotyml-file-for-github-actions= + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 72fbea6..8979d53 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -5,7 +5,7 @@ jobs: name: cargo check runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: actions-rs/toolchain@v1 with: profile: minimal @@ -18,7 +18,7 @@ jobs: name: cargo test runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: actions-rs/toolchain@v1 with: profile: minimal @@ -31,7 +31,7 @@ jobs: name: cargo fmt runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: actions-rs/toolchain@v1 with: profile: minimal diff --git a/Cargo.toml b/Cargo.toml index 402bf89..ad3748f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,8 +15,8 @@ build-bin = ["md-5"] name = "identicon" [dependencies] -image = { version = "0.23.14", default-features = false, features = ["png"] } -md-5 = { version = "0.9.1", features = ["asm"], optional = true } +image = { version = "0.25.0", default-features = false, features = ["png"] } +md-5 = { version = "0.10", optional = true } [[bin]] name = "identicon" diff --git a/src/hsl.rs b/src/hsl.rs index 7a6f246..27cbd55 100644 --- a/src/hsl.rs +++ b/src/hsl.rs @@ -1,18 +1,14 @@ use image::Rgb; -pub struct HSL { +pub struct Hsl { hue: f32, sat: f32, lum: f32, } -impl HSL { - pub fn new(hue: f32, sat: f32, lum: f32) -> HSL { - HSL { - hue: hue, - sat: sat, - lum: lum, - } +impl Hsl { + pub fn new(hue: f32, sat: f32, lum: f32) -> Hsl { + Hsl { hue, sat, lum } } // http://www.w3.org/TR/css3-color/#hsl-color @@ -28,9 +24,9 @@ impl HSL { }; let a = lum * 2.0 - b; - let r = HSL::hue_to_rgb(a, b, hue + 1.0 / 3.0); - let g = HSL::hue_to_rgb(a, b, hue); - let b = HSL::hue_to_rgb(a, b, hue - 1.0 / 3.0); + let r = Hsl::hue_to_rgb(a, b, hue + 1.0 / 3.0); + let g = Hsl::hue_to_rgb(a, b, hue); + let b = Hsl::hue_to_rgb(a, b, hue - 1.0 / 3.0); Rgb([ (r * 255.0).round() as u8, @@ -66,41 +62,41 @@ impl HSL { #[cfg(test)] mod tests { - use super::HSL; + use super::Hsl; use image::Rgb; #[test] fn it_converts_black() { let black = Rgb([0, 0, 0]); - let rgb = HSL::new(0.0, 0.0, 0.0).rgb(); + let rgb = Hsl::new(0.0, 0.0, 0.0).rgb(); assert_eq!(black, rgb); } #[test] fn it_converts_white() { let white = Rgb([255, 255, 255]); - let rgb = HSL::new(0.0, 0.0, 100.0).rgb(); + let rgb = Hsl::new(0.0, 0.0, 100.0).rgb(); assert_eq!(white, rgb); } #[test] fn it_converts_red() { let red = Rgb([255, 0, 0]); - let rgb = HSL::new(0.0, 100.0, 50.0).rgb(); + let rgb = Hsl::new(0.0, 100.0, 50.0).rgb(); assert_eq!(red, rgb); } #[test] fn it_converts_green() { let green = Rgb([0, 255, 0]); - let rgb = HSL::new(120.0, 100.0, 50.0).rgb(); + let rgb = Hsl::new(120.0, 100.0, 50.0).rgb(); assert_eq!(green, rgb); } #[test] fn it_converts_blue() { let blue = Rgb([0, 0, 255]); - let rgb = HSL::new(240.0, 100.0, 50.0).rgb(); + let rgb = Hsl::new(240.0, 100.0, 50.0).rgb(); assert_eq!(blue, rgb); } } diff --git a/src/lib.rs b/src/lib.rs index 90f1ff5..9e443e0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ use image::{ImageBuffer, Rgb, RgbImage}; -use hsl::HSL; +use hsl::Hsl; use nibbler::Nibbler; mod hsl; @@ -13,10 +13,7 @@ pub struct Identicon<'a> { impl<'a> Identicon<'a> { pub fn new(source: &[u8]) -> Identicon { - Identicon { - source: source, - size: 420, - } + Identicon { source, size: 420 } } // https://processing.org/reference/map_.html @@ -25,7 +22,7 @@ impl<'a> Identicon<'a> { } fn foreground(&self) -> Rgb { - // Use last 28 bits to determine HSL values. + // Use last 28 bits to determine Hsl values. let h1 = (self.source[12] as u16 & 0x0f) << 8; let h2 = self.source[13] as u16; @@ -37,7 +34,7 @@ impl<'a> Identicon<'a> { let sat = Identicon::map(s, 0, 255, 0, 20); let lum = Identicon::map(l, 0, 255, 0, 20); - HSL::new(hue, 65.0 - sat, 75.0 - lum).rgb() + Hsl::new(hue, 65.0 - sat, 75.0 - lum).rgb() } fn rect(image: &mut RgbImage, x0: u32, y0: u32, x1: u32, y1: u32, color: Rgb) { diff --git a/src/main.rs b/src/main.rs index 7bb4aaf..ea56153 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,8 +4,8 @@ use std::io; use std::io::Result; use std::process::exit; -use image::png::PngEncoder; use image::ColorType; +use image::{codecs::png::PngEncoder, ImageEncoder}; use md5::{Digest, Md5}; use identicon::Identicon; @@ -27,7 +27,7 @@ fn generate(input: &[u8]) -> Result<()> { let output = &mut io::stdout(); let encoder = PngEncoder::new(output); encoder - .encode(image.as_ref(), width, height, ColorType::Rgb8) + .write_image(image.as_ref(), width, height, ColorType::Rgb8.into()) .map_err(|e| io::Error::new(io::ErrorKind::Other, e)) }