public IdenticonGenerator(string algorithm, Size size, Color defaultBackgroundColor, Size defaultBlocks, Encoding encoding, IBlockGenerator[] blockGenerators, IBrushGenerator brushGenerator) { this.DefaultAlgorithm = algorithm; this.DefaultSize = size; this.DefaultBackgroundColor = defaultBackgroundColor; this.DefaultBlocks = defaultBlocks; this.DefaultEncoding = encoding; this.DefaultBlockGenerators = blockGenerators; this.DefaultBrushGenerator = brushGenerator; }
public void Parse <TPackage>(IBlockGenerator <TBlock, TPackage> inGenerator, BlockMetaCache inCache = null) where TPackage : ScriptableDataBlockPackage <TBlock> { if (m_Parsed) { return; } TPackage self = (TPackage)this; BlockParser.Parse(ref self, name, Source(), BlockParsingRules.Default, inGenerator, inCache); }
public IEnumerator ParseAsync <TPackage>(IBlockParsingRules inRules, IBlockGenerator <TBlock, TPackage> inGenerator, BlockMetaCache inCache = null) where TPackage : ScriptableDataBlockPackage <TBlock> { if (m_Parsed) { return(null); } TPackage self = (TPackage)this; return(BlockParser.ParseAsync(ref self, name, Source(), inRules, inGenerator, inCache)); }
public void Dispose() { if (Builder != null) { BlockParser.ReturnStringBuilder(Builder); Builder = null; } if (ContentBuilder != null) { BlockParser.ReturnStringBuilder(ContentBuilder); ContentBuilder = null; } PrefixPriorities = null; Rules = null; Generator = null; TagDelimiters = null; Cache = null; Package = null; CurrentBlock = null; }
public Bitmap Create(byte[] value, Size size, Color backgroundcolor, Size blocks, IBlockGenerator[] blockGenerators, IBrushGenerator brushGenerator) { return this.Create(value, size, backgroundcolor, blocks, blockGenerators, brushGenerator, this.DefaultAlgorithm); }
public Bitmap Create(byte[] value, Size size, Color backgroundcolor, Size blocks, IBlockGenerator[] blockGenerators, IBrushGenerator brushGenerator, string algorithm) { var ha = HashAlgorithm.Create(algorithm); if (ha == null) throw new ArgumentOutOfRangeException(string.Format("Unknown algorithm '{0}'", algorithm)); if (blocks.Width < 1) throw new ArgumentOutOfRangeException("blockshorizontal"); if (blocks.Height < 1) throw new ArgumentOutOfRangeException("blocksvertical"); if (size.Width <= 0) throw new ArgumentOutOfRangeException("width"); if (size.Height <= 0) throw new ArgumentOutOfRangeException("height"); if (blockGenerators.Length == 0) throw new ArgumentException("blockgenerators"); if (blockGenerators.Any(b => b == null)) throw new ArgumentNullException("blockgenerators"); size.Width -= size.Width % blocks.Width; size.Height -= size.Height % blocks.Height; if (size.Width <= 0) throw new ArgumentOutOfRangeException("width after rounding to nearest value"); if (size.Height <= 0) throw new ArgumentOutOfRangeException("height after rounding to nearest value"); bool hasunevencols = blocks.Width % 2 != 0; var allblockgens = blockGenerators.ToArray(); var symblockgens = blockGenerators.Where(sbg => sbg.IsSymmetric).ToArray(); if (hasunevencols && symblockgens.Length==0) throw new Exception("At least one symmetrical blockgenerator required for identicons with uneven number of horizontal blocks"); ha.Initialize(); var hash = ha.ComputeHash(value); var blockwidth = (int)Math.Ceiling((double)size.Width / blocks.Width); var blockheight = (int)Math.Ceiling((double)size.Height / blocks.Height); var result = new Bitmap(size.Width, size.Height); using (var bgbrush = new SolidBrush(backgroundcolor)) using (var gfx = Graphics.FromImage(result)) { gfx.FillRectangle(bgbrush, 0, 0, size.Width, size.Height); var dhash = hash.Concat(hash).ToArray(); int hashlen = hash.Length; int i = 0; int halfwidth = blocks.Width / 2; for (var x = 0; x < (hasunevencols ? halfwidth+1 : halfwidth); x++) { for (var y = 0; y < blocks.Height; y++, i++) { var blockgen = GetBlockGenerator((x == halfwidth && hasunevencols) ? symblockgens : allblockgens, hash[i % hashlen]); var seed = BitConverter.ToUInt32(dhash, i % hashlen); using (var fgbrush = brushGenerator.GetBrush(seed)) { Rectangle rl = new Rectangle(x * blockwidth, y * blockheight, blockwidth, blockheight); blockgen.Draw(gfx, rl, bgbrush, fgbrush, seed, false); if ((x != halfwidth) || ((x==halfwidth) && !hasunevencols)) { Rectangle rr = new Rectangle((size.Width - blockwidth) - (x * blockwidth), y * blockheight, blockwidth, blockheight); blockgen.Draw(gfx, rr, bgbrush, fgbrush, seed, true); } } } } } return result; }
public Bitmap Create(IPAddress ipaddress, Size size, Color backgroundcolor, Size blocks, IBlockGenerator[] blockGenerators, IBrushGenerator brushGenerator) { return this.Create(ipaddress, size, backgroundcolor, blocks, blockGenerators, brushGenerator, this.DefaultAlgorithm); }
public Bitmap Create(IPAddress ipaddress, Size size, Color backgroundcolor, Size blocks, IBlockGenerator[] blockGenerators, IBrushGenerator brushGenerator, string algorithm) { if (ipaddress == null) throw new ArgumentNullException("ipaddress"); return this.Create(ipaddress.GetAddressBytes(), size, backgroundcolor, blocks, blockGenerators, brushGenerator, algorithm); }
public Bitmap Create(string value, Size size, Color backgroundcolor, Size blocks, Encoding encoding, IBlockGenerator[] blockGenerators) { return this.Create(value, size, backgroundcolor, blocks, encoding, blockGenerators, this.DefaultBrushGenerator); }
public Bitmap Create(string value, Size size, Color backgroundcolor, Size blocks, Encoding encoding, IBlockGenerator[] blockGenerators, IBrushGenerator brushGenerator, string algorithm) { if (this.DefaultEncoding == null) throw new ArgumentNullException("encoding"); return this.Create(encoding.GetBytes(value ?? string.Empty), size, backgroundcolor, blocks, blockGenerators, brushGenerator); }
public void InjectDependency(IBlockGenerator dependency) { _blockGenerator = dependency; }
/// <summary> /// Parses the given file contents into blocks. /// </summary> static public TPackage Parse <TBlock, TPackage>(string inFileName, StringSlice inFile, IBlockParsingRules inRules, IBlockGenerator <TBlock, TPackage> inGenerator, BlockMetaCache inCache = null) where TBlock : class, IDataBlock where TPackage : class, IDataBlockPackage <TBlock> { IEnumerator parser; TPackage package = ParseAsync(inFileName, inFile, inRules, inGenerator, inCache, out parser); if (parser != null) { while (parser.MoveNext()) { ; } } return(package); }
static internal IEnumerator ParseFile(string inFileName, StringSlice inFile, TPackage ioPackage, IBlockParsingRules inRules, IBlockGenerator <TBlock, TPackage> inGenerator, BlockMetaCache inCache) { var state = new ParseState(); state.PrefixPriorities = GeneratePrefixPriority(inRules); state.Rules = inRules; state.Generator = inGenerator; state.TagDelimiters = new BlockParser.BlockTagDelimiters(inRules); state.Package = ioPackage; state.Builder = BlockParser.RentStringBuilder(); state.ContentBuilder = BlockParser.RentStringBuilder(); state.Cache = inCache ?? BlockMetaCache.Default; using (var disposeRef = state) { uint lineNumber = 0; state.Position = new BlockFilePosition(inFileName, lineNumber); inGenerator.OnStart(state, state.Package); foreach (var rawLine in SplitIntoLines(inRules, inFile)) { lineNumber++; state.Position = new BlockFilePosition(inFileName, lineNumber); LineResult result = ParseLine(ref state, rawLine); if (result == LineResult.Exception) { inGenerator.OnEnd(state, state.Package, true); yield break; } yield return(null); } if (state.CurrentBlock != null) { state.Error |= !TryEndBlock(ref state, StringSlice.Empty); } inGenerator.OnEnd(state, state.Package, state.Error); } }
public IdenticonGenerator(string algorithm, Size size, Color defaultBackgroundColor, Size defaultBlocks, Encoding encoding, IBlockGenerator[] blockGenerators) : this(algorithm, size, defaultBackgroundColor, defaultBlocks, encoding, blockGenerators, IdenticonGenerator.DefaultBrushGeneratorConfig) { }
/// <summary> /// Parses the given file contents into blocks asynchronously. /// Each MoveNext() call on the returned IEnumerator will parse one line. /// </summary> static public TPackage ParseAsync <TBlock, TPackage>(string inFileName, StringSlice inFile, IBlockParsingRules inRules, IBlockGenerator <TBlock, TPackage> inGenerator, BlockMetaCache inCache, out IEnumerator outLoader) where TBlock : class, IDataBlock where TPackage : class, IDataBlockPackage <TBlock> { if (inFile.IsEmpty) { outLoader = null; return(null); } if (inRules == null) { throw new ArgumentNullException("inRules"); } if (inGenerator == null) { throw new ArgumentNullException("inGenerator"); } string fileName = string.IsNullOrEmpty(inFileName) ? NullFilename : inFileName; TPackage package = inGenerator.CreatePackage(fileName); outLoader = InternalBlockParser <TBlock, TPackage> .ParseFile(fileName, inFile, package, inRules, inGenerator, inCache); return(package); }
/// <summary> /// Parses the given file contents into blocks asynchronously. /// Each MoveNext() call on the returned IEnumerator will parse one line. /// </summary> static public TPackage ParseAsync <TBlock, TPackage>(string inFileName, StringSlice inFile, IBlockParsingRules inRules, IBlockGenerator <TBlock, TPackage> inGenerator, out IEnumerator outLoader) where TBlock : class, IDataBlock where TPackage : class, IDataBlockPackage <TBlock> { return(ParseAsync <TBlock, TPackage>(inFileName, inFile, inRules, inGenerator, null, out outLoader)); }
/// <summary> /// Parses the given file contents into blocks /// and merges into the given package. /// </summary> static public void Parse <TBlock, TPackage>(ref TPackage ioPackage, string inFileName, StringSlice inFile, IBlockParsingRules inRules, IBlockGenerator <TBlock, TPackage> inGenerator, BlockMetaCache inCache = null) where TBlock : class, IDataBlock where TPackage : class, IDataBlockPackage <TBlock> { IEnumerator parser = ParseAsync(ref ioPackage, inFileName, inFile, inRules, inGenerator, inCache); if (parser != null) { while (parser.MoveNext()) { ; } } }
public IdenticonGenerator WithBlockGenerators(IBlockGenerator[] blockGenerators) { this.DefaultBlockGenerators = blockGenerators; return this; }
public BlockSpawner(IBlockGenerator blockGenerator, IBlockPositionHolder positionHolder) { this.blockGenerator = blockGenerator; this.positionHolder = positionHolder; }
private IBlockGenerator GetBlockGenerator(IBlockGenerator[] generators, byte seed) { var totalweight = generators.Sum(w => w.Weight); var f = ((double)totalweight / 256); //Determine which generator to use var r = seed * f; //Determine "random" number from hash from 0 .. totalweight int g = -1; while (r >= 0) r -= generators[++g].Weight; return generators[g]; }
/// <summary> /// Parses the given file contents into blocks asynchronously /// and merges into the given package. /// Each MoveNext() call on the returned IEnumerator will parse one line. /// </summary> static public IEnumerator ParseAsync <TBlock, TPackage>(ref TPackage ioPackage, string inFileName, StringSlice inFile, IBlockParsingRules inRules, IBlockGenerator <TBlock, TPackage> inGenerator, BlockMetaCache inCache = null) where TBlock : class, IDataBlock where TPackage : class, IDataBlockPackage <TBlock> { if (inFile.IsEmpty) { return(null); } if (inRules == null) { throw new ArgumentNullException("inRules"); } if (inGenerator == null) { throw new ArgumentNullException("inGenerator"); } string fileName = string.IsNullOrEmpty(inFileName) ? NullFilename : inFileName; if (ioPackage == null) { ioPackage = inGenerator.CreatePackage(fileName); } return(InternalBlockParser <TBlock, TPackage> .ParseFile(fileName, inFile, ioPackage, inRules, inGenerator, inCache)); }
public DecompressTask(string compressedFilename, string decompressedFileName, IBlockGenerator <BlockMetadata> blockGenerator) { _compressedFilename = compressedFilename; _decompressedFileName = decompressedFileName; _blockGenerator = blockGenerator; }
private IEnumerable<IBlock> LoadLibrary(IEnumerable<Bitmap> libraryBase, IBlockGenerator generator) { return libraryBase.SelectMany(generator.GenerateBlocks); }