Prototype FSM implementation of adaptive entropy decoder
[platform/upstream/libaec.git] / src / mytest.c
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <stdlib.h>
4 #include <inttypes.h>
5 #include "aecd.h"
6
7 #define CHUNK_OUT 1
8 #define CHUNK_IN 1
9 #define ALL_IN 9478
10
11 int main(int argc, char *argv[])
12 {
13         ae_stream strm;
14         int c, i, n, status, todo;
15         uint8_t *in;
16         uint32_t *out;
17         size_t total_out;
18
19         in = (uint8_t *)malloc(ALL_IN);
20         out = (uint32_t *)malloc(CHUNK_OUT * sizeof(uint32_t));
21         if (in == NULL || out == NULL)
22                 return 1;
23
24         n = 0;
25         while ((c = getc(stdin)) != EOF)
26         {
27                 *in++ = c;
28                 n++;
29         }
30         in -= n;
31
32         strm.bit_per_sample = 8;
33         strm.block_size = 8;
34         strm.segment_size = 2;
35         strm.pp = 1;
36
37         if (ae_decode_init(&strm) != AE_OK)
38                 return 1;
39         
40         strm.next_in = in;
41         strm.avail_in = CHUNK_IN;
42         strm.next_out = out;
43         strm.avail_out = CHUNK_OUT;
44         todo = 1;
45         total_out = 0;
46         
47         while(todo)
48         {
49                 todo = 0;
50                 if ((status = ae_decode(&strm, 0)) != AE_OK)
51                 {
52                         fprintf(stderr, "error is %i\n", status);
53                         return 1;
54                 }
55                 fprintf(stderr, "avail in %li total in %li avail out %li total out %lx\n", strm.avail_in, strm.total_in, strm.avail_out, strm.total_out);
56
57                 if (strm.avail_in == 0 && strm.total_in < ALL_IN)
58                 {
59                         in += CHUNK_IN;
60
61                         strm.next_in = in;
62                         if (ALL_IN - strm.total_in < CHUNK_IN)
63                                 strm.avail_in = ALL_IN - strm.total_in;
64                         else
65                                 strm.avail_in = CHUNK_IN;
66                         todo = 1;
67                 }
68
69                 if (strm.total_out - total_out > 0)
70                 {
71                         for (i=0; i < strm.total_out - total_out; i++)
72                         {
73                                 putc(out[i], stdout);
74                         }
75                         total_out = strm.total_out;
76                         strm.next_out = out;
77                         strm.avail_out = CHUNK_OUT;
78                         todo = 1;
79                 }
80         }
81
82         return 0;
83 }