[122] | 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) {
|
---|
[124] | 27 | case Conversion_t::ToGray:
|
---|
[122] | 28 | try{
|
---|
| 29 | cvimage::Type const &imageType=dynamic_cast<cvimage::Type const &>(parent->GetOutputDataType());
|
---|
[124] | 30 | output=new cvimage(this,imageType.GetWidth(),imageType.GetHeight(),cvimage::Type::Format::Gray,"conversion",true,2);
|
---|
[122] | 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 |
|
---|
| 41 | CvtColor::~CvtColor(void) {}
|
---|
| 42 |
|
---|
| 43 | cvimage* CvtColor::Output(void) {
|
---|
| 44 | return output;
|
---|
| 45 |
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | DataType const &CvtColor::GetOutputDataType() const {
|
---|
| 49 | if(output!=NULL) {
|
---|
| 50 | return output->GetDataType();
|
---|
| 51 | } else {
|
---|
| 52 | return dummyType;
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | void CvtColor::UpdateFrom(const io_data *data) {
|
---|
| 57 | IplImage *img=((cvimage*)data)->img;
|
---|
| 58 |
|
---|
| 59 | data->GetMutex();
|
---|
| 60 | output->GetMutex();
|
---|
| 61 |
|
---|
| 62 | switch(conversion) {
|
---|
[124] | 63 | case Conversion_t::ToGray:
|
---|
[122] | 64 | switch(((cvimage*)data)->GetDataType().GetFormat()) {
|
---|
| 65 | case cvimage::Type::Format::YUYV:
|
---|
| 66 | //dspCvtColor(img,output->img,DSP_YUYV2GRAY);
|
---|
| 67 | break;
|
---|
| 68 | case cvimage::Type::Format::UYVY:
|
---|
| 69 | //dspCvtColor(img,output->img,DSP_UYVY2GRAY);
|
---|
| 70 | break;
|
---|
| 71 | case cvimage::Type::Format::BGR:
|
---|
| 72 | //dspCvtColor(img,output->img,DSP_BGR2GRAY);
|
---|
| 73 | break;
|
---|
| 74 | default:
|
---|
| 75 | Err("input format not supported\n");
|
---|
| 76 | }
|
---|
| 77 | break;
|
---|
| 78 | default:
|
---|
| 79 | Err("conversion not supported\n");
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | output->ReleaseMutex();
|
---|
| 83 | data->ReleaseMutex();
|
---|
| 84 |
|
---|
| 85 | output->SetDataTime(data->DataTime());
|
---|
| 86 | ProcessUpdate(output);
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | } // end namespace filter
|
---|
| 90 | } // end namespace flair
|
---|