Example #1
0
        public AseLayerChunk(AseFrame frame, AseReader reader)
            : base(frame)
        {
            Flags      = (LayerChunkFlags)reader.ReadWORD();
            Type       = (LayerType)reader.ReadWORD();
            ChildLevel = reader.ReadWORD();

            // Ignore next two words
            reader.ReadWORD();
            reader.ReadWORD();

            BlendMode = (BlendMode)reader.ReadWORD();
            Opacity   = reader.ReadBYTE();

            if ((frame.AseFile.Header.Flags & HeaderFlags.HasLayerOpacity) == 0)
            {
                // Assume full opacity
                Opacity = 255;
            }

            // Ignore next three bytes
            reader.ReadBYTEs(3);

            Name = reader.ReadSTRING();
        }
Example #2
0
 public AseDummyChunk(AseFrame frame, AseReader reader, ChunkType type, int size)
     : base(frame)
 {
     m_ChunkType = type;
     ChunkSize   = size;
     Bytes       = reader.ReadBYTEs(size);
 }
Example #3
0
        public AseFile(AseReader reader)
        {
            Header = new AseHeader(reader);

            Frames = Enumerable.Repeat<AseFrame>(null, Header.NumFrames).ToList();
            for (int i = 0; i < Header.NumFrames; i++)
            {
                Frames[i] = new AseFrame(this, reader);
            }
        }
Example #4
0
        public static AseChunk ReadChunk(AseFrame frame, ChunkType type, int size, AseReader reader)
        {
            var      pos   = reader.Position;
            AseChunk chunk = null;

            switch (type)
            {
            // Chunk types we care about
            case ChunkType.Palette:
                chunk = new AsePaletteChunk(frame, reader);
                break;

            case ChunkType.Layer:
                chunk = new AseLayerChunk(frame, reader);
                break;

            case ChunkType.Cel:
                chunk = new AseCelChunk(frame, reader, size);
                break;

            case ChunkType.ColorProfile:
                chunk = new AseColorProfileChunk(frame, reader);
                break;

            case ChunkType.FrameTags:
                chunk = new AseFrameTagsChunk(frame, reader);
                break;

            case ChunkType.Slice:
                chunk = new AseSliceChunk(frame, reader);
                break;

            case ChunkType.UserData:
                chunk = new AseUserDataChunk(frame, reader);
                break;

            // Chunk types we don't care about
            case ChunkType.OldPalette:
                chunk = new AseDummyChunk(frame, reader, type, size);
                break;

            // Chunk types we haven't handled yet. Indicates a bug that should be fixed.
            default:
                chunk = new AseDummyChunk(frame, reader, type, size);
                Debug.LogErrorFormat("Unhandled chunk type: {0}", ((ushort)type).ToString("X4"));
                break;
            }

            // Check that we read the right amount of bytes
            Assert.IsTrue((reader.Position - pos) == size, string.Format("Chunk {0} read {1} bytes but we were expected {2} bytes read", type, reader.Position - pos, size));
            reader.LastChunk = chunk;

            return(chunk);
        }
Example #5
0
        public AseFrameTagsChunk(AseFrame frame, AseReader reader)
            : base(frame)
        {
            NumTags = reader.ReadWORD();

            // Ignore next 8 bytes
            reader.ReadBYTEs(8);

            Entries = Enumerable.Repeat <AseFrameTagEntry>(null, NumTags).ToList();
            for (int i = 0; i < (int)NumTags; i++)
            {
                Entries[i] = new AseFrameTagEntry(reader);
            }
        }
Example #6
0
        public void EndFrameVisit(AseFrame frame)
        {
            // We should have everything we need to make a sprite and add it to our asset

            // The texture should be ready to be added to our asset
            m_Texture2D.Apply();
            m_Context.AddObjectToAsset(m_Texture2D.name, m_Texture2D);

            // Make a sprite out of the texture
            var pivot  = m_Pivot ?? new Vector2(0.5f, 0.5f);
            var sprite = Sprite.Create(m_Texture2D, new Rect(0, 0, m_Texture2D.width, m_Texture2D.height), pivot, m_PixelsPerUnit);

            sprite.name = string.Format("{0}_sprite_{1}", Path.GetFileNameWithoutExtension(assetPath), m_Sprites.Count);
            m_Sprites.Add(sprite);
            m_Context.AddObjectToAsset(sprite.name, sprite);
        }
Example #7
0
        public void BeginFrameVisit(AseFrame frame)
        {
            var width  = m_AseFile.Header.Width;
            var height = m_AseFile.Header.Height;

            m_Texture2D            = new Texture2D(width, height, TextureFormat.RGBA32, false);
            m_Texture2D.wrapMode   = TextureWrapMode.Clamp;
            m_Texture2D.filterMode = FilterMode.Point;
            m_Texture2D.name       = string.Format("{0}_tex2d_{1}", Path.GetFileNameWithoutExtension(assetPath), m_Frames.Count);

            // Texture starts off blank
            m_Texture2D.SetPixels(0, 0, width, height, m_ClearPixels);
            m_Texture2D.Apply();

            m_Frames.Add(frame);
        }
