static FExtent GetFExtent(int srcLength, int weightsLength) { FExtentKey key = new FExtentKey(srcLength, weightsLength); FExtent extent; lock (fCache) { extent = (FExtent)fCache[key]; } int fOffset = -weightsLength / 2; if (extent == null) { extent = new FExtent(); extent.fStarts = new int[srcLength]; extent.fEnds = new int[srcLength]; for (int dst = 0; dst < srcLength; ++dst) { int startSrc = dst + fOffset; if (startSrc < 0) { extent.fStarts[dst] = -startSrc; } else { extent.fStarts[dst] = 0; } int end = startSrc + weightsLength; int endDelta = srcLength - end; if (endDelta < 0) { extent.fEnds[dst] = weightsLength + endDelta; } else { extent.fEnds[dst] = weightsLength; } } lock (fCache) { if (fCache.Count > 16) { object top = fCacheQ.Dequeue(); fCache.Remove(top); } fCache[key] = extent; fCacheQ.Enqueue(key); } } return(extent); }
private static FExtent GetFExtent(int srcLength, int weightsLength) { FExtentKey key = new FExtentKey(srcLength, weightsLength); FExtent extent; lock (fCache) { extent = (FExtent)fCache[key]; } int fOffset = -weightsLength / 2; if (extent == null) { extent = new FExtent(); extent.fStarts = new int[srcLength]; extent.fEnds = new int[srcLength]; for (int dst = 0; dst < srcLength; ++dst) { int startSrc = dst + fOffset; if (startSrc < 0) { extent.fStarts[dst] = -startSrc; } else { extent.fStarts[dst] = 0; } int end = startSrc + weightsLength; int endDelta = srcLength - end; if (endDelta < 0) { extent.fEnds[dst] = weightsLength + endDelta; } else { extent.fEnds[dst] = weightsLength; } } lock (fCache) { if (fCache.Count > 16) { object top = fCacheQ.Dequeue(); fCache.Remove(top); } fCache[key] = extent; fCacheQ.Enqueue(key); } } return extent; }
public void DrawMap() { view.SetValue(view.MyMapExtent, panel1.ClientRectangle); if (backwindow != null) { backwindow.Dispose(); } backwindow = new Bitmap(panel1.ClientRectangle.Width, panel1.ClientRectangle.Height); Graphics g = Graphics.FromImage(backwindow); g.FillRectangle(new SolidBrush(Color.AliceBlue), panel1.ClientRectangle); FVertex v1 = view.ToMapVertex(new Point(0, view.myWindowSize.Height - 1)); FVertex v2 = view.ToMapVertex(new Point(view.myWindowSize.Width - 1, 0)); FExtent displayextent = new FExtent(v2, v1); if (layer != null) { layer.draw(g, view, displayextent); } Graphics graphics = panel1.CreateGraphics(); graphics.DrawImage(backwindow, 0, 0); }
public unsafe void RenderConvolutionFilter(int[][] weights, int offset, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length) { int weightsWidth = weights[0].Length; int weightsHeight = weights.Length; int fYOffset = -(weightsHeight / 2); int fXOffset = -(weightsWidth / 2); // we cache the beginning and ending horizontal indices into the weights matrix // for every source pixel X location // i.e. for src[x,y], where we're concerned with x, what weight[x,y] horizontal // extent should we worry about? // this way we end up with less branches and faster code (hopefully?!) FExtent fxExtent = GetFExtent(srcArgs.Surface.Width, weightsWidth); FExtent fyExtent = GetFExtent(srcArgs.Surface.Height, weightsHeight); for (int ri = startIndex; ri < startIndex + length; ++ri) { Rectangle roi = rois[ri]; for (int y = roi.Top; y < roi.Bottom; ++y) { ColorBgra *dstPixel = dstArgs.Surface.GetPointAddressUnchecked(roi.Left, y); int fyStart = fyExtent.fStarts[y]; int fyEnd = fyExtent.fEnds[y]; for (int x = roi.Left; x < roi.Right; ++x) { int redSum = 0; int greenSum = 0; int blueSum = 0; int alphaSum = 0; int colorFactor = 0; int alphaFactor = 0; int fxStart = fxExtent.fStarts[x]; int fxEnd = fxExtent.fEnds[x]; for (int fy = fyStart; fy < fyEnd; ++fy) { int srcY = y + fy + fYOffset; int srcX1 = x + fXOffset + fxStart; ColorBgra *srcPixel = srcArgs.Surface.GetPointAddressUnchecked(srcX1, srcY); int[] wRow = weights[fy]; for (int fx = fxStart; fx < fxEnd; ++fx) { int srcX = fx + srcX1; int weight = wRow[fx]; ColorBgra c = *srcPixel; alphaFactor += weight; weight = weight * (c.A + (c.A >> 7)); colorFactor += weight; weight >>= 8; redSum += c.R * weight; blueSum += c.B * weight; greenSum += c.G * weight; alphaSum += c.A * weight; ++srcPixel; } } colorFactor /= 256; if (colorFactor != 0) { redSum /= colorFactor; greenSum /= colorFactor; blueSum /= colorFactor; } else { redSum = 0; greenSum = 0; blueSum = 0; } if (alphaFactor != 0) { alphaSum /= alphaFactor; } else { alphaSum = 0; } redSum += offset; greenSum += offset; blueSum += offset; alphaSum += offset; #region clamp values to [0,255] if (redSum < 0) { redSum = 0; } else if (redSum > 255) { redSum = 255; } if (greenSum < 0) { greenSum = 0; } else if (greenSum > 255) { greenSum = 255; } if (blueSum < 0) { blueSum = 0; } else if (blueSum > 255) { blueSum = 255; } if (alphaSum < 0) { alphaSum = 0; } else if (alphaSum > 255) { alphaSum = 255; } #endregion *dstPixel = ColorBgra.FromBgra((byte)blueSum, (byte)greenSum, (byte)redSum, (byte)alphaSum); ++dstPixel; } } } }
private void panel1_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { switch (MouseCommand) { case MOUSECOMMAND.Select: { if (layer == null) { break; } layer.ClearSelection(); if (e.X == MouseStartX && e.Y == MouseStartY) //点选 { FFeature feature = layer.SelectByClick(new Point(e.X, e.Y), view); if (feature != null) { feature.selected = true; } } else //框选 { FExtent extent = view.RectToExtent(new Rectangle( Math.Min(e.X, MouseStartX), Math.Min(e.Y, MouseStartY), Math.Abs(e.X - MouseStartX), Math.Abs(e.Y - MouseStartY))); List <FFeature> features = layer.SelectByExtent(extent); for (int j = 0; j < features.Count; j++) { features[j].selected = true; } } DrawMap(); if (attributeDialog != null) { attributeDialog.UpdataSelection(); } break; } case MOUSECOMMAND.ZoomIn: { if (e.X == MouseStartX && e.Y == MouseStartY) { FVertex mouselocation = view.ToMapVertex(new Point(e.X, e.Y)); double ZoomInfactor = 0.9; double newwidth = view.MyMapExtent.width * ZoomInfactor; double newheight = view.MyMapExtent.height * ZoomInfactor; double newminx = mouselocation.getX() - (mouselocation.getX() - view.MyMapExtent.minX) * ZoomInfactor; double newminy = mouselocation.getY() - (mouselocation.getY() - view.MyMapExtent.minY) * ZoomInfactor; view.MyMapExtent.setValue(new FVertex(newminx + newwidth, newminy + newheight), new FVertex(newminx, newminy)); } else { view.MyMapExtent = view.RectToExtent(new Rectangle( Math.Min(e.X, MouseStartX), Math.Min(e.Y, MouseStartY), Math.Abs(e.X - MouseStartX), Math.Abs(e.Y - MouseStartY))); } DrawMap(); break; } case MOUSECOMMAND.ZoomOut: { if (e.X == MouseStartX && e.Y == MouseStartY) { FVertex mouselocation = view.ToMapVertex(new Point(e.X, e.Y)); double ZoomInfactor = 0.9; double newwidth = view.MyMapExtent.width / ZoomInfactor; double newheight = view.MyMapExtent.height / ZoomInfactor; double newminx = mouselocation.getX() - (mouselocation.getX() - view.MyMapExtent.minX) / ZoomInfactor; double newminy = mouselocation.getY() - (mouselocation.getY() - view.MyMapExtent.minY) / ZoomInfactor; view.MyMapExtent.setValue(new FVertex(newminx + newwidth, newminy + newheight), new FVertex(newminx, newminy)); } else { FExtent extent = view.RectToExtent(new Rectangle( Math.Min(e.X, MouseStartX), Math.Min(e.Y, MouseStartY), Math.Abs(e.X - MouseStartX), Math.Abs(e.Y - MouseStartY))); //新的地图范围 double newwidth = view.MyMapExtent.width * view.MyMapExtent.width / extent.width; double newheight = view.MyMapExtent.height * view.MyMapExtent.height / extent.height; double newminx = extent.minX - (extent.minX - view.MyMapExtent.minX) * newwidth / view.MyMapExtent.width; double newminy = extent.minY - (extent.minY - view.MyMapExtent.minY) * newheight / view.MyMapExtent.height; view.MyMapExtent.setValue(new FVertex(newminx + newwidth, newminy + newheight), new FVertex(newminx, newminy)); } DrawMap(); break; } case MOUSECOMMAND.Pan: { FVertex C1 = view.MyMapExtent.mapcenter; FVertex M1 = view.ToMapVertex(new Point(MouseStartX, MouseStartY)); FVertex M2 = view.ToMapVertex(new Point(e.X, e.Y)); FVertex C2 = new FVertex(C1.getX() - (M2.getX() - M1.getX()), C1.getY() - (M2.getY() - M1.getY())); view.MyMapExtent.SetMapCenter(C2); DrawMap(); break; } } } }