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);
                }
            }
        }
示例#2
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);
        }
示例#3
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);
                }
            }
        }
示例#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);
        }
示例#5
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();
            }
        }
示例#6
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);
            //    }
            //}
        }
示例#7
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);
                        }
                    }
                }
            }
        }
        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);
        }
示例#9
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);
            }
        }
示例#10
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);
                }
            }
        }
示例#11
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
        }
示例#12
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
        }
        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);
            }
        }