public static CellChunk Read(AsepriteStreamReader reader, ColorDepth colorDepth) { // WORD Layer index(see NOTE.2) var layerIndex = reader.WORD(); // SHORT X position var xPosition = reader.SHORT(); // SHORT Y position var yPosition = reader.SHORT(); // BYTE Opacity level var opacityLevel = reader.BYTE(); // WORD Cel type var cellType = reader.WORD(); // BYTE[7] For future(set to zero) reader.BYTES(7); // +For cel type = 0(Raw Cel) if (cellType == 0) { // WORD Width in pixels var width = reader.WORD(); // WORD Height in pixels var height = reader.WORD(); // PIXEL[] Raw pixel data: row by row from top to bottom, // for each scanline read pixels from left to right. var depthModifier = 0; if (colorDepth == ColorDepth.RGBA) { depthModifier = 4; } else if (colorDepth == ColorDepth.Grayscale) { depthModifier = 2; } else if (colorDepth == ColorDepth.Indexed) { depthModifier = 1; } var pixels = reader.BYTES(width * height * depthModifier); return(new CellChunk(layerIndex, xPosition, yPosition, opacityLevel, cellType, width, height, pixels)); } // + For cel type = 1(Linked Cel) else if (cellType == 1) { // WORD Frame position to link with var linkedFramePosition = reader.WORD(); return(new CellChunk(layerIndex, xPosition, yPosition, opacityLevel, cellType, linkedFramePosition)); } // + For cel type = 2(Compressed Image) else if (cellType == 2) { // WORD Width in pixels var width = reader.WORD(); // WORD Height in pixels var height = reader.WORD(); // BYTE[] "Raw Cel" data compressed with ZLIB method var depthModifier = 0; if (colorDepth == ColorDepth.RGBA) { depthModifier = 4; } else if (colorDepth == ColorDepth.Grayscale) { depthModifier = 2; } else if (colorDepth == ColorDepth.Indexed) { depthModifier = 1; } var count = width * height * depthModifier; var pixels = new byte[count]; reader.DEFLATE(pixels); return(new CellChunk(layerIndex, xPosition, yPosition, opacityLevel, cellType, width, height, pixels)); } else { return(new CellChunk(layerIndex, xPosition, yPosition, opacityLevel, cellType)); } }