Update of /cvsroot/ufraw/ufraw
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv28712

Modified Files:
        ufraw-batch.c ufraw.h ufraw_conf.c ufraw_lens_ui.c 
        ufraw_ufraw.c 
Log Message:
Added a --lensfun=auto|none option. Based on patch by Konrad.
The default is --lensfun=none also in interactive mode which used
to behave like --lensfun=auto.

Fixed a small bug in the --grayscale option.


Index: ufraw_lens_ui.c
===================================================================
RCS file: /cvsroot/ufraw/ufraw/ufraw_lens_ui.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- ufraw_lens_ui.c     28 Oct 2009 04:44:05 -0000      1.15
+++ ufraw_lens_ui.c     3 Nov 2009 06:41:31 -0000       1.16
@@ -146,54 +146,45 @@
     return cbe;
 }
 
-static void camera_set (preview_data *data, const lfCamera *cam)
+static void camera_set(preview_data *data)
 {
-    gchar *fm;
-    const char *maker, *model, *variant;
-    char _variant [100];
-
-    lf_camera_copy (CFG->camera, cam);
-    if (!cam)
-    {
-        gtk_entry_set_text(GTK_ENTRY(data->CameraModel), "");
-        uf_widget_set_tooltip(data->CameraModel, NULL);
-        return;
-    }
-
-    maker = lf_mlstr_get (cam->Maker);
-    model = lf_mlstr_get (cam->Model);
-    variant = lf_mlstr_get (cam->Variant);
+    const char *maker = lf_mlstr_get(CFG->camera->Maker);
+    const char *model = lf_mlstr_get(CFG->camera->Model);
+    const char *variant = lf_mlstr_get(CFG->camera->Variant);
 
-    if (model)
+    if (model != NULL)
     {
-        if (maker)
-            fm = g_strdup_printf ("%s, %s", maker, model);
-        else
-            fm = g_strdup_printf ("%s", model);
-        gtk_entry_set_text (GTK_ENTRY (data->CameraModel), fm);
-        g_free (fm);
+       gchar *fm;
+       if (maker != NULL)
+           fm = g_strdup_printf("%s, %s", maker, model);
+       else
+           fm = g_strdup_printf("%s", model);
+       gtk_entry_set_text(GTK_ENTRY(data->CameraModel), fm);
+       g_free (fm);
     }
-
-    if (variant)
-        snprintf (_variant, sizeof (_variant), " (%s)", variant);
+    char _variant[100];
+    if (variant != NULL)
+       snprintf(_variant, sizeof(_variant), " (%s)", variant);
     else
-        _variant [0] = 0;
+       _variant[0] = 0;
 
-    fm = g_strdup_printf (_("Maker:\t\t%s\n"
-                            "Model:\t\t%s%s\n"
-                            "Mount:\t\t%s\n"
-                            "Crop factor:\t%.1f"),
-                          maker, model, _variant,
-                          cam->Mount, cam->CropFactor);
+    gchar *fm = g_strdup_printf(_("Maker:\t\t%s\n"
+                       "Model:\t\t%s%s\n"
+                       "Mount:\t\t%s\n"
+                       "Crop factor:\t%.1f"),
+                       maker, model, _variant,
+                       CFG->camera->Mount, CFG->camera->CropFactor);
     uf_widget_set_tooltip(data->CameraModel, fm);
-    g_free (fm);
+    g_free(fm);
 }
 
 static void camera_menu_select (
     GtkMenuItem *menuitem, gpointer user_data)
 {
     preview_data *data = (preview_data *)user_data;
-    camera_set (data, (lfCamera *)g_object_get_data(G_OBJECT(menuitem), 
"lfCamera"));
+    lfCamera *cam = g_object_get_data(G_OBJECT(menuitem), "lfCamera");
+    lf_camera_copy(CFG->camera, cam);
+    camera_set(data);
 }
 
 static void camera_menu_fill (
@@ -1243,36 +1234,23 @@
         subnb, _("Lens geometry"), "geometry");
 
     /* Create a default lens & camera */
-    CFG->lens = lf_lens_new ();
-    CFG->camera = lf_camera_new ();
-    CFG->cur_lens_type = LF_UNKNOWN;
-
-    /* Set lens and camera from EXIF info, if possible */
-    if (CFG->real_make [0] || CFG->real_model [0])
-    {
-        const lfCamera **cams = lf_db_find_cameras (
-            CFG->lensdb, CFG->real_make, CFG->real_model);
-        if (cams)
-        {
-            camera_set (data, cams [0]);
-            lf_free (cams);
-        }
-    }
+    ufraw_lensfun_init(data->UF);
+    camera_set(data);
+    lens_set(data, CFG->lens);
 
     fill_tca_page (data);
     fill_vignetting_page (data);
     fill_distortion_page (data);
     fill_geometry_page (data);
 
