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

raster.cc

Go to the documentation of this file.
00001 /*--------------------------------------------------------------------
00002  *
00003  * (C) Copyright Koninklijke Philips Electronics NV 2006. 
00004  * All rights reserved. This software is licensed under the terms of
00005  * version 2.1 of the GNU Lesser General Public License as published 
00006  * by the Free Software Foundation. For licensing and warranty
00007  * information, see the file COPYING in the main directory.
00008  *
00009  *------------------------------------------------------------------*/
00010 
00011 #include "raster.h"
00012 #include <stdio.h>
00013 
00014 Raster::Raster(
00015   const Id&               n, 
00016   In<VYApixel>&           Cin,
00017   In<VYAimageDepth>&      imageDepthIn,
00018   In<VYAimageComponent>&  imageComponentIdIn,
00019   In<VYAimageWidth>&      imageWidthIn,
00020   In<VYAimageHeight>&     imageHeightIn,
00021   In<VYAimageH>&          imageHIn,
00022   In<VYAimageV>&          imageVIn,
00023   In<VYAimageDepth>&      scanDepthIn,
00024   In<VYAimageComponent>&  scanComponentIdIn,
00025   Out<VYApixel>&          Yout,
00026   Out<VYApixel>&          Uout,
00027   Out<VYApixel>&          Vout,
00028   Out<VYAimageWidth>&     YimageWidthOut,
00029   Out<VYAimageHeight>&    YimageHeightOut,
00030   Out<VYAimageWidth>&     UVimageWidthOut,
00031   Out<VYAimageHeight>&    UVimageHeightOut,
00032   Out<VYAimageType>&      YUVimgTypeOut)
00033 :
00034   Process(n),
00035   CinP(               id("CinP"),               Cin),
00036   imageDepthInP(      id("imageDepthInP"),      imageDepthIn),
00037   imageComponentIdInP(id("imageComponentIdInP"),imageComponentIdIn),
00038   imageWidthInP(      id("imageWidthInP"),      imageWidthIn),
00039   imageHeightInP(     id("imageHeightInP"),     imageHeightIn),
00040   imageHInP(          id("imageHInP"),          imageHIn),
00041   imageVInP(          id("imageVInP"),          imageVIn),
00042   scanDepthInP(       id("scanDepthInP"),       scanDepthIn),
00043   scanComponentIdInP( id("scanComponentIdInP"), scanComponentIdIn),
00044   YoutP(              id("YoutP"),              Yout),
00045   UoutP(              id("UoutP"),              Uout),
00046   VoutP(              id("VoutP"),              Vout),
00047   YimageWidthOutP(    id("YimageWidthOutP"),    YimageWidthOut),
00048   YimageHeightOutP(   id("YimageHeightOutP"),   YimageHeightOut),
00049   UVimageWidthOutP(   id("UVimageWidthOutP"),   UVimageWidthOut),
00050   UVimageHeightOutP(  id("UVimageHeightOutP"),  UVimageHeightOut),
00051   YUVimgTypeOutP(     id("YUVimgTypeOutP"),     YUVimgTypeOut)
00052 {
00053 }
00054 
00055 void Raster::main()
00056 {
00057   VYAimageDepth   nrOfImageComponents;
00058   VYAimageComponent*  imageComponent;
00059   VYAimageX     Xmax = 0;
00060   VYAimageY     Ymax = 0;
00061   VYAimageH   Hmax = 0;
00062   VYAimageV     Vmax = 0;
00063   VYAimageH*    H;
00064   VYAimageV*    V;
00065   VYAimageX*    X;
00066   VYAimageY*    Y;
00067     
00068   read(imageWidthInP, Xmax);
00069   read(imageHeightInP, Ymax);
00070   read(imageDepthInP, nrOfImageComponents);
00071   imageComponent = new VYAimageComponent[nrOfImageComponents];
00072   H = new VYAimageH[nrOfImageComponents];
00073   V = new VYAimageV[nrOfImageComponents];
00074   X = new VYAimageX[nrOfImageComponents];
00075   Y = new VYAimageY[nrOfImageComponents];
00076   VYApixel** stripe = new VYApixel*[nrOfImageComponents];
00077   unsigned int i;
00078   for(i=0; i<nrOfImageComponents; i++)
00079   {
00080     read(imageComponentIdInP, imageComponent[i]);
00081     read(imageHInP, H[i]);
00082     read(imageVInP, V[i]);
00083     if (H[i] > Hmax) Hmax = H[i];
00084     if (V[i] > Vmax) Vmax = V[i];
00085   }
00086 
00087   int MCU_sx = 8*Hmax;
00088   int MCU_sy = 8*Vmax;
00089   int mx_size = ceil_div(Xmax,MCU_sx);
00090   int my_size = ceil_div(Ymax,MCU_sy);
00091     
00092   for(i=0; i<nrOfImageComponents; i++)
00093   {
00094     X[i] = ceil_div(Xmax*H[i],Hmax);
00095     Y[i] = ceil_div(Ymax*V[i],Vmax);
00096     stripe[i] = new VYApixel[8*V[i]*X[i]];
00097   }
00098 
00099   if (nrOfImageComponents == 1)
00100   {
00101     write(YimageWidthOutP, X[0]);
00102     write(YimageHeightOutP, Y[0]);
00103   } 
00104   else if (nrOfImageComponents == 3)
00105   {
00106     write(YimageWidthOutP, X[0]);
00107     write(YimageHeightOutP, Y[0]);
00108     write(UVimageWidthOutP, X[1]);
00109     write(UVimageHeightOutP, Y[1]);
00110   }
00111   write(YUVimgTypeOutP, VYA_FRAME);
00112       
00113   while (true)
00114   {
00115     VYAimageDepth   nrOfScanComponents;
00116     VYAimageComponent*  scanComponentId;
00117     
00118     read(scanDepthInP, nrOfScanComponents);
00119     assert(nrOfScanComponents == 3);
00120     scanComponentId = new VYAimageComponent[nrOfScanComponents];
00121     for(unsigned int i=0; i<nrOfScanComponents; i++)
00122     {
00123       read(scanComponentIdInP, scanComponentId[i]);
00124     }
00125   
00126     for (int stripeCount=0; stripeCount<my_size; stripeCount++)
00127     {
00128       #ifdef VERBOSE
00129         printf("%s:\n\tProcessing stripe %d/%d\n", fullName(), stripeCount+1, my_size);
00130       #endif
00131       for (int mcuCount=0; mcuCount<mx_size; mcuCount++)
00132       {
00133         for(unsigned int i=0; i<nrOfScanComponents; i++)
00134         {
00135           int ci = scanComponentId[i];
00136           int hi = H[ci];
00137           int vi = V[ci];
00138           int xi = mcuCount*8*H[ci];
00139     
00140           for(int v=0; v<vi; v++)
00141           {
00142             for(int h=0; h<hi; h++)
00143             {
00144               VYApixel dummy[8];
00145               unsigned int x = xi+8*h;
00146               for(int l=0; l<8; l++)
00147               {
00148                 if ((x<X[ci]) && (X[ci]-x >= 8)) {
00149                   read(CinP, &stripe[ci][(8*v+l)*X[ci]+xi+8*h], 8);
00150                 } else if ((x<X[ci]) && (X[ci]-x < 8)) {
00151                   read(CinP, &stripe[ci][(8*v+l)*X[ci]+xi+8*h], X[ci]-x);
00152                   read(CinP, dummy, 8-(X[ci]-x));
00153                 } else {
00154                   read(CinP, dummy, 8);
00155                 }
00156               }
00157             }
00158           }
00159         }
00160       }
00161       
00162       for(unsigned int i=0; i<nrOfScanComponents; i++)
00163       {
00164         int ci = scanComponentId[i];
00165         int xi = X[ci];
00166         int yi = 8*V[ci];
00167         
00168         if ((stripeCount+1)*8*V[ci] > Y[ci]) {
00169           yi = Y[ci] - stripeCount*8*V[ci];
00170         }         
00171         switch (ci)
00172         {
00173         case 0: write(YoutP, stripe[ci], yi*xi);
00174           break;
00175         case 1: write(UoutP, stripe[ci], yi*xi);
00176           break;
00177         case 2: write(VoutP, stripe[ci], yi*xi);
00178           break;
00179         }
00180       }
00181     } 
00182   }
00183 
00184   for(unsigned int j=0; j<nrOfImageComponents; j++)
00185   {
00186     delete [] stripe[j];
00187   }
00188       
00189   delete [] imageComponent;
00190   delete [] H;
00191   delete [] V;
00192   delete [] X;
00193   delete [] Y;
00194   delete [] stripe;
00195 }

Generated on Wed Feb 15 14:52:45 2006 for jpegdec by doxygen 1.3.2