41 #define CLIP_CHAR(c) ((c)>255?255:(c)<0?0:(c)) 48 :
Image (image_meta_data)
52 ImageYUV422::~ImageYUV422 () throw ()
56 bool ImageYUV422::isResizingSupported (
unsigned input_width,
unsigned input_height,
unsigned output_width,
unsigned output_height)
const 58 return ImageYUV422::resizingSupported (input_width, input_height, output_width, output_height);
61 void ImageYUV422::fillRGB (
unsigned width,
unsigned height,
unsigned char* rgb_buffer,
unsigned rgb_line_step)
const throw (
OpenNIException)
66 if (image_md_->XRes() != width && image_md_->YRes() != height)
68 if (width > image_md_->XRes () || height > image_md_->YRes ())
69 THROW_OPENNI_EXCEPTION (
"Upsampling not supported. Request was: %d x %d -> %d x %d", image_md_->XRes (), image_md_->YRes (), width, height);
71 if ( image_md_->XRes () % width != 0 || image_md_->YRes () % height != 0
72 || (image_md_->XRes () / width) & 0x01 || (image_md_->YRes () / height & 0x01) )
73 THROW_OPENNI_EXCEPTION (
"Downsampling only possible for power of two scale in both dimensions. Request was %d x %d -> %d x %d.", image_md_->XRes (), image_md_->YRes (), width, height);
76 register const XnUInt8* yuv_buffer = image_md_->WritableData();
78 unsigned rgb_line_skip = 0;
79 if (rgb_line_step != 0)
80 rgb_line_skip = rgb_line_step - width * 3;
82 if (image_md_->XRes() == width && image_md_->YRes() == height)
84 for(
register unsigned yIdx = 0; yIdx < height; ++yIdx, rgb_buffer += rgb_line_skip )
86 for(
register unsigned xIdx = 0; xIdx < width; xIdx += 2, rgb_buffer += 6, yuv_buffer += 4 )
88 int v = yuv_buffer[2] - 128;
89 int u = yuv_buffer[0] - 128;
91 rgb_buffer[0] =
CLIP_CHAR (yuv_buffer[1] + ((v * 18678 + 8192 ) >> 14));
92 rgb_buffer[1] =
CLIP_CHAR (yuv_buffer[1] + ((v * -9519 - u * 6472 + 8192 ) >> 14));
93 rgb_buffer[2] =
CLIP_CHAR (yuv_buffer[1] + ((u * 33292 + 8192 ) >> 14));
95 rgb_buffer[3] =
CLIP_CHAR (yuv_buffer[3] + ((v * 18678 + 8192 ) >> 14));
96 rgb_buffer[4] =
CLIP_CHAR (yuv_buffer[3] + ((v * -9519 - u * 6472 + 8192 ) >> 14));
97 rgb_buffer[5] =
CLIP_CHAR (yuv_buffer[3] + ((u * 33292 + 8192 ) >> 14));
103 register unsigned yuv_step = image_md_->XRes() / width;
104 register unsigned yuv_x_step = yuv_step << 1;
105 register unsigned yuv_skip = (image_md_->YRes() / height - 1) * ( image_md_->XRes() << 1 );
107 for(
register unsigned yIdx = 0; yIdx < image_md_->YRes(); yIdx += yuv_step, yuv_buffer += yuv_skip, rgb_buffer += rgb_line_skip )
109 for(
register unsigned xIdx = 0; xIdx < image_md_->XRes(); xIdx += yuv_step, rgb_buffer += 3, yuv_buffer += yuv_x_step )
111 int v = yuv_buffer[2] - 128;
112 int u = yuv_buffer[0] - 128;
114 rgb_buffer[0] =
CLIP_CHAR (yuv_buffer[1] + ((v * 18678 + 8192 ) >> 14));
115 rgb_buffer[1] =
CLIP_CHAR (yuv_buffer[1] + ((v * -9519 - u * 6472 + 8192 ) >> 14));
116 rgb_buffer[2] =
CLIP_CHAR (yuv_buffer[1] + ((u * 33292 + 8192 ) >> 14));
122 void ImageYUV422::fillGrayscale (
unsigned width,
unsigned height,
unsigned char* gray_buffer,
unsigned gray_line_step)
const throw (
OpenNIException)
125 if (width > image_md_->XRes () || height > image_md_->YRes ())
126 THROW_OPENNI_EXCEPTION (
"Upsampling not supported. Request was: %d x %d -> %d x %d", image_md_->XRes (), image_md_->YRes (), width, height);
128 if (image_md_->XRes () % width != 0 || image_md_->YRes () % height != 0)
129 THROW_OPENNI_EXCEPTION (
"Downsampling only possible for integer scales in both dimensions. Request was %d x %d -> %d x %d.", image_md_->XRes (), image_md_->YRes (), width, height);
131 unsigned gray_line_skip = 0;
132 if (gray_line_step != 0)
133 gray_line_skip = gray_line_step - width;
135 register unsigned yuv_step = image_md_->XRes() / width;
136 register unsigned yuv_x_step = yuv_step << 1;
137 register unsigned yuv_skip = (image_md_->YRes() / height - 1) * ( image_md_->XRes() << 1 );
138 register const XnUInt8* yuv_buffer = (image_md_->WritableData() + 1);
140 for(
register unsigned yIdx = 0; yIdx < image_md_->YRes(); yIdx += yuv_step, yuv_buffer += yuv_skip, gray_buffer += gray_line_skip )
142 for(
register unsigned xIdx = 0; xIdx < image_md_->XRes(); xIdx += yuv_step, ++gray_buffer, yuv_buffer += yuv_x_step )
144 *gray_buffer = *yuv_buffer;
#define THROW_OPENNI_EXCEPTION(format,...)
Image class containing just a reference to image meta data. Thus this class just provides an interfac...