예제 #1
0
        protected Layer(BinaryReader reader, ushort flags, Ase ase)
        {
            Level
                = reader.ReadUInt16();
            var defaultWidth
                = reader.ReadUInt16();
            var defaultHeight
                = reader.ReadUInt16();

            mode
                = (BlendMode)reader.ReadUInt16();
            opacity
                = reader.ReadByte();
            var future
                = reader.ReadBytes(3);

            Name
                = Ase.ReadString(reader);

            this.flags = flags;
            Ase        = ase;

            if (Level == 0)
            {
                Parent = null;
            }
            else
            {
                Parent = ase.Layers.Last() as GroupLayer;

                if (Parent == null)
                {
                    throw new ArgumentException($"Layer at level {Level} (i.e. greater than 0) expects a non-null previous layer.");
                }

                var delta = Level - Parent.Level;
                if (delta > 1)
                {
                    throw new ArgumentException($"Level difference between this Layer and the previous is {delta} (i.e. greater than 1).");
                }

                try
                {
                    while (delta++ < 1)
                    {
                        Parent = Parent.Parent;
                    }
                    Parent.GetHashCode(); // smelly null check
                }
                catch (NullReferenceException ex)
                {
                    throw new ArgumentNullException("Layer heirarchy is broken.", ex);
                }
            }
        }
예제 #2
0
        private static FrameTag FromReader(BinaryReader reader)
        {
            ushort fromFrame
                = reader.ReadUInt16();
            ushort toFrame
                = reader.ReadUInt16();
            var direction
                = reader.ReadByte();
            var future
                = reader.ReadBytes(8);
            Color color
                = Color.FromArgb(reader.ReadByte(), reader.ReadByte(), reader.ReadByte());
            var zero
                = reader.ReadByte();
            string tagName
                = Ase.ReadString(reader);

            return(new FrameTag(fromFrame, toFrame, (AnimationDirection)direction, color, tagName));
        }
예제 #3
0
        internal static Layer FromChunk(Chunk chunk, Ase ase)
        {
            using (var reader = chunk.GetDataReader())
            {
                ushort flags
                    = reader.ReadUInt16();
                var layerType
                    = reader.ReadUInt16();
                switch (layerType)
                {
                case 0:
                    return(ImageLayer.FromReader(reader, flags, ase));

                case 1:
                    return(GroupLayer.FromReader(reader, flags, ase));

                default:
                    throw new ArgumentException($"{layerType} is not a valid layer type.");
                }
            }
        }
예제 #4
0
        internal static UserData FromChunk(Chunk chunk)
        {
            using (var reader = chunk.GetDataReader())
            {
                switch (reader.ReadUInt32())
                {
                case 0b00:
                    return(new UserData());

                case 0b01:
                    return(new UserData(Ase.ReadString(reader)));

                case 0b10:
                    return(new UserData(Colorizing.ReadColor(reader)));

                case 0b11:
                    return(new UserData(Ase.ReadString(reader), Colorizing.ReadColor(reader)));

                default:
                    throw new ArgumentException($"Unknown user data flags encountered at {reader.BaseStream.Position - 4}.");
                }
            }
        }
예제 #5
0
 internal static ImageLayer FromReader(BinaryReader reader, ushort flags, Ase ase)
 => new ImageLayer(reader, flags, ase);
예제 #6
0
 protected ImageLayer(BinaryReader reader, ushort flags, Ase ase) : base(reader, flags, ase)
 {
 }
예제 #7
0
 internal Frame(FrameHeader header, Ase ase)
 {
     this.header = header;
     Ase         = ase;
 }
예제 #8
0
 internal static GroupLayer FromReader(BinaryReader reader, ushort flags, Ase ase)
 => new GroupLayer(reader, flags, ase);