Pi66

Home | Repos | About | Blog | Gaza

walrs
pywal but if its Fast-Minimal-Simple
git clone https://git.pi66.xyz/walrs

About | Files | Commits | Refs | License


add support for non-JPEG image formats

Author: pixel
Date: 2025-03-21 11:15
commit: 7c5608c7

Stat

M src/get_colors.rs 19 +15 -4

Diff

diff --git a/src/get_colors.rs b/src/get_colors.rs
index a71b0a3..1d85e4a 100644
--- a/src/get_colors.rs
+++ b/src/get_colors.rs
@@ -3,7 +3,7 @@ use image;
 use palette_extract::{MaxColors, Quality,};
 use std::collections::HashSet;
 use std::process::exit;
-use std::u8;
+use std::fs::read;
 use crate::utils::warning;

fn adjust_rgb(r: u8, g: u8, b: u8, brightness: i16, saturation: i16) -> (u8, u8, u8) { @@ -37,10 +37,21 @@ fn generate_variation(color: (u8, u8, u8), offset: i16) -> (u8, u8, u8) { }

pub fn get_colors(image_path: &str,send:bool) -> (Vec<(u8,u8,u8)>,u8){ - let image = match image::open(image_path){ - Ok(v) => v, - Err(_) => {warning("Image", "Unsupported or corrupted image format",send);exit(1)}, ...

Show all

diff --git a/src/get_colors.rs b/src/get_colors.rs
index a71b0a3..1d85e4a 100644
--- a/src/get_colors.rs
+++ b/src/get_colors.rs
@@ -3,7 +3,7 @@ use image;
 use palette_extract::{MaxColors, Quality,};
 use std::collections::HashSet;
 use std::process::exit;
-use std::u8;
+use std::fs::read;
 use crate::utils::warning;

fn adjust_rgb(r: u8, g: u8, b: u8, brightness: i16, saturation: i16) -> (u8, u8, u8) { @@ -37,10 +37,21 @@ fn generate_variation(color: (u8, u8, u8), offset: i16) -> (u8, u8, u8) { }

pub fn get_colors(image_path: &str,send:bool) -> (Vec<(u8,u8,u8)>,u8){ - let image = match image::open(image_path){ - Ok(v) => v, - Err(_) => {warning("Image", "Unsupported or corrupted image format",send);exit(1)}, + + let image = match image::open(image_path) { + Ok(img) => img, + Err(_) => { + let data = read(image_path).unwrap(); + match image::guess_format(&data) { + Ok(fmt) => image::load_from_memory_with_format(&data, fmt).unwrap(), + Err(_) => { + warning("Image", "Unsupported or corrupted image format", send); + exit(1); + } + } + } }; + let native_rgba = image.to_rgba8(); let alpha = &native_rgba.get_pixel(0, 0)[3]; let mut collect_rgb:Vec<(u8,u8,u8)> = Vec::new();

// Created by Pi66

// Copyright ©Pi66 2026