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

Modified Files:
        ufraw.h ufraw_conf.c ufraw_preview.c ufraw_ufraw.c ufraw_ui.h 
Log Message:
Fixed again flip & rotate logic, hopefully once and for all.
Rotation reset button, resets to camera orientation.


Index: ufraw.h
===================================================================
RCS file: /cvsroot/ufraw/ufraw/ufraw.h,v
retrieving revision 1.122
retrieving revision 1.123
diff -u -d -r1.122 -r1.123
--- ufraw.h     29 Sep 2009 16:45:36 -0000      1.122
+++ ufraw.h     3 Oct 2009 06:55:56 -0000       1.123
@@ -188,6 +188,7 @@
     char darkframeFile[max_path];
     struct ufraw_struct *darkframe;
     int CropX1, CropY1, CropX2, CropY2;
+    int orientation;
     double rotationAngle;
     int lightnessAdjustmentCount;
     lightness_adjustment lightnessAdjustment[max_adjustments];
@@ -221,7 +222,7 @@
     char remoteGimpCommand[max_path];
 
     /* EXIF data */
-    int orientation;
+    int CameraOrientation;
     float iso_speed, shutter, aperture, focal_len, subject_distance;
     char exifSource[max_name], isoText[max_name], shutterText[max_name],
         apertureText[max_name], focalLenText[max_name],
@@ -316,7 +317,6 @@
 ufraw_image_data *ufraw_convert_image_area(ufraw_data *uf, unsigned saidx,
        UFRawPhase phase);
 void ufraw_close(ufraw_data *uf);
-void ufraw_flip_orientation(ufraw_data *uf, int flip);
 int ufraw_flip_image(ufraw_data *uf, int flip);
 int ufraw_set_wb(ufraw_data *uf);
 void ufraw_auto_expose(ufraw_data *uf);
@@ -326,6 +326,7 @@
                      int bitDepth, int row, int offset, int width);
 void ufraw_rotate_image_buffer(ufraw_image_data *img, double angle);
 void ufraw_normalize_rotation(ufraw_data *uf);
