Changeset 330 in flair-src for trunk/lib/FlairCore/src/cvimage.cpp
- Timestamp:
- Sep 25, 2019, 3:29:26 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairCore/src/cvimage.cpp
r252 r330 22 22 namespace core { 23 23 24 char* (*cvimage::allocFunction)(ssize_t)=cvimage::DefaultAllocFunction; 25 void (*cvimage::freeFunction)(char*)=cvimage::DefaultFreeFunction; 26 24 27 cvimage::cvimage(const Object *parent, uint16_t width, uint16_t height, 25 28 Type::Format format, string name, bool allocate_data, int n) 26 29 : io_data(parent, name, n), dataType(width, height, format) { 27 30 this->allocate_data = allocate_data; 28 31 //Printf("cvimage %s\n",ObjectName().c_str()); 29 32 if (allocate_data) { 30 33 switch (format) { 31 34 case Type::Format::YUYV: 32 35 case Type::Format::UYVY: 33 img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U,2);36 buffer=allocFunction(width*height*2); 34 37 break; 35 38 case Type::Format::BGR: 36 img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U,3);39 buffer=allocFunction(width*height*3); 37 40 break; 38 41 case Type::Format::Gray: 39 img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U,1);42 buffer=allocFunction(width*height*1); 40 43 break; 41 44 default: 42 Err("format no supported");45 Err("format not supported"); 43 46 break; 44 47 } … … 47 50 Err("number of samples!=1 not possible when not allocating data\n"); 48 51 n = 1; 49 switch (format) {50 case Type::Format::YUYV:51 case Type::Format::UYVY:52 img = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 2);53 break;54 case Type::Format::BGR:55 img = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 3);56 break;57 case Type::Format::Gray:58 img = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 1);59 break;60 default:61 Err("format no supported");62 break;63 }64 52 } 65 53 66 SetPtrToCircle((void **)& img);54 SetPtrToCircle((void **)&buffer); 67 55 68 56 if (n > 1) … … 72 60 cvimage::~cvimage() { 73 61 // printf("destructeur cvimage\n"); 74 75 cvReleaseImage(&img); 62 if(allocate_data) freeFunction(buffer); 76 63 } 77 64 78 65 void cvimage::RawRead(char *dst) const { Warn("non implementé\n"); } 79 66 67 void cvimage::RegisterAllocFunction(char*(*func)(ssize_t size)) { 68 if(allocFunction==DefaultAllocFunction) allocFunction=func; 69 } 70 71 void cvimage::RegisterFreeFunction(void(*func)(char* buffer)) { 72 if(freeFunction==DefaultFreeFunction) freeFunction=func; 73 } 74 75 char* cvimage::DefaultAllocFunction(ssize_t size){ 76 Printf("default alloc %i\n",size); 77 return (char*)malloc(size); 78 } 79 80 void cvimage::DefaultFreeFunction(char* buffer){ 81 Printf("default free\n"); 82 free(buffer); 83 } 84 80 85 } // end namespace core 81 86 } // end namespace flair
Note:
See TracChangeset
for help on using the changeset viewer.