OpenCores
URL https://opencores.org/ocsvn/mb-jpeg/mb-jpeg/trunk

Subversion Repositories mb-jpeg

[/] [mb-jpeg/] [tags/] [Step2_2/] [bmp2jpg_mb/] [dct.c] - Blame information for rev 68

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

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

powered by: WebSVN 2.1.0

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