Example #1
0
        //--------------------------------------------------------------------
        public unsafe override void BlendSolidVerticalSpan(int x, int y,
										  uint len,
										  RGBA_Bytes c,
										  byte* covers)
        {
            PixelFormat.BlendSolidHorizontalSpan(y, x, len, c, covers);
        }
 public unsafe abstract void Generate(RGBA_Bytes* span, int x, int y, uint len);
Example #3
0
 //--------------------------------------------------------------------
 public RGBA_Bytes Gradient(RGBA_Bytes c, double k)
 {
     RGBA_Bytes ret = new RGBA_Bytes();
     uint ik = Basics.UnsignedRound(k * base_scale);
     ret.R_Byte = (byte)((uint)(R_Byte) + ((((uint)(c.R_Byte) - R_Byte) * ik) >> BaseShift));
     ret.G_Byte = (byte)((uint)(G_Byte) + ((((uint)(c.G_Byte) - G_Byte) * ik) >> BaseShift));
     ret.B_Byte = (byte)((uint)(B_Byte) + ((((uint)(c.B_Byte) - B_Byte) * ik) >> BaseShift));
     ret.A_Byte = (byte)((uint)(A_Byte) + ((((uint)(c.A_Byte) - A_Byte) * ik) >> BaseShift));
     return ret;
 }
Example #4
0
 //--------------------------------------------------------------------
 RGBA_Bytes(RGBA_Bytes c, uint a_)
 {
     m_R = (byte)c.m_R;
     m_G = (byte)c.m_G;
     m_B = (byte)c.m_B;
     m_A = (byte)a_;
 }
Example #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[3];
            uint src_alpha;

            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 SourceRenderingBuffer = base.source().PixelFormat.RenderingBuffer;
            int maxx = (int)SourceRenderingBuffer.Width() - 1;
            int maxy = (int)SourceRenderingBuffer.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] = (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 = SourceRenderingBuffer.GetPixelPointer(y_lr) + x_lr * 3;

                        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];

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

                        ++y_lr;
                        fg_ptr = SourceRenderingBuffer.GetPixelPointer(y_lr) + x_lr * 3;

                        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];

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

                        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;
                        src_alpha = base_mask;
                    }
                    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;
                            src_alpha = back_a;
                        }
                        else
                        {
                            fg[0] =
                            fg[1] =
                            fg[2] = (int)image_subpixel_scale_e.Scale * (int)image_subpixel_scale_e.Scale / 2;
                            src_alpha = (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, ref src_alpha, back_r, back_g, back_b, back_a, SourceRenderingBuffer, maxx, maxy, x_lr, y_lr, weight);

                            x_lr++;

                            weight = (uint)(x_hr * ((int)image_subpixel_scale_e.Scale - y_hr));
                            BlendInFilterPixel(fg, ref src_alpha, back_r, back_g, back_b, back_a, SourceRenderingBuffer, 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, ref src_alpha, back_r, back_g, back_b, back_a, SourceRenderingBuffer, maxx, maxy, x_lr, y_lr, weight);

                            x_lr++;

                            weight = (uint)(x_hr * y_hr);
                            BlendInFilterPixel(fg, ref src_alpha, back_r, back_g, back_b, back_a, SourceRenderingBuffer, 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;
                            src_alpha >>= (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)src_alpha;
                    ++span;
                    spanInterpolator.Next();

                } while (--len != 0);
            }
            #if use_timers
            Generate_Span.Stop();
            #endif
        }
Example #6
0
        //--------------------------------------------------------------------
        public span_image_filter_rgb_bilinear_clip(IRasterBufferAccessor src,
											IColorType back_color,
											ISpanInterpolator inter)
            : base(src, inter, null)
        {
            m_back_color = back_color.GetAsRGBA_Bytes();
            OrderR = src.PixelFormat.Blender.OrderR;
            OrderG = src.PixelFormat.Blender.OrderG;
            OrderB = src.PixelFormat.Blender.OrderB;
            OrderA = src.PixelFormat.Blender.OrderA;
        }
