00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "edge_aware.h"
00035
00036 #define AVG(a,b) (((int)(a) + (int)(b)) >> 1)
00037 #define AVG3(a,b,c) (((int)(a) + (int)(b) + (int)(c)) / 3)
00038 #define AVG4(a,b,c,d) (((int)(a) + (int)(b) + (int)(c) + (int)(d)) >> 2)
00039 #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))) ) )
00040 using namespace std;
00041
00042 namespace image_proc {
00043
00044 void debayerEdgeAware(const cv::Mat& bayer, cv::Mat& color)
00045 {
00046 unsigned width = bayer.cols;
00047 unsigned height = bayer.rows;
00048 unsigned rgb_line_step = color.step[0];
00049 unsigned rgb_line_skip = rgb_line_step - width * 3;
00050 int bayer_line_step = bayer.step[0];
00051 int bayer_line_step2 = bayer_line_step * 2;
00052
00053 unsigned char* rgb_buffer = color.data;
00054 unsigned char* bayer_pixel = bayer.data;
00055 unsigned yIdx, xIdx;
00056
00057 int dh, dv;
00058
00059
00060
00061
00062
00063
00064
00065 rgb_buffer[3] = rgb_buffer[0] = bayer_pixel[1];
00066 rgb_buffer[1] = bayer_pixel[0];
00067 rgb_buffer[rgb_line_step + 2] = rgb_buffer[2] = bayer_pixel[bayer_line_step];
00068
00069
00070
00071
00072
00073
00074 rgb_buffer[4] = AVG3 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1]);
00075 rgb_buffer[rgb_line_step + 5] = rgb_buffer[5] = AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
00076
00077
00078
00079
00080
00081
00082 rgb_buffer[rgb_line_step + 3] = rgb_buffer[rgb_line_step ] = AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
00083 rgb_buffer[rgb_line_step + 1] = AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step + 1], bayer_pixel[bayer_line_step2]);
00084
00085
00086
00087
00088
00089
00090
00091 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
00092
00093
00094 rgb_buffer += 6;
00095 bayer_pixel += 2;
00096
00097 for (xIdx = 2; xIdx < width - 2; xIdx += 2, rgb_buffer += 6, bayer_pixel += 2)
00098 {
00099
00100
00101
00102
00103
00104 rgb_buffer[0] = AVG (bayer_pixel[1], bayer_pixel[-1]);
00105 rgb_buffer[1] = bayer_pixel[0];
00106 rgb_buffer[2] = bayer_pixel[bayer_line_step + 1];
00107
00108
00109
00110
00111
00112 rgb_buffer[3] = bayer_pixel[1];
00113 rgb_buffer[4] = AVG3 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1]);
00114 rgb_buffer[rgb_line_step + 5] = rgb_buffer[5] = AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
00115
00116
00117
00118
00119
00120
00121 rgb_buffer[rgb_line_step ] = AVG4 (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1], bayer_pixel[-1], bayer_pixel[bayer_line_step2 - 1]);
00122 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]);
00123 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
00124
00125
00126
00127
00128
00129 rgb_buffer[rgb_line_step + 3] = AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
00130 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
00131
00132 }
00133
00134
00135
00136
00137
00138
00139
00140 rgb_buffer[0] = AVG (bayer_pixel[1], bayer_pixel[-1]);
00141 rgb_buffer[1] = bayer_pixel[0];
00142 rgb_buffer[rgb_line_step + 5] = rgb_buffer[rgb_line_step + 2] = rgb_buffer[5] = rgb_buffer[2] = bayer_pixel[bayer_line_step];
00143
00144
00145
00146
00147
00148 rgb_buffer[3] = bayer_pixel[1];
00149 rgb_buffer[4] = AVG (bayer_pixel[0], bayer_pixel[bayer_line_step + 1]);
00150
00151
00152
00153
00154
00155
00156
00157 rgb_buffer[rgb_line_step ] = AVG4 (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1], bayer_pixel[-1], bayer_pixel[bayer_line_step2 - 1]);
00158 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]);
00159
00160
00161
00162
00163
00164
00165 rgb_buffer[rgb_line_step + 3] = AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
00166 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
00167
00168
00169 bayer_pixel += bayer_line_step + 2;
00170 rgb_buffer += rgb_line_step + 6 + rgb_line_skip;
00171
00172 for (yIdx = 2; yIdx < height - 2; yIdx += 2)
00173 {
00174
00175
00176
00177
00178
00179
00180
00181 rgb_buffer[3] = rgb_buffer[0] = bayer_pixel[1];
00182 rgb_buffer[1] = bayer_pixel[0];
00183 rgb_buffer[2] = AVG (bayer_pixel[bayer_line_step], bayer_pixel[-bayer_line_step]);
00184
00185
00186
00187
00188
00189
00190
00191 rgb_buffer[4] = AVG4 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1], bayer_pixel[1 - bayer_line_step]);
00192 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]);
00193
00194
00195
00196
00197
00198
00199 rgb_buffer[rgb_line_step + 3] = rgb_buffer[rgb_line_step ] = AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
00200 rgb_buffer[rgb_line_step + 1] = AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step + 1], bayer_pixel[bayer_line_step2]);
00201 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
00202
00203
00204
00205
00206
00207
00208 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
00209 rgb_buffer[rgb_line_step + 5] = AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
00210
00211 rgb_buffer += 6;
00212 bayer_pixel += 2;
00213
00214 for (xIdx = 2; xIdx < width - 2; xIdx += 2, rgb_buffer += 6, bayer_pixel += 2)
00215 {
00216
00217
00218
00219
00220
00221
00222 rgb_buffer[0] = AVG (bayer_pixel[1], bayer_pixel[-1]);
00223 rgb_buffer[1] = bayer_pixel[0];
00224 rgb_buffer[2] = AVG (bayer_pixel[bayer_line_step], bayer_pixel[-bayer_line_step]);
00225
00226
00227
00228
00229
00230
00231
00232 dh = abs (bayer_pixel[0] - bayer_pixel[2]);
00233 dv = abs (bayer_pixel[-bayer_line_step + 1] - bayer_pixel[bayer_line_step + 1]);
00234
00235 if (dh > dv)
00236 rgb_buffer[4] = AVG (bayer_pixel[-bayer_line_step + 1], bayer_pixel[bayer_line_step + 1]);
00237 else if (dv > dh)
00238 rgb_buffer[4] = AVG (bayer_pixel[0], bayer_pixel[2]);
00239 else
00240 rgb_buffer[4] = AVG4 (bayer_pixel[-bayer_line_step + 1], bayer_pixel[bayer_line_step + 1], bayer_pixel[0], bayer_pixel[2]);
00241
00242 rgb_buffer[3] = bayer_pixel[1];
00243 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]);
00244
00245
00246
00247
00248
00249
00250
00251 rgb_buffer[rgb_line_step ] = AVG4 (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1], bayer_pixel[-1], bayer_pixel[bayer_line_step2 - 1]);
00252 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
00253
00254 dv = abs (bayer_pixel[0] - bayer_pixel[bayer_line_step2]);
00255 dh = abs (bayer_pixel[bayer_line_step - 1] - bayer_pixel[bayer_line_step + 1]);
00256
00257 if (dv > dh)
00258 rgb_buffer[rgb_line_step + 1] = AVG (bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
00259 else if (dh > dv)
00260 rgb_buffer[rgb_line_step + 1] = AVG (bayer_pixel[0], bayer_pixel[bayer_line_step2]);
00261 else
00262 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]);
00263
00264
00265
00266
00267
00268
00269 rgb_buffer[rgb_line_step + 3] = AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
00270 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
00271 rgb_buffer[rgb_line_step + 5] = AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
00272 }
00273
00274
00275
00276
00277
00278
00279
00280
00281 rgb_buffer[0] = AVG (bayer_pixel[1], bayer_pixel[-1]);
00282 rgb_buffer[1] = bayer_pixel[0];
00283 rgb_buffer[rgb_line_step + 5] = rgb_buffer[rgb_line_step + 2] = rgb_buffer[5] = rgb_buffer[2] = bayer_pixel[bayer_line_step];
00284
00285
00286
00287
00288
00289 rgb_buffer[3] = bayer_pixel[1];
00290 rgb_buffer[4] = AVG (bayer_pixel[0], bayer_pixel[bayer_line_step + 1]);
00291
00292
00293
00294
00295
00296
00297
00298 rgb_buffer[rgb_line_step ] = AVG4 (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1], bayer_pixel[-1], bayer_pixel[bayer_line_step2 - 1]);
00299 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]);
00300
00301
00302
00303
00304
00305
00306 rgb_buffer[rgb_line_step + 3] = AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
00307 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
00308
00309
00310 bayer_pixel += bayer_line_step + 2;
00311 rgb_buffer += rgb_line_step + 6 + rgb_line_skip;
00312 }
00313
00314
00315
00316
00317
00318
00319
00320 rgb_buffer[rgb_line_step + 3] = rgb_buffer[rgb_line_step ] = rgb_buffer[3] = rgb_buffer[0] = bayer_pixel[1];
00321 rgb_buffer[1] = bayer_pixel[0];
00322 rgb_buffer[rgb_line_step + 2] = rgb_buffer[2] = bayer_pixel[bayer_line_step];
00323
00324
00325
00326
00327
00328
00329 rgb_buffer[4] = AVG4 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1], bayer_pixel[1 - bayer_line_step]);
00330 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]);
00331
00332
00333
00334
00335
00336
00337
00338 rgb_buffer[rgb_line_step + 1] = AVG (bayer_pixel[0], bayer_pixel[bayer_line_step + 1]);
00339 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
00340
00341
00342
00343
00344
00345
00346 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
00347 rgb_buffer[rgb_line_step + 5] = AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
00348
00349 rgb_buffer += 6;
00350 bayer_pixel += 2;
00351
00352 for (xIdx = 2; xIdx < width - 2; xIdx += 2, rgb_buffer += 6, bayer_pixel += 2)
00353 {
00354
00355
00356
00357
00358
00359 rgb_buffer[0] = AVG (bayer_pixel[1], bayer_pixel[-1]);
00360 rgb_buffer[1] = bayer_pixel[0];
00361 rgb_buffer[2] = AVG (bayer_pixel[bayer_line_step], bayer_pixel[-bayer_line_step]);
00362
00363
00364
00365
00366
00367 rgb_buffer[rgb_line_step + 3] = rgb_buffer[3] = bayer_pixel[1];
00368 rgb_buffer[4] = AVG4 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1], bayer_pixel[1 - bayer_line_step]);
00369 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]);
00370
00371
00372
00373
00374
00375
00376 rgb_buffer[rgb_line_step ] = AVG (bayer_pixel[-1], bayer_pixel[1]);
00377 rgb_buffer[rgb_line_step + 1] = AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
00378 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
00379
00380
00381
00382
00383
00384
00385
00386 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
00387 rgb_buffer[rgb_line_step + 5] = AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
00388 }
00389
00390
00391
00392
00393
00394
00395
00396 rgb_buffer[rgb_line_step ] = rgb_buffer[0] = AVG (bayer_pixel[1], bayer_pixel[-1]);
00397 rgb_buffer[1] = bayer_pixel[0];
00398 rgb_buffer[5] = rgb_buffer[2] = AVG (bayer_pixel[bayer_line_step], bayer_pixel[-bayer_line_step]);
00399
00400
00401
00402
00403
00404 rgb_buffer[rgb_line_step + 3] = rgb_buffer[3] = bayer_pixel[1];
00405 rgb_buffer[4] = AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step + 1], bayer_pixel[-bayer_line_step + 1]);
00406
00407
00408
00409
00410
00411
00412
00413
00414 rgb_buffer[rgb_line_step + 1] = AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
00415 rgb_buffer[rgb_line_step + 5] = rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
00416
00417
00418
00419
00420
00421
00422 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
00423
00424 }
00425
00426 void debayerEdgeAwareWeighted(const cv::Mat& bayer, cv::Mat& color)
00427 {
00428 unsigned width = bayer.cols;
00429 unsigned height = bayer.rows;
00430 unsigned rgb_line_step = color.step[0];
00431 unsigned rgb_line_skip = rgb_line_step - width * 3;
00432 int bayer_line_step = bayer.step[0];
00433 int bayer_line_step2 = bayer_line_step * 2;
00434
00435 unsigned char* rgb_buffer = color.data;
00436 unsigned char* bayer_pixel = bayer.data;
00437 unsigned yIdx, xIdx;
00438
00439 int dh, dv;
00440
00441
00442
00443
00444
00445
00446
00447 rgb_buffer[3] = rgb_buffer[0] = bayer_pixel[1];
00448 rgb_buffer[1] = bayer_pixel[0];
00449 rgb_buffer[rgb_line_step + 2] = rgb_buffer[2] = bayer_pixel[bayer_line_step];
00450
00451
00452
00453
00454
00455
00456 rgb_buffer[4] = AVG3 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1]);
00457 rgb_buffer[rgb_line_step + 5] = rgb_buffer[5] = AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
00458
00459
00460
00461
00462
00463
00464 rgb_buffer[rgb_line_step + 3] = rgb_buffer[rgb_line_step ] = AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
00465 rgb_buffer[rgb_line_step + 1] = AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step + 1], bayer_pixel[bayer_line_step2]);
00466
00467
00468
00469
00470
00471
00472
00473 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
00474
00475
00476 rgb_buffer += 6;
00477 bayer_pixel += 2;
00478
00479 for (xIdx = 2; xIdx < width - 2; xIdx += 2, rgb_buffer += 6, bayer_pixel += 2)
00480 {
00481
00482
00483
00484
00485
00486 rgb_buffer[0] = AVG (bayer_pixel[1], bayer_pixel[-1]);
00487 rgb_buffer[1] = bayer_pixel[0];
00488 rgb_buffer[2] = bayer_pixel[bayer_line_step + 1];
00489
00490
00491
00492
00493
00494 rgb_buffer[3] = bayer_pixel[1];
00495 rgb_buffer[4] = AVG3 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1]);
00496 rgb_buffer[rgb_line_step + 5] = rgb_buffer[5] = AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
00497
00498
00499
00500
00501
00502
00503 rgb_buffer[rgb_line_step ] = AVG4 (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1], bayer_pixel[-1], bayer_pixel[bayer_line_step2 - 1]);
00504 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]);
00505 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
00506
00507
00508
00509
00510
00511 rgb_buffer[rgb_line_step + 3] = AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
00512 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
00513
00514 }
00515
00516
00517
00518
00519
00520
00521
00522 rgb_buffer[0] = AVG (bayer_pixel[1], bayer_pixel[-1]);
00523 rgb_buffer[1] = bayer_pixel[0];
00524 rgb_buffer[rgb_line_step + 5] = rgb_buffer[rgb_line_step + 2] = rgb_buffer[5] = rgb_buffer[2] = bayer_pixel[bayer_line_step];
00525
00526
00527
00528
00529
00530 rgb_buffer[3] = bayer_pixel[1];
00531 rgb_buffer[4] = AVG (bayer_pixel[0], bayer_pixel[bayer_line_step + 1]);
00532
00533
00534
00535
00536
00537
00538
00539 rgb_buffer[rgb_line_step ] = AVG4 (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1], bayer_pixel[-1], bayer_pixel[bayer_line_step2 - 1]);
00540 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]);
00541
00542
00543
00544
00545
00546
00547 rgb_buffer[rgb_line_step + 3] = AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
00548 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
00549
00550
00551 bayer_pixel += bayer_line_step + 2;
00552 rgb_buffer += rgb_line_step + 6 + rgb_line_skip;
00553
00554 for (yIdx = 2; yIdx < height - 2; yIdx += 2)
00555 {
00556
00557
00558
00559
00560
00561
00562
00563 rgb_buffer[3] = rgb_buffer[0] = bayer_pixel[1];
00564 rgb_buffer[1] = bayer_pixel[0];
00565 rgb_buffer[2] = AVG (bayer_pixel[bayer_line_step], bayer_pixel[-bayer_line_step]);
00566
00567
00568
00569
00570
00571
00572
00573 rgb_buffer[4] = AVG4 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1], bayer_pixel[1 - bayer_line_step]);
00574 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]);
00575
00576
00577
00578
00579
00580
00581 rgb_buffer[rgb_line_step + 3] = rgb_buffer[rgb_line_step ] = AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
00582 rgb_buffer[rgb_line_step + 1] = AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step + 1], bayer_pixel[bayer_line_step2]);
00583 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
00584
00585
00586
00587
00588
00589
00590 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
00591 rgb_buffer[rgb_line_step + 5] = AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
00592
00593 rgb_buffer += 6;
00594 bayer_pixel += 2;
00595
00596 for (xIdx = 2; xIdx < width - 2; xIdx += 2, rgb_buffer += 6, bayer_pixel += 2)
00597 {
00598
00599
00600
00601
00602
00603
00604 rgb_buffer[0] = AVG (bayer_pixel[1], bayer_pixel[-1]);
00605 rgb_buffer[1] = bayer_pixel[0];
00606 rgb_buffer[2] = AVG (bayer_pixel[bayer_line_step], bayer_pixel[-bayer_line_step]);
00607
00608
00609
00610
00611
00612
00613
00614 dh = abs (bayer_pixel[0] - bayer_pixel[2]);
00615 dv = abs (bayer_pixel[-bayer_line_step + 1] - bayer_pixel[bayer_line_step + 1]);
00616
00617 if (dv == 0 && dh == 0)
00618 rgb_buffer[4] = AVG4 (bayer_pixel[1 - bayer_line_step], bayer_pixel[1 + bayer_line_step], bayer_pixel[0], bayer_pixel[2]);
00619 else
00620 rgb_buffer[4] = WAVG4 (bayer_pixel[1 - bayer_line_step], bayer_pixel[1 + bayer_line_step], bayer_pixel[0], bayer_pixel[2], dh, dv);
00621 rgb_buffer[3] = bayer_pixel[1];
00622 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]);
00623
00624
00625
00626
00627
00628
00629
00630 rgb_buffer[rgb_line_step ] = AVG4 (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1], bayer_pixel[-1], bayer_pixel[bayer_line_step2 - 1]);
00631 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
00632
00633 dv = abs (bayer_pixel[0] - bayer_pixel[bayer_line_step2]);
00634 dh = abs (bayer_pixel[bayer_line_step - 1] - bayer_pixel[bayer_line_step + 1]);
00635
00636 if (dv == 0 && dh == 0)
00637 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]);
00638 else
00639 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);
00640
00641
00642
00643
00644
00645
00646 rgb_buffer[rgb_line_step + 3] = AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
00647 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
00648 rgb_buffer[rgb_line_step + 5] = AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
00649 }
00650
00651
00652
00653
00654
00655
00656
00657
00658 rgb_buffer[0] = AVG (bayer_pixel[1], bayer_pixel[-1]);
00659 rgb_buffer[1] = bayer_pixel[0];
00660 rgb_buffer[rgb_line_step + 5] = rgb_buffer[rgb_line_step + 2] = rgb_buffer[5] = rgb_buffer[2] = bayer_pixel[bayer_line_step];
00661
00662
00663
00664
00665
00666 rgb_buffer[3] = bayer_pixel[1];
00667 rgb_buffer[4] = AVG (bayer_pixel[0], bayer_pixel[bayer_line_step + 1]);
00668
00669
00670
00671
00672
00673
00674
00675 rgb_buffer[rgb_line_step ] = AVG4 (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1], bayer_pixel[-1], bayer_pixel[bayer_line_step2 - 1]);
00676 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]);
00677
00678
00679
00680
00681
00682
00683 rgb_buffer[rgb_line_step + 3] = AVG (bayer_pixel[1], bayer_pixel[bayer_line_step2 + 1]);
00684 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
00685
00686
00687 bayer_pixel += bayer_line_step + 2;
00688 rgb_buffer += rgb_line_step + 6 + rgb_line_skip;
00689 }
00690
00691
00692
00693
00694
00695
00696
00697 rgb_buffer[rgb_line_step + 3] = rgb_buffer[rgb_line_step ] = rgb_buffer[3] = rgb_buffer[0] = bayer_pixel[1];
00698 rgb_buffer[1] = bayer_pixel[0];
00699 rgb_buffer[rgb_line_step + 2] = rgb_buffer[2] = bayer_pixel[bayer_line_step];
00700
00701
00702
00703
00704
00705
00706 rgb_buffer[4] = AVG4 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1], bayer_pixel[1 - bayer_line_step]);
00707 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]);
00708
00709
00710
00711
00712
00713
00714
00715 rgb_buffer[rgb_line_step + 1] = AVG (bayer_pixel[0], bayer_pixel[bayer_line_step + 1]);
00716 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
00717
00718
00719
00720
00721
00722
00723 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
00724 rgb_buffer[rgb_line_step + 5] = AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
00725
00726 rgb_buffer += 6;
00727 bayer_pixel += 2;
00728
00729 for (xIdx = 2; xIdx < width - 2; xIdx += 2, rgb_buffer += 6, bayer_pixel += 2)
00730 {
00731
00732
00733
00734
00735
00736 rgb_buffer[0] = AVG (bayer_pixel[1], bayer_pixel[-1]);
00737 rgb_buffer[1] = bayer_pixel[0];
00738 rgb_buffer[2] = AVG (bayer_pixel[bayer_line_step], bayer_pixel[-bayer_line_step]);
00739
00740
00741
00742
00743
00744 rgb_buffer[rgb_line_step + 3] = rgb_buffer[3] = bayer_pixel[1];
00745 rgb_buffer[4] = AVG4 (bayer_pixel[0], bayer_pixel[2], bayer_pixel[bayer_line_step + 1], bayer_pixel[1 - bayer_line_step]);
00746 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]);
00747
00748
00749
00750
00751
00752
00753 rgb_buffer[rgb_line_step ] = AVG (bayer_pixel[-1], bayer_pixel[1]);
00754 rgb_buffer[rgb_line_step + 1] = AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
00755 rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
00756
00757
00758
00759
00760
00761
00762
00763 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
00764 rgb_buffer[rgb_line_step + 5] = AVG (bayer_pixel[bayer_line_step], bayer_pixel[bayer_line_step + 2]);
00765 }
00766
00767
00768
00769
00770
00771
00772
00773 rgb_buffer[rgb_line_step ] = rgb_buffer[0] = AVG (bayer_pixel[1], bayer_pixel[-1]);
00774 rgb_buffer[1] = bayer_pixel[0];
00775 rgb_buffer[5] = rgb_buffer[2] = AVG (bayer_pixel[bayer_line_step], bayer_pixel[-bayer_line_step]);
00776
00777
00778
00779
00780
00781 rgb_buffer[rgb_line_step + 3] = rgb_buffer[3] = bayer_pixel[1];
00782 rgb_buffer[4] = AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step + 1], bayer_pixel[-bayer_line_step + 1]);
00783
00784
00785
00786
00787
00788
00789
00790
00791 rgb_buffer[rgb_line_step + 1] = AVG3 (bayer_pixel[0], bayer_pixel[bayer_line_step - 1], bayer_pixel[bayer_line_step + 1]);
00792 rgb_buffer[rgb_line_step + 5] = rgb_buffer[rgb_line_step + 2] = bayer_pixel[bayer_line_step];
00793
00794
00795
00796
00797
00798
00799 rgb_buffer[rgb_line_step + 4] = bayer_pixel[bayer_line_step + 1];
00800
00801
00802 }
00803
00804 }