Esempio n. 1
0
        override public int inverse2(Block vb, Object i, Object memo, float[] fout)
        {
            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];

                        render_line(lx, hx, ly, hy, fout);

                        lx = hx;
                        ly = hy;
                    }
                }
                for (int j = hx; j < n; j++)
                {
                    fout[j] *= fout[j - 1];                 /* be certain */
                }
                return(1);
            }
            for (int j = 0; j < n; j++)
            {
                fout[j] = 0.0f;
            }
            return(0);
        }
Esempio n. 2
0
        override public 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(ilog(look.quant_q - 1));
                fit_value[1] = vb.opb.read(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;
                    int cval     = 0;

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

                        if (cval == -1)
                        {
                            //goto eop;
                            return(null);
                        }
                    }

                    for (int k = 0; k < cdim; k++)
                    {
                        int book = info.class_subbook[clss][cval & (csub - 1)];
                        cval = (int)((uint)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);
            }

            //  eop:
            //    return(NULL);
            return(null);
        }
Esempio n. 3
0
        override public 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);
        }