[324] | 1 | // %flair:license{
|
---|
| 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
| 4 | // %flair:license}
|
---|
| 5 | // created: 2012/03/20
|
---|
| 6 | // filename: Image.cpp
|
---|
| 7 | //
|
---|
| 8 | // author: Guillaume Sanahuja
|
---|
| 9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 10 | //
|
---|
| 11 | // version: $Id: $
|
---|
| 12 | //
|
---|
| 13 | // purpose: Class defining an image
|
---|
| 14 | //
|
---|
| 15 | /*********************************************************************/
|
---|
| 16 |
|
---|
| 17 | #include "Image.h"
|
---|
| 18 |
|
---|
| 19 | using std::string;
|
---|
| 20 |
|
---|
| 21 | namespace flair {
|
---|
| 22 | namespace core {
|
---|
| 23 |
|
---|
| 24 | char* (*Image::allocFunction)(ssize_t)=Image::DefaultAllocFunction;
|
---|
| 25 | void (*Image::freeFunction)(char*)=Image::DefaultFreeFunction;
|
---|
| 26 |
|
---|
| 27 | Image::Image(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;
|
---|
[326] | 31 |
|
---|
[324] | 32 | if (allocate_data) {
|
---|
| 33 | switch (format) {
|
---|
| 34 | case Type::Format::YUYV:
|
---|
| 35 | case Type::Format::UYVY:
|
---|
| 36 | buffer=allocFunction(width*height*2);
|
---|
| 37 | break;
|
---|
| 38 | case Type::Format::BGR:
|
---|
| 39 | buffer=allocFunction(width*height*3);
|
---|
| 40 | break;
|
---|
| 41 | case Type::Format::Gray:
|
---|
| 42 | buffer=allocFunction(width*height*1);
|
---|
| 43 | break;
|
---|
| 44 | default:
|
---|
| 45 | Err("format not supported");
|
---|
| 46 | break;
|
---|
| 47 | }
|
---|
| 48 | } else {
|
---|
| 49 | if (n > 1)
|
---|
| 50 | Err("number of samples!=1 not possible when not allocating data\n");
|
---|
| 51 | n = 1;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | SetPtrToCircle((void **)&buffer);
|
---|
| 55 |
|
---|
| 56 | if (n > 1)
|
---|
| 57 | prev = new Image(this, width, height, format, name, n - 1);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | Image::~Image() {
|
---|
| 61 | if(allocate_data) freeFunction(buffer);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | void Image::RawRead(char *dst) const { Warn("non implementé\n"); }
|
---|
| 65 |
|
---|
| 66 | void Image::RegisterAllocFunction(char*(*func)(ssize_t size)) {
|
---|
| 67 | if(allocFunction==DefaultAllocFunction) allocFunction=func;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | void Image::RegisterFreeFunction(void(*func)(char* buffer)) {
|
---|
| 71 | if(freeFunction==DefaultFreeFunction) freeFunction=func;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | char* Image::DefaultAllocFunction(ssize_t size){
|
---|
| 75 | return (char*)malloc(size);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | void Image::DefaultFreeFunction(char* buffer){
|
---|
| 79 | free(buffer);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | } // end namespace core
|
---|
| 83 | } // end namespace flair
|
---|