Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

decompress.cpp

Go to the documentation of this file.
00001 #include <string.h>
00002 #include "decompress.h"
00003 #include <zlib.h>
00004 #include <stdlib.h>
00005 
00006 size_t UnZip(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize)
00007 {
00008   z_stream zstream;
00009   memset(&zstream,sizeof(zstream),0);
00010   zstream.next_in = compressedbuffer;
00011   zstream.next_out = tgtbuffer;
00012   zstream.avail_out = bsize;
00013   zstream.avail_in = reclen;
00014 
00015   int keylen = 0;
00016 
00017   zstream.zalloc = Z_NULL;
00018   zstream.zfree = Z_NULL;
00019   zstream.opaque = Z_NULL;
00020   
00021   //  printf("Initialising\n");
00022   
00023   inflateInit(&zstream);
00024   int err = 0;
00025   do {
00026     if ( zstream.avail_in == 0 && 0 < keylen ) {
00027       zstream.next_in   = compressedbuffer + keylen;
00028       zstream.avail_in  = reclen - keylen;
00029       keylen      = 0;
00030     }
00031     zstream.next_out  = tgtbuffer;
00032     zstream.avail_out = bsize;
00033 
00034     err = inflate( &zstream, Z_SYNC_FLUSH );
00035 
00036     //  //qDebug("err:%d - %u", err, zstream.avail_in);
00037 
00038   } while ( err == Z_OK );
00039 
00040   inflateEnd(&zstream);
00041   return zstream.total_out;
00042 }
00043 
00044 #if defined(__STATIC) && defined(USENEF)
00045 #include "Model.h"
00046 size_t (*getdecompressor(char* _s))(UInt8*, size_t, UInt8*, size_t)
00047 {
00048   if (strcmp(_s, "PluckerDecompress3") == 0)
00049     {
00050       return PluckerDecompress3;
00051     }
00052   if (strcmp(_s, "PluckerDecompress4") == 0)
00053     {
00054       return PluckerDecompress4;
00055     }
00056   if (strcmp(_s, "RebDecompress") == 0)
00057     {
00058       return RebDecompress;
00059     }
00060   return NULL;
00061 }
00062 #else
00063 
00064 #include "qfileinfo.h"
00065 
00066 #include <dlfcn.h>
00067 
00068 size_t (*getdecompressor(char* _s))(UInt8*, size_t, UInt8*, size_t)
00069 {
00070 #ifdef USEQPE
00071 #ifdef OPIE
00072   QString codecpath(getenv("OPIEDIR"));
00073 #else
00074   QString codecpath(getenv("QTDIR"));
00075 #endif
00076   codecpath += "/plugins/reader/support/libpluckerdecompress.so";
00077 #else
00078   QString codecpath(getenv("READERDIR"));
00079   codecpath += "/support/libpluckerdecompress.so";
00080 #endif
00081   qDebug("Codec:%s", (const char*)codecpath);
00082   if (QFile::exists(codecpath))
00083     {
00084       qDebug("Codec:%s", (const char*)codecpath);
00085       void* handle = dlopen(codecpath, RTLD_LAZY);
00086       if (handle == 0)
00087         {
00088           qDebug("Can't find codec:%s", dlerror());
00089           return NULL;
00090         }
00091       return (size_t (*)(UInt8*, size_t, UInt8*, size_t))dlsym(handle, _s);
00092     }
00093   return NULL;
00094 }
00095 #endif

Generated on Sat Nov 5 16:16:54 2005 for OPIE by  doxygen 1.4.2