public async Task <FileStreamResult> GetAsync(int batchNumber, [FromQuery] DateTime since)
        {
            Console.WriteLine($"api/internal/{batchNumber}");
            var pixelsUpdatedSince = await PixelFetcher.UpdatedSinceAsync(batchNumber, since);

            return(new FileStreamResult(pixelsUpdatedSince.GetMemoryStream(), "text/plain"));
        }
Beispiel #2
0
        public void Render(BoolMatrix boolMatrix, PixelFetcher pf, 
		       Drawable drawable)
        {
            var dimensions = drawable.Dimensions;
              RenderDrop(boolMatrix, pf, dimensions);
              RenderShadow(pf, drawable, dimensions);
        }
Beispiel #3
0
        public void Render(BoolMatrix boolMatrix, PixelFetcher pf,
                           Drawable drawable)
        {
            var dimensions = drawable.Dimensions;

            RenderDrop(boolMatrix, pf, dimensions);
            RenderShadow(pf, drawable, dimensions);
        }
        public ColorCoordinateSet(Drawable drawable, int cellSize)
        {
            _cellSize2 = cellSize * cellSize;

            _backgroundColor = new Pixel(Context.Background.Bytes);

            var pf = new PixelFetcher(drawable, false);

            _width  = drawable.Width;
            _height = drawable.Height;

            int nrOfCells = (int)(2.5 * _width * _height / _cellSize2);

            _matrixColumns = (int)Math.Sqrt(nrOfCells * _width / 8.0 / _height);
            _matrixRows    = _matrixColumns * _height / _width;

            _matrixColumns = Math.Max(_matrixColumns, 1);
            _matrixRows    = Math.Max(_matrixRows, 1);

            _matrix = new List <ColorCoordinate> [_matrixRows, _matrixColumns];

            foreach (var c in new RandomCoordinateGenerator(_width - 1, _height - 1,
                                                            nrOfCells))
            {
                int x = c.X;
                int y = c.Y;

                var color = pf.GetPixel(c);
                color.AddNoise(5);

                var coordinate = new ColorCoordinate(c, color);
                Add(coordinate);

                int row = y * _matrixRows / _height;
                int col = x * _matrixColumns / _width;

                Add(row, col, coordinate);

                int top    = row * _height / _matrixRows;
                int left   = col * _width / _matrixColumns;
                int bottom = (row + 1) * _height / _matrixRows;
                int right  = (col + 1) * _width / _matrixColumns;

                Intersects(left, top, col - 1, row - 1, coordinate);
                Intersects(x, top, col, row - 1, coordinate);
                Intersects(right, top, col + 1, row - 1, coordinate);
                Intersects(left, y, col - 1, row, coordinate);
                Intersects(right, y, col + 1, row, coordinate);
                Intersects(left, bottom, col - 1, row + 1, coordinate);
                Intersects(x, bottom, col, row + 1, coordinate);
                Intersects(right, bottom, col + 1, row + 1, coordinate);
            }

            pf.Dispose();
        }
Beispiel #5
0
        public void Render(Image image, Drawable drawable)
        {
            Tile.CacheDefault(drawable);

            var activeLayer = image.ActiveLayer;
            var newLayer    = new Layer(activeLayer)
            {
                Name    = "_DifferenceClouds_",
                Visible = false,
                Mode    = activeLayer.Mode,
                Opacity = activeLayer.Opacity
            };

            // Initialization steps
            _bpp = drawable.Bpp;
            var pf = new PixelFetcher(drawable, true);

            _progress = 0;
            _hasAlpha = newLayer.HasAlpha;

            var rectangle = drawable.MaskBounds;

            _maxProgress = rectangle.Area;

            if (rectangle.Width > 0 && rectangle.Height > 0)
            {
                //
                // This first time only puts in the seed pixels - one in each
                // corner, and one in the center of each edge, plus one in the
                // center of the image.
                //
                InitSeedPixels(pf, rectangle);

                //
                // Now we recurse through the images, going further each time.
                //
                int depth = 1;
                while (!DoDifferenceClouds(pf, rectangle.X1, rectangle.Y1,
                                           rectangle.X2 - 1, rectangle.Y2 - 1,
                                           depth, 0))
                {
                    depth++;
                }
            }

            pf.Dispose();

            drawable.Flush();
            drawable.MergeShadow(true);

            DoDifference(drawable, newLayer);

            drawable.Update(rectangle);
        }
