Exemplo n.º 1
0
        public void CopyFrom(RasterBuffer src,
                       RectI rect_src_ptr,
                       int dx,
                       int dy)
        {
            RectI rsrc = new RectI(rect_src_ptr.x1, rect_src_ptr.y1, rect_src_ptr.x2 + 1, rect_src_ptr.y2 + 1);

            // Version with xdst, ydst (absolute positioning)
            //RectI rdst(xdst, ydst, xdst + rsrc.x2 - rsrc.x1, ydst + rsrc.y2 - rsrc.y1);

            // Version with dx, dy (relative positioning)
            RectI rdst = new RectI(rsrc.x1 + dx, rsrc.y1 + dy, rsrc.x2 + dx, rsrc.y2 + dy);

            RectI rc = ClipRectangleArea(ref rdst, ref rsrc, (int)src.Width(), (int)src.Height());

            if(rc.x2 > 0)
            {
                int incy = 1;
                if(rdst.y1 > rsrc.y1)
                {
                    rsrc.y1 += rc.y2 - 1;
                    rdst.y1 += rc.y2 - 1;
                    incy = -1;
                }
                while(rc.y2 > 0)
                {
                    base.CopyFrom(src,
                                     rdst.x1, rdst.y1,
                                     rsrc.x1, rsrc.y1,
                                     (uint)rc.x2);
                    rdst.y1 += incy;
                    rsrc.y1 += incy;
                    --rc.y2;
                }
            }
        }
Exemplo n.º 2
0
 public void CopyFrom(RasterBuffer src)
 {
     CopyFrom(src, new RectI(0, 0, (int)src.Width(), (int)src.Height()), 0, 0);
 }
Exemplo n.º 3
0
        public unsafe override void Generate(RGBA_Bytes *span, int x, int y, uint len)
        {
#if use_timers
            Generate_Span.Start();
#endif
            base.interpolator().Begin(x + base.filter_dx_dbl(), y + base.filter_dy_dbl(), len);

            //uint[] fg = new uint[4];
            uint *fg = stackalloc uint[4];

            uint back_r = m_back_color.m_R;
            uint back_g = m_back_color.m_G;
            uint back_b = m_back_color.m_B;
            uint back_a = m_back_color.m_A;

            byte *fg_ptr;

            RasterBuffer      pSourceRenderingBuffer = base.source().PixelFormat.RenderingBuffer;
            int               maxx             = (int)pSourceRenderingBuffer.Width() - 1;
            int               maxy             = (int)pSourceRenderingBuffer.Height() - 1;
            ISpanInterpolator spanInterpolator = base.interpolator();

            unchecked
            {
                do
                {
                    int x_hr;
                    int y_hr;

                    spanInterpolator.Coordinates(out x_hr, out y_hr);

                    x_hr -= base.filter_dx_int();
                    y_hr -= base.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;

                    if (x_lr >= 0 && y_lr >= 0 &&
                        x_lr < maxx && y_lr < maxy)
                    {
                        fg[0]             =
                            fg[1]         =
                                fg[2]     =
                                    fg[3] = (int)image_subpixel_scale_e.Scale * (int)image_subpixel_scale_e.Scale / 2;

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

                        fg_ptr = pSourceRenderingBuffer.GetPixelPointer(y_lr) + (x_lr << 2);

                        weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) *
                                        ((int)image_subpixel_scale_e.Scale - y_hr));
                        fg[0] += weight * fg_ptr[0];
                        fg[1] += weight * fg_ptr[1];
                        fg[2] += weight * fg_ptr[2];
                        fg[3] += weight * fg_ptr[3];

                        weight = (uint)(x_hr * ((int)image_subpixel_scale_e.Scale - y_hr));
                        fg[0] += weight * fg_ptr[4];
                        fg[1] += weight * fg_ptr[5];
                        fg[2] += weight * fg_ptr[6];
                        fg[3] += weight * fg_ptr[7];

                        ++y_lr;
                        fg_ptr = pSourceRenderingBuffer.GetPixelPointer(y_lr) + (x_lr << 2);

                        weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) * y_hr);
                        fg[0] += weight * fg_ptr[0];
                        fg[1] += weight * fg_ptr[1];
                        fg[2] += weight * fg_ptr[2];
                        fg[3] += weight * fg_ptr[3];

                        weight = (uint)(x_hr * y_hr);
                        fg[0] += weight * fg_ptr[4];
                        fg[1] += weight * fg_ptr[5];
                        fg[2] += weight * fg_ptr[6];
                        fg[3] += weight * fg_ptr[7];

                        fg[0] >>= (int)image_subpixel_scale_e.Shift * 2;
                        fg[1] >>= (int)image_subpixel_scale_e.Shift * 2;
                        fg[2] >>= (int)image_subpixel_scale_e.Shift * 2;
                        fg[3] >>= (int)image_subpixel_scale_e.Shift * 2;
                    }
                    else
                    {
                        if (x_lr < -1 || y_lr < -1 ||
                            x_lr > maxx || y_lr > maxy)
                        {
                            fg[OrderR] = back_r;
                            fg[OrderG] = back_g;
                            fg[OrderB] = back_b;
                            fg[OrderA] = back_a;
                        }
                        else
                        {
                            fg[0]             =
                                fg[1]         =
                                    fg[2]     =
                                        fg[3] = (int)image_subpixel_scale_e.Scale * (int)image_subpixel_scale_e.Scale / 2;

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

                            weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) *
                                            ((int)image_subpixel_scale_e.Scale - y_hr));
                            BlendInFilterPixel(fg, back_r, back_g, back_b, back_a, pSourceRenderingBuffer, maxx, maxy, x_lr, y_lr, weight);

                            x_lr++;

                            weight = (uint)(x_hr * ((int)image_subpixel_scale_e.Scale - y_hr));
                            BlendInFilterPixel(fg, back_r, back_g, back_b, back_a, pSourceRenderingBuffer, maxx, maxy, x_lr, y_lr, weight);

                            x_lr--;
                            y_lr++;

                            weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) * y_hr);
                            BlendInFilterPixel(fg, back_r, back_g, back_b, back_a, pSourceRenderingBuffer, maxx, maxy, x_lr, y_lr, weight);

                            x_lr++;

                            weight = (uint)(x_hr * y_hr);
                            BlendInFilterPixel(fg, back_r, back_g, back_b, back_a, pSourceRenderingBuffer, maxx, maxy, x_lr, y_lr, weight);

                            fg[0] >>= (int)image_subpixel_scale_e.Shift * 2;
                            fg[1] >>= (int)image_subpixel_scale_e.Shift * 2;
                            fg[2] >>= (int)image_subpixel_scale_e.Shift * 2;
                            fg[3] >>= (int)image_subpixel_scale_e.Shift * 2;
                        }
                    }

                    (*span).m_R = (byte)fg[0];
                    (*span).m_G = (byte)fg[1];
                    (*span).m_B = (byte)fg[2];
                    (*span).m_A = (byte)fg[3];
                    ++span;
                    spanInterpolator.Next();
                } while (--len != 0);
            }
