SetPixel() 공개 메소드

public SetPixel ( int x, int y, uint color ) : bool
x int
y int
color uint
리턴 bool
예제 #1
0
        public void CopyFromSkipTransparent()
        {
            var result = new PixelBuffer(PixelFormat.ARGB8888, new Size(30, 20));

            src.SetPixel(0, 0, Color.FromArgb(0, 255, 255, 255));

            result.CopyFrom(src, new Rectangle(Point.Zero, src.Size), Point.Zero, false, true);

            VerifyCopyResult(result);
        }
예제 #2
0
파일: Plugin.cs 프로젝트: cadypaul/xLights
 public void ManipulateBuffer(PixelBuffer buffer)
 {
     for (int i = 0; i < 10; i++)
     {
         buffer.SetPixel(i, Color.Magenta);
     }
 }
        private static void RasterizeBlockingSplines(TerrainComponent terrain, TerrainVegetationComponent component, PixelBuffer mask, int maskChannel, float terrainOffset)
        {
            foreach (var spline in component.BlockingSplines)
            {
                var vertices = new FastList <Splines.VertexPositionNormalTangentColorTexture>();
                var indices  = new FastList <int>();
                Splines.SplineMeshBuilder.CreateSplineMesh(spline, vertices, indices);

                for (var i = 0; i < indices.Count; i += 3)
                {
                    var vt1f = vertices[indices[i + 0]].Position;
                    var vt2f = vertices[indices[i + 1]].Position;
                    var vt3f = vertices[indices[i + 2]].Position;

                    vt1f = (vt1f + terrainOffset) / terrain.Size * mask.Width;
                    vt2f = (vt2f + terrainOffset) / terrain.Size * mask.Width;
                    vt3f = (vt3f + terrainOffset) / terrain.Size * mask.Width;

                    // Just ignore Y axis, works well enoguh for splines but if we
                    // support generic volumes in the future then we might want to project it a bit more properly
                    // or maybe just do an offscreen render pass on the gpu ...
                    var vt1 = new Int2((int)vt1f.X, (int)vt1f.Z);
                    var vt2 = new Int2((int)vt2f.X, (int)vt2f.Z);
                    var vt3 = new Int2((int)vt3f.X, (int)vt3f.Z);

                    // Calculate bounding box
                    var maxX = Math.Max(vt1.X, Math.Max(vt2.X, vt3.X));
                    var minX = Math.Min(vt1.X, Math.Min(vt2.X, vt3.X));
                    var maxY = Math.Max(vt1.Y, Math.Max(vt2.Y, vt3.Y));
                    var minY = Math.Min(vt1.Y, Math.Min(vt2.Y, vt3.Y));

                    // Triangle intersection
                    var vs1 = vt2 - vt1;
                    var vs2 = vt3 - vt1;

                    for (var x = minX; x <= maxX; x++)
                    {
                        for (var y = minY; y < maxY; y++)
                        {
                            var q = new Int2(x - vt1.X, y - vt1.Y);

                            var s = (float)CrossProduct(q, vs2) / CrossProduct(vs1, vs2);
                            var t = (float)CrossProduct(vs1, q) / CrossProduct(vs1, vs2);

                            if (s >= 0 && t >= 0 && (s + t) <= 1)
                            {
                                var currentPixel = mask.GetPixel <Color>(x, y);
                                currentPixel[maskChannel] = 0;

                                mask.SetPixel <Color>(x, y, currentPixel);
                            }
                        }
                    }
                }
            }
        }
예제 #4
0
        public void Init()
        {
            src = new PixelBuffer(PixelFormat.ABGR8888, new Size(30, 20));

            for (int j = 0; j < src.Height; j++)
            {
                for (int i = 0; i < src.Width; i++)
                {
                    src.SetPixel(i, j, SourceColorAt(i, j));
                }
            }
        }
