OpenCores
URL https://opencores.org/ocsvn/mpdma/mpdma/trunk

Subversion Repositories mpdma

[/] [mpdma/] [trunk/] [mb-cc/] [mb-cc.c] - Blame information for rev 28

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 20 quickwayne
#include "xutil.h"
2
#include "mb_interface.h"
3
#include "fifo_link.h"
4
 
5
#include "ejpgl.h"
6
#include "io.h"
7
 
8
#define XPAR_FSL_FIFO_LINK_0_INPUT_SLOT_ID 0
9
#define XPAR_FSL_FIFO_LINK_0_OUTPUT_SLOT_ID 0
10
 
11
 
12
#define RGB2Y(r, g, b)     (((66*r + 129*g + 25*b + 128)>>8)+128)
13
#define RGB2Cr(r, g, b)    (((-38*r - 74*g + 112*b + 128)>>8)+128)
14
#define RGB2Cb(r, g, b)   (((112*r - 94*g - 18*b + 128)>>8)+128)
15
 
16
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)
17
{
18
        unsigned int row, col, rowoffset, coloffset, xoffset, yoffset;
19
        for(row = 0;row < MATRIX_SIZE; row++) {
20
                for(col = 0; col < MATRIX_SIZE; col++) {
21
                        coloffset = (sample&0x01)*8;
22
                        rowoffset = (sample&0x02)*4;
23
                        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;
24
                        if (col%2==0) {
25
                                yoffset = (sample&0x01)*4;
26
                                xoffset = (sample&0x02)*2;
27
                                if (row%2==0) {
28
                                        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;
29
                                } else {
30
                                        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;
31
                                }
32
                        }
33
                }
34
        }
35
}
36
 
37
signed char pixelmatrix[MACRO_BLOCK_SIZE][MACRO_BLOCK_SIZE*3];
38
signed char YMatrix[MATRIX_SIZE][MATRIX_SIZE];
39
signed char CrMatrix[MATRIX_SIZE][MATRIX_SIZE];
40
signed char CbMatrix[MATRIX_SIZE][MATRIX_SIZE];
41
 
42
main() {
43
  unsigned int i,j;
44
  int result;
45
  int sample;
46
  int color;
47
  int msg;
48
 
49
  for (;;) {
50
                read_from_fsl(msg, XPAR_FSL_FIFO_LINK_0_INPUT_SLOT_ID);
51
                if (msg == 0xff) {
52
                        write_into_fsl(color, XPAR_FSL_FIFO_LINK_0_OUTPUT_SLOT_ID);
53
                        continue;
54
                        }
55
 
56
                for (i=0; i<MACRO_BLOCK_SIZE*MACRO_BLOCK_SIZE*3; i++) {
57
                        read_from_fsl(result, XPAR_FSL_FIFO_LINK_0_INPUT_SLOT_ID);
58
                        ((signed char*)pixelmatrix)[i]=result;
59
                        }
60
 
61
                for(sample=0;sample<5;sample++) {
62
                        if(sample<4) {
63
                                RGB2YCrCb(pixelmatrix,YMatrix,CrMatrix,CbMatrix,sample);
64
                                color = 0;                                               //Y-encoding
65
                                write_into_fsl(color, XPAR_FSL_FIFO_LINK_0_OUTPUT_SLOT_ID);
66
                        for (i=0; i<MATRIX_SIZE*MATRIX_SIZE; i++) {
67
                                result = ((signed char*)YMatrix)[i];
68
                                write_into_fsl(result, XPAR_FSL_FIFO_LINK_0_OUTPUT_SLOT_ID);
69
                                }
70
                                } else {
71
 
72
                                color = 1;                                              //Cr-encoding
73
                                write_into_fsl(color, XPAR_FSL_FIFO_LINK_0_OUTPUT_SLOT_ID);
74
                        for (i=0; i<MATRIX_SIZE*MATRIX_SIZE; i++) {
75
                                result = ((signed char*)CrMatrix)[i];
76
                                write_into_fsl(result, XPAR_FSL_FIFO_LINK_0_OUTPUT_SLOT_ID);
77
                                }
78
                                color = 2;                                              //Cb-encoding
79
                                write_into_fsl(color, XPAR_FSL_FIFO_LINK_0_OUTPUT_SLOT_ID);
80
                                                        //Cb-encoding
81
                        for (i=0; i<MATRIX_SIZE*MATRIX_SIZE; i++) {
82
                                result = ((signed char*)CbMatrix)[i];
83
                                write_into_fsl(result, XPAR_FSL_FIFO_LINK_0_OUTPUT_SLOT_ID);
84
                                }
85
                                }
86
 
87
                        }
88
 
89
        }
90
 
91
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.