use std::fmt;
use std::borrow::BorrowMut;
use std::sync::{Arc, Mutex};
-use log::LevelFilter;
+use log::{debug, warn, LevelFilter};
use num_traits::Zero;
use num_traits::cast::AsPrimitive;
use percent_encoding::percent_decode_str;
use actix_web::{middleware::Logger, get, web, App, HttpServer, HttpRequest, HttpResponse, Responder, ResponseError, Result};
use actix_web::body::BoxBody;
use actix_web::http::StatusCode;
+use actix_web::cookie::time::OffsetDateTime;
use image::{ImageBuffer, ColorType, Rgb, RgbImage, write_buffer_with_format};
use image::ImageOutputFormat::Png;
use image::imageops::{FilterType, overlay, resize};
use image::error::{LimitError, LimitErrorKind};
-use actix_web::cookie::time::OffsetDateTime;
const TIMEAVATAR_SIZE_U32: u32 = 6;
Ok(response_image!(cursor))
}
+#[get("/gen/4/{scale}")]
+async fn img_gen4(req: HttpRequest, path: web::Path<u32>) -> Result<impl Responder> {
+ let scale = path.into_inner();
+ let signal = &mut extract_header!(req, "user-agent").bytes();
+ let mut resimg: RgbImage = ImageBuffer::new(1600, 600);
+ let mut x: f32 = 0.0;
+ let max_x: f32 = (resimg.width() - 1) as f32;
+ //let max_y: f32 = (resimg.height() - 1) as f32;
+ let run: f32 = 20.0;
+ let amplitude: f32 = 200.0;
+ let wave_offset: f32 = (resimg.height() / 2) as f32 + amplitude / 2.0 - 1.0;
+ let freq_base: f32 = 50.0;
+ while x < max_x {
+ let px = x;
+ let s = signal.next().unwrap_or(0);
+ warn!("Next char: {:>1} {:#02X}", s as char, s);
+ while ((x - px) < run) && (x < max_x) {
+ let y = if s != 0 {
+ (x / (freq_base / s as f32)).sin() * amplitude + wave_offset
+ }
+ else { wave_offset };
+ x += 0.001;
+ debug!("{x}, {y}");
+ resimg.put_pixel(x as u32, y as u32, Rgb([255, 255, 255]));
+ resimg.put_pixel(x as u32, s.into(), Rgb([255, 0, 0]));
+ }
+ }
+ let cursor = image_to_cursor(resimg, scale)?;
+ Ok(response_image!(cursor))
+}
+
#[get("/pgen/0/{data}")]
async fn img_pgen0(req: HttpRequest, canvas0: web::Data<Arc<Mutex<Canvas0>>>) -> Result<impl Responder> {
let data = extract_data!(req, 3);
.service(img_gen1)
.service(img_gen2)
.service(img_gen3)
+ .service(img_gen4)
.service(img_pgen0)
.service(img_pgen1)
.service(img_pgen2)