This commit is contained in:
l1npengtul
2022-12-31 16:32:37 +09:00
parent 557eba6c04
commit a623cce828
11 changed files with 312 additions and 86 deletions
+123
View File
@@ -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
+38
View File
@@ -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
+23 -2
View File
@@ -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
+2 -2
View File
@@ -1,6 +1,6 @@
[package]
name = "nokhwa"
version = "0.10.3"
version = "0.11.0"
authors = ["l1npengtul <l1npengtul@protonmail.com>"]
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]
+1 -1
View File
@@ -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]
+1 -1
View File
@@ -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]
+1 -1
View File
@@ -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]
+2 -1
View File
@@ -1,10 +1,11 @@
[package]
name = "nokhwa-core"
version = "0.1.0"
version = "0.2.0"
authors = ["l1npengtul <l1npengtul@protonmail.com>"]
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
+120
View File
@@ -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<Self, Self::Err> {
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,
]
}
+1
View File
@@ -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;
-78
View File
@@ -285,84 +285,6 @@ impl TryFrom<CameraIndex> 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<Self, Self::Err> {
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). <br>
/// Note: the [`Ord`] implementation of this struct is flipped from highest to lowest.