RGB8ToY8UV8Operator.cpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *  RGB8ToY8UV8Operator.cpp
00003  *
00004  *  (C) 2007 AG Aktives Sehen <agas@uni-koblenz.de>
00005  *           Universitaet Koblenz-Landau
00006  *
00007  *  Additional information:
00008  *  $Id: RGB8ToY8UV8Operator.cpp 25610 2008-06-20 08:30:53Z dgossow $
00009  *******************************************************************************/
00010 
00011 #include "RGB8ToY8UV8Operator.h"
00012 #include <iostream>
00013 
00014 
00015 using namespace std;
00016 
00017 namespace puma2
00018 {
00019 
00020   void RGB8ToY8UV8Operator::apply ( const ColorImageRGB8& constRgbImage, GrayLevelImage8& imageY, ColorImageUV8& imageUV )
00021   {
00022     ColorImageRGB8& imageRGB=const_cast<ColorImageRGB8&> ( constRgbImage );
00023 
00024     unsigned width=imageRGB.getWidth();
00025     unsigned height=imageRGB.getHeight();
00026 
00027     unsigned char* yData = ( unsigned char* ) ( imageY.unsafeRowPointerArray() [0] );
00028     unsigned char* uvData = ( unsigned char* ) ( imageUV.unsafeRowPointerArray() [0][0] );
00029     unsigned char* rgbData = imageRGB.unsafeRowPointerArray() [0][0];
00030 
00031     float cY,cU,cV;
00032     float cR,cG,cB;
00033 
00034     for ( unsigned y = 0; y < height ; y++ )
00035     {
00036       for ( unsigned x = 0; x < width ; x++ )
00037       {
00038         cR = rgbData[0];
00039         cG = rgbData[1];
00040         cB = rgbData[2];
00041 
00042         cY = 0.2989*cR+ 0.5866*cG + 0.1145*cB;
00043         if ( cY > 255 ) { cY=255; }
00044         if ( cY < 0 ) { cY=0; }
00045 
00046         cU = -0.1688*cR - 0.3312*cG + 0.5000*cB +128;
00047         if ( cU > 255 ) { cU=255; }
00048         if ( cU < 0 ) { cU=0; }
00049 
00050         cV = 0.5000*cR - 0.4183*cG - 0.0817*cB +128;
00051         if ( cV > 255 ) { cV=255; }
00052         if ( cV < 0 ) { cV=0; }
00053 
00054         *yData=cY;
00055         uvData[0]=cU;
00056         uvData[1]=cV;
00057 
00058         rgbData+=3;
00059         uvData+=2;
00060         yData++;
00061       }
00062 
00063     }
00064 
00065   }
00066 
00067 }
00068 


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