-    const lfLens **lenses = NULL;
-    if (strlen(CFG->lensText) > 0)
-       lenses = lf_db_find_lenses_hd(CFG->lensdb,
-               CFG->camera, NULL, CFG->lensText, 0);
-    if (lenses!=NULL) {
-       lf_lens_copy(CFG->lens, lenses[0]);
-       lf_free(lenses);
+    if (CFG->lensfunMode == lensfun_none) {
+       gtk_combo_box_set_active(GTK_COMBO_BOX(data->LensDistortionModel),
+               LF_DIST_MODEL_NONE);
+       gtk_combo_box_set_active(GTK_COMBO_BOX(data->LensTCAModel),
+               LF_TCA_MODEL_NONE);
+       gtk_combo_box_set_active(GTK_COMBO_BOX(data->LensVignettingModel),
+               LF_VIGNETTING_MODEL_NONE);
     }
-    lens_set(data, CFG->lens);
 }
 
 #endif /* HAVE_LENSFUN */

Index: ufraw-batch.c
===================================================================
RCS file: /cvsroot/ufraw/ufraw/ufraw-batch.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- ufraw-batch.c       6 Oct 2009 02:30:24 -0000       1.28
+++ ufraw-batch.c       3 Nov 2009 06:41:31 -0000       1.29
@@ -106,6 +106,10 @@
        else
            stat[0] = '\0';
        ufraw_message(UFRAW_MESSAGE, _("Loaded %s %s"), uf->filename, stat);
+#ifdef HAVE_LENSFUN
+        if (uf->conf->lensfunMode == lensfun_auto)
+           ufraw_lensfun_init(uf);
+#endif
        status = ufraw_batch_saver(uf);
        if (status==UFRAW_SUCCESS || status==UFRAW_WARNING) {
            if (uf->conf->createID!=only_id)
@@ -156,6 +160,7 @@
        status = ufraw_write_embedded(uf);
        return status;
     } else {
+
        int status = ufraw_write_image(uf);
        if ( status!=UFRAW_SUCCESS )
            ufraw_message(status, ufraw_get_message(uf));

Index: ufraw.h
===================================================================
RCS file: /cvsroot/ufraw/ufraw/ufraw.h,v
retrieving revision 1.128
retrieving revision 1.129
diff -u -d -r1.128 -r1.129
--- ufraw.h     31 Oct 2009 01:59:19 -0000      1.128
+++ ufraw.h     3 Nov 2009 06:41:31 -0000       1.129
@@ -74,6 +74,7 @@
         ufraw_lensfun_phase, ufraw_display_phase, ufraw_phases_num } 
UFRawPhase;
 typedef enum { grayscale_none, grayscale_lightness, grayscale_luminance,
        grayscale_value, grayscale_mixer } GrayscaleMode;
+typedef enum { lensfun_none, lensfun_auto } LensfunMode;
 
 typedef struct {
     const char *make;
@@ -235,6 +236,7 @@
     lfLensCalibVignetting lens_vignetting; /* lens vignetting parameters */
     lfLensType cur_lens_type;
     float lens_scale; /* Additional lens postprocessing scale power-of-two, 
default 0 */
+    int lensfunMode;
 #endif /* HAVE_LENSFUN */
 } conf_data;
 
@@ -309,6 +311,7 @@
 void ufraw_convert_image_first(ufraw_data *uf, UFRawPhase phase);
 #ifdef HAVE_LENSFUN
 int ufraw_prepare_lensfun(ufraw_data *uf);
+void ufraw_lensfun_init(ufraw_data *uf);
 #endif
 void ufraw_image_format(int *colors, int *bytes, ufraw_image_data *img,
        const char *formats, const char *caller);

Index: ufraw_conf.c
===================================================================
RCS file: /cvsroot/ufraw/ufraw/ufraw_conf.c,v
retrieving revision 1.149
retrieving revision 1.150
diff -u -d -r1.149 -r1.150
--- ufraw_conf.c        21 Oct 2009 14:00:20 -0000      1.149
+++ ufraw_conf.c        3 Nov 2009 06:41:31 -0000       1.150
@@ -142,6 +142,7 @@
     { LF_VIGNETTING_MODEL_NONE, 0, 0, 0, { 0, 0, 0 } },
     LF_UNKNOWN,                   /* lens type */
     0,                            /* lens postprocessing scale power-of-two */ 
