Exemplo n.º 1
0
void InfoResponder::replyXml(StreamExtension& se)
{
  time_t now = time(0);
  StatusMonitor* statm = StatusMonitor::get();


  se.writeXmlHeader();
  se.write("<info xmlns=\"http://www.domain.org/restfulapi/2011/info-xml\">\n");
  se.write(" <version>0.0.1</version>\n");
  se.write(cString::sprintf(" <time>%i</time>\n", (int)now)); 
  se.write(" <services>\n");
  
  vector< RestfulService* > restful_services = RestfulServices::get()->Services(true, true);
  for (size_t i = 0; i < restful_services.size(); i++) {
    se.write(cString::sprintf("  <service path=\"%s\"  version=\"%i\" internal=\"%s\" />\n", 
              restful_services[i]->Path().c_str(),
              restful_services[i]->Version(),
              restful_services[i]->Internal() ? "true" : "false"));
  }
  se.write(" </services>\n");

  
  if ( statm->getRecordingName().length() > 0 || statm->getRecordingFile().length() > 0 ) {
     se.write(cString::sprintf(" <video name=\"%s\">%s</video>\n", StringExtension::encodeToXml(statm->getRecordingName()).c_str(), StringExtension::encodeToXml(statm->getRecordingFile()).c_str()));
  } else {
     cChannel* channel = Channels.GetByNumber(statm->getChannel());
     string channelid = "";
     cEvent* event = NULL;
     if (channel != NULL) { 
        channelid = (const char*)channel->GetChannelID().ToString();
        event = VdrExtension::getCurrentEventOnChannel(channel);  
     }

     se.write(cString::sprintf(" <channel>%s</channel>\n", channelid.c_str()));
     if ( event != NULL) {
        string eventTitle = "";
        if ( event->Title() != NULL ) { eventTitle = event->Title(); }

	se.write(cString::sprintf(" <eventid>%i</eventid>\n", event->EventID()));
        se.write(cString::sprintf(" <start_time>%i</start_time>\n", (int)event->StartTime()));
	se.write(cString::sprintf(" <duration>%i</duration>\n", (int)event->Duration()));
	se.write(cString::sprintf(" <title>%s</title>\n", StringExtension::encodeToXml(eventTitle).c_str()));
     }
  }

  se.write(" <vdr>\n");
  se.write("  <plugins>\n");
 
  cPlugin* p = NULL; 
  int counter = 0;
  while ( (p = cPluginManager::GetPlugin(counter) ) != NULL ) {
     se.write(cString::sprintf("   <plugin name=\"%s\" version=\"%s\" />\n", p->Name(), p->Version()));
     counter++;
  }

  se.write("  </plugins>\n");
  se.write(" </vdr>\n");

  se.write("</info>");
}
Exemplo n.º 2
0
template <class P1, class P2> static
void ApplyFilter_2( GenericImage<P1>& image, const GenericImage<P2>& sharp,
                    float amount, float threshold, float deringing,
                    float rangeLow, float rangeHigh, pcl_bool disableExtension, int c, pcl_bool highPass )
{
   float rangeWidth = 1 + rangeHigh + rangeLow;
   bool isRange = rangeWidth + 1 != 1;

   StandardStatus callback;
   StatusMonitor monitor;
   monitor.SetCallback( &callback );
   monitor.Initialize( "<end><cbr>Larson-Sekanina filter", image.NumberOfPixels() );

   for ( int x = 0; x < image.Width(); ++x )
      for ( int y = 0; y < image.Height(); ++y, ++monitor )
      {
         double f1, f2;
         P1::FromSample( f1, image.Pixel( x, y, c ) );
         P2::FromSample( f2, sharp.Pixel( x, y ) );
         Apply_PixelValues( f1, f2, threshold, deringing, amount, highPass );

         if ( disableExtension )
            image.Pixel( x, y, c ) = P1::ToSample( f1 );
         else
         {
            if ( isRange )
               f1 = (f1 + rangeLow)/rangeWidth;
            image.Pixel( x, y, c ) = P1::ToSample( pcl::Range( f1, 0.0, 1.0 ) );
         }
      }

   if ( disableExtension )
      Console().WarningLn( "<end><cbr>*** Warning: Dynamic range extension has been disabled - check pixel values!" );
}
Exemplo n.º 3
0
void SpinStatus::InfoUpdated( const StatusMonitor& monitor ) const
{
   if ( m_thread != 0 )
   {
      m_console.WriteLn( "<end>*" );
      m_console.Write( "<end><cbr>" + monitor.Info() + ": " );
   }
   else
   {
      if ( !m_console.AbortRequested() )
         m_console.Write( "<end><bol><clreol>" + monitor.Info() + ": " + cspin[m_spinCount%4] );
   }
}
Exemplo n.º 4
0
   template <class P> static
   void Rotate90CW( GenericImage<P>& image )
   {
      image.SetUnique();

      int w = image.Width();
      int h = image.Height();
      int h1 = h - 1;
      int n = image.NumberOfChannels();
      size_type N = image.NumberOfPixels();
      typename GenericImage<P>::color_space cs0 = image.ColorSpace();
      StatusMonitor status = image.Status();

      typename P::sample** f0 = 0;

      try
      {
         if ( image.Status().IsInitializationEnabled() )
            status.Initialize( "Rotate 90 degrees, clockwise", n*N );

         f0 = image.ReleaseData();

         typename GenericImage<P>::sample_array tmp( N );

         for ( int c = 0; c < n; ++c, status += N )
         {
            typename P::sample* f = f0[c];
            typename P::sample* t = tmp.Begin();
            ::memcpy( t, f, N*P::BytesPerSample() );
            for ( int y = 0; y < h; ++y )
               for ( int x = 0, h1y = h1-y; x < w; ++x, ++t )
                  f[x*h + h1y] = *t;
         }

         image.ImportData( f0, h, w, n, cs0 ).Status() = status;
      }
      catch ( ... )
      {
         if ( f0 != 0 )
         {
            for ( int c = 0; c < n; ++c )
               if ( f0[c] != 0 )
                  image.Allocator().Deallocate( f0[c] );
            image.Allocator().Deallocate( f0 );
            image.FreeData();
         }
         throw;
      }
   }
