mirror of
https://github.com/l1npengtul/nokhwa.git
synced 2026-07-04 02:27:26 +00:00
import adjustments
This commit is contained in:
+4
-9
@@ -15,18 +15,13 @@
|
||||
*/
|
||||
|
||||
use crate::{
|
||||
buffer::Buffer, BackendsEnum, CameraControl, CameraFormat, CameraInfo, CaptureAPIBackend,
|
||||
CaptureBackendTrait, FrameFormat, KnownCameraControls, NokhwaError, Resolution,
|
||||
buffer::Buffer, pixel_format::PixelFormat, BackendsEnum, CameraControl, CameraFormat,
|
||||
CameraInfo, CaptureAPIBackend, CaptureBackendTrait, FrameFormat, KnownCameraControls,
|
||||
NokhwaError, Resolution,
|
||||
};
|
||||
use image::buffer::ConvertBuffer;
|
||||
use image::RgbaImage;
|
||||
use std::{any::Any, borrow::Cow, collections::HashMap};
|
||||
#[cfg(feature = "output-wgpu")]
|
||||
use wgpu::{
|
||||
Device as WgpuDevice, Extent3d, ImageCopyTexture, ImageDataLayout, Queue as WgpuQueue,
|
||||
Texture as WgpuTexture, TextureAspect, TextureDescriptor, TextureDimension, TextureFormat,
|
||||
TextureUsages,
|
||||
};
|
||||
use wgpu::{Device as WgpuDevice, Queue as WgpuQueue, Texture as WgpuTexture};
|
||||
|
||||
/// The main `Camera` struct. This is the struct that abstracts over all the backends, providing a simplified interface for use.
|
||||
pub struct Camera {
|
||||
|
||||
+12
-10
@@ -14,17 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use crate::buffer::Buffer;
|
||||
use crate::pixel_format::PixelFormat;
|
||||
use crate::{
|
||||
error::NokhwaError,
|
||||
frame_formats,
|
||||
utils::{CameraFormat, CameraInfo, FrameFormat, Resolution, buf_mjpeg_to_rgb, buf_yuyv422_to_rgb},
|
||||
CameraControl, CaptureAPIBackend, KnownCameraControls,
|
||||
utils::{
|
||||
buf_mjpeg_to_rgb, buf_yuyv422_to_rgb, CameraFormat, CameraInfo, FrameFormat, Resolution,
|
||||
},
|
||||
Buffer, CameraControl, CaptureAPIBackend, KnownCameraControls, PixelFormat,
|
||||
};
|
||||
use enum_dispatch::enum_dispatch;
|
||||
use image::{buffer::ConvertBuffer, ImageBuffer, Rgb, RgbaImage};
|
||||
use std::{any::Any, borrow::Cow, collections::HashMap};
|
||||
use enum_dispatch::enum_dispatch;
|
||||
#[cfg(feature = "output-wgpu")]
|
||||
use wgpu::{
|
||||
Device as WgpuDevice, Extent3d, ImageCopyTexture, ImageDataLayout, Queue as WgpuQueue,
|
||||
@@ -243,8 +243,7 @@ pub trait CaptureBackendTrait {
|
||||
&mut self,
|
||||
buffer: &mut [u8],
|
||||
write_alpha: bool,
|
||||
) -> Result<usize, NokhwaError>
|
||||
{
|
||||
) -> Result<usize, NokhwaError> {
|
||||
let cfmt = self.camera_format()?;
|
||||
let frame = self.frame_raw()?;
|
||||
let data = match cfmt.format() {
|
||||
@@ -252,7 +251,10 @@ pub trait CaptureBackendTrait {
|
||||
FrameFormat::YUYV => buf_yuyv422_to_rgb(&frame, buffer, write_alpha),
|
||||
FrameFormat::GRAY8 => {
|
||||
let data = if write_alpha {
|
||||
frame.into_iter().flat_map(|px| [*px, u8::MAX]).collect::<Cow<[u8]>>()
|
||||
frame
|
||||
.into_iter()
|
||||
.flat_map(|px| [*px, u8::MAX])
|
||||
.collect::<Cow<[u8]>>()
|
||||
} else {
|
||||
frame
|
||||
};
|
||||
@@ -274,9 +276,9 @@ pub trait CaptureBackendTrait {
|
||||
queue: &WgpuQueue,
|
||||
label: Option<&'a str>,
|
||||
) -> Result<WgpuTexture, NokhwaError> {
|
||||
use std::{convert::TryFrom, num::NonZeroU32};
|
||||
use image::RgbaImage;
|
||||
let frame = RgbaImage::from( elf.frame()?.to_image_with_custom_format::<F>()?);
|
||||
use std::{convert::TryFrom, num::NonZeroU32};
|
||||
let frame = RgbaImage::from(elf.frame()?.to_image_with_custom_format::<F>()?);
|
||||
|
||||
let texture_size = Extent3d {
|
||||
width: frame.width(),
|
||||
|
||||
+8
-4
@@ -22,18 +22,20 @@
|
||||
|
||||
use crate::{CameraIndex, CameraInfo, NokhwaError, Resolution};
|
||||
use image::{buffer::ConvertBuffer, ImageBuffer, Rgb, RgbImage, Rgba};
|
||||
#[cfg(feature = "output-wasm")]
|
||||
use js_sys::{Array, JsString, Map, Object, Promise};
|
||||
use std::borrow::Borrow;
|
||||
use std::{
|
||||
borrow::Borrow,
|
||||
borrow::Cow,
|
||||
convert::TryFrom,
|
||||
fmt::{Debug, Display, Formatter},
|
||||
ops::Deref,
|
||||
};
|
||||
#[cfg(feature = "output-wasm")]
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
use wasm_bindgen::{JsCast, JsValue};
|
||||
use wasm_bindgen::{prelude::wasm_bindgen, JsCast, JsValue};
|
||||
#[cfg(feature = "output-wasm")]
|
||||
use wasm_bindgen_futures::JsFuture;
|
||||
#[cfg(feature = "output-wasm")]
|
||||
use web_sys::{
|
||||
console::log_1, CanvasRenderingContext2d, Document, Element, HtmlCanvasElement,
|
||||
HtmlVideoElement, ImageData, MediaDeviceInfo, MediaDeviceKind, MediaDevices, MediaStream,
|
||||
@@ -1675,7 +1677,8 @@ impl Deref for JSCameraConstraints {
|
||||
/// A wrapper around a [`MediaStream`](https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.MediaStream.html)
|
||||
/// # JS-WASM
|
||||
/// This is exported as `NokhwaCamera`.
|
||||
#[cfg_attr(feature = "output-wasm", wasm_bindgen(js_name = NokhwaCamera))]
|
||||
#[cfg(feature = "output-wasm")]
|
||||
#[cfg_attr(feature = "output-wasm", wasm_bindgen(js_name = NokhwaCamera))#[cfg(feature = "output-wasm")]]
|
||||
#[cfg_attr(feature = "docs-features", doc(cfg(feature = "input-jscam")))]
|
||||
pub struct JSCamera {
|
||||
media_stream: MediaStream,
|
||||
@@ -1687,6 +1690,7 @@ pub struct JSCamera {
|
||||
canvas_context: Option<CanvasRenderingContext2d>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "output-wasm")]
|
||||
#[cfg_attr(feature = "output-wasm", wasm_bindgen(js_class = NokhwaCamera))]
|
||||
impl JSCamera {
|
||||
/// Creates a new [`JSCamera`] using [`JSCameraConstraints`].
|
||||
|
||||
+3
-2
@@ -41,7 +41,8 @@ pub mod js_camera;
|
||||
#[cfg(feature = "input-ipcam")]
|
||||
#[cfg_attr(feature = "docs-features", doc(cfg(feature = "input-ipcam")))]
|
||||
pub mod network_camera;
|
||||
pub mod pixel_format;
|
||||
mod pixel_format;
|
||||
pub use pixel_format::PixelFormat;
|
||||
mod query;
|
||||
/// A camera that runs in a different thread and can call your code based on callbacks.
|
||||
#[cfg(feature = "output-threaded")]
|
||||
@@ -49,10 +50,10 @@ mod query;
|
||||
mod threaded;
|
||||
mod utils;
|
||||
|
||||
pub use buffer::Buffer;
|
||||
pub use camera::Camera;
|
||||
pub use camera_traits::*;
|
||||
pub use error::NokhwaError;
|
||||
pub use buffer::Buffer;
|
||||
pub use init::*;
|
||||
#[cfg(feature = "input-jscam")]
|
||||
#[cfg_attr(feature = "docs-features", doc(cfg(feature = "input-jscam")))]
|
||||
|
||||
+2
-4
@@ -14,11 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use crate::buffer_output::{BufferOutput, GrayU8, RgbU8};
|
||||
use crate::FrameFormat;
|
||||
use image::{Luma, Pixel, Rgb};
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
use image::Pixel;
|
||||
use std::{fmt::Debug, hash::Hash};
|
||||
|
||||
pub trait PixelFormat: Copy + Clone + Debug + Default + Hash + Send + Sync {
|
||||
type Output: Pixel;
|
||||
|
||||
Reference in New Issue
Block a user