forked from l1npengtul/nokhwa
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support kCMPixelFormat_32BGRA and add github action for running tests #1
Open
darioalessandro
wants to merge
15
commits into
0.10
Choose a base branch
from
fix-yuyv-parser
base: 0.10
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8c12b38
add bgra
darioalessandro 7eb5e9d
not ready for primetime but renameb yuyv to i420 because that is what…
darioalessandro 5584868
save
darioalessandro fec4d19
save
darioalessandro 3b0a2fe
save
darioalessandro aad27f7
add bgra to linux bindings
darioalessandro a701a6e
checkin test assets
darioalessandro c46d077
adding assets with license
darioalessandro 8a2f4fc
add tests to ci
darioalessandro ed9d6b5
added better tests
darioalessandro 1c9385b
remove unused imports
darioalessandro 9552a9c
move nokhwa ci to a different file
darioalessandro ac3fbfb
run fmt
darioalessandro 074f3da
revert unrelated ci change
darioalessandro 72dba49
add better logging for bad buffer size
darioalessandro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# 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: | ||
pull_request: {} | ||
|
||
|
||
name: Compile and test Nokhwa Core | ||
|
||
jobs: | ||
run_core_tests: | ||
name: Test | ||
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 Test | ||
run: | | ||
cd nokhwa-core | ||
cargo test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,9 +117,7 @@ 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")))] | ||
pub fn decode_opencv_mat<F: FormatDecoder>( | ||
&mut self, | ||
) -> Result<BoxedRef<Mat>, NokhwaError> { | ||
pub fn decode_opencv_mat<F: FormatDecoder>(&mut self) -> Result<BoxedRef<Mat>, NokhwaError> { | ||
use crate::buffer::channel_defs::make_mat; | ||
|
||
make_mat::<F>(self.resolution, self.buffer()) | ||
|
@@ -137,11 +135,11 @@ impl Buffer { | |
&mut self, | ||
dst: &mut Mat, | ||
) -> Result<(), NokhwaError> { | ||
use bytes::Buf; | ||
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, | ||
|
@@ -221,23 +219,45 @@ impl Buffer { | |
/// 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}; | ||
use bytemuck::{cast_slice, Pod, Zeroable}; | ||
use image::Pixel; | ||
|
||
#[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 { | ||
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)), | ||
1 => Mat::new_rows_cols_with_data::<G8>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is just |
||
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, | ||
|
@@ -253,16 +273,15 @@ pub mod channel_defs { | |
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] | ||
pub data: [u8; 3], | ||
} | ||
|
||
unsafe impl opencv::core::DataType for RGB8 { | ||
|
@@ -324,7 +343,7 @@ pub mod channel_defs { | |
#[repr(transparent)] | ||
#[derive(Copy, Clone, Debug)] | ||
pub struct RGBA8 { | ||
pub data: [u8; 4] | ||
pub data: [u8; 4], | ||
} | ||
|
||
unsafe impl opencv::core::DataType for RGBA8 { | ||
|
@@ -340,4 +359,4 @@ pub mod channel_defs { | |
unsafe impl Zeroable for RGBA8 {} | ||
|
||
unsafe impl Pod for RGBA8 {} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more
cargo fmt