jpeg2000: Refactor decode_packets