public unsafe static int[] LineValues(this Image image, int line)
        {
            if (line < 0 || line > image.Height)
            {
                throw new ArgumentException("That line is not possible");
            }

            ImagePlane plane = image.Planes[0];

            var size   = plane.Parent.Size;
            var access = plane.GetLinearAccess();

            var xInc  = access.XInc.ToInt64();
            var yInc  = access.YInc.ToInt64();
            var pBase = (byte *)access.BasePtr;

            int y = line;

            int[] lineValues = new int[size.Width];
            for (int x = 0; x < size.Width; x++)
            {
                var pPixel = pBase + x * xInc + y * yInc;
                lineValues[x] = *pPixel;
            }

            return(lineValues);
        }
Ejemplo n.º 2
0
        public unsafe PixelHelper(ImagePlane plane)
        {
            Size   = plane.Parent.Size;
            Access = plane.GetLinearAccess <byte>();

            XInc  = Access.XInc.ToInt64();
            YInc  = Access.YInc.ToInt64();
            PBase = (byte *)Access.BasePtr;
        }
        public static unsafe int[] ToHistogram(this ImagePlane plane)
        {
            var histogram = new int[byte.MaxValue + 1];

            var size   = plane.Parent.Size;
            var access = plane.GetLinearAccess();

            var xInc  = access.XInc.ToInt64();
            var yInc  = access.YInc.ToInt64();
            var pBase = (byte *)access.BasePtr;

            for (int y = 0; y < size.Height; y++)
            {
                for (int x = 0; x < size.Width; x++)
                {
                    var pPixel = pBase + x * xInc + y * yInc;
                    ++histogram[*pPixel];
                }
            }
            return(histogram);
        }