misc/libfreetype/src/gzip/infutil.c
author sheepluva
Fri, 21 Oct 2011 19:17:08 +0200
changeset 6171 8627698134b6
parent 5172 88f2e05288ba
permissions -rw-r--r--
fix layout of net page
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/* inflate_util.c -- data and routines common to blocks and codes
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
 * Copyright (C) 1995-2002 Mark Adler
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
 * For conditions of distribution and use, see copyright notice in zlib.h
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
#include "zutil.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
#include "infblock.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
#include "inftrees.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
#include "infcodes.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
#include "infutil.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/* And'ing with mask[n] masks the lower n bits */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
local const uInt inflate_mask[17] = {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
    0x0000,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
    0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
    0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
};
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
/* copy as much as possible from the sliding window to the output area */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
local int inflate_flush( /* s, z, r) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
inflate_blocks_statef *s,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
z_streamp z,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
int r )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
{
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
  uInt n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
  Bytef *p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
  Bytef *q;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  /* local copies of source and destination pointers */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  p = z->next_out;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
  q = s->read;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
  /* compute number of bytes to copy as far as end of window */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
  n = (uInt)((q <= s->write ? s->write : s->end) - q);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
  if (n > z->avail_out) n = z->avail_out;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
  if (n && r == Z_BUF_ERROR) r = Z_OK;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
  /* update counters */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  z->avail_out -= n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
  z->total_out += n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  /* update check information */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
  if (s->checkfn != Z_NULL)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
    z->adler = s->check = (*s->checkfn)(s->check, q, n);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
  /* copy as far as end of window */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  zmemcpy(p, q, n);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
  p += n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
  q += n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
  /* see if more to copy at beginning of window */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
  if (q == s->end)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
    /* wrap pointers */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
    q = s->window;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
    if (s->write == s->end)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
      s->write = s->window;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
    /* compute bytes to copy */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
    n = (uInt)(s->write - q);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
    if (n > z->avail_out) n = z->avail_out;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
    if (n && r == Z_BUF_ERROR) r = Z_OK;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
    /* update counters */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
    z->avail_out -= n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
    z->total_out += n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
    /* update check information */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
    if (s->checkfn != Z_NULL)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
      z->adler = s->check = (*s->checkfn)(s->check, q, n);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
    /* copy */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
    zmemcpy(p, q, n);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
    p += n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
    q += n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
  /* update pointers */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
  z->next_out = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
  s->read = q;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
  /* done */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
  return r;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
}