HdrImage.fromImage constructor

HdrImage.fromImage(
  1. Image other, {
  2. int type = FLOAT,
  3. int bitsPerSample = 16,
})

Create an HDR image from a LDR Image by transforming the channel values to the range 0, 1.

Implementation

HdrImage.fromImage(Image other, {int type = FLOAT, int bitsPerSample = 16}) {
  addSlice(HdrSlice(R, other.width, other.height, type, bitsPerSample));
  addSlice(HdrSlice(G, other.width, other.height, type, bitsPerSample));
  addSlice(HdrSlice(B, other.width, other.height, type, bitsPerSample));
  if (other.channels == Channels.rgba) {
    addSlice(HdrSlice(A, other.width, other.height, type, bitsPerSample));
  }
  final rgb = other.getBytes();
  for (var y = 0, si = 0; y < other.height; ++y) {
    for (var x = 0; x < other.width; ++x) {
      red!.setFloat(x, y, rgb[si++] / 255.0);
      green!.setFloat(x, y, rgb[si++] / 255.0);
      blue!.setFloat(x, y, rgb[si++] / 255.0);
      if (alpha != null) {
        alpha!.setFloat(x, y, rgb[si++] / 255.0);
      }
    }
  }
}