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

Subversion Repositories mpdma

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 quickwayne
#pragma argsused
2
/*
3
Only encoder
4
This version works correctly, it is tested with testcase.jpg
5
The translation into real huffman codes works.
6
Changed: If huffman wants to send 0xFFxx (FF in one byte) than there must be 0x00 inserted between FF and xx
7
possible fault in finish send:
8
-must it be filled up with zeros?          YES
9
-must it be filled up to one bye? or 2 byte? --> in this code there is filled up to 2 bytes, but I (joris) thinks this must be filled up to 1 byte.
10
 still dont know
11
- 24-11-05 code clean up
12
- 24-11-05 tables added for color
13
 
14
 
15
 
16
Block numbers:
17
Y = 0
18
cb =1
19
cr= 2
20
*/
21
//---------------------------------------------------------------------------
22 18 quickwayne
 
23
int vlc_init_start() {
24
 
25
        return 0;
26
 
27
}
28
 
29
void vlc_end_done() {
30
 
31
}
32
 
33
#if 0
34 7 quickwayne
#include <stdio.h>
35
 
36
static unsigned int vlc_remaining;
37
static unsigned char vlc_amount_remaining;
38
static unsigned char dcvalue[4];   // 3 is enough
39
 
40
int vlc_init_start() {
41
 
42
       vlc_remaining=0x00;
43
       vlc_amount_remaining=0x00;
44
        memset(dcvalue, 0, 4);
45
        return 0;
46
 
47
}
48
 
49
#define vlc_output_byte(c)             put_char(c)
50
 
51
#ifdef __MULTI_TASK
52
 
53
void vlc_task() {
54
 
55
 
56
}
57
 
58
#endif
59
 
60
#ifdef __MULTI_PROCESSOR
61
 
62
int main() {
63
 
64
        for (;;) {
65
 
66
 
67
                }
68
 
69
}
70
 
71
#endif
72
 
73
static unsigned char convertDCMagnitudeCLengthTable[16] = {
74
  0x02, 0x02, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
75
  0x08, 0x09, 0x0a, 0x0b, 0x00, 0x00, 0x00, 0x00
76
};
77
 
78
static unsigned short convertDCMagnitudeCOutTable[16] = {
79
        0x0000, 0x0001, 0x0002, 0x0006, 0x000e, 0x001e, 0x003e, 0x007e,
80
        0x00fe, 0x01fe, 0x03fe, 0x07fe, 0x0000, 0x0000, 0x0000, 0x0000
81
};
82
 
83
void ConvertDCMagnitudeC(unsigned char magnitude,unsigned short int *out, unsigned short int *lenght)
84
{
85
        unsigned char len;
86
 
87
        if ((magnitude>16) || ((len=convertDCMagnitudeCLengthTable[magnitude])==0)) {
88
#ifndef __MICROBLAZE
89
                printf("WAARDE STAAT NIET IN TABEL!!!!!!!!!!!!!!!!!!!!\n");
90
#endif
91
                }
92
        *lenght = len;
93
        *out = convertDCMagnitudeCOutTable[magnitude];
94
 
95
#if 0   
96
        switch (magnitude) {
97
                case 0x00 : *out=0x0000; *lenght=2; break;
98
                case 0x01 : *out=0x0001; *lenght=2; break;
99
                case 0x02 : *out=0x0002; *lenght=2; break;
100
                case 0x03 : *out=0x0006; *lenght=3; break;
101
                case 0x04 : *out=0x000e; *lenght=4; break;
102
                case 0x05 : *out=0x001e; *lenght=5; break;
103
                case 0x06 : *out=0x003e; *lenght=6; break;
104
                case 0x07 : *out=0x007e; *lenght=7; break;
105
                case 0x08 : *out=0x00fe; *lenght=8; break;
106
                case 0x09 : *out=0x01fe; *lenght=9; break;
107
                case 0x0a : *out=0x03fe; *lenght=10; break;
108
                case 0x0b : *out=0x07fe; *lenght=11; break;
109
        }
110
#endif
111
 
112
}
113
 
114
static unsigned char convertACMagnitudeCLengthTable[256] = {
115
0x02, 0x02, 0x03, 0x04, 0x05, 0x05, 0x06, 0x07, 0x09, 0x0a, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,    // 00 - 0f
116
0x00, 0x04, 0x06, 0x08, 0x09, 0x0b, 0x0c, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // 10 - 1f
117
0x00, 0x05, 0x08, 0x0a, 0x0c, 0x0f, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // 20 - 2f
118
0x00, 0x05, 0x08, 0x0a, 0x0c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // 30 - 3f
119
0x00, 0x06, 0x09, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // 40 - 4f
120
0x00, 0x06, 0x0a, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // 50 - 5f
121
0x00, 0x07, 0x0b, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // 60 - 6f
122
0x00, 0x07, 0x0b, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // 70 - 7f
123
0x00, 0x08, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // 80 - 8f
124
0x00, 0x09, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // 90 - 9f
125
0x00, 0x09, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // a0 - af
126
0x00, 0x09, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // b0 - bf
127
0x00, 0x09, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // c0 - cf
128
0x00, 0x0b, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // d0 - df
129
0x00, 0x0e, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // e0 - ef
130
0x0a, 0x0f, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00
131
};
132
 
