00001 /*!@file Transport/ColorbarsInput.C FrameIstream class that generates a static "colorbars" test pattern */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00005 // by the University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Transport/ColorbarsInput.C $ 00035 // $Id: ColorbarsInput.C 9547 2008-03-28 23:32:43Z rjpeters $ 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), // white 00078 PixRGB<byte>(255, 255, 0), // yellow 00079 PixRGB<byte>(0, 255, 255), // cyan 00080 PixRGB<byte>(0, 255, 0), // green 00081 PixRGB<byte>(255, 0, 255), // magenta 00082 PixRGB<byte>(255, 0, 0), // red 00083 PixRGB<byte>(0, 0, 255) // blue 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 // NOTE: if you modify any behavior here, then please update the 00125 // corresponding documentation for the global "--in" option inside 00126 // the OPT_InputFrameSource definition in Media/MediaOpts.C 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 /* So things look consistent in everyone's emacs... */ 00187 /* Local Variables: */ 00188 /* mode: c++ */ 00189 /* indent-tabs-mode: nil */ 00190 /* End: */ 00191 00192 #endif // TRANSPORT_COLORBARSINPUT_C_DEFINED