Argus API Argus Camera API

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Types.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2016, 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 #ifndef _ARGUS_TYPES_H
30 #define _ARGUS_TYPES_H
31
32 /**
33 * @file Types.h
34 * Defines the basic types that are used by the API.
35 */
36
37 #include <stdint.h>
38 #include <vector>
39 #include <assert.h>
40
41 #include <EGL/egl.h>
42 #include <EGL/eglext.h>
43
44 // Some versions of the Xlib.h header file define 'Status' to 'int'. This collides with the Argus
45 // 'Status' type.
46 // If 'Status' is defined then undefine it and use a typedef instead.
47 #ifdef Status
48 #undef Status
49 typedef int Status;
50 #endif // Status
51
52 namespace Argus
53 {
54
55 /*
56 * Forward declaration of standard objects
57 */
58 class CameraDevice;
59 class CameraProvider;
60 class CaptureSession;
61 class CaptureMetadata;
62 class CaptureMetadataContainer;
63 class Event;
64 class EventQueue;
65 class InputStream;
66 class OutputStream;
67 class OutputStreamSettings;
68 class Request;
69 class SensorMode;
70
71 /*
72 * Forward declaration of standard interfaces
73 */
74 class ICameraProperties;
75 class ICameraProvider;
76 class ICaptureSession;
77 class IAutoControlSettings;
78 class IRequest;
79 class IStream;
80 class IStreamSettings;
81
82 /**
83 * Constant used for infinite timeouts.
84 */
85 const uint64_t TIMEOUT_INFINITE = 0xFFFFFFFFFFFFFFFF;
86
87 /**
88 * Extension name UUID. Values are defined in extension headers.
89 */
90 class ExtensionName : public NamedUUID
91 {
92 public:
93 ExtensionName(uint32_t time_low_
94 , uint16_t time_mid_
95 , uint16_t time_hi_and_version_
96 , uint16_t clock_seq_
97 , uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint8_t c5
98 , const char* name)
99 : NamedUUID(time_low_, time_mid_, time_hi_and_version_, clock_seq_,
100 c0, c1, c2, c3, c4, c5, name)
101 {}
102
103 ExtensionName()
104 : NamedUUID(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "EXT_UNSPECIFIED")
105 {}
106 };
107
108 /*
109 * Named UUID classes.
110 */
111
112 DEFINE_NAMED_UUID_CLASS(AwbMode);
113 DEFINE_NAMED_UUID_CLASS(CaptureIntent);
114 DEFINE_NAMED_UUID_CLASS(DenoiseMode);
115 DEFINE_NAMED_UUID_CLASS(EdgeEnhanceMode);
116 DEFINE_NAMED_UUID_CLASS(SensorModeType);
117 DEFINE_NAMED_UUID_CLASS(VideoStabilizationMode);
118
119 /*
120 * Named UUIDs sorted alphabetically.
121 */
122
123 DEFINE_UUID(AwbMode, AWB_MODE_OFF, FB3F365A,CC62,11E5,9956,62,56,62,87,07,61);
124 DEFINE_UUID(AwbMode, AWB_MODE_AUTO, FB3F365B,CC62,11E5,9956,62,56,62,87,07,61);
125 DEFINE_UUID(AwbMode, AWB_MODE_INCANDESCENT, FB3F365C,CC62,11E5,9956,62,56,62,87,07,61);
126 DEFINE_UUID(AwbMode, AWB_MODE_FLUORESCENT, FB3F365D,CC62,11E5,9956,62,56,62,87,07,61);
127 DEFINE_UUID(AwbMode, AWB_MODE_WARM_FLUORESCENT, FB3F365E,CC62,11E5,9956,62,56,62,87,07,61);
128 DEFINE_UUID(AwbMode, AWB_MODE_DAYLIGHT, FB3F365F,CC62,11E5,9956,62,56,62,87,07,61);
129 DEFINE_UUID(AwbMode, AWB_MODE_CLOUDY_DAYLIGHT, FB3F3660,CC62,11E5,9956,62,56,62,87,07,61);
130 DEFINE_UUID(AwbMode, AWB_MODE_TWILIGHT, FB3F3661,CC62,11E5,9956,62,56,62,87,07,61);
131 DEFINE_UUID(AwbMode, AWB_MODE_SHADE, FB3F3662,CC62,11E5,9956,62,56,62,87,07,61);
132 DEFINE_UUID(AwbMode, AWB_MODE_MANUAL, 20FB45DA,C49F,4293,AB02,13,3F,8C,CA,DD,69);
133
134 DEFINE_UUID(CaptureIntent, CAPTURE_INTENT_MANUAL,
135 FB3F3663,CC62,11E5,9956,62,56,62,87,07,61);
136 DEFINE_UUID(CaptureIntent, CAPTURE_INTENT_PREVIEW,
137 FB3F3664,CC62,11E5,9956,62,56,62,87,07,61);
138 DEFINE_UUID(CaptureIntent, CAPTURE_INTENT_STILL_CAPTURE,
139 FB3F3665,CC62,11E5,9956,62,56,62,87,07,61);
140 DEFINE_UUID(CaptureIntent, CAPTURE_INTENT_VIDEO_RECORD,
141 FB3F3666,CC62,11E5,9956,62,56,62,87,07,61);
142 DEFINE_UUID(CaptureIntent, CAPTURE_INTENT_VIDEO_SNAPSHOT,
143 FB3F3667,CC62,11E5,9956,62,56,62,87,07,61);
144
145 DEFINE_UUID(DenoiseMode, DENOISE_MODE_OFF, FB3F3668,CC62,11E5,9956,62,56,62,87,07,61);
146 DEFINE_UUID(DenoiseMode, DENOISE_MODE_FAST, FB3F3669,CC62,11E5,9956,62,56,62,87,07,61);
147 DEFINE_UUID(DenoiseMode, DENOISE_MODE_HIGH_QUALITY, FB3F366A,CC62,11E5,9956,62,56,62,87,07,61);
148
149 DEFINE_UUID(EdgeEnhanceMode, EDGE_ENHANCE_MODE_OFF, F7100B40,6A5F,11E6,BDF4,08,00,20,0C,9A,66);
150 DEFINE_UUID(EdgeEnhanceMode, EDGE_ENHANCE_MODE_FAST, F7100B41,6A5F,11E6,BDF4,08,00,20,0C,9A,66);
151 DEFINE_UUID(EdgeEnhanceMode, EDGE_ENHANCE_MODE_HIGH_QUALITY, F7100B42,6A5F,11E6,BDF4,08,00,20,0C,9A,66);
152
153 DEFINE_UUID(SensorModeType, SENSOR_MODE_TYPE_DEPTH,
154 64483464,4b91,11e6,bbbd,40,16,7e,ab,86,92);
155 DEFINE_UUID(SensorModeType, SENSOR_MODE_TYPE_YUV,
156 6453e00c,4b91,11e6,871d,40,16,7e,ab,86,92);
157 DEFINE_UUID(SensorModeType, SENSOR_MODE_TYPE_RGB,
158 6463d4c6,4b91,11e6,88a3,40,16,7e,ab,86,92);
159 DEFINE_UUID(SensorModeType, SENSOR_MODE_TYPE_BAYER,
160 646f04ea,4b91,11e6,9c06,40,16,7e,ab,86,92);
161
162 DEFINE_UUID(VideoStabilizationMode, VIDEO_STABILIZATION_MODE_OFF,
163 FB3F366E,CC62,11E5,9956,62,56,62,87,07,61);
164 DEFINE_UUID(VideoStabilizationMode, VIDEO_STABILIZATION_MODE_ON,
165 FB3F366F,CC62,11E5,9956,62,56,62,87,07,61);
166
167 /*
168 * Camera settings constants - sorted alphabetically.
169 */
170
171 enum AeAntibandingMode
172 {
173 AE_ANTIBANDING_MODE_OFF,
174 AE_ANTIBANDING_MODE_AUTO,
175 AE_ANTIBANDING_MODE_50HZ,
176 AE_ANTIBANDING_MODE_60HZ,
177
178 AE_ANTIBANDING_MODE_COUNT
179 };
180
181 enum AeState
182 {
183 AE_STATE_INACTIVE,
184 AE_STATE_SEARCHING,
185 AE_STATE_CONVERGED,
186 AE_STATE_FLASH_REQUIRED,
187 AE_STATE_LOCKED,
188
189 AE_STATE_COUNT
190 };
191
192 enum AwbState
193 {
194 AWB_STATE_INACTIVE,
195 AWB_STATE_SEARCHING,
196 AWB_STATE_CONVERGED,
197 AWB_STATE_LOCKED,
198
199 AWB_STATE_COUNT
200 };
201
202 enum BayerChannel
203 {
204 BAYER_CHANNEL_R,
205 BAYER_CHANNEL_G_EVEN,
206 BAYER_CHANNEL_G_ODD,
207 BAYER_CHANNEL_B,
208
209 BAYER_CHANNEL_COUNT
210 };
211
212 /**
213 * Status values returned by API function calls.
214 */
215 enum Status
216 {
217 /// Function succeeded.
218 STATUS_OK,
219
220 /// The set of parameters passed was invalid.
221 STATUS_INVALID_PARAMS,
222
223 /// The requested settings are invalid.
224 STATUS_INVALID_SETTINGS,
225
226 /// The requested device is unavailable.
227 STATUS_UNAVAILABLE,
228
229 /// An operation failed because of insufficient mavailable memory.
230 STATUS_OUT_OF_MEMORY,
231
232 /// This method has not been implemented.
233 STATUS_UNIMPLEMENTED,
234
235 /// An operation timed out.
236 STATUS_TIMEOUT,
237
238 /// The capture was aborted. @see ICaptureSession::cancelRequests()
239 STATUS_CANCELLED,
240
241 /// The stream or other resource has been disconnected.
242 STATUS_DISCONNECTED,
243
244 // Number of elements in this enum.
245 STATUS_COUNT
246 };
247
248 enum RGBColorChannel
249 {
250 RGB_CHANNEL_RED,
251 RGB_CHANNEL_GREEN,
252 RGB_CHANNEL_BLUE,
253
254 RGB_CHANNEL_COUNT
255 };
256
257
258 /**
259 * Pixel formats.
260 */
261 class PixelFormat : public NamedUUID
262 {
263 public:
264 PixelFormat(uint32_t time_low_
265 , uint16_t time_mid_
266 , uint16_t time_hi_and_version_
267 , uint16_t clock_seq_
268 , uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint8_t c5
269 , const char* name)
270 : NamedUUID(time_low_, time_mid_, time_hi_and_version_, clock_seq_,
271 c0, c1, c2, c3, c4, c5, name)
272 {}
273
274 private:
275 PixelFormat(); // No default c'tor please use PIXEL_FMT_UNKNOWN
276 };
277
278 DEFINE_UUID(PixelFormat, PIXEL_FMT_UNKNOWN, 00000000,93d5,11e5,0000,1c,b7,2c,ef,d4,1e);
279 DEFINE_UUID(PixelFormat, PIXEL_FMT_Y8, 569be14a,93d5,11e5,91bc,1c,b7,2c,ef,d4,1e);
280 DEFINE_UUID(PixelFormat, PIXEL_FMT_Y16, 56ddb19c,93d5,11e5,8e2c,1c,b7,2c,ef,d4,1e);
281 DEFINE_UUID(PixelFormat, PIXEL_FMT_YCbCr_420_888, 570c10e6,93d5,11e5,8ff3,1c,b7,2c,ef,d4,1e);
282 DEFINE_UUID(PixelFormat, PIXEL_FMT_YCbCr_422_888, 573a7940,93d5,11e5,99c2,1c,b7,2c,ef,d4,1e);
283 DEFINE_UUID(PixelFormat, PIXEL_FMT_YCbCr_444_888, 576043dc,93d5,11e5,8983,1c,b7,2c,ef,d4,1e);
284 DEFINE_UUID(PixelFormat, PIXEL_FMT_JPEG_BLOB, 578b08c4,93d5,11e5,9686,1c,b7,2c,ef,d4,1e);
285 DEFINE_UUID(PixelFormat, PIXEL_FMT_RAW16, 57b484d8,93d5,11e5,aeb6,1c,b7,2c,ef,d4,1e);
286
287 /**
288 * Utility class for Argus interfaces.
289 */
290 class NonCopyable
291 {
292 protected:
293 NonCopyable() {}
294
295 private:
296 NonCopyable(NonCopyable& other);
297 NonCopyable& operator=(NonCopyable& other);
298 };
299
300 /**
301 * The top-level interface class.
302 *
303 * By convention, every Interface subclass exposes a public static method called @c id(),
304 * which returns the unique InterfaceID for that interface.
305 * This is required for the @c interface_cast<> template to work with that interface.
306 */
307 class Interface : NonCopyable
308 {
309 protected:
310 Interface() {}
311 ~Interface() {}
312 };
313
314 /**
315 * A unique identifier for an Argus Interface.
316 */
317 class InterfaceID : public NamedUUID
318 {
319 public:
320 InterfaceID(uint32_t time_low_
321 , uint16_t time_mid_
322 , uint16_t time_hi_and_version_
323 , uint16_t clock_seq_
324 , uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4, uint8_t c5
325 , const char* name)
326 : NamedUUID(time_low_, time_mid_, time_hi_and_version_, clock_seq_,
327 c0, c1, c2, c3, c4, c5, name)
328 {}
329
330 InterfaceID()
331 : NamedUUID(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "IID_UNSPECIFIED")
332 {}
333 };
334
335 /**
336 * The base interface for a class that provides Argus Interfaces.
337 */
338 class InterfaceProvider : NonCopyable
339 {
340 public:
341
342 /**
343 * Acquire the interface specified by @c interfaceId.
344 * @returns An instance of the requested interface,
345 * or NULL if that interface is not available.
346 */
347 virtual Interface* getInterface(const InterfaceID& interfaceId) = 0;
348
349 protected:
350 ~InterfaceProvider() {}
351 };
352
353 /**
354 * Interface-casting helper similar to dynamic_cast.
355 */
356
357 template <typename TheInterface>
358 inline TheInterface* interface_cast(InterfaceProvider* obj)
359 {
360 return static_cast<TheInterface*>(obj ? obj->getInterface(TheInterface::id()): 0);
361 }
362
363 template <typename TheInterface>
364 inline TheInterface* interface_cast(const InterfaceProvider* obj)
365 {
366 return static_cast<TheInterface*>(
367 obj ? const_cast<const Interface*>(
368 const_cast< InterfaceProvider*>(obj)->getInterface(TheInterface::id())): 0);
369 }
370
371 /**
372 * A top level object class for Argus objects that are created and owned by
373 * the client. All Destructable objects created by the client must be explicitly destroyed.
374 */
375 class Destructable
376 {
377 public:
378
379 /**
380 * Destroy this object.
381 * After making this call, the client cannot make any more calls on this object.
382 */
383 virtual void destroy() = 0;
384
385 protected:
386 ~Destructable() {}
387 };
388
389 /**
390 * Template helper emulating C++11 rvalue semantics.
391 */
392 template<typename T>
393 class rv : public T
394 {
395 rv();
396 ~rv();
397 rv(const rv&);
398 void operator=(const rv&);
399 };
400
401 template<typename T>
402 rv<T>& move(T& self)
403 {
404 return *static_cast< rv<T>*>(&self);
405 }
406
407 /**
408 * Movable smart pointer mimicking std::unique_ptr.
409 */
410 template <typename T> struct remove_const;
411 template <typename T> struct remove_const<const T&>{ typedef T& type; };
412 template <typename T> struct remove_const<const T*>{ typedef T* type; };
413 template <typename T> struct remove_const<const T >{ typedef T type; };
414 template <typename T> struct remove_const { typedef T type; };
415
416 template <typename T>
417 class UniqueObj : NonCopyable
418 {
419 public:
420 explicit UniqueObj(T* obj=NULL): m_obj(obj) {}
421
422 void reset(T* obj=NULL)
423 { if (m_obj) const_cast<typename remove_const<T*>::type >(m_obj)->destroy(); m_obj = obj; }
424 T* release()
425 { T* obj = m_obj; m_obj = NULL; return obj; }
426
427 UniqueObj( rv<UniqueObj>& moved ): m_obj(moved.release()) {}
428 UniqueObj& operator=( rv<UniqueObj>& moved ){ reset( moved.release()); return *this; }
429
430 ~UniqueObj() { reset(); }
431
432 T& operator*() const { return *m_obj; }
433 T* get() const { return m_obj; }
434
435 operator bool() const { return !!m_obj; }
436
437 operator rv<UniqueObj>&() { return *static_cast< rv<UniqueObj>*>(this); }
438 operator const rv<UniqueObj>&() const { return *static_cast<const rv<UniqueObj>*>(this); }
439
440 private:
441 T* m_obj;
442
443 T* operator->() const; // Prevent calling destroy() directly.
444 // Note: For getInterface functionality use interface_cast.
445 };
446
447 template <typename TheInterface, typename TObject>
448 inline TheInterface* interface_cast(const UniqueObj<TObject>& obj)
449 {
450 return interface_cast<TheInterface>( obj.get());
451 }
452
453 /**
454 * A templatized class to hold a min/max range of values.
455 */
456 template <typename T>
457 struct Range
458 {
459 T min;
460 T max;
461
462 Range(T value) : min( value ), max( value ) {}
463 Range(T min, T max) : min( min ), max( max ) {};
464 bool operator== (const Range<T>& rhs) const
465 {
466 return (min == rhs.min && max == rhs.max);
467 }
468
469 bool empty() const
470 {
471 return max < min;
472 }
473 };
474
475 /**
476 * Defines a rectangle in pixel space.
477 */
478 struct Rectangle
479 {
480 uint32_t left;
481 uint32_t top;
482 uint32_t width;
483 uint32_t height;
484
485 Rectangle() : left(0), top(0), width(0), height(0) {}
486 Rectangle(uint32_t _left, uint32_t _top, uint32_t _width, uint32_t _height)
487 : left(_left), top(_top), width(_width), height(_height)
488 {}
489
490 bool operator==(const Rectangle& other) const
491 {
492 return (left == other.left) && (top == other.top) &&
493 (width == other.width) && (height == other.height);
494 }
495 };
496
497 /**
498 * Aggregates width and height in a single structure.
499 */
500 struct Size
501 {
502 uint32_t width;
503 uint32_t height;
504
505 Size() : width(0), height(0) {}
506
507 /// Construct size from width and height
508 Size(uint32_t w, uint32_t h) : width(w), height(h) {}
509
510 bool operator==(const Size& a) const
511 {
512 return width == a.width && height == a.height;
513 }
514
515 Size operator+(const Size& b) const
516 {
517 return Size(width + b.width, height + b.height);
518 }
519
520 Size operator-(const Size& b) const
521 {
522 return Size(width - b.width, height - b.height);
523 }
524 };
525
526 /**
527 * Aggregates 2D co-ordinates of a location in a single structure.
528 */
529 struct Location
530 {
531 uint32_t x;
532 uint32_t y;
533
534 Location() : x(0), y(0) {}
535
536 /// Construct location from x and y
537 Location(uint32_t a, uint32_t b) : x(a), y(b) {}
538
539 bool operator==(const Location& other) const
540 {
541 return x == other.x && y == other.y;
542 }
543 };
544
545 /**
546 * Defines a normalized rectangle region in [0.0, 1.0].
547 */
548 struct NormalizedRect
549 {
550 float left;
551 float top;
552 float right;
553 float bottom;
554
555 NormalizedRect() : left(0.0f), top(0.0f), right(1.0f), bottom(1.0f) {}
556 NormalizedRect(float l, float t, float r, float b) : left(l), top(t), right(r), bottom(b) {}
557 bool operator==(const NormalizedRect& other) const
558 {
559 return (left == other.left) &&
560 (top == other.top) &&
561 (right == other.right) &&
562 (bottom == other.bottom);
563 }
564 };
565
566 /**
567 * Tuple template class. This provides a finite ordered list of N elements having type T.
568 */
569 template <unsigned int N, typename T>
570 struct Tuple
571 {
572 T data[N];
573
574 bool operator==(const Tuple<N,T>& other) const {
575 return !memcmp(data, other.data, sizeof(data));
576 }
577
578 T& operator[](unsigned int i) { assert(i < N); return data[i]; }
579 const T& operator[](unsigned int i) const { assert(i < N); return data[i]; }
580 };
581
582 /**
583 * BayerTuple template class. This is a Tuple specialization containing 4 elements corresponding
584 * to the Bayer color channels: R, G_EVEN, G_ODD, and B. Values can be accessed using the named
585 * methods or subscript indexing using the Argus::BayerChannel enum.
586 */
587 template <typename T>
588 struct BayerTuple : public Tuple<BAYER_CHANNEL_COUNT, T>
589 {
590 BayerTuple() {}
591 BayerTuple(T r, T gEven, T gOdd, T b)
592 {
593 Tuple<BAYER_CHANNEL_COUNT, T>::data[BAYER_CHANNEL_R] = r;
594 Tuple<BAYER_CHANNEL_COUNT, T>::data[BAYER_CHANNEL_G_EVEN] = gEven;
595 Tuple<BAYER_CHANNEL_COUNT, T>::data[BAYER_CHANNEL_G_ODD] = gOdd;
596 Tuple<BAYER_CHANNEL_COUNT, T>::data[BAYER_CHANNEL_B] = b;
597 }
598
599 T& r() { return Tuple<BAYER_CHANNEL_COUNT, T>::data[BAYER_CHANNEL_R]; }
600 const T& r() const { return Tuple<BAYER_CHANNEL_COUNT, T>::data[BAYER_CHANNEL_R]; }
601 T& gEven() { return Tuple<BAYER_CHANNEL_COUNT, T>::data[BAYER_CHANNEL_G_EVEN]; }
602 const T& gEven() const { return Tuple<BAYER_CHANNEL_COUNT, T>::data[BAYER_CHANNEL_G_EVEN]; }
603 T& gOdd() { return Tuple<BAYER_CHANNEL_COUNT, T>::data[BAYER_CHANNEL_G_ODD]; }
604 const T& gOdd() const { return Tuple<BAYER_CHANNEL_COUNT, T>::data[BAYER_CHANNEL_G_ODD]; }
605 T& b() { return Tuple<BAYER_CHANNEL_COUNT, T>::data[BAYER_CHANNEL_B]; }
606 const T& b() const { return Tuple<BAYER_CHANNEL_COUNT, T>::data[BAYER_CHANNEL_B]; }
607 };
608
609 /**
610 * Defines an autocontrol region of interest (in pixel space).
611 */
612 struct AcRegion
613 {
614 AcRegion()
615 : rect(0, 0, 0, 0)
616 , weight(1.0f)
617 {}
618
619 AcRegion(uint32_t _left, uint32_t _top, uint32_t _width, uint32_t _height, float _weight)
620 : rect(_left, _top, _width, _height)
621 , weight(_weight)
622 {}
623
624 bool operator==(const AcRegion& other) const
625 {
626 return (weight == other.weight) &&
627 (rect == other.rect);
628 }
629
630 Rectangle rect;
631 float weight;
632 };
633
634 /**
635 * A template class to hold a 2-dimensional array of data.
636 * Data in this array is tightly packed in a 1-dimensional vector in row-major order;
637 * that is, the vector index for any value given its 2-dimensional Location is
638 * index = location.x + (location.y * size.x);
639 * Indexing operators using iterators, 1-dimensional, or 2-dimensional coordinates are provided.
640 */
641 template <typename T>
642 class Array2D
643 {
644 public:
645 // Iterator types.
646 typedef T* iterator;
647 typedef const T* const_iterator;
648
649 /// Default Constructor.
650 Array2D() : m_size(0, 0) {}
651
652 /// Constructor given initial array size.
653 Array2D(Size size) : m_size(size)
654 {
655 m_data.resize(size.width * size.height);
656 }
657
658 /// Constructor given initial array size and initial fill value.
659 Array2D(Size size, const T& value) : m_size(size)
660 {
661 m_data.resize(size.width * size.height, value);
662 }
663
664 /// Copy constructor.
665 Array2D(const Array2D<T>& other)
666 {
667 m_data = other.m_data;
668 m_size = other.m_size;
669 }
670
671 /// Assignment operator.
672 Array2D& operator= (const Array2D<T>& other)
673 {
674 m_data = other.m_data;
675 m_size = other.m_size;
676 return *this;
677 }
678
679 /// Equality operator.
680 bool operator== (const Array2D<T>& other) const
681 {
682 return (m_size == other.m_size && m_data == other.m_data);
683 }
684
685 /// Returns the size (dimensions) of the array.
686 Size size() const { return m_size; }
687
688 /// Resize the array. Array contents after resize are undefined.
689 /// Boolean return value enables error checking when exceptions are not available.
690 bool resize(Size size)
691 {
692 uint32_t s = size.width * size.height;
693 m_data.resize(s);
694 if (m_data.size() != s)
695 return false;
696 m_size = size;
697 return true;
698 }
699
700 /// STL style iterators.
701 inline const_iterator begin() const { return m_data.data(); }
702 inline const_iterator end() const { return m_data.data() + m_data.size(); }
703 inline iterator begin() { return m_data.data(); }
704 inline iterator end() { return m_data.data() + m_data.size(); }
705
706 /// Array indexing using [] operator.
707 T& operator[](unsigned int i) { return m_data[checkIndex(i)]; }
708 const T& operator[](unsigned int i) const { return m_data[checkIndex(i)]; }
709
710 /// Array indexing using () operator.
711 inline const T& operator() (uint32_t i) const { return m_data[checkIndex(i)]; }
712 inline const T& operator() (uint32_t x, uint32_t y) const { return m_data[checkIndex(x, y)]; }
713 inline const T& operator() (Location l) const { return m_data[checkIndex(l.x, l.y)]; }
714 inline T& operator() (uint32_t i) { return m_data[checkIndex(i)]; }
715 inline T& operator() (uint32_t x, uint32_t y) { return m_data[checkIndex(x, y)]; }
716 inline T& operator() (Location l) { return m_data[checkIndex(l.x, l.y)]; }
717
718 // Get pointers to data.
719 inline const T* data() const { return m_data.data(); }
720 inline T* data() { return m_data.data(); }
721
722 private:
723 inline uint32_t checkIndex(uint32_t i) const
724 {
725 assert(i < m_data.size());
726 return i;
727 }
728
729 inline uint32_t checkIndex(uint32_t x, uint32_t y) const
730 {
731 assert(x < m_size.width);
732 assert(y < m_size.height);
733 return x + (y * m_size.width);
734 }
735
736 std::vector<T> m_data;
737 Size m_size;
738 };
739
740 typedef uint32_t AutoControlId;
741
742 } // namespace Argus
743
744 #endif // _ARGUS_TYPES_H