# Warping Functionality

The Warping Library supports the following functionality:

<div class="contents" id="bkmrk-warp-matrix-computat"><div class="contents"><div class="textblock">- Warp matrix computation
- Warp matrix adjustment
- Reference Point Shift Vector encoding and retrieval
- Warp image bounds computation

</div></div></div>---

#### Warp Matrix Computation

##### Input:  


<div class="contents" id="bkmrk-shift-vectors-config"><div class="contents"><div class="textblock">- Shift Vectors
- Configuration information (please refer to <span style="color: rgb(230, 126, 35);">[Configuration of warping parameters](https://doc316en.candera.eu/link/423#bkmrk-page-title)</span>)

</div></div></div>##### Output:  


<div class="contents" id="bkmrk-warp-matrix"><div class="contents"><div class="textblock">- Warp Matrix

</div></div></div>##### Algorithm:  


<div class="contents" id="bkmrk-decode-and-cache-the"><div class="contents"><div class="textblock">- Decode and cache the reference point shift vectors.
- Computation of warp matrix from reference points and corresponding shift vectors. The reference points are distributed over the whole bitmap area according to the specifications in the parameter list.
- Rotation of warp matrix. The rotation of the warped reference points take place aroung the center point of the warped bitmap. (please refer to [<span style="color: rgb(230, 126, 35);">Rotation and Scale</span>](https://doc316en.candera.eu/link/447#bkmrk-page-title))
- Scaling of warp matrix to illuminated area, if outside of illuminated area. (please refer to [<span style="color: rgb(230, 126, 35);">Rotation and Scale</span>](https://doc316en.candera.eu/link/447#bkmrk-page-title))
- Normalize of warp matrix. <span style="color: rgb(230, 126, 35);">[Candera](http://dev.doc.cgistudio.at/APILINK/namespace_candera.html "[DataBinding_RefTypeSample]")</span> uses normalized coordinates in range \[0..1\] for rendering, therefore the warp matrix data has to be normalized in this range.

</div></div></div>##### Interface:

CalculateWarpMatrix(const stc\_warp\_configuration\_parameter\_t\* const pstcWarpConfigParams, const stc\_warp\_parameter\_set\_t\* const pstcWarpRefPoints, stc\_warp\_matrix\_t\* pstcWarpMatrix)

---

#### Warp Matrix Adjustment

##### Input:  


<div class="contents" id="bkmrk-configuration-inform"><div class="contents"><div class="textblock">- Configuration information.
- Adjustment configuration (please refer to [<span style="color: rgb(230, 126, 35);">Adjustments</span>](https://doc316en.candera.eu/link/427#bkmrk-page-title))<span style="color: rgb(230, 126, 35);">.</span>

</div></div></div>##### Output:  


<div class="contents" id="bkmrk-warp-matrix-0"><div class="contents"><div class="textblock">- Warp Matrix

</div></div></div>##### Algorithm:  


<div class="contents" id="bkmrk-adjustment-of-refere"><div class="contents"><div class="textblock">- Adjustment of reference point shift vectors according to the specified adjustment configuration structure using the according mathematical formulas.
- Computation of warp matrix from reference points and corresponding shift vectors.
- Rotation of warp matrix.
- Scaling of warp matrix to illuminated area, if outside of illuminated area.
- Normalize of warp matrix.

</div></div></div>##### Interface:

AdjustWarpMatrix(const stc\_warp\_configuration\_parameter\_t\* const pstcWarpConfigParams, const stc\_warp\_adjust\_parameter\_t\* const pstcWarpAdjustParams, en\_warp\_bool\_t\* pbRefPointsChanged, stc\_warp\_matrix\_t\* pstcWarpMatrix)

---

#### Reference Points Encoding and Retrieval

##### Input:  


<div class="contents" id="bkmrk-internally-cached-co"><div class="contents"><div class="textblock">- Internally cached configuration
- Internally cached shift vectors

</div></div></div>##### Output:  


<div class="contents" id="bkmrk-encoded-bitmap-image"><div class="contents"><div class="textblock">- Encoded bitmap image shift vectors

</div></div></div>##### Algorithm:  


<div class="contents" id="bkmrk-encode-shift-vectors"><div class="contents"><div class="textblock">- Encode shift vectors.
- Write shift vectors to application supplied memory location.

</div></div></div>The current active reference point shift vector set is retrieved from the warping library. Shift vectors are encoded according to the provided configuration.

##### Interface:

GetRefPoints(stc\_warp\_parameter\_set\_t\* pstcWarpRefPoints)

---

#### Warp Image Bounds Computation

##### Input:  


<div class="contents" id="bkmrk-configuration-inform-0"><div class="contents"><div class="textblock">- Configuration information.

</div></div></div>##### Output:  


<div class="contents" id="bkmrk-bitmap-image-area-bo"><div class="contents"><div class="textblock">- Bitmap image area bounds in normalized coordinates

</div></div></div>##### Algorithm:  


<div class="contents" id="bkmrk-calculate-area-bound"><div class="contents"><div class="textblock">- Calculate area bounds based on the provided configuration information: 
    - x = (bitmapAreaShiftX - bitmapAreaX/2) / displaySizeX
    - y = (bitmapAreaShiftY - bitmapAreaY/2) / displaySizeY
    - width = bitmapAreaX / displaySizeX
    - height = bitmapAreaY / displaySizeY

</div></div></div>The image area bounds are normalized as required by <span style="color: rgb(230, 126, 35);">[Candera](http://dev.doc.cgistudio.at/APILINK/namespace_candera.html "[DataBinding_RefTypeSample]")</span>, as it uses normalized coordinates in range \[0..1\] for rendering.

##### Interface:

ComputeWarpImageBoundsFromConfig(stc\_warp\_configuration\_parameter\_t\* config, WRP\_SFLOAT\* x, WRP\_SFLOAT\* y, WRP\_SFLOAT\* width, WRP\_SFLOAT\* height)

---