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

Subversion Repositories mpdma

[/] [mpdma/] [trunk/] [mb-vlc/] [mb-huffman.c] - Blame information for rev 17

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

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

powered by: WebSVN 2.1.0

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