Skip to content

Commit

Permalink
Fixed error with reading in the wrong number of chunks. Start of hand…
Browse files Browse the repository at this point in the history
…ling beta feature for color profiles.
  • Loading branch information
seanb-22ct committed Jan 15, 2019
1 parent 660720b commit 2115bfd
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 13 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ sysinfo.txt
#*.unitypackage
Aseprite2Unity/Logs/Packages-Update.log
deploy/output.log
docs/_build
docs/_build

# Test data
Aseprite2Unity/Assets/TestData/
Aseprite2Unity/Assets/TestData.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Aseprite2Unity.Editor
{
public class AseColorProfileChunk : AseChunk
{
public override ChunkType ChunkType => ChunkType.ColorProfile;

public ColorProfileType ColorProfileType { get; }
public ColorProfileFlags ColorProfileFlags { get; }
public uint GammaFixed { get; }

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 Visit(IAseVisitor visitor)
{
// fixit - nothing for now
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 14 additions & 12 deletions Aseprite2Unity/Assets/Aseprite2Unity/Editor/AseReader/AseFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,35 @@ public class AseFrame
{
public AseFile AseFile { get; private set; }

public uint NumBytesInFrame { get; private set; }
public ushort MagicNumber { get; private set; }
public ushort NumChunksOld { get; private set; }
public ushort FrameDurationMs { get; private set; }
public uint NumChunksNew { get; private set; }
public uint NumBytesInFrame { get; }
public ushort MagicNumber { get; }
public uint NumChunks { get; }
public ushort FrameDurationMs { get; }

public int NumChunksTotal { get { return (int)(NumChunksOld + NumChunksNew); } }

public List<AseChunk> Chunks { get; private set; }
public List<AseChunk> Chunks { get; }

public AseFrame(AseFile file, AseReader reader)
{
AseFile = file;

NumBytesInFrame = reader.ReadDWORD();
MagicNumber = reader.ReadWORD();
NumChunksOld = reader.ReadWORD();
NumChunks = reader.ReadWORD();
FrameDurationMs = reader.ReadWORD();

// Ingore next two bytes
reader.ReadBYTEs(2);

NumChunksNew = reader.ReadDWORD();
// 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, NumChunksTotal).ToList();
for (int i = 0; i < NumChunksTotal; i++)
Chunks = Enumerable.Repeat<AseChunk>(null, (int)NumChunks).ToList();
for (int i = 0; i < NumChunks; i++)
{
Chunks[i] = ReadChunk(reader);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public static AseChunk ReadChunk(AseFrame frame, ChunkType type, int size, AseRe
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum ChunkType : ushort
OldPalette = 0x0004,
Layer = 0x2004,
Cel = 0x2005,
ColorProfile = 0x2007,
FrameTags = 0x2018,
Palette = 0x2019,
UserData = 0x2020,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Aseprite2Unity.Editor
{
public enum ColorProfileFlags : ushort
{
SpecialFixedGamma = 1,
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Aseprite2Unity.Editor
{
public enum ColorProfileType : ushort
{
NoColorProfile = 0,
sRGB = 1,
EmbeddedICC = 2,
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2115bfd

Please sign in to comment.