Example #7
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);
            }
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="vertexSource"></param>
 /// <param name="idx"></param>
 /// <param name="color"></param>
 public void Render(IVertexSource vertexSource, uint idx, RGBA_Bytes color)
 {
     m_Rasterizer.Reset();
     Affine transform = Transform;
     if (!transform.IsIdentity())
     {
         vertexSource = new TransformationConverter(vertexSource, transform);
     }
     m_Rasterizer.AddPath(vertexSource, idx);
     Renderer.RenderSolid(m_PixelFormat, m_Rasterizer, m_Scanline, color);
 }
		public static void RenderCompound(AntiAliasedCompundRasterizer ras,
									   IScanline sl_aa,
									   IScanline sl_bin,
									   IPixelFormat pixelFormat,
									   SpanAllocator alloc,
									   IStyleHandler sh)
		{
#if true
			unsafe
			{
				if (ras.RewindScanlines())
				{
					int min_x = ras.MinX();
					int len = ras.MaxX() - min_x + 2;
					sl_aa.Reset(min_x, ras.MaxX());
					sl_bin.Reset(min_x, ras.MaxX());

					//typedef typename BaseRenderer::color_type color_type;
					ArrayPOD<RGBA_Bytes> color_span = alloc.Allocate((uint)len * 2);
					byte[] ManagedCoversArray = sl_aa.GetCovers();
					fixed (byte* pCovers = ManagedCoversArray)
					{
						fixed (RGBA_Bytes* pColorSpan = color_span.Array)
						{
							int mix_bufferOffset = len;
							uint num_spans;

							uint num_styles;
							uint style;
							bool solid;
							while ((num_styles = ras.SweepStyles()) > 0)
							{
								if (num_styles == 1)
								{
									// Optimization for a single Style. Happens often
									//-------------------------
									if (ras.SweepScanline(sl_aa, 0))
									{
										style = ras.Style(0);
										if (sh.IsSolid(style))
										{
											// Just solid fill
											//-----------------------
											RenderSolidSingleScanLine(pixelFormat, sl_aa, sh.Color(style));
										}
										else
										{
											// Arbitrary Span Generator
											//-----------------------
											ScanlineSpan span_aa = sl_aa.Begin;
											num_spans = sl_aa.NumberOfSpans;

											for (; ; )
											{
												len = span_aa.len;
												sh.GenerateSpan(pColorSpan,
																 span_aa.x,
																 sl_aa.y(),
																 (uint)len,
																 style);

												pixelFormat.BlendHorizontalColorSpan(span_aa.x,
																	  sl_aa.y(),
																	  (uint)span_aa.len,
																	  pColorSpan,
																	  &pCovers[span_aa.cover_index], 0);
												if (--num_spans == 0) break;
												span_aa = sl_aa.GetNextScanlineSpan();
											}
										}
									}
								}
								else // there are multiple Styles
								{
									if (ras.SweepScanline(sl_bin, -1))
									{
										// Clear the spans of the mix_buffer
										//--------------------
										ScanlineSpan span_bin = sl_bin.Begin;
										num_spans = sl_bin.NumberOfSpans;
										for (; ; )
										{
											Basics.MemClear((byte*)&pColorSpan[mix_bufferOffset + span_bin.x - min_x],
												   span_bin.len * sizeof(RGBA_Bytes));

											if (--num_spans == 0) break;
											span_bin = sl_bin.GetNextScanlineSpan();
										}

										for (uint i = 0; i < num_styles; i++)
										{
											style = ras.Style(i);
											solid = sh.IsSolid(style);

											if (ras.SweepScanline(sl_aa, (int)i))
											{
												//IColorType* Colors;
												//IColorType* cspan;
												//typename ScanlineAA::cover_type* covers;
												ScanlineSpan span_aa = sl_aa.Begin;
												num_spans = sl_aa.NumberOfSpans;
												if (solid)
												{
													// Just solid fill
													//-----------------------
													for (; ; )
													{
														RGBA_Bytes c = sh.Color(style);
														len = span_aa.len;
														RGBA_Bytes* colors = &pColorSpan[mix_bufferOffset + span_aa.x - min_x];
														byte* covers = &pCovers[span_aa.cover_index];
														do
														{
															if (*covers == cover_full)
															{
																*colors = c;
															}
															else
															{
																colors->add(c, *covers);
															}
															++colors;
															++covers;
														}
														while (--len != 0);
														if (--num_spans == 0) break;
														span_aa = sl_aa.GetNextScanlineSpan();
													}
												}
												else
												{
													// Arbitrary Span Generator
													//-----------------------
													for (; ; )
													{
														len = span_aa.len;
														RGBA_Bytes* colors = &pColorSpan[mix_bufferOffset + span_aa.x - min_x];
														RGBA_Bytes* cspan = pColorSpan;
														sh.GenerateSpan(cspan,
																		 span_aa.x,
																		 sl_aa.y(),
																		 (uint)len,
																		 style);
														byte* covers = &pCovers[span_aa.cover_index];
														do
														{
															if (*covers == cover_full)
															{
																*colors = *cspan;
															}
															else
															{
																colors->add(*cspan, *covers);
															}
															++cspan;
															++colors;
															++covers;
														}
														while (--len != 0);
														if (--num_spans == 0) break;
														span_aa = sl_aa.GetNextScanlineSpan();
													}
												}
											}
										}

										// Emit the blended result as a Color hspan
										//-------------------------
										span_bin = sl_bin.Begin;
										num_spans = sl_bin.NumberOfSpans;
										for (; ; )
										{
											pixelFormat.BlendHorizontalColorSpan(span_bin.x,
																  sl_bin.y(),
																  (uint)span_bin.len,
																  &pColorSpan[mix_bufferOffset + span_bin.x - min_x],
																  null,
																  cover_full);
											if (--num_spans == 0) break;
											span_bin = sl_bin.GetNextScanlineSpan();
										}
									} // if(ras.SweepScanline(sl_bin, -1))
								} // if(num_styles == 1) ... else
							} // while((num_styles = ras.SweepStyles()) > 0)
						}
					}
				} // if(ras.RewindScanlines())
#endif
			}
		}
		public void Line(PointD Start, PointD End, RGBA_Bytes color)
		{
			Line(Start.x, Start.y, End.x, End.y, color);
		}
		//================================================render_scanline_aa_solid
		private static void RenderSolidSingleScanLine(IPixelFormat pixFormat, IScanline scanLine, RGBA_Bytes color)
		{
#if use_timers
			render_scanline_aa_solidTimer.Start();
#endif
			int y = scanLine.y();
			uint num_spans = scanLine.NumberOfSpans;
			ScanlineSpan scanlineSpan = scanLine.Begin;

			byte[] ManagedCoversArray = scanLine.GetCovers();
			unsafe
			{
				fixed (byte* pCovers = ManagedCoversArray)
				{
					for (; ; )
					{
						int x = scanlineSpan.x;
						if (scanlineSpan.len > 0)
						{
#if use_timers
							render_scanline_aa_solid_blend_solid_hspan.Start();
#endif
							pixFormat.BlendSolidHorizontalSpan(x, y, (uint)scanlineSpan.len, color, &pCovers[scanlineSpan.cover_index]);
#if use_timers
							render_scanline_aa_solid_blend_solid_hspan.Stop();
#endif
						}
						else
						{
#if use_timers
							render_scanline_aa_solid_blend_hline.Start();
#endif
							pixFormat.BlendHorizontalLine(x, y, (x - (int)scanlineSpan.len - 1), color, pCovers[scanlineSpan.cover_index]);
#if use_timers
							render_scanline_aa_solid_blend_hline.Stop();
#endif
						}
						if (--num_spans == 0) break;
						scanlineSpan = scanLine.GetNextScanlineSpan();
					}
				}
			}
#if use_timers
			render_scanline_aa_solidTimer.Stop();
#endif
		}
		//========================================================render_scanlines
		public static void RenderSolid(IPixelFormat pixFormat, IRasterizer rasterizer, IScanline scanLine, RGBA_Bytes color)
		{
			if (rasterizer.RewindScanlines())
			{
				scanLine.Reset(rasterizer.MinX(), rasterizer.MaxX());
#if use_timers
				PrepareTimer.Start();
#endif

				//renderer.Prepare();
#if use_timers
				PrepareTimer.Stop();
#endif
				while (rasterizer.SweepScanline(scanLine))
				{
					Renderer.RenderSolidSingleScanLine(pixFormat, scanLine, color);
				}
			}
		}
		/// <summary>
		///
		/// </summary>
		/// <param name="vertexSource"></param>
		/// <param name="color"></param>
		public void Render(IVertexSource vertexSource, RGBA_Bytes color)
		{
			Render(vertexSource, 0, color);
		}
 //========================================================render_scanlines
 public static void RenderSolid(IPixelFormat pixFormat, IRasterizer rasterizer, IScanline scanLine, RGBA_Bytes color)
 {
     if(rasterizer.RewindScanlines())
     {
         scanLine.Reset(rasterizer.MinX(), rasterizer.MaxX());
     #if use_timers
         PrepareTimer.Start();
     #endif
         //renderer.Prepare();
     #if use_timers
         PrepareTimer.Stop();
     #endif
         while(rasterizer.SweepScanline(scanLine))
         {
             Renderer.RenderSolidSingleScanLine(pixFormat, scanLine, color);
         }
     }
 }
