Esempio n. 1
0
void gui_update (struct dt_iop_module_t *self)
{
    dt_iop_module_t *module = (dt_iop_module_t *)self;
    self->request_color_pick = 0;
    self->color_picker_box[0] = self->color_picker_box[1] = .25f;
    self->color_picker_box[2] = self->color_picker_box[3] = .75f;
    self->color_picker_point[0] = self->color_picker_point[1] = 0.5f;
    dt_iop_temperature_gui_data_t *g = (dt_iop_temperature_gui_data_t *)self->gui_data;
    dt_iop_temperature_params_t *p  = (dt_iop_temperature_params_t *)module->params;
    dt_iop_temperature_params_t *fp = (dt_iop_temperature_params_t *)module->default_params;
    float temp, tint, mul[3];
    for(int k=0; k<3; k++) mul[k] = g->daylight_wb[k]/p->coeffs[k];
    convert_rgb_to_k(mul, &temp, &tint);

    dt_bauhaus_slider_set(g->scale_r, p->coeffs[0]);
    dt_bauhaus_slider_set(g->scale_g, p->coeffs[1]);
    dt_bauhaus_slider_set(g->scale_b, p->coeffs[2]);
    dt_bauhaus_slider_set(g->scale_k, temp);
    dt_bauhaus_slider_set(g->scale_tint, tint);

    dt_bauhaus_combobox_clear(g->presets);
    dt_bauhaus_combobox_add(g->presets, _("camera white balance"));
    dt_bauhaus_combobox_add(g->presets, _("spot white balance"));
    dt_bauhaus_combobox_add(g->presets, _("passthrough"));
    g->preset_cnt = 3;
    const char *wb_name = NULL;
    char makermodel[1024];
    char *model = makermodel;
    dt_colorspaces_get_makermodel_split(makermodel, 1024, &model, self->dev->image_storage.exif_maker, self->dev->image_storage.exif_model);
    if(!dt_image_is_ldr(&self->dev->image_storage)) for(int i=0; i<wb_preset_count; i++)
        {
            if(g->preset_cnt >= 50) break;
            if(!strcmp(wb_preset[i].make,  makermodel) &&
                    !strcmp(wb_preset[i].model, model))
            {
                if(!wb_name || strcmp(wb_name, wb_preset[i].name))
                {
                    wb_name = wb_preset[i].name;
                    dt_bauhaus_combobox_add(g->presets, _(wb_preset[i].name));
                    g->preset_num[g->preset_cnt++] = i;
                }
            }
        }

    if(fabsf(p->coeffs[0]-fp->coeffs[0]) + fabsf(p->coeffs[1]-fp->coeffs[1]) + fabsf(p->coeffs[2]-fp->coeffs[2]) < 0.01)
        dt_bauhaus_combobox_set(g->presets, 0);
    else
        dt_bauhaus_combobox_set(g->presets, -1);
    dt_bauhaus_slider_set(g->finetune, 0);
    gtk_widget_set_sensitive(g->finetune, 0);
}
Esempio n. 2
0
static void
apply_preset(dt_iop_module_t *self)
{
    self->request_color_pick = 0;
    if(self->dt->gui->reset) return;
    dt_iop_temperature_gui_data_t *g = (dt_iop_temperature_gui_data_t *)self->gui_data;
    dt_iop_temperature_params_t *p  = (dt_iop_temperature_params_t *)self->params;
    dt_iop_temperature_params_t *fp = (dt_iop_temperature_params_t *)self->default_params;
    const int tune = dt_bauhaus_slider_get(g->finetune);
    const int pos = dt_bauhaus_combobox_get(g->presets);
    switch(pos)
    {
    case -1: // just un-setting.
        return;
    case 0: // camera wb
        for(int k=0; k<3; k++) p->coeffs[k] = fp->coeffs[k];
        break;
    case 1: // spot wb, exposure callback will set p->coeffs.
        for(int k=0; k<3; k++) p->coeffs[k] = fp->coeffs[k];
        dt_iop_request_focus(self);
        self->request_color_pick = 1;

        /* set the area sample size*/
        if (self->request_color_pick)
            dt_lib_colorpicker_set_area(darktable.lib, 0.99);

        break;
    case 2: // passthrough mode, raw data
        for(int k=0; k<3; k++) p->coeffs[k] = 1.0;
        break;
    default:
        for(int i=g->preset_num[pos]; i<wb_preset_count; i++)
        {
            char makermodel[1024];
            char *model = makermodel;
            dt_colorspaces_get_makermodel_split(makermodel, 1024, &model, self->dev->image_storage.exif_maker, self->dev->image_storage.exif_model);
            if(!strcmp(wb_preset[i].make,  makermodel) &&
                    !strcmp(wb_preset[i].model, model) && wb_preset[i].tuning == tune)
            {
                for(int k=0; k<3; k++) p->coeffs[k] = wb_preset[i].channel[k];
                break;
            }
        }
        break;
    }
    if(self->off) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(self->off), 1);
    gui_update_from_coeffs(self);
    dt_dev_add_history_item(darktable.develop, self, TRUE);
}
Esempio n. 3
0
void reload_defaults(dt_iop_module_t *module)
{
    // raw images need wb (to convert from uint16_t to float):
    if(dt_image_is_raw(&module->dev->image_storage))
    {
        module->default_enabled = 1;
        module->hide_enable_button = 1;
    }
    else module->default_enabled = 0;
    dt_iop_temperature_params_t tmp = (dt_iop_temperature_params_t)
    {
        5000.0, {1.0, 1.0, 1.0}
    };

    // get white balance coefficients, as shot
    char filename[DT_MAX_PATH_LEN];
    int ret=0;
    /* check if file is raw / hdr */
    if(dt_image_is_raw(&module->dev->image_storage))
    {
        gboolean from_cache = TRUE;
        dt_image_full_path(module->dev->image_storage.id, filename, DT_MAX_PATH_LEN, &from_cache);
        libraw_data_t *raw = libraw_init(0);

        ret = libraw_open_file(raw, filename);
        if(!ret)
        {
            module->default_enabled = 1;

            for(int k=0; k<3; k++) tmp.coeffs[k] = raw->color.cam_mul[k];
            if(tmp.coeffs[0] <= 0.0)
            {
                for(int k=0; k<3; k++) tmp.coeffs[k] = raw->color.pre_mul[k];
            }
            if(tmp.coeffs[0] == 0 || tmp.coeffs[1] == 0 || tmp.coeffs[2] == 0)
            {
                // could not get useful info, try presets:
                char makermodel[1024];
                char *model = makermodel;
                dt_colorspaces_get_makermodel_split(makermodel, 1024, &model,
                                                    module->dev->image_storage.exif_maker,
                                                    module->dev->image_storage.exif_model);
                for(int i=0; i<wb_preset_count; i++)
                {
                    if(!strcmp(wb_preset[i].make,  makermodel) &&
                            !strcmp(wb_preset[i].model, model))
                    {
                        // just take the first preset we find for this camera
                        for(int k=0; k<3; k++) tmp.coeffs[k] = wb_preset[i].channel[k];
                        break;
                    }
                }
                if(tmp.coeffs[0] == 0 || tmp.coeffs[1] == 0 || tmp.coeffs[2] == 0)
                {
                    // final security net: hardcoded default that fits most cams.
                    tmp.coeffs[0] = 2.0f;
                    tmp.coeffs[1] = 1.0f;
                    tmp.coeffs[2] = 1.5f;
                }
            }
            else
            {
                tmp.coeffs[0] /= tmp.coeffs[1];
                tmp.coeffs[2] /= tmp.coeffs[1];
                tmp.coeffs[1] = 1.0f;
            }
            // remember daylight wb used for temperature/tint conversion,
            // assuming it corresponds to CIE daylight (D65)
            if(module->gui_data)
            {
                dt_iop_temperature_gui_data_t *g = (dt_iop_temperature_gui_data_t *)module->gui_data;
                for(int c = 0; c < 3; c++)
                    g->daylight_wb[c] = raw->color.pre_mul[c];

                if(g->daylight_wb[0] == 1.0f &&
                        g->daylight_wb[1] == 1.0f &&
                        g->daylight_wb[2] == 1.0f)
                {
                    // if we didn't find anything for daylight wb, look for a wb preset with appropriate name.
                    // we're normalising that to be D65
                    char makermodel[1024];
                    char *model = makermodel;
                    dt_colorspaces_get_makermodel_split(makermodel, 1024, &model,
                                                        module->dev->image_storage.exif_maker,
                                                        module->dev->image_storage.exif_model);
                    for(int i=0; i<wb_preset_count; i++)
                    {
                        if(!strcmp(wb_preset[i].make,  makermodel) &&
                                !strcmp(wb_preset[i].model, model) &&
                                !strncasecmp(wb_preset[i].name, "daylight", 8))
                        {
                            for(int k=0; k<3; k++)
                                g->daylight_wb[k] = wb_preset[i].channel[k];
                            break;
                        }
                    }
                }
                float temp, tint, mul[3];
                for(int k=0; k<3; k++) mul[k] = g->daylight_wb[k]/tmp.coeffs[k];
                convert_rgb_to_k(mul, &temp, &tint);
                dt_bauhaus_slider_set_default(g->scale_k,    temp);
                dt_bauhaus_slider_set_default(g->scale_tint, tint);
            }

        }
        libraw_close(raw);
    }

    memcpy(module->params, &tmp, sizeof(dt_iop_temperature_params_t));
    memcpy(module->default_params, &tmp, sizeof(dt_iop_temperature_params_t));
}
Esempio n. 4
0
void gui_init (struct dt_iop_module_t *self)
{
  self->gui_data = malloc(sizeof(dt_iop_temperature_gui_data_t));
  dt_iop_temperature_gui_data_t *g = (dt_iop_temperature_gui_data_t *)self->gui_data;
  dt_iop_temperature_params_t *p = (dt_iop_temperature_params_t*)self->default_params;

  self->request_color_pick = 0;
  self->widget = gtk_vbox_new(TRUE, DT_BAUHAUS_SPACE);
  g_signal_connect(G_OBJECT(self->widget), "expose-event", G_CALLBACK(expose), self);

  g->scale_tint  = dt_bauhaus_slider_new_with_range(self,0.1, 8.0, .01,1.0,3);
  g->scale_k     = dt_bauhaus_slider_new_with_range(self,DT_IOP_LOWEST_TEMPERATURE, DT_IOP_HIGHEST_TEMPERATURE, 10.,5000.0,0);
  g->scale_k_out = dt_bauhaus_slider_new_with_range(self,DT_IOP_LOWEST_TEMPERATURE, DT_IOP_HIGHEST_TEMPERATURE, 10.,5000.0,0);
  g->scale_r     = dt_bauhaus_slider_new_with_range(self,0.0, 8.0, .001,p->coeffs[0],3);
  g->scale_g     = dt_bauhaus_slider_new_with_range(self,0.0, 8.0, .001,p->coeffs[1],3);
  g->scale_b     = dt_bauhaus_slider_new_with_range(self,0.0, 8.0, .001,p->coeffs[2],3);
  dt_bauhaus_slider_set_format(g->scale_k,"%.0fK");
  dt_bauhaus_slider_set_format(g->scale_k_out,"%.0fK");
  dt_bauhaus_widget_set_label(g->scale_tint,_("tint"));
  dt_bauhaus_widget_set_label(g->scale_k,_("temperature in"));
  dt_bauhaus_widget_set_label(g->scale_k_out,_("temperature out"));
  dt_bauhaus_widget_set_label(g->scale_r,_("red"));
  dt_bauhaus_widget_set_label(g->scale_g,_("green"));
  dt_bauhaus_widget_set_label(g->scale_b,_("blue"));

  gtk_box_pack_start(GTK_BOX(self->widget), g->scale_tint, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(self->widget), g->scale_k, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(self->widget), g->scale_k_out, TRUE, TRUE, 0);

  gtk_box_pack_start(GTK_BOX(self->widget), g->scale_r, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(self->widget), g->scale_g, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(self->widget), g->scale_b, TRUE, TRUE, 0);

  g->presets = dt_bauhaus_combobox_new(self);
  dt_bauhaus_widget_set_label(g->presets,_("preset"));
  dt_bauhaus_combobox_add(g->presets, _("camera white balance"));
  dt_bauhaus_combobox_add(g->presets, _("spot white balance"));
  dt_bauhaus_combobox_add(g->presets, _("passthrough"));
  g->preset_cnt = 3;
  const char *wb_name = NULL;
  char makermodel[1024];
  char *model = makermodel;
  dt_colorspaces_get_makermodel_split(makermodel, 1024, &model, self->dev->image_storage.exif_maker, self->dev->image_storage.exif_model);
  if(!dt_image_is_ldr(&self->dev->image_storage)) for(int i=0; i<wb_preset_count; i++)
    {
      if(g->preset_cnt >= 50) break;
      if(!strcmp(wb_preset[i].make,  makermodel) &&
          !strcmp(wb_preset[i].model, model))
      {
        if(!wb_name || strcmp(wb_name, wb_preset[i].name))
        {
          wb_name = wb_preset[i].name;
          dt_bauhaus_combobox_add(g->presets, _(wb_preset[i].name));
          g->preset_num[g->preset_cnt++] = i;
        }
      }
    }
  gtk_box_pack_start(GTK_BOX(self->widget), g->presets, TRUE, TRUE, 0);
  g_object_set(G_OBJECT(g->presets), "tooltip-text", _("choose white balance preset from camera"), (char *)NULL);

  g->finetune = dt_bauhaus_slider_new_with_range(self,-9.0, 9.0, 1.0, 0.0, 0);
  dt_bauhaus_widget_set_label(g->finetune, _("finetune"));
  dt_bauhaus_slider_set_format(g->finetune, _("%.0f mired"));
  // initially doesn't have fine tuning stuff (camera wb)
  gtk_widget_set_sensitive(g->finetune, FALSE);
  gtk_box_pack_start(GTK_BOX(self->widget), g->finetune, TRUE, TRUE, 0);
  g_object_set(G_OBJECT(g->finetune), "tooltip-text", _("fine tune white balance preset"), (char *)NULL);

  self->gui_update(self);

  g_signal_connect (G_OBJECT (g->scale_tint), "value-changed",
                    G_CALLBACK (tint_callback), self);
  g_signal_connect (G_OBJECT (g->scale_k), "value-changed",
                    G_CALLBACK (temp_callback), self);
  g_signal_connect (G_OBJECT (g->scale_k_out), "value-changed",
                    G_CALLBACK (temp_out_callback), self);
  g_signal_connect (G_OBJECT (g->scale_r), "value-changed",
                    G_CALLBACK (rgb_callback), self);
  g_signal_connect (G_OBJECT (g->scale_g), "value-changed",
                    G_CALLBACK (rgb_callback), self);
  g_signal_connect (G_OBJECT (g->scale_b), "value-changed",
                    G_CALLBACK (rgb_callback), self);
  g_signal_connect (G_OBJECT (g->presets), "value-changed",
                    G_CALLBACK (presets_changed), self);
  g_signal_connect (G_OBJECT (g->finetune), "value-changed",
                    G_CALLBACK (finetune_changed), self);
}
Esempio n. 5
0
void reload_defaults(dt_iop_module_t *module)
{
  // raw images need wb (to convert from uint16_t to float):
  if(dt_image_is_raw(&module->dev->image_storage))
  {
    module->default_enabled = 1;
    module->hide_enable_button = 1;
  }
  else module->default_enabled = 0;
  dt_iop_temperature_params_t tmp = (dt_iop_temperature_params_t)
  {
    5000.0, {1.0, 1.0, 1.0}
  };

  // get white balance coefficients, as shot
  char filename[DT_MAX_PATH_LEN];
  int ret=0;
  /* check if file is raw / hdr */
  if(dt_image_is_raw(&module->dev->image_storage))
  {
    dt_image_full_path(module->dev->image_storage.id, filename, DT_MAX_PATH_LEN);
    libraw_data_t *raw = libraw_init(0);

    ret = libraw_open_file(raw, filename);
    if(!ret)
    {
      module->default_enabled = 1;
      for(int k=0; k<3; k++) tmp.coeffs[k] = raw->color.cam_mul[k];
      if(tmp.coeffs[0] <= 0.0)
      {
        for(int k=0; k<3; k++) tmp.coeffs[k] = raw->color.pre_mul[k];
      }
      if(tmp.coeffs[0] == 0 || tmp.coeffs[1] == 0 || tmp.coeffs[2] == 0)
      {
        // could not get useful info, try presets:
        char makermodel[1024];
        char *model = makermodel;
        dt_colorspaces_get_makermodel_split(makermodel, 1024, &model,
                                            module->dev->image_storage.exif_maker,
                                            module->dev->image_storage.exif_model);
        for(int i=0; i<wb_preset_count; i++)
        {
          if(!strcmp(wb_preset[i].make,  makermodel) &&
              !strcmp(wb_preset[i].model, model))
          {
            // just take the first preset we find for this camera
            for(int k=0; k<3; k++) tmp.coeffs[k] = wb_preset[i].channel[k];
            break;
          }
        }
        if(tmp.coeffs[0] == 0 || tmp.coeffs[1] == 0 || tmp.coeffs[2] == 0)
        {
          // final security net: hardcoded default that fits most cams.
          tmp.coeffs[0] = 2.0f;
          tmp.coeffs[1] = 1.0f;
          tmp.coeffs[2] = 1.5f;
        }
      }
      else
      {
        tmp.coeffs[0] /= tmp.coeffs[1];
        tmp.coeffs[2] /= tmp.coeffs[1];
        tmp.coeffs[1] = 1.0f;
      }
    }
    libraw_close(raw);
  }

  memcpy(module->params, &tmp, sizeof(dt_iop_temperature_params_t));
  memcpy(module->default_params, &tmp, sizeof(dt_iop_temperature_params_t));
}
Esempio n. 6
0
void gui_update(struct dt_iop_module_t *self)
{
  dt_iop_module_t *module = (dt_iop_module_t *)self;
  self->request_color_pick = DT_REQUEST_COLORPICK_OFF;
  self->color_picker_box[0] = self->color_picker_box[1] = .25f;
  self->color_picker_box[2] = self->color_picker_box[3] = .75f;
  self->color_picker_point[0] = self->color_picker_point[1] = 0.5f;
  dt_iop_temperature_gui_data_t *g = (dt_iop_temperature_gui_data_t *)self->gui_data;
  dt_iop_temperature_params_t *p = (dt_iop_temperature_params_t *)module->params;
  dt_iop_temperature_params_t *fp = (dt_iop_temperature_params_t *)module->default_params;
  float temp, tint, mul[3];
  for(int k = 0; k < 3; k++) mul[k] = g->daylight_wb[k] / p->coeffs[k];
  convert_rgb_to_k(mul, &temp, &tint);

  dt_bauhaus_slider_set(g->scale_r, p->coeffs[0]);
  dt_bauhaus_slider_set(g->scale_g, p->coeffs[1]);
  dt_bauhaus_slider_set(g->scale_b, p->coeffs[2]);
  dt_bauhaus_slider_set(g->scale_k, temp);
  dt_bauhaus_slider_set(g->scale_tint, tint);

  dt_bauhaus_combobox_clear(g->presets);
  dt_bauhaus_combobox_add(g->presets, _("camera white balance"));
  dt_bauhaus_combobox_add(g->presets, _("spot white balance"));
  g->preset_cnt = DT_IOP_NUM_OF_STD_TEMP_PRESETS;

  dt_bauhaus_combobox_set(g->presets, -1);
  dt_bauhaus_slider_set(g->finetune, 0);
  gtk_widget_set_sensitive(g->finetune, 0);

  const char *wb_name = NULL;
  char makermodel[1024];
  char *model = makermodel;
  dt_colorspaces_get_makermodel_split(makermodel, sizeof(makermodel), &model,
                                      self->dev->image_storage.exif_maker,
                                      self->dev->image_storage.exif_model);
  if(!dt_image_is_ldr(&self->dev->image_storage))
    for(int i = 0; i < wb_preset_count; i++)
    {
      if(g->preset_cnt >= 50) break;
      if(!strcmp(wb_preset[i].make, makermodel) && !strcmp(wb_preset[i].model, model))
      {
        if(!wb_name || strcmp(wb_name, wb_preset[i].name))
        {
          wb_name = wb_preset[i].name;
          dt_bauhaus_combobox_add(g->presets, _(wb_preset[i].name));
          g->preset_num[g->preset_cnt++] = i;
        }
      }
    }

  if(memcmp(p->coeffs, fp->coeffs, 3 * sizeof(float)) == 0)
    dt_bauhaus_combobox_set(g->presets, 0);
  else
  {
    gboolean found = FALSE;
    // look through all added presets
    for(int j = DT_IOP_NUM_OF_STD_TEMP_PRESETS; !found && (j < g->preset_cnt); j++)
    {
      // look through all variants of this preset, with different tuning
      for(int i = g->preset_num[j];
          !found && !strcmp(wb_preset[i].make, makermodel) && !strcmp(wb_preset[i].model, model)
              && !strcmp(wb_preset[i].name, wb_preset[g->preset_num[j]].name);
          i++)
      {
        float coeffs[3];
        for(int k = 0; k < 3; k++) coeffs[k] = wb_preset[i].channel[k];

        if(memcmp(coeffs, p->coeffs, 3 * sizeof(float)) == 0)
        {
          // got exact match!
          dt_bauhaus_combobox_set(g->presets, j);
          gtk_widget_set_sensitive(g->finetune, 1);
          dt_bauhaus_slider_set(g->finetune, wb_preset[i].tuning);
          found = TRUE;
          break;
        }
      }
    }

    if(!found)
    {
      // ok, we haven't found exact match, maybe this was interpolated?

      // look through all added presets
      for(int j = DT_IOP_NUM_OF_STD_TEMP_PRESETS; !found && (j < g->preset_cnt); j++)
      {
        // look through all variants of this preset, with different tuning
        int i = g->preset_num[j] + 1;
        while(!found && !strcmp(wb_preset[i].make, makermodel) && !strcmp(wb_preset[i].model, model)
              && !strcmp(wb_preset[i].name, wb_preset[g->preset_num[j]].name))
        {
          // let's find gaps
          if(wb_preset[i - 1].tuning + 1 == wb_preset[i].tuning)
          {
            i++;
            continue;
          }

          // we have a gap!

          // we do not know what finetuning value was set, we need to bruteforce to find it
          for(int tune = wb_preset[i - 1].tuning + 1; !found && (tune < wb_preset[i].tuning); tune++)
          {
            wb_data interpolated = {.tuning = tune };
            dt_wb_preset_interpolate(&wb_preset[i - 1], &wb_preset[i], &interpolated);

            float coeffs[3];
            for(int k = 0; k < 3; k++) coeffs[k] = interpolated.channel[k];

            if(memcmp(coeffs, p->coeffs, 3 * sizeof(float)) == 0)
            {
              // got exact match!

              dt_bauhaus_combobox_set(g->presets, j);
              gtk_widget_set_sensitive(g->finetune, 1);
              dt_bauhaus_slider_set(g->finetune, tune);
              found = TRUE;
              break;
            }
          }
          i++;
        }
      }
    }
  }
}