コード例 #1
0
ファイル: SliceChunk.cs プロジェクト: 0circle0/ASE
        public void GenerateChunk(ref byte[] chunkData)
        {
            number_of_slice_keys = Read.DWORD(ref chunkData);
            flags      = Read.DWORD(ref chunkData);
            reserved   = Read.DWORD(ref chunkData);
            name       = Read.STRING(ref chunkData);
            slice_keys = new List <SliceKey>();
            for (int i = 0; i < number_of_slice_keys; i++)
            {
                SliceKey sliceKey = new SliceKey()
                {
                    frame_number   = Read.DWORD(ref chunkData),
                    slice_x_origin = Read.LONG(ref chunkData),
                    slice_y_origin = Read.LONG(ref chunkData),
                    slice_width    = Read.DWORD(ref chunkData),
                    slice_height   = Read.DWORD(ref chunkData)
                };
                if (flags == 1)
                {
                    sliceKey.center_x_position = Read.LONG(ref chunkData);
                    sliceKey.center_y_position = Read.LONG(ref chunkData);
                    sliceKey.center_width      = Read.DWORD(ref chunkData);
                    sliceKey.center_height     = Read.DWORD(ref chunkData);
                }
                else if (flags == 2)
                {
                    sliceKey.pivot_x_position = Read.LONG(ref chunkData);
                    sliceKey.pivot_y_position = Read.LONG(ref chunkData);
                }

                slice_keys.Add(sliceKey);
            }
        }
コード例 #2
0
ファイル: Frame.cs プロジェクト: 0circle0/ASE
 public void GenerateChunk(ref byte[] chunkData)
 {
     old_chunks     = Read.WORD(ref chunkData);
     frame_duration = Read.WORD(ref chunkData);
     for_future     = Read.BYTEARRAY(ref chunkData, 2);
     chunks         = Read.DWORD(ref chunkData);
 }
コード例 #3
0
 public void GenerateChunk(ref byte[] chunkData)
 {
     filesize           = Read.DWORD(ref chunkData);
     magic_number       = Read.WORD(ref chunkData);
     frames             = Read.WORD(ref chunkData);
     width_in_pixels    = Read.WORD(ref chunkData);
     height_in_pixels   = Read.WORD(ref chunkData);
     color_depth        = Read.WORD(ref chunkData);
     flags              = Read.DWORD(ref chunkData);
     speed              = Read.WORD(ref chunkData);
     _empty1            = Read.DWORD(ref chunkData);
     _empty2            = Read.DWORD(ref chunkData);
     palette_index      = Read.BYTE(ref chunkData);
     ignore_these_bytes = Read.BYTEARRAY(ref chunkData, 3);
     number_of_colors   = Read.WORD(ref chunkData);
     pixel_width        = Read.BYTE(ref chunkData);
     pixel_height       = Read.BYTE(ref chunkData);
     x_position_on_grid = Read.SHORT(ref chunkData);
     y_position_on_grid = Read.SHORT(ref chunkData);
     grid_width         = Read.WORD(ref chunkData);
     grid_height        = Read.WORD(ref chunkData);
     for_future         = Read.BYTEARRAY(ref chunkData, 84);
     headerHex          = magic_number.ToString("x");
     pixels             = new Color32[width_in_pixels * height_in_pixels];
 }
コード例 #4
0
ファイル: PaletteChunk.cs プロジェクト: 0circle0/ASE
        public void GenerateChunk(ref byte[] chunkData)
        {
            new_palette_size = Read.DWORD(ref chunkData);
            start            = Read.DWORD(ref chunkData);
            end        = Read.DWORD(ref chunkData);
            for_future = Read.BYTEARRAY(ref chunkData, 8);

            palette_entries = new List <PaletteEntry>();
            for (int i = 0; i < end - start + 1; i++)
            {
                PaletteEntry paletteEntry = new PaletteEntry()
                {
                    entry_flags = Read.WORD(ref chunkData),
                    r           = Read.BYTE(ref chunkData),
                    g           = Read.BYTE(ref chunkData),
                    b           = Read.BYTE(ref chunkData),
                    a           = Read.BYTE(ref chunkData)
                };
                if (paletteEntry.entry_flags == 1)
                {
                    paletteEntry.name = Read.STRING(ref chunkData);
                }
                palette_entries.Add(paletteEntry);
            }
        }
コード例 #5
0
        public byte[] for_future; //size 16

        public void GenerateChunk(ref byte[] chunkData)
        {
            flags = Read.DWORD(ref chunkData);
            precise_x_position      = Read.FIXED(ref chunkData);
            precise_y_position      = Read.FIXED(ref chunkData);
            width_of_cel_in_sprite  = Read.FIXED(ref chunkData);
            height_of_cel_in_sprite = Read.FIXED(ref chunkData);
            for_future = Read.BYTEARRAY(ref chunkData, 16);
        }
コード例 #6
0
ファイル: ColorProfileChunk.cs プロジェクト: 0circle0/ASE
 public void GenerateChunk(ref byte[] chunkData)
 {
     type        = Read.WORD(ref chunkData);
     flags       = Read.WORD(ref chunkData);
     fixed_gamma = Read.FIXED(ref chunkData);
     reserved    = Read.BYTEARRAY(ref chunkData, 8);
     if (type == 2)
     {
         icc_profile_length = Read.DWORD(ref chunkData);
         icc_profile_data   = Read.BYTEARRAY(ref chunkData, (int)icc_profile_length - (ASE.Read.DWORD_LENGTH));
     }
 }
コード例 #7
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);
        }