readInfo method

JpegInfo? readInfo(
  1. List<int> bytes
)

Implementation

JpegInfo? readInfo(List<int> bytes) {
  input = InputBuffer(bytes, bigEndian: true);

  var marker = _nextMarker();
  if (marker != Jpeg.M_SOI) {
    return null;
  }

  final info = JpegInfo();

  var hasSOF = false;
  var hasSOS = false;

  marker = _nextMarker();
  while (marker != Jpeg.M_EOI && !input.isEOS) {
    // EOI (End of image)
    switch (marker) {
      case Jpeg.M_SOF0: // SOF0 (Start of Frame, Baseline DCT)
      case Jpeg.M_SOF1: // SOF1 (Start of Frame, Extended DCT)
      case Jpeg.M_SOF2: // SOF2 (Start of Frame, Progressive DCT)
        hasSOF = true;
        _readFrame(marker, _readBlock());
        break;
      case Jpeg.M_SOS: // SOS (Start of Scan)
        hasSOS = true;
        _skipBlock();
        break;
      default:
        _skipBlock();
        break;
    }

    marker = _nextMarker();
  }

  if (frame != null) {
    info.width = frame!.samplesPerLine!;
    info.height = frame!.scanLines!;
  }
  frame = null;
  frames.clear();

  return (hasSOF && hasSOS) ? info : null;
}