lookuptable.cpp
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
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 ColorModelLookupTable::ColorModelLookupTable(YuvColormap *colormap)
00060 {
00061 __colormap = colormap;
00062 }
00063
00064
00065
00066
00067
00068 ColorModelLookupTable::ColorModelLookupTable(const char *lut_id, bool destroy_on_free)
00069 {
00070 __colormap = new YuvColormap(lut_id, destroy_on_free);
00071 }
00072
00073
00074
00075
00076
00077
00078
00079 ColorModelLookupTable::ColorModelLookupTable(unsigned int depth,
00080 const char *lut_id, bool destroy_on_free)
00081 {
00082 __colormap = new YuvColormap(lut_id, destroy_on_free, depth);
00083 }
00084
00085
00086
00087
00088
00089
00090
00091 ColorModelLookupTable::ColorModelLookupTable(const char *file,
00092 const char *lut_id, bool destroy_on_free)
00093 {
00094 ColormapFile cmf;
00095 cmf.read(file);
00096 Colormap *tcm = cmf.get_colormap();
00097 YuvColormap *tycm = dynamic_cast<YuvColormap *>(tcm);
00098 if ( ! tycm ) {
00099 delete tcm;
00100 throw TypeMismatchException("File does not contain a YUV colormap");
00101 }
00102 __colormap = new YuvColormap(tycm, lut_id, destroy_on_free);
00103 delete tcm;
00104 }
00105
00106
00107
00108
00109
00110 ColorModelLookupTable::ColorModelLookupTable(const char *file)
00111 {
00112 ColormapFile cmf;
00113 cmf.read(file);
00114 Colormap *tcm = cmf.get_colormap();
00115 __colormap = dynamic_cast<YuvColormap *>(tcm);
00116 if ( ! __colormap ) {
00117 delete tcm;
00118 throw TypeMismatchException("File does not contain a YUV colormap");
00119 }
00120 }
00121
00122
00123
00124 ColorModelLookupTable::~ColorModelLookupTable()
00125 {
00126 delete __colormap;
00127 }
00128
00129
00130 const char *
00131 ColorModelLookupTable::get_name()
00132 {
00133 return "ColorModelLookupTable";
00134 }
00135
00136
00137
00138
00139 YuvColormap *
00140 ColorModelLookupTable::get_colormap() const
00141 {
00142 return __colormap;
00143 }
00144
00145
00146
00147
00148
00149 void
00150 ColorModelLookupTable::load(const char *filename)
00151 {
00152 ColormapFile cmf;
00153 cmf.read(filename);
00154 Colormap *tcm = cmf.get_colormap();
00155 YuvColormap *tycm = dynamic_cast<YuvColormap *>(tcm);
00156 if ( ! tycm ) {
00157 delete tcm;
00158 throw TypeMismatchException("File does not contain a YUV colormap");
00159 }
00160 *__colormap = *tycm;
00161 delete tcm;
00162 }
00163
00164
00165
00166
00167
00168
00169
00170 ColorModelLookupTable &
00171 ColorModelLookupTable::operator+=(const ColorModelLookupTable &cmlt)
00172 {
00173 *__colormap += *(cmlt.__colormap);
00174 return *this;
00175 }
00176
00177
00178
00179 void
00180 ColorModelLookupTable::reset()
00181 {
00182 __colormap->reset();
00183 }
00184
00185
00186
00187
00188
00189
00190 std::string
00191 ColorModelLookupTable::compose_filename(const std::string format)
00192 {
00193 return ColormapFile::compose_filename(format);
00194 }