Example #15
0
        /*
        //--------------------------------------------------------------------
        public void copy_bar(int x1, int y1, int x2, int y2, IColorType c)
        {
            RectI rc(x1, y1, x2, y2);
            rc.Normalize();
            if(rc.Clip(ClipBox()))
            {
                int y;
                for(y = rc.y1; y <= rc.y2; y++)
                {
                    m_ren->CopyHorizontalLine(rc.x1, y, uint(rc.x2 - rc.x1 + 1), c);
                }
            }
        }

        //--------------------------------------------------------------------
        public void blend_bar(int x1, int y1, int x2, int y2,
                       IColorType c, byte cover)
        {
            RectI rc(x1, y1, x2, y2);
            rc.Normalize();
            if(rc.Clip(ClipBox()))
            {
                int y;
                for(y = rc.y1; y <= rc.y2; y++)
                {
                    m_ren->BlendHorizontalLine(rc.x1,
                                       y,
                                       uint(rc.x2 - rc.x1 + 1),
                                       c,
                                       cover);
                }
            }
        }
         */
        //--------------------------------------------------------------------
        public unsafe override void BlendSolidHorizontalSpan(int x, int y, uint in_len, RGBA_Bytes c, byte* covers)
        {
            int len = (int)in_len;
            if (y > MaxY) return;
            if(y < MinY) return;

            if(x < MinX)
            {
                len -= MinX - x;
                if(len <= 0) return;
                covers += MinX - x;
                x = MinX;
            }
            if(x + len > MaxX)
            {
                len = MaxX - x + 1;
                if(len <= 0) return;
            }
            base.BlendSolidHorizontalSpan(x, y, (uint)len, c, covers);
        }
 public void Line(PointD Start, PointD End, RGBA_Bytes color)
 {
     Line(Start.x, Start.y, End.x, End.y, color);
 }
