openni_image_rgb24.cpp
Go to the documentation of this file.
2 
3 namespace openni_wrapper
4 {
6 : Image (image_meta_data)
7 {
8 }
9 
11 {
12 }
13 
14 void ImageRGB24::fillGrayscale (unsigned width, unsigned height, unsigned char* gray_buffer, unsigned gray_line_step) const throw (OpenNIException)
15 {
16  if (width > image_md_->XRes () || height > image_md_->YRes ())
17  THROW_OPENNI_EXCEPTION ("Up-sampling not supported. Request was %d x %d -> %d x %d.", image_md_->XRes (), image_md_->YRes (), width, height);
18 
19  if (image_md_->XRes () % width == 0 && image_md_->YRes () % height == 0)
20  {
21  unsigned src_step = image_md_->XRes () / width;
22  unsigned src_skip = (image_md_->YRes () / height - 1) * image_md_->XRes ();
23 
24  if (gray_line_step == 0)
25  gray_line_step = width;
26 
27  unsigned dst_skip = gray_line_step - width; // skip of padding values in bytes
28 
29  unsigned char* dst_line = gray_buffer;
30  const XnRGB24Pixel* src_line = image_md_->RGB24Data();
31 
32  for (unsigned yIdx = 0; yIdx < height; ++yIdx, src_line += src_skip, dst_line += dst_skip)
33  {
34  for (unsigned xIdx = 0; xIdx < width; ++xIdx, src_line += src_step, dst_line ++)
35  {
36  *dst_line = (unsigned char)(((int)src_line->nRed * 299 + (int)src_line->nGreen * 587 + (int)src_line->nBlue * 114) * 0.001);
37  }
38  }
39  }
40  else
41  {
42  THROW_OPENNI_EXCEPTION ("Down-sampling only possible for integer scale. Request was %d x %d -> %d x %d.", image_md_->XRes (), image_md_->YRes (), width, height);
43  }
44 }
45 
46 void ImageRGB24::fillRGB (unsigned width, unsigned height, unsigned char* rgb_buffer, unsigned rgb_line_step) const throw (OpenNIException)
47 {
48  if (width > image_md_->XRes () || height > image_md_->YRes ())
49  THROW_OPENNI_EXCEPTION ("Up-sampling not supported. Request was %d x %d -> %d x %d.", image_md_->XRes (), image_md_->YRes (), width, height);
50 
51  if (width == image_md_->XRes () && height == image_md_->YRes ())
52  {
53  unsigned line_size = width * 3;
54  if (rgb_line_step == 0 || rgb_line_step == line_size)
55  {
56  memcpy (rgb_buffer, image_md_->WritableData(), image_md_->DataSize());
57  }
58  else // line by line
59  {
60  unsigned char* rgb_line = rgb_buffer;
61  const unsigned char* src_line = (const unsigned char*)image_md_->WritableData();
62  for (unsigned yIdx = 0; yIdx < height; ++yIdx, rgb_line += rgb_line_step, src_line += line_size)
63  {
64  memcpy (rgb_line, src_line, line_size);
65  }
66  }
67  }
68  else if (image_md_->XRes () % width == 0 && image_md_->YRes () % height == 0) // downsamplig
69  {
70  unsigned src_step = image_md_->XRes () / width;
71  unsigned src_skip = (image_md_->YRes () / height - 1) * image_md_->XRes ();
72 
73  if (rgb_line_step == 0)
74  rgb_line_step = width * 3;
75 
76  unsigned dst_skip = rgb_line_step - width * 3; // skip of padding values in bytes
77 
78  XnRGB24Pixel* dst_line = (XnRGB24Pixel*)rgb_buffer;
79  const XnRGB24Pixel* src_line = image_md_->RGB24Data();
80 
81  for (unsigned yIdx = 0; yIdx < height; ++yIdx, src_line += src_skip)
82  {
83  for (unsigned xIdx = 0; xIdx < width; ++xIdx, src_line += src_step, dst_line ++)
84  {
85  *dst_line = *src_line;
86  }
87 
88  if (dst_skip != 0)
89  {
90  // use bytes to skip rather than XnRGB24Pixel's, since line_step does not need to be multiple of 3
91  unsigned char* temp = (unsigned char*) dst_line;
92  dst_line = (XnRGB24Pixel*) (temp + dst_skip);
93  }
94  }
95  }
96  else
97  {
98  THROW_OPENNI_EXCEPTION ("Down-sampling only possible for integer scale. Request was %d x %d -> %d x %d.", image_md_->XRes (), image_md_->YRes (), width, height);
99  }
100 }
101 
102 bool ImageRGB24::isResizingSupported (unsigned input_width, unsigned input_height, unsigned output_width, unsigned output_height) const
103 {
104  return ImageRGB24::resizingSupported (input_width, input_height, output_width, output_height);
105 }
106 }
107 
#define THROW_OPENNI_EXCEPTION(format,...)
virtual void fillRGB(unsigned width, unsigned height, unsigned char *rgb_buffer, unsigned rgb_line_step=0) const
Image class containing just a reference to image meta data. Thus this class just provides an interfac...
Definition: openni_image.h:54
General exception class.
virtual void fillGrayscale(unsigned width, unsigned height, unsigned char *gray_buffer, unsigned gray_line_step=0) const
ImageRGB24(boost::shared_ptr< xn::ImageMetaData > image_meta_data)
boost::shared_ptr< xn::ImageMetaData > image_md_
Definition: openni_image.h:93
virtual bool isResizingSupported(unsigned input_width, unsigned input_height, unsigned output_width, unsigned output_height) const
static bool resizingSupported(unsigned input_width, unsigned input_height, unsigned output_width, unsigned output_height)


openni_camera
Author(s): Patrick Mihelich, Suat Gedikli, Radu Bogdan Rusu
autogenerated on Wed Jun 5 2019 20:15:22