Index: trunk/lib/FlairVisionFilter/src/CvtColor.cpp
===================================================================
--- trunk/lib/FlairVisionFilter/src/CvtColor.cpp	(revision 330)
+++ trunk/lib/FlairVisionFilter/src/CvtColor.cpp	(revision 338)
@@ -13,5 +13,6 @@
 
 #include "CvtColor.h"
-#include <cvimage.h>
+#include "VisionFilter.h"
+#include <Image.h>
 #include <typeinfo>
 
@@ -19,36 +20,101 @@
 using namespace flair::core;
 
+class CvtColor_impl {
+public:
+    CvtColor_impl(flair::filter::CvtColor *self,flair::filter::CvtColor::Conversion_t conversion):output(0) {
+        this->conversion=conversion;
+        this->self=self;
+
+        switch(conversion) {
+        case flair::filter::CvtColor::Conversion_t::ToGray:
+            try{
+                Image::Type const &imageType=dynamic_cast<Image::Type const &>(((IODevice*)(self->Parent()))->GetOutputDataType());
+                output=new Image(self,imageType.GetWidth(),imageType.GetHeight(),Image::Type::Format::Gray,"conversion",true,2);
+                //inIplImage = (IplImage*)AllocFunction(sizeof(IplImage));
+                //outIplImage = (IplImage*)AllocFunction(sizeof(IplImage));
+            } catch(std::bad_cast& bc) {
+                self->Err("io type mismatch\n");
+            }
+            break;
+        default:
+            self->Err("conversion not supported\n");
+        }
+    }
+
+    ~CvtColor_impl() {
+        //FreeFunction((char*)(inIplImage));
+        //FreeFunction((char*)(outIplImage));
+    }
+    
+    void UpdateFrom(const io_data *data){
+        Image *img=(Image*)data;
+
+        if(output!=NULL) {
+            data->GetMutex();/*
+            inIplImage->width=img->GetDataType().GetWidth();
+            inIplImage->height=img->GetDataType().GetHeight();
+            inIplImage->imageData=img->buffer;
+            inIplImage->imageSize=img->GetDataType().GetSize();
+            */
+            output->GetMutex();/*
+            outIplImage->width=output->GetDataType().GetWidth();
+            outIplImage->height=output->GetDataType().GetHeight();
+            outIplImage->imageData=output->buffer;
+            outIplImage->imageSize=output->GetDataType().GetSize();
+*/
+            switch(conversion) {
+            case flair::filter::CvtColor::Conversion_t::ToGray:
+                switch(((Image*)data)->GetDataType().GetFormat()) {
+                case Image::Type::Format::YUYV:
+                    //dspCvtColor(inIplImage,outIplImage,DSP_YUYV2GRAY);
+                    break;
+                case Image::Type::Format::UYVY:
+                    //dspCvtColor(inIplImage,outIplImage,DSP_UYVY2GRAY);
+                    break;
+                case Image::Type::Format::BGR:
+                    //dspCvtColor(inIplImage,outIplImage,DSP_BGR2GRAY);
+                    break;
+                default:
+                    self->Err("input format not supported\n");
+                }
+                break;
+            default:
+                self->Err("conversion not supported\n");
+            }
+
+            output->ReleaseMutex();
+            data->ReleaseMutex();
+
+            output->SetDataTime(data->DataTime());
+        }
+    };
+    
+    Image *output;
+
+private:
+    flair::filter::CvtColor::Conversion_t conversion;
+    //IplImage *inIplImage,*outIplImage;
+    flair::filter::CvtColor *self;
+};
+
+
 namespace flair { namespace filter {
 
-CvtColor::CvtColor(const core::IODevice* parent,std::string name,Conversion_t conversion) : IODevice(parent,name),output(0) {
-    this->conversion=conversion;
-
-    switch(conversion) {
-    case Conversion_t::ToGray:
-        try{
-            cvimage::Type const &imageType=dynamic_cast<cvimage::Type const &>(parent->GetOutputDataType());
-            output=new cvimage(this,imageType.GetWidth(),imageType.GetHeight(),cvimage::Type::Format::Gray,"conversion",true,2);
-
-        } catch(std::bad_cast& bc) {
-            Err("io type mismatch\n");
-        }
-        break;
-    default:
-        Err("conversion not supported\n");
-    }
-    
-    SetIsReady(true);
+CvtColor::CvtColor(const core::IODevice* parent,std::string name,Conversion_t conversion) : IODevice(parent,name) {
+    pimpl_=new CvtColor_impl(this,conversion);
 }
 
-CvtColor::~CvtColor(void) {}
+CvtColor::~CvtColor(void) {
+    delete pimpl_;
+}
 
-cvimage* CvtColor::Output(void) {
-    return output;
+Image* CvtColor::Output(void) {
+    return pimpl_->output;
 
 }
 
 DataType const &CvtColor::GetOutputDataType() const {
-    if(output!=NULL) {
-        return output->GetDataType();
+    if(pimpl_->output!=NULL) {
+        return pimpl_->output->GetDataType();
     } else {
         return dummyType;
@@ -57,34 +123,7 @@
 
 void CvtColor::UpdateFrom(const io_data *data) {
-    cvimage *img=(cvimage*)data;
-
-    data->GetMutex();
-    output->GetMutex();
-
-    switch(conversion) {
-    case Conversion_t::ToGray:
-        switch(img->GetDataType().GetFormat()) {
-        case cvimage::Type::Format::YUYV:
-            //dspCvtColor(img,output->img,DSP_YUYV2GRAY);
-            break;
-        case cvimage::Type::Format::UYVY:
-            //dspCvtColor(img,output->img,DSP_UYVY2GRAY);
-            break;
-        case cvimage::Type::Format::BGR:
-            //dspCvtColor(img,output->img,DSP_BGR2GRAY);
-            break;
-        default:
-            Err("input format not supported\n");
-        }
-        break;
-    default:
-        Err("conversion not supported\n");
-    }
-
-    output->ReleaseMutex();
-    data->ReleaseMutex();
-
-    output->SetDataTime(data->DataTime());
-    ProcessUpdate(output);
+    pimpl_->UpdateFrom(data);
+    if(pimpl_->output!=NULL) ProcessUpdate(pimpl_->output);
+    
 }
 