Example #17
0
        //--------------------------------------------------------------------
        public unsafe override void BlendSolidVerticalSpan(int x, int y, uint len, RGBA_Bytes c, byte* covers)
        {
            if(x > MaxX) return;
            if(x < MinX) return;

            if(y < MinY)
            {
                len -= (uint)(MinY - y);
                if(len <= 0) return;
                covers += MinY - y;
                y = MinY;
            }
            if(y + len > MaxY)
            {
                len = (uint)(MaxY - y + 1);
                if(len <= 0) return;
            }
            base.BlendSolidVerticalSpan(x, y, len, c, covers);
        }
Example #18
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];
            }
        }
Example #19
0
        //--------------------------------------------------------------------
        public unsafe override void BlendVerticalColorSpan(int x, int y, uint len, RGBA_Bytes* colors, byte* covers, byte cover)
        {
            if(x > MaxX) return;
            if(x < MinX) return;

            if(y < MinY)
            {
                int d = MinY - y;
                len -= (uint)d;
                if(len <= 0) return;
                if(covers != null) covers += d;
                colors += d;
                y = MinY;
            }
            if(y + len > MaxY)
            {
                len = (uint)(MaxY - y + 1);
                if(len <= 0) return;
            }
            base.BlendVerticalColorSpan(x, y, len, colors, covers, cover);
        }
