public unsafe override void Generate(RGBA_Bytes *span, int x, int y, uint len)
        {
            RasterBuffer          pSourceRenderingBuffer = base.Source().PixelFormat.GetRenderingBuffer();
            ISpanInterpolator <T> spanInterpolator       = base.Interpolator;

            spanInterpolator.Begin(M.New <T>(x).Add(base.FilterDxDbl()), M.New <T>(y).Add(base.FilterDyDbl()), len);
            do
            {
                int x_hr;
                int y_hr;
                spanInterpolator.Coordinates(out x_hr, out y_hr);
                int   x_lr   = x_hr >> (int)image_subpixel_scale_e.Shift;
                int   y_lr   = y_hr >> (int)image_subpixel_scale_e.Shift;
                byte *fg_ptr = pSourceRenderingBuffer.GetPixelPointer(y_lr) + (x_lr << 2);
                //byte* fg_ptr = spanInterpolator.span(x_lr, y_lr, 1);


                //(*span).R = fg_ptr[OrderR];
                //(*span).G = fg_ptr[OrderG];
                //(*span).B = fg_ptr[OrderB];
                //(*span).A = fg_ptr[OrderA];


                (*span) = new RGBA_Bytes(fg_ptr[OrderR], fg_ptr[OrderG], fg_ptr[OrderB], fg_ptr[OrderA]);

                ++span;
                spanInterpolator.Next();
            } while (--len != 0);
        }
        public override void GenerateColors(ColorRGBA[] outputColors, int startIndex, int x, int y, int len)
        {
            int bytesBetweenPixelsInclusive    = srcRW.BytesBetweenPixelsInclusive;
            ISpanInterpolator spanInterpolator = Interpolator;

            spanInterpolator.Begin(x + dx, y + dy, len);
            int x_hr;
            int y_hr;

            spanInterpolator.GetCoord(out x_hr, out y_hr);
            int x_lr = x_hr >> img_subpix_const.SHIFT;
            int y_lr = y_hr >> img_subpix_const.SHIFT;
            int bufferIndex;

            bufferIndex = srcRW.GetBufferOffsetXY(x_lr, y_lr);
            byte[] srcBuff = srcRW.GetBuffer();
            unsafe
            {
                fixed(byte *pSource = srcBuff)
                {
                    do
                    {
                        outputColors[startIndex].red   = pSource[bufferIndex];
                        outputColors[startIndex].green = pSource[bufferIndex];
                        outputColors[startIndex].blue  = pSource[bufferIndex];
                        outputColors[startIndex].alpha = 255;
                        startIndex++;
                        bufferIndex += bytesBetweenPixelsInclusive;
                    } while (--len != 0);
                }
            }
        }
Example #3
0
        //--------------------------------------------------------------------
        public unsafe void Generate(RGBA_Bytes *span, int x, int y, uint len)
        {
            int dd = m_d2 - m_d1;

            if (dd < 1)
            {
                dd = 1;
            }
            m_interpolator.Begin(x + 0.5, y + 0.5, len);
            do
            {
                m_interpolator.Coordinates(out x, out y);
                int d = m_gradient_function.Calculate(x >> downscale_shift,
                                                      y >> downscale_shift, m_d2);
                d = ((d - m_d1) * (int)m_color_function.Size) / dd;
                if (d < 0)
                {
                    d = 0;
                }
                if (d >= (int)m_color_function.Size)
                {
                    d = m_color_function.Size - 1;
                }

                *span++ = m_color_function[d];
                m_interpolator.Next();
            }while(--len != 0);
        }
Example #4
0
        public override void GenerateColors(ColorRGBA[] outputColors, int startIndex, int x, int y, int len)
        {
            ISpanInterpolator spanInterpolator = Interpolator;

            spanInterpolator.Begin(x + dx, y + dy, len);
            int x_hr;
            int y_hr;

            spanInterpolator.GetCoord(out x_hr, out y_hr);
            int x_lr        = x_hr >> img_subpix_const.SHIFT;
            int y_lr        = y_hr >> img_subpix_const.SHIFT;
            int bufferIndex = srcRW.GetBufferOffsetXY(x_lr, y_lr);

            byte[] srcBuff = srcRW.GetBuffer();

            ColorRGBA color = ColorRGBA.White;

            do
            {
                color.blue  = srcBuff[bufferIndex++];
                color.green = srcBuff[bufferIndex++];
                color.red   = srcBuff[bufferIndex++];

                outputColors[startIndex++] = color;
            } while (--len != 0);
        }
Example #5
0
        public override void GenerateColors(ColorRGBA[] outputColors, int startIndex, int x, int y, int len)
        {
            ISpanInterpolator spanInterpolator = Interpolator;

            spanInterpolator.Begin(x + dx, y + dy, len);
            int x_hr;
            int y_hr;

            spanInterpolator.GetCoord(out x_hr, out y_hr);
            int x_lr = x_hr >> img_subpix_const.SHIFT;
            int y_lr = y_hr >> img_subpix_const.SHIFT;

            int bufferIndex = srcRW.GetBufferOffsetXY(x_lr, y_lr);

            byte[] srcBuffer = srcRW.GetBuffer();

            unsafe
            {
                fixed(byte *pSource = srcBuffer)
                {
                    do
                    {
                        outputColors[startIndex++] = *(ColorRGBA *)&(pSource[bufferIndex]);
                        bufferIndex += 4;
                    } while (--len != 0);
                }
            }
        }
Example #6
0
        //--------------------------------------------------------------------
        public void GenerateColors(ColorRGBA[] outputColors, int startIndex, int x, int y, int len)
        {
            m_interpolator.Begin(x + 0.5, y + 0.5, len);

            do
            {
                m_interpolator.GetCoord(out x, out y);
                float d = m_grValueCalculator.Calculate(x >> DOWN_SCALE_SHIFT,
                                                        y >> DOWN_SCALE_SHIFT,
                                                        m_d2);

                d = ((d - m_d1) * stepRatio);

                if (d < 0)
                {
                    d = 0;
                }
                if (d >= m_colorsProvider.GradientSteps)
                {
                    d = m_colorsProvider.GradientSteps - 1;
                }

                outputColors[startIndex++] = m_colorsProvider.GetColor((int)d);
                m_interpolator.Next();
            }while (--len != 0);
        }
Example #7
0
 public static void SubPixTranslateBeginCoord(this ISpanInterpolator interpolator,
                                              double inX, double inY,
                                              out int outX, out int outY)
 {
     interpolator.Begin(inX, inY, 1);
     interpolator.GetCoord(out int x_hr, out int y_hr);
     //get translate version
     outX = x_hr >> subpix_const.SHIFT;
     outY = y_hr >> subpix_const.SHIFT;
 }
Example #8
0
 public static void TranslateBeginCoord(this ISpanInterpolator interpolator,
                                        double inX, double inY,
                                        out int outX, out int outY,
                                        int shift)
 {
     interpolator.Begin(inX, inY, 1);
     interpolator.GetCoord(out int x_hr, out int y_hr);
     //get translate version
     outX = x_hr >> shift;
     outY = y_hr >> shift;
 }
Example #9
0
        //public void SubDivShift(int shift)
        //{
        //    m_subdiv_shift = shift;
        //    m_subdiv_size = 1 << m_subdiv_shift;
        //    m_subdiv_mask = m_subdiv_size - 1;
        //}

        //----------------------------------------------------------------
        public void Begin(T x, T y, uint len)
        {
            m_pos   = 1;
            m_src_x = Basics.RoundInt(x.Multiply((SubPixelScale))) + SubPixelScale;
            m_src_y = y;
            m_len   = len;
            if (len > m_subdiv_size)
            {
                len = (uint)m_subdiv_size;
            }
            m_interpolator.Begin(x, y, len);
        }
Example #10
0
 //----------------------------------------------------------------
 public void Begin(double x, double y, uint len)
 {
     m_pos   = 1;
     m_src_x = Basics.Round(x * subpixel_scale) + subpixel_scale;
     m_src_y = y;
     m_len   = len;
     if (len > m_subdiv_size)
     {
         len = (uint)m_subdiv_size;
     }
     m_interpolator.Begin(x, y, len);
 }
Example #11
0
        public override void GenerateColors(Drawing.Color[] outputColors, int startIndex, int x, int y, int len)
        {
            if (_noTransformation)
            {
                //Interpolator.GetCoord(out int x_hr, out int y_hr);
                //int x_lr = x_hr >> subpix_const.SHIFT;
                //int y_lr = y_hr >> subpix_const.SHIFT;

                Interpolator.SubPixTranslateBeginCoord(x + dx, y + dy, out int x_lr, out int y_lr);
                NN_StepXBy1(_bmpSrc, _bmpSrc.GetBufferOffsetXY32(x_lr, y_lr), outputColors, startIndex, len);
            }
            else
            {
                ISpanInterpolator spanInterpolator = Interpolator;
                spanInterpolator.Begin(x + dx, y + dy, len);
                unsafe
                {
                    using (TempMemPtr.FromBmp(_bmpSrc, out int *srcBuffer))
                    {
                        //TODO: if no any transformation,=> skip spanInterpolator (see above example)
                        do
                        {
                            //spanInterpolator.GetCoord(out int x_hr, out int y_hr);
                            //int x_lr = x_hr >> subpix_const.SHIFT;
                            //int y_lr = y_hr >> subpix_const.SHIFT;

                            spanInterpolator.SubPixGetTranslatedCoord(out int x_lr, out int y_lr);

                            int bufferIndex = _bmpSrc.GetBufferOffsetXY32(x_lr, y_lr);

                            int srcColor = srcBuffer[bufferIndex++];

                            outputColors[startIndex] = Drawing.Color.FromArgb(
                                (srcColor >> CO.A_SHIFT) & 0xff,   //a
                                (srcColor >> CO.R_SHIFT) & 0xff,   //r
                                (srcColor >> CO.G_SHIFT) & 0xff,   //g
                                (srcColor >> CO.B_SHIFT) & 0xff);  //b

                            ++startIndex;
                            spanInterpolator.Next();
                        } while (--len != 0);
                    }
                }
            }
        }
