source: Sophya/trunk/Poubelle/archediab.old/archediab.sources/c/compress.c@ 637

Last change on this file since 637 was 637, checked in by ansari, 26 years ago

archediab version 24 initial import

File size: 14.5 KB
Line 
1#include <manip.h>
2#include "compress.h"
3
4
5/*******************************************************************************************/
6/**************** ****************/
7/**************** compress_3 ****************/
8/**************** ****************/
9/*******************************************************************************************/
10
11void com_3(long val,long* in,long*out,int n,int pasin);
12
13
14#define kmax_ 15 /* valeur maximum de l'exposant */
15#define kmak_ 0xf /* masque pour l'exposant */
16#define emak_ 0x7 /* masque pour l'ecart */
17#define sgbi_ 0x4 /* bit de signe de l'ecart */
18#define sign_ 0xfffffff8 /* masque de signe de l'ecart */
19
20/* compress un tableau in de n*9 points disposé avec un pas pasin */
21/* les data compressées sont ecrites dans le tableau out de n points */
22/* la valeur val est la valeur de reference du point origine */
23
24
25/* comprime 9*n points : 1er point dans 1er mot, tous les ecarts dans les n mots suivants */
26/* 9*n ==> n+1 pour 72 points : 9 mots */
27
28void compress_3_1(long* in,long*out,int n,int pasin)
29{
30long val;
31val=in[0]; out[0]=val;
32com_3(val,in,out+1,n/9,pasin);
33}
34
35
36
37void com_3(long val,long* in,long*out,int n,int pasin)
38{
39int filtre[16]={0xffffffff,0xfffffffe,0xfffffffc,0xfffffff8,
40 0xfffffff0,0xffffffe0,0xffffffc0,0xffffff80,
41 0xffffff00,0xfffffe00,0xfffffc00,0xfffff800,
42 0xfffff000,0xffffe000,0xffffc000,0xffff8000};
43int test[16]= {0x00000000,0x00000001,0x00000002,0x00000004,
44 0x00000008,0x00000010,0x00000020,0x00000040,
45 0x00000080,0x00000100,0x00000200,0x00000400,
46 0x00000800,0x00001000,0x00002000,0x00004000};
47
48long val1;
49long ec1,ec2,ec3,ec4,ec5,ec6,ec7,ec8,ec9;
50int i,k,k1;long q;
51
52
53for(i=0;i<n;i++)
54 {
55 k=0;q=3; /* 3 bit = 7 = +-3 */
56
57 ec1=in[i*9*pasin]-val;
58 shif(ec1,k,q);
59 val1=val + arrondi(ec1,k);
60
61 k1=k;
62 ec2=in[(i*9+1)*pasin]-val1;
63 shif(ec2,k,q);
64
65 if(k>k1) {k1=k;val1=val + arrondi(ec1,k);}
66 val1+= arrondi(ec2,k);
67
68 ec3=in[(i*9+2)*pasin]-val1;
69 shif(ec3,k,q);
70
71 if(k>k1) {k1=k;val1=val + arrondi(ec1,k) + arrondi(ec2,k);}
72 val1+= arrondi(ec3,k);
73
74 ec4=in[(i*9+3)*pasin]-val1;
75 shif(ec4,k,q);
76
77 if(k>k1) {k1=k;val1=val + arrondi(ec1,k) + arrondi(ec2,k) + arrondi(ec3,k);}
78 val1+= arrondi(ec4,k);
79
80 ec5=in[(i*9+4)*pasin]-val1;
81 shif(ec5,k,q);
82
83 if(k>k1) {k1=k;val1=val + arrondi(ec1,k) + arrondi(ec2,k) + arrondi(ec3,k) + arrondi(ec4,k);}
84 val1+= arrondi(ec5,k);
85
86 ec6=in[(i*9+5)*pasin]-val1;
87 shif(ec6,k,q);
88
89 if(k>k1) {k1=k;val1=val + arrondi(ec1,k) + arrondi(ec2,k) + arrondi(ec3,k)
90 + arrondi(ec4,k) + arrondi(ec5,k);}
91 val1+= arrondi(ec6,k);
92
93 ec7=in[(i*9+6)*pasin]-val1;
94 shif(ec7,k,q);
95
96 if(k>k1) {k1=k;val1=val + arrondi(ec1,k) + arrondi(ec2,k)
97 + arrondi(ec3,k) + arrondi(ec4,k) + arrondi(ec5,k) + arrondi(ec6,k);}
98 val1+= arrondi(ec7,k);
99
100 ec8=in[(i*9+7)*pasin]-val1;
101 shif(ec8,k,q);
102
103 if(k>k1) {k1=k;val1=val + arrondi(ec1,k) + arrondi(ec2,k) + arrondi(ec3,k)
104 + arrondi(ec4,k) + arrondi(ec5,k) + arrondi(ec6,k) + arrondi(ec7,k);}
105 val1+= arrondi(ec8,k);
106
107 ec9=in[(i*9+8)*pasin]-val1;
108 shif(ec9,k,q);
109
110/*printf("i=%d k=%d ec= %d %d %d \n",i,k,ec1,ec2,ec3,out[(i+8)/7]); */
111
112 ec1 = arrondi(ec1,k) >> k;
113 ec2 = arrondi(ec2,k) >> k;
114 ec3 = arrondi(ec3,k) >> k;
115 ec4 = arrondi(ec4,k) >> k;
116 ec5 = arrondi(ec5,k) >> k;
117 ec6 = arrondi(ec6,k) >> k;
118 ec7 = arrondi(ec7,k) >> k;
119 ec8 = arrondi(ec8,k) >> k;
120 ec9 = arrondi(ec9,k) >> k;
121
122 out[i]= ((ec1&emak_)<<29) | ((ec2&emak_)<<26) | ((ec3&emak_)<<23)
123 | ((ec4&emak_)<<20) | ((ec5&emak_)<<17) | ((ec6&emak_)<<14)
124 | ((ec7&emak_)<<11) | ((ec8&emak_)<<8) | ((ec9&emak_)<<5) | k ;
125
126
127/* if(i<30) printf("i=%d k=%d ec= %d %d %d \n",i,k,ec1,ec2,ec3,out[(i+8)/7]);*/
128
129 val+= ( (ec1 + ec2 + ec3 + ec4 + ec5 + ec6 + ec7 + ec8 + ec9 ) << k );
130 }
131}
132
133
134
135/*******************************************************************************************/
136/**************** *****************/
137/**************** compress_4 *****************/
138/**************** *****************/
139/*******************************************************************************************/
140
141void com_4(long val,long* in,long*out,int n,int pasin);
142void com_4_paire(long val1,long val2,long* in,long*out,int n,int pasin);
143
144
145#undef kmax_
146#undef kmak_
147#undef emak_
148#undef sgbi_
149#undef sign_
150
151
152#define kmax_ 15 /* valeur maximum de l'exposant */
153#define kmak_ 0xf /* masque pour l'exposant */
154#define emak_ 0xf /* masque pour l'ecart */
155#define sgbi_ 0x8 /* bit de signe de l'ecart */
156#define sign_ 0xfffffff0 /* masque de signe de l'ecart */
157
158/* compress un tableau in de n*7 points disposé avec un pas pasin */
159/* les data compressées sont ecrites dans le tableau out de n points*/
160/* la valeur val est la valeur de reference du point origine*/
161
162
163/* comprime 7*n + 2 points (de 16 bit chacun) */
164/* 1er et 2 eme point dans 1er mot, les ecarts dans les n mots suivants*/
165/* 7*n + 2 ==> n+1 ==> pour 72 points : 11 mots */
166
167void compress_4_1(long* in,long*out,int n,int pasin)
168{
169long val1,val2;
170val1=in[0];val2=in[1];
171*out=( (val1<<16) & 0xffff0000 ) | ( ( val2 ) & 0xffff ) ;
172
173com_4(val2,in+2,out+1,n/7,pasin);
174}
175
176
177
178void com_4(long val,long* in,long*out,int n,int pasin)
179{
180int filtre[16]={0xffffffff,0xfffffffe,0xfffffffc,0xfffffff8,
181 0xfffffff0,0xffffffe0,0xffffffc0,0xffffff80,
182 0xffffff00,0xfffffe00,0xfffffc00,0xfffff800,
183 0xfffff000,0xffffe000,0xffffc000,0xffff8000};
184int test[16]= {0x00000000,0x00000001,0x00000002,0x00000004,
185 0x00000008,0x00000010,0x00000020,0x00000040,
186 0x00000080,0x00000100,0x00000200,0x00000400,
187 0x00000800,0x00001000,0x00002000,0x00004000};
188
189long val1;
190long ec1,ec2,ec3,ec4,ec5,ec6,ec7;
191int i,k,k1;long q;
192
193
194for(i=0;i<n;i++)
195 {
196 k=0;q=7; /* 4 bit = 15 = +-7 */
197
198 ec1=in[i*7*pasin]-val;
199 shif(ec1,k,q);
200 val1=val + arrondi(ec1,k);
201
202 k1=k;
203 ec2=in[(i*7+1)*pasin]-val1;
204 shif(ec2,k,q);
205
206 if(k>k1) {k1=k;val1=val + arrondi(ec1,k);}
207 val1+= arrondi(ec2,k);
208
209 ec3=in[(i*7+2)*pasin]-val1;
210 shif(ec3,k,q);
211
212 if(k>k1) {k1=k;val1=val + arrondi(ec1,k) + arrondi(ec2,k);}
213 val1+= arrondi(ec3,k);
214
215 ec4=in[(i*7+3)*pasin]-val1;
216 shif(ec4,k,q);
217
218 if(k>k1) {k1=k;val1=val + arrondi(ec1,k) + arrondi(ec2,k) + arrondi(ec3,k);}
219 val1+= arrondi(ec4,k);
220
221 ec5=in[(i*7+4)*pasin]-val1;
222 shif(ec5,k,q);
223
224 if(k>k1) {k1=k;val1=val + arrondi(ec1,k) + arrondi(ec2,k) + arrondi(ec3,k) + arrondi(ec4,k);}
225 val1+= arrondi(ec5,k);
226
227 ec6=in[(i*7+5)*pasin]-val1;
228 shif(ec6,k,q);
229
230 if(k>k1) {k1=k;val1=val + arrondi(ec1,k) + arrondi(ec2,k) + arrondi(ec3,k)
231 + arrondi(ec4,k) + arrondi(ec5,k);}
232 val1+= arrondi(ec6,k);
233
234 ec7=in[(i*7+6)*pasin]-val1;
235 shif(ec7,k,q);
236
237/*printf("i=%d k=%d ec= %d %d %d \n",i,k,ec1,ec2,ec3,out[(i+8)/7]);*/
238
239 ec1 = arrondi(ec1,k) >> k;
240 ec2 = arrondi(ec2,k) >> k;
241 ec3 = arrondi(ec3,k) >> k;
242 ec4 = arrondi(ec4,k) >> k;
243 ec5 = arrondi(ec5,k) >> k;
244 ec6 = arrondi(ec6,k) >> k;
245 ec7 = arrondi(ec7,k) >> k;
246
247 out[i]= ((ec1&emak_)<<28) | ((ec2&emak_)<<24) | ((ec3&emak_)<<20)
248 | ((ec4&emak_)<<16) | ((ec5&emak_)<<12) | ((ec6&emak_)<<8) | ((ec7&emak_)<<4) | k ;
249
250
251/* if(i<30) printf("i=%d k=%d ec= %d %d %d \n",i,k,ec1,ec2,ec3,out[(i+8)/7]);*/
252
253 val+= ( (ec1 + ec2 + ec3 + ec4 + ec5 + ec6 + ec7 ) << k );
254 }
255}
256
257/********************************************************************************************/
258
259/* compresse en 4 bit mais par paire (pour data provenant de la detection synchrone) */
260
261/* 21 bit maleur maximum */
262/* comprime 7*n+2 points : 1er et 2eme point dans 1er et 2eme mot, suite dans n mots */
263/* différences entre valeures paires et entre valeures impaires uniquement */
264/* 7*n+2 ==> n+2 ==> pour 72 points : 12 mots */
265
266void compress_4_2(long* in,long*out,int n,int pasin)
267{
268long val1,val2;
269val1=in[0]; val2=in[1];
270out[0]=val1; out[1]=val2;
271com_4_paire(val1,val2,in+2,out+2,n/7,pasin);
272}
273
274
275void com_4_paire(long val1,long val2,long* in,long*out,int n,int pasin)
276{
277int filtre[16]={0xffffffff,0xfffffffe,0xfffffffc,0xfffffff8,
278 0xfffffff0,0xffffffe0,0xffffffc0,0xffffff80,
279 0xffffff00,0xfffffe00,0xfffffc00,0xfffff800,
280 0xfffff000,0xffffe000,0xffffc000,0xffff8000};
281int test[16]= {0x00000000,0x00000001,0x00000002,0x00000004,
282 0x00000008,0x00000010,0x00000020,0x00000040,
283 0x00000080,0x00000100,0x00000200,0x00000400,
284 0x00000800,0x00001000,0x00002000,0x00004000};
285
286long val1p,val2p;
287long ec1,ec2,ec3,ec4,ec5,ec6,ec7;
288int i,k,k1;long q;
289
290
291for(i=0;i<n;i++)
292 {
293 k=0;q=7; /* 4 bit = 15 = +-7 */
294
295 ec1=in[i*7*pasin]-val1;
296 shif(ec1,k,q);
297
298 ec2=in[(i*7+1)*pasin]-val2;
299 shif(ec2,k,q);
300
301 k1=k;
302 val1p=val1 + arrondi(ec1,k);
303
304
305 ec3=in[(i*7+2)*pasin]-val1p;
306 shif(ec3,k,q);
307
308 val2p=val2 + arrondi(ec2,k);
309
310 ec4=in[(i*7+3)*pasin]-val2p;
311 shif(ec4,k,q);
312
313 if(k>k1) {k1=k;val1p=val1 + arrondi(ec1,k);val2p = val2 + arrondi(ec2,k);}
314
315 val1p+= arrondi(ec3,k);
316
317 ec5=in[(i*7+4)*pasin]-val1p;
318 shif(ec5,k,q);
319
320 if(k>k1) { k1=k;
321 val1p=val1 + arrondi(ec1,k) + arrondi(ec3,k);
322 val2p=val2 + arrondi(ec2,k);
323 }
324 val2p+= arrondi(ec4,k);
325
326 ec6=in[(i*7+5)*pasin]-val2p;
327 shif(ec6,k,q);
328
329 if(k>k1) { k1=k;
330 val1p=val1 + arrondi(ec1,k) + arrondi(ec3,k);
331 val2p=val2 + arrondi(ec2,k) + arrondi(ec4,k);
332 }
333 val1p+= arrondi(ec5,k);
334
335 ec7=in[(i*7+6)*pasin]-val1p;
336 shif(ec7,k,q);
337
338/*printf("i=%d k=%d ec= %d %d %d \n",i,k,ec1,ec2,ec3,out[(i+8)/7]);*/
339
340 ec1 = arrondi(ec1,k) >> k;
341 ec2 = arrondi(ec2,k) >> k;
342 ec3 = arrondi(ec3,k) >> k;
343 ec4 = arrondi(ec4,k) >> k;
344 ec5 = arrondi(ec5,k) >> k;
345 ec6 = arrondi(ec6,k) >> k;
346 ec7 = arrondi(ec7,k) >> k;
347
348 out[i]= ((ec1&emak_)<<28) | ((ec2&emak_)<<24) | ((ec3&emak_)<<20)
349 | ((ec4&emak_)<<16) | ((ec5&emak_)<<12) | ((ec6&emak_)<<8) | ((ec7&emak_)<<4) | k ;
350
351
352/* if(i<30) printf("i=%d k=%d ec= %d %d %d \n",i,k,ec1,ec2,ec3,out[(i+8)/7]);*/
353
354 val1p = val1 + ( (ec1 + ec3 + ec5 + ec7 ) << k );
355 val1= val2 + ( (ec2 + ec4 + ec6 ) << k );
356 val2 = val1p;
357 }
358}
359
360
361
362
363
364/*******************************************************************************************/
365/**************** *****************/
366/**************** compress_7 *****************/
367/**************** *****************/
368/*******************************************************************************************/
369
370
371void compress_7(long val,long* in,long*out,int n,int pasin);
372void compress_7_paire(long val1,long val2,long* in,long*out,int n,int pasin);
373
374
375#undef kmax_
376#undef kmak_
377#undef emak_
378#undef sgbi_
379#undef sign_
380
381
382
383#define kmax_ 15 /* valeur maximum de l'exposant */
384#define kmak_ 0xf /* masque pour l'exposant */
385#define emak_ 0x7f /* masque pour l'ecart */
386#define sgbi_ 0x40 /* bit de signe de l'ecart */
387#define sign_ 0xffffff80 /* masque de signe de l'ecart */
388
389
390/* comprime 4*n points : 1er point dans 1er mot, tous les ecarts dans les n mots suivants */
391/* 4*n ==> n+1 */
392
393void compress_7_1(long* in,long*out,int n,int pasin)
394{
395long val;
396val=*in;
397*out=val;
398compress_7(val,in,out+1,n/4,pasin);
399}
400
401
402
403/* compress un tableau in de n*4 points disposé avec un pas pasin */
404/* les data compressées sont ecrites dans le tableau out de n points */
405/* la valeur val est la valeur de reference du point origine */
406
407void compress_7(long val,long* in,long*out,int n,int pasin)
408{
409int filtre[16]={0xffffffff,0xfffffffe,0xfffffffc,0xfffffff8,
410 0xfffffff0,0xffffffe0,0xffffffc0,0xffffff80,
411 0xffffff00,0xfffffe00,0xfffffc00,0xfffff800,
412 0xfffff000,0xffffe000,0xffffc000,0xffff8000};
413int test[16]= {0x00000000,0x00000001,0x00000002,0x00000004,
414 0x00000008,0x00000010,0x00000020,0x00000040,
415 0x00000080,0x00000100,0x00000200,0x00000400,
416 0x00000800,0x00001000,0x00002000,0x00004000};
417
418long val1;
419long ec1,ec2,ec3,ec4;
420int i,k,k1;long q;
421
422
423for(i=0;i<n;i++)
424 {
425 k=0;q=63; /* 7 bit -> 127 -> +-63 */
426
427 ec1=in[i*4*pasin]-val;
428 shif(ec1,k,q);
429 val1=val + arrondi(ec1,k);
430
431 k1=k;
432 ec2=in[(i*4+1)*pasin]-val1;
433 shif(ec2,k,q);
434
435/* if(k>k1) {k1=k;val1=val + arrondi(ec1,k);} */
436 val1+= arrondi(ec2,k);
437
438 ec3=in[(i*4+2)*pasin]-val1;
439 shif(ec3,k,q);
440
441/* if(k>k1) {k1=k;val1=val + arrondi(ec1,k) + arrondi(ec2,k);} */
442 val1+= arrondi(ec3,k);
443
444 ec4=in[(i*4+3)*pasin]-val1;
445 shif(ec4,k,q);
446
447/*printf("i=%d k=%d ec= %d %d %d \n",i,k,ec1,ec2,ec3,out[(i+8)/7]); */
448
449 ec1 = arrondi(ec1,k) >> k;
450 ec2 = arrondi(ec2,k) >> k;
451 ec3 = arrondi(ec3,k) >> k;
452 ec4 = arrondi(ec4,k) >> k;
453
454 out[i]= ((ec1&emak_)<<25) | ((ec2&emak_)<<18) | ((ec3&emak_)<<11) | ((ec4&emak_)<<4) | k ;
455
456/* if(i<30) printf("i=%d k=%d ec= %d %d %d \n",i,k,ec1,ec2,ec3,out[(i+8)/7]); */
457
458 val+= ( (ec1 + ec2 + ec3 + ec4 ) << k );
459 }
460}
461
462
463/*******************************************************************************************/
464
465/* compresse en 7 bit mais par paire (pour data provenant de la detection synchrone */
466
467/* ne prend que les 21 bit de poid faible dans le mot en entree */
468/* comprime 4*n points : 1er et 2eme point dans 1er mot (16 bit chacun), suite dans n mots */
469/* différences entre valeures paires et entre valeures impaires uniquement */
470/* 4*n ==> n+1 */
471
472#define point_in(i,pasin,n) (in[(i*4+n)*pasin]&0x1fffff)
473
474
475void compress_7_2(long* in,long*out,int n,int pasin)
476{
477long val1,val2;
478val1=in[0]&0x1fffe0;val2=in[1]&0x1fffe0;
479*out=( (val1<<11) & 0xffff0000 ) | ( (val2 >> 5) & 0xffff ) ;
480
481/*printf("in[0]=%x val1=%x // in[1]=%x val2=%x \n",in[0],val1,in[1],val2);
482printf("in[2]=%x in[3]=%x \n",in[2],in[3]);*/
483compress_7_paire(val1,val2,in,out+1,n/4,pasin);
484}
485
486
487void compress_7_paire(long val1,long val2,long* in,long*out,int n,int pasin)
488{
489int filtre[16]={0xffffffff,0xfffffffe,0xfffffffc,0xfffffff8,
490 0xfffffff0,0xffffffe0,0xffffffc0,0xffffff80,
491 0xffffff00,0xfffffe00,0xfffffc00,0xfffff800,
492 0xfffff000,0xffffe000,0xffffc000,0xffff8000};
493int test[16]= {0x00000000,0x00000001,0x00000002,0x00000004,
494 0x00000008,0x00000010,0x00000020,0x00000040,
495 0x00000080,0x00000100,0x00000200,0x00000400,
496 0x00000800,0x00001000,0x00002000,0x00004000};
497
498long val1p,val2p;
499long ec1,ec2,ec3,ec4;
500int i,k;long q;
501
502
503for(i=0;i<n;i++)
504 {
505 k=0;q=63; /* 7 bit -> 127 -> +-63 */
506
507 ec1=point_in(i,pasin,0)-val1;
508 shif(ec1,k,q);
509
510
511 ec2=point_in(i,pasin,1)-val2;
512 shif(ec2,k,q);
513
514 val1p =val1 + arrondi(ec1,k);
515
516 ec3=point_in(i,pasin,2)-val1p;
517 shif(ec3,k,q);
518
519 val2p=val2+ arrondi(ec2,k);
520
521 ec4=point_in(i,pasin,3)-val2p;
522 shif(ec4,k,q);
523
524/*printf("i=%d k=%d ec= %d %d %d \n",i,k,ec1,ec2,ec3,out[(i+8)/7]); */
525
526 ec1 = arrondi(ec1,k) >> k;
527 ec2 = arrondi(ec2,k) >> k;
528 ec3 = arrondi(ec3,k) >> k;
529 ec4 = arrondi(ec4,k) >> k;
530
531 out[i]= ((ec1&emak_)<<25) | ((ec2&emak_)<<18) | ((ec3&emak_)<<11) | ((ec4&emak_)<<4) | k ;
532
533/* if(i<5) printf("i=%d k=%d ec= %x %x %x %x out=%x \n",i,k,ec1,ec2,ec3,ec4,out[i]);*/
534
535 val1+= ( (ec1 + ec3 ) << k );
536 val2+= ( (ec2 + ec4 ) << k );
537 }
538}
539
540
541
542
Note: See TracBrowser for help on using the repository browser.