133
static unsigned short convertACMagnitudeCOutTable[256] = {
134
0x0000, 0x0001, 0x0004, 0x000a, 0x0018, 0x0019, 0x0038, 0x0078, 0x01f4, 0x03f6, 0x0ff4, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // 00 - 0f
135
0x0000, 0x000b, 0x0039, 0x00f6, 0x01f5, 0x07f6, 0x0ff5, 0xff88, 0xff89, 0xff8a, 0xff8b, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // 10 - 1f
136
0x0000, 0x001a, 0x00f7, 0x03f7, 0x0ff6, 0x7fc2, 0xff8c, 0xff8d, 0xff8e, 0xff8f, 0xff90, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // 20 - 2f
137
0x0000, 0x001b, 0x00f8, 0x03f8, 0x0ff7, 0xff91, 0xff92, 0xff93, 0xff94, 0xff95, 0xff96, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // 30 - 3f
138
0x0000, 0x003a, 0x01f6, 0xff97, 0xff98, 0xff99, 0xff9a, 0xff9b, 0xff9c, 0xff9d, 0xff9e, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // 40 - 4f
139
0x0000, 0x003b, 0x03f9, 0xff9f, 0xffa0, 0xffa1, 0xFFA2, 0xFFA3, 0xFFA4, 0xFFA5, 0xFFA6, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // 50 - 5f
140
0x0000, 0x0079, 0x07f7, 0xffa7, 0xffa8, 0xffa9, 0xffaa, 0xffab, 0xFFAc, 0xFFAf, 0xFFAe, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // 60 - 6f
141
0x0000, 0x007a, 0x07f8, 0xffaf, 0xffb0, 0xFFB1, 0xFFB2, 0xFFB3, 0xFFB4, 0xFFB5, 0xFFB6, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // 70 - 7f
142
0x0000, 0x00f9, 0xffb7, 0xFFB8, 0xFFB9, 0xFFBa, 0xFFBb, 0xFFBc, 0xFFBd, 0xFFBe, 0xFFBf, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // 80 - 8f
143
0x0000, 0x01f7, 0xffc0, 0xffc1, 0xFFC2, 0xFFC3, 0xFFC4, 0xFFC5, 0xFFC6, 0xFFC7, 0xFFC8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // 90 - 9f
144
0x0000, 0x01f8, 0xffc9, 0xFFCa, 0xFFCb, 0xFFCc, 0xFFCd, 0xFFCe, 0xFFCf, 0xFFd0, 0xFFd1, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // a0 - af
145
0x0000, 0x01f9, 0xFFD2, 0xFFD3, 0xFFD4, 0xFFD5, 0xFFD6, 0xFFD7, 0xFFD8, 0xFFD9, 0xFFDa, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // b0 - bf
146
0x0000, 0x01fa, 0xFFDb, 0xFFDc, 0xFFDd, 0xFFDe, 0xFFDf, 0xFFe0, 0xFFe1, 0xFFe2, 0xFFe3, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // c0 - cf
147
0x0000, 0x07f9, 0xFFE4, 0xFFE5, 0xFFE6, 0xFFE7, 0xFFE8, 0xFFE9, 0xFFEa, 0xFFEb, 0xFFEc, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // d0 - df
148
0x0000, 0x3fe0, 0xffed, 0xFFEe, 0xFFEf, 0xFFf0, 0xFFF1, 0xFFF2, 0xFFF3, 0xFFF4, 0xFFF5, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // e0 - ef
149
0x03fa, 0x7fc3, 0xFFF6, 0xFFF7, 0xFFF8, 0xFFF9, 0xFFFA, 0xFFFB, 0xFFFC, 0xFFFD, 0xFFFE, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
150
};
151
 
