public static HyperspectralImage Load(Stream stream, HyperspectralImageInfo info) { using (var reader = new BinaryReader(stream)) { var dataPtr = Marshal.AllocHGlobal(info.Bands * info.Height * info.Width * 2); unsafe { var destPointer = (UInt16 *)dataPtr.ToPointer(); for (int height = 0; height < info.Height; height++) { for (int width = 0; width < info.Width; width++) { for (int band = 0; band < info.Bands; band++) { ushort t = reader.ReadByte(); t <<= 8; t += reader.ReadByte(); *(destPointer + info.Width * info.Height * band + info.Width * height + width) = t; } } } } return(new HyperspectralImage(info, dataPtr)); } }
public static HyperspectralImage Load(IntPtr data, HyperspectralImageInfo info) { var dataPtr = Marshal.AllocHGlobal(info.Bands * info.Height * info.Width * 2); unsafe { var sourcePointer = (UInt16 *)data.ToPointer(); var destPointer = (UInt16 *)dataPtr.ToPointer(); for (int i = 0; i < info.Bands * info.Height * info.Width; i++) { *(destPointer + i) = *(sourcePointer + i); } } return(new HyperspectralImage(info, dataPtr)); }
protected HyperspectralImage(HyperspectralImageInfo info, IntPtr data) { _disposed = false; _imageInfo = info; _data = data; }