1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
use crate::*;
use azure_kinect_sys::k4a::*;
use std::ptr;
pub struct Image<'a> {
api: &'a azure_kinect_sys::api::Api,
pub(crate) handle: k4a_image_t,
}
impl<'a> Image<'a> {
pub(crate) fn from_handle(api: &azure_kinect_sys::api::Api, handle: k4a_image_t) -> Image {
Image { api, handle }
}
#[deprecated(since = "0.2", note = "Factory::image_create")]
pub fn with_format(
factory: &'a Factory,
format: ImageFormat,
width_pixels: i32,
height_pixels: i32,
stride_bytes: i32,
) -> Result<Image<'a>, Error> {
factory.image_create(format, width_pixels, height_pixels, stride_bytes)
}
#[deprecated(since = "0.2", note = "Factory::image_create_from_buffer")]
pub fn with_buffer(
factory: &'a Factory,
format: ImageFormat,
width_pixels: i32,
height_pixels: i32,
stride_bytes: i32,
buffer: *mut u8,
buffer_size: usize,
buffer_release_cb: Option<MemoryDestroyCallback>,
buffer_release_cb_context: *mut (),
) -> Result<Image<'a>, Error> {
factory.image_create_from_buffer_native(
format,
width_pixels,
height_pixels,
stride_bytes,
buffer,
buffer_size,
buffer_release_cb,
buffer_release_cb_context,
)
}
pub fn get_buffer(&self) -> *const u8 {
unsafe { (self.api.funcs.k4a_image_get_buffer)(self.handle) }
}
pub fn get_mut_buffer(&mut self) -> *mut u8 {
unsafe { (self.api.funcs.k4a_image_get_buffer)(self.handle) }
}
pub fn get_size(&self) -> usize {
unsafe { (self.api.funcs.k4a_image_get_size)(self.handle) }
}
pub fn get_format(&self) -> ImageFormat {
ImageFormat::from_primitive(unsafe { (self.api.funcs.k4a_image_get_format)(self.handle) })
}
pub fn get_width_pixels(&self) -> i32 {
unsafe { (self.api.funcs.k4a_image_get_width_pixels)(self.handle) }
}
pub fn get_height_pixels(&self) -> i32 {
unsafe { (self.api.funcs.k4a_image_get_height_pixels)(self.handle) }
}
pub fn get_stride_bytes(&self) -> i32 {
unsafe { (self.api.funcs.k4a_image_get_stride_bytes)(self.handle) }
}
pub fn get_device_timestamp_usec(&self) -> u64 {
unsafe { (self.api.funcs.k4a_image_get_device_timestamp_usec)(self.handle) }
}
pub fn get_system_timestamp_nsec(&self) -> u64 {
unsafe { (self.api.funcs.k4a_image_get_system_timestamp_nsec)(self.handle) }
}
pub fn get_exposure_usec(&self) -> u64 {
unsafe { (self.api.funcs.k4a_image_get_exposure_usec)(self.handle) }
}
pub fn get_white_balance(&self) -> u32 {
unsafe { (self.api.funcs.k4a_image_get_white_balance)(self.handle) }
}
pub fn get_iso_speed(&self) -> u32 {
unsafe { (self.api.funcs.k4a_image_get_iso_speed)(self.handle) }
}
pub fn set_device_timestamp_usec(&mut self, timestamp: u64) {
unsafe { (self.api.funcs.k4a_image_set_device_timestamp_usec)(self.handle, timestamp) }
}
pub fn set_system_timestamp_nsec(&mut self, timestamp: u64) {
unsafe { (self.api.funcs.k4a_image_set_system_timestamp_nsec)(self.handle, timestamp) }
}
pub fn set_exposure_usec(&mut self, exposure: u64) {
unsafe { (self.api.funcs.k4a_image_set_exposure_usec)(self.handle, exposure) }
}
pub fn set_white_balance(&mut self, white_balance: u32) {
unsafe { (self.api.funcs.k4a_image_set_white_balance)(self.handle, white_balance) }
}
pub fn set_iso_speed(&mut self, iso_speed: u32) {
unsafe { (self.api.funcs.k4a_image_set_iso_speed)(self.handle, iso_speed) }
}
}
impl Drop for Image<'_> {
fn drop(&mut self) {
unsafe {
(self.api.funcs.k4a_image_release)(self.handle);
}
self.handle = ptr::null_mut();
}
}
impl Clone for Image<'_> {
fn clone(&self) -> Self {
unsafe {
(self.api.funcs.k4a_image_reference)(self.handle);
}
Image::from_handle(&self.api, self.handle)
}
}