Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RAWRGB to RGB32 ColoSpace #135

Open
wangjianhong0574 opened this issue Dec 17, 2020 · 1 comment
Open

RAWRGB to RGB32 ColoSpace #135

wangjianhong0574 opened this issue Dec 17, 2020 · 1 comment

Comments

@wangjianhong0574
Copy link

wangjianhong0574 commented Dec 17, 2020

i use your RAW to RGB32 the speed is very fast.Thank you for your great and selfless work. But in some cases the effect is not good, I have the following C language image quality is good. I hope it will be useful for you.

this is better
/*

  • BayerConversion

  • function: fairly basic interpolation scheme creating RGB values from surrounding R,G,B in bayer
  •       image.bordercases are handled by coloring them black
    
  • in: pointer to 8bpp Bayer buffer
  • out: pointer to 32bpp RGB buffer
  • special: using the following 3x3 kernel interpolation:
  •       R G R     R      B G B     B
    
  •        \|/.     |       \|/      |
    
  •       G-B-G   B-G1-B   G-R-G   R-G2-R
    
  •        /|\      |       /|\      |
    
  •       R G R     R      B G B     B
    

/
/

G R
B G
*/

#define B_OFFSET 0
#define G_OFFSET 1
#define R_OFFSET 2

#define ODD(i) ((i)&1)
#define EVEN(i) (!((i)&1))
typedef enum {
Pattern_Recognition_Filter,
Laroche_Prescott_Filter,
Fast_Linear_Filter,
Anisotropic_Filter
}Bayer_Filter;

