Beispiel #1
0
        public void Load(Stream stream)
        {
            Stack <AseColorEntryCollection> colors;
            AseColorGroupCollection         groups;
            AseColorEntryCollection         globalColors;
            int blockCount;

            groups       = new AseColorGroupCollection();
            globalColors = new AseColorEntryCollection();
            colors       = new Stack <AseColorEntryCollection>();

            // add the global collection to the bottom of the stack to handle color blocks outside of a group
            colors.Push(globalColors);

            this.ReadAndValidateVersion(stream);

            blockCount = stream.ReadUInt32BigEndian();

            for (int i = 0; i < blockCount; i++)
            {
                this.ReadBlock(stream, groups, colors);
            }

            this.Groups = groups;
            this.Colors = globalColors;
        }
Beispiel #2
0
        private void ReadBlock(Stream stream, AseColorGroupCollection groups, Stack <AseColorEntryCollection> colorStack)
        {
            AseBlockType blockType;
            int          blockLength;
            int          offset;
            int          dataLength;
            _BlockData   block = null;

            blockType = (AseBlockType)stream.ReadUInt16BigEndian();

            blockLength = stream.ReadUInt32BigEndian();

            // store the current position of the stream, so we can calculate the offset
            // from bytes read to the block length in order to skip the bits we didn't
            // read, support or know what they are
            offset = (int)stream.Position;

            // process the actual block
            switch (blockType)
            {
            case AseBlockType.Color:
                block = this.ReadColorBlock(stream, colorStack);
                break;

            case AseBlockType.GroupStart:
                block = this.ReadGroupBlock(stream, groups, colorStack);
                break;

            case AseBlockType.GroupEnd:
                block = null;
                colorStack.Pop();
                break;

            default:
                throw new InvalidDataException(string.Format("Unsupported block type '{0}'.", blockType));
            }

            // load in any custom data and attach it to the
            // current block (if available) as raw byte data
            dataLength = blockLength - (int)(stream.Position - offset);

            if (dataLength > 0)
            {
                byte[] extraData;

                extraData = new byte[dataLength];
                stream.Read(extraData, 0, dataLength);

                if (block != null)
                {
                    block.ExtraData = extraData;
                }
            }
        }
Beispiel #3
0
        private _BlockData ReadGroupBlock(Stream stream, AseColorGroupCollection groups, Stack <AseColorEntryCollection> colorStack)
        {
            AseColorGroupData block;
            string            name;

            // read the name of the group
            name = stream.ReadStringBigEndian();

            // create the group and add it to the results set
            block = new AseColorGroupData
            {
                Name = name
            };

            groups.Add(block);

            // add the group color collection to the stack, so when subsequent color blocks
            // are read, they will be added to the correct collection
            colorStack.Push(block.Colors);

            return(block);
        }