Beispiel #6
0
        public void Render(Image image, Drawable drawable)
        {
            Tile.CacheDefault(drawable);

              var activeLayer = image.ActiveLayer;
              var newLayer = new Layer(activeLayer)
            {
              Name = "_DifferenceClouds_",
              Visible = false,
              Mode = activeLayer.Mode,
              Opacity = activeLayer.Opacity
            };

              // Initialization steps
              _bpp = drawable.Bpp;
              var pf = new PixelFetcher(drawable, true);
              _progress = 0;
              _hasAlpha = newLayer.HasAlpha;

              var rectangle = drawable.MaskBounds;
              _maxProgress = rectangle.Area;

              if (rectangle.Width > 0 && rectangle.Height > 0)
            {
              //
              // This first time only puts in the seed pixels - one in each
              // corner, and one in the center of each edge, plus one in the
              // center of the image.
              //
              InitSeedPixels(pf, rectangle);

              //
              // Now we recurse through the images, going further each time.
              //
              int depth = 1;
              while (!DoDifferenceClouds(pf, rectangle.X1, rectangle.Y1,
                     rectangle.X2 - 1, rectangle.Y2 - 1,
                     depth, 0))
            {
              depth++;
            }
            }

              pf.Dispose();

              drawable.Flush();
              drawable.MergeShadow(true);

              DoDifference(drawable, newLayer);

              drawable.Update(rectangle);
        }
Beispiel #7
0
        protected override void Render(Drawable drawable)
        {
            Tile.CacheDefault(drawable);

              var iter = new RgnIterator(drawable, _("Fragment"));

              using (var pf = new PixelFetcher(drawable) {EdgeMode = EdgeMode.Black})
            {
              iter.IterateDest((x, y) =>
            {
              return (pf[y - 4, x - 4] +
              pf[y - 4, x + 4] +
              pf[y + 4, x - 4] +
              pf[y + 4, x + 4]) / 4;
            });
            }
        }
Beispiel #8
0
        override protected void Render(Drawable drawable)
        {
            Tile.CacheDefault(drawable);

            var iter = new RgnIterator(drawable, _("Fragment"));

            using (var pf = new PixelFetcher(drawable)
            {
                EdgeMode = EdgeMode.Black
            })
            {
                iter.IterateDest((x, y) =>
                                 (pf[y - 4, x - 4] +
                                  pf[y - 4, x + 4] +
                                  pf[y + 4, x - 4] +
                                  pf[y + 4, x + 4]) / 4);
            }
        }
Beispiel #9
0
        void RenderShadow(PixelFetcher pf, Drawable drawable, Dimensions dimensions)
        {
            int blurRadius = _newSize / 25 + 1;

            int x0        = -_radius - blurRadius;
            int y0        = x0;
            int x1        = _newSize - _radius + blurRadius;
            int y1        = x1;
            var rectangle = new Rectangle(x0, y0, x1, y1);

            foreach (var c in new CoordinateGenerator(rectangle))
            {
                if (c.Radius <= _radius * 1.1)
                {
                    var average = drawable.CreatePixel();
                    int blurPixels = 0;
                    int m, n;

                    for (int k = -blurRadius; k < blurRadius + 1; k++)
                    {
                        m = X + c.X + k;
                        for (int l = -blurRadius; l < blurRadius + 1; l++)
                        {
                            n = Y + c.Y + l;

                            if (dimensions.IsInside(m, n))
                            {
                                average += pf[n, m];
                                blurPixels++;
                            }
                        }
                    }

                    m = X + c.X;
                    n = Y + c.Y;

                    if (dimensions.IsInside(m, n))
                    {
                        pf[n, m] = average / blurPixels;
                    }
                }
            }
        }
