示例#1
0
文件: CelChunk.cs 项目: 0circle0/ASE
 private void BuildWidthHeight(ref byte[] chunkData)
 {
     width_in_pixels  = Read.WORD(ref chunkData);
     height_in_pixels = Read.WORD(ref chunkData);
 }
示例#2
0
        //Keep track of the start time of coroutine
        //yield when the coroutine is taking too long.
        public IEnumerator Load(string path)
        {
            LayerNames = new List <string>();
            using UnityWebRequest w = UnityWebRequest.Get(path);
            yield return(w.SendWebRequest());

            data = w.downloadHandler.data;

            if (data.Length < 128)
            {
                //Debug.Log("File too small.");
                OnError?.Invoke("File too small.");
                yield break;
            }

            //I want a perm object
            asepriteObj = new AsepriteObj {
                header = new Header()
            };


            asepriteObj.header.GenerateChunk(ref data);


            if (!asepriteObj.header.headerHex.Equals(HEADER_MAGIC))
            {
                //Debug.Log("Only supports aseprite files.");
                OnError?.Invoke("Only supports aseprite files.");
                yield break;
            }

            while (data.Length > 1)
            {
                //Expect a frame
                var bytesInFrame   = Read.DWORD(ref data);
                var magicNumber    = Read.WORD(ref data);
                var magicNumberHex = magicNumber.ToString("x");

                //frameData bytesInFrame include the bytesInFrame and MagicNumber. Since we already have them adjust the length.
                var frameData = Read.BYTEARRAY(ref data, (int)bytesInFrame - (Read.DWORD_LENGTH + Read.WORD_LENGTH));

                //Making sure we have an aseprite file frame. This is guarenteed if a real aseprite file was loaded
                if (magicNumberHex.Equals(FRAME_MAGIC))
                {
                    Frame frame = new Frame(bytesInFrame, magicNumber, asepriteObj.header.color_depth)
                    {
                        width_in_pixels  = asepriteObj.header.width_in_pixels,
                        height_in_pixels = asepriteObj.header.height_in_pixels
                    };
                    frame.GenerateChunk(ref frameData);

                    while (frameData.Length > 1)
                    {
                        var chunkSize    = Read.DWORD(ref frameData);
                        var chunkType    = Read.WORD(ref frameData);
                        var chunkTypeHex = chunkType.ToString("x");
                        var chunkData    = Read.BYTEARRAY(ref frameData, (int)chunkSize - (Read.DWORD_LENGTH + Read.WORD_LENGTH));

                        Magic.TryGetValue(chunkTypeHex, out Action <byte[], Frame> Create);
                        Create(chunkData, frame);
                    }
                    asepriteObj.frames.Add(frame);
                }
            }
            OnSuccess?.Invoke(asepriteObj);
        }
示例#3
0
 public void GenerateChunk(ref byte[] chunkData)
 {
     number_of_packets         = Read.WORD(ref chunkData);
     old_palette_chunk_packets = new List <OldPaletteChunkPacket>();
     for (int i = 0; i < number_of_packets; i++)
     {
         OldPaletteChunkPacket oldPaletteChunkPacket = new OldPaletteChunkPacket()
         {
             number_of_palette_entries = Read.BYTE(ref chunkData),
             number_of_colors          = Read.BYTE(ref chunkData),
             colors = new List <Color32>()
         };
         Color32 color = new Color32(Read.BYTE(ref chunkData), Read.BYTE(ref chunkData), Read.BYTE(ref chunkData), 1);
         oldPaletteChunkPacket.colors.Add(color);
     }
 }