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(); }
public AseFrameTagEntry(AseReader reader) { FromFrame = reader.ReadWORD(); ToFrame = reader.ReadWORD(); LoopAnimationDirection = (LoopAnimationDirection)reader.ReadBYTE(); // Ignore next 8 bytes reader.ReadBYTEs(8); ColorRGB = reader.ReadBYTEs(3); // Ignore a byte reader.ReadBYTE(); Name = reader.ReadSTRING(); // "OneShot" loop hack if (Name.StartsWith("[") && Name.EndsWith("]")) { Name = Name.Remove(0, 1); Name = Name.Remove(Name.Length - 1, 1); IsOneShot = true; } else { IsOneShot = false; } }
public AseDummyChunk(AseFrame frame, AseReader reader, ChunkType type, int size) : base(frame) { m_ChunkType = type; ChunkSize = size; Bytes = reader.ReadBYTEs(size); }
public AseHeader(AseReader reader) { FileSize = reader.ReadDWORD(); MagicNumber = reader.ReadWORD(); NumFrames = reader.ReadWORD(); Width = reader.ReadWORD(); Height = reader.ReadWORD(); ColorDepth = reader.ReadColorDepth(); Flags = (HeaderFlags)reader.ReadDWORD(); Speed = reader.ReadWORD(); // Next two dwords are ignored reader.ReadDWORD(); reader.ReadDWORD(); TransparentIndex = reader.ReadBYTE(); // Next 3 bytes are ignored reader.ReadBYTEs(3); NumColors = reader.ReadWORD(); PixelWidth = reader.ReadBYTE(); PixelHeight = reader.ReadBYTE(); // Last 92 bytes are reserved for future use reader.ReadBYTEs(92); Debug.Assert(MagicNumber == 0xA5E0); }
private AseChunk ReadChunk(AseReader reader) { uint size = reader.ReadDWORD(); ChunkType type = (ChunkType)reader.ReadWORD(); return(ChunkFactory.ReadChunk(this, type, (int)(size - 6), reader)); }
public AseFrame(AseFile file, AseReader reader) { AseFile = file; NumBytesInFrame = reader.ReadDWORD(); MagicNumber = reader.ReadWORD(); NumChunks = reader.ReadWORD(); FrameDurationMs = reader.ReadWORD(); // Ingore next two bytes reader.ReadBYTEs(2); // Later versions of Aseprite may overwrite our number of chunks var nchunks = reader.ReadDWORD(); if (NumChunks == 0xFFFF && NumChunks < nchunks) { NumChunks = nchunks; } // Read in old and new chunks Chunks = Enumerable.Repeat <AseChunk>(null, (int)NumChunks).ToList(); for (int i = 0; i < NumChunks; i++) { Chunks[i] = ReadChunk(reader); } Debug.Assert(MagicNumber == 0xF1FA); }
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); } }
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); }
public AsePaletteEntry(AseReader reader) { Flags = reader.ReadWORD(); Red = reader.ReadBYTE(); Green = reader.ReadBYTE(); Blue = reader.ReadBYTE(); Alpha = reader.ReadBYTE(); if (HasName) { Name = reader.ReadSTRING(); } }
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); } }
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); } }
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); } }
public override void OnImportAsset(AssetImportContext ctx) { m_Errors.Clear(); #if UNITY_2018_1_OR_NEWER m_Context = ctx; using (var reader = new AseReader(ctx.assetPath)) { m_AseFile = new AseFile(reader); m_AseFile.VisitContents(this); } #else string msg = string.Format("Aesprite2Unity requires Unity 2018.3 or later. You are using {0}", Application.unityVersion); m_Errors.Add(msg); Debug.LogError(msg); #endif }
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); } }
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 AseSliceEntry(AseReader reader, SliceFlags flags) { FrameNumber = reader.ReadDWORD(); OriginX = reader.ReadLONG(); OriginY = reader.ReadLONG(); Width = reader.ReadDWORD(); Height = reader.ReadDWORD(); if ((flags & SliceFlags.Is9PatchSlice) != 0) { CenterX = reader.ReadLONG(); CenterY = reader.ReadLONG(); CenterWidth = reader.ReadDWORD(); CenterHeight = reader.ReadDWORD(); } if ((flags & SliceFlags.HasPivotInformation) != 0) { PivotX = reader.ReadLONG(); PivotY = reader.ReadLONG(); } }
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; } }