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