public static void DrawLineEFLA(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, Color color, EFLAMode mode)
 {
     int a = color.A + 1;
     int col = (color.A << 24)
               | ((byte) ((color.R*a) >> 8) << 16)
               | ((byte) ((color.G*a) >> 8) << 8)
               | ((byte) ((color.B*a) >> 8));
     DrawLineEFLA(bmp, x1, y1, x2, y2, col, mode);
 }
        public static void DrawLineEFLA(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, int color, EFLAMode mode)
        {
            int w = bmp.PixelWidth;
            int h = bmp.PixelHeight;
            bmp.Lock();

            bool yLonger;
            int incrementVal, endVal;
            int shortLen;
            int longLen;

            unsafe
            {
                var pixels = (int*) bmp.BackBuffer;
                int x, y;

                switch (mode)
                {
                    case EFLAMode.Div:
                        yLonger = false;

                        shortLen = y2 - y1;
                        longLen = x2 - x1;

                        if (Math.Abs(shortLen) > Math.Abs(longLen))
                        {
                            int swap = shortLen;
                            shortLen = longLen;
                            longLen = swap;
                            yLonger = true;
                        }

                        if (longLen < 0) incrementVal = -1;
                        else incrementVal = 1;

                        double divDiff;
                        if (shortLen == 0) divDiff = longLen;
                        else divDiff = longLen/(double) shortLen;
                        if (yLonger)
                        {
                            for (int i = 0; i != longLen; i += incrementVal)
                            {
                                x = x1 + (int) (i/divDiff);
                                y = y1 + i;
                                pixels[y*w + x] = color;
                            }
                        }
                        else
                        {
                            for (int i = 0; i != longLen; i += incrementVal)
                            {
                                x = x1 + i;
                                y = y1 + (int) (i/divDiff);
                                pixels[y*w + x] = color;
                            }
                        }
                        break;
                    case EFLAMode.Mul:
                        yLonger = false;
                        shortLen = y2 - y1;
                        longLen = x2 - x1;

                        if (Math.Abs(shortLen) > Math.Abs(longLen))
                        {
                            int swap = shortLen;
                            shortLen = longLen;
                            longLen = swap;
                            yLonger = true;
                        }

                        if (longLen < 0) incrementVal = -1;
                        else incrementVal = 1;

                        double multDiff;
                        if (longLen == 0.0) multDiff = shortLen;
                        else multDiff = shortLen/(double) longLen;
                        if (yLonger)
                        {
                            for (int i = 0; i != longLen; i += incrementVal)
                            {
                                x = x1 + (int) (i*multDiff);
                                y = y1 + i;
                                pixels[y*w + x] = color;
                            }
                        }
                        else
                        {
                            for (int i = 0; i != longLen; i += incrementVal)
                            {
                                x = x1 + i;
                                y = y1 + (int) (i*multDiff);
                                pixels[y*w + x] = color;
                            }
                        }
                        break;
                    case EFLAMode.Add:
                        yLonger = false;

                        shortLen = y2 - y1;
                        longLen = x2 - x1;
                        if (Math.Abs(shortLen) > Math.Abs(longLen))
                        {
                            int swap = shortLen;
                            shortLen = longLen;
                            longLen = swap;
                            yLonger = true;
                        }

                        endVal = longLen;
                        if (longLen < 0)
                        {
                            incrementVal = -1;
                            longLen = -longLen;
                        }
                        else incrementVal = 1;

                        double decInc;
                        if (longLen == 0) decInc = shortLen;
                        else decInc = (shortLen/(double) longLen);
                        double j = 0.0;
                        if (yLonger)
                        {
                            for (int i = 0; i != endVal; i += incrementVal)
                            {
                                x = x1 + (int) j;
                                y = y1 + i;
                                pixels[y*w + x] = color;
                                j += decInc;
                            }
                        }
                        else
                        {
                            for (int i = 0; i != endVal; i += incrementVal)
                            {
                                x = x1 + i;
                                y = y1 + (int) j;
                                pixels[y*w + x] = color;
                                j += decInc;
                            }
                        }
                        break;
                    case EFLAMode.AddFixed:
                        yLonger = false;
                        shortLen = y2 - y1;
                        longLen = x2 - x1;
                        if (Math.Abs(shortLen) > Math.Abs(longLen))
                        {
                            int swap = shortLen;
                            shortLen = longLen;
                            longLen = swap;
                            yLonger = true;
                        }
                        endVal = longLen;
                        if (longLen < 0)
                        {
                            incrementVal = -1;
                            longLen = -longLen;
                        }
                        else incrementVal = 1;

                        int decIncI = 0;
                        if (longLen == 0) decInc = 0;
                        else decIncI = (shortLen << 16)/longLen;
                        int jI = 0;
                        if (yLonger)
                        {
                            for (int i = 0; i != endVal; i += incrementVal)
                            {
                                x = x1 + (jI >> 16);
                                y = y1 + i;
                                pixels[y*w + x] = color;
                                jI += decIncI;
                            }
                        }
                        else
                        {
                            for (int i = 0; i != endVal; i += incrementVal)
                            {
                                x = x1 + i;
                                y = y1 + (jI >> 16);
                                pixels[y*w + x] = color;
                                jI += decIncI;
                            }
                        }

                        break;
                    case EFLAMode.AddFixedPreCal:
                        break;
                    default:
                        throw new ArgumentOutOfRangeException("mode");
                }
            }
            bmp.AddDirtyRect(new Int32Rect(0, 0, bmp.PixelWidth, bmp.PixelHeight));
            bmp.Unlock();
        }
        public static void DrawLineEFLA(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, int color, EFLAMode mode)
        {
            int w = bmp.PixelWidth;
            int h = bmp.PixelHeight;

            bmp.Lock();

            bool yLonger;
            int  incrementVal, endVal;
            int  shortLen;
            int  longLen;

            unsafe
            {
                var pixels = (int *)bmp.BackBuffer;
                int x, y;

                switch (mode)
                {
                case EFLAMode.Div:
                    yLonger = false;

                    shortLen = y2 - y1;
                    longLen  = x2 - x1;

                    if (Math.Abs(shortLen) > Math.Abs(longLen))
                    {
                        int swap = shortLen;
                        shortLen = longLen;
                        longLen  = swap;
                        yLonger  = true;
                    }

                    if (longLen < 0)
                    {
                        incrementVal = -1;
                    }
                    else
                    {
                        incrementVal = 1;
                    }

                    double divDiff;
                    if (shortLen == 0)
                    {
                        divDiff = longLen;
                    }
                    else
                    {
                        divDiff = longLen / (double)shortLen;
                    }
                    if (yLonger)
                    {
                        for (int i = 0; i != longLen; i += incrementVal)
                        {
                            x = x1 + (int)(i / divDiff);
                            y = y1 + i;
                            pixels[y * w + x] = color;
                        }
                    }
                    else
                    {
                        for (int i = 0; i != longLen; i += incrementVal)
                        {
                            x = x1 + i;
                            y = y1 + (int)(i / divDiff);
                            pixels[y * w + x] = color;
                        }
                    }
                    break;

                case EFLAMode.Mul:
                    yLonger  = false;
                    shortLen = y2 - y1;
                    longLen  = x2 - x1;

                    if (Math.Abs(shortLen) > Math.Abs(longLen))
                    {
                        int swap = shortLen;
                        shortLen = longLen;
                        longLen  = swap;
                        yLonger  = true;
                    }

                    if (longLen < 0)
                    {
                        incrementVal = -1;
                    }
                    else
                    {
                        incrementVal = 1;
                    }

                    double multDiff;
                    if (longLen == 0.0)
                    {
                        multDiff = shortLen;
                    }
                    else
                    {
                        multDiff = shortLen / (double)longLen;
                    }
                    if (yLonger)
                    {
                        for (int i = 0; i != longLen; i += incrementVal)
                        {
                            x = x1 + (int)(i * multDiff);
                            y = y1 + i;
                            pixels[y * w + x] = color;
                        }
                    }
                    else
                    {
                        for (int i = 0; i != longLen; i += incrementVal)
                        {
                            x = x1 + i;
                            y = y1 + (int)(i * multDiff);
                            pixels[y * w + x] = color;
                        }
                    }
                    break;

                case EFLAMode.Add:
                    yLonger = false;

                    shortLen = y2 - y1;
                    longLen  = x2 - x1;
                    if (Math.Abs(shortLen) > Math.Abs(longLen))
                    {
                        int swap = shortLen;
                        shortLen = longLen;
                        longLen  = swap;
                        yLonger  = true;
                    }

                    endVal = longLen;
                    if (longLen < 0)
                    {
                        incrementVal = -1;
                        longLen      = -longLen;
                    }
                    else
                    {
                        incrementVal = 1;
                    }

                    double decInc;
                    if (longLen == 0)
                    {
                        decInc = shortLen;
                    }
                    else
                    {
                        decInc = (shortLen / (double)longLen);
                    }
                    double j = 0.0;
                    if (yLonger)
                    {
                        for (int i = 0; i != endVal; i += incrementVal)
                        {
                            x = x1 + (int)j;
                            y = y1 + i;
                            pixels[y * w + x] = color;
                            j += decInc;
                        }
                    }
                    else
                    {
                        for (int i = 0; i != endVal; i += incrementVal)
                        {
                            x = x1 + i;
                            y = y1 + (int)j;
                            pixels[y * w + x] = color;
                            j += decInc;
                        }
                    }
                    break;

                case EFLAMode.AddFixed:
                    yLonger  = false;
                    shortLen = y2 - y1;
                    longLen  = x2 - x1;
                    if (Math.Abs(shortLen) > Math.Abs(longLen))
                    {
                        int swap = shortLen;
                        shortLen = longLen;
                        longLen  = swap;
                        yLonger  = true;
                    }
                    endVal = longLen;
                    if (longLen < 0)
                    {
                        incrementVal = -1;
                        longLen      = -longLen;
                    }
                    else
                    {
                        incrementVal = 1;
                    }

                    int decIncI = 0;
                    if (longLen == 0)
                    {
                        decInc = 0;
                    }
                    else
                    {
                        decIncI = (shortLen << 16) / longLen;
                    }
                    int jI = 0;
                    if (yLonger)
                    {
                        for (int i = 0; i != endVal; i += incrementVal)
                        {
                            x = x1 + (jI >> 16);
                            y = y1 + i;
                            pixels[y * w + x] = color;
                            jI += decIncI;
                        }
                    }
                    else
                    {
                        for (int i = 0; i != endVal; i += incrementVal)
                        {
                            x = x1 + i;
                            y = y1 + (jI >> 16);
                            pixels[y * w + x] = color;
                            jI += decIncI;
                        }
                    }

                    break;

                case EFLAMode.AddFixedPreCal:
                    break;

                default:
                    throw new ArgumentOutOfRangeException("mode");
                }
            }
            bmp.AddDirtyRect(new Int32Rect(0, 0, bmp.PixelWidth, bmp.PixelHeight));
            bmp.Unlock();
        }
        public static void DrawLineEFLA(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, Color color, EFLAMode mode)
        {
            int a   = color.A + 1;
            int col = (color.A << 24)
                      | ((byte)((color.R * a) >> 8) << 16)
                      | ((byte)((color.G * a) >> 8) << 8)
                      | ((byte)((color.B * a) >> 8));

            DrawLineEFLA(bmp, x1, y1, x2, y2, col, mode);
        }