public PatternGraphicsFormat(string name, PixelColorType colorType, int colorDepth, ImageLayout layout, PixelPacking packing, int defaultWidth, int defaultHeight) { Name = name; ColorType = colorType; ColorDepth = colorDepth; Layout = layout; Packing = packing; DefaultWidth = defaultWidth; DefaultHeight = defaultHeight; }
/// <summary> /// Tries to create a PatternList /// </summary> /// <param name="patterns">List of pattern strings containing only valid pattern characters</param> /// <param name="width">Width of image in pixels</param> /// <param name="height">Height of image in pixels</param> /// <param name="planes">Number of planes in the image</param> /// <param name="patternSize">Combined size of all patterns in number of characters (bits)</param> /// <returns></returns> public static MagitekResult <PatternList> TryCreatePatternList(IList <string> patterns, PixelPacking packing, int width, int height, int planes, int patternSize) { if (patternSize <= 0) { return(new MagitekResult <PatternList> .Failed($"Pattern size ({patternSize}) must be greater than 0")); } if (patterns?.Any() is false) { throw new ArgumentException($"{nameof(TryCreatePatternList)} parameter '{nameof(patterns)}' must contain items"); } if (patterns.Any(x => string.IsNullOrWhiteSpace(x))) { throw new ArgumentException($"{nameof(TryCreatePatternList)} parameter '{nameof(patterns)}' contains items that are null or empty"); } int patternsLengthSum = default; if (packing == PixelPacking.Planar) { patternsLengthSum = patterns.Sum(x => x.Length); } else { patternsLengthSum = patterns.First().Length *planes; } if (patternSize != patternsLengthSum) { return(new MagitekResult <PatternList> .Failed($"The specified pattern size ({patternSize}) did not match the size of the pattern sequences ({patternsLengthSum})")); } if (packing == PixelPacking.Planar && patterns.Count != planes) { throw new ArgumentException($"{nameof(PixelPacking)}.{PixelPacking.Planar} must contain the same number of patterns as the color depth"); } if (packing == PixelPacking.Chunky && patterns.Count != 1) { return(new MagitekResult <PatternList> .Failed($"{nameof(PixelPacking)}.{PixelPacking.Chunky} must contain only one pattern")); } var imageSize = width * height * planes; if (imageSize % patternSize != 0) { return(new MagitekResult <PatternList> .Failed($"The image size ({imageSize}) is not an even multiple of the pattern size ({patternSize})")); } if (patterns.Any(x => x.Length != patterns[0].Length)) { return(new MagitekResult <PatternList> .Failed($"The pattern length of all patterns must be equal")); } if (packing == PixelPacking.Planar) { return(TryCreatePlanarPatternList(patterns, width, height, planes, patternSize)); } else if (packing == PixelPacking.Chunky) { return(TryCreateChunkyPatternList(patterns, width, height, planes, patternSize)); } else { throw new NotSupportedException($"{nameof(TryCreatePatternList)} does not support {nameof(PixelPacking)} of value {packing}"); } }
public void ChangePacking(PixelPacking packing) { this.Log(LogLevel.Noisy, "The display is using {0} packing format", packing); pixelPacking = packing; }