Example #12
0
        public sealed override void GenerateColors(Drawing.Color[] outputColors, int startIndex, int x, int y, int len)
        {
            int bytesBetweenPixelsInclusive    = srcRW.BytesBetweenPixelsInclusive;
            ISpanInterpolator spanInterpolator = Interpolator;

            spanInterpolator.Begin(x + dx, y + dy, len);
            int x_hr;
            int y_hr;

            spanInterpolator.GetCoord(out x_hr, out y_hr);
            int x_lr = x_hr >> img_subpix_const.SHIFT;
            int y_lr = y_hr >> img_subpix_const.SHIFT;
            int bufferIndex;

            bufferIndex = srcRW.GetByteBufferOffsetXY(x_lr, y_lr);

            unsafe
            {
                TempMemPtr srcBuffPtr = srcRW.GetBufferPtr();
                byte *     pSource    = (byte *)srcBuffPtr.Ptr;
                {
                    do
                    {
                        //outputColors[startIndex].red = pSource[bufferIndex];
                        //outputColors[startIndex].green = pSource[bufferIndex];
                        //outputColors[startIndex].blue = pSource[bufferIndex];
                        //outputColors[startIndex].alpha = 255;

                        byte grayValue = pSource[bufferIndex];
                        outputColors[startIndex] = Drawing.Color.FromArgb(255,
                                                                          grayValue,
                                                                          grayValue,
                                                                          grayValue);

                        startIndex++;
                        bufferIndex += bytesBetweenPixelsInclusive;
                    } while (--len != 0);
                }
                srcBuffPtr.Release();
            }
        }