Example #20
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[3];
            uint src_alpha;

            RasterBuffer SourceRenderingBuffer = base.source().PixelFormat.RenderingBuffer;
            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_lrX3 = (x_hr >> (int)image_subpixel_scale_e.Shift) * 3;
                    int y_lr = y_hr >> (int)image_subpixel_scale_e.Shift;
                    uint weight;

                    fg[0] =
                    fg[1] =
                    fg[2] = (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;

                    byte* fg_ptr = SourceRenderingBuffer.GetPixelPointer(y_lr) + x_lrX3;

                    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];

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

                    ++y_lr;
                    fg_ptr = SourceRenderingBuffer.GetPixelPointer(y_lr) + x_lrX3;

                    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];

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

                    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;
                    src_alpha = base_mask;

                    (*span).m_R = (byte)fg[OrderR];
                    (*span).m_G = (byte)fg[OrderG];
                    (*span).m_B = (byte)fg[OrderB];
                    (*span).m_A = (byte)src_alpha;
                    ++span;
                    spanInterpolator.Next();

                } while (--len != 0);
            }
            #if use_timers
            Generate_Span.Stop();
            #endif
        }
Example #21
0
        //--------------------------------------------------------------------
        public override void BlendVerticalLine(int x, int y1, int y2, RGBA_Bytes c, byte cover)
        {
            if(y1 > y2) { int t = y2; y2 = y1; y1 = t; }
            if(x  > MaxX) return;
            if(x  < MinX) return;
            if(y1 > MaxY) return;
            if(y2 < MinY) return;

            if(y1 < MinY) y1 = MinY;
            if(y2 > MaxY) y2 = MaxY;

            base.BlendVerticalLine(x, y1, y2, c, cover);
        }
Example #22
0
 public void background_color(IColorType v)
 {
     m_back_color = v.GetAsRGBA_Bytes();
 }
Example #23
0
 //--------------------------------------------------------------------
 public void Clear(IColorType in_c)
 {
     uint y;
     RGBA_Bytes c = new RGBA_Bytes(in_c.R_Byte, in_c.G_Byte, in_c.B_Byte, in_c.A_Byte);
     if(Width != 0)
     {
         for(y = 0; y < Height; y++)
         {
             base.CopyHorizontalLine(0, (int)y, Width, c);
         }
     }
 }
Example #24
0
 //--------------------------------------------------------------------
 public unsafe override void Generate(RGBA_Bytes* span, int x, int y, uint len)
 {
     RasterBuffer SourceRenderingBuffer = 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 = SourceRenderingBuffer.GetPixelPointer(y_lr) + (x_lr * 3);
         //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 = 255;
         ++span;
         spanInterpolator.Next();
     } while (--len != 0);
 }
Example #25
0
        //--------------------------------------------------------------------
        public unsafe override void CopyHorizontalColorSpan(int x, int y, uint len, RGBA_Bytes* colors)
        {
            if(y > MaxY) return;
            if(y < MinY) return;

            if(x < MinX)
            {
                int d = MinX - x;
                len -= (uint)d;
                if(len <= 0) return;
                colors += d;
                x = MinX;
            }
            if(x + len > MaxX)
            {
                len = (uint)(MaxX - x + 1);
                if(len <= 0) return;
            }
            base.CopyHorizontalColorSpan(x, y, len, colors);
        }
Example #26
0
 //--------------------------------------------------------------------
 public void add(RGBA_Bytes c, uint cover)
 {
     uint cr, cg, cb, ca;
     if(cover == cover_mask)
     {
         if(c.A_Byte == base_mask)
         {
             this = c;
         }
         else
         {
             cr = R_Byte + c.R_Byte; R_Byte = (cr > (uint)(base_mask)) ? (uint)(base_mask) : cr;
             cg = G_Byte + c.G_Byte; G_Byte = (cg > (uint)(base_mask)) ? (uint)(base_mask) : cg;
             cb = B_Byte + c.B_Byte; B_Byte = (cb > (uint)(base_mask)) ? (uint)(base_mask) : cb;
             ca = A_Byte + c.A_Byte; A_Byte = (ca > (uint)(base_mask)) ? (uint)(base_mask) : ca;
         }
     }
     else
     {
         cr = R_Byte + ((c.R_Byte * cover + cover_mask/2) >> cover_shift);
         cg = G_Byte + ((c.G_Byte * cover + cover_mask/2) >> cover_shift);
         cb = B_Byte + ((c.B_Byte * cover + cover_mask/2) >> cover_shift);
         ca = A_Byte + ((c.A_Byte * cover + cover_mask/2) >> cover_shift);
         R_Byte = (cr > (uint)(base_mask)) ? (uint)(base_mask) : cr;
         G_Byte = (cg > (uint)(base_mask)) ? (uint)(base_mask) : cg;
         B_Byte = (cb > (uint)(base_mask)) ? (uint)(base_mask) : cb;
         A_Byte = (ca > (uint)(base_mask)) ? (uint)(base_mask) : ca;
     }
 }
