27 #include FT_INTERNAL_MEMORY_H 28 #include FT_INTERNAL_STREAM_H 29 #include FT_INTERNAL_DEBUG_H 31 #include FT_CONFIG_STANDARD_LIBRARY_H 34 #include FT_MODULE_ERRORS_H 39 #define FT_ERR_PREFIX Bzip2_Err_ 40 #define FT_ERR_BASE FT_Mod_Err_Bzip2 45 #ifdef FT_CONFIG_OPTION_USE_BZIP2 47 #ifdef FT_CONFIG_OPTION_PIC 48 #error "bzip2 code does not support PIC yet" 66 typedef void *(* alloc_func)(
void*,
int,
int);
67 typedef void (* free_func)(
void*,
void*);
100 #define FT_BZIP2_BUFFER_SIZE 4096 102 typedef struct FT_BZip2FileRec_
116 } FT_BZip2FileRec, *FT_BZip2File;
133 if ( head[0] != 0x42 ||
137 error =
FT_THROW( Invalid_File_Format );
147 ft_bzip2_file_init( FT_BZip2File zip,
151 bz_stream* bzstream = &zip->bzstream;
157 zip->memory = stream->
memory;
159 zip->limit = zip->buffer + FT_BZIP2_BUFFER_SIZE;
160 zip->cursor = zip->limit;
167 error = ft_bzip2_check_header( stream );
176 bzstream->bzalloc = (alloc_func)ft_bzip2_alloc;
177 bzstream->bzfree = (free_func) ft_bzip2_free;
178 bzstream->opaque = zip->memory;
180 bzstream->avail_in = 0;
181 bzstream->next_in = (
char*)zip->buffer;
183 if ( BZ2_bzDecompressInit( bzstream, 0, 0 ) != BZ_OK ||
184 bzstream->next_in ==
NULL )
185 error =
FT_THROW( Invalid_File_Format );
193 ft_bzip2_file_done( FT_BZip2File zip )
195 bz_stream* bzstream = &zip->bzstream;
198 BZ2_bzDecompressEnd( bzstream );
201 bzstream->bzalloc =
NULL;
202 bzstream->bzfree =
NULL;
203 bzstream->opaque =
NULL;
204 bzstream->next_in =
NULL;
205 bzstream->next_out =
NULL;
206 bzstream->avail_in = 0;
207 bzstream->avail_out = 0;
216 ft_bzip2_file_reset( FT_BZip2File zip )
224 bz_stream* bzstream = &zip->bzstream;
227 BZ2_bzDecompressEnd( bzstream );
229 bzstream->avail_in = 0;
230 bzstream->next_in = (
char*)zip->input;
231 bzstream->avail_out = 0;
232 bzstream->next_out = (
char*)zip->buffer;
234 zip->limit = zip->buffer + FT_BZIP2_BUFFER_SIZE;
235 zip->cursor = zip->limit;
238 BZ2_bzDecompressInit( bzstream, 0, 0 );
246 ft_bzip2_file_fill_input( FT_BZip2File zip )
248 bz_stream* bzstream = &zip->bzstream;
255 size = stream->
read( stream, stream->
pos, zip->input,
256 FT_BZIP2_BUFFER_SIZE );
258 return FT_THROW( Invalid_Stream_Operation );
262 size = stream->
size - stream->
pos;
263 if ( size > FT_BZIP2_BUFFER_SIZE )
264 size = FT_BZIP2_BUFFER_SIZE;
267 return FT_THROW( Invalid_Stream_Operation );
273 bzstream->next_in = (
char*)zip->input;
274 bzstream->avail_in = size;
281 ft_bzip2_file_fill_output( FT_BZip2File zip )
283 bz_stream* bzstream = &zip->bzstream;
287 zip->cursor = zip->buffer;
288 bzstream->next_out = (
char*)zip->cursor;
289 bzstream->avail_out = FT_BZIP2_BUFFER_SIZE;
291 while ( bzstream->avail_out > 0 )
296 if ( bzstream->avail_in == 0 )
298 error = ft_bzip2_file_fill_input( zip );
303 err = BZ2_bzDecompress( bzstream );
305 if ( err == BZ_STREAM_END )
307 zip->limit = (
FT_Byte*)bzstream->next_out;
308 if ( zip->limit == zip->cursor )
309 error =
FT_THROW( Invalid_Stream_Operation );
312 else if ( err != BZ_OK )
314 error =
FT_THROW( Invalid_Stream_Operation );
325 ft_bzip2_file_skip_output( FT_BZip2File zip,
334 delta = (
FT_ULong)( zip->limit - zip->cursor );
335 if ( delta >= count )
338 zip->cursor += delta;
345 error = ft_bzip2_file_fill_output( zip );
355 ft_bzip2_file_io( FT_BZip2File zip,
366 if ( pos < zip->pos )
368 error = ft_bzip2_file_reset( zip );
374 if ( pos > zip->pos )
376 error = ft_bzip2_file_skip_output( zip, (
FT_ULong)( pos - zip->pos ) );
390 delta = (
FT_ULong)( zip->limit - zip->cursor );
391 if ( delta >= count )
397 zip->cursor += delta;
404 error = ft_bzip2_file_fill_output( zip );
423 ft_bzip2_stream_close(
FT_Stream stream )
432 ft_bzip2_file_done( zip );
450 return ft_bzip2_file_io( zip, pos,
buffer, count );
460 FT_BZip2File zip =
NULL;
467 error = ft_bzip2_check_header( source );
476 error = ft_bzip2_file_init( zip, stream, source );
486 stream->
size = 0x7FFFFFFFL;
489 stream->
read = ft_bzip2_stream_io;
490 stream->
close = ft_bzip2_stream_close;
505 return FT_THROW( Unimplemented_Feature );
#define FT_ALLOC(ptr, size)
return FT_THROW(Missing_Property)
GLsizei GLsizei GLchar * source
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
GLenum GLenum GLenum input
FT_Stream_OpenBzip2(FT_Stream stream, FT_Stream source)
FT_Stream_CloseFunc close
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
#define FT_STREAM_SEEK(position)
if(!abbox) return FT_THROW(Invalid_Argument)
GLuint GLuint GLsizei count
#define FT_MEM_COPY(dest, source, count)
#define FT_STREAM_READ(buffer, count)