Example #13
0
        public unsafe override void Generate(RGBA_Bytes *span, int x, int y, uint len)
        {
            RasterBuffer      pSourceRenderingBuffer = base.source().PixelFormat.RenderingBuffer;
            ISpanInterpolator spanInterpolator       = base.interpolator();

            spanInterpolator.Begin(x + base.filter_dx_dbl(), y + base.filter_dy_dbl(), len);
            do
            {
                int x_hr;
                int y_hr;
                spanInterpolator.Coordinates(out x_hr, out y_hr);
                int   x_lr   = x_hr >> (int)image_subpixel_scale_e.Shift;
                int   y_lr   = y_hr >> (int)image_subpixel_scale_e.Shift;
                byte *fg_ptr = pSourceRenderingBuffer.GetPixelPointer(y_lr) + (x_lr << 2);
                //byte* fg_ptr = spanInterpolator.Span(x_lr, y_lr, 1);
                (*span).m_R = fg_ptr[OrderR];
                (*span).m_G = fg_ptr[OrderG];
                (*span).m_B = fg_ptr[OrderB];
                (*span).m_A = fg_ptr[OrderA];
                ++span;
                spanInterpolator.Next();
            } while(--len != 0);
        }
        //--------------------------------------------------------------------
        public unsafe override void Generate(RGBA_Bytes *span, int x, int y, uint len)
        {
            ISpanInterpolator spanInterpolator = base.interpolator();

            spanInterpolator.Begin(x + base.filter_dx_dbl(), y + base.filter_dy_dbl(), len);

            int *fg = stackalloc int[4];

            byte *fg_ptr;

            fixed(short *pWeightArray = filter().weight_array())
            {
                int diameter     = (int)base.filter().diameter();
                int filter_scale = diameter << (int)image_subpixel_scale_e.Shift;

                short *weight_array = pWeightArray;

                do
                {
                    int rx;
                    int ry;
                    int rx_inv = (int)image_subpixel_scale_e.Scale;
                    int ry_inv = (int)image_subpixel_scale_e.Scale;
                    spanInterpolator.Coordinates(out x, out y);
                    spanInterpolator.LocalScale(out rx, out ry);
                    base.AdjustScale(ref rx, ref ry);

                    rx_inv = (int)image_subpixel_scale_e.Scale * (int)image_subpixel_scale_e.Scale / rx;
                    ry_inv = (int)image_subpixel_scale_e.Scale * (int)image_subpixel_scale_e.Scale / ry;

                    int radius_x = (diameter * rx) >> 1;
                    int radius_y = (diameter * ry) >> 1;
                    int len_x_lr =
                        (diameter * rx + (int)image_subpixel_scale_e.Mask) >>
                        (int)(int)image_subpixel_scale_e.Shift;

                    x += base.filter_dx_int() - radius_x;
                    y += base.filter_dy_int() - radius_y;

                    fg[0] = fg[1] = fg[2] = fg[3] = (int)image_filter_scale_e.Scale / 2;

                    int y_lr = y >> (int)(int)image_subpixel_scale_e.Shift;
                    int y_hr = (((int)image_subpixel_scale_e.Mask - (y & (int)image_subpixel_scale_e.Mask)) *
                                ry_inv) >>
                               (int)(int)image_subpixel_scale_e.Shift;
                    int total_weight = 0;
                    int x_lr         = x >> (int)(int)image_subpixel_scale_e.Shift;
                    int x_hr         = (((int)image_subpixel_scale_e.Mask - (x & (int)image_subpixel_scale_e.Mask)) *
                                        rx_inv) >>
                                       (int)(int)image_subpixel_scale_e.Shift;
                    int x_hr2 = x_hr;
                    fg_ptr = base.source().Span(x_lr, y_lr, (uint)len_x_lr);

                    for (; ;)
                    {
                        int weight_y = weight_array[y_hr];
                        x_hr = x_hr2;
                        for (; ;)
                        {
                            int weight = (weight_y * weight_array[x_hr] +
                                          (int)image_filter_scale_e.Scale / 2) >>
                                         downscale_shift;
                            fg[0]        += *fg_ptr++ *weight;
                            fg[1]        += *fg_ptr++ *weight;
                            fg[2]        += *fg_ptr++ *weight;
                            fg[3]        += *fg_ptr++ *weight;
                            total_weight += weight;
                            x_hr         += rx_inv;
                            if (x_hr >= filter_scale)
                            {
                                break;
                            }
                            fg_ptr = base.source().NextX();
                        }
                        y_hr += ry_inv;
                        if (y_hr >= filter_scale)
                        {
                            break;
                        }

                        fg_ptr = base.source().NextY();
                    }

                    fg[0] /= total_weight;
                    fg[1] /= total_weight;
                    fg[2] /= total_weight;
                    fg[3] /= total_weight;

                    if (fg[0] < 0)
                    {
                        fg[0] = 0;
                    }
                    if (fg[1] < 0)
                    {
                        fg[1] = 0;
                    }
                    if (fg[2] < 0)
                    {
                        fg[2] = 0;
                    }
                    if (fg[3] < 0)
                    {
                        fg[3] = 0;
                    }

                    if (fg[0] > fg[0])
                    {
                        fg[0] = fg[0];
                    }
                    if (fg[1] > fg[1])
                    {
                        fg[1] = fg[1];
                    }
                    if (fg[2] > fg[2])
                    {
                        fg[2] = fg[2];
                    }
                    if (fg[3] > base_mask)
                    {
                        fg[3] = base_mask;
                    }

                    span->R_Byte = (byte)fg[OrderR];
                    span->G_Byte = (byte)fg[OrderG];
                    span->B_Byte = (byte)fg[OrderB];
                    span->A_Byte = (byte)fg[OrderA];

                    ++span;
                    interpolator().Next();
                } while (--len != 0);
            }
        }
        //--------------------------------------------------------------------
        public unsafe override void Generate(RGBA_Bytes *span, int x, int y, uint len)
        {
            ISpanInterpolator <T> spanInterpolator = base.Interpolator;

            spanInterpolator.Begin(M.New <T>(x).Add(base.FilterDxDbl()), M.New <T>(y).Add(base.FilterDyDbl()), len);

            int *fg = stackalloc int[3];

            byte *fg_ptr;

            fixed(short *pWeightArray = Filter.WeightArray())
            {
                short *weight_array = pWeightArray;

                weight_array = &pWeightArray[((Filter.Diameter() / 2 - 1) << (int)image_subpixel_scale_e.Shift)];

                do
                {
                    int x_hr;
                    int y_hr;

                    spanInterpolator.Coordinates(out x_hr, out y_hr);

                    x_hr -= FilterDxInt();
                    y_hr -= FilterDyInt();

                    int x_lr = x_hr >> (int)image_subpixel_scale_e.Shift;
                    int y_lr = y_hr >> (int)image_subpixel_scale_e.Shift;

                    uint weight;
                    fg[0] = fg[1] = fg[2] = (int)image_filter_scale_e.Scale / 2;

                    x_hr &= (int)image_subpixel_scale_e.Mask;
                    y_hr &= (int)image_subpixel_scale_e.Mask;

                    fg_ptr = Source().span(x_lr, y_lr, 2);
                    weight = (uint)((weight_array[x_hr + (int)image_subpixel_scale_e.Scale] *
                                     weight_array[y_hr + (int)image_subpixel_scale_e.Scale] +
                                     (int)image_filter_scale_e.Scale / 2) >>
                                    (int)image_filter_scale_e.Shift);
                    fg[0] += (int)weight * *fg_ptr++;
                    fg[1] += (int)weight * *fg_ptr++;
                    fg[2] += (int)weight * *fg_ptr;

                    fg_ptr = Source().next_x();
                    weight = (uint)((weight_array[x_hr] *
                                     weight_array[y_hr + (int)image_subpixel_scale_e.Scale] +
                                     (int)image_filter_scale_e.Scale / 2) >>
                                    (int)image_filter_scale_e.Shift);
                    fg[0] += (int)weight * *fg_ptr++;
                    fg[1] += (int)weight * *fg_ptr++;
                    fg[2] += (int)weight * *fg_ptr;

                    fg_ptr = Source().next_y();
                    weight = (uint)((weight_array[x_hr + (int)image_subpixel_scale_e.Scale] *
                                     weight_array[y_hr] +
                                     (int)image_filter_scale_e.Scale / 2) >>
                                    (int)image_filter_scale_e.Shift);
                    fg[0] += (int)weight * *fg_ptr++;
                    fg[1] += (int)weight * *fg_ptr++;
                    fg[2] += (int)weight * *fg_ptr;

                    fg_ptr = Source().next_x();
                    weight = (uint)((weight_array[x_hr] *
                                     weight_array[y_hr] +
                                     (int)image_filter_scale_e.Scale / 2) >>
                                    (int)image_filter_scale_e.Shift);
                    fg[0] += (int)weight * *fg_ptr++;
                    fg[1] += (int)weight * *fg_ptr++;
                    fg[2] += (int)weight * *fg_ptr;

                    fg[0] >>= (int)image_filter_scale_e.Shift;
                    fg[1] >>= (int)image_filter_scale_e.Shift;
                    fg[2] >>= (int)image_filter_scale_e.Shift;

                    if (fg[OrderR] > BaseMask)
                    {
                        fg[OrderR] = BaseMask;
                    }
                    if (fg[OrderG] > BaseMask)
                    {
                        fg[OrderG] = BaseMask;
                    }
                    if (fg[OrderB] > BaseMask)
                    {
                        fg[OrderB] = BaseMask;
                    }

                    //span->R_Byte = (byte)fg[OrderR];
                    //span->G_Byte = (byte)fg[OrderG];
                    //span->B_Byte = (byte)fg[OrderB];
                    //span->A_Byte = (uint)BaseMask;

                    (*span) = new RGBA_Bytes((byte)fg[OrderR], (byte)fg[OrderG], (byte)fg[OrderB], (uint)BaseMask);

                    ++span;
                    spanInterpolator.Next();
                } while (--len != 0);
            }
        }
        //--------------------------------------------------------------------
        public unsafe override void Generate(RGBA_Bytes *span, int x, int y, uint len)
        {
            ISpanInterpolator spanInterpolator = base.interpolator();

            spanInterpolator.Begin(x + base.filter_dx_dbl(), y + base.filter_dy_dbl(), len);

            int *fg = stackalloc int[3];

            byte *fg_ptr;

            fixed(short *pWeightArray = filter().weight_array())
            {
                short *weight_array = pWeightArray;

                weight_array = &pWeightArray[((filter().diameter() / 2 - 1) << (int)image_subpixel_scale_e.Shift)];

                do
                {
                    int x_hr;
                    int y_hr;

                    spanInterpolator.Coordinates(out x_hr, out y_hr);

                    x_hr -= filter_dx_int();
                    y_hr -= filter_dy_int();

                    int x_lr = x_hr >> (int)image_subpixel_scale_e.Shift;
                    int y_lr = y_hr >> (int)image_subpixel_scale_e.Shift;

                    uint weight;
                    fg[0] = fg[1] = fg[2] = (int)image_filter_scale_e.Scale / 2;

                    x_hr &= (int)image_subpixel_scale_e.Mask;
                    y_hr &= (int)image_subpixel_scale_e.Mask;

                    fg_ptr = source().Span(x_lr, y_lr, 2);
                    weight = (uint)((weight_array[x_hr + (int)image_subpixel_scale_e.Scale] *
                                     weight_array[y_hr + (int)image_subpixel_scale_e.Scale] +
                                     (int)image_filter_scale_e.Scale / 2) >>
                                    (int)image_filter_scale_e.Shift);
                    fg[0] += (int)weight * *fg_ptr++;
                    fg[1] += (int)weight * *fg_ptr++;
                    fg[2] += (int)weight * *fg_ptr;

                    fg_ptr = source().NextX();
                    weight = (uint)((weight_array[x_hr] *
                                     weight_array[y_hr + (int)image_subpixel_scale_e.Scale] +
                                     (int)image_filter_scale_e.Scale / 2) >>
                                    (int)image_filter_scale_e.Shift);
                    fg[0] += (int)weight * *fg_ptr++;
                    fg[1] += (int)weight * *fg_ptr++;
                    fg[2] += (int)weight * *fg_ptr;

                    fg_ptr = source().NextY();
                    weight = (uint)((weight_array[x_hr + (int)image_subpixel_scale_e.Scale] *
                                     weight_array[y_hr] +
                                     (int)image_filter_scale_e.Scale / 2) >>
                                    (int)image_filter_scale_e.Shift);
                    fg[0] += (int)weight * *fg_ptr++;
                    fg[1] += (int)weight * *fg_ptr++;
                    fg[2] += (int)weight * *fg_ptr;

                    fg_ptr = source().NextX();
                    weight = (uint)((weight_array[x_hr] *
                                     weight_array[y_hr] +
                                     (int)image_filter_scale_e.Scale / 2) >>
                                    (int)image_filter_scale_e.Shift);
                    fg[0] += (int)weight * *fg_ptr++;
                    fg[1] += (int)weight * *fg_ptr++;
                    fg[2] += (int)weight * *fg_ptr;

                    fg[0] >>= (int)image_filter_scale_e.Shift;
                    fg[1] >>= (int)image_filter_scale_e.Shift;
                    fg[2] >>= (int)image_filter_scale_e.Shift;

                    if (fg[OrderR] > base_mask)
                    {
                        fg[OrderR] = base_mask;
                    }
                    if (fg[OrderG] > base_mask)
                    {
                        fg[OrderG] = base_mask;
                    }
                    if (fg[OrderB] > base_mask)
                    {
                        fg[OrderB] = base_mask;
                    }

                    span->R_Byte = (byte)fg[OrderR];
                    span->G_Byte = (byte)fg[OrderG];
                    span->B_Byte = (byte)fg[OrderB];
                    span->A_Byte = (uint)base_mask;

                    ++span;
                    spanInterpolator.Next();
                } while (--len != 0);
            }
        }
        //--------------------------------------------------------------------
        public unsafe override void Generate(RGBA_Bytes *span, int x, int y, uint len)
        {
            ISpanInterpolator <T> spanInterpolator = base.Interpolator;

            spanInterpolator.Begin(M.New <T>(x).Add(base.FilterDxDbl()), M.New <T>(y).Add(base.FilterDyDbl()), len);

            int *fg = stackalloc int[3];

            byte *fg_ptr;

            fixed(short *pWeightArray = Filter.WeightArray())
            {
                int diameter     = (int)base.Filter.Diameter();
                int filter_scale = diameter << (int)image_subpixel_scale_e.Shift;

                short *weight_array = pWeightArray;

                do
                {
                    int rx;
                    int ry;
                    int rx_inv = (int)image_subpixel_scale_e.Scale;
                    int ry_inv = (int)image_subpixel_scale_e.Scale;
                    spanInterpolator.Coordinates(out x, out y);
                    spanInterpolator.LocalScale(out rx, out ry);
                    base.AdjustScale(ref rx, ref ry);

                    rx_inv = (int)image_subpixel_scale_e.Scale * (int)image_subpixel_scale_e.Scale / rx;
                    ry_inv = (int)image_subpixel_scale_e.Scale * (int)image_subpixel_scale_e.Scale / ry;

                    int radius_x = (diameter * rx) >> 1;
                    int radius_y = (diameter * ry) >> 1;
                    int len_x_lr =
                        (diameter * rx + (int)image_subpixel_scale_e.Mask) >>
                        (int)(int)image_subpixel_scale_e.Shift;

                    x += base.FilterDxInt() - radius_x;
                    y += base.FilterDyInt() - radius_y;

                    fg[0] = fg[1] = fg[2] = (int)image_filter_scale_e.Scale / 2;

                    int y_lr = y >> (int)(int)image_subpixel_scale_e.Shift;
                    int y_hr = (((int)image_subpixel_scale_e.Mask - (y & (int)image_subpixel_scale_e.Mask)) *
                                ry_inv) >>
                               (int)(int)image_subpixel_scale_e.Shift;
                    int total_weight = 0;
                    int x_lr         = x >> (int)(int)image_subpixel_scale_e.Shift;
                    int x_hr         = (((int)image_subpixel_scale_e.Mask - (x & (int)image_subpixel_scale_e.Mask)) *
                                        rx_inv) >>
                                       (int)(int)image_subpixel_scale_e.Shift;
                    int x_hr2 = x_hr;
                    fg_ptr = base.Source().span(x_lr, y_lr, (uint)len_x_lr);

                    for (; ;)
                    {
                        int weight_y = weight_array[y_hr];
                        x_hr = x_hr2;
                        for (; ;)
                        {
                            int weight = (weight_y * weight_array[x_hr] +
                                          (int)image_filter_scale_e.Scale / 2) >>
                                         DownscaleShift;
                            fg[0]        += *fg_ptr++ *weight;
                            fg[1]        += *fg_ptr++ *weight;
                            fg[2]        += *fg_ptr++ *weight;
                            total_weight += weight;
                            x_hr         += rx_inv;
                            if (x_hr >= filter_scale)
                            {
                                break;
                            }
                            fg_ptr = base.Source().next_x();
                        }
                        y_hr += ry_inv;
                        if (y_hr >= filter_scale)
                        {
                            break;
                        }

                        fg_ptr = base.Source().next_y();
                    }

                    fg[0] /= total_weight;
                    fg[1] /= total_weight;
                    fg[2] /= total_weight;

                    if (fg[0] < 0)
                    {
                        fg[0] = 0;
                    }
                    if (fg[1] < 0)
                    {
                        fg[1] = 0;
                    }
                    if (fg[2] < 0)
                    {
                        fg[2] = 0;
                    }

                    if (fg[0] > fg[0])
                    {
                        fg[0] = fg[0];
                    }
                    if (fg[1] > fg[1])
                    {
                        fg[1] = fg[1];
                    }
                    if (fg[2] > fg[2])
                    {
                        fg[2] = fg[2];
                    }

                    //span->R_Byte = (byte)fg[OrderR];
                    //span->G_Byte = (byte)fg[OrderG];
                    //span->B_Byte = (byte)fg[OrderB];
                    //span->A_Byte = (byte)BaseMask;

                    (*span) = new RGBA_Bytes((byte)fg[OrderR], (byte)fg[OrderG], (byte)fg[OrderB], (byte)BaseMask);

                    ++span;
                    Interpolator.Next();
                } while (--len != 0);
            }
        }
        public override void GenerateColors(ColorRGBA[] outputColors, int startIndex, int x, int y, int len)
        {
            ISpanInterpolator spanInterpolator = base.Interpolator;

            spanInterpolator.Begin(x + base.dx, y + base.dy, len);
            int c0, c1, c2;
            int diameter     = base.FilterLookup.Diameter;
            int filter_scale = diameter << img_subpix_const.SHIFT;

            int[] weight_array = FilterLookup.WeightArray;
            do
            {
                int rx;
                int ry;
                int rx_inv = img_subpix_const.SCALE;
                int ry_inv = img_subpix_const.SCALE;
                spanInterpolator.GetCoord(out x, out y);
                spanInterpolator.GetLocalScale(out rx, out ry);
                AdjustScale(ref rx, ref ry);
                rx_inv = img_subpix_const.SCALE * img_subpix_const.SCALE / rx;
                ry_inv = img_subpix_const.SCALE * img_subpix_const.SCALE / ry;
                int radius_x = (diameter * rx) >> 1;
                int radius_y = (diameter * ry) >> 1;
                int len_x_lr =
                    (diameter * rx + img_subpix_const.MASK) >>
                    img_subpix_const.SHIFT;
                x += base.dxInt - radius_x;
                y += base.dyInt - radius_y;
                c0 = c1 = c2 = img_filter_const.SCALE / 2;
                int y_lr = y >> img_subpix_const.SHIFT;
                int y_hr = ((img_subpix_const.MASK - (y & img_subpix_const.MASK)) *
                            ry_inv) >> img_subpix_const.SHIFT;
                int total_weight = 0;
                int x_lr         = x >> img_subpix_const.SHIFT;
                int x_hr         = ((img_subpix_const.MASK - (x & img_subpix_const.MASK)) *
                                    rx_inv) >> img_subpix_const.SHIFT;
                int    x_hr2 = x_hr;
                int    sourceIndex;
                byte[] buff = BaseGetSpan(x_lr, y_lr, len_x_lr, out sourceIndex);
                for (;;)
                {
                    int weight_y = weight_array[y_hr];
                    x_hr = x_hr2;
                    for (;;)
                    {
                        int weight = (weight_y * weight_array[x_hr] +
                                      (int)img_filter_const.SCALE / 2) >>
                                     DOWNSCALE_SHIFT;
                        c0           += buff[sourceIndex + CO.R] * weight;
                        c1           += buff[sourceIndex + CO.G] * weight;
                        c2           += buff[sourceIndex + CO.B] * weight;
                        total_weight += weight;
                        x_hr         += rx_inv;
                        if (x_hr >= filter_scale)
                        {
                            break;
                        }
                        buff = BaseNextX(out sourceIndex);
                    }
                    y_hr += ry_inv;
                    if (y_hr >= filter_scale)
                    {
                        break;
                    }

                    buff = BaseNextY(out sourceIndex);
                }

                c0 /= total_weight;
                c1 /= total_weight;
                c2 /= total_weight;
                //clamps..
                if (c0 < 0)
                {
                    c0 = 0;
                }
                else if (c0 > BASE_MASK)
                {
                    c0 = BASE_MASK;
                }

                if (c1 < 0)
                {
                    c1 = 0;
                }
                else if (c1 > BASE_MASK)
                {
                    c1 = BASE_MASK;
                }

                if (c2 < 0)
                {
                    c2 = 0;
                }
                else if (c2 > BASE_MASK)
                {
                    c2 = BASE_MASK;
                }


                outputColors[startIndex].alpha = BASE_MASK;
                outputColors[startIndex].red   = (byte)c0;
                outputColors[startIndex].green = (byte)c1;
                outputColors[startIndex].blue  = (byte)c2;
                startIndex++;
                spanInterpolator.Next();
            } while (--len != 0);
        }
        public override void GenerateColors(ColorRGBA[] outputColors, int startIndex, int x, int y, int len)
        {
            ISpanInterpolator spanInterpolator = base.Interpolator;

            spanInterpolator.Begin(x + base.dx, y + base.dy, len);
            int accColor0, accColor1, accColor2;
            int sourceAlpha;
            int back_r = m_bgcolor.red;
            int back_g = m_bgcolor.green;
            int back_b = m_bgcolor.blue;
            int back_a = m_bgcolor.alpha;
            int bufferIndex;
            int maxx = (int)srcRW.Width - 1;
            int maxy = (int)srcRW.Height - 1;

            byte[] srcBuffer = srcRW.GetBuffer();
            unchecked
            {
                do
                {
                    int x_hr;
                    int y_hr;
                    spanInterpolator.GetCoord(out x_hr, out y_hr);
                    x_hr -= base.dxInt;
                    y_hr -= base.dyInt;
                    int x_lr = x_hr >> img_subpix_const.SHIFT;
                    int y_lr = y_hr >> img_subpix_const.SHIFT;
                    int weight;
                    if (x_lr >= 0 && y_lr >= 0 &&
                        x_lr < maxx && y_lr < maxy)
                    {
                        accColor0         =
                            accColor1     =
                                accColor2 = img_subpix_const.SCALE * img_subpix_const.SCALE / 2;
                        x_hr       &= img_subpix_const.MASK;
                        y_hr       &= img_subpix_const.MASK;
                        bufferIndex = srcRW.GetBufferOffsetXY(x_lr, y_lr);
                        weight      = ((img_subpix_const.SCALE - x_hr) *
                                       (img_subpix_const.SCALE - y_hr));
                        accColor0   += weight * srcBuffer[bufferIndex + CO.R];
                        accColor1   += weight * srcBuffer[bufferIndex + CO.G];
                        accColor2   += weight * srcBuffer[bufferIndex + CO.B];
                        bufferIndex += 3;
                        weight       = (x_hr * (img_subpix_const.SCALE - y_hr));
                        accColor0   += weight * srcBuffer[bufferIndex + CO.R];
                        accColor1   += weight * srcBuffer[bufferIndex + CO.G];
                        accColor2   += weight * srcBuffer[bufferIndex + CO.B];
                        y_lr++;
                        bufferIndex  = srcRW.GetBufferOffsetXY(x_lr, y_lr);
                        weight       = ((img_subpix_const.SCALE - x_hr) * y_hr);
                        accColor0   += weight * srcBuffer[bufferIndex + CO.R];
                        accColor1   += weight * srcBuffer[bufferIndex + CO.G];
                        accColor2   += weight * srcBuffer[bufferIndex + CO.B];
                        bufferIndex += 3;
                        weight       = (x_hr * y_hr);
                        accColor0   += weight * srcBuffer[bufferIndex + CO.R];
                        accColor1   += weight * srcBuffer[bufferIndex + CO.G];
                        accColor2   += weight * srcBuffer[bufferIndex + CO.B];
                        accColor0  >>= img_subpix_const.SHIFT * 2;
                        accColor1  >>= img_subpix_const.SHIFT * 2;
                        accColor2  >>= img_subpix_const.SHIFT * 2;
                        sourceAlpha  = BASE_MASK;
                    }
                    else
                    {
                        if (x_lr < -1 || y_lr < -1 ||
                            x_lr > maxx || y_lr > maxy)
                        {
                            accColor0   = back_r;
                            accColor1   = back_g;
                            accColor2   = back_b;
                            sourceAlpha = back_a;
                        }
                        else
                        {
                            accColor0         =
                                accColor1     =
                                    accColor2 = img_subpix_const.SCALE * img_subpix_const.SCALE / 2;
                            sourceAlpha       = img_subpix_const.SCALE * img_subpix_const.SCALE / 2;
                            x_hr  &= img_subpix_const.MASK;
                            y_hr  &= img_subpix_const.MASK;
                            weight = ((img_subpix_const.SCALE - x_hr) * (img_subpix_const.SCALE - y_hr));
                            if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                            {
                                BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref sourceAlpha,
                                                   srcRW.GetBuffer(),
                                                   srcRW.GetBufferOffsetXY(x_lr, y_lr),
                                                   weight);
                            }
                            else
                            {
                                accColor0   += back_r * weight;
                                accColor1   += back_g * weight;
                                accColor2   += back_b * weight;
                                sourceAlpha += back_a * weight;
                            }
                            x_lr++;
                            weight = (x_hr * (img_subpix_const.SCALE - y_hr));
                            if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                            {
                                BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref sourceAlpha,
                                                   srcRW.GetBuffer(),
                                                   srcRW.GetBufferOffsetXY(x_lr, y_lr),
                                                   weight);
                            }
                            else
                            {
                                accColor0   += back_r * weight;
                                accColor1   += back_g * weight;
                                accColor2   += back_b * weight;
                                sourceAlpha += back_a * weight;
                            }

                            x_lr--;
                            y_lr++;
                            weight = ((img_subpix_const.SCALE - x_hr) * y_hr);
                            if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                            {
                                BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref sourceAlpha,
                                                   srcRW.GetBuffer(),
                                                   srcRW.GetBufferOffsetXY(x_lr, y_lr),
                                                   weight);
                            }
                            else
                            {
                                accColor0   += back_r * weight;
                                accColor1   += back_g * weight;
                                accColor2   += back_b * weight;
                                sourceAlpha += back_a * weight;
                            }

                            x_lr++;
                            weight = (x_hr * y_hr);
                            if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                            {
                                BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref sourceAlpha,
                                                   srcRW.GetBuffer(),
                                                   srcRW.GetBufferOffsetXY(x_lr, y_lr),
                                                   weight);
                            }
                            else
                            {
                                accColor0   += back_r * weight;
                                accColor1   += back_g * weight;
                                accColor2   += back_b * weight;
                                sourceAlpha += back_a * weight;
                            }
                            accColor0   >>= img_subpix_const.SHIFT * 2;
                            accColor1   >>= img_subpix_const.SHIFT * 2;
                            accColor2   >>= img_subpix_const.SHIFT * 2;
                            sourceAlpha >>= img_subpix_const.SHIFT * 2;
                        }
                    }

                    outputColors[startIndex].red   = (byte)accColor0;
                    outputColors[startIndex].green = (byte)accColor1;
                    outputColors[startIndex].blue  = (byte)accColor2;
                    outputColors[startIndex].alpha = (byte)sourceAlpha;
                    startIndex++;
                    spanInterpolator.Next();
                } while (--len != 0);
            }
        }
