⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ezzlib.pas

📁 很管用的GIS控件
💻 PAS
📖 第 1 页 / 共 5 页
字号:
unit EzZLib;

{$IFNDEF Win32}
!! This unit requires 32 - bit Windows !!
{$ENDIF}

{ Define the following (THREAD_SAFE) to ensure that this code is
  completely thread safe. If it is undefined, then, in extremely rare
  circumstances (failure to dynamically allocate some small arrays), the
  routines may not be thread safe. }

{$DEFINE THREAD_SAFE}

{ Delphi 2 and 3 define the cardinal type as a 31-bit integer that
  is stored in 32-bits. This can result in range check errors
  during compilation. To avoid this, in D2 and D3 we'll define
  cardinal as a longint. In D4 and higher, cardinal uses all
  32-bits so special measures are not required. }

{$IFDEF VER90}   { Delphi 2 }
  {$DEFINE Delphi2or3}
{$ENDIF}

{$IFDEF VER100}  { Delphi 3 }
  {$DEFINE Delphi2or3}
{$ENDIF}

interface

const
  Version = '1.1';

{$IFDEF Delphi2or3}
type
  cardinal = longint;
{$ENDIF}

{-----------------------------------------------------------------------------}
{-----------------------------------------------------------------------------}
{-----------------------------------------------------------------------------}

{ zutil.pas
  Copyright (C) 1998 by Jacques Nomssi Nzali
}

type
  Bytef = byte;
  charf = byte;

  int = integer;
  intf = int;
  uInt = cardinal;
  uIntf = uInt;

  Long = longint;
  uLong = cardinal; { changed so that Delphi2+ all use cardinal--8/11/00 by DOM }
  uLongf = uLong;

  voidp = pointer;
  voidpf = voidp;
  pBytef = ^Bytef;
  pIntf = ^intf;
  puIntf = ^uIntf;
  puLong = ^uLongf;

  ptr2int = uInt;   { a pointer to integer casting is used to do pointer arithmetic }

const
  MaxMemBlock = MaxInt;

type
  zByteArray = array[0..(MaxMemBlock div SizeOf(Bytef)) - 1] of Bytef;
  pzByteArray = ^zByteArray;
  zIntfArray = array[0..(MaxMemBlock div SizeOf(Intf)) - 1] of Intf;
  pzIntfArray = ^zIntfArray;
  zuIntArray = array[0..(MaxMemBlock div SizeOf(uInt)) - 1] of uInt;
  PuIntArray = ^zuIntArray;
  uch = byte;
  uchf = uch;
  ush = word;
  ushf = ush;
  ulg = Longint;//cardinal;   { changed from LongInt--8/11/00 by DOM }
  unsigned = uInt;
  pcharf = ^charf;
  puchf = ^uchf;
  pushf = ^ushf;
  zuchfArray = zByteArray;
  puchfArray = ^zuchfArray;
  zushfArray = array[0..(MaxMemBlock div SizeOf(ushf)) - 1] of ushf;
  pushfArray = ^zushfArray;

{-----------------------------------------------------------------------------}
{-----------------------------------------------------------------------------}
{-----------------------------------------------------------------------------}

{ zlib.h -- interface of the 'zlib' general purpose compression library
  Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler

  zlib.pas -- pascal translation
  Copyright (C) 1998 by Jacques Nomssi Nzali
}

const
  MAX_MEM_LEVEL = 9;
  DEF_MEM_LEVEL = 8;
  MAX_WBITS = 15;
  DEF_WBITS = MAX_WBITS;