152
//===========================================================================
153
void ConvertACMagnitudeC(unsigned char magnitude,unsigned short int *out, unsigned short int *lenght)
154
{
155
        unsigned char len;
156
 
157
        len = convertACMagnitudeCLengthTable[magnitude];
158
        if (!len) {
159
#ifndef __MICROBLAZE
160
                printf("WAARDE STAAT NIET IN TABEL!!!!!!!!!!!!!!!!!!!!\n");
161
#endif
162
                }
163
        *lenght = len;
164
        *out = convertACMagnitudeCOutTable[magnitude];
165
 
166
#if 0
167
        switch (magnitude) {
168
case 0x00 :  *lenght=0x02; *out=0x0000; break; //1010
169
case 0x01 :  *lenght=0x02; *out=0x0001; break; //00
170
case 0x02 :  *lenght=0x03; *out=0x0004; break; //01
171
case 0x03 :  *lenght=0x04; *out=0x000a; break; //100
172
case 0x04 :  *lenght=0x05; *out=0x0018; break; //1011
173
case 0x05 :  *lenght=0x05; *out=0x0019; break; //11010
174
case 0x06 :  *lenght=0x06; *out=0x0038; break; //1111000
175
case 0x07 :  *lenght=0x07; *out=0x0078; break; //11111000
176
case 0x08 :  *lenght=0x09; *out=0x01f4; break; //1111110110
177
case 0x09 :  *lenght=0x0a; *out=0x03f6; break; //1111111110000010
178
case 0x0A :  *lenght=0x0c; *out=0x0ff4; break; //1111111110000011
179
case 0x11 :  *lenght=0x04; *out=0x000b; break; //1100
180
case 0x12 :  *lenght=0x06; *out=0x0039; break; //11011
181
case 0x13 :  *lenght=0x08; *out=0x00f6; break; //1111001
182
case 0x14 :  *lenght=0x09; *out=0x01f5; break; //111110110
183
case 0x15 :  *lenght=0x0b; *out=0x07f6; break; //11111110110
184
case 0x16 :  *lenght=0x0c; *out=0x0ff5; break; //1111111110000100
185
case 0x17 :  *lenght=0x10; *out=0xff88; break; //1111111110000101
186
case 0x18 :  *lenght=0x10; *out=0xff89; break; //1111111110000110
187
case 0x19 :  *lenght=0x10; *out=0xff8a; break; //1111111110000111
188
case 0x1A :  *lenght=0x10; *out=0xff8b; break; //1111111110001000
189
case 0x21 :  *lenght=0x05; *out=0x001a; break; //11100
190
case 0x22 :  *lenght=0x08; *out=0x00f7; break; //11111001
191
case 0x23 :  *lenght=0x0a; *out=0x03f7; break; //1111110111
192
case 0x24 :  *lenght=0x0c; *out=0x0ff6; break; //111111110100
193
case 0x25 :  *lenght=0x0f; *out=0x7fc2; break; //1111111110001001
194
case 0x26 :  *lenght=0x10; *out=0xff8c; break; //1111111110001010
195
case 0x27 :  *lenght=0x10; *out=0xff8d; break; //1111111110001011
196
case 0x28 :  *lenght=0x10; *out=0xff8e; break; //1111111110001100
197
case 0x29 :  *lenght=0x10; *out=0xff8f; break; //1111111110001101
198
case 0x2A :  *lenght=0x10; *out=0xff90; break; //1111111110001110
199
case 0x31 :  *lenght=0x05; *out=0x001b; break; //111010
200
case 0x32 :  *lenght=0x08; *out=0x00f8; break; //111110111
201
case 0x33 :  *lenght=0x0a; *out=0x03f8; break; //111111110101
202
case 0x34 :  *lenght=0x0c; *out=0x0ff7; break; //1111111110001111
203
case 0x35 :  *lenght=0x10; *out=0xff91; break; //1111111110010000
204
case 0x36 :  *lenght=0x10; *out=0xff92; break; //1111111110010001
205
case 0x37 :  *lenght=0x10; *out=0xff93; break; //1111111110010010
206
case 0x38 :  *lenght=0x10; *out=0xff94; break; //1111111110010011
207
case 0x39 :  *lenght=0x10; *out=0xff95; break; //1111111110010100
208
case 0x3A :  *lenght=0x10; *out=0xff96; break; //1111111110010101
209
case 0x41 :  *lenght=0x06; *out=0x003a; break; //111011
210
case 0x42 :  *lenght=0x09; *out=0x01f6; break; //1111111000
211
case 0x43 :  *lenght=0x10; *out=0xff97; break; //1111111110010110
212
case 0x44 :  *lenght=0x10; *out=0xff98; break; //1111111110010111
213
case 0x45 :  *lenght=0x10; *out=0xff99; break; //1111111110011000
214
case 0x46 :  *lenght=0x10; *out=0xff9a; break; //1111111110011001
215
case 0x47 :  *lenght=0x10; *out=0xff9b; break; //1111111110011010
216
case 0x48 :  *lenght=0x10; *out=0xff9c; break; //1111111110011011
217
case 0x49 :  *lenght=0x10; *out=0xff9d; break; //1111111110011100
218
case 0x4A :  *lenght=0x10; *out=0xff9e; break; //1111111110011101
219
case 0x51 :  *lenght=0x06; *out=0x003b; break; //1111010
220
case 0x52 :  *lenght=0x0a; *out=0x03f9; break; //11111110111
221
case 0x53 :  *lenght=0x10; *out=0xff9f; break; //1111111110011110
222
case 0x54 :  *lenght=0x10; *out=0xffa0; break; //1111111110011111
223
case 0x55 :  *lenght=0x10; *out=0xffa1; break; //1111111110100000
224
case 0x56 :  *lenght=0x10; *out=0xFFA2; break; //1111111110100001
225
case 0x57 :  *lenght=0x10; *out=0xFFA3; break; //1111111110100010
226
case 0x58 :  *lenght=0x10; *out=0xFFA4; break; //1111111110100011
227
case 0x59 :  *lenght=0x10; *out=0xFFA5; break; //1111111110100100
228
case 0x5A :  *lenght=0x10; *out=0xFFA6; break; //1111111110100101
229
case 0x61 :  *lenght=0x07; *out=0x0079; break; //1111011
230
case 0x62 :  *lenght=0x0b; *out=0x07f7; break; //111111110110
231
case 0x63 :  *lenght=0x10; *out=0xffa7; break; //1111111110100110
232
case 0x64 :  *lenght=0x10; *out=0xffa8; break; //1111111110100111
233
case 0x65 :  *lenght=0x10; *out=0xffa9; break; //1111111110101000
234
case 0x66 :  *lenght=0x10; *out=0xffaa; break; //1111111110101001
235
case 0x67 :  *lenght=0x10; *out=0xffab; break; //1111111110101010
236
case 0x68 :  *lenght=0x10; *out=0xFFAc; break; //1111111110101011
237
case 0x69 :  *lenght=0x10; *out=0xFFAf; break; //1111111110101100
238
case 0x6A :  *lenght=0x10; *out=0xFFAe; break; //1111111110101101
239
case 0x71 :  *lenght=0x07; *out=0x007a; break; //11111010
240
case 0x72 :  *lenght=0x0b; *out=0x07f8; break; //111111110111
241
case 0x73 :  *lenght=0x10; *out=0xffaf; break; //1111111110101110
242
case 0x74 :  *lenght=0x10; *out=0xffb0; break; //1111111110101111
243
case 0x75 :  *lenght=0x10; *out=0xFFB1; break; //1111111110110000
244
case 0x76 :  *lenght=0x10; *out=0xFFB2; break; //111111110110001
245
case 0x77 :  *lenght=0x10; *out=0xFFB3; break; //111111110110010
246
case 0x78 :  *lenght=0x10; *out=0xFFB4; break; //111111110110011
247
case 0x79 :  *lenght=0x10; *out=0xFFB5; break; //1111111110110100
248
case 0x7A :  *lenght=0x10; *out=0xFFB6; break; //1111111110110101
249
case 0x81 :  *lenght=0x08; *out=0x00f9; break; //111111000
250
case 0x82 :  *lenght=0x10; *out=0xffb7; break; //111111111000000
251
case 0x83 :  *lenght=0x10; *out=0xFFB8; break; //1111111110110110
252
case 0x84 :  *lenght=0x10; *out=0xFFB9; break; //1111111110110111
253
case 0x85 :  *lenght=0x10; *out=0xFFBa; break; //1111111110111000
254
case 0x86 :  *lenght=0x10; *out=0xFFBb; break; //1111111110111001
255
case 0x87 :  *lenght=0x10; *out=0xFFBc; break; //1111111110111010
256
case 0x88 :  *lenght=0x10; *out=0xFFBd; break; //1111111110111011
257
case 0x89 :  *lenght=0x10; *out=0xFFBe; break; //1111111110111100
258
case 0x8A :  *lenght=0x10; *out=0xFFBf; break; //1111111110111101
259
case 0x91 :  *lenght=0x09; *out=0x01f7; break; //111111001
260
case 0x92 :  *lenght=0x10; *out=0xffc0; break; //1111111110111110
261
case 0x93 :  *lenght=0x10; *out=0xffc1; break; //1111111110111111
262
case 0x94 :  *lenght=0x10; *out=0xFFC2; break; //1111111111000000
263
case 0x95 :  *lenght=0x10; *out=0xFFC3; break; //1111111111000001
264
case 0x96 :  *lenght=0x10; *out=0xFFC4; break; //1111111111000010
265
case 0x97 :  *lenght=0x10; *out=0xFFC5; break; //1111111111000011
266
case 0x98 :  *lenght=0x10; *out=0xFFC6; break; //1111111111000100
267
case 0x99 :  *lenght=0x10; *out=0xFFC7; break; //1111111111000101
268
case 0x9A :  *lenght=0x10; *out=0xFFC8; break; //1111111111000110
269
case 0xA1 :  *lenght=0x09; *out=0x01f8; break; //111111010
270
case 0xA2 :  *lenght=0x10; *out=0xffc9; break; //1111111111000111
271
case 0xA3 :  *lenght=0x10; *out=0xFFCa; break; //1111111111001000
272
case 0xA4 :  *lenght=0x10; *out=0xFFCb; break; //1111111111001001
273
case 0xA5 :  *lenght=0x10; *out=0xFFCc; break; //1111111111001010
274
case 0xA6 :  *lenght=0x10; *out=0xFFCd; break; //1111111111001011
275
case 0xA7 :  *lenght=0x10; *out=0xFFCe; break; //1111111111001100
276
case 0xA8 :  *lenght=0x10; *out=0xFFCf; break; //1111111111001101
277
case 0xA9 :  *lenght=0x10; *out=0xFFd0; break; //1111111111001110
278
case 0xAA :  *lenght=0x10; *out=0xFFd1; break; //1111111111001111
279
case 0xB1 :  *lenght=0x09; *out=0x01f9; break; //1111111001
280
case 0xB2 :  *lenght=0x10; *out=0xFFD2; break; //1111111111010000
281
case 0xB3 :  *lenght=0x10; *out=0xFFD3; break; //1111111111010001
282
case 0xB4 :  *lenght=0x10; *out=0xFFD4; break; //1111111111010010
283
case 0xB5 :  *lenght=0x10; *out=0xFFD5; break; //1111111111010011
284
case 0xB6 :  *lenght=0x10; *out=0xFFD6; break; //1111111111010100
285
case 0xB7 :  *lenght=0x10; *out=0xFFD7; break; //1111111111010101
286
case 0xB8 :  *lenght=0x10; *out=0xFFD8; break; //1111111111010110
287
case 0xB9 :  *lenght=0x10; *out=0xFFD9; break; //1111111111010111
288
case 0xBA :  *lenght=0x10; *out=0xFFDa; break; //1111111111011000
289
case 0xC1 :  *lenght=0x09; *out=0x01fa; break; //1111111010
290
case 0xC2 :  *lenght=0x10; *out=0xFFDb; break; //1111111111011001
291
case 0xC3 :  *lenght=0x10; *out=0xFFDc; break; //1111111111011010
292
case 0xC4 :  *lenght=0x10; *out=0xFFDd; break; //1111111111011011
293
case 0xC5 :  *lenght=0x10; *out=0xFFDe; break; //1111111111011100
294
case 0xC6 :  *lenght=0x10; *out=0xFFDf; break; //1111111111011101
295
case 0xC7 :  *lenght=0x10; *out=0xFFe0; break; //1111111111011110
296
case 0xC8 :  *lenght=0x10; *out=0xFFe1; break; //1111111111011111
297
case 0xC9 :  *lenght=0x10; *out=0xFFe2; break; //1111111111100000
298
case 0xCA :  *lenght=0x10; *out=0xFFe3; break; //1111111111100001
299
case 0xD1 :  *lenght=0x0b; *out=0x07f9; break; //11111111000
300
case 0xD2 :  *lenght=0x10; *out=0xFFE4; break; //1111111111100010
301
case 0xD3 :  *lenght=0x10; *out=0xFFE5; break; //1111111111100011
302
case 0xD4 :  *lenght=0x10; *out=0xFFE6; break; //1111111111100100
303
case 0xD5 :  *lenght=0x10; *out=0xFFE7; break; //1111111111100101
304
case 0xD6 :  *lenght=0x10; *out=0xFFE8; break; //1111111111100110
305
case 0xD7 :  *lenght=0x10; *out=0xFFE9; break; //1111111111100111
306
case 0xD8 :  *lenght=0x10; *out=0xFFEa; break; //1111111111101000
307
case 0xD9 :  *lenght=0x10; *out=0xFFEb; break; //1111111111101001
308
case 0xDA :  *lenght=0x10; *out=0xFFEc; break; //1111111111101010
309
case 0xE1 :  *lenght=0x0e; *out=0x3fe0; break; //1111111111101011
310
case 0xE2 :  *lenght=0x10; *out=0xffed; break; //1111111111101100
311
case 0xE3 :  *lenght=0x10; *out=0xFFEe; break; //1111111111101101
312
case 0xE4 :  *lenght=0x10; *out=0xFFEf; break; //1111111111101110
313
case 0xE5 :  *lenght=0x10; *out=0xFFf0; break; //1111111111101111
314
case 0xE6 :  *lenght=0x10; *out=0xFFF1; break; //1111111111110000
315
case 0xE7 :  *lenght=0x10; *out=0xFFF2; break; //1111111111110001
316
case 0xE8 :  *lenght=0x10; *out=0xFFF3; break; //1111111111110010
317
case 0xE9 :  *lenght=0x10; *out=0xFFF4; break; //1111111111110011
318
case 0xEA :  *lenght=0x10; *out=0xFFF5; break; //1111111111110100
319
case 0xF0 :  *lenght=0x0a; *out=0x03fa; break; //11111111001
320
case 0xF1 :  *lenght=0x0f; *out=0x7fc3; break; //1111111111110101
321
case 0xF2 :  *lenght=0x10; *out=0xFFF6; break; //1111111111110110
322
case 0xF3 :  *lenght=0x10; *out=0xFFF7; break; //1111111111110111
323
case 0xF4 :  *lenght=0x10; *out=0xFFF8; break; //1111111111111000
324
case 0xF5 :  *lenght=0x10; *out=0xFFF9; break; //1111111111111001
325
case 0xF6 :  *lenght=0x10; *out=0xFFFA; break; //1111111111111010
326
case 0xF7 :  *lenght=0x10; *out=0xFFFB; break; //1111111111111011
327
case 0xF8 :  *lenght=0x10; *out=0xFFFC; break; //1111111111111100
328
case 0xF9 :  *lenght=0x10; *out=0xFFFD; break; //1111111111111101
329
case 0xFA :  *lenght=0x10; *out=0xFFFE; break; //1111111111111110
330
#ifndef __MICROBLAZE
331
default : printf("WAARDE STAAT NIET IN TABEL!!!!!!!!!!!!!!!!!!!!\n");break;
332
#endif
333
        }
334
  //      printf("magnitude= %x out= %x lenght= %d \n",magnitude,*out,*lenght);
335
        return;
336
#endif
337
 
338
 
339
}
340
 