Example #20
0
        //--------------------------------------------------------------------
        public void GenerateColors(Color[] outputColors, int startIndex, int x, int y, int spanLen)
        {
            //set interpolation start point
            //spanLen => horizontal span len
#if COSMOS
#else
            _interpolator.Begin(_grad0X + _xoffset + x + 0.5, _grad0Y + _yoffset + y + 0.5, spanLen);
            int gradientSteps = _colorsProvider.GradientSteps;

            int scanline_x = x;

            do
            {
                //find actual x and y
                _interpolator.GetCoord(out x, out y);

                float d = _grValueCalculator.Calculate(x >> DOWN_SCALE_SHIFT,
                                                       y >> DOWN_SCALE_SHIFT,
                                                       _dist) * _stepRatio;
                if (d < 0)
                {
                    if (PartNo == 0)
                    {
                        d = 0;
                    }
                    else
                    {
                        //move to prev part
                        d = 0;

                        //move to next part
                        if (RequestGradientPart != null)
                        {
                            GradientSpanGen nextPart = RequestGradientPart(this.PartNo - 1);
                            if (nextPart != null)
                            {
                                //generate next part
                                nextPart.GenerateColors(outputColors, startIndex, scanline_x, y, spanLen);
                                return;
                            }
                        }
                        else
                        {
                            d = 0;
                        }
                    }
                }
                else if (d >= gradientSteps)
                {
                    if (IsLastPart)
                    {
                        d = gradientSteps - 1;
                    }
                    else
                    {
                        //move to next part
                        if (RequestGradientPart != null)
                        {
                            GradientSpanGen nextPart = RequestGradientPart(this.PartNo + 1);
                            if (nextPart != null)
                            {
                                //generate next part
                                nextPart.GenerateColors(outputColors, startIndex, scanline_x, y, spanLen);
                                return;
                            }
                        }
                        else
                        {
                            d = gradientSteps - 1;
                        }
                    }
                }
                else
                {
                    //
                }
                outputColors[startIndex++] = _colorsProvider.GetColor((int)d);
                _interpolator.Next();//**
                scanline_x++;
            }while (--spanLen != 0);
#endif
        }
