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

Subversion Repositories mpdma

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

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

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

powered by: WebSVN 2.1.0

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