Example #27
0
        //--------------------------------------------------------------------
        public override void CopyHorizontalLine(int x1, int y, uint x2, RGBA_Bytes c)
        {
            if(x1 > x2) { int t = (int)x2; x2 = (uint)x1; x1 = t; }
            if(y  > MaxY) return;
            if(y  < MinY) return;
            if(x1 > MaxX) return;
            if(x2 < MinX) return;

            if(x1 < MinX) x1 = MinX;
            if(x2 > MaxX) x2 = (uint)MaxX;

            base.CopyHorizontalLine(x1, y, (uint)(x2 - x1 + 1), c);
        }
Example #28
0
 //--------------------------------------------------------------------
 public RGBA_Bytes Gradient(RGBA_Bytes c_8, double k)
 {
     RGBA_Doubles c = c_8.GetAsRGBA_Doubles();
     RGBA_Doubles ret;
     ret.m_r = m_r + (c.m_r - m_r) * k;
     ret.m_g = m_g + (c.m_g - m_g) * k;
     ret.m_b = m_b + (c.m_b - m_b) * k;
     ret.m_a = m_a + (c.m_a - m_a) * k;
     return ret.GetAsRGBA_Bytes();
 }
Example #29
0
        //--------------------------------------------------------------------
        public unsafe override void CopyVerticalColorSpan(int x, int y, uint len, RGBA_Bytes* colors)
        {
            if(x > MaxX) return;
            if(x < MinX) return;

            if(y < MinY)
            {
                int d = MinY - y;
                len -= (uint)d;
                if(len <= 0) return;
                colors += d;
                y = MinY;
            }
            if(y + len > MaxY)
            {
                len = (uint)(MaxY - y + 1);
                if(len <= 0) return;
            }
            base.CopyVerticalColorSpan(x, y, len, colors);
        }
        //================================================render_scanline_aa_solid
        private static void RenderSolidSingleScanLine(IPixelFormat pixFormat, IScanline scanLine, RGBA_Bytes color)
        {
            #if use_timers
            render_scanline_aa_solidTimer.Start();
            #endif
            int y = scanLine.y();
            uint num_spans = scanLine.NumberOfSpans;
            ScanlineSpan scanlineSpan = scanLine.Begin;

            byte[] ManagedCoversArray = scanLine.GetCovers();
            unsafe
            {
                fixed (byte* pCovers = ManagedCoversArray)
                {
                    for (; ; )
                    {
                        int x = scanlineSpan.x;
                        if (scanlineSpan.len > 0)
                        {
            #if use_timers
                            render_scanline_aa_solid_blend_solid_hspan.Start();
            #endif
                            pixFormat.BlendSolidHorizontalSpan(x, y, (uint)scanlineSpan.len, color, &pCovers[scanlineSpan.cover_index]);
            #if use_timers
                            render_scanline_aa_solid_blend_solid_hspan.Stop();
            #endif
                        }
                        else
                        {
            #if use_timers
                            render_scanline_aa_solid_blend_hline.Start();
            #endif
                            pixFormat.BlendHorizontalLine(x, y, (x - (int)scanlineSpan.len - 1), color, pCovers[scanlineSpan.cover_index]);
            #if use_timers
                            render_scanline_aa_solid_blend_hline.Stop();
            #endif
                        }
                        if (--num_spans == 0) break;
                        scanlineSpan = scanLine.GetNextScanlineSpan();
                    }
                }
            }
            #if use_timers
            render_scanline_aa_solidTimer.Stop();
            #endif
        }
