diff options
| author | Fuwn <[email protected]> | 2022-08-02 04:28:16 -1000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-08-02 04:28:16 -1000 |
| commit | c57a1ba0b680840f38a9a3765009b961a0025d5d (patch) | |
| tree | 73e511b02a8337efc88a5eaf7e4e1e0e907d5587 /src | |
| parent | 41f19a9aa2126a3044a15ff381fdbb30fffa7891 (diff) | |
| download | para-c57a1ba0b680840f38a9a3765009b961a0025d5d.tar.xz para-c57a1ba0b680840f38a9a3765009b961a0025d5d.zip | |
refactor(ppm.rs): drop lazy_static for std::lazy
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 2 | ||||
| -rw-r--r-- | src/ppm.rs | 92 |
2 files changed, 46 insertions, 48 deletions
diff --git a/src/main.rs b/src/main.rs index 8541135..b12f6c5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ // Copyright (C) 2022-2022 Fuwn <[email protected]> // SPDX-License-Identifier: MIT -#![feature(decl_macro, generators, generator_trait)] +#![feature(decl_macro, generators, generator_trait, once_cell)] #![deny( warnings, nonstandard_style, @@ -7,55 +7,53 @@ use std::{ collections::HashMap, fs, io::{Cursor, Read}, + lazy::SyncLazy, ops::Generator, }; use byteorder::{LittleEndian, ReadBytesExt}; use chrono::{DateTime, NaiveDateTime, Utc}; -lazy_static::lazy_static! { - // Flipnote speed -> frames per second - static ref FRAMERATES: HashMap<u8, f64> = { - let mut hashmap = HashMap::new(); - - hashmap.insert(1, 0.5); - hashmap.insert(2, 1.0); - hashmap.insert(3, 2.0); - hashmap.insert(4, 4.0); - hashmap.insert(5, 6.0); - hashmap.insert(6, 12.0); - hashmap.insert(7, 20.0); - hashmap.insert(8, 30.0); - - hashmap - }; - - // Thumbnail bitmap RGB colours - static ref THUMBNAIL_PALETTE: &'static [(u64, u64, u64)] = &[ - (0xFF, 0xFF, 0xFF), - (0x52, 0x52, 0x52), - (0xFF, 0xFF, 0xFF), - (0x9C, 0x9C, 0x9C), - (0xFF, 0x48, 0x44), - (0xC8, 0x51, 0x4F), - (0xFF, 0xAD, 0xAC), - (0x00, 0xFF, 0x00), - (0x48, 0x40, 0xFF), - (0x51, 0x4F, 0xB8), - (0xAD, 0xAB, 0xFF), - (0x00, 0xFF, 0x00), - (0xB6, 0x57, 0xB7), - (0x00, 0xFF, 0x00), - (0x00, 0xFF, 0x00), - (0x00, 0xFF, 0x00), - ]; - - // Frame RGB colours - static ref BLACK: (u8, u8, u8) = (0x0E, 0x0E, 0x0E); - static ref WHITE: (u8, u8, u8) = (0xFF, 0xFF, 0xFF); - static ref BLUE: (u8, u8, u8) = (0x0A, 0x39, 0xFF); - static ref RED: (u8, u8, u8) = (0xFF, 0x2A, 0x2A); -} +/// Flipnote speed -> frames per second +static FRAMERATES: SyncLazy<HashMap<u8, f64>> = SyncLazy::new(|| { + let mut hashmap = HashMap::new(); + + hashmap.insert(1, 0.5); + hashmap.insert(2, 1.0); + hashmap.insert(3, 2.0); + hashmap.insert(4, 4.0); + hashmap.insert(5, 6.0); + hashmap.insert(6, 12.0); + hashmap.insert(7, 20.0); + hashmap.insert(8, 30.0); + + hashmap +}); + +/// Thumbnail bitmap RGB colours +// const THUMBNAIL_PALETTE: &'static [(u64, u64, u64)] = &[ +// (0xFF, 0xFF, 0xFF), +// (0x52, 0x52, 0x52), +// (0xFF, 0xFF, 0xFF), +// (0x9C, 0x9C, 0x9C), +// (0xFF, 0x48, 0x44), +// (0xC8, 0x51, 0x4F), +// (0xFF, 0xAD, 0xAC), +// (0x00, 0xFF, 0x00), +// (0x48, 0x40, 0xFF), +// (0x51, 0x4F, 0xB8), +// (0xAD, 0xAB, 0xFF), +// (0x00, 0xFF, 0x00), +// (0xB6, 0x57, 0xB7), +// (0x00, 0xFF, 0x00), +// (0x00, 0xFF, 0x00), +// (0x00, 0xFF, 0x00), +// ]; +// Frame RGB colours +const BLACK: (u8, u8, u8) = (0x0E, 0x0E, 0x0E); +const WHITE: (u8, u8, u8) = (0xFF, 0xFF, 0xFF); +const BLUE: (u8, u8, u8) = (0x0A, 0x39, 0xFF); +const RED: (u8, u8, u8) = (0xFF, 0x2A, 0x2A); macro read_n_to_as_utf8_from_stream($n:expr, $from:ident) { String::from_utf8({ @@ -467,13 +465,13 @@ impl PPMParser { let paper_colour = header & 0x1; let pen = vec![ None, - Some(if paper_colour == 1 { *BLACK } else { *WHITE }), - Some(*RED), - Some(*BLUE), + Some(if paper_colour == 1 { BLACK } else { WHITE }), + Some(RED), + Some(BLUE), ]; vec![ - if paper_colour == 1 { *WHITE } else { *BLACK }, + if paper_colour == 1 { WHITE } else { BLACK }, pen.get(((header >> 1) & 0x3) as usize).unwrap().unwrap(), // Layer one colour pen.get(((header >> 3) & 0x3) as usize).unwrap().unwrap(), // Layer two colour ] |