depth-formats-converter.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2019 Intel Corporation. All Rights Reserved.
3 
5 
6 #include "stream.h"
7 
8 #ifdef RS2_USE_CUDA
9 #include "cuda/cuda-conversion.cuh"
10 #endif
11 
12 namespace librealsense
13 {
14  void unpack_z16_y8_from_sr300_inzi(byte * const dest[], const byte * source, int width, int height, int actual_size)
15  {
16  auto count = width * height;
17  auto in = reinterpret_cast<const uint16_t*>(source);
18  auto out_ir = reinterpret_cast<uint8_t *>(dest[1]);
19 #ifdef RS2_USE_CUDA
20  rscuda::unpack_z16_y8_from_sr300_inzi_cuda(out_ir, in, count);
21 #else
22  for (int i = 0; i < count; ++i) *out_ir++ = *in++ >> 2;
23 #endif
24  librealsense::copy(dest[0], in, count * 2);
25  }
26 
27  void unpack_z16_y16_from_sr300_inzi(byte * const dest[], const byte * source, int width, int height, int actual_size)
28  {
29  auto count = width * height;
30  auto in = reinterpret_cast<const uint16_t*>(source);
31  auto out_ir = reinterpret_cast<uint16_t*>(dest[1]);
32 #ifdef RS2_USE_CUDA
33  rscuda::unpack_z16_y16_from_sr300_inzi_cuda(out_ir, in, count);
34 #else
35  for (int i = 0; i < count; ++i) *out_ir++ = *in++ << 6;
36 #endif
37  librealsense::copy(dest[0], in, count * 2);
38  }
39 
40  void unpack_inzi(rs2_format dst_ir_format, byte * const d[], const byte * s, int width, int height, int actual_size)
41  {
42  switch (dst_ir_format)
43  {
44  case RS2_FORMAT_Y8:
45  unpack_z16_y8_from_sr300_inzi(d, s, width, height, actual_size);
46  break;
47  case RS2_FORMAT_Y16:
48  unpack_z16_y16_from_sr300_inzi(d, s, width, height, actual_size);
49  break;
50  default:
51  LOG_ERROR("Unsupported format for INZI conversion.");
52  break;
53  }
54  }
55 
56  template<class SOURCE, class UNPACK> void unpack_pixels(byte * const dest[], int count, const SOURCE * source, UNPACK unpack, int actual_size)
57  {
58  auto out = reinterpret_cast<decltype(unpack(SOURCE())) *>(dest[0]);
59  for (int i = 0; i < count; ++i) *out++ = unpack(*source++);
60  }
61 
62  void unpack_y16_from_y16_10(byte * const d[], const byte * s, int width, int height, int actual_size) { unpack_pixels(d, width * height, reinterpret_cast<const uint16_t*>(s), [](uint16_t pixel) -> uint16_t { return pixel << 6; }, actual_size); }
63  void unpack_y8_from_y16_10(byte * const d[], const byte * s, int width, int height, int actual_size) { unpack_pixels(d, width * height, reinterpret_cast<const uint16_t*>(s), [](uint16_t pixel) -> uint8_t { return pixel >> 2; }, actual_size); }
64 
65  void unpack_invi(rs2_format dst_format, byte * const d[], const byte * s, int width, int height, int actual_size)
66  {
67  switch (dst_format)
68  {
69  case RS2_FORMAT_Y8:
70  unpack_y8_from_y16_10(d, s, width, height, actual_size);
71  break;
72  case RS2_FORMAT_Y16:
73  unpack_y16_from_y16_10(d, s, width, height, actual_size);
74  break;
75  default:
76  LOG_ERROR("Unsupported format for INVI conversion.");
77  break;
78  }
79  }
80 
81  void copy_raw10(byte * const dest[], const byte * source, int width, int height, int actual_size)
82  {
83  auto count = width * height; // num of pixels
84  librealsense::copy(dest[0], source, size_t(5.0 * (count / 4.0)));
85  }
86 
87  void unpack_y10bpack(byte * const dest[], const byte * source, int width, int height, int actual_size)
88  {
89  auto count = width * height / 4; // num of pixels
90  uint8_t * from = (uint8_t*)(source);
91  uint16_t * to = (uint16_t*)(dest[0]);
92 
93  // Put the 10 bit into the msb of uint16_t
94  for (int i = 0; i < count; i++, from += 5) // traverse macro-pixels
95  {
96  *to++ = ((from[0] << 2) | (from[4] & 3)) << 6;
97  *to++ = ((from[1] << 2) | ((from[4] >> 2) & 3)) << 6;
98  *to++ = ((from[2] << 2) | ((from[4] >> 4) & 3)) << 6;
99  *to++ = ((from[3] << 2) | ((from[4] >> 6) & 3)) << 6;
100  }
101  }
102 
103  void unpack_w10(rs2_format dst_format, byte * const d[], const byte * s, int width, int height, int actual_size)
104  {
105  switch (dst_format)
106  {
107  case RS2_FORMAT_W10:
108  case RS2_FORMAT_RAW10:
109  copy_raw10(d, s, width, height, actual_size);
110  break;
111  case RS2_FORMAT_Y10BPACK:
112  unpack_y10bpack(d, s, width, height, actual_size);
113  break;
114  default:
115  LOG_ERROR("Unsupported format for W10 unpacking.");
116  break;
117  }
118  }
119 
120  // INZI converter
121  inzi_converter::inzi_converter(const char * name, rs2_format target_ir_format)
123  target_ir_format, RS2_STREAM_INFRARED, RS2_EXTENSION_VIDEO_FRAME, 1)
124  {}
125 
126  void inzi_converter::process_function(byte * const dest[], const byte * source, int width, int height, int actual_size, int input_size)
127  {
128  // convension: right frame is IR and left is Z16
129  unpack_inzi(_right_target_format, dest, source, width, height, actual_size);
130  }
131 
132  void invi_converter::process_function(byte * const dest[], const byte * source, int width, int height, int actual_size, int input_size)
133  {
134  unpack_invi(_target_format, dest, source, width, height, actual_size);
135  }
136 
137  w10_converter::w10_converter(const char * name, const rs2_format& target_format) :
139 
140  void w10_converter::process_function(byte * const dest[], const byte * source, int width, int height, int actual_size, int input_size)
141  {
142  unpack_w10(_target_format, dest, source, width, height, actual_size);
143  }
144 }
GLuint const GLchar * name
GLdouble s
void unpack_y8_from_y16_10(byte *const d[], const byte *s, int width, int height, int actual_size)
void unpack_inzi(rs2_format dst_ir_format, byte *const d[], const byte *s, int width, int height, int actual_size)
void unpack_w10(rs2_format dst_format, byte *const d[], const byte *s, int width, int height, int actual_size)
unsigned short uint16_t
Definition: stdint.h:79
d
Definition: rmse.py:171
unsigned char uint8_t
Definition: stdint.h:78
void unpack_pixels(byte *const dest[], int count, const SOURCE *source, UNPACK unpack, int actual_size)
void unpack_z16_y8_from_sr300_inzi(byte *const dest[], const byte *source, int width, int height, int actual_size)
inzi_converter(rs2_format target_ir_format)
GLint GLsizei GLsizei height
rs2_format
A stream&#39;s format identifies how binary data is encoded within a frame.
Definition: rs_sensor.h:59
w10_converter(const rs2_format &target_format)
#define LOG_ERROR(...)
Definition: src/types.h:242
void unpack_y10bpack(byte *const dest[], const byte *source, int width, int height, int actual_size)
unsigned char byte
Definition: src/types.h:52
void process_function(byte *const dest[], const byte *source, int width, int height, int actual_size, int input_size) override
GLuint in
Definition: glext.h:8859
GLint GLsizei count
GLsizei GLsizei GLchar * source
LZ4LIB_API char * dest
Definition: lz4.h:438
int i
void process_function(byte *const dest[], const byte *source, int width, int height, int actual_size, int input_size) override
void process_function(byte *const dest[], const byte *source, int width, int height, int actual_size, int input_size) override
void unpack_z16_y16_from_sr300_inzi(byte *const dest[], const byte *source, int width, int height, int actual_size)
void unpack_y16_from_y16_10(byte *const d[], const byte *s, int width, int height, int actual_size)
void unpack_invi(rs2_format dst_format, byte *const d[], const byte *s, int width, int height, int actual_size)
void copy_raw10(byte *const dest[], const byte *source, int width, int height, int actual_size)
GLint GLsizei width
void copy(void *dst, void const *src, size_t size)
Definition: types.cpp:836


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