Note that on each iteration you do two reads instead of just one.  If this function has to read through the long image data segments, then it should be as fast as possible.  You can double the speed by having a boolean that indicates whether the last byte was 0xff.