From 85aeecb1c5b59679baebc03242e5c8471b92f217 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sat, 16 Jun 2018 19:50:14 +0200 Subject: [PATCH] delete PixelAccessor --- src/ImageSharp/PixelAccessor{TPixel}.cs | 142 ------------------------ 1 file changed, 142 deletions(-) delete mode 100644 src/ImageSharp/PixelAccessor{TPixel}.cs diff --git a/src/ImageSharp/PixelAccessor{TPixel}.cs b/src/ImageSharp/PixelAccessor{TPixel}.cs deleted file mode 100644 index f4b79715b..000000000 --- a/src/ImageSharp/PixelAccessor{TPixel}.cs +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Diagnostics; -using System.Runtime.CompilerServices; -using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.Memory; - -namespace SixLabors.ImageSharp -{ - /// - /// Provides per-pixel access to generic pixels. - /// - /// The pixel format. - internal sealed class PixelAccessor : IDisposable, IBuffer2D - where TPixel : struct, IPixel - { - /// - /// Initializes a new instance of the class. - /// - /// The image to provide pixel access for. - public PixelAccessor(IPixelSource image) - { - Guard.NotNull(image, nameof(image)); - Guard.MustBeGreaterThan(image.PixelBuffer.Width, 0, "image width"); - Guard.MustBeGreaterThan(image.PixelBuffer.Height, 0, "image height"); - - this.SetPixelBufferUnsafe(image.PixelBuffer); - } - - /// - /// Gets the containing the pixel data. - /// - internal Buffer2D PixelBuffer { get; private set; } - - /// - /// Gets the size of a single pixel in the number of bytes. - /// - public int PixelSize { get; private set; } - - /// - /// Gets the width of one row in the number of bytes. - /// - public int RowStride { get; private set; } - - /// - public int Width { get; private set; } - - /// - public int Height { get; private set; } - - public IBuffer Buffer => this.PixelBuffer.Buffer; - - /// - /// Gets or sets the pixel at the specified position. - /// - /// The x-coordinate of the pixel. Must be greater than or equal to zero and less than the width of the image. - /// The y-coordinate of the pixel. Must be greater than or equal to zero and less than the height of the image. - /// The at the specified position. - public TPixel this[int x, int y] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - this.CheckCoordinates(x, y); - return this.GetSpan()[(y * this.Width) + x]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - set - { - this.CheckCoordinates(x, y); - Span span = this.GetSpan(); - span[(y * this.Width) + x] = value; - } - } - - /// - public void Dispose() - { - } - - /// - /// Resets all the pixels to it's initial value. - /// - public void Reset() - { - this.PixelBuffer.Buffer.Clear(); - } - - /// - /// Sets the pixel buffer in an unsafe manner. This should not be used unless you know what its doing!!! - /// - /// The pixels. - /// Returns the old pixel data thats has gust been replaced. - /// If is true then caller is responsible for ensuring is called. - internal Buffer2D SwapBufferOwnership(Buffer2D pixels) - { - Buffer2D oldPixels = this.PixelBuffer; - this.SetPixelBufferUnsafe(pixels); - return oldPixels; - } - - /// - /// Sets the pixel buffer in an unsafe manor this should not be used unless you know what its doing!!! - /// - /// The pixel buffer - private void SetPixelBufferUnsafe(Buffer2D pixels) - { - this.PixelBuffer = pixels; - - this.Width = pixels.Width; - this.Height = pixels.Height; - this.PixelSize = Unsafe.SizeOf(); - this.RowStride = this.Width * this.PixelSize; - } - - /// - /// Checks the coordinates to ensure they are within bounds. - /// - /// The x-coordinate of the pixel. Must be greater than zero and less than the width of the image. - /// The y-coordinate of the pixel. Must be greater than zero and less than the height of the image. - /// - /// Thrown if the coordinates are not within the bounds of the image. - /// - [Conditional("DEBUG")] - private void CheckCoordinates(int x, int y) - { - if (x < 0 || x >= this.Width) - { - throw new ArgumentOutOfRangeException(nameof(x), x, $"{x} is outwith the image bounds."); - } - - if (y < 0 || y >= this.Height) - { - throw new ArgumentOutOfRangeException(nameof(y), y, $"{y} is outwith the image bounds."); - } - } - } -} \ No newline at end of file