341
static unsigned char convertDCMagnitudeYLengthTable[16] = {
342
0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x04, 0x05,
343
0x06, 0x07, 0x08, 0x09, 0x00, 0x00, 0x00, 0x00
344
};
345
 
346
static unsigned short convertDCMagnitudeYOutTable[16] = {
347
0x0000, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x000e, 0x001e,
348
0x003e, 0x007e, 0x00fe, 0x01fe, 0x0000, 0x0000, 0x0000, 0x0000
349
};
350
 
351
//===========================================================================
352
void ConvertDCMagnitudeY(unsigned char magnitude,unsigned short int *out, unsigned short int *lenght)
353
{
354
        unsigned char len;
355
 
356
        if ((magnitude>16) || ((len=convertDCMagnitudeYLengthTable[magnitude])==0)) {
357
#ifndef __MICROBLAZE
358
                printf("WAARDE STAAT NIET IN TABEL!!!!!!!!!!!!!!!!!!!!\n");
359
#endif
360
                }
361
        *lenght = len;
362
        *out = convertDCMagnitudeYOutTable[magnitude];
363
#if 0
364
        switch (magnitude) {
365
                case 0x00 : *out=0x0000; *lenght=2; break;
366
                case 0x01 : *out=0x0002; *lenght=3; break;
367
                case 0x02 : *out=0x0003; *lenght=3; break;
368
                case 0x03 : *out=0x0004; *lenght=3; break;
369
                case 0x04 : *out=0x0005; *lenght=3; break;
370
                case 0x05 : *out=0x0006; *lenght=3; break;
371
                case 0x06 : *out=0x000e; *lenght=4; break;
372
                case 0x07 : *out=0x001e; *lenght=5; break;
373
                case 0x08 : *out=0x003e; *lenght=6; break;
374
                case 0x09 : *out=0x007e; *lenght=7; break;
375
                case 0x0a : *out=0x00fe; *lenght=8; break;
376
                case 0x0b : *out=0x01fe; *lenght=9; break;
377
        }
378
#endif          
379
}
380
 
381
static unsigned char convertACMagnitudeYLength[256] = {
382
0x04, 0x02, 0x02, 0x03, 0x04, 0x05, 0x07, 0x08, 0x0a, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // 00 - 0f
383
0x00, 0x04, 0x05, 0x07, 0x09, 0x0b, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // 10 - 1f
384
0x00, 0x05, 0x08, 0x0a, 0x0c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // 20 - 2f
385
0x00, 0x06, 0x09, 0x0c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // 30 - 3f
386
0x00, 0x06, 0x0a, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // 40 - 4f
387
0x00, 0x07, 0x0b, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // 50 - 5f
388
0x00, 0x07, 0x0c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // 60 - 6f
389
0x00, 0x08, 0x0c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // 70 - 7f
390
0x00, 0x09, 0x0f, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // 80 - 8f
391
0x00, 0x09, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // 90 - 9f
392
0x00, 0x09, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // a0 - af
393
0x00, 0x0a, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // b0 - bf
394
0x00, 0x0a, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // c0 - cf
395
0x00, 0x0b, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // d0 - df
396
0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,    // e0 - ef
397
0x0b, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00
398
};
399
 
