【VC开源代码栏目提醒】:网学会员为广大网友收集整理了,typeapi.cpp,希望对大家有所帮助!
/*************************************************************************
This software module was originally developed by
Ming-Chieh Lee (mingcl@microsoft.com), Microsoft Corporation
Wei-ge Chen (wchen@microsoft.com), Microsoft Corporation
Bruce Lin (blin@microsoft.com), Microsoft Corporation
Chuang Gu (chuanggu@microsoft.com), Microsoft Corporation
(date: March, 1996)
in the course of development of the MPEG-4 Video (ISO/IEC 14496-2).
This software module is an implementation of a part of one or more MPEG-4 Video tools
as specified by the MPEG-4 Video.
ISO/IEC gives users of the MPEG-4 Video free license to this software module or modifications
thereof for use in hardware or software products claiming conformance to the MPEG-4 Video.
Those intending to use this software module in hardware or software products are advised that its use may infringe existing patents.
The original developer of this software module and his/her company,
the subsequent editors and their companies,
and ISO/IEC have no liability for use of this software module or modifications thereof in an implementation.
Copyright is not released for non MPEG-4 Video conforming products.
Microsoft retains full right to use the code for his/her own purpose,
assign or donate the code to a third party and to inhibit third parties from using the code for non MPEG-4 Video conforming products.
This copyright notice must be included in all copies or derivative works.
Copyright (c) 1996, 1997.
Module Name:
typeapi.cpp
Abstract:
Glue for TYPE called from elsewhere
Revision History:
NOTE: CALLER OWNS ALL THE RETURNED POINTERS!!
*************************************************************************/
#include "typeapi.h"
#include <stdlib.h>
#include <math.h>
#ifdef __MFC_
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
#define new DEBUG_NEW
#endif // __MFC_
// handy functions
Int nint (Double x) // returns nearest integer to x, analog of FORTRAN NINT
{
return x > 0 ? (Int) (x + .5) : (Int) (x - .5);
}
#ifndef __DOUBLE_PRECISION_
Double checkrange (Double x, Double cMin, Double cMax) // returns cMin if x < cMin, cMax if x > cMax, otherwise x
{
if (x < cMin) return cMin;
if (x > cMax) return cMax;
return x;
}
#endif // __DOUBLE_PRECISION_
U8 checkrangeU8 (U8 x, U8 cMin, U8 cMax) // returns cMin if x < cMin, cMax if x > cMax, otherwise x
{
if (x < cMin) return cMin;
if (x > cMax) return cMax;
return x;
}
// NBIT: add checkrange for U16
unsigned char checkrange (unsigned char x, unsigned char cMin, unsigned char cMax) // returns cMin if x < cMin, cMax if x > cMax, otherwise x
{
if (x < cMin) return cMin;
if (x > cMax) return cMax;
return x;
}
U16 checkrange (U16 x, U16 cMin, U16 cMax) // returns cMin if x < cMin, cMax if x > cMax, otherwise x
{
if (x < cMin) return cMin;
if (x > cMax) return cMax;
return x;
}
Int checkrange (Int x, Int cMin, Int cMax) // returns cMin if x < cMin, cMax if x > cMax, otherwise x
{
if (x < cMin) return cMin;
if (x > cMax) return cMax;
return x;
}
Long checkrange (Long x, Long cMin, Long cMax) // returns cMin if x < cMin, cMax if x > cMax, otherwise x
{
if (x < cMin) return cMin;
if (x > cMax) return cMax;
return x;
}
Float checkrange (Float x, Float cMin, Float cMax) // returns cMin if x < cMin, cMax if x > cMax, otherwise x
{
if (x < cMin) return cMin;
if (x > cMax) return cMax;
return x;
}
Double dist (Double x0, Double y0, Double x1, Double y1) // returns distance between (x0,y0) and (x1,y1)
{
Double dx = x0 - x1;
Double dy = y0 - y1;
return sqrt (dx * dx + dy * dy);
}
// handy numerical functions
Int sad (const CIntImage& fi0, const CIntImage& fi1, const CIntImage& fiMsk)
{
assert (fi0.where () == fi1.where ());
const UInt area = fi0.where ().area ();
const PixelI* ppxlf0 = fi0.pixels ();
const PixelI* ppxlf1 = fi1.pixels ();
const PixelI* ppxlfMsk = fiMsk.pixels ();
Int sadRet = 0;
for (UInt ip = 0; ip < area; ip++, ppxlf0++, ppxlf1++, ppxlfMsk++) {
if (*ppxlfMsk != (PixelI) transpValue)
sadRet += abs (*ppxlf0 - *ppxlf1);
}
return sadRet;
}
Void mse (const CVideoObjectPlane& vop1, const CVideoObjectPlane& vop2, Double dmse [3])
{
assert (vop1.where () == vop2.where ());
Int sqrR = 0, sqrG = 0, sqrB = 0;
const CPixel* ppxlVopThis = vop1.pixels ();
const CPixel* ppxlVopCompare = vop2.pixels ();
UInt area = vop1.where ().area ();
for (UInt i = 0; i < area; i++) {
Int diffR = ppxlVopThis -> pxlU.rgb.r - ppxlVopCompare -> pxlU.rgb.r;
Int diffG = ppxlVopThis -> pxlU.rgb.g - ppxlVopCompare -> pxlU.rgb.g;