Update of /cvsroot/ufraw/ufraw In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv3107
Modified Files: ufraw.h ufraw_conf.c ufraw_lens_ui.c ufraw_ufraw.c ufraw_ui.h Log Message: Automatically calculate lensfun scaling to preserve image area. Remove manual scaling option. Index: ufraw.h =================================================================== RCS file: /cvsroot/ufraw/ufraw/ufraw.h,v retrieving revision 1.147 retrieving revision 1.148 diff -u -d -r1.147 -r1.148 --- ufraw.h 7 Feb 2010 22:26:49 -0000 1.147 +++ ufraw.h 10 Feb 2010 23:37:02 -0000 1.148 @@ -277,7 +277,6 @@ lfLensCalibTCA lens_tca; /* lens tca parameters */ 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; Index: ufraw_conf.c =================================================================== RCS file: /cvsroot/ufraw/ufraw/ufraw_conf.c,v retrieving revision 1.158 retrieving revision 1.159 diff -u -d -r1.158 -r1.159 --- ufraw_conf.c 7 Feb 2010 22:26:49 -0000 1.158 +++ ufraw_conf.c 10 Feb 2010 23:37:02 -0000 1.159 @@ -138,7 +138,6 @@ /* lens vignetting parameters */ { 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 */ }; Index: ufraw_ui.h =================================================================== RCS file: /cvsroot/ufraw/ufraw/ufraw_ui.h,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- ufraw_ui.h 7 Feb 2010 22:26:49 -0000 1.36 +++ ufraw_ui.h 10 Feb 2010 23:37:02 -0000 1.37 @@ -138,12 +138,6 @@ GtkWidget *LensFromGeometrySel, *LensToGeometrySel; /* The hbox containing focal, aperture, distance combos */ GtkWidget *LensParamBox; - /* Additional image scale to be applied during postprocessing */ - GtkAdjustment *LensScaleAdjustment; - /* The button that resets lens scale to 0.0 */ - GtkWidget *LensScaleResetButton; - /* The button that automatically computes the optimal scale */ - GtkWidget *LensAutoScaleButton; #endif /* HAVE_LENSFUN */ long (*SaveFunc)(); RenderModeType RenderMode; Index: ufraw_lens_ui.c =================================================================== RCS file: /cvsroot/ufraw/ufraw/ufraw_lens_ui.c,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- ufraw_lens_ui.c 8 Feb 2010 04:30:11 -0000 1.26 +++ ufraw_lens_ui.c 10 Feb 2010 23:37:02 -0000 1.27 @@ -460,7 +460,6 @@ gtk_widget_show_all (data->LensParamBox); CFG->cur_lens_type = LF_UNKNOWN; - CFG->lens_scale = 0.0; lens_interpolate (data, lens); } @@ -606,43 +605,6 @@ return adj; } -static void lens_scale_update (GtkAdjustment *adj, float *valuep) -{ - preview_data *data = get_preview_data (adj); - *valuep = gtk_adjustment_get_value (adj); - ufraw_invalidate_layer(data->UF, ufraw_transform_phase); - resize_canvas(data); - render_preview (data); -} - -static void lens_scale_reset (GtkWidget *button, gpointer user_data) -{ - (void)user_data; - preview_data *data = get_preview_data (button); - gtk_adjustment_set_value (data->LensScaleAdjustment, 0.0); - ufraw_invalidate_layer(data->UF, ufraw_transform_phase); - resize_canvas(data); - render_preview (data); -} - -static void lens_autoscale (GtkWidget *button, gpointer user_data) -{ - (void)user_data; - preview_data *data = get_preview_data (button); - if (!data->UF->modifier) - gtk_adjustment_set_value (data->LensScaleAdjustment, 0.0); - else - { - float cs = pow (2.0, CFG->lens_scale); - float as = lf_modifier_get_auto_scale (data->UF->modifier, 0); - gtk_adjustment_set_value (data->LensScaleAdjustment, - log (cs * as) / log (2.0)); - ufraw_invalidate_layer(data->UF, ufraw_transform_phase); - resize_canvas(data); - render_preview (data); - } -} - /* --- TCA correction page --- */ static void remove_tca_models (preview_data *data, lfTCAModel model) @@ -1084,11 +1046,10 @@ */ void lens_fill_interface (preview_data *data, GtkWidget *page) { - GtkTable *table, *subTable; GtkWidget *label, *button, *subpage; /* Camera selector */ - table = GTK_TABLE(gtk_table_new(10, 10, FALSE)); + GtkTable *table = GTK_TABLE(gtk_table_new(10, 10, FALSE)); gtk_box_pack_start(GTK_BOX(page), GTK_WIDGET(table), FALSE, FALSE, 0); label = gtk_label_new(_("Camera")); @@ -1134,24 +1095,6 @@ data->LensParamBox = gtk_hbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (page), data->LensParamBox, FALSE, FALSE, 2); - subTable = GTK_TABLE (gtk_table_new (10, 10, FALSE)); - gtk_box_pack_start (GTK_BOX (page), GTK_WIDGET (subTable), FALSE, FALSE, 0); - - data->LensScaleAdjustment = adjustment_scale ( - subTable, 0, 0, _("Scale"), CFG->lens_scale, &CFG->lens_scale, - -3, 3, 0.001, 0.1, 3, FALSE, _("Image scale power-of-two"), - G_CALLBACK (lens_scale_update), NULL, NULL, NULL); - - data->LensScaleResetButton = stock_icon_button( - GTK_STOCK_REFRESH, _("Reset image scale to default"), - G_CALLBACK (lens_scale_reset), NULL); - gtk_table_attach (subTable, data->LensScaleResetButton, 7, 8, 0, 1, 0,0,0,0); - - data->LensAutoScaleButton = stock_icon_button( - GTK_STOCK_ZOOM_FIT, _("Autoscale the image for best fit"), - G_CALLBACK (lens_autoscale), NULL); - gtk_table_attach (subTable, data->LensAutoScaleButton, 8, 9, 0, 1, 0,0,0,0); - GtkNotebook *subnb = GTK_NOTEBOOK(gtk_notebook_new()); gtk_box_pack_start(GTK_BOX(page), GTK_WIDGET(subnb), TRUE, TRUE, 0); Index: ufraw_ufraw.c =================================================================== RCS file: /cvsroot/ufraw/ufraw/ufraw_ufraw.c,v retrieving revision 1.235 retrieving revision 1.236 diff -u -d -r1.235 -r1.236 --- ufraw_ufraw.c 7 Feb 2010 22:26:49 -0000 1.235 +++ ufraw_ufraw.c 10 Feb 2010 23:37:02 -0000 1.236 @@ -1383,7 +1383,7 @@ } static void ufraw_convert_prepare_transform(ufraw_data *uf, - int width, int height, gboolean reverse) + int width, int height, gboolean reverse, float scale) { #ifdef HAVE_LENSFUN conf_data *conf = uf->conf; @@ -1399,10 +1399,9 @@ if (uf->modifier == NULL) return; - float real_scale = pow(2.0, conf->lens_scale); uf->modFlags = lf_modifier_initialize(uf->modifier, conf->lens, LF_PF_U16, conf->focal_len, conf->aperture, conf->subject_distance, - real_scale, conf->cur_lens_type, + scale, conf->cur_lens_type, UF_LF_TRANSFORM | LF_MODIFY_VIGNETTING, reverse); if ((uf->modFlags & UF_LF_ALL) == 0) { lf_modifier_destroy(uf->modifier); @@ -1421,7 +1420,7 @@ { const int iWidth = uf->initialWidth; const int iHeight = uf->initialHeight; - ufraw_convert_prepare_transform(uf, iWidth, iHeight, TRUE); + ufraw_convert_prepare_transform(uf, iWidth, iHeight, TRUE, 1.0); #ifdef HAVE_LENSFUN if (uf->conf->rotationAngle == 0 && (uf->modifier == NULL || !(uf->modFlags & UF_LF_TRANSFORM))) @@ -1434,15 +1433,15 @@ img->width = width; img->height = height; // We still need the transform for vignetting - ufraw_convert_prepare_transform(uf, width, height, FALSE); + ufraw_convert_prepare_transform(uf, width, height, FALSE, 1.0); uf->rotatedWidth = iWidth; uf->rotatedHeight = iHeight; uf->autoCropWidth = iWidth; uf->autoCropHeight = iHeight; return; } - const float sine = sin(uf->conf->rotationAngle * 2 * M_PI / 360); - const float cosine = cos(uf->conf->rotationAngle * 2 * M_PI / 360); + const double sine = sin(uf->conf->rotationAngle * 2 * M_PI / 360); + const double cosine = cos(uf->conf->rotationAngle * 2 * M_PI / 360); const float aspectRatio = (float)(uf->conf->CropX2 - uf->conf->CropX1) / (uf->conf->CropY2 - uf->conf->CropY1); const float midX = iWidth/2.0 - 0.5; @@ -1452,6 +1451,7 @@ #endif float maxX = 0, maxY = 0; float minX = 999999, minY = 999999; + double lastX = 0, lastY = 0, area = 0; int i; for (i = 0; i < iWidth + iHeight - 1; i++) { int x, y; @@ -1475,8 +1475,12 @@ buff[0] = x; buff[1] = y; #endif - float srcX = (buff[0]-midX)*cosine - (buff[1]-midY)*sine; - float srcY = (buff[0]-midX)*sine + (buff[1]-midY)*cosine; + double srcX = (buff[0]-midX)*cosine - (buff[1]-midY)*sine; + double srcY = (buff[0]-midX)*sine + (buff[1]-midY)*cosine; + // A digital planimeter: + area += srcY * lastX - srcX * lastY; + lastX = srcX; + lastY = srcY; maxX = MAX(maxX, fabs(srcX)); maxY = MAX(maxY, fabs(srcY)); if (fabs(srcX/srcY) > aspectRatio) @@ -1484,15 +1488,16 @@ else minY = MIN(minY, fabs(srcY)); } + float scale = sqrt((iWidth-1) * (iHeight-1) / area); // Do not allow increasing canvas size by more than a factor of 2 - uf->rotatedWidth = MIN(ceil(2*maxX), 2*iWidth); - uf->rotatedHeight = MIN(ceil(2*maxY), 2*iHeight); - uf->autoCropWidth = MIN(floor(2*minX), 2*iWidth); - uf->autoCropHeight = MIN(floor(2*minY), 2*iHeight); + uf->rotatedWidth = MIN(ceil(2*maxX)*scale, 2*iWidth); + uf->rotatedHeight = MIN(ceil(2*maxY)*scale, 2*iHeight); + uf->autoCropWidth = MIN(floor(2*minX)*scale, 2*iWidth); + uf->autoCropHeight = MIN(floor(2*minY)*scale, 2*iHeight); int newWidth = uf->rotatedWidth * width / iWidth; int newHeight = uf->rotatedHeight * height / iHeight; ufraw_image_init(img, newWidth, newHeight, 8); - ufraw_convert_prepare_transform(uf, width, height, FALSE); + ufraw_convert_prepare_transform(uf, width, height, FALSE, scale); } /* ------------------------------------------------------------------------------ SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev _______________________________________________ ufraw-cvs mailing list ufraw-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ufraw-cvs