AcademySoftwareFoundation / OpenColorIO

A color management framework for visual effects and animation.
https://opencolorio.org
BSD 3-Clause "New" or "Revised" License
1.8k stars 456 forks source link

ApplyRGB should honor Numpy internal matrix storage order #2075

Open doug-walker opened 1 month ago

doug-walker commented 1 month ago

Numpy matrices may be stored in either row-major or column-major order. The user is typically not aware of the order being used, especially since some Numpy operators swap the order if it is more efficient for them. For example, transpose simply swaps the ordering flag rather than moving numeric values.

The applyRGB function in OCIO essentially just flattens the input and expects channel-interleaved ordering. Ideally, applyRGB would check the storage order and transpose values, if needed. At a minimum, it should issue a warning if the storage order is not as expected.

nick-shaw commented 1 month ago

The flags property of a NumPy array shows the storage order.

  C_CONTIGUOUS : True
  F_CONTIGUOUS : False
  OWNDATA : False
  WRITEABLE : True
  ALIGNED : True
  WRITEBACKIFCOPY : False

Currently applyRGB() will only work correctly if C_CONTIGUOUS is True.

KelSolaar commented 1 month ago

Easiest is wrapping the array with np.ascontiguousarray before using ApplyRGB. I modified Colour for now with this.