public LuaArgs replace(LuaArgs args) { var inColor = args.GetByte(0); var outColor = args.GetByte(1); CheckWritable(); Image.Replace(inColor, outColor); return(LuaArgs.Empty); }
public LuaArgs write(LuaArgs args) { int x = args.GetInt(0); int y = args.GetInt(1); if (args.IsNumber(2)) { var n = args.GetByte(2); CheckWritable(); if (x >= 0 && x < Image.Width && y >= 0 && y < Image.Height) { Image[x, y] = n; } return(LuaArgs.Empty); } else { var bytes = args.GetByteString(2); if (x < 0 || x >= Image.Width || y < 0 || y >= Image.Height || (x + y * Image.Width + bytes.Length) > Image.Width * Image.Height) { throw new LuaError("Write must start and end within the image bounds"); } CheckWritable(); Image.Write(bytes, 0, bytes.Length, x, y); return(LuaArgs.Empty); } }
public LuaArgs fill(LuaArgs args) { var color = args.GetByte(0); if (args.IsNil(1)) { CheckWritable(); Image.Fill(color); } else { int x = args.GetInt(1); int y = args.GetInt(2); int w = args.GetInt(3); int h = args.GetInt(4); if (w < 0) { throw new LuaError("Fill width must be positive"); } if (h < 0) { throw new LuaError("Fill height must be positive"); } if (x < 0 || x + w > Image.Width || y < 0 || y + h > Image.Height) { throw new LuaError("Fill must start and end within the image bounds"); } CheckWritable(); Image.Fill(color, x, y, w, h); } return(LuaArgs.Empty); }
public LuaArgs translate(LuaArgs args) { var x = args.GetInt(0); var y = args.GetInt(1); var fillColor = args.IsNil(2) ? (byte)0 : args.GetByte(2); CheckWritable(); Image.Translate(x, y, fillColor); return(LuaArgs.Empty); }