Пример #1
0
        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);
            }
        }
Пример #2
0
 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
        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);
        }
Пример #5
0
 private void BuildChunkVariables(ref byte[] chunkData)
 {
     layer_index = Read.WORD(ref chunkData);
     x_position  = Read.SHORT(ref chunkData);
     y_position  = Read.SHORT(ref chunkData);
     opacity     = Read.BYTE(ref chunkData);
     cel_type    = Read.WORD(ref chunkData);
     for_future  = Read.BYTEARRAY(ref chunkData, 7);
 }
Пример #6
0
 public void GenerateChunk(ref byte[] chunkData)
 {
     x_position   = Read.SHORT(ref chunkData);
     y_position   = Read.SHORT(ref chunkData);
     width        = Read.WORD(ref chunkData);
     height       = Read.WORD(ref chunkData);
     for_future   = Read.BYTEARRAY(ref chunkData, 8);
     mask_name    = Read.STRING(ref chunkData);
     bit_map_data = Read.BYTEARRAY(ref chunkData, height * ((width + 7) / 8));
 }
Пример #7
0
 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));
     }
 }
Пример #8
0
 public void GenerateChunk(ref byte[] chunkData)
 {
     flags                          = Read.WORD(ref chunkData);
     layer_type                     = Read.WORD(ref chunkData);
     layer_child_level              = Read.WORD(ref chunkData);
     default_layer_width_in_pixels  = Read.WORD(ref chunkData);
     default_layer_height_in_pixels = Read.WORD(ref chunkData);
     blend_mode                     = Read.WORD(ref chunkData);
     opacity                        = Read.BYTE(ref chunkData);
     for_future                     = Read.BYTEARRAY(ref chunkData, 3);
     layer_name                     = Read.STRING(ref chunkData);
 }
Пример #9
0
        private void ProcessCell(ref byte[] chunkData, bool compressed)
        {
            BuildWidthHeight(ref chunkData);

            if (compressed)
            {
                raw_cel_compressed = chunkData;

                int count = width_in_pixels * height_in_pixels * (color_depth / 8);
                raw_data = Read.DecompressImageBytes(raw_cel_compressed, count);
            }
            else
            {
                raw_data = Read.BYTEARRAY(ref chunkData, width_in_pixels * height_in_pixels);
            }

            BuildColor32Direct();
        }
Пример #10
0
 public void GenerateChunk(ref byte[] chunkData)
 {
     number_of_tags = Read.WORD(ref chunkData);
     for_future     = Read.BYTEARRAY(ref chunkData, 8);
     tags           = new List <Tag>();
     for (int i = 0; i < number_of_tags; i++)
     {
         Tag tag = new Tag()
         {
             from_frame = Read.WORD(ref chunkData),
             to_frame   = Read.WORD(ref chunkData),
             loop_animation_direction = Read.BYTE(ref chunkData),
             for_future    = Read.BYTEARRAY(ref chunkData, 8),
             RBG_tag_color = Read.BYTEARRAY(ref chunkData, 3),
             extra_byte    = Read.BYTE(ref chunkData),
             tag_name      = Read.STRING(ref chunkData)
         };
         tags.Add(tag);
     }
 }
Пример #11
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);
        }