Image Component Library (ICL)
|
00001 /******************************************************************** 00002 ** Image Component Library (ICL) ** 00003 ** ** 00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** 00005 ** Neuroinformatics Group ** 00006 ** Website: www.iclcv.org and ** 00007 ** http://opensource.cit-ec.de/projects/icl ** 00008 ** ** 00009 ** File : ICLIO/src/ICLIO/FourCC.h ** 00010 ** Module : ICLIO ** 00011 ** Authors: Christof Elbrechter ** 00012 ** ** 00013 ** ** 00014 ** GNU LESSER GENERAL PUBLIC LICENSE ** 00015 ** This file may be used under the terms of the GNU Lesser General ** 00016 ** Public License version 3.0 as published by the ** 00017 ** ** 00018 ** Free Software Foundation and appearing in the file LICENSE.LGPL ** 00019 ** included in the packaging of this file. Please review the ** 00020 ** following information to ensure the license requirements will ** 00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** 00022 ** ** 00023 ** The development of this software was supported by the ** 00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** 00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** 00026 ** Forschungsgemeinschaft (DFG) in the context of the German ** 00027 ** Excellence Initiative. ** 00028 ** ** 00029 ********************************************************************/ 00030 00031 #pragma once 00032 00033 #include <ICLUtils/CompatMacros.h> 00034 #include <ICLUtils/BasicTypes.h> 00035 #include <ICLUtils/Exception.h> 00036 #include <string> 00037 #include <iostream> 00038 00039 namespace icl{ 00040 namespace io{ 00041 00043 00044 class ICLIO_API FourCC{ 00045 icl32s key; 00046 00047 public: 00049 FourCC():key(0){} 00050 00052 FourCC(icl32s key):key(key){} 00053 00055 FourCC(const std::string &key){ 00056 init(key); 00057 } 00058 00060 FourCC(const char *key){ 00061 init(key); 00062 } 00063 00065 void init(const std::string &key) throw (utils::ICLException){ 00066 if(key.length() != 4) throw utils::ICLException("FourCC::FourCC(string): invalid fourcc code " + key); 00067 if(key == "null") this->key = 0; 00068 else this->key = (((icl32u)(key[0])<<0)|((icl32u)(key[1])<<8)|((icl32u)(key[2])<<16)|((icl32u)(key[3])<<24)); 00069 } 00070 00072 inline FourCC &operator=(icl32s key) { return *this=FourCC(key); } 00073 00075 inline FourCC &operator=(const std::string &key) { return *this=FourCC(key); } 00076 00078 std::string asString() const { 00079 if(!key) return "null"; 00080 int tmp[2] = {key,0}; 00081 return std::string((char*)tmp); 00082 } 00083 00085 icl32s asInt() const { 00086 return key; 00087 } 00088 00090 operator bool() { return key != 0; } 00091 00093 operator int() { return asInt(); } 00094 }; 00095 00097 inline std::ostream &operator<<(std::ostream &stream, const FourCC &fourCC){ 00098 return stream << "FourCC(" << fourCC.asString() << ")" << std::endl; 00099 } 00100 00101 } // namespace io 00102 } 00103