/// <summary> /// Создаёт файл-образ раздела жёсткого диска с файловой системой DehaxFS с параметрами. /// </summary> /// <param name="diskPartitionSize">Размер раздела</param> /// <param name="diskClusterFactor">Размер кластера, множитель секторов диска</param> public DFSImage(long diskPartitionSize, byte diskClusterFactor) { diskClusterFactor = (byte)Math.Pow(2, diskClusterFactor - 1); _diskPartitionSize = diskPartitionSize; _diskClusterFactor = diskClusterFactor; _diskClusterSize = DISK_BYTES_PER_SECTOR * diskClusterFactor; _bitMap = new BitMap((int)(_diskPartitionSize / _diskClusterSize)); _inodes = new Inodes((int)(_diskPartitionSize / _diskClusterSize)); _rootDirectory = new RootDirectory(_diskClusterSize); _emptyData = new byte[_diskPartitionSize - Marshal.SizeOf<Superblock>() - _bitMap.GetLength() - _inodes.GetLength() - _rootDirectory.GetLength()]; _superblock = new Superblock() { filesystemType = 0x28, numClusters = (int)(_diskPartitionSize / _diskClusterSize), clusterFactor = diskClusterFactor, inodeArraySize = _inodes.GetLength(), bitMapSize = _bitMap.GetLength(), numFreeClusters = _emptyData.Length / _diskClusterSize, numFreeInode = (int)(_diskPartitionSize / _diskClusterSize - 1) }; InitializeFileSystem(); }
public AllocationContext(StackAllocator stackAlloc, RegisterMasks masks, int intervalsCount) { StackAlloc = stackAlloc; Masks = masks; Active = new BitMap(Allocators.Default, intervalsCount); Inactive = new BitMap(Allocators.Default, intervalsCount); PopulateFreePositions(RegisterType.Integer, out _intFreePositions, out _intFreePositionsCount); PopulateFreePositions(RegisterType.Vector, out _vecFreePositions, out _vecFreePositionsCount); void PopulateFreePositions(RegisterType type, out int[] positions, out int count) { positions = new int[RegistersCount]; count = BitOperations.PopCount((uint)masks.GetAvailableRegisters(type)); int mask = masks.GetAvailableRegisters(type); for (int i = 0; i < positions.Length; i++) { if ((mask & (1 << i)) != 0) { positions[i] = int.MaxValue; } } } }
public bool SaveDataIntoBitmap() { if (BitMap == null) { return(false); } if (data == null) { return(false); } BitmapData bData = BitMap.LockBits(new Rectangle(0, 0, BitMap.Width, BitMap.Height), ImageLockMode.WriteOnly, BitMap.PixelFormat); bool bottomToTop = bData.Stride < 0; int size = Math.Abs(bData.Stride) * bData.Height; Debug.Assert(size == data.Length); if (!bottomToTop) { System.Runtime.InteropServices.Marshal.Copy(bData.Scan0, data, 0, size); } else { for (int i = 0; i < Height; i++) { IntPtr pointer = new IntPtr(bData.Scan0.ToInt32() - stride * i); System.Runtime.InteropServices.Marshal.Copy(data, stride * i, pointer, stride); } } BitMap.UnlockBits(bData); return(true); }
public void ShutDown() { // Release the light object. Light = null; // Release the camera object. Camera = null; // Release the model object. BitMap?.Shutdown(); BitMap = null; // Release the text object. Text?.Shutdown(); Text = null; // Release the light shader object. LightShader?.ShutDown(); LightShader = null; // Release the model object. Model?.Shutdown(); Model = null; // Release the input object. Input?.Shutdown(); Input = null; // Release the texture shader object. TextureShader?.ShutDown(); TextureShader = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
/// <summary> /// Создаёт файл-образ раздела жёсткого диска с файловой системой DehaxFS с параметрами. /// </summary> /// <param name="diskPartitionSize">Размер раздела</param> /// <param name="diskClusterFactor">Размер кластера, множитель секторов диска</param> public DFSImage(long diskPartitionSize, byte diskClusterFactor) { diskClusterFactor = (byte)Math.Pow(2, diskClusterFactor - 1); _diskPartitionSize = diskPartitionSize; _diskClusterFactor = diskClusterFactor; _diskClusterSize = DISK_BYTES_PER_SECTOR * diskClusterFactor; _bitMap = new BitMap((int)(_diskPartitionSize / _diskClusterSize)); _inodes = new Inodes((int)(_diskPartitionSize / _diskClusterSize)); _rootDirectory = new RootDirectory(_diskClusterSize); _emptyData = new byte[_diskPartitionSize - Marshal.SizeOf <Superblock>() - _bitMap.GetLength() - _inodes.GetLength() - _rootDirectory.GetLength()]; _superblock = new Superblock() { filesystemType = 0x28, numClusters = (int)(_diskPartitionSize / _diskClusterSize), clusterFactor = diskClusterFactor, inodeArraySize = _inodes.GetLength(), bitMapSize = _bitMap.GetLength(), numFreeClusters = _emptyData.Length / _diskClusterSize, numFreeInode = (int)(_diskPartitionSize / _diskClusterSize - 1) }; InitializeFileSystem(); }
private bool FillDataFromBitmap(bool keepAlpha = false) { if (BitMap == null) { return(false); } BitmapData bData = BitMap.LockBits(new Rectangle(0, 0, BitMap.Width, BitMap.Height), ImageLockMode.ReadOnly, BitMap.PixelFormat); Height = bData.Height; Width = bData.Width; stride = bData.Stride; bitsPerPixel = GetBitsPerPixel(bData.PixelFormat); bytesPerPixel = bitsPerPixel / 8; size = Math.Abs(bData.Stride * bData.Height); data = new byte[size]; if (stride > 0) { System.Runtime.InteropServices.Marshal.Copy(bData.Scan0, data, 0, size); } else { stride = -stride; for (int i = 0; i < Height; i++) { IntPtr pointer = new IntPtr(bData.Scan0.ToInt32() - stride * i); System.Runtime.InteropServices.Marshal.Copy(pointer, data, stride * i, stride); } } BitMap.UnlockBits(bData); return(true); }
public void ReadFromTpmBlob(TPMBlob blob) { uint size = blob.ReadUInt16(); byte[] selectionBits = new byte[size]; blob.Read(selectionBits, 0, (int)size); _pcrSelection = new BitMap(selectionBits); }
public Color NativeGetPixel(int x, int y) { if (BitMap == null) { return(Color.Empty); } return(BitMap.GetPixel(x, y)); }
public static BitMap Allocate(int initialCapacity) { BitMap result = ThreadStaticPool <BitMap> .Instance.Allocate(); result.Reset(initialCapacity); return(result); }
public AllocationContext(StackAllocator stackAlloc, RegisterMasks masks, int intervalsCount) { StackAlloc = stackAlloc; Masks = masks; Active = new BitMap(intervalsCount); Inactive = new BitMap(intervalsCount); }
public Pattern(string nam, int size) { PatternName = nam; BitMap map = new BitMap(size * size); BitMaps = map.ToStr; Size = size; }
private void FreeCurrentImage() { if (BitMap != null) { BitMap.Dispose(); BitMap = null; data = null; dataChanged = false; } }
public BufferUsageBitmap(int size, int granularity) { _size = size; _granularity = granularity; _bits = (size + (granularity - 1)) / granularity; _intsPerCb = (_bits + (BitMap.IntSize - 1)) / BitMap.IntSize; _bitsPerCb = _intsPerCb * BitMap.IntSize; _bitmap = new BitMap(_bitsPerCb * CommandBufferPool.MaxCommandBuffers); }
// сериализация в бинарник public void GetObjectData(SerializationInfo sInfo, StreamingContext contextArg) { sInfo.AddValue("BitMap", BitMap.ToByteArray()); sInfo.AddValue("Visibility", Visibility); sInfo.AddValue("ToolTip", ToolTip); sInfo.AddValue("X", X); sInfo.AddValue("Y", Y); sInfo.AddValue("Opacity", Opacity); sInfo.AddValue("Height", Height); sInfo.AddValue("Width", Width); sInfo.AddValue("BlurRadius", BlurRadius); }
public static XElement ToXml(this BitMap map) { var elem = new XElement( EventManifestSchema.Namespace + "bitMap", new XAttribute("name", map.Name)); if (map.Symbol != null) { elem.Add(new XAttribute("symbol", map.Symbol)); } elem.Add(map.Items.Select(i => ((BitMapItem)i).ToXml())); return(elem); }
public void Shutdown() { // Release the camera object. Camera = null; // Release the glow shader object. GlowShader?.ShutDown(); GlowShader = null; // Release the glow map shader object. GlowMapShader?.ShutDown(); GlowMapShader = null; // Release the full screen ortho window object. FullScreenWindow?.Shutdown(); FullScreenWindow = null; // Release the small ortho window object. SmallWindow?.Shutdown(); SmallWindow = null; // Release the up sample render to texture object. UpSampleTexure?.Shutdown(); UpSampleTexure = null; // Release the vertical blur render to texture object. VerticalBlurTexture?.Shutdown(); VerticalBlurTexture = null; // Release the vertical blur shader object. VerticalBlurShader?.ShutDown(); VerticalBlurShader = null; // Release the horizontal blur render to texture object. HorizontalBlurTexture?.Shutdown(); HorizontalBlurTexture = null; // Release the horizontal blur shader object. HorizontalBlurShader?.ShutDown(); HorizontalBlurShader = null; // Release the small ortho window object. SmallWindow?.Shutdown(); SmallWindow = null; // Release the down sample render to texture object. DownSampleTexture?.Shutdown(); DownSampleTexture = null; // Release the render to texture object. RenderTexture?.Shutdown(); RenderTexture = null; // Release the model object. BitMap?.Shutdown(); BitMap = null; // Release the texture shader object. TextureShader?.ShutDown(); TextureShader = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
//kolorwanie mapy private void Wczytaj_Click(object sender, EventArgs e) { BitMap bitMap = new BitMap(); DialogResult wynikOtwierania = openFileDialog1.ShowDialog(); if (wynikOtwierania == DialogResult.OK) { Bitmap Obrazek = new Bitmap(Image.FromFile(openFileDialog1.FileName)); bitMap.KolorujMape(Obrazek); Obrazek.Save(openFileDialog1.FileName + " .png"); MessageBox.Show("Done"); } }
private void InitNewFile() { this.FileFreePosition = this.InitialFreePos; this.DataFile.Seek(12L); this.DataFile.WriteLong((long)this.InitialFreePos); int map = 0; if (this.database.logger.PropIncrementBackup) { map = BitMap.Set(map, 1); } map = BitMap.Set(map, 4); this.DataFile.Seek(0x1cL); this.DataFile.WriteInt(map); this.DataFile.Synch(); }
public List <List <cell> > ToCells() { BitMap map = new BitMap(Size * Size, BitMaps); List <List <cell> > tmp = new List <List <cell> >(); List <bool> ls = map.ToList; for (int i = 0; i < Size; i++) { tmp.Add(new List <cell>()); for (int j = 0; j < Size; j++) { tmp[i].Add(new cell(ls[i * Size + j])); } } return(tmp); }
public void AddItems() { var bitMap = new BitMap(64); bitMap.Set(0); bitMap.Set(4); Assert.Throws <IndexOutOfRangeException>(() => bitMap.Set(65)); Assert.True(bitMap.IsSet(0)); Assert.True(bitMap.IsSet(4)); Assert.False(bitMap.IsSet(3)); bitMap.Reset(4); Assert.False(bitMap.IsSet(4)); }
public static TileSet makeTileset(Texture texture, bool collisions) { var ts = new TileSet(); int i = 0; for (int y = 0; y < TILESET_HEIGHT; y++) { for (int x = 0; x < TILESET_WIDTH; x++) { ts.CreateTile(i); ts.TileSetTexture(i, texture); var region = new Rect2(x * TILE_WIDTH, y * TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT); ts.TileSetRegion(i, region); if (collisions) { var image = texture.GetData(); var bitmap = new BitMap(); bitmap.CreateFromImageAlpha(image, .01f); var polygons = bitmap.OpaqueToPolygons(region, 2); List <Vector2> plist = new List <Vector2>(); for (int j = 0; j < polygons.Count; j++) { Vector2[] v = (Vector2[])polygons[j]; for (int k = 0; k < v.Length; k++) { // I have no idea why it's adding y*48 to y coordinates... Vector2 mv = new Vector2(v[k].x, v[k].y - (y * TILE_HEIGHT * 2)); plist.Add(mv); } } // Point cloud must be at least 3 if (plist.Count >= 3) { var collision = new ConvexPolygonShape2D(); collision.SetPointCloud(plist.ToArray()); ts.TileSetShape(i, 0, collision); } } i++; } } return(ts); }
public Pattern(string str, List <List <cell> > cells) { PatternName = str; List <bool> ls = new List <bool>(); for (int i = 0; i < cells.Count; i++) { for (int j = 0; j < cells[i].Count; j++) { ls.Add(cells[i][j].LiveNow); } } BitMap map = new BitMap(ls); BitMaps = map.ToStr; Size = cells.Count; }
public void Can_Generate_DE_For_Second_BitMap() { //Arrage DataString bitMapString = new DataString("0000000000800000"); int bitMapNumber = 2; BitMap bitMap = new BitMap(bitMapString.ToBibnaryString(), bitMapNumber); //Act List <int> dataElements = new List <int>(bitMap.PresentDataElements); //Assert Assert.Contains(105, dataElements); Assert.DoesNotContain(2, dataElements); Assert.DoesNotContain(65, dataElements); }
public void Can_Generate_DE_For_First_BitMap() { //Arrage DataString bitMapString = new DataString("B220000000100000"); int bitMapNumeber = 1; BitMap bitMap = new BitMap(bitMapString.ToBibnaryString(), bitMapNumeber); //Act List <int> dataElements = new List <int>(bitMap.PresentDataElements); //Assert Assert.Contains(1, dataElements); Assert.Contains(3, dataElements); Assert.Contains(4, dataElements); Assert.Contains(7, dataElements); Assert.Contains(44, dataElements); Assert.DoesNotContain(2, dataElements); }
protected void UpdateMap() { BitMap.Lock(); unsafe { var pbuff = (byte *)BitMap.BackBuffer.ToPointer(); var bpp = BitMap.Format.BitsPerPixel / 8; var h = BitMap.Height; var w = BitMap.Width; var s = BitMap.BackBufferStride; var neurons = network.Layers[0].Neurons; var i = 0; var v = Convert.ToInt32(DisplayChannels.ShowRed) + Convert.ToInt32(DisplayChannels.ShowGreen) + Convert.ToInt32(DisplayChannels.ShowBlue); var f = 1d / v; for (var y = 0; y < h; y++) { for (var x = 0; x < w; x++, i++) { var loc = y * s + x * bpp; var weights = neurons[i].InputWeights; var r = DisplayChannels.ShowRed ? weights[0] * 255 : 0; var g = DisplayChannels.ShowGreen ? weights[1] * 255 : 0; var b = DisplayChannels.ShowBlue ? weights[2] * 255 : 0; if (DisplayChannels.ShowGrayscale) { var gray = (byte)(f * r + f * g + f * b); pbuff[loc] = gray; pbuff[loc + 1] = gray; pbuff[loc + 2] = gray; } else { pbuff[loc] = (byte)r; pbuff[loc + 1] = (byte)g; pbuff[loc + 2] = (byte)b; } } } } BitMap.AddDirtyRect(new Int32Rect(0, 0, (int)BitMap.Width, (int)BitMap.Height)); BitMap.Unlock(); }
private bool RenderUIElementsToTexture() { // Set the render target to be the render to texture. RenderTexture.SetRenderTarget(D3D.DeviceContext); // Clear the render to texture. RenderTexture.ClearRenderTarget(D3D.DeviceContext, 0.0f, 0.0f, 0.0f, 1.0f); // Generate the view matrix based on the camera's position. Camera.Render(); // Get the world, view, and ortho matrices from the camera and d3d objects. Matrix worldMatrix = D3D.WorldMatrix; Matrix viewMatrix = Camera.ViewMatrix; Matrix orthoMatrix = D3D.OrthoMatrix; // Turn off the Z buffer to begin all 2D rendering. D3D.TurnZBufferOff(); // Put the bitmap vertex and index buffers on the graphics pipeline to prepare them for drawing. if (!BitMap.Render(D3D.DeviceContext, 100, 100)) { return(false); } // Render the bitmap using the texture shader. if (!TextureShader.Render(D3D.DeviceContext, BitMap.IndexCount, worldMatrix, viewMatrix, orthoMatrix, BitMap.Texture.TextureResource)) { return(false); } // Turn the Z buffer back on now that all 2D rendering has completed. D3D.TurnZBufferOn(); // Reset the render target back to the original back buffer and not the render to texture anymore. D3D.SetBackBufferRenderTarget(); // Reset the viewport back to the original. D3D.ResetViewPort(); return(true); }
public void CountTest() { var bitMap = new BitMap(64); bitMap.Set(0); bitMap.Set(0); Assert.Equal(1, bitMap.Count); bitMap.Set(4); Assert.Throws <IndexOutOfRangeException>(() => bitMap.Set(65)); Assert.Equal(2, bitMap.Count); bitMap.Reset(4); Assert.False(bitMap.IsSet(4)); bitMap.Reset(4); Assert.Equal(1, bitMap.Count); bitMap.Reset(0); Assert.Equal(0, bitMap.Count); }
// set depth for main image based on Holliman public void setDepthHollmanMultiRegionAlgo(BitMap Bmp, double[] depthX, double[] depthY, double[] depthZ) { for (int i = 0; i < 300; i++) { Bmp.SetPixel(depthX[i], depthY[i], depthZ[i]); } for (i = 0; i < Xmax; i++) { for (j = 0; j < Ymax; j++) { for (k = 0; k < Zmax; k++) { // set brightness also based on previously calculated Laplace equation Bmp.SetBrightness(i, j, k, LapMatrix[i, j, k]); } } } }
// set depth for main image based on Holliman public void setDepthHollmanMultiRegionAlgo(BitMap Bmp, double[] depthX, double[] depthY, double[] depthZ) { for (int i = 0; i < 300; i++) { Bmp.SetPixel(depthX[i], depthY[i], depthZ[i]); } for (i = 0; i < Xmax; i++) { for (j = 0; j < Ymax; j++) { for (k = 0; k < Zmax; k++) { // set brightness also based on previously calculated Laplace equation Bmp.SetBrightness(i,j,k,LapMatrix[i, j, k]); } } } }
public void SetIncrementBackup(bool value) { Monitor.Enter(this.Lock); try { this.DataFile.Seek(0x1cL); int map = this.DataFile.ReadInt(); map = value ? BitMap.Set(map, 1) : BitMap.Unset(map, 1); this.DataFile.Seek(0x1cL); this.DataFile.WriteInt(map); this.DataFile.Synch(); } catch (Exception exception) { this.database.logger.LogSevereEvent(FwNs.Core.LC.cResources.SR.DataFileCache_SetIncrementBackup_backupFile_failed, exception); } finally { Monitor.Exit(this.Lock); } }
private static IEnumerable <Vector2[]> tilePolygons(BitMap bitmap, Rect2 region) { /*if (debug) // Print bitmap mask: before * for (float n = region.Position.y; n < region.End.y; n++) * GD.Print(String.Join("", Enumerable.Range((int)region.Position.x, TILE_WIDTH).Select(m => bitmap.GetBit(new Vector2(m, n)) ? "1" : "0"))); * if (debug) GD.Print("");*/ // Smooth mask a little: grow true bits, then shrink. This will fill inner void pixels and reduce number of polygons. // Also workaround for https://github.com/godotengine/godot/issues/31675 bitmap.GrowMask(1, region); bitmap.GrowMask(-1, new Rect2(region.Position.x - 1, region.Position.y - 1, TILE_WIDTH + 2, TILE_HEIGHT + 2)); /*if (debug) // Print bitmap mask: after * for (float n = region.Position.y; n < region.End.y; n++) * GD.Print(String.Join("", Enumerable.Range((int)region.Position.x, TILE_WIDTH).Select(m => bitmap.GetBit(new Vector2(m, n)) ? "1" : "0")));*/ var polygons = (bitmap.OpaqueToPolygons(region, 0.99f) as IEnumerable).Cast <Vector2[]>(); // I have no idea why it's adding y*48 to y coordinates... return(polygons.Select(p => p.Select(v => new Vector2(v.x, v.y - (region.Position.y * 2))).ToArray())); }
public bool Save(string fileName) { if (dataChanged && !SaveDataIntoBitmap()) { return(false); } if (BitMap == null) { return(false); } try { BitMap.Save(fileName); dataChanged = false; } catch (Exception ex) { Debug.Assert(false, ex.Message); return(false); } return(true); }
/// <summary> /// Выполняет инициализацию структур файловой системы. /// </summary> private void Initialize() { _superblock = (Superblock)ReadStruct(FileStream, typeof(Superblock)); CLUSTER_SIZE = _superblock.clusterFactor * DISK_BYTES_PER_SECTOR; FileStream.Seek(_superblock.bitMapAddress, SeekOrigin.Begin); byte[] bitMapData = new byte[_superblock.bitMapSize]; FileStream.Read(bitMapData, 0, bitMapData.Length); _bitMap = new BitMap(bitMapData); if (_superblock.filesystemType != DFS_ID) { throw new InvalidDataException("Неизвестный тип файлово системы! Возможно, диск был повреждён."); } _rootDirectory = ReadDirectoryClusters(0, null, true); CurrentDirectory = _rootDirectory; //_openedPath = "/"; }