Exemplo n.º 1
0
float perlinNoise2d(float x, float y) {
        float result = 0.0f;
        for (int i = 0; i < 5; i++) {
                result += interpNoise2d(x * exp2f(i), y * exp2f(i)) * exp2f(-i);
        }
        return result;
}
Exemplo n.º 2
0
void RescaleWidget::
        updateModel()
{
    bool success1, success2;

    Heightmap::Position last = view_->getPlanePos( mapToParent(dragSource_), &success1);
    Heightmap::Position current = view_->getPlanePos( mapToParent(lastPos_), &success2);

    QPointF d = lastPos_ - dragSource_;
    float dx = d.x() / width();
    float dy = -d.y() / height();
    dx = max(-.1f, min(.1f, dx));
    dy = max(-.1f, min(.1f, dy));
    scalex_ *= exp2f(dx);
    scaley_ *= exp2f(dy);
    scalex_ = max(0.5f, min(1.8f, scalex_));
    scaley_ = max(0.5f, min(1.8f, scaley_));

    if (success1 && success2)
    {
        float r = DIRECT_RESCALING ? 4 : .1;
        float dt = r*(current.time - last.time)*view_->model->xscale/view_->model->_pz;
        float ds = r*(current.scale - last.scale)*view_->model->zscale/view_->model->_pz;

        Tools::Commands::pCommand cmd( new Tools::Commands::ZoomCameraCommand(view_->model, dt, ds, 0.f ));
        view_->model->project()->commandInvoker()->invokeCommand( cmd );
    }

    //dragSource_ = event->pos();
    recreatePolygon();
}
Exemplo n.º 3
0
    GaborParams (const NoiseParams &opt) :
        omega(opt.direction),  // anisotropy orientation
        anisotropic(opt.anisotropic),
        do_filter(opt.do_filter),
        weight(Gabor_Impulse_Weight),
        bandwidth(Imath::clamp(opt.bandwidth,0.01f,100.0f)),
        periodic(false)
    {
#if OSL_FAST_MATH
        float TWO_to_bandwidth = OIIO::fast_exp2(bandwidth);
#else
        float TWO_to_bandwidth = exp2f(bandwidth);
#endif
        static const float SQRT_PI_OVER_LN2 = sqrtf (M_PI / M_LN2);
        a = Gabor_Frequency * ((TWO_to_bandwidth - 1.0) / (TWO_to_bandwidth + 1.0)) * SQRT_PI_OVER_LN2;
        // Calculate the maximum radius from which we consider the kernel
        // impulse centers -- derived from the threshold and bandwidth.
        radius = sqrtf(-logf(Gabor_Truncate) / float(M_PI)) / a;
        radius2 = radius * radius;
        radius3 = radius2 * radius;
        radius_inv = 1.0f / radius;
        // Lambda is the impulse density.
        float impulses = Imath::clamp (opt.impulses, 1.0f, 32.0f);
        lambda = impulses / (float(1.33333 * M_PI) * radius3);
        sqrt_lambda_inv = 1.0f / sqrtf(lambda);
    }
Exemplo n.º 4
0
//
// powf
//
float powf(float x, float y)
{
   if(isnan(x)) return x;
   if(isnan(y)) return y;

   return exp2f(y * log2f(x));
}
Exemplo n.º 5
0
void test_exp2()
{
    static_assert((std::is_same<decltype(exp2((double)0)), double>::value), "");
    static_assert((std::is_same<decltype(exp2f(0)), float>::value), "");
    static_assert((std::is_same<decltype(exp2l(0)), long double>::value), "");
    assert(exp2(1) == 2);
}
Exemplo n.º 6
0
TEST(math, exp2_STRICT_ALIGN_OpenBSD_bug) {
  // OpenBSD/x86's libm had a bug here, but it was already fixed in FreeBSD:
  // http://svnweb.FreeBSD.org/base/head/lib/msun/src/math_private.h?revision=240827&view=markup
  ASSERT_DOUBLE_EQ(5.0, exp2(log2(5)));
  ASSERT_FLOAT_EQ(5.0f, exp2f(log2f(5)));
  ASSERT_DOUBLE_EQ(5.0L, exp2l(log2l(5)));
}
Exemplo n.º 7
0
static TACommandVerdict exp2f_cmd(TAThread thread,TAInputStream stream)
{
    float x, res;

    // Prepare

    x = readFloat(&stream);
    errno = 0;
    
    START_TARGET_OPERATION(thread);
    
    // Execute

    res = exp2f(x);
    
    END_TARGET_OPERATION(thread);
    
    // Response
    
    writeFloat(thread, res);
    writeInt(thread, errno);

    sendResponse(thread);
    return taDefaultVerdict;
}
Exemplo n.º 8
0
 void operator() ( Buffer< SampleType > &_buffer ) {
   if ( is_end ) {
     fillZero ( _buffer );
     return;
   }
   double time = instrument.getGlobalTime();
   while ( !release_stack.empty() && time - release_stack.top().first >= -0.00001f ) {
     instrument.noteOff ( release_stack.top().second );
     release_stack.pop();
   }
   while ( time - current_score->pos >= -0.00001f ) {
     if ( current_score->length == 0.0f ) {
       is_end = true;
       fillZero ( _buffer );
       return;
     }
     else {
       std::pair< double, int > temp;
       temp.first = current_score->pos + current_score->length;
       temp.second = instrument.noteOn ( current_score->note, exp2f ( ( current_score->touch - 1.0f ) * 10.0f ) );
       release_stack.push ( temp );
     }
     current_score++;
   }
   instrument ( _buffer );
 }
