SkJpegSegmentScanner: Use state-machine based scan

Separate what had previously been SkJpegSegmentScan into two classes.

The first is SkJpegSegmentScanner. This is a state machine that is
fed bytes and tracks the JPEG segment structure of the data that has
been provided to it. This should be significantly more efficient than
the previous scanning structure, because it does not do any stream
operations itself.

The second is SkJpegSeekableScan. This is created from a seekable
SkStream. It uses SkJpegSegmentScanner to determine the JPEG segment
structure of the data, and provides utility functions for retrieving
parameters and sub-streams.

This is towards supporting decoding JpegR gainmaps from unseekable
and unrewindable streams.

Bug: skia:14031
Change-Id: Icdb36dae6c3bbb2e282ade1cd5469e171d7e8001
Commit-Queue: Christopher Cameron <>
Reviewed-by: Brian Osman <>
6 files changed