public async Task <object> Get() { var dbStats = await this._getter.GatherDbStats(); var assemblyInfo = Assembly.GetEntryAssembly().GetName().Version.ToString(); var indexes = await IndexGetter.GatherDbIndexes(this._neoservice); return(new { serverVersion = assemblyInfo, dbStats, indexes }); }
bool TryIndex <T>(PathNode node, int index, IndexGetter <T> getter) where T : class { var list = node.model as T; if (list == null) { return(false); } return(getter(node, list, index)); }
public static byte[] FromImage(Image <Rgba32> image, List <Rgba32> palette, IndexGetter indexGetter) { int width = image.Width; int height = image.Height; byte[] pixels = new byte[width * height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Rgba32 pixColor = image[x, y]; int pltIndex; if (pixColor.A == 0) { pltIndex = 0; } else { pltIndex = palette.IndexOf(pixColor); if (pltIndex == -1) { pltIndex = palette.Count; palette.Add(pixColor); } if (pltIndex > byte.MaxValue) { throw new InvalidPaletteException($"There can not be more than {byte.MaxValue + 1} colors"); } } pixels[indexGetter(new Point(x, y), width)] = (byte)pltIndex; } } return(pixels); }
public void Lock() { if (_bits == null) { var pf = _bmp.PixelFormat; var r = new Rectangle(0, 0, _bmp.Width, _bmp.Height); _bits = _bmp.LockBits(r, ImageLockMode.ReadWrite, pf); switch (pf) { #region Indexed case PixelFormat.Format1bppIndexed: _get = GetColor1; _set = SetColor1; _getIndex = GetIndex1; _setIndex = SetIndex1; _pal = _bmp.Palette.Entries; break; case PixelFormat.Format4bppIndexed: _get = GetColor4; _set = SetColor4; _getIndex = GetIndex4; _setIndex = SetIndex4; _pal = _bmp.Palette.Entries; break; case PixelFormat.Format8bppIndexed: _get = GetColor8; _set = SetColor8; _getIndex = GetIndex8; _setIndex = SetIndex8; _pal = _bmp.Palette.Entries; break; case PixelFormat.Indexed: throw new NotSupportedException(); #endregion case PixelFormat.Format16bppArgb1555: _get = GetFormat16bppArgb1555; _set = SetFormat16bppArgb1555; break; case PixelFormat.Format16bppRgb555: //_get = new GET(GetFormat16bppRgb555); //_set = new SET(SetFormat16bppRgb555); break; case PixelFormat.Format16bppRgb565: //_get = new GET(GetFormat16bppRgb565); //_set = new SET(SetFormat16bppRgb565); break; case PixelFormat.Format16bppGrayScale: //_get = new GET(GetFormat16bppGrayScale); //_set = new SET(SetFormat16bppGrayScale); break; #region 24, 32 case PixelFormat.Canonical: _get = GetFormat32bppArgb; _set = SetFormat32bppArgb; break; case PixelFormat.Format24bppRgb: _get = GetFormat24bppRgb; _set = SetFormat24bppRgb; break; case PixelFormat.Format32bppArgb: _get = GetFormat32bppArgb; _set = SetFormat32bppArgb; break; case PixelFormat.Format32bppPArgb: _get = GetFormat32bppPArgb; _set = SetFormat32bppPArgb; break; case PixelFormat.Format32bppRgb: _get = GetFormat32bppRgb; _set = SetFormat32bppRgb; break; #endregion #region NotImplemented case PixelFormat.Format48bppRgb: //_get = GetFormat48bppRgb; //_set = SetFormat48bppRgb; throw new NotImplementedException(); case PixelFormat.Format64bppArgb: //_get = new GET(GetFormat64bppArgb); //_set = new SET(SetFormat64bppArgb); throw new NotImplementedException(); case PixelFormat.Format64bppPArgb: //_get = new GET(GetFormat64bppPArgb); //_set = new SET(SetFormat64bppPArgb); throw new NotImplementedException(); #endregion default: break; } } }
public static ImageInfo LoadPng(string file, Cell[] bank, uint blockSize, bool tiled = false) { IndexGetter indexGetter = tiled ? new IndexGetter(PointUtil.GetIndexTiled8) : new IndexGetter(PointUtil.GetIndex); if (bank.Length == 0) { throw new Exception($"Tried to load png with empty bank (when loading file '{file}')"); } Image <Rgba32> image; try { image = Image.Load <Rgba32>(file); } catch (UnknownImageFormatException e) { throw new UnknownImageFormatException(e.Message + $" File='{file}'"); } var width = image.Width; var height = image.Height; var palette32 = new List <Rgba32> { Color.Transparent }; var pixels = new List <byte>(); int minY = bank.Min(i => i.YOffset); int yShift = minY < 0 ? -minY : 0; int minX = bank.Min(i => i.XOffset); int xShift = minX < 0 ? -minX : 0; foreach (Cell cell in bank) { if (cell.Width == 0x00 || cell.Height == 0x00) { continue; } int tileOffset = cell.TileOffset << (byte)blockSize; int bankDataOffset = 0; var startByte = tileOffset * 0x20 + bankDataOffset; var endByte = startByte + cell.Width * cell.Height; using (var cellImg = image.Clone(g => { g.Crop(new Rectangle(cell.XOffset + xShift, cell.YOffset + yShift, cell.Width, cell.Height)); if (cell.FlipX) { g.Flip(FlipMode.Horizontal); } if (cell.FlipY) { g.Flip(FlipMode.Vertical); } })) { byte[] cellPixels = FromImage(cellImg, palette32, indexGetter); pixels.AddRange(cellPixels); } } var pixelArray = pixels.ToArray(); palette32[0] = Color.Magenta; image.Dispose(); return(new ImageInfo(pixelArray, palette32.ToArray(), width, height)); }