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 u_char *dest_nxt_p = dest + pitch*3;
00446
00447 u_char red_row;
00448 u_char green_start;
00449
00450 u_char testgreen;
00451
00452 int y;
00453
00454 if (depth == 8)
00455 return convert_bayer_image_8_BGR((u_char *) src,
00456 width,rows,pitch,dest, order);
00457
00458
00459 #ifdef USE_MMX
00460
00461 if (bayer_can_use_mmx())
00462 {
00463 return convert_bayer_image_BGR_mmx((u_char *) src,
00464 width, rows, pitch,
00465 dest, 0, order, depth);
00466
00467 }
00468
00469 #endif
00470
00471
00472 if (order >= 0)
00473 {
00474 red_row = ((order & 2) != 0);
00475 green_start = ((order & 1) != 0);
00476 }
00477 else
00478 {
00479 red_row = bayer_red_first;
00480 green_start = bayer_green_first;
00481
00482 }
00483
00484 testgreen = green_start;
00485
00486 if (bayer_current_base_size == 0)
00487 {
00488
00489 set_bayer_parameters(depth,
00490 default_rgb_scale,
00491 1.0,
00492 0,
00493 red_row,
00494 green_start);
00495
00496 }
00497
00498 cur_p = src + pitch + 1;
00499 lst_p = src + 1;
00500 nxt_p = cur_p + pitch;
00501
00502 green_start = !green_start;
00503
00504 if (green_start)
00505 {
00506 if (red_row)
00507 {
00508 for (y = 1; y < rows - 1; y += 2)
00509 {
00510 convert_blue_row_16(lst_p, cur_p, nxt_p, dest_p, width);
00511 lst_p += pitch;
00512 cur_p += pitch;
00513 nxt_p += pitch;
00514 dest_p += pitch*3;
00515 convert_red_row_16_green(lst_p, cur_p, nxt_p, dest_p, width);
00516 lst_p += pitch;
00517 cur_p += pitch;
00518 nxt_p += pitch;
00519 dest_p += pitch*3;
00520
00521 }
00522 }
00523 else
00524 {
00525 for (y = 1; y < rows - 1; y += 2)
00526 {
00527 convert_red_row_16(lst_p, cur_p, nxt_p, dest_p, width);
00528 lst_p += pitch;
00529 cur_p += pitch;
00530 nxt_p += pitch;
00531 dest_p += pitch*3;
00532 convert_blue_row_16_green(lst_p, cur_p, nxt_p, dest_p, width);
00533 lst_p += pitch;
00534 cur_p += pitch;
00535 nxt_p += pitch;
00536 dest_p += pitch*3;
00537 }
00538 }
00539 }
00540 else
00541 {
00542 if (red_row)
00543 {
00544 for (y = 1; y < rows - 1; y += 2)
00545 {
00546 convert_blue_row_16_green(lst_p, cur_p, nxt_p, dest_p, width);
00547 lst_p += pitch;
00548 cur_p += pitch;
00549 nxt_p += pitch;
00550 dest_p += pitch*3;
00551 convert_red_row_16(lst_p, cur_p, nxt_p, dest_p, width);
00552 lst_p += pitch;
00553 cur_p += pitch;
00554 nxt_p += pitch;
00555 dest_p += pitch*3;
00556 }
00557 }
00558 else
00559 {
00560 for (y = 1; y < rows - 1; y += 2)
00561 {
00562 convert_red_row_16_green(lst_p, cur_p, nxt_p, dest_p, width);
00563 lst_p += pitch;
00564 cur_p += pitch;
00565 nxt_p += pitch;
00566 dest_p += pitch*3;
00567 convert_blue_row_16(lst_p, cur_p, nxt_p, dest_p, width);
00568 lst_p += pitch;
00569 cur_p += pitch;
00570 nxt_p += pitch;
00571 dest_p += pitch*3;
00572 }
00573
00574 }
00575 }
00576
00577 return (0);
00578 }
00579
00580
00581
00582 void
00583 convert_red_row_8_green(u_char * lst_p,
00584 u_char * cur_p,
00585 u_char * nxt_p,
00586 u_char * dest_p,
00587 int width)
00588
00589 {
00590 u_char *end_p = cur_p + (width - 4);
00591
00592 do
00593 {
00594
00595
00596
00597 dest_p[0] = BLUE_LUT((lst_p[0] + nxt_p[0]) >> 1);
00598 dest_p[3] = BLUE_LUT((lst_p[0] + nxt_p[0] + lst_p[2] + nxt_p[2]) >> 2);
00599 dest_p[6] = BLUE_LUT((lst_p[2] + nxt_p[2]) >> 1);
00600 dest_p[9] = BLUE_LUT((lst_p[2] + nxt_p[2] + lst_p[4] + nxt_p[4]) >> 2);
00601
00602 dest_p[1] = GREEN_LUT(cur_p[0]);
00603 dest_p[7] = GREEN_LUT(cur_p[2]);
00604 dest_p[4] = GREEN_LUT((cur_p[0] + cur_p[2] + lst_p[1] + nxt_p[1]) >> 2);
00605 dest_p[10] = GREEN_LUT((cur_p[2] + cur_p[4] + lst_p[3] + nxt_p[3]) >> 2);
00606
00607
00608
00609 dest_p[5] = RED_LUT(cur_p[1]);
00610 dest_p[11] = RED_LUT(cur_p[3]);
00611 dest_p[2] = RED_LUT((cur_p[-1] + cur_p[1]) >> 1);
00612 dest_p[8] = RED_LUT((cur_p[1] + cur_p[3]) >> 1);
00613
00614
00615 dest_p += 12;
00616 lst_p += 4;
00617 cur_p += 4;
00618 nxt_p += 4;
00619
00620 } while (cur_p < end_p);
00621
00622 }
00623
00624 void
00625 convert_red_row_8(u_char * lst_p, u_char * cur_p, u_char * nxt_p,
00626 u_char * dest_p, int width)
00627
00628 {
00629 int x;
00630
00631 for (x = 1; x < width - 4; x += 4)
00632 {
00633
00634 dest_p[0] = BLUE_LUT((lst_p[-1] + nxt_p[-1] + lst_p[1] + nxt_p[1]) >> 2);
00635 dest_p[3] = BLUE_LUT((lst_p[1] + nxt_p[1]) >> 1);
00636 dest_p[6] = BLUE_LUT((lst_p[1] + nxt_p[1] + lst_p[3] + nxt_p[3]) >> 2);
00637 dest_p[9] = BLUE_LUT((lst_p[3] + nxt_p[3]) >> 1);
00638
00639 dest_p[1] = GREEN_LUT((cur_p[-1] + cur_p[1] + lst_p[0] + nxt_p[0]) >> 2);
00640 dest_p[4] = GREEN_LUT(cur_p[1]);
00641 dest_p[7] = GREEN_LUT((cur_p[1] + cur_p[3] + lst_p[2] + nxt_p[2]) >> 2);
00642 dest_p[10] = GREEN_LUT(cur_p[3]);
00643
00644 dest_p[2] = RED_LUT(cur_p[0]);
00645 dest_p[5] = RED_LUT((cur_p[0] + cur_p[2]) >> 1);
00646 dest_p[8] = RED_LUT(cur_p[2]);
00647 dest_p[11] = RED_LUT((cur_p[2] + cur_p[4]) >> 1);
00648
00649 dest_p += 12;
00650 lst_p += 4;
00651 cur_p += 4;
00652 nxt_p += 4;
00653
00654 }
00655
00656
00657 }
00658
00659
00660 void
00661 convert_blue_row_8_green(u_char * lst_p, u_char * cur_p, u_char * nxt_p,
00662 u_char * dest_p, int width)
00663
00664 {
00665 int x;
00666
00667 for (x = 1; x < width - 4; x += 4)
00668 {
00669
00670 dest_p[0] = BLUE_LUT((cur_p[-1] + cur_p[1]) >> 1);
00671 dest_p[3] = BLUE_LUT(cur_p[1]);
00672 dest_p[6] = BLUE_LUT((cur_p[1] + cur_p[3]) >> 1);
00673 dest_p[9] = BLUE_LUT(cur_p[3]);
00674
00675 dest_p[1] = GREEN_LUT(cur_p[0]);
00676 dest_p[4] = GREEN_LUT((cur_p[0] + cur_p[2] + lst_p[1] + nxt_p[1]) >> 2);
00677 dest_p[7] = GREEN_LUT(cur_p[2]);
00678 dest_p[10] = GREEN_LUT((cur_p[2] + cur_p[4] + lst_p[3] + nxt_p[3]) >> 2);
00679
00680 dest_p[2] = RED_LUT((lst_p[0] + nxt_p[0]) >> 1);
00681 dest_p[5] = RED_LUT((lst_p[0] + nxt_p[0] + lst_p[2] + nxt_p[2]) >> 2);
00682 dest_p[8] = RED_LUT((lst_p[2] + nxt_p[2]) >> 1);
00683 dest_p[11] = RED_LUT((lst_p[2] + nxt_p[2] + lst_p[4] + nxt_p[4]) >> 2);
00684
00685 dest_p += 12;
00686 lst_p += 4;
00687 cur_p += 4;
00688 nxt_p += 4;
00689
00690 }
00691
00692 }
00693
00694
00695
00696 void
00697 convert_blue_row_8(u_char * lst_p, u_char * cur_p, u_char * nxt_p,
00698 u_char * dest_p, int width)
00699
00700 {
00701 int x;
00702
00703 for (x = 1; x < width - 4; x += 4)
00704 {
00705
00706 dest_p[0] = BLUE_LUT(cur_p[0]);
00707 dest_p[3] = BLUE_LUT((cur_p[0] + cur_p[2]) >> 1);
00708 dest_p[9] = BLUE_LUT((cur_p[2] + cur_p[4]) >> 1);
00709 dest_p[6] = BLUE_LUT(cur_p[2]);
00710 dest_p[1] = GREEN_LUT((cur_p[-1] + cur_p[1] + lst_p[0] + nxt_p[0]) >> 2);
00711 dest_p[4] = GREEN_LUT(cur_p[1]);
00712 dest_p[7] = GREEN_LUT((cur_p[1] + cur_p[3] + lst_p[2] + nxt_p[2]) >> 2);
00713 dest_p[10] = GREEN_LUT(cur_p[3]);
00714 dest_p[2] = RED_LUT((lst_p[-1] + nxt_p[-1] + lst_p[1] + nxt_p[1]) >> 2);
00715 dest_p[5] = RED_LUT((lst_p[1] + nxt_p[1]) >> 1);
00716 dest_p[8] = RED_LUT((lst_p[1] + nxt_p[1] + lst_p[3] + nxt_p[3]) >> 2);
00717 dest_p[11] = RED_LUT((lst_p[3] + nxt_p[3]) >> 1);
00718
00719 dest_p += 12;
00720 lst_p += 4;
00721 cur_p += 4;
00722 nxt_p += 4;
00723
00724 }
00725
00726 }
00727
00728 int
00729 convert_bayer_image_8_BGR(u_char * src,
00730 int width, int rows, int pitch,
00731 u_char * dest,
00732 int order)
00733
00734
00735 {
00736 u_char *cur_p;
00737 u_char *nxt_p;
00738 u_char *lst_p;
00739
00740 u_char *dest_p = dest;
00741 u_char *dest_nxt_p = dest + pitch*3;
00742
00743 u_char red_row;
00744 u_char green_start;
00745
00746 u_char testgreen;
00747
00748 int y;
00749
00750 #ifdef USE_MMX
00751
00752 if (bayer_can_use_mmx())
00753 {
00754 return convert_bayer_image_BGR_mmx((u_char *) src,
00755 width, rows, pitch,
00756 dest, 0, order, 8);
00757
00758 }
00759
00760 #endif
00761
00762 if (order >= 0)
00763 {
00764 red_row = ((order & 2) != 0);
00765 green_start = ((order & 1) != 0);
00766 }
00767 else
00768 {
00769 red_row = bayer_red_first;
00770 green_start = bayer_green_first;
00771
00772 }
00773
00774 testgreen = green_start;
00775
00776 if (bayer_current_base_size == 0)
00777 {
00778
00779 set_bayer_parameters(8,
00780 default_rgb_scale,
00781 1.0,
00782 0,
00783 red_row,
00784 green_start);
00785
00786 }
00787
00788
00789 cur_p = src + pitch + 1;
00790 lst_p = src + 1;
00791 nxt_p = cur_p + pitch;
00792
00793 green_start = !green_start;
00794
00795 if (green_start)
00796 {
00797 if (red_row)
00798 {
00799 for (y = 1; y < rows - 1; y += 2)
00800 {
00801 convert_blue_row_8(lst_p, cur_p, nxt_p, dest_p, width);
00802 lst_p += pitch;
00803 cur_p += pitch;
00804 nxt_p += pitch;
00805 dest_p += pitch*3;
00806 convert_red_row_8_green(lst_p, cur_p, nxt_p, dest_p, width);
00807 lst_p += pitch;
00808 cur_p += pitch;
00809 nxt_p += pitch;
00810 dest_p += pitch*3;
00811
00812 }
00813 }
00814 else
00815 {
00816 for (y = 1; y < rows - 1; y += 2)
00817 {
00818 convert_red_row_8(lst_p, cur_p, nxt_p, dest_p, width);
00819 lst_p += pitch;
00820 cur_p += pitch;
00821 nxt_p += pitch;
00822 dest_p += pitch*3;
00823 convert_blue_row_8_green(lst_p, cur_p, nxt_p, dest_p, width);
00824 lst_p += pitch;
00825 cur_p += pitch;
00826 nxt_p += pitch;
00827 dest_p += pitch*3;
00828 }
00829 }
00830 }
00831 else
00832 {
00833 if (red_row)
00834 {
00835 for (y = 1; y < rows - 1; y += 2)
00836 {
00837 convert_blue_row_8_green(lst_p, cur_p, nxt_p, dest_p, width);
00838 lst_p += pitch;
00839 cur_p += pitch;
00840 nxt_p += pitch;
00841 dest_p += pitch*3;
00842 convert_red_row_8(lst_p, cur_p, nxt_p, dest_p, width);
00843 lst_p += pitch;
00844 cur_p += pitch;
00845 nxt_p += pitch;
00846 dest_p += pitch*3;
00847 }
00848 }
00849 else
00850 {
00851 for (y = 1; y < rows - 1; y += 2)
00852 {
00853 convert_red_row_8_green(lst_p, cur_p, nxt_p, dest_p, width);
00854 lst_p += pitch;
00855 cur_p += pitch;
00856 nxt_p += pitch;
00857 dest_p += pitch*3;
00858 convert_blue_row_8(lst_p, cur_p, nxt_p, dest_p, width);
00859 lst_p += pitch;
00860 cur_p += pitch;
00861 nxt_p += pitch;
00862 dest_p += pitch*3;
00863 }
00864
00865 }
00866 }
00867
00868
00869 return (0);
00870 }
00871