예제 #5
0
        void Mouse_MouseMove(InputEventArgs e)
        {
            Color clr;
            Point pt = new Point(e.MousePosition.X - imageLocation.X,
                                 e.MousePosition.Y - imageLocation.Y);

            if (buffer.IsPointValid(pt) == false)
            {
                frm.lblPixelColor.Text = "No Pixel";
                return;
            }

            if (Mouse.Buttons[Mouse.MouseButtons.Primary])
            {
                // do a circle of radius 3
                for (int y = -3; y <= 3; y++)
                {
                    for (int x = -3; x <= 3; x++)
                    {
                        // if we're out of the circle radius, go to the next iteration.
                        if (x * x + y * y > 9)
                        {
                            continue;
                        }

                        Point newpt = new Point(pt.X + x, pt.Y + y);

                        if (newpt.X < 0 || newpt.X >= buffer.Width)
                        {
                            continue;
                        }
                        if (newpt.Y < 0 || newpt.Y >= buffer.Height)
                        {
                            continue;
                        }

                        buffer.SetPixel(newpt.X, newpt.Y, Color.FromArgb(frm.btnColor.BackColor.ToArgb()));
                    }
                }
                image.WritePixels(buffer);
            }

            clr = buffer.GetPixel(e.MousePosition.X - imageLocation.X,
                                  e.MousePosition.Y - imageLocation.Y);

            frm.lblPixelColor.Text =
                string.Format("R: {0}  G: {1}\r\nB: {2}  A: {3}",
                              FormatComponent(clr.R), FormatComponent(clr.G),
                              FormatComponent(clr.B), FormatComponent(clr.A));
        }
예제 #6
0
        public void PixelsEqualSameFormat()
        {
            var result = new PixelBuffer(PixelFormat.ABGR8888, src.Size);

            result.CopyFrom(src, new Rectangle(Point.Zero, src.Size), Point.Zero, false);

            VerifyCopyResult(result);

            Assert.IsTrue(PixelBuffer.PixelsEqual(result, src));

            result.SetPixel(0, 0, Color.Black);

            Assert.IsFalse(PixelBuffer.PixelsEqual(src, result));
        }