+    lensfun_none,                 /* do not apply any lensfun corrections */
 #endif /* HAVE_LENSFUN */
 };
 
@@ -155,25 +156,12 @@
     { "perceptual", "relative", "saturation", "absolute", "disable", NULL };
 static const char *grayscaleModeNames[] =
     { "none", "lightness", "luminance", "value", "mixer", NULL };
+static const char *lensfunModeNames[] =
+    { "none", "auto", NULL };
 
-void conf_init (conf_data *c)
+void conf_init(conf_data *c)
 {
-#ifdef HAVE_LENSFUN
-    static lfDatabase *lensdb = NULL;
-
-    if (!lensdb)
-    {
-       /* Load lens database */
-       lensdb = lf_db_new ();
-       lf_db_load (lensdb);
-    }
-#endif /* HAVE_LENSFUN */
-
     *c = conf_default;
-
-#ifdef HAVE_LENSFUN
-    c->lensdb = lensdb;
-#endif /* HAVE_LENSFUN */
 }
 
 static int conf_find_name(const char name[],const char *namesList[], int 
notFound)
@@ -725,7 +713,7 @@
     GError *err = NULL;
     int i;
 
-    conf_init (c);
+    conf_init(c);
     if (IDFilename==NULL) {
        hd = uf_get_home_dir();
        confFilename = g_build_filename(hd, ".ufrawrc", NULL);
@@ -1311,6 +1299,7 @@
     dst->intent[display_profile] = src->intent[display_profile];
 
 #ifdef HAVE_LENSFUN
+    dst->lensfunMode = src->lensfunMode;
     dst->lensdb = src->lensdb;
     if (src->camera)
     {
@@ -1381,6 +1370,9 @@
     if (cmd->CropX2 !=-1) conf->CropX2 = cmd->CropX2;
     if (cmd->CropY2 !=-1) conf->CropY2 = cmd->CropY2;
     if (cmd->silent!=-1) conf->silent = cmd->silent;
+#ifdef HAVE_LENSFUN
+    if (cmd->lensfunMode!=-1) conf->lensfunMode = cmd->lensfunMode;
+#endif
     if (cmd->compression!=NULLF) conf->compression = cmd->compression;
     if (cmd->autoExposure) {
        conf->autoExposure = cmd->autoExposure;
@@ -1408,7 +1400,7 @@
                cmd->profile[1][0].BitDepth;
     if (cmd->saturation!=NULLF)
        conf->saturation=cmd->saturation;
-    if (cmd->grayscaleMode!=NULLF)
+    if (cmd->grayscaleMode!=-1)
       conf->grayscaleMode=cmd->grayscaleMode;
     if (cmd->BaseCurveIndex>=0) conf->BaseCurveIndex = cmd->BaseCurveIndex;
     if (cmd->curveIndex>=0) conf->curveIndex = cmd->curveIndex;
@@ -1545,6 +1537,10 @@
 N_("--crop-(left|right|top|bottom)=PIXELS\n"
 "                      Crop the output to the given pixel range, relative to 
the\n"
 "                      raw image after rotation but before any scaling.\n"),
+#ifdef HAVE_LENSFUN
+N_("--lensfun=none|auto          Do not apply lens correction or try to 
apply\n"
+"                      correction by auto-detecting the lens (default 
none).\n"),
+#endif
 N_("--out-path=PATH       PATH for output file (default use input file's 
path).\n"),
 N_("--output=FILE         Output file name, use '-' to output to stdout.\n"),
 N_("--darkframe=FILE      Use FILE for raw darkframe subtraction.\n"),
@@ -1616,7 +1612,8 @@
         *curveName=NULL, *curveFile=NULL, *outTypeName=NULL, *rotateName=NULL,
         *createIDName=NULL, *outPath=NULL, *output=NULL, *conf=NULL,
         *interpolationName=NULL, *darkframeFile=NULL,
-        *restoreName=NULL, *clipName=NULL, *grayscaleName=NULL;
+        *restoreName=NULL, *clipName=NULL, *grayscaleName=NULL,
+        *lensfunName = NULL;
     static const struct option options[] = {
        { "wb", 1, 0, 'w'},
        { "temperature", 1, 0, 't'},
@@ -1652,6 +1649,9 @@
        { "crop-top", 1, 0, '2'},
        { "crop-right", 1, 0, '3'},
        { "crop-bottom", 1, 0, '4'},
+#ifdef HAVE_LENSFUN
+        { "lensfun", 1, 0, 'A'},
+#endif
 /* Binary flags that don't have a value are here at the end */
        { "zip", 0, 0, 'z'},
        { "nozip", 0, 0, 'Z'},
@@ -1679,7 +1679,7 @@
        &outTypeName, &cmd->profile[1][0].BitDepth, &rotateName,
        &createIDName, &outPath, &output, &darkframeFile,
        &restoreName, &clipName, &conf,
-       &cmd->CropX1, &cmd->CropY1, &cmd->CropX2, &cmd->CropY2 };
+       &cmd->CropX1, &cmd->CropY1, &cmd->CropX2, &cmd->CropY2, &lensfunName };
     cmd->autoExposure = disabled_state;
     cmd->autoBlack = disabled_state;
     cmd->losslessCompress=-1;
@@ -1770,6 +1770,7 @@
        case 'r':
        case 'u':
        case 'Y':
+       case 'A':
            *(char **)optPointer[index] = optarg;
            break;
        case 'O': cmd->overwrite = TRUE; break;
@@ -1932,7 +1933,7 @@
        else
            cmd->smoothing = 1;
     }
-    cmd->grayscaleMode = NULLF;
+    cmd->grayscaleMode = -1;
     if (grayscaleName!=NULL) {
       cmd->grayscaleMode = conf_find_name(grayscaleName, grayscaleModeNames,
                                          conf_default.grayscaleMode);
@@ -2138,6 +2139,18 @@
            return -1;
        }
     }
