1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- using System.Collections.Generic;
- using System.IO;
- using System.Collections.ObjectModel;
- using UnityEngine;
-
- namespace UnityEditor.U2D.Aseprite
- {
- /// <summary>
- /// Parsed representation of an Aseprite Old Palette chunk.
- /// </summary>
- /// <note>Not supported yet.</note>
- internal class OldPaletteChunk : BaseChunk, IPaletteProvider
- {
- public override ChunkTypes chunkType => ChunkTypes.OldPalette;
-
- /// <summary>
- /// Array of palette entries.
- /// </summary>
- public ReadOnlyCollection<PaletteEntry> entries => System.Array.AsReadOnly(m_Entries);
- PaletteEntry[] m_Entries;
-
- internal OldPaletteChunk(uint chunkSize) : base(chunkSize) { }
-
- protected override void InternalRead(BinaryReader reader)
- {
- var noOfPackets = reader.ReadUInt16();
- var colorEntries = new List<PaletteEntry>();
-
- var colorIndex = 0;
- for (var i = 0; i < noOfPackets; ++i)
- {
- var noOfColorsToSkip = reader.ReadByte();
- colorIndex += noOfColorsToSkip;
-
- int noOfColorsInEntry = reader.ReadByte();
- if (noOfColorsInEntry == 0)
- noOfColorsInEntry = 256;
-
- // If j + colorIndex >= 256 it means that the color chunk is invalid, so we stop reading.
- for (var j = 0; j < noOfColorsInEntry && (j + colorIndex < 256); ++j)
- {
- var r = reader.ReadByte();
- var g = reader.ReadByte();
- var b = reader.ReadByte();
-
- colorEntries.Add(new PaletteEntry("", new Color32(r, g, b, 255)));
- }
- }
-
- m_Entries = colorEntries.ToArray();
- }
- }
- }
|