41 #define AVG(a,b) (((int)(a) + (int)(b)) >> 1) 42 #define AVG3(a,b,c) (((int)(a) + (int)(b) + (int)(c)) / 3) 43 #define AVG4(a,b,c,d) (((int)(a) + (int)(b) + (int)(c) + (int)(d)) >> 2) 44 #define WAVG4(a,b,c,d,x,y) ( ( ((int)(a) + (int)(b)) * (int)(x) + ((int)(c) + (int)(d)) * (int)(y) ) / ( 2 * ((int)(x) + (int(y))) ) ) 51 :
Image (image_meta_data)
52 , debayering_method_ (method)
56 ImageBayerGRBG::~ImageBayerGRBG () throw ()
60 bool ImageBayerGRBG::isResizingSupported (
unsigned input_width,
unsigned input_height,
unsigned output_width,
unsigned output_height)
const 62 return ImageBayerGRBG::resizingSupported (input_width, input_height, output_width, output_height);
65 void ImageBayerGRBG::fillGrayscale (
unsigned width,
unsigned height,
unsigned char* gray_buffer,
unsigned gray_line_step)
const throw (
OpenNIException)
67 if (width > image_md_->XRes () || height > image_md_->YRes ())
68 THROW_OPENNI_EXCEPTION (
"Upsampling not supported. Request was: %d x %d -> %d x %d", image_md_->XRes (), image_md_->YRes (), width, height);
70 if (gray_line_step == 0)
71 gray_line_step = width;
74 unsigned gray_line_skip = gray_line_step - width;
75 if (image_md_->XRes () == width && image_md_->YRes () == height)
77 const XnUInt8 *bayer_pixel = image_md_->WritableData ();
78 int line_skip = image_md_->XRes ();
79 if (debayering_method_ == Bilinear)
82 for (
register unsigned xIdx = 0; xIdx < width - 2; xIdx += 2, gray_buffer += 2, bayer_pixel += 2)
84 gray_buffer[0] = bayer_pixel[0];
85 gray_buffer[1] =
AVG3 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[1 + line_skip]);
87 gray_buffer[0] = bayer_pixel[0];
88 gray_buffer[1] =
AVG (bayer_pixel[0], bayer_pixel[1 + line_skip]);
89 gray_buffer += 2 + gray_line_skip;
92 for (
register unsigned yIdx = 1; yIdx < height - 1; yIdx += 2)
95 gray_buffer[0] =
AVG3 (bayer_pixel[-line_skip], bayer_pixel[line_skip], bayer_pixel[1]);
96 gray_buffer[1] = bayer_pixel[1];
99 for (
register unsigned xIdx = 2; xIdx < width; xIdx += 2, gray_buffer += 2, bayer_pixel += 2)
101 gray_buffer[0] =
AVG4 (bayer_pixel[-line_skip], bayer_pixel[line_skip], bayer_pixel[-1], bayer_pixel[1]);
102 gray_buffer[1] = bayer_pixel[1];
104 gray_buffer += gray_line_skip;
107 for (
register unsigned xIdx = 0; xIdx < width - 2; xIdx += 2, gray_buffer += 2, bayer_pixel += 2)
109 gray_buffer[0] = bayer_pixel[0];
110 gray_buffer[1] =
AVG4 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[-line_skip + 1], bayer_pixel[line_skip + 1]);
112 gray_buffer[0] = bayer_pixel[0];
113 gray_buffer[1] =
AVG3 (bayer_pixel[-line_skip + 1], bayer_pixel[line_skip + 1], bayer_pixel[-1]);
114 gray_buffer += 2 + gray_line_skip;
119 gray_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-line_skip]);
120 gray_buffer[1] = bayer_pixel[1];
123 for (
register unsigned xIdx = 2; xIdx < width; xIdx += 2, gray_buffer += 2, bayer_pixel += 2)
125 gray_buffer[0] =
AVG3 (bayer_pixel[-1], bayer_pixel[1], bayer_pixel[-line_skip]);
126 gray_buffer[1] = bayer_pixel[1];
129 else if (debayering_method_ == EdgeAware)
133 for (
register unsigned xIdx = 0; xIdx < width - 2; xIdx += 2, gray_buffer += 2, bayer_pixel += 2)
135 gray_buffer[0] = bayer_pixel[0];
136 gray_buffer[1] =
AVG3 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[1 + line_skip]);
138 gray_buffer[0] = bayer_pixel[0];
139 gray_buffer[1] =
AVG (bayer_pixel[0], bayer_pixel[1 + line_skip]);
140 gray_buffer += 2 + gray_line_skip;
143 for (
register unsigned yIdx = 1; yIdx < height - 1; yIdx += 2)
146 gray_buffer[0] =
AVG3 (bayer_pixel[-line_skip], bayer_pixel[line_skip], bayer_pixel[1]);
147 gray_buffer[1] = bayer_pixel[1];
150 for (
register unsigned xIdx = 2; xIdx < width; xIdx += 2, gray_buffer += 2, bayer_pixel += 2)
152 dv = abs (bayer_pixel[-line_skip] - bayer_pixel[line_skip]);
153 dh = abs (bayer_pixel[-1] - bayer_pixel[1]);
155 gray_buffer[0] =
AVG (bayer_pixel[-line_skip], bayer_pixel[line_skip]);
157 gray_buffer[0] =
AVG (bayer_pixel[-1], bayer_pixel[1]);
159 gray_buffer[0] =
AVG4 (bayer_pixel[-line_skip], bayer_pixel[line_skip], bayer_pixel[-1], bayer_pixel[1]);
161 gray_buffer[1] = bayer_pixel[1];
163 gray_buffer += gray_line_skip;
166 for (
register unsigned xIdx = 0; xIdx < width - 2; xIdx += 2, gray_buffer += 2, bayer_pixel += 2)
168 gray_buffer[0] = bayer_pixel[0];
170 dv = abs (bayer_pixel[1 - line_skip] - bayer_pixel[1 + line_skip]);
171 dh = abs (bayer_pixel[0] - bayer_pixel[2]);
173 gray_buffer[1] =
AVG (bayer_pixel[1 - line_skip], bayer_pixel[1 + line_skip]);
175 gray_buffer[1] =
AVG (bayer_pixel[0], bayer_pixel[2]);
177 gray_buffer[1] =
AVG4 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[-line_skip + 1], bayer_pixel[line_skip + 1]);
179 gray_buffer[0] = bayer_pixel[0];
180 gray_buffer[1] =
AVG3 (bayer_pixel[-line_skip + 1], bayer_pixel[line_skip + 1], bayer_pixel[-1]);
181 gray_buffer += 2 + gray_line_skip;
186 gray_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-line_skip]);
187 gray_buffer[1] = bayer_pixel[1];
190 for (
register unsigned xIdx = 2; xIdx < width; xIdx += 2, gray_buffer += 2, bayer_pixel += 2)
192 gray_buffer[0] =
AVG3 (bayer_pixel[-1], bayer_pixel[1], bayer_pixel[-line_skip]);
193 gray_buffer[1] = bayer_pixel[1];
196 else if (debayering_method_ == EdgeAwareWeighted)
200 for (
register unsigned xIdx = 0; xIdx < width - 2; xIdx += 2, gray_buffer += 2, bayer_pixel += 2)
202 gray_buffer[0] = bayer_pixel[0];
203 gray_buffer[1] =
AVG3 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[1 + line_skip]);
205 gray_buffer[0] = bayer_pixel[0];
206 gray_buffer[1] =
AVG (bayer_pixel[0], bayer_pixel[1 + line_skip]);
207 gray_buffer += 2 + gray_line_skip;
210 for (
register unsigned yIdx = 1; yIdx < height - 1; yIdx += 2)
213 gray_buffer[0] =
AVG3 (bayer_pixel[-line_skip], bayer_pixel[line_skip], bayer_pixel[1]);
214 gray_buffer[1] = bayer_pixel[1];
217 for (
register unsigned xIdx = 2; xIdx < width; xIdx += 2, gray_buffer += 2, bayer_pixel += 2)
219 dv = abs (bayer_pixel[-line_skip] - bayer_pixel[line_skip]);
220 dh = abs (bayer_pixel[-1] - bayer_pixel[1]);
222 if (dv == 0 && dh == 0)
223 gray_buffer[0] =
AVG4 (bayer_pixel[-line_skip], bayer_pixel[line_skip], bayer_pixel[-1], bayer_pixel[1]);
225 gray_buffer[0] =
WAVG4 (bayer_pixel[-line_skip], bayer_pixel[line_skip], bayer_pixel[-1], bayer_pixel[1], dh, dv);
227 gray_buffer[1] = bayer_pixel[1];
230 gray_buffer += gray_line_skip;
233 for (
register unsigned xIdx = 0; xIdx < width - 2; xIdx += 2, gray_buffer += 2, bayer_pixel += 2)
235 gray_buffer[0] = bayer_pixel[0];
237 dv = abs (bayer_pixel[1 - line_skip] - bayer_pixel[1 + line_skip]);
238 dh = abs (bayer_pixel[0] - bayer_pixel[2]);
240 if (dv == 0 && dh == 0)
241 gray_buffer[1] =
AVG4 (bayer_pixel[1 - line_skip], bayer_pixel[1 + line_skip], bayer_pixel[0], bayer_pixel[2]);
243 gray_buffer[1] =
WAVG4 (bayer_pixel[1 - line_skip], bayer_pixel[1 + line_skip], bayer_pixel[0], bayer_pixel[2], dh, dv);
245 gray_buffer[0] = bayer_pixel[0];
246 gray_buffer[1] =
AVG3 (bayer_pixel[-line_skip + 1], bayer_pixel[line_skip + 1], bayer_pixel[-1]);
247 gray_buffer += 2 + gray_line_skip;
252 gray_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-line_skip]);
253 gray_buffer[1] = bayer_pixel[1];
256 for (
register unsigned xIdx = 2; xIdx < width; xIdx += 2, gray_buffer += 2, bayer_pixel += 2)
258 gray_buffer[0] =
AVG3 (bayer_pixel[-1], bayer_pixel[1], bayer_pixel[-line_skip]);
259 gray_buffer[1] = bayer_pixel[1];
268 if ((image_md_->XRes () >> 1) % width != 0 || (image_md_->YRes () >> 1) % height != 0)
269 THROW_OPENNI_EXCEPTION (
"Downsampling only possible for multiple of 2 in both dimensions. Request was %d x %d -> %d x %d.", image_md_->XRes (), image_md_->YRes (), width, height);
272 register unsigned bayerXStep = image_md_->XRes () / width;
273 register unsigned bayerYSkip = (image_md_->YRes () / height - 1) * image_md_->XRes ();
276 register const XnUInt8* bayer_buffer = image_md_->WritableData ();
278 for (
register unsigned yIdx = 0; yIdx < height; ++yIdx, bayer_buffer += bayerYSkip, gray_buffer += gray_line_skip)
280 for (
register unsigned xIdx = 0; xIdx < width; ++xIdx, ++gray_buffer, bayer_buffer += bayerXStep)
282 *gray_buffer =
AVG (bayer_buffer[0], bayer_buffer[ image_md_->XRes () + 1]);
288 void ImageBayerGRBG::fillRGB (
unsigned width,
unsigned height,
unsigned char* rgb_buffer,
unsigned rgb_line_step)
const throw (
OpenNIException)
290 if (width > image_md_->XRes () || height > image_md_->YRes ())
291 THROW_OPENNI_EXCEPTION (
"Upsampling only possible for multiple of 2 in both dimensions. Request was %d x %d -> %d x %d.", image_md_->XRes (), image_md_->YRes (), width, height);
293 if (rgb_line_step == 0)
294 rgb_line_step = width * 3;
297 unsigned rgb_line_skip = rgb_line_step - width * 3;
299 if (image_md_->XRes () == width && image_md_->YRes () == height)
301 register const XnUInt8 *bayer_pixel = image_md_->WritableData ();
302 register unsigned yIdx, xIdx;
304 int bayer_line_step = image_md_->XRes ();
305 int bayer_line_step2 = image_md_->XRes () << 1;
307 if (debayering_method_ == Bilinear)
315 rgb_buffer[3] = rgb_buffer[0] = bayer_pixel[1];
316 rgb_buffer[1] = bayer_pixel[0];
317 rgb_buffer[rgb_line_step + 2] = rgb_buffer[2] = bayer_pixel[bayer_line_step];
324 rgb_buffer[4] =
AVG3 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1]);
325 rgb_buffer[rgb_line_step + 5] = rgb_buffer[5] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
332 rgb_buffer[rgb_line_step + 3] = rgb_buffer[rgb_line_step ] =
AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
333 rgb_buffer[rgb_line_step + 1] =
AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step + 1], bayer_pixel[bayer_line_step2]);
341 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
348 for (xIdx = 2; xIdx < width - 2; xIdx += 2, rgb_buffer += 6, bayer_pixel += 2)
355 rgb_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-1]);
356 rgb_buffer[1] = bayer_pixel[0];
357 rgb_buffer[2] = bayer_pixel[bayer_line_step + 1];
363 rgb_buffer[3] = bayer_pixel[1];
364 rgb_buffer[4] =
AVG3 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1]);
365 rgb_buffer[rgb_line_step + 5] = rgb_buffer[5] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
372 rgb_buffer[rgb_line_step ] =
AVG4 (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1], bayer_pixel[-1], bayer_pixel[bayer_line_step2 - 1]);
373 rgb_buffer[rgb_line_step + 1] =
AVG4 (bayer_pixel[0], bayer_pixel[bayer_line_step2], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
374 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
380 rgb_buffer[rgb_line_step + 3] =
AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
381 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
391 rgb_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-1]);
392 rgb_buffer[1] = bayer_pixel[0];
393 rgb_buffer[rgb_line_step + 5] = rgb_buffer[rgb_line_step + 2] = rgb_buffer[5] = rgb_buffer[2] = bayer_pixel[bayer_line_step];
399 rgb_buffer[3] = bayer_pixel[1];
400 rgb_buffer[4] =
AVG (bayer_pixel[0], bayer_pixel[bayer_line_step + 1]);
408 rgb_buffer[rgb_line_step ] =
AVG4 (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1], bayer_pixel[-1], bayer_pixel[bayer_line_step2 - 1]);
409 rgb_buffer[rgb_line_step + 1] =
AVG4 (bayer_pixel[0], bayer_pixel[bayer_line_step2], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
416 rgb_buffer[rgb_line_step + 3] =
AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
417 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
420 bayer_pixel += bayer_line_step + 2;
421 rgb_buffer += rgb_line_step + 6 + rgb_line_skip;
425 for (yIdx = 2; yIdx < height - 2; yIdx += 2)
434 rgb_buffer[3] = rgb_buffer[0] = bayer_pixel[1];
435 rgb_buffer[1] = bayer_pixel[0];
436 rgb_buffer[2] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[-bayer_line_step]);
444 rgb_buffer[4] =
AVG4 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1], bayer_pixel[1 - bayer_line_step]);
445 rgb_buffer[5] =
AVG4 (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2], bayer_pixel[-bayer_line_step], bayer_pixel[2 - bayer_line_step]);
452 rgb_buffer[rgb_line_step + 3] = rgb_buffer[rgb_line_step ] =
AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
453 rgb_buffer[rgb_line_step + 1] =
AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step + 1], bayer_pixel[bayer_line_step2]);
454 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
461 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
462 rgb_buffer[rgb_line_step + 5] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
467 for (xIdx = 2; xIdx < width - 2; xIdx += 2, rgb_buffer += 6, bayer_pixel += 2)
475 rgb_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-1]);
476 rgb_buffer[1] = bayer_pixel[0];
477 rgb_buffer[2] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[-bayer_line_step]);
484 rgb_buffer[3] = bayer_pixel[1];
485 rgb_buffer[4] =
AVG4 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1], bayer_pixel[1 - bayer_line_step]);
486 rgb_buffer[5] =
AVG4 (bayer_pixel[-bayer_line_step], bayer_pixel[2 - bayer_line_step], bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
494 rgb_buffer[rgb_line_step ] =
AVG4 (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1], bayer_pixel[-1], bayer_pixel[bayer_line_step2 - 1]);
495 rgb_buffer[rgb_line_step + 1] =
AVG4 (bayer_pixel[0], bayer_pixel[bayer_line_step2], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
496 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
503 rgb_buffer[rgb_line_step + 3] =
AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
504 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
505 rgb_buffer[rgb_line_step + 5] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
515 rgb_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-1]);
516 rgb_buffer[1] = bayer_pixel[0];
517 rgb_buffer[rgb_line_step + 5] = rgb_buffer[rgb_line_step + 2] = rgb_buffer[5] = rgb_buffer[2] = bayer_pixel[bayer_line_step];
523 rgb_buffer[3] = bayer_pixel[1];
524 rgb_buffer[4] =
AVG (bayer_pixel[0], bayer_pixel[bayer_line_step + 1]);
532 rgb_buffer[rgb_line_step ] =
AVG4 (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1], bayer_pixel[-1], bayer_pixel[bayer_line_step2 - 1]);
533 rgb_buffer[rgb_line_step + 1] =
AVG4 (bayer_pixel[0], bayer_pixel[bayer_line_step2], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
540 rgb_buffer[rgb_line_step + 3] =
AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
541 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
544 bayer_pixel += bayer_line_step + 2;
545 rgb_buffer += rgb_line_step + 6 + rgb_line_skip;
554 rgb_buffer[rgb_line_step + 3] = rgb_buffer[rgb_line_step ] = rgb_buffer[3] = rgb_buffer[0] = bayer_pixel[1];
555 rgb_buffer[1] = bayer_pixel[0];
556 rgb_buffer[rgb_line_step + 2] = rgb_buffer[2] = bayer_pixel[bayer_line_step];
563 rgb_buffer[4] =
AVG4 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1], bayer_pixel[1 - bayer_line_step]);
564 rgb_buffer[5] =
AVG4 (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2], bayer_pixel[-bayer_line_step], bayer_pixel[2 - bayer_line_step]);
572 rgb_buffer[rgb_line_step + 1] =
AVG (bayer_pixel[0], bayer_pixel[bayer_line_step + 1]);
573 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
580 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
581 rgb_buffer[rgb_line_step + 5] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
586 for (xIdx = 2; xIdx < width - 2; xIdx += 2, rgb_buffer += 6, bayer_pixel += 2)
593 rgb_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-1]);
594 rgb_buffer[1] = bayer_pixel[0];
595 rgb_buffer[2] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[-bayer_line_step]);
601 rgb_buffer[rgb_line_step + 3] = rgb_buffer[3] = bayer_pixel[1];
602 rgb_buffer[4] =
AVG4 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1], bayer_pixel[1 - bayer_line_step]);
603 rgb_buffer[5] =
AVG4 (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2], bayer_pixel[-bayer_line_step], bayer_pixel[-bayer_line_step + 2]);
610 rgb_buffer[rgb_line_step ] =
AVG (bayer_pixel[-1], bayer_pixel[1]);
611 rgb_buffer[rgb_line_step + 1] =
AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
612 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
620 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
621 rgb_buffer[rgb_line_step + 5] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
630 rgb_buffer[rgb_line_step ] = rgb_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-1]);
631 rgb_buffer[1] = bayer_pixel[0];
632 rgb_buffer[5] = rgb_buffer[2] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[-bayer_line_step]);
638 rgb_buffer[rgb_line_step + 3] = rgb_buffer[3] = bayer_pixel[1];
639 rgb_buffer[4] =
AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step + 1], bayer_pixel[-bayer_line_step + 1]);
648 rgb_buffer[rgb_line_step + 1] =
AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
649 rgb_buffer[rgb_line_step + 5] = rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
656 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
659 else if (debayering_method_ == EdgeAware)
669 rgb_buffer[3] = rgb_buffer[0] = bayer_pixel[1];
670 rgb_buffer[1] = bayer_pixel[0];
671 rgb_buffer[rgb_line_step + 2] = rgb_buffer[2] = bayer_pixel[bayer_line_step];
678 rgb_buffer[4] =
AVG3 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1]);
679 rgb_buffer[rgb_line_step + 5] = rgb_buffer[5] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
686 rgb_buffer[rgb_line_step + 3] = rgb_buffer[rgb_line_step ] =
AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
687 rgb_buffer[rgb_line_step + 1] =
AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step + 1], bayer_pixel[bayer_line_step2]);
695 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
701 for (xIdx = 2; xIdx < width - 2; xIdx += 2, rgb_buffer += 6, bayer_pixel += 2)
708 rgb_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-1]);
709 rgb_buffer[1] = bayer_pixel[0];
710 rgb_buffer[2] = bayer_pixel[bayer_line_step + 1];
716 rgb_buffer[3] = bayer_pixel[1];
717 rgb_buffer[4] =
AVG3 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1]);
718 rgb_buffer[rgb_line_step + 5] = rgb_buffer[5] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
725 rgb_buffer[rgb_line_step ] =
AVG4 (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1], bayer_pixel[-1], bayer_pixel[bayer_line_step2 - 1]);
726 rgb_buffer[rgb_line_step + 1] =
AVG4 (bayer_pixel[0], bayer_pixel[bayer_line_step2], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
727 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
733 rgb_buffer[rgb_line_step + 3] =
AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
734 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
744 rgb_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-1]);
745 rgb_buffer[1] = bayer_pixel[0];
746 rgb_buffer[rgb_line_step + 5] = rgb_buffer[rgb_line_step + 2] = rgb_buffer[5] = rgb_buffer[2] = bayer_pixel[bayer_line_step];
752 rgb_buffer[3] = bayer_pixel[1];
753 rgb_buffer[4] =
AVG (bayer_pixel[0], bayer_pixel[bayer_line_step + 1]);
761 rgb_buffer[rgb_line_step ] =
AVG4 (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1], bayer_pixel[-1], bayer_pixel[bayer_line_step2 - 1]);
762 rgb_buffer[rgb_line_step + 1] =
AVG4 (bayer_pixel[0], bayer_pixel[bayer_line_step2], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
769 rgb_buffer[rgb_line_step + 3] =
AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
770 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
773 bayer_pixel += bayer_line_step + 2;
774 rgb_buffer += rgb_line_step + 6 + rgb_line_skip;
776 for (yIdx = 2; yIdx < height - 2; yIdx += 2)
785 rgb_buffer[3] = rgb_buffer[0] = bayer_pixel[1];
786 rgb_buffer[1] = bayer_pixel[0];
787 rgb_buffer[2] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[-bayer_line_step]);
795 rgb_buffer[4] =
AVG4 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1], bayer_pixel[1 - bayer_line_step]);
796 rgb_buffer[5] =
AVG4 (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2], bayer_pixel[-bayer_line_step], bayer_pixel[2 - bayer_line_step]);
803 rgb_buffer[rgb_line_step + 3] = rgb_buffer[rgb_line_step ] =
AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
804 rgb_buffer[rgb_line_step + 1] =
AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step + 1], bayer_pixel[bayer_line_step2]);
805 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
812 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
813 rgb_buffer[rgb_line_step + 5] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
818 for (xIdx = 2; xIdx < width - 2; xIdx += 2, rgb_buffer += 6, bayer_pixel += 2)
826 rgb_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-1]);
827 rgb_buffer[1] = bayer_pixel[0];
828 rgb_buffer[2] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[-bayer_line_step]);
836 dh = abs (bayer_pixel[0] - bayer_pixel[2]);
837 dv = abs (bayer_pixel[-bayer_line_step + 1] - bayer_pixel[bayer_line_step + 1]);
840 rgb_buffer[4] =
AVG (bayer_pixel[-bayer_line_step + 1], bayer_pixel[bayer_line_step + 1]);
842 rgb_buffer[4] =
AVG (bayer_pixel[0], bayer_pixel[2]);
844 rgb_buffer[4] =
AVG4 (bayer_pixel[-bayer_line_step + 1], bayer_pixel[bayer_line_step + 1], bayer_pixel[0], bayer_pixel[2]);
846 rgb_buffer[3] = bayer_pixel[1];
847 rgb_buffer[5] =
AVG4 (bayer_pixel[-bayer_line_step], bayer_pixel[2 - bayer_line_step], bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
855 rgb_buffer[rgb_line_step ] =
AVG4 (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1], bayer_pixel[-1], bayer_pixel[bayer_line_step2 - 1]);
856 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
858 dv = abs (bayer_pixel[0] - bayer_pixel[bayer_line_step2]);
859 dh = abs (bayer_pixel[bayer_line_step - 1] - bayer_pixel[bayer_line_step + 1]);
862 rgb_buffer[rgb_line_step + 1] =
AVG (bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
864 rgb_buffer[rgb_line_step + 1] =
AVG (bayer_pixel[0], bayer_pixel[bayer_line_step2]);
866 rgb_buffer[rgb_line_step + 1] =
AVG4 (bayer_pixel[0], bayer_pixel[bayer_line_step2], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
873 rgb_buffer[rgb_line_step + 3] =
AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
874 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
875 rgb_buffer[rgb_line_step + 5] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
885 rgb_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-1]);
886 rgb_buffer[1] = bayer_pixel[0];
887 rgb_buffer[rgb_line_step + 5] = rgb_buffer[rgb_line_step + 2] = rgb_buffer[5] = rgb_buffer[2] = bayer_pixel[bayer_line_step];
893 rgb_buffer[3] = bayer_pixel[1];
894 rgb_buffer[4] =
AVG (bayer_pixel[0], bayer_pixel[bayer_line_step + 1]);
902 rgb_buffer[rgb_line_step ] =
AVG4 (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1], bayer_pixel[-1], bayer_pixel[bayer_line_step2 - 1]);
903 rgb_buffer[rgb_line_step + 1] =
AVG4 (bayer_pixel[0], bayer_pixel[bayer_line_step2], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
910 rgb_buffer[rgb_line_step + 3] =
AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
911 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
914 bayer_pixel += bayer_line_step + 2;
915 rgb_buffer += rgb_line_step + 6 + rgb_line_skip;
924 rgb_buffer[rgb_line_step + 3] = rgb_buffer[rgb_line_step ] = rgb_buffer[3] = rgb_buffer[0] = bayer_pixel[1];
925 rgb_buffer[1] = bayer_pixel[0];
926 rgb_buffer[rgb_line_step + 2] = rgb_buffer[2] = bayer_pixel[bayer_line_step];
933 rgb_buffer[4] =
AVG4 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1], bayer_pixel[1 - bayer_line_step]);
934 rgb_buffer[5] =
AVG4 (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2], bayer_pixel[-bayer_line_step], bayer_pixel[2 - bayer_line_step]);
942 rgb_buffer[rgb_line_step + 1] =
AVG (bayer_pixel[0], bayer_pixel[bayer_line_step + 1]);
943 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
950 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
951 rgb_buffer[rgb_line_step + 5] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
956 for (xIdx = 2; xIdx < width - 2; xIdx += 2, rgb_buffer += 6, bayer_pixel += 2)
963 rgb_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-1]);
964 rgb_buffer[1] = bayer_pixel[0];
965 rgb_buffer[2] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[-bayer_line_step]);
971 rgb_buffer[rgb_line_step + 3] = rgb_buffer[3] = bayer_pixel[1];
972 rgb_buffer[4] =
AVG4 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1], bayer_pixel[1 - bayer_line_step]);
973 rgb_buffer[5] =
AVG4 (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2], bayer_pixel[-bayer_line_step], bayer_pixel[-bayer_line_step + 2]);
980 rgb_buffer[rgb_line_step ] =
AVG (bayer_pixel[-1], bayer_pixel[1]);
981 rgb_buffer[rgb_line_step + 1] =
AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
982 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
990 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
991 rgb_buffer[rgb_line_step + 5] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
1000 rgb_buffer[rgb_line_step ] = rgb_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-1]);
1001 rgb_buffer[1] = bayer_pixel[0];
1002 rgb_buffer[5] = rgb_buffer[2] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[-bayer_line_step]);
1008 rgb_buffer[rgb_line_step + 3] = rgb_buffer[3] = bayer_pixel[1];
1009 rgb_buffer[4] =
AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step + 1], bayer_pixel[-bayer_line_step + 1]);
1018 rgb_buffer[rgb_line_step + 1] =
AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
1019 rgb_buffer[rgb_line_step + 5] = rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
1026 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
1029 else if (debayering_method_ == EdgeAwareWeighted)
1039 rgb_buffer[3] = rgb_buffer[0] = bayer_pixel[1];
1040 rgb_buffer[1] = bayer_pixel[0];
1041 rgb_buffer[rgb_line_step + 2] = rgb_buffer[2] = bayer_pixel[bayer_line_step];
1048 rgb_buffer[4] =
AVG3 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1]);
1049 rgb_buffer[rgb_line_step + 5] = rgb_buffer[5] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
1056 rgb_buffer[rgb_line_step + 3] = rgb_buffer[rgb_line_step ] =
AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
1057 rgb_buffer[rgb_line_step + 1] =
AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step + 1], bayer_pixel[bayer_line_step2]);
1065 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
1071 for (xIdx = 2; xIdx < width - 2; xIdx += 2, rgb_buffer += 6, bayer_pixel += 2)
1078 rgb_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-1]);
1079 rgb_buffer[1] = bayer_pixel[0];
1080 rgb_buffer[2] = bayer_pixel[bayer_line_step + 1];
1086 rgb_buffer[3] = bayer_pixel[1];
1087 rgb_buffer[4] =
AVG3 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1]);
1088 rgb_buffer[rgb_line_step + 5] = rgb_buffer[5] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
1095 rgb_buffer[rgb_line_step ] =
AVG4 (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1], bayer_pixel[-1], bayer_pixel[bayer_line_step2 - 1]);
1096 rgb_buffer[rgb_line_step + 1] =
AVG4 (bayer_pixel[0], bayer_pixel[bayer_line_step2], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
1097 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
1103 rgb_buffer[rgb_line_step + 3] =
AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
1104 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
1114 rgb_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-1]);
1115 rgb_buffer[1] = bayer_pixel[0];
1116 rgb_buffer[rgb_line_step + 5] = rgb_buffer[rgb_line_step + 2] = rgb_buffer[5] = rgb_buffer[2] = bayer_pixel[bayer_line_step];
1122 rgb_buffer[3] = bayer_pixel[1];
1123 rgb_buffer[4] =
AVG (bayer_pixel[0], bayer_pixel[bayer_line_step + 1]);
1131 rgb_buffer[rgb_line_step ] =
AVG4 (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1], bayer_pixel[-1], bayer_pixel[bayer_line_step2 - 1]);
1132 rgb_buffer[rgb_line_step + 1] =
AVG4 (bayer_pixel[0], bayer_pixel[bayer_line_step2], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
1139 rgb_buffer[rgb_line_step + 3] =
AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
1140 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
1143 bayer_pixel += bayer_line_step + 2;
1144 rgb_buffer += rgb_line_step + 6 + rgb_line_skip;
1146 for (yIdx = 2; yIdx < height - 2; yIdx += 2)
1155 rgb_buffer[3] = rgb_buffer[0] = bayer_pixel[1];
1156 rgb_buffer[1] = bayer_pixel[0];
1157 rgb_buffer[2] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[-bayer_line_step]);
1165 rgb_buffer[4] =
AVG4 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1], bayer_pixel[1 - bayer_line_step]);
1166 rgb_buffer[5] =
AVG4 (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2], bayer_pixel[-bayer_line_step], bayer_pixel[2 - bayer_line_step]);
1173 rgb_buffer[rgb_line_step + 3] = rgb_buffer[rgb_line_step ] =
AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
1174 rgb_buffer[rgb_line_step + 1] =
AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step + 1], bayer_pixel[bayer_line_step2]);
1175 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
1182 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
1183 rgb_buffer[rgb_line_step + 5] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
1188 for (xIdx = 2; xIdx < width - 2; xIdx += 2, rgb_buffer += 6, bayer_pixel += 2)
1196 rgb_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-1]);
1197 rgb_buffer[1] = bayer_pixel[0];
1198 rgb_buffer[2] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[-bayer_line_step]);
1206 dh = abs (bayer_pixel[0] - bayer_pixel[2]);
1207 dv = abs (bayer_pixel[-bayer_line_step + 1] - bayer_pixel[bayer_line_step + 1]);
1209 if (dv == 0 && dh == 0)
1210 rgb_buffer[4] =
AVG4 (bayer_pixel[1 - bayer_line_step], bayer_pixel[1 + bayer_line_step], bayer_pixel[0], bayer_pixel[2]);
1212 rgb_buffer[4] =
WAVG4 (bayer_pixel[1 - bayer_line_step], bayer_pixel[1 + bayer_line_step], bayer_pixel[0], bayer_pixel[2], dh, dv);
1213 rgb_buffer[3] = bayer_pixel[1];
1214 rgb_buffer[5] =
AVG4 (bayer_pixel[-bayer_line_step], bayer_pixel[2 - bayer_line_step], bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
1222 rgb_buffer[rgb_line_step ] =
AVG4 (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1], bayer_pixel[-1], bayer_pixel[bayer_line_step2 - 1]);
1223 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
1225 dv = abs (bayer_pixel[0] - bayer_pixel[bayer_line_step2]);
1226 dh = abs (bayer_pixel[bayer_line_step - 1] - bayer_pixel[bayer_line_step + 1]);
1228 if (dv == 0 && dh == 0)
1229 rgb_buffer[rgb_line_step + 1] =
AVG4 (bayer_pixel[0], bayer_pixel[bayer_line_step2], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
1231 rgb_buffer[rgb_line_step + 1] =
WAVG4 (bayer_pixel[0], bayer_pixel[bayer_line_step2], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1], dh, dv);
1238 rgb_buffer[rgb_line_step + 3] =
AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
1239 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
1240 rgb_buffer[rgb_line_step + 5] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
1250 rgb_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-1]);
1251 rgb_buffer[1] = bayer_pixel[0];
1252 rgb_buffer[rgb_line_step + 5] = rgb_buffer[rgb_line_step + 2] = rgb_buffer[5] = rgb_buffer[2] = bayer_pixel[bayer_line_step];
1258 rgb_buffer[3] = bayer_pixel[1];
1259 rgb_buffer[4] =
AVG (bayer_pixel[0], bayer_pixel[bayer_line_step + 1]);
1267 rgb_buffer[rgb_line_step ] =
AVG4 (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1], bayer_pixel[-1], bayer_pixel[bayer_line_step2 - 1]);
1268 rgb_buffer[rgb_line_step + 1] =
AVG4 (bayer_pixel[0], bayer_pixel[bayer_line_step2], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
1275 rgb_buffer[rgb_line_step + 3] =
AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
1276 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
1279 bayer_pixel += bayer_line_step + 2;
1280 rgb_buffer += rgb_line_step + 6 + rgb_line_skip;
1289 rgb_buffer[rgb_line_step + 3] = rgb_buffer[rgb_line_step ] = rgb_buffer[3] = rgb_buffer[0] = bayer_pixel[1];
1290 rgb_buffer[1] = bayer_pixel[0];
1291 rgb_buffer[rgb_line_step + 2] = rgb_buffer[2] = bayer_pixel[bayer_line_step];
1298 rgb_buffer[4] =
AVG4 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1], bayer_pixel[1 - bayer_line_step]);
1299 rgb_buffer[5] =
AVG4 (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2], bayer_pixel[-bayer_line_step], bayer_pixel[2 - bayer_line_step]);
1307 rgb_buffer[rgb_line_step + 1] =
AVG (bayer_pixel[0], bayer_pixel[bayer_line_step + 1]);
1308 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
1315 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
1316 rgb_buffer[rgb_line_step + 5] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
1321 for (xIdx = 2; xIdx < width - 2; xIdx += 2, rgb_buffer += 6, bayer_pixel += 2)
1328 rgb_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-1]);
1329 rgb_buffer[1] = bayer_pixel[0];
1330 rgb_buffer[2] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[-bayer_line_step]);
1336 rgb_buffer[rgb_line_step + 3] = rgb_buffer[3] = bayer_pixel[1];
1337 rgb_buffer[4] =
AVG4 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1], bayer_pixel[1 - bayer_line_step]);
1338 rgb_buffer[5] =
AVG4 (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2], bayer_pixel[-bayer_line_step], bayer_pixel[-bayer_line_step + 2]);
1345 rgb_buffer[rgb_line_step ] =
AVG (bayer_pixel[-1], bayer_pixel[1]);
1346 rgb_buffer[rgb_line_step + 1] =
AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
1347 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
1355 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
1356 rgb_buffer[rgb_line_step + 5] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
1365 rgb_buffer[rgb_line_step ] = rgb_buffer[0] =
AVG (bayer_pixel[1], bayer_pixel[-1]);
1366 rgb_buffer[1] = bayer_pixel[0];
1367 rgb_buffer[5] = rgb_buffer[2] =
AVG (bayer_pixel[bayer_line_step], bayer_pixel[-bayer_line_step]);
1373 rgb_buffer[rgb_line_step + 3] = rgb_buffer[3] = bayer_pixel[1];
1374 rgb_buffer[4] =
AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step + 1], bayer_pixel[-bayer_line_step + 1]);
1383 rgb_buffer[rgb_line_step + 1] =
AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
1384 rgb_buffer[rgb_line_step + 5] = rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
1391 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
1399 if (image_md_->XRes () % width != 0 || image_md_->YRes () % height != 0)
1400 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);
1403 register unsigned bayerXStep = image_md_->XRes () / width;
1404 register unsigned bayerYSkip = (image_md_->YRes () / height - 1) * image_md_->XRes ();
1407 register const XnUInt8* bayer_buffer = image_md_->WritableData ();
1409 for (
register unsigned yIdx = 0; yIdx < height; ++yIdx, bayer_buffer += bayerYSkip, rgb_buffer += rgb_line_skip)
1411 for (
register unsigned xIdx = 0; xIdx < width; ++xIdx, rgb_buffer += 3, bayer_buffer += bayerXStep)
1413 rgb_buffer[ 2 ] = bayer_buffer[ image_md_->XRes () ];
1414 rgb_buffer[ 1 ] =
AVG (bayer_buffer[0], bayer_buffer[ image_md_->XRes () + 1]);
1415 rgb_buffer[ 0 ] = bayer_buffer[ 1 ];
#define THROW_OPENNI_EXCEPTION(format,...)
#define WAVG4(a, b, c, d, x, y)
Image class containing just a reference to image meta data. Thus this class just provides an interfac...