13#ifndef ML_SCALE_SHIFT_DATA_H
14#define ML_SCALE_SHIFT_DATA_H
77 : _scale(static_cast<DT>(1)),
78 _shift(static_cast<DT>(0)),
87 _reorderMode(ssd._reorderMode)
125 _reorderMode = ssd._reorderMode;
147 return !(*
this == ssd);
177 if (toMin > toMax) { std::swap(toMin, toMax); }
178 if (fromMin > fromMax) { std::swap(fromMin, fromMax); }
179 DT srcWidth = fromMax-fromMin;
181 _scale = (toMax - toMin) / srcWidth;
182 _shift = -fromMin * _scale + toMin;
190 _scale =
static_cast<DT
>(1);
191 _shift = toMin - fromMin;
236 if (toMin > toMax) { std::swap(toMin, toMax); }
237 if (fromMin > fromMax) { std::swap(fromMin, fromMax); }
238 DT srcWidth = fromMax-fromMin;
239 DT destWidth = toMax-toMin;
243 if (!fromTypeIsInt) {
248 }
else if (srcWidth > destWidth) {
267 _scale = destWidth / srcWidth;
268 _shift = -fromMin * _scale + toMin;
276 _scale =
static_cast<DT
>(1);
277 _shift = toMin - fromMin;
284 _scale =
static_cast<DT
>(1);
285 _shift =
static_cast<DT
>(0);
321 ReorderMode _reorderMode;
337 inline ostream&
operator<<(ostream& s,
const ML_NAMESPACE::ScaleShiftData &ssd)
339 return s <<
"Scale=" << ssd.getScale() <<
", Shift=" << ssd.getShift();
TScaleShiftData()
Default constructor, i.e., builds identity transformation.
void setReorderMode(ReorderMode mode)
Sets the reorder mode.
TScaleShiftData(DT fromMin, DT fromMax, DT toMin, DT toMax)
TScaleShiftData & operator=(const TScaleShiftData< DT > &ssd)
Assignment operator from an existing object to get an identical copy.
bool operator!=(const TScaleShiftData< DT > &ssd) const
Returns true if any members differ.
DT getScale() const
Returns the scale constant of the transformation y=scale*x+offset.
TScaleShiftData(const TScaleShiftData< DT > &ssd)
Copy constructor.
void setFromMinMaxToMinMax(MLdouble fromMin, MLdouble fromMax, MLdouble toMin, MLdouble toMax)
void setScaleOffset(DT scale, DT shift)
void setFromMinMaxToMinMax(MLDataType fromType, DT fromMin, DT fromMax, MLDataType toType, DT toMin, DT toMax)
ReorderMode getReorderMode() const
Returns the reorder mode.
bool operator==(const TScaleShiftData< DT > &ssd) const
Returns true if all members are equal.
void unset()
Sets the default, i.e., identity transformation.
@ ReorderColorPlanesToInterleaved
TScaleShiftData(DT scale, DT shift)
DT getShift() const
Returns the addition constant of the transformation y=scale*x+shift.
MLEXPORT MLint32 MLIsIntType(MLDataType dataType)
bool MLValuesAreEqualWOM(MLint8 a, MLint8 b)
TScaleShiftData< MLdouble > ScaleShiftData
Double version of TScaleShiftData for maximum reasonable precision.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator '<<' for stream output of Field objects.