Beispiel #10
0
        public void Render(Image image, Drawable drawable, Progress progress)
        {
            var dimensions = image.Dimensions;

            Tile.CacheDefault(drawable);
            var pf = new PixelFetcher(drawable, false);

            var iter = new RgnIterator(drawable, RunMode.Interactive);

            iter.IterateSrcDest(src => src);

            int dropSize = GetValue <int>("drop_size");
            int fishEye  = GetValue <int>("fish_eye");
            int number   = GetValue <int>("number");

            var factory = new RaindropFactory(dropSize, fishEye, dimensions);

            for (int numBlurs = 0; numBlurs <= number; numBlurs++)
            {
                var raindrop = factory.Create();
                if (raindrop == null)
                {
                    if (progress != null)
                    {
                        progress.Update(1.0);
                    }
                    break;
                }

                raindrop.Render(factory.BoolMatrix, pf, drawable);

                if (progress != null)
                {
                    progress.Update((double)numBlurs / number);
                }
            }

            pf.Dispose();

            drawable.Flush();
            drawable.Update();
        }
Beispiel #11
0
        void InitSeedPixels(PixelFetcher pf, Rectangle rectangle)
        {
            int x1 = rectangle.X1;
            int y1 = rectangle.Y1;
            int x2 = rectangle.X2 - 1;
            int y2 = rectangle.Y2 - 1;

            int xm = (x1 + x2) / 2;
            int ym = (y1 + y2) / 2;

            pf[y1, x1] = RandomRGB();
            pf[y1, x2] = RandomRGB();
            pf[y2, x1] = RandomRGB();
            pf[y2, x2] = RandomRGB();
            pf[ym, x1] = RandomRGB();
            pf[ym, x2] = RandomRGB();
            pf[y1, xm] = RandomRGB();
            pf[y2, xm] = RandomRGB();

            _progress += 8;
        }
Beispiel #12
0
        public async Task <IActionResult> UpdateAsync(int x, int y, [FromBody] PixelColorRequest pixelColorRequest)
        {
            Console.WriteLine($"api/pixels/{x}/{y}");
            if (x < 0 || x >= PixelFetcher.Pixels || y < 0 || y >= PixelFetcher.Pixels)
            {
                return(BadRequest($"X and Y must be between 0 and {PixelFetcher.Pixels}"));
            }

            if (string.IsNullOrWhiteSpace(pixelColorRequest.Color) || pixelColorRequest.Color.Length != 6)
            {
                return(BadRequest("Color must be 6 hex characters"));
            }

            var color = Enumerable.Range(0, pixelColorRequest.Color.Length / 2)
                        .Select(i => Convert.ToByte(pixelColorRequest.Color.Substring(i * 2, 2), 16))
                        .ToArray();

            await PixelFetcher.UpdatePixelAsync(x, y, color);

            return(Ok());
        }
Beispiel #13
0
        public void Render(Image image, Drawable drawable, Progress progress)
        {
            var dimensions = image.Dimensions;

              Tile.CacheDefault(drawable);
              var pf = new PixelFetcher(drawable, false);

              var iter = new RgnIterator(drawable, RunMode.Interactive);
              iter.IterateSrcDest(src => src);

              int dropSize = GetValue<int>("drop_size");
              int fishEye = GetValue<int>("fish_eye");
              int number = GetValue<int>("number");

              var factory = new RaindropFactory(dropSize, fishEye, dimensions);

              for (int numBlurs = 0; numBlurs <= number; numBlurs++)
            {
              var raindrop = factory.Create();
              if (raindrop == null)
            {
              if (progress != null)
            progress.Update(1.0);
              break;
            }

              raindrop.Render(factory.BoolMatrix, pf, drawable);

              if (progress != null)
            progress.Update((double) numBlurs / number);
            }

              pf.Dispose();

              drawable.Flush();
              drawable.Update();
        }
Beispiel #14
0
        void RenderDrop(BoolMatrix boolMatrix, PixelFetcher pf,
                        Dimensions dimensions)
        {
            int x0        = -_radius;
            int y0        = -_radius;
            int x1        = _newSize - _radius;
            int y1        = _newSize - _radius;
            var rectangle = new Rectangle(x0, y0, x1, y1);

            foreach (var c in new CoordinateGenerator(rectangle))
            {
                double r = c.Radius;
                double a = c.Angle;

                if (r <= _radius)
                {
                    double oldRadius = r;
                    r = (Math.Exp(r / _s) - 1) / _newCoeff;

                    int k = X + (int)(r * Math.Sin(a));
                    int l = Y + (int)(r * Math.Cos(a));

                    int m = X + c.X;
                    int n = Y + c.Y;

                    if (dimensions.IsInside(k, l) && dimensions.IsInside(m, n))
                    {
                        boolMatrix[n, m] = true;

                        var newColor = pf[l, k] + GetBright(oldRadius, a);
                        newColor.Clamp0255();
                        pf[l, k] = newColor;
                    }
                }
            }
        }
