4 #include "../include/librealsense2/hpp/rs_sensor.hpp" 5 #include "../include/librealsense2/hpp/rs_processing.hpp" 17 #define PIX_SORT(a,b) { if ((a)>(b)) PIX_SWAP((a),(b)); } 18 #define PIX_SWAP(a,b) { pixelvalue temp=(a);(a)=(b);(b)=temp; } 19 #define PIX_MIN(a,b) ((a)>(b)) ? (b) : (a) 20 #define PIX_MAX(a,b) ((a)>(b)) ? (a) : (b) 33 template <
class pixelvalue>
46 template <
class pixelvalue>
65 template <
class pixelvalue>
88 template <
class pixelvalue>
115 template <
class pixelvalue>
137 template <
class pixelvalue>
173 template <
class pixelvalue>
204 _decimation_factor(decimation_default_val),
205 _control_val(decimation_default_val),
206 _patch_size(decimation_default_val),
207 _kernel_size(_patch_size*_patch_size),
212 _recalc_profile(false),
213 _options_changed(false)
218 auto decimation_control = std::make_shared<ptr_option<uint8_t>>(
224 decimation_control->on_set([
this, decimation_control](
float val)
228 if (!decimation_control->is_valid(val))
230 <<
"Unsupported decimation scale " << val <<
" is out of range.");
264 static_cast<uint16_t*>(const_cast<void*>(tgt.get_data())),
270 const_cast<void*
>(tgt.get_data()),
335 tgt_vspi->set_intrinsics([tgt_intrin]() {
return tgt_intrin; });
336 tgt_vspi->set_dims(tgt_intrin.
width, tgt_intrin.
height);
348 vf.get_bytes_per_pixel(),
358 size_t width_in,
size_t height_in,
size_t scale)
362 auto wk_begin = working_kernel.data();
363 auto wk_itr = wk_begin;
364 std::vector<uint16_t*> pixel_raws(scale);
367 if (scale == 2 || scale == 3)
373 for (
size_t i = 0;
i < pixel_raws.size();
i++)
374 pixel_raws[
i] = block_start + (width_in*
i);
376 for (
size_t i = 0, chunk_offset = 0; i <
_real_width; i++)
382 p = pixel_raws[
n] + chunk_offset;
386 *wk_itr++ = *(
p +
m);
391 auto ks = (int)(wk_itr - wk_begin);
393 *frame_data_out++ = 0;
399 *frame_data_out++ = working_kernel[0];
402 *frame_data_out++ =
PIX_MIN(working_kernel[0], working_kernel[1]);
405 *frame_data_out++ = opt_med3<uint16_t>(working_kernel.data());
408 *frame_data_out++ = opt_med4<uint16_t>(working_kernel.data());
411 *frame_data_out++ = opt_med5<uint16_t>(working_kernel.data());
414 *frame_data_out++ = opt_med6<uint16_t>(working_kernel.data());
417 *frame_data_out++ = opt_med7<uint16_t>(working_kernel.data());
420 *frame_data_out++ = opt_med8<uint16_t>(working_kernel.data());
423 *frame_data_out++ = opt_med9<uint16_t>(working_kernel.data());
428 chunk_offset +=
scale;
433 *frame_data_out++ = 0;
436 block_start += width_in *
scale;
445 for (
size_t i = 0;
i < pixel_raws.size();
i++)
446 pixel_raws[
i] = block_start + (width_in*
i);
448 for (
size_t i = 0, chunk_offset = 0; i <
_real_width; i++)
456 p = pixel_raws[
n] + chunk_offset;
467 *frame_data_out++ = (counter == 0 ? 0 : sum /
counter);
468 chunk_offset +=
scale;
473 *frame_data_out++ = 0;
476 block_start += width_in *
scale;
484 *frame_data_out++ = 0;
489 size_t width_in,
size_t height_in,
size_t scale)
492 auto patch_size = scale *
scale;
502 auto w_2 = width_in >> 1;
505 auto s2 = scale >> 1;
506 bool odd = (scale & 1);
509 for (
int i = 0;
i < rw_2; ++
i)
511 p = from + scale * (
j * w_2 +
i) * 4;
520 *q++ = (
uint8_t)(sum / patch_size);
522 p = from + scale * (
j * w_2 +
i) * 4 + 1;
526 for (
size_t m = 0;
m < s2; ++
m)
534 *q++ = (
uint8_t)(sum / patch_size);
536 p = from + scale * (
j * w_2 +
i) * 4 + s2 * 4 + (odd ? 2 : 0);
545 *q++ = (
uint8_t)(sum / patch_size);
547 p = from + scale * (
j * w_2 +
i) * 4 + 3;
551 for (
size_t m = 0;
m < s2; ++
m)
559 *q++ = (
uint8_t)(sum / patch_size);
562 for (
int i = rw_2;
i < pw_2; ++
i)
588 auto w_2 = width_in >> 1;
591 auto s2 = scale >> 1;
592 bool odd = (scale & 1);
595 for (
int i = 0;
i < rw_2; ++
i)
597 p = from + scale * (
j * w_2 +
i) * 4;
601 for (
size_t m = 0;
m < s2; ++
m)
609 *q++ = (
uint8_t)(sum / patch_size);
611 p = from + scale * (
j * w_2 +
i) * 4 + 1;
620 *q++ = (
uint8_t)(sum / patch_size);
622 p = from + scale * (
j * w_2 +
i) * 4 + 2;
626 for (
size_t m = 0;
m < s2; ++
m)
634 *q++ = (
uint8_t)(sum / patch_size);
636 p = from + scale * (
j * w_2 +
i) * 4 + s2 * 4 + (odd ? 3 : 1);
645 *q++ = (
uint8_t)(sum / patch_size);
648 for (
int i = rw_2;
i < pw_2; ++
i)
679 for (
int k = 0; k < 3; ++k)
681 p = from + scale * (
j * width_in +
i) * 3 + k;
691 *q++ = (
uint8_t)(sum / patch_size);
726 for (
int k = 0; k < 4; ++k)
728 p = from + scale * (
j * width_in +
i) * 4 + k;
738 *q++ = (
uint8_t)(sum / patch_size);
774 p = from + scale * (
j * width_in +
i);
784 *q++ = (
uint8_t)(sum / patch_size);
809 p = from + scale * (
j * width_in +
i);
819 *q++ = (
uint16_t)(sum / patch_size);
pixelvalue opt_med7(pixelvalue *p)
static const textual_icon lock
pixelvalue opt_med9(pixelvalue *p)
pixelvalue opt_med8(pixelvalue *p)
GLenum GLenum GLenum GLenum GLenum scale
stream_profile get_profile() const
pixelvalue opt_med4(pixelvalue *p)
rs2::frame prepare_target_frame(const rs2::frame &f, const rs2::frame_source &source, rs2_extension tgt_type)
const uint8_t decimation_min_val
pixelvalue opt_med5(pixelvalue *p)
rs2::stream_profile _target_stream_profile
void register_option(rs2_option id, std::shared_ptr< option > option)
frame allocate_video_frame(const stream_profile &profile, const frame &original, int new_bpp=0, int new_width=0, int new_height=0, int new_stride=0, rs2_extension frame_type=RS2_EXTENSION_VIDEO_FRAME) const
void decimate_depth(const uint16_t *frame_data_in, uint16_t *frame_data_out, size_t width_in, size_t height_in, size_t scale)
GLint GLint GLsizei GLint GLenum format
rs2_format
A stream's format identifies how binary data is encoded within a frame.
const uint8_t decimation_max_val
void decimate_others(rs2_format format, const void *frame_data_in, void *frame_data_out, size_t width_in, size_t height_in, size_t scale)
stream_filter _stream_filter
rs2_stream
Streams are different types of data provided by RealSense devices.
void update_output_profile(const rs2::frame &f)
const uint8_t decimation_default_val
librealsense::stream_profile_interface * profile
rs2_format format() const
uint8_t _decimation_factor
pixelvalue opt_med3(pixelvalue *p)
GLdouble GLdouble GLdouble q
rs2_extension
Specifies advanced interfaces (capabilities) objects may implement.
pixelvalue opt_med6(pixelvalue *p)
rs2::stream_profile _source_stream_profile
const rs2_stream_profile * get() const
std::map< std::tuple< const rs2_stream_profile *, uint8_t >, rs2::stream_profile > _registered_profiles
GLsizei GLsizei GLchar * source
rs2::frame process_frame(const rs2::frame_source &source, const rs2::frame &f) override
const uint8_t decimation_step
rs2_stream stream_type() const
stream_profile clone(rs2_stream type, int index, rs2_format format) const
std::string to_string(T value)