summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/ppm_expander.cpp
Unidiff
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.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/noncore/apps/opie-reader/ppm_expander.cpp b/noncore/apps/opie-reader/ppm_expander.cpp
index 2a4318b..61ef90e 100644
--- a/noncore/apps/opie-reader/ppm_expander.cpp
+++ b/noncore/apps/opie-reader/ppm_expander.cpp
@@ -17,49 +17,49 @@
17 17
18#define METHOD_STORE 0 18#define METHOD_STORE 0
19#define METHOD_PPM 1 19#define METHOD_PPM 1
20 20
21 21
22#define DEFAULT_SUFFIX ".st" /* extension par défault */ 22#define DEFAULT_SUFFIX ".st" /* extension par défault */
23/* signature en début de fichier */ 23/* signature en début de fichier */
24#define STAT_MAGIC_SIZE 4 24#define STAT_MAGIC_SIZE 4
25char stat_magic[STAT_MAGIC_SIZE]={'P','P','M','S'}; 25char stat_magic[STAT_MAGIC_SIZE]={'P','P','M','S'};
26 26
27#include "ppm_expander.h" 27#include "ppm_expander.h"
28 28
29ppm_expander::~ppm_expander() { 29ppm_expander::~ppm_expander() {
30 if (needppmend) ppm.PPM_End(); 30 if (needppmend) ppm.PPM_End();
31 ppm.arith.Arith_DecodeEnd(); 31 ppm.arith.Arith_DecodeEnd();
32 if (buf_in!=NULL) delete [] buf_in; 32 if (buf_in!=NULL) delete [] buf_in;
33 if (buf_out!=NULL) delete [] buf_out; 33 if (buf_out!=NULL) delete [] buf_out;
34 if (my_read_buf != NULL) delete my_read_buf; 34 if (my_read_buf != NULL) delete my_read_buf;
35 if (my_file_in != NULL) fclose(my_file_in); 35 if (my_file_in != NULL) fclose(my_file_in);
36} 36}
37 37
38int ppm_expander::OpenFile(const char* infile) 38int ppm_expander::OpenFile(const char* infile)
39{ 39{
40 my_file_in=fopen(infile,"rb"); 40 my_file_in=fopen(infile,"rb");
41 my_read_buf = new PPM_ReadBuf(my_file_in); 41 my_read_buf = new PPM_ReadBuf(my_file_in, this);
42 return home(); 42 return home();
43} 43}
44 44
45void ppm_expander::sizes(unsigned long& file, unsigned long& text) 45void ppm_expander::sizes(unsigned long& file, unsigned long& text)
46{ 46{
47 struct stat _stat; 47 struct stat _stat;
48 fstat(fileno(my_file_in),&_stat); 48 fstat(fileno(my_file_in),&_stat);
49 file = _stat.st_size; 49 file = _stat.st_size;
50 text = numblocks*blocksize; 50 text = numblocks*blocksize;
51} 51}
52 52
53int ppm_expander::home() 53int ppm_expander::home()
54{ 54{
55 fseek(my_file_in,0, SEEK_SET); 55 fseek(my_file_in,0, SEEK_SET);
56 unsigned char header[STAT_MAGIC_SIZE]; 56 unsigned char header[STAT_MAGIC_SIZE];
57 size_t len=fread(header,1,STAT_MAGIC_SIZE,my_file_in); 57 size_t len=fread(header,1,STAT_MAGIC_SIZE,my_file_in);
58 if (strncmp((char*)header,stat_magic,STAT_MAGIC_SIZE)!=0) { 58 if (strncmp((char*)header,stat_magic,STAT_MAGIC_SIZE)!=0) {
59 return 1; 59 return 1;
60 } 60 }
61 if (len!=(STAT_MAGIC_SIZE)) { 61 if (len!=(STAT_MAGIC_SIZE)) {
62 return 1; 62 return 1;
63 } 63 }
64 if (fread(&maxnode,sizeof(maxnode),1,my_file_in) != 1) return 1; 64 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; 65 if (fread(&blocksize,sizeof(blocksize),1,my_file_in) != 1) return 1;
@@ -86,30 +86,39 @@ void ppm_expander::locate(unsigned short block, unsigned int n)
86 fseek(my_file_in,STAT_MAGIC_SIZE+sizeof(maxnode)+sizeof(blocksize)+sizeof(numblocks)+block*sizeof(fpos),SEEK_SET); 86 fseek(my_file_in,STAT_MAGIC_SIZE+sizeof(maxnode)+sizeof(blocksize)+sizeof(numblocks)+block*sizeof(fpos),SEEK_SET);
87 fread(&fpos,sizeof(fpos),1,my_file_in); 87 fread(&fpos,sizeof(fpos),1,my_file_in);
88 fseek(my_file_in,fpos,SEEK_SET); 88 fseek(my_file_in,fpos,SEEK_SET);
89 89
90 ppm.arith.Arith_DecodeInit(my_read_buf,buf_in,bufsize); 90 ppm.arith.Arith_DecodeInit(my_read_buf,buf_in,bufsize);
91 int err=ppm.PPM_Init(maxnode); 91 int err=ppm.PPM_Init(maxnode);
92 needppmend = true; 92 needppmend = true;
93 curblock = block; 93 curblock = block;
94 for (int i = 0; i < n; i++) getch(); 94 for (int i = 0; i < n; i++) getch();
95} 95}
96 96
97int ppm_expander::getch() { 97int ppm_expander::getch() {
98 if (curblock >= numblocks) return EOF; 98 if (curblock >= numblocks) return EOF;
99 int c=ppm.PPM_Decode(); 99 int c=ppm.PPM_Decode();
100 if (c == SYM_EOF) 100 if (c == SYM_EOF)
101 { 101 {
102 if (++curblock >= numblocks) return EOF; 102 if (++curblock >= numblocks) return EOF;
103 locate(curblock,0); 103 locate(curblock,0);
104 c = ppm.PPM_Decode(); 104 c = ppm.PPM_Decode();
105 } 105 }
106 outbytes++; 106 outbytes++;
107 return (c==SYM_EOF) ? EOF : c; 107 return (c==SYM_EOF) ? EOF : c;
108} 108}
109 109
110UINT PPM_ReadBuf::readbuf(UCHAR *buf,UINT len)
111 {
112 UINT len1;
113 parent->unsuspend();
114 len1=fread(buf,1,len,my_file_in);
115 return len1;
116 }
117
118
110#ifndef __STATIC 119#ifndef __STATIC
111extern "C" 120extern "C"
112{ 121{
113 CExpander* newcodec() { return new ppm_expander; } 122 CExpander* newcodec() { return new ppm_expander; }
114} 123}
115#endif 124#endif