Skip to content

Commit

Permalink
overlay roster picture display and other stuff (#173)
Browse files Browse the repository at this point in the history
* random improvements

* random improvements

* update dependencies, load images

* basic rpd page

* retry if request fails

* little refactor

* basic implementation of all rpd features. other random changes lost track of

* remove unnecessary images

* add ellipses when truncating text

* equally spaced cards in rpd, preferring arrangement of 4s and 3s

* remove animation of time and state graphic in game

* remove animation of time and state graphic in game

* small refactor, new rpd textures, better network performance

* updated graphics, placement and text fitting, improved code readability, sponsor, member pictures

* revert gid and tid, remove background image

* resolve cargo.lock merge conflict

* tournament logo changes from upstream

* prefetch next game data

* clippy

* new api for team data

* clippy

* more clippy

* separate uwhscores and uwhportal links

* Misc improvements and react changes to tournament ID

* make network calls concurrent

* Skip sections of rpd when no data is present, Fix quotes in text, Correct role logic

* skip rpd section if there are no images to display

* cargo clippy

* fetch next game data if tid changes

* typo

* reduce height of each row in roster list by 2 pixels

* show old game's results if is_old_game is still true

* show old game's results if is_old_game is still true

* fix issues with game data caching and reacting to tid changes

* restore lock file

* improve some variable naming

* check for updates to `next_game_number` each snapshot

* don't invalidate cache

* Only request the same information once

---------

Co-authored-by: Tristan Debrunner <tdebrunner@atlantissports.org>
  • Loading branch information
actuday6418 and TristanDebrunner authored Dec 6, 2023
1 parent 129a531 commit f0f88fd
Show file tree
Hide file tree
Showing 84 changed files with 3,947 additions and 1,465 deletions.
320 changes: 210 additions & 110 deletions Cargo.lock

Large diffs are not rendered by default.

951 changes: 951 additions & 0 deletions alphagen/Cargo.lock

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions alphagen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
name = "alphagen"
version = "0.1.0"
edition = "2021"
description = "Used to generate greyscale mask images based on the alpha channel of existing images"
description = "Used to generate greyscale mask images based on the alpha channel of an image"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4", features = ["derive"] }
image = "*"
clap = { version = "4.3.0", features = ["derive"] }
image = "0.24.6"
log = "0.4.18"
pretty_env_logger = "0.5.0"
rayon = "*"

[lib]
name = "alphagen"
21 changes: 21 additions & 0 deletions alphagen/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# AlphaGen

AlphaGen is a small Rust application used to generate greyscale mask images based on the alpha channel of an image. It takes input image files and an output directory as command-line arguments and processes the images in parallel to generate greyscale mask images.

## Usage

```shell
alphagen input_file(s) output_directory
```

### Installation

To use AlphaGen, you need to have Rust and Cargo installed. If you don't have them installed, you can follow the official Rust installation guide: https://www.rust-lang.org/tools/install

Once Rust is installed, you can clone the project repository and navigate to the project directory:

```shell
git clone <repository-url>
cd alphagen
cargo install --path .
```
51 changes: 51 additions & 0 deletions alphagen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use image::io::Reader;
use image::GenericImageView;
use image::ImageFormat;
use rayon::iter::ParallelBridge;
use rayon::iter::ParallelIterator;
use std::fs;
use std::io::BufWriter;
use std::io::Cursor;
use std::path::PathBuf;

/// Processes all files in `paths` and writes output images to `dir_output`
pub fn on_paths(paths: Vec<&PathBuf>, dir_output: PathBuf) {
paths.iter().par_bridge().for_each(|path| {
let file = image::open(path).unwrap();
let mut output_image_buff = image::GrayAlphaImage::new(file.width(), file.height());
let mut pixs = output_image_buff.pixels_mut();
let mut file_out = fs::File::create(dir_output.join(path.file_name().unwrap()))
.expect("Couldn't create output file");
for (_, _, alpha_channel) in file.pixels() {
let p = pixs.next().unwrap();
p.0[0] = alpha_channel[3];
p.0[1] = alpha_channel[3];
}
output_image_buff
.write_to(&mut file_out, image::ImageFormat::Png)
.unwrap_or_else(|_| {
panic!(
"Couldn't write to output directory {}/{:?}",
dir_output.display(),
path.file_name().unwrap_or_default()
)
});
});
}

/// Process raw image data
pub fn on_raw(input: &[u8]) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
let img_in = Reader::new(Cursor::new(input))
.with_guessed_format()?
.decode()?;
let mut img_out = image::GrayAlphaImage::new(img_in.width(), img_in.height());
let mut pixs = img_out.pixels_mut();
for (_, _, alpha_channel) in img_in.pixels() {
let p = pixs.next().unwrap();
p.0[0] = alpha_channel[3];
p.0[1] = alpha_channel[3];
}
let mut writer = BufWriter::new(Cursor::new(Vec::new()));
img_out.write_to(&mut writer, ImageFormat::Png)?;
Ok(writer.into_inner()?.into_inner())
}
74 changes: 27 additions & 47 deletions alphagen/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,63 +1,43 @@
use alphagen::on_paths;
use clap::Parser;
use image::GenericImageView;
use log::warn;
use rayon::iter::ParallelBridge;
use rayon::iter::ParallelIterator;
use std::{fs, path::PathBuf};
use std::path::PathBuf;

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Cli {
#[clap(long, short, required = true)]
/// Directory within which to find the color images
path: PathBuf,
#[command(author, version, about)]
struct Args {
#[clap(help = "Input files", required = true)]
input_location: Vec<PathBuf>,

#[clap(long, short)]
/// Output directory for the alpha images
out: Option<PathBuf>,
#[clap(help = "Output directory", required = true)]
output_location: PathBuf,
}

fn main() {
let args = Cli::parse();
pretty_env_logger::init();
let args = Args::parse();

if let Some(ref out) = args.out {
if out == &args.path {
println!("Error: if the <out> arg is specified, it cannot match the <path> arg");
return;
}
assert!(out.is_dir());
let dir_output = args.output_location;
if !dir_output.is_dir() {
std::fs::create_dir_all(&dir_output).expect("Could not create output directory!");
}

assert!(args.path.is_dir());

let append_alpha = args.out.is_none();
let out_dir = args.out.as_ref().unwrap_or(&args.path).to_path_buf();

let input_paths = fs::read_dir(args.path).unwrap();

input_paths.par_bridge().for_each(|path| {
if let Ok(path) = path {
let file_name: String = path.path().file_stem().unwrap().to_str().unwrap().into();
let file = image::open(path.path()).unwrap();

let mut imgbuf = image::GrayAlphaImage::new(file.width(), file.height());
let mut pixs = imgbuf.pixels_mut();

let mut out_path = out_dir.clone();
out_path.push(if append_alpha {
format!("{file_name}_alpha.png")
let paths = args
.input_location
.iter()
.par_bridge()
.filter(|p| {
if p.is_file() {
true
} else {
format!("{file_name}.png")
});
let fout = &mut fs::File::create(out_path).unwrap();

for pixel in file.pixels() {
let p = pixs.next().unwrap();
p.0[0] = pixel.2[3];
p.0[1] = pixel.2[3];
warn!("{} is not a valid file path. Skipping.", p.display());
false
}
})
.collect::<Vec<_>>();

imgbuf.write_to(fout, image::ImageFormat::Png).unwrap();
println!("Completed: {}", path.path().to_str().unwrap());
}
});
assert!(paths.is_empty(), "No valid input file paths!");
on_paths(paths, dir_output);
}
22 changes: 12 additions & 10 deletions overlay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4", features = ["derive"] }
coarsetime = "*"
clap = { version = "4.3.1", features = ["derive"] }
futures = "0.3"
coarsetime = "0.1.23"
confy = "0.5"
crossbeam-channel = "*"
directories = "5"
image = { version = "*", features = ["png", "jpeg"] }
log = "*"
crossbeam-channel = "0.5.8"
directories = "5.0.1"
log = "0.4.18"
log-panics = { version = "2", features = ["with-backtrace"]}
log4rs = { version = "1", default-features = false, features = ["background_rotation", "compound_policy", "console_appender", "fixed_window_roller", "gzip", "pattern_encoder", "rolling_file_appender", "size_trigger"]}
macroquad = { version = "0.3", default-features = false }
pollster = "*"
reqwest = { version = "*", features = ["blocking"] }
reqwest = {version = "0.11", features = ["gzip"]}
serde = { version = "1", features = ["derive"] }
serde_json = { version = "*" }
tokio = { version = "*", features = ["macros"] }
serde_json = { version = "1" }
tokio = { version = "1.28", features = ["full"] }
uwh-common = { path = "../uwh-common/" }
bytes = "1.4.0"
alphagen = {path="../alphagen"}
image = { version = "0.24", default-features = false, features = ["png", "jpeg_rayon"] }
Binary file modified overlay/assets/alpha/1080/Atlantis Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added overlay/assets/alpha/1080/Black Team Name.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified overlay/assets/alpha/1080/Black Timeout Flag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified overlay/assets/alpha/1080/Bottom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified overlay/assets/alpha/1080/Final Score.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added overlay/assets/alpha/1080/Number Background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified overlay/assets/alpha/1080/Penalty Black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified overlay/assets/alpha/1080/Penalty Shot Flag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified overlay/assets/alpha/1080/Penalty White.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added overlay/assets/alpha/1080/Red Team Name.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified overlay/assets/alpha/1080/Referee Timeout Flag.png
Binary file modified overlay/assets/alpha/1080/Team Bars.png
Binary file modified overlay/assets/alpha/1080/Team Black.png
Binary file modified overlay/assets/alpha/1080/Team Information.png
Binary file modified overlay/assets/alpha/1080/Team White.png
Binary file modified overlay/assets/alpha/1080/Time and Game State.png
Binary file added overlay/assets/alpha/1080/White Team Name.png
Binary file modified overlay/assets/alpha/1080/White Timeout Flag.png
Binary file removed overlay/assets/alpha/1080/mask.png
Diff not rendered.
Binary file added overlay/assets/color/1080/Black Team Name.png
Binary file added overlay/assets/color/1080/Number Background.png
Binary file added overlay/assets/color/1080/Red Team Name.png
Binary file added overlay/assets/color/1080/White Team Name.png
Binary file removed overlay/assets/color/1080/mask.png
Diff not rendered.
Loading

0 comments on commit f0f88fd

Please sign in to comment.