00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef SCRIPT_MEDIASCRIPT_C_DEFINED
00039 #define SCRIPT_MEDIASCRIPT_C_DEFINED
00040
00041 #include "Script/MediaScript.H"
00042
00043 #include "Component/OptionManager.H"
00044 #include "Image/Image.H"
00045 #include "Image/Pixels.H"
00046 #include "Media/FrameSeries.H"
00047 #include "Media/SimFrameSeries.H"
00048 #include "Script/ImageScript.H"
00049 #include "Script/ModelScript.H"
00050 #include "rutz/error.h"
00051 #include "rutz/sfmt.h"
00052 #include "tcl/list.h"
00053 #include "tcl/objpkg.h"
00054 #include "tcl/pkg.h"
00055 #include "tcl/stdconversions.h"
00056
00057 using nub::soft_ref;
00058
00059 namespace
00060 {
00061 tcl::list ifsDims(soft_ref<InputFrameSeries> ifs)
00062 {
00063 Dims d = ifs->peekDims();
00064 tcl::list result;
00065 result.append(d.w());
00066 result.append(d.h());
00067 return result;
00068 }
00069
00070 Image< PixRGB<byte> > ifsReadRGB(soft_ref<InputFrameSeries> ifs)
00071 { return ifs->readRGB(); }
00072
00073 Image<byte> ifsReadGray(soft_ref<InputFrameSeries> ifs)
00074 { return ifs->readGray(); }
00075
00076 void ofsWriteRGB(soft_ref<OutputFrameSeries> ofs,
00077 const Image< PixRGB<byte> >& image,
00078 const char* stem)
00079 { ofs->writeRGB(image, stem); }
00080
00081 void ofsWriteGray(soft_ref<OutputFrameSeries> ofs,
00082 const Image<byte>& image,
00083 const char* stem)
00084 { ofs->writeGray(image, stem); }
00085
00086 void ofsWriteFloat(soft_ref<OutputFrameSeries> ofs,
00087 const Image<float>& image,
00088 const char* stem)
00089 { ofs->writeFloat(image, FLOAT_NORM_0_255, stem); }
00090 }
00091
00092 tcl::obj tcl::aux_convert_from(const FrameState s)
00093 {
00094 switch (s)
00095 {
00096 case FRAME_SAME: return tcl::convert_from("SAME");
00097 case FRAME_NEXT: return tcl::convert_from("NEXT");
00098 case FRAME_FINAL: return tcl::convert_from("FINAL");
00099 case FRAME_COMPLETE: return tcl::convert_from("COMPLETE");
00100 }
00101
00102
00103 throw rutz::error(rutz::sfmt("unknown FrameState '%d'", int(s)),
00104 SRC_POS);
00105
00106 return tcl::obj();
00107 }
00108
00109 FrameState tcl::aux_convert_to(Tcl_Obj* obj, FrameState*)
00110 {
00111 const rutz::fstring f = tcl::aux_convert_to(obj, (rutz::fstring*)0);
00112
00113 if (f == "SAME") return FRAME_SAME;
00114 else if (f == "NEXT") return FRAME_NEXT;
00115 else if (f == "FINAL") return FRAME_FINAL;
00116 else if (f == "COMPLETE") return FRAME_COMPLETE;
00117
00118
00119 throw rutz::error(rutz::sfmt("unknown FrameSeries:State '%s'",
00120 f.c_str()), SRC_POS);
00121
00122 return FrameState(0);
00123 }
00124
00125 tcl::obj tcl::aux_convert_from(SimTime t)
00126 {
00127 return tcl::convert_from(t.nsecs());
00128 }
00129
00130 SimTime tcl::aux_convert_to(Tcl_Obj* obj, SimTime*)
00131 {
00132 return SimTime::NSECS(tcl::aux_convert_to(obj, (int64*)0));
00133 }
00134
00135 extern "C"
00136 int Frameseries_Init(Tcl_Interp* interp)
00137 {
00138 GVX_PKG_CREATE(pkg, interp, "FrameSeries", "4.$Revision: 1$");
00139 pkg->inherit_pkg("Modelcomponent");
00140 tcl::def_basic_type_cmds<ModelComponent>(pkg, SRC_POS);
00141
00142 GVX_PKG_RETURN(pkg);
00143 }
00144
00145 extern "C"
00146 int Inputframeseries_Init(Tcl_Interp* interp)
00147 {
00148 GVX_PKG_CREATE(pkg, interp, "InputFrameSeries", "4.$Revision: 1$");
00149 pkg->inherit_pkg("Frameseries");
00150 tcl::def_basic_type_cmds<InputFrameSeries>(pkg, SRC_POS);
00151
00152 registerComponentCreator<InputFrameSeries>();
00153
00154 pkg->def("update", "stime", &InputFrameSeries::update, SRC_POS);
00155 pkg->def("updateNext", "objref", &InputFrameSeries::updateNext, SRC_POS);
00156 pkg->def("shouldWait", "objref", &InputFrameSeries::shouldWait, SRC_POS);
00157
00158 pkg->def("dims", "objref", &ifsDims, SRC_POS);
00159 pkg->def("readRGB", "objref", &ifsReadRGB, SRC_POS);
00160 pkg->def("readGray", "objref", &ifsReadGray, SRC_POS);
00161
00162 GVX_PKG_RETURN(pkg);
00163 }
00164
00165 extern "C"
00166 int Outputframeseries_Init(Tcl_Interp* interp)
00167 {
00168 GVX_PKG_CREATE(pkg, interp, "OutputFrameSeries", "4.$Revision: 1$");
00169 pkg->inherit_pkg("Frameseries");
00170 tcl::def_basic_type_cmds<OutputFrameSeries>(pkg, SRC_POS);
00171
00172 registerComponentCreator<OutputFrameSeries>();
00173
00174 pkg->def("update", "stime new_event", &OutputFrameSeries::update, SRC_POS);
00175 pkg->def("updateNext", "objref", &OutputFrameSeries::updateNext, SRC_POS);
00176 pkg->def("shouldWait", "objref", &OutputFrameSeries::shouldWait, SRC_POS);
00177
00178 pkg->def("writeRGB", "ofs img stem", &ofsWriteRGB, SRC_POS);
00179 pkg->def("writeGray", "ofs img stem", &ofsWriteGray, SRC_POS);
00180 pkg->def("writeFloat", "ofs img stem", &ofsWriteFloat, SRC_POS);
00181
00182 GVX_PKG_RETURN(pkg);
00183 }
00184
00185 extern "C"
00186 int Siminputframeseries_Init(Tcl_Interp* interp)
00187 {
00188 GVX_PKG_CREATE(pkg, interp, "SimInputFrameSeries", "4.$Revision: 1$");
00189 pkg->inherit_pkg("Simmodule");
00190 tcl::def_basic_type_cmds<SimInputFrameSeries>(pkg, SRC_POS);
00191
00192 registerComponentCreator<SimInputFrameSeries>();
00193
00194 GVX_PKG_RETURN(pkg);
00195 }
00196
00197 extern "C"
00198 int Simoutputframeseries_Init(Tcl_Interp* interp)
00199 {
00200 GVX_PKG_CREATE(pkg, interp, "SimOutputFrameSeries", "4.$Revision: 1$");
00201 pkg->inherit_pkg("Simmodule");
00202 tcl::def_basic_type_cmds<SimOutputFrameSeries>(pkg, SRC_POS);
00203
00204 registerComponentCreator<SimOutputFrameSeries>();
00205
00206 GVX_PKG_RETURN(pkg);
00207 }
00208
00209
00210
00211
00212
00213
00214
00215 #endif // SCRIPT_MEDIASCRIPT_C_DEFINED