6 :
Image (image_meta_data)
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);
19 if (image_md_->XRes () % width == 0 && image_md_->YRes () % height == 0)
21 unsigned src_step = image_md_->XRes () / width;
22 unsigned src_skip = (image_md_->YRes () / height - 1) * image_md_->XRes ();
24 if (gray_line_step == 0)
25 gray_line_step = width;
27 unsigned dst_skip = gray_line_step - width;
29 unsigned char* dst_line = gray_buffer;
30 const XnRGB24Pixel* src_line = image_md_->RGB24Data();
32 for (
unsigned yIdx = 0; yIdx < height; ++yIdx, src_line += src_skip, dst_line += dst_skip)
34 for (
unsigned xIdx = 0; xIdx < width; ++xIdx, src_line += src_step, dst_line ++)
36 *dst_line = (
unsigned char)(((
int)src_line->nRed * 299 + (int)src_line->nGreen * 587 + (
int)src_line->nBlue * 114) * 0.001);
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);
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);
51 if (width == image_md_->XRes () && height == image_md_->YRes ())
53 unsigned line_size = width * 3;
54 if (rgb_line_step == 0 || rgb_line_step == line_size)
56 memcpy (rgb_buffer, image_md_->WritableData(), image_md_->DataSize());
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)
64 memcpy (rgb_line, src_line, line_size);
68 else if (image_md_->XRes () % width == 0 && image_md_->YRes () % height == 0)
70 unsigned src_step = image_md_->XRes () / width;
71 unsigned src_skip = (image_md_->YRes () / height - 1) * image_md_->XRes ();
73 if (rgb_line_step == 0)
74 rgb_line_step = width * 3;
76 unsigned dst_skip = rgb_line_step - width * 3;
78 XnRGB24Pixel* dst_line = (XnRGB24Pixel*)rgb_buffer;
79 const XnRGB24Pixel* src_line = image_md_->RGB24Data();
81 for (
unsigned yIdx = 0; yIdx < height; ++yIdx, src_line += src_skip)
83 for (
unsigned xIdx = 0; xIdx < width; ++xIdx, src_line += src_step, dst_line ++)
85 *dst_line = *src_line;
91 unsigned char* temp = (
unsigned char*) dst_line;
92 dst_line = (XnRGB24Pixel*) (temp + dst_skip);
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);