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