In other words, if you expect your final image data to start with the byte '255', and you have a scanline filter of 1 (sub), then your next byte should be a 1. (0 minus 1 -> modulo 256 -> 255)

Not quite.

For the first byte, you can just write the raw value. The equation is (curr - prev), and x < 0 is defined as 0. So filtering with the PNG subtraction filter would give 255 - 0, mod 256, which is still 255. So byte 1 would be "1" for sub filter, and byte 2 would be "255".

Oops, you're right. I read the encoding and decoding parts backwards. Decoding *adds* the previously decoded byte (zero if there is no previous value) with the current byte, so the first filtered byte using the Sub filter is effectively the same before/after encoding/decoding.