/// <summary>
        /// Calculate the LOD dictionary based on the Bitmap Source and requested LOD in the constructor.
        ///
        /// The colour returned (the byte) is dependent on the CalculateBestColor method, which can be
        /// overridden to weight specific colour keys.
        /// </summary>
        /// <returns></returns>
        public virtual Dictionary <Int32Rect, byte> CalculateLod()
        {
            var initialRect = new Int32Rect(0, 0, BitmapSource.PixelHeight, BitmapSource.PixelHeight);

            // Subdivide the rectangle
            var outputList = new List <Int32Rect>();

            initialRect.Subdivide(LevelOfDetail, outputList);

            var outputDictionary = new ConcurrentDictionary <Int32Rect, byte>();

            if (BitmapSource.CanFreeze)
            {
                BitmapSource.Freeze();
            }

            Parallel.ForEach(outputList, (element) =>
            {
                Dictionary <byte, int> colorsWithFrequency = BitmapSource.GetDistinctColors(element);

                byte bestColor = CalculateBestColor(element, colorsWithFrequency);

                outputDictionary[element] = bestColor;
            });

            return(outputDictionary.ToDictionary(c => c.Key, c => c.Value));
        }