YUVScalingAdaptor Class Reference

Implementation of Adaptor that applies spatial transformation on YUVFrame objects. Up- and downscaling is implemented using SDL. More...

#include <YUVScalingAdaptor.hpp>

Inheritance diagram for YUVScalingAdaptor:

VideoAdaptor Adaptor List of all members.

Public Member Functions

 YUVScalingAdaptor (VideoESInfo *pESInfo, u32 width, u32 height)
 Constructor.
list< Frame * > adapt (Frame *frm)
 YUVFrame frm in - list of YUVFrame objects out.
list< Frame * > close ()
 Flush all buffered YUVFrame objects (if any).
Adaptorclone ()
 Not implemented.
void initialize ()
 Initialize internal data structures.
u32 getTranscodingCosts () const
 returns adaptation costs (CPU only) YUVscaling is expensive, nearly twice as much as encoding!

Detailed Description

Implementation of Adaptor that applies spatial transformation on YUVFrame objects. Up- and downscaling is implemented using SDL.

Author:
Bernhard Penz and Michael Kropfberger
Version:
Id
YUVScalingAdaptor.hpp,v 1.4 2004/09/06 08:48:09 pschojer Exp

Definition at line 61 of file YUVScalingAdaptor.hpp.


Constructor & Destructor Documentation

YUVScalingAdaptor::YUVScalingAdaptor VideoESInfo *  pESInfo,
u32  width,
u32  height
 

Constructor.

Takes input frame size from pESInfo, and sets arbitrary output frame size according to puiWidth/puiHeight.

Parameters:
pESInfo Pointer to ESInfo object, containing valid size information about the input YUVFrame objects.
width Pointer to target width of output YUVFrame objects.
height Pointer to target height of output YUVFrame objects.
Definition at line 51 of file YUVScalingAdaptor.cpp.

References initialize().

Referenced by clone().

00054 { 00055 es = pESInfo; 00056 initialized = false; 00057 muiTargetWidth = width; 00058 muiTargetHeight = height; 00059 strcpy(name,"YUVScalingAdaptor"); 00060 initialize(); 00061 }


Member Function Documentation

list< Frame * > YUVScalingAdaptor::adapt Frame frm  )  [virtual]
 

YUVFrame frm in - list of YUVFrame objects out.

Output list will contain one YUVFrame object only. If the incoming frm has already the correct size, no scaling is done

Parameters:
frm Pointer to uncompressed YUVFrame object
Returns:
List of YUVFrame objects

Reimplemented from Adaptor.

Definition at line 91 of file YUVScalingAdaptor.cpp.

References Frame::getAU(), VideoFrame::getHeight(), Frame::getType(), VideoFrame::getWidth(), initialize(), VideoFrame::setHeight(), and VideoFrame::setWidth().

