Exemplo n.º 1
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);
                }
            }
        }
Exemplo n.º 2
0
        public Color GetPixel(int x, int y)
        {
            var px = x % _prototype.Width;
            var py = y % _prototype.Height;

            return(_prototype.GetPixel(px, py));
        }
Exemplo n.º 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)));
                }
            }
        }
Exemplo n.º 4
0
 public static bool AllTransparentColumn(IBitmap bmp, int x)
 {
     for (int y = 0; y < bmp.Height; ++y)
     {
         if (bmp.GetPixel(x, y).A != 0)
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 5
0
 public static bool AllTransparentRow(IBitmap bmp, int y)
 {
     for (int x = 0; x < bmp.Width; ++x)
     {
         if (bmp.GetPixel(x, y).A != 0)
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 6
0
 private void manipulateImage(IBitmap bitmap, ILoadImageConfig config)
 {
     if (config == null)
     {
         return;
     }
     if (config.TransparentColorSamplePoint != null)
     {
         Color transparentColor = bitmap.GetPixel(config.TransparentColorSamplePoint.Value.X,
                                                  config.TransparentColorSamplePoint.Value.Y);
         bitmap.MakeTransparent(transparentColor);
     }
 }
Exemplo n.º 7
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();
        }
Exemplo n.º 8
0
        private static Color[,] GetColors(IBitmap bitmap)
        {
            Color[,] result = new Color[bitmap.Width, bitmap.Height];

            for (int r = 0; r < bitmap.Height; r++)
            {
                for (int c = 0; c < bitmap.Width; c++)
                {
                    result[c, r] = bitmap.GetPixel(c, r);
                }
            }

            return(result);
        }
        public override void Run(float deltaTime)
        {
            float angle = 0.0f;
            // NOTE: since MonoAGS has Y axis pointing up, we need to invert the lookup array's Y index
            float x = _veh.Position.X;
            float y = _veh.Position.Y;

            y = _regionMask.Height - y;
            Color color = _regionMask.GetPixel((int)Math.Round(x), (int)Math.Round(y));

            _regionAngles.TryGetValue(color, out angle);

            // Steering
            _targetAngle = angle;
            float dirAngle     = _veh.Direction.Angle();
            float angleBetween = MathEx.AnglePiFast(_targetAngle - MathEx.Angle2Pi(dirAngle));

            // HACK: reduce "jittering" when AI is trying to follow strict direction:
            // if the necessary angle is very close to the angle car will turn in one tick, then just adjust yourself
            float steeringDT = SteeringAngle * deltaTime * 1.1f;

            if (Math.Abs(angleBetween) <= Math.Abs(steeringDT))
            {
                _veh.SteeringWheelAngle = 0.0f;
                _veh.Direction          = Vectors.Rotate(new Vector2(1.0f, 0.0f), _targetAngle);
            }
            // ...otherwise turn properly, without cheating
            else if (angleBetween > 0.0f)
            {
                _veh.SteeringWheelAngle = SteeringAngle;
            }
            else if (angleBetween < 0.0f)
            {
                _veh.SteeringWheelAngle = -SteeringAngle;
            }
            else
            {
                _veh.SteeringWheelAngle = 0.0f;
            }

            // Always accelerating
            _veh.Accelerator = 1.0f;
            _veh.Brakes      = 0.0f;
        }
Exemplo n.º 10
0
 public RGBLuminanceSource(IBitmap d, int W, int H)
     : base(W, H) {
     int width = __width = W;
     int height = __height = H;
     // In order to measure pure decoding speed, we convert the entire image to a greyscale array
     // up front, which is the same as the Y channel of the YUVLuminanceSource in the real app.
     luminances = new sbyte[width * height];
     //if (format == PixelFormat.Format8bppIndexed)
     {
         Color c;
         for (int y = 0; y < height; y++) {
             int offset = y * width;
             for (int x = 0; x < width; x++) {
                 c = d.GetPixel(x, y);
                 luminances[offset + x] = (sbyte)(((int)c.R) << 16 | ((int)c.G) << 8 | ((int)c.B));
             }
         }
     }
 }
        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;
        }
Exemplo n.º 12
0
		private void manipulateImage(IBitmap bitmap, ILoadImageConfig config)
		{
			if (config == null) return;
			if (config.TransparentColorSamplePoint != null)
			{
				Color transparentColor = bitmap.GetPixel((int)config.TransparentColorSamplePoint.Value.X,
					(int)config.TransparentColorSamplePoint.Value.Y);
				bitmap.MakeTransparent(transparentColor);
			}
		}
Exemplo n.º 13
0
 private static IBitmap doWork(Func <byte, int> filter, IBitmap container, Action progressBar)
 {
     return(doDirtyWork(container, progressBar, (i, j) => container.GetPixel(i, j).FilterBy(filter)));
 }