public static IsAreaNegativeOrEmpty ( |
||
rect | ||
Résultat | bool |
public void Apply(PixelFunctionXY pixelFunc, Rectangle region) { Rectangle rect = ClampRectangle(region, Bounds); if (Rectangle.IsAreaNegativeOrEmpty(rect)) { return; } int sourceOffset = rect.Y * ScanlineSize + rect.X * _bytesPerPixel; for (int y = 0; y < rect.Height; y++) { int lineIndex = sourceOffset + y * ScanlineSize; for (int x = 0; x < rect.Width; x++) { int index = lineIndex + x * _bytesPerPixel; Color result = pixelFunc(new Color( _data[index + 0], _data[index + 1], _data[index + 2], _data[index + 3]), rect.X + x, rect.Y + y); _data[index + 0] = result.R; _data[index + 1] = result.G; _data[index + 2] = result.B; _data[index + 3] = result.A; } } }
public void Set(TextureResource data, Point location) { if (data == null) { return; } Rectangle rect = ClampRectangle(new Rectangle(location, data.Size), Bounds); if (Rectangle.IsAreaNegativeOrEmpty(rect)) { return; } int dataScan = data.ScanlineSize; int clampScan = rect.Width * _bytesPerPixel; int sourceOffset = (rect.Y - location.Y) * dataScan + (rect.X - location.X) * _bytesPerPixel; int targetOffset = rect.Y * ScanlineSize + rect.X * _bytesPerPixel; for (int y = 0; y < rect.Height; y++) { int sourceIndex = sourceOffset + y * dataScan; int destIndex = targetOffset + y * ScanlineSize; Array.Copy(data._data, sourceIndex, _data, destIndex, clampScan); } }
public void SetComposite(TextureResource data, Point location) { Rectangle rect = ClampRectangle(new Rectangle(location, data.Size), Bounds); if (Rectangle.IsAreaNegativeOrEmpty(rect)) { return; } int dataScan = data.ScanlineSize; int clampScan = rect.Width * _bytesPerPixel; int sourceOffset = (rect.Y - location.Y) * dataScan + (rect.X - location.X) * _bytesPerPixel; int targetOffset = rect.Y * ScanlineSize + rect.X * _bytesPerPixel; for (int y = 0; y < rect.Height; y++) { for (int x = 0; x < rect.Width; x++) { int sourceIndex = sourceOffset + y * dataScan + x * _bytesPerPixel; int destIndex = targetOffset + y * ScanlineSize + x * _bytesPerPixel; float alpha = data._data[sourceIndex + 3] / 255f; _data[destIndex + 0] = (byte)(_data[destIndex + 0] * (1f - alpha) + data._data[sourceIndex + 0] * alpha); _data[destIndex + 1] = (byte)(_data[destIndex + 1] * (1f - alpha) + data._data[sourceIndex + 1] * alpha); _data[destIndex + 2] = (byte)(_data[destIndex + 2] * (1f - alpha) + data._data[sourceIndex + 2] * alpha); _data[destIndex + 3] = (byte)Math.Min(255, _data[destIndex + 3] * (1f - alpha) + data._data[sourceIndex + 3]); } } }
public TextureResource Crop(Rectangle region) { Rectangle rect = ClampRectangle(region, Bounds); if (Rectangle.IsAreaNegativeOrEmpty(rect)) { return(new TextureResource(0, 0)); } TextureResource sub = new TextureResource(rect.Width, rect.Height); int priScan = ScanlineSize; int subScan = sub.ScanlineSize; int sourceOffset = rect.Y * priScan + rect.X * _bytesPerPixel; for (int y = 0; y < rect.Height; y++) { int sourceIndex = sourceOffset + y * priScan; int destIndex = y * subScan; Array.Copy(_data, sourceIndex, sub._data, destIndex, subScan); } return(sub); }