Skip to content

Commit

Permalink
Merge pull request WasmEdge#9 from yanghaku/fix_font_error
Browse files Browse the repository at this point in the history
Fix compile errors in WasmEdge#6.
  • Loading branch information
hydai authored Jun 17, 2024
2 parents 7eee049 + c6d2b33 commit 68462d2
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 20 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ thiserror = "1"
flatbuffers = "^23"
image = { version = "^0", default-features = false, optional = true }
imageproc = { version = "^0", default-features = false, optional = true }
rusttype = { version = "^0", default-features = false, optional = true }
conv = { version = "^0", default-features = false, optional = true }
ab_glyph = { version = "^0", optional = true }
regex = { version = "^1", optional = true }
lazy_static = { version = "^1", optional = true }
symphonia-core = { version = "^0", optional = true }
Expand All @@ -50,7 +49,7 @@ branch = "wasm32-wasi"
default = ["audio", "vision", "text"]

audio = ["symphonia-core"]
vision = ["image", "imageproc", "rusttype", "lazy_static", "conv"]
vision = ["image", "imageproc", "lazy_static", "ab_glyph"]
text = ["regex", "lazy_static"]

ffmpeg = ["ffmpeg-next"]
Expand Down
6 changes: 2 additions & 4 deletions src/postprocess/containers/vision/detection_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ impl DetectionResult {
where
I: image::GenericImage,
I::Pixel: 'static + DefaultPixel,
<I::Pixel as image::Pixel>::Subpixel:
conv::ValueInto<f32> + imageproc::definitions::Clamp<f32>,
<I::Pixel as image::Pixel>::Subpixel: Into<f32> + imageproc::definitions::Clamp<f32>,
{
draw_detection_with_options(img, self, &Default::default());
}
Expand All @@ -43,8 +42,7 @@ impl DetectionResult {
where
I: image::GenericImage,
I::Pixel: 'static,
<I::Pixel as image::Pixel>::Subpixel:
conv::ValueInto<f32> + imageproc::definitions::Clamp<f32>,
<I::Pixel as image::Pixel>::Subpixel: Into<f32> + imageproc::definitions::Clamp<f32>,
{
draw_detection_with_options(img, self, options);
}
Expand Down
2 changes: 1 addition & 1 deletion src/postprocess/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ pub(crate) use ops::{Activation, QuantizationParameters};
mod processing;
pub(crate) use processing::*;

/// Utils to to make use of task results, such as drawing utils.
/// Utils to make use of task results, such as drawing utils.
pub mod utils;
6 changes: 3 additions & 3 deletions src/postprocess/utils/vision/default_font/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// The file `Roboto-Regulat.ttf` is downloaded from https://fonts.google.com/specimen/Roboto.
// This font file is under Apache 2.0: https://github.com/googlefonts/roboto/blob/main/LICENSE

use rusttype::Font;
use ab_glyph::FontArc;

const DEFAULT_FONT_BYTES: &[u8] = include_bytes!("./Roboto-Regular.ttf");

lazy_static::lazy_static! {
static ref DEFAULT_FONT: Font<'static> = Font::try_from_bytes(DEFAULT_FONT_BYTES).unwrap();
static ref DEFAULT_FONT: FontArc = FontArc::try_from_slice(DEFAULT_FONT_BYTES).unwrap();
}

/// Get default ascii font
pub fn default_font() -> &'static Font<'static> {
pub fn default_font() -> &'static FontArc {
&DEFAULT_FONT
}
10 changes: 5 additions & 5 deletions src/postprocess/utils/vision/draw_detections.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::DefaultPixel;
use crate::postprocess::DetectionResult;
use ab_glyph::{FontArc, PxScale};
use image::{GenericImage, Pixel};
use imageproc::{definitions::Clamp, drawing};
use rusttype::{Font, Scale};

/// draw detection results options
#[derive(Debug)]
Expand All @@ -14,7 +14,7 @@ pub struct DrawDetectionsOptions<'font, P: Pixel> {
pub keypoint_radius_percent: f32,

pub draw_label: bool,
pub font: &'font Font<'font>,
pub font: &'font FontArc,
pub font_color: P,
pub font_scale: f32,
}
Expand Down Expand Up @@ -43,7 +43,7 @@ pub fn draw_detection<I>(img: &mut I, detection_result: &DetectionResult)
where
I: GenericImage,
I::Pixel: 'static + DefaultPixel,
<I::Pixel as Pixel>::Subpixel: conv::ValueInto<f32> + Clamp<f32>,
<I::Pixel as Pixel>::Subpixel: Into<f32> + Clamp<f32>,
{
draw_detection_with_options::<I>(img, detection_result, &Default::default())
}
Expand All @@ -55,7 +55,7 @@ pub fn draw_detection_with_options<I>(
options: &DrawDetectionsOptions<I::Pixel>,
) where
I: GenericImage,
<I::Pixel as Pixel>::Subpixel: conv::ValueInto<f32> + Clamp<f32>,
<I::Pixel as Pixel>::Subpixel: Into<f32> + Clamp<f32>,
I::Pixel: 'static,
{
let img_w = img.width() as f32;
Expand All @@ -67,7 +67,7 @@ pub fn draw_detection_with_options<I>(
} else {
options.keypoint_colors[0]
};
let font_scale = Scale {
let font_scale = PxScale {
x: img_min * options.font_scale,
y: img_min * options.font_scale,
};
Expand Down
6 changes: 2 additions & 4 deletions src/tasks/vision/hand_landmark/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ impl HandLandmarkResult {
where
I: image::GenericImage,
I::Pixel: 'static + DefaultPixel,
<I::Pixel as image::Pixel>::Subpixel:
conv::ValueInto<f32> + imageproc::definitions::Clamp<f32>,
<I::Pixel as image::Pixel>::Subpixel: Into<f32> + imageproc::definitions::Clamp<f32>,
{
let mut options = DrawLandmarksOptions::default();
options.connections = HandLandmark::CONNECTIONS;
Expand All @@ -36,8 +35,7 @@ impl HandLandmarkResult {
where
I: image::GenericImage,
I::Pixel: 'static,
<I::Pixel as image::Pixel>::Subpixel:
conv::ValueInto<f32> + imageproc::definitions::Clamp<f32>,
<I::Pixel as image::Pixel>::Subpixel: Into<f32> + imageproc::definitions::Clamp<f32>,
{
draw_landmarks_with_options(img, &self.hand_landmarks, options);
}
Expand Down

0 comments on commit 68462d2

Please sign in to comment.