13#ifndef ML_SCALE_SHIFT_DATA_H
14#define ML_SCALE_SHIFT_DATA_H
67 ReorderColorPlanesToInterleaved = 1
77 : _scale(static_cast<DT>(1)),
78 _shift(static_cast<DT>(0)),
79 _reorderMode(NoReordering)
87 _reorderMode(ssd._reorderMode)
93 inline TScaleShiftData(DT scale, DT shift) : _scale(scale), _shift(shift) , _reorderMode(NoReordering)
108 :_reorderMode(NoReordering)
110 setFromMinMaxToMinMax(fromMin, fromMax, toMin, toMax);
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);
286 _reorderMode = NoReordering;
321 ReorderMode _reorderMode;
337 inline ostream&
operator<<(ostream& s,
const ML_NAMESPACE::ScaleShiftData &ssd)
339 return s <<
"Scale=" << ssd.getScale() <<
", Shift=" << ssd.getShift();
Class to define a first order linear transformation.
TScaleShiftData()
Default constructor, i.e., builds identity transformation.
void setReorderMode(ReorderMode mode)
Set the reorder mode.
TScaleShiftData(DT fromMin, DT fromMax, DT toMin, DT toMax)
Values from interval [fromMin, fromMax] are transformed linearly into [toMin, 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 scale constant from transformation y=scale*x+offset.
TScaleShiftData(const TScaleShiftData< DT > &ssd)
Copy constructor.
void setFromMinMaxToMinMax(DT fromMin, DT fromMax, DT toMin, DT toMax)
Values from interval [fromMin, fromMax] are transformed linearly into [toMin, toMax].
void setScaleOffset(DT scale, DT shift)
Sets scale and shift: values are multiplied with scale and then shift is added.
void setFromMinMaxToMinMax(MLDataType fromType, DT fromMin, DT fromMax, MLDataType toType, DT toMin, DT toMax)
Values from interval [fromMin, fromMax] are transformed linearly into [toMin, toMax].
ReorderMode getReorderMode() const
Get the reorder mode.
bool operator==(const TScaleShiftData< DT > &ssd) const
Returns true if all members are equal.
void unset()
Sets default, i.e., identity transformation.
ReorderMode
Mode that indicates if copySubImage should reorder the color from planes (from x,y,...
TScaleShiftData(DT scale, DT shift)
Constructor: Sets scale and shift to define a transformation so that a scaled value v' is v' = v*scal...
DT getShift() const
Returns addition constant shift from transformation y=scale*x+shift.
MLint32 MLDataType
MLDataType.
MLEXPORT MLint32 MLIsIntType(MLDataType dataType)
Returns true(=1) if data type dataType is an integer data type, otherwise false(=0).
bool MLValuesAreEqualWOM(MLint8 a, MLint8 b)
Returns true if values a and b are equal, otherwise false.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator "<<" for stream output of Field objects.