예제 #7
0
        /// <summary>
        /// Creates a normal map by interpreting the pixel data in the passed buffer
        /// as a height map.
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="normalStr">The weight for the x-y components of the normals in
        /// the normal map.  Smaller values make the normal map more subtle.
        /// Values in the range 0.5f to 3.0f are reasonable.</param>
        /// <returns></returns>
        public static PixelBuffer NormalMapFromHeightMap(PixelBuffer buffer, float normalStr)
        {
            int[,] heights = new int[buffer.Width, buffer.Height];

            for (int j = 0; j < buffer.Height; j++)
            {
                for (int i = 0; i < buffer.Width; i++)
                {
                    heights[i, j] = (int)(buffer.GetPixel(i, j).Intensity *short.MaxValue);
                }
            }

            PixelBuffer result = new PixelBuffer(buffer.PixelFormat, buffer.Size);

            int[,] square = new int[3, 3];

            for (int j = 0; j < result.Height; j++)
            {
                for (int i = 0; i < result.Width; i++)
                {
                    GetSquare(square, heights, i, j);

                    // sobel operator:
                    int diffx = square[0, 0] - square[2, 0] +
                                2 * (square[0, 1] - square[2, 1]) +
                                square[0, 2] - square[2, 0];

                    int diffy = square[0, 0] + 2 * square[1, 0] + square[0, 2] +
                                -square[0, 2] - 2 * square[1, 2] - square[2, 2];

                    Vector3f vec = new Vector3f(diffx / (float)short.MaxValue, diffy / (float)short.MaxValue, 0);
                    vec  *= normalStr;
                    vec.Z = 1;

                    vec    = vec.Normalize();
                    vec    = vec / 2;
                    vec.X += 0.5f; vec.Y += 0.5f; vec.Z += 0.5f;
                    Color clr = Color.FromRgb((int)(vec.X * 255),
                                              (int)(vec.Y * 255),
                                              (int)(vec.Z * 255));

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

            return(result);
        }
예제 #8
0
        private static void PostProcessFont(BitmapFontOptions options, System.Drawing.Bitmap bmp)
        {
            if (options.EdgeOptions == BitmapFontEdgeOptions.None)
            {
                return;
            }

            Drawing.Imaging.BitmapData data = bmp.LockBits(
                new Drawing.Rectangle(Drawing.Point.Empty, bmp.Size),
                Drawing.Imaging.ImageLockMode.ReadWrite, Drawing.Imaging.PixelFormat.Format32bppArgb);

            PixelFormat bitmapFormat = PixelFormat.BGRA8888;

            PixelBuffer buffer = new PixelBuffer(bitmapFormat, Interop.Convert(bmp.Size),
                                                 data.Scan0, bitmapFormat, data.Stride);

            // now convert pixels to gray scale.
            for (int j = 0; j < buffer.Height; j++)
            {
                for (int i = 0; i < buffer.Width; i++)
                {
                    Color clr = buffer.GetPixel(i, j);
                    if (clr.ToArgb() == 0)
                    {
                        continue;
                    }

                    int  alpha     = clr.A;
                    int  intensity = (int)Math.Round(0.30 * clr.R + 0.59 * clr.G + 0.11 * clr.B);
                    byte value     = (byte)intensity;

                    System.Diagnostics.Debug.Assert(0 <= intensity && intensity <= 255);
                    if (intensity < 0)
                    {
                        intensity = 0;
                    }
                    if (intensity > 255)
                    {
                        intensity = 255;
                    }


                    switch (options.EdgeOptions)
                    {
                    case BitmapFontEdgeOptions.IntensityAlphaWhite:
                        clr = Color.FromArgb(value, Color.White);
                        break;

                    case BitmapFontEdgeOptions.IntensityAlphaColor:
                        clr = Color.FromArgb(value, clr);
                        break;
                    }

                    buffer.SetPixel(i, j, clr);
                }
            }


            System.Runtime.InteropServices.Marshal.Copy(
                buffer.Data, 0, data.Scan0, buffer.Data.Length);

            bmp.UnlockBits(data);
        }
예제 #9
0
        public void Run(string[] args)
        {
            using (new DisplayWindowBuilder(args)
                   .BackbufferSize(800, 600)
                   .QuitOnClose()
                   .Build())
            {
                PixelBuffer pbMaskBg     = PixelBuffer.FromFile("mask_bg-bricks.png");
                PixelBuffer pbBg         = PixelBuffer.FromFile("bg-bricks.png");
                PixelBuffer pbMaskCircle = PixelBuffer.FromFile("mask_circle.png");

                Surface surfRealBg = new Surface(pbMaskBg.Size);


                for (int x = 0; x < pbMaskBg.Width; x++)
                {
                    for (int y = 0; y < pbMaskBg.Height; y++)
                    {
                        if (pbMaskBg.GetPixel(x, y) == Color.FromArgb(255, 0, 0, 0))
                        {
                            pbBg.SetPixel(x, y, Color.FromArgb(0, 0, 0, 0));
                        }
                    }
                }

                surfRealBg.WritePixels(pbBg);

                bool mouseDown = false;

                Input.Unhandled.MouseDown += (sender, e) =>
                {
                    if (e.MouseButton == MouseButton.Primary)
                    {
                        mouseDown = true;
                    }
                };
                Input.Unhandled.MouseUp += (sender, e) =>
                {
                    if (e.MouseButton == MouseButton.Primary)
                    {
                        mouseDown = false;
                    }
                };
                Input.Unhandled.MouseMove += (sender, e) => mouse = e.MousePosition;

                while (AgateApp.IsAlive)
                {
                    Display.CurrentWindow.Title = Display.FramesPerSecond.ToString();
                    Display.BeginFrame();

                    if (Input.Unhandled.Keys[KeyCode.Escape])
                    {
                        return;
                    }

                    if (mouseDown)
                    {
                        int mX = mouse.X;
                        int mY = mouse.Y;

                        Rectangle rect = new Rectangle(mX, mY, pbMaskCircle.Width, pbMaskCircle.Height);
                        Point     p    = new Point(mX, mY);

                        for (int x = 0; x < pbMaskCircle.Width; x++)
                        {
                            if (mX + x >= pbBg.Width)
                            {
                                break;
                            }

                            for (int y = 0; y < pbMaskCircle.Height; y++)
                            {
                                if (mY + y >= pbBg.Height)
                                {
                                    break;
                                }

                                if (pbMaskCircle.GetPixel(x, y) == Color.FromArgb(255, 0, 0, 0))
                                {
                                    pbBg.SetPixel(mX + x, mY + y, Color.FromArgb(0, 0, 0, 0));
                                }
                            }
                        }

                        surfRealBg.WritePixels(pbBg, rect, p);
                    }

                    Display.Clear(Color.Blue);
                    surfRealBg.Draw();

                    Display.EndFrame();
                    AgateApp.KeepAlive();
                }
            }
        }