public static BitMap FromCells(BitSize cellwidth, int cellcount) { var bitcount = cellcount * cellwidth; var indices = new BitIndex[bitcount]; for (var cell = 0u; cell < cellcount; cell++) { for (byte bit = 0; bit < bitcount; bit++) { indices[cell * cellwidth + bit] = new BitIndex(cell, bit); } } return(FromIndices(cellcount, cellwidth, indices)); }
public static BitMap FromBits(BitSize cellwidth, BitSize bitcount) { var q = Math.DivRem(bitcount, cellwidth, out int r); var cellcount = r == 0 ? q : q + 1; var indices = new BitIndex[cellcount * cellwidth]; for (var cell = 0u; cell < cellcount; cell++) { for (byte bit = 0; bit < cellwidth; bit++) { indices[cell * cellwidth + bit] = new BitIndex(cell, bit); } } return(new BitMap(cellcount, cellwidth, indices)); }
/// <summary> /// Creates a bitmap over cells of unmanaged parametric type /// </summary> /// <param name="bitcount">The number of bits to spread over the cells</param> /// <typeparam name="T">The cell type</typeparam> public static BitMap <T> FromBits <T>(BitSize bitcount) where T : unmanaged { var cellwidth = bitsize <T>(); var q = Math.DivRem(bitcount, cellwidth, out int r); var cellcount = r == 0 ? q : q + 1; var indices = new BitIndex[bitcount]; for (var cell = 0u; cell < cellcount; cell++) { for (byte bit = 0; bit < cellwidth; bit++) { indices[cell * cellwidth + bit] = new BitIndex(cell, bit); } } return(new BitMap <T>(FromIndices(cellcount, cellwidth, indices))); }
/// <summary> /// Creates a bitmap over a specified number of cells of unmanaged type /// </summary> /// <param name="cellcount">The cell count</param> /// <typeparam name="T">The cell type</typeparam> public static BitMap <T> FromCells <T>(int cellcount) where T : unmanaged { var cellwidth = bitsize <T>(); var bits = cellcount * cellwidth; var indices = new BitIndex[bits]; for (var cell = 0u; cell < cellcount; cell++) { for (byte bit = 0; bit < bits; bit++) { indices[cell * cellwidth + bit] = new BitIndex(cell, bit); } } return(new BitMap <T>(FromIndices(cellcount, cellwidth, indices))); }