source: flair-src/trunk/lib/FlairCore/src/Image.h@ 348

Last change on this file since 348 was 338, checked in by Sanahuja Guillaume, 5 years ago

remove opencv dep

File size: 2.9 KB
Line 
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/*!
6 * \file Image.h
7 * \brief Class defining an image
8 * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253
9 * \date 2012/03/20
10 * \version 4.0
11 */
12
13#ifndef IMAGE_H
14#define IMAGE_H
15
16#include <io_data.h>
17#include <stdint.h>
18
19
20namespace flair {
21namespace sensor {
22class V4LCamera;
23}
24}
25
26
27namespace flair {
28namespace core {
29/*! \class Image
30*
31* \brief Class defining an image
32*
33*
34*/
35class Image : public io_data {
36 public:
37 friend class flair::sensor::V4LCamera;
38 class Type : public DataType {
39 public:
40 /*!
41 \enum Format_t
42 \brief Picture formats
43 */
44 enum class Format {
45 YUYV, /*!< YUYV 16 bits */
46 UYVY, /*!< UYVY 16 bits */
47 BGR, /*!< BGR 24 bits */
48 Gray, /*!< gray 8 bits */
49 };
50 Type(uint16_t _width, uint16_t _height, Format _format)
51 : width(_width), height(_height), format(_format) {}
52
53 size_t GetSize() const {
54 size_t pixelSize;
55 switch (format) {
56 case Format::Gray:
57 pixelSize = 1;
58 break;
59 case Format::YUYV:
60 case Format::UYVY:
61 pixelSize = 2;
62 break;
63 case Format::BGR:
64 pixelSize = 3;
65 break;
66 default:
67 pixelSize = 0; // TODO should throw an exception instead
68 }
69 return pixelSize * width * height;
70 }
71 std::string GetDescription() const { return "cv image"; };
72
73 Format GetFormat() const { return format; };
74 uint16_t GetWidth() const { return width; };
75 uint16_t GetHeight() const { return height; };
76
77 private:
78 uint16_t width;
79 uint16_t height;
80 Format format;
81 };
82
83 /*!
84 * \brief Constructor
85 *
86 * Construct an io_data representing an image.
87 *
88 * \param parent parent
89 * \param width image width
90 * \param height image height
91 * \param name name
92 * \param allocate_data if true, image data is allocated; otherwise
93 *img->imagedata must be changed
94 * \param n number of samples
95 */
96 Image(const Object *parent, uint16_t width, uint16_t height,
97 Type::Format format, std::string name = "", bool allocate_data = true,
98 int n = 1);
99
100 /*!
101 * \brief Destructor
102 *
103 */
104 ~Image();
105
106
107 char *buffer;
108
109 Type const &GetDataType() const { return dataType; };
110
111 static void RegisterAllocFunction(char*(*func)(ssize_t size));
112 static void RegisterFreeFunction(void(*func)(char* buffer));
113
114private:
115 /*!
116 * \brief Raw read datas
117 *
118 * Reimplemented from io_data. \n
119 * See io_data::RawRead.
120 *
121 * \param dst destination buffer
122 */
123 void RawRead(char *dst) const;
124
125 bool allocate_data;
126 Type dataType;
127 static char* (*allocFunction)(ssize_t);
128 static void (*freeFunction)(char*);
129 static char* DefaultAllocFunction(ssize_t size);
130 static void DefaultFreeFunction(char* buffer);
131
132};
133
134} // end namespace core
135} // end namespace flair
136
137#endif // IMAGE_H
Note: See TracBrowser for help on using the repository browser.