Exemple #1
0
int handle_changed_size(UNDO_DEF *undo, MFDB *current_img)
{
  int err = 0 ;

  if ( size_has_changed( undo, current_img ) )
  {
    /* Essaie de r‚allouer la taille d'origine */
    long taille ;
    void *pt ;

    taille = img_size( undo->w, undo->h, nb_plane ) ;
    pt = malloc( taille ) ;
    if ( pt == NULL ) err = 1 ;
    else
    {
      free( current_img->fd_addr ) ;
      current_img->fd_addr = pt ;
      current_img->fd_w = undo->w ;
      current_img->fd_wdwidth = current_img->fd_w/16 ;
      if ( current_img->fd_w % 16 ) current_img->fd_wdwidth++ ;
      current_img->fd_h = undo->h ;
    }
  }

  return( err ) ;
}
Exemple #2
0
ImageRGB FrameCapturer::getFrame(){
    LOG(INFO) << __PRETTY_FUNCTION__;
    //TODO
    //int width, height, depth;
    //unsigned char *imgBytes = axis.getImageBytes(width, height, depth);
    //mirage::img::Coordinate img_size(width, height);

    axis.getDefaultBMPImage();
    int dummy;
    mirage::img::Coordinate img_size(axis.getWidth(), axis.getHeight());
    frame.resize(img_size,
            (ImageRGB::value_type*)axis.getImageBytes(dummy, dummy, dummy));
    rgb2bgr(frame);
    return frame;
}
Exemple #3
0
ControlBar::ControlBar(wxWindow* win, wxWindowID id, wxPoint pt, wxSize size)
    : wxPanel(win, id, pt, size)
{
    // Heavy lifting
    this->SetBackgroundStyle(wxBG_STYLE_CUSTOM); // Tell some platforms not to use default background.
    //wxImage::AddHandler(new wxPNGHandler); // Format of images to use (usually only one).
    this->SetBackgroundColour(wxColour(50, 50, 50));


    // Initialize buttons
    int x = BTN_OFFSET.x, deltaX = BTN_DELTAX, y = BTN_OFFSET.y; // Offset pour controls
    wxSize img_size(25, 25); // Size of button images
    
    axMultipleBitmap backwardIm(wxString("resources/ControlBar/backwardBtn.png"), 3, img_size);
    backwardBtn = new axButton(this, BACK_BTN, wxPoint(x, y), backwardIm);

    axMultipleBitmap stopIm(wxString("resources/ControlBar/stopBtn.png"), 3, img_size);
    stopBtn = new axButton(this, STOP_BTN, wxPoint(x += deltaX, y), stopIm);

    axMultipleBitmap playPauseIm(wxString("resources/ControlBar/playPauseBtn.png"), 6, img_size);
    playPauseBtn = new axToggle(this, PLAY_PAUSE_BTN, wxPoint(x += deltaX, y), playPauseIm, false);
	
    axMultipleBitmap forwardIm(wxString("resources/ControlBar/forwardBtn.png"), 3, img_size);
    forwardBtn = new axButton(this, FWRD_BTN, wxPoint(x += deltaX, y), forwardIm);

    // Slider
	axSliderID sliderID;
	sliderID.leftDownID = SLIDER_LEFT_DOWN; 
	sliderID.leftUpID = SLIDER_LEFT_UP;
	sliderID.motionID = SLIDER_MOTION;

	axSliderData sliderData;
	sliderData.imgs = axMultipleBitmap(wxT("resources/ControlBar/sliderCtrl.png"), 3, wxSize(12, 12), UP_TO_DOWN);
	sliderData.bgColorNormal		= wxColor(50, 50, 50); 
	sliderData.bgColorHover			= wxColor(70, 70, 70); 
	sliderData.bgColorClicked		= wxColor(100, 100, 100);
	sliderData.sliderColorNormal	= wxColor(200, 0, 0); 
	sliderData.sliderColorHover		= wxColor(240, 0, 0);
	sliderData.sliderColorClicked	= wxColor(230, 0, 0);
	sliderData.sliderContourColor	= wxColor(0, 0, 0);
	sliderData.contourColor			= wxColor(50, 50, 50);
	sliderData.sliderHeight			= 8;

	slider = new axSlider(this, sliderID, sliderData, SLIDER_OFFSET, wxSize(300, 16), 0.0, 0.0, 1.0);


	timeCtrl = new axTimeCtrl(this, wxID_ANY, wxPoint(GetSize().x - 70, BTN_OFFSET.y + 8));
}
Exemple #4
0
void SubtitleScreen::DisplayAVSubtitles(void)
{
    if (!m_player || !m_subreader)
        return;

    AVSubtitles* subs = m_subreader->GetAVSubtitles();
    QMutexLocker lock(&(subs->lock));
    if (subs->buffers.empty() && (kDisplayAVSubtitle != m_subtitleType))
        return;

    VideoOutput    *videoOut = m_player->GetVideoOutput();
    VideoFrame *currentFrame = videoOut ? videoOut->GetLastShownFrame() : NULL;

    if (!currentFrame || !videoOut)
        return;

    float tmp = 0.0;
    QRect dummy;
    videoOut->GetOSDBounds(dummy, m_safeArea, tmp, tmp, tmp);

    while (!subs->buffers.empty())
    {
        const AVSubtitle subtitle = subs->buffers.front();
        if (subtitle.start_display_time > currentFrame->timecode)
            break;

        ClearDisplayedSubtitles();
        subs->buffers.pop_front();
        for (std::size_t i = 0; i < subtitle.num_rects; ++i)
        {
            AVSubtitleRect* rect = subtitle.rects[i];

            bool displaysub = true;
            if (subs->buffers.size() > 0 &&
                subs->buffers.front().end_display_time <
                currentFrame->timecode)
            {
                displaysub = false;
            }

            if (displaysub && rect->type == SUBTITLE_BITMAP)
            {
                // AVSubtitleRect's image data's not guaranteed to be 4 byte
                // aligned.

                QSize img_size(rect->w, rect->h);
                QRect img_rect(rect->x, rect->y, rect->w, rect->h);
                QRect display(rect->display_x, rect->display_y,
                              rect->display_w, rect->display_h);

                // XSUB and some DVD/DVB subs are based on the original video
                // size before the video was converted. We need to guess the
                // original size and allow for the difference

                int right  = rect->x + rect->w;
                int bottom = rect->y + rect->h;
                if (subs->fixPosition || (currentFrame->height < bottom) ||
                   (currentFrame->width  < right))
                {
                    int sd_height = 576;
                    if ((m_player->GetFrameRate() > 26.0f) && bottom <= 480)
                        sd_height = 480;
                    int height = ((currentFrame->height <= sd_height) &&
                                  (bottom <= sd_height)) ? sd_height :
                                 ((currentFrame->height <= 720) && bottom <= 720)
                                   ? 720 : 1080;
                    int width  = ((currentFrame->width  <= 720) &&
                                  (right <= 720)) ? 720 :
                                 ((currentFrame->width  <= 1280) &&
                                  (right <= 1280)) ? 1280 : 1920;
                    display = QRect(0, 0, width, height);
                }

                QRect scaled = videoOut->GetImageRect(img_rect, &display);
                QImage qImage(img_size, QImage::Format_ARGB32);
                for (int y = 0; y < rect->h; ++y)
                {
                    for (int x = 0; x < rect->w; ++x)
                    {
                        const uint8_t color = rect->pict.data[0][y*rect->pict.linesize[0] + x];
                        const uint32_t pixel = *((uint32_t*)rect->pict.data[1]+color);
                        qImage.setPixel(x, y, pixel);
                    }
                }

                if (scaled.size() != img_size)
                {
                    qImage = qImage.scaled(scaled.width(), scaled.height(),
                             Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
                }

                MythPainter *osd_painter = videoOut->GetOSDPainter();
                MythImage* image = NULL;
                if (osd_painter)
                   image = osd_painter->GetFormatImage();

                long long displayfor = subtitle.end_display_time -
                                       subtitle.start_display_time;
                if (displayfor == 0)
                    displayfor = 60000;
                displayfor = (displayfor < 50) ? 50 : displayfor;
                long long late = currentFrame->timecode -
                                 subtitle.start_display_time;
                MythUIImage *uiimage = NULL;
                if (image)
                {
                    image->Assign(qImage);
                    QString name = QString("avsub%1").arg(i);
                    uiimage = new MythUIImage(this, name);
                    if (uiimage)
                    {
                        m_refreshArea = true;
                        uiimage->SetImage(image);
                        uiimage->SetArea(MythRect(scaled));
                        m_expireTimes.insert(uiimage,
                                     currentFrame->timecode + displayfor);
                    }
                }
                if (uiimage)
                {
                    LOG(VB_PLAYBACK, LOG_INFO, LOC +
                        QString("Display %1AV subtitle for %2ms")
                        .arg(subtitle.forced ? "FORCED " : "")
                        .arg(displayfor));
                    if (late > 50)
                        LOG(VB_PLAYBACK, LOG_INFO, LOC +
                            QString("AV Sub was %1ms late").arg(late));
                }
            }
#ifdef USING_LIBASS
            else if (displaysub && rect->type == SUBTITLE_ASS)
            {
                InitialiseAssTrack(m_player->GetDecoder()->GetTrack(kTrackTypeSubtitle));
                AddAssEvent(rect->ass);
            }
#endif
        }
        m_subreader->FreeAVSubtitle(subtitle);
    }
#ifdef USING_LIBASS
    RenderAssTrack(currentFrame->timecode);
#endif
}
Exemple #5
0
int uundo_put(GEM_WINDOW *gwnd)
{
  VXIMAGE *vimage ;
  long    taille ;
  int     xy[8] ;
  int     type_alloc ;

  if ( gwnd == NULL) return( -1 ) ;
  if ( config.use_redo == 0 ) return( 0 ) ;
  vimage = (VXIMAGE *) gwnd->Extension ;

  FreeUUndoBuffer( gwnd ) ;
  vimage->Redo = AllocateUUndoBuffer( gwnd ) ;
  if ( vimage->Redo == NULL ) return( -3 ) ;

  vimage->Redo->w     = vimage->raster.fd_w ;
  vimage->Redo->h     = vimage->raster.fd_h ;
  vimage->Redo->mitem = REDO ;

  if ( !Truecolor && vimage->inf_img.nb_cpal && vimage->inf_img.palette )
  {
    size_t size ;

    vimage->Redo->nb_cpal = (int) vimage->inf_img.nb_cpal ;
    size                  = vimage->Redo->nb_cpal * 3 * sizeof(int) ;
    vimage->Redo->palette = (int *) malloc( size ) ;
    if ( vimage->Redo->palette == NULL )
    {
      FreeUndoBuffer( vimage->Redo ) ;
      vimage->Redo = NULL ;
      return( -1 ) ;
    }
    memcpy( vimage->Redo->palette, vimage->inf_img.palette, size ) ;
  }
  taille = img_size( vimage->Redo->w, vimage->Redo->h, nb_plane ) ;

  vimage->Redo->original_width  = vimage->raster.fd_w ;
  vimage->Redo->original_height = vimage->raster.fd_h ;

  type_alloc = must_alloc( vimage->Redo->mitem, taille, vimage->Redo->spec ) ;
  if ( type_alloc )
  {
    xy[0] = vimage->Redo->x ; xy[1] = vimage->Redo->y ;
    xy[2] = vimage->Redo->x + vimage->Redo->w-1 ;
    xy[3] = vimage->Redo->y + vimage->Redo->h-1 ;
    xy[4] = 0 ;         xy[5] = 0 ;
    xy[6] = vimage->Redo->w-1 ; xy[7] = vimage->Redo->h-1 ;
    if ( type_alloc == 1 )
    {
      vimage->Redo->img.fd_w       = vimage->Redo->w ;
      vimage->Redo->img.fd_w       = vimage->Redo->h ;
      vimage->Redo->img.fd_wdwidth = vimage->Redo->w / 16 ;
      if ( vimage->Redo->w % 16 ) vimage->Redo->img.fd_wdwidth++ ;
      vimage->Redo->img.fd_nplanes = nb_plane ;

      vimage->Redo->img.fd_addr = malloc( taille ) ;
      if ( vimage->Redo->img.fd_addr == NULL ) return( -1 ) ;
      vro_cpyfm( handle, S_ONLY, xy, &vimage->raster, &vimage->Redo->img ) ;
    }
    else undo_disk( gwnd, vimage->Redo, xy, &vimage->raster ) ;
  }

  return( 0 ) ;
}
Exemple #6
0
int undo_put(GEM_WINDOW *gwnd, int x1, int y1, int x2, int y2, int type_modif, XUNDO *xundo)
{
  VXIMAGE  *vimage ;
  UNDO_DEF *undo_buf ;
  void     *spec = NULL ;
  long     taille = 0 ;
  int      xy[8] ;
  int      wx, wy ;
  int      larg, temp ;
  int      type_alloc ;
/*  int      redo = 0 ;*/
  int      err = 0 ;

  if ( config.nb_undo == 0 ) return( -1 ) ;
  if ( !GWIsWindowValid( gwnd ) ) return( -1 ) ;
  undo_buf = AllocateNewUndoBuffer( gwnd ) ;
  if ( undo_buf == NULL ) return( -3 ) ;

  vimage = (VXIMAGE *) gwnd->Extension ;
/*  if ( type_modif & REDO ) redo = 1 ;
  type_modif &= ~REDO ;
*/
  if ( xundo )
  {
    if ( xundo->nb_bytes_to_allocate_and_copy > 0 )
    {
      spec = malloc( xundo->nb_bytes_to_allocate_and_copy ) ;
      if ( spec ) memcpy( spec, xundo->spec, xundo->nb_bytes_to_allocate_and_copy ) ;
      else        return( -3 ) ;
    }
  }

  if ( x1 > x2 )
  {
    temp = x1 ;
    x1   = x2 ;
    x2   = temp ;
  }

  if ( y1 > y2 )
  {
    temp = y1 ;
    y1   = y2 ;
    y2   = temp ;
  }

  wx = x2 - x1 + 1 ;
  wy = y2 - y1 + 1 ;

  larg = ALIGN16( wx ) ;

  if ( need_palette( type_modif, spec ) )
  {
    size_t size ;

    undo_buf->nb_cpal = (int) vimage->inf_img.nb_cpal ;
    size              = undo_buf->nb_cpal * 3 * sizeof(int) ;
    undo_buf->palette = (int *) malloc( size ) ;
    if ( undo_buf->palette == NULL ) return( -3 ) ;
    else                             memcpy( undo_buf->palette, vimage->inf_img.palette, size ) ;
  }

  if ( x1 < 0 ) taille = 0 ; /* Pas de modif sur l'image (palette sans doute) */
  else          taille = img_size( larg, wy, nb_plane ) ;

  undo_buf->original_width  = vimage->raster.fd_w ;
  undo_buf->original_height = vimage->raster.fd_h ;

  type_alloc = must_alloc( type_modif, taille, spec ) ;
  if ( type_alloc == 0 ) /* Est-il n‚cessaire d'allouer de la m‚moire ? */
  {
    undo_buf->img.fd_addr = NULL ;
    undo_buf->x           = x1 ;
    undo_buf->y           = y1 ;
    undo_buf->w           = wx ;
    undo_buf->h           = wy ;
    undo_buf->mitem       = type_modif ;
    undo_buf->spec        = spec ;
  }
  else
  {
    if ( type_alloc == 2 ) undo_buf->disk        = 1 ;
    else                   undo_buf->img.fd_addr = malloc( taille ) ;
    if ( undo_buf->disk || ( undo_buf->img.fd_addr != NULL ) )
    {
      undo_buf->img.fd_w       = larg ; /* Si possible, on m‚morise */
      undo_buf->img.fd_h       = wy ;   /* Les nouvelles donn‚es    */
      undo_buf->img.fd_wdwidth = larg/16 ;
      undo_buf->img.fd_nplanes = nb_plane ;
      undo_buf->img.fd_stand   = 0 ;
      undo_buf->gwindow        = gwnd ;
      undo_buf->x              = x1 ;
      undo_buf->y              = y1 ;
      undo_buf->w              = wx ;
      undo_buf->h              = wy ;
      undo_buf->mitem          = type_modif ;
      undo_buf->spec           = spec ;

      xy[0] = x1 ;   xy[1] = y1 ;
      xy[2] = x2 ;   xy[3] = y2 ;
      xy[4] = 0 ;    xy[5] = 0 ;
      xy[6] = wx-1 ; xy[7] = wy-1 ;
      if ( undo_buf->disk ) undo_disk( gwnd, undo_buf, xy, &vimage->raster ) ;
      else                  vro_cpyfm( handle, S_ONLY, xy, &vimage->raster, &undo_buf->img ) ;
    }
  }

  if ( !err )
  {
    LIST_ENTRY* entry = GET_LIST_ENTRY_FROM_UNDO_DEF( undo_buf ) ;

    InsertHeadList( &vimage->UndoListHead, entry ) ;
    if ( type_modif != REDO ) FreeUUndoBuffer( gwnd ) ;
  }
  else
  {
    FreeUndoBuffer( undo_buf ) ;
    form_stop( 1, msg[MSG_UNDOERROR] ) ;
  }

  return( err ) ;
}
Exemple #7
0
void restore_undo_disk(GEM_WINDOW *wnd, UNDO_DEF *undo, int *xy, MFDB *raster)
{
  MFDB img ;
  long taille ;
  char name[200] ;

  memset( &img, 0,sizeof(MFDB) ) ;
  sprintf( name, "%s\\~%02d~.TMP", config.path_temp, undo->undo_num ) ;
  img.fd_w = 1+xy[2]-xy[0] ;
  img.fd_wdwidth = img.fd_w / 16 ;
  if ( img.fd_w % 16 ) img.fd_wdwidth++ ;
  img.fd_h = 1 ;
  img.fd_nplanes = raster->fd_nplanes ;
  taille = img_size( img.fd_w, 1, img.fd_nplanes ) ;
  img.fd_addr = malloc ( taille ) ;
  if ( img.fd_addr == NULL )
  {
    form_stop( 1, msg[MSG_UNDOERROR] ) ;
    return ;
  }
  else
  {
    FILE *stream ;

    stream = fopen( name, "rb" ) ;
    if ( stream == NULL )
    {
      form_stop(1, msg[MSG_UNDOERROR]) ;
      return ;
    }
    else
    {
      MFDB timg ;
      int txy[8] ;
      int y ;
      int pc, err = 0 ;

      fread( &timg, sizeof(MFDB), 1, stream) ;
      txy[0] = 0 ; txy[2] = img.fd_w-1 ;
      txy[1] = txy[3] = 0 ;
      txy[4] = xy[4] ;
      txy[6] = xy[6] ;
      for ( y = xy[5]; !err && ( y <= xy[7] ); y++ )
      {
        txy[5] = txy[7] = y ;
        if ( fread( img.fd_addr, taille, 1, stream ) != 1 ) err = 1 ;
        vro_cpyfm( handle, S_ONLY, txy, &img, raster ) ;
        if ( wnd && wnd->ProgPc && ( ( ( (y - xy[5]) & 0x0F ) == 0x0F ) ) )
        {
          pc = (int) ( (100L * (long)(y - xy[5])) / (long)(xy[7]- xy[5]) ) ;
          if ( undo->mitem == REDO ) wnd->ProgPc( wnd, pc, "Redo" ) ;
          else                       wnd->ProgPc( wnd, pc, "Undo" ) ;
        }
      }
      fclose( stream ) ;
      if ( wnd && wnd->ProgPc ) wnd->ProgPc( wnd, 100, NULL ) ;
      if ( err )
      {
        form_stop(1, msg[MSG_UNDOERROR]) ;
      }
    }
    free( img.fd_addr ) ;
  }
}
Exemple #8
0
int main(int argc, char* argv[]) {
    std::string hostname,user,password;
    int port;
    double pan,tilt,zoom;

    if(argc!=10) {
        std::cout << "Usage :" << std::endl
                  << "  " << argv[0]
                  << " <hostname> <port:80> <username> <password> <pan> <tilt> <zoom> <x> <y>"
                  << std::endl;
        return 0;
    }

    hostname = argv[1];
    port     = atoi(argv[2]);
    user     = argv[3];
    password = argv[4];

    axis::PTZ axis(hostname,port);
    if(!axis.connect(user,password)) {
        std::cout << "Connot connect " << user
                  << " (" << password << ") on "
                  << hostname << ':' << port << ". Aborting."
                  << std::endl;
        return 1;
    }

    axis.setAutoiris("off");
    axis.setIris(1000);

    axis.getPosition(pan,tilt,zoom);
    std::cout << "Current position is " << std::endl
              << "  pan  = " << pan << std::endl
              << "  tilt = " << tilt << std::endl
              << "  zoom = " << zoom << std::endl;

    pan  = atof(argv[5]);;
    tilt = atof(argv[6]);
    zoom = atof(argv[7]);

    std::cout << "Reaching now... " << std::endl
              << "  pan  = " << pan << std::endl
              << "  tilt = " << tilt << std::endl
              << "  zoom = " << zoom << std::endl;
    axis.setPanTilt(pan,tilt);
    axis.setZoom(zoom);
    axis.wait();

    std::cout << "... reached." << std::endl;
    axis.getPosition(pan,tilt,zoom);
    std::cout << "  pan  = " << pan << std::endl
              << "  tilt = " << tilt << std::endl
              << "  zoom = " << zoom << std::endl;

    // Let us now grab an image.
    // We wait 2 seconds for autofocus to stabilize, since we mah have zoomed.
    ost::Thread::sleep(2000);
    axis.getDefaultBMPImage();

    // Let us now handle the image with mirage
    ImageRGB img;
    int dummy;
    mirage::img::Coordinate img_size(axis.getWidth(),axis.getHeight());
    img.resize(img_size,
               (ImageRGB::value_type*)axis.getImageBytes(dummy,dummy,dummy));

    // Let is save the mirage image in a file.
    std::ostringstream outputnamestream;
    outputnamestream << "X_" << argv[8] << "Y_" << argv[9] << "pan_" << pan << "tilt_" << tilt << "zoom_" << zoom << ".jpg";
    std::string outputname = outputnamestream.str();
    rgb2bgr(img);
    mirage::img::JPEG::write(img,outputname,80);
    std::cout << "Image has been captured in ptz.jpg file." << std::endl;

    return 0;
}
void CTransformationThread::Process(size_t index)
{
	ASSERT(index < files_.size());
	ASSERT(files_[index] != 0);
	ASSERT(index < files_.size());

	PhotoInfo& photo= *files_[index];

	// output file
	Path output= GetDestFileName(index);

	if (transformation_.size() == 1 && transformation_.front().needs_input_file_)
	{
		transformation_.front().fn_transform_img_(photo.GetOriginalPath(), output);

		return;		// exclusive transformation done, exit
	}

	// start loading
	SetOperationLabel(IDS_IMG_TRANSFORM_LOADING);

	CImageDecoderPtr decoder= photo.GetDecoder();

	decoder->SetProgressCallback(boost::bind(&CTransformationThread::LinesDecoded, this, _1, _2, _3));

	CSize img_size(0, 0);
	Dib dib;
	if (ImageStat status= decoder->DecodeImg(dib, img_size, false))
		throw ImageStatMsg(status);

	SetOperationLabel(IDS_IMG_TRANSFORM_APPLYING);

	for (size_t i= 0; i < transformation_.size(); ++i)
	{
		ASSERT(!transformation_[i].needs_input_file_);

		transformation_[i].fn_transform_bmp_(dib);
	}

	// EXIF block
	std::vector<uint8> exif;
	if (params_.copy_exif_ && photo.IsExifDataPresent())
	{
		ExifBlock exifBlock;
		if (photo.ReadExifBlock(exifBlock))
		{
			exifBlock.ModifySizeFields(dib.GetSize(), true);
			exifBlock.GetExifMarkerBlock(exif);
		}
	}

	// start storing result
	SetOperationLabel(IDS_IMG_TRANSFORM_STORING);

	// destination file
	CFileDataDestination fdest(output.c_str());

	// write transformed photo
	if (!encoder_->Encode(fdest, &dib, &exif))
		throw _T("Error encoding JPEG file.");
}