/home/fwph/code/wurde/rde/utils/ImageSource.cpp

Go to the documentation of this file.
00001 #include <ImageSource.H>
00002 #include <Logger.H>
00003 
00004 using namespace WURDE;
00005 using namespace std;
00006 
00007 WURDEImage ImageSource::getImage(){
00008 
00009        if(m_supplier){
00010               m_localImage.second=NULL;
00011               return m_localImage;
00012        }
00013 
00014        // check if we need to release the current image
00015        if((m_localImage.second)){
00016 
00017               if(m_localImage.second->width!=info.width.getValue()||
00018                  m_localImage.second->height!=info.height.getValue()||
00019                  m_format!=info.format.getValue()||
00020                  m_compression!=info.compression.getValue()){
00021                      cvReleaseImage(&m_localImage.second);
00022                      m_localImage.second=NULL;
00023                      m_format=info.format.getValue();
00024                      m_compression=info.compression.getValue();
00025               }
00026        }else{
00027              m_format=info.format.getValue();
00028              m_compression=info.compression.getValue();
00029        }
00030        
00031        // allocate a new image
00032        if(!(m_localImage.second)){
00033               switch(m_format){
00034                      
00035               case FORMAT_CHAR_111_YUV24:
00036               case FORMAT_CHAR_111_RGB:
00037                      
00038                      m_localImage.second=cvCreateImage(cvSize(info.width.getValue(), info.height.getValue()), IPL_DEPTH_8U, 3);
00039                      break;
00040 
00041               case FORMAT_CHAR_11_YUV422:
00042                      m_localImage.second=cvCreateImage(cvSize(info.width.getValue(), info.height.getValue()), IPL_DEPTH_8U, 2);
00043                      break;
00044 
00045               case FORMAT_CHAR_1_GRAY:
00046                      m_localImage.second=cvCreateImage(cvSize(info.width.getValue(), info.height.getValue()), IPL_DEPTH_8U, 1);
00047                      break;
00048                      
00049               default:
00050                      char buffer[512];
00051                      sprintf(buffer,"Unhandled format in ImageSource: %d,%d",m_format,info.format.getValue());
00052                      g_warn(buffer);
00053                      return m_localImage;
00054               }
00055        }
00056 
00057        
00058        // copy the image data
00059        switch(m_compression){
00060        case COMPRESSION_RLE_HIGHQUALITY:
00061               switch(m_format){
00062               case FORMAT_CHAR_111_YUV24:
00063               case FORMAT_CHAR_111_RGB:
00064                      //PIX functions are written for three channel images
00065                      GCM_rleDecodePixMed(data.image,data.imagesize,(unsigned char *)m_localImage.second->imageData);
00066                      break;
00067               case FORMAT_CHAR_11_YUV422:
00068                      //YUV422 compression will probably suck
00069               case FORMAT_CHAR_1_GRAY:
00070                      GCM_rleDecodeGreyMed(data.image,data.imagesize,(unsigned char *)m_localImage.second->imageData);                
00071                      break;
00072               default:
00073                      g_error("Attempted to uncompress image of type not supported for compression.");
00074               }
00075               break;
00076        case COMPRESSION_RLE_LOWQUALITY:
00077               switch(m_format){
00078               case FORMAT_CHAR_111_YUV24:
00079               case FORMAT_CHAR_111_RGB:
00080                      //PIX functions are written for three channel images
00081                      GCM_rleDecodePixLow(data.image,data.imagesize,(unsigned char *)m_localImage.second->imageData);
00082                      break;
00083               case FORMAT_CHAR_11_YUV422:
00084                      //YUV422 compression will probably suck
00085               case FORMAT_CHAR_1_GRAY:
00086                      GCM_rleDecodeGreyLow(data.image,data.imagesize,(unsigned char *)m_localImage.second->imageData);                
00087                      break;
00088               default:
00089                      g_error("Attempted to uncompress image of type not supported for compression.");
00090               }
00091               break;
00092 
00093        case COMPRESSION_NULL:
00094        case COMPRESSION_UNCOMPRESSED:
00095               memcpy(m_localImage.second->imageData, data.image,data.imagesize);
00096               break;
00097 
00098 
00099        }
00100 
00101        m_localImage.first=data.timestamp;
00102 
00103        return m_localImage;
00104 
00105 }
00106 
00107 void ImageSource::publishImage(WURDEImage &image){
00108 
00109        if(!m_supplier){
00110               return;
00111        }
00112 
00113        //set the info and publish if necessary 
00114        if(image.second->width!=info.width.getValue()||
00115           image.second->height!=info.height.getValue()||
00116           m_format!=info.format.getValue()||
00117           m_compression!=info.compression.getValue()){
00118               info.width.setValue(image.second->width);
00119               info.height.setValue(image.second->height);
00120               info.format.setValue(m_format);
00121               info.compression.setValue(m_compression);
00122               info.timestamp.now();
00123               publishInfo();
00124               //              m_format=info.format.getValue();
00125               // m_compression=info.compression.getValue();
00126               if(data.image){
00127                      delete [] data.image;
00128                      data.image=NULL;       
00129               }  
00130        }
00131 
00132        //allocate the image if necessary
00133 
00134        switch(m_format){
00135               
00136        case FORMAT_CHAR_111_YUV24:
00137        case FORMAT_CHAR_111_RGB:
00138 
00139               if(!data.image){
00140                      data.image = new unsigned char[image.second->width*image.second->height*3];
00141                      data.imagesize=sizeof(unsigned char)*image.second->width*image.second->height*3;
00142               }
00143               memcpy(data.image,image.second->imageData,data.imagesize);
00144 
00145               switch(m_compression){
00146               case COMPRESSION_RLE_HIGHQUALITY:
00147                      g_logdebug << "Compressing an image" << endl;
00148                      data.imagesize=GCM_rleEncodePixMed(data.image,image.second->height, image.second->width);
00149                      break;
00150               case COMPRESSION_RLE_LOWQUALITY:
00151                      data.imagesize=GCM_rleEncodePixLow(data.image,image.second->height, image.second->width);
00152                      break;
00153               case COMPRESSION_NULL:
00154               case COMPRESSION_UNCOMPRESSED:
00155               default:
00156                      break;
00157               }
00158        case FORMAT_CHAR_11_YUV422:
00159               if(!data.image){
00160                      data.image = new unsigned char[image.second->width*image.second->height*2];
00161                      data.imagesize=sizeof(unsigned char)*image.second->width*image.second->height*2;
00162               }
00163               memcpy(data.image,image.second->imageData,data.imagesize);
00164               switch(m_compression){
00165               case COMPRESSION_RLE_HIGHQUALITY:
00166                      data.imagesize=GCM_rleEncodeGreyMed(data.image,image.second->height, image.second->width*2);
00167                      break;
00168               case COMPRESSION_RLE_LOWQUALITY:
00169                      data.imagesize=GCM_rleEncodeGreyLow(data.image,image.second->height, image.second->width*2);
00170                      break;
00171               case COMPRESSION_NULL:
00172               case COMPRESSION_UNCOMPRESSED:
00173               default:
00174                      break;
00175               }
00176 
00177               break;
00178               
00179        case FORMAT_CHAR_1_GRAY:
00180               if(!data.image){
00181                      data.image = new unsigned char[image.second->width*image.second->height];
00182                      data.imagesize=sizeof(unsigned char)*image.second->width*image.second->height;
00183               }
00184               memcpy(data.image,image.second->imageData,data.imagesize);
00185               switch(m_compression){
00186               case COMPRESSION_RLE_HIGHQUALITY:
00187                      data.imagesize=GCM_rleEncodeGreyMed(data.image,image.second->height, image.second->width);
00188                      break;
00189               case COMPRESSION_RLE_LOWQUALITY:
00190                      data.imagesize=GCM_rleEncodeGreyLow(data.image,image.second->height, image.second->width);
00191                      break;
00192               case COMPRESSION_NULL:
00193               case COMPRESSION_UNCOMPRESSED:
00194               default:
00195                      break;
00196               }
00197               
00198               break;
00199               
00200        default:
00201               g_error("Unhandled format in ImageSource");
00202        }
00203        data.timestamp=image.first;
00204        publishData();
00205 }
00206 

Generated on Thu Feb 1 15:31:54 2007 for WURDE by  doxygen 1.5.1