public object Process(object asset, AssetInfo info) { if (info == null) { throw new ArgumentNullException(nameof(info)); } return(ImageSharpUtil.FromImageSharp(info.AssetId, info.AssetId.ToString(), (Image <Rgba32>)asset)); }
static byte[] Write(IImageEncoder encoder, uint[] palette, IReadOnlyTexture <byte> existing, int frameNum) { var frame = existing.Regions[frameNum]; var buffer = new ReadOnlyImageBuffer <byte>( frame.Width, frame.Height, existing.Width, existing.PixelData.Slice(frame.PixelOffset, frame.PixelLength)); Image <Rgba32> image = ImageSharpUtil.ToImageSharp(buffer, palette); var bytes = FormatUtil.BytesFromStream(stream => encoder.Encode(image, stream)); return(bytes); }
static byte[] Write(IImageEncoder encoder, uint[] palette, IReadOnlyTexture <byte> existing) { var image = ImageSharpUtil.PackSpriteSheet(palette, existing.Regions.Count, existing.GetRegionBuffer); return(FormatUtil.BytesFromStream(stream => encoder.Encode(image, stream))); }
public IList <ExportedImageInfo> ExportImage( AssetId assetId, IAssetManager assets, string directory, DumpFormats formats, Func <int, int, bool> frameFilter = null) { var filenames = new List <ExportedImageInfo>(); var config = assets.GetAssetInfo(assetId); AlbionPalette palette; if (config != null) { var rawPaletteId = config.Get(AssetProperty.PaletteId, 0); var paletteId = new PaletteId(AssetType.Palette, rawPaletteId); palette = assets.LoadPalette(paletteId); } else { palette = assets.LoadPalette(Base.Palette.Inventory); } var texture = assets.LoadTexture(assetId); if (texture == null) { return(filenames); } if (texture is IReadOnlyTexture <uint> trueColor) { var path = Path.Combine(directory, $"{assetId.Id}_{assetId}"); var image = ImageSharpUtil.ToImageSharp(trueColor.GetLayerBuffer(0)); Save(image, path, formats, filenames); } else if (texture is IReadOnlyTexture <byte> tilemap && ( assetId.Type == AssetType.Font || assetId.Type == AssetType.TilesetGraphics || assetId.Type == AssetType.AutomapGraphics)) { if (palette == null) { Error($"Could not load palette for {assetId}"); return(filenames); } var colors = BlitUtil.DistinctColors(tilemap.PixelData); int palettePeriod = palette.CalculatePeriod(colors); for (int palFrame = 0; palFrame < palettePeriod; palFrame++) { if (frameFilter != null && !frameFilter(0, palFrame)) { continue; } var path = Path.Combine(directory, $"{assetId.Id}_{palFrame}_{assetId}"); var image = ImageSharpUtil.ToImageSharp(tilemap.GetLayerBuffer(0), palette.GetPaletteAtTime(palFrame)); Save(image, path, formats, filenames); } } else if (texture is IReadOnlyTexture <byte> eightBit) { for (int subId = 0; subId < eightBit.Regions.Count; subId++) { if (palette == null) { Error($"Could not load palette for {assetId}"); break; } var colors = BlitUtil.DistinctColors(eightBit.GetRegionBuffer(subId)); int palettePeriod = palette.CalculatePeriod(colors); for (int palFrame = 0; palFrame < palettePeriod; palFrame++) { if (frameFilter != null && !frameFilter(subId, palFrame)) { continue; } var path = Path.Combine(directory, $"{assetId.Id}_{subId}_{palFrame}_{assetId}"); var image = ImageSharpUtil.ToImageSharp(eightBit.GetRegionBuffer(subId), palette.GetPaletteAtTime(palFrame)); Save(image, path, formats, filenames); } } } else { var path = Path.Combine(directory, $"{assetId.Id}_{assetId}.png.todo"); File.WriteAllText(path, ""); return(null); } return(filenames); }