+#ifdef HAVE_LENSFUN
+    cmd->lensfunMode = -1;
+    if (lensfunName!=NULL) {
+      cmd->lensfunMode = conf_find_name(lensfunName, lensfunModeNames, -1);
+      if (cmd->lensfunMode==-1) {
+           ufraw_message(UFRAW_ERROR,
+               _("'%s' is not a valid lensfun option."),
+               lensfunName);
+           return -1;
+       }
+    }
+#endif
     cmd->createID = -1;
     if (createIDName!=NULL) {
        if (!strcmp(createIDName, "no"))

Index: ufraw_ufraw.c
===================================================================
RCS file: /cvsroot/ufraw/ufraw/ufraw_ufraw.c,v
retrieving revision 1.204
retrieving revision 1.205
diff -u -d -r1.204 -r1.205
--- ufraw_ufraw.c       31 Oct 2009 05:18:37 -0000      1.204
+++ ufraw_ufraw.c       3 Nov 2009 06:41:31 -0000       1.205
@@ -1145,6 +1145,42 @@
 #endif /* HAVE_LENSFUN */
 }
 
+#ifdef HAVE_LENSFUN
+void ufraw_lensfun_init(ufraw_data *uf)
+{
+    /* Load lens database only once */
+    static lfDatabase *lensdb = NULL;
+    if (lensdb == NULL) {
+       lensdb = lf_db_new();
+       lf_db_load(lensdb);
+    }
+    uf->conf->lensdb = lensdb;
+
+    /* Create a default lens & camera */
+    uf->conf->lens = lf_lens_new();
+    uf->conf->camera = lf_camera_new();
+    uf->conf->cur_lens_type = LF_UNKNOWN;
+
+    /* Set lens and camera from EXIF info, if possible */
+    if (uf->conf->real_make[0] || uf->conf->real_model[0]) {
+       const lfCamera **cams = lf_db_find_cameras(uf->conf->lensdb,
+               uf->conf->real_make, uf->conf->real_model);
+       if (cams != NULL) {
+           lf_camera_copy(uf->conf->camera, cams[0]);
+           lf_free(cams);
+       }
+    }
+    if (strlen(uf->conf->lensText) > 0) {
+       const lfLens **lenses = lf_db_find_lenses_hd(uf->conf->lensdb,
+               uf->conf->camera, NULL, uf->conf->lensText, 0);
+       if (lenses != NULL) {
+           lf_lens_copy(uf->conf->lens, lenses[0]);
+           lf_free(lenses);
+       }
+    }
+}
+#endif /* HAVE_LENSFUN */
+
 static void ufraw_convert_import_buffer(ufraw_data *uf, UFRawPhase phase, 
dcraw_image_data *dcimg)
 {
     ufraw_image_data *img = &uf->Images[phase];


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
ufraw-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ufraw-cvs

Reply via email to