Upon finishing a row it might zero out a final buffer, zero out the temporary buffer, iterates over each pixel using helpers to colour-correct & either dither or quantize each pixel before bitpacking them, tells the ditherer if any that we're on a new row, & writes it out to the file. Or a variant might average adjacent pixels before applying similar logic to output the downsampled image.
There's an init callback which initializes its buffers & metadata from the image's metadata.
2/3!