#if use_timers
            Generate_Span.Stop();
#endif
        }
Exemplo n.º 4
0
        public unsafe void Generate(out RGBA_Bytes destPixel, int x, int y)
        {
            base.interpolator().Begin(x + base.filter_dx_dbl(), y + base.filter_dy_dbl(), 1);

            uint *fg = stackalloc uint[4];

            byte *fg_ptr;

            RasterBuffer      pSourceRenderingBuffer = base.source().PixelFormat.RenderingBuffer;
            int               maxx             = (int)pSourceRenderingBuffer.Width() - 1;
            int               maxy             = (int)pSourceRenderingBuffer.Height() - 1;
            ISpanInterpolator spanInterpolator = base.interpolator();

            unchecked
            {
                int x_hr;
                int y_hr;

                spanInterpolator.Coordinates(out x_hr, out y_hr);

                x_hr -= base.filter_dx_int();
                y_hr -= base.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] = fg[3] = (int)image_subpixel_scale_e.Scale * (int)image_subpixel_scale_e.Scale / 2;

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

                fg_ptr = pSourceRenderingBuffer.GetPixelPointer(y_lr) + (x_lr << 2);

                weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) *
                                ((int)image_subpixel_scale_e.Scale - y_hr));
                fg[0] += weight * fg_ptr[0];
                fg[1] += weight * fg_ptr[1];
                fg[2] += weight * fg_ptr[2];
                fg[3] += weight * fg_ptr[3];

                weight = (uint)(x_hr * ((int)image_subpixel_scale_e.Scale - y_hr));
                fg[0] += weight * fg_ptr[4];
                fg[1] += weight * fg_ptr[5];
                fg[2] += weight * fg_ptr[6];
                fg[3] += weight * fg_ptr[7];

                ++y_lr;
                fg_ptr = pSourceRenderingBuffer.GetPixelPointer(y_lr) + (x_lr << 2);

                weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) * y_hr);
                fg[0] += weight * fg_ptr[0];
                fg[1] += weight * fg_ptr[1];
                fg[2] += weight * fg_ptr[2];
                fg[3] += weight * fg_ptr[3];

                weight = (uint)(x_hr * y_hr);
                fg[0] += weight * fg_ptr[4];
                fg[1] += weight * fg_ptr[5];
                fg[2] += weight * fg_ptr[6];
                fg[3] += weight * fg_ptr[7];

                fg[0] >>= (int)image_subpixel_scale_e.Shift * 2;
                fg[1] >>= (int)image_subpixel_scale_e.Shift * 2;
                fg[2] >>= (int)image_subpixel_scale_e.Shift * 2;
                fg[3] >>= (int)image_subpixel_scale_e.Shift * 2;

                destPixel.m_R = (byte)fg[OrderR];
                destPixel.m_G = (byte)fg[OrderG];
                destPixel.m_B = (byte)fg[OrderB];
                destPixel.m_A = (byte)fg[OrderA];
            }
        }
