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