From a623cce8280fd003a97922f4f1d741e06cbb0345 Mon Sep 17 00:00:00 2001 From: l1npengtul Date: Sat, 31 Dec 2022 16:32:37 +0900 Subject: [PATCH] new ci --- .github/workflows/ci.yml | 123 +++++++++++++++++++++++++++++ .github/workflows/docs.yml | 38 +++++++++ .github/workflows/examples.yml | 25 +++++- Cargo.toml | 4 +- nokhwa-bindings-linux/Cargo.toml | 2 +- nokhwa-bindings-macos/Cargo.toml | 2 +- nokhwa-bindings-windows/Cargo.toml | 2 +- nokhwa-core/Cargo.toml | 3 +- nokhwa-core/src/frame_format.rs | 120 ++++++++++++++++++++++++++++ nokhwa-core/src/lib.rs | 1 + nokhwa-core/src/types.rs | 78 ------------------ 11 files changed, 312 insertions(+), 86 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/docs.yml create mode 100644 nokhwa-core/src/frame_format.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..43725f8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,123 @@ +# Based on https://github.com/actions-rs/meta/blob/master/recipes/quickstart.md +# +# While our "example" application has the platform-specific code, +# for simplicity we are compiling and testing everything on the Ubuntu environment only. +# For multi-OS testing see the `cross.yml` workflow. +on: + push: + paths-ignore: + - '*.md' + pull_request: {} + +name: Format and Clippy All + +# We specify the examples individually since they might need a different environment +jobs: + check_fmt: + name: Check RustFMT + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install nightly toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + + - name: Cargo FMT Check + run: cargo fmt --all -- --check + check_core: + name: Clippy Core + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install nightly toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + - name: Install nasm and OpenCV + run: sudo apt-get update; sudo apt-get install --no-install-recommends nasm libopencv-dev + + - name: Cargo Clippy Core + run: | + cd nokhwa-core/ + cargo clippy --all-features -- -Dwarnings + check_windows: + name: Clippy Core + runs-on: windows-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install nightly toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + + - name: Cargo Clippy bindings-windows + run: | + cd nokhwa-bindings-windows/ + cargo clippy --all-features -- -Dwarnings + + - name: Cargo Clippy Main Crate + run: | + cd .. + cargo clippy --features "serialize, decoding, input-native, output-threaded, output-wgpu" -- -Dwarnings + check_macos: + name: Clippy Core bindings-macos + runs-on: macos-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install nightly toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + + - name: Cargo Clippy bindings-macos + run: | + cd nokhwa-bindings-macos/ + cargo clippy --all-features -- -Dwarnings + + - name: Cargo Clippy Main Crate + run: | + cd .. + cargo clippy --features "serialize, decoding, input-native, output-threaded, output-wgpu" -- -Dwarnings + check_linux_opencv: + name: Clippy Core bindings-linux + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install nightly toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + + - name: Install nasm and OpenCV + run: sudo apt-get update; sudo apt-get install --no-install-recommends nasm libopencv-dev + + - name: Cargo Clippy bindings-linux + run: | + cd nokhwa-bindings-linux/ + cargo clippy --all-features -- -Dwarnings + + - name: Cargo Clippy Main Crate + run: | + cd .. + cargo clippy --features "serialize, decoding, input-opencv, input-native, output-threaded, output-wgpu" -- -Dwarnings diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..7347ddb --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,38 @@ +# Based on https://github.com/actions-rs/meta/blob/master/recipes/quickstart.md +# +# While our "example" application has the platform-specific code, +# for simplicity we are compiling and testing everything on the Ubuntu environment only. +# For multi-OS testing see the `cross.yml` workflow. +on: + push: + paths-ignore: + - '*.md' + pull_request: {} + + +name: Document All + +# We specify the examples individually since they might need a different environment +jobs: + docs: + name: Check + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install nightly toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + + - name: Cargo Doc Core + run: | + cd nokhwa-core/ + cargo doc --features "test-fail-warning, docs-features" -- -Dwarnings + - name: Cargo Doc Main Crate + run: | + cd .. + cargo doc --features "test-fail-warning, docs-features, docs-nolink, docs-only" -- -Dwarnings \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 42ee9de..96855a6 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -5,6 +5,9 @@ # For multi-OS testing see the `cross.yml` workflow. on: + push: + paths-ignore: + - '*.md' pull_request: {} @@ -26,7 +29,25 @@ jobs: toolchain: nightly override: true - - name: Cargo Check + - name: Cargo Clippy run: | cd examples/threaded-capture - cargo check + cargo clippy + compile_example_nokhwactl: + name: Check + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install nightly toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + + - name: Cargo Check + run: | + cd examples/capture + cargo clippy diff --git a/Cargo.toml b/Cargo.toml index 51278e8..8687e57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "nokhwa" -version = "0.10.3" +version = "0.11.0" authors = ["l1npengtul "] edition = "2021" description = "A Simple-to-use, cross-platform Rust Webcam Capture Library" @@ -44,7 +44,7 @@ thiserror = "1.0" paste = "1.0" [dependencies.nokhwa-core] -version = "0.1.0" +version = "0.2" path = "nokhwa-core" [dependencies.serde] diff --git a/nokhwa-bindings-linux/Cargo.toml b/nokhwa-bindings-linux/Cargo.toml index e7a552b..0cc52f0 100644 --- a/nokhwa-bindings-linux/Cargo.toml +++ b/nokhwa-bindings-linux/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["v4l", "v4l2", "linux", "capture", "webcam"] [dependencies] [dependencies.nokhwa-core] -version = "0.1.0" +version = "0.2" path = "../nokhwa-core" [target.'cfg(target_os="linux")'.dependencies] diff --git a/nokhwa-bindings-macos/Cargo.toml b/nokhwa-bindings-macos/Cargo.toml index 72bf4ca..c702ad6 100644 --- a/nokhwa-bindings-macos/Cargo.toml +++ b/nokhwa-bindings-macos/Cargo.toml @@ -12,7 +12,7 @@ keywords = ["avfoundation", "macos", "capture", "webcam"] [dependencies] [dependencies.nokhwa-core] -version = "0.1.0" +version = "0.2" path = "../nokhwa-core" [target.'cfg(any(target_os="macos",target_os="ios"))'.dependencies] diff --git a/nokhwa-bindings-windows/Cargo.toml b/nokhwa-bindings-windows/Cargo.toml index 6aa82e3..b7ee556 100644 --- a/nokhwa-bindings-windows/Cargo.toml +++ b/nokhwa-bindings-windows/Cargo.toml @@ -13,7 +13,7 @@ keywords = ["media-foundation", "windows", "capture", "webcam"] [dependencies] [dependencies.nokhwa-core] -version = "0.1.0" +version = "0.2" path = "../nokhwa-core" [target.'cfg(target_os="windows")'.dependencies.windows] diff --git a/nokhwa-core/Cargo.toml b/nokhwa-core/Cargo.toml index d3515ee..e6a1bcd 100644 --- a/nokhwa-core/Cargo.toml +++ b/nokhwa-core/Cargo.toml @@ -1,10 +1,11 @@ [package] name = "nokhwa-core" -version = "0.1.0" +version = "0.2.0" authors = ["l1npengtul "] edition = "2021" description = "Core type definitions for nokhwa" keywords = ["camera", "webcam", "capture", "cross-platform"] +categories = ["api-bindings", "multimedia", "web-programming"] license = "Apache-2.0" repository = "https://github.com/l1npengtul/nokhwa" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/nokhwa-core/src/frame_format.rs b/nokhwa-core/src/frame_format.rs new file mode 100644 index 0000000..6b5a27d --- /dev/null +++ b/nokhwa-core/src/frame_format.rs @@ -0,0 +1,120 @@ +use crate::error::NokhwaError; +use std::fmt::{Display, Formatter}; +use std::str::FromStr; + +/// Describes a frame format (i.e. how the bytes themselves are encoded). Often called `FourCC`. +/// - YUYV is a mathematical color space. You can read more [here.](https://en.wikipedia.org/wiki/YCbCr) +/// - NV12 is same as above. Note that a partial compression (e.g. [16, 235] may be coerced to [0, 255]. +/// - MJPEG is a motion-jpeg compressed frame, it allows for high frame rates. +/// - GRAY is a grayscale image format, usually for specialized cameras such as IR Cameras. +/// - RAWRGB is a Raw RGB888 format. +#[derive(Copy, Clone, Debug, Hash, Ord, PartialOrd, Eq, PartialEq)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +pub enum FrameFormat { + // Compressed Formats + H265, + H264, + H263, + AVC1, + MPEG1, + MPEG2, + MPEG4, + MJPEG, + XVid, + VP8, + VP9, + + // YCbCr formats + + // -> 422 16 BPP + Yuv422, + Uyv422, + + // 420 + Nv12, + Nv21, + Yv12, + Imc2, + Imc4, + + // UV + UV8, + + // Grayscale Formats + Luma8, + Luma8I, + Luma10, + Luma10B, + Luma12, + Luma12I, + Luma16, + + // Depth Formats + Z16, + + // RGB Formats + Rgb8, + // Bayer +} + +impl Display for FrameFormat { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + FrameFormat::MJPEG => { + write!(f, "MJPEG") + } + FrameFormat::YUYV => { + write!(f, "YUYV") + } + FrameFormat::GRAY => { + write!(f, "GRAY") + } + FrameFormat::RAWRGB => { + write!(f, "RAWRGB") + } + FrameFormat::NV12 => { + write!(f, "NV12") + } + } + } +} +impl FromStr for FrameFormat { + type Err = NokhwaError; + + fn from_str(s: &str) -> Result { + match s { + "MJPEG" => Ok(FrameFormat::MJPEG), + "YUYV" => Ok(FrameFormat::YUYV), + "GRAY" => Ok(FrameFormat::GRAY), + "RAWRGB" => Ok(FrameFormat::RAWRGB), + "NV12" => Ok(FrameFormat::NV12), + _ => Err(NokhwaError::StructureError { + structure: "FrameFormat".to_string(), + error: format!("No match for {s}"), + }), + } + } +} + +/// Returns all the frame formats +#[must_use] +pub const fn frame_formats() -> &'static [FrameFormat] { + &[ + FrameFormat::MJPEG, + FrameFormat::YUYV, + FrameFormat::NV12, + FrameFormat::GRAY, + FrameFormat::RAWRGB, + ] +} + +/// Returns all the color frame formats +#[must_use] +pub const fn color_frame_formats() -> &'static [FrameFormat] { + &[ + FrameFormat::MJPEG, + FrameFormat::YUYV, + FrameFormat::NV12, + FrameFormat::RAWRGB, + ] +} diff --git a/nokhwa-core/src/lib.rs b/nokhwa-core/src/lib.rs index 699be21..f4c5a06 100644 --- a/nokhwa-core/src/lib.rs +++ b/nokhwa-core/src/lib.rs @@ -21,6 +21,7 @@ //! Core type definitions for `nokhwa` pub mod buffer; pub mod error; +pub mod frame_format; pub mod pixel_format; pub mod traits; pub mod types; diff --git a/nokhwa-core/src/types.rs b/nokhwa-core/src/types.rs index 9a0f5d3..e86661f 100644 --- a/nokhwa-core/src/types.rs +++ b/nokhwa-core/src/types.rs @@ -285,84 +285,6 @@ impl TryFrom for usize { } } -/// Describes a frame format (i.e. how the bytes themselves are encoded). Often called `FourCC`. -/// - YUYV is a mathematical color space. You can read more [here.](https://en.wikipedia.org/wiki/YCbCr) -/// - NV12 is same as above. Note that a partial compression (e.g. [16, 235] may be coerced to [0, 255]. -/// - MJPEG is a motion-jpeg compressed frame, it allows for high frame rates. -/// - GRAY is a grayscale image format, usually for specialized cameras such as IR Cameras. -/// - RAWRGB is a Raw RGB888 format. -#[derive(Copy, Clone, Debug, Hash, Ord, PartialOrd, Eq, PartialEq)] -#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] -pub enum FrameFormat { - MJPEG, - YUYV, - NV12, - GRAY, - RAWRGB, -} - -impl Display for FrameFormat { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - match self { - FrameFormat::MJPEG => { - write!(f, "MJPEG") - } - FrameFormat::YUYV => { - write!(f, "YUYV") - } - FrameFormat::GRAY => { - write!(f, "GRAY") - } - FrameFormat::RAWRGB => { - write!(f, "RAWRGB") - } - FrameFormat::NV12 => { - write!(f, "NV12") - } - } - } -} -impl FromStr for FrameFormat { - type Err = NokhwaError; - - fn from_str(s: &str) -> Result { - match s { - "MJPEG" => Ok(FrameFormat::MJPEG), - "YUYV" => Ok(FrameFormat::YUYV), - "GRAY" => Ok(FrameFormat::GRAY), - "RAWRGB" => Ok(FrameFormat::RAWRGB), - "NV12" => Ok(FrameFormat::NV12), - _ => Err(NokhwaError::StructureError { - structure: "FrameFormat".to_string(), - error: format!("No match for {s}"), - }), - } - } -} - -/// Returns all the frame formats -#[must_use] -pub const fn frame_formats() -> &'static [FrameFormat] { - &[ - FrameFormat::MJPEG, - FrameFormat::YUYV, - FrameFormat::NV12, - FrameFormat::GRAY, - FrameFormat::RAWRGB, - ] -} - -/// Returns all the color frame formats -#[must_use] -pub const fn color_frame_formats() -> &'static [FrameFormat] { - &[ - FrameFormat::MJPEG, - FrameFormat::YUYV, - FrameFormat::NV12, - FrameFormat::RAWRGB, - ] -} - /// Describes a Resolution. /// This struct consists of a Width and a Height value (x,y).
/// Note: the [`Ord`] implementation of this struct is flipped from highest to lowest.