Example #1
0
        public int?[] avg(bool force = false)
        {
            var vbox  = this;
            var histo = vbox.histo;

            if (vbox._avg == null || force)
            {
                int ntot = 0,
                    mult = 1 << (8 - EICTextureColor.sigbits);

                float rsum = 0,
                      gsum = 0,
                      bsum = 0;
                int hval,
                    i, j, k, histoindex;
                for (i = vbox.r1; i <= vbox.r2; i++)
                {
                    for (j = vbox.g1; j <= vbox.g2; j++)
                    {
                        for (k = vbox.b1; k <= vbox.b2; k++)
                        {
                            histoindex =
                                EICTextureColor.GetColorIndex(i, j, k);
                            hval  = histoindex < histo.Length ? histo[histoindex] : 0;
                            ntot += hval;
                            rsum += (hval * (i + 0.5f) * mult);
                            gsum += (hval * (j + 0.5f) * mult);
                            bsum += (hval * (k + 0.5f) * mult);
                        }
                    }
                }
                if (ntot > 0)
                {
                    vbox._avg = new int?[] {
                        ~~(int)(rsum / ntot),
                        ~~(int)(gsum / ntot),
                        ~~(int)(bsum / ntot)
                    };
                }
                else
                {
                    vbox._avg = new int?[] {
                        ~~(mult * (vbox.r1 + vbox.r2 + 1) / 2),
                        ~~(mult * (vbox.g1 + vbox.g2 + 1) / 2),
                        ~~(mult * (vbox.b1 + vbox.b2 + 1) / 2)
                    };
                }
            }
            return(vbox._avg);
        }
Example #2
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// 得到空间的点政数量
 /// </summary>
 /// <param name="force"></param>
 /// <returns></returns>
 public int count(bool force = false)
 {
     if (!_count_set || force)
     {
         int npix = 0,
             i, j, k;
         for (i = r1; i <= r2; i++)
         {
             for (j = g1; j <= g2; j++)
             {
                 for (k = b1; k <= b2; k++)
                 {
                     var index = EICTextureColor.GetColorIndex(i, j, k);
                     npix += index < histo.Length ? histo[index] : 0;
                 }
             }
         }
         _count     = npix;
         _count_set = true;
     }
     return(_count);
 }
Example #3
0
        //-------------------------------------------------------------------------
        void forcebw()
        {
            // XXX: won't  work yet
            var vboxes = this.vboxes;

            vboxes.sort((a, b) =>
            {
                return
                (EICTextureColor.NaturalOrder(
                     EICTextureColor.sum(a.color),
                     EICTextureColor.sum(b.color)));
            });

            // force darkest color to black if everything < 5
            var lowest = vboxes[0].color;

            if (lowest[0] < 5 && lowest[1] < 5 && lowest[2] < 5)
            {
                vboxes[0].color = new int?[] { 0, 0, 0 }
            }
            ;

            // force lightest color to white if everything > 251
            var idx     = vboxes.size() - 1;
            var highest = vboxes[idx].color;

            if (highest[0] > 251 && highest[1] > 251 && highest[2] > 251)
            {
                vboxes[idx].color = new int?[] { 255, 255, 255 }
            }
            ;
        }

        //-------------------------------------------------------------------------
    }
}