Exemplo n.º 5
0
int SpinStatus::Initialized( const StatusMonitor& monitor ) const
{
   m_thread = (*API->Thread->GetCurrentThread)();
   if ( m_thread != 0 )
   {
      if ( ThreadAborted( m_thread ) )
         return 1;

      m_console.Write( "<end><cbr>" + monitor.Info() + ": " );
   }
   else
   {
      if ( m_console.AbortRequested() )
      {
         m_console.Abort();
         return 1;
      }

      m_console.Write( "<end><cbr>" + monitor.Info() + ": " + cspin[0] );
      m_spinCount = 0;
   }

   return 0;
}
Exemplo n.º 6
0
   template <class P> inline
   static void Apply( GenericImage<P>& image, const IntegerResample& Z )
   {
      int width = image.Width();
      int w0 = width;
      int height = image.Height();
      int h0 = height;

      Z.GetNewSizes( width, height );

      if ( width == w0 && height == h0 )
         return;

      if ( width == 0 || height == 0 )
      {
         image.FreeData();
         return;
      }

      image.EnsureUnique();

      typename P::sample* f = 0;
      typename P::sample** f0 = 0;

      int n = image.NumberOfChannels();
      size_type N = image.NumberOfPixels();
      typename GenericImage<P>::color_space cs0 = image.ColorSpace();

      StatusMonitor status = image.Status();

      int z = pcl::Abs( Z.ZoomFactor() );
      int z2 = z*z;
      int n2 = z2 >> 1;

      try
      {
         if ( status.IsInitializationEnabled() )
         {
            String info = (Z.ZoomFactor() > 0) ? "Upsampling" : "Downsampling";

            info.AppendFormat( " %d:%d, %dx%d",
               (Z.ZoomFactor() > 0) ? z : 1, (Z.ZoomFactor() > 0) ? 1 : z, width, height );

            if ( Z.ZoomFactor() < 0 )
            {
               info += ", ";
               switch ( Z.DownsampleMode() )
               {
               default:
               case IntegerDownsampleMode::Average: info += "average"; break;
               case IntegerDownsampleMode::Median:  info += "median"; break;
               case IntegerDownsampleMode::Maximum: info += "maximum"; break;
               case IntegerDownsampleMode::Minimum: info += "minimum"; break;
               }
            }

            status.Initialize( info, n*N );
         }

         GenericVector<typename P::sample> fm;
         if ( Z.ZoomFactor() < 0 && Z.DownsampleMode() == IntegerDownsampleMode::Median )
            fm = GenericVector<typename P::sample>( z2 );

         f0 = image.ReleaseData();

         for ( int c = 0; c < n; ++c, status += N )
         {
            f = image.Allocator().AllocatePixels( width, height );

            if ( Z.ZoomFactor() > 0 )
            {
               const typename P::sample* f0c = f0[c];

               for ( int y = 0; y < h0; ++y )
               {
                  int yz = y*z;

                  for ( int x = 0; x < w0; ++x )
                  {
                     int xz = x*z;
                     typename P::sample v = *f0c++;

                     for ( int i = 0; i < z; ++i )
                     {
                        typename P::sample* fi = f + (size_type( yz + i )*width + xz);

                        for ( int j = 0; j < z; ++j )
                           *fi++ = v;
                     }
                  }
               }
            }
            else
            {
               typename P::sample* fz = f;

               for ( int y = 0; y < height; ++y )
               {
                  const typename P::sample* fy = f0[c] + size_type( y )*z*w0;

                  for ( int x = 0; x < width; ++x )
                  {
                     const typename P::sample* fyx = fy + x*z;

                     switch ( Z.DownsampleMode() )
                     {
                     default:
                     case IntegerDownsampleMode::Average:
                        {
                           double s = 0;
                           for ( int i = 0; i < z; ++i, fyx += w0 )
                              for ( int j = 0; j < z; ++j )
                                 s += fyx[j];
                           *fz++ = typename P::sample( P::IsFloatSample() ? s/z2 : Round( s/z2 ) );
                        }
                        break;

                     case IntegerDownsampleMode::Median:
                        {
                           typename P::sample* fmi = *fm;
                           for ( int i = 0; i < z; ++i, fyx += w0 )
                              for ( int j = 0; j < z; ++j )
                                 *fmi++ = fyx[j];

                           *fz++ = (z & 1) ?
                                 *Select( *fm, fm.At( z2 ), n2 ) :
                                 P::FloatToSample( 0.5*(double( *Select( *fm, fm.At( z2 ), n2   ) ) +
                                                        double( *Select( *fm, fm.At( z2 ), n2-1 ) )) );
                        }
                        break;

                     case IntegerDownsampleMode::Maximum:
                        {
                           *fz = P::MinSampleValue();
                           for ( int i = 0; i < z; ++i, fyx += w0 )
                              for ( int j = 0; j < z; ++j )
                                 if ( fyx[j] > *fz )
                                    *fz = fyx[j];
                           ++fz;
                        }
                        break;

                     case IntegerDownsampleMode::Minimum:
                        {
                           *fz = P::MaxSampleValue();
                           for ( int i = 0; i < z; ++i, fyx += w0 )
                              for ( int j = 0; j < z; ++j )
                                 if ( fyx[j] < *fz )
                                    *fz = fyx[j];
                           ++fz;
                        }
                        break;
                     }
                  }
               }
            }

            image.Allocator().Deallocate( f0[c] );
            f0[c] = f;
            f = 0;
         }

         image.ImportData( f0, width, height, n, cs0 ).Status() = status;
      }
      catch ( ... )
      {
         if ( f != 0 )
            image.Allocator().Deallocate( f );
         if ( f0 != 0 )
         {
            for ( int c = 0; c < n; ++c )
               if ( f0[c] != 0 )
                  image.Allocator().Deallocate( f0[c] );
            image.Allocator().Deallocate( f0 );
         }
         image.FreeData();
         throw;
      }
   }
