ExrImage constructor

ExrImage(
  1. List<int> bytes
)

Implementation

ExrImage(List<int> bytes) {
  final input = InputBuffer(bytes);
  final magic = input.readUint32();
  if (magic != MAGIC) {
    throw ImageException('File is not an OpenEXR image file.');
  }

  version = input.readByte();
  if (version != EXR_VERSION) {
    throw ImageException('Cannot read version $version image files.');
  }

  flags = input.readUint24();
  if (!_supportsFlags(flags)) {
    throw ImageException('The file format version number\'s flag field '
        'contains unrecognized flags.');
  }

  if (!_isMultiPart()) {
    final ExrPart part = InternalExrPart(_isTiled(), input);
    if (part.isValid) {
      _parts.add(part as InternalExrPart);
    }
  } else {
    while (true) {
      final ExrPart part = InternalExrPart(_isTiled(), input);
      if (!part.isValid) {
        break;
      }
      _parts.add(part as InternalExrPart);
    }
  }

  if (_parts.isEmpty) {
    throw ImageException('Error reading image header');
  }

  for (var part in _parts) {
    part.readOffsets(input);
  }

  _readImage(input);
}