Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members
YUVSpatialReductionAdaptor.cpp
00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: YUVSpatialReductionAdaptor.cpp * 00006 * * 00007 * * 00008 * * 00009 * ITEC institute of the University of Klagenfurt (Austria) * 00010 * http://www.itec.uni-klu.ac.at * 00011 * * 00012 * * 00013 * For more information visit the ViTooKi homepage: * 00014 * http://ViTooKi.sourceforge.net * 00015 * vitooki-user@lists.sourceforge.net * 00016 * vitooki-devel@lists.sourceforge.net * 00017 * * 00018 * This file is part of ViTooKi, a free video toolkit. * 00019 * ViTooKi is free software; you can redistribute it and/or * 00020 * modify it under the terms of the GNU General Public License * 00021 * as published by the Free Software Foundation; either version 2 * 00022 * of the License, or (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the Free Software * 00031 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00032 * MA 02111-1307, USA. * 00033 * * 00034 ***********************************************************************/ 00035 00036 /*********************************************************************** 00037 * * 00038 * REVISION HISTORY: * 00039 * * 00040 * * 00041 * * 00042 ***********************************************************************/ 00043 00044 #include "YUVSpatialReductionAdaptor.hpp" 00045 #include "string.h" 00046 #include "math.h" 00047 00048 00049 YUVSpatialReductionAdaptor::YUVSpatialReductionAdaptor(VideoESInfo * pESInfo, 00050 u32 * puiWidth, 00051 u32 * puiHeight) { 00052 es = pESInfo; 00053 initialized = false; 00054 muiTargetWidth = *puiWidth; 00055 muiTargetHeight = *puiHeight; 00056 strcpy(name,"YUVSpatialReductionAdaptor"); 00057 } 00058 00059 00060 void YUVSpatialReductionAdaptor::initialize() { 00061 if(initialized) 00062 return; 00063 00064 muiWidth = es->getWidth(); 00065 muiHeight = es->getHeight(); 00066 00067 if (muiTargetWidth % 2 == 1) 00068 muiTargetWidth += 1; 00069 if (muiTargetHeight % 2 == 1) 00070 muiTargetHeight += 1; 00071 00072 // disable upscaling, let the hw do this when rendering to the screen!!! 00073 // this allows us to reuse the incoming frame, os we don't have to newly 00074 // allocate memory 00075 if(muiTargetWidth>muiWidth) 00076 muiTargetWidth=muiWidth; 00077 if(muiTargetHeight>muiHeight) 00078 muiTargetHeight=muiHeight; 00079 00080 es->setWidth(muiTargetWidth); 00081 es->setHeight(muiTargetHeight); 00082 00083 muiScaleFactorWidth = (u32) ((muiTargetWidth * 1000000) / muiWidth) ; 00084 muiScaleFactorHeight = (u32)((muiTargetHeight* 1000000) / muiHeight) ; 00085 initialized = true; 00086 00087 dprintf_full("Scalefactors [w|h]: [%i|%i]\n", muiScaleFactorWidth, 00088 muiScaleFactorHeight); 00089 } 00090 00091 00092 YUVSpatialReductionAdaptor::~YUVSpatialReductionAdaptor() { 00093 } 00094 00095 00096 list < Frame * >YUVSpatialReductionAdaptor::adapt(Frame * frm) { 00097 list < Frame * >retFrameList; 00098 if (!initialized) 00099 initialize(); 00100 00101 if (!initialized) 00102 return retFrameList; 00103 00104 u32 h, w, hOrig, wOrig; 00105 u8 *pOffsetTarget=NULL; 00106 u8 *pOffsetOrig=NULL; 00107 00108 u8 *origFrame = frm->getAU()->payload; 00109 pOffsetOrig = origFrame; 00110 00111 // u8 *retFrame = new u8[muiTargetWidth * muiTargetHeight * 3 / 2]; 00112 // memset(retFrame, 128, muiTargetWidth * muiTargetHeight * 3 / 2); 00113 u8* retFrame=origFrame; // reuse incoming frame 00114 pOffsetTarget = retFrame; 00115 00116 00117 // Y 00118 for (h = 0; h < muiTargetHeight; h++) { 00119 for (w = 0; w < muiTargetWidth; w++) { 00120 // hOrig = (u32) (((float)h)/mfScaleFactorHeight); 00121 // wOrig = (u32) (((float)w)/mfScaleFactorWidth); 00122 hOrig = (u32) ((h * 1000000) / muiScaleFactorHeight); 00123 wOrig = (u32) ((w * 1000000) / muiScaleFactorWidth); 00124 pOffsetTarget[h * muiTargetWidth + w] = 00125 pOffsetOrig[hOrig * muiWidth + wOrig]; 00126 } 00127 } 00128 // V 00129 pOffsetOrig = pOffsetOrig + muiWidth * muiHeight; 00130 pOffsetTarget = pOffsetTarget + muiTargetWidth * muiTargetHeight; 00131 for (h = 0; h < muiTargetHeight / 2; h++) { 00132 for (w = 0; w < muiTargetWidth / 2; w++) { 00133 // hOrig = (u32) (((float)h)/mfScaleFactorHeight); 00134 // wOrig = (u32) (((float)w)/mfScaleFactorWidth); 00135 hOrig = (u32) ((h * 1000000) / muiScaleFactorHeight); 00136 wOrig = (u32) ((w * 1000000) / muiScaleFactorWidth); 00137 pOffsetTarget[h * muiTargetWidth / 2 + w] = 00138 pOffsetOrig[hOrig * muiWidth / 2 + wOrig]; 00139 } 00140 } 00141 // U 00142 pOffsetOrig = pOffsetOrig + muiWidth * muiHeight / 4; 00143 pOffsetTarget = pOffsetTarget + muiTargetWidth * muiTargetHeight / 4; 00144 for (h = 0; h < muiTargetHeight / 2; h++) { 00145 for (w = 0; w < muiTargetWidth / 2; w++) { 00146 // hOrig = (u32) (((float)h)/mfScaleFactorHeight); 00147 // wOrig = (u32) (((float)w)/mfScaleFactorWidth); 00148 hOrig = (u32) ((h * 1000000) / muiScaleFactorHeight); 00149 wOrig = (u32) ((w * 1000000) / muiScaleFactorWidth); 00150 pOffsetTarget[h * muiTargetWidth / 2 + w] = 00151 pOffsetOrig[hOrig * muiWidth / 2 + wOrig]; 00152 } 00153 } 00154 00155 frm->getAU()->payload = retFrame; 00156 frm->getAU()->size = muiTargetWidth * muiTargetHeight * 3 / 2; // YV12 00157 retFrameList.push_back(frm); 00158 return retFrameList; 00159 } 00160 00161 00162 list < Frame * >YUVSpatialReductionAdaptor::close() { 00163 list < Frame * >retFrameList; 00164 00165 return retFrameList; 00166 } 00167 00168 00169 Adaptor *YUVSpatialReductionAdaptor::clone() { 00170 u32 w=muiTargetWidth; 00171 u32 h=muiTargetHeight; 00172 return new YUVSpatialReductionAdaptor(es,&w,&h); 00173 } 00174