+ uint8_t *bs = pnmctx.bytestream;
+ const uint8_t *end = pnmctx.bytestream_end;
+ uint8_t *sync = bs;
+
+ if (pc->index) {
+ av_assert0(pnmpc->ascii_scan <= end - bs);
+ bs += pnmpc->ascii_scan;
+ }
+
+ while (bs < end) {
+ int c;
+ sync = bs;
+ c = *bs++;
+ if (c == '#') {
+ uint8_t *match = memchr(bs, '\n', end-bs);
+ if (match)
+ bs = match + 1;
+ else
+ break;
+ } else if (c == 'P') {
+ next = bs - pnmctx.bytestream_start + skip - 1;
+ pnmpc->ascii_scan = 0;
+ break;
+ }
+ }
+ if (next == END_NOT_FOUND)
+ pnmpc->ascii_scan = sync - pnmctx.bytestream + skip;