⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dc1394_bayer.c

📁 This library provides functionality to control any camera that conforms to the 1394-Based Digital C
💻 C
📖 第 1 页 / 共 5 页
字号:
		    - bayer[bayerStep2 + 5]		    + ((bayer[3] + bayer[bayerStep4 + 3] + 1) >> 1);		t0 = (t0 + 4) >> 3;		CLIP(t0, rgb[4]);		t1 = (t1 + 4) >> 3;		CLIP(t1, rgb[2]);	    }	}	if (bayer < bayerEnd) {	    /* B at B */	    rgb[blue] = bayer[bayerStep2 + 2];	    /* R at B */	    t0 = ((bayer[bayerStep + 1] + bayer[bayerStep + 3] +		   bayer[bayerStep3 + 1] + bayer[bayerStep3 + 3]) << 1)		-		(((bayer[2] + bayer[bayerStep2] +		   bayer[bayerStep2 + 4] + bayer[bayerStep4 +						 2]) * 3 + 1) >> 1)		+ rgb[blue] * 6;	    /* G at B */	    t1 = (((bayer[bayerStep + 2] + bayer[bayerStep2 + 1] +		    bayer[bayerStep2 + 3] + bayer[bayerStep3 + 2])) << 1)		- (bayer[2] + bayer[bayerStep2] +		   bayer[bayerStep2 + 4] + bayer[bayerStep4 + 2])		+ (rgb[blue] << 2);	    t0 = (t0 + 4) >> 3;	    CLIP(t0, rgb[-blue]);	    t1 = (t1 + 4) >> 3;	    CLIP(t1, rgb[0]);	    bayer++;	    rgb += 3;	}	bayer -= width;	rgb -= width * 3;	blue = -blue;	start_with_green = !start_with_green;    }}/* coriander's Bayer decoding (GPL) *//* Edge Sensing Interpolation II from http://www-ise.stanford.edu/~tingchen/ *//*   (Laroche,Claude A.  "Apparatus and method for adaptively     interpolating a full color image utilizing chrominance gradients"     U.S. Patent 5,373,322) */voiddc1394_bayer_EdgeSense(const uchar_t *restrict bayer, uchar_t *restrict rgb, int sx, int sy, int tile){    uchar_t *outR, *outG, *outB;    register int i3, j3, base;    int i, j;    int dh, dv;    int tmp;    int sx3=sx*3;    // sx and sy should be even    switch (tile) {    case DC1394_COLOR_FILTER_GRBG:    case DC1394_COLOR_FILTER_BGGR:	outR = &rgb[0];	outG = &rgb[1];	outB = &rgb[2];	break;    case DC1394_COLOR_FILTER_GBRG:    case DC1394_COLOR_FILTER_RGGB:	outR = &rgb[2];	outG = &rgb[1];	outB = &rgb[0];	break;    default:	fprintf(stderr, "Bad bayer pattern ID: %d\n", tile);	return;	break;    }    switch (tile) {    case DC1394_COLOR_FILTER_GRBG:	//---------------------------------------------------------    case DC1394_COLOR_FILTER_GBRG:	// copy original RGB data to output images      for (i = 0, i3=0; i < sy*sx; i += (sx<<1), i3 += (sx3<<1)) {	for (j = 0, j3=0; j < sx; j += 2, j3+=6) {	  base=i3+j3;	  outG[base]           = bayer[i + j];	  outG[base + sx3 + 3] = bayer[i + j + sx + 1];	  outR[base + 3]       = bayer[i + j + 1];	  outB[base + sx3]     = bayer[i + j + sx];	}      }      // process GREEN channel      for (i3= 3*sx3; i3 < (sy - 2)*sx3; i3 += (sx3<<1)) {	for (j3=6; j3 < sx3 - 9; j3+=6) {	  base=i3+j3;	  dh = abs(((outB[base - 6] +		     outB[base + 6]) >> 1) -		     outB[base]);	  dv = abs(((outB[base - (sx3<<1)] +		     outB[base + (sx3<<1)]) >> 1) -		     outB[base]);	  tmp = (((outG[base - 3]   + outG[base + 3]) >> 1) * (dh<=dv) +		 ((outG[base - sx3] + outG[base + sx3]) >> 1) * (dh>dv));	  //tmp = (dh==dv) ? tmp>>1 : tmp;	  CLIP(tmp, outG[base]);	}      }	      for (i3=2*sx3; i3 < (sy - 3)*sx3; i3 += (sx3<<1)) {	for (j3=9; j3 < sx3 - 6; j3+=6) {	  base=i3+j3;	  dh = abs(((outR[base - 6] +		     outR[base + 6]) >>1 ) -		     outR[base]);	  dv = abs(((outR[base - (sx3<<1)] +		     outR[base + (sx3<<1)]) >>1 ) -		     outR[base]);	  tmp = (((outG[base - 3]   + outG[base + 3]) >> 1) * (dh<=dv) +		 ((outG[base - sx3] + outG[base + sx3]) >> 1) * (dh>dv));	  //tmp = (dh==dv) ? tmp>>1 : tmp;	  CLIP(tmp, outG[base]);	}      }      // process RED channel      for (i3=0; i3 < (sy - 1)*sx3; i3 += (sx3<<1)) {	for (j3=6; j3 < sx3 - 3; j3+=6) {	  base=i3+j3;	  tmp = outG[base] +	      ((outR[base - 3] -		outG[base - 3] +		outR[base + 3] -		outG[base + 3]) >> 1);	  CLIP(tmp, outR[base]);	}      }      for (i3=sx3; i3 < (sy - 2)*sx3; i3 += (sx3<<1)) {	for (j3=3; j3 < sx3; j3+=6) {	  base=i3+j3;	  tmp = outG[base] +	      ((outR[base - sx3] -		outG[base - sx3] +		outR[base + sx3] -		outG[base + sx3]) >> 1);	  CLIP(tmp, outR[base]);	}	for (j3=6; j3 < sx3 - 3; j3+=6) {	  base=i3+j3;	  tmp = outG[base] +	      ((outR[base - sx3 - 3] -		outG[base - sx3 - 3] +		outR[base - sx3 + 3] -		outG[base - sx3 + 3] +		outR[base + sx3 - 3] -		outG[base + sx3 - 3] +		outR[base + sx3 + 3] -		outG[base + sx3 + 3]) >> 2);	  CLIP(tmp, outR[base]);	}      }      // process BLUE channel      for (i3=sx3; i3 < sy*sx3; i3 += (sx3<<1)) {	for (j3=3; j3 < sx3 - 6; j3+=6) {	  base=i3+j3;	  tmp = outG[base] +	      ((outB[base - 3] -		outG[base - 3] +		outB[base + 3] -		outG[base + 3]) >> 1);	  CLIP(tmp, outB[base]);	}      }      for (i3=2*sx3; i3 < (sy - 1)*sx3; i3 += (sx3<<1)) {	for (j3=0; j3 < sx3 - 3; j3+=6) {	  base=i3+j3;	  tmp = outG[base] +	      ((outB[base - sx3] -		outG[base - sx3] +		outB[base + sx3] -		outG[base + sx3]) >> 1);	  CLIP(tmp, outB[base]);	}	for (j3=3; j3 < sx3 - 6; j3+=6) {	  base=i3+j3;	  tmp = outG[base] +	      ((outB[base - sx3 - 3] -		outG[base - sx3 - 3] +		outB[base - sx3 + 3] -		outG[base - sx3 + 3] +		outB[base + sx3 - 3] -		outG[base + sx3 - 3] +		outB[base + sx3 + 3] -		outG[base + sx3 + 3]) >> 2);	  CLIP(tmp, outB[base]);	}      }      break;    case DC1394_COLOR_FILTER_BGGR:	//---------------------------------------------------------    case DC1394_COLOR_FILTER_RGGB:	// copy original RGB data to output images      for (i = 0, i3=0; i < sy*sx; i += (sx<<1), i3 += (sx3<<1)) {	for (j = 0, j3=0; j < sx; j += 2, j3+=6) {	  base=i3+j3;	  outB[base] = bayer[i + j];	  outR[base + sx3 + 3] = bayer[i + sx + (j + 1)];	  outG[base + 3] = bayer[i + j + 1];	  outG[base + sx3] = bayer[i + sx + j];	}      }      // process GREEN channel      for (i3=2*sx3; i3 < (sy - 2)*sx3; i3 += (sx3<<1)) {	for (j3=6; j3 < sx3 - 9; j3+=6) {	  base=i3+j3;	  dh = abs(((outB[base - 6] +		     outB[base + 6]) >> 1) -		     outB[base]);	  dv = abs(((outB[base - (sx3<<1)] +		     outB[base + (sx3<<1)]) >> 1) -		     outB[base]);	  tmp = (((outG[base - 3]   + outG[base + 3]) >> 1) * (dh<=dv) +		 ((outG[base - sx3] + outG[base + sx3]) >> 1) * (dh>dv));	  //tmp = (dh==dv) ? tmp>>1 : tmp;	  CLIP(tmp, outG[base]);	}      }      for (i3=3*sx3; i3 < (sy - 3)*sx3; i3 += (sx3<<1)) {	for (j3=9; j3 < sx3 - 6; j3+=6) {	  base=i3+j3;	  dh = abs(((outR[base - 6] +		     outR[base + 6]) >> 1) -		     outR[base]);	  dv = abs(((outR[base - (sx3<<1)] +		     outR[base + (sx3<<1)]) >> 1) -		     outR[base]);	  tmp = (((outG[base - 3]   + outG[base + 3]) >> 1) * (dh<=dv) +		 ((outG[base - sx3] + outG[base + sx3]) >> 1) * (dh>dv));	  //tmp = (dh==dv) ? tmp>>1 : tmp;	  CLIP(tmp, outG[base]);	}      }      // process RED channel      for (i3=sx3; i3 < (sy - 1)*sx3; i3 += (sx3<<1)) {	// G-points (1/2)	for (j3=6; j3 < sx3 - 3; j3+=6) {	  base=i3+j3;	  tmp = outG[base] +	      ((outR[base - 3] -		outG[base - 3] +		outR[base + 3] -		outG[base + 3]) >>1);	  CLIP(tmp, outR[base]);	}      }      for (i3=2*sx3; i3 < (sy - 2)*sx3; i3 += (sx3<<1)) {	for (j3=3; j3 < sx3; j3+=6) {	// G-points (2/2)	  base=i3+j3;	  tmp = outG[base] +	      ((outR[base - sx3] -		outG[base - sx3] +		outR[base + sx3] -		outG[base + sx3]) >> 1);	  CLIP(tmp, outR[base]);	}	for (j3=6; j3 < sx3 - 3; j3+=6) {	// B-points	  base=i3+j3;	  tmp = outG[base] +	      ((outR[base - sx3 - 3] -		outG[base - sx3 - 3] +		outR[base - sx3 + 3] -		outG[base - sx3 + 3] +		outR[base + sx3 - 3] -		outG[base + sx3 - 3] +		outR[base + sx3 + 3] -		outG[base + sx3 + 3]) >> 2);	  CLIP(tmp, outR[base]);	}      }            // process BLUE channel      for (i = 0,i3=0; i < sy*sx; i += (sx<<1), i3 += (sx3<<1)) {	for (j = 1, j3=3; j < sx - 2; j += 2, j3+=6) {	  base=i3+j3;	  tmp = outG[base] +	      ((outB[base - 3] -		outG[base - 3] +		outB[base + 3] -		outG[base + 3]) >> 1);	  CLIP(tmp, outB[base]);	}      }      for (i3=sx3; i3 < (sy - 1)*sx3; i3 += (sx3<<1)) {	for (j3=0; j3 < sx3 - 3; j3+=6) {	  base=i3+j3;	  tmp = outG[base] +	      ((outB[base - sx3] -		outG[base - sx3] +		outB[base + sx3] -		outG[base + sx3]) >> 1);	  CLIP(tmp, outB[base]);	}	for (j3=3; j3 < sx3 - 6; j3+=6) {	  base=i3+j3;	  tmp = outG[base] +	      ((outB[base - sx3 - 3] -		outG[base - sx3 - 3] +		outB[base - sx3 + 3] -		outG[base - sx3 + 3] +		outB[base + sx3 - 3] -		outG[base + sx3 - 3] +		outB[base + sx3 + 3] -		outG[base + sx3 + 3]) >> 2);	  CLIP(tmp, outB[base]);	}      }      break;    default:			//---------------------------------------------------------      fprintf(stderr, "Bad bayer pattern ID: %d\n", tile);      return;      break;    }        ClearBorders(rgb, sx, sy, 3);}/* coriander's Bayer decoding */voiddc1394_bayer_Downsample(const uchar_t *restrict bayer, uchar_t *restrict rgb, int sx, int sy, int tile){    uchar_t *outR, *outG, *outB;    register int i, j;    int tmp;    sx *= 2;    sy *= 2;    switch (tile) {    case DC1394_COLOR_FILTER_GRBG:    case DC1394_COLOR_FILTER_BGGR:	outR = &rgb[0];	outG = &rgb[1];	outB = &rgb[2];	break;    case DC1394_COLOR_FILTER_GBRG:    case DC1394_COLOR_FILTER_RGGB:	outR = &rgb[2];	outG = &rgb[1];	outB = &rgb[0];	break;    default:	fprintf(stderr, "Bad Bayer pattern ID: %d\n", tile);	return;	break;    }    switch (tile) {    case DC1394_COLOR_FILTER_GRBG:	//---------------------------------------------------------    case DC1394_COLOR_FILTER_GBRG:	for (i = 0; i < sy*sx; i += (sx<<1)) {	    for (j = 0; j < sx; j += 2) {		tmp = ((bayer[i + j] + bayer[i + sx + j + 1]) >> 1);		CLIP(tmp, outG[((i >> 2) + (j >> 1)) * 3]);		tmp = bayer[i + sx + j + 1];		CLIP(tmp, outR[((i >> 2) + (j >> 1)) * 3]);		tmp = bayer[i + sx + j];		CLIP(tmp, outB[((i >> 2) + (j >> 1)) * 3]);	    }	}	break;    case DC1394_COLOR_FILTER_BGGR:	//---------------------------------------------------------    case DC1394_COLOR_FILTER_RGGB:	for (i = 0; i < sy*sx; i += (sx<<1)) {	    for (j = 0; j < sx; j += 2) {		tmp = ((bayer[i + sx + j] + bayer[i + j + 1]) >> 1);		CLIP(tmp, outG[((i >> 2) + (j >> 1)) * 3]);		tmp = bayer[i + sx + j + 1];		CLIP(tmp, outR[((i >> 2) + (j >> 1)) * 3]);		tmp = bayer[i + j];		CLIP(tmp, outB[((i >> 2) + (j >> 1)) * 3]);	    }	}	break;    default:			//---------------------------------------------------------	fprintf(stderr, "Bad Bayer pattern ID: %d\n", tile);	return;	break;    }}/* this is the method used inside AVT cameras. See AVT docs. */voiddc1394_bayer_Simple(const uchar_t *restrict bayer, uchar_t *restrict rgb, int sx, int sy, int tile){    const int bayerStep = sx;    const int rgbStep = 3 * sx;    int width = sx;    int height = sy;    int blue = tile == DC1394_COLOR_FILTER_BGGR        || tile == DC1394_COLOR_FILTER_GBRG ? -1 : 1;    int start_with_green = tile == DC1394_COLOR_FILTER_GBRG        || tile == DC1394_COLOR_FILTER_GRBG;    int i, imax, iinc;    /* add black border */    imax = sx * sy * 3;    for (i = sx * (sy - 1) * 3; i < imax; i++) {        rgb[i] = 0;    }    iinc = (sx - 1) * 3;    for (i = (sx - 1) * 3; i < imax; i += iinc) {        rgb[i++] = 0;        rgb[i++] = 0;        rgb[i++] = 0;    }    rgb += 1;    width -= 1;    height -= 1;    for (; height--; bayer += bayerStep, rgb += rgbStep) {        const uchar_t *bayerEnd = bayer + width;        if (start_with_green) {            rgb[-blue] = bayer[1];            rgb[0] = (bayer[0] + bayer[bayerStep + 1] + 1) >> 1;            rgb[blue] = bayer[bayerStep];            bayer++;            rgb += 3;        }        if (blue > 0) {            for (; bayer <= bayerEnd - 2; bayer += 2, rgb += 6) {                rgb[-1] = bayer[0];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -