TigsInputFrame.C
Go to the documentation of this file.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 TIGS_TIGSINPUTFRAME_C_DEFINED
00039 #define TIGS_TIGSINPUTFRAME_C_DEFINED
00040
00041 #include "TIGS/TigsInputFrame.H"
00042
00043 #include "Image/ColorOps.H"
00044 #include "Util/StringConversions.H"
00045 #include "rutz/trace.h"
00046
00047 #include <sstream>
00048
00049
00050
00051
00052
00053
00054
00055
00056 Image<PixRGB<float> > rescaleAndPromote(const Image<PixRGB<byte> >& src,
00057 const int new_w, const int new_h)
00058 {
00059 GVX_TRACE(__PRETTY_FUNCTION__);
00060
00061 ASSERT(src.initialized()); ASSERT(new_w > 0 && new_h > 0);
00062
00063 const int orig_w = src.getWidth();
00064 const int orig_h = src.getHeight();
00065
00066
00067 if (new_w == orig_w && new_h == orig_h) return src;
00068
00069 const float sw = float(orig_w) / float(new_w);
00070 const float sh = float(orig_h) / float(new_h);
00071
00072 Image<PixRGB<float> > result(new_w, new_h, NO_INIT);
00073 Image<PixRGB<float> >::iterator dptr = result.beginw();
00074 Image<PixRGB<byte> >::const_iterator const sptr = src.begin();
00075
00076 for (int j = 0; j < new_h; ++j)
00077 {
00078 const float y = std::max(0.0f, (j+0.5f) * sh - 0.5f);
00079
00080 const int y0 = int(y);
00081 const int y1 = std::min(y0 + 1, orig_h - 1);
00082
00083 const float fy = y - float(y0);
00084
00085 const int wy0 = orig_w * y0;
00086 const int wy1 = orig_w * y1;
00087
00088 for (int i = 0; i < new_w; ++i)
00089 {
00090 const float x = std::max(0.0f, (i+0.5f) * sw - 0.5f);
00091
00092 const int x0 = int(x);
00093 const int x1 = std::min(x0 + 1, orig_w - 1);
00094
00095 const float fx = x - float(x0);
00096
00097 #define RGB_BILINEAR_INTERP(EL) \
00098 do { \
00099 const float \
00100 d00( sptr[x0 + wy0].p[EL] ), d10( sptr[x1 + wy0].p[EL] ), \
00101 d01( sptr[x0 + wy1].p[EL] ), d11( sptr[x1 + wy1].p[EL] ); \
00102 \
00103 const float \
00104 dx0( d00 + (d10 - d00) * fx ), \
00105 dx1( d01 + (d11 - d01) * fx ); \
00106 \
00107 dptr->p[EL] = float( int( dx0 + (dx1 - dx0) * fy ) ); \
00108 } while(0)
00109
00110
00111
00112
00113
00114
00115 RGB_BILINEAR_INTERP(0);
00116 RGB_BILINEAR_INTERP(1);
00117 RGB_BILINEAR_INTERP(2);
00118
00119 #undef RGB_BILINEAR_INTERP
00120
00121 ++dptr;
00122 }
00123 }
00124 return result;
00125 }
00126
00127 rutz::shared_ptr<TigsInputFrame>
00128 TigsInputFrame::fromGhostString(const std::string& s)
00129 {
00130 std::istringstream iss(s);
00131 int64 nanosecs;
00132 std::string dimsstr;
00133 std::string hashstr;
00134 iss >> nanosecs >> dimsstr >> hashstr;
00135
00136 const Dims dims = fromStr<Dims>(dimsstr);
00137 const Digest<16> hash = Digest<16>::fromString(hashstr);
00138
00139 return rutz::shared_ptr<TigsInputFrame>
00140 (new TigsInputFrame(SimTime::NSECS(nanosecs), dims, hash));
00141 }
00142
00143 std::string TigsInputFrame::toGhostString() const
00144 {
00145 std::ostringstream oss;
00146 oss << itsTime.nsecs()
00147 << ' ' << convertToString(itsOrigbounds.dims())
00148 << ' ' << this->getHash().asString();
00149 return oss.str();
00150 }
00151
00152 void TigsInputFrame::initialize() const
00153 {
00154 if (itsLum.initialized()
00155 && itsRG.initialized()
00156 && itsBY.initialized()
00157 && itsRGB.initialized())
00158 return;
00159
00160 GVX_TRACE(__PRETTY_FUNCTION__);
00161
00162 const Image<PixRGB<float> > fframe =
00163 rescaleAndPromote(itsOrigframe, 512, 512);
00164
00165 itsRGB = Image<PixRGB<byte> >(fframe);
00166
00167 itsLum = luminance(fframe);
00168
00169 getRGBYsimple(fframe, itsRG, itsBY, float(5.0f));
00170
00171 {GVX_TRACE("re-range");
00172 itsRG += 1.0f;
00173 itsBY += 1.0f;
00174 itsRG *= 127.5f;
00175 itsBY *= 127.5f;
00176 }
00177 }
00178
00179
00180
00181
00182
00183
00184
00185
00186 #endif // TIGS_TIGSINPUTFRAME_C_DEFINED