Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
satler-git committed Aug 3, 2024
1 parent ead4351 commit b76a452
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src-tauri/src/icon/shuffle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::arch::x86_64::_mm_shuffle_epi8;
use std::arch::x86_64::_mm_storeu_si128;

/// Convert BGRA to RGBA
///
///
/// Uses SIMD to go fast
pub fn bgra_to_rgba(data: &mut [u8]) {
// The shuffle mask for converting BGRA -> RGBA
Expand All @@ -26,4 +26,4 @@ pub fn bgra_to_rgba(data: &mut [u8]) {
vector = unsafe { _mm_shuffle_epi8(vector, mask) };
unsafe { _mm_storeu_si128(chunk.as_mut_ptr() as *mut __m128i, vector) };
}
}
}
2 changes: 1 addition & 1 deletion src-tauri/src/icon/win_icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use windows::Win32::UI::WindowsAndMessaging::GetIconInfoExW;
use windows::Win32::UI::WindowsAndMessaging::HICON;
use windows::Win32::UI::WindowsAndMessaging::ICONINFOEXW;

use anyhow::{bail, Result, anyhow};
use anyhow::{anyhow, bail, Result};

pub fn get_images_from_exe(executable_path: &str) -> Result<Vec<RgbaImage>> {
unsafe {
Expand Down
23 changes: 10 additions & 13 deletions src-tauri/src/img.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{bail, Context as _, Ok, Result};
use image::{DynamicImage, Pixel, Rgba};
use fxhash::FxHashMap;
use image::{DynamicImage, Pixel, Rgba};

/// pngをbase64_pngに変換する
/// `format!("data:image/png;base64,{}", resp_base64)`
Expand Down Expand Up @@ -29,8 +29,8 @@ pub fn find_most_used_color(image: &DynamicImage) -> Result<u32> {
let mut counts: FxHashMap<usize, u32> = FxHashMap::default();

for pi in pixels {
let count = counts.entry(cast_rgbau8_to_usize(pi)).or_insert(0);
*count += 1;
let count = counts.entry(cast_rgbau8_to_usize(pi)).or_insert(0);
*count += 1;
}

let most_common_color = counts
Expand Down Expand Up @@ -60,19 +60,16 @@ mod tests {
}

fn check_one_colored_image(rgb: Rgb<u8>) -> Result<()> {
let image = &make_one_colored_image(&rgb)?;
let rgb_u32 = ((rgb[0] as u32) << 16) | ((rgb[1] as u32) << 8) | (rgb[2] as u32);
assert_eq!(
find_most_used_color(image)?,
rgb_u32
);
Ok(())
let image = &make_one_colored_image(&rgb)?;
let rgb_u32 = ((rgb[0] as u32) << 16) | ((rgb[1] as u32) << 8) | (rgb[2] as u32);
assert_eq!(find_most_used_color(image)?, rgb_u32);
Ok(())
}

#[test]
fn one_colored_images() -> Result<()> {
check_one_colored_image(Rgb([255, 255, 255]))?;
check_one_colored_image(Rgb([0, 0, 0]))?;
Ok(())
check_one_colored_image(Rgb([255, 255, 255]))?;
check_one_colored_image(Rgb([0, 0, 0]))?;
Ok(())
}
}
8 changes: 5 additions & 3 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ async fn main() -> Result<()> {

for incoming in notify_receiver.incoming() {
match incoming {
Ok(_) => if main_window_notify.is_visible().unwrap() {
// フロントエンド側に再レンダリングを要求
},
Ok(_) => {
if main_window_notify.is_visible().unwrap() {
// フロントエンド側に再レンダリングを要求
}
}
Err(_) => {
continue;
}
Expand Down

0 comments on commit b76a452

Please sign in to comment.