00001
00007 #include "edtinc.h"
00008 #include "pdv_interlace_methods.h"
00009
00010 #include <math.h>
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #define PDV_BAYER_ORDER_BGGR 0
00025 #define PDV_BAYER_ORDER_GBRG 1
00026 #define PDV_BAYER_ORDER_RGGB 2
00027 #define PDV_BAYER_ORDER_GRBG 3
00028
00029 #define PDV_BAYER_ORDER(dd_p) ((((Dependent *) dd_p)->kbs_red_row_first << 1) \
00030 | ((Dependent *) dd_p)->kbs_green_pixel_first)
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 u_char * pdv_red_lut = NULL;
00042 u_char * pdv_green_lut = NULL;
00043 u_char * pdv_blue_lut = NULL;
00044
00045
00046 #define USING_LUTS
00047
00048 #ifdef USING_LUTS
00049
00050 #define RED_LUT(x) pdv_red_lut[(x)]
00051 #define GREEN_LUT(x) pdv_green_lut[(x)]
00052 #define BLUE_LUT(x) pdv_blue_lut[(x)]
00053
00054 #else
00055
00056 #define RED_LUT(x) (u_char)(x)
00057 #define GREEN_LUT(x) (u_char)(x)
00058 #define BLUE_LUT(x) (u_char)(x)
00059
00060 #endif
00061
00062 int bayer_current_base_size = 0;
00063
00064 double default_rgb_scale[3] = {1.0, 1.0, 1.0};
00065 double bayer_rgb_scale[3] = {1.0, 1.0, 1.0};
00066
00067 double bayer_even_row_scale = 1.0, bayer_odd_row_scale = 1.0;
00068
00069 int bayer_red_first = 0;
00070 int bayer_green_first = 0;
00071
00072 static void allocate_luts(int outsize)
00073
00074
00075 {
00076
00077
00078
00079 pdv_red_lut = edt_alloc(outsize);
00080 pdv_green_lut = edt_alloc(outsize);
00081 pdv_blue_lut = edt_alloc(outsize);
00082
00083 bayer_current_base_size = outsize;
00084
00085
00086 }
00087
00088 void get_bayer_luts(u_char **red, u_char **green, u_char **blue)
00089
00090 {
00091
00092 if (!pdv_red_lut)
00093 allocate_luts(256);
00094
00095 *red = pdv_red_lut;
00096 *green = pdv_green_lut;
00097 *blue = pdv_blue_lut;
00098 }
00099
00100 u_char
00101 byte_gamma_function(double val, double scale, double gamma, int blackoffset)
00102
00103 {
00104 double v = val;
00105
00106 v -= blackoffset;
00107
00108 if (v < 0)
00109 v = 0;
00110
00111 v = 255 * pow((double) (scale * v) / 255.0, 1.0 / gamma);
00112
00113 if (v > 255)
00114 v = 255;
00115
00116 return (u_char) v;
00117
00118 }
00119
00120
00121 void
00122 set_bayer_parameters(int input_bits,
00123 double rgb_scale[3],
00124 double gamma,
00125 int blackoffset,
00126 int red_row_first,
00127 int green_pixel_first)
00128
00129 {
00130
00131 int base_size = 256;
00132
00133 double maxvalue;
00134 double delta;
00135 double val = 0;
00136 u_char rval, gval, bval;
00137 int i;
00138
00139 #ifndef USE_MMX
00140
00141 base_size = 1 << input_bits;
00142
00143 #endif
00144
00145 maxvalue = base_size;
00146 delta = (1.0 / maxvalue) * 256;
00147
00148 bayer_red_first = red_row_first;
00149 bayer_green_first = green_pixel_first;
00150
00151 if (gamma <= 0)
00152 gamma = 1.0;
00153
00154 for (i = 0; i < 3; i++)
00155 bayer_rgb_scale[i] = rgb_scale[i];
00156
00157 if (!pdv_red_lut)
00158 allocate_luts(base_size);
00159
00160 for (i = 0; i < base_size; i++)
00161 {
00162 rval = byte_gamma_function(val, rgb_scale[0], gamma, blackoffset);
00163 gval = byte_gamma_function(val, rgb_scale[1], gamma, blackoffset);
00164 bval = byte_gamma_function(val, rgb_scale[2], gamma, blackoffset);
00165
00166 pdv_red_lut[i] = rval;
00167 pdv_green_lut[i] = gval;
00168 pdv_blue_lut[i] = bval;
00169
00170 val += delta;
00171
00172 }
00173
00174
00175 #ifdef USE_MMX
00176
00177 if (bayer_can_use_mmx())
00178 set_bayer_parameters_mmx(input_bits,
00179 rgb_scale,
00180 gamma,
00181 blackoffset,
00182 red_row_first,
00183 green_pixel_first);
00184
00185 #endif
00186
00187 }
00188
00236 void
00237 pdv_set_full_bayer_parameters(int nSourceDepth,
00238 double scale[3],
00239 double gamma,
00240 int nBlackOffset,
00241 int bRedRowFirst,
00242 int bGreenPixelFirst,
00243 int quality,
00244 int bias,
00245 int gradientcolor)
00246
00247 {
00248 set_bayer_parameters(nSourceDepth,
00249 scale,
00250 gamma,
00251 nBlackOffset,
00252 bRedRowFirst,
00253 bGreenPixelFirst);
00254
00255
00256 #ifdef USE_MMX
00257
00258
00259 set_bayer_quality(quality);
00260 set_bayer_gradient_color(gradientcolor);
00261
00262 set_bayer_bias_value(bias);
00263 #endif
00264
00265 }
00266
00267 void
00268 set_bayer_even_odd_row_scale(double evenscale, double oddscale)
00269
00270 {
00271 bayer_even_row_scale = evenscale;
00272 bayer_odd_row_scale = oddscale;
00273
00274 }
00275
00276 void
00277 clear_bayer_parameters()
00278
00279 {
00280
00281 }
00282
00283
00284
00285 void
00286 convert_red_row_16_green(u_short * lst_p,
00287 u_short * cur_p,
00288 u_short * nxt_p,
00289 u_char * dest_p,
00290 int width)
00291
00292 {
00293 u_short *end_p = cur_p + (width - 4);
00294
00295 do
00296 {
00297
00298
00299
00300 dest_p[0] = BLUE_LUT((lst_p[0] + nxt_p[0]) >> 1);
00301 dest_p[3] = BLUE_LUT((lst_p[0] + nxt_p[0] + lst_p[2] + nxt_p[2]) >> 2);
00302 dest_p[6] = BLUE_LUT((lst_p[2] + nxt_p[2]) >> 1);
00303 dest_p[9] = BLUE_LUT((lst_p[2] + nxt_p[2] + lst_p[4] + nxt_p[4]) >> 2);
00304
00305 dest_p[1] = GREEN_LUT(cur_p[0]);
00306 dest_p[7] = GREEN_LUT(cur_p[2]);
00307 dest_p[4] = GREEN_LUT((cur_p[0] + cur_p[2] + lst_p[1] + nxt_p[1]) >> 2);
00308 dest_p[10] = GREEN_LUT((cur_p[2] + cur_p[4] + lst_p[3] + nxt_p[3]) >> 2);
00309
00310
00311
00312 dest_p[5] = RED_LUT(cur_p[1]);
00313 dest_p[11] = RED_LUT(cur_p[3]);
00314 dest_p[2] = RED_LUT((cur_p[-1] + cur_p[1]) >> 1);
00315 dest_p[8] = RED_LUT((cur_p[1] + cur_p[3]) >> 1);
00316
00317
00318 dest_p += 12;
00319 lst_p += 4;
00320 cur_p += 4;
00321 nxt_p += 4;
00322
00323 } while (cur_p < end_p);
00324
00325 }
00326
00327 void
00328 convert_red_row_16(u_short * lst_p, u_short * cur_p, u_short * nxt_p,
00329 u_char * dest_p, int width)
00330
00331 {
00332 int x;
00333
00334 for (x = 1; x < width - 4; x += 4)
00335 {
00336
00337 dest_p[0] = BLUE_LUT((lst_p[-1] + nxt_p[-1] + lst_p[1] + nxt_p[1]) >> 2);
00338 dest_p[3] = BLUE_LUT((lst_p[1] + nxt_p[1]) >> 1);
00339 dest_p[6] = BLUE_LUT((lst_p[1] + nxt_p[1] + lst_p[3] + nxt_p[3]) >> 2);
00340 dest_p[9] = BLUE_LUT((lst_p[3] + nxt_p[3]) >> 1);
00341
00342 dest_p[1] = GREEN_LUT((cur_p[-1] + cur_p[1] + lst_p[0] + nxt_p[0]) >> 2);
00343 dest_p[4] = GREEN_LUT(cur_p[1]);
00344 dest_p[7] = GREEN_LUT((cur_p[1] + cur_p[3] + lst_p[2] + nxt_p[2]) >> 2);
00345 dest_p[10] = GREEN_LUT(cur_p[3]);
00346
00347 dest_p[2] = RED_LUT(cur_p[0]);
00348 dest_p[5] = RED_LUT((cur_p[0] + cur_p[2]) >> 1);
00349 dest_p[8] = RED_LUT(cur_p[2]);
00350 dest_p[11] = RED_LUT((cur_p[2] + cur_p[4]) >> 1);
00351
00352 dest_p += 12;
00353 lst_p += 4;
00354 cur_p += 4;
00355 nxt_p += 4;
00356
00357 }
00358
00359
00360 }
00361
00362
00363 void
00364 convert_blue_row_16_green(u_short * lst_p, u_short * cur_p, u_short * nxt_p,
00365 u_char * dest_p, int width)
00366
00367 {
00368 int x;
00369
00370 for (x = 1; x < width - 4; x += 4)
00371 {
00372
00373 dest_p[0] = BLUE_LUT((cur_p[-1] + cur_p[1]) >> 1);
00374 dest_p[3] = BLUE_LUT(cur_p[1]);
00375 dest_p[6] = BLUE_LUT((cur_p[1] + cur_p[3]) >> 1);
00376 dest_p[9] = BLUE_LUT(cur_p[3]);
00377
00378 dest_p[1] = GREEN_LUT(cur_p[0]);
00379 dest_p[4] = GREEN_LUT((cur_p[0] + cur_p[2] + lst_p[1] + nxt_p[1]) >> 2);
00380 dest_p[7] = GREEN_LUT(cur_p[2]);
00381 dest_p[10] = GREEN_LUT((cur_p[2] + cur_p[4] + lst_p[3] + nxt_p[3]) >> 2);
00382
00383 dest_p[2] = RED_LUT((lst_p[0] + nxt_p[0]) >> 1);
00384 dest_p[5] = RED_LUT((lst_p[0] + nxt_p[0] + lst_p[2] + nxt_p[2]) >> 2);
00385 dest_p[8] = RED_LUT((lst_p[2] + nxt_p[2]) >> 1);
00386 dest_p[11] = RED_LUT((lst_p[2] + nxt_p[2] + lst_p[4] + nxt_p[4]) >> 2);
00387
00388 dest_p += 12;
00389 lst_p += 4;
00390 cur_p += 4;
00391 nxt_p += 4;
00392
00393 }
00394
00395 }
00396
00397
00398
00399 void
00400 convert_blue_row_16(u_short * lst_p, u_short * cur_p, u_short * nxt_p,
00401 u_char * dest_p, int width)
00402
00403 {
00404 int x;
00405
00406 for (x = 1; x < width - 4; x += 4)
00407 {
00408
00409 dest_p[0] = BLUE_LUT(cur_p[0]);
00410 dest_p[3] = BLUE_LUT((cur_p[0] + cur_p[2]) >> 1);
00411 dest_p[9] = BLUE_LUT((cur_p[2] + cur_p[4]) >> 1);
00412 dest_p[6] = BLUE_LUT(cur_p[2]);
00413 dest_p[1] = GREEN_LUT((cur_p[-1] + cur_p[1] + lst_p[0] + nxt_p[0]) >> 2);
00414 dest_p[4] = GREEN_LUT(cur_p[1]);
00415 dest_p[7] = GREEN_LUT((cur_p[1] + cur_p[3] + lst_p[2] + nxt_p[2]) >> 2);
00416 dest_p[10] = GREEN_LUT(cur_p[3]);
00417 dest_p[2] = RED_LUT((lst_p[-1] + nxt_p[-1] + lst_p[1] + nxt_p[1]) >> 2);
00418 dest_p[5] = RED_LUT((lst_p[1] + nxt_p[1]) >> 1);
00419 dest_p[8] = RED_LUT((lst_p[1] + nxt_p[1] + lst_p[3] + nxt_p[3]) >> 2);
00420 dest_p[11] = RED_LUT((lst_p[3] + nxt_p[3]) >> 1);
00421
00422 dest_p += 12;
00423 lst_p += 4;
00424 cur_p += 4;
00425 nxt_p += 4;
00426
00427 }
00428
00429 }
00430
00431
00432 int
00433 convert_bayer_image_16_BGR(u_short * src,
00434 int width, int rows, int pitch,
00435 u_char * dest,
00436 int order, int depth)
00437
00438
00439 {
00440 u_short *cur_p;
00441 u_short *nxt_p;
00442 u_short *lst_p;
00443
00444 u_char *dest_p = dest;
00445
00446 u_char red_row;
00447 u_char green_start;
00448
00449 u_char testgreen;
00450
00451 int y;
00452
00453 if (depth == 8)
00454 return convert_bayer_image_8_BGR((u_char *) src,
00455 width,rows,pitch,dest, order);
00456
00457
00458 #ifdef USE_MMX
00459
00460 if (bayer_can_use_mmx())
00461 {
00462 return convert_bayer_image_BGR_mmx((u_char *) src,
00463 width, rows, pitch,
00464 dest, 0, order, depth);
00465
00466 }
00467
00468 #endif
00469
00470
00471 if (order >= 0)
00472 {
00473 red_row = ((order & 2) != 0);
00474 green_start = ((order & 1) != 0);
00475 }
00476 else
00477 {
00478 red_row = bayer_red_first;
00479 green_start = bayer_green_first;
00480
00481 }
00482
00483 testgreen = green_start;
00484
00485 if (bayer_current_base_size == 0)
00486 {
00487
00488 set_bayer_parameters(depth,
00489 default_rgb_scale,
00490 1.0,
00491 0,
00492 red_row,
00493 green_start);
00494
00495 }
00496
00497 cur_p = src + pitch + 1;
00498 lst_p = src + 1;
00499 nxt_p = cur_p + pitch;
00500
00501 green_start = !green_start;
00502
00503 if (green_start)
00504 {
00505 if (red_row)
00506 {
00507 for (y = 1; y < rows - 1; y += 2)
00508 {
00509 convert_blue_row_16(lst_p, cur_p, nxt_p, dest_p, width);
00510 lst_p += pitch;
00511 cur_p += pitch;
00512 nxt_p += pitch;
00513 dest_p += pitch*3;
00514 convert_red_row_16_green(lst_p, cur_p, nxt_p, dest_p, width);
00515 lst_p += pitch;
00516 cur_p += pitch;
00517 nxt_p += pitch;
00518 dest_p += pitch*3;
00519
00520 }
00521 }
00522 else
00523 {
00524 for (y = 1; y < rows - 1; y += 2)
00525 {
00526 convert_red_row_16(lst_p, cur_p, nxt_p, dest_p, width);
00527 lst_p += pitch;
00528 cur_p += pitch;
00529 nxt_p += pitch;
00530 dest_p += pitch*3;
00531 convert_blue_row_16_green(lst_p, cur_p, nxt_p, dest_p, width);
00532 lst_p += pitch;
00533 cur_p += pitch;
00534 nxt_p += pitch;
00535 dest_p += pitch*3;
00536 }
00537 }
00538 }
00539 else
00540 {
00541 if (red_row)
00542 {
00543 for (y = 1; y < rows - 1; y += 2)
00544 {
00545 convert_blue_row_16_green(lst_p, cur_p, nxt_p, dest_p, width);
00546 lst_p += pitch;
00547 cur_p += pitch;
00548 nxt_p += pitch;
00549 dest_p += pitch*3;
00550 convert_red_row_16(lst_p, cur_p, nxt_p, dest_p, width);
00551 lst_p += pitch;
00552 cur_p += pitch;
00553 nxt_p += pitch;
00554 dest_p += pitch*3;
00555 }
00556 }
00557 else
00558 {
00559 for (y = 1; y < rows - 1; y += 2)
00560 {
00561 convert_red_row_16_green(lst_p, cur_p, nxt_p, dest_p, width);
00562 lst_p += pitch;
00563 cur_p += pitch;
00564 nxt_p += pitch;
00565 dest_p += pitch*3;
00566 convert_blue_row_16(lst_p, cur_p, nxt_p, dest_p, width);
00567 lst_p += pitch;
00568 cur_p += pitch;
00569 nxt_p += pitch;
00570 dest_p += pitch*3;
00571 }
00572
00573 }
00574 }
00575
00576 return (0);
00577 }
00578
00579
00580
00581 void
00582 convert_red_row_8_green(u_char * lst_p,
00583 u_char * cur_p,
00584 u_char * nxt_p,
00585 u_char * dest_p,
00586 int width)
00587
00588 {
00589 u_char *end_p = cur_p + (width - 4);
00590
00591 do
00592 {
00593
00594
00595
00596 dest_p[0] = BLUE_LUT((lst_p[0] + nxt_p[0]) >> 1);
00597 dest_p[3] = BLUE_LUT((lst_p[0] + nxt_p[0] + lst_p[2] + nxt_p[2]) >> 2);
00598 dest_p[6] = BLUE_LUT((lst_p[2] + nxt_p[2]) >> 1);
00599 dest_p[9] = BLUE_LUT((lst_p[2] + nxt_p[2] + lst_p[4] + nxt_p[4]) >> 2);
00600
00601 dest_p[1] = GREEN_LUT(cur_p[0]);
00602 dest_p[7] = GREEN_LUT(cur_p[2]);
00603 dest_p[4] = GREEN_LUT((cur_p[0] + cur_p[2] + lst_p[1] + nxt_p[1]) >> 2);
00604 dest_p[10] = GREEN_LUT((cur_p[2] + cur_p[4] + lst_p[3] + nxt_p[3]) >> 2);
00605
00606
00607
00608 dest_p[5] = RED_LUT(cur_p[1]);
00609 dest_p[11] = RED_LUT(cur_p[3]);
00610 dest_p[2] = RED_LUT((cur_p[-1] + cur_p[1]) >> 1);
00611 dest_p[8] = RED_LUT((cur_p[1] + cur_p[3]) >> 1);
00612
00613
00614 dest_p += 12;
00615 lst_p += 4;
00616 cur_p += 4;
00617 nxt_p += 4;
00618
00619 } while (cur_p < end_p);
00620
00621 }
00622
00623 void
00624 convert_red_row_8(u_char * lst_p, u_char * cur_p, u_char * nxt_p,
00625 u_char * dest_p, int width)
00626
00627 {
00628 int x;
00629
00630 for (x = 1; x < width - 4; x += 4)
00631 {
00632
00633 dest_p[0] = BLUE_LUT((lst_p[-1] + nxt_p[-1] + lst_p[1] + nxt_p[1]) >> 2);
00634 dest_p[3] = BLUE_LUT((lst_p[1] + nxt_p[1]) >> 1);
00635 dest_p[6] = BLUE_LUT((lst_p[1] + nxt_p[1] + lst_p[3] + nxt_p[3]) >> 2);
00636 dest_p[9] = BLUE_LUT((lst_p[3] + nxt_p[3]) >> 1);
00637
00638 dest_p[1] = GREEN_LUT((cur_p[-1] + cur_p[1] + lst_p[0] + nxt_p[0]) >> 2);
00639 dest_p[4] = GREEN_LUT(cur_p[1]);
00640 dest_p[7] = GREEN_LUT((cur_p[1] + cur_p[3] + lst_p[2] + nxt_p[2]) >> 2);
00641 dest_p[10] = GREEN_LUT(cur_p[3]);
00642
00643 dest_p[2] = RED_LUT(cur_p[0]);
00644 dest_p[5] = RED_LUT((cur_p[0] + cur_p[2]) >> 1);
00645 dest_p[8] = RED_LUT(cur_p[2]);
00646 dest_p[11] = RED_LUT((cur_p[2] + cur_p[4]) >> 1);
00647
00648 dest_p += 12;
00649 lst_p += 4;
00650 cur_p += 4;
00651 nxt_p += 4;
00652
00653 }
00654
00655
00656 }
00657
00658
00659 void
00660 convert_blue_row_8_green(u_char * lst_p, u_char * cur_p, u_char * nxt_p,
00661 u_char * dest_p, int width)
00662
00663 {
00664 int x;
00665
00666 for (x = 1; x < width - 4; x += 4)
00667 {
00668
00669 dest_p[0] = BLUE_LUT((cur_p[-1] + cur_p[1]) >> 1);
00670 dest_p[3] = BLUE_LUT(cur_p[1]);
00671 dest_p[6] = BLUE_LUT((cur_p[1] + cur_p[3]) >> 1);
00672 dest_p[9] = BLUE_LUT(cur_p[3]);
00673
00674 dest_p[1] = GREEN_LUT(cur_p[0]);
00675 dest_p[4] = GREEN_LUT((cur_p[0] + cur_p[2] + lst_p[1] + nxt_p[1]) >> 2);
00676 dest_p[7] = GREEN_LUT(cur_p[2]);
00677 dest_p[10] = GREEN_LUT((cur_p[2] + cur_p[4] + lst_p[3] + nxt_p[3]) >> 2);
00678
00679 dest_p[2] = RED_LUT((lst_p[0] + nxt_p[0]) >> 1);
00680 dest_p[5] = RED_LUT((lst_p[0] + nxt_p[0] + lst_p[2] + nxt_p[2]) >> 2);
00681 dest_p[8] = RED_LUT((lst_p[2] + nxt_p[2]) >> 1);
00682 dest_p[11] = RED_LUT((lst_p[2] + nxt_p[2] + lst_p[4] + nxt_p[4]) >> 2);
00683
00684 dest_p += 12;
00685 lst_p += 4;
00686 cur_p += 4;
00687 nxt_p += 4;
00688
00689 }
00690
00691 }
00692
00693
00694
00695 void
00696 convert_blue_row_8(u_char * lst_p, u_char * cur_p, u_char * nxt_p,
00697 u_char * dest_p, int width)
00698
00699 {
00700 int x;
00701
00702 for (x = 1; x < width - 4; x += 4)
00703 {
00704
00705 dest_p[0] = BLUE_LUT(cur_p[0]);
00706 dest_p[3] = BLUE_LUT((cur_p[0] + cur_p[2]) >> 1);
00707 dest_p[9] = BLUE_LUT((cur_p[2] + cur_p[4]) >> 1);
00708 dest_p[6] = BLUE_LUT(cur_p[2]);
00709 dest_p[1] = GREEN_LUT((cur_p[-1] + cur_p[1] + lst_p[0] + nxt_p[0]) >> 2);
00710 dest_p[4] = GREEN_LUT(cur_p[1]);
00711 dest_p[7] = GREEN_LUT((cur_p[1] + cur_p[3] + lst_p[2] + nxt_p[2]) >> 2);
00712 dest_p[10] = GREEN_LUT(cur_p[3]);
00713 dest_p[2] = RED_LUT((lst_p[-1] + nxt_p[-1] + lst_p[1] + nxt_p[1]) >> 2);
00714 dest_p[5] = RED_LUT((lst_p[1] + nxt_p[1]) >> 1);
00715 dest_p[8] = RED_LUT((lst_p[1] + nxt_p[1] + lst_p[3] + nxt_p[3]) >> 2);
00716 dest_p[11] = RED_LUT((lst_p[3] + nxt_p[3]) >> 1);
00717
00718 dest_p += 12;
00719 lst_p += 4;
00720 cur_p += 4;
00721 nxt_p += 4;
00722
00723 }
00724
00725 }
00726
00727 int
00728 convert_bayer_image_8_BGR(u_char * src,
00729 int width, int rows, int pitch,
00730 u_char * dest,
00731 int order)
00732
00733
00734 {
00735 u_char *cur_p;
00736 u_char *nxt_p;
00737 u_char *lst_p;
00738
00739 u_char *dest_p = dest;
00740
00741 u_char red_row;
00742 u_char green_start;
00743
00744 u_char testgreen;
00745
00746 int y;
00747
00748 #ifdef USE_MMX
00749
00750 if (bayer_can_use_mmx())
00751 {
00752 return convert_bayer_image_BGR_mmx((u_char *) src,
00753 width, rows, pitch,
00754 dest, 0, order, 8);
00755
00756 }
00757
00758 #endif
00759
00760 if (order >= 0)
00761 {
00762 red_row = ((order & 2) != 0);
00763 green_start = ((order & 1) != 0);
00764 }
00765 else
00766 {
00767 red_row = bayer_red_first;
00768 green_start = bayer_green_first;
00769
00770 }
00771
00772 testgreen = green_start;
00773
00774 if (bayer_current_base_size == 0)
00775 {
00776
00777 set_bayer_parameters(8,
00778 default_rgb_scale,
00779 1.0,
00780 0,
00781 red_row,
00782 green_start);
00783
00784 }
00785
00786
00787 cur_p = src + pitch + 1;
00788 lst_p = src + 1;
00789 nxt_p = cur_p + pitch;
00790
00791 green_start = !green_start;
00792
00793 if (green_start)
00794 {
00795 if (red_row)
00796 {
00797 for (y = 1; y < rows - 1; y += 2)
00798 {
00799 convert_blue_row_8(lst_p, cur_p, nxt_p, dest_p, width);
00800 lst_p += pitch;
00801 cur_p += pitch;
00802 nxt_p += pitch;
00803 dest_p += pitch*3;
00804 convert_red_row_8_green(lst_p, cur_p, nxt_p, dest_p, width);
00805 lst_p += pitch;
00806 cur_p += pitch;
00807 nxt_p += pitch;
00808 dest_p += pitch*3;
00809
00810 }
00811 }
00812 else
00813 {
00814 for (y = 1; y < rows - 1; y += 2)
00815 {
00816 convert_red_row_8(lst_p, cur_p, nxt_p, dest_p, width);
00817 lst_p += pitch;
00818 cur_p += pitch;
00819 nxt_p += pitch;
00820 dest_p += pitch*3;
00821 convert_blue_row_8_green(lst_p, cur_p, nxt_p, dest_p, width);
00822 lst_p += pitch;
00823 cur_p += pitch;
00824 nxt_p += pitch;
00825 dest_p += pitch*3;
00826 }
00827 }
00828 }
00829 else
00830 {
00831 if (red_row)
00832 {
00833 for (y = 1; y < rows - 1; y += 2)
00834 {
00835 convert_blue_row_8_green(lst_p, cur_p, nxt_p, dest_p, width);
00836 lst_p += pitch;
00837 cur_p += pitch;
00838 nxt_p += pitch;
00839 dest_p += pitch*3;
00840 convert_red_row_8(lst_p, cur_p, nxt_p, dest_p, width);
00841 lst_p += pitch;
00842 cur_p += pitch;
00843 nxt_p += pitch;
00844 dest_p += pitch*3;
00845 }
00846 }
00847 else
00848 {
00849 for (y = 1; y < rows - 1; y += 2)
00850 {
00851 convert_red_row_8_green(lst_p, cur_p, nxt_p, dest_p, width);
00852 lst_p += pitch;
00853 cur_p += pitch;
00854 nxt_p += pitch;
00855 dest_p += pitch*3;
00856 convert_blue_row_8(lst_p, cur_p, nxt_p, dest_p, width);
00857 lst_p += pitch;
00858 cur_p += pitch;
00859 nxt_p += pitch;
00860 dest_p += pitch*3;
00861 }
00862
00863 }
00864 }
00865
00866
00867 return (0);
00868 }
00869