Example #21
0
        public sealed override void GenerateColors(Drawing.Color[] outputColors, int startIndex, int x, int y, int len)
        {
#if DEBUG
            int tmp_len = len;
#endif
            unsafe
            {
                //TODO: review here

                if (_mode0)
                {
                    using (CpuBlit.Imaging.TempMemPtr.FromBmp(_imgsrc, out int *srcBuffer))
                    {
                        int bufferIndex = _imgsrc.GetBufferOffsetXY32(x, y);
                        //unsafe
                        {
#if true
                            do
                            {
                                //TODO: review here, match component?
                                //ORDER IS IMPORTANT!
                                //TODO : use CO (color order instead)
                                int color = srcBuffer[bufferIndex++];

                                //byte b = (byte)srcBuffer[bufferIndex++];
                                //byte g = (byte)srcBuffer[bufferIndex++];
                                //byte r = (byte)srcBuffer[bufferIndex++];
                                //byte a = (byte)srcBuffer[bufferIndex++];

                                //outputColors[startIndex] = Drawing.Color.FromArgb(a, r, g, b);
                                outputColors[startIndex] = Drawing.Color.FromArgb(
                                    (color >> 24) & 0xff, //a
                                    (color >> 16) & 0xff, //r
                                    (color >> 8) & 0xff,  //b
                                    (color) & 0xff        //b
                                    );

                                ++startIndex;
                            } while (--len != 0);
#else
                            fixed(byte *pSource = &fg_ptr[bufferIndex])
                            {
                                int *pSourceInt = (int *)pSource;

                                fixed(RGBA_Bytes *pDest = &span[spanIndex])
                                {
                                    int *pDestInt = (int *)pDest;

                                    do
                                    {
                                        *pDestInt++ = *pSourceInt++;
                                    } while (--len != 0);
                                }
                            }
#endif
                        }
                    }
                }
                else
                {
                    ISpanInterpolator spanInterpolator = base.Interpolator;
                    using (CpuBlit.Imaging.TempMemPtr srcBufferPtr = _imgsrc.GetBufferPtr())
                    {
                        int *srcBuffer = (int *)srcBufferPtr.Ptr;

                        spanInterpolator.Begin(x + base.dx, y + base.dy, len);
                        int accColor0, accColor1, accColor2, accColor3;
                        int back_r = m_bgcolor.red;
                        int back_g = m_bgcolor.green;
                        int back_b = m_bgcolor.blue;
                        int back_a = m_bgcolor.alpha;
                        int maxx   = _imgsrc.Width - 1;
                        int maxy   = _imgsrc.Height - 1;
                        int color  = 0;

                        unchecked
                        {
                            do
                            {
                                int x_hr;
                                int y_hr;
                                spanInterpolator.GetCoord(out x_hr, out y_hr);
                                x_hr -= base.dxInt;
                                y_hr -= base.dyInt;
                                int x_lr = x_hr >> img_subpix_const.SHIFT;
                                int y_lr = y_hr >> img_subpix_const.SHIFT;
                                int weight;
                                if (x_lr >= 0 && y_lr >= 0 &&
                                    x_lr < maxx && y_lr < maxy)
                                {
                                    int bufferIndex = _imgsrc.GetBufferOffsetXY32(x_lr, y_lr);


                                    accColor0             =
                                        accColor1         =
                                            accColor2     =
                                                accColor3 = (int)img_subpix_const.SCALE * (int)img_subpix_const.SCALE / 2;

                                    x_hr &= img_subpix_const.MASK;
                                    y_hr &= img_subpix_const.MASK;

                                    //bufferIndex = _imgsrc.GetBufferOffsetXY32(x_lr, y_lr);

                                    weight = ((img_subpix_const.SCALE - x_hr) *
                                              (img_subpix_const.SCALE - y_hr));
                                    if (weight > BASE_MASK)
                                    {
                                        color = srcBuffer[bufferIndex];

                                        accColor3 += weight * ((color >> 24) & 0xff); //a
                                        accColor0 += weight * ((color >> 16) & 0xff); //r
                                        accColor1 += weight * ((color >> 8) & 0xff);  //g
                                        accColor2 += weight * ((color) & 0xff);       //b
                                    }

                                    weight = (x_hr * ((int)img_subpix_const.SCALE - y_hr));
                                    if (weight > BASE_MASK)
                                    {
                                        bufferIndex++;
                                        color = srcBuffer[bufferIndex];
                                        //
                                        accColor3 += weight * ((color >> 24) & 0xff); //a
                                        accColor0 += weight * ((color >> 16) & 0xff); //r
                                        accColor1 += weight * ((color >> 8) & 0xff);  //g
                                        accColor2 += weight * ((color) & 0xff);       //b
                                    }

                                    weight = (((int)img_subpix_const.SCALE - x_hr) * y_hr);
                                    if (weight > BASE_MASK)
                                    {
                                        ++y_lr;
                                        //
                                        bufferIndex = _imgsrc.GetBufferOffsetXY32(x_lr, y_lr);
                                        color       = srcBuffer[bufferIndex];
                                        //
                                        accColor3 += weight * ((color >> 24) & 0xff); //a
                                        accColor0 += weight * ((color >> 16) & 0xff); //r
                                        accColor1 += weight * ((color >> 8) & 0xff);  //g
                                        accColor2 += weight * ((color) & 0xff);       //b
                                    }
                                    weight = (x_hr * y_hr);
                                    if (weight > BASE_MASK)
                                    {
                                        bufferIndex++;
                                        color = srcBuffer[bufferIndex];
                                        //
                                        accColor3 += weight * ((color >> 24) & 0xff); //a
                                        accColor0 += weight * ((color >> 16) & 0xff); //r
                                        accColor1 += weight * ((color >> 8) & 0xff);  //g
                                        accColor2 += weight * ((color) & 0xff);       //b
                                    }
                                    accColor0 >>= img_subpix_const.SHIFT * 2;
                                    accColor1 >>= img_subpix_const.SHIFT * 2;
                                    accColor2 >>= img_subpix_const.SHIFT * 2;
                                    accColor3 >>= img_subpix_const.SHIFT * 2;
                                }
                                else
                                {
                                    if (x_lr < -1 || y_lr < -1 ||
                                        x_lr > maxx || y_lr > maxy)
                                    {
                                        accColor0 = back_r;
                                        accColor1 = back_g;
                                        accColor2 = back_b;
                                        accColor3 = back_a;
                                    }
                                    else
                                    {
                                        accColor0             =
                                            accColor1         =
                                                accColor2     =
                                                    accColor3 = (int)img_subpix_const.SCALE * (int)img_subpix_const.SCALE / 2;
                                        x_hr  &= (int)img_subpix_const.MASK;
                                        y_hr  &= (int)img_subpix_const.MASK;
                                        weight = (((int)img_subpix_const.SCALE - x_hr) *
                                                  ((int)img_subpix_const.SCALE - y_hr));
                                        if (weight > BASE_MASK)
                                        {
                                            if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                                            {
                                                BlendInFilterPixel(
                                                    ref accColor0, ref accColor1, ref accColor2, ref accColor3,
                                                    srcBuffer,
                                                    _imgsrc.GetBufferOffsetXY32(x_lr, y_lr),
                                                    weight);
                                            }
                                            else
                                            {
                                                accColor0 += back_r * weight;
                                                accColor1 += back_g * weight;
                                                accColor2 += back_b * weight;
                                                accColor3 += back_a * weight;
                                            }
                                        }

                                        x_lr++;
                                        weight = (x_hr * ((int)img_subpix_const.SCALE - y_hr));
                                        if (weight > BASE_MASK)
                                        {
                                            if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                                            {
                                                BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3,
                                                                   srcBuffer,
                                                                   _imgsrc.GetBufferOffsetXY32(x_lr, y_lr),
                                                                   weight);
                                            }
                                            else
                                            {
                                                accColor0 += back_r * weight;
                                                accColor1 += back_g * weight;
                                                accColor2 += back_b * weight;
                                                accColor3 += back_a * weight;
                                            }
                                        }

                                        x_lr--;
                                        y_lr++;
                                        weight = (((int)img_subpix_const.SCALE - x_hr) * y_hr);
                                        if (weight > BASE_MASK)
                                        {
                                            if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                                            {
                                                BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3,
                                                                   srcBuffer,
                                                                   _imgsrc.GetBufferOffsetXY32(x_lr, y_lr),
                                                                   weight);
                                            }
                                            else
                                            {
                                                accColor0 += back_r * weight;
                                                accColor1 += back_g * weight;
                                                accColor2 += back_b * weight;
                                                accColor3 += back_a * weight;
                                            }
                                        }

                                        x_lr++;
                                        weight = (x_hr * y_hr);
                                        if (weight > BASE_MASK)
                                        {
                                            if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                                            {
                                                BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3,
                                                                   srcBuffer,
                                                                   _imgsrc.GetBufferOffsetXY32(x_lr, y_lr),
                                                                   weight);
                                            }
                                            else
                                            {
                                                accColor0 += back_r * weight;
                                                accColor1 += back_g * weight;
                                                accColor2 += back_b * weight;
                                                accColor3 += back_a * weight;
                                            }
                                        }

                                        accColor0 >>= img_subpix_const.SHIFT * 2;
                                        accColor1 >>= img_subpix_const.SHIFT * 2;
                                        accColor2 >>= img_subpix_const.SHIFT * 2;
                                        accColor3 >>= img_subpix_const.SHIFT * 2;
                                    }
                                }

#if DEBUG
                                if (startIndex >= outputColors.Length)
                                {
                                }
#endif
                                outputColors[startIndex] = PixelFarm.Drawing.Color.FromArgb(
                                    (byte)accColor3,
                                    (byte)accColor0,
                                    (byte)accColor1,
                                    (byte)accColor2
                                    );

                                //outputColors[startIndex].red = (byte)accColor0;
                                //outputColors[startIndex].green = (byte)accColor1;
                                //outputColors[startIndex].blue = (byte)accColor2;
                                //outputColors[startIndex].alpha = (byte)accColor3;
                                ++startIndex;
                                spanInterpolator.Next();
                            } while (--len != 0);
                        }
                    }
                }
            }
        }