Beispiel #15
0
        void InitSeedPixels(PixelFetcher pf, Rectangle rectangle)
        {
            int x1 = rectangle.X1;
              int y1 = rectangle.Y1;
              int x2 = rectangle.X2 - 1;
              int y2 = rectangle.Y2 - 1;

              int xm = (x1 + x2) / 2;
              int ym = (y1 + y2) / 2;

              pf[y1, x1] = RandomRGB();
              pf[y1, x2] = RandomRGB();
              pf[y2, x1] = RandomRGB();
              pf[y2, x2] = RandomRGB();
              pf[ym, x1] = RandomRGB();
              pf[ym, x2] = RandomRGB();
              pf[y1, xm] = RandomRGB();
              pf[y2, xm] = RandomRGB();

              _progress += 8;
        }
Beispiel #16
0
        bool DoDifferenceClouds(PixelFetcher pf, int x1, int y1, int x2, int y2, 
			    int depth, int scaleDepth)
        {
            int xm = (x1 + x2) / 2;
              int ym = (y1 + y2) / 2;

              if (depth == 0)
            {
              if (x1 == x2 && y1 == y2)
            {
              return false;
            }

              var tl = pf[y1, x1];
              var tr = pf[y1, x2];
              var bl = pf[y2, x1];
              var br = pf[y2, x2];

              int ran = (int)((256.0 / (2.0 * scaleDepth)) * _turbulence);

              if (xm != x1 || xm != x2)
            {
              // Left
              pf[ym, x1] = AddRandom((tl + bl) / 2, ran);
              _progress++;

              if (x1 != x2)
            {
              // Right
              pf[ym, x2] = AddRandom((tr + br) / 2, ran);
              _progress++;
            }
            }

              if (ym != y1 || ym != y2)
            {
              if (x1 != xm || ym != y2)
            {
              // Bottom
              pf[y2, xm] = AddRandom((bl + br) / 2, ran);
              _progress++;
            }

              if (y1 != y2)
            {
              // Top
              pf[y1, xm] = AddRandom((tl + tr) / 2, ran);
              _progress++;
            }
            }

              if (y1 != y2 || x1 != x2)
            {
              // Middle pixel
              pf[ym, xm] = AddRandom((tl + tr + bl + br) / 4, ran);
              _progress++;
            }

              _count++;

              if (_count % 2000 == 0)
            {
              _progressBar.Update((double)_progress / (double) _maxProgress);
            }

              return (x2 - x1 < 3) && (y2 - y1 < 3);
            }
              else if (x1 < x2 || y1 < y2)
            {
              depth--;
              scaleDepth++;

              // Top left
              DoDifferenceClouds(pf, x1, y1, xm, ym, depth, scaleDepth);
              // Bottom left
              DoDifferenceClouds(pf, x1, ym, xm ,y2, depth, scaleDepth);
              // Top right
              DoDifferenceClouds(pf, xm, y1, x2 , ym, depth, scaleDepth);
              // Bottom right
              return DoDifferenceClouds(pf, xm, ym, x2, y2, depth, scaleDepth);
            }
              else
            {
              return true;
            }
        }
