コード例 #1
0
void ColorScale::draw(sf::Image& img,const sf::Vector2f& start,const sf::Vector2f& end,GradientStyle::GradientStyle style, int size) const
{

	sf::Color (*pFunction)(sf::Color*,int,const sf::Vector2f&,const sf::Vector2f&,int,int);

	sf::Color* tab =new sf::Color[size];
	fillTab(tab,size);

	switch (style)
	{
		case GradientStyle::Linear : pFunction = GradientLinear; break;
		case GradientStyle::Circle : pFunction = GradientCircle; break;
		case GradientStyle::Radial : pFunction = GradientRadial; break;
		case GradientStyle::Reflex : pFunction = GradientReflex; break;

		default: pFunction = GradientLinear;  break;
	}

	for(int i=0;i<img.GetWidth();i++)
	{
		for(int j=0;j<img.GetHeight();j++)
		{
			img.SetPixel(i,j,pFunction(tab,size,start,end,i,j));
		}
	}
	delete[] tab;
}
コード例 #2
0
ファイル: checkutil.c プロジェクト: Distrotech/libdwarf
/* Traverse Bucket Set and execute a supplied function */
static void
ProcessBucketGroup(Bucket_Group *pBucketGroup,
    void (*pFunction)(Bucket_Group *pBucketGroup,Bucket_Data *pBucketData))
{
    int nIndex = 0;
    int nStart = 0;
    Bucket *pBucket = 0;
    Bucket_Data *pBucketData = 0;
    Bucket_Data *pLower = 0;
    Bucket_Data *pUpper = 0;
    Dwarf_Bool bFound = FALSE;

    /* Sanity checks */
    assert(pBucketGroup);

    /* No sentinels present; do nothing */
    if (!pBucketGroup->pFirst || !pBucketGroup->pLast) {
        return;
    }

    /* Find bucket that contains the first sentinel */
    for (pBucket = pBucketGroup->pHead; pBucket && pBucket->nEntries;
        pBucket = pBucket->pNext) {

        pLower = &pBucket->Entries[0];
        pUpper = &pBucket->Entries[pBucket->nEntries - 1];

        /* Check if the first sentinel is in this bucket */
        if (pBucketGroup->pFirst >= pLower && pBucketGroup->pFirst <= pUpper) {
            /* Low sentinel is in this bucket */
            bFound = TRUE;
            break;
        }
    }

    /* Invalid sentinel; do nothing */
    if (!bFound) {
        return;
    }

    /* Calculate index for first sentinel */
    nStart = pBucketGroup->pFirst - pLower;

    /* Start traversing from found bucket */
    for (; pBucket && pBucket->nEntries; pBucket = pBucket->pNext) {
        for (nIndex = nStart; nIndex < pBucket->nEntries; ++nIndex) {
            pBucketData = &pBucket->Entries[nIndex];
            if (pBucketData > pBucketGroup->pLast) {
                return;
            }
            /* Call the user supplied function */
            if (pFunction) {
                pFunction(pBucketGroup,pBucketData);
            }
        }
        /* For next bucket start with first entry */
        nStart = 0;
    }
}
コード例 #3
0
void ColorScale::fillTab(sf::Color* colorTab, int size,InterpolationFunction::InterpolationFunction function) const
{

	ColorScale::const_iterator start = std::map<double,sf::Color>::begin();
	ColorScale::const_iterator last  = std::map<double,sf::Color>::end();
	last--;

	double pos = 0.0;
	double distance = last->first - start->first;
	ColorScale::const_iterator it =  start;

	double(*pFunction)(double,double,double);

	switch (function)
	{
		case InterpolationFunction::Cosinus: pFunction = interpolateCosinus;  break;
		case InterpolationFunction::Linear : pFunction = linearInterpolation; break;
		default: pFunction = interpolateCosinus;  break;

	}
	while(it!=last)
	{
		sf::Color startColor = it->second;
		double    startPos   = it->first;
		it++;
		sf::Color endColor   = it->second;
		double    endPos     = it->first;
		double nb_color         = ((endPos-startPos)*(double)size/distance);

		for(int i = (int)pos;i<(int)(pos+nb_color);i++)
		{
			colorTab[i].r = (unsigned char)pFunction(startColor.r,endColor.r,std::abs((double)i-pos)/(nb_color-1.0));
			colorTab[i].g = (unsigned char)pFunction(startColor.g,endColor.g,std::abs((double)i-pos)/(nb_color-1.0));
			colorTab[i].b = (unsigned char)pFunction(startColor.b,endColor.b,std::abs((double)i-pos)/(nb_color-1.0));
			colorTab[i].a = (unsigned char)pFunction(startColor.a,endColor.a,std::abs((double)i-pos)/(nb_color-1.0));
		}
		pos+=nb_color;
	}

}
コード例 #4
0
ファイル: data.c プロジェクト: acmyonghua/eucalyptus
//!
//! Helper to do something on each instance of a given list
//!
//! @param[in] ppHead a pointer to the pointer to the head of the list
//! @param[in] pFunction a pointer to the function to execute on each node
//! @param[in] pParam a transparent pointer to provide to pFunction
//!
//! @return EUCA_OK on success or the following error code:
//!         \li EUCA_INVALID_ERROR: if any of our parameters do not meet the pre-conditions
//!
//! @pre Both \p ppHead and \p pFunction fields must not be NULL
//!
//! @post The function \p pFunction is applied to each member of the instance list.
//!
int for_each_instance(bunchOfInstances ** ppHead, void (*pFunction) (bunchOfInstances **, ncInstance *, void *), void *pParam)
{
    bunchOfInstances *pHead = NULL;

    // Make sure our parameters aren't NULL
    if (ppHead && pFunction) {
        for (pHead = *ppHead; pHead; pHead = pHead->next) {
            pFunction(ppHead, pHead->instance, pParam);
        }

        return (EUCA_OK);
    }
    return (EUCA_INVALID_ERROR);
}
コード例 #5
0
ファイル: dvb-fe.c プロジェクト: ElecardSTB/elecard-apps
int32_t dvbfe_setParam(uint32_t adapter, int32_t wait_for_lock,
						EIT_media_config_t *media, dvbfe_cancelFunctionDef* pFunction)
{
    uint8_t needTune = 0;
    fe_delivery_system_t delSys;
    uint32_t frequency;
    int32_t ret;
    int32_t hasLock;
    int32_t hasSignal;
    int32_t timeout;


	if(media == NULL) {
		eprintf("%s(): Error on tuning adapter%d, bad params!\n", __func__, adapter);
		return -1;
	}
	delSys = dvbfe_getDelSysFromMedia(media);
	frequency = media->frequency;

	if(g_adapterInfo[adapter].state.forceSetDelSys || (g_adapterInfo[adapter].state.curDelSys != delSys)) {
		if(dvbfe_setFrontendType(adapter, delSys) != 0) {
			eprintf("%s[%d]: Failed to set frontend delSys for current service\n", __func__, adapter);
			return -1;
		}
		g_adapterInfo[adapter].state.forceSetDelSys = 0;
		needTune = 1;
	}
	if(g_adapterInfo[adapter].state.frequency != frequency) {
		g_adapterInfo[adapter].state.frequency = frequency;
		needTune = 1;
	}

	switch(delSys) {
		case SYS_DVBT2: {
			uint8_t plp_id = media->dvb_t.plp_id;

			//check if tune needed
			if(g_adapterInfo[adapter].state.dvbtInfo.plp_id != plp_id) {
				g_adapterInfo[adapter].state.dvbtInfo.plp_id = plp_id;
				needTune = 1;
			}
			//no break!!!
		}
		case SYS_DVBT:
//			g_adapterInfo[adapter].state.dvbtInfo.generation = generation;
//			g_adapterInfo[adapter].state.dvbtInfo.bandwidth = bandwidth;
			break;
		case SYS_DVBC_ANNEX_AC:
			if((g_adapterInfo[adapter].state.dvbcInfo.symbolRate != media->dvb_c.symbol_rate)
			|| (g_adapterInfo[adapter].state.dvbcInfo.modulation != media->dvb_c.modulation)) {
				g_adapterInfo[adapter].state.dvbcInfo.symbolRate = media->dvb_c.symbol_rate;
				g_adapterInfo[adapter].state.dvbcInfo.modulation = media->dvb_c.modulation;
				needTune = 1;
			}
			break;
		case SYS_DVBS:
		case SYS_DVBS2: {
			uint32_t polarization = media->dvb_s.polarization;
			if(g_adapterInfo[adapter].state.dvbsInfo.polarization != polarization) {
				g_adapterInfo[adapter].state.dvbsInfo.polarization = polarization;
				needTune = 1;
			}
// 			g_adapterInfo[adapter].state.dvbsInfo.band = appControlInfo.dvbsInfo.band;
// 			g_adapterInfo[adapter].state.dvbsInfo.diseqc = appControlInfo.dvbsInfo.diseqc;
// 			g_adapterInfo[adapter].state.dvbsInfo.symbolRate = symbol_rate;
			break;
		}
		case SYS_ATSC:
		case SYS_DVBC_ANNEX_B:
// 			g_adapterInfo[adapter].state.atscInfo.modulation = modulation;
			break;
		default:
			needTune = 1;
			break;
	}

    if(needTune == 0) {
        //check if tuner locked
        tunerState_t state;

        memset(&state, 0, sizeof(state));
        dvbfe_getSignalInfo(adapter, &state);
        if(state.fe_status & FE_HAS_LOCK) {
            //no need to reconfigure tuner
            return 0;
        }
    }

    ret = -1;
    eprintf("%s(): Tune adapter=%d tuner, frequency=%uHz\n", __func__, adapter, frequency);
    switch(g_adapterInfo[adapter].driverType) {
        case eTunerDriver_linuxDVBapi:
            ret = dvbfe_setParamLinuxDVBapi(adapter, delSys, frequency, media);
            break;
        case eTunerDriver_STAPISDK:
            ret = dvbfe_setParamSTAPISDK(adapter, delSys, frequency, media);
            break;
        default:
            break;
    }
    if(ret != 0) {
        eprintf("%s(): Tuner %d not tuned on %u\n", __func__, adapter, frequency);
    }

    if(appControlInfo.dvbCommonInfo.adapterSpeed < 0) {//is this can happen?
        wait_for_lock = 0;
    }
    if(wait_for_lock == 0) {
//        eprintf("%s(): g_adapterInfo[%d].fd=%d\n", __func__, adapter, g_adapterInfo[adapter].fd);
        return 1;//1 mean 'no lock'
    }

    hasLock = 0;
    hasSignal = 0;
    timeout = (appControlInfo.dvbCommonInfo.adapterSpeed + 1);
#ifdef STBTI
    timeout *= 10;
#endif

    do {
        tunerState_t state;
        uint32_t us;
        uint32_t i;

        memset(&state, 0, sizeof(state));
        state.ber = BER_THRESHOLD;
        dvbfe_getSignalInfo(adapter, &state);

        if(state.fe_status & FE_HAS_LOCK) {
            if(!hasLock) {
                // locked, give adapter even more time... 
                dprintf("%s()[%d]: L\n", __func__, adapter);
            } else {
                break;
            }
            hasLock = 1;
        } else if(state.fe_status & FE_HAS_SIGNAL) {
            if(hasSignal == 0) {
                eprintf("%s()[%d]: Has signal\n", __func__, adapter);
                // found something above the noise level, increase timeout time 
                timeout += appControlInfo.dvbCommonInfo.adapterSpeed;
                hasSignal = 1;
            }
            dprintf("%s()[%d]: S (%d)\n", __func__, adapter, timeout);
        } else {
            dprintf("%s()[%d]: N (%d)\n", __func__, adapter, timeout);
            // there's no and never was any signal, reach timeout faster 
            if(hasSignal == 0) {
                eprintf("%s()[%d]: Skip\n", __func__, adapter);
                --timeout;
            }
        }

        // If ber is not -1, then wait a bit more 
//         if(state.ber == 0xffffffff) {
            dprintf("%s()[%d]: All clear...\n", __func__, adapter);
            us = 100000;
//         } else {
//             eprintf("%s()[%d]: Something is out there... (ber %u)\n", __func__, adapter, state.ber);
//             us = 500000;
//         }
        usleep(appControlInfo.dvbCommonInfo.adapterSpeed*10000);

        for(i = 0; i < us; i += SLEEP_QUANTUM) {
            if(pFunction && (pFunction() == -1)) {
                return -1;
            }
            if(dvbfe_getSignalInfo(adapter, NULL) == 1) {
                break;
            }
            usleep(SLEEP_QUANTUM);
        }

//         if((state.ber > 0) && (state.ber < BER_THRESHOLD)) {
//             break;
//         }
    } while(--timeout > 0);

    dprintf("%s[%d]: %u timeout %d, ber %u\n", __func__, adapter, frequency, timeout, ber);
    eprintf("%s(): Frequency set: adapter=%d, frequency=%ud, hasLock=%d, wait_for_lock=%d\n",
            __func__, adapter, frequency, hasLock, wait_for_lock);

    return !hasLock;
}
コード例 #6
0
 pStatement Statement::parse() {
     if (currentToken().type == TT_NAMESPACE) 
     {
         nextToken();
         _namespace = new_Namespace()->parse();       
     }
     else if(currentToken().type == TT_TYPEDEF) 
     {
             
     }
     else if(currentToken().type == TT_STRUCT || currentToken().type == TT_CLASS) 
     {
         isClass = true;
         if(currentToken().type == TT_STRUCT) {
             isStruct = true;
         }
         nextToken();
         _namespace = new_Namespace();
         _namespace->statementsBlock = new_StatementsBlock();
         _namespace->id = currentToken().strVal;
         pType newType = pType(new Type(owner, false) );
         pExprResult res = owner->new_ExprResult();
         res->evalType = ERT_TYPE;
         res->type = newType;
         newType->definition = this;
         owner->parsingStatementsBlockStack.back()->vars[_namespace->id] = res;
         _namespace->parse();   
         if(currentToken().type != TT_SEMICOLON) 
         {
             Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken(), "Expected semicolon");   
         }
         nextToken();
     }
     else if (currentToken().type == TT_BRACE_OPEN) {
         this->sb = new_StatementsBlock()->parse();
     }
     else if (currentToken().type == TT_BREAK 
         || currentToken().type == TT_RETURN 
         || currentToken().type == TT_ECHO 
         || currentToken().type == TT_CONTINUE) {
             isSpecial = true;
             specialType = currentToken().type;
             nextToken();
             if (specialType == TT_RETURN || specialType == TT_ECHO) {
                 expr = new_Expr()->parse();
             }
             if (currentToken().type != TT_SEMICOLON) {
                 throwTokenExpected(TT_SEMICOLON);
             }
             nextToken();
     }
     else if (currentToken().type == TT_IF) 
     {
         isSpecial = true;
         specialType = currentToken().type;
         nextToken();
         expr = new_Expr()->parse();
         statement1 = new_Statement()->parse();
         if (currentToken().type == TT_ELSE) 
         {
             nextToken();
             statement2 = new_Statement()->parse();
         }
     }
     else if (currentToken().type == TT_WHILE) 
     {
         localStatementsBlock = new_StatementsBlock();
         owner->parsingStatementsBlockStack.push_back(localStatementsBlock);
         isSpecial = true;
         specialType = currentToken().type;
         if (nextToken().type != TT_PARENTHESIS_OPEN) 
         {
             Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() );
         }
         nextToken();
         expr = new_Expr()->parse();
         if (currentToken().type != TT_PARENTHESIS_CLOSE) 
         {
             Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() );
         }
         nextToken();
         statement1 = new_Statement()->parse();
         owner->parsingStatementsBlockStack.pop_back();
     }
     else if (currentToken().type == TT_FOR) {
         localStatementsBlock = new_StatementsBlock();
         owner->parsingStatementsBlockStack.push_back(localStatementsBlock);
         isSpecial = true;
         specialType = currentToken().type;
         if (nextToken().type != TT_PARENTHESIS_OPEN) 
         {
             Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() );
         }
         nextToken();
         statement1 = new_Statement()->parse();
         expr = new_Expr()->parse();
         if (currentToken().type != TT_SEMICOLON) 
         {
             Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() );
         }
         nextToken();
         expr2 = new_Expr()->parse();
         if (currentToken().type != TT_PARENTHESIS_CLOSE) 
         {
             Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() );
         }
         nextToken();
         statement2 = new_Statement()->parse();
         owner->parsingStatementsBlockStack.pop_back();
     }
     else {
         tryParse([this]() {  
             tn = new_Typename()->parse();
             pVarDeclarationAllowDefault vd = new_VarDeclarationAllowDefault()->parse();
             if (owner->currentToken().type == TT_PARENTHESIS_OPEN) 
             {
                 if (!vd->canBeFunctionDeclaration() ) 
                 {
                     Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() );
                 }
                 nextToken();
                 this->function = pFunction(new Function(owner, vd->vd->id) );
                 this->function->args = new_FunctionArgs()->parse();
             
                 if (currentToken().type == TT_PARENTHESIS_CLOSE) 
                 {
                     if (nextToken().type == ';') 
                     {
                         this->function->statementsBlock = nullptr;    
                     }
                     else 
                     {
                         this->function->statementsBlock = new_StatementsBlock()->parse();
                         for (auto vd: this->function->args->vds) 
                         {
                             this->function->statementsBlock->vars[vd->vd->id] = nullptr;
                         }
                     }
                 }
                 else 
                 {
                     Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken(), "Unexpeted token");
                 }
             }
             else 
             {
                 if (currentToken().type == TT_COMMA || currentToken().type == TT_SEMICOLON) 
                 {
                     vds.push_back(vd);   
                 }
                 while (currentToken().type == TT_COMMA) 
                 {
                     nextToken();
                     vds.push_back(new_VarDeclarationAllowDefault()->parse() );
                 }
                 if (currentToken().type != TT_SEMICOLON) 
                 {
                     Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() );
                 }
                 nextToken();
             }
         },
         [this](exception &e) {
             vds.clear();
             tn = nullptr;
             expr = new_Expr()->parse();
             this->function = nullptr;
             if (currentToken().type != TT_SEMICOLON) 
             {
                 Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() );
             }
             nextToken();
         });
     }
     return pStatement(this);
 }