24 #include FT_INTERNAL_MEMORY_H
25 #include FT_INTERNAL_STREAM_H
26 #include FT_INTERNAL_DEBUG_H
28 #include FT_CONFIG_STANDARD_LIBRARY_H
31 #include FT_MODULE_ERRORS_H
36 #define FT_ERR_PREFIX Gzip_Err_
37 #define FT_ERR_BASE FT_Mod_Err_Gzip
42 #ifdef FT_CONFIG_OPTION_USE_ZLIB
44 #ifdef FT_CONFIG_OPTION_PIC
45 #error "gzip code does not support PIC yet"
48 #ifdef FT_CONFIG_OPTION_SYSTEM_ZLIB
62 #ifndef USE_ZLIB_ZCALLOC
73 #define NO_INFLATE_MASK
79 #undef NO_INFLATE_MASK
127 #if !defined( FT_CONFIG_OPTION_SYSTEM_ZLIB ) && !defined( USE_ZLIB_ZCALLOC )
134 return ft_gzip_alloc( (
FT_Memory)opaque, items, size );
155 #define FT_GZIP_BUFFER_SIZE 4096
157 typedef struct FT_GZipFileRec_
172 } FT_GZipFileRec, *FT_GZipFile;
176 #define FT_GZIP_ASCII_FLAG 0x01
177 #define FT_GZIP_HEAD_CRC 0x02
178 #define FT_GZIP_EXTRA_FIELD 0x04
179 #define FT_GZIP_ORIG_NAME 0x08
180 #define FT_GZIP_COMMENT 0x10
181 #define FT_GZIP_RESERVED 0xE0
198 if ( head[0] != 0x1f ||
201 (head[3] & FT_GZIP_RESERVED) )
203 error = Gzip_Err_Invalid_File_Format;
211 if ( head[3] & FT_GZIP_EXTRA_FIELD )
222 if ( head[3] & FT_GZIP_ORIG_NAME )
236 if ( head[3] & FT_GZIP_COMMENT )
250 if ( head[3] & FT_GZIP_HEAD_CRC )
260 ft_gzip_file_init( FT_GZipFile zip,
270 zip->memory = stream->
memory;
272 zip->limit = zip->buffer + FT_GZIP_BUFFER_SIZE;
273 zip->cursor = zip->limit;
280 error = ft_gzip_check_header( stream );
288 zstream->
zalloc = (alloc_func)ft_gzip_alloc;
289 zstream->
zfree = (free_func) ft_gzip_free;
293 zstream->
next_in = zip->buffer;
297 error = Gzip_Err_Invalid_File_Format;
305 ft_gzip_file_done( FT_GZipFile zip )
328 ft_gzip_file_reset( FT_GZipFile zip )
346 zip->limit = zip->buffer + FT_GZIP_BUFFER_SIZE;
347 zip->cursor = zip->limit;
356 ft_gzip_file_fill_input( FT_GZipFile zip )
365 size = stream->
read( stream, stream->
pos, zip->input,
366 FT_GZIP_BUFFER_SIZE );
368 return Gzip_Err_Invalid_Stream_Operation;
372 size = stream->
size - stream->
pos;
373 if ( size > FT_GZIP_BUFFER_SIZE )
374 size = FT_GZIP_BUFFER_SIZE;
377 return Gzip_Err_Invalid_Stream_Operation;
391 ft_gzip_file_fill_output( FT_GZipFile zip )
397 zip->cursor = zip->buffer;
399 zstream->
avail_out = FT_GZIP_BUFFER_SIZE;
408 error = ft_gzip_file_fill_input( zip );
418 if ( zip->limit == zip->cursor )
419 error = Gzip_Err_Invalid_Stream_Operation;
422 else if ( err !=
Z_OK )
424 error = Gzip_Err_Invalid_Stream_Operation;
435 ft_gzip_file_skip_output( FT_GZipFile zip,
444 delta = (
FT_ULong)( zip->limit - zip->cursor );
445 if ( delta >= count )
448 zip->cursor += delta;
455 error = ft_gzip_file_fill_output( zip );
465 ft_gzip_file_io( FT_GZipFile zip,
476 if ( pos < zip->pos )
478 error = ft_gzip_file_reset( zip );
484 if ( pos > zip->pos )
486 error = ft_gzip_file_skip_output( zip, (
FT_ULong)( pos - zip->pos ) );
500 delta = (
FT_ULong)( zip->limit - zip->cursor );
501 if ( delta >= count )
507 zip->cursor += delta;
514 error = ft_gzip_file_fill_output( zip );
542 ft_gzip_file_done( zip );
560 return ft_gzip_file_io( zip, pos, buffer, count );
565 ft_gzip_get_uncompressed_size(
FT_Stream stream )
572 old_pos = stream->
pos;
592 FT_GZipFile zip =
NULL;
599 error = ft_gzip_check_header( source );
604 stream->memory = memory;
608 error = ft_gzip_file_init( zip, stream, source );
615 stream->descriptor.pointer = zip;
627 FT_ULong zip_size = ft_gzip_get_uncompressed_size( source );
630 if ( zip_size != 0 && zip_size < 40 * 1024 )
635 if ( !
FT_ALLOC( zip_buff, zip_size ) )
640 count = ft_gzip_file_io( zip, 0, zip_buff, zip_size );
641 if ( count == zip_size )
643 ft_gzip_file_done( zip );
646 stream->descriptor.pointer =
NULL;
648 stream->size = zip_size;
650 stream->base = zip_buff;
652 stream->close = ft_gzip_stream_close;
657 ft_gzip_file_io( zip, 0,
NULL, 0 );
664 stream->size = 0x7FFFFFFFL;
667 stream->read = ft_gzip_stream_io;
668 stream->close = ft_gzip_stream_close;
683 return Gzip_Err_Unimplemented_Feature;
#define FT_ALLOC(ptr, size)
FT_Stream_Seek(FT_Stream stream, FT_ULong pos)
#define FT_READ_USHORT_LE(var)
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
int ZEXPORT inflateEnd(z_streamp strm)
#define FT_READ_BYTE(var)
void zcfree(voidpf opaque, voidpf ptr)
FT_BEGIN_HEADER FT_Stream_OpenGzip(FT_Stream stream, FT_Stream source)
EGLContext EGLenum EGLClientBuffer buffer
#define FT_STREAM_SKIP(distance)
FT_Stream_ReadULong(FT_Stream stream, FT_Error *error)
GLuint GLuint64EXT address
#define inflateInit2(strm, windowBits)
int ZEXPORT inflate(z_streamp strm, int flush)
int ZEXPORT inflateReset(z_streamp strm)
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
#define FT_STREAM_SEEK(position)
GLenum GLenum GLenum input
voidpf zcalloc(voidpf opaque, unsigned items, unsigned size)
#define FT_MEM_COPY(dest, source, count)
GLsizei GLsizei GLchar * source
#define FT_STREAM_READ(buffer, count)