Пример #1
0
Decimal & Decimal::subtractDigits(const Decimal & other)
{
    extendRange(other);
    byte oLo = other.lsb;
    byte oHi = other.msb;
    byte hi = msb;

    unsigned idx;
    byte carry = 0;
    for (idx = oLo; (idx <= oHi); idx++)
    {
        int next = digits[idx] - (other.digits[idx] + carry);
        carry = 0;
        if (next < 0)
        {
            carry++;
            next += 10;
        }
        digits[idx] = next;
    }

    for (;carry && idx <= hi; idx++)
    {
        digits[idx]--;
        carry = 0;
        if (digits[idx] == 255)
        {
            carry = 1;
            digits[idx] += 10;
        }
    }

    if (carry)
    {
        //underflow => complement the result and add 1
        negative = !negative;
        carry = 1;
        for (idx = lsb; idx <= hi; idx++)
        {
            byte next = 9 - digits[idx] + carry;
            carry = 0;
            if (next == 10)
            {
                carry = 1;
                next -= 10;
            }
            digits[idx] = next;
        }
        assertex(!carry);
    }
    return *this;
}
Пример #2
0
Decimal & Decimal::addDigits(const Decimal & other)
{
    extendRange(other);
    byte oLo = other.lsb;
    byte oHi = other.msb;
    byte hi = msb;

    unsigned idx;
    byte carry = 0;
    for (idx = oLo; (idx <= oHi); idx++)
    {
        digits[idx] += other.digits[idx] + carry;
        carry = 0;
        if (digits[idx] > 9)
        {
            carry++;
            digits[idx] -= 10;
        }
    }

    for (;carry && idx <= hi; idx++)
    {
        digits[idx]++;
        carry = 0;
        if (digits[idx] > 9)
        {
            carry = 1;
            digits[idx] -= 10;
        }
    }

    if (carry && hi != lastDigit)
    {
        digits[++hi] = carry;
        msb = hi;
    }
    return *this;
}
PFSViewMainWin::PFSViewMainWin(  float window_min, float window_max ):
  QMainWindow( 0 )
{
  currentFrame = frameList.end();
  
  QScrollArea *pfsViewArea = new PFSViewWidgetArea( this );
  
  pfsView = (PFSViewWidget*)pfsViewArea->widget();
  
  setCentralWidget( pfsViewArea );

  setWindowIcon( QIcon( ":icons/appicon.png" ) );

  QAction *nextFrameAct = new QAction( tr( "&Next frame" ), this );
  nextFrameAct->setStatusTip( tr( "Load next frame" ) );
  nextFrameAct->setShortcut( Qt::Key_PageDown );
  connect( nextFrameAct, SIGNAL(triggered()), this, SLOT(gotoNextFrame()) );

  QAction *previousFrameAct = new QAction( tr( "&Previous frame" ), this );
  previousFrameAct->setStatusTip( tr( "Load previous frame" ) );
  previousFrameAct->setShortcut( Qt::Key_PageUp );
  connect( previousFrameAct, SIGNAL(triggered()), this, SLOT(gotoPreviousFrame()) );
  
  QToolBar *toolBar = addToolBar( tr( "Navigation" ) );
//  toolBar->setHorizontalStretchable( true );

  QToolButton *previousFrameBt = new QToolButton( toolBar );
  previousFrameBt->setArrowType( Qt::LeftArrow );
  previousFrameBt->setMinimumWidth( 15 );
  connect( previousFrameBt, SIGNAL(clicked()), this, SLOT(gotoPreviousFrame()) );
  previousFrameBt->setToolTip( "Goto previous frame" );
  toolBar->addWidget( previousFrameBt );
  
  QToolButton *nextFrameBt = new QToolButton( toolBar );
  nextFrameBt->setArrowType( Qt::RightArrow );
  nextFrameBt->setMinimumWidth( 15 );
  connect( nextFrameBt, SIGNAL(clicked()), this, SLOT(gotoNextFrame()) );
  nextFrameBt->setToolTip( "Goto next frame" );
  toolBar->addWidget( nextFrameBt );

  QLabel *channelSelLabel = new QLabel( "&Channel", toolBar );
  channelSelection = new QComboBox( toolBar );
  channelSelLabel->setBuddy( channelSelection );
  connect( channelSelection, SIGNAL( activated( int ) ),
    this, SLOT( setChannelSelection(int) ) );
  toolBar->addWidget( channelSelLabel );
  toolBar->addWidget( channelSelection );
  
  toolBar->addSeparator();

  QLabel *mappingMethodLabel = new QLabel( "&Mapping", toolBar );
  mappingMethodLabel->setAlignment(  Qt::AlignRight | Qt::AlignVCenter ); // | 
//				    Qt::TextExpandTabs | Qt::TextShowMnemonic );
  mappingMethodCB = new QComboBox( toolBar );
  mappingMethodLabel->setBuddy( mappingMethodCB );
  mappingMethodCB->addItem( "Linear" );
  mappingMethodCB->addItem( "Gamma 1.4" );
  mappingMethodCB->addItem( "Gamma 1.8" );
  mappingMethodCB->addItem( "Gamma 2.2" );
  mappingMethodCB->addItem( "Gamma 2.6" );
  mappingMethodCB->addItem( "Logarithmic" );
  mappingMethodCB->setCurrentIndex( 3 );
  connect( mappingMethodCB, SIGNAL( activated( int ) ),
    this, SLOT( setLumMappingMethod(int) ) );
  toolBar->addWidget( mappingMethodLabel );
  toolBar->addWidget( mappingMethodCB );
  
//  addToolBar( Qt::BottomToolBarArea, toolBar );  
  
  QToolBar *toolBarLR = addToolBar( tr( "Histogram" ) );
  lumRange = new LuminanceRangeWidget( toolBarLR );
  connect( lumRange, SIGNAL( updateRangeWindow() ), this,
    SLOT( updateRangeWindow() ) );
  toolBarLR->addWidget( lumRange );
//  addToolBar( toolBar );

  
  pointerPosAndVal = new QLabel( statusBar() );
  statusBar()->addWidget( pointerPosAndVal );
//  QFont fixedFont = QFont::defaultFont();
//  fixedFont.setFixedPitch( true );
//  pointerPosAndVal->setFont( fixedFont );
  zoomValue = new QLabel( statusBar() );
  statusBar()->addWidget( zoomValue );
  exposureValue = new QLabel( statusBar() );
  statusBar()->addWidget( exposureValue );

  connect( pfsView, SIGNAL(updatePointerValue()),
             this, SLOT(updatePointerValue()) );



  QMenu *frameMenu = menuBar()->addMenu( tr( "&Frame" ) );
  frameMenu->addAction( nextFrameAct );
  frameMenu->addAction( previousFrameAct );
  frameMenu->addSeparator();
  frameMenu->addAction( "&Save image...", this, SLOT(saveImage()), QKeySequence::Save ); 
  frameMenu->addAction( "&Copy image to clipboard", this, SLOT(copyImage()), QKeySequence::Copy ); 
  frameMenu->addSeparator();
  frameMenu->addAction( "&Quit", qApp, SLOT(quit()), Qt::Key_Q ); //QKeySequence::Quit
  QShortcut *shortcut = new QShortcut( QKeySequence::Close, this );
  connect( shortcut, SIGNAL(activated()), qApp, SLOT(quit()) );
  
  
  QAction *act;
  QMenu *viewMenu = menuBar()->addMenu( tr( "&View" ) );

  act = viewMenu->addAction( "&Zoom in", pfsView, SLOT(zoomIn()), Qt::Key_Period ); // QKeySequence::ZoomIn -- not doing it -- silly binding under Linux
  connect( act, SIGNAL(triggered()), this, SLOT(updateZoomValue()) );
  act = viewMenu->addAction( "Zoom &out", pfsView, SLOT(zoomOut()), Qt::Key_Comma ); 
  connect( act, SIGNAL(triggered()), this, SLOT(updateZoomValue()) );
  act = viewMenu->addAction( "Zoom &1:1", pfsView, SLOT(zoomOriginal()), Qt::Key_N ); 
  connect( act, SIGNAL(triggered()), this, SLOT(updateZoomValue()) );
  viewMenu->addAction( "&Fit window to content", this, SLOT(updateViewSize()), Qt::Key_C ); 

  viewMenu->addSeparator();  

  QMenu *infnanMenu = viewMenu->addMenu( "NaN and &Inf values" );
  QActionGroup *infnanActGrp = new QActionGroup( this );
  infnanActGrp->setExclusive( true );
  QAction *infnanHideAct = new QAction( tr( "&Hide" ), this );
  infnanHideAct->setCheckable(true);
  infnanHideAct->setData(0);
  infnanActGrp->addAction( infnanHideAct );
  infnanMenu->addAction( infnanHideAct );
  QAction *infnanMarkAct = new QAction( tr( "Mark with &red color" ), this );
  infnanMarkAct->setCheckable(true);
  infnanMarkAct->setData(1);
  infnanActGrp->addAction( infnanMarkAct );
  infnanMenu->addAction( infnanMarkAct );
  infnanMarkAct->setChecked( true );
  connect( infnanActGrp, SIGNAL(triggered(QAction*)), pfsView, SLOT(setInfNaNTreatment(QAction*)) );

  QMenu *colorClipMenu = viewMenu->addMenu( "&Color clipping" );
  QActionGroup *colorClipActGrp = new QActionGroup( this );
  colorClipActGrp->setExclusive( true );
  QAction *colorClipSimpleAct = new QAction( tr( "&Simple clipping" ), this );
  colorClipSimpleAct->setCheckable(true);
  colorClipSimpleAct->setData(CLIP_SIMPLE);
  colorClipSimpleAct->setShortcut( Qt::CTRL + Qt::Key_H );
  colorClipActGrp->addAction( colorClipSimpleAct );
  colorClipMenu->addAction( colorClipSimpleAct );
  QAction *colorClipCodedAct = new QAction( tr( "&Color-coded clipping" ), this );
  colorClipCodedAct->setCheckable(true);
  colorClipCodedAct->setShortcut( Qt::CTRL + Qt::Key_J );
  colorClipCodedAct->setData(CLIP_COLORCODED);
  colorClipActGrp->addAction( colorClipCodedAct );
  colorClipMenu->addAction( colorClipCodedAct );
  QAction *colorClipBriHueAct = new QAction( tr( "&Keep brightness and hue" ), this );
  colorClipBriHueAct->setCheckable(true);
  colorClipBriHueAct->setShortcut( Qt::CTRL + Qt::Key_K );
  colorClipBriHueAct->setData(CLIP_KEEP_BRI_HUE);
  colorClipActGrp->addAction( colorClipBriHueAct );
  colorClipMenu->addAction( colorClipBriHueAct );
  colorClipSimpleAct->setChecked( true );
  connect( colorClipActGrp, SIGNAL(triggered(QAction*)), pfsView, SLOT(setRGBClippingMethod(QAction*)) );

  QMenu *negativeMenu = viewMenu->addMenu( "&Negative values" );
  QActionGroup *negativeActGrp = new QActionGroup( this );
  negativeActGrp->setExclusive( true );
  act = new QAction( tr( "&Black" ), this );
  act->setCheckable(true);
  act->setData(NEGATIVE_BLACK);
  act->setShortcut( Qt::ALT + Qt::Key_B );
  negativeActGrp->addAction( act );
  negativeMenu->addAction( act );
  act->setChecked( true );
  act = new QAction( tr( "Mark with &red color" ), this );
  act->setCheckable(true);
  act->setData(NEGATIVE_MARK_AS_RED);
  act->setShortcut( Qt::ALT + Qt::Key_R );
  negativeActGrp->addAction( act );
  negativeMenu->addAction( act );
  act = new QAction( tr( "Use &green color scale" ), this );
  act->setCheckable(true);
  act->setData(NEGATIVE_GREEN_SCALE);
  act->setShortcut( Qt::ALT + Qt::Key_G );
  negativeActGrp->addAction( act );
  negativeMenu->addAction( act );
  act = new QAction( tr( "Use &absolute values" ), this );
  act->setCheckable(true);
  act->setData(NEGATIVE_ABSOLUTE);
  act->setShortcut( Qt::ALT + Qt::Key_A );
  negativeActGrp->addAction( act );
  negativeMenu->addAction( act );
  connect( negativeActGrp, SIGNAL(triggered(QAction*)), pfsView, SLOT(setNegativeTreatment(QAction*)) );
  
  viewMenu->addSeparator();
  
  QMenu *colorCoordMenu = viewMenu->addMenu( "Color coo&rdinates" );
  QActionGroup *colorCoordActGrp = new QActionGroup( this );
  colorCoordActGrp->setExclusive( true );
  act = new QAction( tr( "&RGB" ), this );
  act->setCheckable(true);
  act->setData(CC_RGB);
  act->setShortcut( Qt::SHIFT + Qt::ALT + Qt::Key_R );
  colorCoordActGrp->addAction( act );
  colorCoordMenu->addAction( act );
  act->setChecked( true );
  act = new QAction( tr( "&XYZ" ), this );
  act->setCheckable(true);
  act->setData(CC_XYZ);
  act->setShortcut( Qt::SHIFT + Qt::ALT + Qt::Key_X );
  colorCoordActGrp->addAction( act );
  colorCoordMenu->addAction( act );
  act = new QAction( tr( "Y&u'v'" ), this );
  act->setCheckable(true);
  act->setData(CC_Yupvp);
  act->setShortcut( Qt::SHIFT + Qt::ALT + Qt::Key_U );
  colorCoordActGrp->addAction( act );
  colorCoordMenu->addAction( act );
  act = new QAction( tr( "Yx&y" ), this );
  act->setCheckable(true);
  act->setData(CC_Yxy);
  act->setShortcut( Qt::SHIFT + Qt::ALT + Qt::Key_Y );
  colorCoordActGrp->addAction( act );
  colorCoordMenu->addAction( act );
  connect( colorCoordActGrp, SIGNAL(triggered(QAction*)), this, SLOT(setColorCoord(QAction*)) );
  

  QMenu *mappingMenu = menuBar()->addMenu( tr( "&Tone mapping" ) );
  
  
  mappingMenu->addAction( "Increase exposure", lumRange, 
			SLOT(increaseExposure()), Qt::Key_Minus ); 
  mappingMenu->addAction( "Decrease exposure", lumRange, 
			SLOT(decreaseExposure()), Qt::Key_Equal );
  mappingMenu->addAction( "Extend dynamic range", lumRange, 
			SLOT(extendRange()), Qt::Key_BracketRight ); 
  mappingMenu->addAction( "Shrink dynamic range", lumRange, 
			SLOT(shrinkRange()), Qt::Key_BracketLeft );
  mappingMenu->addAction( "Fit to dynamic range", lumRange, 
			SLOT(fitToDynamicRange()), Qt::Key_Backslash );
  mappingMenu->addAction( "Low dynamic range", lumRange, 
			SLOT(lowDynamicRange()), Qt::ALT + Qt::Key_L );


  QMenu *mapfuncMenu = mappingMenu->addMenu( "&Mapping function" );
  QActionGroup *mapfuncActGrp = new QActionGroup( this );
  mapfuncActGrp->setExclusive( true );
  mappingAct[0] = act = new QAction( tr( "&Linear" ), this );
  act->setCheckable(true);
  act->setData(0);
  act->setShortcut( Qt::Key_L );
  mapfuncActGrp->addAction( act );
  mapfuncMenu->addAction( act );
  mappingAct[1] = act = new QAction( tr( "Gamma 1.&4" ), this );
  act->setCheckable(true);
  act->setData(1);
  act->setShortcut( Qt::Key_1 );
  mapfuncActGrp->addAction( act );
  mapfuncMenu->addAction( act );
  mappingAct[2] = act = new QAction( tr( "Gamma 1.&8" ), this );
  act->setCheckable(true);
  act->setData(2);
  act->setShortcut( Qt::Key_2 );
  mapfuncActGrp->addAction( act );
  mapfuncMenu->addAction( act );
  mappingAct[3] = act = new QAction( tr( "Gamma 2.&2" ), this );
  act->setCheckable(true);
  act->setData(3);
  act->setChecked( true );
  act->setShortcut( Qt::Key_3 );
  mapfuncActGrp->addAction( act );
  mapfuncMenu->addAction( act );
  mappingAct[4] = act = new QAction( tr( "Gamma 2.&6" ), this );
  act->setCheckable(true);
  act->setData(4);
  act->setShortcut( Qt::Key_4 );
  mapfuncActGrp->addAction( act );
  mapfuncMenu->addAction( act );
  mappingAct[5] = act = new QAction( tr( "L&ogarithmic" ), this );
  act->setCheckable(true);
  act->setData(5);
  act->setShortcut( Qt::Key_O );
  mapfuncActGrp->addAction( act );
  mapfuncMenu->addAction( act );
  connect( mapfuncActGrp, SIGNAL(triggered(QAction*)), this, SLOT(setLumMappingMethod(QAction*)) );

  
  QMenu *helpMenu = menuBar()->addMenu( tr( "&Help" ) );
  helpMenu->addAction( "&About", this, SLOT(showAboutdialog()) );
  
  colorCoord = CC_RGB;
  
  //Window should not be larger than desktop
  // TODO: how to find desktop size - gnome taksbars
//  setMaximumSize( QApplication::desktop()->width(), QApplication::desktop()->height() );

  try {
    
    if( !readNextFrame() ) 
      throw PFSViewException();
    
    if( window_min < window_max )
      lumRange->setRangeWindowMinMax( window_min, window_max );  
    
  } catch( pfs::Exception ex ) {
    QMessageBox::critical( this, "pfsview error", ex.getMessage() );
    throw PFSViewException();
  }

}
Пример #4
0
FindBlack::FindBlack(double *bL, double *bK, double *a, double *b, int32 nB, 
					 double u_g, double miL, double maL, double *bT,
					 McoHandle gsmbH,McoHandle gsmbLH,double minGam, double maxGam,calib_base *cal)
{
double	*tx,*ty,yd1,ydn;
int i;
double *gammutSurfaceManyBlack;
double *gammutSurfaceManyBlackL;
double	gam_dim_k_vals[] = GAM_DIM_K_VALS;

	_gammutSurfaceManyBlackH = gsmbH;
	_gammutSurfaceManyBlackLH = gsmbLH;

	numB = nB;
	
	calib = cal;
	
	blackL = 0L;
	
	
/*	blackL = new double[numB];
	for (i=0; i<numB; i++)
		{
		blackL[i] = 100-bL[i];
		}
*/	
	//blackL = bL;
	blackK = bK;
	blacka = a;
	blackb = b;

//	tx = blackL;
	ty = blackK;
	
	K2 = new double[numB];
	if (!K2) goto bail;
	a2 = new double[numB];
	if (!a2) goto bail;
	b2 = new double[numB];
	if (!b2) goto bail;
	
//	yd1=(ty[2]-ty[1])/(tx[2]-tx[1])/4;
//	ydn=(ty[numB-1]-ty[numB-2])/(tx[numB-1]-tx[numB-2])/4;
	
//	spline(tx-1,ty-1,numB,yd1,ydn,K2-1);
	
	tx = blackK;
	ty = blacka;
	
	yd1=(ty[2]-ty[1])/(tx[2]-tx[1])/4;
	ydn=(ty[numB-1]-ty[numB-2])/(tx[numB-1]-tx[numB-2])/4;
	
	spline(tx-1,ty-1,numB,yd1,ydn,a2-1);
	
	tx = blackK;
	ty = blackb;
	
	yd1=(ty[2]-ty[1])/(tx[2]-tx[1])/4;
	ydn=(ty[numB-1]-ty[numB-2])/(tx[numB-1]-tx[numB-2])/4;
	
	spline(tx-1,ty-1,numB,yd1,ydn,b2-1);
	
	ucrgcr = u_g;
	//ucrgcr = u_g;
	
	minL = miL;
	maxL = maL;
	blackTable = bT;
	
	y2a = new double[GAM_DIM_K*50*72];
	if (!y2a) goto bail;
	
	fixmanyBlackL();
	
	gammutSurfaceManyBlack = (double*)McoLockHandle(_gammutSurfaceManyBlackH);
	gammutSurfaceManyBlackL = (double*)McoLockHandle(_gammutSurfaceManyBlackLH);

	
	x1 = new double[GAM_DIM_K];
	if (!x1) goto bail;
	x2 = new double[72];
	if (!x2) goto bail;
	x3 = new double[72];
	if (!x3) goto bail;
	
	
	for (i=0; i<GAM_DIM_K; i++) 
		{
		x1[i] = gam_dim_k_vals[i]/100.0;
		}
	for (i=0; i<72; i++) x2[i] = (double)i*5.0;

	spline3_s3(x1,x2,gammutSurfaceManyBlackL,gammutSurfaceManyBlack,GAM_DIM_K,72,50, y2a);

	McoUnlockHandle(_gammutSurfaceManyBlackH);
	McoUnlockHandle(_gammutSurfaceManyBlackH);

	findNeutralMins();
	extendRange();
	
	error = MCO_SUCCESS;
	return;	
bail:
	error = MCO_MEM_ALLOC_ERROR;
	return;
}