public void Init(double x1, double y1, double cx, double cy, double x2, double y2) { _start_x = x1; _start_y = y1; _end_x = x2; _end_y = y2; double dx1 = cx - x1; double dy1 = cy - y1; double dx2 = x2 - cx; double dy2 = y2 - cy; double len = Math.Sqrt(dx1 * dx1 + dy1 * dy1) + Math.Sqrt(dx2 * dx2 + dy2 * dy2); _num_steps = (int)AggMath.uround(len * 0.25 * _scale); if (_num_steps < 4) { _num_steps = 4; } double eachIncStep = 1.0 / _num_steps; double eachIncStep2 = eachIncStep * eachIncStep; double tmpx = (x1 - cx * 2.0 + x2) * eachIncStep2; double tmpy = (y1 - cy * 2.0 + y2) * eachIncStep2; _saved_fx = _fx = x1; _saved_fy = _fy = y1; _saved_dfx = _dfx = tmpx + (cx - x1) * (2.0 * eachIncStep); _saved_dfy = _dfy = tmpy + (cy - y1) * (2.0 * eachIncStep); _ddfx = tmpx * 2.0; _ddfy = tmpy * 2.0; _step = _num_steps; }
public void Init(double x1, double y1, double cx, double cy, double x2, double y2) { m_start_x = x1; m_start_y = y1; m_end_x = x2; m_end_y = y2; double dx1 = cx - x1; double dy1 = cy - y1; double dx2 = x2 - cx; double dy2 = y2 - cy; double len = Math.Sqrt(dx1 * dx1 + dy1 * dy1) + Math.Sqrt(dx2 * dx2 + dy2 * dy2); m_num_steps = (int)AggMath.uround(len * 0.25 * m_scale); if (m_num_steps < 4) { m_num_steps = 4; } double subdivide_step = 1.0 / m_num_steps; double subdivide_step2 = subdivide_step * subdivide_step; double tmpx = (x1 - cx * 2.0 + x2) * subdivide_step2; double tmpy = (y1 - cy * 2.0 + y2) * subdivide_step2; m_saved_fx = m_fx = x1; m_saved_fy = m_fy = y1; m_saved_dfx = m_dfx = tmpx + (cx - x1) * (2.0 * subdivide_step); m_saved_dfy = m_dfy = tmpy + (cy - y1) * (2.0 * subdivide_step); m_ddfx = tmpx * 2.0; m_ddfy = tmpy * 2.0; m_step = m_num_steps; }
public override void Line0(LineParameters lp) { if (doClipping) { int x1 = lp.x1; int y1 = lp.y1; int x2 = lp.x2; int y2 = lp.y2; int flags = ClipLiangBarsky.ClipLineSegment(ref x1, ref y1, ref x2, ref y2, clippingRectangle); if ((flags & 4) == 0) { if (flags != 0) { LineParameters lp2 = new LineParameters(x1, y1, x2, y2, AggMath.uround(AggMath.calc_distance(x1, y1, x2, y2))); Line0NoClip(lp2); } else { Line0NoClip(lp); } } } else { Line0NoClip(lp); } }
//---------------------------------------------------------------- public void Begin(double x, double y, int len) { // Calculate transformed coordinates at x1,y1 double xt = x; double yt = y; m_trans_dir.Transform(ref xt, ref yt); int x1 = AggMath.iround(xt * SUBPIXEL_SCALE); int y1 = AggMath.iround(yt * SUBPIXEL_SCALE); double dx; double dy; double delta = 1 / (double)SUBPIXEL_SCALE; // Calculate scale by X at x1,y1 dx = xt + delta; dy = yt; m_trans_inv.Transform(ref dx, ref dy); dx -= x; dy -= y; int sx1 = (int)AggMath.uround(SUBPIXEL_SCALE / Math.Sqrt(dx * dx + dy * dy)) >> SUBPIXEL_SHIFT; // Calculate scale by Y at x1,y1 dx = xt; dy = yt + delta; m_trans_inv.Transform(ref dx, ref dy); dx -= x; dy -= y; int sy1 = (int)AggMath.uround(SUBPIXEL_SCALE / Math.Sqrt(dx * dx + dy * dy)) >> SUBPIXEL_SHIFT; // Calculate transformed coordinates at x2,y2 x += len; xt = x; yt = y; m_trans_dir.Transform(ref xt, ref yt); int x2 = AggMath.iround(xt * SUBPIXEL_SCALE); int y2 = AggMath.iround(yt * SUBPIXEL_SCALE); // Calculate scale by X at x2,y2 dx = xt + delta; dy = yt; m_trans_inv.Transform(ref dx, ref dy); dx -= x; dy -= y; int sx2 = (int)AggMath.uround(SUBPIXEL_SCALE / Math.Sqrt(dx * dx + dy * dy)) >> SUBPIXEL_SHIFT; // Calculate scale by Y at x2,y2 dx = xt; dy = yt + delta; m_trans_inv.Transform(ref dx, ref dy); dx -= x; dy -= y; int sy2 = (int)AggMath.uround(SUBPIXEL_SCALE / Math.Sqrt(dx * dx + dy * dy)) >> SUBPIXEL_SHIFT; // Initialize the interpolators m_coord_x = new LineInterpolatorDDA2(x1, x2, (int)len); m_coord_y = new LineInterpolatorDDA2(y1, y2, (int)len); m_scale_x = new LineInterpolatorDDA2(sx1, sx2, (int)len); m_scale_y = new LineInterpolatorDDA2(sy1, sy2, (int)len); }
//bool AutoClose //{ // get { return m_auto_close; } // set { this.m_auto_close = value; } //} //-------------------------------------------------------------------- public void ResetGamma(IGammaFunction gamma_function) { for (int i = AA_SCALE - 1; i >= 0; --i) { m_gammaLut[i] = AggMath.uround( gamma_function.GetGamma((float)(i) / AA_MASK) * AA_MASK); } }
public PrebuiltGammaTable(IGammaFunction gamma_function) { for (int i = ScanlineRasterizer.AA_SCALE - 1; i >= 0; --i) { _gammaLut[i] = AggMath.uround( gamma_function.GetGamma((float)(i) / ScanlineRasterizer.AA_MASK) * ScanlineRasterizer.AA_MASK); } }
public override void ToPix(ref Color c) { c = new Color(c.A, (byte)AggMath.uround(r), c.G, c.B ); }
static LineProfileAnitAlias() { //GammaNone => just return i*** s_gamma_none = new byte[AA_SCALE]; for (int i = AA_SCALE - 1; i >= 0; --i) { s_gamma_none[i] = (byte)(AggMath.uround(((float)(i) / AA_MASK) * AA_MASK)); } }
public override void ToPix(ref Color c) { c = new Color( (byte)AggMath.uround(a), (byte)AggMath.uround(r), (byte)AggMath.uround(g), (byte)AggMath.uround(b) ); }
public override void Line3(LineParameters lp, int sx, int sy, int ex, int ey) { if (doClipping) { int x1 = lp.x1; int y1 = lp.y1; int x2 = lp.x2; int y2 = lp.y2; int flags = ClipLiangBarsky.ClipLineSegment(ref x1, ref y1, ref x2, ref y2, clippingRectangle); if ((flags & 4) == 0) { if (flags != 0) { LineParameters lp2 = new LineParameters(x1, y1, x2, y2, AggMath.uround(AggMath.calc_distance(x1, y1, x2, y2))); if ((flags & 1) != 0) { sx = x1 + (y2 - y1); sy = y1 - (x2 - x1); } else { while (Math.Abs(sx - lp.x1) + Math.Abs(sy - lp.y1) > lp2.len) { sx = (lp.x1 + sx) >> 1; sy = (lp.y1 + sy) >> 1; } } if ((flags & 2) != 0) { ex = x2 + (y2 - y1); ey = y2 - (x2 - x1); } else { while (Math.Abs(ex - lp.x2) + Math.Abs(ey - lp.y2) > lp2.len) { ex = (lp.x2 + ex) >> 1; ey = (lp.y2 + ey) >> 1; } } Line3NoClip(lp2, sx, sy, ex, ey); } else { Line3NoClip(lp, sx, sy, ex, ey); } } } else { Line3NoClip(lp, sx, sy, ex, ey); } }
void SetGamma(float g) { _gamma = g; float inv_g = (float)(1.0 / g); for (int i = GAMMA_SIZE - 1; i >= 0; --i) { _dir_gamma[i] = (byte)AggMath.uround(Math.Pow(i / (float)GAMMA_MASK, _gamma) * (float)GAMMA_MASK); _inv_gamma[i] = (byte)AggMath.uround(Math.Pow(i / (float)GAMMA_MASK, inv_g) * (float)GAMMA_MASK); } }
static PreBuiltLineAAGammaTable() { { byte[] gammaValues = new byte[LineProfileAnitAlias.AA_SCALE]; for (int i = LineProfileAnitAlias.AA_SCALE - 1; i >= 0; --i) { gammaValues[i] = (byte)(AggMath.uround(((float)(i) / LineProfileAnitAlias.AA_MASK) * LineProfileAnitAlias.AA_MASK)); } None = new PreBuiltLineAAGammaTable(gammaValues); } }
public override void ToPix(ref Color c) { //c.red = (byte)AggMath.uround(r); //c.green = (byte)AggMath.uround(g); //c.blue = (byte)AggMath.uround(b); c = new Color(c.A, (byte)AggMath.uround(r), (byte)AggMath.uround(g), (byte)AggMath.uround(b) ); }
public bool IsDiff(LineAAVertex val) { //*** NEED 64 bits long long dx = val.x - x; long dy = val.y - y; if ((dx + dy) == 0) { return(false); } return((len = AggMath.uround(Math.Sqrt(dx * dx + dy * dy))) > SIGDIFF); }
byte[] GetProfileBuffer(double w) { m_subpixel_width = (int)AggMath.uround(w * SUBPIX_SCALE); int size = m_subpixel_width + SUBPIX_SCALE * 6; if (size > m_profile.Length) { //clear ? m_profile = new byte[size]; //m_profile.Resize(size); } return(m_profile); }
public PreBuiltLineAAGammaTable(Func <float, float> gammaValueGenerator) { if (gammaValueGenerator != null) { _gammaValues = new byte[LineProfileAnitAlias.AA_SCALE]; for (int i = LineProfileAnitAlias.AA_SCALE - 1; i >= 0; --i) { //pass i to gamma func *** _gammaValues[i] = (byte)(AggMath.uround(gammaValueGenerator((float)i / LineProfileAnitAlias.AA_MASK) * LineProfileAnitAlias.AA_MASK)); } } else { _gammaValues = null; } }
public void Init(double x1, double y1, double cx1, double cy1, double cx2, double cy2, double x2, double y2) { m_start_x = x1; m_start_y = y1; m_end_x = x2; m_end_y = y2; double dx1 = cx1 - x1; double dy1 = cy1 - y1; double dx2 = cx2 - cx1; double dy2 = cy2 - cy1; double dx3 = x2 - cx2; double dy3 = y2 - cy2; double len = (Math.Sqrt(dx1 * dx1 + dy1 * dy1) + Math.Sqrt(dx2 * dx2 + dy2 * dy2) + Math.Sqrt(dx3 * dx3 + dy3 * dy3)) * 0.25 * m_scale; m_num_steps = (int)AggMath.uround(len); if (m_num_steps < 4) { m_num_steps = 4; } double subdivide_step = 1.0 / m_num_steps; double subdivide_step2 = subdivide_step * subdivide_step; double subdivide_step3 = subdivide_step * subdivide_step * subdivide_step; double pre1 = 3.0 * subdivide_step; double pre2 = 3.0 * subdivide_step2; double pre4 = 6.0 * subdivide_step2; double pre5 = 6.0 * subdivide_step3; double tmp1x = x1 - cx1 * 2.0 + cx2; double tmp1y = y1 - cy1 * 2.0 + cy2; double tmp2x = (cx1 - cx2) * 3.0 - x1 + x2; double tmp2y = (cy1 - cy2) * 3.0 - y1 + y2; m_saved_fx = m_fx = x1; m_saved_fy = m_fy = y1; m_saved_dfx = m_dfx = (cx1 - x1) * pre1 + tmp1x * pre2 + tmp2x * subdivide_step3; m_saved_dfy = m_dfy = (cy1 - y1) * pre1 + tmp1y * pre2 + tmp2y * subdivide_step3; m_saved_ddfx = m_ddfx = tmp1x * pre4 + tmp2x * pre5; m_saved_ddfy = m_ddfy = tmp1y * pre4 + tmp2y * pre5; m_dddfx = tmp2x * pre5; m_dddfy = tmp2y * pre5; m_step = m_num_steps; }
void SetGamma(IGammaFunction gamma_function) { //TODO:review gamma again*** if (gamma_function == null) { m_gamma = s_gamma_none; } else { m_gamma = new byte[AA_SCALE]; for (int i = AA_SCALE - 1; i >= 0; --i) { //pass i to gamma func *** m_gamma[i] = (byte)(AggMath.uround(gamma_function.GetGamma((float)(i) / AA_MASK) * AA_MASK)); } } }
//---------------------------------------------------------------- public void ReSync(double xe, double ye, int len) { // Assume x1,y1 are equal to the ones at the previous end point int x1 = m_coord_x.Y; int y1 = m_coord_y.Y; int sx1 = m_scale_x.Y; int sy1 = m_scale_y.Y; // Calculate transformed coordinates at x2,y2 double xt = xe; double yt = ye; m_trans_dir.Transform(ref xt, ref yt); int x2 = AggMath.iround(xt * SUBPIXEL_SCALE); int y2 = AggMath.iround(yt * SUBPIXEL_SCALE); double delta = 1 / (double)SUBPIXEL_SCALE; double dx; double dy; // Calculate scale by X at x2,y2 dx = xt + delta; dy = yt; m_trans_inv.Transform(ref dx, ref dy); dx -= xe; dy -= ye; int sx2 = (int)AggMath.uround(SUBPIXEL_SCALE / Math.Sqrt(dx * dx + dy * dy)) >> SUBPIXEL_SHIFT; // Calculate scale by Y at x2,y2 dx = xt; dy = yt + delta; m_trans_inv.Transform(ref dx, ref dy); dx -= xe; dy -= ye; int sy2 = (int)AggMath.uround(SUBPIXEL_SCALE / Math.Sqrt(dx * dx + dy * dy)) >> SUBPIXEL_SHIFT; // Initialize the interpolators m_coord_x = new LineInterpolatorDDA2(x1, x2, (int)len); m_coord_y = new LineInterpolatorDDA2(y1, y2, (int)len); m_scale_x = new LineInterpolatorDDA2(sx1, sx2, (int)len); m_scale_y = new LineInterpolatorDDA2(sy1, sy2, (int)len); }
// Create //-------------------------------------------------------------------- public void Create(IBitmapSrc src) { // we are going to create a dialated image for filtering // we add m_dilation pixels to every side of the image and then copy the image in the x // dirrection into each end so that we can sample into this image to get filtering on x repeating // if the original image look like this // // 123456 // // the new image would look like this // // 0000000000 // 0000000000 // 5612345612 // 0000000000 // 0000000000 _height = (int)AggMath.uceil(src.Height); _width = (int)AggMath.uceil(src.Width); _width_hr = (int)AggMath.uround(src.Width * LineAA.SUBPIXEL_SCALE); _half_height_hr = (int)AggMath.uround(src.Height * LineAA.SUBPIXEL_SCALE / 2); _offset_y_hr = _dilation_hr + _half_height_hr - LineAA.SUBPIXEL_SCALE / 2; _half_height_hr += LineAA.SUBPIXEL_SCALE / 2; int bufferWidth = _width + _dilation * 2; int bufferHeight = _height + _dilation * 2; int bytesPerPixel = src.BitDepth / 8; int newSizeInBytes = bufferWidth * bufferHeight * bytesPerPixel; if (_DataSizeInBytes < newSizeInBytes) { _DataSizeInBytes = newSizeInBytes; _data.Dispose(); IntPtr nativeBuff = System.Runtime.InteropServices.Marshal.AllocHGlobal(_DataSizeInBytes); _data = new TempMemPtr(nativeBuff, _DataSizeInBytes); } _buf = new PixelProcessing.SubBitmapBlender(_data, 0, bufferWidth, bufferHeight, bufferWidth * bytesPerPixel, src.BitDepth, bytesPerPixel); unsafe { using (TempMemPtr destMemPtr = _buf.GetBufferPtr()) using (TempMemPtr srcMemPtr = src.GetBufferPtr()) { int *destBuffer = (int *)destMemPtr.Ptr; int *srcBuffer = (int *)srcMemPtr.Ptr; // copy the image into the middle of the dest for (int y = 0; y < _height; y++) { for (int x = 0; x < _width; x++) { int sourceOffset = src.GetBufferOffsetXY32(x, y); int destOffset = _buf.GetBufferOffsetXY32(_dilation, y + _dilation); destBuffer[destOffset] = srcBuffer[sourceOffset]; } } // copy the first two pixels form the end into the begining and from the begining into the end for (int y = 0; y < _height; y++) { int s1Offset = src.GetBufferOffsetXY32(0, y); int d1Offset = _buf.GetBufferOffsetXY32(_dilation + _width, y); int s2Offset = src.GetBufferOffsetXY32(_width - _dilation, y); int d2Offset = _buf.GetBufferOffsetXY32(0, y); for (int x = 0; x < _dilation; x++) { destBuffer[d1Offset++] = srcBuffer[s1Offset++]; destBuffer[d2Offset++] = srcBuffer[s2Offset++]; } } } } }
// Create //-------------------------------------------------------------------- public void Create(IBitmapSrc src) { // we are going to create a dialated image for filtering // we add m_dilation pixels to every side of the image and then copy the image in the x // dirrection into each end so that we can sample into this image to get filtering on x repeating // if the original image look like this // // 123456 // // the new image would look like this // // 0000000000 // 0000000000 // 5612345612 // 0000000000 // 0000000000 m_height = (int)AggMath.uceil(src.Height); m_width = (int)AggMath.uceil(src.Width); m_width_hr = (int)AggMath.uround(src.Width * LineAA.SUBPIXEL_SCALE); m_half_height_hr = (int)AggMath.uround(src.Height * LineAA.SUBPIXEL_SCALE / 2); m_offset_y_hr = m_dilation_hr + m_half_height_hr - LineAA.SUBPIXEL_SCALE / 2; m_half_height_hr += LineAA.SUBPIXEL_SCALE / 2; int bufferWidth = m_width + m_dilation * 2; int bufferHeight = m_height + m_dilation * 2; int bytesPerPixel = src.BitDepth / 8; int newSizeInBytes = bufferWidth * bufferHeight * bytesPerPixel; if (m_DataSizeInBytes < newSizeInBytes) { m_DataSizeInBytes = newSizeInBytes; m_data = new int[m_DataSizeInBytes / 4]; } m_buf = new PixelProcessing.SubBitmapBlender(m_data, 0, bufferWidth, bufferHeight, bufferWidth * bytesPerPixel, src.BitDepth, bytesPerPixel); unsafe { CpuBlit.Imaging.TempMemPtr destMemPtr = m_buf.GetBufferPtr(); CpuBlit.Imaging.TempMemPtr srcMemPtr = src.GetBufferPtr(); int *destBuffer = (int *)destMemPtr.Ptr; int *srcBuffer = (int *)srcMemPtr.Ptr; // copy the image into the middle of the dest for (int y = 0; y < m_height; y++) { for (int x = 0; x < m_width; x++) { int sourceOffset = src.GetBufferOffsetXY32(x, y); int destOffset = m_buf.GetBufferOffsetXY32(m_dilation, y + m_dilation); destBuffer[destOffset] = srcBuffer[sourceOffset]; } } // copy the first two pixels form the end into the begining and from the begining into the end for (int y = 0; y < m_height; y++) { int s1Offset = src.GetBufferOffsetXY32(0, y); int d1Offset = m_buf.GetBufferOffsetXY32(m_dilation + m_width, y); int s2Offset = src.GetBufferOffsetXY32(m_width - m_dilation, y); int d2Offset = m_buf.GetBufferOffsetXY32(0, y); for (int x = 0; x < m_dilation; x++) { destBuffer[d1Offset++] = srcBuffer[s1Offset++]; destBuffer[d2Offset++] = srcBuffer[s2Offset++]; } } srcMemPtr.Release(); destMemPtr.Release(); } }
public int Calculate(int x, int y, int d) { return((int)AggMath.uround(System.Math.Abs(System.Math.Atan2((double)(y), (double)(x))) * (double)(d) / System.Math.PI)); }