Changeset 330 in flair-src for trunk/lib/FlairCore/src/cvimage.cpp


Ignore:
Timestamp:
09/25/19 15:29:26 (5 years ago)
Author:
Sanahuja Guillaume
Message:

use less bandwidth in vprnlite

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairCore/src/cvimage.cpp

    r252 r330  
    2222namespace core {
    2323
     24char* (*cvimage::allocFunction)(ssize_t)=cvimage::DefaultAllocFunction;
     25void (*cvimage::freeFunction)(char*)=cvimage::DefaultFreeFunction;
     26   
    2427cvimage::cvimage(const Object *parent, uint16_t width, uint16_t height,
    2528                 Type::Format format, string name, bool allocate_data, int n)
    2629    : io_data(parent, name, n), dataType(width, height, format) {
    2730  this->allocate_data = allocate_data;
    28 
     31//Printf("cvimage %s\n",ObjectName().c_str());
    2932  if (allocate_data) {
    3033    switch (format) {
    3134    case Type::Format::YUYV:
    3235    case Type::Format::UYVY:
    33       img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 2);
     36      buffer=allocFunction(width*height*2);
    3437      break;
    3538    case Type::Format::BGR:
    36       img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
     39      buffer=allocFunction(width*height*3);
    3740      break;
    3841    case Type::Format::Gray:
    39       img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
     42      buffer=allocFunction(width*height*1);
    4043      break;
    4144    default:
    42       Err("format no supported");
     45      Err("format not supported");
    4346      break;
    4447    }
     
    4750      Err("number of samples!=1 not possible when not allocating data\n");
    4851    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     }
    6452  }
    6553
    66   SetPtrToCircle((void **)&img);
     54  SetPtrToCircle((void **)&buffer);
    6755
    6856  if (n > 1)
     
    7260cvimage::~cvimage() {
    7361  // printf("destructeur cvimage\n");
    74 
    75   cvReleaseImage(&img);
     62  if(allocate_data) freeFunction(buffer);
    7663}
    7764
    7865void cvimage::RawRead(char *dst) const { Warn("non implementé\n"); }
    7966
     67void cvimage::RegisterAllocFunction(char*(*func)(ssize_t size)) {
     68  if(allocFunction==DefaultAllocFunction) allocFunction=func;
     69}
     70
     71void cvimage::RegisterFreeFunction(void(*func)(char* buffer)) {
     72  if(freeFunction==DefaultFreeFunction) freeFunction=func;
     73}
     74
     75char* cvimage::DefaultAllocFunction(ssize_t size){
     76  Printf("default alloc %i\n",size);
     77  return (char*)malloc(size);
     78}
     79
     80void cvimage::DefaultFreeFunction(char* buffer){
     81  Printf("default free\n");
     82  free(buffer);
     83}
     84
    8085} // end namespace core
    8186} // end namespace flair
Note: See TracChangeset for help on using the changeset viewer.