Exemple #1
0
        static IUserDataAcceptor ParseCel(AseFile file, ColorType colorType,
                                          BinaryReader reader, int chunkBytes, Frame frame)
        {
            var layerIndex = reader.ReadWord();          // 2
            var x          = reader.ReadInt16();         // 2
            var y          = reader.ReadInt16();         // 2
            var opacity    = reader.ReadByte() / 255.0f; // 1
            var type       = (CelType)reader.ReadWord(); // 2

            reader.ReadBytes(7);                         // 7

            Cel cel;

            switch (type)
            {
            case CelType.Raw:
            {
                var celWidth    = reader.ReadWord(); // 2
                var celHeight   = reader.ReadWord(); // 2
                var colorBuffer = ToColorBuffer(colorType, reader.ReadBytes(chunkBytes - 6 - 16 - 4));
                cel = new Cel(x, y, celWidth, celHeight, colorBuffer, layerIndex, opacity);
                break;
            }

            case CelType.Linked:
            {
                var linkedFrame = reader.ReadWord();
                cel = new Cel(linkedFrame, layerIndex);
                break;
            }

            case CelType.Compressed:
            {
                var celWidth    = reader.ReadWord();
                var celHeight   = reader.ReadWord();
                var colorBuffer = ToColorBuffer(colorType, reader.ReadCompressedBytes(chunkBytes - 6 - 16 - 4));
                cel = new Cel(x, y, celWidth, celHeight, colorBuffer, layerIndex, opacity);
                break;
            }

            default:
            {
                throw new ArgumentException();
            }
            }

            if (file.FindLayer(cel.LayerIndex) != null)
            {
                frame.AddCel(cel);
            }

            return(cel);
        }
Exemple #2
0
        static void ParseFrameTags(AseFile file, BinaryReader reader)
        {
            var count = reader.ReadWord();

            reader.ReadBytes(8);

            for (int c = 0; c < count; ++c)
            {
                var fromFrame = reader.ReadWord();
                var toFrame   = reader.ReadWord();
                var loopMode  = (LoopMode)reader.ReadByte();
                reader.ReadBytes(8);
                reader.ReadBytes(3);
                reader.ReadByte();

                var name = reader.ReadUTF8();

                if (name.StartsWith("//"))
                {
                    // Commented tags are ignored
                    continue;
                }

                var originalName = name;

                var tagIdx      = name.IndexOf('#');
                var nameInvalid = false;
                var properties  = new HashSet <string>();
                if (tagIdx != -1)
                {
                    name = name.Substring(0, tagIdx).Trim();
                    var possibleProperties = originalName.Substring(tagIdx).Split(' ');
                    foreach (var possibleProperty in possibleProperties)
                    {
                        if (possibleProperty.Length > 1 && possibleProperty[0] == '#')
                        {
                            properties.Add(possibleProperty.Substring(1));
                        }
                        else
                        {
                            nameInvalid = true;
                        }
                    }
                }

                if (nameInvalid)
                {
                    Debug.LogWarning("Invalid frame name: " + originalName);
                }

                file.AddTag(new FrameTag(name, fromFrame, toFrame, loopMode, properties));
            }
        }
Exemple #3
0
        static AseFile ParseHeader(BinaryReader reader,
                                   out int frameCount,
                                   out ColorType colorType)
        {
            reader.ReadDWord(); // File size
            _CheckMagicNumber(reader.ReadWord(), 0xA5E0);

            frameCount = reader.ReadWord();

            var width  = reader.ReadWord();
            var height = reader.ReadWord();
            var file   = new AseFile(width, height);

            var colorDepth = reader.ReadWord();

            if (colorDepth == 32)
            {
                colorType = ColorType.RGBA;
            }
            else if (colorDepth == 16)
            {
                colorType = ColorType.GrayScale;
            }
            else
            {
                throw new ArgumentException("Colour depth of " + colorDepth + " bits is not currently supported.");
            }

            reader.ReadDWord(); // Flags
            reader.ReadWord();  // Deprecated speed
            _CheckMagicNumber(reader.ReadDWord(), 0);
            _CheckMagicNumber(reader.ReadDWord(), 0);

            reader.ReadBytes(4);
            reader.ReadWord();
            reader.ReadBytes(2);
            reader.ReadBytes(92);
            return(file);
        }
Exemple #4
0
 static Layer FindLayer(this AseFile file, int index)
 {
     return(FindLayerGlobally(file.Layers, index));
 }
Exemple #5
0
        static IUserDataAcceptor ParseLayer(AseFile file,
                                            BinaryReader reader,
                                            Stack <LayerGroup> layerGroups,
                                            int readLayerIndex)
        {
            IUserDataAcceptor lastUserdataAcceptor;
            var flags = reader.ReadWord();

            var visible        = (flags & 0x1) != 0;
            var referenceLayer = (flags & 0x20) != 0;

            var layerType  = (AseLayerType)reader.ReadWord();
            var childLevel = reader.ReadWord(); // childLevel

            if ((layerGroups.Count - 1) != (childLevel))
            {
                layerGroups.Pop();
                if (layerGroups.Count == 0)
                {
                    // workaround broken files ..
                    Debug.LogWarning("Layer Structure Parsing Error.");
                    layerGroups.Push(file.Layers);
                }
            }

            reader.ReadWord();
            reader.ReadWord();

            var blendMode = (BlendMode)reader.ReadWord();
            var opacity   = reader.ReadByte() / 255.0f;

            reader.ReadBytes(3);

            var layerName = reader.ReadUTF8();
            var type      = layerName.StartsWith("@") ? LayerType.Meta : LayerType.Content;

            Debug.Log("Reading layer definition " + readLayerIndex + ", " + layerName);

            if (layerType == AseLayerType.Layer && !layerName.StartsWith("//") && !referenceLayer)
            {
                //layer.index = readLayerIndex;
                var layer = new Layer(readLayerIndex, type, layerName, visible, blendMode, opacity);
                if (layer.Type == LayerType.Meta || visible)
                {
                    MetaLayerParser.Parse(layer);
                    layerGroups.Peek().Layers.Add(layer);
                }

                lastUserdataAcceptor = layer;
            }
            else if (layerType == AseLayerType.LayerGroup)
            {
                // is a layer group.
                var layerGroup = new LayerGroup(readLayerIndex, layerName);
                MetaLayerParser.Parse(layerGroup);
                layerGroups.Peek().SubGroups.Add(layerGroup);
                layerGroups.Push(layerGroup);
                lastUserdataAcceptor = layerGroup;
            }
            else
            {
                lastUserdataAcceptor = new NoOpUserDataAcceptor();
            }

            return(lastUserdataAcceptor);
        }