400
static unsigned short convertACMagnitudeYOut[256] = {
401
0xFFFA, 0xFFF0, 0xFFF1, 0xFFF4, 0xFFFB, 0xFFFA, 0xFFF8, 0xFFF8, 0xFFF6, 0xFF82, 0xFF83, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // 00 - 0f
402
0x0000, 0xFFFC, 0xFFFB, 0xFFF9, 0xFFF6, 0xFFF6, 0xFF84, 0xFF85, 0xFF86, 0xFF87, 0xFF88, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // 10 - 1f
403
0x0000, 0xFFFC, 0xFFF9, 0xFFF7, 0xFFF4, 0xFF89, 0xFF8A, 0xFF8B, 0xFF8C, 0xFF8D, 0xFF8E, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // 20 - 2f
404
0x0000, 0xFFFA, 0xFFF7, 0xFFF5, 0xFF8F, 0xFF90, 0xFF91, 0xFF92, 0xFF93, 0xFF94, 0xFF95, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // 30 - 3f
405
0x0000, 0xFFFB, 0xFFF8, 0xFF96, 0xFF97, 0xFF98, 0xFF99, 0xFF9A, 0xFF9B, 0xFF9C, 0xFF9D, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // 40 - 4f
406
0x0000, 0xFFFA, 0xFFF7, 0xFF9E, 0xFF9F, 0xFFA0, 0xFFA1, 0xFFA2, 0xFFA3, 0xFFA4, 0xFFA5, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // 50 - 5f
407
0x0000, 0xFFFB, 0xFFF6, 0xFFA6, 0xFFA7, 0xFFA8, 0xFFA9, 0xFFAA, 0xFFAB, 0xFFAC, 0xFFAD, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // 60 - 6f
408
0x0000, 0xFFFA, 0xFFF7, 0xFFAE, 0xFFAF, 0xFFB0, 0xFFB1, 0xFFB2, 0xFFB3, 0xFFB4, 0xFFB5, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // 70 - 7f
409
0x0000, 0xFFF8, 0xFFC0, 0xFFB6, 0xFFB7, 0xFFB8, 0xFFB9, 0xFFBA, 0xFFBB, 0xFFBC, 0xFFBD, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // 80 - 8f
410
0x0000, 0xFFF9, 0xFFBE, 0xFFBF, 0xFFC0, 0xFFC1, 0xFFC2, 0xFFC3, 0xFFC4, 0xFFC5, 0xFFC6, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // 90 - 9f
411
0x0000, 0xFFFA, 0xFFC7, 0xFFC8, 0xFFC9, 0xFFCA, 0xFFCB, 0xFFCC, 0xFFCD, 0xFFCE, 0xFFCF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // a0 - af
412
0x0000, 0xFFF9, 0xFFD0, 0xFFD1, 0xFFD2, 0xFFD3, 0xFFD4, 0xFFD5, 0xFFD6, 0xFFD7, 0xFFD8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // b0 - bf
413
0x0000, 0xFFFA, 0xFFD9, 0xFFDA, 0xFFDB, 0xFFDC, 0xFFDD, 0xFFDE, 0xFFDF, 0xFFE0, 0xFFE1, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // c0 - cf
414
0x0000, 0xFFF8, 0xFFE2, 0xFFE3, 0xFFE4, 0xFFE5, 0xFFE6, 0xFFE7, 0xFFE8, 0xFFE9, 0xFFEA, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // d0 - df
415
0x0000, 0xFFEB, 0xFFEC, 0xFFED, 0xFFEE, 0xFFEF, 0xFFF0, 0xFFF1, 0xFFF2, 0xFFF3, 0xFFF4, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,    // e0 - ef
416
0xFFF9, 0xFFF5, 0xFFF6, 0xFFF7, 0xFFF8, 0xFFF9, 0xFFFA, 0xFFFB, 0xFFFC, 0xFFFD, 0xFFFE, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
417
};
418
 
