URL
https://opencores.org/ocsvn/mpdma/mpdma/trunk
[/] [mpdma/] [trunk/] [mb-bmp2jpg/] [ColorConversion.c] - Blame information for rev 7
Go to most recent revision |
Details |
Compare with Previous |
View Log
Line No. |
Rev |
Author |
Line |
1 |
7 |
quickwayne |
#include <stdio.h>
|
2 |
|
|
#include "io.h"
|
3 |
|
|
|
4 |
|
|
#define RGB2Y(r, g, b) (((66*r + 129*g + 25*b + 128)>>8)+128)
|
5 |
|
|
#define RGB2Cr(r, g, b) (((-38*r - 74*g + 112*b + 128)>>8)+128)
|
6 |
|
|
#define RGB2Cb(r, g, b) (((112*r - 94*g - 18*b + 128)>>8)+128)
|
7 |
|
|
|
8 |
|
|
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)
|
9 |
|
|
{
|
10 |
|
|
unsigned int row, col, rowoffset, coloffset, xoffset, yoffset;
|
11 |
|
|
for(row = 0;row < MATRIX_SIZE; row++) {
|
12 |
|
|
for(col = 0; col < MATRIX_SIZE; col++) {
|
13 |
|
|
coloffset = (sample&0x01)*8;
|
14 |
|
|
rowoffset = (sample&0x02)*4;
|
15 |
|
|
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;
|
16 |
|
|
if (col%2==0) {
|
17 |
|
|
yoffset = (sample&0x01)*4;
|
18 |
|
|
xoffset = (sample&0x02)*2;
|
19 |
|
|
if (row%2==0) {
|
20 |
|
|
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;
|
21 |
|
|
} else {
|
22 |
|
|
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;
|
23 |
|
|
}
|
24 |
|
|
}
|
25 |
|
|
}
|
26 |
|
|
}
|
27 |
|
|
}
|
© copyright 1999-2025
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.