mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-03 00:47:53 +00:00
streaming color camera
This commit is contained in:
1 parent
65d397c5f1
commit
52fbe25154
2 files changed
+50
-7
No files matched your search
+7
-7
@@ -57,7 +57,8 @@ void main() {
|
||||
//out_color = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
//out_color = vec4(triangleColor, 1.0); // Uniform
|
||||
//out_color = vec4(Color, 1.0);
|
||||
out_color = texture(tex, Texcoord) * vec4(Color, 1.0);
|
||||
//out_color = texture(tex, Texcoord) * vec4(Color, 1.0);
|
||||
out_color = texture(tex, Texcoord);
|
||||
}";
|
||||
|
||||
// Vertex data
|
||||
@@ -290,27 +291,26 @@ pub fn run(capture_provider: Arc<CaptureProvider>) {
|
||||
|
||||
// TODO: This belongs in a worker thread with buffers on both producer and consumer.
|
||||
if let Some(capture) = capture_provider.get_capture() {
|
||||
if let Ok(image) = capture.get_depth_image() {
|
||||
if let Ok(image) = capture.get_color_image() {
|
||||
let width = image.get_width_pixels() as i32;
|
||||
let height = image.get_height_pixels() as i32;
|
||||
println!("Size: {}x{}", width, height);
|
||||
|
||||
let format = image.get_format();
|
||||
println!("format: {:?}", format);
|
||||
|
||||
let buffer = image.get_buffer();
|
||||
|
||||
//let img_ptr: *const c_void = raw_img.as_ptr() as *const c_void;
|
||||
|
||||
|
||||
unsafe {
|
||||
gl::BindTexture(gl::TEXTURE_2D, tex);
|
||||
gl::TexImage2D(
|
||||
gl::TEXTURE_2D,
|
||||
0,
|
||||
gl::RGBA as i32,
|
||||
//format as i32,
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
gl::RGBA,
|
||||
//format,
|
||||
gl::UNSIGNED_BYTE,
|
||||
buffer as *const c_void,
|
||||
);
|
||||
|
||||
@@ -6,6 +6,8 @@ use std::ffi::{CStr, CString};
|
||||
use std::ptr;
|
||||
|
||||
use k4a_sys;
|
||||
use k4a_sys_wrapper::ImageFormat::ColorMjpg;
|
||||
use glutin::platform::unix::x11::ffi::IconMaskHint;
|
||||
|
||||
pub fn device_get_installed_count() -> u32 {
|
||||
unsafe {
|
||||
@@ -261,6 +263,47 @@ impl Image {
|
||||
k4a_sys::k4a_image_get_buffer(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
/// Use this function to determine the format of the image buffer.
|
||||
/// This function is not expected to fail, all k4a_image_t's are created with a
|
||||
/// known format. If the image_handle is invalid, the function will return
|
||||
/// K4A_IMAGE_FORMAT_CUSTOM.
|
||||
pub fn get_format(&self) -> ImageFormat {
|
||||
unsafe {
|
||||
let format = k4a_sys::k4a_image_get_format(self.0);
|
||||
match format {
|
||||
0 => ImageFormat::ColorMjpg,
|
||||
1 => ImageFormat::ColorNv12,
|
||||
2 => ImageFormat::ColorYuy2,
|
||||
3 => ImageFormat::ColorBgra32,
|
||||
4 => ImageFormat::Depth16,
|
||||
5 => ImageFormat::Ir16,
|
||||
6 => ImageFormat::Custom8,
|
||||
7 => ImageFormat::Custom16,
|
||||
8 => ImageFormat::Custom,
|
||||
_ => ImageFormat::UnknownFormatError,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Copy)]
|
||||
pub enum ImageFormat {
|
||||
ColorMjpg,
|
||||
ColorNv12,
|
||||
ColorYuy2,
|
||||
ColorBgra32,
|
||||
/// Depth image type DEPTH16.
|
||||
/// Each pixel of DEPTH16 data is two bytes of little endian unsigned depth data.
|
||||
/// The unit of the data is in millimeters from the origin of the camera.
|
||||
/// Stride indicates the length of each line in bytes and should be used to determine
|
||||
/// the start location of each line of the image in memory.
|
||||
Depth16,
|
||||
Ir16,
|
||||
Custom8,
|
||||
Custom16,
|
||||
Custom,
|
||||
UnknownFormatError, // FIXME: Just return Result<T>?
|
||||
}
|
||||
|
||||
/// Deallocate open device handles
|
||||
|
||||
Reference in new issue
Block a user