419
//===========================================================================
420
void ConvertACMagnitudeY(unsigned char magnitude,unsigned short int *out, unsigned short int *lenght)
421
{
422
        unsigned char len;
423
 
424
        len = convertACMagnitudeYLength[magnitude];
425
        if (!len) {
426
#ifndef __MICROBLAZE
427
        printf("WAARDE STAAT NIET IN TABEL!!!!!!!!!!!!!!!!!!!!\n");
428
#endif
429
                }
430
        *lenght = len;
431
        *out = convertACMagnitudeYOut[magnitude];
432
 
433
#if 0
434
        switch (magnitude) {
435
case 0x00 :  *lenght=4;  *out=0xFFFA; break; //1010
436
case 0x01 :  *lenght=2;  *out=0xFFF0; break; //00
437
case 0x02 :  *lenght=2;  *out=0xFFF1; break; //01
438
case 0x03 :  *lenght=3;  *out=0xFFF4; break; //100
439
case 0x04 :  *lenght=4;  *out=0xFFFB; break; //1011
440
case 0x05 :  *lenght=5;  *out=0xFFFA; break; //11010
441
case 0x06 :  *lenght=7;  *out=0xFFF8; break; //1111000
442
case 0x07 :  *lenght=8;  *out=0xFFF8; break; //11111000
443
case 0x08 :  *lenght=10; *out=0xFFF6; break; //1111110110
444
case 0x09 :  *lenght=16; *out=0xFF82; break; //1111111110000010
445
case 0x0A :  *lenght=16; *out=0xFF83; break; //1111111110000011
446
case 0x11 :  *lenght=4;  *out=0xFFFC; break; //1100
447
case 0x12 :  *lenght=5;  *out=0xFFFB; break; //11011
448
case 0x13 :  *lenght=7;  *out=0xFFF9; break; //1111001
449
case 0x14 :  *lenght=9;  *out=0xFFF6; break; //111110110
450
case 0x15 :  *lenght=11; *out=0xFFF6; break; //11111110110
451
case 0x16 :  *lenght=16; *out=0xFF84; break; //1111111110000100
452
case 0x17 :  *lenght=16; *out=0xFF85; break; //1111111110000101
453
case 0x18 :  *lenght=16; *out=0xFF86; break; //1111111110000110
454
case 0x19 :  *lenght=16; *out=0xFF87; break; //1111111110000111
455
case 0x1A :  *lenght=16; *out=0xFF88; break; //1111111110001000
456
case 0x21 :  *lenght=5;  *out=0xFFFC; break; //11100
457
case 0x22 :  *lenght=8;  *out=0xFFF9; break; //11111001
458
case 0x23 :  *lenght=10; *out=0xFFF7; break; //1111110111
459
case 0x24 :  *lenght=12; *out=0xFFF4; break; //111111110100
460
case 0x25 :  *lenght=16; *out=0xFF89; break; //1111111110001001
461
case 0x26 :  *lenght=16; *out=0xFF8A; break; //1111111110001010
462
case 0x27 :  *lenght=16; *out=0xFF8B; break; //1111111110001011
463
case 0x28 :  *lenght=16; *out=0xFF8C; break; //1111111110001100
464
case 0x29 :  *lenght=16; *out=0xFF8D; break; //1111111110001101
465
case 0x2A :  *lenght=16; *out=0xFF8E; break; //1111111110001110
466
case 0x31 :  *lenght=6;  *out=0xFFFA; break; //111010
467
case 0x32 :  *lenght=9;  *out=0xFFF7; break; //111110111
468
case 0x33 :  *lenght=12; *out=0xFFF5; break; //111111110101
469
case 0x34 :  *lenght=16; *out=0xFF8F; break; //1111111110001111
470
case 0x35 :  *lenght=16; *out=0xFF90; break; //1111111110010000
471
case 0x36 :  *lenght=16; *out=0xFF91; break; //1111111110010001
472
case 0x37 :  *lenght=16; *out=0xFF92; break; //1111111110010010
473
case 0x38 :  *lenght=16; *out=0xFF93; break; //1111111110010011
474
case 0x39 :  *lenght=16; *out=0xFF94; break; //1111111110010100
475
case 0x3A :  *lenght=16; *out=0xFF95; break; //1111111110010101
476
case 0x41 :  *lenght=6;  *out=0xFFFB; break; //111011
477
case 0x42 :  *lenght=10; *out=0xFFF8; break; //1111111000
478
case 0x43 :  *lenght=16; *out=0xFF96; break; //1111111110010110
479
case 0x44 :  *lenght=16; *out=0xFF97; break; //1111111110010111
480
case 0x45 :  *lenght=16; *out=0xFF98; break; //1111111110011000
481
case 0x46 :  *lenght=16; *out=0xFF99; break; //1111111110011001
482
case 0x47 :  *lenght=16; *out=0xFF9A; break; //1111111110011010
483
case 0x48 :  *lenght=16; *out=0xFF9B; break; //1111111110011011
484
case 0x49 :  *lenght=16; *out=0xFF9C; break; //1111111110011100
485
case 0x4A :  *lenght=16; *out=0xFF9D; break; //1111111110011101
486
case 0x51 :  *lenght=7;  *out=0xFFFA; break; //1111010
487
case 0x52 :  *lenght=11; *out=0xFFF7; break; //11111110111
488
case 0x53 :  *lenght=16; *out=0xFF9E; break; //1111111110011110
489
case 0x54 :  *lenght=16; *out=0xFF9F; break; //1111111110011111
490
case 0x55 :  *lenght=16; *out=0xFFA0; break; //1111111110100000
491
case 0x56 :  *lenght=16; *out=0xFFA1; break; //1111111110100001
492
case 0x57 :  *lenght=16; *out=0xFFA2; break; //1111111110100010
493
case 0x58 :  *lenght=16; *out=0xFFA3; break; //1111111110100011
494
case 0x59 :  *lenght=16; *out=0xFFA4; break; //1111111110100100
495
case 0x5A :  *lenght=16; *out=0xFFA5; break; //1111111110100101
496
case 0x61 :  *lenght=7;  *out=0xFFFB; break; //1111011
497
case 0x62 :  *lenght=12; *out=0xFFF6; break; //111111110110
498
case 0x63 :  *lenght=16; *out=0xFFA6; break; //1111111110100110
499
case 0x64 :  *lenght=16; *out=0xFFA7; break; //1111111110100111
500
case 0x65 :  *lenght=16; *out=0xFFA8; break; //1111111110101000
501
case 0x66 :  *lenght=16; *out=0xFFA9; break; //1111111110101001
502
case 0x67 :  *lenght=16; *out=0xFFAA; break; //1111111110101010
503
case 0x68 :  *lenght=16; *out=0xFFAB; break; //1111111110101011
504
case 0x69 :  *lenght=16; *out=0xFFAC; break; //1111111110101100
505
case 0x6A :  *lenght=16; *out=0xFFAD; break; //1111111110101101
506
case 0x71 :  *lenght=8;  *out=0xFFFA; break; //11111010
507
case 0x72 :  *lenght=12; *out=0xFFF7; break; //111111110111
508
case 0x73 :  *lenght=16; *out=0xFFAE; break; //1111111110101110
509
case 0x74 :  *lenght=16; *out=0xFFAF; break; //1111111110101111
510
case 0x75 :  *lenght=16; *out=0xFFB0; break; //1111111110110000
511
case 0x76 :  *lenght=16; *out=0xFFB1; break; //111111110110001
512
case 0x77 :  *lenght=16; *out=0xFFB2; break; //111111110110010
513
case 0x78 :  *lenght=16; *out=0xFFB3; break; //111111110110011
514
case 0x79 :  *lenght=16; *out=0xFFB4; break; //1111111110110100
515
case 0x7A :  *lenght=16; *out=0xFFB5; break; //1111111110110101
516
case 0x81 :  *lenght=9;  *out=0xFFF8; break; //111111000
517
case 0x82 :  *lenght=15; *out=0xFFC0; break; //111111111000000
518
case 0x83 :  *lenght=16; *out=0xFFB6; break; //1111111110110110
519
case 0x84 :  *lenght=16; *out=0xFFB7; break; //1111111110110111
520
case 0x85 :  *lenght=16; *out=0xFFB8; break; //1111111110111000
521
case 0x86 :  *lenght=16; *out=0xFFB9; break; //1111111110111001
522
case 0x87 :  *lenght=16; *out=0xFFBA; break; //1111111110111010
523
case 0x88 :  *lenght=16; *out=0xFFBB; break; //1111111110111011
524
case 0x89 :  *lenght=16; *out=0xFFBC; break; //1111111110111100
525
case 0x8A :  *lenght=16; *out=0xFFBD; break; //1111111110111101
526
case 0x91 :  *lenght=9;  *out=0xFFF9; break; //111111001
527
case 0x92 :  *lenght=16; *out=0xFFBE; break; //1111111110111110
528
case 0x93 :  *lenght=16; *out=0xFFBF; break; //1111111110111111
529
case 0x94 :  *lenght=16; *out=0xFFC0; break; //1111111111000000
530
case 0x95 :  *lenght=16; *out=0xFFC1; break; //1111111111000001
531
case 0x96 :  *lenght=16; *out=0xFFC2; break; //1111111111000010
532
case 0x97 :  *lenght=16; *out=0xFFC3; break; //1111111111000011
533
case 0x98 :  *lenght=16; *out=0xFFC4; break; //1111111111000100
534
case 0x99 :  *lenght=16; *out=0xFFC5; break; //1111111111000101
535
case 0x9A :  *lenght=16; *out=0xFFC6; break; //1111111111000110
536
case 0xA1 :  *lenght=9;  *out=0xFFFA; break; //111111010
537
case 0xA2 :  *lenght=16; *out=0xFFC7; break; //1111111111000111
538
case 0xA3 :  *lenght=16; *out=0xFFC8; break; //1111111111001000
539
case 0xA4 :  *lenght=16; *out=0xFFC9; break; //1111111111001001
540
case 0xA5 :  *lenght=16; *out=0xFFCA; break; //1111111111001010
541
case 0xA6 :  *lenght=16; *out=0xFFCB; break; //1111111111001011
542
case 0xA7 :  *lenght=16; *out=0xFFCC; break; //1111111111001100
543
case 0xA8 :  *lenght=16; *out=0xFFCD; break; //1111111111001101
544
case 0xA9 :  *lenght=16; *out=0xFFCE; break; //1111111111001110
545
case 0xAA :  *lenght=16; *out=0xFFCF; break; //1111111111001111
546
case 0xB1 :  *lenght=10; *out=0xFFF9; break; //1111111001
547
case 0xB2 :  *lenght=16; *out=0xFFD0; break; //1111111111010000
548
case 0xB3 :  *lenght=16; *out=0xFFD1; break; //1111111111010001
549
case 0xB4 :  *lenght=16; *out=0xFFD2; break; //1111111111010010
550
case 0xB5 :  *lenght=16; *out=0xFFD3; break; //1111111111010011
551
case 0xB6 :  *lenght=16; *out=0xFFD4; break; //1111111111010100
552
case 0xB7 :  *lenght=16; *out=0xFFD5; break; //1111111111010101
553
case 0xB8 :  *lenght=16; *out=0xFFD6; break; //1111111111010110
554
case 0xB9 :  *lenght=16; *out=0xFFD7; break; //1111111111010111
555
case 0xBA :  *lenght=16; *out=0xFFD8; break; //1111111111011000
556
case 0xC1 :  *lenght=10; *out=0xFFFA; break; //1111111010
557
case 0xC2 :  *lenght=16; *out=0xFFD9; break; //1111111111011001
558
case 0xC3 :  *lenght=16; *out=0xFFDA; break; //1111111111011010
559
case 0xC4 :  *lenght=16; *out=0xFFDB; break; //1111111111011011
560
case 0xC5 :  *lenght=16; *out=0xFFDC; break; //1111111111011100
561
case 0xC6 :  *lenght=16; *out=0xFFDD; break; //1111111111011101
562
case 0xC7 :  *lenght=16; *out=0xFFDE; break; //1111111111011110
563
case 0xC8 :  *lenght=16; *out=0xFFDF; break; //1111111111011111
564
case 0xC9 :  *lenght=16; *out=0xFFE0; break; //1111111111100000
565
case 0xCA :  *lenght=16; *out=0xFFE1; break; //1111111111100001
566
case 0xD1 :  *lenght=11; *out=0xFFF8; break; //11111111000
567
case 0xD2 :  *lenght=16; *out=0xFFE2; break; //1111111111100010
568
case 0xD3 :  *lenght=16; *out=0xFFE3; break; //1111111111100011
569
case 0xD4 :  *lenght=16; *out=0xFFE4; break; //1111111111100100
570
case 0xD5 :  *lenght=16; *out=0xFFE5; break; //1111111111100101
571
case 0xD6 :  *lenght=16; *out=0xFFE6; break; //1111111111100110
572
case 0xD7 :  *lenght=16; *out=0xFFE7; break; //1111111111100111
573
case 0xD8 :  *lenght=16; *out=0xFFE8; break; //1111111111101000
574
case 0xD9 :  *lenght=16; *out=0xFFE9; break; //1111111111101001
575
case 0xDA :  *lenght=16; *out=0xFFEA; break; //1111111111101010
576
case 0xE1 :  *lenght=16; *out=0xFFEB; break; //1111111111101011
577
case 0xE2 :  *lenght=16; *out=0xFFEC; break; //1111111111101100
578
case 0xE3 :  *lenght=16; *out=0xFFED; break; //1111111111101101
579
case 0xE4 :  *lenght=16; *out=0xFFEE; break; //1111111111101110
580
case 0xE5 :  *lenght=16; *out=0xFFEF; break; //1111111111101111
581
case 0xE6 :  *lenght=16; *out=0xFFF0; break; //1111111111110000
582
case 0xE7 :  *lenght=16; *out=0xFFF1; break; //1111111111110001
583
case 0xE8 :  *lenght=16; *out=0xFFF2; break; //1111111111110010
584
case 0xE9 :  *lenght=16; *out=0xFFF3; break; //1111111111110011
585
case 0xEA :  *lenght=16; *out=0xFFF4; break; //1111111111110100
586
case 0xF0 :  *lenght=11; *out=0xFFF9; break; //11111111001
587
case 0xF1 :  *lenght=16; *out=0xFFF5; break; //1111111111110101
588
case 0xF2 :  *lenght=16; *out=0xFFF6; break; //1111111111110110
589
case 0xF3 :  *lenght=16; *out=0xFFF7; break; //1111111111110111
590
case 0xF4 :  *lenght=16; *out=0xFFF8; break; //1111111111111000
591
case 0xF5 :  *lenght=16; *out=0xFFF9; break; //1111111111111001
592
case 0xF6 :  *lenght=16; *out=0xFFFA; break; //1111111111111010
593
case 0xF7 :  *lenght=16; *out=0xFFFB; break; //1111111111111011
594
case 0xF8 :  *lenght=16; *out=0xFFFC; break; //1111111111111100
595
case 0xF9 :  *lenght=16; *out=0xFFFD; break; //1111111111111101
596
case 0xFA :  *lenght=16; *out=0xFFFE; break; //1111111111111110
597
#ifndef __MICROBLAZE
598
default : printf("WAARDE STAAT NIET IN TABEL!!!!!!!!!!!!!!!!!!!!\n");break;
599
#endif
600
        }
601
  //      printf("magnitude= %x out= %x lenght= %d \n",magnitude,*out,*lenght);
602
        return;
603
 #endif
604
 
605
}
606
//===========================================================================
607
char Extend (char additional, unsigned char magnitude)
608
{
609
        int vt= 1 << (magnitude-1);
610
        if ( additional < vt ) return (additional + (-1 << magnitude) + 1);
611
        else return additional;
612
}
613
//===========================================================================
614
void ReverseExtend (char value, unsigned char *magnitude, unsigned char *bits)
615
{
616
 //     printf("reverseextend value= %d\n",*magnitude);
617
        if (value >=0)
618
        {
619
                *bits=value;
620
        }
621
        else
622
        {
623
                value=-value;
624
                *bits=~value;
625
        }
626
        *magnitude=0;
627
        while (value !=0)
628
        {
629
                value>>=1;
630
                ++*magnitude;
631
        }
632
 //     printf("reverseextend magnitude= %d bits= %d",magnitude,bits);
633
        return;
634
}
635
//===========================================================================
636
void WriteRawBits16(unsigned char amount_bits, unsigned int bits)     //*remaining needs bo be more than 8 bits because 8 bits could be added and ther ecould already be up ot 7 bits in *remaining
637
// this function collects bits to send
638
// if there less than 16 bits collected, nothing is send and these bits are stored in *remaining. In *amount_remaining there is stated how much bits are stored in *remaining
639
// if more than 16 bits are collected, 16 bits are send and the remaining bits are stored again
640
{
641
        unsigned short int send;
642
        unsigned int mask;
643
        unsigned char send2;
644
        int count;
645
        mask=0x00;                                                              //init mask
646
        vlc_remaining=(vlc_remaining<<amount_bits);                                   //shift to make place for the new bits
647
        for (count=amount_bits; count>0; count--) mask=(mask<<1)|0x01;          //create mask for adding bit
648
        vlc_remaining=vlc_remaining | (bits&mask);                                    //add bits
649
        vlc_amount_remaining=vlc_amount_remaining + amount_bits;                      //change *amount_remaining to the correct new value
650
        if (vlc_amount_remaining >= 16)                                            //are there more than 16 bits in buffer, send 16 bits
651
        {
652
#ifndef __MICROBLAZE        
653
if (vlc_amount_remaining >= 32 ) printf("ERROR, more bits to send %d",vlc_amount_remaining);
654
#endif
655
                send=vlc_remaining>>(vlc_amount_remaining-16);                        //this value can be send/stored (in art this can be dony by selecting bits)
656
                send2=(send & 0xFF00) >>8;
657
                  vlc_output_byte(send2);
658
//                fwrite(&send2,1,1,file);
659
                if (send2==0xFF)
660
                {
661
                        send2=0x00;
662
                  vlc_output_byte(send2);
663
//                        fwrite(&send2,1,1,file);
664
                }
665
                send2=send & 0xFF;
666
                  vlc_output_byte(send2);
667
//                fwrite(&send2,1,1,file);
668
                if (send2==0xFF)
669
                {
670
                        send2=0x00;
671
                           vlc_output_byte(send2);
672
//                        fwrite(&send2,1,1,file);
673
                }
674
                vlc_amount_remaining=vlc_amount_remaining-16;                         //descrease by 16 because these are send
675
        }
676
        return;
677
}
678
//===========================================================================
679
void HuffmanEncodeFinishSend()
680
// There are still some bits left to send at the end of the 8x8 matrix (or maybe the file),
681
// the remaining bits are filled up with ones and send
682
// possible fault: -must it be filled up with ones?
683
{
684
        unsigned short int send;
685
        unsigned int mask;
686
        int  count;
687
        mask=0x00;                                                              //init mask
688
        if (vlc_amount_remaining >= 8)                                             //2 bytes to send, send first byte
689
        {
690
                send=vlc_remaining>>(vlc_amount_remaining-8);                         //shift so that first byte is ready to send
691
                  vlc_output_byte(send&0xff);
692
//                fwrite(&send,1,1,file);
693
                if (send==0xFF)                                                 //is this still needed????
694
                {
695
                        send=0x00;
696
                           vlc_output_byte(send&0xff);
697
//                        fwrite(&send,1,1,file);
698
                }
699
                vlc_amount_remaining=vlc_amount_remaining -8;                         // lower the value to the amount of bits that still needs to be send
700
        }
701
        if (vlc_amount_remaining >= 0)                                             //there is a last byte to send
702
        {
703
                send=vlc_remaining<<(8-vlc_amount_remaining);                         //shift the last bits to send to the front of the byte
704
                mask=0x00;                                                      //init mask
705
                for (count=(8-vlc_amount_remaining); count>0; count--) mask=(mask<<1)|0x01; //create mask to fill byte up with ones
706
                send=send | mask;                                               //add the ones to the byte
707
                vlc_output_byte(send&0xff);
708
//                fwrite(&send,1,1,file);
709
                vlc_amount_remaining=0x00;                                         //is this needed?
710
        }
711
        return;
712
}
713
//===========================================================================
714
void HuffmanEncodeUsingDCTable(unsigned char magnitude)
715
// Translate magnitude into needed data (from table) and send it
716
{
717
        unsigned char send;
718
        unsigned short int huffmancode, huffmanlengt;
719
        ConvertDCMagnitudeY(magnitude, &huffmancode, &huffmanlengt);
720
        WriteRawBits16(huffmanlengt,huffmancode);
721
        //printf("Write DC magnitude= %2x \n",magnitude);
722
        //WriteRawBits16(0x08,magnitude,remaining,amount_remaining, file);
723
        return;
724
}
725
//===========================================================================
726
void HuffmanEncodeUsingACTable(unsigned char mag)
727
// Translate magnitude into needed data (from table) and send it
728
{
729
        unsigned char send;
730
        unsigned short int huffmancode, huffmanlengt;
731
        ConvertACMagnitudeY(mag, &huffmancode, &huffmanlengt);
732
        WriteRawBits16(huffmanlengt,huffmancode);
733
        return;
734
}
735
//===========================================================================
736
char EncodeDataUnit(char dataunit[64], unsigned int color)
737
{
738
        char difference;
739
        unsigned char magnitude,zerorun,ii,ert;
740
        unsigned int bits;
741
        unsigned char bit_char;
742
         char last_dc_value;
743
                                         //init
744
  //    PrintMatrix(dataunit) ;
745
        last_dc_value = dcvalue[color];
746
        difference = dataunit[0] - last_dc_value;
747
        last_dc_value=dataunit[0];
748
        ReverseExtend(difference, &magnitude,&bit_char);
749
        bits = bit_char;
750
        HuffmanEncodeUsingDCTable(magnitude);
751
        WriteRawBits16(magnitude,bits);
752
        zerorun=0;
753
        ii=1;
754
        while ( ii < 64 )
755
        {
756
                if (dataunit[ii] != 0 )
757
                {
758
                        while ( zerorun >= 16 )
759
                        {
760
                                HuffmanEncodeUsingACTable(0xF0);
761
                                zerorun=zerorun-16;
762
                            //    printf("16 zeros:  %d\n",zerorun);
763
                        }
764
                        ReverseExtend(dataunit[ii],&magnitude,&bit_char);
765
                        bits=bit_char;
766
                        ert= ((int)zerorun *16);                                     //ERROR !!!!!!!!!!!
767
                        ert=ert + magnitude;
768
                        HuffmanEncodeUsingACTable(ert);
769
                        WriteRawBits16(magnitude,bits);
770
                        zerorun=0;
771
                }
772
                else zerorun=zerorun+1;
773
                ii++;
774
        }
775
        if ( zerorun != 0 )
776
        {
777
                HuffmanEncodeUsingACTable(0x00);
778
//                printf("NUL DE REST IS NUL\n");
779
        }
780
 //       HuffmanEncodeFinishSend(remaining,amount_remaining,file);
781
        dcvalue[color] = last_dc_value;
782
        return 0;
783
}
784 18 quickwayne
 
785
 
786
#endif

powered by: WebSVN 2.1.0

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