Пример #1
0
        private Int32 GetMatrixFactor()
        {
            Int32 result = 0;

            for (Int32 y = 0; y < CachedMatrix.GetLength(0); y++)
            {
                for (Int32 x = 0; x < CachedMatrix.GetLength(1); x++)
                {
                    Int32 value = CachedMatrix[y, x];
                    if (value > result)
                    {
                        result = value;
                    }
                }
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Called when ditherer is about to be prepared.
        /// </summary>
        protected virtual void OnPrepare()
        {
            // creates coeficient matrix and determines the matrix factor/divisor/maximum
            CachedMatrix = CreateCoeficientMatrix();
            Single maximum = GetMatrixFactor();

            // prepares the cache arrays
            Int32 width  = CachedMatrix.GetLength(1);
            Int32 height = CachedMatrix.GetLength(0);

            CachedSummedMatrix = new Single[height, width];

            // caches the matrix (and division by a sum)
            for (Int32 y = 0; y < height; y++)
            {
                for (Int32 x = 0; x < width; x++)
                {
                    CachedSummedMatrix[y, x] = CachedMatrix[y, x] / maximum;
                }
            }
        }