예제 #1
0
파일: exposure.c 프로젝트: cyr123/darktable
static int
compute_correction(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece,
                   const uint32_t *const histogram,
                   const dt_dev_histogram_stats_t *const histogram_stats,
                   float *correction)
{
  dt_iop_exposure_data_t *d = (dt_iop_exposure_data_t *)piece->data;

  if(histogram == NULL) return 1;

  *correction = NAN;

  uint32_t total = histogram_stats->ch*histogram_stats->pixels;

  float thr = (total * d->deflicker_percentile / 100.0f) - 2; // 50% => median; allow up to 2 stuck pixels
  uint32_t n = 0;
  uint32_t raw = 0;
  gboolean found = FALSE;

  for(uint32_t i=0; i < histogram_stats->bins_count; i++)
  {
    for(uint32_t k=0; k < histogram_stats->ch; k++)
      n += histogram[4*i+k];

    if (!found && (n >= thr))
    {
      raw = i;
      found = TRUE;
      break;
    }
  }

  if(found)
  {
    float ev = raw_to_ev(raw, self->dev->image_storage.raw_black_level + d->black, self->dev->image_storage.raw_white_point);
    *correction = d->deflicker_target_level - ev;

    return 0;
  }

  return 1;
}
예제 #2
0
static int compute_correction(dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece,
                              const uint32_t *const histogram,
                              const dt_dev_histogram_stats_t *const histogram_stats, float *correction)
{
  dt_iop_exposure_data_t *d = (dt_iop_exposure_data_t *)piece->data;

  *correction = NAN;

  if(histogram == NULL) return 1;

  const size_t total = (size_t)histogram_stats->ch * histogram_stats->pixels;

  const float thr = (float)total * d->deflicker_percentile / 100.0f;
  size_t n = 0;
  uint32_t raw = 0;
  gboolean found = FALSE;

  for(uint32_t i = 0; i < histogram_stats->bins_count; i++)
  {
    for(uint32_t k = 0; k < histogram_stats->ch; k++) n += histogram[4 * i + k];

    if(!found && (n >= thr))
    {
      raw = i;
      found = TRUE;
      break;
    }
  }

  if(found)
  {
    // FIXME: get those from rawprepare IOP somehow !!!
    const float ev
        = raw_to_ev(raw, self->dev->image_storage.raw_black_level, self->dev->image_storage.raw_white_point);
    *correction = d->deflicker_target_level - ev;

    return 0;
  }

  return 1;
}
예제 #3
0
파일: exposure.c 프로젝트: hean01/darktable
static int compute_correction(dt_iop_module_t *self, float *correction)
{
  dt_iop_exposure_params_t *p = (dt_iop_exposure_params_t *)self->params;

  if(self->histogram == NULL) return 1;

  float total = 0;
  for(int i=0; i < self->histogram_params.bins_count; i++)
  {
    total += self->histogram[4*i];
    total += self->histogram[4*i+1];
    total += self->histogram[4*i+2];
  }

  float thr = (total * p->deflicker_percentile / 100) - 2; // 50% => median; allow up to 2 stuck pixels
  float n = 0;
  float raw = -1;

  for(int i=0; i < self->histogram_params.bins_count; i++)
  {
    n += self->histogram[4*i];
    n += self->histogram[4*i+1];
    n += self->histogram[4*i+2];

    if (n >= thr)
    {
      raw = i;
      break;
    }
  }

  float ev = raw_to_ev(raw, self->dev->image_storage.raw_black_level + p->black, self->dev->image_storage.raw_white_point);

  *correction = p->deflicker_level - ev;

  return 0;
}