Example #22
0
        public override void GenerateColors(Color[] outputColors, int startIndex, int x, int y, int len)
        {
            ISpanInterpolator spanInterpolator = this.Interpolator;

            int acc_r, acc_g, acc_b, acc_a;
            int diameter = _lut.Diameter;
            int start    = _lut.Start;

            int[] weight_array = _lut.WeightArray;

            int x_count;
            int weight_y;

            unsafe
            {
                using (CpuBlit.TempMemPtr srcBufferPtr = _bmpSrc.GetBufferPtr())
                {
                    int *srcBuffer = (int *)srcBufferPtr.Ptr;
                    spanInterpolator.Begin(x + base.dx, y + base.dy, len);

                    do
                    {
                        spanInterpolator.GetCoord(out x, out y);

                        x -= base.dxInt;
                        y -= base.dyInt;

                        int x_hr = x;
                        int y_hr = y;

                        int x_lr = x_hr >> subpix_const.SHIFT;
                        int y_lr = y_hr >> subpix_const.SHIFT;

                        //accumualted color components
                        acc_r             =
                            acc_g         =
                                acc_b     =
                                    acc_a = filter_const.SCALE / 2;


                        int x_fract = x_hr & subpix_const.MASK;
                        int y_count = diameter;

                        y_hr = subpix_const.MASK - (y_hr & subpix_const.MASK);
                        int bufferIndex = _bmpSrc.GetBufferOffsetXY32(x_lr, y_lr);

                        int tmp_Y = y_lr;
                        for (; ;)
                        {
                            x_count  = diameter;
                            weight_y = weight_array[y_hr];
                            x_hr     = subpix_const.MASK - x_fract;

                            //-------------------
                            for (; ;)
                            {
                                int weight = (weight_y * weight_array[x_hr] +
                                              filter_const.SCALE / 2) >>
                                             filter_const.SHIFT;

                                int srcColor = srcBuffer[bufferIndex];

                                acc_a += weight * ((srcColor >> CO.A_SHIFT) & 0xff); //a
                                acc_r += weight * ((srcColor >> CO.R_SHIFT) & 0xff); //r
                                acc_g += weight * ((srcColor >> CO.G_SHIFT) & 0xff); //g
                                acc_b += weight * ((srcColor >> CO.B_SHIFT) & 0xff); //b

                                if (--x_count == 0)
                                {
                                    break;                 //for
                                }
                                x_hr += subpix_const.SCALE;
                                bufferIndex++;
                            }
                            //-------------------

                            if (--y_count == 0)
                            {
                                break;
                            }
                            y_hr += subpix_const.SCALE;

                            tmp_Y++; //move down to next row-> and find start bufferIndex
                            bufferIndex = _bmpSrc.GetBufferOffsetXY32(x_lr, tmp_Y);
                        }

                        acc_r >>= filter_const.SHIFT;
                        acc_g >>= filter_const.SHIFT;
                        acc_b >>= filter_const.SHIFT;
                        acc_a >>= filter_const.SHIFT;

                        unchecked
                        {
                            if ((uint)acc_r > BASE_MASK)
                            {
                                if (acc_r < 0)
                                {
                                    acc_r = 0;
                                }
                                if (acc_r > BASE_MASK)
                                {
                                    acc_r = BASE_MASK;
                                }
                            }

                            if ((uint)acc_g > BASE_MASK)
                            {
                                if (acc_g < 0)
                                {
                                    acc_g = 0;
                                }
                                if (acc_g > BASE_MASK)
                                {
                                    acc_g = BASE_MASK;
                                }
                            }

                            if ((uint)acc_b > BASE_MASK)
                            {
                                if (acc_b < 0)
                                {
                                    acc_b = 0;
                                }
                                if (acc_b > BASE_MASK)
                                {
                                    acc_b = BASE_MASK;
                                }
                            }

                            if ((uint)acc_a > BASE_MASK)
                            {
                                if (acc_a < 0)
                                {
                                    acc_a = 0;
                                }
                                if (acc_a > BASE_MASK)
                                {
                                    acc_a = BASE_MASK;
                                }
                            }
                        }
                        outputColors[startIndex] = PixelFarm.Drawing.Color.FromArgb(
                            (byte)acc_a,    //a
                            (byte)acc_r,
                            (byte)acc_g,
                            (byte)acc_b);

                        startIndex++;

                        spanInterpolator.Next();
                    } while (--len != 0);
                }
            }
        }
