Main Page | Namespace List | Compound List | File List | Compound Members | File Members

videomux.cc

Go to the documentation of this file.
00001 #include "videomux.h"
00002 #include <algorithm>
00003 
00004 using namespace std;
00005 
00006 VideoMux::VideoMux (
00007   const Id&             n,
00008  
00009   In<VYApixel>&         CinF0,
00010   In<VYAimageWidth>&    imgWidthInF0,
00011   In<VYAimageHeight>&   imgHeightInF0,
00012   In<imagePosition>&    imgPosInF0,
00013 
00014   In<VYApixel>&         CinF1,
00015   In<VYAimageWidth>&    imgWidthInF1,
00016   In<VYAimageHeight>&   imgHeightInF1,
00017   In<imagePosition>&    imgPosInF1,
00018 
00019   Out<VYApixel>&        CoutF,
00020   Out<VYAimageWidth>&   imgWidthOutF,
00021   Out<VYAimageHeight>&  imgHeightOutF)
00022 :
00023   Process(n),
00024 
00025   CinP0(id("CinP0"), CinF0),
00026   imgWidthInP0(id("imgWidthInP0"), imgWidthInF0),
00027   imgHeightInP0(id("imgHeightInP0"), imgHeightInF0),
00028   imgPosInP0(id("imgPosInP0"), imgPosInF0),
00029 
00030   CinP1(id("CinP1"), CinF1),
00031   imgWidthInP1(id("imgWidthInP1"), imgWidthInF1),
00032   imgHeightInP1(id("imgHeightInP1"), imgHeightInF1),
00033   imgPosInP1(id("imgPosInP1"), imgPosInF1),
00034 
00035   CoutP(id("CoutP"), CoutF),
00036   imgWidthOutP(id("imgWidthOutP"), imgWidthOutF),
00037   imgHeightOutP(id("imgHeightOutP"), imgHeightOutF)
00038 {
00039 }
00040 
00041 const char* VideoMux::type() const
00042 {
00043         return "VideoMux";
00044 }
00045 
00046 void VideoMux::main()
00047 {
00048   /* N is the number of input streams */
00049   /* Index N+1 contains the output stream dimensions */
00050   
00051   const unsigned int N = 2;
00052   
00053   imagePosition   imgPos[N];
00054   VYApixel*   line[N+1] = { 0, 0, 0 };
00055   VYAimageWidth   imgWidth[N+1] = { 0, 0, 0 };
00056   VYAimageHeight  imgHeight[N+1] = { 0, 0, 0 };
00057 
00058   VYAimageWidth   prevImgWidth[N+1] = { 0, 0, 0 };
00059   
00060   unsigned int  mapToDepth[N];
00061       
00062   while(true)
00063   {
00064     for(unsigned int i=0; i<=N; i++)
00065     {
00066       imgWidth[i] = 0;
00067       imgHeight[i] = 0;
00068     }
00069   
00070     read(imgPosInP0, imgPos[0]);
00071     if (imgPos[0].enabled)
00072     {
00073       read(imgWidthInP0, imgWidth[0]);
00074       read(imgHeightInP0, imgHeight[0]);  
00075     }
00076     read(imgPosInP1, imgPos[1]);
00077     if (imgPos[1].enabled)
00078     {
00079       read(imgWidthInP1, imgWidth[1]);
00080       read(imgHeightInP1, imgHeight[1]);
00081     }
00082     
00083     for(unsigned int i=0; i<N; i++)
00084     {
00085       imgWidth[N] = max(imgWidth[N], imgPos[i].x + imgWidth[i]);
00086       imgHeight[N] = max(imgHeight[N], imgPos[i].y + imgHeight[i]);
00087     }
00088     write(imgWidthOutP, imgWidth[N]);
00089     write(imgHeightOutP, imgHeight[N]);
00090 
00091     for(unsigned int i=0; i<=N; i++)
00092     {
00093       if (imgWidth[i] != prevImgWidth[i])
00094       {
00095         if (!line[i]) delete [] line[i];
00096         line[i] = new VYApixel[imgWidth[i]];
00097         prevImgWidth[i] = imgWidth[i];
00098         
00099       }
00100     }
00101 
00102     for(unsigned int i=0; i<N; i++)
00103     {
00104       mapToDepth[i] = i;
00105     }
00106     for(unsigned int i=0; i<N-1; i++)
00107     {
00108       for (unsigned int j=i; j<N; j++)
00109       {
00110         if (imgPos[mapToDepth[i]].z > imgPos[mapToDepth[j]].z)
00111         {
00112           mapToDepth[i] = j;
00113           mapToDepth[j] = i;
00114         }
00115       }
00116     }
00117     
00118     for(VYAimageHeight h=0; h<imgHeight[N]; h++)
00119     {
00120       /*  If we allow read with port reference, we do not need line buffers 0..N.
00121         Input of length imgWidth[mi] can be read immediately in line[N][imgPos[mi].x],
00122         i.e.,
00123       
00124         for (unsigned int i=0; i<N; i++)
00125         {
00126           unsigned int mi = mapToDepth[i];
00127           if ((imgPos[mi].y<=h) && (h<imgHeight[mi]+imgPos[mi].y))
00128           {
00129             read(CinP[mi], &line[N][imgPos[mi].x], imgWidth[mi]);
00130           } 
00131         }
00132       */
00133       if ((imgPos[0].y<=h) && (h<imgHeight[0]+imgPos[0].y) && imgPos[0].enabled)
00134       {
00135         read(CinP0, &line[0][0], imgWidth[0]);
00136       }
00137       if ((imgPos[1].y<=h) && (h<imgHeight[1]+imgPos[1].y) && imgPos[1].enabled)
00138       {
00139         read(CinP1, &line[1][0], imgWidth[1]);
00140       }
00141 
00142       for(unsigned int i=0; i<imgWidth[N]; i++)
00143       {
00144         line[N][i] = 0;
00145       }
00146             
00147       for (unsigned int i=0; i<N; i++)
00148       {
00149         unsigned int mi = mapToDepth[i];
00150         if ((imgPos[mi].y<=h) && (h<imgHeight[mi]+imgPos[mi].y) && imgPos[mi].enabled)
00151         {
00152           for(unsigned j=0; j<imgWidth[mi]; j++)
00153           {
00154             line[N][imgPos[mi].x+j] = line[mi][j];
00155           }
00156         }
00157       }
00158       
00159       write(CoutP, &line[N][0], imgWidth[N]);
00160     }   
00161   }
00162 }
00163 

Generated on Wed Feb 15 14:52:44 2006 for videomux by doxygen 1.3.2