////////////////////////////////////////////////////////////////////////////////// // updateDimensions -------------------------------------------------------------- ////////////////////////////////////////////////////////////////////////////////// void ofxUeye::updateDimensions() { bool wasLive = bLive; if (wasLive) disableLive(); // Get current and maximum AOI IS_RECT curAOI; is_AOI(m_hCam, IS_AOI_IMAGE_GET_AOI, (void*)&curAOI, sizeof(curAOI)); calculateMaxAOI(); // Update dimensions that might have changed _AOI.x = curAOI.s32X; _AOI.y = curAOI.s32Y; _AOI.height = curAOI.s32Height; _AOI.width = curAOI.s32Width; _AOINormalized.x = _AOI.x / _AOIMax.width; _AOINormalized.y = _AOI.y / _AOIMax.height; _AOINormalized.width = _AOI.width / _AOIMax.width; _AOINormalized.height = _AOI.height / _AOIMax.height; _width = curAOI.s32Width; _height = curAOI.s32Height; // reallocate our pixels for the new size if(_pixels != NULL) delete _pixels; _pixels = new unsigned char [_width*_height*_channels]; if (wasLive) enableLive(); // Notify that the dimensions has changed ofNotifyEvent(events.dimensionChanged, events.voidEventArgs); }
////////////////////////////////////////////////////////////////////////////////// // calculateMaxAOI --------------------------------------------------------------- ////////////////////////////////////////////////////////////////////////////////// void ofxUeye::calculateMaxAOI() { bool wasLive = bLive; if (wasLive) disableLive(); // Maximize AOI int curBinning = _binning; int curSubSampling = _subSampling; double curScaler = _scaler; is_SetBinning (m_hCam, IS_BINNING_DISABLE); is_SetSubSampling (m_hCam, IS_SUBSAMPLING_DISABLE); is_SetSensorScaler (m_hCam, IS_ENABLE_SENSOR_SCALER | IS_ENABLE_ANTI_ALIASING, 1.0); IS_RECT fullAOI; fullAOI.s32X = 0; fullAOI.s32Y = 0; fullAOI.s32Width = _sensorWidth; fullAOI.s32Height = _sensorHeight; is_AOI(m_hCam, IS_AOI_IMAGE_SET_AOI, (void*)&fullAOI, sizeof(fullAOI)); is_SetBinning (m_hCam, curBinning); is_SetSubSampling (m_hCam, curSubSampling); is_SetSensorScaler (m_hCam, IS_ENABLE_SENSOR_SCALER | IS_ENABLE_ANTI_ALIASING, curScaler); // Get the maximum AOI in the current binning, sub sampling and scaler IS_SIZE_2D maxAOI; is_AOI(m_hCam, IS_AOI_IMAGE_GET_SIZE_MAX, (void*)&maxAOI, sizeof(maxAOI)); _AOIMax.x = 0; _AOIMax.y = 0; _AOIMax.width = (float)maxAOI.s32Width; _AOIMax.height = (float)maxAOI.s32Height; if (wasLive) enableLive(); }
CdWidget::CdWidget( const QString &ad, int port, int info, const QString &tspath, QWidget *parent, QObject *objParent, const char *name ) : KaffeineInput( objParent, name ) { mainWidget = new QVBox( parent ); mainWidget->setSizePolicy( QSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred) ); split = new QSplitter( mainWidget ); split->setOpaqueResize( true ); playerBox = new QVBox( split ); playerBox->setMinimumWidth( 200 ); channelsLb = new QListBox( split ); split->moveToFirst( channelsLb ); channelsLb->setSizePolicy( QSizePolicy (QSizePolicy::Preferred, QSizePolicy::MinimumExpanding) ); split->setResizeMode( channelsLb, QSplitter::KeepSize ); cdAddress = ad; cdPort = port; cdInfo = info; cdShiftDir = tspath; if ( !cdShiftDir.endsWith("/") ) cdShiftDir+= "/"; cleaner = new CdCleaner( cdShiftDir ); chan.setAutoDelete( true ); KIconLoader *icon = new KIconLoader(); tvPix = icon->loadIcon( "kdvbtv", KIcon::Small ); raPix = icon->loadIcon( "kdvbra", KIcon::Small ); delete icon; listen = new CdListen(); listen->go( cdAddress, cdInfo ); fifoName = QDir::homeDirPath()+"/.kaxclient.ts"; QFile f( fifoName ); if ( f.exists() ) f.remove(); if ( (mkfifo( fifoName.ascii(), 0644 ))<0 ) { perror( fifoName.latin1() ); fifoName = ""; dump = 0; } else { dump = new CdDump( fifoName ); connect( channelsLb, SIGNAL(selected(const QString &)), this, SLOT(channelSelected(const QString &)) ); connect( listen, SIGNAL(listChanged(const QString&)), this, SLOT(updateList(const QString&)) ); } lastChannel = 0; enableLive( false ); loadConfig( KGlobal::config() ); }
////////////////////////////////////////////////////////////////////////////////// // setSubSampling ---------------------------------------------------------------- ////////////////////////////////////////////////////////////////////////////////// int ofxUeye::setSubSampling(INT mode) { bool wasLive = bLive; if (wasLive) disableLive(); // As the subsampling change will make the camera irresponsive for a while, we need to flag as NOT ready for thread safety bReady = false; int result; result = is_SetSubSampling (m_hCam, mode); if(result == IS_SUCCESS){ _subSampling = mode; updateDimensions(); ofLog(OF_LOG_WARNING, "ofxUeye - setSubSampling - (%i) Success.", mode); } else { if(bVerbose) ofLog(OF_LOG_WARNING, "ofxUeye - setSubSampling - Couldn't apply %i value.", mode); } if (wasLive) enableLive(); return result; }
////////////////////////////////////////////////////////////////////////////////// // setAOI ------------------------------------------------------------------------ ////////////////////////////////////////////////////////////////////////////////// int ofxUeye::setAOI(ofRectangle aoi) { bool wasLive = bLive; if (wasLive) disableLive(); // We need to request a native aoi, otherwise it will fail, it requeire a couple of steps to get it right... // Update the curent max AOI calculateMaxAOI(); // Clamp the desired AOI to safe values; ofClamp(aoi.width, 0, _AOIMax.width); ofClamp(aoi.height, 0, _AOIMax.height); ofClamp(aoi.x, 0, (_AOIMax.width - aoi.width)); ofClamp(aoi.y, 0, (_AOIMax.height - aoi.height)); IS_RECT newAOI; newAOI.s32X = aoi.x; newAOI.s32Y = aoi.y; newAOI.s32Width = aoi.width; newAOI.s32Height = aoi.height; // Round the size value to a valid increment IS_SIZE_2D sizeInc; is_AOI(m_hCam, IS_AOI_IMAGE_GET_SIZE_INC, (void*)&sizeInc, sizeof(sizeInc)); newAOI.s32Width = (newAOI.s32Width / sizeInc.s32Width) * sizeInc.s32Width; newAOI.s32Height = (newAOI.s32Height / sizeInc.s32Height) * sizeInc.s32Height; // Clamp size to min and max accepted by the sensor IS_SIZE_2D minSize; is_AOI(m_hCam, IS_AOI_IMAGE_GET_SIZE_MIN, (void*)&minSize, sizeof(minSize)); IS_SIZE_2D maxSize; is_AOI(m_hCam, IS_AOI_IMAGE_GET_SIZE_MAX, (void*)&maxSize, sizeof(maxSize)); ofClamp(newAOI.s32Width, minSize.s32Width, maxSize.s32Height); ofClamp(newAOI.s32Height, minSize.s32Height, maxSize.s32Height); // Now we are sure the size is valid, so we apply it in order to be abble get the max and min values for the position IS_RECT newAOISize; newAOISize.s32X = 0; newAOISize.s32Y = 0; newAOISize.s32Width = newAOI.s32Width; newAOISize.s32Height = newAOI.s32Height; is_AOI( m_hCam, IS_AOI_IMAGE_SET_AOI, (void*)&newAOISize, sizeof(newAOISize)); // Round the position value to a valid increment IS_SIZE_2D posInc; is_AOI(m_hCam, IS_AOI_IMAGE_GET_POS_INC, (void*)&posInc, sizeof(posInc)); newAOI.s32X = (newAOI.s32X / posInc.s32Width) * posInc.s32Width; newAOI.s32Y = (newAOI.s32Y / posInc.s32Height) * posInc.s32Height; // Clamp position to min and max accepted by the sensor IS_POINT_2D minPos; is_AOI(m_hCam, IS_AOI_IMAGE_GET_POS_MIN, (void*)&minPos, sizeof(minPos)); IS_POINT_2D maxPos; is_AOI(m_hCam, IS_AOI_IMAGE_GET_POS_MAX, (void*)&maxPos, sizeof(maxPos)); ofClamp(newAOI.s32X, minPos.s32X, maxPos.s32X); ofClamp(newAOI.s32Y, minPos.s32Y, maxPos.s32Y); // As the AOI change will make the camera irresponsive for a while, we need to flag as NOT ready for thread safety bReady = false; // Apply the AOI int result; result = is_AOI( m_hCam, IS_AOI_IMAGE_SET_AOI, (void*)&newAOI, sizeof(newAOI)); if(result == IS_SUCCESS) { updateDimensions(); ofLog(OF_LOG_WARNING, "ofxUeye - setAOI - (%f, %f, %f, %f) Success.", _AOI.x, _AOI.y, _AOI.width, _AOI.height); } else { if(bVerbose) ofLog(OF_LOG_WARNING, "ofxUeye - setAOI - Couldn't apply (%i, %i, %i, %i) value.", newAOI.s32X, newAOI.s32Y, newAOI.s32Width, newAOI.s32Height); } if (wasLive) enableLive(); return result; }