Ejemplo n.º 1
0
        public BoundedTextureData <Color> CombineMask(BoundedTextureData <Color> color,
                                                      BoundedTextureData <Color> mask)
        {
            var colorBounds = color.Bounds;
            var maskBounds  = mask.Bounds;

            if (colorBounds.Size != maskBounds.Size)
            {
                throw new ArgumentException("Masking requires equal-sized texture data: " + colorBounds.Size + " vs mask " + maskBounds.Size);
            }

            var width  = colorBounds.Width;
            var height = colorBounds.Height;
            var retval = new Color[width * height];

            for (var y = 0; y < height; y += 1)
            {
                for (var x = 0; x < width; x += 1)
                {
                    var px = colorBounds.X + x;
                    var py = colorBounds.Y + y;
                    var c  = color[px, py];

                    var mx = maskBounds.X + x;
                    var my = maskBounds.Y + y;
                    var a  = mask[mx, my];

                    var tidx = y * width + x;
                    retval[tidx] = c * (a.A / 255f);
                }
            }

            return(new BoundedTextureData <Color>(colorBounds, retval));
        }
Ejemplo n.º 2
0
        public XnaTexture ApplyTextureData(XnaTexture texture, BoundedTextureData <Color> result, TextureCoordinatePoint offset)
        {
            var b = result.Bounds;

            if (result.TextureData.Length != b.Width * b.Height)
            {
                throw new ArgumentException();
            }

            if (offset.X + b.Width > texture.Texture.Width)
            {
                throw new IndexOutOfRangeException();
            }

            if (offset.Y + b.Height > texture.Texture.Height)
            {
                throw new IndexOutOfRangeException();
            }

            texture.Texture.SetData(0, new Rectangle(offset.X,
                                                     offset.Y,
                                                     b.Width,
                                                     b.Height),
                                    result.TextureData,
                                    0, result.TextureData.Length);
            return(texture);
        }
Ejemplo n.º 3
0
        bool TryFindSourceMask(CardinalIndex dir, out BoundedTextureData <TColor> colorData, out IntPoint anchor)
        {
            var idx = (int)dir;
            var ce  = maskCache[idx];

            colorData = ce.ColorData;
            anchor    = ce.Anchor;
            return(ce.Exists);
        }
Ejemplo n.º 4
0
        public void MakeDebugVisible(BoundedTextureData <Color> b)
        {
            for (var i = 0; i < b.TextureData.Length; i++)
            {
                if (b.TextureData[i].A > 0)
                {
                    return;
                }
            }

            // Debug.LogWarning("Data is all transparent pixels");
        }
Ejemplo n.º 5
0
        public BoundedTextureData <Color> CombineBlend(BoundedTextureData <Color> background,
                                                       BoundedTextureData <Color> foreground)
        {
            var backgroundBounds = background.Bounds;
            var foregroundBounds = foreground.Bounds;

            if (foreground.Bounds.Size != background.Bounds.Size)
            {
                throw new ArgumentException("Blending requires equal-sized texture data.");
            }

            var width  = backgroundBounds.Width;
            var height = backgroundBounds.Height;

            var retval = new Color[width * height];

            for (var y = 0; y < height; y += 1)
            {
                for (var x = 0; x < width; x += 1)
                {
                    var   px  = backgroundBounds.X + x;
                    var   py  = backgroundBounds.Y + y;
                    Color src = background[px, py];

                    var   tx  = foregroundBounds.X + x;
                    var   ty  = foregroundBounds.Y + y;
                    Color tgt = foreground[tx, ty];

                    var tidx = y * width + x;

                    var srcW = src; // * (1 - tgt.A);
                    var tgtW = tgt * tgt.A;
                    retval[tidx] = new Color(srcW.R + tgtW.R, srcW.G + tgtW.G, srcW.B + tgtW.B, srcW.A + tgtW.A);
                }
            }

            return(new BoundedTextureData <Color>(backgroundBounds, retval));
        }
Ejemplo n.º 6
0
        public XnaTexture ApplyTextureData(XnaTexture texture, BoundedTextureData <Color> result)
        {
            var b = result.Bounds;

            if (result.TextureData.Length != b.Width * b.Height)
            {
                throw new ArgumentException(
                          $"Texture data needs to have {b.Width} * {b.Height} = {b.Width * b.Height} pixels.");
            }

            if (texture.Bounds.Width != result.Bounds.Width)
            {
                throw new ArgumentException($"Width mismatch: src: {b.Width} target:{texture.Bounds.Width}");
            }

            if (texture.Bounds.Height != result.Bounds.Height)
            {
                throw new ArgumentException($"Width mismatch: src: {b.Width} target:{texture.Bounds.Width}");
            }

            texture.Texture.SetData(0, new Rectangle(b.X, b.Y, b.Width, b.Height), result.TextureData, 0, result.TextureData.Length);
            return(texture);
        }
Ejemplo n.º 7
0
 public CacheEntry(bool exists, BoundedTextureData <TColor> colorData, IntPoint anchor)
 {
     Exists    = exists;
     ColorData = colorData;
     Anchor    = anchor;
 }