/// <summary>Puts a copy of 2D pixel data in a BytePixels object, specifying a source rectangle and a destination X,Y point.</summary> /// <param name="rect">The section of the pixel data to copy. <paramref name="null"/> indicates the data will be copied from the entire object.</param> /// <param name="dest">The destination BytePixels object.</param> /// <param name="xy">The top-left corner of the destination.</param> public void PutData(RectI?rect, BytePixels dest, PointInt32 xy) { RectI r; if (rect != null) { r = (RectI)rect; } else { r = new RectI(new PointInt32(), this.Size); } var sOfs = (r.Y * this.Size.W) + r.X; sOfs *= Bpp; var dOfs = (xy.Y * dest.Size.W) + xy.X; dOfs *= Bpp; // note: we're not factoring for Bpp mismatches here... var dataLeft = r.Size.Total * Bpp; for (int y = 0; y < r.Height; y++) { Array.Copy(_data, sOfs, dest.Data, dOfs, r.Width * Bpp); sOfs += this.Size.W * Bpp; dOfs += dest.Size.W * Bpp; } }
public static BytePixels operator +(BytePixels a, BytePixels b) { var bp = new BytePixels(new SizeInt32(a.Size.W + b.Size.W, a.Size.H > b.Size.H ? a.Size.H : b.Size.H)); bp.SetData(a); bp.SetData(b, new PointInt32(a.Size.W, 0)); return(bp); }
public TexturePlus(Texture2D t2d) : base(t2d.GraphicsDevice, t2d.Width, t2d.Height) { var wh = t2d.Width * t2d.Height; var byte4 = new Byte4[wh]; t2d.GetData <Byte4>(byte4); base.SetData <Byte4>(byte4); _dataBytes = new BytePixels(t2d.Width / 2, t2d.Height / 2, this.Convert2DData(byte4)); }
/// <summary>Gets a copy of 2D texture data in an one-dimensional byte array, specifying a source rectangle, and start index.</summary> /// <param name="rect">The section of the texture to copy. <paramref name="null"/> indicates the data will be copied from the entire texture.</param> /// <param name="data">An one-dimensional byte array.</param> /// <param name="startIndex">Index within the array of the first element (pixel) to get.</param> public void GetData(Microsoft.Xna.Framework.Rectangle?rect, BytePixels data, int startIndex) { if (rect != null) { var r = (Microsoft.Xna.Framework.Rectangle)rect; GetData(r, data, startIndex, r.Width * r.Height); return; } GetData(data); }
/// <summary>Returns a copy of 2D texture data in an one-dimensional byte array, specifying a source rectangle.</summary> /// <param name="rect">The section of the texture to copy. <paramref name="null"/> indicates the data will be copied from the entire texture.</param> public BytePixels GetData(Microsoft.Xna.Framework.Rectangle?rect) { if (rect != null) { var r = (Microsoft.Xna.Framework.Rectangle)rect; var data = new BytePixels(new SizeInt32(r.Width, r.Height), Bpp); GetData(r, data, 0, data.Size.Total); return(data); } return(GetData()); }
/// <summary>Gets a copy of 2D texture data in an one-dimensional byte array, specifying a source rectangle, start index, and number of elements.</summary> /// <param name="rect">The section of the texture to copy. <paramref name="null"/> indicates the data will be copied from the entire texture.</param> /// <param name="data">An one-dimensional byte array.</param> /// <param name="startIndex">Index within the array of the first element (pixel) to get.</param> /// <param name="elementCount">Number of elements (pixels) to get.</param> public void GetData(Microsoft.Xna.Framework.Rectangle?rect, BytePixels data, int startIndex, int elementCount) { Microsoft.Xna.Framework.Rectangle r; if (rect != null) { r = (Microsoft.Xna.Framework.Rectangle)rect; } else { GetData(data, startIndex, elementCount); return; } var sOfs = (r.Y * _dataBytes.Size.W) + r.X; sOfs *= Bpp; var dOfs = startIndex; var dataLeft = elementCount * Bpp; for (int y = 0; y < r.Height; y++) { var lineLen = r.Width * Bpp; lineLen = dataLeft < lineLen ? dataLeft : lineLen; Array.Copy(_dataBytes.Data, sOfs, data.Data, dOfs, lineLen); sOfs += _dataBytes.Size.W * Bpp; dOfs += lineLen; dataLeft -= lineLen; if (dataLeft <= 0) { break; } } }
public void SetData(RectI? rect, byte[] src, int width, int height, PointInt32 xy) { var bp = new BytePixels(width, height, src); bp.PutData(rect, this, xy); }
public void SetData(RectI? rect, BytePixels src) { src.PutData(rect, this, new PointInt32()); }
public void SetData(RectI? rect, BytePixels src, PointInt32 xy) { src.PutData(rect, this, xy); }
// PutData and its various overloads public void PutData(BytePixels dest) { PutData(null, dest); }
public void SetData(BytePixels src, PointInt32 xy) { src.PutData(null, this, xy); }
public void PutData(BytePixels dest, PointInt32 xy) { PutData(null, dest, xy); }
public static BytePixels operator +(BytePixels a, byte[] b) { var bp = new BytePixels(new SizeInt32(a.Size.W + b.Length / a.Size.H / a.Bpp, a.Size.H), a.GetData()); return(a + bp); }
public void PutData(RectI?rect, BytePixels dest) { PutData(rect, dest, new PointInt32()); }
public TexturePlus(GraphicsDevice graphicsDevice, int width, int height) : base(graphicsDevice, width, height) { _dataBytes = new BytePixels(width / 2, height / 2, this.Convert2DData()); }
public void SetData(RectI?rect, BytePixels src, PointInt32 xy) { src.PutData(rect, this, xy); }
public BytePixels AlphaBlend(BytePixels bp, bool selfIsBack = true) { return AlphaBlend(bp.GetData(), selfIsBack); }
public void SetData(RectI?rect, BytePixels src) { src.PutData(rect, this, new PointInt32()); }
/* * /// <summary>Gets a copy of all frames within 2D texture data into a two-dimensional byte array, using the specified frame size.</summary> * /// <param name="size">The pixel size of each frame.</param> * public byte[,] GetData(SizeInt32 size) * { * * } */ public void SetData(BytePixels src) { src.PutData(null, this); }
public static BytePixels operator +(BytePixels a, BytePixels b) { var bp = new BytePixels(new SizeInt32(a.Size.W + b.Size.W, a.Size.H > b.Size.H ? a.Size.H : b.Size.H)); bp.SetData(a); bp.SetData(b, new PointInt32(a.Size.W, 0)); return bp; }
/// <summary>Gets a copy of 2D texture data in an one-dimensional byte array.</summary> /// <param name="data">An one-dimensional byte array.</param> public void GetData(BytePixels data) { data = _dataBytes; }
public static BytePixels operator +(BytePixels a, byte[] b) { var bp = new BytePixels(new SizeInt32(a.Size.W + b.Length / a.Size.H / a.Bpp, a.Size.H), a.GetData()); return a + bp; }
/// <summary>Gets a copy of 2D texture data in an one-dimensional byte array, specifying a start index, and number of elements.</summary> /// <param name="data">An one-dimensional byte array.</param> /// <param name="startIndex">Index within the array of the first element (pixel) to get.</param> /// <param name="elementCount">Number of elements (pixels) to get.</param> public void GetData(BytePixels data, int startIndex, int elementCount) { Array.Copy(_dataBytes.Data, 0, data.Data, startIndex, elementCount); }
public BytePixels AlphaBlend(BytePixels bp, bool selfIsBack = true) { return(AlphaBlend(bp.GetData(), selfIsBack)); }
public void PutData(RectI? rect, BytePixels dest) { PutData(rect, dest, new PointInt32()); }
public TexturePlus(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat format) : base(graphicsDevice, width, height, mipMap, format) { _dataBytes = new BytePixels(width / 2, height / 2, this.Convert2DData()); }
/// <summary>Puts a copy of 2D pixel data in a BytePixels object, specifying a source rectangle and a destination X,Y point.</summary> /// <param name="rect">The section of the pixel data to copy. <paramref name="null"/> indicates the data will be copied from the entire object.</param> /// <param name="dest">The destination BytePixels object.</param> /// <param name="xy">The top-left corner of the destination.</param> public void PutData(RectI? rect, BytePixels dest, PointInt32 xy) { RectI r; if (rect != null) r = (RectI)rect; else r = new RectI(new PointInt32(), this.Size); var sOfs = (r.Y * this.Size.W) + r.X; sOfs *= Bpp; var dOfs = (xy.Y * dest.Size.W) + xy.X; dOfs *= Bpp; // note: we're not factoring for Bpp mismatches here... var dataLeft = r.Size.Total * Bpp; for (int y = 0; y < r.Height; y++) { Array.Copy(_data, sOfs, dest.Data, dOfs, r.Width * Bpp); sOfs += this.Size.W * Bpp; dOfs += dest.Size.W * Bpp; } }
/// <summary>Gets a copy of 2D texture data in an one-dimensional byte array, specifying a source rectangle.</summary> /// <param name="rect">The section of the texture to copy. <paramref name="null"/> indicates the data will be copied from the entire texture.</param> /// <param name="data">An one-dimensional byte array.</param> public void GetData(Microsoft.Xna.Framework.Rectangle?rect, BytePixels data) { GetData(rect, data, 0); }
/* /// <summary>Gets a copy of all frames within 2D texture data into a two-dimensional byte array, using the specified frame size.</summary> /// <param name="size">The pixel size of each frame.</param> public byte[,] GetData(SizeInt32 size) { } */ public void SetData(BytePixels src) { src.PutData(null, this); }
private BytePixels GetTextureLayer(string layerType, int y, Tile tile) { var size = 8; var sizeI = new SizeInt32(size, size); var pixels = new BytePixels(sizeI, 4); var rect00 = new RectI(0, 0, sizeI); string key = String.Empty; switch (layerType) { case "TilePixel": Color c = GetTileColor(y, tile); var b = new byte[4]; b[0] = c.B; b[1] = c.G; b[2] = c.R; b[3] = c.A; pixels = new BytePixels(1, 1, b); break; case "Wall": key = GetTileKey(y, tile, 'W'); if (textureCache.Contains(key)) return (BytePixels)textureCache.Get(key); // FIXME: A complete wall is actually 16x16 big, with 3x3 variations, depending how many tiles exist // if (tile.Wall > 0) pixels = WorldSettings.Walls[tile.Wall].Texture.GetData(new RectI(166, 58, sizeI)); // tile with most coverage (will be eventually replaced per FIXME) else { // FIXME: These are actually pretty large bitmaps // // Might need to go on a WallsBack layer... // if (y >= _world.Header.WorldBounds.Bottom - 192) pixels = WorldSettings.GlobalColors["Hell"].Texture.GetData(rect00); else if (y > _world.Header.WorldRockLayer) pixels = WorldSettings.GlobalColors["Rock"].Texture.GetData(rect00); else if (y > _world.Header.WorldSurface) pixels = WorldSettings.GlobalColors["Earth"].Texture.GetData(rect00); else pixels = WorldSettings.GlobalColors["Sky"].Texture.GetData(rect00); } break; case "TileBack": key = GetTileKey(y, tile, 'T'); if (textureCache.Contains(key)) return (BytePixels)textureCache.Get(key); // FIXME: Need XML property for larger than 8x8 sizes if (tile.IsActive && !WorldSettings.Tiles[tile.Type].IsSolid) { var rect = (WorldSettings.Tiles[tile.Type].IsFramed) ? new RectI(tile.Frame.X / 2, tile.Frame.Y / 2, sizeI) : rect00; pixels = WorldSettings.Tiles[tile.Type].Texture.GetData(rect); } break; // FIXME: NPC layer would go here... // case "TileFront": key = GetTileKey(y, tile, 'T'); if (textureCache.Contains(key)) return (BytePixels)textureCache.Get(key); // FIXME: Need XML property for larger than 8x8 sizes if (tile.IsActive && WorldSettings.Tiles[tile.Type].IsSolid) { var rect = (WorldSettings.Tiles[tile.Type].IsFramed) ? new RectI(tile.Frame.X / 2, tile.Frame.Y / 2, sizeI) : rect00; pixels = WorldSettings.Tiles[tile.Type].Texture.GetData(rect); } break; case "Liquid": key = GetTileKey(y, tile, 'L'); if (textureCache.Contains(key)) return (BytePixels)textureCache.Get(key); if (tile.Liquid > 0) { // Should use Liquid levels to determine final height // // Actually, bottom 4x4 should be for 255, and top 4x4 for anything else // if (tile.IsLava) pixels = WorldSettings.GlobalColors["Lava"].Texture.GetData(rect00); else pixels = WorldSettings.GlobalColors["Water"].Texture.GetData(rect00); } break; } // Cache policy for new cache items var cachePolicy = new CacheItemPolicy(); cachePolicy.SlidingExpiration = new TimeSpan(0, 5, 0); // 5 minute duration if not used if (shortKeyRegEx.IsMatch(key)) cachePolicy.Priority = CacheItemPriority.NotRemovable; // single unframed tiles and walls get perma-cached textureCache.Add(key, pixels, cachePolicy); return pixels; }
public void SetData(RectI?rect, byte[] src, int width, int height, PointInt32 xy) { var bp = new BytePixels(width, height, src); bp.PutData(rect, this, xy); }
public void UpdateWorldImage(RectI area, bool isRenderedLayer = false, string renderMsg = "Render Update Complete.", WriteableBitmap img = null) { // validate area area.Rebound(_world.Header.WorldBounds); int width = area.Width; int height = area.Height; int rts = isRenderedLayer ? 8 : 1; string renderProgressMsg = isRenderedLayer ? "Rendering Textured World..." : "Rendering Pixel World..."; if (img == null) img = isRenderedLayer ? _worldImage.Rendered : _worldImage.Image; var pixels = new BytePixels(area.Size * rts, 4); var stride = img.PixelWidth * img.Format.BitsPerPixel / 8; for (int x = area.X; x <= area.Right; x++) { int dx = x - area.X; if (renderMsg != null) OnProgressChanged(this, dx, width, renderProgressMsg); for (int y = area.Y; y <= area.Bottom; y++) { int dy = y - area.Y; Tile tile = _world.Tiles[x, y]; if (tile != null) { var xy = (new PointInt32(x, y) - area.TopLeft) * rts; var bp = isRenderedLayer ? GetTexture(y, tile) : GetTextureLayer("TilePixel", y, tile); bp.PutData(pixels, xy); } } } SizeInt32 ts = new SizeInt32(rts, rts); var realArea = isRenderedLayer ? new RectI(new PointInt32(), area.Size * ts) : area; // Rendered layer starts at 0,0 img.Lock(); img.WritePixels(realArea, pixels.GetData(), stride, 0); if (!isRenderedLayer) img.AddDirtyRect(realArea); img.Unlock(); if (renderMsg != null) OnProgressChanged(this, 100, 100, renderMsg); }