Exemplo n.º 7
0
void InfoResponder::replyJson(StreamExtension& se)
{
  time_t now = time(0);
  StatusMonitor* statm = StatusMonitor::get();

  cxxtools::JsonSerializer serializer(*se.getBasicStream());
  serializer.serialize("0.0.1", "version");
  serializer.serialize((int)now, "time");
  
  vector< struct SerService > services;
  vector< RestfulService* > restful_services = RestfulServices::get()->Services(true, true);
  struct SerService s;
  for (size_t i = 0; i < restful_services.size(); i++) {
     s.Path = StringExtension::UTF8Decode(restful_services[i]->Path());
     s.Version = restful_services[i]->Version();
     s.Internal = restful_services[i]->Internal();
     services.push_back(s);
  }

  struct SerPluginList pl;

  cPlugin* p = NULL;
  int counter = 0;
  while ( (p = cPluginManager::GetPlugin(counter)) != NULL ) {
     struct SerPlugin sp;
     sp.Name = StringExtension::UTF8Decode(p->Name());
     sp.Version = StringExtension::UTF8Decode(p->Version());
     pl.plugins.push_back(sp);
     counter++;
  }

  serializer.serialize(services, "services");

  if ( statm->getRecordingName().length() > 0 || statm->getRecordingFile().length() > 0 ) {
     SerPlayerInfo pi;
     pi.Name = StringExtension::UTF8Decode(statm->getRecordingName());
     pi.FileName = StringExtension::UTF8Decode(statm->getRecordingFile());
     serializer.serialize(pi, "video");
  } else {
     string channelid = "";
     cChannel* channel = Channels.GetByNumber(statm->getChannel());
     if (channel != NULL) { 
        channelid = (const char*)channel->GetChannelID().ToString();
        serializer.serialize(channelid, "channel");
        cEvent* event = VdrExtension::getCurrentEventOnChannel(channel);
                
        string eventTitle = "";
        int start_time = -1;
	int duration = -1;
        int eventId = -1;

        if ( event != NULL) {
           eventTitle = event->Title();
	   start_time = event->StartTime();
           duration = event->Duration(),
           eventId = (int)event->EventID();	   
        }

        serializer.serialize(eventId, "eventid");
        serializer.serialize(start_time, "start_time");
	serializer.serialize(duration, "duration");
        serializer.serialize(StringExtension::UTF8Decode(eventTitle), "title");
     }
  }

  serializer.serialize(pl, "vdr");
  serializer.finish();  
}
Exemplo n.º 8
0
   template <class P> static
   void Apply( GenericImage<P>& image, const Translation& translation )
   {
      if ( translation.Delta() == 0.0 )
         return;

      int width = image.Width();
      int height = image.Height();
      if ( width == 0 || height == 0 )
         return;

      image.EnsureUnique();

      typename P::sample* f = nullptr;
      typename P::sample** f0 = nullptr;

      int n = image.NumberOfChannels();
      typename GenericImage<P>::color_space cs0 = image.ColorSpace();

      StatusMonitor status = image.Status();

      int numberOfThreads = translation.IsParallelProcessingEnabled() ?
               Min( translation.MaxProcessors(), pcl::Thread::NumberOfThreads( height, 1 ) ) : 1;
      int rowsPerThread = height/numberOfThreads;

      try
      {
         size_type N = size_type( width )*size_type( height );
         if ( status.IsInitializationEnabled() )
            status.Initialize( String().Format( "Translate dx=%.3lf, dy=%.3lf, ",
                        translation.Delta().x, translation.Delta().y ) + translation.Interpolation().Description(),
                        size_type( n )*N );

         f0 = image.ReleaseData();

         for ( int c = 0; c < n; ++c )
         {
            ThreadData<P> data( translation.Delta(), width, height, status, N );

            data.f = f = image.Allocator().AllocatePixels( size_type( width )*size_type( height ) );
            data.fillValue = (c < translation.FillValues().Length()) ? P::ToSample( translation.FillValues()[c] ) : P::MinSampleValue();

            ReferenceArray<Thread<P> > threads;
            for ( int i = 0, j = 1; i < numberOfThreads; ++i, ++j )
               threads.Add( new Thread<P>( data,
                                           translation.Interpolation().NewInterpolator<P>( f0[c], width, height ),
                                           i*rowsPerThread,
                                           (j < numberOfThreads) ? j*rowsPerThread : height ) );

            AbstractImage::RunThreads( threads, data );

            threads.Destroy();

            image.Allocator().Deallocate( f0[c] );
            f0[c] = f;
            f = nullptr;

            status = data.status;
         }

         image.ImportData( f0, width, height, n, cs0 ).Status() = status;
      }
      catch ( ... )
      {
         if ( f != nullptr )
            image.Allocator().Deallocate( f );
         if ( f0 != nullptr )
         {
            for ( int c = 0; c < n; ++c )
               if ( f0[c] != nullptr )
                  image.Allocator().Deallocate( f0[c] );
            image.Allocator().Deallocate( f0 );
         }
         image.FreeData();
         throw;
      }
   }
