Changeset 13041 for OpenSceneGraph/trunk/src/osgDB/Compressors.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osgDB/Compressors.cpp (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgDB/Compressors.cpp
r12292 r13041 26 26 public: 27 27 NullCompressor() {} 28 28 29 29 virtual bool compress( std::ostream& fout, const std::string& src ) 30 30 { … … 34 34 return true; 35 35 } 36 36 37 37 virtual bool decompress( std::istream& fin, std::string& target ) 38 38 { … … 60 60 public: 61 61 ZLibCompressor() {} 62 62 63 63 virtual bool compress( std::ostream& fout, const std::string& src ) 64 64 { … … 67 67 z_stream strm; 68 68 unsigned char out[CHUNK]; 69 69 70 70 int level = 6; 71 71 int stategy = Z_DEFAULT_STRATEGY; 72 72 73 73 /* allocate deflate state */ 74 74 strm.zalloc = Z_NULL; … … 80 80 stategy ); 81 81 if ( ret != Z_OK ) return false; 82 82 83 83 strm.avail_in = src.size(); 84 84 strm.next_in = (Bytef*)( &(*src.begin()) ); 85 85 86 86 /* run deflate() on input until output buffer not full, finish 87 87 compression if all of source has been read in */ … … 91 91 strm.next_out = out; 92 92 ret = deflate(&strm, flush); /* no bad return value */ 93 93 94 94 if ( ret == Z_STREAM_ERROR ) 95 95 { … … 97 97 return false; 98 98 } 99 99 100 100 have = CHUNK - strm.avail_out; 101 101 if ( have>0 ) fout.write( (const char*)out, have ); 102 102 103 103 if ( fout.fail() ) 104 104 { … … 107 107 } 108 108 } while ( strm.avail_out==0 ); 109 109 110 110 /* clean up and return */ 111 111 (void)deflateEnd( &strm ); 112 112 return true; 113 113 } 114 114 115 115 virtual bool decompress( std::istream& fin, std::string& target ) 116 116 { … … 120 120 unsigned char in[CHUNK]; 121 121 unsigned char out[CHUNK]; 122 122 123 123 /* allocate inflate state */ 124 124 strm.zalloc = Z_NULL; … … 129 129 ret = inflateInit2( &strm, 130 130 15 + 32 ); // autodected zlib or gzip header 131 131 132 132 if ( ret!=Z_OK ) 133 133 { … … 135 135 return ret!=0; 136 136 } 137 137 138 138 /* decompress until deflate stream ends or end of file */ 139 139 do … … 142 142 strm.avail_in = fin.gcount(); 143 143 if (strm.avail_in==0 ) break; 144 144 145 145 /* run inflate() on input until output buffer not full */ 146 146 strm.next_in = in; … … 150 150 strm.next_out = out; 151 151 ret = inflate( &strm, Z_NO_FLUSH ); 152 152 153 153 switch (ret) 154 154 { … … 162 162 target.append( (char*)out, have ); 163 163 } while ( strm.avail_out==0 ); 164 164 165 165 /* done when inflate() says it's done */ 166 166 } while ( ret!=Z_STREAM_END ); 167 167 168 168 /* clean up and return */ 169 169 (void)inflateEnd( &strm );
