rotation-transform.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 
4 #include "rotation-transform.h"
5 
6 #include "../include/librealsense2/hpp/rs_sensor.hpp"
7 #include "../include/librealsense2/hpp/rs_processing.hpp"
8 #include "context.h"
9 #include "image.h"
10 #include "stream.h"
11 
12 namespace librealsense
13 {
15  template<size_t SIZE>
16  void rotate_image_optimized(byte * const dest[], const byte * source, int width, int height, int actual_size)
17  {
18  auto width_out = height;
19  auto height_out = width;
20 
21  auto out = dest[0];
22  byte buffer[8][8 * SIZE]; // = { 0 };
23  for (int i = 0; i <= height - 8; i = i + 8)
24  {
25  for (int j = 0; j <= width - 8; j = j + 8)
26  {
27  for (int ii = 0; ii < 8; ++ii)
28  {
29  for (int jj = 0; jj < 8; ++jj)
30  {
31  auto source_index = ((j + jj) + (width * (i + ii))) * SIZE;
32  memcpy((void*)(&buffer[7 - jj][(7 - ii) * SIZE]), &source[source_index], SIZE);
33  }
34  }
35 
36  for (int ii = 0; ii < 8; ++ii)
37  {
38  auto out_index = (((height_out - 8 - j + 1) * width_out) - i - 8 + (ii)* width_out);
39  memcpy(&out[(out_index)* SIZE], &(buffer[ii]), 8 * SIZE);
40  }
41  }
42  }
43  }
44 
45  template<size_t SIZE>
46  void rotate_image(byte * const dest[], const byte * source, int width, int height, int actual_size)
47  {
48  auto width_out = height;
49  auto height_out = width;
50 
51  auto out = dest[0];
52  for (int i = 0; i < height; ++i)
53  {
54  auto row_offset = i * width;
55  for (int j = 0; j < width; ++j)
56  {
57  auto out_index = (((height_out - j) * width_out) - i - 1) * SIZE;
58  librealsense::copy((void*)(&out[out_index]), &(source[(row_offset + j) * SIZE]), SIZE);
59  }
60  }
61  }
62 
63  void rotate_confidence(byte * const dest[], const byte * source, int width, int height, int actual_size)
64  {
65 #pragma pack (push, 1)
66  struct lsb_msb
67  {
68  unsigned lsb : 4;
69  unsigned msb : 4;
70  };
71 #pragma pack(pop)
72 
73  rotate_image<1>(dest, source, width, height, actual_size);
74  auto out = dest[0];
75  for (int i = (width - 1), out_i = ((width - 1) * 2); i >= 0; --i, out_i -= 2)
76  {
77  auto row_offset = i * height;
78  for (int j = 0; j < height; ++j)
79  {
80  auto val = *(reinterpret_cast<const lsb_msb*>(&out[(row_offset + j)]));
81  auto out_index = out_i * height + j;
82  out[out_index] = val.lsb << 4;
83  out[out_index + height] = val.msb << 4;
84  }
85  }
86  }
87 
89  rotation_transform::rotation_transform(rs2_format target_format, rs2_stream target_stream, rs2_extension extension_type)
90  : rotation_transform("Rotation Transform", target_format, target_stream, extension_type)
91  {}
92 
93  rotation_transform::rotation_transform(const char* name, rs2_format target_format, rs2_stream target_stream, rs2_extension extension_type)
94  : functional_processing_block(name, target_format, target_stream, extension_type)
95  {
98  }
99 
101  {
102  auto p = f->get_profile();
103  if (p.get() != _source_stream_profile.get())
104  {
106  _target_stream_profile = p.clone(p.stream_type(), p.stream_index(), _target_format);
108 
109  // Set the unique ID as the original frame.
110  // The frames are piped through a syncer and must have the origin UID.
112  target_spi->set_unique_id(p.unique_id());
113  }
114  }
115 
116  void rotation_transform::process_function(byte * const dest[], const byte * source, int width, int height, int actual_size, int input_size)
117  {
118  int rotated_width = height;
119  int rotated_height = width;
120  switch (_target_bpp)
121  {
122  case 1:
123  rotate_image_optimized<1>(dest, source, rotated_width, rotated_height, actual_size);
124  break;
125  case 2:
126  rotate_image_optimized<2>(dest, source, rotated_width, rotated_height, actual_size);
127  break;
128  default:
129  LOG_ERROR("Rotation transform does not support format: " + std::string(rs2_format_to_string(_target_format)));
130  }
131  }
132 
134  confidence_rotation_transform("Confidence Rotation Transform")
135  {}
136 
139  {}
140 
141  void confidence_rotation_transform::process_function(byte * const dest[], const byte * source, int width, int height, int actual_size, int input_size)
142  {
143  int rotated_width = height;
144  int rotated_height = width;
145 
146  // Workaround: the height is given by bytes and not by pixels.
147  rotate_confidence(dest, source, rotated_width / 2, rotated_height, actual_size);
148  }
149 }
const char * rs2_format_to_string(rs2_format format)
Definition: rs.cpp:1263
GLuint const GLchar * name
GLfloat GLfloat p
Definition: glext.h:12687
stream_profile get_profile() const
Definition: rs_frame.hpp:557
GLsizei const GLchar *const * string
GLenum GLfloat * buffer
GLuint GLfloat * val
GLdouble f
void rotate_confidence(byte *const dest[], const byte *source, int width, int height, int actual_size)
rotation_transform(rs2_format target_format, rs2_stream target_stream, rs2_extension extension_type)
void rotate_image(byte *const dest[], const byte *source, int width, int height, int actual_size)
GLint GLsizei GLsizei height
GLint j
void process_function(byte *const dest[], const byte *source, int width, int height, int actual_size, int input_size) override
rs2_format
A stream&#39;s format identifies how binary data is encoded within a frame.
Definition: rs_sensor.h:59
#define LOG_ERROR(...)
Definition: src/types.h:242
void rotate_image_optimized(byte *dest[], const byte *source, int width, int height)
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:42
librealsense::stream_profile_interface * profile
Definition: context.h:34
unsigned char byte
Definition: src/types.h:52
rs2_extension
Specifies advanced interfaces (capabilities) objects may implement.
Definition: rs_types.h:166
void init_profiles_info(const rs2::frame *f) override
const rs2_stream_profile * get() const
Definition: rs_frame.hpp:137
GLsizei GLsizei GLchar * source
LZ4LIB_API char * dest
Definition: lz4.h:438
virtual void set_unique_id(int uid)=0
void process_function(byte *const dest[], const byte *source, int width, int height, int actual_size, int input_size) override
int i
int get_image_bpp(rs2_format format)
Definition: image.cpp:21
stream_profile clone(rs2_stream type, int index, rs2_format format) const
Definition: rs_frame.hpp:63
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:40