Exemplo n.º 5
0
        public unsafe override void Generate(RGBA_Bytes *span, int x, int y, uint len)
        {
#if use_timers
            Generate_Span.Start();
#endif
            base.interpolator().Begin(x + base.filter_dx_dbl(), y + base.filter_dy_dbl(), len);

            uint *fg = stackalloc uint[4];

            byte *fg_ptr;

            RasterBuffer      pSourceRenderingBuffer = base.source().PixelFormat.RenderingBuffer;
            int               maxx             = (int)pSourceRenderingBuffer.Width() - 1;
            int               maxy             = (int)pSourceRenderingBuffer.Height() - 1;
            ISpanInterpolator spanInterpolator = base.interpolator();

            unchecked
            {
                do
                {
                    int x_hr;
                    int y_hr;

                    spanInterpolator.Coordinates(out x_hr, out y_hr);

                    x_hr -= base.filter_dx_int();
                    y_hr -= base.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] = fg[3] = (int)image_subpixel_scale_e.Scale * (int)image_subpixel_scale_e.Scale / 2;

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

                    fg_ptr = pSourceRenderingBuffer.GetPixelPointer(y_lr) + (x_lr << 2);

                    weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) *
                                    ((int)image_subpixel_scale_e.Scale - y_hr));
                    fg[0] += weight * fg_ptr[0];
                    fg[1] += weight * fg_ptr[1];
                    fg[2] += weight * fg_ptr[2];
                    fg[3] += weight * fg_ptr[3];

                    weight = (uint)(x_hr * ((int)image_subpixel_scale_e.Scale - y_hr));
                    fg[0] += weight * fg_ptr[4];
                    fg[1] += weight * fg_ptr[5];
                    fg[2] += weight * fg_ptr[6];
                    fg[3] += weight * fg_ptr[7];

                    ++y_lr;
                    fg_ptr = pSourceRenderingBuffer.GetPixelPointer(y_lr) + (x_lr << 2);

                    weight = (uint)(((int)image_subpixel_scale_e.Scale - x_hr) * y_hr);
                    fg[0] += weight * fg_ptr[0];
                    fg[1] += weight * fg_ptr[1];
                    fg[2] += weight * fg_ptr[2];
                    fg[3] += weight * fg_ptr[3];

                    weight = (uint)(x_hr * y_hr);
                    fg[0] += weight * fg_ptr[4];
                    fg[1] += weight * fg_ptr[5];
                    fg[2] += weight * fg_ptr[6];
                    fg[3] += weight * fg_ptr[7];

                    fg[0] >>= (int)image_subpixel_scale_e.Shift * 2;
                    fg[1] >>= (int)image_subpixel_scale_e.Shift * 2;
                    fg[2] >>= (int)image_subpixel_scale_e.Shift * 2;
                    fg[3] >>= (int)image_subpixel_scale_e.Shift * 2;

                    (*span).m_R = (byte)fg[OrderR];
                    (*span).m_G = (byte)fg[OrderG];
                    (*span).m_B = (byte)fg[OrderB];
                    (*span).m_A = (byte)fg[OrderA];
                    ++span;
                    spanInterpolator.Next();
                } while (--len != 0);
            }
#if use_timers
            Generate_Span.Stop();
#endif
        }