00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <models/color/lookuptable.h>
00025
00026 #include <fvutils/color/yuv.h>
00027 #include <fvutils/colormap/yuvcm.h>
00028 #include <fvutils/colormap/cmfile.h>
00029 #include <fvutils/ipc/shm_lut.h>
00030
00031 #include <core/exceptions/software.h>
00032 #include <core/exceptions/system.h>
00033
00034 #include <iostream>
00035 #include <sys/utsname.h>
00036 #include <sys/stat.h>
00037 #include <unistd.h>
00038 #include <sys/types.h>
00039 #include <errno.h>
00040 #include <cstring>
00041 #include <cstdlib>
00042 #include <cmath>
00043
00044 using namespace std;
00045 using namespace fawkes;
00046
00047 namespace firevision {
00048 #if 0
00049 }
00050 #endif
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 ColorModelLookupTable::ColorModelLookupTable(YuvColormap *colormap)
00065 {
00066 __colormap = colormap;
00067 }
00068
00069
00070
00071
00072
00073 ColorModelLookupTable::ColorModelLookupTable(const char *lut_id, bool destroy_on_free)
00074 {
00075 __colormap = new YuvColormap(lut_id, destroy_on_free);
00076 }
00077
00078
00079
00080
00081
00082
00083
00084 ColorModelLookupTable::ColorModelLookupTable(unsigned int depth,
00085 const char *lut_id, bool destroy_on_free)
00086 {
00087 __colormap = new YuvColormap(lut_id, destroy_on_free, depth);
00088 }
00089
00090
00091
00092
00093
00094
00095
00096 ColorModelLookupTable::ColorModelLookupTable(const char *file,
00097 const char *lut_id, bool destroy_on_free)
00098 {
00099 ColormapFile cmf;
00100 cmf.read(file);
00101 Colormap *tcm = cmf.get_colormap();
00102 YuvColormap *tycm = dynamic_cast<YuvColormap *>(tcm);
00103 if ( ! tycm ) {
00104 delete tcm;
00105 throw TypeMismatchException("File does not contain a YUV colormap");
00106 }
00107 __colormap = new YuvColormap(tycm, lut_id, destroy_on_free);
00108 delete tcm;
00109 }
00110
00111
00112
00113
00114
00115 ColorModelLookupTable::ColorModelLookupTable(const char *file)
00116 {
00117 ColormapFile cmf;
00118 cmf.read(file);
00119 Colormap *tcm = cmf.get_colormap();
00120 __colormap = dynamic_cast<YuvColormap *>(tcm);
00121 if ( ! __colormap ) {
00122 delete tcm;
00123 throw TypeMismatchException("File does not contain a YUV colormap");
00124 }
00125 }
00126
00127
00128
00129 ColorModelLookupTable::~ColorModelLookupTable()
00130 {
00131 delete __colormap;
00132 }
00133
00134
00135 const char *
00136 ColorModelLookupTable::get_name()
00137 {
00138 return "ColorModelLookupTable";
00139 }
00140
00141
00142
00143
00144 YuvColormap *
00145 ColorModelLookupTable::get_colormap() const
00146 {
00147 return __colormap;
00148 }
00149
00150
00151
00152
00153
00154 void
00155 ColorModelLookupTable::load(const char *filename)
00156 {
00157 ColormapFile cmf;
00158 cmf.read(filename);
00159 Colormap *tcm = cmf.get_colormap();
00160 YuvColormap *tycm = dynamic_cast<YuvColormap *>(tcm);
00161 if ( ! tycm ) {
00162 delete tcm;
00163 throw TypeMismatchException("File does not contain a YUV colormap");
00164 }
00165 *__colormap = *tycm;
00166 delete tcm;
00167 }
00168
00169
00170
00171
00172
00173
00174
00175 ColorModelLookupTable &
00176 ColorModelLookupTable::operator+=(const ColorModelLookupTable &cmlt)
00177 {
00178 *__colormap += *(cmlt.__colormap);
00179 return *this;
00180 }
00181
00182
00183
00184 void
00185 ColorModelLookupTable::reset()
00186 {
00187 __colormap->reset();
00188 }
00189
00190
00191
00192
00193
00194
00195 std::string
00196 ColorModelLookupTable::compose_filename(const std::string format)
00197 {
00198 return ColormapFile::compose_filename(format);
00199 }
00200
00201 }