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

Last change on this file since 326 was 326, 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 <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 */
58 output->GetMutex();/*
59 outIplImage->width=output->GetDataType().GetWidth();
60 outIplImage->height=output->GetDataType().GetHeight();
61 outIplImage->imageData=output->buffer;
62*/
63 switch(conversion) {
64 case flair::filter::CvtColor::Conversion_t::ToGray:
65 switch(((Image*)data)->GetDataType().GetFormat()) {
66 case Image::Type::Format::YUYV:
67 //dspCvtColor(inIplImage,outIplImage,DSP_YUYV2GRAY);
68 break;
69 case Image::Type::Format::UYVY:
70 //dspCvtColor(inIplImage,outIplImage,DSP_UYVY2GRAY);
71 break;
72 case Image::Type::Format::BGR:
73 //dspCvtColor(inIplImage,outIplImage,DSP_BGR2GRAY);
74 break;
75 default:
76 self->Err("input format not supported\n");
77 }
78 break;
79 default:
80 self->Err("conversion not supported\n");
81 }
82
83 output->ReleaseMutex();
84 data->ReleaseMutex();
85
86 output->SetDataTime(data->DataTime());
87 }
88 };
89
90 Image *output;
91
92private:
93 flair::filter::CvtColor::Conversion_t conversion;
94 //IplImage *inIplImage,*outIplImage;
95 flair::filter::CvtColor *self;
96};
97
98
99namespace flair { namespace filter {
100
101CvtColor::CvtColor(const core::IODevice* parent,std::string name,Conversion_t conversion) : IODevice(parent,name) {
102 pimpl_=new CvtColor_impl(this,conversion);
103}
104
105CvtColor::~CvtColor(void) {
106 delete pimpl_;
107}
108
109Image* CvtColor::Output(void) {
110 return pimpl_->output;
111
112}
113
114DataType const &CvtColor::GetOutputDataType() const {
115 if(pimpl_->output!=NULL) {
116 return pimpl_->output->GetDataType();
117 } else {
118 return dummyType;
119 }
120}
121
122void CvtColor::UpdateFrom(const io_data *data) {
123 pimpl_->UpdateFrom(data);
124 if(pimpl_->output!=NULL) ProcessUpdate(pimpl_->output);
125
126}
127
128} // end namespace filter
129} // end namespace flair
Note: See TracBrowser for help on using the repository browser.