+void ufraw_unnormalize_rotation(ufraw_data *uf);
 void ufraw_get_image_dimensions(dcraw_data *raw, ufraw_data *uf);
 
 void ufraw_img_get_subarea_coord (ufraw_image_data *img, unsigned saidx,

Index: ufraw_ui.h
===================================================================
RCS file: /cvsroot/ufraw/ufraw/ufraw_ui.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- ufraw_ui.h  2 Oct 2009 14:30:09 -0000       1.22
+++ ufraw_ui.h  3 Oct 2009 06:55:56 -0000       1.23
@@ -169,8 +169,6 @@
     int SpotX1, SpotY1, SpotX2, SpotY2;
     CursorType CropMotionType;
     int DrawnCropX1, DrawnCropX2, DrawnCropY1, DrawnCropY2;
-    double unnormalized_angle;
-    int reference_orientation;
     double shrink, height, width;
     gboolean OptionsChanged;
     int PageNum;

Index: ufraw_conf.c
===================================================================
RCS file: /cvsroot/ufraw/ufraw/ufraw_conf.c,v
retrieving revision 1.146
retrieving revision 1.147
diff -u -d -r1.146 -r1.147
--- ufraw_conf.c        29 Sep 2009 16:45:36 -0000      1.146
+++ ufraw_conf.c        3 Oct 2009 06:55:56 -0000       1.147
@@ -81,6 +81,7 @@
     ahd_interpolation, 0, /* interpolation, smoothing */
     "", NULL, /* darkframeFile, darkframe */
     -1, -1, -1, -1, /* Crop X1,Y1,X2,Y2 */
+    -1, /* orientation */
     0, /* rotationAngle */
     0, /* lightness adjustment count */
     {
@@ -126,7 +127,7 @@
 #endif
 
     /* EXIF data */
-    -1, /* orientation */
+    0, /* CameraOrientation */
     0.0, 0.0, 0.0, 0.0, 1.0, /* iso_speed, shutter, aperture, focal_len, 
subject_dist */
     "", "", "", "", /* exifSource, isoText, shutterText, apertureText */
     "", "", "", "", /* focalLenText, focalLen35Text, lensText, flashText */

Index: ufraw_ufraw.c
===================================================================
RCS file: /cvsroot/ufraw/ufraw/ufraw_ufraw.c,v
retrieving revision 1.191
retrieving revision 1.192
diff -u -d -r1.191 -r1.192
--- ufraw_ufraw.c       29 Sep 2009 21:30:19 -0000      1.191
+++ ufraw_ufraw.c       3 Oct 2009 06:55:56 -0000       1.192
@@ -311,41 +311,17 @@
     return UFRAW_SUCCESS;
 }
 
-/*
- * Normalize arbitrary rotations into a 0..90 degree range.
- */
-void ufraw_normalize_rotation(ufraw_data *uf)
+void ufraw_get_image_dimensions(dcraw_data *raw, ufraw_data *uf)
 {
-    int angle, flip = 0;
-
-    uf->conf->rotationAngle = fmod(uf->conf->rotationAngle, 360.0);
-    if (uf->conf->rotationAngle < 0.0)
-       uf->conf->rotationAngle += 360.0;
-    angle = floor(uf->conf->rotationAngle / 90) * 90;
-    switch (angle) {
-       case  90: flip = 6; break;
-       case 180: flip = 3; break;
-       case 270: flip = 5; break;
-    }
-    ufraw_flip_orientation(uf, flip);
-    uf->conf->rotationAngle -= angle;
-}
+    dcraw_image_dimensions(raw, uf->conf->orientation,
+           &uf->initialHeight, &uf->initialWidth);
 
-void ufraw_update_rotated_dimensions(ufraw_data *uf)
-{
+    // update rotated dimensions
     double rotationRadians = (uf->conf->rotationAngle * 2 * M_PI) / 360;
     uf->rotatedWidth = ceil((uf->initialHeight * sin(rotationRadians))
        + (uf->initialWidth * cos(rotationRadians)));
     uf->rotatedHeight = ceil((uf->initialWidth * sin(rotationRadians))
        + (uf->initialHeight * cos(rotationRadians)));
-}
-
-void ufraw_get_image_dimensions(dcraw_data *raw, ufraw_data *uf)
-{
-    dcraw_image_dimensions(raw, uf->conf->orientation,
-           &uf->initialHeight, &uf->initialWidth);
-
-    ufraw_update_rotated_dimensions(uf);
 
     if (uf->conf->CropX1 < 0) uf->conf->CropX1 = 0;
     if (uf->conf->CropY1 < 0) uf->conf->CropY1 = 0;
@@ -464,14 +440,16 @@
 
     uf->conf->timestamp = raw->timestamp;
 
+    uf->conf->CameraOrientation = raw->flip;
+
     if ( !uf->conf->rotate ) {
        uf->conf->orientation = 0;
        uf->conf->rotationAngle = 0;
     } else {
        if ( !uf->LoadingID || uf->conf->orientation<0 )
-           uf->conf->orientation = raw->flip;
-       ufraw_normalize_rotation(uf);
+           uf->conf->orientation = uf->conf->CameraOrientation;
        // Normalise rotations to a flip, then rotation of 0 < a < 90 degrees.
+       ufraw_normalize_rotation(uf);
     }
 
     if (uf->inputExifBuf==NULL) {
@@ -1409,7 +1387,7 @@
     return UFRAW_SUCCESS;
 }
 
-void ufraw_flip_orientation(ufraw_data *uf, int flip)
+static void ufraw_flip_orientation(ufraw_data *uf, int flip)
 {
     const char flipMatrix[8][8] = {
        { 0, 1, 2, 3, 4, 5, 6, 7 }, /* No flip */
@@ -1424,10 +1402,68 @@
     uf->conf->orientation = flipMatrix[uf->conf->orientation][flip];
 }
 
-int ufraw_flip_image(ufraw_data *uf, int flip)
+/*
+ * Normalize arbitrary rotations into a 0..90 degree range.
+ */
+void ufraw_normalize_rotation(ufraw_data *uf)
 {
+    int angle, flip = 0;
+
+    uf->conf->rotationAngle = fmod(uf->conf->rotationAngle, 360.0);
+    if (uf->conf->rotationAngle < 0.0)
+       uf->conf->rotationAngle += 360.0;
+    angle = floor(uf->conf->rotationAngle / 90) * 90;
+    switch (angle) {
+       case  90: flip = 6; break;
+       case 180: flip = 3; break;
+       case 270: flip = 5; break;
+    }
     ufraw_flip_orientation(uf, flip);
+    uf->conf->rotationAngle -= angle;
+}
+
+/*
+ * Unnormalize a normalized rotaion into a -180..180 degree range,
+ * while orientation can be either 0 (normal) or 1 (flipped).
+ * All image processing code assumes normalized rotation, therefore
+ * each call to ufraw_unnormalize_rotation() must be followed by a call
+ * to ufraw_normalize_rotation().
+ */
+void ufraw_unnormalize_rotation(ufraw_data *uf)
+{
+    switch (uf->conf->orientation) {
+    case 5: /* Rotate 270 */
+       uf->conf->rotationAngle += 90;
+    case 3: /* Rotate 180 */
+       uf->conf->rotationAngle += 90;
+    case 6: /* Rotate 90 */
+       uf->conf->rotationAngle += 90;
+       uf->conf->orientation = 0;
+    case 0: /* No flip */
+       break;
+    case 4: /* Flip over diagonal "\" */
+       uf->conf->rotationAngle += 90;
+    case 2: /* Flip vertical */
+       uf->conf->rotationAngle += 90;
+    case 7: /* Flip over diagonal "/" */
+       uf->conf->rotationAngle += 90;
+       uf->conf->orientation = 1;
+    case 1: /* Flip horizontal */
+       break;
+    default:
+       g_error("ufraw_unnormalized_roation(): orientation=%d out of range",
+               uf->conf->orientation);
+    }
+    uf->conf->rotationAngle = remainder(uf->conf->rotationAngle, 360.0);
+}
 
+int ufraw_flip_image(ufraw_data *uf, int flip)
+{
+    ufraw_flip_orientation(uf, flip);
+    if (flip==1 || flip==2 || flip==4 || flip==7) {
+       uf->conf->rotationAngle = -uf->conf->rotationAngle;
+       ufraw_normalize_rotation(uf);
+    }
     ufraw_flip_image_buffer(&uf->Images[ufraw_first_phase], flip);
     if (ufraw_do_denoise_phase(uf))
        ufraw_flip_image_buffer(&uf->Images[ufraw_denoise_phase], flip);

Index: ufraw_preview.c
===================================================================
RCS file: /cvsroot/ufraw/ufraw/ufraw_preview.c,v
retrieving revision 1.279
retrieving revision 1.280
diff -u -d -r1.279 -r1.280
--- ufraw_preview.c     2 Oct 2009 14:30:09 -0000       1.279
+++ ufraw_preview.c     3 Oct 2009 06:55:56 -0000       1.280
@@ -2176,12 +2176,6 @@
        }
     }
     if (flip & 4) {
-       temp = data->UF->rotatedWidth;
-       data->UF->rotatedWidth = data->UF->rotatedHeight;
-       data->UF->rotatedHeight = temp;
-       temp = data->UF->initialWidth;
-       data->UF->initialWidth = data->UF->initialHeight;
-       data->UF->initialHeight = temp;
        temp = CFG->CropX1;
        CFG->CropX1 = CFG->CropY1;
        CFG->CropY1 = temp;
@@ -2197,26 +2191,20 @@
            data->SpotY2 = temp;
        }
     }
-    switch (flip) {
-       case 6:
-           data->unnormalized_angle += 90;
-           break;
-       case 5:
-           data->unnormalized_angle -= 90;
-           break;
-       case 1:
-       case 2:
-           data->reference_orientation ^= flip;
-           data->unnormalized_angle = -data->unnormalized_angle;
-           break;
-       default:
-           g_error("flip_image(): flip:%d invalid", flip);
-    }
-    data->unnormalized_angle = remainder(data->unnormalized_angle, 360);
+    // image dimensions cannot really change here,
+    // yet width and height might be flipped (independent of flip&4).
+    ufraw_get_image_dimensions(data->UF->raw, data->UF);
+
     ++data->FreezeDialog;
+    ufraw_unnormalize_rotation(data->UF);
     gtk_adjustment_set_value(data->RotationAdjustment,
-           data->unnormalized_angle);
+           CFG->rotationAngle);
+    ufraw_normalize_rotation(data->UF);
+    gtk_widget_set_sensitive(data->ResetRotationAdjustment,
+           CFG->rotationAngle != 0 ||
+           CFG->orientation != CFG->CameraOrientation);
     --data->FreezeDialog;
