//public static APNG AssembleAPNG(IList<string> files, bool optimize) { // if(files.Count < 1) { // return null; // } // uint sequenceCount = 0; // APNG apng = new APNG(); // PNG first = new PNG(); // using(Stream s = File.OpenRead(files.First())) { // first.Load(s); // } // SetupAPNGChunks(apng, first); // Frame firstFrame = CreateFrame(first.Height, first.Width, 0, 0, ref sequenceCount, true, first.IDATList); // apng.AddFrame(firstFrame); // foreach(string file in files.Skip(1)) { // Point p = new Point(0, 0); // PNG png = new PNG(); // using(Stream fileStr = File.OpenRead(file)) { // if(optimize) { // using(Stream optStr = OptimizeBitmapStream(fileStr, out p)) { // png.Load(optStr); // } // } else { // png.Load(fileStr); // } // } // Frame f = CreateFrame(png.Height, png.Width, (uint)p.X, (uint)p.Y, ref sequenceCount, false, png.IDATList); // apng.AddFrame(f); // } // apng.acTL.NumFrames = (uint)apng.FrameCount; // apng.Validate(); // return apng; //} //public static APNG AssembleAPNG(IList<FileInfo> files, bool optimize) { // IList<string> filenames = new List<string>(); // foreach(FileInfo fi in files) { // filenames.Add(fi.FullName); // } // return AssembleAPNG(filenames, optimize); //} private static Frame CreateFrame(int fps, uint h, uint w, uint xoff, uint yoff, ref uint seq, bool first, IList <IDATChunk> idats) { fcTLChunk fctl = new fcTLChunk() { DelayNumerator = 1, DelayDenominator = (ushort)fps, Height = h, Width = w, DisposeOperation = 1, BlendOperation = 0, XOffset = xoff, YOffset = yoff, SequenceNumber = seq++ }; Frame f = new Frame(first, fctl); foreach (IDATChunk idat in idats) { if (first) { f.AddChunk(idat); } else { fdATChunk fdat = new fdATChunk() { FrameData = idat.ImageData, SequenceNumber = seq++ }; f.AddChunk(fdat); } } return(f); }
public Frame(bool first, fcTLChunk fChunk) { IFrame = first; if (IFrame) { idats = new List <IDATChunk>(); } else { fdats = new List <fdATChunk>(); } fctl = fChunk; }
private void Handle_fcTL(PNGChunk chunk) { bool IFrame = IDATList.Count < 1; fcTLChunk fctlC = new fcTLChunk(); fctlC.ChunkData = chunk.ChunkData; if ((fctlC.XOffset + fctlC.Width) > IHDR.Width || (fctlC.YOffset + fctlC.Height) > IHDR.Height) { throw new ApplicationException("Frame is outside of image space"); } Frame f = new Frame(IFrame, fctlC); frames.Add(f); }