diff --git a/apng.d b/apng.d index 433f4c7..5a3d8f9 100644 --- a/apng.d +++ b/apng.d @@ -57,6 +57,7 @@ class ApngFrame { auto height = frameControlChunk.height; auto bytesPerLine = bytesPerLineOfPng(parent.header.depth, parent.header.type, width); + bytesPerLine--; // removing filter byte from this calculation since we handle separtely int idataIdx; ubyte[] idata; @@ -79,11 +80,7 @@ class ApngFrame { this.data = idata; } - // then need to uncompress it - // and unfilter it... - // and then convert it to the right format. - - MemoryImage frameData; + //MemoryImage frameData; } class ApngAnimation { @@ -109,16 +106,16 @@ enum APNG_BLEND_OP : byte { OVER = 1 } -void readApng(in ubyte[] data) { +ApngAnimation readApng(in ubyte[] data) { auto png = readPng(data); auto header = PngHeader.fromChunk(png.chunks[0]); - Color[] palette; - if(header.type == 3) { - palette = fetchPalette(png); - } auto obj = new ApngAnimation(); + if(header.type == 3) { + obj.palette = fetchPalette(png); + } + bool seenIdat = false; bool seenFctl = false; @@ -227,11 +224,13 @@ void readApng(in ubyte[] data) { expectedSequenceNumber++; // and the rest of it is a datastream... - obj.frames[frameNumber - 1].compressedDatastream ~= chunk.payload; + obj.frames[frameNumber - 1].compressedDatastream ~= chunk.payload[offset .. $]; break; default: // ignore } } + + return obj; } diff --git a/png.d b/png.d index 8b618d1..bdebb07 100644 --- a/png.d +++ b/png.d @@ -231,7 +231,7 @@ void convertPngData(ubyte type, ubyte depth, const(ubyte)[] data, int width, uby break; default: assert(0); } - assert(data.length == 0, "not all consumed, wtf ");// ~ to!string(h)); + assert(data.length == 0, "not all consumed, wtf " ~ to!string(data)); } /* @@ -1482,6 +1482,7 @@ struct LazyPngFile(LazyPngChunksProvider) } // FIXME: doesn't handle interlacing... I think +// note it returns the length including the filter byte!! @nogc @safe pure nothrow int bytesPerLineOfPng(ubyte depth, ubyte type, uint width) { immutable bitsPerChannel = depth;