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