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

📄 dc1394_bayer.c

📁 This library provides functionality to control any camera that conforms to the 1394-Based Digital C
💻 C
📖 第 1 页 / 共 5 页
字号:
    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; i < sy*sx; i += (sx<<1)) {	for (j = 0; j < sx; j += 2) {	  outG[(i + j) * 3] = bayer[i + j];	  outG[(i + sx + (j + 1)) * 3] = bayer[i + sx + (j + 1)];	  outR[(i + j + 1) * 3] = bayer[i + j + 1];	  outB[(i + sx + j) * 3] = bayer[i + sx + j];	}      }      // process GREEN channel      for (i = 3*sx; i < (sy - 2)*sx; i += (sx<<1)) {	for (j = 2; j < sx - 3; j += 2) {	  dh = abs(((outB[(i + j - 2) * 3] +		     outB[(i + j + 2) * 3]) >> 1) -		   outB[(i + j) * 3]);	  dv = abs(((outB[(i - (sx<<1) + j) * 3] +		     outB[(i + (sx<<1) + j) * 3]) >> 1)  -		   outB[(i + j) * 3]);	  if (dh < dv)	    tmp = (outG[(i + j - 1) * 3] +		   outG[(i + j + 1) * 3]) >> 1;	  else {	    if (dh > dv)	      tmp = (outG[(i - sx + j) * 3] +		     outG[(i + sx + j) * 3]) >> 1;	    else	      tmp = (outG[(i + j - 1) * 3] +		     outG[(i + j + 1) * 3] +		     outG[(i - sx + j) * 3] +		     outG[(i + sx + j) * 3]) >> 2;	  }	  CLIP16(tmp, outR[(i + j) * 3], bits);	}      }	      for (i = 2*sx; i < (sy - 3)*sx; i += (sx<<1)) {	for (j = 3; j < sx - 2; j += 2) {	  dh = abs(((outR[(i + j - 2) * 3] +		     outR[(i + j + 2) * 3]) >>1 ) -		   outR[(i + j) * 3]);	  dv = abs(((outR[(i - (sx<<1) + j) * 3] +		     outR[(i + (sx<<1) + j) * 3]) >>1 ) -		   outR[(i + j) * 3]);	  if (dh < dv)	    tmp = (outG[(i + j - 1) * 3] +		   outG[(i + j + 1) * 3]) >> 1;	  else {	    if (dh > dv)	      tmp = (outG[(i - sx + j) * 3] +		     outG[(i + sx + j) * 3]) >> 1;	    else	      tmp = (outG[(i + j - 1) * 3] +		     outG[(i + j + 1) * 3] +		     outG[(i - sx + j) * 3] +		     outG[(i + sx + j) * 3]) >> 2;	  }	  CLIP16(tmp, outR[(i + j) * 3], bits);	}      }      // process RED channel      for (i = 0; i < (sy - 1)*sx; i += (sx<<1)) {	for (j = 2; j < sx - 1; j += 2) {	  tmp = outG[(i + j) * 3] +	      ((outR[(i + j - 1) * 3] -		outG[(i + j - 1) * 3] +		outR[(i + j + 1) * 3] -		outG[(i + j + 1) * 3]) >> 1);	  CLIP16(tmp, outR[(i + j) * 3], bits);	}      }      for (i = sx; i < (sy - 2)*sx; i += (sx<<1)) {	for (j = 1; j < sx; j += 2) {	  tmp = outG[(i + j) * 3] +	      ((outR[(i - sx + j) * 3] -		outG[(i - sx + j) * 3] +		outR[(i + sx + j) * 3] -		outG[(i + sx + j) * 3]) >> 1);	  CLIP16(tmp, outR[(i + j) * 3], bits);	}	for (j = 2; j < sx - 1; j += 2) {	  tmp = outG[(i + j) * 3] +	      ((outR[(i - sx + j - 1) * 3] -		outG[(i - sx + j - 1) * 3] +		outR[(i - sx + j + 1) * 3] -		outG[(i - sx + j + 1) * 3] +		outR[(i + sx + j - 1) * 3] -		outG[(i + sx + j - 1) * 3] +		outR[(i + sx + j + 1) * 3] -		outG[(i + sx + j + 1) * 3]) >> 2);	  CLIP16(tmp, outR[(i + j) * 3], bits);	}      }      // process BLUE channel      for (i = sx; i < sy*sx; i += (sx<<1)) {	for (j = 1; j < sx - 2; j += 2) {	  tmp = outG[(i + j) * 3] +	      ((outB[(i + j - 1) * 3] -		outG[(i + j - 1) * 3] +		outB[(i + j + 1) * 3] -		outG[(i + j + 1) * 3]) >> 1);	  CLIP16(tmp, outR[(i + j) * 3], bits);	}      }      for (i = 2*sx; i < (sy - 1)*sx; i += (sx<<1)) {	for (j = 0; j < sx - 1; j += 2) {	  tmp = outG[(i + j) * 3] +	      ((outB[(i - sx + j) * 3] -		outG[(i - sx + j) * 3] +		outB[(i + sx + j) * 3] -		outG[(i + sx + j) * 3]) >> 1);	  CLIP16(tmp, outR[(i + j) * 3], bits);	}	for (j = 1; j < sx - 2; j += 2) {	  tmp = outG[(i + j) * 3] +	      ((outB[(i - sx + j - 1) * 3] -		outG[(i - sx + j - 1) * 3] +		outB[(i - sx + j + 1) * 3] -		outG[(i - sx + j + 1) * 3] +		outB[(i + sx + j - 1) * 3] -		outG[(i + sx + j - 1) * 3] +		outB[(i + sx + j + 1) * 3] -		outG[(i + sx + j + 1) * 3]) >> 2);	  CLIP16(tmp, outR[(i + j) * 3], bits);	}      }      break;    case DC1394_COLOR_FILTER_BGGR:	//---------------------------------------------------------    case DC1394_COLOR_FILTER_RGGB:	// copy original RGB data to output images      for (i = 0; i < sy*sx; i += (sx<<1)) {	for (j = 0; j < sx; j += 2) {	  outB[(i + j) * 3] = bayer[i + j];	  outR[(i + sx + (j + 1)) * 3] = bayer[i + sx + (j + 1)];	  outG[(i + j + 1) * 3] = bayer[i + j + 1];	  outG[(i + sx + j) * 3] = bayer[i + sx + j];	}      }      // process GREEN channel      for (i = 2*sx; i < (sy - 2)*sx; i += (sx<<1)) {	for (j = 2; j < sx - 3; j += 2) {	  dh = abs(((outB[(i + j - 2) * 3] +		    outB[(i + j + 2) * 3]) >> 1) -		   outB[(i + j) * 3]);	  dv = abs(((outB[(i - (sx<<1) + j) * 3] +		    outB[(i + (sx<<1) + j) * 3]) >> 1) -		   outB[(i + j) * 3]);	  if (dh < dv)	    tmp = (outG[(i + j - 1) * 3] +		   outG[(i + j + 1) * 3]) >> 1;	  else {	    if (dh > dv)	      tmp = (outG[(i - sx + j) * 3] +		     outG[(i + sx + j) * 3]) >> 1;	    else	      tmp = (outG[(i + j - 1) * 3] +		     outG[(i + j + 1) * 3] +		     outG[(i - sx + j) * 3] +		     outG[(i + sx + j) * 3]) >> 2;	  }	  CLIP16(tmp, outR[(i + j) * 3], bits);	}      }      for (i = 3*sx; i < (sy - 3)*sx; i += (sx<<1)) {	for (j = 3; j < sx - 2; j += 2) {	  dh = abs(((outR[(i + j - 2) * 3] +		    outR[(i + j + 2) * 3]) >> 1) -		   outR[(i + j) * 3]);	  dv = abs(((outR[(i - (sx<<1) + j) * 3] +		    outR[(i + (sx<<1) + j) * 3]) >> 1) -		   outR[(i + j) * 3]);	  if (dh < dv)	    tmp = (outG[(i + j - 1) * 3] +		   outG[(i + j + 1) * 3]) >>1;	  else {	    if (dh > dv)	      tmp = (outG[(i - sx + j) * 3] +		     outG[(i + sx + j) * 3]) >>1;	    else	      tmp = (outG[(i + j - 1) * 3] +		     outG[(i + j + 1) * 3] +		     outG[(i - sx + j) * 3] +		     outG[(i + sx + j) * 3]) >>2;	  }	  CLIP16(tmp, outR[(i + j) * 3], bits);	}      }      // process RED channel      for (i = sx; i < (sy - 1)*sx; i += (sx<<1)) {	// G-points (1/2)	for (j = 2; j < sx - 1; j += 2) {	  tmp = outG[(i + j) * 3] +	      ((outR[(i + j - 1) * 3] -		outG[(i + j - 1) * 3] +		outR[(i + j + 1) * 3] -		outG[(i + j + 1) * 3]) >>1);	  CLIP16(tmp, outR[(i + j) * 3], bits);	}      }      for (i = 2*sx; i < (sy - 2)*sx; i += (sx<<1)) {	for (j = 1; j < sx; j += 2) {	// G-points (2/2)	  tmp = outG[(i + j) * 3] +	      ((outR[(i - sx + j) * 3] -		outG[(i - sx + j) * 3] +		outR[(i + sx + j) * 3] -		outG[(i + sx + j) * 3]) >> 1);	  CLIP16(tmp, outR[(i + j) * 3], bits);	}	for (j = 2; j < sx - 1; j += 2) {	// B-points	  tmp = outG[(i + j) * 3] +	      ((outR[(i - sx + j - 1) * 3] -		outG[(i - sx + j - 1) * 3] +		outR[(i - sx + j + 1) * 3] -		outG[(i - sx + j + 1) * 3] +		outR[(i + sx + j - 1) * 3] -		outG[(i + sx + j - 1) * 3] +		outR[(i + sx + j + 1) * 3] -		outG[(i + sx + j + 1) * 3]) >> 2);	  CLIP16(tmp, outR[(i + j) * 3], bits);	}      }            // process BLUE channel      for (i = 0; i < sy*sx; i += (sx<<1)) {	for (j = 1; j < sx - 2; j += 2) {	  tmp = outG[(i + j) * 3] +	      ((outB[(i + j - 1) * 3] -		outG[(i + j - 1) * 3] +		outB[(i + j + 1) * 3] -		outG[(i + j + 1) * 3]) >> 1);	  CLIP16(tmp, outR[(i + j) * 3], bits);	}      }      for (i = sx; i < (sy - 1)*sx; i += (sx<<1)) {	for (j = 0; j < sx - 1; j += 2) {	  tmp = outG[(i + j) * 3] +	      ((outB[(i - sx + j) * 3] -		outG[(i - sx + j) * 3] +		outB[(i + sx + j) * 3] -		outG[(i + sx + j) * 3]) >> 1);	  CLIP16(tmp, outR[(i + j) * 3], bits);	}	for (j = 1; j < sx - 2; j += 2) {	  tmp = outG[(i + j) * 3] +	      ((outB[(i - sx + j - 1) * 3] -		outG[(i - sx + j - 1) * 3] +		outB[(i - sx + j + 1) * 3] -		outG[(i - sx + j + 1) * 3] +		outB[(i + sx + j - 1) * 3] -		outG[(i + sx + j - 1) * 3] +		outB[(i + sx + j + 1) * 3] -		outG[(i + sx + j + 1) * 3]) >> 2);	  CLIP16(tmp, outR[(i + j) * 3], bits);	}      }      break;    default:			//---------------------------------------------------------      fprintf(stderr, "Bad bayer pattern ID: %d\n", tile);      return;      break;    }       ClearBorders_uint16(rgb, sx, sy, 3);}/* coriander's Bayer decoding */voiddc1394_bayer_Downsample_uint16(const uint16_t *restrict bayer, uint16_t *restrict rgb, int sx, int sy, int tile, int bits){    uint16_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);		CLIP16(tmp, outG[((i >> 2) + (j >> 1)) * 3], bits);		tmp = bayer[i + sx + j + 1];		CLIP16(tmp, outR[((i >> 2) + (j >> 1)) * 3], bits);		tmp = bayer[i + sx + j];		CLIP16(tmp, outB[((i >> 2) + (j >> 1)) * 3], bits);	    }	}	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);		CLIP16(tmp, outG[((i >> 2) + (j >> 1)) * 3], bits);		tmp = bayer[i + sx + j + 1];		CLIP16(tmp, outR[((i >> 2) + (j >> 1)) * 3], bits);		tmp = bayer[i + j];		CLIP16(tmp, outB[((i >> 2) + (j >> 1)) * 3], bits);	    }	}	break;    default:			//---------------------------------------------------------	fprintf(stderr, "Bad Bayer pattern ID: %d\n", tile);	return;	break;    }}/* coriander's Bayer decoding */voiddc1394_bayer_Simple_uint16(const uint16_t *restrict bayer, uint16_t *restrict rgb, int sx, int sy, int tile, int bits){    uint16_t *outR, *outG, *outB;    register int i, j;    int tmp, base;    // 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_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:	outR = NULL;	outG = NULL;	outB = NULL;	break;    }    switch (tile) {    case DC1394_COLOR_FILTER_GRBG:	//---------------------------------------------------------    case DC1394_COLOR_FILTER_GBRG:	for (i = 0; i < sy - 1; i += 2) {	    for (j = 0; j < sx - 1; j += 2) {		base = i * sx + j;		tmp = ((bayer[base] + bayer[base + sx + 1]) >> 1);		CLIP16(tmp, outG[base * 3], bits);		tmp = bayer[base + 1];		CLIP16(tmp, outR[base * 3], bits);		tmp = bayer[base + sx];		CLIP16(tmp, outB[base * 3], bits);	    }	}	for (i = 0; i < sy - 1; i += 2) {	    for (j = 1; j < sx - 1; j += 2) {		base = i * sx + j;		tmp = ((bayer[base + 1] + bayer[base + sx]) >> 1);		CLIP16(tmp, outG[(base) * 3], bits);		tmp = bayer[base];		CLIP16(tmp, outR[(base) * 3], bits);		tmp = bayer[base + 1 + sx];		CLIP16(tmp, outB[(base) * 3], bits);	    }	}	for (i = 1; i < sy - 1; i += 2) {	    for (j = 0; j < sx - 1; j += 2) {		base = i * sx + j;		tmp = ((bayer[base + sx] + bayer[base + 1]) >> 1);		CLIP16(tmp, outG[base * 3], bits);		tmp = bayer[base + sx + 1];		CLIP16(tmp, outR[base * 3], bits);		tmp = bayer[base];		CLIP16(tmp, outB[base * 3], bits);	    }	}	for (i = 1; i < sy - 1; i += 2) {

⌨️ 快捷键说明

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