Exemplo n.º 1
0
void RGB2YCrCb(signed char pixelmatrix[MACRO_BLOCK_SIZE][MACRO_BLOCK_SIZE*3],signed char YMatrix[MATRIX_SIZE][MATRIX_SIZE],signed char CrMatrix[MATRIX_SIZE][MATRIX_SIZE],signed char CbMatrix[MATRIX_SIZE][MATRIX_SIZE], unsigned int sample)
{
	unsigned int row, col, rowoffset, coloffset, xoffset, yoffset;
	for(row = 0;row < MATRIX_SIZE; row++) {
		for(col = 0; col < MATRIX_SIZE; col++) {
			coloffset = (sample&0x01)*8;
			rowoffset = (sample&0x02)*4;
			YMatrix[row][col] = RGB2Y(pixelmatrix[row+rowoffset][(col+coloffset)*3+2],pixelmatrix[row+rowoffset][(col+coloffset)*3+1],pixelmatrix[row+rowoffset][(col+coloffset)*3]) - 128;
			if (col%2==0) {
				yoffset = (sample&0x01)*4;
				xoffset = (sample&0x02)*2;
				if (row%2==0) {
					CrMatrix[xoffset+(row>>1)][yoffset+(col>>1)] = RGB2Cr(pixelmatrix[row+rowoffset][(col+coloffset)*3+2],pixelmatrix[row+rowoffset][(col+coloffset)*3+1],pixelmatrix[row+rowoffset][(col+coloffset)*3]) - 128;
				} else {
					CbMatrix[xoffset+((row)>>2)][yoffset+(col>>2)] = RGB2Cb(pixelmatrix[row+rowoffset][(col+coloffset)*3+2],pixelmatrix[row+rowoffset][(col+coloffset)*3+1],pixelmatrix[row+rowoffset][(col+coloffset)*3]) - 128;
				}
			}
void subsample(const BGR rgb[16][16], short cb[8][8], short cr[8][8])
{
	for (unsigned r = 0; r < 8; r++)
		for (unsigned c = 0; c < 8; c++)
		{
			unsigned rr = (r << 1);
			unsigned cc = (c << 1);

			// calculating average values
			color R = (rgb[rr][cc].Red + rgb[rr][cc + 1].Red + rgb[rr + 1][cc].Red + rgb[rr + 1][cc + 1].Red) >> 2;
			color G = (rgb[rr][cc].Green + rgb[rr][cc + 1].Green + rgb[rr + 1][cc].Green + rgb[rr + 1][cc + 1].Green) >> 2;
			color B = (rgb[rr][cc].Blue + rgb[rr][cc + 1].Blue + rgb[rr + 1][cc].Blue + rgb[rr + 1][cc + 1].Blue) >> 2;

			cb[r][c] = (short) RGB2Cb(R, G, B) - 128;
			cr[r][c] = (short) RGB2Cr(R, G, B) - 128;
		}
}
Exemplo n.º 3
0
void subsample2(const BGR rgb[16][16], conv Y[2][2][8][8], conv cb[8][8], conv cr[8][8])
{
	unsigned r, c;

	for (r = 0; r < 16; r += 2)
	for (c = 0; c < 16; c += 2)
	{
		//unsigned rr, cc;
		unsigned i, j, k, l;
		unsigned sR, sG, sB;
		unsigned R, G, B;

		i = r >> 3, j = c >> 3,
		k = r & 7, l = c & 7;

		sR = R = rgb[r][c].Red,
		sG = G = rgb[r][c].Green,
		sB = B = rgb[r][c].Blue;
		Y[i][j][k][l] = RGB2Y(R, G, B)-128;

		sR += R = rgb[r][c+1].Red,
		sG += G = rgb[r][c+1].Green,
		sB += B = rgb[r][c+1].Blue;
		Y[i][j][k][l+1] = RGB2Y(R, G, B)-128;

		sR += R = rgb[r+1][c].Red,
		sG += G = rgb[r+1][c].Green,
		sB += B = rgb[r+1][c].Blue;
		Y[i][j][k+1][l] = RGB2Y(R, G, B)-128;

		sR += R = rgb[r+1][c+1].Red,
		sG += G = rgb[r+1][c+1].Green,
		sB += B = rgb[r+1][c+1].Blue;
		Y[i][j][k+1][l+1] = RGB2Y(R, G, B)-128;

		// calculating an average values
		R = sR >> 2,
		G = sG >> 2,
		B = sB >> 2;

		//rr = r >> 1, cc = c >> 1;

		cb[r>>1][c>>1] = (conv)RGB2Cb(R, G, B)-128;
		cr[r>>1][c>>1] = (conv)RGB2Cr(R, G, B)-128;
	}
}