Пример #1
0
        override internal int inverse2(Block vb, Object i, Object memo, float[] Out)
        {
            LookFloor1 look = (LookFloor1)i;
            InfoFloor1 info = look.vi;
            int        n    = vb.vd.vi.blocksizes[vb.mode] / 2;

            if (memo != null)
            {
                /* render the lines */
                int[] fit_value = (int[])memo;
                int   hx        = 0;
                int   lx        = 0;
                int   ly        = fit_value[0] * info.mult;
                for (int j = 1; j < look.posts; j++)
                {
                    int current = look.forward_index[j];
                    int hy      = fit_value[current] & 0x7fff;
                    if (hy == fit_value[current])
                    {
                        hy *= info.mult;
                        hx  = info.postlist[current];

                        RenderLine(lx, hx, ly, hy, Out);

                        lx = hx;
                        ly = hy;
                    }
                }
                for (int j = hx; j < n; j++)
                {
                    Out[j] *= Out[j - 1];                     /* be certain */
                }
                return(1);
            }
            for (int j = 0; j < n; j++)
            {
                Out[j] = 0.0f;
            }
            return(0);
        }
Пример #2
0
        override internal Object look(DspState vd, InfoMode mi, Object i)
        {
            int _n = 0;

            int[] sortpointer = new int[VIF_POSIT + 2];

            //    Info vi=vd.vi;

            InfoFloor1 info = (InfoFloor1)i;
            LookFloor1 look = new LookFloor1();

            look.vi = info;
            look.n  = info.postlist[1];

            /* we drop each position value in-between already decoded values,
             * and use linear interpolation to predict each new value past the
             * edges.  The positions are read in the order of the position
             * list... we precompute the bounding positions in the lookup.  Of
             * course, the neighbors can change (if a position is declined), but
             * this is an initial mapping */

            for (int j = 0; j < info.Partitions; j++)
            {
                _n += info.class_dim[info.Partitionclass[j]];
            }
            _n        += 2;
            look.posts = _n;

            /* also store a sorted position index */
            for (int j = 0; j < _n; j++)
            {
                sortpointer[j] = j;
            }
            //    qsort(sortpointer,n,sizeof(int),icomp); // !!

            int foo;

            for (int j = 0; j < _n - 1; j++)
            {
                for (int k = j; k < _n; k++)
                {
                    if (info.postlist[sortpointer[j]] > info.postlist[sortpointer[k]])
                    {
                        foo            = sortpointer[k];
                        sortpointer[k] = sortpointer[j];
                        sortpointer[j] = foo;
                    }
                }
            }

            /* points from sort order back to range number */
            for (int j = 0; j < _n; j++)
            {
                look.forward_index[j] = sortpointer[j];
            }
            /* points from range order to sorted position */
            for (int j = 0; j < _n; j++)
            {
                look.reverse_index[look.forward_index[j]] = j;
            }
            /* we actually need the post values too */
            for (int j = 0; j < _n; j++)
            {
                look.sorted_index[j] = info.postlist[look.forward_index[j]];
            }

            /* quantize values to multiplier spec */
            switch (info.mult)
            {
            case 1:                     /* 1024 -> 256 */
                look.quant_q = 256;
                break;

            case 2:                     /* 1024 -> 128 */
                look.quant_q = 128;
                break;

            case 3:                     /* 1024 -> 86 */
                look.quant_q = 86;
                break;

            case 4:                     /* 1024 -> 64 */
                look.quant_q = 64;
                break;

            default:
                look.quant_q = -1;
                break;
            }

            /* discover our neighbors for decode where we don't use fit flags
             * (that would push the neighbors outward) */
            for (int j = 0; j < _n - 2; j++)
            {
                int lo       = 0;
                int hi       = 1;
                int lx       = 0;
                int hx       = look.n;
                int currentx = info.postlist[j + 2];
                for (int k = 0; k < j + 2; k++)
                {
                    int x = info.postlist[k];
                    if (x > lx && x < currentx)
                    {
                        lo = k;
                        lx = x;
                    }
                    if (x < hx && x > currentx)
                    {
                        hi = k;
                        hx = x;
                    }
                }
                look.loneighbor[j] = lo;
                look.hineighbor[j] = hi;
            }

            return(look);
        }
Пример #3
0
        override internal Object inverse1(Block vb, Object ii, Object memo)
        {
            LookFloor1 look = (LookFloor1)ii;
            InfoFloor1 info = look.vi;

            CodeBook[] books = vb.vd.fullbooks;

            /* unpack wrapped/predicted values from stream */
            if (vb.opb.Read(1) == 1)
            {
                int[] fit_value = null;
                if (memo is int[])
                {
                    fit_value = (int[])memo;
                }
                if (fit_value == null || fit_value.Length < look.posts)
                {
                    fit_value = new int[look.posts];
                }
                else
                {
                    for (int i = 0; i < fit_value.Length; i++)
                    {
                        fit_value[i] = 0;
                    }
                }

                fit_value[0] = vb.opb.Read(Util.ilog(look.quant_q - 1));
                fit_value[1] = vb.opb.Read(Util.ilog(look.quant_q - 1));

                /* partition by partition */
                for (int i = 0, j = 2; i < info.Partitions; i++)
                {
                    int  clss     = info.Partitionclass[i];
                    int  cdim     = info.class_dim[clss];
                    int  csubbits = info.class_subs[clss];
                    int  csub     = 1 << csubbits;
                    uint cval     = 0;

                    /* decode the partition's first stage cascade value */
                    if (csubbits != 0)
                    {
                        cval = (uint)books[info.class_book[clss]].decode(vb.opb);

                        if (unchecked (cval == (uint)(-1)))
                        {
                            return(null);
                        }
                    }

                    for (int k = 0; k < cdim; k++)
                    {
                        int book = info.class_subbook[clss][cval & (csub - 1)];
                        cval >>= csubbits;
                        if (book >= 0)
                        {
                            if ((fit_value[j + k] = books[book].decode(vb.opb)) == -1)
                            {
                                return(null);
                            }
                        }
                        else
                        {
                            fit_value[j + k] = 0;
                        }
                    }
                    j += cdim;
                }

                /* unwrap positive values and reconsitute via linear interpolation */
                for (int i = 2; i < look.posts; i++)
                {
                    int predicted = render_point(info.postlist[look.loneighbor[i - 2]],
                                                 info.postlist[look.hineighbor[i - 2]],
                                                 fit_value[look.loneighbor[i - 2]], fit_value[look.hineighbor[i - 2]],
                                                 info.postlist[i]);
                    int hiroom = look.quant_q - predicted;
                    int loroom = predicted;
                    int room   = (hiroom < loroom ? hiroom : loroom) << 1;
                    int val    = fit_value[i];

                    if (val != 0)
                    {
                        if (val >= room)
                        {
                            if (hiroom > loroom)
                            {
                                val = val - loroom;
                            }
                            else
                            {
                                val = -1 - (val - hiroom);
                            }
                        }
                        else
                        {
                            if ((val & 1) != 0)
                            {
                                val = -(int)(((uint)(val + 1)) >> 1);
                            }
                            else
                            {
                                val >>= 1;
                            }
                        }

                        fit_value[i] = val + predicted;
                        fit_value[look.loneighbor[i - 2]] &= 0x7fff;
                        fit_value[look.hineighbor[i - 2]] &= 0x7fff;
                    }
                    else
                    {
                        fit_value[i] = predicted | 0x8000;
                    }
                }
                return(fit_value);
            }

            return(null);
        }
Пример #4
0
        internal override Object look(DspState vd, InfoMode mi, Object i)
        {
            int _n = 0;

            int[] sortpointer = new int[VIF_POSIT + 2];

            //    Info vi=vd.vi;

            InfoFloor1 info = (InfoFloor1)i;
            LookFloor1 look = new LookFloor1();
            look.vi = info;
            look.n = info.postlist[1];

            /* we drop each position value in-between already decoded values,
             and use linear interpolation to predict each new value past the
             edges.  The positions are read in the order of the position
             list... we precompute the bounding positions in the lookup.  Of
             course, the neighbors can change (if a position is declined), but
             this is an initial mapping */

            for (int j = 0; j < info.Partitions; j++)
            {
                _n += info.class_dim[info.Partitionclass[j]];
            }
            _n += 2;
            look.posts = _n;

            /* also store a sorted position index */
            for (int j = 0; j < _n; j++)
            {
                sortpointer[j] = j;
            }
            //    qsort(sortpointer,n,sizeof(int),icomp); // !!

            int foo;
            for (int j = 0; j < _n - 1; j++)
            {
                for (int k = j; k < _n; k++)
                {
                    if (info.postlist[sortpointer[j]] > info.postlist[sortpointer[k]])
                    {
                        foo = sortpointer[k];
                        sortpointer[k] = sortpointer[j];
                        sortpointer[j] = foo;
                    }
                }
            }

            /* points from sort order back to range number */
            for (int j = 0; j < _n; j++)
            {
                look.forward_index[j] = sortpointer[j];
            }
            /* points from range order to sorted position */
            for (int j = 0; j < _n; j++)
            {
                look.reverse_index[look.forward_index[j]] = j;
            }
            /* we actually need the post values too */
            for (int j = 0; j < _n; j++)
            {
                look.sorted_index[j] = info.postlist[look.forward_index[j]];
            }

            /* quantize values to multiplier spec */
            switch (info.mult)
            {
                case 1: /* 1024 -> 256 */
                    look.quant_q = 256;
                    break;
                case 2: /* 1024 -> 128 */
                    look.quant_q = 128;
                    break;
                case 3: /* 1024 -> 86 */
                    look.quant_q = 86;
                    break;
                case 4: /* 1024 -> 64 */
                    look.quant_q = 64;
                    break;
                default:
                    look.quant_q = -1;
                    break;
            }

            /* discover our neighbors for decode where we don't use fit flags
               (that would push the neighbors outward) */
            for (int j = 0; j < _n - 2; j++)
            {
                int lo = 0;
                int hi = 1;
                int lx = 0;
                int hx = look.n;
                int currentx = info.postlist[j + 2];
                for (int k = 0; k < j + 2; k++)
                {
                    int x = info.postlist[k];
                    if (x > lx && x < currentx)
                    {
                        lo = k;
                        lx = x;
                    }
                    if (x < hx && x > currentx)
                    {
                        hi = k;
                        hx = x;
                    }
                }
                look.loneighbor[j] = lo;
                look.hineighbor[j] = hi;
            }

            return look;
        }