Exemplo n.º 9
0
template <class P1, class P2> static
void Convolve_2( const GenericImage<P1>& image, GenericImage<P2>& sharp,
                 pcl_enum interpolation, float dR, float angleD, DPoint center, int c )
{
   PixelInterpolation* P = 0;
   PixelInterpolation::Interpolator<P1>* interpolator = 0;

   try
   {
      switch ( interpolation )
      {
      case LSInterpolation::Bilinear:
         P = new BilinearPixelInterpolation();
         break;
      default:
      case LSInterpolation::Bicubic:
         P = new BicubicPixelInterpolation();
         break;
      case LSInterpolation::BicubicSpline:
         P = new BicubicSplinePixelInterpolation();
         break;
      case LSInterpolation::BicubicBSpline:
         P = new BicubicBSplinePixelInterpolation();
         break;
      }

      interpolator = P->NewInterpolator<P1>( image[c], image.Width(), image.Height() );

      int w = image.Width() - 1;
      int h = image.Height() - 1;

      double fimg, fsharp;
      StatusMonitor monitor;
      monitor.Initialize( "<end><cbr>High-pass Larson-Sekanina filter", image.NumberOfPixels() );

      sharp.Zero();

      float dAlpha = Rad( angleD );
      for ( int x = 0; x < image.Width(); ++x )
         for ( int y = 0; y < image.Height(); ++y, ++monitor )
         {
            // Get the central value
            P1::FromSample( fimg, image.Pixel( x, y, c ) );
            fsharp = fimg+fimg;

            double r, theta;
            ToPolar( x, y, center, r, theta);

            DPoint delta;

            // Positive differential
            ToCartesian( r-dR, theta+dAlpha, center, delta );
            if ( delta.x < 0 )
               delta.x = Abs( delta.x );
            else if ( delta.x > w )
               delta.x = 2*w - delta.x;
            if ( delta.y < 0 )
               delta.y = Abs( delta.y );
            else if ( delta.y > h )
               delta.y = 2*h - delta.y;
            P1::FromSample( fimg, (*interpolator)( delta ) );
            fsharp -= fimg;

            //Negative differential
            ToCartesian( r-dR, theta-dAlpha, center, delta );
            if ( delta.x < 0 )
               delta.x = Abs( delta.x );
            else if ( delta.x > w )
               delta.x = 2*w - delta.x;
            if ( delta.y < 0 )
               delta.y = Abs( delta.y );
            else if ( delta.y > h )
               delta.y = 2*h - delta.y;
            P1::FromSample( fimg, (*interpolator)( delta ) );
            fsharp -= fimg;

            sharp.Pixel( x, y ) = P2::ToSample( fsharp );
         }

      delete interpolator;
      delete P;
   }

   catch ( ... )
   {
      if ( interpolator != 0 )
         delete interpolator;
      if ( P != 0 )
         delete P;
      throw;
   }
}
Exemplo n.º 10
0
   template <class P> static
   void Apply( GenericImage<P>& image, const Resample& resample )
   {
      int width = image.Width();
      int w0 = width;
      int height = image.Height();
      int h0 = height;

      resample.GetNewSizes( width, height );

      if ( width == w0 && height == h0 )
         return;

      if ( width <= 0 || height <= 0 )
      {
         image.FreeData();
         return;
      }

      image.EnsureUnique();

      typename P::sample* f = nullptr;
      typename P::sample** f0 = nullptr;

      int n = image.NumberOfChannels();
      typename GenericImage<P>::color_space cs0 = image.ColorSpace();

      double rx = double( w0 )/width;
      double ry = double( h0 )/height;

      StatusMonitor status = image.Status();

      int numberOfThreads = resample.IsParallelProcessingEnabled() ?
               Min( resample.MaxProcessors(), pcl::Thread::NumberOfThreads( height, 1 ) ) : 1;
      int rowsPerThread = height/numberOfThreads;

      try
      {
         size_type N = size_type( width )*size_type( height );
         if ( status.IsInitializationEnabled() )
            status.Initialize( String().Format( "Resampling to %dx%d px, ", width, height )
                                                + resample.Interpolation().Description(), size_type( n )*N );
         f0 = image.ReleaseData();

         for ( int c = 0; c < n; ++c )
         {
            ThreadData<P> data( rx, ry, width, status, N );
            data.f = f = image.Allocator().AllocatePixels( width, height );

            ReferenceArray<Thread<P> > threads;
            for ( int i = 0, j = 1; i < numberOfThreads; ++i, ++j )
               threads.Add( new Thread<P>( data, resample.Interpolation().NewInterpolator<P>( f0[c], w0, h0 ),
                                           i*rowsPerThread,
                                           (j < numberOfThreads) ? j*rowsPerThread : height ) );

            AbstractImage::RunThreads( threads, data );

            threads.Destroy();

            image.Allocator().Deallocate( f0[c] );
            f0[c] = f;
            f = nullptr;

            status = data.status;
         }

         image.ImportData( f0, width, height, n, cs0 ).Status() = status;
      }
      catch ( ... )
      {
         if ( f != nullptr )
            image.Allocator().Deallocate( f );
         if ( f0 != nullptr )
         {
            for ( int c = 0; c < n; ++c )
               if ( f0[c] != nullptr )
                  image.Allocator().Deallocate( f0[c] );
            image.Allocator().Deallocate( f0 );
         }
         image.FreeData();
         throw;
      }
   }