decimation-filter.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2017 Intel Corporation. All Rights Reserved.
3 
4 #include "../include/librealsense2/hpp/rs_sensor.hpp"
5 #include "../include/librealsense2/hpp/rs_processing.hpp"
6 
7 #include <numeric>
8 #include <cmath>
9 #include "environment.h"
10 #include "option.h"
11 #include "context.h"
12 #include "core/video.h"
13 #include "proc/synthetic-stream.h"
14 #include "proc/decimation-filter.h"
15 
16 
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)
21 
22 namespace librealsense
23 {
24  /*----------------------------------------------------------------------------
25  Function : opt_med3()
26  In : pointer to array of 3 pixel values
27  Out : a pixelvalue
28  Job : optimized search of the median of 3 pixel values
29  Notice : found on sci.image.processing
30  cannot go faster unless assumptions are made
31  on the nature of the input signal.
32  ---------------------------------------------------------------------------*/
33  template <class pixelvalue>
34  inline pixelvalue opt_med3(pixelvalue * p)
35  {
36  PIX_SORT(p[0], p[1]);
37  PIX_SORT(p[1], p[2]);
38  PIX_SORT(p[0], p[1]);
39  return p[1];
40  }
41 
42  /*
43  ** opt_med4()
44  hacked version
45  **/
46  template <class pixelvalue>
47  inline pixelvalue opt_med4(pixelvalue * p)
48  {
49  PIX_SORT(p[0], p[1]);
50  PIX_SORT(p[2], p[3]);
51  PIX_SORT(p[0], p[2]);
52  PIX_SORT(p[1], p[3]);
53  return PIX_MIN(p[1], p[2]);
54  }
55 
56  /*----------------------------------------------------------------------------
57  Function : opt_med5()
58  In : pointer to array of 5 pixel values
59  Out : a pixelvalue
60  Job : optimized search of the median of 5 pixel values
61  Notice : found on sci.image.processing
62  cannot go faster unless assumptions are made
63  on the nature of the input signal.
64  ---------------------------------------------------------------------------*/
65  template <class pixelvalue>
66  inline pixelvalue opt_med5(pixelvalue * p)
67  {
68  PIX_SORT(p[0], p[1]);
69  PIX_SORT(p[3], p[4]);
70  p[3] = PIX_MAX(p[0], p[3]);
71  p[1] = PIX_MIN(p[1], p[4]);
72  PIX_SORT(p[1], p[2]);
73  p[2] = PIX_MIN(p[2], p[3]);
74  return PIX_MAX(p[1], p[2]);
75  }
76 
77  /*----------------------------------------------------------------------------
78  Function : opt_med6()
79  In : pointer to array of 6 pixel values
80  Out : a pixelvalue
81  Job : optimized search of the median of 6 pixel values
82  Notice : from Christoph_John@gmx.de
83  based on a selection network which was proposed in
84  "FAST, EFFICIENT MEDIAN FILTERS WITH EVEN LENGTH WINDOWS"
85  J.P. HAVLICEK, K.A. SAKADY, G.R.KATZ
86  If you need larger even length kernels check the paper
87  ---------------------------------------------------------------------------*/
88  template <class pixelvalue>
89  inline pixelvalue opt_med6(pixelvalue * p)
90  {
91  PIX_SORT(p[1], p[2]);
92  PIX_SORT(p[3], p[4]);
93  PIX_SORT(p[0], p[1]);
94  PIX_SORT(p[2], p[3]);
95  PIX_SORT(p[4], p[5]);
96  PIX_SORT(p[1], p[2]);
97  PIX_SORT(p[3], p[4]);
98  PIX_SORT(p[0], p[1]);
99  PIX_SORT(p[2], p[3]);
100  p[4] = PIX_MIN(p[4], p[5]);
101  p[2] = PIX_MAX(p[1], p[2]);
102  p[3] = PIX_MIN(p[3], p[4]);
103  return PIX_MIN(p[2], p[3]);
104  }
105 
106  /*----------------------------------------------------------------------------
107  Function : opt_med7()
108  In : pointer to array of 7 pixel values
109  Out : a pixelvalue
110  Job : optimized search of the median of 7 pixel values
111  Notice : found on sci.image.processing
112  cannot go faster unless assumptions are made
113  on the nature of the input signal.
114  ---------------------------------------------------------------------------*/
115  template <class pixelvalue>
116  inline pixelvalue opt_med7(pixelvalue * p)
117  {
118  PIX_SORT(p[0], p[5]);
119  PIX_SORT(p[0], p[3]);
120  PIX_SORT(p[1], p[6]);
121  PIX_SORT(p[2], p[4]);
122  PIX_SORT(p[0], p[1]);
123  PIX_SORT(p[3], p[5]);
124  PIX_SORT(p[2], p[6]);
125  p[3] = PIX_MAX(p[2], p[3]);
126  p[3] = PIX_MIN(p[3], p[6]);
127  p[4] = PIX_MIN(p[4], p[5]);
128  PIX_SORT(p[1], p[4]);
129  p[3] = PIX_MAX(p[1], p[3]);
130  return PIX_MIN(p[3], p[4]);
131  }
132 
133  /*----------------------------------------------------------------------------
134  Function : opt_med9()
135  Hacked version of opt_med9()
136  */
137  template <class pixelvalue>
138  inline pixelvalue opt_med8(pixelvalue * p)
139  {
140  PIX_SORT(p[0], p[1]);
141  PIX_SORT(p[3], p[4]);
142  PIX_SORT(p[6], p[7]);
143  PIX_SORT(p[2], p[3]);
144  PIX_SORT(p[5], p[6]);
145  PIX_SORT(p[3], p[4]);
146  PIX_SORT(p[6], p[7]);
147  p[4] = PIX_MIN(p[4], p[7]);
148  PIX_SORT(p[3], p[6]);
149  p[5] = PIX_MAX(p[2], p[5]);
150  p[3] = PIX_MAX(p[0], p[3]);
151  p[1] = PIX_MIN(p[1], p[4]);
152  p[3] = PIX_MIN(p[3], p[6]);
153  PIX_SORT(p[3], p[1]);
154  p[3] = PIX_MAX(p[5], p[3]);
155  return PIX_MIN(p[3], p[1]);
156  }
157 
158  /*----------------------------------------------------------------------------
159  Function : opt_med9()
160  In : pointer to an array of 9 pixelvalues
161  Out : a pixelvalue
162  Job : optimized search of the median of 9 pixelvalues
163  Notice : in theory, cannot go faster without assumptions on the
164  signal.
165  Formula from:
166  XILINX XCELL magazine, vol. 23 by John L. Smith
167 
168  The input array is modified in the process
169  The result array is guaranteed to contain the median
170  value
171  in middle position, but other elements are NOT sorted.
172  ---------------------------------------------------------------------------*/
173  template <class pixelvalue>
174  inline pixelvalue opt_med9(pixelvalue * p)
175  {
176  PIX_SORT(p[1], p[2]);
177  PIX_SORT(p[4], p[5]);
178  PIX_SORT(p[7], p[8]);
179  PIX_SORT(p[0], p[1]);
180  PIX_SORT(p[3], p[4]);
181  PIX_SORT(p[6], p[7]);
182  PIX_SORT(p[1], p[2]);
183  PIX_SORT(p[4], p[5]);
184  PIX_SORT(p[7], p[8]);
185  p[3] = PIX_MAX(p[0], p[3]);
186  p[5] = PIX_MIN(p[5], p[8]);
187  PIX_SORT(p[4], p[7]);
188  p[6] = PIX_MAX(p[3], p[6]);
189  p[4] = PIX_MAX(p[1], p[4]);
190  p[2] = PIX_MIN(p[2], p[5]);
191  p[4] = PIX_MIN(p[4], p[7]);
192  PIX_SORT(p[4], p[2]);
193  p[4] = PIX_MAX(p[6], p[4]);
194  return PIX_MIN(p[4], p[2]);
195  }
196 
198  const uint8_t decimation_max_val = 8; // Decimation levels according to the reference design
200  const uint8_t decimation_step = 1; // Linear decimation
201 
203  stream_filter_processing_block("Decimation Filter"),
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),
208  _real_width(),
209  _real_height(0),
210  _padded_width(0),
211  _padded_height(0),
212  _recalc_profile(false),
213  _options_changed(false)
214  {
217 
218  auto decimation_control = std::make_shared<ptr_option<uint8_t>>(
223  &_control_val, "Decimation scale");
224  decimation_control->on_set([this, decimation_control](float val)
225  {
226  std::lock_guard<std::mutex> lock(_mutex);
227 
228  if (!decimation_control->is_valid(val))
230  << "Unsupported decimation scale " << val << " is out of range.");
231 
232  // Linear decimation factor
233  if (_control_val != _decimation_factor)
234  {
237  _options_changed = true;
238  }
239  });
240 
241  register_option(RS2_OPTION_FILTER_MAGNITUDE, decimation_control);
242  }
243 
245  {
247 
248  auto src = f.as<rs2::video_frame>();
250  rs2_format format = profile.format();
251  rs2_stream type = profile.stream_type();
252 
253  rs2_extension tgt_type;
254  if (type == RS2_STREAM_COLOR || type == RS2_STREAM_INFRARED)
255  tgt_type = RS2_EXTENSION_VIDEO_FRAME;
256  else
258 
259  if (auto tgt = prepare_target_frame(f, source, tgt_type))
260  {
261  if (format == RS2_FORMAT_Z16)
262  {
263  decimate_depth(static_cast<const uint16_t*>(src.get_data()),
264  static_cast<uint16_t*>(const_cast<void*>(tgt.get_data())),
265  src.get_width(), src.get_height(), this->_patch_size);
266  }
267  else
268  {
269  decimate_others(format, src.get_data(),
270  const_cast<void*>(tgt.get_data()),
271  src.get_width(), src.get_height(), this->_patch_size);
272  }
273  return tgt;
274  }
275  return f;
276  }
277 
279  {
281  {
282  _options_changed = false;
284  const auto pf = _registered_profiles.find(std::make_tuple(_source_stream_profile.get(), _decimation_factor));
285  if (_registered_profiles.end() != pf)
286  {
287  _target_stream_profile = pf->second;
288  auto tgt_vspi = dynamic_cast<video_stream_profile_interface*>(_target_stream_profile.get()->profile);
289  auto f_pf = dynamic_cast<video_stream_profile_interface*>(_source_stream_profile.get()->profile);
290  rs2_intrinsics tgt_intrin = tgt_vspi->get_intrinsics();
291 
292  // Update real/padded output frame size based on retrieved input properties
293  _real_width = f_pf->get_width() / _patch_size;
294  _real_height = f_pf->get_height() / _patch_size;
295  _padded_width = tgt_intrin.width;
296  _padded_height = tgt_intrin.height;
297  }
298  else
299  {
300  _recalc_profile = true;
301  }
302  }
303 
304  // Buld a new target profile for every system/filter change
305  if (_recalc_profile)
306  {
308 
310  auto src_vspi = dynamic_cast<video_stream_profile_interface*>(_source_stream_profile.get()->profile);
311  auto tgt_vspi = dynamic_cast<video_stream_profile_interface*>(tmp_profile.get()->profile);
312  rs2_intrinsics src_intrin = src_vspi->get_intrinsics();
313  rs2_intrinsics tgt_intrin = tgt_vspi->get_intrinsics();
314 
315  // recalculate real/padded output frame size based on new input porperties
316  _real_width = src_vspi->get_width() / _patch_size;
317  _real_height = src_vspi->get_height() / _patch_size;
318 
319  // The resulted frame dimension will be dividible by 4;
321  _padded_width /= 4;
322  _padded_width *= 4;
323 
325  _padded_height /= 4;
326  _padded_height *= 4;
327 
328  tgt_intrin.width = _padded_width;
329  tgt_intrin.height = _padded_height;
330  tgt_intrin.fx = src_intrin.fx / _patch_size;
331  tgt_intrin.fy = src_intrin.fy / _patch_size;
332  tgt_intrin.ppx = src_intrin.ppx / _patch_size;
333  tgt_intrin.ppy = src_intrin.ppy / _patch_size;
334 
335  tgt_vspi->set_intrinsics([tgt_intrin]() { return tgt_intrin; });
336  tgt_vspi->set_dims(tgt_intrin.width, tgt_intrin.height);
337 
339 
340  _recalc_profile = false;
341  }
342  }
343 
345  {
346  auto vf = f.as<rs2::video_frame>();
347  auto ret = source.allocate_video_frame(_target_stream_profile, f,
348  vf.get_bytes_per_pixel(),
351  _padded_width*vf.get_bytes_per_pixel(),
352  tgt_type);
353 
354  return ret;
355  }
356 
357  void decimation_filter::decimate_depth(const uint16_t * frame_data_in, uint16_t * frame_data_out,
358  size_t width_in, size_t height_in, size_t scale)
359  {
360  // Use median filtering
361  std::vector<uint16_t> working_kernel(_kernel_size);
362  auto wk_begin = working_kernel.data();
363  auto wk_itr = wk_begin;
364  std::vector<uint16_t*> pixel_raws(scale);
365  uint16_t* block_start = const_cast<uint16_t*>(frame_data_in);
366 
367  if (scale == 2 || scale == 3)
368  {
369  for (int j = 0; j < _real_height; j++)
370  {
371  uint16_t *p{};
372  // Mark the beginning of each of the N lines that the filter will run upon
373  for (size_t i = 0; i < pixel_raws.size(); i++)
374  pixel_raws[i] = block_start + (width_in*i);
375 
376  for (size_t i = 0, chunk_offset = 0; i < _real_width; i++)
377  {
378  wk_itr = wk_begin;
379  // extract data the kernel to process
380  for (size_t n = 0; n < scale; ++n)
381  {
382  p = pixel_raws[n] + chunk_offset;
383  for (size_t m = 0; m < scale; ++m)
384  {
385  if (*(p + m))
386  *wk_itr++ = *(p + m);
387  }
388  }
389 
390  // For even-size kernels pick the member one below the middle
391  auto ks = (int)(wk_itr - wk_begin);
392  if (ks == 0)
393  *frame_data_out++ = 0;
394  else
395  {
396  switch (ks)
397  {
398  case 1:
399  *frame_data_out++ = working_kernel[0];
400  break;
401  case 2:
402  *frame_data_out++ = PIX_MIN(working_kernel[0], working_kernel[1]);
403  break;
404  case 3:
405  *frame_data_out++ = opt_med3<uint16_t>(working_kernel.data());
406  break;
407  case 4:
408  *frame_data_out++ = opt_med4<uint16_t>(working_kernel.data());
409  break;
410  case 5:
411  *frame_data_out++ = opt_med5<uint16_t>(working_kernel.data());
412  break;
413  case 6:
414  *frame_data_out++ = opt_med6<uint16_t>(working_kernel.data());
415  break;
416  case 7:
417  *frame_data_out++ = opt_med7<uint16_t>(working_kernel.data());
418  break;
419  case 8:
420  *frame_data_out++ = opt_med8<uint16_t>(working_kernel.data());
421  break;
422  case 9:
423  *frame_data_out++ = opt_med9<uint16_t>(working_kernel.data());
424  break;
425  }
426  }
427 
428  chunk_offset += scale;
429  }
430 
431  // Fill-in the padded colums with zeros
432  for (int j = _real_width; j < _padded_width; j++)
433  *frame_data_out++ = 0;
434 
435  // Skip N lines to the beginnig of the next processing segment
436  block_start += width_in * scale;
437  }
438  }
439  else
440  {
441  for (int j = 0; j < _real_height; j++)
442  {
443  uint16_t *p{};
444  // Mark the beginning of each of the N lines that the filter will run upon
445  for (size_t i = 0; i < pixel_raws.size(); i++)
446  pixel_raws[i] = block_start + (width_in*i);
447 
448  for (size_t i = 0, chunk_offset = 0; i < _real_width; i++)
449  {
450  int sum = 0;
451  int counter = 0;
452 
453  // extract data the kernel to process
454  for (size_t n = 0; n < scale; ++n)
455  {
456  p = pixel_raws[n] + chunk_offset;
457  for (size_t m = 0; m < scale; ++m)
458  {
459  if (*(p + m))
460  {
461  sum += p[m];
462  ++counter;
463  }
464  }
465  }
466 
467  *frame_data_out++ = (counter == 0 ? 0 : sum / counter);
468  chunk_offset += scale;
469  }
470 
471  // Fill-in the padded colums with zeros
472  for (int j = _real_width; j < _padded_width; j++)
473  *frame_data_out++ = 0;
474 
475  // Skip N lines to the beginnig of the next processing segment
476  block_start += width_in * scale;
477  }
478  }
479 
480  // Fill-in the padded rows with zeros
481  for (auto v = _real_height; v < _padded_height; ++v)
482  {
483  for (auto u = 0; u < _padded_width; ++u)
484  *frame_data_out++ = 0;
485  }
486  }
487 
488  void decimation_filter::decimate_others(rs2_format format, const void * frame_data_in, void * frame_data_out,
489  size_t width_in, size_t height_in, size_t scale)
490  {
491  int sum = 0;
492  auto patch_size = scale * scale;
493 
494  switch (format)
495  {
496  case RS2_FORMAT_YUYV:
497  {
498  uint8_t* from = (uint8_t*)frame_data_in;
499  uint8_t* p = nullptr;
500  uint8_t* q = (uint8_t*)frame_data_out;
501 
502  auto w_2 = width_in >> 1;
503  auto rw_2 = _real_width >> 1;
504  auto pw_2 = _padded_width >> 1;
505  auto s2 = scale >> 1;
506  bool odd = (scale & 1);
507  for (int j = 0; j < _real_height; ++j)
508  {
509  for (int i = 0; i < rw_2; ++i)
510  {
511  p = from + scale * (j * w_2 + i) * 4;
512  sum = 0;
513  for (size_t n = 0; n < scale; ++n)
514  {
515  for (size_t m = 0; m < scale; ++m)
516  sum += p[m * 2];
517 
518  p += w_2 * 4;
519  }
520  *q++ = (uint8_t)(sum / patch_size);
521 
522  p = from + scale * (j * w_2 + i) * 4 + 1;
523  sum = 0;
524  for (size_t n = 0; n < scale; ++n)
525  {
526  for (size_t m = 0; m < s2; ++m)
527  sum += 2 * p[m * 4];
528 
529  if (odd)
530  sum += p[s2 * 4];
531 
532  p += w_2 * 4;
533  }
534  *q++ = (uint8_t)(sum / patch_size);
535 
536  p = from + scale * (j * w_2 + i) * 4 + s2 * 4 + (odd ? 2 : 0);
537  sum = 0;
538  for (size_t n = 0; n < scale; ++n)
539  {
540  for (size_t m = 0; m < scale; ++m)
541  sum += p[m * 2];
542 
543  p += w_2 * 4;
544  }
545  *q++ = (uint8_t)(sum / patch_size);
546 
547  p = from + scale * (j * w_2 + i) * 4 + 3;
548  sum = 0;
549  for (size_t n = 0; n < scale; ++n)
550  {
551  for (size_t m = 0; m < s2; ++m)
552  sum += 2 * p[m * 4];
553 
554  if (odd)
555  sum += p[s2 * 4];
556 
557  p += w_2 * 4;
558  }
559  *q++ = (uint8_t)(sum / patch_size);
560  }
561 
562  for (int i = rw_2; i < pw_2; ++i)
563  {
564  *q++ = 0;
565  *q++ = 0;
566  *q++ = 0;
567  *q++ = 0;
568  }
569  }
570 
571  for (int j = _real_height; j < _padded_height; ++j)
572  {
573  for (int i = 0; i < _padded_width; ++i)
574  {
575  *q++ = 0;
576  *q++ = 0;
577  }
578  }
579  }
580  break;
581 
582  case RS2_FORMAT_UYVY:
583  {
584  uint8_t* from = (uint8_t*)frame_data_in;
585  uint8_t* p = nullptr;
586  uint8_t* q = (uint8_t*)frame_data_out;
587 
588  auto w_2 = width_in >> 1;
589  auto rw_2 = _real_width >> 1;
590  auto pw_2 = _padded_width >> 1;
591  auto s2 = scale >> 1;
592  bool odd = (scale & 1);
593  for (int j = 0; j < _real_height; ++j)
594  {
595  for (int i = 0; i < rw_2; ++i)
596  {
597  p = from + scale * (j * w_2 + i) * 4;
598  sum = 0;
599  for (size_t n = 0; n < scale; ++n)
600  {
601  for (size_t m = 0; m < s2; ++m)
602  sum += 2 * p[m * 4];
603 
604  if (odd)
605  sum += p[s2 * 4];
606 
607  p += w_2 * 4;
608  }
609  *q++ = (uint8_t)(sum / patch_size);
610 
611  p = from + scale * (j * w_2 + i) * 4 + 1;
612  sum = 0;
613  for (size_t n = 0; n < scale; ++n)
614  {
615  for (size_t m = 0; m < scale; ++m)
616  sum += p[m * 2];
617 
618  p += w_2 * 4;
619  }
620  *q++ = (uint8_t)(sum / patch_size);
621 
622  p = from + scale * (j * w_2 + i) * 4 + 2;
623  sum = 0;
624  for (size_t n = 0; n < scale; ++n)
625  {
626  for (size_t m = 0; m < s2; ++m)
627  sum += 2 * p[m * 4];
628 
629  if (odd)
630  sum += p[s2 * 4];
631 
632  p += w_2 * 4;
633  }
634  *q++ = (uint8_t)(sum / patch_size);
635 
636  p = from + scale * (j * w_2 + i) * 4 + s2 * 4 + (odd ? 3 : 1);
637  sum = 0;
638  for (size_t n = 0; n < scale; ++n)
639  {
640  for (size_t m = 0; m < scale; ++m)
641  sum += p[m * 2];
642 
643  p += w_2 * 4;
644  }
645  *q++ = (uint8_t)(sum / patch_size);
646  }
647 
648  for (int i = rw_2; i < pw_2; ++i)
649  {
650  *q++ = 0;
651  *q++ = 0;
652  *q++ = 0;
653  *q++ = 0;
654  }
655  }
656 
657  for (int j = _real_height; j < _padded_height; ++j)
658  {
659  for (int i = 0; i < _padded_width; ++i)
660  {
661  *q++ = 0;
662  *q++ = 0;
663  }
664  }
665  }
666  break;
667 
668  case RS2_FORMAT_RGB8:
669  case RS2_FORMAT_BGR8:
670  {
671  uint8_t* from = (uint8_t*)frame_data_in;
672  uint8_t* p = nullptr;
673  uint8_t* q = (uint8_t*)frame_data_out;;
674 
675  for (int j = 0; j < _real_height; ++j)
676  {
677  for (int i = 0; i < _real_width; ++i)
678  {
679  for (int k = 0; k < 3; ++k)
680  {
681  p = from + scale * (j * width_in + i) * 3 + k;
682  sum = 0;
683  for (size_t n = 0; n < scale; ++n)
684  {
685  for (size_t m = 0; m < scale; ++m)
686  sum += p[m * 3];
687 
688  p += width_in * 3;
689  }
690 
691  *q++ = (uint8_t)(sum / patch_size);
692  }
693  }
694 
695  for (int i = _real_width; i < _padded_width; ++i)
696  {
697  *q++ = 0;
698  *q++ = 0;
699  *q++ = 0;
700  }
701  }
702 
703  for (int j = _real_height; j < _padded_height; ++j)
704  {
705  for (int i = 0; i < _padded_width; ++i)
706  {
707  *q++ = 0;
708  *q++ = 0;
709  *q++ = 0;
710  }
711  }
712  }
713  break;
714 
715  case RS2_FORMAT_RGBA8:
716  case RS2_FORMAT_BGRA8:
717  {
718  uint8_t* from = (uint8_t*)frame_data_in;
719  uint8_t* p = nullptr;
720  uint8_t* q = (uint8_t*)frame_data_out;
721 
722  for (int j = 0; j < _real_height; ++j)
723  {
724  for (int i = 0; i < _real_width; ++i)
725  {
726  for (int k = 0; k < 4; ++k)
727  {
728  p = from + scale * (j * width_in + i) * 4 + k;
729  sum = 0;
730  for (size_t n = 0; n < scale; ++n)
731  {
732  for (size_t m = 0; m < scale; ++m)
733  sum += p[m * 4];
734 
735  p += width_in * 4;
736  }
737 
738  *q++ = (uint8_t)(sum / patch_size);
739  }
740  }
741 
742  for (int i = _real_width; i < _padded_width; ++i)
743  {
744  *q++ = 0;
745  *q++ = 0;
746  *q++ = 0;
747  *q++ = 0;
748  }
749  }
750 
751  for (int j = _real_height; j < _padded_height; ++j)
752  {
753  for (int i = 0; i < _padded_width; ++i)
754  {
755  *q++ = 0;
756  *q++ = 0;
757  *q++ = 0;
758  *q++ = 0;
759  }
760  }
761  }
762  break;
763 
764  case RS2_FORMAT_Y8:
765  {
766  uint8_t* from = (uint8_t*)frame_data_in;
767  uint8_t* p = nullptr;
768  uint8_t* q = (uint8_t*)frame_data_out;
769 
770  for (int j = 0; j < _real_height; ++j)
771  {
772  for (int i = 0; i < _real_width; ++i)
773  {
774  p = from + scale * (j * width_in + i);
775  sum = 0;
776  for (size_t n = 0; n < scale; ++n)
777  {
778  for (size_t m = 0; m < scale; ++m)
779  sum += p[m];
780 
781  p += width_in;
782  }
783 
784  *q++ = (uint8_t)(sum / patch_size);
785  }
786 
787  for (int i = _real_width; i < _padded_width; ++i)
788  *q++ = 0;
789  }
790 
791  for (int j = _real_height; j < _padded_height; ++j)
792  {
793  for (int i = 0; i < _padded_width; ++i)
794  *q++ = 0;
795  }
796  }
797  break;
798 
799  case RS2_FORMAT_Y16:
800  {
801  uint16_t* from = (uint16_t*)frame_data_in;
802  uint16_t* p = nullptr;
803  uint16_t* q = (uint16_t*)frame_data_out;
804 
805  for (int j = 0; j < _real_height; ++j)
806  {
807  for (int i = 0; i < _real_width; ++i)
808  {
809  p = from + scale * (j * width_in + i);
810  sum = 0;
811  for (size_t n = 0; n < scale; ++n)
812  {
813  for (size_t m = 0; m < scale; ++m)
814  sum += p[m];
815 
816  p += width_in;
817  }
818 
819  *q++ = (uint16_t)(sum / patch_size);
820  }
821 
822  for (int i = _real_width; i < _padded_width; ++i)
823  *q++ = 0;
824  }
825 
826  for (int j = _real_height; j < _padded_height; ++j)
827  {
828  for (int i = 0; i < _padded_width; ++i)
829  *q++ = 0;
830  }
831  }
832  break;
833 
834  default:
835  break;
836  }
837  }
838 }
839 
pixelvalue opt_med7(pixelvalue *p)
static const textual_icon lock
Definition: model-views.h:218
pixelvalue opt_med9(pixelvalue *p)
pixelvalue opt_med8(pixelvalue *p)
GLfloat GLfloat p
Definition: glext.h:12687
const GLfloat * m
Definition: glext.h:6814
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:10806
stream_profile get_profile() const
Definition: rs_frame.hpp:557
pixelvalue opt_med4(pixelvalue *p)
rs2::frame prepare_target_frame(const rs2::frame &f, const rs2::frame_source &source, rs2_extension tgt_type)
#define PIX_MIN(a, b)
const uint8_t decimation_min_val
unsigned short uint16_t
Definition: stdint.h:79
GLenum src
Definition: glext.h:1751
GLdouble n
Definition: glext.h:1966
unsigned char uint8_t
Definition: stdint.h:78
pixelvalue opt_med5(pixelvalue *p)
rs2::stream_profile _target_stream_profile
void register_option(rs2_option id, std::shared_ptr< option > option)
Definition: options.h:86
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
GLuint GLfloat * val
GLdouble f
bool is() const
Definition: rs_frame.hpp:570
GLuint counter
Definition: glext.h:5684
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
GLint j
rs2_format
A stream&#39;s format identifies how binary data is encoded within a frame.
Definition: rs_sensor.h:59
int stream_index() const
Definition: rs_frame.hpp:34
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)
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:42
void update_output_profile(const rs2::frame &f)
const uint8_t decimation_default_val
librealsense::stream_profile_interface * profile
Definition: context.h:34
rs2_format format() const
Definition: rs_frame.hpp:44
pixelvalue opt_med3(pixelvalue *p)
GLdouble GLdouble GLdouble q
rs2_extension
Specifies advanced interfaces (capabilities) objects may implement.
Definition: rs_types.h:166
pixelvalue opt_med6(pixelvalue *p)
rs2::stream_profile _source_stream_profile
GLenum type
const rs2_stream_profile * get() const
Definition: rs_frame.hpp:137
std::map< std::tuple< const rs2_stream_profile *, uint8_t >, rs2::stream_profile > _registered_profiles
Video stream intrinsics.
Definition: rs_types.h:58
GLsizei GLsizei GLchar * source
rs2::frame process_frame(const rs2::frame_source &source, const rs2::frame &f) override
int i
const uint8_t decimation_step
rs2_stream stream_type() const
Definition: rs_frame.hpp:39
GLdouble v
#define PIX_SORT(a, b)
stream_profile clone(rs2_stream type, int index, rs2_format format) const
Definition: rs_frame.hpp:63
#define PIX_MAX(a, b)
T as() const
Definition: rs_frame.hpp:580
std::string to_string(T value)


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:12