Diffstat (limited to 'noncore/apps/opie-reader/ppm_expander.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/ppm_expander.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/noncore/apps/opie-reader/ppm_expander.cpp b/noncore/apps/opie-reader/ppm_expander.cpp index fe2745c..ea5b955 100644 --- a/noncore/apps/opie-reader/ppm_expander.cpp +++ b/noncore/apps/opie-reader/ppm_expander.cpp | |||
@@ -1,34 +1,35 @@ | |||
1 | /* | 1 | /* |
2 | * Interface pour le programme de compression | 2 | * Interface pour le programme de compression |
3 | * (c) 1995 Fabrice Bellard | 3 | * (c) 1995 Fabrice Bellard |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
7 | //#include <unistd.h> | 7 | //#include <unistd.h> |
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <string.h> | 9 | #include <string.h> |
10 | #include <time.h> | 10 | #include <time.h> |
11 | #include "static.h" | ||
11 | 12 | ||
12 | /*************************************************************************** | 13 | /*************************************************************************** |
13 | * Interface avec les routines de compression | 14 | * Interface avec les routines de compression |
14 | */ | 15 | */ |
15 | 16 | ||
16 | #define METHOD_NB 2 /* nombre total de méthodes de compression */ | 17 | #define METHOD_NB 2 /* nombre total de méthodes de compression */ |
17 | 18 | ||
18 | #define METHOD_STORE 0 | 19 | #define METHOD_STORE 0 |
19 | #define METHOD_PPM 1 | 20 | #define METHOD_PPM 1 |
20 | 21 | ||
21 | 22 | ||
22 | #define DEFAULT_SUFFIX ".st" /* extension par défault */ | 23 | #define DEFAULT_SUFFIX ".st" /* extension par défault */ |
23 | /* signature en début de fichier */ | 24 | /* signature en début de fichier */ |
24 | #define STAT_MAGIC_SIZE 4 | 25 | #define STAT_MAGIC_SIZE 4 |
25 | char stat_magic[STAT_MAGIC_SIZE]={'P','P','M','S'}; | 26 | char stat_magic[STAT_MAGIC_SIZE]={'P','P','M','S'}; |
26 | 27 | ||
27 | #include "ppm_expander.h" | 28 | #include "ppm_expander.h" |
28 | 29 | ||
29 | ppm_expander::~ppm_expander() { | 30 | ppm_expander::~ppm_expander() { |
30 | if (needppmend) ppm.PPM_End(); | 31 | if (needppmend) ppm.PPM_End(); |
31 | ppm.arith.Arith_DecodeEnd(); | 32 | ppm.arith.Arith_DecodeEnd(); |
32 | if (buf_in!=NULL) delete [] buf_in; | 33 | if (buf_in!=NULL) delete [] buf_in; |
33 | if (buf_out!=NULL) delete [] buf_out; | 34 | if (buf_out!=NULL) delete [] buf_out; |
34 | if (my_read_buf != NULL) delete my_read_buf; | 35 | if (my_read_buf != NULL) delete my_read_buf; |
@@ -44,65 +45,72 @@ int ppm_expander::OpenFile(const char* infile) | |||
44 | 45 | ||
45 | void ppm_expander::sizes(unsigned long& file, unsigned long& text) | 46 | void ppm_expander::sizes(unsigned long& file, unsigned long& text) |
46 | { | 47 | { |
47 | struct stat _stat; | 48 | struct stat _stat; |
48 | fstat(fileno(my_file_in),&_stat); | 49 | fstat(fileno(my_file_in),&_stat); |
49 | file = _stat.st_size; | 50 | file = _stat.st_size; |
50 | text = numblocks*blocksize; | 51 | text = numblocks*blocksize; |
51 | } | 52 | } |
52 | 53 | ||
53 | int ppm_expander::home() | 54 | int ppm_expander::home() |
54 | { | 55 | { |
55 | fseek(my_file_in,0, SEEK_SET); | 56 | fseek(my_file_in,0, SEEK_SET); |
56 | unsigned char header[STAT_MAGIC_SIZE]; | 57 | unsigned char header[STAT_MAGIC_SIZE]; |
57 | size_t len=fread(header,1,STAT_MAGIC_SIZE,my_file_in); | 58 | size_t len=fread(header,1,STAT_MAGIC_SIZE,my_file_in); |
58 | if (strncmp((char*)header,stat_magic,STAT_MAGIC_SIZE)!=0) { | 59 | if (strncmp((char*)header,stat_magic,STAT_MAGIC_SIZE)!=0) { |
59 | return 1; | 60 | return 1; |
60 | } | 61 | } |
61 | if (len!=(STAT_MAGIC_SIZE)) { | 62 | if (len!=(STAT_MAGIC_SIZE)) { |
62 | return 1; | 63 | return 1; |
63 | } | 64 | } |
64 | if (fread(&maxnode,sizeof(maxnode),1,my_file_in) != 1) return 1; | 65 | if (fread(&maxnode,sizeof(maxnode),1,my_file_in) != 1) return 1; |
65 | if (fread(&blocksize,sizeof(blocksize),1,my_file_in) != 1) return 1; | 66 | if (fread(&blocksize,sizeof(blocksize),1,my_file_in) != 1) return 1; |
66 | if (fread(&numblocks,sizeof(numblocks),1,my_file_in) != 1) return 1; | 67 | if (fread(&numblocks,sizeof(numblocks),1,my_file_in) != 1) return 1; |
67 | //fprintf(stderr,"<%u,%u,%u>\n",maxnode,blocksize,numblocks); | 68 | //fprintf(stderr,"<%u,%u,%u>\n",maxnode,blocksize,numblocks); |
68 | int err = locate(0,0); | 69 | locate(0,0); |
69 | outbytes = 0; | 70 | outbytes = 0; |
70 | return err; | 71 | return 0; |
71 | } | 72 | } |
72 | 73 | ||
73 | void ppm_expander::locate(unsigned int n) { | 74 | void ppm_expander::locate(unsigned int n) { |
74 | locate(n/blocksize, n%blocksize); | 75 | locate(n/blocksize, n%blocksize); |
75 | outbytes = n; | 76 | outbytes = n; |
76 | } | 77 | } |
77 | 78 | ||
78 | int ppm_expander::locate(unsigned short block, unsigned int n) | 79 | void ppm_expander::locate(unsigned short block, unsigned int n) |
79 | { | 80 | { |
80 | if (needppmend) | 81 | if (needppmend) |
81 | { | 82 | { |
82 | ppm.PPM_End(); | 83 | ppm.PPM_End(); |
83 | needppmend = false; | 84 | needppmend = false; |
84 | } | 85 | } |
85 | size_t fpos; | 86 | size_t fpos; |
86 | fseek(my_file_in,STAT_MAGIC_SIZE+sizeof(maxnode)+sizeof(blocksize)+sizeof(numblocks)+block*sizeof(fpos),SEEK_SET); | 87 | fseek(my_file_in,STAT_MAGIC_SIZE+sizeof(maxnode)+sizeof(blocksize)+sizeof(numblocks)+block*sizeof(fpos),SEEK_SET); |
87 | if (fread(&fpos,sizeof(fpos),1,my_file_in) != 1) return 1; | 88 | fread(&fpos,sizeof(fpos),1,my_file_in); |
88 | fseek(my_file_in,fpos,SEEK_SET); | 89 | fseek(my_file_in,fpos,SEEK_SET); |
89 | 90 | ||
90 | ppm.arith.Arith_DecodeInit(my_read_buf,buf_in,bufsize); | 91 | ppm.arith.Arith_DecodeInit(my_read_buf,buf_in,bufsize); |
91 | int err=ppm.PPM_Init(maxnode); | 92 | int err=ppm.PPM_Init(maxnode); |
92 | needppmend = true; | 93 | needppmend = true; |
93 | curblock = block; | 94 | curblock = block; |
94 | for (int i = 0; i < n; i++) getch(); | 95 | for (int i = 0; i < n; i++) getch(); |
95 | } | 96 | } |
96 | 97 | ||
97 | int ppm_expander::getch() { | 98 | int ppm_expander::getch() { |
98 | if (curblock >= numblocks) return EOF; | 99 | if (curblock >= numblocks) return EOF; |
99 | int c=ppm.PPM_Decode(); | 100 | int c=ppm.PPM_Decode(); |
100 | if (c == SYM_EOF) | 101 | if (c == SYM_EOF) |
101 | { | 102 | { |
102 | if (++curblock >= numblocks) return EOF; | 103 | if (++curblock >= numblocks) return EOF; |
103 | locate(curblock,0); | 104 | locate(curblock,0); |
104 | c = ppm.PPM_Decode(); | 105 | c = ppm.PPM_Decode(); |
105 | } | 106 | } |
106 | outbytes++; | 107 | outbytes++; |
107 | return (c==SYM_EOF) ? EOF : c; | 108 | return (c==SYM_EOF) ? EOF : c; |
108 | } | 109 | } |
110 | |||
111 | #ifndef __STATIC | ||
112 | extern "C" | ||
113 | { | ||
114 | CExpander* newcodec() { return new ppm_expander; } | ||
115 | } | ||
116 | #endif | ||