-
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
base: 0.10
Are you sure you want to change the base?
Conversation
nokhwa-core/src/pixel_format.rs
Outdated
@@ -405,9 +496,10 @@ impl FormatDecoder for LumaAFormat { | |||
/// let image: ImageBuffer<Rgb<u8>, Vec<u8>> = buffer.to_image::<YuyvFormat>(); | |||
/// ``` | |||
#[derive(Copy, Clone, Debug, Default, Hash, Ord, PartialOrd, Eq, PartialEq)] | |||
pub struct YuyvFormat; | |||
pub struct I420Format; |
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.
This was never YUYV it was always meant to be i420, this is a breaking change but it is the right thing to do
.github/workflows/examples.yml
Outdated
@@ -29,4 +29,4 @@ jobs: | |||
- name: Cargo Check | |||
run: | | |||
cd examples/threaded-capture | |||
cargo check |
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.
revert
nokhwa-core/src/buffer.rs
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
this is just cargo fmt
@@ -77,6 +77,16 @@ impl FormatDecoder for RgbFormat { | |||
.collect()), | |||
FrameFormat::RAWRGB => Ok(data.to_vec()), | |||
FrameFormat::NV12 => nv12_to_rgb(resolution, data, false), | |||
FrameFormat::BGRA => { |
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.
this is the meat
of the change
@@ -0,0 +1,38 @@ | |||
|
|||
# Assets |
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.
Documenting how I added the test images and the license for the pyramid picture
@@ -32,7 +32,7 @@ fn main() { | |||
|
|||
let format = RequestedFormat::new::<RgbFormat>(RequestedFormatType::AbsoluteHighestFrameRate); | |||
|
|||
let first_camera = cameras.first().unwrap(); |
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.
This is not needed, remove
/// let image: ImageBuffer<Rgb<u8>, Vec<u8>> = buffer.to_image::<YuyvFormat>(); | ||
/// ``` | ||
#[derive(Copy, Clone, Debug, Default, Hash, Ord, PartialOrd, Eq, PartialEq)] | ||
pub struct YuyvFormat; | ||
|
||
impl FormatDecoder for YuyvFormat { | ||
// YUV 4:2:0 planar colors. but we need to change the image crate to use this format |
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.
This should be a TODO
} | ||
|
||
/// Converts an image in YUYV format to I420 (YUV 4:2:0) format. |
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.
Ensure that this is a proper rust doc comment
@@ -1548,21 +1557,21 @@ pub fn buf_mjpeg_to_rgb(data: &[u8], dest: &mut [u8], rgba: bool) -> Result<(), | |||
}); | |||
} | |||
|
|||
jpeg_decompress.read_scanlines_into::<u8>(dest).map_err(|why| { | |||
NokhwaError::ProcessFrameError { | |||
jpeg_decompress |
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.
cargo fmt
return Err(NokhwaError::ProcessFrameError { | ||
src: FrameFormat::NV12, | ||
destination: "RGB".to_string(), | ||
error: "bad input buffer size".to_string(), | ||
error: format!("bad input buffer size, expected {} but got {}", expected_len, data.len()), |
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.
Add better error
nokhwa-core/src/types.rs
Outdated
let b = chunk[0]; | ||
let g = chunk[1]; | ||
let r = chunk[2]; | ||
// let _a = chunk[3]; // Alpha is ignored for RGB |
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.
remove commented code
Summary
This pull request introduces a new function
buf_bgra_to_rgb
that converts image data from BGRA (Blue, Green, Red, Alpha) format to RGB format. Thefunction now supports the specific pixel format
kCMPixelFormat_32BGRA
, enhancing its versatility for handling images in Apple's Core Media framework.Key Changes
kCMPixelFormat_32BGRA
: Added functionality to process images with this specific pixel format, expanding the library's capability tohandle diverse image types.
chunks_exact
for efficient handling.New Features
kCMPixelFormat_32BGRA
pixel format, aligning with Core Mediastandards.
dimensions.
Bug Fixes
Known Issues
Documentation Improvements
kCMPixelFormat_32BGRA
.Testing
kCMPixelFormat_32BGRA
.Integration
This implementation strengthens the image processing library by adding support for the
kCMPixelFormat_32BGRA
pixel format while maintaining efficiency and safety.