public override void ToPix(ref Color c) { c.red = (byte)AggBasics.uround(r); c.green = (byte)AggBasics.uround(g); c.blue = (byte)AggBasics.uround(b); c.alpha = (byte)AggBasics.uround(a); }
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, AggBasics.uround(AggMath.calc_distance(x1, y1, x2, y2))); Line0NoClip(lp2); } else { Line0NoClip(lp); } } } else { Line0NoClip(lp); } }
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)AggBasics.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 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 = AggBasics.iround(xt * SUBPIXEL_SCALE); int y1 = AggBasics.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)AggBasics.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)AggBasics.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 = AggBasics.iround(xt * SUBPIXEL_SCALE); int y2 = AggBasics.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)AggBasics.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)AggBasics.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); }
void SetGamma(IGammaFunction gamma_function) { int i; for (i = 0; i < AA_SCALE; i++) { m_gamma[i] = (byte)(AggBasics.uround(gamma_function.GetGamma((float)(i) / AA_MASK) * AA_MASK)); } }
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)(AggBasics.uround(((float)(i) / AA_MASK) * AA_MASK)); } }
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)AggBasics.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; }
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, AggBasics.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); } }
public bool IsDiff(LineAAVertex val) { int dx = val.x - x; int dy = val.y - y; if ((dx + dy) == 0) { return(false); } return((len = AggBasics.uround(Math.Sqrt(dx * dx + dy * dy))) > SIGDIFF); }
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 = AggBasics.uround(Math.Sqrt(dx * dx + dy * dy))) > SIGDIFF); }
byte[] GetProfileBuffer(double w) { m_subpixel_width = (int)AggBasics.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); }
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)(AggBasics.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 = AggBasics.iround(xt * SUBPIXEL_SCALE); int y2 = AggBasics.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)AggBasics.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)AggBasics.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(IImageReaderWriter 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)AggBasics.uceil(src.Height); m_width = (int)AggBasics.uceil(src.Width); m_width_hr = (int)AggBasics.uround(src.Width * LineAA.SUBPIXEL_SCALE); m_half_height_hr = (int)AggBasics.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 byte[m_DataSizeInBytes]; } m_buf = new ChildImage(m_data, 0, bufferWidth, bufferHeight, bufferWidth * bytesPerPixel, src.BitDepth, bytesPerPixel); byte[] destBuffer = m_buf.GetBuffer(); byte[] srcBuffer = src.GetBuffer(); // 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.GetBufferOffsetXY(x, y); int destOffset = m_buf.GetBufferOffsetXY(m_dilation, y + m_dilation); for (int channel = 0; channel < bytesPerPixel; channel++) { 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.GetBufferOffsetXY(0, y); int d1Offset = m_buf.GetBufferOffsetXY(m_dilation + m_width, y); int s2Offset = src.GetBufferOffsetXY(m_width - m_dilation, y); int d2Offset = m_buf.GetBufferOffsetXY(0, y); for (int x = 0; x < m_dilation; x++) { for (int channel = 0; channel < bytesPerPixel; channel++) { destBuffer[d1Offset++] = srcBuffer[s1Offset++]; destBuffer[d2Offset++] = srcBuffer[s2Offset++]; } } } }
public override void ToPix(ref Color c) { c.red = (byte)AggBasics.uround(r); }
public int Calculate(int x, int y, int d) { return((int)AggBasics.uround(System.Math.Abs(System.Math.Atan2((double)(y), (double)(x))) * (double)(d) / System.Math.PI)); }