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

Subversion Repositories mpdma

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 10 quickwayne
#include "xparameters.h"
2
#include "xutil.h"
3
#include "mb_interface.h"
4
#include "fifo_link.h"
5
 
6
#include "ejpgl.h"
7
#include "mb-dct.h"
8
#include "mb-weights.h"
9
 
10
signed short dctresult[MATRIX_SIZE][MATRIX_SIZE];
11
 
12
#define XPAR_FSL_FIFO_LINK_0_INPUT_SLOT_ID 0
13
#define XPAR_FSL_FIFO_LINK_0_OUTPUT_SLOT_ID 0
14
 
15
int dct_init_start() {
16
 
17
        return 0;
18
 
19
}
20
 
21
/*
22
        Function Name: dct
23
 
24
        Operation: Find the 8x8 DCT of an array using separable DCT
25
        First, finds 1-d DCT along rows, storing the result in inter[][]
26
        Then, 1-d DCT along columns of inter[][] is found
27
 
28
        Input: pixels is the 8x8 input array
29
 
30
        Output: dct is the 8x8 output array
31
*/
32
 
33
void dct(signed char pixels[8][8], int color)
34
{
35
        FILE * file;
36
        int inr, inc;           /* rows and columns of input image */
37
        int intr, intc;         /* rows and columns of intermediate image */
38
        int outr, outc;         /* rows and columns of dct */
39
        int f_val;              /* cumulative sum */
40
        int inter[8][8];        /* stores intermediate result */
41
        int i,j,k;
42
        k=0;
43
    //    file = fopen("weights.h","w+");
44
      //  fprintf(file,"double weights1[512] = {");
45
        /* find 1-d dct along rows */
46
        for (intr=0; intr<8; intr++)
47
                for (intc=0; intc<8; intc++) {
48
                        for (i=0,f_val=0; i<8; i++) {
49
 
50
                                f_val += (pixels[intr][i]* weights[k]);//cos((double)(2*i+1)*(double)intc*PI/16);
51
                                k++;
52
                          //     fprintf(file, "\n%.0f,",cos((double)(2*i+1)*(double)intc*PI/16)*16384);
53
                        }
54
                        if (intc!=0)
55
                                inter[intr][intc] =  f_val>>15;
56
                        else
57
                                inter[intr][intc] =  (11585*(f_val>>14))>>15;
58
 
59
                }
60
   //     fprintf(file,"\n};");
61
   //     fclose(file);
62
         k=0;
63
        /* find 1-d dct along columns */
64
        for (outc=0; outc<8; outc++)
65
                for (outr=0; outr<8; outr++) {
66
                        for (i=0,f_val=0; i<8; i++) {
67
                                f_val += (inter[i][outc] *weights[k]);
68
                                k++;
69
                        }
70
                        if (outr!=0)
71
                                dctresult[outr][outc] = f_val>>15;
72
                        else
73
                                dctresult[outr][outc] = (11585*(f_val>>14)>>15);
74
                }
75
 
76
}
77
 
78
 
79
 
80
/*****************************************************************
81
    UNCOMMENT THIS SECTION TO TEST 2D DCT
82
*****************************************************************/
83
 
84
signed char ipixels[8][8];
85
 
86
main()
87
{
88
 
89
  unsigned int i,j;
90
  int result;
91
  int color;
92
 
93
  dct_init_start();
94
 
95
  for (;;) {
96
        read_from_fsl(color, XPAR_FSL_FIFO_LINK_0_INPUT_SLOT_ID);
97
 
98 18 quickwayne
        if (color==0xff) {
99
                write_into_fsl(color, XPAR_FSL_FIFO_LINK_0_OUTPUT_SLOT_ID);
100 10 quickwayne
                }
101 18 quickwayne
        else {
102
                for (i=0; i<64; i++) {
103
                        read_from_fsl(result, XPAR_FSL_FIFO_LINK_0_INPUT_SLOT_ID);
104
                        ((signed char*)ipixels)[i]=result;
105
                        }
106
 
107
              dct(ipixels, color);
108
 
109
                write_into_fsl(color, XPAR_FSL_FIFO_LINK_0_OUTPUT_SLOT_ID);
110
 
111
                for (i=0; i<64; i++) {
112
                        write_into_fsl(((short*)dctresult)[i], XPAR_FSL_FIFO_LINK_0_OUTPUT_SLOT_ID);
113
                        }
114
                }
115 10 quickwayne
 
116 18 quickwayne
        }
117 10 quickwayne
 
118
}

powered by: WebSVN 2.1.0

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