00091 { 00092 list < Frame * >retFrameList; 00093 UncompressedVideoFrame* ufrm = (UncompressedVideoFrame*)frm; 00094 00095 if ( ((u32)ufrm->getWidth() != muiWidth) 00096 || ((u32)ufrm->getHeight() != muiHeight) ) { 00097 //resolution has changed because of stream switching 00098 initialize(); 00099 } 00100 00101 if (ufrm->getType() != Frame::YUV_VOP) { 00102 dprintf_err("YUVScalingAdaptor::adapt does only support YUV frames!\n"); 00103 ::exit(1); 00104 } 00105 00106 //to be save on switching, always set ES dimensions 00107 //not anymore: FIXME: this should go into the out_es (all ViTooKi Adaptors should have this....) 00108 // es->setWidth(muiTargetWidth); 00109 //es->setHeight(muiTargetHeight); 00110 00111 dprintf_full("YUVScalingAdaptor::adapt %ix%i --> %ix%i\n", muiWidth,muiHeight,muiTargetWidth,muiTargetHeight); 00112 00113 if ( (muiWidth == muiTargetWidth) && (muiHeight == muiTargetHeight) ) { 00114 retFrameList.push_back(frm); //same size, so leave untouched 00115 return retFrameList; 00116 } 00117 00118 u32 h, w, hOrig, wOrig; 00119 u8 *pOffsetTarget=NULL; 00120 u8 *pOffsetOrig=NULL; 00121 00122 u8 *origFrame = frm->getAU()->payload; 00123 pOffsetOrig = origFrame; 00124 00125 00126 u8 *retFrame = new u8[muiTargetWidth * muiTargetHeight * 3 / 2]; 00127 // memset(retFrame, 128, muiTargetWidth * muiTargetHeight * 3 / 2); 00128 pOffsetTarget = retFrame; 00129 00130 00131 // Y 00132 for (h = 0; h < muiTargetHeight; h++) { 00133 for (w = 0; w < muiTargetWidth; w++) { 00134 hOrig = (u32) ((h * 1000000) / muiScaleFactorHeight); 00135 wOrig = (u32) ((w * 1000000) / muiScaleFactorWidth); 00136 pOffsetTarget[h * muiTargetWidth + w] = pOffsetOrig[hOrig * muiWidth + wOrig]; 00137 } 00138 } 00139 // V 00140 pOffsetOrig = pOffsetOrig + muiWidth * muiHeight; 00141 pOffsetTarget = pOffsetTarget + muiTargetWidth * muiTargetHeight; 00142 for (h = 0; h < muiTargetHeight / 2; h++) { 00143 for (w = 0; w < muiTargetWidth / 2; w++) { 00144 hOrig = (u32) ((h * 1000000) / muiScaleFactorHeight); 00145 wOrig = (u32) ((w * 1000000) / muiScaleFactorWidth); 00146 pOffsetTarget[h * muiTargetWidth / 2 + w] = pOffsetOrig[hOrig * muiWidth / 2 + wOrig]; 00147 } 00148 } 00149 // U 00150 pOffsetOrig = pOffsetOrig + muiWidth * muiHeight / 4; 00151 pOffsetTarget = pOffsetTarget + muiTargetWidth * muiTargetHeight / 4; 00152 for (h = 0; h < muiTargetHeight / 2; h++) { 00153 for (w = 0; w < muiTargetWidth / 2; w++) { 00154 hOrig = (u32) ((h * 1000000) / muiScaleFactorHeight); 00155 wOrig = (u32) ((w * 1000000) / muiScaleFactorWidth); 00156 pOffsetTarget[h * muiTargetWidth / 2 + w] = pOffsetOrig[hOrig * muiWidth / 2 + wOrig]; 00157 } 00158 } 00159 00160 ufrm->setWidth(muiTargetWidth); 00161 ufrm->setHeight(muiTargetHeight); 00162 frm->getAU()->payload = retFrame; 00163 frm->getAU()->size = muiTargetWidth * muiTargetHeight * 3 / 2; // YV12 00164 retFrameList.push_back(frm); 00165 delete origFrame; // not needed any more 00166 00167 return retFrameList; 00168 }

Adaptor * YUVScalingAdaptor::clone  )  [virtual]
 

Not implemented.

Returns:
Defaults to NULL.

Implements Adaptor.

Definition at line 181 of file YUVScalingAdaptor.cpp.

References YUVScalingAdaptor().

00181 { 00182 return new YUVScalingAdaptor(es,muiTargetWidth,muiTargetHeight); 00183 }

list< Frame * > YUVScalingAdaptor::close  )  [virtual]
 

Flush all buffered YUVFrame objects (if any).

Returns:
List of YUVFrame objects

Reimplemented from Adaptor.

Definition at line 172 of file YUVScalingAdaptor.cpp.

00172 { 00173 list < Frame * >retFrameList; 00174 00175 return retFrameList; 00176 }

void YUVScalingAdaptor::initialize  )  [virtual]
 

Initialize internal data structures.

Implements Adaptor.

Definition at line 65 of file YUVScalingAdaptor.cpp.

Referenced by adapt(), and YUVScalingAdaptor().

00065 { 00066 00067 muiWidth = es->getWidth(); 00068 muiHeight = es->getHeight(); 00069 00070 00071 //FIXME: this should go into the out_es (all ViTooKi Adaptors should have this....) 00072 // es->setWidth(muiTargetWidth); 00073 //es->setHeight(muiTargetHeight); 00074 00075 muiScaleFactorWidth = (u32) ((muiTargetWidth * 1000000) / muiWidth) ; 00076 muiScaleFactorHeight = (u32)((muiTargetHeight* 1000000) / muiHeight) ; 00077 initialized = true; 00078 00079 dprintf_full("YUVScalingAdaptor::initialize %ix%i --> %ix%i Scalefactors [w|h]: [%i|%i]\n", 00080 muiWidth,muiHeight,muiTargetWidth,muiTargetHeight,muiScaleFactorWidth, muiScaleFactorHeight); 00081 }


The documentation for this class was generated from the following files: