double ExRandomTrees::lnFunc(double num){
		if(num <= 1e-6){
			return 0;
		} 
		else{
			return num * fast_log2(float(num));
			//return num * log(num);
		}
	}
float GainComputer::operator()(const float x) const {
	const auto abs_x = std::abs(x);
	const auto db = (abs_x < lin_floor) ? db_floor : log2_db_k * fast_log2(abs_x);
	const auto overshoot_db = db - threshold_db;
	if( knee_width_db > 0.0f ) {
		const auto w2 = knee_width_db / 2.0f;
		const auto a = w2 / (knee_width_db * knee_width_db);
		const auto in_transition = (overshoot_db > -w2) && (overshoot_db < w2);
		const auto rectified_overshoot = in_transition ? (a * std::pow(overshoot_db + w2, 2.0f)) : std::max(overshoot_db, 0.0f);
		return rectified_overshoot * slope;
	} else {
		const auto rectified_overshoot = std::max(overshoot_db, 0.0f);
		return rectified_overshoot * slope;
	}
}
Exemple #3
0
static int set_auto_gain(sensor_t *sensor, int enable, float gain_db, float gain_db_ceiling)
{
   uint8_t reg;
   int ret = cambus_readb(sensor->slv_addr, BANK_SEL, &reg);
   ret |= cambus_writeb(sensor->slv_addr, BANK_SEL, reg | BANK_SEL_SENSOR);
   ret |= cambus_readb(sensor->slv_addr, COM8, &reg);
   ret |= cambus_writeb(sensor->slv_addr, COM8, (reg & (~COM8_AGC_EN)) | ((enable != 0) ? COM8_AGC_EN : 0));

   if ((enable == 0) && (!isnanf(gain_db)) && (!isinff(gain_db))) {
       float gain = IM_MAX(IM_MIN(fast_expf((gain_db / 20.0) * fast_log(10.0)), 32.0), 1.0);

       int gain_temp = fast_roundf(fast_log2(IM_MAX(gain / 2.0, 1.0)));
       int gain_hi = 0xF >> (4 - gain_temp);
       int gain_lo = IM_MIN(fast_roundf(((gain / (1 << gain_temp)) - 1.0) * 16.0), 15);

       ret |= cambus_writeb(sensor->slv_addr, GAIN, (gain_hi << 4) | (gain_lo << 0));
   } else if ((enable != 0) && (!isnanf(gain_db_ceiling)) && (!isinff(gain_db_ceiling))) {
Exemple #4
0
static int set_auto_gain(sensor_t *sensor, int enable, float gain_db, float gain_db_ceiling)
{
    uint8_t reg;
    int ret = cambus_readb(sensor->slv_addr, REG_COM8, &reg);
    ret |= cambus_writeb(sensor->slv_addr, REG_COM8, (reg & (~REG_COM8_AGC)) | ((enable != 0) ? REG_COM8_AGC : 0));

    if ((enable == 0) && (!isnanf(gain_db)) && (!isinf(gain_db))) {
        float gain = IM_MAX(IM_MIN(fast_expf((gain_db / 20.0) * fast_log(10.0)), 128.0), 1.0);

        int gain_temp = fast_roundf(fast_log2(IM_MAX(gain / 2.0, 1.0)));
        int gain_hi = 0x3F >> (6 - gain_temp);
        int gain_lo = IM_MIN(fast_roundf(((gain / (1 << gain_temp)) - 1.0) * 16.0), 15);

        ret |= cambus_writeb(sensor->slv_addr, REG_GAIN, ((gain_hi & 0x0F) << 4) | (gain_lo << 0));
        ret |= cambus_readb(sensor->slv_addr, REG_VREF, &reg);
        ret |= cambus_writeb(sensor->slv_addr, REG_VREF, ((gain_hi & 0x30) << 2) | (reg & 0x3F));
    } else if ((enable != 0) && (!isnanf(gain_db_ceiling)) && (!isinf(gain_db_ceiling))) {
Exemple #5
0
/** Error of ~0.01% */
float fast_log(float val)
{
  return (fast_log2 (val) * 0.69314718f);
}
JNIEXPORT void JNICALL Java_com_lightcrafts_jai_opimage_ColorSelectionMaskOpImage_nativeUshortLoop
(JNIEnv *env, jobject cls, jshortArray jsrcData, jbyteArray jdstData,
 jint width, jint height, jintArray jsrcBandOffsets,
 jint dstOffset, jint srcLineStride, jint dstLineStride,
 jfloatArray jcolorSelection, jfloat wr, jfloat wg, jfloat wb)
{
    ushort *srcData = (ushort *) env->GetPrimitiveArrayCritical(jsrcData, 0);
    byte *dstData = (byte *) env->GetPrimitiveArrayCritical(jdstData, 0);
    int *srcBandOffsets = (int *) env->GetPrimitiveArrayCritical(jsrcBandOffsets, 0);
    float *colorSelection = (float *) env->GetPrimitiveArrayCritical(jcolorSelection, 0);
    
    int srcROffset = srcBandOffsets[0];
    int srcGOffset = srcBandOffsets[1];
    int srcBOffset = srcBandOffsets[2];
    
    float hueLower                  = colorSelection[0];
    float hueLowerFeather           = colorSelection[1];
    float hueUpper                  = colorSelection[2];
    float hueUpperFeather           = colorSelection[3];
    float luminosityLower           = colorSelection[4];
    float luminosityLowerFeather    = colorSelection[5];
    float luminosityUpper           = colorSelection[6];
    float luminosityUpperFeather    = colorSelection[7];
    
    int hueOffset = 0;
    
    if (hueLower < 0 || hueLower - hueLowerFeather < 0 || hueUpper < 0) {
        hueLower += 1;
        hueUpper += 1;
        hueOffset = 1;
    } else if (hueLower > 1 || hueUpper + hueUpperFeather > 1 || hueUpper > 1) {
        hueOffset = -1;
    }
    
    for (int row = 0; row < height; row++) {
        for (int col = 0; col < width; col++) {
            float r = srcData[3 * col + row * srcLineStride + srcROffset];
            float g = srcData[3 * col + row * srcLineStride + srcGOffset];
            float b = srcData[3 * col + row * srcLineStride + srcBOffset];
            
            // float hue = hue(r / (float) 0xffff, g / (float) 0xffff, b / (float) 0xffff) / (float) (2 * Math.PI);
            
            float cmax = (r > g) ? r : g;
            if (b > cmax) cmax = b;
            float cmin = (r < g) ? r : g;
            if (b < cmin) cmin = b;
            
            float saturation;
            if (cmax != 0)
                saturation = (cmax - cmin) / cmax;
            else
                saturation = 0;

#if defined(__ppc__)            
            float luminosity = (float) (log1pf((wr * r + wg * g + wb * b)/0x100) / (8 * logf(2)));
#else
            float luminosity = (float) (fast_log2((wr * r + wg * g + wb * b)/0x100) / 8);
#endif
            float luminosityMask, colorMask;
            
            const float stmin = 0.01f;
            const float stmax = 0.02f;
            
            const float ltmin = .01;
            const float ltmax = .02;
            
            if (saturation > stmin && luminosity > ltmin) {
                float h = hue(r, g, b) / (float) (2 * M_PI);
                
                if (hueOffset == 1 && h < hueLower - hueLowerFeather)
                    h += 1;
                else if (hueOffset == -1 && h < 0.5)
                    h += 1;
                
                if (h >= hueLower && h <= hueUpper)
                    colorMask = 1;
                else if (h >= (hueLower - hueLowerFeather) && h < hueLower)
                    colorMask = (h - (hueLower - hueLowerFeather))/hueLowerFeather;
                else if (h > hueUpper && h <= (hueUpper + hueUpperFeather))
                    colorMask = (hueUpper + hueUpperFeather - h)/hueUpperFeather;
                else
                    colorMask = 0;
                
                if (saturation < stmax)
                    colorMask *= (saturation - stmin) / (stmax - stmin);

                if (luminosity < ltmax)
                    colorMask *= (luminosity - ltmin) / (ltmax - ltmin);
            } else
                colorMask = 0;
            
            if (luminosity >= luminosityLower && luminosity <= luminosityUpper)
                luminosityMask = 1;
            else if (luminosity >= (luminosityLower - luminosityLowerFeather) && luminosity < luminosityLower)
                luminosityMask = (luminosity - (luminosityLower - luminosityLowerFeather))/luminosityLowerFeather;
            else if (luminosity > luminosityUpper && luminosity <= (luminosityUpper + luminosityUpperFeather))
                luminosityMask = (luminosityUpper + luminosityUpperFeather - luminosity)/luminosityUpperFeather;
            else
                luminosityMask = 0;
            
            colorMask *= luminosityMask;
            
            dstData[col + row * dstLineStride + dstOffset] = (byte) (0xff * colorMask);
        }
    }    
    
    env->ReleasePrimitiveArrayCritical(jsrcData, srcData, 0);
    env->ReleasePrimitiveArrayCritical(jdstData, dstData, 0);
    env->ReleasePrimitiveArrayCritical(jsrcBandOffsets, srcBandOffsets, 0);
    env->ReleasePrimitiveArrayCritical(jcolorSelection, colorSelection, 0);
}
Exemple #7
0
FFTX_FN_PREFIX
inline float fast_log10 (const float val) {
  return fast_log2(val) / 3.312500f;
}
Exemple #8
0
FFTX_FN_PREFIX
inline float fast_log (const float val) {
  return (fast_log2 (val) * 0.69314718f);
}
Exemple #9
0
 inline float fast_log(float x)
{
    return 0.69314718f * fast_log2 (x);
}
Exemple #10
0
inline float fast_log (const float &val)
{
  return (fast_log2 (val) * 0.69314718f);
}