Libargus API Libargus Camera API

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Types.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2016-2018, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of NVIDIA CORPORATION nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 /**
30 * @file
31 * <b>Libargus API: Types API</b>
32 *
33 * @b Description: Defines the basic types that are used by the API.
34 */
35
36 #ifndef _ARGUS_TYPES_H
37 #define _ARGUS_TYPES_H
38
39 #include <stdint.h>
40 #include <vector>
41 #include <string>
42 #include <assert.h>
43
44 #include <EGL/egl.h>
45 #include <EGL/eglext.h>
46
47 // Some versions of the Xlib.h header file define 'Status' to 'int'.
48 // This collides with the libargus 'Status' type.
49 // If 'Status' is defined then undefine it and use a typedef instead.
50 #ifdef Status
51 #undef Status
52 typedef int Status;
53 #endif // Status
54
55 namespace Argus
56 {
57
58 /*
59 * Forward declaration of standard objects
60 */
61 class CameraDevice;
62 class CameraProvider;
63 class CaptureSession;
64 class CaptureMetadata;
65 class CaptureMetadataContainer;
66 class Event;
67 class EventQueue;
68 class InputStream;
69 class OutputStream;
70 class OutputStreamSettings;
71 class Request;
72 class SensorMode;
73
74 /*
75 * Forward declaration of standard interfaces
76 */
77 class ICameraProperties;
78 class ICameraProvider;
79 class ICaptureSession;
80 class IAutoControlSettings;
81 class IRequest;
82 class IStream;
83 class IStreamSettings;
84
85 /**
86 * Constant used for infinite timeouts.
87 */
88 const uint64_t TIMEOUT_INFINITE = 0xFFFFFFFFFFFFFFFF;
89
90 /**
91 * Status values returned by API function calls.
92 */
93 enum Status
94 {
95 /// Function succeeded.
96 STATUS_OK = 0,
97
98 /// The set of parameters passed was invalid.
99 STATUS_INVALID_PARAMS = 1,
100
101 /// The requested settings are invalid.
102 STATUS_INVALID_SETTINGS = 2,
103
104 /// The requested device is unavailable.
105 STATUS_UNAVAILABLE = 3,
106
107 /// An operation failed because of insufficient mavailable memory.
108 STATUS_OUT_OF_MEMORY = 4,
109
110 /// This method has not been implemented.
111 STATUS_UNIMPLEMENTED = 5,
112
113 /// An operation timed out.
114 STATUS_TIMEOUT = 6,
115
116 /// The capture was aborted. @see ICaptureSession::cancelRequests()
117 STATUS_CANCELLED = 7,
118
119 /// The stream or other resource has been disconnected.
120 STATUS_DISCONNECTED = 8,
121
122 /// End of stream, used by Stream objects.
123 STATUS_END_OF_STREAM = 9,
124
125 // Number of elements in this enum.
126 STATUS_COUNT
127 };
128
129 /**
130 * Color channel constants for Bayer data.
131 */
132 enum BayerChannel
133 {
134 BAYER_CHANNEL_R,
135 BAYER_CHANNEL_G_EVEN,
136 BAYER_CHANNEL_G_ODD,
137 BAYER_CHANNEL_B,
138
139 BAYER_CHANNEL_COUNT
140 };
141
142 /**
143 * Coordinates used for 2D and 3D points.
144 */
145 enum Coordinate
146 {
147 COORDINATE_X,
148 COORDINATE_Y,
149 COORDINATE_Z,
150
151 COORDINATE_2D_COUNT = 2,
152 COORDINATE_3D_COUNT = 3
153 };
154
155 /**
156 * Color channel constants for RGB data.
157 */
158 enum RGBChannel
159 {
160 RGB_CHANNEL_R,
161 RGB_CHANNEL_G,
162 RGB_CHANNEL_B,
163
164 RGB_CHANNEL_COUNT
165 };
166
167 /**
168 * Auto Exposure Anti-Banding Modes.
169 */
170 DEFINE_NAMED_UUID_CLASS(AeAntibandingMode);
171 DEFINE_UUID(AeAntibandingMode, AE_ANTIBANDING_MODE_OFF, AD1E5560,9C16,11E8,B568,18,00,20,0C,9A,66);
172 DEFINE_UUID(AeAntibandingMode, AE_ANTIBANDING_MODE_AUTO, AD1E5561,9C16,11E8,B568,18,00,20,0C,9A,66);
173 DEFINE_UUID(AeAntibandingMode, AE_ANTIBANDING_MODE_50HZ, AD1E5562,9C16,11E8,B568,18,00,20,0C,9A,66);
174 DEFINE_UUID(AeAntibandingMode, AE_ANTIBANDING_MODE_60HZ, AD1E5563,9C16,11E8,B568,18,00,20,0C,9A,66);
175
176 /**
177 * Auto Exposure States.
178 */
179 DEFINE_NAMED_UUID_CLASS(AeState);
180 DEFINE_UUID(AeState, AE_STATE_INACTIVE, D2EBEA50,9C16,11E8,B568,18,00,20,0C,9A,66);
181 DEFINE_UUID(AeState, AE_STATE_SEARCHING, D2EBEA51,9C16,11E8,B568,18,00,20,0C,9A,66);
182 DEFINE_UUID(AeState, AE_STATE_CONVERGED, D2EBEA52,9C16,11E8,B568,18,00,20,0C,9A,66);
183 DEFINE_UUID(AeState, AE_STATE_FLASH_REQUIRED, D2EBEA53,9C16,11E8,B568,18,00,20,0C,9A,66);
184 DEFINE_UUID(AeState, AE_STATE_TIMEOUT, D2EBEA54,9C16,11E8,B568,18,00,20,0C,9A,66);
185
186 /**
187 * Auto White Balance (AWB) Modes.
188 */
189 DEFINE_NAMED_UUID_CLASS(AwbMode);
190 DEFINE_UUID(AwbMode, AWB_MODE_OFF, FB3F365A,CC62,11E5,9956,62,56,62,87,07,61);
191 DEFINE_UUID(AwbMode, AWB_MODE_AUTO, FB3F365B,CC62,11E5,9956,62,56,62,87,07,61);
192 DEFINE_UUID(AwbMode, AWB_MODE_INCANDESCENT, FB3F365C,CC62,11E5,9956,62,56,62,87,07,61);
193 DEFINE_UUID(AwbMode, AWB_MODE_FLUORESCENT, FB3F365D,CC62,11E5,9956,62,56,62,87,07,61);
194 DEFINE_UUID(AwbMode, AWB_MODE_WARM_FLUORESCENT, FB3F365E,CC62,11E5,9956,62,56,62,87,07,61);
195 DEFINE_UUID(AwbMode, AWB_MODE_DAYLIGHT, FB3F365F,CC62,11E5,9956,62,56,62,87,07,61);
196 DEFINE_UUID(AwbMode, AWB_MODE_CLOUDY_DAYLIGHT, FB3F3660,CC62,11E5,9956,62,56,62,87,07,61);
197 DEFINE_UUID(AwbMode, AWB_MODE_TWILIGHT, FB3F3661,CC62,11E5,9956,62,56,62,87,07,61);
198 DEFINE_UUID(AwbMode, AWB_MODE_SHADE, FB3F3662,CC62,11E5,9956,62,56,62,87,07,61);
199 DEFINE_UUID(AwbMode, AWB_MODE_MANUAL, 20FB45DA,C49F,4293,AB02,13,3F,8C,CA,DD,69);
200
201 /**
202 * Auto White-Balance States.
203 */
204 DEFINE_NAMED_UUID_CLASS(AwbState);
205 DEFINE_UUID(AwbState, AWB_STATE_INACTIVE, E33CDB30,9C16,11E8,B568,18,00,20,0C,9A,66);
206 DEFINE_UUID(AwbState, AWB_STATE_SEARCHING, E33CDB31,9C16,11E8,B568,18,00,20,0C,9A,66);
207 DEFINE_UUID(AwbState, AWB_STATE_CONVERGED, E33CDB32,9C16,11E8,B568,18,00,20,0C,9A,66);
208 DEFINE_UUID(AwbState, AWB_STATE_LOCKED, E33CDB33,9C16,11E8,B568,18,00,20,0C,9A,66);
209
210 /**
211 * A CaptureIntent may be provided during capture request creation to initialize the new
212 * Request with default settings that are appropriate for captures of the given intent.
213 * For example, a PREVIEW intent may disable post-processing in order to reduce latency
214 * and resource usage while a STILL_CAPTURE intent will enable post-processing in order
215 * to optimize still image quality.
216 */
217 DEFINE_NAMED_UUID_CLASS(CaptureIntent);
218 DEFINE_UUID(CaptureIntent, CAPTURE_INTENT_MANUAL, FB3F3663,CC62,11E5,9956,62,56,62,87,07,61);
219 DEFINE_UUID(CaptureIntent, CAPTURE_INTENT_PREVIEW, FB3F3664,CC62,11E5,9956,62,56,62,87,07,61);
220 DEFINE_UUID(CaptureIntent, CAPTURE_INTENT_STILL_CAPTURE, FB3F3665,CC62,11E5,9956,62,56,62,87,07,61);
221 DEFINE_UUID(CaptureIntent, CAPTURE_INTENT_VIDEO_RECORD, FB3F3666,CC62,11E5,9956,62,56,62,87,07,61);
222 DEFINE_UUID(CaptureIntent, CAPTURE_INTENT_VIDEO_SNAPSHOT, FB3F3667,CC62,11E5,9956,62,56,62,87,07,61);
223
224 /**
225 * Denoise (noise reduction) Modes.
226 */
227 DEFINE_NAMED_UUID_CLASS(DenoiseMode);
228 DEFINE_UUID(DenoiseMode, DENOISE_MODE_OFF, FB3F3668,CC62,11E5,9956,62,56,62,87,07,61);
229 DEFINE_UUID(DenoiseMode, DENOISE_MODE_FAST, FB3F3669,CC62,11E5,9956,62,56,62,87,07,61);
230 DEFINE_UUID(DenoiseMode, DENOISE_MODE_HIGH_QUALITY, FB3F366A,CC62,11E5,9956,62,56,62,87,07,61);
231
232 /**
233 * Edge Enhance Modes.
234 */
235 DEFINE_NAMED_UUID_CLASS(EdgeEnhanceMode);
236 DEFINE_UUID(EdgeEnhanceMode, EDGE_ENHANCE_MODE_OFF, F7100B40,6A5F,11E6,BDF4,08,00,20,0C,9A,66);
237 DEFINE_UUID(EdgeEnhanceMode, EDGE_ENHANCE_MODE_FAST, F7100B41,6A5F,11E6,BDF4,08,00,20,0C,9A,66);
238 DEFINE_UUID(EdgeEnhanceMode, EDGE_ENHANCE_MODE_HIGH_QUALITY, F7100B42,6A5F,11E6,BDF4,08,00,20,0C,9A,66);
239
240 /**
241 * Extension Names. Note that ExtensionName UUIDs are defined by their respective extension headers.
242 */
243 DEFINE_NAMED_UUID_CLASS(ExtensionName);
244
245 /**
246 * Pixel formats.
247 */
248 DEFINE_NAMED_UUID_CLASS(PixelFormat);
249 DEFINE_UUID(PixelFormat, PIXEL_FMT_UNKNOWN, 00000000,93d5,11e5,0000,1c,b7,2c,ef,d4,1e);
250 DEFINE_UUID(PixelFormat, PIXEL_FMT_Y8, 569be14a,93d5,11e5,91bc,1c,b7,2c,ef,d4,1e);
251 DEFINE_UUID(PixelFormat, PIXEL_FMT_Y16, 56ddb19c,93d5,11e5,8e2c,1c,b7,2c,ef,d4,1e);
252 DEFINE_UUID(PixelFormat, PIXEL_FMT_YCbCr_420_888, 570c10e6,93d5,11e5,8ff3,1c,b7,2c,ef,d4,1e);
253 DEFINE_UUID(PixelFormat, PIXEL_FMT_YCbCr_422_888, 573a7940,93d5,11e5,99c2,1c,b7,2c,ef,d4,1e);
254 DEFINE_UUID(PixelFormat, PIXEL_FMT_YCbCr_444_888, 576043dc,93d5,11e5,8983,1c,b7,2c,ef,d4,1e);
255 DEFINE_UUID(PixelFormat, PIXEL_FMT_JPEG_BLOB, 578b08c4,93d5,11e5,9686,1c,b7,2c,ef,d4,1e);
256 DEFINE_UUID(PixelFormat, PIXEL_FMT_RAW16, 57b484d8,93d5,11e5,aeb6,1c,b7,2c,ef,d4,1e);
257 DEFINE_UUID(PixelFormat, PIXEL_FMT_P016, 57b484d9,93d5,11e5,aeb6,1c,b7,2c,ef,d4,1e);
258
259 /**
260 * The SensorModeType of a sensor defines the type of image data that is output by the
261 * imaging sensor before any sort of image processing (ie. pre-ISP format).
262 */
263 DEFINE_NAMED_UUID_CLASS(SensorModeType);
264 DEFINE_UUID(SensorModeType, SENSOR_MODE_TYPE_DEPTH, 64483464,4b91,11e6,bbbd,40,16,7e,ab,86,92);
265 DEFINE_UUID(SensorModeType, SENSOR_MODE_TYPE_YUV, 6453e00c,4b91,11e6,871d,40,16,7e,ab,86,92);
266 DEFINE_UUID(SensorModeType, SENSOR_MODE_TYPE_RGB, 6463d4c6,4b91,11e6,88a3,40,16,7e,ab,86,92);
267 DEFINE_UUID(SensorModeType, SENSOR_MODE_TYPE_BAYER, 646f04ea,4b91,11e6,9c06,40,16,7e,ab,86,92);
268
269
270 /**
271 * Utility class for libargus interfaces.
272 */
273 class NonCopyable
274 {
275 protected:
276 NonCopyable() {}
277
278 private:
279 NonCopyable(NonCopyable& other);
280 NonCopyable& operator=(NonCopyable& other);
281 };
282
283 /**
284 * The top-level interface class.
285 *
286 * By convention, every Interface subclass exposes a public static method called @c id(),
287 * which returns the unique InterfaceID for that interface.
288 * This is required for the @c interface_cast<> template to work with that interface.
289 */
290 class Interface : NonCopyable
291 {
292 protected:
293 Interface() {}
294 ~Interface() {}
295 };
296
297 /**
298 * A unique identifier for a libargus Interface.
299 */
300 class InterfaceID : public NamedUUID
301 {
302 public:
303 InterfaceID(uint32_t time_low_
304 , uint16_t time_mid_
305 , uint16_t time_hi_and_version_
306 , uint16_t clock_seq_
307 , uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint8_t c5
308 , const char* name)
309 : NamedUUID(time_low_, time_mid_, time_hi_and_version_, clock_seq_,
310 c0, c1, c2, c3, c4, c5, name)
311 {}
312
313 InterfaceID()
314 : NamedUUID(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "IID_UNSPECIFIED")
315 {}
316 };
317
318 /**
319 * The base interface for a class that provides libargus Interfaces.
320 */
321 class InterfaceProvider : NonCopyable
322 {
323 public:
324
325 /**
326 * Acquire the interface specified by @c interfaceId.
327 * @returns An instance of the requested interface,
328 * or NULL if that interface is not available.
329 */
330 virtual Interface* getInterface(const InterfaceID& interfaceId) = 0;
331
332 protected:
333 ~InterfaceProvider() {}
334 };
335
336 /**
337 * Interface-casting helper similar to dynamic_cast.
338 */
339
340 template <typename TheInterface>
341 inline TheInterface* interface_cast(InterfaceProvider* obj)
342 {
343 return static_cast<TheInterface*>(obj ? obj->getInterface(TheInterface::id()): 0);
344 }
345
346 template <typename TheInterface>
347 inline TheInterface* interface_cast(const InterfaceProvider* obj)
348 {
349 return static_cast<TheInterface*>(
350 obj ? const_cast<const Interface*>(
351 const_cast<InterfaceProvider*>(obj)->getInterface(TheInterface::id())): 0);
352 }
353
354 /**
355 * A top level object class for libargus objects that are created and owned by
356 * the client. All Destructable objects created by the client must be explicitly destroyed.
357 */
358 class Destructable
359 {
360 public:
361
362 /**
363 * Destroy this object.
364 * After making this call, the client cannot make any more calls on this object.
365 */
366 virtual void destroy() = 0;
367
368 protected:
369 ~Destructable() {}
370 };
371
372 /**
373 * Template helper emulating C++11 rvalue semantics.
374 * @cond
375 */
376 template<typename T>
377 class rv : public T
378 {
379 rv();
380 ~rv();
381 rv(const rv&);
382 void operator=(const rv&);
383 };
384
385 template<typename T>
386 rv<T>& move(T& self)
387 {
388 return *static_cast<rv<T>*>(&self);
389 }
390 /** @endcond */
391
392 /**
393 * Movable smart pointer mimicking std::unique_ptr.
394 * @cond
395 */
396 template <typename T> struct remove_const;
397 template <typename T> struct remove_const<const T&>{ typedef T& type; };
398 template <typename T> struct remove_const<const T*>{ typedef T* type; };
399 template <typename T> struct remove_const<const T >{ typedef T type; };
400 template <typename T> struct remove_const { typedef T type; };
401 /** @endcond */
402
403 template <typename T>
404 class UniqueObj : NonCopyable
405 {
406 public:
407 explicit UniqueObj(T* obj=NULL): m_obj(obj) {}
408
409 void reset(T* obj=NULL)
410 { if (m_obj) const_cast<typename remove_const<T*>::type>(m_obj)->destroy(); m_obj = obj; }
411 T* release()
412 { T* obj = m_obj; m_obj = NULL; return obj; }
413
414 UniqueObj( rv<UniqueObj>& moved ): m_obj(moved.release()) {}
415 UniqueObj& operator=( rv<UniqueObj>& moved ){ reset( moved.release()); return *this; }
416
417 ~UniqueObj() { reset(); }
418
419 T& operator*() const { return *m_obj; }
420 T* get() const { return m_obj; }
421
422 operator bool() const { return !!m_obj; }
423
424 operator rv<UniqueObj>&() { return *static_cast< rv<UniqueObj>*>(this); }
425 operator const rv<UniqueObj>&() const { return *static_cast<const rv<UniqueObj>*>(this); }
426
427 private:
428 T* m_obj;
429
430 T* operator->() const; // Prevent calling destroy() directly.
431 // Note: For getInterface functionality use interface_cast.
432 };
433
434 template <typename TheInterface, typename TObject>
435 inline TheInterface* interface_cast(const UniqueObj<TObject>& obj)
436 {
437 return interface_cast<TheInterface>( obj.get());
438 }
439
440 /**
441 * Tuple template class. This provides a finite ordered list of N elements having type T.
442 */
443 template <unsigned int N, typename T>
444 class Tuple
445 {
446 public:
447 Tuple() {}
448
449 /// Initialize every element of the tuple to a single value.
450 Tuple(T init)
451 {
452 for (unsigned int i = 0; i < N; i++)
453 m_data[i] = init;
454 }
455
456 /// Returns true when every element in the two tuples are identical.
457 bool operator==(const Tuple<N,T>& rhs) const
458 {
459 return !memcmp(m_data, rhs.m_data, sizeof(m_data));
460 }
461
462 /// Returns true if there are any differences between the two tuples.
463 bool operator!=(const Tuple<N,T>& rhs) const
464 {
465 return !(*this == rhs);
466 }
467
468 /// Adds every element of another tuple to the elements of this tuple.
469 Tuple<N, T>& operator+=(const Tuple<N, T>& rhs)
470 {
471 for (unsigned int i = 0; i < N; i++)
472 m_data[i] += rhs.m_data[i];
473 return *this;
474 }
475
476 /// Subtracts every element of another tuple from the elements of this tuple.
477 Tuple<N, T>& operator-=(const Tuple<N, T>& rhs)
478 {
479 for (unsigned int i = 0; i < N; i++)
480 m_data[i] -= rhs.m_data[i];
481 return *this;
482 }
483
484 /// Multiplies every element in the tuple by a single value.
485 Tuple<N, T>& operator*=(const T& rhs)
486 {
487 for (unsigned int i = 0; i < N; i++)
488 m_data[i] *= rhs;
489 return *this;
490 }
491
492 /// Divides every element in the tuple by a single value.
493 Tuple<N, T>& operator/=(const T& rhs)
494 {
495 for (unsigned int i = 0; i < N; i++)
496 m_data[i] /= rhs;
497 return *this;
498 }
499
500 /// Returns the result of adding another tuple to this tuple.
501 const Tuple<N, T> operator+(const Tuple<N, T>& rhs) const
502 {
503 return Tuple<N, T>(*this) += rhs;
504 }
505
506 /// Returns the result of subtracting another tuple from this tuple.
507 const Tuple<N, T> operator-(const Tuple<N, T>& rhs) const
508 {
509 return Tuple<N, T>(*this) -= rhs;
510 }
511
512 /// Returns the result of multiplying this tuple by a single value.
513 const Tuple<N, T> operator*(const T& rhs) const
514 {
515 return Tuple<N, T>(*this) *= rhs;
516 }
517
518 /// Returns the result of dividing this tuple by a single value.
519 const Tuple<N, T> operator/(const T& rhs) const
520 {
521 return Tuple<N, T>(*this) /= rhs;
522 }
523
524 T& operator[](unsigned int i) { assert(i < N); return m_data[i]; }
525 const T& operator[](unsigned int i) const { assert(i < N); return m_data[i]; }
526
527 /// Returns the number of elements in the tuple.
528 static unsigned int tupleSize() { return N; }
529
530 protected:
531 T m_data[N];
532 };
533
534 /**
535 * BayerTuple template class. This is a Tuple specialization containing 4 elements corresponding
536 * to the Bayer color channels: R, G_EVEN, G_ODD, and B. Values can be accessed using the named
537 * methods or subscript indexing using the Argus::BayerChannel enum.
538 */
539 template <typename T>
540 class BayerTuple : public Tuple<BAYER_CHANNEL_COUNT, T>
541 {
542 public:
543 BayerTuple() {}
544 BayerTuple(const Tuple<BAYER_CHANNEL_COUNT, T>& other) : Tuple<BAYER_CHANNEL_COUNT, T>(other) {}
545
546 BayerTuple(T init)
547 {
548 r() = gEven() = gOdd() = b() = init;
549 }
550
551 BayerTuple(T _r, T _gEven, T _gOdd, T _b)
552 {
553 r() = _r;
554 gEven() = _gEven;
555 gOdd() = _gOdd;
556 b() = _b;
557 }
558
559 T& r() { return Tuple<BAYER_CHANNEL_COUNT, T>::m_data[BAYER_CHANNEL_R]; }
560 const T& r() const { return Tuple<BAYER_CHANNEL_COUNT, T>::m_data[BAYER_CHANNEL_R]; }
561 T& gEven() { return Tuple<BAYER_CHANNEL_COUNT, T>::m_data[BAYER_CHANNEL_G_EVEN]; }
562 const T& gEven() const { return Tuple<BAYER_CHANNEL_COUNT, T>::m_data[BAYER_CHANNEL_G_EVEN]; }
563 T& gOdd() { return Tuple<BAYER_CHANNEL_COUNT, T>::m_data[BAYER_CHANNEL_G_ODD]; }
564 const T& gOdd() const { return Tuple<BAYER_CHANNEL_COUNT, T>::m_data[BAYER_CHANNEL_G_ODD]; }
565 T& b() { return Tuple<BAYER_CHANNEL_COUNT, T>::m_data[BAYER_CHANNEL_B]; }
566 const T& b() const { return Tuple<BAYER_CHANNEL_COUNT, T>::m_data[BAYER_CHANNEL_B]; }
567 };
568
569 /**
570 * RGBTuple template class. This is a Tuple specialization containing 3 elements corresponding
571 * to the RGB color channels: R, G, and B. Values can be accessed using the named methods or
572 * subscript indexing using the Argus::RGBChannel enum.
573 */
574 template <typename T>
575 class RGBTuple : public Tuple<RGB_CHANNEL_COUNT, T>
576 {
577 public:
578 RGBTuple() {}
579 RGBTuple(const Tuple<RGB_CHANNEL_COUNT, T>& other) : Tuple<RGB_CHANNEL_COUNT, T>(other) {}
580
581 RGBTuple(T init)
582 {
583 r() = g() = b() = init;
584 }
585
586 RGBTuple(T _r, T _g, T _b)
587 {
588 r() = _r;
589 g() = _g;
590 b() = _b;
591 }
592
593 T& r() { return Tuple<RGB_CHANNEL_COUNT, T>::m_data[RGB_CHANNEL_R]; }
594 const T& r() const { return Tuple<RGB_CHANNEL_COUNT, T>::m_data[RGB_CHANNEL_R]; }
595 T& g() { return Tuple<RGB_CHANNEL_COUNT, T>::m_data[RGB_CHANNEL_G]; }
596 const T& g() const { return Tuple<RGB_CHANNEL_COUNT, T>::m_data[RGB_CHANNEL_G]; }
597 T& b() { return Tuple<RGB_CHANNEL_COUNT, T>::m_data[RGB_CHANNEL_B]; }
598 const T& b() const { return Tuple<RGB_CHANNEL_COUNT, T>::m_data[RGB_CHANNEL_B]; }
599 };
600
601 /**
602 * Point2D template class. This is a Tuple specialization containing 2 elements corresponding
603 * to the x and y coordinates a 2D point. Values can be accessed using the named methods or
604 * subscript indexing using the Argus::Coordinate enum.
605 */
606 template <typename T>
607 class Point2D : public Tuple<COORDINATE_2D_COUNT, T>
608 {
609 public:
610 Point2D() {}
611 Point2D(const Tuple<COORDINATE_2D_COUNT, T>& other) : Tuple<COORDINATE_2D_COUNT, T>(other) {}
612
613 Point2D(T init)
614 {
615 x() = y() = init;
616 }
617
618 Point2D(T _x, T _y)
619 {
620 x() = _x;
621 y() = _y;
622 }
623
624 T& x() { return Tuple<COORDINATE_2D_COUNT, T>::m_data[COORDINATE_X]; }
625 const T& x() const { return Tuple<COORDINATE_2D_COUNT, T>::m_data[COORDINATE_X]; }
626 T& y() { return Tuple<COORDINATE_2D_COUNT, T>::m_data[COORDINATE_Y]; }
627 const T& y() const { return Tuple<COORDINATE_2D_COUNT, T>::m_data[COORDINATE_Y]; }
628 };
629
630 /**
631 * Size2D template class. This is a Tuple specialization containing 2 elements corresponding to the
632 * width and height of a 2D size, in that order. Values can be accessed using the named methods.
633 */
634 template <typename T>
635 class Size2D : public Tuple<2, T>
636 {
637 public:
638 Size2D() {}
639 Size2D(const Tuple<2, T>& other) : Tuple<2, T>(other) {}
640
641 Size2D(T init)
642 {
643 width() = height() = init;
644 }
645
646 Size2D(T _width, T _height)
647 {
648 width() = _width;
649 height() = _height;
650 }
651
652 T& width() { return Tuple<2, T>::m_data[0]; }
653 const T& width() const { return Tuple<2, T>::m_data[0]; }
654 T& height() { return Tuple<2, T>::m_data[1]; }
655 const T& height() const { return Tuple<2, T>::m_data[1]; }
656
657 /// Returns the area of the size (width * height).
658 T area() const { return width() * height(); }
659 };
660
661 /**
662 * Rectangle template class. This is a Tuple specialization containing 4 elements corresponding
663 * to the positions of the left, top, right, and bottom edges of a rectangle, in that order.
664 * Values can be accessed using the named methods.
665 */
666 template <typename T>
667 class Rectangle : public Tuple<4, T>
668 {
669 public:
670 Rectangle() {}
671 Rectangle(const Tuple<4, T>& other) : Tuple<4, T>(other) {}
672
673 Rectangle(T init)
674 {
675 left() = top() = right() = bottom() = init;
676 }
677
678 Rectangle(T _left, T _top, T _right, T _bottom)
679 {
680 left() = _left;
681 top() = _top;
682 right() = _right;
683 bottom() = _bottom;
684 }
685
686 T& left() { return Tuple<4, T>::m_data[0]; }
687 const T& left() const { return Tuple<4, T>::m_data[0]; }
688 T& top() { return Tuple<4, T>::m_data[1]; }
689 const T& top() const { return Tuple<4, T>::m_data[1]; }
690 T& right() { return Tuple<4, T>::m_data[2]; }
691 const T& right() const { return Tuple<4, T>::m_data[2]; }
692 T& bottom() { return Tuple<4, T>::m_data[3]; }
693 const T& bottom() const { return Tuple<4, T>::m_data[3]; }
694
695 /// Returns the width of the rectangle.
696 T width() const { return right() - left(); }
697
698 /// Returns the height of the rectangle.
699 T height() const { return bottom() - top(); }
700
701 /// Returns the area of the rectangle (width * height).
702 T area() const { return width() * height(); }
703 };
704
705 /**
706 * Range template class. This is a Tuple specialization containing 2 elements corresponding to the
707 * min and max values of the range, in that order. Values can be accessed using the named methods.
708 */
709 template <typename T>
710 class Range : public Tuple<2, T>
711 {
712 public:
713 Range() {}
714 Range(const Tuple<2, T>& other) : Tuple<2, T>(other) {}
715
716 Range(T init)
717 {
718 min() = max() = init;
719 }
720
721 Range(T _min, T _max)
722 {
723 min() = _min;
724 max() = _max;
725 }
726
727 T& min() { return Tuple<2, T>::m_data[0]; }
728 const T& min() const { return Tuple<2, T>::m_data[0]; }
729 T& max() { return Tuple<2, T>::m_data[1]; }
730 const T& max() const { return Tuple<2, T>::m_data[1]; }
731
732 bool empty() const { return max() < min(); }
733 };
734
735 /**
736 * Defines an autocontrol region of interest (in pixel space). This region consists of a rectangle
737 * (inherited from the Rectangle<uint32_t> Tuple) and a floating point weight value.
738 */
739 class AcRegion : public Rectangle<uint32_t>
740 {
741 public:
742 AcRegion()
743 : Rectangle<uint32_t>(0, 0, 0, 0)
744 , m_weight(1.0f)
745 {}
746
747 AcRegion(uint32_t _left, uint32_t _top, uint32_t _right, uint32_t _bottom, float _weight)
748 : Rectangle<uint32_t>(_left, _top, _right, _bottom)
749 , m_weight(_weight)
750 {}
751
752 float& weight() { return m_weight; }
753 const float& weight() const { return m_weight; }
754
755 protected:
756 float m_weight;
757 };
758
759 /**
760 * A template class to hold a 2-dimensional array of data.
761 * Data in this array is tightly packed in a 1-dimensional vector in row-major order;
762 * that is, the vector index for any value given its 2-dimensional location (Point2D) is
763 * index = location.x() + (location.y() * size.x());
764 * Indexing operators using iterators, 1-dimensional, or 2-dimensional coordinates are provided.
765 */
766 template <typename T>
767 class Array2D
768 {
769 public:
770 // Iterator types.
771 typedef T* iterator;
772 typedef const T* const_iterator;
773
774 /// Default Constructor.
775 Array2D() : m_size(0, 0) {}
776
777 /// Constructor given initial array size.
778 Array2D(const Size2D<uint32_t>& size) : m_size(size)
779 {
780 m_data.resize(size.width() * size.height());
781 }
782
783 /// Constructor given initial array size and initial fill value.
784 Array2D(const Size2D<uint32_t>& size, const T& value) : m_size(size)
785 {
786 m_data.resize(size.width() * size.height(), value);
787 }
788
789 /// Copy constructor.
790 Array2D(const Array2D<T>& other)
791 {
792 m_data = other.m_data;
793 m_size = other.m_size;
794 }
795
796 /// Assignment operator.
797 Array2D& operator= (const Array2D<T>& other)
798 {
799 m_data = other.m_data;
800 m_size = other.m_size;
801 return *this;
802 }
803
804 /// Equality operator.
805 bool operator== (const Array2D<T>& other) const
806 {
807 return (m_size == other.m_size && m_data == other.m_data);
808 }
809
810 /// Returns the size (dimensions) of the array.
811 Size2D<uint32_t> size() const { return m_size; }
812
813 /// Resize the array. Array contents after resize are undefined.
814 /// Boolean return value enables error checking when exceptions are not available.
815 bool resize(const Size2D<uint32_t>& size)
816 {
817 uint32_t s = size.width() * size.height();
818 m_data.resize(s);
819 if (m_data.size() != s)
820 return false;
821 m_size = size;
822 return true;
823 }
824
825 /// STL style iterators.
826 inline const_iterator begin() const { return m_data.data(); }
827 inline const_iterator end() const { return m_data.data() + m_data.size(); }
828 inline iterator begin() { return m_data.data(); }
829 inline iterator end() { return m_data.data() + m_data.size(); }
830
831 /// Array indexing using [] operator.
832 T& operator[](unsigned int i) { return m_data[checkIndex(i)]; }
833 const T& operator[](unsigned int i) const { return m_data[checkIndex(i)]; }
834
835 /// Array indexing using () operator.
836 inline const T& operator() (uint32_t i) const { return m_data[checkIndex(i)]; }
837 inline const T& operator() (uint32_t x, uint32_t y) const { return m_data[checkIndex(x, y)]; }
838 inline const T& operator() (const Point2D<uint32_t>& p) const
839 { return m_data[checkIndex(p.x(), p.y())]; }
840 inline T& operator() (uint32_t i) { return m_data[checkIndex(i)]; }
841 inline T& operator() (uint32_t x, uint32_t y) { return m_data[checkIndex(x, y)]; }
842 inline T& operator() (const Point2D<uint32_t>& p)
843 { return m_data[checkIndex(p.x(), p.y())]; }
844
845 // Get pointers to data.
846 inline const T* data() const { return m_data.data(); }
847 inline T* data() { return m_data.data(); }
848
849 private:
850 inline uint32_t checkIndex(uint32_t i) const
851 {
852 assert(i < m_data.size());
853 return i;
854 }
855
856 inline uint32_t checkIndex(uint32_t x, uint32_t y) const
857 {
858 assert(x < m_size.width());
859 assert(y < m_size.height());
860 return x + (y * m_size.width());
861 }
862
863 std::vector<T> m_data;
864 Size2D<uint32_t> m_size;
865 };
866
867 typedef uint32_t AutoControlId;
868
869 } // namespace Argus
870
871 #endif // _ARGUS_TYPES_H