【VC开源代码栏目提醒】:本文主要为网学会员提供grayi.cpp,希望对需要grayi.cpp网友有所帮助,学习一下!
/*************************************************************************
This software module was originally developed by
Ming-Chieh Lee (
grayi.cpp为[网学网-网友上传,谢谢支持]。), Microsoft Corporation
Wei-ge Chen (
grayi.cpp为[网学网-网友上传,谢谢支持]。), Microsoft Corporation
Bruce Lin (
grayi.cpp为[网学网-网友上传,谢谢支持]。), Microsoft Corporation
Chuang Gu (
grayi.cpp为[网学网-网友上传,谢谢支持]。), 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 standard> conforming products.
This copyright notice must be included in all copies or derivative works.
Copyright (c) 1996, 1997.
Module Name:
grayf.hpp
Abstract:
Float image class for gray (one-plane) pictures
Revision History:
*************************************************************************/
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "typeapi.h"
#ifdef __MFC_
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
#define new DEBUG_NEW
#endif // __MFC_
CIntImage::~CIntImage ()
{
delete [] m_ppxli;
m_ppxli = NULL;
}
Void CIntImage::allocate (const CRct& r, PixelI pxli)
{
m_rc = r;
delete [] m_ppxli, m_ppxli = NULL;
// allocate pixels and initialize
if (m_rc.empty ()) return;
m_ppxli = new PixelI [m_rc.area ()];
assert (m_ppxli);
for (UInt ic = 0; ic < where ().area (); ic++)
m_ppxli [ic] = pxli;
}
Void CIntImage::allocate (const CRct& r)
{
m_rc = r;
delete [] m_ppxli, m_ppxli = NULL;
// allocate pixels and initialize
if (m_rc.empty ()) return;
m_ppxli = new PixelI [m_rc.area ()];
assert (m_ppxli);
}
Void CIntImage::copyConstruct (const CIntImage& ii, const CRct& rct)
{
CRct r = rct;
if (!r.valid())
r = ii.where ();
if (!ii.valid () || (!ii.m_rc.empty () && ii.m_ppxli == NULL))
assert (FALSE);
allocate (r, (PixelI) 0);
if (!valid ()) return;
// Copy data
if (r == ii.where ())
memcpy (m_ppxli, ii.pixels (), m_rc.area () * sizeof (PixelI));
else {
r.clip (ii.where ()); // find the intersection
CoordI x = r.left; // copy pixels
Int cbLine = r.width * sizeof (PixelI);
PixelI* ppxl = (PixelI*) pixels (x, r.top);
const PixelI* ppxlFi = ii.pixels (x, r.top);
Int widthCurr = where ().width;
Int widthFi = ii.where ().width;
for (CoordI y = r.top; y < r.bottom; y++) {
memcpy (ppxl, ppxlFi, cbLine);
ppxl += widthCurr;
ppxlFi += widthFi;
}
}
}
Void CIntImage::swap (CIntImage& ii)
{
assert (this && &ii);
CRct rcT = ii.m_rc;
ii.m_rc = m_rc;
m_rc = rcT;
PixelI* ppxliT = ii.m_ppxli;
ii.m_ppxli = m_ppxli;
m_ppxli = ppxliT;
}
CIntImage::CIntImage (const CIntImage& ii, const CRct& r) : m_ppxli (NULL)
{
copyConstruct (ii, r);
}
CIntImage::CIntImage (const CRct& r, PixelI px) : m_ppxli (NULL)
{
allocate (r, px);
}
CIntImage::CIntImage (const CVideoObjectPlane& vop, RGBA comp) : m_ppxli (NULL)
{
if (!vop.valid ()) return;
allocate (vop.where ());
const CPixel* ppxl = vop.pixels ();
for (UInt ip = 0; ip < where ().area (); ip++)
m_ppxli [ip] = ppxl [ip].pxlU.color [comp];
}
CIntImage::CIntImage (
const Char* pchFileName,
UInt ifr,
const CRct& rct,
UInt nszHeader
) : m_ppxli (NULL), m_rc (rct)
{
assert (!rct.empty ());
allocate (rct);
UInt uiArea = rct.area ();
// read data from a file
FILE* fpSrc = fopen (pchFileName, "rb");
assert (fpSrc != NULL);
fseek (fpSrc, nszHeader + ifr * sizeof (U8) * uiArea, SEEK_SET);
for (UInt ip = 0; ip < uiArea; ip++)
m_ppxli [ip] = getc (fpSrc);
fclose (fpSrc);
}
CIntImage::CIntImage (const Char* vdlFileName) : m_ppxli (NULL)// read from a VM file.
{
CVideoObjectPlane vop (vdlFileName);
allocate (vop.where ());
const CPixel* ppxl = vop.pixels ();
for (UInt ip = 0; ip < where ().area (); ip++)
m_ppxli [ip] = ppxl [ip].pxlU.rgb.r;
}
Void CIntImage::where (const CRct& r)
{
if (!valid ()) return;
if (where () == r) return;
CIntImage* pii = new CIntImage (*this, r);
swap (*pii);
delete pii;
}
CRct CIntImage::boundingBox (const PixelI pxliOutsideColor) const
{
if (allValue ((PixelI) pxliOutsideColor))
return CRct ();
CoordI left = where ().right - 1;
CoordI top = where ().bottom - 1;
CoordI right = where ().left;
CoordI bottom = where ().top;
const PixelI* ppxliThis = pixels ();
for (CoordI y = where ().top; y < where ().bottom; y++) {
for (CoordI x = where ().left; x < where ().right; x++) {
if (*ppxliThis != (PixelI) pxliOutsideColor) {
left = min (left, x);
top = min (top, y);
right = max (right, x);
bottom = max (bottom, y);
}
ppxliThis++;
}
}
right++;
bottom++;
return (CRct (left, top, right, bottom));
}
Int CIntImage::mean () const
{
if (where ().empty ())
return 0;
Int meanRet = 0;
PixelI* ppxli = (PixelI*) pixels ();
UInt area = where ().area ();
for (UInt ip = 0; ip < area; ip++)
meanRet += ppxli [ip];
return (Int) (meanRet / area);
}
Int CIntImage::mean (const CIntImage* piiMsk) const
{
assert (where () == piiMsk -> where ()); // no compute if rects are different
if (where ().empty ()) return 0;
Int meanRet = 0;
PixelI* ppxli = (PixelI*) pixels ();
const PixelI* ppxliMsk = piiMsk -> pixels ();
UInt area = where ().area ();
UInt uiNumNonTransp = 0;
for (UInt ip = 0; ip < area; ip++) {
if (ppxliMsk [ip] != transpValue) {
uiNumNonTransp++;
meanRet += ppxli [ip];
}
}
return (Int) (meanRet / uiNumNonTransp);
}
Int CIntImage::sumAbs (const CRct& rct) const
{
CRct rctToDo = (!rct.valid ()) ? where () : rct;
Int intRet = 0;
if (rctToDo == where ()) {
const PixelI* ppxli = pixels ();
UInt area = where ().area ();
for (UInt ip = 0; ip < area; ip++, ppxli++)
intRet += (*ppxli);
}
else {
Int width = where ().width;
const PixelI* ppxliRow = pixels (rct.left, rct.top);
for (CoordI y = rctToDo.top; y < rctToDo.bottom; y++) {
const PixelI* ppxli = ppxliRow;
上一篇:
GrayHandle.cpp
下一篇:
法律专业开题报告范文