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
61#ifndef USE_ZLIB_ZCALLOC
82#if defined( _MSC_VER )
87#pragma warning( push )
88#pragma warning( disable : 4244 )
93#define NO_INFLATE_MASK
110#if defined( _MSC_VER )
111#pragma warning( pop )
151#if !defined( FT_CONFIG_OPTION_SYSTEM_ZLIB ) && !defined( USE_ZLIB_ZCALLOC )
179#define FT_GZIP_BUFFER_SIZE 4096
181 typedef struct FT_GZipFileRec_
196 } FT_GZipFileRec, *FT_GZipFile;
200#define FT_GZIP_ASCII_FLAG 0x01
201#define FT_GZIP_HEAD_CRC 0x02
202#define FT_GZIP_EXTRA_FIELD 0x04
203#define FT_GZIP_ORIG_NAME 0x08
204#define FT_GZIP_COMMENT 0x10
205#define FT_GZIP_RESERVED 0xE0
222 if (
head[0] != 0x1F ||
225 (
head[3] & FT_GZIP_RESERVED) )
235 if (
head[3] & FT_GZIP_EXTRA_FIELD )
246 if (
head[3] & FT_GZIP_ORIG_NAME )
260 if (
head[3] & FT_GZIP_COMMENT )
274 if (
head[3] & FT_GZIP_HEAD_CRC )
284 ft_gzip_file_init( FT_GZipFile zip,
294 zip->memory =
stream->memory;
296 zip->limit = zip->buffer + FT_GZIP_BUFFER_SIZE;
297 zip->cursor = zip->limit;
317 zstream->
next_in = zip->buffer;
329 ft_gzip_file_done( FT_GZipFile zip )
352 ft_gzip_file_reset( FT_GZipFile zip )
370 zip->limit = zip->buffer + FT_GZIP_BUFFER_SIZE;
371 zip->cursor = zip->limit;
380 ft_gzip_file_fill_input( FT_GZipFile zip )
390 FT_GZIP_BUFFER_SIZE );
393 zip->limit = zip->cursor;
394 return FT_THROW( Invalid_Stream_Operation );
400 if (
size > FT_GZIP_BUFFER_SIZE )
401 size = FT_GZIP_BUFFER_SIZE;
405 zip->limit = zip->cursor;
406 return FT_THROW( Invalid_Stream_Operation );
421 ft_gzip_file_fill_output( FT_GZipFile zip )
427 zip->cursor = zip->buffer;
429 zstream->
avail_out = FT_GZIP_BUFFER_SIZE;
438 error = ft_gzip_file_fill_input( zip );
448 if ( zip->limit == zip->cursor )
454 zip->limit = zip->cursor;
466 ft_gzip_file_skip_output( FT_GZipFile zip,
475 delta = (
FT_ULong)( zip->limit - zip->cursor );
476 if ( delta >=
count )
479 zip->cursor += delta;
486 error = ft_gzip_file_fill_output( zip );
496 ft_gzip_file_io( FT_GZipFile zip,
507 if ( pos < zip->
pos )
509 error = ft_gzip_file_reset( zip );
515 if (
pos > zip->pos )
531 delta = (
FT_ULong)( zip->limit - zip->cursor );
532 if ( delta >=
count )
538 zip->cursor += delta;
545 error = ft_gzip_file_fill_output( zip );
566 FT_GZipFile zip = (FT_GZipFile)
stream->descriptor.pointer;
573 ft_gzip_file_done( zip );
589 unsigned long count )
591 FT_GZipFile zip = (FT_GZipFile)
stream->descriptor.pointer;
628 FT_GZipFile zip =
NULL;
659 stream->descriptor.pointer = zip;
674 if ( zip_size != 0 && zip_size < 40 * 1024 )
679 if ( !
FT_ALLOC( zip_buff, zip_size ) )
684 count = ft_gzip_file_io( zip, 0, zip_buff, zip_size );
685 if (
count == zip_size )
687 ft_gzip_file_done( zip );
696 stream->close = ft_gzip_stream_close;
701 ft_gzip_file_io( zip, 0,
NULL, 0 );
715 stream->read = ft_gzip_stream_io;
716 stream->close = ft_gzip_stream_close;
738 if ( !
memory || ! output_len || !output )
739 return FT_THROW( Invalid_Argument );
755 return FT_THROW( Invalid_Argument );
766 *output_len =
stream.total_out;
793 return FT_THROW( Unimplemented_Feature );
810 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)