Example #23
0
        public sealed override void GenerateColors(Drawing.Color[] outputColors, int startIndex, int x, int y, int len)
        {
#if DEBUG
            int tmp_len = len;
#endif
            unsafe
            {
                //TODO: review here

                if (_noTransformation)
                {
                    using (CpuBlit.TempMemPtr.FromBmp(_bmpSrc, out int *srcBuffer))
                    {
                        int bufferIndex = _bmpSrc.GetBufferOffsetXY32(x, y);
                        do
                        {
                            //TODO: review here, match component?
                            //ORDER IS IMPORTANT!
                            //TODO : use CO (color order instead)
                            int srcColor = srcBuffer[bufferIndex++];
                            outputColors[startIndex] = Drawing.Color.FromArgb(
                                (srcColor >> CO.A_SHIFT) & 0xff,  //a
                                (srcColor >> CO.R_SHIFT) & 0xff,  //r
                                (srcColor >> CO.G_SHIFT) & 0xff,  //g
                                (srcColor >> CO.B_SHIFT) & 0xff); //b

                            ++startIndex;
                        } while (--len != 0);
                    }
                }
                else
                {
                    //Bilinear interpolation, without lookup table
                    ISpanInterpolator spanInterpolator = base.Interpolator;
                    using (CpuBlit.TempMemPtr srcBufferPtr = _bmpSrc.GetBufferPtr())
                    {
                        int *srcBuffer = (int *)srcBufferPtr.Ptr;

                        spanInterpolator.Begin(x + base.dx, y + base.dy, len);

                        //accumulated color component
                        int acc_r, acc_g, acc_b, acc_a;

                        Color bgColor  = this.BackgroundColor;
                        int   back_r   = bgColor.R;
                        int   back_g   = bgColor.G;
                        int   back_b   = bgColor.B;
                        int   back_a   = bgColor.A;
                        int   maxx     = _bmpSrc.Width - 1;
                        int   maxy     = _bmpSrc.Height - 1;
                        int   srcColor = 0;

                        do
                        {
                            int x_hr;
                            int y_hr;
                            spanInterpolator.GetCoord(out x_hr, out y_hr);
                            x_hr -= base.dxInt;
                            y_hr -= base.dyInt;

                            int x_lr = x_hr >> subpix_const.SHIFT;
                            int y_lr = y_hr >> subpix_const.SHIFT;
                            int weight;

                            if (x_lr >= 0 && y_lr >= 0 &&
                                x_lr < maxx && y_lr < maxy)
                            {
                                int bufferIndex = _bmpSrc.GetBufferOffsetXY32(x_lr, y_lr);

                                //accumulated color components
                                acc_r             =
                                    acc_g         =
                                        acc_b     =
                                            acc_a = subpix_const.SCALE * subpix_const.SCALE / 2;

                                x_hr &= subpix_const.MASK;
                                y_hr &= subpix_const.MASK;


                                weight = (subpix_const.SCALE - x_hr) * (subpix_const.SCALE - y_hr);

                                if (weight > BASE_MASK)
                                {
                                    srcColor = srcBuffer[bufferIndex];

                                    acc_a += weight * ((srcColor >> CO.A_SHIFT) & 0xff); //a
                                    acc_r += weight * ((srcColor >> CO.R_SHIFT) & 0xff); //r
                                    acc_g += weight * ((srcColor >> CO.G_SHIFT) & 0xff); //g
                                    acc_b += weight * ((srcColor >> CO.B_SHIFT) & 0xff); //b
                                }

                                weight = (x_hr * (subpix_const.SCALE - y_hr));

                                if (weight > BASE_MASK)
                                {
                                    bufferIndex++;
                                    srcColor = srcBuffer[bufferIndex];
                                    //
                                    acc_a += weight * ((srcColor >> CO.A_SHIFT) & 0xff); //a
                                    acc_r += weight * ((srcColor >> CO.R_SHIFT) & 0xff); //r
                                    acc_g += weight * ((srcColor >> CO.G_SHIFT) & 0xff); //g
                                    acc_b += weight * ((srcColor >> CO.B_SHIFT) & 0xff); //b
                                }

                                weight = ((subpix_const.SCALE - x_hr) * y_hr);

                                if (weight > BASE_MASK)
                                {
                                    ++y_lr;
                                    //
                                    bufferIndex = _bmpSrc.GetBufferOffsetXY32(x_lr, y_lr);
                                    srcColor    = srcBuffer[bufferIndex];
                                    //
                                    acc_a += weight * ((srcColor >> CO.A_SHIFT) & 0xff); //a
                                    acc_r += weight * ((srcColor >> CO.R_SHIFT) & 0xff); //r
                                    acc_g += weight * ((srcColor >> CO.G_SHIFT) & 0xff); //g
                                    acc_b += weight * ((srcColor >> CO.B_SHIFT) & 0xff); //b
                                }

                                weight = (x_hr * y_hr);

                                if (weight > BASE_MASK)
                                {
                                    bufferIndex++;
                                    srcColor = srcBuffer[bufferIndex];
                                    //
                                    acc_a += weight * ((srcColor >> CO.A_SHIFT) & 0xff); //a
                                    acc_r += weight * ((srcColor >> CO.R_SHIFT) & 0xff); //r
                                    acc_g += weight * ((srcColor >> CO.G_SHIFT) & 0xff); //g
                                    acc_b += weight * ((srcColor >> CO.B_SHIFT) & 0xff); //b
                                }
                                acc_r >>= subpix_const.SHIFT * 2;
                                acc_g >>= subpix_const.SHIFT * 2;
                                acc_b >>= subpix_const.SHIFT * 2;
                                acc_a >>= subpix_const.SHIFT * 2;
                            }
                            else
                            {
                                if (x_lr < -1 || y_lr < -1 ||
                                    x_lr > maxx || y_lr > maxy)
                                {
                                    acc_r = back_r;
                                    acc_g = back_g;
                                    acc_b = back_b;
                                    acc_a = back_a;
                                }
                                else
                                {
                                    acc_r             =
                                        acc_g         =
                                            acc_b     =
                                                acc_a = subpix_const.SCALE * subpix_const.SCALE / 2;

                                    x_hr &= subpix_const.MASK;
                                    y_hr &= subpix_const.MASK;

                                    weight = (subpix_const.SCALE - x_hr) * (subpix_const.SCALE - y_hr);

                                    if (weight > BASE_MASK)
                                    {
                                        if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                                        {
                                            srcColor = srcBuffer[_bmpSrc.GetBufferOffsetXY32(x_lr, y_lr)];
                                            //
                                            acc_a += weight * ((srcColor >> CO.A_SHIFT) & 0xff); //a
                                            acc_r += weight * ((srcColor >> CO.R_SHIFT) & 0xff); //r
                                            acc_g += weight * ((srcColor >> CO.G_SHIFT) & 0xff); //g
                                            acc_b += weight * ((srcColor >> CO.B_SHIFT) & 0xff); //b
                                        }
                                        else
                                        {
                                            acc_r += back_r * weight;
                                            acc_g += back_g * weight;
                                            acc_b += back_b * weight;
                                            acc_a += back_a * weight;
                                        }
                                    }

                                    x_lr++;
                                    weight = x_hr * (subpix_const.SCALE - y_hr);
                                    if (weight > BASE_MASK)
                                    {
                                        if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                                        {
                                            srcColor = srcBuffer[_bmpSrc.GetBufferOffsetXY32(x_lr, y_lr)];
                                            //
                                            acc_a += weight * ((srcColor >> CO.A_SHIFT) & 0xff); //a
                                            acc_r += weight * ((srcColor >> CO.R_SHIFT) & 0xff); //r
                                            acc_g += weight * ((srcColor >> CO.G_SHIFT) & 0xff); //g
                                            acc_b += weight * ((srcColor >> CO.B_SHIFT) & 0xff); //b
                                        }
                                        else
                                        {
                                            acc_r += back_r * weight;
                                            acc_g += back_g * weight;
                                            acc_b += back_b * weight;
                                            acc_a += back_a * weight;
                                        }
                                    }

                                    x_lr--;
                                    y_lr++;
                                    weight = (subpix_const.SCALE - x_hr) * y_hr;
                                    if (weight > BASE_MASK)
                                    {
                                        if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                                        {
                                            srcColor = srcBuffer[_bmpSrc.GetBufferOffsetXY32(x_lr, y_lr)];
                                            //
                                            acc_a += weight * ((srcColor >> CO.A_SHIFT) & 0xff); //a
                                            acc_r += weight * ((srcColor >> CO.R_SHIFT) & 0xff); //r
                                            acc_g += weight * ((srcColor >> CO.G_SHIFT) & 0xff); //g
                                            acc_b += weight * ((srcColor >> CO.B_SHIFT) & 0xff); //b
                                        }
                                        else
                                        {
                                            acc_r += back_r * weight;
                                            acc_g += back_g * weight;
                                            acc_b += back_b * weight;
                                            acc_a += back_a * weight;
                                        }
                                    }

                                    x_lr++;
                                    weight = (x_hr * y_hr);
                                    if (weight > BASE_MASK)
                                    {
                                        if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                                        {
                                            srcColor = srcBuffer[_bmpSrc.GetBufferOffsetXY32(x_lr, y_lr)];
                                            //
                                            acc_a += weight * ((srcColor >> CO.A_SHIFT) & 0xff); //a
                                            acc_r += weight * ((srcColor >> CO.R_SHIFT) & 0xff); //r
                                            acc_g += weight * ((srcColor >> CO.G_SHIFT) & 0xff); //g
                                            acc_b += weight * ((srcColor >> CO.B_SHIFT) & 0xff); //b
                                        }
                                        else
                                        {
                                            acc_r += back_r * weight;
                                            acc_g += back_g * weight;
                                            acc_b += back_b * weight;
                                            acc_a += back_a * weight;
                                        }
                                    }

                                    acc_r >>= subpix_const.SHIFT * 2;
                                    acc_g >>= subpix_const.SHIFT * 2;
                                    acc_b >>= subpix_const.SHIFT * 2;
                                    acc_a >>= subpix_const.SHIFT * 2;
                                }
                            }

#if DEBUG
                            if (startIndex >= outputColors.Length)
                            {
                            }
#endif
                            outputColors[startIndex] = PixelFarm.Drawing.Color.FromArgb(
                                (byte)acc_a,
                                (byte)acc_r,
                                (byte)acc_g,
                                (byte)acc_b
                                );

                            ++startIndex;
                            spanInterpolator.Next();
                        } while (--len != 0);
                    } //using
                }     //else
            }         //unsafe
        }
Example #24
0
        public sealed override void GenerateColors(Drawing.Color[] outputColors, int startIndex, int x, int y, int len)
        {
            ISpanInterpolator spanInterpolator = Interpolator;

            spanInterpolator.Begin(x + dx, y + dy, len);
            int x_hr;
            int y_hr;

            spanInterpolator.GetCoord(out x_hr, out y_hr);
            int x_lr = x_hr >> img_subpix_const.SHIFT;
            int y_lr = y_hr >> img_subpix_const.SHIFT;

            int bufferIndex = _bmpSrc.GetBufferOffsetXY32(x_lr, y_lr);

            unsafe
            {
                using (CpuBlit.Imaging.TempMemPtr srcBufferPtr = _bmpSrc.GetBufferPtr())
                {
                    int *pSource = (int *)srcBufferPtr.Ptr + bufferIndex;

                    do
                    {
                        int src_value = *pSource;
                        //separate each component
                        //TODO: review here, color from source buffer
                        //should be in 'pre-multiplied' format.
                        //so it should be converted to 'straight' color by call something like ..'FromPreMult()'

                        outputColors[startIndex++] = Drawing.Color.FromArgb(
                            (byte)((src_value >> 24) & 0xff), //a
                            (byte)((src_value >> 16) & 0xff), //r
                            (byte)((src_value >> 8) & 0xff),  //g
                            (byte)((src_value) & 0xff));      //b

                        pSource++;                            //move next
                    } while (--len != 0);
                }
            }



            //version 1 , incorrect
            //ISpanInterpolator spanInterpolator = Interpolator;
            //spanInterpolator.Begin(x + dx, y + dy, len);
            //int x_hr;
            //int y_hr;
            //spanInterpolator.GetCoord(out x_hr, out y_hr);
            //int x_lr = x_hr >> img_subpix_const.SHIFT;
            //int y_lr = y_hr >> img_subpix_const.SHIFT;
            //int bufferIndex = srcRW.GetBufferOffsetXY(x_lr, y_lr);
            //byte[] srcBuffer = srcRW.GetBuffer();
            //unsafe
            //{
            //    fixed (byte* pSource = srcBuffer)
            //    {
            //        do
            //        {
            //            outputColors[startIndex++] = *(Drawing.Color*)&(pSource[bufferIndex]);
            //            bufferIndex += 4;
            //        } while (--len != 0);
            //    }
            //}
        }
