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

Subversion Repositories mpdma

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 quickwayne
#include "xparameters.h"
2
#include "xutil.h"
3
#include "mb_interface.h"
4
#include "fifo_link.h"
5
 
6
#include "ejpgl.h"
7
 
8 18 quickwayne
#define XPAR_FSL_FIFO_LINK_0_INPUT_SLOT_ID 0
9
#define  XPAR_FSL_FIFO_LINK_0_OUTPUT_SLOT_ID 0
10
 
11
 
12 13 quickwayne
int dct_init_start() {
13
 
14
        return 0;
15
 
16
}
17
 
18 18 quickwayne
int dct_end_done() {
19 13 quickwayne
 
20 18 quickwayne
        return 0;
21
 
22
}
23
 
24 13 quickwayne
void dct(signed char pixels[8][8], int color)
25
{
26
        int i;
27
        long result;
28
 
29 18 quickwayne
        check_fsl();
30 13 quickwayne
        write_into_fsl(color, XPAR_FSL_FIFO_LINK_0_OUTPUT_SLOT_ID);
31
 
32
       for (i=0; i<64; i++) {
33 18 quickwayne
                check_fsl();
34 13 quickwayne
        write_into_fsl(((char*)pixels)[i], XPAR_FSL_FIFO_LINK_0_OUTPUT_SLOT_ID);
35
        }
36
 
37 18 quickwayne
/*      for (i=0; i<64; i++){
38
        read_from_fsl(result, XPAR_FSL_FIFO_LINK_0_INPUT_SLOT_ID);
39
                ((short*)dctresult)[i] = result;
40
                } */
41
 
42
// Read from FSL in non-blocking mode
43
        check_fsl();
44
 
45
}
46
 
47
 
48
 
49
#if 0
50
signed short dctresult[MATRIX_SIZE][MATRIX_SIZE];
51
 
52
void dct(signed char pixels[8][8], int color)
53
{
54
        int i;
55
        long result;
56
 
57
        write_into_fsl(color, XPAR_FSL_FIFO_LINK_0_OUTPUT_SLOT_ID);
58
 
59
       for (i=0; i<64; i++) {
60
        write_into_fsl(((char*)pixels)[i], XPAR_FSL_FIFO_LINK_0_OUTPUT_SLOT_ID);
61
        }
62
 
63 13 quickwayne
        for (i=0; i<64; i++){
64
        read_from_fsl(result, XPAR_FSL_FIFO_LINK_0_INPUT_SLOT_ID);
65
                ((short*)dctresult)[i] = result;
66
                }
67
 
68
        zzq_encode(dctresult, color);
69
 
70
}
71
 
72 18 quickwayne
#endif
73
 
74 13 quickwayne
#if 0
75 7 quickwayne
#include <stdio.h>
76
#include "dct.h"
77
#include "weights.h"
78
 
79
#include "ejpgl.h"
80
 
81
signed short dctresult[MATRIX_SIZE][MATRIX_SIZE];
82
 
83
#ifdef MULTITASK
84
 
85
/******************************************/
86
/*
87
/*  DCT task
88
/*  for multitask RTOS implementation or
89
/*       multiprocessor implementation
90
/*
91
/******************************************/
92
 
93
void dct_task(void* dct_cfg) {
94
        struct dct_cfg_block* cb;
95
 
96
        cb = (struct dct_cfg_block*)dct_cfg;
97
 
98
        for (;;) {
99
                semTake();
100
                dct(cb->input, cb->output);
101
                semGive();
102
                }
103
 
104
}
105
 
106
#endif
107
 
108
int dct_init_start() {
109
 
110
        return 0;
111
 
112
}
113
 
114
/*
115
        Function Name: dct
116
 
117
        Operation: Find the 8x8 DCT of an array using separable DCT
118
        First, finds 1-d DCT along rows, storing the result in inter[][]
119
        Then, 1-d DCT along columns of inter[][] is found
120
 
121
        Input: pixels is the 8x8 input array
122
 
123
        Output: dct is the 8x8 output array
124
*/
125
 
126
void dct(signed char pixels[8][8], int color)
127
{
128
        FILE * file;
129
        int inr, inc;           /* rows and columns of input image */
130
        int intr, intc;         /* rows and columns of intermediate image */
131
        int outr, outc;         /* rows and columns of dct */
132
        int f_val;              /* cumulative sum */
133
        int inter[8][8];        /* stores intermediate result */
134
        int i,j,k;
135
        k=0;
136
    //    file = fopen("weights.h","w+");
137
      //  fprintf(file,"double weights1[512] = {");
138
        /* find 1-d dct along rows */
139
        for (intr=0; intr<8; intr++)
140
                for (intc=0; intc<8; intc++) {
141
                        for (i=0,f_val=0; i<8; i++) {
142
 
143
                                f_val += (pixels[intr][i]* weights[k]);//cos((double)(2*i+1)*(double)intc*PI/16);
144
                                k++;
145
                          //     fprintf(file, "\n%.0f,",cos((double)(2*i+1)*(double)intc*PI/16)*16384);
146
                        }
147
                        if (intc!=0)
148
                                inter[intr][intc] =  f_val>>15;
149
                        else
150
                                inter[intr][intc] =  (11585*(f_val>>14))>>15;
151
 
152
                }
153
   //     fprintf(file,"\n};");
154
   //     fclose(file);
155
         k=0;
156
        /* find 1-d dct along columns */
157
        for (outc=0; outc<8; outc++)
158
                for (outr=0; outr<8; outr++) {
159
                        for (i=0,f_val=0; i<8; i++) {
160
                                f_val += (inter[i][outc] *weights[k]);
161
                                k++;
162
                        }
163
                        if (outr!=0)
164
                                dctresult[outr][outc] = f_val>>15;
165
                        else
166
                                dctresult[outr][outc] = (11585*(f_val>>14)>>15);
167
                }
168
 
169
        zzq_encode(dctresult, color);
170
 
171
 
172
}
173
 
174
 
175
 
176
/*****************************************************************
177
    UNCOMMENT THIS SECTION TO TEST 2D DCT
178
*****************************************************************/
179
 
180
/*
181
main()
182
{
183
 
184
  unsigned char inputmatrix[8][8];
185
  unsigned char outputmatrix[8][8];
186
  unsigned int i,j;
187
 
188
 
189
  printf("Input Matrix (8*8) :-\n");
190
  for (i=0; i<8; i++){
191
          printf("\n");
192
          for (j=0;j<8;j++){
193
                   inputmatrix[i][j] = i*8+j;
194
                   printf("%4d",inputmatrix[i][j]);
195
          }
196
 
197
  }
198
 
199
 
200
 
201
  dct(inputmatrix,outputmatrix);
202
 
203
  printf("\n\nOutput Matrix (8*8) :-\n");
204
 
205
   for (i=0; i<8; i++){
206
           printf("\n");
207
          for (j=0;j<8;j++){
208
           printf("%4d",outputmatrix[i][j]);
209
 
210
          }
211
 
212
  }
213
printf("\n");
214
 
215
}
216
*/
217 13 quickwayne
#endif
218 18 quickwayne
 

powered by: WebSVN 2.1.0

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