Exemplo n.º 1
0
  /**
   * Creates a new packet header encoder, using the information from the 'infoSrc' object. The
   * information used is the number of components, number of tiles, subband decomposition, etc.
   *
   * <p>Note that this constructor visits all the tiles in the 'infoSrc' object. The 'infoSrc'
   * object is left at the original tile (i.e. the current tile before calling this constructor),
   * but any side effects of visiting the tiles is not reverted.
   *
   * @param infoSrc The source of information to construct the object.
   * @param encSpec The parameters for the encoding
   * @param maxNumPrec Maximum number of precinct in each tile, component and resolution level.
   * @param pl ParameterList instance that holds command line options
   */
  public PktEncoder(CodedCBlkDataSrcEnc infoSrc, J2KImageWriteParamJava wp, Point[][][] numPrec) {
    this.infoSrc = infoSrc;
    this.wp = wp;
    //        this.numPrec = numPrec;

    // Get number of components and tiles
    int nc = infoSrc.getNumComps();
    int nt = infoSrc.getNumTiles();

    // Do initial allocation
    ttIncl = new TagTreeEncoder[nt][nc][][][];
    ttMaxBP = new TagTreeEncoder[nt][nc][][][];
    lblock = new int[nt][nc][][][];
    prevtIdxs = new int[nt][nc][][][];
    ppinfo = new PrecInfo[nt][nc][][];

    // Finish allocation
    SubbandAn root, sb;
    int maxs, mins;
    int mrl;
    Point tmpCoord = null;
    int numcb; // Number of code-blocks
    Vector cblks = null;
    infoSrc.setTile(0, 0);
    for (int t = 0; t < nt; t++) { // Loop on tiles
      for (int c = 0; c < nc; c++) { // Loop on components
        // Get number of resolution levels
        root = infoSrc.getAnSubbandTree(t, c);
        mrl = root.resLvl;

        lblock[t][c] = new int[mrl + 1][][];
        ttIncl[t][c] = new TagTreeEncoder[mrl + 1][][];
        ttMaxBP[t][c] = new TagTreeEncoder[mrl + 1][][];
        prevtIdxs[t][c] = new int[mrl + 1][][];
        ppinfo[t][c] = new PrecInfo[mrl + 1][];

        for (int r = 0; r <= mrl; r++) { // Loop on resolution levels
          mins = (r == 0) ? 0 : 1;
          maxs = (r == 0) ? 1 : 4;

          int maxPrec = numPrec[t][c][r].x * numPrec[t][c][r].y;

          ttIncl[t][c][r] = new TagTreeEncoder[maxPrec][maxs];
          ttMaxBP[t][c][r] = new TagTreeEncoder[maxPrec][maxs];
          prevtIdxs[t][c][r] = new int[maxs][];
          lblock[t][c][r] = new int[maxs][];

          // Precincts and code-blocks
          ppinfo[t][c][r] = new PrecInfo[maxPrec];
          fillPrecInfo(t, c, r);

          for (int s = mins; s < maxs; s++) {
            // Loop on subbands
            sb = (SubbandAn) root.getSubbandByIdx(r, s);
            numcb = sb.numCb.x * sb.numCb.y;

            lblock[t][c][r][s] = new int[numcb];
            ArrayUtil.intArraySet(lblock[t][c][r][s], INIT_LBLOCK);

            prevtIdxs[t][c][r][s] = new int[numcb];
            ArrayUtil.intArraySet(prevtIdxs[t][c][r][s], -1);
          }
        }
      }
      if (t != nt - 1) infoSrc.nextTile();
    }
  }