Beispiel #1
0
        private unsafe void ApplyLine(int *grayImageData, PointF point1, PointF point2, int lineChange)
        {
            void Plot(int x, int y, double brightness)
            {
                if (y >= _panelSize)
                {
                    return;
                }

                int pixelValueIndex = y * _panelSize + x;
                int oldPixelValue   = grayImageData[pixelValueIndex];
                int newPixelValue   = oldPixelValue - (int)(brightness * lineChange);

                grayImageData[pixelValueIndex] = newPixelValue;
            }

            XiaolinWuLineAlgorithm.PlotLine(point1.X, point1.Y, point2.X, point2.Y, Plot);
        }
Beispiel #2
0
        private int[] RemoveLine(int[] grayImageData, PointF point1, PointF point2, int lineChange)
        {
            int[] newGrayImageData = (int[])grayImageData.Clone();
            void Plot(int x, int y, double brightness)
            {
                if (y >= _panelSize)
                {
                    return;
                }

                int pixelValueIndex = y * _panelSize + x;
                int oldPixelValue   = grayImageData[pixelValueIndex];
                int newPixelValue   = Math.Min(oldPixelValue + (int)(brightness * lineChange), 255);

                newGrayImageData[pixelValueIndex] = newPixelValue;
            }

            XiaolinWuLineAlgorithm.PlotLine(point1.X, point1.Y, point2.X, point2.Y, Plot);
            return(newGrayImageData);
        }
Beispiel #3
0
        private long CalculateLineRemovalDifference(int[] grayImageData, PointF point1, PointF point2, int lineChange, byte[] comparisonByteArray)
        {
            long difference = 0;

            void Plot(int x, int y, double brightness)
            {
                if (y >= _panelSize)
                {
                    return;
                }

                int pixelValueIndex = y * _panelSize + x;

                int  oldPixelValue     = grayImageData[pixelValueIndex];
                byte oldPixelValueByte = (byte)Math.Max(oldPixelValue, 0);

                int  newPixelValue     = Math.Min(grayImageData[pixelValueIndex] + (int)(brightness * lineChange), 255);
                byte newPixelValueByte =
                    (byte)Math.Max(newPixelValue, 0);


                byte targetPixelValue = comparisonByteArray[pixelValueIndex];

                int oldTargetDiff = Math.Abs(oldPixelValueByte - targetPixelValue);
                int newTargetDiff = Math.Abs(newPixelValueByte - targetPixelValue);

                int delta = oldTargetDiff - newTargetDiff;

                if (delta < 0)
                {
                    delta = (int)(delta * 1.25d);
                }

                difference += delta;
            }

            XiaolinWuLineAlgorithm.PlotLine(point1.X, point1.Y, point2.X, point2.Y, Plot);
            return(difference);
        }