+
     render_init(data);
     if ( data->RenderSubArea >= 0 ) {
        /* We are in the middle or a rendering scan,
@@ -2954,25 +2942,25 @@
  * are valid. Try to preserve them over a rotate forth and back and try to
  * preserve their geometry.
  */
-static void set_rotation_angle(preview_data *data, double angle)
+static void adjustment_update_rotation(GtkAdjustment *adj, gpointer user_data)
 {
-    int d;
+    preview_data *data = get_preview_data(adj);
+    (void)user_data;
 
     /* Normalize the "unnormalized" value displayed to the user to
      * -180 < a <= 180, though we later normalize to an orientation
      * and flip plus 0 <= a < 90 rotation for processing.  */
-    data->unnormalized_angle = remainder(angle, 360);
-    CFG->rotationAngle = data->unnormalized_angle;
-    CFG->orientation = data->reference_orientation;
-    ufraw_normalize_rotation(data->UF);
     if (data->FreezeDialog)
        return;
-    gtk_adjustment_set_value(data->RotationAdjustment,
-           data->unnormalized_angle);
+    
+    ufraw_unnormalize_rotation(data->UF);
+    CFG->rotationAngle = gtk_adjustment_get_value(data->RotationAdjustment);
+    ufraw_normalize_rotation(data->UF);
     gtk_widget_set_sensitive(data->ResetRotationAdjustment,
-           data->unnormalized_angle != 0);
+           CFG->rotationAngle != 0 ||
+           CFG->orientation != CFG->CameraOrientation);
     ufraw_get_image_dimensions(data->UF->raw, data->UF);
-    d = MIN(CFG->CropX1, CFG->CropX2 - data->UF->rotatedWidth);
+    int d = MIN(CFG->CropX1, CFG->CropX2 - data->UF->rotatedWidth);
     if (d > 0) {
        CFG->CropX1 -= d;
        CFG->CropX2 -= d;
@@ -3011,20 +2999,16 @@
     update_scales(data);
 }
 
-static void adjustment_update_rotation(GtkAdjustment *adj, gpointer user_data)
-{
-    preview_data *data = get_preview_data(adj);
-
-    (void)user_data;
-    set_rotation_angle(data, gtk_adjustment_get_value(adj));
-}
-
-static void adjustment_reset_rotation(GtkAdjustment *adj, gpointer user_data)
+static void adjustment_reset_rotation(GtkWidget *widget, gpointer user_data)
 {
-    preview_data *data = get_preview_data(adj);
+    preview_data *data = get_preview_data(widget);
 
     (void)user_data;
-    gtk_adjustment_set_value(data->RotationAdjustment, 0);
+    CFG->orientation = CFG->CameraOrientation;
+    CFG->rotationAngle = 0;
+    ufraw_unnormalize_rotation(data->UF);
+    gtk_adjustment_set_value(data->RotationAdjustment, CFG->rotationAngle);
+    ufraw_normalize_rotation(data->UF);
 }
 
 GtkWidget *reset_button(const char *tip, GCallback callback, void *data)
@@ -4927,18 +4911,19 @@
     gtk_table_attach(table, button, 4, 5, 0, 1, 0, 0, 0, 0);
 
     /* Rotation controls */
-    data->unnormalized_angle = CFG->rotationAngle;
-    data->reference_orientation = CFG->orientation;
     table = GTK_TABLE(table_with_frame(page, NULL, TRUE));
+    ufraw_unnormalize_rotation(data->UF);
     data->RotationAdjustment = adjustment_scale(
        table, 0, 0, _("Rotation"),
-       data->unnormalized_angle, &data->unnormalized_angle,
+       CFG->rotationAngle, NULL,
        -180, 180, 0.1, 1, 2, TRUE, _("Rotation Angle"),
        G_CALLBACK(adjustment_update_rotation),
        &data->ResetRotationAdjustment, _("Reset Rotation Angle"),
        G_CALLBACK(adjustment_reset_rotation));
+    ufraw_normalize_rotation(data->UF);
     gtk_widget_set_sensitive(data->ResetRotationAdjustment,
-           data->unnormalized_angle != 0);
+           CFG->rotationAngle != 0 ||
+           CFG->orientation != CFG->CameraOrientation);
 
     // drawLines toggle button
     GtkWidget *subtable = gtk_table_new(10, 10, FALSE);


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; 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&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
ufraw-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ufraw-cvs

Reply via email to