Example #8
0
        public AsePaletteChunk(AseFrame frame, AseReader reader)
            : base(frame)
        {
            PaletteSize = (int)reader.ReadDWORD();
            FirstIndex  = (int)reader.ReadDWORD();
            LastIndex   = (int)reader.ReadDWORD();

            // Next 8 bytes are ignored
            reader.ReadBYTEs(8);

            Entries = Enumerable.Repeat <AsePaletteEntry>(null, LastIndex + 1).ToList();
            for (int i = FirstIndex; i <= LastIndex; i++)
            {
                Entries[i] = new AsePaletteEntry(reader);
            }
        }
Example #9
0
        public AseSliceChunk(AseFrame frame, AseReader reader)
            : base(frame)
        {
            NumSliceKeys = reader.ReadDWORD();
            Flags        = (SliceFlags)reader.ReadDWORD();

            // Ignore next dword
            reader.ReadDWORD();

            Name = reader.ReadSTRING();

            Entries = Enumerable.Repeat <AseSliceEntry>(null, (int)NumSliceKeys).ToList();
            for (int i = 0; i < (int)NumSliceKeys; i++)
            {
                Entries[i] = new AseSliceEntry(reader, Flags);
            }
        }
        public AseColorProfileChunk(AseFrame frame, AseReader reader)
            : base(frame)
        {
            ColorProfileType  = (ColorProfileType)reader.ReadWORD();
            ColorProfileFlags = (ColorProfileFlags)reader.ReadWORD();
            GammaFixed        = reader.ReadDWORD();

            // Next 8 bytes are reserved
            reader.ReadBYTEs(8);

            // fixit - what to do with color profile data?
            if (ColorProfileType == ColorProfileType.EmbeddedICC)
            {
                var length = (int)reader.ReadDWORD();
                reader.ReadBYTEs(length);
            }
        }
Example #11
0
        public AseColorProfileChunk(AseFrame frame, AseReader reader)
            : base(frame)
        {
            ColorProfileType  = (ColorProfileType)reader.ReadWORD();
            ColorProfileFlags = (ColorProfileFlags)reader.ReadWORD();
            GammaFixed        = reader.ReadDWORD();

            // Next 8 bytes are reserved
            reader.ReadBYTEs(8);

            // Do we need to do anything with color profile data?
            // For now, just keep on truckin'
            if (ColorProfileType == ColorProfileType.EmbeddedICC)
            {
                var length = (int)reader.ReadDWORD();
                reader.ReadBYTEs(length);
            }
        }
Example #12
0
        public AseCelChunk(AseFrame frame, AseReader reader, int size)
            : base(frame)
        {
            // Keep track of read position
            var pos = reader.Position;

            LayerIndex = reader.ReadWORD();
            PositionX  = reader.ReadSHORT();
            PositionY  = reader.ReadSHORT();
            Opacity    = reader.ReadBYTE();
            CelType    = (CelType)reader.ReadWORD();

            // Ignore next 7 bytes
            reader.ReadBYTEs(7);

            if (CelType == CelType.Raw)
            {
                Width  = reader.ReadWORD();
                Height = reader.ReadWORD();

                var bytesRead = reader.Position - pos;
                PixelBytes = reader.ReadBYTEs(size - bytesRead);
            }
            else if (CelType == CelType.Linked)
            {
                FramePositionLink = reader.ReadWORD();

                // Get a reference to our linked cell. It should be in a previous frame with a matching layer index.
                Debug.Assert(Frame.AseFile.Frames.Count > FramePositionLink);
                LinkedCel = Frame.AseFile.Frames[FramePositionLink].Chunks.OfType <AseCelChunk>().FirstOrDefault(c => c.LayerIndex == LayerIndex);
                Debug.Assert(LinkedCel != null);
            }
            else if (CelType == CelType.CompressedImage)
            {
                Width  = reader.ReadWORD();
                Height = reader.ReadWORD();

                var bytesRead  = reader.Position - pos;
                var compressed = reader.ReadBYTEs(size - bytesRead);
                PixelBytes = ZlibDeflate(compressed);
            }
        }
        public AseUserDataChunk(AseFrame frame, AseReader reader)
            : base(frame)
        {
            Flags = (UserDataFlags)reader.ReadDWORD();

            if ((Flags & UserDataFlags.HasText) != 0)
            {
                Text = reader.ReadSTRING();
            }

            if ((Flags & UserDataFlags.HasColor) != 0)
            {
                ColorRGBA = reader.ReadBYTEs(4);
            }

            // Place the user data in the last chunk
            if (reader.LastChunk != null)
            {
                reader.LastChunk.UserText  = Text;
                reader.LastChunk.UserColor = ColorRGBA;
            }
        }
Example #14
0
 protected AseChunk(AseFrame frame)
 {
     Frame = frame;
 }