calculate method

ImageDimension calculate ()

Calculate size for jpg file

Implementation

ImageDimension calculate() {
  int i;
  int next;

  if (!isJpg()) return null;

  // Skip 5 chars, they are for signature
  codeUnits = codeUnits.sublist(4);

  while (codeUnits.isNotEmpty) {
    // read length of the next block
    i = MoreList.readUInt16BE(codeUnits, 0);

    // ensure correct format
    if (!validateJpgBuffer(i)) return null;

    // 0xFFC0 is baseline(SOF)
    // 0xFFC2 is progressive(SOF2)
    next = codeUnits[i + 1];
    if (next == 192 || next == 194) return extractJpgSize(i + 5);

    // move to the next block
    codeUnits = codeUnits.sublist(i + 2);
  }
  return null;
}