# Smart Image Tools - Custom APNG Format Documentation ## Format Overview The Smart Image Tools custom APNG (Animated PNG) format is a simple binary container format that stores a sequence of PNG images along with timing information. This format is designed to be easy to read and write, while maintaining the full quality of each individual PNG frame. Unlike standard APNG files that follow the PNG specification extensions, this custom format uses a simpler structure optimized for storing image sequences created with ComfyUI. ## File Structure The file consists of a header followed by a sequence of frame blocks: ``` [Header] [Frame 1] [Frame 2] ... [Frame N] ``` ### Header Structure (8 bytes total) - Bytes 0-3: Total number of frames (4-byte signed integer, little-endian) - Bytes 4-7: FPS value multiplied by 100 (4-byte signed integer, little-endian) - FPS is multiplied by 100 to store decimal precision without using floating point ### Frame Block Structure (variable length) Each frame block has the following structure: - Bytes 0-3: Length of the PNG data in bytes (4-byte signed integer, little-endian) - Bytes 4-(4+length-1): Raw PNG file data Frames are stored sequentially, with each frame's data directly following the previous frame's data. ## Reading the Format To read this format: 1. Read the first 8 bytes to get frame count and FPS 2. For each frame: a. Read 4 bytes to get the PNG data length b. Read that many bytes to get the PNG data c. Decode the PNG data using any standard PNG decoder d. Repeat until all frames are read Sample pseudocode for reading: ```python def read_apng_file(file_path): with open(file_path, 'rb') as f: # Read header frame_count = struct.unpack('