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_SYSTEM_ZLIB
57#ifndef USE_ZLIB_ZCALLOC
78#if defined( _MSC_VER )
83#pragma warning( push )
84#pragma warning( disable : 4244 )
89#define NO_INFLATE_MASK
106#if defined( _MSC_VER )
107#pragma warning( pop )
147#if !defined( FT_CONFIG_OPTION_SYSTEM_ZLIB ) && !defined( USE_ZLIB_ZCALLOC )
175#define FT_GZIP_BUFFER_SIZE 4096
177 typedef struct FT_GZipFileRec_
192 } FT_GZipFileRec, *FT_GZipFile;
196#define FT_GZIP_ASCII_FLAG 0x01
197#define FT_GZIP_HEAD_CRC 0x02
198#define FT_GZIP_EXTRA_FIELD 0x04
199#define FT_GZIP_ORIG_NAME 0x08
200#define FT_GZIP_COMMENT 0x10
201#define FT_GZIP_RESERVED 0xE0
218 if (
head[0] != 0x1F ||
221 (
head[3] & FT_GZIP_RESERVED) )
231 if (
head[3] & FT_GZIP_EXTRA_FIELD )
242 if (
head[3] & FT_GZIP_ORIG_NAME )
256 if (
head[3] & FT_GZIP_COMMENT )
270 if (
head[3] & FT_GZIP_HEAD_CRC )
280 ft_gzip_file_init( FT_GZipFile zip,
290 zip->memory =
stream->memory;
292 zip->limit = zip->buffer + FT_GZIP_BUFFER_SIZE;
293 zip->cursor = zip->limit;
313 zstream->
next_in = zip->buffer;
325 ft_gzip_file_done( FT_GZipFile zip )
348 ft_gzip_file_reset( FT_GZipFile zip )
366 zip->limit = zip->buffer + FT_GZIP_BUFFER_SIZE;
367 zip->cursor = zip->limit;
376 ft_gzip_file_fill_input( FT_GZipFile zip )
386 FT_GZIP_BUFFER_SIZE );
389 zip->limit = zip->cursor;
390 return FT_THROW( Invalid_Stream_Operation );
396 if (
size > FT_GZIP_BUFFER_SIZE )
397 size = FT_GZIP_BUFFER_SIZE;
401 zip->limit = zip->cursor;
402 return FT_THROW( Invalid_Stream_Operation );
417 ft_gzip_file_fill_output( FT_GZipFile zip )
423 zip->cursor = zip->buffer;
425 zstream->
avail_out = FT_GZIP_BUFFER_SIZE;
434 error = ft_gzip_file_fill_input( zip );
444 if ( zip->limit == zip->cursor )
450 zip->limit = zip->cursor;
462 ft_gzip_file_skip_output( FT_GZipFile zip,
471 delta = (
FT_ULong)( zip->limit - zip->cursor );
472 if ( delta >=
count )
475 zip->cursor += delta;
482 error = ft_gzip_file_fill_output( zip );
492 ft_gzip_file_io( FT_GZipFile zip,
503 if ( pos < zip->
pos )
505 error = ft_gzip_file_reset( zip );
511 if (
pos > zip->pos )
527 delta = (
FT_ULong)( zip->limit - zip->cursor );
528 if ( delta >=
count )
534 zip->cursor += delta;
541 error = ft_gzip_file_fill_output( zip );
562 FT_GZipFile zip = (FT_GZipFile)
stream->descriptor.pointer;
569 ft_gzip_file_done( zip );
585 unsigned long count )
587 FT_GZipFile zip = (FT_GZipFile)
stream->descriptor.pointer;
624 FT_GZipFile zip =
NULL;
655 stream->descriptor.pointer = zip;
670 if ( zip_size != 0 && zip_size < 40 * 1024 )
675 if ( !
FT_ALLOC( zip_buff, zip_size ) )
680 count = ft_gzip_file_io( zip, 0, zip_buff, zip_size );
681 if (
count == zip_size )
683 ft_gzip_file_done( zip );
692 stream->close = ft_gzip_stream_close;
697 ft_gzip_file_io( zip, 0,
NULL, 0 );
711 stream->read = ft_gzip_stream_io;
712 stream->close = ft_gzip_stream_close;
734 if ( !
memory || !output_len || !output )
735 return FT_THROW( Invalid_Argument );
751 return FT_THROW( Invalid_Argument );
762 *output_len =
stream.total_out;
789 return FT_THROW( Unimplemented_Feature );
806 return FT_THROW( Unimplemented_Feature );
struct outqueuenode * head
static int inflateReset(z_streamp strm)
int inflate(z_streamp strm, int flush)
int inflateEnd(z_streamp strm)
void(* free_func)(voidpf opaque, voidpf address)
voidpf(* alloc_func)(voidpf opaque, uInt items, uInt size)
void zcfree(voidpf opaque, voidpf ptr)
voidpf zcalloc(voidpf opaque, unsigned items, unsigned size)
FT_Stream_OpenGzip(FT_Stream stream, FT_Stream source)
FT_Gzip_Uncompress(FT_Memory memory, FT_Byte *output, FT_ULong *output_len, const FT_Byte *input, FT_ULong input_len)
#define FT_ALLOC(ptr, size)
#define FT_MEM_COPY(dest, source, count)
#define FT_STREAM_SEEK(position)
FT_Stream_ReadULongLE(FT_Stream stream, FT_Error *error)
#define FT_READ_BYTE(var)
#define FT_STREAM_SKIP(distance)
#define FT_READ_USHORT_LE(var)
#define FT_STREAM_READ(buffer, count)
FT_Stream_Seek(FT_Stream stream, FT_ULong pos)
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
GLuint GLuint GLsizei count
GLenum GLenum GLenum input
static char memory[1024 *256]
#define inflateInit2(strm, windowBits)