mirror of
https://github.com/l1npengtul/nokhwa.git
synced 2026-07-04 02:27:26 +00:00
bump version fix #183
This commit is contained in:
+1
-1
@@ -33,7 +33,7 @@ input-v4l-no-arena-buffer = ["nokhwa-bindings-linux/no-arena-buffer"]
|
||||
input-native = ["input-avfoundation", "input-v4l", "input-msmf"]
|
||||
# Re-enable it once soundness has been proven + mozjpeg is updated to 0.9.x
|
||||
# input-uvc = ["uvc", "uvc/vendor", "usb_enumeration", "lazy_static"]
|
||||
input-opencv = ["opencv", "opencv/videoio", "opencv/rgb", "rgb", "nokhwa-core/opencv-mat"]
|
||||
input-opencv = ["opencv", "opencv/videoio", "opencv/rgb", "opencv/clang-runtime", "nokhwa-core/opencv-mat"]
|
||||
input-jscam = ["web-sys", "js-sys", "wasm-bindgen-futures", "wasm-bindgen", "wasm-rs-async-executor"]
|
||||
output-wgpu = ["wgpu", "nokhwa-core/wgpu-types"]
|
||||
#output-wasm = ["input-jscam"]
|
||||
|
||||
-116
@@ -1,116 +0,0 @@
|
||||
{
|
||||
"nodes": {
|
||||
"devenv": {
|
||||
"locked": {
|
||||
"dir": "src/modules",
|
||||
"lastModified": 1728679870,
|
||||
"owner": "cachix",
|
||||
"repo": "devenv",
|
||||
"rev": "c1117e089b5b78d54885603bf988d26fe88cf44e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"dir": "src/modules",
|
||||
"owner": "cachix",
|
||||
"repo": "devenv",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-compat": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1696426674,
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"gitignore": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"pre-commit-hooks",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1709087332,
|
||||
"owner": "hercules-ci",
|
||||
"repo": "gitignore.nix",
|
||||
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "gitignore.nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1716977621,
|
||||
"owner": "cachix",
|
||||
"repo": "devenv-nixpkgs",
|
||||
"rev": "4267e705586473d3e5c8d50299e71503f16a6fb6",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "cachix",
|
||||
"ref": "rolling",
|
||||
"repo": "devenv-nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-stable": {
|
||||
"locked": {
|
||||
"lastModified": 1728627514,
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "c505ebf777526041d792a49d5f6dd4095ea391a7",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-24.05",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"pre-commit-hooks": {
|
||||
"inputs": {
|
||||
"flake-compat": "flake-compat",
|
||||
"gitignore": "gitignore",
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
],
|
||||
"nixpkgs-stable": "nixpkgs-stable"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1728727368,
|
||||
"owner": "cachix",
|
||||
"repo": "pre-commit-hooks.nix",
|
||||
"rev": "eb74e0be24a11a1531b5b8659535580554d30b28",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "cachix",
|
||||
"repo": "pre-commit-hooks.nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"devenv": "devenv",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"pre-commit-hooks": "pre-commit-hooks"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
{ pkgs, lib, config, inputs, stdenv, ... }:
|
||||
|
||||
{
|
||||
# https://devenv.sh/basics/
|
||||
env.GREET = "devenv";
|
||||
env.LIBCLANG_PATH = "${config.env.DEVENV_PROFILE}/lib/libclang.so";
|
||||
env.CPATH = "${config.env.DEVENV_PROFILE}/include";
|
||||
# https://devenv.sh/packages/
|
||||
packages = [ pkgs.git (pkgs.v4l-utils.override { withUtils = true; }) pkgs.clangStdenv pkgs.mesa
|
||||
pkgs.cmake pkgs.opencv4 pkgs.systemdLibs pkgs.libudev-zero
|
||||
pkgs.libudev0-shim pkgs.vcpkg pkgs.pkg-config pkgs.libclang
|
||||
pkgs.fontconfig pkgs.clang-tools pkgs.linuxHeaders pkgs.gccStdenv pkgs.libcxxStdenv
|
||||
pkgs.glibc_multi
|
||||
];
|
||||
|
||||
# https://devenv.sh/languages/
|
||||
languages.rust.enable = true;
|
||||
# https://devenv.sh/processes/
|
||||
processes.cargo-watch.exec = "cargo-watch";
|
||||
|
||||
# https://devenv.sh/services/
|
||||
# services.postgres.enable = true;
|
||||
|
||||
# https://devenv.sh/scripts/
|
||||
scripts.hello.exec = ''
|
||||
echo hello from $GREET
|
||||
'';
|
||||
|
||||
enterShell = ''
|
||||
hello
|
||||
git --version
|
||||
echo ''${LIBCLANG_PATH}
|
||||
echo ''${CPATH}
|
||||
'';
|
||||
|
||||
# https://devenv.sh/tests/
|
||||
enterTest = ''
|
||||
echo "Running tests"
|
||||
git --version | grep --color=auto "${pkgs.git.version}"
|
||||
'';
|
||||
|
||||
|
||||
|
||||
# https://devenv.sh/pre-commit-hooks/
|
||||
# pre-commit.hooks.shellcheck.enable = true;
|
||||
|
||||
# See full reference at https://devenv.sh/reference/options/
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json
|
||||
inputs:
|
||||
nixpkgs:
|
||||
url: github:cachix/devenv-nixpkgs/rolling
|
||||
|
||||
# If you're using non-OSS software, you can set allowUnfree to true.
|
||||
# allowUnfree: true
|
||||
|
||||
# If you're willing to use a package that's vulnerable
|
||||
# permittedInsecurePackages:
|
||||
# - "openssl-1.1.1w"
|
||||
|
||||
# If you have more than one devenv you can merge them
|
||||
#imports:
|
||||
# - ./backend
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "nokhwa-core"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
authors = ["l1npengtul <l1npengtul@protonmail.com>"]
|
||||
edition = "2021"
|
||||
description = "Core type definitions for nokhwa"
|
||||
@@ -14,7 +14,7 @@ default = []
|
||||
serialize = ["serde"]
|
||||
wgpu-types = ["wgpu"]
|
||||
mjpeg = ["mozjpeg"]
|
||||
opencv-mat = ["opencv"]
|
||||
opencv-mat = ["opencv", "opencv/clang-runtime", "bytemuck"]
|
||||
docs-features = ["serialize", "wgpu-types", "mjpeg"]
|
||||
test-fail-warnings = []
|
||||
|
||||
@@ -33,12 +33,15 @@ features = ["derive"]
|
||||
optional = true
|
||||
|
||||
[dependencies.wgpu]
|
||||
version = "22"
|
||||
version = "23"
|
||||
optional = true
|
||||
|
||||
[dependencies.opencv]
|
||||
version = "0.93"
|
||||
default-features = false
|
||||
optional = true
|
||||
|
||||
[dependencies.bytemuck]
|
||||
version = "1"
|
||||
optional = true
|
||||
|
||||
[dependencies.mozjpeg]
|
||||
|
||||
+138
-39
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use crate::{
|
||||
error::NokhwaError,
|
||||
pixel_format::FormatDecoder,
|
||||
@@ -21,6 +20,8 @@ use crate::{
|
||||
};
|
||||
use bytes::Bytes;
|
||||
use image::ImageBuffer;
|
||||
#[cfg(feature = "opencv-mat")]
|
||||
use opencv::{boxed_ref::BoxedRef, core::Mat};
|
||||
|
||||
/// A buffer returned by a camera to accommodate custom decoding.
|
||||
/// Contains information of Resolution, the buffer's [`FrameFormat`], and the buffer.
|
||||
@@ -103,9 +104,11 @@ impl Buffer {
|
||||
)
|
||||
}
|
||||
|
||||
/// Decodes a image with allocation using the provided [`FormatDecoder`] into a [`Mat`](https://docs.rs/opencv/latest/opencv/core/struct.Mat.html).
|
||||
/// Decodes an image with allocation using the provided [`FormatDecoder`] into a [`Mat`](https://docs.rs/opencv/latest/opencv/core/struct.Mat.html).
|
||||
///
|
||||
/// Note that this does a clone when creating the buffer, to decouple the lifetime of the internal data to the temporary Buffer. If you want to avoid this, please see [`decode_opencv_mat`](Self::decode_opencv_mat).
|
||||
///
|
||||
/// This is **NOT** coherent when the input data is not Gray8, GrayAlpha87, RGB8, or RGBA8
|
||||
/// # Errors
|
||||
/// Will error when the decoding fails, or `OpenCV` failed to create/copy the [`Mat`](https://docs.rs/opencv/latest/opencv/core/struct.Mat.html).
|
||||
/// # Safety
|
||||
@@ -114,48 +117,17 @@ impl Buffer {
|
||||
/// Most notably, the `data` **must** stay in scope for the duration of the [`Mat`](https://docs.rs/opencv/latest/opencv/core/struct.Mat.html) or bad, ***bad*** things happen.
|
||||
#[cfg(feature = "opencv-mat")]
|
||||
#[cfg_attr(feature = "docs-features", doc(cfg(feature = "opencv-mat")))]
|
||||
#[allow(clippy::cast_possible_wrap)]
|
||||
pub fn decode_opencv_mat<F: FormatDecoder>(
|
||||
&mut self,
|
||||
) -> Result<opencv::core::Mat, NokhwaError> {
|
||||
use image::Pixel;
|
||||
use opencv::core::{Mat, Mat_AUTO_STEP, CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4};
|
||||
) -> Result<BoxedRef<Mat>, NokhwaError> {
|
||||
use crate::buffer::channel_defs::make_mat;
|
||||
|
||||
let array_type = match F::Output::CHANNEL_COUNT {
|
||||
1 => CV_8UC1,
|
||||
2 => CV_8UC2,
|
||||
3 => CV_8UC3,
|
||||
4 => CV_8UC4,
|
||||
_ => {
|
||||
return Err(NokhwaError::ProcessFrameError {
|
||||
src: FrameFormat::RAWRGB,
|
||||
destination: "OpenCV Mat".to_string(),
|
||||
error: "Invalid Decoder FormatDecoder Channel Count".to_string(),
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
unsafe {
|
||||
// TODO: Look into removing this unnecessary copy.
|
||||
let mat1 = Mat::new_rows_cols_with_data(
|
||||
self.resolution.height_y as i32,
|
||||
self.resolution.width_x as i32,
|
||||
array_type,
|
||||
self.buffer.as_ref().as_ptr().cast_mut().cast(),
|
||||
Mat_AUTO_STEP,
|
||||
)
|
||||
.map_err(|why| NokhwaError::ProcessFrameError {
|
||||
src: FrameFormat::RAWRGB,
|
||||
destination: "OpenCV Mat".to_string(),
|
||||
error: why.to_string(),
|
||||
})?;
|
||||
|
||||
Ok(mat1)
|
||||
}
|
||||
make_mat::<F>(self.resolution, self.buffer())
|
||||
}
|
||||
|
||||
/// Decodes a image with allocation using the provided [`FormatDecoder`] into a [`Mat`](https://docs.rs/opencv/latest/opencv/core/struct.Mat.html).
|
||||
/// Decodes an image with allocation using the provided [`FormatDecoder`] into a [`Mat`](https://docs.rs/opencv/latest/opencv/core/struct.Mat.html).
|
||||
///
|
||||
/// This is **NOT** coherent when the input data is not Gray8, GrayAlpha87, RGB8, or RGBA8
|
||||
/// # Errors
|
||||
/// Will error when the decoding fails, or `OpenCV` failed to create/copy the [`Mat`](https://docs.rs/opencv/latest/opencv/core/struct.Mat.html).
|
||||
#[cfg(feature = "opencv-mat")]
|
||||
@@ -163,12 +135,13 @@ impl Buffer {
|
||||
#[allow(clippy::cast_possible_wrap)]
|
||||
pub fn decode_into_opencv_mat<F: FormatDecoder>(
|
||||
&mut self,
|
||||
dst: &mut opencv::core::Mat,
|
||||
dst: &mut Mat,
|
||||
) -> Result<(), NokhwaError> {
|
||||
use image::Pixel;
|
||||
use opencv::core::{
|
||||
Mat, MatTraitConst, MatTraitManual, Scalar, CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4,
|
||||
};
|
||||
use bytes::Buf;
|
||||
|
||||
let array_type = match F::Output::CHANNEL_COUNT {
|
||||
1 => CV_8UC1,
|
||||
@@ -242,3 +215,129 @@ impl Buffer {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Channel definitions and utilities for making Mat for OpenCV
|
||||
///
|
||||
/// You (probably) shouldn't use this.
|
||||
#[cfg(feature = "opencv-mat")]
|
||||
pub mod channel_defs {
|
||||
use bytemuck::{cast_slice, Pod, Zeroable};
|
||||
use image::Pixel;
|
||||
use crate::error::NokhwaError;
|
||||
use crate::pixel_format::FormatDecoder;
|
||||
use crate::types::{FrameFormat, Resolution};
|
||||
|
||||
#[cfg(feature = "opencv-mat")]
|
||||
#[cfg_attr(feature = "docs-features", doc(cfg(feature = "opencv-mat")))]
|
||||
pub(crate) fn make_mat<F>(resolution: Resolution, data: &[u8]) -> Result<opencv::boxed_ref::BoxedRef<opencv::core::Mat>, NokhwaError> where F: FormatDecoder {
|
||||
use crate::buffer::channel_defs::*;
|
||||
use opencv::core::Mat;
|
||||
|
||||
let mat = match F::Output::CHANNEL_COUNT {
|
||||
1 => Mat::new_rows_cols_with_data::<G8>(resolution.width() as i32, resolution.height() as i32, cast_slice(data)),
|
||||
2 => Mat::new_rows_cols_with_data::<GA8>(resolution.width() as i32, resolution.height() as i32, cast_slice(data)),
|
||||
3 => Mat::new_rows_cols_with_data::<RGB8>(resolution.width() as i32, resolution.height() as i32, cast_slice(data)),
|
||||
4 => Mat::new_rows_cols_with_data::<RGBA8>(resolution.width() as i32, resolution.height() as i32, cast_slice(data)),
|
||||
_ => {
|
||||
return Err(NokhwaError::ProcessFrameError {
|
||||
src: FrameFormat::RAWRGB,
|
||||
destination: "OpenCV Mat".to_string(),
|
||||
error: "Invalid Decoder FormatDecoder Channel Count".to_string(),
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
match mat {
|
||||
Ok(m) => Ok(m),
|
||||
Err(why) => Err(NokhwaError::ProcessFrameError {
|
||||
src: FrameFormat::RAWRGB,
|
||||
destination: "OpenCV Mat".to_string(),
|
||||
error: why.to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Three u8
|
||||
#[repr(transparent)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct RGB8 {
|
||||
pub data: [u8; 3]
|
||||
}
|
||||
|
||||
unsafe impl opencv::core::DataType for RGB8 {
|
||||
fn opencv_depth() -> i32 {
|
||||
1
|
||||
}
|
||||
|
||||
fn opencv_channels() -> i32 {
|
||||
3
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Pod for RGB8 {}
|
||||
|
||||
unsafe impl Zeroable for RGB8 {}
|
||||
|
||||
/// Two u8
|
||||
#[repr(transparent)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct GA8 {
|
||||
pub data: [u8; 2],
|
||||
}
|
||||
|
||||
unsafe impl opencv::core::DataType for GA8 {
|
||||
fn opencv_depth() -> i32 {
|
||||
1
|
||||
}
|
||||
|
||||
fn opencv_channels() -> i32 {
|
||||
2
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Zeroable for GA8 {}
|
||||
|
||||
unsafe impl Pod for GA8 {}
|
||||
|
||||
/// One u8
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct G8 {
|
||||
pub data: u8,
|
||||
}
|
||||
|
||||
unsafe impl opencv::core::DataType for G8 {
|
||||
fn opencv_depth() -> i32 {
|
||||
1
|
||||
}
|
||||
|
||||
fn opencv_channels() -> i32 {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Zeroable for G8 {}
|
||||
|
||||
unsafe impl Pod for G8 {}
|
||||
|
||||
/// Four u8
|
||||
#[repr(transparent)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct RGBA8 {
|
||||
pub data: [u8; 4]
|
||||
}
|
||||
|
||||
unsafe impl opencv::core::DataType for RGBA8 {
|
||||
fn opencv_depth() -> i32 {
|
||||
1
|
||||
}
|
||||
|
||||
fn opencv_channels() -> i32 {
|
||||
4
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Zeroable for RGBA8 {}
|
||||
|
||||
unsafe impl Pod for RGBA8 {}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#![deny(clippy::pedantic)]
|
||||
#![warn(clippy::all)]
|
||||
#![cfg_attr(feature = "test-fail-warning", deny(warnings))]
|
||||
#![cfg_attr(feature = "test-fail-warnings", deny(warnings))]
|
||||
#![cfg_attr(feature = "docs-features", feature(doc_cfg))]
|
||||
/*
|
||||
* Copyright 2022 l1npengtul <l1npengtul@protonmail.com> / The Nokhwa Contributors
|
||||
|
||||
@@ -37,7 +37,8 @@ use wgpu::{
|
||||
/// - Backends, if not provided with a camera format, will be spawned with 640x480@15 FPS, MJPEG [`CameraFormat`].
|
||||
/// - Behaviour can differ from backend to backend. While the Camera struct abstracts most of this away, if you plan to use the raw backend structs please read the `Quirks` section of each backend.
|
||||
/// - If you call [`stop_stream()`](CaptureBackendTrait::stop_stream()), you will usually need to call [`open_stream()`](CaptureBackendTrait::open_stream()) to get more frames from the camera.
|
||||
pub trait CaptureBackendTrait {
|
||||
pub trait
|
||||
CaptureBackendTrait {
|
||||
/// Returns the current backend used.
|
||||
fn backend(&self) -> ApiBackend;
|
||||
|
||||
|
||||
@@ -166,7 +166,7 @@ impl RequestedFormat<'_> {
|
||||
let res = x.resolution();
|
||||
let x_diff = res.x() as i32 - c.resolution().x() as i32;
|
||||
let y_diff = res.y() as i32 - c.resolution().y() as i32;
|
||||
let dist_no_sqrt = (x_diff.abs()).pow(2) + (y_diff.abs()).pow(2);
|
||||
let dist_no_sqrt = x_diff.abs().pow(2) + y_diff.abs().pow(2);
|
||||
(dist_no_sqrt, res)
|
||||
})
|
||||
.collect::<Vec<(i32, Resolution)>>();
|
||||
@@ -368,7 +368,6 @@ pub const fn color_frame_formats() -> &'static [FrameFormat] {
|
||||
/// Note: the [`Ord`] implementation of this struct is flipped from highest to lowest.
|
||||
/// # JS-WASM
|
||||
/// This is exported as `JSResolution`
|
||||
#[cfg_attr(feature = "output-wasm", wasm_bindgen)]
|
||||
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
|
||||
#[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)]
|
||||
pub struct Resolution {
|
||||
@@ -376,13 +375,11 @@ pub struct Resolution {
|
||||
pub height_y: u32,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "output-wasm", wasm_bindgen)]
|
||||
impl Resolution {
|
||||
/// Create a new resolution from 2 image size coordinates.
|
||||
/// # JS-WASM
|
||||
/// This is exported as a constructor for [`Resolution`].
|
||||
#[must_use]
|
||||
#[cfg_attr(feature = "output-wasm", wasm_bindgen(constructor))]
|
||||
pub fn new(x: u32, y: u32) -> Self {
|
||||
Resolution {
|
||||
width_x: x,
|
||||
@@ -394,7 +391,6 @@ impl Resolution {
|
||||
/// # JS-WASM
|
||||
/// This is exported as `get_Width`.
|
||||
#[must_use]
|
||||
#[cfg_attr(feature = "output-wasm", wasm_bindgen(getter = Width))]
|
||||
#[inline]
|
||||
pub fn width(self) -> u32 {
|
||||
self.width_x
|
||||
@@ -404,7 +400,6 @@ impl Resolution {
|
||||
/// # JS-WASM
|
||||
/// This is exported as `get_Height`.
|
||||
#[must_use]
|
||||
#[cfg_attr(feature = "output-wasm", wasm_bindgen(getter = Height))]
|
||||
#[inline]
|
||||
pub fn height(self) -> u32 {
|
||||
self.height_y
|
||||
@@ -412,7 +407,6 @@ impl Resolution {
|
||||
|
||||
/// Get the x (width) of Resolution
|
||||
#[must_use]
|
||||
#[cfg_attr(feature = "output-wasm", wasm_bindgen(skip))]
|
||||
#[inline]
|
||||
pub fn x(self) -> u32 {
|
||||
self.width_x
|
||||
@@ -420,7 +414,6 @@ impl Resolution {
|
||||
|
||||
/// Get the y (height) of Resolution
|
||||
#[must_use]
|
||||
#[cfg_attr(feature = "output-wasm", wasm_bindgen(skip))]
|
||||
#[inline]
|
||||
pub fn y(self) -> u32 {
|
||||
self.height_y
|
||||
@@ -553,7 +546,6 @@ impl Display for CameraFormat {
|
||||
/// `description` amd `misc` may contain information that may differ from backend to backend. Refer to each backend for details.
|
||||
/// `index` is a camera's index given to it by (usually) the OS usually in the order it is known to the system.
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd)]
|
||||
#[cfg_attr(feature = "output-wasm", wasm_bindgen)]
|
||||
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
|
||||
pub struct CameraInfo {
|
||||
human_name: String,
|
||||
@@ -562,16 +554,14 @@ pub struct CameraInfo {
|
||||
index: CameraIndex,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "output-wasm", wasm_bindgen(js_class = CameraInfo))]
|
||||
impl CameraInfo {
|
||||
/// Create a new [`CameraInfo`].
|
||||
/// # JS-WASM
|
||||
/// This is exported as a constructor for [`CameraInfo`].
|
||||
#[must_use]
|
||||
#[cfg_attr(feature = "output-wasm", wasm_bindgen(constructor))]
|
||||
// OK, i just checkeed back on this code. WTF was I on when I wrote `&(impl AsRef<str> + ?Sized)` ????
|
||||
// I need to get on the same shit that my previous self was on, because holy shit that stuff is strong as FUCK!
|
||||
// Finally fixed this insanity. Hopefully I didnt torment anyone by actually putting this in a stable release.
|
||||
// Finally fixed this insanity. Hopefully I didn't torment anyone by actually putting this in a stable release.
|
||||
pub fn new(human_name: &str, description: &str, misc: &str, index: CameraIndex) -> Self {
|
||||
CameraInfo {
|
||||
human_name: human_name.to_string(),
|
||||
@@ -585,10 +575,6 @@ impl CameraInfo {
|
||||
/// # JS-WASM
|
||||
/// This is exported as a `get_HumanReadableName`.
|
||||
#[must_use]
|
||||
#[cfg_attr(
|
||||
feature = "output-wasm",
|
||||
wasm_bindgen(getter = HumanReadableName)
|
||||
)]
|
||||
// yes, i know, unnecessary alloc this, unnecessary alloc that
|
||||
// but wasm bindgen
|
||||
pub fn human_name(&self) -> String {
|
||||
@@ -598,10 +584,6 @@ impl CameraInfo {
|
||||
/// Set the device info's human name.
|
||||
/// # JS-WASM
|
||||
/// This is exported as a `set_HumanReadableName`.
|
||||
#[cfg_attr(
|
||||
feature = "output-wasm",
|
||||
wasm_bindgen(setter = HumanReadableName)
|
||||
)]
|
||||
pub fn set_human_name(&mut self, human_name: &str) {
|
||||
self.human_name = human_name.to_string();
|
||||
}
|
||||
@@ -610,7 +592,6 @@ impl CameraInfo {
|
||||
/// # JS-WASM
|
||||
/// This is exported as a `get_Description`.
|
||||
#[must_use]
|
||||
#[cfg_attr(feature = "output-wasm", wasm_bindgen(getter = Description))]
|
||||
pub fn description(&self) -> &str {
|
||||
self.description.borrow()
|
||||
}
|
||||
@@ -618,7 +599,6 @@ impl CameraInfo {
|
||||
/// Set the device info's description.
|
||||
/// # JS-WASM
|
||||
/// This is exported as a `set_Description`.
|
||||
#[cfg_attr(feature = "output-wasm", wasm_bindgen(setter = Description))]
|
||||
pub fn set_description(&mut self, description: &str) {
|
||||
self.description = description.to_string();
|
||||
}
|
||||
@@ -627,7 +607,6 @@ impl CameraInfo {
|
||||
/// # JS-WASM
|
||||
/// This is exported as a `get_MiscString`.
|
||||
#[must_use]
|
||||
#[cfg_attr(feature = "output-wasm", wasm_bindgen(getter = MiscString))]
|
||||
pub fn misc(&self) -> String {
|
||||
self.misc.clone()
|
||||
}
|
||||
@@ -635,7 +614,6 @@ impl CameraInfo {
|
||||
/// Set the device info's misc.
|
||||
/// # JS-WASM
|
||||
/// This is exported as a `set_MiscString`.
|
||||
#[cfg_attr(feature = "output-wasm", wasm_bindgen(setter = MiscString))]
|
||||
pub fn set_misc(&mut self, misc: &str) {
|
||||
self.misc = misc.to_string();
|
||||
}
|
||||
@@ -644,7 +622,6 @@ impl CameraInfo {
|
||||
/// # JS-WASM
|
||||
/// This is exported as a `get_Index`.
|
||||
#[must_use]
|
||||
#[cfg_attr(feature = "output-wasm", wasm_bindgen(getter = Index))]
|
||||
pub fn index(&self) -> &CameraIndex {
|
||||
&self.index
|
||||
}
|
||||
@@ -652,7 +629,6 @@ impl CameraInfo {
|
||||
/// Set the device info's index.
|
||||
/// # JS-WASM
|
||||
/// This is exported as a `set_Index`.
|
||||
#[cfg_attr(feature = "output-wasm", wasm_bindgen(setter = Index))]
|
||||
pub fn set_index(&mut self, index: CameraIndex) {
|
||||
self.index = index;
|
||||
}
|
||||
@@ -662,7 +638,6 @@ impl CameraInfo {
|
||||
// /// If the index is not parsable as a `u32`, this will error.
|
||||
// /// # JS-WASM
|
||||
// /// This is exported as `get_Index_Int`
|
||||
// #[cfg_attr(feature = "output-wasm", wasm_bindgen(getter = Index_Int))]
|
||||
// pub fn index_num(&self) -> Result<u32, NokhwaError> {
|
||||
// match &self.index {
|
||||
// CameraIndex::Index(i) => Ok(*i),
|
||||
@@ -861,7 +836,7 @@ impl ControlValueDescription {
|
||||
}
|
||||
}
|
||||
|
||||
/// Verifies if the [setter](crate::types::ControlValueSetter) is valid for the provided [`ControlValueDescription`].
|
||||
/// Verifies if the [setter](ControlValueSetter) is valid for the provided [`ControlValueDescription`].
|
||||
/// - `true` => Is valid.
|
||||
/// - `false` => Is not valid.
|
||||
///
|
||||
@@ -1468,7 +1443,7 @@ impl Display for ApiBackend {
|
||||
/// # Safety
|
||||
/// This function uses `unsafe`. The caller must ensure that:
|
||||
/// - The input data is of the right size, does not exceed bounds, and/or the final size matches with the initial size.
|
||||
#[cfg(all(feature = "mjpeg", not(target_arch = "wasm")))]
|
||||
#[cfg(all(feature = "mjpeg", not(target_arch = "wasm32")))]
|
||||
#[cfg_attr(feature = "docs-features", doc(cfg(feature = "mjpeg")))]
|
||||
#[inline]
|
||||
pub fn mjpeg_to_rgb(data: &[u8], rgba: bool) -> Result<Vec<u8>, NokhwaError> {
|
||||
@@ -1521,7 +1496,7 @@ pub fn mjpeg_to_rgb(data: &[u8], rgba: bool) -> Result<Vec<u8>, NokhwaError> {
|
||||
Ok(scanlines_res)
|
||||
}
|
||||
|
||||
#[cfg(not(all(feature = "mjpeg", not(target_arch = "wasm"))))]
|
||||
#[cfg(not(all(feature = "mjpeg", not(target_arch = "wasm32"))))]
|
||||
pub fn mjpeg_to_rgb(_data: &[u8], _rgba: bool) -> Result<Vec<u8>, NokhwaError> {
|
||||
Err(NokhwaError::NotImplementedError(
|
||||
"Not available on WASM".to_string(),
|
||||
@@ -1531,7 +1506,7 @@ pub fn mjpeg_to_rgb(_data: &[u8], _rgba: bool) -> Result<Vec<u8>, NokhwaError> {
|
||||
/// Equivalent to [`mjpeg_to_rgb`] except with a destination buffer.
|
||||
/// # Errors
|
||||
/// If the decoding fails (e.g. invalid MJPEG stream), the buffer is not large enough, or you are doing this on `WebAssembly`, this will error.
|
||||
#[cfg(all(feature = "mjpeg", not(target_arch = "wasm")))]
|
||||
#[cfg(all(feature = "mjpeg", not(target_arch = "wasm32")))]
|
||||
#[cfg_attr(feature = "docs-features", doc(cfg(feature = "mjpeg")))]
|
||||
#[inline]
|
||||
pub fn buf_mjpeg_to_rgb(data: &[u8], dest: &mut [u8], rgba: bool) -> Result<(), NokhwaError> {
|
||||
@@ -1591,7 +1566,7 @@ pub fn buf_mjpeg_to_rgb(data: &[u8], dest: &mut [u8], rgba: bool) -> Result<(),
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(not(all(feature = "mjpeg", not(target_arch = "wasm"))))]
|
||||
#[cfg(not(all(feature = "mjpeg", not(target_arch = "wasm32"))))]
|
||||
pub fn buf_mjpeg_to_rgb(_data: &[u8], _dest: &mut [u8], _rgba: bool) -> Result<(), NokhwaError> {
|
||||
Err(NokhwaError::NotImplementedError(
|
||||
"Not available on WASM".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user