[2] | 1 | // %flair:license{
|
---|
[15] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[2] | 4 | // %flair:license}
|
---|
| 5 | // created: 2012/03/20
|
---|
| 6 | // filename: cvimage.cpp
|
---|
| 7 | //
|
---|
| 8 | // author: Guillaume Sanahuja
|
---|
| 9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 10 | //
|
---|
| 11 | // version: $Id: $
|
---|
| 12 | //
|
---|
| 13 | // purpose: Class defining an image of kind IplImage
|
---|
| 14 | //
|
---|
| 15 | /*********************************************************************/
|
---|
| 16 |
|
---|
| 17 | #include "cvimage.h"
|
---|
| 18 |
|
---|
| 19 | using std::string;
|
---|
| 20 |
|
---|
[15] | 21 | namespace flair {
|
---|
| 22 | namespace core {
|
---|
[2] | 23 |
|
---|
[330] | 24 | char* (*cvimage::allocFunction)(ssize_t)=cvimage::DefaultAllocFunction;
|
---|
| 25 | void (*cvimage::freeFunction)(char*)=cvimage::DefaultFreeFunction;
|
---|
| 26 |
|
---|
[15] | 27 | cvimage::cvimage(const Object *parent, uint16_t width, uint16_t height,
|
---|
| 28 | Type::Format format, string name, bool allocate_data, int n)
|
---|
| 29 | : io_data(parent, name, n), dataType(width, height, format) {
|
---|
| 30 | this->allocate_data = allocate_data;
|
---|
[330] | 31 | //Printf("cvimage %s\n",ObjectName().c_str());
|
---|
[15] | 32 | if (allocate_data) {
|
---|
| 33 | switch (format) {
|
---|
| 34 | case Type::Format::YUYV:
|
---|
| 35 | case Type::Format::UYVY:
|
---|
[330] | 36 | buffer=allocFunction(width*height*2);
|
---|
[15] | 37 | break;
|
---|
| 38 | case Type::Format::BGR:
|
---|
[330] | 39 | buffer=allocFunction(width*height*3);
|
---|
[15] | 40 | break;
|
---|
[124] | 41 | case Type::Format::Gray:
|
---|
[330] | 42 | buffer=allocFunction(width*height*1);
|
---|
[15] | 43 | break;
|
---|
| 44 | default:
|
---|
[330] | 45 | Err("format not supported");
|
---|
[15] | 46 | break;
|
---|
[2] | 47 | }
|
---|
[15] | 48 | } else {
|
---|
| 49 | if (n > 1)
|
---|
| 50 | Err("number of samples!=1 not possible when not allocating data\n");
|
---|
| 51 | n = 1;
|
---|
| 52 | }
|
---|
[2] | 53 |
|
---|
[330] | 54 | SetPtrToCircle((void **)&buffer);
|
---|
[2] | 55 |
|
---|
[15] | 56 | if (n > 1)
|
---|
| 57 | prev = new cvimage(this, width, height, format, name, n - 1);
|
---|
[2] | 58 | }
|
---|
| 59 |
|
---|
| 60 | cvimage::~cvimage() {
|
---|
[15] | 61 | // printf("destructeur cvimage\n");
|
---|
[330] | 62 | if(allocate_data) freeFunction(buffer);
|
---|
[2] | 63 | }
|
---|
| 64 |
|
---|
[252] | 65 | void cvimage::RawRead(char *dst) const { Warn("non implementé\n"); }
|
---|
[2] | 66 |
|
---|
[330] | 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 |
|
---|
[2] | 85 | } // end namespace core
|
---|
| 86 | } // end namespace flair
|
---|