Example #1
0
        public void SetPixel(int x, int y, Color value)
        {
            var px = x % _prototype.Width;
            var py = y % _prototype.Height;

            _prototype.SetPixel(px, py, value);
        }
Example #2
0
        public void Draw(IBitmap canvas)
        {
            var lightDirection         = _configuration.LightDirection.normalized;
            var reversedLightDirection = -lightDirection;
            var reversedViewDirection  = -Vector3.down;

            for (var x = 0; x < canvas.Width; x++)
            {
                for (var y = 0; y < canvas.Height; y++)
                {
                    var position = _coordinateConverter.Convert(new Vector2Int(x, y));

                    var normal = GetNormal(position);

                    var diffuseComponent  = GetDiffuse(normal, reversedLightDirection);
                    var specularComponent = GetSpecular(normal, lightDirection, reversedViewDirection);

                    var canvasColor    = canvas.GetPixel(x, y);
                    var resultingColor = GetLightComponent(canvasColor, _configuration.AmbientColor,
                                                           _configuration.AmbientIntensity) +
                                         GetLightComponent(canvasColor, _configuration.LightColor,
                                                           _configuration.LightIntensity * diffuseComponent) +
                                         GetSpecularComponent(_configuration.SpecularColor, _configuration.LightColor,
                                                              specularComponent, _configuration.SpecularIntensity);

                    resultingColor.a = canvasColor.a;
                    canvas.SetPixel(x, y, resultingColor);
                }
            }
        }
Example #3
0
        public void Draw(IBitmap canvas)
        {
            for (var x = 0; x < canvas.Width; x++)
            {
                for (var y = 0; y < canvas.Height; y++)
                {
                    var position = _coordinateConverter.Convert(new Vector2Int(x, y));

                    if (!Physics.Raycast(position, Vector3.down, out var hit, RAYCAST_DISTANCE, _raycastMask,
                                         QueryTriggerInteraction.Ignore))
                    {
                        continue;
                    }

                    var materialBitmap = _materialSource.GetTexture(hit.collider.gameObject.name.ToLower());
                    if (materialBitmap == null)
                    {
                        continue;
                    }

                    canvas.SetPixel(x, y,
                                    NormalColorBlending.Instance.Blend(canvas.GetPixel(x, y), materialBitmap.GetPixel(x, y)));
                }
            }
        }
Example #4
0
        public void Draw(IBitmap canvas)
        {
            var bitmap = _bitmapProvider.GetItem();

            for (var x = 0; x < canvas.Width; x++)
            {
                for (var y = 0; y < canvas.Height; y++)
                {
                    canvas.SetPixel(x, y, _blending.Blend(canvas.GetPixel(x, y), bitmap.GetPixel(x, y)));
                }
            }

            (bitmap as IDisposable)?.Dispose();
        }
Example #5
0
        private static IBitmap doDirtyWork(IBitmap container, Action progressBar, Func <int, int, Color> predicate)
        {
            IBitmap result = CreateIBitmap(container.Width, container.Height, container.PixelFormat);

            for (int i = 0; i < container.Width; i++)
            {
                for (int j = 0; j < container.Height; j++)
                {
                    if (progressBar != null)
                    {
                        progressBar();
                    }

                    result.SetPixel(i, j, predicate(i, j));
                }
            }

            return(result);
        }
        public void generate(object sender, DoWorkEventArgs work)
        {
            System.Drawing.Color srcColor, maskColor;
            int    width = src.Width;
            int    height = src.Height;
            double lum, mr, mg, mb;

            //progress updating vars
            double totalPixels     = width * height * 3;
            double processedPixels = 0;
            double progress        = 0;
            double prevProg        = 0;

            //difference mask vars

            //first pass -- get min/max bounds, count and sum
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    maskColor = mask.GetPixel(x, y);
                    if (maskColor.R == 0 && maskColor.G == 0 && maskColor.B == 0)
                    {
                        continue;
                    }                                                                          //unmasked pixel, skip
                    getPixelColors(maskColor, out mr, out mg, out mb);
                    normalizeMask(ref mr, ref mg, ref mb);
                    srcColor = src.GetPixel(x, y);
                    lum      = getChannelLuminance(srcColor);
                    channelCalc(lum, mr, ref countR, ref sumR, ref minR, ref maxR);
                    channelCalc(lum, mg, ref countG, ref sumG, ref minG, ref maxG);
                    channelCalc(lum, mb, ref countB, ref sumB, ref minB, ref maxB);
                    processedPixels++;
                    progress = workStart + ((processedPixels / totalPixels) * 100d) / workDiv;
                    if (progress - prevProg > 1)
                    {
                        prevProg = progress;
                        ((BackgroundWorker)sender).ReportProgress((int)progress);
                    }
                }
            }

            //guard against NAN from div/0
            outR = countR == 0? 0 : sumR / countR;
            outG = countG == 0? 0 : sumG / countG;
            outB = countB == 0? 0 : sumB / countB;

            //third pass -- write output
            dest        = new DirectBitmap(src.Width, src.Height);
            difference  = new DirectBitmap(src.Width, src.Height);
            coloredDiff = new DirectBitmap(src.Width, src.Height);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    maskColor = mask.GetPixel(x, y);
                    if (maskColor.R == 0 && maskColor.G == 0 && maskColor.B == 0)
                    {
                        continue;
                    }                                                                          //unmasked pixel, skip
                    getPixelColors(maskColor, out mr, out mg, out mb);
                    normalizeMask(ref mr, ref mg, ref mb);
                    double pix = outR * mr + outG * mg + outB * mb;
                    pix = Math.Min(pix, 1);
                    dest.SetPixel(x, y, setPixelColors(pix, pix, pix));

                    srcColor = src.GetPixel(x, y);
                    lum      = getChannelLuminance(srcColor);

                    difference.SetPixel(x, y, getDiffColor(pix, lum, false));
                    coloredDiff.SetPixel(x, y, getDiffColor(pix, lum, true));

                    //double op in this loop, count twice for progress reporting
                    processedPixels++;
                    processedPixels++;
                    progress = workStart + ((processedPixels / totalPixels) * 100d) / workDiv;
                    if (progress - prevProg > 1)
                    {
                        prevProg = progress;
                        ((BackgroundWorker)sender).ReportProgress((int)progress);
                    }
                }
            }
            outText = outR + "," + outG + "," + outB;
        }