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

Subversion Repositories mpdma

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

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

powered by: WebSVN 2.1.0

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