Esempio n. 1
0
 private void init_ase_frame_header(ref ASE_FRAME_HEADER _h)
 {
     _h.byte_per_frame = 0;
     _h.magic_number   = 0;
     _h.chunks         = 0;
     _h.frame_duration = 100;
     _h.reserved       = new byte[3];
 }
Esempio n. 2
0
        private void import_ase(bool _from_wd = false)
        {
            if (!ase_auto_import_cbx.Checked && _from_wd)
            {
                return;
            }
            if (!ase_import_complete)
            {
                MessageBox.Show("ASE IMPORT NOT FINISHED");
                return;
            }

            ase_import_complete = false;
            int byte_read_offset = 0;

            byte[] buffer = File.ReadAllBytes(ase_path);


            //https://github.com/aseprite/aseprite/blob/master/docs/files/ase.txt

            ASE_HEADER file_head = new ASE_HEADER();

            init_ase_header(ref file_head);
            file_head = (ASE_HEADER)ByteArrayToStruct(buffer, byte_read_offset, typeof(ASE_HEADER));
            if (file_head.magic_number != 42464)
            {
                MessageBox.Show("ASE IMPORT FAILED - MAGIC NUMBER WRONG - AUTO IMPORT DISBALED");
                ase_auto_import_cbx.Checked = false;
                return;
            }
            if (file_head.frames <= 0)
            {
                MessageBox.Show("ASE IMPORT FAILED - NO FRAMES AVARIABLE");
                return;
            }

            ase_parsed_frames.Clear();
            byte_read_offset += 128; //pos after file head

            for (int frame_head_counter = 0; frame_head_counter < file_head.frames; frame_head_counter++)
            {
                ASE_FRAME_HEADER current_frame_header = new ASE_FRAME_HEADER();
                current_frame_header = (ASE_FRAME_HEADER)ByteArrayToStruct(buffer, byte_read_offset, typeof(ASE_FRAME_HEADER));
                byte_read_offset    += 16;
                if (current_frame_header.magic_number != 61946)
                {
                    MessageBox.Show("ASE IMPORT FAILED - INVALID FRAME DATA");
                    return;
                }

                List <ASE_CHUNK> chunks_list = new List <ASE_CHUNK>();
                //FOR EACH CHUNK
                for (int j = 0; j < current_frame_header.chunks; j++)
                {
                    ASE_CHUNK curr_chunk = new ASE_CHUNK();
                    curr_chunk.chunk_head = new ASE_CHUNK_HEAD();
                    //READ CHUNK DATA
                    curr_chunk.chunk_head = (ASE_CHUNK_HEAD)ByteArrayToStruct(buffer, byte_read_offset, typeof(ASE_CHUNK_HEAD));
                    //READ CHUNK DATA
                    curr_chunk.chunk_data = new byte[curr_chunk.chunk_head.chunk_size];

                    //SWITCH TYPE AND CREARTE TYPE
                    switch (curr_chunk.chunk_head.chunk_type)
                    {
                    case 4:
                        curr_chunk.chunk_type = ASE_CHUNK_TYPE.OLD_PALETTE;
                        break;

                    case 17:
                        curr_chunk.chunk_type = ASE_CHUNK_TYPE.OLD_PALETTE;
                        break;

                    case 8196:
                        curr_chunk.chunk_type = ASE_CHUNK_TYPE.LAYER;
                        break;

                    case 8197:
                        curr_chunk.chunk_type = ASE_CHUNK_TYPE.CELL;
                        break;

                    case 8214:
                        curr_chunk.chunk_type = ASE_CHUNK_TYPE.MASK;
                        break;

                    case 8215:
                        curr_chunk.chunk_type = ASE_CHUNK_TYPE.PATH;
                        break;

                    case 2016:
                        curr_chunk.chunk_type = ASE_CHUNK_TYPE.FRAME_TAG;
                        break;

                    case 8217:
                        curr_chunk.chunk_type = ASE_CHUNK_TYPE.PALETTE;
                        break;

                    case 8224:
                        curr_chunk.chunk_type = ASE_CHUNK_TYPE.USER_DATA;
                        break;

                    default:
                        curr_chunk.chunk_type = ASE_CHUNK_TYPE.INVLAID;
                        break;
                    }
                    //WRITE BYTES TO DATA BLOB
                    curr_chunk.chunk_data = new byte[curr_chunk.chunk_head.chunk_size];
                    for (int i = 0; i < curr_chunk.chunk_head.chunk_size; i++)
                    {
                        curr_chunk.chunk_data[i] = buffer[byte_read_offset + i];
                    }
                    //SET OFFSET TO NEXT CHUNK START
                    byte_read_offset += (int)curr_chunk.chunk_head.chunk_size;
                    //ADD PARSED CHUNK TO LIST
                    chunks_list.Add(curr_chunk);
                }
                //SAVE DATA AS NEW COMBINED
                ASE_PARSED_PROJECT tmp_frame = new ASE_PARSED_PROJECT();
                tmp_frame.frame_id   = frame_head_counter;
                tmp_frame.frame_info = current_frame_header;
                tmp_frame.chunks     = chunks_list;
                //SAVE IN FRAME STORE
                ase_parsed_frames.Add(tmp_frame);
            }
            ase_import_complete = true;
            return;
        }