コード例 #1
0
ファイル: BadaBitmap.cpp プロジェクト: zc5872061/wonderland
BadaBitmap::BadaBitmap(const std::string& fileName) :
		m_pixels(null),
		m_width(0),
		m_height(0)
{
	if(s_image == null)
	{
		s_image = new Osp::Media::Image();
		if(s_image->Construct() != E_SUCCESS)
		{
			AppAssertf(0, "BadaBitmap::BadaBitmap - could not construct image object.");
		}
	}
	Osp::Base::String badaFile(fileName.c_str());
	std::auto_ptr<Osp::Graphics::Bitmap> bitmap(s_image->DecodeN(badaFile, Osp::Graphics::BITMAP_PIXEL_FORMAT_ARGB8888));

	AppAssertf(bitmap.get() != null, "BadaBitmap::BadaBitmap - could not load image %s", fileName.c_str());

	m_width = bitmap->GetWidth();
	m_height = bitmap->GetHeight();

	copyBitmap(bitmap.get());

	fixColors();
}
コード例 #2
0
ファイル: semsnglw.c プロジェクト: MikeyG/open-watcom-v2
static void AddBitmapResource( WResID * name, ResMemFlags flags,
                            const char * filename )
/**************************************************************/
{
    BitmapFileHeader    head;
    WResFileID          handle;
    RcStatus            ret;
    int                 err_code;

    handle = RcIoOpenInput( filename, O_RDONLY | O_BINARY );
    if( handle == NIL_HANDLE)
        goto FILE_OPEN_ERROR;

    ret = readBitmapFileHeader( handle, &head, &err_code );
    if( ret != RS_OK )
        goto READ_HEADER_ERROR;

    if( head.Type != BITMAP_MAGIC )
        goto NOT_BITMAP_ERROR;

    ret = copyBitmap( &head, handle, name, flags, &err_code );
    if( ret != RS_OK )
        goto COPY_BITMAP_ERROR;

    RCCLOSE( handle );

    return;


FILE_OPEN_ERROR:
    RcError( ERR_CANT_OPEN_FILE, filename, strerror( errno ) );
    ErrorHasOccured = true;
    RCFREE( name );
    return;

READ_HEADER_ERROR:
    ReportCopyError( ret, ERR_READING_BITMAP, filename, err_code );
    ErrorHasOccured = true;
    RCFREE( name );
    RCCLOSE( handle );
    return;

NOT_BITMAP_ERROR:
    RcError( ERR_NOT_BITMAP_FILE, filename );
    ErrorHasOccured = true;
    RCFREE( name );
    RCCLOSE( handle );
    return;

COPY_BITMAP_ERROR:
    ReportCopyError( ret, ERR_READING_BITMAP, filename, err_code );
    ErrorHasOccured = true;
    RCCLOSE( handle );
    return;
}
コード例 #3
0
ファイル: vpFFMPEG.cpp プロジェクト: 976717326/visp
/*!
  Gets the \f$ frame \f$ th frame from the video and stores it in the image  \f$ I \f$.
  
  \param I : The vpImage used to stored the video's frame.
  \param frame : The index of the frame which has to be read.
  
  \return It returns true if the frame could be read. Else it returns false.
*/
bool vpFFMPEG::getFrame(vpImage<unsigned char> &I, unsigned int frame)
{

  if (frame < frameNumber && streamWasInitialized== true)
  {
    int64_t targetPts = index[frame];
    av_seek_frame(pFormatCtx,(int)videoStream,targetPts, AVSEEK_FLAG_ANY);
  }
  else
  {
    vpTRACE("Couldn't get a frame");
    return false;
  }
  
  avcodec_flush_buffers(pCodecCtx) ;

  int frameFinished ;

  av_init_packet(packet);
  while (av_read_frame (pFormatCtx, packet) >= 0)
  {
    if (packet->stream_index == (int)videoStream)
    {
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(52,72,2)
      avcodec_decode_video(pCodecCtx, pFrame,
         &frameFinished, packet->data, packet->size);
#else
      avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, packet); // libavcodec >= 52.72.2 (0.6)
#endif
      if (frameFinished)
      {
        if (color_type == vpFFMPEG::COLORED)
          sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
	else if (color_type == vpFFMPEG::GRAY_SCALED)
          sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameGRAY->data, pFrameGRAY->linesize);

          copyBitmap(I);
          break;
        }
      }
    }

    av_free_packet(packet);
    return true;
}
コード例 #4
0
ファイル: vpFFMPEG.cpp プロジェクト: 976717326/visp
/*!
  Gets the Next frame in the video.
  
  \param I : The vpImage used to stored the video's frame.
  
  \return It returns true if the frame could be read. Else it returns false.
*/
bool vpFFMPEG::acquire(vpImage<unsigned char> &I)
{
  int frameFinished ;
  
  if (streamWasInitialized == false)
  {
    vpTRACE("Couldn't get a frame. The parameters have to be initialized before ");
    return false;
  }

  av_init_packet(packet);
  while (av_read_frame (pFormatCtx, packet) >= 0)
  {
    if (packet->stream_index == (int)videoStream)
    {
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(52,72,2)
      avcodec_decode_video(pCodecCtx, pFrame,
         &frameFinished, packet->data, packet->size);
#else
      avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, packet); // libavcodec >= 52.72.2 (0.6)
#endif
     if (frameFinished)
      {
        if (color_type == vpFFMPEG::COLORED)
	  sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
        else if (color_type == vpFFMPEG::GRAY_SCALED)
	  sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameGRAY->data, pFrameGRAY->linesize);

        copyBitmap(I);
        break;
      }
    }
  }
  av_free_packet(packet);
  return true;
}