Example #25
0
        public override void GenerateColors(ColorRGBA[] outputColors, int startIndex, int x, int y, int len)
        {
            ISpanInterpolator spanInterpolator = base.Interpolator;
            int bufferIndex;

            byte[] srcBuffer = srcRW.GetBuffer();
            if (spanInterpolator.GetType() == typeof(PixelFarm.Agg.Transform.SpanInterpolatorLinear) &&
                ((PixelFarm.Agg.Transform.SpanInterpolatorLinear)spanInterpolator).Transformer.GetType() == typeof(PixelFarm.Agg.Transform.Affine) &&
                ((PixelFarm.Agg.Transform.Affine)((PixelFarm.Agg.Transform.SpanInterpolatorLinear)spanInterpolator).Transformer).IsIdentity())
            {
                bufferIndex = srcRW.GetBufferOffsetXY(x, y);
                //unsafe
                {
#if true
                    do
                    {
                        outputColors[startIndex].blue  = (byte)srcBuffer[bufferIndex++];
                        outputColors[startIndex].green = (byte)srcBuffer[bufferIndex++];
                        outputColors[startIndex].red   = (byte)srcBuffer[bufferIndex++];
                        outputColors[startIndex].alpha = (byte)srcBuffer[bufferIndex++];
                        ++startIndex;
                    } while (--len != 0);
#else
                    fixed(byte *pSource = &fg_ptr[bufferIndex])
                    {
                        int *pSourceInt = (int *)pSource;

                        fixed(RGBA_Bytes *pDest = &span[spanIndex])
                        {
                            int *pDestInt = (int *)pDest;

                            do
                            {
                                *pDestInt++ = *pSourceInt++;
                            } while (--len != 0);
                        }
                    }
#endif
                }

                return;
            }

            spanInterpolator.Begin(x + base.dx, y + base.dy, len);


            int accColor0, accColor1, accColor2, accColor3;

            int back_r = m_bgcolor.red;
            int back_g = m_bgcolor.green;
            int back_b = m_bgcolor.blue;
            int back_a = m_bgcolor.alpha;

            int maxx = srcRW.Width - 1;
            int maxy = srcRW.Height - 1;

            srcBuffer = srcRW.GetBuffer();

            unchecked
            {
                do
                {
                    int x_hr;
                    int y_hr;

                    spanInterpolator.GetCoord(out x_hr, out y_hr);

                    x_hr -= base.dxInt;
                    y_hr -= base.dyInt;

                    int x_lr = x_hr >> img_subpix_const.SHIFT;
                    int y_lr = y_hr >> img_subpix_const.SHIFT;
                    int weight;

                    if (x_lr >= 0 && y_lr >= 0 &&
                        x_lr < maxx && y_lr < maxy)
                    {
                        accColor0             =
                            accColor1         =
                                accColor2     =
                                    accColor3 = (int)img_subpix_const.SCALE * (int)img_subpix_const.SCALE / 2;

                        x_hr &= (int)img_subpix_const.MASK;
                        y_hr &= (int)img_subpix_const.MASK;

                        bufferIndex = srcRW.GetBufferOffsetXY(x_lr, y_lr);

                        weight = (((int)img_subpix_const.SCALE - x_hr) *
                                  ((int)img_subpix_const.SCALE - y_hr));
                        if (weight > BASE_MASK)
                        {
                            accColor0 += weight * srcBuffer[bufferIndex + CO.R];
                            accColor1 += weight * srcBuffer[bufferIndex + CO.G];
                            accColor2 += weight * srcBuffer[bufferIndex + CO.B];
                            accColor3 += weight * srcBuffer[bufferIndex + CO.A];
                        }

                        weight = (x_hr * ((int)img_subpix_const.SCALE - y_hr));
                        if (weight > BASE_MASK)
                        {
                            bufferIndex += bytesBetweenPixelInclusive;
                            accColor0   += weight * srcBuffer[bufferIndex + CO.R];
                            accColor1   += weight * srcBuffer[bufferIndex + CO.G];
                            accColor2   += weight * srcBuffer[bufferIndex + CO.B];
                            accColor3   += weight * srcBuffer[bufferIndex + CO.A];
                        }

                        weight = (((int)img_subpix_const.SCALE - x_hr) * y_hr);
                        if (weight > BASE_MASK)
                        {
                            ++y_lr;

                            bufferIndex = srcRW.GetBufferOffsetXY(x_lr, y_lr);
                            accColor0  += weight * srcBuffer[bufferIndex + CO.R];
                            accColor1  += weight * srcBuffer[bufferIndex + CO.G];
                            accColor2  += weight * srcBuffer[bufferIndex + CO.B];
                            accColor3  += weight * srcBuffer[bufferIndex + CO.A];
                        }
                        weight = (x_hr * y_hr);
                        if (weight > BASE_MASK)
                        {
                            bufferIndex += bytesBetweenPixelInclusive;
                            accColor0   += weight * srcBuffer[bufferIndex + CO.R];
                            accColor1   += weight * srcBuffer[bufferIndex + CO.G];
                            accColor2   += weight * srcBuffer[bufferIndex + CO.B];
                            accColor3   += weight * srcBuffer[bufferIndex + CO.A];
                        }
                        accColor0 >>= img_subpix_const.SHIFT * 2;
                        accColor1 >>= img_subpix_const.SHIFT * 2;
                        accColor2 >>= img_subpix_const.SHIFT * 2;
                        accColor3 >>= img_subpix_const.SHIFT * 2;
                    }
                    else
                    {
                        if (x_lr < -1 || y_lr < -1 ||
                            x_lr > maxx || y_lr > maxy)
                        {
                            accColor0 = back_r;
                            accColor1 = back_g;
                            accColor2 = back_b;
                            accColor3 = back_a;
                        }
                        else
                        {
                            accColor0             =
                                accColor1         =
                                    accColor2     =
                                        accColor3 = (int)img_subpix_const.SCALE * (int)img_subpix_const.SCALE / 2;

                            x_hr &= (int)img_subpix_const.MASK;
                            y_hr &= (int)img_subpix_const.MASK;

                            weight = (((int)img_subpix_const.SCALE - x_hr) *
                                      ((int)img_subpix_const.SCALE - y_hr));
                            if (weight > BASE_MASK)
                            {
                            }

                            x_lr++;

                            weight = (x_hr * ((int)img_subpix_const.SCALE - y_hr));
                            if (weight > BASE_MASK)
                            {
                                if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                                {
                                    BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3,
                                                       srcRW.GetBuffer(),
                                                       srcRW.GetBufferOffsetXY(x_lr, y_lr),
                                                       weight);
                                }
                                else
                                {
                                    accColor0 += back_r * weight;
                                    accColor1 += back_g * weight;
                                    accColor2 += back_b * weight;
                                    accColor3 += back_a * weight;
                                }
                            }

                            x_lr--;
                            y_lr++;

                            weight = (((int)img_subpix_const.SCALE - x_hr) * y_hr);
                            if (weight > BASE_MASK)
                            {
                                if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                                {
                                    BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3,
                                                       srcRW.GetBuffer(),
                                                       srcRW.GetBufferOffsetXY(x_lr, y_lr),
                                                       weight);
                                }
                                else
                                {
                                    accColor0 += back_r * weight;
                                    accColor1 += back_g * weight;
                                    accColor2 += back_b * weight;
                                    accColor3 += back_a * weight;
                                }
                            }

                            x_lr++;

                            weight = (x_hr * y_hr);
                            if (weight > BASE_MASK)
                            {
                                if ((uint)x_lr <= (uint)maxx && (uint)y_lr <= (uint)maxy)
                                {
                                    BlendInFilterPixel(ref accColor0, ref accColor1, ref accColor2, ref accColor3,
                                                       srcRW.GetBuffer(),
                                                       srcRW.GetBufferOffsetXY(x_lr, y_lr),
                                                       weight);
                                }
                                else
                                {
                                    accColor0 += back_r * weight;
                                    accColor1 += back_g * weight;
                                    accColor2 += back_b * weight;
                                    accColor3 += back_a * weight;
                                }
                            }

                            accColor0 >>= img_subpix_const.SHIFT * 2;
                            accColor1 >>= img_subpix_const.SHIFT * 2;
                            accColor2 >>= img_subpix_const.SHIFT * 2;
                            accColor3 >>= img_subpix_const.SHIFT * 2;
                        }
                    }

                    outputColors[startIndex].red   = (byte)accColor0;
                    outputColors[startIndex].green = (byte)accColor1;
                    outputColors[startIndex].blue  = (byte)accColor2;
                    outputColors[startIndex].alpha = (byte)accColor3;
                    ++startIndex;
                    spanInterpolator.Next();
                } while (--len != 0);
            }
        }