type
  pInflate_huft = ^inflate_huft;
  inflate_huft = record
    Exop,
    Bits: Byte;
    base: uInt;
  end;
  huft_field = array[0..(MaxMemBlock div SizeOf(inflate_huft)) - 1] of inflate_huft;
  huft_ptr = ^huft_field;
  ppInflate_huft = ^pInflate_huft;
  inflate_codes_mode = (
    START,
    LEN,
    LENEXT,
    DIST,
    DISTEXT,
    COPY,
    LIT,
    WASH,
    ZEND,
    BADCODE);
  pInflate_codes_state = ^inflate_codes_state;
  inflate_codes_state = record
    mode: inflate_codes_mode;
    len: uInt;
    sub: record
      case Byte of
        0: (code: record
            tree: pInflate_huft;
            need: uInt;
          end);
        1: (lit: uInt);
        2: (copy: record
            get: uInt;
            dist: uInt;
          end);
    end;
    lbits: Byte;
    dbits: Byte;
    ltree: pInflate_huft;
    dtree: pInflate_huft;
  end;
  check_func = function(check: uLong;
    buf: pBytef;
    len: uInt): uLong;
  inflate_block_mode =
    (ZTYPE,
    LENS,
    STORED,
    TABLE,
    BTREE,
    DTREE,
    CODES,
    DRY,
    BLKDONE,
    BLKBAD);
  pInflate_blocks_state = ^inflate_blocks_state;
  inflate_blocks_state = record
    mode: inflate_block_mode;
    sub: record
      case Byte of
        0: (left: uInt);
        1: (trees: record
            table: uInt;
            index: uInt;
            blens: PuIntArray;
            bb: uInt;
            tb: pInflate_huft;
          end);
        2: (decode: record
            tl: pInflate_huft;
            td: pInflate_huft;
            codes: pInflate_codes_state;
          end);
    end;
    last: boolean;
    bitk: uInt;
    bitb: uLong;
    hufts: huft_ptr;
    window: pBytef;
    zend: pBytef;
    read: pBytef;
    write: pBytef;
    checkfn: check_func;
    check: uLong;
  end;
  inflate_mode = (
    METHOD,
    FLAG,
    DICT4,
    DICT3,
    DICT2,
    DICT1,
    DICT0,
    BLOCKS,
    CHECK4,
    CHECK3,
    CHECK2,
    CHECK1,
    DONE,
    BAD);
  pInternal_state = ^internal_state;
  internal_state = record
    mode: inflate_mode;
    sub: record
      case byte of
        0: (method: uInt);
        1: (check: record
            was: uLong;
            need: uLong;
          end);
        2: (marker: uInt);
    end;
    nowrap: boolean;
    wbits: uInt;
    blocks: pInflate_blocks_state;
  end;
  alloc_func = function(opaque: voidpf; items: uInt; size: uInt): voidpf;
  free_func = procedure(opaque: voidpf; address: voidpf);
  z_streamp = ^z_stream;
  z_stream = record
    next_in: pBytef;
    avail_in: uInt;
    total_in: uLong;
    next_out: pBytef;
    avail_out: uInt;
    total_out: uLong;
    msg: string[255];
    state: pInternal_state;
    zalloc: alloc_func;
    zfree: free_func;
    opaque: voidpf;
    data_type: int;
    adler: uLong;
    reserved: uLong;
  end;

const
  Z_NO_FLUSH = 0;
  Z_PARTIAL_FLUSH = 1;
  Z_SYNC_FLUSH = 2;
  Z_FULL_FLUSH = 3;
  Z_FINISH = 4;

  Z_OK = 0;
  Z_STREAM_END = 1;
  Z_NEED_DICT = 2;
  Z_ERRNO = (-1);
  Z_STREAM_ERROR = (-2);
  Z_DATA_ERROR = (-3);
  Z_MEM_ERROR = (-4);
  Z_BUF_ERROR = (-5);
  Z_VERSION_ERROR = (-6);

  Z_NO_COMPRESSION = 0;
  Z_BEST_SPEED = 1;
  Z_BEST_COMPRESSION = 9;
  Z_DEFAULT_COMPRESSION = (-1);

  Z_FILTERED = 1;
  Z_HUFFMAN_ONLY = 2;
  Z_DEFAULT_STRATEGY = 0;

  Z_BINARY = 0;
  Z_ASCII = 1;
  Z_UNKNOWN = 2;

  Z_DEFLATED = 8;

  Z_NULL = nil;

  STORED_BLOCK = 0;
  STATIC_TREES = 1;
  DYN_TREES = 2;

  MIN_MATCH = 3;
  MAX_MATCH = 258;

  PRESET_DICT = $20;

