public unsafe Span GetPixelSpan()

in binding/SkiaSharp/SKPixmap.cs [129:172]


		public unsafe Span<T> GetPixelSpan<T> (int x, int y)
			where T : unmanaged
		{
			var info = Info;
			if (info.IsEmpty)
				return null;

			var bpp = info.BytesPerPixel;
			if (bpp <= 0)
				return null;

			var spanLength = 0;
			var spanOffset = 0;
			if (typeof (T) == typeof (byte))
			{
				// byte is always valid

				spanLength = info.BytesSize;

				if (x != 0 || y != 0)
					spanOffset = info.GetPixelBytesOffset (x, y);
			}
			else
			{
				// other types need to make sure they fit

				var size = sizeof (T);
				if (bpp != size)
					throw new ArgumentException ($"Size of T ({size}) is not the same as the size of each pixel ({bpp}).", nameof (T));

				spanLength = info.Width * info.Height;

				if (x != 0 || y != 0)
					spanOffset = y * info.Height + x;
			}

			var addr = SkiaApi.sk_pixmap_get_writable_addr (Handle);
			var span = new Span<T> (addr, spanLength);

			if (spanOffset != 0)
				span = span.Slice (spanOffset);

			return span;
		}