Beispiel #1
0
        /// <summary>
        ///     Creates a new <see cref="AsepritePaletteColor"/> instance.
        /// </summary>
        /// <param name="reader">
        ///     The <see cref="AsepriteReader"/> instance being used to read the
        ///     Aseprite file.
        /// </param>
        internal AsepritePaletteColor(AsepriteReader reader, bool isNewPalette)
        {
            if (isNewPalette)
            {
                //  Only read flag if this is the new palette type.
                _flag = (AsepritePaletteFlags)reader.ReadWORD();
            }

            Red   = reader.ReadByte();
            Green = reader.ReadByte();
            Blue  = reader.ReadByte();

            if (isNewPalette)
            {
                //  Only read alpha value if this is the new palette type
                Alpha = reader.ReadByte();
            }
            else
            {
                Alpha = 255;
            }

            PackedValue = Utils.BytesToPacked(Red, Green, Blue, Alpha);

            //  If the HasName flag is present, we need to read the string value, however
            //  this seems to always never exist. Not sure what the field is for, but may
            //  just be some compatibility thing with named palette formats like .gpl.
            if ((_flag & AsepritePaletteFlags.HasName) != 0)
            {
                Name = reader.ReadString();
            }
        }
Beispiel #2
0
        /// <summary>
        ///     Creates a new <see cref="AsepriteLayerChunk"/> instance.
        /// </summary>
        /// <param name="reader">
        ///     The <see cref="AsepriteReader"/> instance being used to read the
        ///     Aseprite file.
        /// </param>
        internal AsepriteLayerChunk(AsepriteReader reader)
        {
            //  Read the flags that are set for this layer.
            Flags = (AsepriteLayerFlags)reader.ReadWORD();

            //  Read the type of layer we're dealing with.
            Type = (AsepriteLayerType)reader.ReadWORD();

            //  Read the sub level of this layer. If this layer is not a
            //  child layer, this value will be 0.
            ChildLevel = reader.ReadWORD();

            //  Per ase file spec, default layer width in pixels is ignored
            _ = reader.ReadWORD();

            //  Per ase file spec, default layer height in pixels is ignored
            _ = reader.ReadWORD();

            //  Read the blend mode used by this layer.
            BlendMode = (AsepriteBlendMode)reader.ReadWORD();

            //  Read the opacity level for this layer.
            Opacity = reader.ReadByte();

            //  Per ase file spec, ignroe next 3 bytes, they are reserved for future use
            reader.Ignore(3);

            //  Read the name of this layer.
            Name = reader.ReadString();
        }
        /// <summary>
        ///     Creates a new <see cref="AsepriteSliceChunk"/> instance.
        /// </summary>
        /// <param name="reader">
        ///     The <see cref="AsepriteReader"/> instance being used to read the
        ///     Aseprite file.
        /// </param>
        internal AsepriteSliceChunk(AsepriteReader reader)
        {
            TotalKeys = (int)reader.ReadDWORD();
            Flags     = (AsepriteSliceFlags)reader.ReadDWORD();

            //  Per ase file spec, ignore the next DWORD, it's "reserved"
            _ = reader.ReadDWORD();

            Name = reader.ReadString();

            Keys = new AsepriteSliceKey[TotalKeys];
            for (int i = 0; i < TotalKeys; i++)
            {
                Keys[i] = new AsepriteSliceKey(reader, Flags);
            }
        }
Beispiel #4
0
        /// <summary>
        ///     Reads the userdata values for this chunk from the provided
        ///     reader.
        /// </summary>
        /// <param name="reader">
        ///     The <see cref="AsepriteReader"/> instance being used to read the
        ///     Aseprite file.
        /// </param>
        internal void ReadUserData(AsepriteReader reader)
        {
            AsepriteUserDataFlags flags = (AsepriteUserDataFlags)reader.ReadDWORD();

            if ((flags & AsepriteUserDataFlags.HasText) != 0)
            {
                UserDataText = reader.ReadString();
            }

            if ((flags & AsepriteUserDataFlags.HasColor) != 0)
            {
                UserDataColor    = new byte[4];
                UserDataColor[0] = reader.ReadByte();
                UserDataColor[1] = reader.ReadByte();
                UserDataColor[2] = reader.ReadByte();
                UserDataColor[3] = reader.ReadByte();
            }
        }
Beispiel #5
0
        /// <summary>
        ///     Creates a new <see cref="AsepriteTagChunk"/> instance.
        /// </summary>
        /// <param name="reader">
        ///     The <see cref="AsepriteReader"/> instance being used to read the
        ///     Aseprite file.
        /// </param>
        internal AsepriteTagChunk(AsepriteReader reader)
        {
            From      = reader.ReadWORD();
            To        = reader.ReadWORD();
            Direction = (AsepriteLoopDirection)reader.ReadByte();

            //  Per ase file spec, ignore next 8 bytes, they are reserved for future use
            reader.Ignore(8);

            ColorR = reader.ReadByte();
            ColorG = reader.ReadByte();
            ColorB = reader.ReadByte();

            //  Per ase file spec, ignore next byte, it's just an extra one set to zero
            reader.Ignore(1);

            Name = reader.ReadString();
        }