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-2017, 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 * Extension name UUID. Values are defined in extension headers.
92 */
93 class ExtensionName : public NamedUUID
94 {
95 public:
96 ExtensionName(uint32_t time_low_
97 , uint16_t time_mid_
98 , uint16_t time_hi_and_version_
99 , uint16_t clock_seq_
100 , uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint8_t c5
101 , const char* name)
102 : NamedUUID(time_low_, time_mid_, time_hi_and_version_, clock_seq_,
103 c0, c1, c2, c3, c4, c5, name)
104 {}
105
106 ExtensionName()
107 : NamedUUID(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "EXT_UNSPECIFIED")
108 {}
109 };
110
111 /*
112 * Named UUID classes.
113 */
114
115 DEFINE_NAMED_UUID_CLASS(AwbMode);
116 DEFINE_NAMED_UUID_CLASS(CaptureIntent);
117 DEFINE_NAMED_UUID_CLASS(DenoiseMode);
118 DEFINE_NAMED_UUID_CLASS(EdgeEnhanceMode);
119 DEFINE_NAMED_UUID_CLASS(SensorModeType);
120 DEFINE_NAMED_UUID_CLASS(VideoStabilizationMode);
121
122 /*
123 * Named UUIDs sorted alphabetically.
124 */
125
126 DEFINE_UUID(AwbMode, AWB_MODE_OFF, FB3F365A,CC62,11E5,9956,62,56,62,87,07,61);
127 DEFINE_UUID(AwbMode, AWB_MODE_AUTO, FB3F365B,CC62,11E5,9956,62,56,62,87,07,61);
128 DEFINE_UUID(AwbMode, AWB_MODE_INCANDESCENT, FB3F365C,CC62,11E5,9956,62,56,62,87,07,61);
129 DEFINE_UUID(AwbMode, AWB_MODE_FLUORESCENT, FB3F365D,CC62,11E5,9956,62,56,62,87,07,61);
130 DEFINE_UUID(AwbMode, AWB_MODE_WARM_FLUORESCENT, FB3F365E,CC62,11E5,9956,62,56,62,87,07,61);
131 DEFINE_UUID(AwbMode, AWB_MODE_DAYLIGHT, FB3F365F,CC62,11E5,9956,62,56,62,87,07,61);
132 DEFINE_UUID(AwbMode, AWB_MODE_CLOUDY_DAYLIGHT, FB3F3660,CC62,11E5,9956,62,56,62,87,07,61);
133 DEFINE_UUID(AwbMode, AWB_MODE_TWILIGHT, FB3F3661,CC62,11E5,9956,62,56,62,87,07,61);
134 DEFINE_UUID(AwbMode, AWB_MODE_SHADE, FB3F3662,CC62,11E5,9956,62,56,62,87,07,61);
135 DEFINE_UUID(AwbMode, AWB_MODE_MANUAL, 20FB45DA,C49F,4293,AB02,13,3F,8C,CA,DD,69);
136
137 DEFINE_UUID(CaptureIntent, CAPTURE_INTENT_MANUAL,
138 FB3F3663,CC62,11E5,9956,62,56,62,87,07,61);
139 DEFINE_UUID(CaptureIntent, CAPTURE_INTENT_PREVIEW,
140 FB3F3664,CC62,11E5,9956,62,56,62,87,07,61);
141 DEFINE_UUID(CaptureIntent, CAPTURE_INTENT_STILL_CAPTURE,
142 FB3F3665,CC62,11E5,9956,62,56,62,87,07,61);
143 DEFINE_UUID(CaptureIntent, CAPTURE_INTENT_VIDEO_RECORD,
144 FB3F3666,CC62,11E5,9956,62,56,62,87,07,61);
145 DEFINE_UUID(CaptureIntent, CAPTURE_INTENT_VIDEO_SNAPSHOT,
146 FB3F3667,CC62,11E5,9956,62,56,62,87,07,61);
147
148 DEFINE_UUID(DenoiseMode, DENOISE_MODE_OFF, FB3F3668,CC62,11E5,9956,62,56,62,87,07,61);
149 DEFINE_UUID(DenoiseMode, DENOISE_MODE_FAST, FB3F3669,CC62,11E5,9956,62,56,62,87,07,61);
150 DEFINE_UUID(DenoiseMode, DENOISE_MODE_HIGH_QUALITY, FB3F366A,CC62,11E5,9956,62,56,62,87,07,61);
151
152 DEFINE_UUID(EdgeEnhanceMode, EDGE_ENHANCE_MODE_OFF, F7100B40,6A5F,11E6,BDF4,08,00,20,0C,9A,66);
153 DEFINE_UUID(EdgeEnhanceMode, EDGE_ENHANCE_MODE_FAST, F7100B41,6A5F,11E6,BDF4,08,00,20,0C,9A,66);
154 DEFINE_UUID(EdgeEnhanceMode, EDGE_ENHANCE_MODE_HIGH_QUALITY, F7100B42,6A5F,11E6,BDF4,08,00,20,0C,9A,66);
155
156 DEFINE_UUID(SensorModeType, SENSOR_MODE_TYPE_DEPTH,
157 64483464,4b91,11e6,bbbd,40,16,7e,ab,86,92);
158 DEFINE_UUID(SensorModeType, SENSOR_MODE_TYPE_YUV,
159 6453e00c,4b91,11e6,871d,40,16,7e,ab,86,92);
160 DEFINE_UUID(SensorModeType, SENSOR_MODE_TYPE_RGB,
161 6463d4c6,4b91,11e6,88a3,40,16,7e,ab,86,92);
162 DEFINE_UUID(SensorModeType, SENSOR_MODE_TYPE_BAYER,
163 646f04ea,4b91,11e6,9c06,40,16,7e,ab,86,92);
164
165 DEFINE_UUID(VideoStabilizationMode, VIDEO_STABILIZATION_MODE_OFF,
166 FB3F366E,CC62,11E5,9956,62,56,62,87,07,61);
167 DEFINE_UUID(VideoStabilizationMode, VIDEO_STABILIZATION_MODE_ON,
168 FB3F366F,CC62,11E5,9956,62,56,62,87,07,61);
169
170 /*
171 * Camera settings constants - sorted alphabetically.
172 */
173
174 enum AeAntibandingMode
175 {
176 AE_ANTIBANDING_MODE_OFF,
177 AE_ANTIBANDING_MODE_AUTO,
178 AE_ANTIBANDING_MODE_50HZ,
179 AE_ANTIBANDING_MODE_60HZ,
180
181 AE_ANTIBANDING_MODE_COUNT
182 };
183
184 <spanclass="keyword">enum AeState
185 {
186 AE_STATE_INACTIVE,
187 AE_STATE_SEARCHING,
188 AE_STATE_CONVERGED,
189 AE_STATE_FLASH_REQUIRED,
190 AE_STATE_TIMEOUT,
191
192 AE_STATE_COUNT
193 };
194
195 enum AwbState
196 {
197 AWB_STATE_INACTIVE,
198 AWB_STATE_SEARCHING,
199 AWB_STATE_CONVERGED,
200 AWB_STATE_LOCKED,
201
202 AWB_STATE_COUNT
203 };
204
205 enum BayerChannel
206 {
207 BAYER_CHANNEL_R,
208 BAYER_CHANNEL_G_EVEN,
209 BAYER_CHANNEL_G_ODD,
210 BAYER_CHANNEL_B,
211
212 BAYER_CHANNEL_COUNT
213 };
214
215 /**
216 * Status values returned by API function calls.
217 */
218 enum Status
219 {
220 /// Function succeeded.
221 STATUS_OK,
222
223 /// The set of parameters passed was invalid.
224 STATUS_INVALID_PARAMS,
225
226 /// The requested settings are invalid.
227 STATUS_INVALID_SETTINGS,
228
229 /// The requested device is unavailable.
230 STATUS_UNAVAILABLE,
231
232 /// An operation failed because of insufficient mavailable memory.
233 STATUS_OUT_OF_MEMORY,
234
235 /// This method has not been implemented.
236 STATUS_UNIMPLEMENTED,
237
238 /// An operation timed out.
239 STATUS_TIMEOUT,
240
241 /// The capture was aborted. @see ICaptureSession::cancelRequests()
242 STATUS_CANCELLED,
243
244 /// The stream or other resource has been disconnected.
245 STATUS_DISCONNECTED,
246
247 // Number of elements in this enum.
248 STATUS_COUNT
249 };
250
251 enum RGBChannel
252 {
253 RGB_CHANNEL_R,
254 RGB_CHANNEL_G,
255 RGB_CHANNEL_B,
256
257 RGB_CHANNEL_COUNT
258 };
259
260 enum Coordinate
261 {
262 COORDINATE_X,
263 COORDINATE_Y,
264 COORDINATE_Z,
265
266 COORDINATE_2D_COUNT = 2,
267 COORDINATE_3D_COUNT = 3
268 };
269
270
271 /**
272 * Pixel formats.
273 */
274 class PixelFormat : public NamedUUID
275 {
276 public:
277 PixelFormat(uint32_t time_low_
278 , uint16_t time_mid_
279 , uint16_t time_hi_and_version_
280 , uint16_t clock_seq_
281 , uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint8_t c5
282 , const char* name)
283 : NamedUUID(time_low_, time_mid_, time_hi_and_version_, clock_seq_,
284 c0, c1, c2, c3, c4, c5, name)
285 {}
286
287 private:
288 PixelFormat(); // No default c'tor please use PIXEL_FMT_UNKNOWN
289 };
290
291 DEFINE_UUID(PixelFormat, PIXEL_FMT_UNKNOWN, 00000000,93d5,11e5,0000,1c,b7,2c,ef,d4,1e);
292 DEFINE_UUID(PixelFormat, PIXEL_FMT_Y8, 569be14a,93d5,11e5,91bc,1c,b7,2c,ef,d4,1e);
293 DEFINE_UUID(PixelFormat, PIXEL_FMT_Y16, 56ddb19c,93d5,11e5,8e2c,1c,b7,2c,ef,d4,1e);
294 DEFINE_UUID(PixelFormat, PIXEL_FMT_YCbCr_420_888, 570c10e6,93d5,11e5,8ff3,1c,b7,2c,ef,d4,1e);
295 DEFINE_UUID(PixelFormat, PIXEL_FMT_YCbCr_422_888, 573a7940,93d5,11e5,99c2,1c,b7,2c,ef,d4,1e);
296 DEFINE_UUID(PixelFormat, PIXEL_FMT_YCbCr_444_888, 576043dc,93d5,11e5,8983,1c,b7,2c,ef,d4,1e);
297 DEFINE_UUID(PixelFormat, PIXEL_FMT_JPEG_BLOB, 578b08c4,93d5,11e5,9686,1c,b7,2c,ef,d4,1e);
298 DEFINE_UUID(PixelFormat, PIXEL_FMT_RAW16, 57b484d8,93d5,11e5,aeb6,1c,b7,2c,ef,d4,1e);
299
300 /**
301 * Utility class for libargus interfaces.
302 */
303 class NonCopyable
304 {
305 protected:
306 NonCopyable() {}
307
308 private:
309 NonCopyable(NonCopyable& other);
310 NonCopyable& operator=(NonCopyable& other);
311 };
312
313 /**
314 * The top-level interface class.
315 *
316 * By convention, every Interface subclass exposes a public static method called @c id(),
317 * which returns the unique InterfaceID for that interface.
318 * This is required for the @c interface_cast<> template to work with that interface.
319 */
320 class Interface : NonCopyable
321 {
322 protected:
323 Interface() {}
324 ~Interface() {}
325 };
326
327 /**
328 * A unique identifier for a libargus Interface.
329 */
330 class InterfaceID : public NamedUUID
331 {
332 public:
333 InterfaceID(uint32_t time_low_
334 , uint16_t time_mid_
335 , uint16_t time_hi_and_version_
336 , uint16_t clock_seq_
337 , uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint8_t c5
338 , const char* name)
339 : NamedUUID(time_low_, time_mid_, time_hi_and_version_, clock_seq_,
340 c0, c1, c2, c3, c4, c5, name)
341 {}
342
343 InterfaceID()
344 : NamedUUID(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "IID_UNSPECIFIED")
345 {}
346 };
347
348 /**
349 * The base interface for a class that provides libargus Interfaces.
350 */
351 class InterfaceProvider : NonCopyable
352 {
353 public:
354
355 /**
356 * Acquire the interface specified by @c interfaceId.
357 * @returns An instance of the requested interface,
358 * or NULL if that interface is not available.
359 */
360 virtual Interface* getInterface(const InterfaceID& interfaceId) = 0;
361
362 protected:
363 ~InterfaceProvider() {}
364 };
365
366 /**
367 * Interface-casting helper similar to dynamic_cast.
368 */
369
370 template <typename TheInterface>
371 inline TheInterface* interface_cast(InterfaceProvider* obj)
372 {
373 return static_cast<TheInterface*>(obj ? obj->getInterface(TheInterface::id()): 0);
374 }
375
376 template <typename TheInterface>
377 inline TheInterface* interface_cast(const InterfaceProvider* obj)
378 {
379 return static_cast<TheInterface*>(
380 obj ? const_cast<const Interface*>(
381 const_cast< InterfaceProvider*>(obj)->getInterface(TheInterface::id())): 0);
382 }
383
384 /**
385 * A top level object class for libargus objects that are created and owned by
386 * the client. All Destructable objects created by the client must be explicitly destroyed.
387 */
388 class Destructable
389 {
390 public:
391
392 /**
393 * Destroy this object.
394 * After making this call, the client cannot make any more calls on this object.
395 */
396 virtual void destroy() = 0;
397
398 protected:
399 ~Destructable() {}
400 };
401
402 /**
403 * Template helper emulating C++11 rvalue semantics.
404 * @cond
405 */
406 template<typename T>
407 class rv : public T
408 {
409 rv();
410 ~rv();
411 rv(const rv&);
412 void operator=(const rv&);
413 };
414
415 template<typename T>
416 rv<T>& move(T& self)
417 {
418 return *static_cast<rv<T>*>(&self);
419 }
420 /** @endcond */
421
422 /**
423 * Movable smart pointer mimicking std::unique_ptr.
424 * @cond
425 */
426 template <typename T> struct remove_const;
427 template <typename T> struct remove_const<const T&>{ typedef T& type; };
428 template <typename T> struct remove_const<const T*>{ typedef T* type; };
429 template <typename T> struct remove_const<const T >{ typedef T type; };
430 template <typename T> struct remove_const { typedef T type; };
431 /** @endcond */
432
433 template <typename T>
434 class UniqueObj : NonCopyable
435 {
436 public:
437 explicit UniqueObj(T* obj=NULL): m_obj(obj) {}
438
439 void reset(T* obj=NULL)
440 { if (m_obj) const_cast<typename remove_const<T*>::type>(m_obj)->destroy(); m_obj = obj; }
441 T* release()
442 { T* obj = m_obj; m_obj = NULL; return obj; }
443
444 UniqueObj( rv<UniqueObj>& moved ): m_obj(moved.release()) {}
445 UniqueObj& operator=( rv<UniqueObj>& moved ){ reset( moved.release()); return *this; }
446
447 ~UniqueObj() { reset(); }
448
449 T& operator*() const { return *m_obj; }
450 T* get() const { return m_obj; }
451
452 operator bool() const { return !!m_obj; }
453
454 operator rv<UniqueObj>&() { return *static_cast< rv<UniqueObj>*>(this); }
455 operator const rv<UniqueObj>&() const { return *static_cast<const rv<UniqueObj>*>(this); }
456
457 private:
458 T* m_obj;
459
460 T* operator->() const; // Prevent calling destroy() directly.
461 // Note: For getInterface functionality use interface_cast.
462 };
463
464 template <typename TheInterface, typename TObject>
465 inline TheInterface* interface_cast(const UniqueObj<TObject>& obj)
466 {
467 return interface_cast<TheInterface>( obj.get());
468 }
469
470 /**
471 * Tuple template class. This provides a finite ordered list of N elements having type T.
472 */
473 template <unsigned int N, typename T>
474 class Tuple
475 {
476 public:
477 Tuple() {}
478
479 /// Initialize every element of the tuple to a single value.
480 Tuple(T init)
481 {
482 for (unsigned int i = 0; i < N; i++)
483 m_data[i] = init;
484 }
485
486 /// Returns true when every element in the two tuples are identical.
487 bool operator==(const Tuple<N,T>& rhs) const
488 {
489 return !memcmp(m_data, rhs.m_data, sizeof(m_data));
490 }
491
492 /// Returns true if there are any differences between the two tuples.
493 bool operator!=(const Tuple<N,T>& rhs) const
494 {
495 return !(*this == rhs);
496 }
497
498 /// Adds every element of another tuple to the elements of this tuple.
499 Tuple<N, T>& operator+=(const Tuple<N, T>& rhs)
500 {
501 for (unsigned int i = 0; i < N; i++)
502 m_data[i] += rhs.m_data[i];
503 return *this;
504 }
505
506 /// Subtracts every element of another tuple from the elements of this tuple.
507 Tuple<N, T>& operator-=(const Tuple<N, T>& rhs)
508 {
509 for (unsigned int i = 0; i < N; i++)
510 m_data[i] -= rhs.m_data[i];
511 return *this;
512 }
513
514 /// Multiplies every element in the tuple by a single value.
515 Tuple<N, T>& operator*=(const T& rhs)
516 {
517 for (unsigned int i = 0; i < N; i++)
518 m_data[i] *= rhs;
519 return *this;
520 }
521
522 /// Divides every element in the tuple by a single value.
523 Tuple<N, T>& operator/=(const T& rhs)
524 {
525 for (unsigned int i = 0; i < N; i++)
526 m_data[i] /= rhs;
527 return *this;
528 }
529
530 /// Returns the result of adding another tuple to this tuple.
531 const Tuple<N, T> operator+(const Tuple<N, T>& rhs) const
532 {
533 return Tuple<N, T>(*this) += rhs;
534 }
535
536 /// Returns the result of subtracting another tuple from this tuple.
537 const Tuple<N, T> operator-(const Tuple<N, T>& rhs) const
538 {
539 return Tuple<N, T>(*this) -= rhs;
540 }
541
542 /// Returns the result of multiplying this tuple by a single value.
543 const Tuple<N, T> operator*(const T& rhs) const
544 {
545 return Tuple<N, T>(*this) *= rhs;
546 }
547
548 /// Returns the result of dividing this tuple by a single value.
549 const Tuple<N, T> operator/(const T& rhs) const
550 {
551 return Tuple<N, T>(*this) /= rhs;
552 }
553
554 T& operator[](unsigned int i) { assert(i < N); return m_data[i]; }
555 const T& operator[](unsigned int i) const { assert(i < N); return m_data[i]; }
556
557 /// Returns the number of elements in the tuple.
558 static unsigned int tupleSize() { return N; }
559
560 protected:
561 T m_data[N];
562 };
563
564 /**
565 * BayerTuple template class. This is a Tuple specialization containing 4 elements corresponding
566 * to the Bayer color channels: R, G_EVEN, G_ODD, and B. Values can be accessed using the named
567 * methods or subscript indexing using the Argus::BayerChannel enum.
568 */
569 template <typename T>
570 class BayerTuple : public Tuple<BAYER_CHANNEL_COUNT, T>
571 {
572 public:
573 BayerTuple() {}
574 BayerTuple(const Tuple<BAYER_CHANNEL_COUNT, T>& other) : Tuple<BAYER_CHANNEL_COUNT, T>(other) {}
575
576 BayerTuple(T init)
577 {
578 r() = gEven() = gOdd() = b() = init;
579 }
580
581 BayerTuple(T _r, T _gEven, T _gOdd, T _b)
582 {
583 r() = _r;
584 gEven() = _gEven;
585 gOdd() = _gOdd;
586 b() = _b;
587 }
588
589 T& r() { return Tuple<BAYER_CHANNEL_COUNT, T>::m_data[BAYER_CHANNEL_R]; }
590 const T& r() const { return Tuple<BAYER_CHANNEL_COUNT, T>::m_data[BAYER_CHANNEL_R]; }
591 T& gEven() { return Tuple<BAYER_CHANNEL_COUNT, T>::m_data[BAYER_CHANNEL_G_EVEN]; }
592 const T& gEven() const { return Tuple<BAYER_CHANNEL_COUNT, T>::m_data[BAYER_CHANNEL_G_EVEN]; }
593 T& gOdd() { return Tuple<BAYER_CHANNEL_COUNT, T>::m_data[BAYER_CHANNEL_G_ODD]; }
594 const T& gOdd() const { return Tuple<BAYER_CHANNEL_COUNT, T>::m_data[BAYER_CHANNEL_G_ODD]; }
595 T& b() { return Tuple<BAYER_CHANNEL_COUNT, T>::m_data[BAYER_CHANNEL_B]; }
596 const T& b() const { return Tuple<BAYER_CHANNEL_COUNT, T>::m_data[BAYER_CHANNEL_B]; }
597 };
598
599 /**
600 * RGBTuple template class. This is a Tuple specialization containing 3 elements corresponding
601 * to the RGB color channels: R, G, and B. Values can be accessed using the named methods or
602 * subscript indexing using the Argus::RGBChannel enum.
603 */
604 template <typename T>
605 class RGBTuple : public Tuple<RGB_CHANNEL_COUNT, T>
606 {
607 public:
608 RGBTuple() {}
609 RGBTuple(const Tuple<RGB_CHANNEL_COUNT, T>& other) : Tuple<RGB_CHANNEL_COUNT, T>(other) {}
610
611 RGBTuple(T init)
612 {
613 r() = g() = b() = init;
614 }
615
616 RGBTuple(T _r, T _g, T _b)
617 {
618 r() = _r;
619 g() = _g;
620 b() = _b;
621 }
622
623 T& r() { return Tuple<RGB_CHANNEL_COUNT, T>::m_data[RGB_CHANNEL_R]; }
624 const T& r() const { return Tuple<RGB_CHANNEL_COUNT, T>::m_data[RGB_CHANNEL_R]; }
625 T& g() { return Tuple<RGB_CHANNEL_COUNT, T>::m_data[RGB_CHANNEL_G]; }
626 const T& g() const { return Tuple<RGB_CHANNEL_COUNT, T>::m_data[RGB_CHANNEL_G]; }
627 T& b() { return Tuple<RGB_CHANNEL_COUNT, T>::m_data[RGB_CHANNEL_B]; }
628 const T& b() const { return Tuple<RGB_CHANNEL_COUNT, T>::m_data[RGB_CHANNEL_B]; }
629 };
630
631 /**
632 * Point2D template class. This is a Tuple specialization containing 2 elements corresponding
633 * to the x and y coordinates a 2D point. Values can be accessed using the named methods or
634 * subscript indexing using the Argus::Coordinate enum.
635 */
636 template <typename T>
637 class Point2D : public Tuple<COORDINATE_2D_COUNT, T>
638 {
639 public:
640 Point2D() {}
641 Point2D(const Tuple<COORDINATE_2D_COUNT, T>& other) : Tuple<COORDINATE_2D_COUNT, T>(other) {}
642
643 Point2D(T init)
644 {
645 x() = y() = init;
646 }
647
648 Point2D(T _x, T _y)
649 {
650 x() = _x;
651 y() = _y;
652 }
653
654 T& x() { return Tuple<COORDINATE_2D_COUNT, T>::m_data[COORDINATE_X]; }
655 const T& x() const { return Tuple<COORDINATE_2D_COUNT, T>::m_data[COORDINATE_X]; }
656 T& y() { return Tuple<COORDINATE_2D_COUNT, T>::m_data[COORDINATE_Y]; }
657 const T& y() const { return Tuple<COORDINATE_2D_COUNT, T>::m_data[COORDINATE_Y]; }
658 };
659
660 /**
661 * Size2D template class. This is a Tuple specialization containing 2 elements corresponding to the
662 * width and height of a 2D size, in that order. Values can be accessed using the named methods.
663 */
664 template <typename T>
665 class Size2D : public Tuple<2, T>
666 {
667 public:
668 Size2D() {}
669 Size2D(const Tuple<2, T>& other) : Tuple<2, T>(other) {}
670
671 Size2D(T init)
672 {
673 width() = height() = init;
674 }
675
676 Size2D(T _width, T _height)
677 {
678 width() = _width;
679 height() = _height;
680 }
681
682 T& width() { return Tuple<2, T>::m_data[0]; }
683 const T& width() const { return Tuple<2, T>::m_data[0]; }
684 T& height() { return Tuple<2, T>::m_data[1]; }
685 const T& height() const { return Tuple<2, T>::m_data[1]; }
686
687 /// Returns the area of the size (width * height).
688 T area() const { return width() * height(); }
689 };
690
691 /**
692 * Rectangle template class. This is a Tuple specialization containing 4 elements corresponding
693 * to the positions of the left, top, right, and bottom edges of a rectangle, in that order.
694 * Values can be accessed using the named methods.
695 */
696 template <typename T>
697 class Rectangle : public Tuple<4, T>
698 {
699 public:
700 Rectangle() {}
701 Rectangle(const Tuple<4, T>& other) : Tuple<4, T>(other) {}
702
703 Rectangle(T init)
704 {
705 left() = top() = right() = bottom() = init;
706 }
707
708 Rectangle(T _left, T _top, T _right, T _bottom)
709 {
710 left() = _left;
711 top() = _top;
712 right() = _right;
713 bottom() = _bottom;
714 }
715
716 T& left() { return Tuple<4, T>::m_data[0]; }
717 const T& left() const { return Tuple<4, T>::m_data[0]; }
718 T& top() { return Tuple<4, T>::m_data[1]; }
719 const T& top() const { return Tuple<4, T>::m_data[1]; }
720 T& right() { return Tuple<4, T>::m_data[2]; }
721 const T& right() const { return Tuple<4, T>::m_data[2]; }
722 T& bottom() { return Tuple<4, T>::m_data[3]; }
723 const T& bottom() const { return Tuple<4, T>::m_data[3]; }
724
725 /// Returns the width of the rectangle.
726 T width() const { return right() - left(); }
727
728 /// Returns the height of the rectangle.
729 T height() const { return bottom() - top(); }
730
731 /// Returns the area of the rectangle (width * height).
732 T area() const { return width() * height(); }
733 };
734
735 /**
736 * Range template class. This is a Tuple specialization containing 2 elements corresponding to the
737 * min and max values of the range, in that order. Values can be accessed using the named methods.
738 */
739 template <typename T>
740 class Range : public Tuple<2, T>
741 {
742 public:
743 Range() {}
744 Range(const Tuple<2, T>& other) : Tuple<2, T>(other) {}
745
746 Range(T init)
747 {
748 min() = max() = init;
749 }
750
751 Range(T _min, T _max)
752 {
753 min() = _min;
754 max() = _max;
755 }
756
757 T& min() { return Tuple<2, T>::m_data[0]; }
758 const T& min() const { return Tuple<2, T>::m_data[0]; }
759 T& max() { return Tuple<2, T>::m_data[1]; }
760 const T& max() const { return Tuple<2, T>::m_data[1]; }
761
762 bool empty() const { return max() < min(); }
763 };
764
765 /**
766 * Defines an autocontrol region of interest (in pixel space). This region consists of a rectangle
767 * (inherited from the Rectangle<uint32_t> Tuple) and a floating point weight value.
768 */
769 class AcRegion : public Rectangle<uint32_t>
770 {
771 public:
772 AcRegion()
773 : Rectangle<uint32_t>(0, 0, 0, 0)
774 , m_weight(1.0f)
775 {}
776
777 AcRegion(uint32_t _left, uint32_t _top, uint32_t _right, uint32_t _bottom, float _weight)
778 : Rectangle<uint32_t>(_left, _top, _right, _bottom)
779 , m_weight(_weight)
780 {}
781
782 float& weight() { return m_weight; }
783 const float& weight() const { return m_weight; }
784
785 protected:
786 float m_weight;
787 };
788
789 /**
790 * A template class to hold a 2-dimensional array of data.
791 * Data in this array is tightly packed in a 1-dimensional vector in row-major order;
792 * that is, the vector index for any value given its 2-dimensional location (Point2D) is
793 * index = location.x() + (location.y() * size.x());
794 * Indexing operators using iterators, 1-dimensional, or 2-dimensional coordinates are provided.
795 */
796 template <typename T>
797 class Array2D
798 {
799 public:
800 // Iterator types.
801 typedef T* iterator;
802 typedef const T* const_iterator;
803
804 /// Default Constructor.
805 Array2D() : m_size(0, 0) {}
806
807 /// Constructor given initial array size.
808 Array2D(const Size2D<uint32_t>& size) : m_size(size)
809 {
810 m_data.resize(size.width() * size.height());
811 }
812
813 /// Constructor given initial array size and initial fill value.
814 Array2D(const Size2D<uint32_t>& size, const T& value) : m_size(size)
815 {
816 m_data.resize(size.width() * size.height(), value);
817 }
818
819 /// Copy constructor.
820 Array2D(const Array2D<T>& other)
821 {
822 m_data = other.m_data;
823 m_size = other.m_size;
824 }
825
826 /// Assignment operator.
827 Array2D& operator= (const Array2D<T>& other)
828 {
829 m_data = other.m_data;
830 m_size = other.m_size;
831 return *this;
832 }
833
834 /// Equality operator.
835 bool operator== (const Array2D<T>& other) const
836 {
837 return (m_size == other.m_size && m_data == other.m_data);
838 }
839
840 /// Returns the size (dimensions) of the array.
841 Size2D<uint32_t> size() const { return m_size; }
842
843 /// Resize the array. Array contents after resize are undefined.
844 /// Boolean return value enables error checking when exceptions are not available.
845 bool resize(const Size2D<uint32_t>& size)
846 {
847 uint32_t s = size.width() * size.height();
848 m_data.resize(s);
849 if (m_data.size() != s)
850 return false;
851 m_size = size;
852 return true;
853 }
854
855 /// STL style iterators.
856 inline const_iterator begin() const { return m_data.data(); }
857 inline const_iterator end() const { return m_data.data() + m_data.size(); }
858 inline iterator begin() { return m_data.data(); }
859 inline iterator end() { return m_data.data() + m_data.size(); }
860
861 /// Array indexing using [] operator.
862 T& operator[](unsigned int i) { return m_data[checkIndex(i)]; }
863 const T& operator[](unsigned int i) const { return m_data[checkIndex(i)]; }
864
865 /// Array indexing using () operator.
866 inline const T& operator() (uint32_t i) const { return m_data[checkIndex(i)]; }
867 inline const T& operator() (uint32_t x, uint32_t y) const { return m_data[checkIndex(x, y)]; }
868 inline const T& operator() (const Point2D<uint32_t>& p) const
869 { return m_data[checkIndex(p.x(), p.y())]; }
870 inline T& operator() (uint32_t i) { return m_data[checkIndex(i)]; }
871 inline T& operator() (uint32_t x, uint32_t y) { return m_data[checkIndex(x, y)]; }
872 inline T& operator() (const Point2D<uint32_t>& p)
873 { return m_data[checkIndex(p.x(), p.y())]; }
874
875 // Get pointers to data.
876 inline const T* data() const { return m_data.data(); }
877 inline T* data() { return m_data.data(); }
878
879 private:
880 inline uint32_t checkIndex(uint32_t i) const
881 {
882 assert(i < m_data.size());
883 return i;
884 }
885
886 inline uint32_t checkIndex(uint32_t x, uint32_t y) const
887 {
888 assert(x < m_size.width());
889 assert(y < m_size.height());
890 return x + (y * m_size.width());
891 }
892
893 std::vector<T> m_data;
894 Size2D<uint32_t> m_size;
895 };
896
897 typedef uint32_t AutoControlId;
898
899 } // namespace Argus
900
901 #endif // _ARGUS_TYPES_H