Exemplo n.º 9
0
/* conversion function to 1.NUMBER_OF_BITS format */
int convert(float value)
{
  float man, t_val, frac, m, exponent = NUMBER_OF_BITS;
  int rnd_val;
  unsigned long int_val;
  unsigned long pm_val;

  m = exp2f(exponent+1)  - 1;

  t_val = value * m ;
  frac = modff(t_val,&man);
  if (frac < 0.0f) 
    {
      rnd_val = (-1);
      if (frac > -0.5f) rnd_val = 0;
    }
  else
    {
      rnd_val = 1;
      if (frac < 0.5f) rnd_val = 0;
    }
  int_val = man + rnd_val;
  
  pm_val = int_val ; 
  return ((int) (pm_val)) ; 
  
}
Exemplo n.º 10
0
int
process_cl (struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, cl_mem dev_out, const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out)
{
  dt_iop_soften_data_t *d = (dt_iop_soften_data_t *)piece->data;
  dt_iop_soften_global_data_t *gd = (dt_iop_soften_global_data_t *)self->data;

  cl_int err = -999;
  cl_mem dev_m = NULL;
  const int devid = piece->pipe->devid;
  const int width = roi_in->width;
  const int height = roi_in->height;

  const float brightness = 1.0f / exp2f ( -d->brightness );
  const float saturation = d->saturation/100.0f;
  const float amount = d->amount/100.0f;

  const float w = piece->iwidth*piece->iscale;
  const float h = piece->iheight*piece->iscale;
  int mrad = sqrt( w*w + h*h) * 0.01f;

  int rad = mrad*(fmin(100.0f, d->size+1)/100.0f);
  const int radius = MIN(mrad, ceilf(rad * roi_in->scale / piece->iscale));

  /* sigma-radius correlation to match opencl vs. non-opencl. identified by numerical experiments but unproven. ask me if you need details. ulrich */
  const float sigma = sqrt((radius * (radius + 1) * BOX_ITERATIONS + 2)/3.0f);
  const int wdh = ceilf(3.0f * sigma);
  const int wd = 2 * wdh + 1;
  float mat[wd];
  float *m = mat + wdh;
  float weight = 0.0f;

  // init gaussian kernel
  for(int l=-wdh; l<=wdh; l++) weight += m[l] = expf(- (l*l)/(2.f*sigma*sigma));
  for(int l=-wdh; l<=wdh; l++) m[l] /= weight;

  // for(int l=-wdh; l<=wdh; l++) printf("%.6f ", (double)m[l]);
  // printf("\n");


  size_t maxsizes[3] = { 0 };        // the maximum dimensions for a work group
  size_t workgroupsize = 0;          // the maximum number of items in a work group
  unsigned long localmemsize = 0;    // the maximum amount of local memory we can use
  size_t kernelworkgroupsize = 0;    // the maximum amount of items in work group for this kernel
  
  // make sure blocksize is not too large
  int blocksize = BLOCKSIZE;
  if(dt_opencl_get_work_group_limits(devid, maxsizes, &workgroupsize, &localmemsize) == CL_SUCCESS &&
     dt_opencl_get_kernel_work_group_size(devid, gd->kernel_soften_hblur, &kernelworkgroupsize) == CL_SUCCESS)
  {
    // reduce blocksize step by step until it fits to limits
    while(blocksize > maxsizes[0] || blocksize > maxsizes[1] || blocksize > kernelworkgroupsize
          || blocksize > workgroupsize || (blocksize+2*wdh)*4*sizeof(float) > localmemsize)
    {
      if(blocksize == 1) break;
      blocksize >>= 1;    
    }
  }
  else
  {
Exemplo n.º 11
0
main()
{
	float a = 1.25,x,y;
	printf("\nNhap vao x :");  scanf("%f",&x);
	y = exp2f(a + sinf(x)*sinf(x) - x);
	printf("\nKQ = %E\n",y);
	getch();
}
Exemplo n.º 12
0
void Gear::createSinePartition() {
    // Use this to draw a sinus surface
    for (int i = 0; i < SEGMENT_COUNT; i++) {
        float position = (float) i / (float) SEGMENT_COUNT;
        float height = exp2f(sinf(position * 2.0f * M_PI));
        heightProfilePartition_.push_back(glm::vec2(position, height));
        //cout << position << ": " << height << std::endl;
    }
}
Exemplo n.º 13
0
bool IVDFileHandler::init( const file_args_t& file_params )
{
    struct stat sb;
    _fileD = ::open( file_params[0].c_str(), O_RDONLY );
    if( _fileD == -1 )
    {
        ::perror("open");
        return false;
    }

    if( ::fstat( _fileD, &sb ) == -1 )
    {
        ::perror("fstat");
        return false;
    }
    _lengthFile = sb.st_size;

    _startFile = (char*) ::mmap(NULL, _lengthFile, PROT_READ, MAP_PRIVATE, _fileD, 0);
    if( _startFile == MAP_FAILED )
    {
        ::perror("mmap");
        return false;
    }

    char * data = _startFile;
    _nLevels = *( (level_t*) data );
    data += sizeof( level_t );
    _level   = *( (level_t*) data );
    data += sizeof( level_t );
    _cubeInc = *( (int32_t*) data );
    data += sizeof( int32_t);
    const int32_t xdim = *( (int32_t*) data );
    data += sizeof( int32_t );
    const int32_t ydim = *( (int32_t*) data );
    data += sizeof( int32_t );
    const int32_t zdim = *( (int32_t*) data );
    data += sizeof( int32_t );
    _realDimension.set( xdim, ydim, zdim );
    _xGrid = (float*) data;
    data += xdim * sizeof( float );
    _yGrid = (float*) data;
    data += ydim * sizeof( float );
    _zGrid = (float*) data;
    data += zdim * sizeof( float );
    _idStart  = 1 << 3 * _level;
    _idFinish = ( 2 << 3 * _level ) - 1;
    _numCubes = _idFinish - _idStart + 1;
    _offsets = (int32_t*) data;
    data += _numCubes * sizeof( int32_t );
    _cubes = (float*) data;

    const uint32_t dim = exp2f( _nLevels - _level );
    _cubeSize = powf( dim + 2 * _cubeInc, 3 );

    return true;
}
Exemplo n.º 14
0
float AudioMixer::gainForSource(const PositionalAudioStream& streamToAdd,
                                const AvatarAudioStream& listeningNodeStream, const glm::vec3& relativePosition, bool isEcho) {
    float gain = 1.0f;

    float distanceBetween = glm::length(relativePosition);

    if (distanceBetween < EPSILON) {
        distanceBetween = EPSILON;
    }

    if (streamToAdd.getType() == PositionalAudioStream::Injector) {
        gain *= reinterpret_cast<const InjectedAudioStream*>(&streamToAdd)->getAttenuationRatio();
    }

    if (!isEcho && (streamToAdd.getType() == PositionalAudioStream::Microphone)) {
        //  source is another avatar, apply fixed off-axis attenuation to make them quieter as they turn away from listener
        glm::vec3 rotatedListenerPosition = glm::inverse(streamToAdd.getOrientation()) * relativePosition;

        float angleOfDelivery = glm::angle(glm::vec3(0.0f, 0.0f, -1.0f),
                                           glm::normalize(rotatedListenerPosition));

        const float MAX_OFF_AXIS_ATTENUATION = 0.2f;
        const float OFF_AXIS_ATTENUATION_FORMULA_STEP = (1 - MAX_OFF_AXIS_ATTENUATION) / 2.0f;

        float offAxisCoefficient = MAX_OFF_AXIS_ATTENUATION +
        (OFF_AXIS_ATTENUATION_FORMULA_STEP * (angleOfDelivery / PI_OVER_TWO));

        // multiply the current attenuation coefficient by the calculated off axis coefficient
        gain *= offAxisCoefficient;
    }

    float attenuationPerDoublingInDistance = _attenuationPerDoublingInDistance;
    for (int i = 0; i < _zonesSettings.length(); ++i) {
        if (_audioZones[_zonesSettings[i].source].contains(streamToAdd.getPosition()) &&
            _audioZones[_zonesSettings[i].listener].contains(listeningNodeStream.getPosition())) {
            attenuationPerDoublingInDistance = _zonesSettings[i].coefficient;
            break;
        }
    }

    if (distanceBetween >= ATTENUATION_BEGINS_AT_DISTANCE) {

        // translate the zone setting to gain per log2(distance)
        float g = 1.0f - attenuationPerDoublingInDistance;
        g = (g < EPSILON) ? EPSILON : g;
        g = (g > 1.0f) ? 1.0f : g;

        // calculate the distance coefficient using the distance to this node
        float distanceCoefficient = exp2f(log2f(g) * log2f(distanceBetween/ATTENUATION_BEGINS_AT_DISTANCE));

        // multiply the current attenuation coefficient by the distance coefficient
        gain *= distanceCoefficient;
    }

    return gain;
}
Exemplo n.º 15
0
bool
TargetNVC0::isPostMultiplySupported(operation op, float f, int& e) const
{
   if (op != OP_MUL)
      return false;
   f = fabsf(f);
   e = static_cast<int>(log2f(f));
   if (e < -3 || e > 3)
      return false;
   return f == exp2f(static_cast<float>(e));
}
Exemplo n.º 16
0
void TerrainGesture::UpdateMomentumOrbit(double secondsSinceLastUpdate)
{
	TerrainView* terrainView = _hotspot->GetTerrainView();
	glm::vec2 screenPosition = _hotspot->GetCurrentScreenPosition1();
	glm::vec3 contentAnchor = terrainView->GetTerrainPosition3(screenPosition);

	terrainView->Orbit(contentAnchor, (float)secondsSinceLastUpdate * _orbitVelocity);

	float slowdown = _hotspot->HasCapturedTouches() ? -8.0f : -4.0f;
	_orbitVelocity = _orbitVelocity * exp2f(slowdown * (float)secondsSinceLastUpdate);
}
Exemplo n.º 17
0
void TerrainGesture::UpdateKeyOrbit(double secondsSinceLastUpdate)
{
	if (_keyOrbitLeft) _keyOrbitMomentum -= 32 * (float)secondsSinceLastUpdate;
	if (_keyOrbitRight) _keyOrbitMomentum += 32 * (float)secondsSinceLastUpdate;

	TerrainView* terrainView = _hotspot->GetTerrainView();
	glm::vec2 centerScreen = terrainView->GetTerrainViewport().NormalizedToLocal(glm::vec2{});
	glm::vec3 contentAnchor = terrainView->GetTerrainPosition3(centerScreen);
	terrainView->Orbit(contentAnchor, (float)secondsSinceLastUpdate * _keyOrbitMomentum);

	_keyOrbitMomentum *= exp2f(-25 * (float)secondsSinceLastUpdate);
}
Exemplo n.º 18
0
void filtering(float** channel, float** dIcdx, float** dHdyT, int h, int w, float num_iterations) {
    float N = num_iterations;

    for (int i = 1; i <= num_iterations; i++) {
        float sigma_H = sigma_s;
        float sigma_H_i = sigma_H * sqrtf(3) * exp2f(N - i) / sqrtf(powf(4, N) - 1);

        TDRF_H(channel, dIcdx, sigma_H_i, h, w);
        channel = transpose(channel, h, w);

        TDRF_H(channel, dHdyT, sigma_H_i, w, h);
        channel = transpose(channel, w, h);
    }
}
Exemplo n.º 19
0
/// Dequantization and stereo decoding (14496-3 sp04 p203)
static void sbr_dequant(SpectralBandReplication *sbr, int id_aac)
{
    int k, e;
    int ch;

    if (id_aac == TYPE_CPE && sbr->bs_coupling) {
        float alpha      = sbr->data[0].bs_amp_res ?  1.0f :  0.5f;
        float pan_offset = sbr->data[0].bs_amp_res ? 12.0f : 24.0f;
        for (e = 1; e <= sbr->data[0].bs_num_env; e++) {
            for (k = 0; k < sbr->n[sbr->data[0].bs_freq_res[e]]; k++) {
                float temp1 = exp2f(sbr->data[0].env_facs[e][k] * alpha + 7.0f);
                float temp2 = exp2f((pan_offset - sbr->data[1].env_facs[e][k]) * alpha);
                float fac;
                if (temp1 > 1E20) {
                    av_log(NULL, AV_LOG_ERROR, "envelope scalefactor overflow in dequant\n");
                    temp1 = 1;
                }
                fac   = temp1 / (1.0f + temp2);
                sbr->data[0].env_facs[e][k] = fac;
                sbr->data[1].env_facs[e][k] = fac * temp2;
            }
        }
        for (e = 1; e <= sbr->data[0].bs_num_noise; e++) {
            for (k = 0; k < sbr->n_q; k++) {
                float temp1 = exp2f(NOISE_FLOOR_OFFSET - sbr->data[0].noise_facs[e][k] + 1);
                float temp2 = exp2f(12 - sbr->data[1].noise_facs[e][k]);
                float fac;
                if (temp1 > 1E20) {
                    av_log(NULL, AV_LOG_ERROR, "envelope scalefactor overflow in dequant\n");
                    temp1 = 1;
                }
                fac = temp1 / (1.0f + temp2);
                sbr->data[0].noise_facs[e][k] = fac;
                sbr->data[1].noise_facs[e][k] = fac * temp2;
            }
        }
    } else { // SCE or one non-coupled CPE
        for (ch = 0; ch < (id_aac == TYPE_CPE) + 1; ch++) {
            float alpha = sbr->data[ch].bs_amp_res ? 1.0f : 0.5f;
            for (e = 1; e <= sbr->data[ch].bs_num_env; e++)
                for (k = 0; k < sbr->n[sbr->data[ch].bs_freq_res[e]]; k++){
                    sbr->data[ch].env_facs[e][k] =
                        exp2f(alpha * sbr->data[ch].env_facs[e][k] + 6.0f);
                    if (sbr->data[ch].env_facs[e][k] > 1E20) {
                        av_log(NULL, AV_LOG_ERROR, "envelope scalefactor overflow in dequant\n");
                        sbr->data[ch].env_facs[e][k] = 1;
                    }
                }

            for (e = 1; e <= sbr->data[ch].bs_num_noise; e++)
                for (k = 0; k < sbr->n_q; k++)
                    sbr->data[ch].noise_facs[e][k] =
                        exp2f(NOISE_FLOOR_OFFSET - sbr->data[ch].noise_facs[e][k]);
        }
    }
}
Exemplo n.º 20
0
        uint getHeight(uint x, uint y, uint z) {
                uint cacheIdx = Morton::encode2(x, y);
                float scalef = exp2f(scale);
                if (z == 0) {
                        uint height = (Perlin::perlinNoise2d(x/scalef, y/scalef) + 2.0f) * scalef/2.0f;
                        if (cachedHeights.size() <= cacheIdx) {
                                cachedHeights.resize(cacheIdx + 1);
                        }
                        cachedHeights[cacheIdx] = height;
                        return height;
                }
                else {
                        return cachedHeights[cacheIdx];
                }

        }
Exemplo n.º 21
0
/* OpenCL processing function */
static cl_int
cl_process (GeglOperation       *op,
            cl_mem               in_tex,
            cl_mem               out_tex,
            size_t               global_worksize,
            const GeglRectangle *roi,
            gint                 level)
{
  /* Retrieve a pointer to GeglProperties structure which contains all the
   * chanted properties
   */

  GeglProperties *o = GEGL_PROPERTIES (op);

  gfloat      black_level = (gfloat) o->black_level;
  gfloat      diff;
  gfloat      exposure_negated = (gfloat) -o->exposure;
  gfloat      gain;
  gfloat      white;
  
  cl_int cl_err = 0;

  if (!cl_data)
    {
      const char *kernel_name[] = {"kernel_exposure", NULL};
      cl_data = gegl_cl_compile_and_build (kernel_source, kernel_name);
    }
  if (!cl_data) return 1;

  white = exp2f (exposure_negated);
  diff = MAX (white - black_level, 0.01);
  gain = 1.0f / diff;

  cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 0, sizeof(cl_mem),   (void*)&in_tex);
  cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 1, sizeof(cl_mem),   (void*)&out_tex);
  cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 2, sizeof(cl_float), (void*)&black_level);
  cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 3, sizeof(cl_float), (void*)&gain);
  if (cl_err != CL_SUCCESS) return cl_err;

  cl_err = gegl_clEnqueueNDRangeKernel(gegl_cl_get_command_queue (),
                                        cl_data->kernel[0], 1,
                                        NULL, &global_worksize, NULL,
                                        0, NULL, NULL);
  if (cl_err != CL_SUCCESS) return cl_err;

  return cl_err;
}
Exemplo n.º 22
0
float sinhf(float x)
{
  if (x >= -80 && x <= 80)
  {
    float e = expm1f(x);
    return (e + e / (e + 1)) * 0.5f;
  }
  else
  {
    // Special case for fabsf(x) > ~logf(FLT_MAX) to avoid
    // premature overflow of expf(x) to infinity
    int neg = x < 0;
    float e = neg ? -x : x;
    e = exp2f(e * 1.44269504f/*log2(e)*/ - 1);
    return neg ? -e : e;
  }
}
Exemplo n.º 23
0
ATF_TC_BODY(ldexpf_exp2f, tc)
{
	const float n[] = { 1, 2, 3, 10, 50, 100 };
	const float eps = 1.0e-9;
	const float x = 12.0;
	float y;
	size_t i;

	for (i = 0; i < __arraycount(n); i++) {

		y = ldexpf(x, n[i]);

		if (fabsf(y - (x * exp2f(n[i]))) > eps) {
			atf_tc_fail_nonfatal("ldexpf(%0.01f, %0.01f) "
			    "!= %0.01f * exp2f(%0.01f)", x, n[i], x, n[i]);
		}
	}
}
Exemplo n.º 24
0
void MyTriangle::calcTextCoords() {

	float base1 = sqrtf(exp2(x2 - x1) + exp2(y2 - y1) + exp2(z2 - z1));
	float hipot = sqrtf(exp2(x3 - x1) + exp2(y3 - y1) + exp2(z3 - z1));
	float teta = acos((x1 * x2 + y1 * y2 + z1 * z2) / (base1 * hipot));
	float base2 = hipot * cos(teta);
	float hight = sqrt(exp2(hipot) - exp2f(base2));
	float deltas1 = base1 / getAppearance()->getSWrap();
	float deltas2 = base2 / getAppearance()->getSWrap();
	float deltat = hight / getAppearance()->getTWrap();

	text_coords[0][0] = 0.0;
	text_coords[0][1] = 0.0;
	text_coords[1][0] = deltas1;
	text_coords[1][1] = 0.0;
	text_coords[2][0] = deltas2;
	text_coords[2][1] = deltat;
}
Exemplo n.º 25
0
int process_cl(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, cl_mem dev_out,
               const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out)
{
  const dt_iop_bloom_data_t *d = (dt_iop_bloom_data_t *)piece->data;
  const dt_iop_bloom_global_data_t *gd = (dt_iop_bloom_global_data_t *)self->data;

  cl_int err = -999;
  cl_mem dev_tmp[NUM_BUCKETS] = { NULL };
  cl_mem dev_tmp1;
  cl_mem dev_tmp2;
  unsigned int state = 0;

  const int devid = piece->pipe->devid;
  const int width = roi_in->width;
  const int height = roi_in->height;

  const float threshold = d->threshold;

  const int rad = 256.0f * (fmin(100.0f, d->size + 1.0f) / 100.0f);
  const float _r = ceilf(rad * roi_in->scale / piece->iscale);
  const int radius = MIN(256.0f, _r);
  const float scale = 1.0f / exp2f(-1.0f * (fmin(100.0f, d->strength + 1.0f) / 100.0f));

  size_t maxsizes[3] = { 0 };     // the maximum dimensions for a work group
  size_t workgroupsize = 0;       // the maximum number of items in a work group
  unsigned long localmemsize = 0; // the maximum amount of local memory we can use
  size_t kernelworkgroupsize = 0; // the maximum amount of items in work group for this kernel

  // make sure blocksize is not too large
  int blocksize = BLOCKSIZE;
  if(dt_opencl_get_work_group_limits(devid, maxsizes, &workgroupsize, &localmemsize) == CL_SUCCESS
     && dt_opencl_get_kernel_work_group_size(devid, gd->kernel_bloom_hblur, &kernelworkgroupsize)
        == CL_SUCCESS)
  {
    // reduce blocksize step by step until it fits to limits
    while(blocksize > maxsizes[0] || blocksize > maxsizes[1] || blocksize > kernelworkgroupsize
          || blocksize > workgroupsize || (blocksize + 2 * radius) * sizeof(float) > localmemsize)
    {
      if(blocksize == 1) break;
      blocksize >>= 1;
    }
  }
  else
  {
Exemplo n.º 26
0
extern "C" void test_math(DataStruct* data)
{
  float f = data->f;
  float fi = data->i;
  data->fa[0] = expf(f);
  data->fa[1] = logf(f);
  data->fa[2] = exp2f(f);
  data->fa[3] = log2f(f);
  data->fa[4] = sinf(f);
  data->fa[5] = cosf(f);
  data->fa[6] = sqrtf(f);
  data->fa[7] = tanf(f);
//  data->fa[8] = rsqrtf(f);
//  data->fa[9] = rcpf(f); // 1/x
  data->fa[10] = floorf(f);
  data->fa[11] = atanf(f);
  data->fa[12] = powf(f,fi);
//  data->fa[13] = powi(f,data->i);


}
Exemplo n.º 27
0
/* GeglOperationPointFilter gives us a linear buffer to operate on
 * in our requested pixel format
 */
static gboolean
process (GeglOperation       *op,
         void                *in_buf,
         void                *out_buf,
         glong                n_pixels,
         const GeglRectangle *roi,
         gint                 level)
{
  GeglProperties *o = GEGL_PROPERTIES (op);
  gfloat     *in_pixel;
  gfloat     *out_pixel;
  gfloat      black_level = (gfloat) o->black_level;
  gfloat      diff;
  gfloat      exposure_negated = (gfloat) -o->exposure;
  gfloat      gain;
  gfloat      white;
  
  glong       i;

  in_pixel = in_buf;
  out_pixel = out_buf;
  
  white = exp2f (exposure_negated);
  diff = MAX (white - black_level, 0.01);
  gain = 1.0f / diff;

  for (i=0; i<n_pixels; i++)
    {
      out_pixel[0] = (in_pixel[0] - black_level) * gain;
      out_pixel[1] = (in_pixel[1] - black_level) * gain;
      out_pixel[2] = (in_pixel[2] - black_level) * gain;
      out_pixel[3] = in_pixel[3];
      
      out_pixel += 4;
      in_pixel  += 4;
    }
    
  return TRUE;
}
Exemplo n.º 28
0
void process (struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, void *ivoid, void *ovoid, const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out)
{
  dt_iop_relight_data_t *data = (dt_iop_relight_data_t *)piece->data;
  const int ch = piece->colors;

  // Precalculate parameters for gauss function
  const float a = 1.0;                                                                // Height of top
  const float b = -1.0+(data->center*2);                                 // Center of top
  const float c = (data->width/10.0)/2.0;      				                    // Width

#ifdef _OPENMP
  #pragma omp parallel for default(none) shared(roi_out, ivoid, ovoid, data) schedule(static)
#endif
  for(int k=0; k<roi_out->height; k++)
  {
    float *in = ((float *)ivoid) + ch*k*roi_out->width;
    float *out = ((float *)ovoid) + ch*k*roi_out->width;
    for(int j=0; j<roi_out->width; j++,in+=ch,out+=ch)
    {
      const float lightness = in[0]/100.0;
      const float x = -1.0+(lightness*2.0);
      float gauss = GAUSS(a,b,c,x);

      if(isnan(gauss) || isinf(gauss))
        gauss = 0.0;

      float relight = 1.0 / exp2f ( -data->ev * CLIP(gauss));

      if(isnan(relight) || isinf(relight))
        relight = 1.0;

      out[0] = 100.0*CLIP (lightness*relight);
      out[1] = in[1];
      out[2] = in[2];
      out[3] = in[3];
    }
  }
}
Exemplo n.º 29
0
void
run_exp2_tests(void)
{
	int i;

	/*
	 * We should insist that exp2() return exactly the correct
	 * result and not raise an inexact exception for integer
	 * arguments.
	 */
	feclearexcept(FE_ALL_EXCEPT);
	for (i = FLT_MIN_EXP - FLT_MANT_DIG; i < FLT_MAX_EXP; i++) {
		assert(exp2f(i) == ldexpf(1.0, i));
		assert(fetestexcept(ALL_STD_EXCEPT) == 0);
	}
	for (i = DBL_MIN_EXP - DBL_MANT_DIG; i < DBL_MAX_EXP; i++) {
		assert(exp2(i) == ldexp(1.0, i));
		assert(fetestexcept(ALL_STD_EXCEPT) == 0);
	}
	for (i = LDBL_MIN_EXP - LDBL_MANT_DIG; i < LDBL_MAX_EXP; i++) {
		assert(exp2l(i) == ldexpl(1.0, i));
		assert(fetestexcept(ALL_STD_EXCEPT) == 0);
	}
}
		return "?";
	return QString::number(width) + "x" + QString::number(height);
}

class QTextEditSmall : public QTextEdit {

public:
	QTextEditSmall(QWidget *parent) : QTextEdit(parent) {}
	QTextEditSmall(const QString& text, QWidget *parent) : QTextEdit(text, parent) {}
	virtual QSize sizeHint() const override { return QSize(-1, 100); }

};

// sound notification sequences
static const std::array<SimpleSynth::Note, 1> SEQUENCE_RECORD_START = {{
	{0    , 500, 10000, 440.0f * exp2f( 3.0f / 12.0f), 0.8f}, // C5
}};
static const std::array<SimpleSynth::Note, 2> SEQUENCE_RECORD_STOP = {{
	{0    , 500, 20000, 440.0f * exp2f( 3.0f / 12.0f), 0.8f}, // C5
	{10000, 500, 20000, 440.0f * exp2f(-2.0f / 12.0f), 0.8f}, // G4
}};
static const std::array<SimpleSynth::Note, 4> SEQUENCE_RECORD_ERROR = {{
	{0    , 500, 20000, 440.0f * exp2f(-2.0f / 12.0f), 0.8f}, // G4
	{10000, 500, 20000, 440.0f * exp2f(-2.0f / 12.0f), 0.8f}, // G4
	{20000, 500, 20000, 440.0f * exp2f(-6.0f / 12.0f), 0.4f}, // D#4
	{20000, 500, 20000, 440.0f * exp2f(-9.0f / 12.0f), 0.6f}, // C4
}};

const int PageRecord::PRIORITY_RECORD = 0;
const int PageRecord::PRIORITY_PREVIEW = -1;