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 TRANSPORT_COLORBARSINPUT_C_DEFINED
00039 #define TRANSPORT_COLORBARSINPUT_C_DEFINED
00040
00041 #include "Transport/ColorbarsInput.H"
00042
00043 #include "Image/DrawOps.H"
00044 #include "Raster/GenericFrame.H"
00045 #include "Util/sformat.H"
00046 #include "rutz/fstring.h"
00047 #include "rutz/time.h"
00048 #include "rutz/timeformat.h"
00049
00050 namespace
00051 {
00052 void fillRegion(Image<PixRGB<byte> >& img, PixRGB<byte> col,
00053 const int x0, const int x1,
00054 const int y0, const int y1)
00055 {
00056 for (int x = x0; x < x1; ++x)
00057 for (int y = y0; y < y1; ++y)
00058 img.setVal(x, y, col);
00059 }
00060 }
00061
00062
00063 ColorbarsInput::ColorbarsInput(OptionManager& mgr)
00064 :
00065 FrameIstream(mgr, "Colorbars Input", "ColorbarsInput"),
00066 itsImage(),
00067 itsFramePeriod(SimTime::ZERO()),
00068 itsFrameNumber(0)
00069 {
00070 const int w = 320;
00071 const int h = 240;
00072
00073 itsImage = Image<PixRGB<byte> >(w, h, ZEROS);
00074
00075 const PixRGB<byte> cols[] =
00076 {
00077 PixRGB<byte>(255, 255, 255),
00078 PixRGB<byte>(255, 255, 0),
00079 PixRGB<byte>(0, 255, 255),
00080 PixRGB<byte>(0, 255, 0),
00081 PixRGB<byte>(255, 0, 255),
00082 PixRGB<byte>(255, 0, 0),
00083 PixRGB<byte>(0, 0, 255)
00084 };
00085
00086 int x1 = 0;
00087 for (int i = 0; i < 7; ++i)
00088 {
00089 const int x0 = x1+1;
00090 x1 = int(double(w)*(i+1)/7.0 + 0.5);
00091 fillRegion(itsImage, cols[i],
00092 x0, x1,
00093 0, int(h*2.0/3.0));
00094 }
00095
00096 x1 = 0;
00097 for (int i = 0; i < 16; ++i)
00098 {
00099 const int x0 = x1;
00100 x1 = int(double(w)*(i+1)/16.0 + 0.5);
00101 const int gray = int(255.0*i/15.0 + 0.5);
00102 fillRegion(itsImage, PixRGB<byte>(gray, gray, gray),
00103 x0, x1,
00104 int(h*2.0/3.0)+1, int(h*5.0/6.0));
00105 }
00106
00107 fillRegion(itsImage, PixRGB<byte>(255, 0, 0),
00108 0, w,
00109 int(h*5.0/6.0)+1, h);
00110
00111 writeText(itsImage, Point2D<int>(1, int(h*5.0/6.0)+2),
00112 "iLab Neuromorphic Vision",
00113 PixRGB<byte>(0, 0, 0), PixRGB<byte>(255, 0, 0),
00114 SimpleFont::FIXED(10));
00115 }
00116
00117
00118 ColorbarsInput::~ColorbarsInput()
00119 {}
00120
00121
00122 void ColorbarsInput::setConfigInfo(const std::string& frametime)
00123 {
00124
00125
00126
00127
00128 if (frametime.size() == 0)
00129 itsFramePeriod = SimTime::ZERO();
00130 else
00131 itsFramePeriod = SimTime::fromString(frametime);
00132 }
00133
00134
00135 bool ColorbarsInput::setFrameNumber(int n)
00136 {
00137 itsFrameNumber = n;
00138
00139 return true;
00140 }
00141
00142
00143 GenericFrameSpec ColorbarsInput::peekFrameSpec()
00144 {
00145 GenericFrameSpec result;
00146
00147 result.nativeType = GenericFrame::RGB_U8;
00148 result.videoFormat = VIDFMT_AUTO;
00149 result.videoByteSwap = false;
00150 result.dims = itsImage.getDims();
00151 result.floatFlags = 0;
00152
00153 return result;
00154 }
00155
00156
00157 GenericFrame ColorbarsInput::readFrame()
00158 {
00159 if (itsStartTime.sec() == 0.0)
00160 itsStartTime = rutz::time::wall_clock_now();
00161
00162 const rutz::time nexttime(itsStartTime.sec()
00163 + itsFrameNumber * itsFramePeriod.secs());
00164
00165 while (rutz::time::wall_clock_now() < nexttime)
00166 { usleep(1000); }
00167
00168 Image<PixRGB<byte> > result = itsImage;
00169 std::string fnum = sformat("%06d", itsFrameNumber);
00170 writeText(result, Point2D<int>(1, 1),
00171 fnum.c_str(),
00172 PixRGB<byte>(0, 0, 0), PixRGB<byte>(255, 255, 255),
00173 SimpleFont::FIXED(10));
00174
00175 rutz::time t = rutz::time::wall_clock_now();
00176
00177 writeText(result, Point2D<int>(1, result.getHeight() - 14),
00178 rutz::format_time(t).c_str(),
00179 PixRGB<byte>(32, 32, 32), PixRGB<byte>(255, 0, 0),
00180 SimpleFont::FIXED(6));
00181
00182 return GenericFrame(result);
00183 }
00184
00185
00186
00187
00188
00189
00190
00191
00192 #endif // TRANSPORT_COLORBARSINPUT_C_DEFINED