暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

OldPaletteChunk.cs 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Collections.ObjectModel;
  4. using UnityEngine;
  5. namespace UnityEditor.U2D.Aseprite
  6. {
  7. /// <summary>
  8. /// Parsed representation of an Aseprite Old Palette chunk.
  9. /// </summary>
  10. /// <note>Not supported yet.</note>
  11. internal class OldPaletteChunk : BaseChunk, IPaletteProvider
  12. {
  13. public override ChunkTypes chunkType => ChunkTypes.OldPalette;
  14. /// <summary>
  15. /// Array of palette entries.
  16. /// </summary>
  17. public ReadOnlyCollection<PaletteEntry> entries => System.Array.AsReadOnly(m_Entries);
  18. PaletteEntry[] m_Entries;
  19. internal OldPaletteChunk(uint chunkSize) : base(chunkSize) { }
  20. protected override void InternalRead(BinaryReader reader)
  21. {
  22. var noOfPackets = reader.ReadUInt16();
  23. var colorEntries = new List<PaletteEntry>();
  24. var colorIndex = 0;
  25. for (var i = 0; i < noOfPackets; ++i)
  26. {
  27. var noOfColorsToSkip = reader.ReadByte();
  28. colorIndex += noOfColorsToSkip;
  29. int noOfColorsInEntry = reader.ReadByte();
  30. if (noOfColorsInEntry == 0)
  31. noOfColorsInEntry = 256;
  32. // If j + colorIndex >= 256 it means that the color chunk is invalid, so we stop reading.
  33. for (var j = 0; j < noOfColorsInEntry && (j + colorIndex < 256); ++j)
  34. {
  35. var r = reader.ReadByte();
  36. var g = reader.ReadByte();
  37. var b = reader.ReadByte();
  38. colorEntries.Add(new PaletteEntry("", new Color32(r, g, b, 255)));
  39. }
  40. }
  41. m_Entries = colorEntries.ToArray();
  42. }
  43. }
  44. }