public void Write(System.Int32 data) { unsafe { System.Int32 *pPtr = &data; Write((IntPtr)pPtr, sizeof(System.Int32)); } }
/// <summary> /// Performs bitwise inversion on source 1bpp Bitmap and returns result. /// </summary> public static unsafe Bitmap invert(Bitmap source) { if (source.PixelFormat != PixelFormat.Format1bppIndexed) { throw new ArgumentException("Unsuported Bitmap format! Expected PixelFormat.Format1bppIndexed"); } int width = source.Width, height = source.Height; Bitmap converted = new Bitmap(width, height, PixelFormat.Format1bppIndexed); Rectangle rectangle = new Rectangle(0, 0, width, height); BitmapData sourceData = source.LockBits(rectangle, ImageLockMode.ReadOnly, source.PixelFormat); BitmapData convertedData = converted.LockBits(rectangle, ImageLockMode.ReadWrite, converted.PixelFormat); System.Int32 *sourcePointer = (System.Int32 *)sourceData.Scan0; System.Int32 *convertedPointer = (System.Int32 *)convertedData.Scan0; int end = (sourceData.Stride / 4) * height; for (int i = 0; i < end; ++i) { convertedPointer[i] = (System.Int32) ~sourcePointer[i]; } source.UnlockBits(sourceData); converted.UnlockBits(convertedData); return(converted); }
private IGeometry FetchShape(System.Int16 index) { unsafe { System.Int32 err_no = 0; SE_SHAPE shape_val = new SE_SHAPE(); System.Int32 *part_offsets = null; System.Int32 *subp_offsets = null; SE_POINT * points = null; try { err_no = Wrapper10.SE_shape_create(new SE_COORDREF(), ref shape_val); if (err_no != 0) { return(null); } err_no = Wrapper10.SE_stream_get_shape(_stream.SeStream, index, shape_val); if (err_no != 0) { return(null); } Int32 shapeType = 0, numPoints = 0, numParts = 0, numSubparts = 0; err_no = Wrapper10.SE_shape_get_type(shape_val, ref shapeType); if (err_no != 0 || shapeType == CONST.SG_NIL_SHAPE) { return(null); } err_no = Wrapper10.SE_shape_get_num_points(shape_val, 0, 0, ref numPoints); if (err_no != 0) { return(null); } err_no = Wrapper10.SE_shape_get_num_parts(shape_val, ref numParts, ref numSubparts); if (err_no != 0) { return(null); } part_offsets = (System.Int32 *)Marshal.AllocHGlobal(((int)numParts + 1) * sizeof(System.Int32)); subp_offsets = (System.Int32 *)Marshal.AllocHGlobal(((int)numSubparts + 1) * sizeof(System.Int32)); points = (SE_POINT *)Marshal.AllocHGlobal((int)numPoints * sizeof(SE_POINT)); part_offsets[numParts] = (int)numSubparts; subp_offsets[numSubparts] = (int)numPoints; err_no = Wrapper10.SE_shape_get_all_points( shape_val, SE_ROTATION_TYPE.SE_DEFAULT_ROTATION, (IntPtr)part_offsets, (IntPtr)subp_offsets, (IntPtr)points, (IntPtr)null, (IntPtr)null); if (err_no != 0) { return(null); } IGeometry ret = null; switch (shapeType) { case CONST.SG_POINT_SHAPE: if (numPoints == 1) { ret = new Point(points[0].x, points[0].y); } else if (numPoints > 1) { MultiPoint mPoint_ = new MultiPoint(); for (int i = 0; i < numPoints; i++) { mPoint_.AddPoint(new Point(points[i].x, points[i].y)); } ret = mPoint_; } break; case CONST.SG_MULTI_POINT_SHAPE: MultiPoint mPoint = new MultiPoint(); for (int i = 0; i < numPoints; i++) { mPoint.AddPoint(new Point(points[i].x, points[i].y)); } ret = mPoint; break; case CONST.SG_LINE_SHAPE: case CONST.SG_SIMPLE_LINE_SHAPE: case CONST.SG_MULTI_LINE_SHAPE: case CONST.SG_MULTI_SIMPLE_LINE_SHAPE: Polyline polyline = new Polyline(); for (int s = 0; s < numSubparts; s++) { Path path = new Path(); int to = subp_offsets[s + 1]; for (int i = subp_offsets[s]; i < to; i++) { path.AddPoint(new Point(points[i].x, points[i].y)); } polyline.AddPath(path); } ret = polyline; break; case CONST.SG_AREA_SHAPE: case CONST.SG_MULTI_AREA_SHAPE: Polygon polygon = new Polygon(); for (int s = 0; s < numSubparts; s++) { Ring ring = new Ring(); int to = subp_offsets[s + 1]; for (int i = subp_offsets[s]; i < to; i++) { ring.AddPoint(new Point(points[i].x, points[i].y)); } polygon.AddRing(ring); } ret = polygon; break; } return(ret); } catch { return(null); } finally { if (part_offsets != null) { Marshal.FreeHGlobal((System.IntPtr)part_offsets); } if (subp_offsets != null) { Marshal.FreeHGlobal((System.IntPtr)subp_offsets); } if (points != null) { Marshal.FreeHGlobal((System.IntPtr)points); } if (shape_val.handle != IntPtr.Zero) { Wrapper10.SE_shape_free(shape_val); } } } }
public static System.Int32 SE_GenerateGeometry(SE_SHAPE shape, IGeometry geometry, SE_ENVELOPE maxExtent) { if (geometry == null) { return(-1); } unsafe { SE_POINT * points = null; System.Int32 *parts = null; switch (geometry.GeometryType) { case geometryType.Envelope: SE_ENVELOPE seEnvelope = new SE_ENVELOPE(); IEnvelope env = geometry.Envelope; seEnvelope.minx = Math.Max(env.minx, maxExtent.minx); seEnvelope.miny = Math.Max(env.miny, maxExtent.miny); seEnvelope.maxx = Math.Min(env.maxx, maxExtent.maxx); seEnvelope.maxy = Math.Min(env.maxy, maxExtent.maxy); if (seEnvelope.minx == seEnvelope.maxx && seEnvelope.miny == seEnvelope.maxy) { /* fudge a rectangle so we have a valid one for generate_rectangle */ /* FIXME: use the real shape for the query and set the filter_type * to be an appropriate type */ seEnvelope.minx = seEnvelope.minx - 0.001; seEnvelope.maxx = seEnvelope.maxx + 0.001; seEnvelope.miny = seEnvelope.miny - 0.001; seEnvelope.maxy = seEnvelope.maxy + 0.001; } return(Wrapper92.SE_shape_generate_rectangle(ref seEnvelope, shape)); case geometryType.Point: points = (SE_POINT *)Marshal.AllocHGlobal(sizeof(SE_POINT) * 1); points[0].x = ((IPoint)geometry).X; points[0].y = ((IPoint)geometry).Y; return(Wrapper92.SE_shape_generate_point(1, (IntPtr)points, (IntPtr)null, (IntPtr)null, shape)); case geometryType.Polyline: IPointCollection col1 = gView.Framework.SpatialAlgorithms.Algorithm.GeometryPoints(geometry, false); IPolyline polyline = (IPolyline)geometry; points = (SE_POINT *)Marshal.AllocHGlobal(sizeof(SE_POINT) * (col1.PointCount)); parts = (Int32 *)Marshal.AllocHGlobal(sizeof(Int32) * polyline.PathCount); int pos1 = 0; for (int i = 0; i < polyline.PathCount; i++) { parts[i] = pos1; IPath path = polyline[i]; if (path.PointCount == 0) { continue; } for (int p = 0; p < path.PointCount; p++) { points[pos1].x = path[p].X; points[pos1].y = path[p].Y; pos1++; } } return(Wrapper92.SE_shape_generate_line(pos1, polyline.PathCount, (IntPtr)parts, (IntPtr)points, (IntPtr)null, (IntPtr)null, shape)); case geometryType.Polygon: IPointCollection col2 = gView.Framework.SpatialAlgorithms.Algorithm.GeometryPoints(geometry, false); IPolygon polygon = (IPolygon)geometry; points = (SE_POINT *)Marshal.AllocHGlobal(sizeof(SE_POINT) * (col2.PointCount + polygon.RingCount)); parts = (Int32 *)Marshal.AllocHGlobal(sizeof(Int32) * polygon.RingCount); int pos2 = 0; for (int i = 0; i < polygon.RingCount; i++) { parts[i] = pos2; IRing ring = polygon[i]; if (ring.PointCount == 0) { continue; } for (int p = 0; p < ring.PointCount; p++) { points[pos2].x = ring[p].X; points[pos2].y = ring[p].Y; pos2++; } points[pos2].x = ring[0].X; points[pos2].y = ring[0].Y; pos2++; } return(Wrapper92.SE_shape_generate_polygon(pos2, polygon.RingCount, (IntPtr)parts, (IntPtr)points, (IntPtr)null, (IntPtr)null, shape)); case geometryType.Aggregate: if (((AggregateGeometry)geometry).GeometryCount == 1) { return(SE_GenerateGeometry(shape, ((AggregateGeometry)geometry)[0], maxExtent)); } //else //{ // Polygon polygon = new Polygon(); // for (int i = 0; i < ((AggregateGeometry)geometry).GeometryCount; i++) // { // IGeometry g = ((AggregateGeometry)geometry)[i]; // if (g is IPolygon) // { // for (int p = 0; p < ((IPolygon)g).RingCount; p++) // polygon.AddRing(((Polygon)g)[p]); // } // } // if (polygon.RingCount > 0) return SE_GenerateGeometry(shape, polygon, maxExtent); //} return(-1); } } return(-1); }