Y8UV8ToRGB8Operator.cpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *  Y8UV8ToRGB8Operator.cpp
00003  *
00004  *  (C) 2007 AG Aktives Sehen <agas@uni-koblenz.de>
00005  *           Universitaet Koblenz-Landau
00006  *
00007  *  Additional information:
00008  *  $Id: Y8UV8ToRGB8Operator.cpp 44313 2011-04-06 22:46:28Z agas $
00009  *******************************************************************************/
00010 
00011 #include "Y8UV8ToRGB8Operator.h"
00012 #include <iostream>
00013 
00014 using namespace std;
00015 
00016 namespace puma2 {
00017 
00018 
00019   bool Y8UV8ToRGB8Operator::initialized=false;
00020 
00021   int Y8UV8ToRGB8Operator::yPalette[256];
00022   int Y8UV8ToRGB8Operator::uPaletteG[256];
00023   int Y8UV8ToRGB8Operator::uPaletteB[256];
00024   int Y8UV8ToRGB8Operator::vPaletteR[256];
00025   int Y8UV8ToRGB8Operator::vPaletteG[256];
00026   Mutex Y8UV8ToRGB8Operator::mutex;
00027 
00028   void Y8UV8ToRGB8Operator::initialize()
00029   {
00044     mutex.lock();
00045       if (!initialized) {
00046         // TRACE_INFO("Creating look up tables."); // TODO use ros
00047         //create palettes
00048         for (int i=0;i<256;i++)
00049         {
00050           yPalette[i]  = i;
00051           vPaletteR[i] = int(  1.4022*float(i-128) );
00052           uPaletteG[i] = int( -0.3458*float(i-128) );
00053           vPaletteG[i] = int( -0.7144*float(i-128) );
00054           uPaletteB[i] = int(  1.7710*float(i-128) );
00055 /*          yPalette[i]  = int(  1.164*float(i-16) );
00056           vPaletteR[i] = int(  1.569*float(i-128) );
00057           uPaletteG[i] = int( -0.392*float(i-128) );
00058           vPaletteG[i] = int( -0.813*float(i-128) );
00059           uPaletteB[i] = int(  2.017*float(i-128) );*/
00060         }
00061         initialized=true;
00062       }
00063     mutex.unlock();
00064   }
00065 
00066 
00067   Y8UV8ToRGB8Operator::Y8UV8ToRGB8Operator() { }
00068 
00069   Y8UV8ToRGB8Operator::~Y8UV8ToRGB8Operator() { }
00070 
00071   void Y8UV8ToRGB8Operator::apply(const GrayLevelImage8& constYImage, const ColorImageUV8& constUvImage, ColorImageRGB8& imageRGB)
00072   {
00073 
00074     initialize();
00075 
00076     unsigned width=imageRGB.getWidth();
00077     unsigned height=imageRGB.getHeight();
00078 
00079     GrayLevelImage8& imageY=const_cast<GrayLevelImage8&>(constYImage);
00080     ColorImageUV8& imageUV=const_cast<ColorImageUV8&>(constUvImage);
00081 
00082     unsigned char* yData = (unsigned char*) ( imageY.unsafeRowPointerArray()[0] );
00083     unsigned char* uvData = (unsigned char*) (imageUV[0][0]);
00084     ColorImageRGB8::PixelType* rgbData = imageRGB.unsafeRowPointerArray()[0];
00085 
00086     int r,g,b;
00087     int cY;
00088     unsigned u,v;
00089 
00090     for( unsigned y = 0; y < height ; y++ ) {
00091       for( unsigned x = 0; x < width ; x++ )
00092       {
00093         cY=yPalette[ *(yData++) ];
00094         u=*(uvData++);
00095         v=*(uvData++);
00096 
00097         r=cY + vPaletteR[ v ];
00098         if (r>255) r=255;
00099         if (r<0) r=0;
00100 
00101         g=cY + uPaletteG[ u ] + vPaletteG[ v ];
00102         if (g>255) g=255;
00103         if (g<0) g=0;
00104 
00105         b=cY + uPaletteB[ u ];
00106         if (b>255) b=255;
00107         if (b<0) b=0;
00108 
00109         (*rgbData)[0]=r;
00110         (*rgbData)[1]=g;
00111         (*rgbData)[2]=b;
00112 
00113         rgbData++;
00114       }
00115 
00116     }
00117 
00118   }
00119 
00120   }
00121 
00122 
00123 /*
00124 
00125   //create palettes
00126   for (int i=0;i<256;i++)
00127   {
00128     uPaletteG[i] = int( -0.3458*float(i-128) );
00129     uPaletteB[i] = int(  1.7710*float(i-128) );
00130     vPaletteR[i] = int(  1.4022*float(i-128) );
00131     vPaletteG[i] = int( -0.7144*float(i-128) );
00132   }
00133 
00134   unsigned char* yData = (unsigned char*) ( imageY.unsafeRowPointerArray()[0] );
00135   char* uvData = (char*) (imageUV.unsafeRowPointerArray()[0]);
00136   ColorImageRGB8::PixelType* rgbData = imageRGB.unsafeRowPointerArray()[0];
00137 
00138   int r,g,b;
00139   unsigned cY,cU,cV;
00140 
00141   for( unsigned y = 0; y < height ; y++ ) {
00142     for( unsigned x = 0; x < width ; x++ )
00143     {
00144       cY=*yData;
00145       cU=unsigned(int( (* uvData   ) ));
00146       cV=unsigned(int( (*(uvData+1)) ));
00147 
00148       r=y                  + vPaletteR[ cV ];
00149       if (r>255) r=255;
00150       if (r<0) r=0;
00151 
00152       g=y + uPaletteG[ cU ] + vPaletteG[ cV ];
00153       if (g>255) g=255;
00154       if (g<0) g=0;
00155 
00156       b=y + uPaletteB[ cU ];
00157       if (b>255) b=255;
00158       if (b<0) b=0;
00159 
00160       (*rgbData)[0]=r;
00161       (*rgbData)[1]=g;
00162       (*rgbData)[2]=b;
00163 
00164       yData++;
00165       uvData+=2;
00166       rgbData++;
00167     }
00168 
00169   }
00170 
00171 */


obj_rec_gui
Author(s): AGAS/agas@uni-koblenz.de
autogenerated on Mon Oct 6 2014 02:53:43