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 <cvimage.h>
|
---|
16 | #include <typeinfo>
|
---|
17 |
|
---|
18 | using std::string;
|
---|
19 | using namespace flair::core;
|
---|
20 |
|
---|
21 | namespace flair { namespace filter {
|
---|
22 |
|
---|
23 | CvtColor::CvtColor(const core::IODevice* parent,std::string name,Conversion_t conversion) : IODevice(parent,name),output(0) {
|
---|
24 | this->conversion=conversion;
|
---|
25 |
|
---|
26 | switch(conversion) {
|
---|
27 | case Conversion_t::ToGray:
|
---|
28 | try{
|
---|
29 | cvimage::Type const &imageType=dynamic_cast<cvimage::Type const &>(parent->GetOutputDataType());
|
---|
30 | output=new cvimage(this,imageType.GetWidth(),imageType.GetHeight(),cvimage::Type::Format::Gray,"conversion",true,2);
|
---|
31 |
|
---|
32 | } catch(std::bad_cast& bc) {
|
---|
33 | Err("io type mismatch\n");
|
---|
34 | }
|
---|
35 | break;
|
---|
36 | default:
|
---|
37 | Err("conversion not supported\n");
|
---|
38 | }
|
---|
39 |
|
---|
40 | SetIsReady(true);
|
---|
41 | }
|
---|
42 |
|
---|
43 | CvtColor::~CvtColor(void) {}
|
---|
44 |
|
---|
45 | cvimage* CvtColor::Output(void) {
|
---|
46 | return output;
|
---|
47 |
|
---|
48 | }
|
---|
49 |
|
---|
50 | DataType const &CvtColor::GetOutputDataType() const {
|
---|
51 | if(output!=NULL) {
|
---|
52 | return output->GetDataType();
|
---|
53 | } else {
|
---|
54 | return dummyType;
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | void CvtColor::UpdateFrom(const io_data *data) {
|
---|
59 | IplImage *img=((cvimage*)data)->img;
|
---|
60 |
|
---|
61 | data->GetMutex();
|
---|
62 | output->GetMutex();
|
---|
63 |
|
---|
64 | switch(conversion) {
|
---|
65 | case Conversion_t::ToGray:
|
---|
66 | switch(((cvimage*)data)->GetDataType().GetFormat()) {
|
---|
67 | case cvimage::Type::Format::YUYV:
|
---|
68 | //dspCvtColor(img,output->img,DSP_YUYV2GRAY);
|
---|
69 | break;
|
---|
70 | case cvimage::Type::Format::UYVY:
|
---|
71 | //dspCvtColor(img,output->img,DSP_UYVY2GRAY);
|
---|
72 | break;
|
---|
73 | case cvimage::Type::Format::BGR:
|
---|
74 | //dspCvtColor(img,output->img,DSP_BGR2GRAY);
|
---|
75 | break;
|
---|
76 | default:
|
---|
77 | Err("input format not supported\n");
|
---|
78 | }
|
---|
79 | break;
|
---|
80 | default:
|
---|
81 | Err("conversion not supported\n");
|
---|
82 | }
|
---|
83 |
|
---|
84 | output->ReleaseMutex();
|
---|
85 | data->ReleaseMutex();
|
---|
86 |
|
---|
87 | output->SetDataTime(data->DataTime());
|
---|
88 | ProcessUpdate(output);
|
---|
89 | }
|
---|
90 |
|
---|
91 | } // end namespace filter
|
---|
92 | } // end namespace flair
|
---|