void BayerConversionGRBG(unsigned char *pIn, unsigned char pOut, int nRealWidth, int nRealHeight, Bayer_Filter BayerFilter)
{
int yWidth = 0, ym1Width = 0, yp1Width;
int x, y;
int pix;
/

* border cases (fill it in with black)
*/
/G R G R G R
B G B G B G
G R G R G R
B G B G B G
/

for (y = 0; y<nRealHeight; y++)
{
	x = 0;
	pOut[((x + y*nRealWidth) << 2) + B_OFFSET] = 0;
	pOut[((x + y*nRealWidth) << 2) + G_OFFSET] = 0;
	pOut[((x + y*nRealWidth) << 2) + R_OFFSET] = 0;
	x = nRealWidth - 1;
	pOut[((x + y*nRealWidth) << 2) + B_OFFSET] = 0;
	pOut[((x + y*nRealWidth) << 2) + G_OFFSET] = 0;
	pOut[((x + y*nRealWidth) << 2) + R_OFFSET] = 0;
}

for (x = 0; x<nRealWidth; x++)
{
	y = 0;
	pOut[((x + y*nRealWidth) << 2) + B_OFFSET] = 0;
	pOut[((x + y*nRealWidth) << 2) + G_OFFSET] = 0;
	pOut[((x + y*nRealWidth) << 2) + R_OFFSET] = 0;
	y = nRealHeight - 1;
	pOut[((x + y*nRealWidth) << 2) + B_OFFSET] = 0;
	pOut[((x + y*nRealWidth) << 2) + G_OFFSET] = 0;
	pOut[((x + y*nRealWidth) << 2) + R_OFFSET] = 0;
}




if (BayerFilter == Anisotropic_Filter)
{
	for (y = 1; y<nRealHeight - 1; y++)
	{
		yWidth += nRealWidth;
		ym1Width = yWidth - nRealWidth;
		yp1Width = yWidth + nRealWidth;

		for (x = 1; x<nRealWidth - 1; x++)
		{
			pix = ((x + yWidth) << 2);
			if (ODD(y))
			if (ODD(x))
			{
				pOut[pix + B_OFFSET] = ((pIn[x - 1 + yWidth] +
					pIn[x + 1 + yWidth]) >> 1);
				pOut[pix + G_OFFSET] = ((pIn[x + yWidth] << 2) + (pIn[x - 1 + ym1Width] + pIn[x + 1 + ym1Width] + pIn[x - 1 + yp1Width] + pIn[x + 1 + yp1Width])) >> 3;
				pOut[pix + R_OFFSET] = ((pIn[x + ym1Width] +
					pIn[x + yp1Width]) >> 1);
			}
			else
			{   // ODD(y) EVEN(x)
				pOut[pix + B_OFFSET] = pIn[x + yWidth];
				if (abs(pIn[x - 1 + yWidth] - pIn[x + 1 + yWidth])<abs(pIn[x + ym1Width] - pIn[x + yp1Width]))
				{
					pOut[pix + G_OFFSET] = (pIn[x - 1 + yWidth] + pIn[x + 1 + yWidth]) >> 1;
				}
				else if (abs(pIn[x - 1 + yWidth] - pIn[x + 1 + yWidth])>abs(pIn[x + ym1Width] - pIn[x + yp1Width]))
				{
					pOut[pix + G_OFFSET] = (pIn[x + ym1Width] + pIn[x + yp1Width]) >> 1;
				}
				else
					pOut[pix + G_OFFSET] = ((pIn[x - 1 + yWidth] +
					pIn[x + 1 + yWidth] +
					pIn[x + ym1Width] +
					pIn[x + yp1Width]) >> 2);

				if (abs(pIn[x - 1 + ym1Width] - pIn[x + 1 + yp1Width])<abs(pIn[x + 1 + ym1Width] - pIn[x - 1 + yp1Width]))
				{
					pOut[pix + R_OFFSET] = (pIn[x - 1 + ym1Width] + pIn[x + 1 + yp1Width]) >> 1;
				}
				else if (abs(pIn[x - 1 + ym1Width] - pIn[x + 1 + yp1Width])>abs(pIn[x + 1 + ym1Width] - pIn[x - 1 + yp1Width]))
				{
					pOut[pix + R_OFFSET] = (pIn[x + 1 + ym1Width] + pIn[x - 1 + yp1Width]) >> 1;
				}
				else
					pOut[pix + R_OFFSET] = ((pIn[x - 1 + ym1Width] +
					pIn[x + 1 + ym1Width] +
					pIn[x - 1 + yp1Width] +
					pIn[x + 1 + yp1Width]) >> 2);
			}
			else
			if (ODD(x))
			{   // EVEN(y) ODD(x)
				if (abs(pIn[x - 1 + ym1Width] - pIn[x + 1 + yp1Width])<abs(pIn[x + 1 + ym1Width] - pIn[x - 1 + yp1Width]))
				{
					pOut[pix + B_OFFSET] = (pIn[x - 1 + ym1Width] + pIn[x + 1 + yp1Width]) >> 1;
				}
				else if (abs(pIn[x - 1 + ym1Width] - pIn[x + 1 + yp1Width])>abs(pIn[x + 1 + ym1Width] - pIn[x - 1 + yp1Width]))
				{
					pOut[pix + B_OFFSET] = (pIn[x + 1 + ym1Width] + pIn[x - 1 + yp1Width]) >> 1;
				}
				else
					pOut[pix + B_OFFSET] = ((pIn[x - 1 + ym1Width] +
					pIn[x + 1 + ym1Width] +
					pIn[x - 1 + yp1Width] +
					pIn[x + 1 + yp1Width]) >> 2);


				if (abs(pIn[x - 1 + yWidth] - pIn[x + 1 + yWidth])<abs(pIn[x + ym1Width] - pIn[x + yp1Width]))
				{
					pOut[pix + G_OFFSET] = (pIn[x - 1 + yWidth] + pIn[x + 1 + yWidth]) >> 1;
				}
				else if (abs(pIn[x - 1 + yWidth] - pIn[x + 1 + yWidth])>abs(pIn[x + ym1Width] - pIn[x + yp1Width]))
				{
					pOut[pix + G_OFFSET] = (pIn[x + ym1Width] + pIn[x + yp1Width]) >> 1;
				}
				else
					pOut[pix + G_OFFSET] = ((pIn[x - 1 + yWidth] +
					pIn[x + 1 + yWidth] +
					pIn[x + ym1Width] +
					pIn[x + yp1Width]) >> 2);

				pOut[pix + R_OFFSET] = pIn[x + yWidth];
			}
			else
			{   //EVEN(y) EVEN(x)
				pOut[pix + B_OFFSET] = ((pIn[x + ym1Width] +
					pIn[x + yp1Width]) >> 1);
				pOut[pix + G_OFFSET] = ((pIn[x + yWidth] << 2) + (pIn[x - 1 + ym1Width] + pIn[x + 1 + ym1Width] + pIn[x - 1 + yp1Width] + pIn[x + 1 + yp1Width])) >> 3;
				pOut[pix + R_OFFSET] = ((pIn[x - 1 + yWidth] +
					pIn[x + 1 + yWidth]) >> 1);
			}
		}
	}
}

}

@ermig1979
Copy link
Owner

I will add this issue to future plans.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants