~ubuntu-branches/ubuntu/vivid/jzlib/vivid

« back to all changes in this revision

Viewing changes to com/jcraft/jzlib/InfTree.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2008-08-24 22:45:34 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080824224534-w0t34odkdtrfevta
Tags: 1.0.7-1
* New upstream release
* New maintainer (Closes: #491858)
* Use CDBS (Ant with debian/build.xml) for building
* Ship examples in libjzlib-java
* debian/libjzlib-java.dirs: Removed because dirs are created by dh_install
* debian/copyright: Made clear statements about license and upstreams
  authors (remove crufted debian/copyright.in and lintian override)
* debian/watch: monitoring of upstream release on jcraft.com
* debian/rules: create a get-orig-source using uscan and debian/watch
* debian/control:
  * Use better synopsis and long description (Thanks to Ben Finney)
  * Add Homepage and Vcs-* fields
  * Bumping debhelper compat level from 4 to 5 (see debian/compat)
  * Build-Depends on GCJ instead of Kaffe 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*-mode:java; c-basic-offset:2; -*- */
 
1
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2
2
/*
3
3
Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
4
4
 
219
219
  // If BMAX needs to be larger than 16, then h and x[] should be uLong.
220
220
  static final int BMAX=15;         // maximum bit length of any code
221
221
 
222
 
  static int huft_build(int[] b, // code lengths in bits (all assumed <= BMAX)
223
 
                        int bindex, 
224
 
                        int n,   // number of codes (assumed <= 288)
225
 
                        int s,   // number of simple-valued codes (0..s-1)
226
 
                        int[] d, // list of base values for non-simple codes
227
 
                        int[] e, // list of extra bits for non-simple codes
228
 
                        int[] t, // result: starting table
229
 
                        int[] m, // maximum lookup bits, returns actual
230
 
                        int[] hp,// space for trees
231
 
                        int[] hn,// hufts used in space
232
 
                        int[] v  // working area: values in order of bit length
233
 
                        ){
 
222
  int[] hn = null;  // hufts used in space
 
223
  int[] v = null;   // work area for huft_build 
 
224
  int[] c = null;   // bit length count table
 
225
  int[] r = null;   // table entry for structure assignment
 
226
  int[] u = null;   // table stack
 
227
  int[] x = null;   // bit offsets, then code stack
 
228
 
 
229
  private int huft_build(int[] b, // code lengths in bits (all assumed <= BMAX)
 
230
                         int bindex, 
 
231
                         int n,   // number of codes (assumed <= 288)
 
232
                         int s,   // number of simple-valued codes (0..s-1)
 
233
                         int[] d, // list of base values for non-simple codes
 
234
                         int[] e, // list of extra bits for non-simple codes
 
235
                         int[] t, // result: starting table
 
236
                         int[] m, // maximum lookup bits, returns actual
 
237
                         int[] hp,// space for trees
 
238
                         int[] hn,// hufts used in space
 
239
                         int[] v  // working area: values in order of bit length
 
240
                         ){
234
241
    // Given a list of code lengths and a maximum table size, make a set of
235
242
    // tables to decode that set of codes.  Return Z_OK on success, Z_BUF_ERROR
236
243
    // if the given code set is incomplete (the tables are still built in this
238
245
    // lengths), or Z_MEM_ERROR if not enough memory.
239
246
 
240
247
    int a;                       // counter for codes of length k
241
 
    int[] c=new int[BMAX+1];     // bit length count table
242
248
    int f;                       // i repeats in table every f entries
243
249
    int g;                       // maximum code length
244
250
    int h;                       // table level
249
255
    int mask;                    // (1 << w) - 1, to avoid cc -O bug on HP
250
256
    int p;                       // pointer into c[], b[], or v[]
251
257
    int q;                       // points to current table
252
 
    int[] r=new int[3];          // table entry for structure assignment
253
 
    int[] u=new int[BMAX];       // table stack
254
258
    int w;                       // bits before this table == (l * h)
255
 
    int[] x=new int[BMAX+1];     // bit offsets, then code stack
256
259
    int xp;                      // pointer into x
257
260
    int y;                       // number of dummy codes added
258
261
    int z;                       // number of entries in current table
354
357
          z = 1 << j;                 // table entries for j-bit table
355
358
 
356
359
          // allocate new table
357
 
          if (hn[0] + z > MANY)       // (note: doesn't matter for fixed)
 
360
          if (hn[0] + z > MANY){       // (note: doesn't matter for fixed)
358
361
            return Z_DATA_ERROR;       // overflow of MANY
 
362
          }
359
363
          u[h] = q = /*hp+*/ hn[0];   // DEBUG
360
364
          hn[0] += z;
361
365
 
412
416
    return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
413
417
  }
414
418
 
415
 
  static int inflate_trees_bits(int[] c,  // 19 code lengths
416
 
                                int[] bb, // bits tree desired/actual depth
417
 
                                int[] tb, // bits tree result
418
 
                                int[] hp, // space for trees
419
 
                                ZStream z // for messages
420
 
                                ){
421
 
    int r;
422
 
    int[] hn = new int[1];          // hufts used in space
423
 
    int[] v=new int[19];            // work area for huft_build 
424
 
 
425
 
    r = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);
426
 
 
427
 
    if (r == Z_DATA_ERROR){
 
419
  int inflate_trees_bits(int[] c,  // 19 code lengths
 
420
                         int[] bb, // bits tree desired/actual depth
 
421
                         int[] tb, // bits tree result
 
422
                         int[] hp, // space for trees
 
423
                         ZStream z // for messages
 
424
                         ){
 
425
    int result;
 
426
    initWorkArea(19);
 
427
    hn[0]=0;
 
428
    result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);
 
429
 
 
430
    if(result == Z_DATA_ERROR){
428
431
      z.msg = "oversubscribed dynamic bit lengths tree";
429
432
    }
430
 
    else if (r == Z_BUF_ERROR || bb[0] == 0){
 
433
    else if(result == Z_BUF_ERROR || bb[0] == 0){
431
434
      z.msg = "incomplete dynamic bit lengths tree";
432
 
      r = Z_DATA_ERROR;
 
435
      result = Z_DATA_ERROR;
433
436
    }
434
 
    return r;
 
437
    return result;
435
438
  }
436
439
 
437
 
  static int inflate_trees_dynamic(int nl,   // number of literal/length codes
 
440
  int inflate_trees_dynamic(int nl,   // number of literal/length codes
438
441
                            int nd,   // number of distance codes
439
442
                            int[] c,  // that many (total) code lengths
440
 
                            int[] bl, // literal desired/actual bit depth
441
 
                            int[] bd, // distance desired/actual bit depth 
442
 
                            int[] tl, // literal/length tree result
443
 
                            int[] td, // distance tree result
444
 
                            int[] hp, // space for trees
445
 
                            ZStream z // for messages
446
 
                            ){
447
 
    int r;
448
 
    int[] hn = new int[1];           // hufts used in space
449
 
    int[] v=new int[288];            // work area for huft_build
 
443
                            int[] bl, // literal desired/actual bit depth
 
444
                            int[] bd, // distance desired/actual bit depth 
 
445
                            int[] tl, // literal/length tree result
 
446
                            int[] td, // distance tree result
 
447
                            int[] hp, // space for trees
 
448
                            ZStream z // for messages
 
449
                            ){
 
450
    int result;
450
451
 
451
452
    // build literal/length tree
452
 
    r = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v);
453
 
    if (r != Z_OK || bl[0] == 0){
454
 
      if(r == Z_DATA_ERROR){
 
453
    initWorkArea(288);
 
454
    hn[0]=0;
 
455
    result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v);
 
456
    if (result != Z_OK || bl[0] == 0){
 
457
      if(result == Z_DATA_ERROR){
455
458
        z.msg = "oversubscribed literal/length tree";
456
459
      }
457
 
      else if (r != Z_MEM_ERROR){
 
460
      else if (result != Z_MEM_ERROR){
458
461
        z.msg = "incomplete literal/length tree";
459
 
        r = Z_DATA_ERROR;
 
462
        result = Z_DATA_ERROR;
460
463
      }
461
 
      return r;
 
464
      return result;
462
465
    }
463
466
 
464
467
    // build distance tree
465
 
    r = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v);
 
468
    initWorkArea(288);
 
469
    result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v);
466
470
 
467
 
    if (r != Z_OK || (bd[0] == 0 && nl > 257)){
468
 
      if (r == Z_DATA_ERROR){
 
471
    if (result != Z_OK || (bd[0] == 0 && nl > 257)){
 
472
      if (result == Z_DATA_ERROR){
469
473
        z.msg = "oversubscribed distance tree";
470
474
      }
471
 
      else if (r == Z_BUF_ERROR) {
 
475
      else if (result == Z_BUF_ERROR) {
472
476
        z.msg = "incomplete distance tree";
473
 
        r = Z_DATA_ERROR;
 
477
        result = Z_DATA_ERROR;
474
478
      }
475
 
      else if (r != Z_MEM_ERROR){
 
479
      else if (result != Z_MEM_ERROR){
476
480
        z.msg = "empty distance tree with lengths";
477
 
        r = Z_DATA_ERROR;
 
481
        result = Z_DATA_ERROR;
478
482
      }
479
 
      return r;
 
483
      return result;
480
484
    }
481
485
 
482
486
    return Z_OK;
488
492
                                 int[][] td,//distance tree result 
489
493
                                 ZStream z  //for memory allocation
490
494
                                 ){
491
 
    bl[0] = fixed_bl;
492
 
    bd[0] = fixed_bd;
493
 
    tl[0] = fixed_tl;
494
 
    td[0] = fixed_td;
 
495
    bl[0]=fixed_bl;
 
496
    bd[0]=fixed_bd;
 
497
    tl[0]=fixed_tl;
 
498
    td[0]=fixed_td;
495
499
    return Z_OK;
496
500
  }
 
501
 
 
502
  private void initWorkArea(int vsize){
 
503
    if(hn==null){
 
504
      hn=new int[1];
 
505
      v=new int[vsize];
 
506
      c=new int[BMAX+1];
 
507
      r=new int[3];
 
508
      u=new int[BMAX];
 
509
      x=new int[BMAX+1];
 
510
    }
 
511
    if(v.length<vsize){ v=new int[vsize]; }
 
512
    for(int i=0; i<vsize; i++){v[i]=0;}
 
513
    for(int i=0; i<BMAX+1; i++){c[i]=0;}
 
514
    for(int i=0; i<3; i++){r[i]=0;}
 
515
//  for(int i=0; i<BMAX; i++){u[i]=0;}
 
516
    System.arraycopy(c, 0, u, 0, BMAX);
 
517
//  for(int i=0; i<BMAX+1; i++){x[i]=0;}
 
518
    System.arraycopy(c, 0, x, 0, BMAX+1);
 
519
  }
497
520
}