Image Component Library (ICL)
FourCC.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLIO/src/ICLIO/FourCC.h **
10 ** Module : ICLIO **
11 ** Authors: Christof Elbrechter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/CompatMacros.h>
34 #include <ICLUtils/BasicTypes.h>
35 #include <ICLUtils/Exception.h>
36 #include <string>
37 #include <iostream>
38 
39 namespace icl{
40  namespace io{
41 
43 
46 
47  public:
49  FourCC():key(0){}
50 
52  FourCC(icl32s key):key(key){}
53 
55  FourCC(const std::string &key){
56  init(key);
57  }
58 
60  FourCC(const char *key){
61  init(key);
62  }
63 
65  void init(const std::string &key) {
66  if(key.length() != 4) throw utils::ICLException("FourCC::FourCC(string): invalid fourcc code " + key);
67  if(key == "null") this->key = 0;
68  else this->key = (((icl32u)(key[0])<<0)|((icl32u)(key[1])<<8)|((icl32u)(key[2])<<16)|((icl32u)(key[3])<<24));
69  }
70 
72  inline FourCC &operator=(icl32s key) { return *this=FourCC(key); }
73 
75  inline FourCC &operator=(const std::string &key) { return *this=FourCC(key); }
76 
78  std::string asString() const {
79  if(!key) return "null";
80  int tmp[2] = {key,0};
81  return std::string((char*)tmp);
82  }
83 
85  icl32s asInt() const {
86  return key;
87  }
88 
90  operator bool() { return key != 0; }
91 
93  operator int() { return asInt(); }
94  };
95 
97  inline std::ostream &operator<<(std::ostream &stream, const FourCC &fourCC){
98  return stream << "FourCC(" << fourCC.asString() << ")" << std::endl;
99  }
100 
101  } // namespace io
102 }
103 
undocument this line if you encounter any issues!
Definition: Any.h:37
icl32s key
internally a fourcc is represented by an u-int value
Definition: FourCC.h:45
icl32s asInt() const
obtain current key (uint)
Definition: FourCC.h:85
Ipp32s icl32s
32bit signed integer type for the ICL
Definition: BasicTypes.h:58
#define ICLIO_API
Definition: CompatMacros.h:176
FourCC(const std::string &key)
create a fourCC from given string color code (e.g. Y422 or MJPG)
Definition: FourCC.h:55
FourCC & operator=(const std::string &key)
std::string-assignment
Definition: FourCC.h:75
FourCC()
create a null FourCC (key = 0)
Definition: FourCC.h:49
FourCC & operator=(icl32s key)
int-assignment
Definition: FourCC.h:72
uint32_t icl32u
32bit unsigned integer type for the ICL
Definition: BasicTypes.h:88
Wrapper class for fourcc color codes.
Definition: FourCC.h:44
Base class for Exception handling in the ICL.
Definition: Exception.h:42
std::ostream & operator<<(std::ostream &stream, const FourCC &fourCC)
overloaded ostream operator for type fourCC
Definition: FourCC.h:97
void init(const std::string &key)
initialization utility method
Definition: FourCC.h:65
std::string asString() const
convert to string
Definition: FourCC.h:78
FourCC(const char *key)
create a fourCC from given string color code (cstring style)
Definition: FourCC.h:60
FourCC(icl32s key)
create a FourCC with given key
Definition: FourCC.h:52