static List<Integer> getIntervalStartPositions(final int[] scanPayload) {
        final List<Integer> intervalStarts = new ArrayList<>();
        intervalStarts.add(0);
        boolean foundFF = false;
        boolean foundD0toD7 = false;
        int pos = 0;
        while (pos < scanPayload.length) {
            if (foundFF) {
                // found 0xFF D0 .. 0xFF D7 => RST marker
                if (scanPayload[pos] >= (0xff & JpegConstants.RST0_MARKER) && scanPayload[pos] <= (0xff & JpegConstants.RST7_MARKER)) {
                    foundD0toD7 = true;
                } else { // found 0xFF followed by something else => no RST marker
                    foundFF = false;
                }
            }

            if (scanPayload[pos] == 0xFF) {
                foundFF = true;
            }

            // true if one of the RST markers was found
            if (foundFF && foundD0toD7) {
                // we need to add the position after the current position because
                // we had already read 0xFF and are now at 0xDn
                intervalStarts.add(pos + 1);
                foundFF = foundD0toD7 = false;
            }
            pos++;
        }
        return intervalStarts;
    }
Returns the positions of where each interval in the provided array starts. The number of start positions is also the count of intervals while the number
of restart markers found is equal to the number of start positions minus one (because restart markers are between intervals).

@param scanPayload array to examine
@return the start positions
src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java