source: flair-src/trunk/lib/FlairVisionFilter/src/CvtColor.cpp@ 419

Last change on this file since 419 was 338, checked in by Sanahuja Guillaume, 3 years ago

remove opencv dep

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