Sample code – Sensoray 2246 User Manual
Page 50
Sample code
See 2246demo code
Setting Custom Merge Method for interlace reconstruction
First set the merge method:
SN_SetMergeMethod( MID2246_FIELDALG_CUST, (mergefunc_t ) custmerge_fields);
Where custmerge_fields follows the mergefunc_t declaration. Finally, define a merge function. Two
examples of a custom merge algorithm are shown below:
/** merge fields
* @param newf pointer to allocated space for new field
* @param size size of newf
* @param f0 pointer to field 0
* @param h0 height of field 0
* @param f1 pointer to field 1 (may be unused in some cases)
* @param h1 height of field 1 (may be unused in some cases)
* @param w width of fields in bytes
* @param pRetW pointer to image width (in Pixels). Modify this to a new value if
* the returned image width is different. Initial value *pRetW = w/3
* @param pRetH pointer to image height. Modify this to a new value if
* the returned image height is different. Initial value *pRetH = h0 + h1
* @return 0 on success, -1 otherwise
*/
int
custmerge_fields( BYTE *newf,
int
size, BYTE *f0,
int
h0, BYTE *f1,
int
h1,
int
w,
int
*pRetW,
int
*pRetH)
{
int
i,j,h;
j = 0;
h = (h0 < h1) ? h0 : h1;
for
( i=0; i< h; i++, j+=2) {
memcpy( newf + j*w, &f0[i*w], w);
memcpy( newf + (j+1)*w, &f1[i*w], w);
}
return
0;
}
int
custmerge_fields_with_clip( BYTE *newf,
int
size, BYTE *f0,
int
h0, BYTE *f1,
int
h1,
int
w,
int
*pRetW,
int
*pRetH)
{
int
i,h,h;
int
TrimXLeft = 4; // Require Trimxxx to be multiples of 2
int
TrimXRight = 8; // to make line calculations easier.
int
TrimYTop = 4;
int
TrimYBottom = 6;
int
TotalLines;
i = TrimYTop/2;
h = (h0 < h1) ? h0 : h1;
TotalLines = 2*(h - ((TrimYTop+TrimYBottom)/2));
for
( j=0; j < TotalLines; i++, j+=2) {
memcpy( newf + ( j *(w - 3*(TrimXLeft+TrimXRight))) ,
&f0[(i*w) + (3*TrimXLeft)],
w - (3*(TrimXLeft+TrimXRight)) ); // 3 bytes per pixel
memcpy( newf + ((j+1)*(w - 3*(TrimXLeft+TrimXRight))) ,
&f1[(i*w) + (3*TrimXLeft)],
w - (3*(TrimXLeft+TrimXRight)) ); // 3 bytes per pixel
}
*pRetW = *pRetW - (TrimXLeft+TrimXRight); // In pixels
*pRetH = TotalLines; // In pixels
return
0;
}
NOTE: The size of BYTE *newf buffer set by size parameter in SN_SnapshotToMem() or CustMergeSize
parameter in SN_SnapshotToFile()
50