Exemple #1
0
        //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);
        }
Exemple #2
0
 public void AddChunk(fdATChunk f)
 {
     if (IFrame)
     {
         throw new ApplicationException("Cannot add fdAT chunk to IDAT frame");
     }
     else
     {
         fdats.Add(f);
     }
 }
Exemple #3
0
        private void Handle_fdAT(PNGChunk chunk)
        {
            fdATChunk fdatC = new fdATChunk();

            fdatC.ChunkData = chunk.ChunkData;
            Frame f = frames.LastOrDefault();

            if (f == null)
            {
                throw new ApplicationException("No fctl chunk defined, fdat chunk received out of order");
            }
            else
            {
                f.AddChunk(fdatC);
            }
        }