// APNG public static PNGWriter CreateIndexed8(int width, int height, int depth, byte[] colors, Color[] palette, Vector4[] materials) { var result = new PNGWriter { stream = new MemoryStream(), width = width, height = height, bitsPerPixel = 8, ColorType = ColorType.Indexed, }; result.writer = new BinaryWriter(result.stream); var frameSize = width * height; result.WriteSignature(); result.WriteIHDR(); if (palette != null) { result.WritePLTE(palette); result.WritetRNS(palette); //result.WritesPLT_RGBA(palette); } if (materials != null) { result.WritesPLT_MATL(materials); } result.WriteacTL((uint)depth); uint sequence = 0; var frameControl = new FrameControl { width = (uint)width, height = (uint)height, delayNum = 1, delayDen = 60, }; frameControl.sequence = sequence++; result.WritefcTL(frameControl); if (depth > 0) { result.WriteIDAT(colors, 0, frameSize); } for (int f = 1; f < depth; f++) { frameControl.sequence = sequence++; result.WritefcTL(frameControl); result.WritefdAT(sequence++, colors, f * frameSize, frameSize); } result.WriteIEND(); return(result); }
public static PNGWriter CreateA8FirstSlice(int width, int height, int depth, byte[] colors) { var result = new PNGWriter { stream = new MemoryStream(), width = width, height = height, bitsPerPixel = 8, ColorType = ColorType.Alpha, }; result.writer = new BinaryWriter(result.stream); result.WriteSignature(); result.WriteIHDR(); result.WriteIDAT(colors, 0, colors.LongLength / depth); result.WriteIEND(); return(result); }