function zlibVersion: string;
function zError(err: int): string;
function ZALLOC(var strm: z_stream; items: uInt; size: uInt): voidpf;
procedure ZFREE(var strm: z_stream; ptr: voidpf);
procedure TRY_FREE(var strm: z_stream; ptr: voidpf);

const
  ZLIB_VERSION: string[10] = '1.1.2';

const
  z_errbase = Z_NEED_DICT;
  z_errmsg: array[0..9] of string[21] =
   ('need dictionary',      { Z_NEED_DICT       2  }
    'stream end',           { Z_STREAM_END      1  }
    '',                     { Z_OK              0  }
    'file error',           { Z_ERRNO         (-1) }
    'stream error',         { Z_STREAM_ERROR  (-2) }
    'data error',           { Z_DATA_ERROR    (-3) }
    'insufficient memory',  { Z_MEM_ERROR     (-4) }
    'buffer error',         { Z_BUF_ERROR     (-5) }
    'incompatible version', { Z_VERSION_ERROR (-6) }
    '');

{-----------------------------------------------------------------------------}
{-----------------------------------------------------------------------------}
{-----------------------------------------------------------------------------}

{ deflate.h -- internal compression state
  deflate.c -- compress data using the deflation algorithm
  Copyright (C) 1995-1996 Jean-loup Gailly.

  zdeflate.pas -- pascal translation
  Copyright (C) 1998 by Jacques Nomssi Nzali
}

function deflateInit_(strm: z_streamp;
  level: int; const version: string; stream_size: int): int;
function deflateInit(var strm: z_stream; level: int): int;
function deflate(var strm: z_stream; flush: int): int;
function deflateEnd(var strm: z_stream): int;
function deflateInit2(var strm: z_stream;
  level: int; method: int; windowBits: int;
  memLevel: int; strategy: int): int;
function deflateSetDictionary(var strm: z_stream;
  dictionary: pBytef; dictLength: uint): int;
function deflateCopy(dest: z_streamp; source: z_streamp): int;
function deflateReset(var strm: z_stream): int;
function deflateParams(var strm: z_stream; level: int; strategy: int): int;

const
  deflate_copyright: string = ' deflate 1.1.2 Copyright 1995-1998 Jean-loup Gailly ';

{ If you use the zlib library in a product, an acknowledgment is welcome
  in the documentation of your product. If for some reason you cannot
  include such an acknowledgment, I would appreciate that you keep this
  copyright string in the executable of your product. }

{-----------------------------------------------------------------------------}
{-----------------------------------------------------------------------------}
{-----------------------------------------------------------------------------}

{ inflate.c -- zlib interface to inflate modules
  Copyright (C) 1995-1998 Mark Adler

  zinflate.pas -- pascal translation
  Copyright (C) 1998 by Jacques Nomssi Nzali
}

function inflateInit(var z: z_stream): int;
function inflateInit_(z: z_streamp;
  const version: string; stream_size: int): int;
function inflateInit2_(var z: z_stream;
  w: int; const version: string; stream_size: int): int;
function inflateInit2(var z: z_stream; windowBits: int): int;
function inflateEnd(var z: z_stream): int;
function inflateReset(var z: z_stream): int;
function inflate(var z: z_stream; f: int): int;
function inflateSetDictionary(var z: z_stream; dictionary: pBytef;
  dictLength: uInt): int;
function inflateSync(var z: z_stream): int;
function inflateSyncPoint(var z: z_stream): int;

const
  inflate_copyright = 'inflate 1.1.2 Copyright 1995-1998 Mark Adler';

{ If you use the zlib library in a product, an acknowledgment is welcome
  in the documentation of your product. If for some reason you cannot
  include such an acknowledgment, I would appreciate that you keep this
  copyright string in the executable of your product. }

implementation

{-----------------------------------------------------------------------------}
{-----------------------------------------------------------------------------}
{-----------------------------------------------------------------------------}

{ zutil.pas
  Copyright (C) 1998 by Jacques Nomssi Nzali
}

procedure zmemcpy(destp: pBytef; sourcep: pBytef; len: uInt);
begin
  Move(sourcep^, destp^, len);
end;

function zmemcmp(s1p, s2p: pBytef; len: uInt): int;
var
  j: uInt;
  source, dest: pBytef;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -