示例#1
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// 有多少矩阵
 /// </summary>
 /// <returns></returns>
 public int size()
 {
     return(vboxes.size());
 }
示例#2
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// 开始计算
        /// </summary>
        /// <param name="pixels"></param>
        /// <param name="maxcolors"></param>
        /// <returns></returns>
        private static EICCMap __Quantize(List <Color> pixels, int maxcolors)
        {
            if (pixels.Count == 0 || maxcolors < 2 || maxcolors > 256)
            {
                return(null);
            }

            //得到颜色空间 里面每种颜色的数量集合
            var histo = __GetHisto(pixels);

            //color总数
            var nColors = 0;

            //代表总共有多少种颜色,通过采样出来的

            foreach (var v in histo)
            {
                if (v > 0)
                {
                    nColors++;
                }
            }

            //如果颜色还少于需要计算的颜色,应该不现实?
            if (nColors <= maxcolors)
            {
                // XXX: generate the new colors from the histo and return
            }

            //得到颜色的三维空间中 三个向量的最大值 最小值
            var vbox = __VboxFromPixels(pixels, histo);

            var pq = new EICPQueue <EICBox>((a, b) =>
            {
                return(NaturalOrder(a.count(), b.count()));
            });

            pq.push(vbox);

            //按照像素点进行切分
            __Iter(pq, histo, fractByPopulations * maxcolors);

            //切分完毕的数据,按照重量进行排序
            var pq2 = new EICPQueue <EICBox>(
                (a, b) =>
            {
                return(NaturalOrder(a.count() * a.volume(), b.count() * b.volume()));
            });

            //把切分完毕的,装在进去
            while (pq.size() > 0)
            {
                pq2.push(pq.pop());
            }

            //?继续切分吗?
            __Iter(pq2, histo, maxcolors - pq2.size());


            // calculate the actual colors
            var cmap = new EICCMap();

            while (pq2.size() > 0)
            {
                cmap.push(pq2.pop());
            }

            return(cmap);
        }