source: flair-src/branches/sanscv/lib/FlairVisionFilter/src/CvtColor.cpp@ 325

Last change on this file since 325 was 325, checked in by Sanahuja Guillaume, 5 years ago

using pimpl

File size: 3.8 KB
Line 
1// created: 2014/07/17
2// filename: CvtColor.cpp
3//
4// author: Guillaume Sanahuja
5// Copyright Heudiasyc UMR UTC/CNRS 7253
6//
7// version: $Id: $
8//
9// purpose: Image color conversion
10//
11//
12/*********************************************************************/
13
14#include "CvtColor.h"
15#include "VisionFilter.h"
16#include <Image.h>
17//#include <dspcv_gpp.h>
18#include <typeinfo>
19
20using std::string;
21using namespace flair::core;
22
23class CvtColor_impl {
24public:
25 CvtColor_impl(flair::filter::CvtColor *self,flair::filter::CvtColor::Conversion_t conversion):output(0) {
26 this->conversion=conversion;
27 this->self=self;
28
29 switch(conversion) {
30 case flair::filter::CvtColor::Conversion_t::ToGray:
31 try{
32 Image::Type const &imageType=dynamic_cast<Image::Type const &>(((IODevice*)(self->Parent()))->GetOutputDataType());
33 output=new Image(self,imageType.GetWidth(),imageType.GetHeight(),Image::Type::Format::Gray,"conversion",true,2);
34 //inIplImage = (IplImage*)AllocFunction(sizeof(IplImage));
35 //outIplImage = (IplImage*)AllocFunction(sizeof(IplImage));
36 } catch(std::bad_cast& bc) {
37 self->Err("io type mismatch\n");
38 }
39 break;
40 default:
41 self->Err("conversion not supported\n");
42 }
43 }
44
45 ~CvtColor_impl() {
46 //FreeFunction((char*)(inIplImage));
47 //FreeFunction((char*)(outIplImage));
48 }
49
50 void UpdateFrom(const io_data *data){
51 Image *img=(Image*)data;
52
53 if(output!=NULL) {
54 data->GetMutex();/*
55 inIplImage->width=img->GetDataType().GetWidth();
56 inIplImage->height=img->GetDataType().GetHeight();
57 inIplImage->imageData=img->buffer;
58 */
59 output->GetMutex();/*
60 outIplImage->width=output->GetDataType().GetWidth();
61 outIplImage->height=output->GetDataType().GetHeight();
62 outIplImage->imageData=output->buffer;
63*/
64 switch(conversion) {
65 case flair::filter::CvtColor::Conversion_t::ToGray:
66 switch(((Image*)data)->GetDataType().GetFormat()) {
67 case Image::Type::Format::YUYV:
68 //dspCvtColor(inIplImage,outIplImage,DSP_YUYV2GRAY);
69 break;
70 case Image::Type::Format::UYVY:
71 //dspCvtColor(inIplImage,outIplImage,DSP_UYVY2GRAY);
72 break;
73 case Image::Type::Format::BGR:
74 //dspCvtColor(inIplImage,outIplImage,DSP_BGR2GRAY);
75 break;
76 default:
77 self->Err("input format not supported\n");
78 }
79 break;
80 default:
81 self->Err("conversion not supported\n");
82 }
83
84 output->ReleaseMutex();
85 data->ReleaseMutex();
86
87 output->SetDataTime(data->DataTime());
88 }
89 };
90
91 Image *output;
92
93private:
94 flair::filter::CvtColor::Conversion_t conversion;
95 //IplImage *inIplImage,*outIplImage;
96 flair::filter::CvtColor *self;
97};
98
99
100namespace flair { namespace filter {
101
102CvtColor::CvtColor(const core::IODevice* parent,std::string name,Conversion_t conversion) : IODevice(parent,name) {
103 pimpl_=new CvtColor_impl(this,conversion);
104}
105
106CvtColor::~CvtColor(void) {
107 delete pimpl_;
108}
109
110Image* CvtColor::Output(void) {
111 return pimpl_->output;
112
113}
114
115DataType const &CvtColor::GetOutputDataType() const {
116 if(pimpl_->output!=NULL) {
117 return pimpl_->output->GetDataType();
118 } else {
119 return dummyType;
120 }
121}
122
123void CvtColor::UpdateFrom(const io_data *data) {
124 pimpl_->UpdateFrom(data);
125 if(pimpl_->output!=NULL) ProcessUpdate(pimpl_->output);
126
127}
128
129} // end namespace filter
130} // end namespace flair
Note: See TracBrowser for help on using the repository browser.