Exemple #1
0
//------------------------------------------------------------------------
bool FormatLoad::getFormats(QList<Format> &formatList)
{
  formatList.clear();

  QProcess babel;
  babel.start("gpsbabel", QStringList() << "-^3");
  if (!babel.waitForStarted())
    return false;
  babel.closeWriteChannel();
  if (!babel.waitForFinished())
    return false;
  if (babel.exitCode() != 0)
    return false;

  QTextStream tstream(babel.readAll());
  QList<int>lineList;
  int k=0;
  while(!tstream.atEnd()) {
    QString l = tstream.readLine();
    k++;
    if (!QRegExp("^[\\s]*$").exactMatch(l)) {
      lines << l;
      lineList<<k;
    }
  }
  currentLine = 0;

  for  (bool dataPresent = skipToValidLine(); dataPresent; dataPresent=skipToValidLine()) {
    Format format;
    if (!processFormat(format)) {
      QMessageBox::information
	(0, appName,
	 QObject::tr("Error processing formats from running process \"gpsbabel -^3\" at line %1").arg(lineList[currentLine]));
    }
    else {
      formatList << format;
    }
  }
  return true;
}
void BufferFormatSpecifier::on_apply_clicked()
{
  setErrors(QString());
  emit processFormat(ui->formatText->toPlainText());
}
Exemple #3
0
ImageSourceFileWic::ImageSourceFileWic( DataSourceRef dataSourceRef, ImageSource::Options options )
	: ImageSource()
{
	::HRESULT hr = S_OK;

	// Initialize COM
	msw::initializeCom();
	
    // Create WIC factory
    IWICImagingFactory *IWICFactoryP = NULL;
    hr = ::CoCreateInstance( CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&IWICFactoryP) );
	if( ! SUCCEEDED( hr ) )
		throw ImageIoExceptionFailedLoad();
	std::shared_ptr<IWICImagingFactory> IWICFactory = msw::makeComShared( IWICFactoryP );
	
    // Create a decoder
	IWICBitmapDecoder *decoderP = NULL;
	if( dataSourceRef->isFilePath() ) {
		hr = IWICFactory->CreateDecoderFromFilename(
				toUtf16( dataSourceRef->getFilePath().string() ).c_str(),                      // Image to be decoded
				NULL,                            // Do not prefer a particular vendor
				GENERIC_READ,                    // Desired read access to the file
				WICDecodeMetadataCacheOnDemand,  // Cache metadata when needed
				&decoderP                        // Pointer to the decoder
			);
		if( ! SUCCEEDED(hr) )
			throw ImageIoExceptionFailedLoad();
	}
	else { // have to use a buffer
		IWICStream *pIWICStream = NULL;
		hr = IWICFactory->CreateStream( &pIWICStream );
		if( ! SUCCEEDED(hr) )
			throw ImageIoExceptionFailedLoad();
		std::shared_ptr<IWICStream> stream = msw::makeComShared( pIWICStream );
		
		Buffer buffer = dataSourceRef->getBuffer();
		hr = stream->InitializeFromMemory( reinterpret_cast<BYTE*>( buffer.getData() ), buffer.getDataSize() );
		if( ! SUCCEEDED(hr) )
			throw ImageIoExceptionFailedLoad();
		
		hr = IWICFactory->CreateDecoderFromStream( stream.get(), NULL, WICDecodeMetadataCacheOnDemand, &decoderP );
		if( ! SUCCEEDED(hr) )
			throw ImageIoExceptionFailedLoad();
	}
	std::shared_ptr<IWICBitmapDecoder> decoder = msw::makeComShared( decoderP );

    // Retrieve the 'index' frame of the image from the decoder
	IWICBitmapFrameDecode *frameP = NULL;
	hr = decoder->GetFrame( options.getIndex(), &frameP );
	if( ! SUCCEEDED(hr) )
		throw ImageIoExceptionFailedLoad();
	std::shared_ptr<IWICBitmapFrameDecode> frame = msw::makeComShared( frameP );

	UINT width = 0, height = 0;
	frame->GetSize( &width, &height );
	mWidth = width; mHeight = height;
	
	GUID pixelFormat = { 0 }, convertPixelFormat;
	frame->GetPixelFormat( &pixelFormat );
	
	bool requiresConversion = processFormat( pixelFormat, &convertPixelFormat );
	mRowBytes = mWidth * ImageIo::dataTypeBytes( mDataType ) * channelOrderNumChannels( mChannelOrder );

	mData = std::shared_ptr<uint8_t>( new uint8_t[mRowBytes * mHeight], boost::checked_array_delete<uint8_t> );

	if( requiresConversion ) {
		IWICFormatConverter *pIFormatConverter = NULL;	
		hr = IWICFactory->CreateFormatConverter( &pIFormatConverter );
		if( ! SUCCEEDED( hr ) )
			throw ImageIoExceptionFailedLoad();
		std::shared_ptr<IWICFormatConverter> formatConverter = msw::makeComShared( pIFormatConverter );
		hr = formatConverter->Initialize( frame.get(), convertPixelFormat, WICBitmapDitherTypeNone,
					NULL, 0.f, WICBitmapPaletteTypeCustom );
		if( ! SUCCEEDED( hr ) )
			throw ImageIoExceptionFailedLoad();
		hr = formatConverter->CopyPixels( NULL, (UINT)mRowBytes, mRowBytes * mHeight, mData.get() );
	}
	else
		hr = frame->CopyPixels( NULL, (UINT)mRowBytes, mRowBytes * mHeight, mData.get() );
}