void GeneratePalette(PaletteId id, string name, uint[] rawPalette) { var factory = Resolve <ICoreFactory>(); PaletteTexture = factory.CreatePaletteTexture(id, name, rawPalette); Version++; }
void ChkListPalettes_ItemCheck(object sender, ItemCheckEventArgs e) { var asset = _core.SelectedObject; if (asset == null) { return; } var palette = (AlbionPalette)chkListPalettes.Items[e.Index]; var paletteId = PaletteId.FromUInt32(palette.Id); if (e.NewValue == CheckState.Checked) { asset.Set(AssetProperty.PaletteId, paletteId.Id); // TODO: Uncheck all others } else { if (asset.Get(AssetProperty.PaletteId, 0) == paletteId.Id) { asset.Set <object>(AssetProperty.PaletteId, null); } } _core.TriggerAssetChanged(asset); }
protected void oneGlobalPaletteChange(PaletteId obj) { if (ColorPalette.SelectedPalette == obj) { generateBehindImage(); } }
private void Accept_Click(object sender, EventArgs e) { pal = new Dictionary <Int32, byte>(); int c; for (byte i = 0; i < 16; i++) { PaletteId a = ColorPalette.SelectedPalette; c = ColorPalette.GetGlobalColor(i).ToArgb(); if (!pal.ContainsKey(c)) { pal.Add(c, i); } } NewFrames.Clear(); try { NewFrames = ImageProcessor.FromSpriteSheetToFrames(bps, mx, my, pal, name.Text, DynamicSpriteSizeDialog.DynSize, ColorPalette.SelectedPalette); } catch (KeyNotFoundException) { MessageBox.Show("A color on the image, doesn't exist on the color palette. Please load the palette of the image.", "Color Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DialogResult = DialogResult.OK; FrameWidth = (int)w.Value; FrameHeight = (int)h.Value; Dispose(); }
static void StatsForEnum <T>(IAssetManager assets, Dictionary <AssetId, int> dict) where T : unmanaged, Enum { foreach (var enumValue in Enum.GetValues(typeof(T)).OfType <T>()) { var id = AssetId.From(enumValue); var info = assets.GetAssetInfo(id); var texture = assets.LoadTexture(id) as IReadOnlyTexture <byte>; if (texture == null) { continue; } var palleteId = new PaletteId(AssetType.Palette, info.Get(AssetProperty.PaletteId, 0)); var palette = assets.LoadPalette(palleteId); var frames = texture.Regions.Count; var uniqueColours = new HashSet <byte>(); foreach (var colour in texture.PixelData) { uniqueColours.Add(colour); } var lcm = BlitUtil.CalculatePalettePeriod(uniqueColours, palette); dict[id] = (int)ApiUtil.Lcm(frames, lcm); } }
public Bitmap GetImage(PaletteId i, Zoom zoom) { if (images == null || images[(int)i, zoom - 1] == null || FullyDirty || _Dirty[(int)i]) { GenerateBitmap(i, zoom); } return(images[(int)i, zoom - 1]); }
public TileMask(TileSP SP, Tile Tile, Zoom Zoom, bool FlipX, bool FlipY) { this.SP = SP; XDisp = 0; YDisp = 0; zoom = Zoom; flipX = FlipX; flipY = FlipY; tile = Tile; palette = ColorPalette.SelectedPalette; ColorPalette.SelectedGlobalPaletteChange += colorPalette_SelectedGlobalPaletteChange; }
public IReadOnlyTexture <byte> Serdes(IReadOnlyTexture <byte> existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) { if (info == null) { throw new ArgumentNullException(nameof(info)); } if (s == null) { throw new ArgumentNullException(nameof(s)); } var paletteNum = info.Get(AssetProperty.PaletteId, 0); var paletteId = new PaletteId(AssetType.Palette, paletteNum); var palette = Resolve <IAssetManager>().LoadPalette(paletteId); if (palette == null) { throw new InvalidOperationException($"Could not load palette {paletteId} ({paletteNum}) for asset {info.AssetId} in file {info.File.Filename}"); } var unambiguousPalette = palette.GetUnambiguousPalette(); if (s.IsWriting()) { if (existing == null) { throw new ArgumentNullException(nameof(existing)); } var encoder = new PngEncoder(); PackedChunks.Pack(s, existing.Regions.Count, frameNum => Write(encoder, unambiguousPalette, existing, frameNum)); return(existing); } // Read var decoder = new PngDecoder(); var configuration = new Configuration(); var images = new List <Image <Rgba32> >(); try { foreach (var(bytes, _) in PackedChunks.Unpack(s)) { using var stream = new MemoryStream(bytes); images.Add(decoder.Decode <Rgba32>(configuration, stream)); } return(Read(info.AssetId, unambiguousPalette, images)); } finally { foreach (var image in images) { image.Dispose(); } } }
void OnTick(int frames) { if (Palette == null || !Palette.IsAnimated) { return; } Frame += frames; while (Frame >= Palette.GetCompletePalette().Count) { Frame -= Palette.GetCompletePalette().Count; } GeneratePalette(PaletteId.FromUInt32(Palette.Id), Palette.Name, Palette.GetPaletteAtTime(Frame)); }
public AlbionPalette LoadPalette(PaletteId id) { var palette = (AlbionPalette)_modApplier.LoadAsset(id); if (palette == null) { return(null); } var commonPalette = (AlbionPalette)_modApplier.LoadAssetCached(AssetId.From(Base.Palette.Common)); palette.SetCommonPalette(commonPalette); return(palette); }
public AlbionPalette LoadPalette(PaletteId id) { var palette = (AlbionPalette)_assetLocatorRegistry.LoadAssetCached(id.ToAssetId()); if (palette == null) { return(null); } var commonPalette = (byte[])_assetLocatorRegistry.LoadAssetCached(new AssetKey(AssetType.PaletteNull)); palette.SetCommonPalette(commonPalette); return(palette); }
public AlbionPalette LoadPalette(PaletteId id) { var palette = (AlbionPalette)_assetLocator.LoadAssetCached(AssetType.Palette, id); if (palette == null) { return(null); } var commonPalette = (byte[])_assetLocator.LoadAssetCached(AssetType.PaletteNull, 0); palette.SetCommonPalette(commonPalette); return(palette); }
void SetPalette(PaletteId paletteId) { var palette = Resolve <IAssetManager>().LoadPalette(paletteId); if (palette == null) { Raise(new LogEvent(LogEvent.Level.Error, $"Palette ID {paletteId} could not be loaded!")); return; } Palette = palette; while (PaletteFrame >= Palette.GetCompletePalette().Count) { PaletteFrame -= Palette.GetCompletePalette().Count; } GeneratePalette(); }
public AlbionPalette LoadPalette(PaletteId id) { var palette = (AlbionPalette)_modApplier.LoadAssetCached(id); if (palette == null) { return(null); } var commonId = AssetId.From(Base.Palette.CommonPalette); if (palette.Id != commonId.ToUInt32()) { var commonPalette = (AlbionPalette)_modApplier.LoadAssetCached(commonId); palette.SetCommonPalette(commonPalette); } return(palette); }
void SyncSelectedPalettes() { var asset = _core.SelectedObject; if (asset == null) { return; } for (int index = 0; index < chkListPalettes.Items.Count; index++) { var item = (AlbionPalette)chkListPalettes.Items[index]; var paletteId = PaletteId.FromUInt32(item.Id); chkListPalettes.SetItemChecked(index, asset.Get(AssetProperty.PaletteId, 0) == paletteId.Id); } if (chkListPalettes.SelectedIndex != -1) { if (!chkListPalettes.GetItemChecked(chkListPalettes.SelectedIndex) && chkListPalettes.CheckedIndices.Count > 0) { chkListPalettes.SelectedIndex = chkListPalettes.CheckedIndices[0]; } } }
public void GenerateBitmap(PaletteId paletteId, Zoom zoom) { if (ColorPalette.GlobalPaletteSize == 0) { return; } int npid = (int)paletteId; if (images == null || images.GetLength(0) != ColorPalette.GlobalPaletteSize) { images = new Bitmap[ColorPalette.GlobalPaletteSize, 20]; } images[npid, zoom - 1] = new Bitmap(Size * zoom, Size * zoom); Bitmap bp = images[npid, zoom - 1]; Brush br; for (int i = 0; i < Size; i++) { for (int j = 0; j < Size; j++) { if (colors[i, j] != 0) { using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bp)) { g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; br = new SolidBrush(ColorPalette.GetGlobalColor(colors[i, j], paletteId)); g.FillRectangle(br, new RectangleF(i * zoom, j * zoom, zoom, zoom)); } } } } FullyDirty = false; setDirty(npid, false); }
public static MapData3D Serdes(AssetInfo info, MapData3D existing, AssetMapping mapping, ISerializer s) { if (info == null) { throw new ArgumentNullException(nameof(info)); } if (s == null) { throw new ArgumentNullException(nameof(s)); } var map = existing ?? new MapData3D(info.AssetId); map.Flags = s.EnumU8(nameof(Flags), map.Flags); // 0 int npcCount = s.Transform("NpcCount", map.Npcs.Count, S.UInt8, NpcCountTransform.Instance); // 1 var _ = s.UInt8("MapType", (byte)map.MapType); // 2 map.SongId = SongId.SerdesU8(nameof(SongId), map.SongId, mapping, s); // 3 map.Width = s.UInt8(nameof(Width), map.Width); // 4 map.Height = s.UInt8(nameof(Height), map.Height); // 5 map.LabDataId = LabyrinthId.SerdesU8(nameof(LabDataId), map.LabDataId, mapping, s); // 6 map.CombatBackgroundId = SpriteId.SerdesU8(nameof(CombatBackgroundId), map.CombatBackgroundId, AssetType.CombatBackground, mapping, s); // 7 TODO: Verify this is combat background map.PaletteId = PaletteId.SerdesU8(nameof(PaletteId), map.PaletteId, mapping, s); map.AmbientSongId = SongId.SerdesU8(nameof(AmbientSongId), map.AmbientSongId, mapping, s); for (int i = 0; i < npcCount; i++) { map.Npcs.TryGetValue(i, out var npc); npc = MapNpc.Serdes(i, npc, MapType.ThreeD, mapping, s); if (!npc.Id.IsNone) { map.Npcs[i] = npc; } } s.Check(); map.Contents ??= new byte[map.Width * map.Height]; map.Floors ??= new byte[map.Width * map.Height]; map.Ceilings ??= new byte[map.Width * map.Height]; for (int i = 0; i < map.Width * map.Height; i++) { map.Contents[i] = s.UInt8(null, map.Contents[i]); map.Floors[i] = s.UInt8(null, map.Floors[i]); map.Ceilings[i] = s.UInt8(null, map.Ceilings[i]); } s.Check(); map.SerdesZones(s); if (s.Mode == SerializerMode.Reading && s.IsComplete() || s.Mode != SerializerMode.Reading && map.AutomapGraphics == null) { ApiUtil.Assert(map.Zones.Count == 0); return(map); } map.SerdesEvents(mapping, s); map.SerdesNpcWaypoints(s); map.SerdesAutomap(s); map.SerdesChains(s, 64); if (s.Mode == SerializerMode.Reading) { map.Unswizzle(); } return(map); }
private void HandleChangeTheme(PaletteId paletteId) { Context.Settings.PaletteId = paletteId; Context.Screen.Palette = Palette.GetPalette(paletteId); }
public static List <Frame> FromSpriteSheetToFrames(Bitmap[] b, int midX, int midY, Dictionary <Int32, byte> Pal, string name, DynamicSize ds, PaletteId curId) { if (name == "" || name == null) { name = "Frame"; } Frame f; List <Frame> frames = new List <Frame>(); for (int i = 0; i < b.Length; i++) { ImageNode imn = CropFrameInTiles(b[i]); f = FillGFX(b[i], midX, midY, curId, imn, ds, Pal); f.Name = name + i; f.MidX = midX; f.MidY = midY; frames.Add(f); } return(frames); }
public static Dictionary <Int32, byte> GetPalette(Bitmap bp, PaletteId pid) { Dictionary <Int32, byte> ret = new Dictionary <int, byte>(); List <Color> cols = new List <Color>(); Color c; for (int i = 0; i < bp.Width; i++) { for (int j = 0; j < bp.Height; j++) { c = bp.GetPixel(i, j); if (c.A == 255 && !cols.Contains(c)) { cols.Add(c); } } } Color minCol = Color.FromArgb(0, 255, 255, 255); int min; int cur; int r, g, b; Color pcol; List <byte> findMin = new List <byte>(); for (byte i = 1; i < 16; i++) { if (cols.Count > 0) { min = -1; pcol = ColorPalette.GetGlobalColor(i, pid); foreach (Color col in cols) { r = col.R - pcol.R; r *= r; g = col.G - pcol.G; g *= g; b = col.B - pcol.B; b *= b; cur = r + g + b; if (min < 0 || cur < min) { minCol = col; min = cur; } } if (min == 0) { ret.Add(minCol.ToArgb(), i); cols.Remove(minCol); } else { findMin.Add(i); } } } foreach (byte i in findMin) { if (cols.Count > 0) { min = -1; pcol = ColorPalette.GetGlobalColor(i, pid); foreach (Color col in cols) { r = col.R - pcol.R; r *= r; g = col.G - pcol.G; g *= g; b = col.B - pcol.B; b *= b; cur = r + g + b; if (min < 0 || cur < min) { minCol = col; min = cur; } } ret.Add(minCol.ToArgb(), i); cols.Remove(minCol); } } foreach (KeyValuePair <int, byte> kvp in ret) { ColorPalette.SetGlobalColor(kvp.Value, Color.FromArgb(kvp.Key), pid); } return(ret); }
private void oneGlobalPaletteChange(PaletteId obj) { getBehindMap(); reDraw(); }
public void Load(LabyrinthData labyrinthData, AssetInfo info, IsometricMode mode, TilemapRequest request, int?paletteNumber, IAssetManager assets) { if (labyrinthData == null) { throw new ArgumentNullException(nameof(labyrinthData)); } if (info == null) { throw new ArgumentNullException(nameof(info)); } if (request == null) { throw new ArgumentNullException(nameof(request)); } if (assets == null) { throw new ArgumentNullException(nameof(assets)); } RemoveAllChildren(); bool floors = mode is IsometricMode.Floors or IsometricMode.All; bool ceilings = mode is IsometricMode.Ceilings or IsometricMode.All; bool walls = mode is IsometricMode.Walls or IsometricMode.All; bool contents = mode is IsometricMode.Contents or IsometricMode.All; paletteNumber ??= info.Get(AssetProperty.PaletteId, 0); var paletteId = new PaletteId(AssetType.Palette, paletteNumber.Value); var palette = assets.LoadPalette(paletteId); if (palette == null) { Error($"Could not load palette {paletteNumber}"); palette = assets.LoadPalette(Base.Palette.Common); } else { Raise(new LoadPaletteEvent(paletteId)); } var etmManager = Resolve <IEtmManager>(); request.Pipeline = DungeonTilemapPipeline.NoCulling; request.DayPalette = palette; _tilemap = etmManager.CreateTilemap(request /*labyrinthData.Id, 0, request, palette, null, DungeonTilemapPipeline.NoCulling */); // Layout: // [Empty] [First frame of all floors] [First frame of all ceilings] [First frame of all walls] [Additional floor frames] [Additional ceiling frames] [Additional wall frames] int totalTiles = 1; if (floors || ceilings) { for (int i = 0; i < labyrinthData.FloorAndCeilings.Count; i++) { var floorInfo = labyrinthData.FloorAndCeilings[i]; var floor = floorInfo == null ? null : assets.LoadTexture(floorInfo.SpriteId); _tilemap.DefineFloor(i + 1, floor); if (floors) { totalTiles += _tilemap.DayFloors.GetFrameCountForLogicalId(i + 1); } if (ceilings) { totalTiles += _tilemap.DayFloors.GetFrameCountForLogicalId(i + 1); } } } if (walls) { for (int i = 0; i < labyrinthData.Walls.Count; i++) { var wallInfo = labyrinthData.Walls[i]; bool isAlphaTested = wallInfo != null && (wallInfo.Properties & Wall.WallFlags.AlphaTested) != 0; var wall = wallInfo == null ? null : assets.LoadTexture(wallInfo.SpriteId); _tilemap.DefineWall(i + 1, wall, 0, 0, wallInfo?.TransparentColour ?? 0, isAlphaTested); foreach (var overlayInfo in wallInfo?.Overlays ?? Array.Empty <Overlay>()) { if (overlayInfo.SpriteId.IsNone) { continue; } var overlay = assets.LoadTexture(overlayInfo.SpriteId); _tilemap.DefineWall(i + 1, overlay, overlayInfo.XOffset, overlayInfo.YOffset, wallInfo?.TransparentColour ?? 0, isAlphaTested); } totalTiles += _tilemap.DayWalls.GetFrameCountForLogicalId(i + 1); } } if (contents) { var transparent = new SimpleTexture <byte>(AssetId.None, "Transparent", 1, 1, new byte[] { 0 }) .AddRegion(Vector2.Zero, Vector2.One, 0); for (byte i = 1; i <= labyrinthData.ObjectGroups.Count; i++) { _tilemap.DefineWall(i, transparent, 0, 0, 0, true); } totalTiles += labyrinthData.ObjectGroups.Count; } _wallCount = labyrinthData.Walls.Count; _floors = new byte[totalTiles]; _ceilings = new byte[totalTiles]; _contents = new byte[totalTiles]; var frames = new int[totalTiles]; int index = 1; // Add initial frames if (floors) { FloorFrames = new List <int> [labyrinthData.FloorAndCeilings.Count + 1]; FloorFrames[0] = new List <int> { 0 }; for (byte i = 1; i <= labyrinthData.FloorAndCeilings.Count; i++) { _floors[index] = i; FloorFrames[i] = new List <int> { index }; index++; } } if (ceilings) { CeilingFrames = new List <int> [labyrinthData.FloorAndCeilings.Count + 1]; CeilingFrames[0] = new List <int> { 0 }; for (byte i = 1; i <= labyrinthData.FloorAndCeilings.Count; i++) { _ceilings[index] = i; CeilingFrames[i] = new List <int> { index }; index++; } } if (walls) { WallFrames = new List <int> [labyrinthData.Walls.Count + 1]; WallFrames[0] = new List <int> { 0 }; for (byte i = 1; i <= labyrinthData.Walls.Count; i++) { _contents[index] = (byte)(i + 100); WallFrames[i] = new List <int> { index }; index++; } } if (contents) { ContentsFrames = new List <int> [labyrinthData.ObjectGroups.Count + 1]; ContentsFrames[0] = new List <int> { 0 }; for (byte i = 1; i <= labyrinthData.ObjectGroups.Count; i++) { _contents[index] = i; ContentsFrames[i] = new List <int> { index }; index++; } } // Add animation frames if (floors) { for (byte i = 1; i <= labyrinthData.FloorAndCeilings.Count; i++) { int frameCount = _tilemap.DayFloors.GetFrameCountForLogicalId(i); for (int j = 1; j < frameCount; j++) { _floors[index] = i; FloorFrames[i].Add(index); frames[index++] = j; } } } if (ceilings) { for (byte i = 1; i <= labyrinthData.FloorAndCeilings.Count; i++) { int frameCount = _tilemap.DayFloors.GetFrameCountForLogicalId(i); for (int j = 1; j < frameCount; j++) { _ceilings[index] = i; CeilingFrames[i].Add(index); frames[index++] = j; } } } if (walls) { for (byte i = 1; i <= labyrinthData.Walls.Count; i++) { int frameCount = _tilemap.DayWalls.GetFrameCountForLogicalId(i); for (int j = 1; j < frameCount; j++) { _contents[index] = (byte)(i + 100); WallFrames[i].Add(index); frames[index++] = j; } } } _tilemap.TileCount = totalTiles; for (int i = 0; i < totalTiles; i++) { SetTile(i, i, frames[i]); } for (int i = 0; i < totalTiles; i++) { AddSprites(labyrinthData, i, request); } }
public static MapData3D Serdes(AssetInfo info, MapData3D existing, AssetMapping mapping, ISerializer s) { if (info == null) { throw new ArgumentNullException(nameof(info)); } if (s == null) { throw new ArgumentNullException(nameof(s)); } var map = existing ?? new MapData3D { Id = info.AssetId }; map.Flags = s.EnumU8(nameof(Flags), map.Flags); // 0 map.OriginalNpcCount = s.UInt8(nameof(OriginalNpcCount), map.OriginalNpcCount); // 1 int npcCount = NpcCountTransform.Instance.FromNumeric(map.OriginalNpcCount); var _ = s.UInt8("MapType", (byte)map.MapType); // 2 map.SongId = SongId.SerdesU8(nameof(SongId), map.SongId, mapping, s); // 3 map.Width = s.UInt8(nameof(Width), map.Width); // 4 map.Height = s.UInt8(nameof(Height), map.Height); // 5 map.LabDataId = LabyrinthId.SerdesU8(nameof(LabDataId), map.LabDataId, mapping, s); // 6 map.CombatBackgroundId = SpriteId.SerdesU8(nameof(CombatBackgroundId), map.CombatBackgroundId, AssetType.CombatBackground, mapping, s); // 7 TODO: Verify this is combat background map.PaletteId = PaletteId.SerdesU8(nameof(PaletteId), map.PaletteId, mapping, s); map.AmbientSongId = SongId.SerdesU8(nameof(AmbientSongId), map.AmbientSongId, mapping, s); map.Npcs = s.List( nameof(Npcs), map.Npcs, npcCount, (n, x, s2) => MapNpc.Serdes(n, x, map.MapType, mapping, s2)).ToArray(); map.Contents ??= new byte[map.Width * map.Height]; map.Floors ??= new byte[map.Width * map.Height]; map.Ceilings ??= new byte[map.Width * map.Height]; for (int i = 0; i < map.Width * map.Height; i++) { map.Contents[i] = s.UInt8(null, map.Contents[i]); map.Floors[i] = s.UInt8(null, map.Floors[i]); map.Ceilings[i] = s.UInt8(null, map.Ceilings[i]); } s.Check(); map.SerdesZones(s); if (s.IsReading() && s.IsComplete() || s.IsWriting() && map.AutomapGraphics == null) { ApiUtil.Assert(map.Zones.Count == 0); foreach (var npc in map.Npcs) { npc.Waypoints = new NpcWaypoint[1]; } return(map); } map.SerdesEvents(mapping, s); map.SerdesNpcWaypoints(s); map.SerdesAutomap(s); map.SerdesChains(s, 64); if (s.IsReading()) { map.Unswizzle(); } return(map); }
public static Frame FillGFX(Bitmap bp, int midx, int midy, PaletteId pid, ImageNode imn, DynamicSize DZ, Dictionary <Int32, byte> pal) { Frame f = new Frame() { Dynamic = true, DynSize = DZ, MidX = midx, MidY = midy }; byte[,] gfx = new byte[128, f.DynSize.Height]; ImageNode[] FollowsX = new ImageNode[imn.Length16]; ImageNode imnaux = imn; ImageNode imnaux2; int next = 0; /* * while(imnaux != null) * { * imnaux2 = imnaux.Father; * while (imnaux2 != null && imnaux.Size == 16) * { * if (imnaux2.Size == 16 && imnaux.Y == imnaux2.Y * && Math.Abs(imnaux.X - imnaux2.X) <= 8) * { * if (imnaux.X < imnaux2.X) * { * FollowsX[next] = imnaux; * FollowsX[next + 1] = imnaux2; * } * else * { * FollowsX[next] = imnaux2; * FollowsX[next + 1] = imnaux; * } * next += 2; * } * imnaux2 = imnaux2.Father; * } * imnaux = imnaux.Father; * }*/ ImageNode[] imns16 = new ImageNode[imn.Length16]; ImageNode[] imns8 = new ImageNode[imn.Length8]; imnaux = imn; int next16 = 0; int next8 = 0; while (imnaux != null) { if (imnaux.Size == 16) { if (!FollowsX.Contains(imnaux)) { imns16[next16] = imnaux; next16++; } } else { imns8[next8] = imnaux; next8++; } imnaux = imnaux.Father; } int w = (f.DynSize.Width / 8); int h = (f.DynSize.Height / 8); int[] spaceUsed = new int[w * h]; int baseX = 0; int baseY = 0; Color c; int bx, by; TileMask tm; ImageNode imn1, imn2; for (int i = 0; i < FollowsX.Length; i += 2) { if (FollowsX[i] == null) { break; } imn1 = FollowsX[i]; imn2 = FollowsX[i + 1]; if (FollowsX[i + 1].X < FollowsX[i].X) { imn1 = FollowsX[i + 1]; imn2 = FollowsX[i]; } bx = baseX / 8; by = baseY / 8; Buffer.BlockCopy(space24x16, 0, spaceUsed, (by / w + (bx % w)) * 4, 12); Buffer.BlockCopy(space24x16, 0, spaceUsed, ((by / w) + w + (bx % w)) * 4, 12); for (int x = 0; x < 16 && x + baseX < f.DynSize.Width; x++) { for (int y = 0; y < 16 && y + baseY < f.DynSize.Height; y++) { c = bp.GetPixel(imn1.X + x, imn1.Y + y); if (c.A == 255) { gfx[baseX + x, baseY + y] = pal[c.ToArgb()]; } } } tm = new TileMask(TileSP.SP23, Tiles16[bx, by], 2, false, false) { XDisp = imn1.X * 2, YDisp = imn1.Y * 2, Priority = Priority, Palette = pid }; f.AddTile(tm); baseX += 8; for (int x = 0; x < 16 && imn1.X + x + 8 < bp.Width && x + baseX < f.DynSize.Width; x++) { for (int y = 0; y < 16 && y + baseY < f.DynSize.Height; y++) { c = bp.GetPixel(imn1.X + x + 8, imn1.Y + y); if (c.A == 255) { gfx[baseX + x, baseY + y] = pal[c.ToArgb()]; } } } tm = new TileMask(TileSP.SP23, Tiles16[bx + 1, by], 2, false, false) { XDisp = (imn1.X + 8) * 2, YDisp = imn1.Y * 2, Priority = Priority, Palette = pid }; f.AddTile(tm); baseX += 16; if (baseX >= f.DynSize.Width) { baseX = 0; baseY += 16; } } bool found = false; for (int i = 0; i < imns16.Length; i++) { if (imns16[i] == null) { break; } found = false; for (int q = 0; q < h - 1; q++) { for (int p = 0; p < w - 1; p++) { if (spaceUsed[q * w + p] == 0 && spaceUsed[q * w + p + 1] == 0 && spaceUsed[q * w + p + w] == 0 && spaceUsed[q * w + p + w + 1] == 0) { found = true; baseX = p * 8; baseY = q * 8; spaceUsed[q * w + p] = 1; spaceUsed[q * w + p + 1] = 1; spaceUsed[q * w + p + w] = 1; spaceUsed[q * w + p + w + 1] = 1; for (int x = 0; x < 16 && x + baseX < f.DynSize.Width && imns16[i].X + x < bp.Width; x++) { for (int y = 0; y < 16 && y + baseY < f.DynSize.Height && imns16[i].Y + y < bp.Height; y++) { c = bp.GetPixel(imns16[i].X + x, imns16[i].Y + y); if (c.A == 255) { if (pal.ContainsKey(c.ToArgb())) { gfx[baseX + x, baseY + y] = pal[c.ToArgb()]; } else { throw new KeyNotFoundException(); } } } } break; } } if (found) { break; } } if (!found) { return(null); } else { bx = baseX / 8; by = baseY / 8; tm = new TileMask(TileSP.SP23, Tiles16[bx, by], 2, false, false) { XDisp = imns16[i].X * 2, YDisp = imns16[i].Y * 2, Priority = Priority, Palette = pid }; f.AddTile(tm); } } for (int i = 0; i < imns8.Length; i++) { if (imns8[i] == null) { break; } found = false; for (int p = 0; p < h; p++) { for (int q = 0; q < w; q++) { if (spaceUsed[p * w + q] == 0) { found = true; baseX = q * 8; baseY = p * 8; spaceUsed[p * w + q] = 1; for (int x = 0; x < 8 && x + baseX < f.DynSize.Width && imns8[i].X + x < bp.Width; x++) { for (int y = 0; y < 8 && y + baseY < f.DynSize.Height && imns8[i].Y + y < bp.Height; y++) { c = bp.GetPixel(imns8[i].X + x, imns8[i].Y + y); if (c.A == 255) { gfx[baseX + x, baseY + y] = pal[c.ToArgb()]; } } } break; } } if (found) { break; } } if (!found) { return(null); } else { bx = baseX / 8; by = baseY / 8; tm = new TileMask(TileSP.SP23, Tiles8[bx, by], 2, false, false) { XDisp = imns8[i].X * 2, YDisp = imns8[i].Y * 2, Priority = Priority, Palette = pid }; f.AddTile(tm); } } f.GFX = SnesGraphics.GetGFXFromColorMatrix(gfx); f.Sort(tilesorter); return(f); }
private void oneGlobalPaletteChange(PaletteId obj) { setDirty((int)obj, true); }
private void colorPalette_OneGlobalPaletteChange(PaletteId obj) { buildSelectionBox(); }
/// <summary> /// Get a palette by its ID. /// </summary> /// <param name="paletteId">Palette ID</param> /// <returns>The requested palette</returns> public static Palette GetPalette(PaletteId paletteId) { return(Palettes[paletteId]); }
public ScreenModeData(ushort width, ushort height, PaletteId paletteId) : this(width, height, ReadInternalPalette(paletteId.ToString())) { }
public LoadPaletteEvent(PaletteId paletteId) { PaletteId = paletteId; }
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); }