Example #31
0
        //--------------------------------------------------------------------
        public override void CopyVerticalLine(int x, int y1, uint y2, RGBA_Bytes c)
        {
            if(y1 > y2) { int t = (int)y2; y2 = (uint)y1; y1 = t; }
            if(x  > MaxX) return;
            if(x  < MinX) return;
            if(y1 > MaxY) return;
            if(y2 < MinY) return;

            if(y1 < MinY) y1 = MinY;
            if(y2 > MaxY) y2 = (uint)MaxY;

            base.CopyVerticalLine(x, y1, (uint)(y2 - y1 + 1), c);
        }
        //========================================================render_all_paths
        public static void RenderSolidAllPaths(IPixelFormat pixFormat, 
            IRasterizer ras, 
            IScanline sl,
            IVertexSource vs, 
            RGBA_Bytes[] color_storage,
            uint[] path_id,
            uint num_paths)
        {
            for(uint i = 0; i < num_paths; i++)
            {
                ras.Reset();

            #if use_timers
                AddPathTimer.Start();
            #endif
                ras.AddPath(vs, path_id[i]);
            #if use_timers
                AddPathTimer.Stop();
            #endif

            #if use_timers
                RenderSLTimer.Start();
            #endif
                RenderSolid(pixFormat, ras, sl, color_storage[i]);
            #if use_timers
                RenderSLTimer.Stop();
            #endif
            }
        }
Example #33
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())
            {
                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] = (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;
                            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;

                    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)base_mask;

                    ++span;
                    interpolator().Next();
                } while (--len != 0);
            }
        }
 public void Line(double x1, double y1, double x2, double y2, RGBA_Bytes color)
 {
     PathStorage m_LinesToDraw = new PathStorage();
     m_LinesToDraw.RemoveAll();
     m_LinesToDraw.move_to(x1, y1);
     m_LinesToDraw.line_to(x2, y2);
     StrokeConverter StrockedLineToDraw = new StrokeConverter(m_LinesToDraw);
     Render(StrockedLineToDraw, color);
 }
Example #35
0
        //--------------------------------------------------------------------
        public unsafe override void Generate(RGBA_Bytes* span, int x, int y, uint len)
        {
            base.interpolator().Begin(x + base.filter_dx_dbl(), y + base.filter_dy_dbl(), len);

            int* fg = stackalloc int[3];

            byte* fg_ptr;

            uint diameter = m_filter.diameter();
            int start = m_filter.start();
            short[] weight_array = m_filter.weight_array();

            int x_count;
            int weight_y;

            ISpanInterpolator spanInterpolator = base.interpolator();

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

                x -= base.filter_dx_int();
                y -= base.filter_dy_int();

                int x_hr = x;
                int y_hr = y;

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

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

                int x_fract = x_hr & (int)image_subpixel_scale_e.Mask;
                uint y_count = diameter;

                y_hr = (int)image_subpixel_scale_e.Mask - (y_hr & (int)image_subpixel_scale_e.Mask);
                fg_ptr = source().Span(x_lr + start, y_lr + start, diameter);
                for (; ; )
                {
                    x_count = (int)diameter;
                    weight_y = weight_array[y_hr];
                    x_hr = (int)image_subpixel_scale_e.Mask - x_fract;
                    for (; ; )
                    {
                        int weight = (weight_y * weight_array[x_hr] +
                                     (int)image_filter_scale_e.Scale / 2) >>
                                     (int)image_filter_scale_e.Shift;

                        fg[0] += weight * *fg_ptr++;
                        fg[1] += weight * *fg_ptr++;
                        fg[2] += weight * *fg_ptr;

                        if (--x_count == 0) break;
                        x_hr += (int)image_subpixel_scale_e.Scale;
                        fg_ptr = source().NextX();
                    }

                    if (--y_count == 0) break;
                    y_hr += (int)image_subpixel_scale_e.Scale;
                    fg_ptr = source().NextY();
                }

                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[0] < 0) fg[0] = 0;
                if (fg[1] < 0) fg[1] = 0;
                if (fg[2] < 0) fg[2] = 0;

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

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

                ++span;
                spanInterpolator.Next();

            } while (--len != 0);
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="vertexSource"></param>
 /// <param name="color"></param>
 public void Render(IVertexSource vertexSource, RGBA_Bytes color)
 {
     Render(vertexSource, 0, color);
 }
Example #37
0
 public void background_color(IColorType v)
 {
     m_back_color = v.GetAsRGBA_Bytes();
 }