summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/decompress.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/decompress.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-reader/decompress.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/noncore/apps/opie-reader/decompress.cpp b/noncore/apps/opie-reader/decompress.cpp
new file mode 100644
index 0000000..9bfec49
--- a/dev/null
+++ b/noncore/apps/opie-reader/decompress.cpp
@@ -0,0 +1,95 @@
1#include <string.h>
2#include "decompress.h"
3#include <zlib.h>
4#include <stdlib.h>
5
6size_t UnZip(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize)
7{
8 z_stream zstream;
9 memset(&zstream,sizeof(zstream),0);
10 zstream.next_in = compressedbuffer;
11 zstream.next_out = tgtbuffer;
12 zstream.avail_out = bsize;
13 zstream.avail_in = reclen;
14
15 int keylen = 0;
16
17 zstream.zalloc = Z_NULL;
18 zstream.zfree = Z_NULL;
19 zstream.opaque = Z_NULL;
20
21 // printf("Initialising\n");
22
23 inflateInit(&zstream);
24 int err = 0;
25 do {
26 if ( zstream.avail_in == 0 && 0 < keylen ) {
27 zstream.next_in = compressedbuffer + keylen;
28 zstream.avail_in = reclen - keylen;
29 keylen = 0;
30 }
31 zstream.next_out = tgtbuffer;
32 zstream.avail_out = bsize;
33
34 err = inflate( &zstream, Z_SYNC_FLUSH );
35
36 ////qDebug("err:%d - %u", err, zstream.avail_in);
37
38 } while ( err == Z_OK );
39
40 inflateEnd(&zstream);
41 return zstream.total_out;
42}
43
44#if defined(__STATIC) && defined(USENEF)
45#include "Model.h"
46size_t (*getdecompressor(char* _s))(UInt8*, size_t, UInt8*, size_t)
47{
48 if (strcmp(_s, "PluckerDecompress3") == 0)
49 {
50 return PluckerDecompress3;
51 }
52 if (strcmp(_s, "PluckerDecompress4") == 0)
53 {
54 return PluckerDecompress4;
55 }
56 if (strcmp(_s, "RebDecompress") == 0)
57 {
58 return RebDecompress;
59 }
60 return NULL;
61}
62#else
63
64#include "qfileinfo.h"
65
66#include <dlfcn.h>
67
68size_t (*getdecompressor(char* _s))(UInt8*, size_t, UInt8*, size_t)
69{
70#ifdef USEQPE
71#ifdef OPIE
72 QString codecpath(getenv("OPIEDIR"));
73#else
74 QString codecpath(getenv("QTDIR"));
75#endif
76 codecpath += "/plugins/reader/support/libpluckerdecompress.so";
77#else
78 QString codecpath(getenv("READERDIR"));
79 codecpath += "/support/libpluckerdecompress.so";
80#endif
81 qDebug("Codec:%s", (const char*)codecpath);
82 if (QFile::exists(codecpath))
83 {
84 qDebug("Codec:%s", (const char*)codecpath);
85 void* handle = dlopen(codecpath, RTLD_LAZY);
86 if (handle == 0)
87 {
88 qDebug("Can't find codec:%s", dlerror());
89 return NULL;
90 }
91 return (size_t (*)(UInt8*, size_t, UInt8*, size_t))dlsym(handle, _s);
92 }
93 return NULL;
94}
95#endif