Beispiel #17
0
        bool DoDifferenceClouds(PixelFetcher pf, int x1, int y1, int x2, int y2,
                                int depth, int scaleDepth)
        {
            int xm = (x1 + x2) / 2;
            int ym = (y1 + y2) / 2;

            if (depth == 0)
            {
                if (x1 == x2 && y1 == y2)
                {
                    return(false);
                }

                var tl = pf[y1, x1];
                var tr = pf[y1, x2];
                var bl = pf[y2, x1];
                var br = pf[y2, x2];

                int ran = (int)((256.0 / (2.0 * scaleDepth)) * _turbulence);

                if (xm != x1 || xm != x2)
                {
                    // Left
                    pf[ym, x1] = AddRandom((tl + bl) / 2, ran);
                    _progress++;

                    if (x1 != x2)
                    {
                        // Right
                        pf[ym, x2] = AddRandom((tr + br) / 2, ran);
                        _progress++;
                    }
                }

                if (ym != y1 || ym != y2)
                {
                    if (x1 != xm || ym != y2)
                    {
                        // Bottom
                        pf[y2, xm] = AddRandom((bl + br) / 2, ran);
                        _progress++;
                    }

                    if (y1 != y2)
                    {
                        // Top
                        pf[y1, xm] = AddRandom((tl + tr) / 2, ran);
                        _progress++;
                    }
                }

                if (y1 != y2 || x1 != x2)
                {
                    // Middle pixel
                    pf[ym, xm] = AddRandom((tl + tr + bl + br) / 4, ran);
                    _progress++;
                }

                _count++;

                if (_count % 2000 == 0)
                {
                    _progressBar.Update((double)_progress / (double)_maxProgress);
                }

                return((x2 - x1 < 3) && (y2 - y1 < 3));
            }
            else if (x1 < x2 || y1 < y2)
            {
                depth--;
                scaleDepth++;

                // Top left
                DoDifferenceClouds(pf, x1, y1, xm, ym, depth, scaleDepth);
                // Bottom left
                DoDifferenceClouds(pf, x1, ym, xm, y2, depth, scaleDepth);
                // Top right
                DoDifferenceClouds(pf, xm, y1, x2, ym, depth, scaleDepth);
                // Bottom right
                return(DoDifferenceClouds(pf, xm, ym, x2, y2, depth, scaleDepth));
            }
            else
            {
                return(true);
            }
        }
Beispiel #18
0
 public Painter(Drawable drawable, int size, RGB color)
 {
     _color = new Pixel(color.Bytes);
       _pf = new PixelFetcher(drawable);
       Size = size;
 }
Beispiel #19
0
        void RenderShadow(PixelFetcher pf, Drawable drawable, Dimensions dimensions)
        {
            int blurRadius = _newSize / 25 + 1;

              int x0 = -_radius - blurRadius;
              int y0 = x0;
              int x1 = _newSize - _radius + blurRadius;
              int y1 = x1;
              var rectangle = new Rectangle(x0, y0, x1, y1);

              foreach (var c in new CoordinateGenerator(rectangle))
            {
              if (c.Radius <= _radius * 1.1)
            {
              var average = drawable.CreatePixel();
              int blurPixels = 0;
              int m, n;

              for (int k = -blurRadius; k < blurRadius + 1; k++)
            {
              m = X + c.X + k;
              for (int l = -blurRadius; l < blurRadius + 1; l++)
            {
              n = Y + c.Y + l;

              if (dimensions.IsInside(m, n))
            {
              average += pf[n, m];
              blurPixels++;
            }
            }
            }

              m = X + c.X;
              n = Y + c.Y;

              if (dimensions.IsInside(m, n))
            {
              pf[n, m] = average / blurPixels;
            }
            }
            }
        }
Beispiel #20
0
        void RenderDrop(BoolMatrix boolMatrix, PixelFetcher pf, 
		    Dimensions dimensions)
        {
            int x0 = -_radius;
              int y0 = -_radius;
              int x1 = _newSize - _radius;
              int y1 = _newSize - _radius;
              var rectangle = new Rectangle(x0, y0, x1, y1);

              foreach (var c in new CoordinateGenerator(rectangle))
            {
              double r = c.Radius;
              double a = c.Angle;

              if (r <= _radius)
            {
              double oldRadius = r;
              r = (Math.Exp (r / _s) - 1) / _newCoeff;

              int k = X + (int) (r * Math.Sin(a));
              int l = Y + (int) (r * Math.Cos(a));

              int m = X + c.X;
              int n = Y + c.Y;

              if (dimensions.IsInside(k, l) && dimensions.IsInside(m, n))
            {
              boolMatrix[n, m] = true;

              var newColor = pf[l, k] + GetBright(oldRadius, a);
              newColor.Clamp0255();
              pf[l, k] = newColor;
            }
            }
            }
        }
Beispiel #21
0
 public Painter(Drawable drawable, int size, RGB color)
 {
     _color = new Pixel(color.Bytes);
     _pf    = new PixelFetcher(drawable);
     Size   = size;
 }