00001 #ifndef Impala_Core_Array_Pattern_FuncNgbOp2dExtra2_h
00002 #define Impala_Core_Array_Pattern_FuncNgbOp2dExtra2_h
00003
00004 #include "Core/Array/Pattern/Categories.h"
00005 #include "Core/Array/Pattern/ArrayFunc.h"
00006
00007 namespace Impala
00008 {
00009 namespace Core
00010 {
00011 namespace Array
00012 {
00013 namespace Pattern
00014 {
00015
00016
00017
00049 template <class SrcArrayT, class ExtraArrayT, class Extra2ArrayT, class NgbT>
00050 inline void
00051 FuncNgbOp2dExtra2_Pix_P1Cnum(SrcArrayT* src, ExtraArrayT* extra,
00052 Extra2ArrayT* extra2, int x, int y, NgbT& ngb)
00053 {
00054 typedef typename SrcArrayT::StorType SrcStorT;
00055 typedef typename SrcArrayT::ArithType SrcArithT;
00056 typedef typename ExtraArrayT::StorType ExtraStorT;
00057 typedef typename ExtraArrayT::ArithType ExtraArithT;
00058 typedef typename Extra2ArrayT::StorType Extra2StorT;
00059 typedef typename Extra2ArrayT::ArithType Extra2ArithT;
00060 typedef typename NgbT::CnumType CnumType;
00061
00062 for (CnumType cnum = ngb.Begin() ; cnum != ngb.End() ; cnum.Inc())
00063 {
00064 SrcStorT* nPtr = ArrayCPB(src, x + cnum.X(), y + cnum.Y());
00065 SrcStorT* ePtr = ArrayCPB(extra, x + cnum.X(), y + cnum.Y());
00066 SrcStorT* e2Ptr = ArrayCPB(extra2, x + cnum.X(), y + cnum.Y());
00067 ngb.NextEl(cnum.X(), cnum.Y(), PtrRead(nPtr, SrcArithT()),
00068 PtrRead(ePtr, ExtraArithT()),
00069 PtrRead(e2Ptr, ExtraArithT()));
00070 }
00071 }
00072
00075 template <class SrcStorT, class SrcArithT, class ExtraStorT, class ExtraArithT,
00076 class Extra2StorT, class Extra2ArithT, class NgbT>
00077 inline void
00078 FuncNgbOp2dExtra2_Pix_P1Loop(SrcStorT* sPtr, ExtraStorT* ePtr,
00079 Extra2StorT* e2Ptr, NgbT& ngb,
00080 int ngbWidth, int ngbHeight,
00081 int srcIncX, int srcIncY, SrcArithT,
00082 int extraIncX, int extraIncY, ExtraArithT,
00083 int extra2IncX, int extra2IncY, Extra2ArithT)
00084 {
00085 for (int j=0 ; j<ngbHeight ; j++)
00086 {
00087 for (int i=0 ; i<ngbWidth ; i++)
00088 {
00089 ngb.NextEl(i, j, PtrRead(sPtr, SrcArithT()),
00090 PtrRead(ePtr, ExtraArithT()),
00091 PtrRead(e2Ptr, ExtraArithT()));
00092 sPtr += srcIncX;
00093 ePtr += extraIncX;
00094 e2Ptr += extra2IncX;
00095 }
00096 sPtr += srcIncY;
00097 ePtr += extraIncY;
00098 e2Ptr += extra2IncY;
00099 }
00100 }
00101
00104 template <class SrcStorT, class SrcArithT, class ExtraStorT, class ExtraArithT,
00105 class Extra2StorT, class Extra2ArithT, class NgbT>
00106 inline void
00107 FuncNgbOp2dExtra2_Pix_P2Loop(SrcStorT* sPtr, ExtraStorT* ePtr,
00108 Extra2StorT* e2Ptr, NgbT& ngb,
00109 int ngbWidth, int ngbHeight,
00110 int srcIncX, int srcIncY, SrcArithT,
00111 int extraIncX, int extraIncY, ExtraArithT,
00112 int extra2IncX, int extra2IncY, Extra2ArithT)
00113 {
00114 for (int j=0 ; j<ngbHeight ; j++)
00115 {
00116 for (int i=0 ; i<ngbWidth ; i++)
00117 {
00118 ngb.NextEl2(i, j, PtrRead(sPtr, SrcArithT()),
00119 PtrRead(ePtr, ExtraArithT()),
00120 PtrRead(e2Ptr, Extra2ArithT()));
00121 sPtr += srcIncX;
00122 ePtr += extraIncX;
00123 e2Ptr += extra2IncX;
00124 }
00125 sPtr += srcIncY;
00126 ePtr += extraIncY;
00127 e2Ptr += extra2IncY;
00128 }
00129 }
00130
00131
00133
00134
00135
00137
00141 template <class DstArrayT, class SrcArrayT, class ExtraArrayT,
00142 class Extra2ArrayT, class NgbT>
00143 inline void
00144 FuncNgbOp2dExtra2_Row(DstArrayT* dst, SrcArrayT* src, ExtraArrayT* extra,
00145 Extra2ArrayT* extra2, NgbT& ngb, int y,
00146 Tag1Phase dummy1, TagCnum dummy2)
00147 {
00148 typedef typename DstArrayT::StorType DstStorT;
00149 typedef typename DstArrayT::ArithType DstArithT;
00150 typedef typename SrcArrayT::StorType SrcStorT;
00151 typedef typename SrcArrayT::ArithType SrcArithT;
00152 typedef typename ExtraArrayT::StorType ExtraStorT;
00153 typedef typename ExtraArrayT::ArithType ExtraArithT;
00154 typedef typename Extra2ArrayT::StorType Extra2StorT;
00155 typedef typename Extra2ArrayT::ArithType Extra2ArithT;
00156
00157 int width = ArrayCW(dst);
00158 DstStorT* dPtr = ArrayCPB(dst, 0, y);
00159 SrcStorT* sPtr = ArrayCPB(src, 0, y);
00160 SrcStorT* ePtr = ArrayCPB(extra, 0, y);
00161 SrcStorT* e2Ptr = ArrayCPB(extra2, 0, y);
00162 for (int x=0 ; x<width ; x++)
00163 {
00164 ngb.Init(x, y, PtrRead(sPtr, SrcArithT()),
00165 PtrRead(ePtr, ExtraArithT()),
00166 PtrRead(e2Ptr, Extra2ArithT()));
00167 FuncNgbOp2dExtra2_Pix_P1Cnum(src, extra, extra2, x, y, ngb);
00168 PtrWrite(dPtr, ngb.Result());
00169 dPtr += DstArrayT::ElemSize();
00170 sPtr += SrcArrayT::ElemSize();
00171 ePtr += ExtraArrayT::ElemSize();
00172 e2Ptr += Extra2ArrayT::ElemSize();
00173 }
00174 }
00175
00178 template <class DstArrayT, class SrcArrayT, class ExtraArrayT,
00179 class Extra2ArrayT, class NgbT>
00180 inline void
00181 FuncNgbOp2dExtra2_Row(DstArrayT* dst, SrcArrayT* src, ExtraArrayT* extra,
00182 Extra2ArrayT* extra2, NgbT& ngb, int y,
00183 Tag1Phase dummy1, TagLoop dummy2)
00184 {
00185 typedef typename DstArrayT::StorType DstStorT;
00186 typedef typename DstArrayT::ArithType DstArithT;
00187 typedef typename SrcArrayT::StorType SrcStorT;
00188 typedef typename SrcArrayT::ArithType SrcArithT;
00189 typedef typename ExtraArrayT::StorType ExtraStorT;
00190 typedef typename ExtraArrayT::ArithType ExtraArithT;
00191 typedef typename Extra2ArrayT::StorType Extra2StorT;
00192 typedef typename Extra2ArrayT::ArithType Extra2ArithT;
00193
00194 int ngbWidth = ngb.Width();
00195 int ngbHeight = ngb.Height();
00196 int width = ArrayCW(dst);
00197 DstStorT* dPtr = ArrayCPB(dst, 0, y);
00198 SrcStorT* sPtr = ArrayCPB(src, -ngbWidth/2, y-ngbHeight/2);
00199 SrcStorT* ePtr = ArrayCPB(extra, -ngbWidth/2, y-ngbHeight/2);
00200 SrcStorT* e2Ptr = ArrayCPB(extra2, -ngbWidth/2, y-ngbHeight/2);
00201 SrcStorT* cenPtr = ArrayCPB(src, 0, y);
00202 SrcStorT* ecenPtr = ArrayCPB(extra, 0, y);
00203 SrcStorT* e2cenPtr = ArrayCPB(extra2, 0, y);
00204 int srcIncX = ArrayInc(src, 1, 0);
00205 int srcIncY = ArrayInc(src, -ngbWidth, 1);
00206 int extraIncX = ArrayInc(extra, 1, 0);
00207 int extraIncY = ArrayInc(extra, -ngbWidth, 1);
00208 int extra2IncX = ArrayInc(extra2, 1, 0);
00209 int extra2IncY = ArrayInc(extra2, -ngbWidth, 1);
00210 for (int x=0 ; x<width ; x++)
00211 {
00212 ngb.Init(x, y, PtrRead(cenPtr, SrcArithT()),
00213 PtrRead(ecenPtr, ExtraArithT()),
00214 PtrRead(e2cenPtr, Extra2ArithT()));
00215 FuncNgbOp2dExtra2_Pix_P1Loop(sPtr, ePtr, e2Ptr, ngb, ngbWidth, ngbHeight,
00216 srcIncX, srcIncY, SrcArithT(),
00217 extraIncX, extraIncY, ExtraArithT(),
00218 extra2IncX, extra2IncY, Extra2ArithT());
00219 PtrWrite(dPtr, ngb.Result());
00220 dPtr += DstArrayT::ElemSize();
00221 sPtr += SrcArrayT::ElemSize();
00222 ePtr += ExtraArrayT::ElemSize();
00223 e2Ptr += Extra2ArrayT::ElemSize();
00224 cenPtr += SrcArrayT::ElemSize();
00225 ecenPtr += ExtraArrayT::ElemSize();
00226 e2cenPtr += Extra2ArrayT::ElemSize();
00227 }
00228 }
00229
00232 template <class DstArrayT, class SrcArrayT, class ExtraArrayT,
00233 class Extra2ArrayT, class NgbT>
00234 inline void
00235 FuncNgbOp2dExtra2_Row(DstArrayT* dst, SrcArrayT* src, ExtraArrayT* extra,
00236 Extra2ArrayT* extra2, NgbT& ngb, int y,
00237 Tag2Phase dummy1, TagLoop dummy2)
00238 {
00239 typedef typename DstArrayT::StorType DstStorT;
00240 typedef typename DstArrayT::ArithType DstArithT;
00241 typedef typename SrcArrayT::StorType SrcStorT;
00242 typedef typename SrcArrayT::ArithType SrcArithT;
00243 typedef typename ExtraArrayT::StorType ExtraStorT;
00244 typedef typename ExtraArrayT::ArithType ExtraArithT;
00245 typedef typename Extra2ArrayT::StorType Extra2StorT;
00246 typedef typename Extra2ArrayT::ArithType Extra2ArithT;
00247
00248 int ngbWidth = ngb.Width();
00249 int ngbHeight = ngb.Height();
00250 int width = ArrayCW(dst);
00251 DstStorT* dPtr = ArrayCPB(dst, 0, y);
00252 SrcStorT* sPtr = ArrayCPB(src, -ngbWidth/2, y-ngbHeight/2);
00253 SrcStorT* ePtr = ArrayCPB(extra, -ngbWidth/2, y-ngbHeight/2);
00254 SrcStorT* e2Ptr = ArrayCPB(extra2, -ngbWidth/2, y-ngbHeight/2);
00255 SrcStorT* cenPtr = ArrayCPB(src, 0, y);
00256 SrcStorT* ecenPtr = ArrayCPB(extra, 0, y);
00257 SrcStorT* e2cenPtr = ArrayCPB(extra2, 0, y);
00258 int srcIncX = ArrayInc(src, 1, 0);
00259 int srcIncY = ArrayInc(src, -ngbWidth, 1);
00260 int extraIncX = ArrayInc(extra, 1, 0);
00261 int extraIncY = ArrayInc(extra, -ngbWidth, 1);
00262 int extra2IncX = ArrayInc(extra2, 1, 0);
00263 int extra2IncY = ArrayInc(extra2, -ngbWidth, 1);
00264 for (int x=0 ; x<width ; x++)
00265 {
00266 ngb.Init(x, y, PtrRead(cenPtr, SrcArithT()),
00267 PtrRead(ecenPtr, ExtraArithT()),
00268 PtrRead(e2cenPtr, Extra2ArithT()));
00269 FuncNgbOp2dExtra2_Pix_P1Loop(sPtr, ePtr, e2Ptr, ngb, ngbWidth, ngbHeight,
00270 srcIncX, srcIncY, SrcArithT(),
00271 extraIncX, extraIncY, ExtraArithT(),
00272 extra2IncX, extra2IncY, Extra2ArithT());
00273 ngb.Init2(x, y, PtrRead(cenPtr, SrcArithT()),
00274 PtrRead(ecenPtr, ExtraArithT()),
00275 PtrRead(e2cenPtr, Extra2ArithT()));
00276 FuncNgbOp2dExtra2_Pix_P2Loop(sPtr, ePtr, e2Ptr, ngb, ngbWidth, ngbHeight,
00277 srcIncX, srcIncY, SrcArithT(),
00278 extraIncX, extraIncY, ExtraArithT(),
00279 extra2IncX, extra2IncY, Extra2ArithT());
00280 PtrWrite(dPtr, ngb.Result());
00281 dPtr += DstArrayT::ElemSize();
00282 sPtr += SrcArrayT::ElemSize();
00283 ePtr += ExtraArrayT::ElemSize();
00284 e2Ptr += Extra2ArrayT::ElemSize();
00285 cenPtr += SrcArrayT::ElemSize();
00286 ecenPtr += ExtraArrayT::ElemSize();
00287 e2cenPtr += Extra2ArrayT::ElemSize();
00288 }
00289 }
00290
00291
00294 template <class DstArrayT, class SrcArrayT, class ExtraArrayT,
00295 class Extra2ArrayT, class NgbT>
00296 inline void
00297 FuncNgbOp2dExtra2_Row(DstArrayT* dst, SrcArrayT* src, ExtraArrayT* extra,
00298 Extra2ArrayT* extra2, NgbT& ngb, int y,
00299 TagNPhase dummy1, TagLoop dummy2)
00300 {
00301 typedef typename DstArrayT::StorType DstStorT;
00302 typedef typename DstArrayT::ArithType DstArithT;
00303 typedef typename SrcArrayT::StorType SrcStorT;
00304 typedef typename SrcArrayT::ArithType SrcArithT;
00305 typedef typename ExtraArrayT::StorType ExtraStorT;
00306 typedef typename ExtraArrayT::ArithType ExtraArithT;
00307 typedef typename Extra2ArrayT::StorType Extra2StorT;
00308 typedef typename Extra2ArrayT::ArithType Extra2ArithT;
00309
00310 int ngbWidth = ngb.Width();
00311 int ngbHeight = ngb.Height();
00312 int width = ArrayCW(dst);
00313 DstStorT* dPtr = ArrayCPB(dst, 0, y);
00314 SrcStorT* sPtr = ArrayCPB(src, -ngbWidth/2, y-ngbHeight/2);
00315 SrcStorT* ePtr = ArrayCPB(extra, -ngbWidth/2, y-ngbHeight/2);
00316 SrcStorT* e2Ptr = ArrayCPB(extra2, -ngbWidth/2, y-ngbHeight/2);
00317 SrcStorT* cenPtr = ArrayCPB(src, 0, y);
00318 SrcStorT* ecenPtr = ArrayCPB(extra, 0, y);
00319 SrcStorT* e2cenPtr = ArrayCPB(extra2, 0, y);
00320 int srcIncX = ArrayInc(src, 1, 0);
00321 int srcIncY = ArrayInc(src, -ngbWidth, 1);
00322 int extraIncX = ArrayInc(extra, 1, 0);
00323 int extraIncY = ArrayInc(extra, -ngbWidth, 1);
00324 int extra2IncX = ArrayInc(extra2, 1, 0);
00325 int extra2IncY = ArrayInc(extra2, -ngbWidth, 1);
00326 for (int x=0 ; x<width ; x++)
00327 {
00328 int phase = 1;
00329 do
00330 {
00331 ngb.Init(phase, x, y, PtrRead(cenPtr, SrcArithT()),
00332 PtrRead(ecenPtr, ExtraArithT()),
00333 PtrRead(e2cenPtr, Extra2ArithT()));
00334 FuncNgbOp2dExtra2_Pix_P1Loop(sPtr, ePtr, e2Ptr, ngb,
00335 ngbWidth, ngbHeight,
00336 srcIncX, srcIncY, SrcArithT(),
00337 extraIncX, extraIncY, ExtraArithT(),
00338 extra2IncX, extra2IncY, Extra2ArithT());
00339 ngb.Done(phase);
00340 }
00341 while (ngb.HasNextPhase(phase++));
00342 PtrWrite(dPtr, ngb.Result());
00343 dPtr += DstArrayT::ElemSize();
00344 sPtr += SrcArrayT::ElemSize();
00345 ePtr += ExtraArrayT::ElemSize();
00346 e2Ptr += Extra2ArrayT::ElemSize();
00347 cenPtr += SrcArrayT::ElemSize();
00348 ecenPtr += ExtraArrayT::ElemSize();
00349 e2cenPtr += Extra2ArrayT::ElemSize();
00350 }
00351 }
00352
00354
00355
00359 template<class DstArrayT, class SrcArrayT, class ExtraArrayT,
00360 class Extra2ArrayT, class NgbT>
00361 void
00362 FuncNgbOp2dExtra2Dispatch(DstArrayT* dst, SrcArrayT* src, ExtraArrayT* extra,
00363 Extra2ArrayT* extra2, NgbT& ngb)
00364 {
00365 int height = ArrayCH(dst);
00366 for (int y=0 ; y<height ; y++)
00367 {
00368 FuncNgbOp2dExtra2_Row(dst, src, extra, extra2, ngb, y,
00369 typename NgbT::PhaseCategory(),
00370 typename NgbT::IteratorCategory());
00371 }
00372 }
00373
00374 }
00375 }
00376 }
00377 }
00378
00379 #endif