Example #1
0
        public void Update(FastImage image, int posX, int posY)
        {
            if (posX < 1)
            {
                posX = 1;
            }
            if (posY < 1)
            {
                posY = 1;
            }
            var pixelSize = Math.Min(3, image.PixelFormatSize);

            for (var i = posY; i < image.Height; ++i)
            {
                for (var j = posX; j < image.Width; ++j)
                {
                    byte pixel = 0;
                    for (var p = 0; p < pixelSize; ++p)
                    {
                        pixel |= image.Data[i * image.Stride + j * image.PixelFormatSize + p];
                    }
                    this.Integral[j, i] = pixel + this.Integral[j - 1, i] + this.Integral[j, i - 1] - this.Integral[j - 1, i - 1];
                }
            }
        }
Example #2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="WordCloud" /> class.
        /// </summary>
        /// <param name="width">The width of word cloud.</param>
        /// <param name="height">The height of word cloud.</param>
        /// <param name="useRank">if set to <c>true</c> will ignore frequencies for best fit.</param>
        /// <param name="fontColor">Color of the font.</param>
        /// <param name="maxFontSize">Maximum size of the font.</param>
        /// <param name="fontStep">The font step to use.</param>
        /// <param name="mask">mask image</param>
        /// <param name="allowVerical">allow vertical text</param>
        /// <param name="fontname">name of the font</param>
        public WordCloud(int width, int height, bool useRank = false, Color?fontColor = null, float maxFontSize = -1,
                         int fontStep = 1, Image mask = null, bool allowVerical = false, string fontname = null)
        {
            if (mask == null)
            {
                Map       = new OccupancyMap(width, height);
                WorkImage = new FastImage(width, height, PixelFormat.Format32bppArgb);
            }
            else
            {
                mask = Util.ResizeImage(mask, width, height);
                if (!Util.CheckMaskValid(mask))
                {
                    throw new Exception("Mask is not a valid black-white image");
                }
                Map       = new OccupancyMap(mask);
                WorkImage = new FastImage(mask);
            }

            MaxFontSize   = maxFontSize < 0 ? height : maxFontSize;
            FontStep      = fontStep;
            _mFontColor   = fontColor;
            UseRank       = useRank;
            Random        = new Random(Environment.TickCount);
            AllowVertical = allowVerical;
            Fontname      = fontname;
#if DEBUG
            _drawWaitHandle = new AutoResetEvent(false);
            StepDrawMode    = false;
#endif
        }
Example #3
0
 public IntegralImage(FastImage image)
 {
     this.Integral        = new uint[image.Width, image.Height];
     this.OutputImgWidth  = image.Width;
     this.OutputImgHeight = image.Height;
     InitMask(image);
 }
Example #4
0
        internal static FastImage CropImage(FastImage img)
        {
            var cropRect = new Rectangle(1, 1, img.Width - 1, img.Height - 1);
            var src      = img.Bitmap;
            var target   = new Bitmap(cropRect.Width, cropRect.Height);

            using (var g = Graphics.FromImage(target))
            {
                g.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height),
                            cropRect,
                            GraphicsUnit.Pixel);
            }
            return(new FastImage(target));
        }
Example #5
0
 private void InitMask(FastImage image)
 {
     Update(Util.CropImage(image), 1, 1);
 }