CSJ2K.j2k.codestream.reader.BitstreamReaderAgent.initSubbandsFields C# (CSharp) Метод

initSubbandsFields() защищенный Метод

Initialises subbands fields, such as number of code-blocks, code-blocks dimension and number of magnitude bits, in the subband tree. The nominal code-block width/height depends on the precincts dimensions if used. The way the number of magnitude bits is computed depends on the quantization type (reversible, derived, expounded).
protected initSubbandsFields ( int c, CSJ2K.j2k.wavelet.synthesis.SubbandSyn sb ) : void
c int The component index /// ///
sb CSJ2K.j2k.wavelet.synthesis.SubbandSyn The subband tree to be initialised. /// ///
Результат void
        protected internal virtual void initSubbandsFields(int c, SubbandSyn sb)
        {
            int t = TileIdx;
            int rl = sb.resLvl;
            int cbw, cbh;

            cbw = decSpec.cblks.getCBlkWidth(ModuleSpec.SPEC_TILE_COMP, t, c);
            cbh = decSpec.cblks.getCBlkHeight(ModuleSpec.SPEC_TILE_COMP, t, c);

            if (!sb.isNode)
            {
                // Code-block dimensions
                if (hd.precinctPartitionUsed())
                {
                    // The precinct partition is used
                    int ppxExp, ppyExp, cbwExp, cbhExp;

                    // Get exponents
                    ppxExp = MathUtil.log2(getPPX(t, c, rl));
                    ppyExp = MathUtil.log2(getPPY(t, c, rl));
                    cbwExp = MathUtil.log2(cbw);
                    cbhExp = MathUtil.log2(cbh);

                    switch (sb.resLvl)
                    {

                        case 0:
                            sb.nomCBlkW = (cbwExp < ppxExp?(1 << cbwExp):(1 << ppxExp));
                            sb.nomCBlkH = (cbhExp < ppyExp?(1 << cbhExp):(1 << ppyExp));
                            break;

                        default:
                            sb.nomCBlkW = (cbwExp < ppxExp - 1?(1 << cbwExp):(1 << (ppxExp - 1)));
                            sb.nomCBlkH = (cbhExp < ppyExp - 1?(1 << cbhExp):(1 << (ppyExp - 1)));
                            break;

                    }
                }
                else
                {
                    sb.nomCBlkW = cbw;
                    sb.nomCBlkH = cbh;
                }

                // Number of code-blocks
                if (sb.numCb == null)
                    sb.numCb = new Coord();
                if (sb.w == 0 || sb.h == 0)
                {
                    sb.numCb.x = 0;
                    sb.numCb.y = 0;
                }
                else
                {
                    int cb0x = CbULX;
                    int cb0y = CbULY;
                    int tmp;

                    // Projects code-block partition origin to subband. Since the
                    // origin is always 0 or 1, it projects to the low-pass side
                    // (throught the ceil operator) as itself (i.e. no change) and
                    // to the high-pass side (through the floor operator) as 0,
                    // always.
                    int acb0x = cb0x;
                    int acb0y = cb0y;

                    switch (sb.sbandIdx)
                    {

                        case Subband.WT_ORIENT_LL:
                            // No need to project since all low-pass => nothing to do
                            break;

                        case Subband.WT_ORIENT_HL:
                            acb0x = 0;
                            break;

                        case Subband.WT_ORIENT_LH:
                            acb0y = 0;
                            break;

                        case Subband.WT_ORIENT_HH:
                            acb0x = 0;
                            acb0y = 0;
                            break;

                        default:
                            throw new System.InvalidOperationException("Internal JJ2000 error");

                    }
                    if (sb.ulcx - acb0x < 0 || sb.ulcy - acb0y < 0)
                    {
                        throw new System.ArgumentException("Invalid code-blocks " + "partition origin or " + "image offset in the " + "reference grid.");
                    }

                    // NOTE: when calculating "floor()" by integer division the
                    // dividend and divisor must be positive, we ensure that by
                    // adding the divisor to the dividend and then substracting 1
                    // to the result of the division

                    tmp = sb.ulcx - acb0x + sb.nomCBlkW;
                    sb.numCb.x = (tmp + sb.w - 1) / sb.nomCBlkW - (tmp / sb.nomCBlkW - 1);

                    tmp = sb.ulcy - acb0y + sb.nomCBlkH;
                    sb.numCb.y = (tmp + sb.h - 1) / sb.nomCBlkH - (tmp / sb.nomCBlkH - 1);
                }

                // Number of magnitude bits
                if (derived[c])
                {
                    sb.magbits = gb[c] + (params_Renamed[c].exp[0][0] - (mdl[c] - sb.level)) - 1;
                }
                else
                {
                    sb.magbits = gb[c] + params_Renamed[c].exp[sb.resLvl][sb.sbandIdx] - 1;
                }
            }
            else
            {
                initSubbandsFields(c, (SubbandSyn) sb.LL);
                initSubbandsFields(c, (SubbandSyn) sb.HL);
                initSubbandsFields(c, (SubbandSyn) sb.LH);
                initSubbandsFields(c, (SubbandSyn) sb.HH);
            }
        }