okra pushed a commit to branch master.

http://git.enlightenment.org/apps/ephoto.git/commit/?id=92736b10aa83cc90c46e403371ae7ea1efe99b66

commit 92736b10aa83cc90c46e403371ae7ea1efe99b66
Author: Stephen Houston <[email protected]>
Date:   Mon Oct 10 20:16:50 2016 -0500

    Ephoto: Fix handling of history and applying of edits.
---
 src/bin/ephoto_bcg.c            | 20 +++++++++++-----
 src/bin/ephoto_color.c          | 20 +++++++++++-----
 src/bin/ephoto_filters.c        | 12 +++++-----
 src/bin/ephoto_hsv.c            | 18 +++++++++++----
 src/bin/ephoto_red_eye.c        | 16 +++++++++----
 src/bin/ephoto_scale.c          |  8 +++++++
 src/bin/ephoto_single_browser.c | 51 +++++++++++++++--------------------------
 7 files changed, 85 insertions(+), 60 deletions(-)

diff --git a/src/bin/ephoto_bcg.c b/src/bin/ephoto_bcg.c
index 2cb4ad6..4601e56 100644
--- a/src/bin/ephoto_bcg.c
+++ b/src/bin/ephoto_bcg.c
@@ -15,7 +15,7 @@ struct _Ephoto_BCG
    int brightness;
    double gamma;
    Evas_Coord w, h;
-   unsigned int *original_im_data;
+   unsigned int *original_im_data; 
 };
 
 static int
@@ -274,11 +274,19 @@ _bcg_apply(void *data, int type EINA_UNUSED,
    unsigned int *image_data;
    Evas_Coord w, h;
 
-   image_data =
-       evas_object_image_data_get(ebcg->image,
-       EINA_FALSE);
-   evas_object_image_size_get(ebcg->image, &w, &h);
-   ephoto_single_browser_image_data_done(ebcg->main, image_data, w, h);
+   if (elm_slider_value_get(ebcg->bslider) == 0 && 
+       elm_slider_value_get(ebcg->cslider) == 0 && 
+       elm_slider_value_get(ebcg->gslider) == 1)
+     {
+        ephoto_single_browser_cancel_editing(ebcg->main);
+     }
+   else
+     {
+        image_data =
+            evas_object_image_data_get(ebcg->image, EINA_FALSE);
+        evas_object_image_size_get(ebcg->image, &w, &h);
+        ephoto_single_browser_image_data_done(ebcg->main, image_data, w, h);
+     }
    ephoto_editor_del(ebcg->editor);
 
    return ECORE_CALLBACK_PASS_ON;
diff --git a/src/bin/ephoto_color.c b/src/bin/ephoto_color.c
index 102e688..56cc547 100644
--- a/src/bin/ephoto_color.c
+++ b/src/bin/ephoto_color.c
@@ -258,12 +258,20 @@ _color_apply(void *data, int type EINA_UNUSED,
    Ephoto_Color *eco = data;
    unsigned int *image_data;
    Evas_Coord w, h;
-
-   image_data =
-       evas_object_image_data_get(eco->image,
-           EINA_FALSE);
-   evas_object_image_size_get(eco->image, &w, &h);
-   ephoto_single_browser_image_data_done(eco->main, image_data, w, h);
+ 
+   if (elm_slider_value_get(eco->rslider) == 0 &&
+       elm_slider_value_get(eco->gslider) == 0 &&
+       elm_slider_value_get(eco->bslider) == 0)
+     {
+        ephoto_single_browser_cancel_editing(eco->main);
+     }
+   else
+     {
+        image_data =
+            evas_object_image_data_get(eco->image, EINA_FALSE);
+        evas_object_image_size_get(eco->image, &w, &h);
+        ephoto_single_browser_image_data_done(eco->main, image_data, w, h);
+     }
    ephoto_editor_del(eco->editor);
 
    return ECORE_CALLBACK_PASS_ON;
diff --git a/src/bin/ephoto_filters.c b/src/bin/ephoto_filters.c
index 1ebe90d..bb1736a 100644
--- a/src/bin/ephoto_filters.c
+++ b/src/bin/ephoto_filters.c
@@ -70,7 +70,7 @@ _initialize_filter(Ephoto_Image_Filter filter,
    ef->ephoto = ephoto;
    ef->image = image;
    ef->im_data = malloc(sizeof(unsigned int) * w * h);
-   ef->im_data = memcpy(ef->im_data, im_data, sizeof(unsigned int) * w * h);
+   memcpy(ef->im_data, im_data, sizeof(unsigned int) * w * h);
    ef->im_data_new = malloc(sizeof(unsigned int) * w * h);
    ef->im_data_two = NULL;
    ef->im_data_orig = NULL;
@@ -193,14 +193,14 @@ _thread_finished_cb(void *data, Ecore_Thread *th 
EINA_UNUSED)
                   ef->im_data_two = NULL;
                }
              ef->im_data_two = malloc(sizeof(unsigned int) * ef->w * ef->h);
-             ef->im_data_two = memcpy(ef->im_data_two, ef->im_data,
+             memcpy(ef->im_data_two, ef->im_data,
                  sizeof(unsigned int) * ef->w * ef->h);
              ef->save_data = EINA_FALSE;
           }
         free(ef->im_data);
         ef->im_data = NULL;
         ef->im_data = malloc(sizeof(unsigned int) * ef->w * ef->h);
-        ef->im_data = memcpy(ef->im_data, ef->im_data_new,
+        memcpy(ef->im_data, ef->im_data_new,
             sizeof(unsigned int) * ef->w * ef->h);
         if (ef->hist)
           free(ef->hist);
@@ -523,7 +523,7 @@ _blur(void *data, Ecore_Thread *th EINA_UNUSED)
 
         rad = (sizes[i] - 1) / 2;
 
-        ef->im_data_new = memcpy(ef->im_data_new, ef->im_data,
+        memcpy(ef->im_data_new, ef->im_data,
             sizeof(unsigned int) * w * h);
         _blur_vertical(ef, rad);
         _blur_horizontal(ef, rad);
@@ -1086,7 +1086,7 @@ ephoto_filter_sharpen(Ephoto *ephoto, Evas_Object *image)
    Ephoto_Filter *ef = _initialize_filter(EPHOTO_IMAGE_FILTER_SHARPEN,
        ephoto, image);
    ef->im_data_orig = malloc(sizeof(unsigned int) * ef->w * ef->h);
-   ef->im_data_orig = memcpy(ef->im_data_orig, ef->im_data,
+   memcpy(ef->im_data_orig, ef->im_data,
        sizeof(unsigned int) * ef->w * ef->h);
 
    ef->rad = 9;
@@ -1103,7 +1103,7 @@ ephoto_filter_dither(Ephoto *ephoto, Evas_Object *image)
 {
    Ephoto_Filter *ef = _initialize_filter(EPHOTO_IMAGE_FILTER_DITHER,
        ephoto, image);
-   ef->im_data_new = memcpy(ef->im_data_new, ef->im_data,
+   memcpy(ef->im_data_new, ef->im_data,
        sizeof(unsigned int) * ef->w * ef->h);
 
    ef->popup = _processing(ephoto->win);
diff --git a/src/bin/ephoto_hsv.c b/src/bin/ephoto_hsv.c
index 593b2f2..41a4a6d 100644
--- a/src/bin/ephoto_hsv.c
+++ b/src/bin/ephoto_hsv.c
@@ -281,11 +281,19 @@ _hsv_apply(void *data, int type EINA_UNUSED,
    unsigned int *image_data;
    Evas_Coord w, h;
 
-   image_data =
-       evas_object_image_data_get(ehsv->image,
-       EINA_FALSE);
-   evas_object_image_size_get(ehsv->image, &w, &h);
-   ephoto_single_browser_image_data_done(ehsv->main, image_data, w, h);
+   if (elm_slider_value_get(ehsv->hslider) == 0 &&
+       elm_slider_value_get(ehsv->sslider) == 0 &&
+       elm_slider_value_get(ehsv->vslider) == 0)
+     {
+        ephoto_single_browser_cancel_editing(ehsv->main);
+     }
+   else
+     {
+        image_data =
+            evas_object_image_data_get(ehsv->image, EINA_FALSE);
+        evas_object_image_size_get(ehsv->image, &w, &h);
+        ephoto_single_browser_image_data_done(ehsv->main, image_data, w, h);
+     }
    ephoto_editor_del(ehsv->editor);
 
    return ECORE_CALLBACK_PASS_ON;
diff --git a/src/bin/ephoto_red_eye.c b/src/bin/ephoto_red_eye.c
index 3689384..d3ec17f 100644
--- a/src/bin/ephoto_red_eye.c
+++ b/src/bin/ephoto_red_eye.c
@@ -150,11 +150,17 @@ _reye_apply(void *data, int type EINA_UNUSED,
    unsigned int *image_data;
    Evas_Coord w, h;
 
-   image_data =
-       evas_object_image_data_get(er->image,
-           EINA_FALSE);
-   evas_object_image_size_get(er->image, &w, &h);
-   ephoto_single_browser_image_data_done(er->main, image_data, w, h);
+   if (!er->edited_im_data)
+     {
+        ephoto_single_browser_cancel_editing(er->main);
+     }
+   else
+     {
+        image_data =
+            evas_object_image_data_get(er->image, EINA_FALSE);
+        evas_object_image_size_get(er->image, &w, &h);
+        ephoto_single_browser_image_data_done(er->main, image_data, w, h);
+     }
    ephoto_editor_del(er->editor);
 
    return ECORE_CALLBACK_PASS_ON;
diff --git a/src/bin/ephoto_scale.c b/src/bin/ephoto_scale.c
index 9a2a0db..840f7c0 100644
--- a/src/bin/ephoto_scale.c
+++ b/src/bin/ephoto_scale.c
@@ -105,6 +105,14 @@ _es_apply(void *data, int type EINA_UNUSED,
    Ecore_Evas *ee;
    Evas *eecanvas;
 
+   if (elm_spinner_value_get(es->scalew) == es->w &&
+       elm_spinner_value_get(es->scaleh) == es->h)
+     {
+        ephoto_single_browser_cancel_editing(es->main);
+        ephoto_editor_del(es->editor);
+        return ECORE_CALLBACK_PASS_ON;
+     }
+
    w = round(elm_spinner_value_get(es->scalew));
    h = round(elm_spinner_value_get(es->scaleh));
    evas_object_image_file_get(es->image,
diff --git a/src/bin/ephoto_single_browser.c b/src/bin/ephoto_single_browser.c
index 6b7fc0b..a858b2e 100644
--- a/src/bin/ephoto_single_browser.c
+++ b/src/bin/ephoto_single_browser.c
@@ -28,9 +28,6 @@ struct _Ephoto_Single_Browser
    unsigned int history_pos;
    Eina_Bool editing:1;
    Eina_Bool cropping:1;
-   unsigned int *edited_image_data;
-   Evas_Coord ew;
-   Evas_Coord eh;
 };
 
 struct _Ephoto_Viewer
@@ -294,7 +291,7 @@ _monitor_cb(void *data, int type,
    Ephoto_Single_Browser *sb = data;
    Ephoto_Viewer *v = evas_object_data_get(sb->viewer, "viewer");
 
-   if (sb->edited_image_data)
+   if (eina_list_count(sb->history))
      return ECORE_CALLBACK_PASS_ON;
    if (type == EIO_MONITOR_FILE_MODIFIED)
      {
@@ -482,10 +479,6 @@ _orient_apply(Ephoto_Single_Browser *sb)
    elm_table_unpack(v->table, v->image);
    elm_object_content_unset(v->scroller);
    evas_object_image_size_get(v->image, &w, &h);
-   sb->edited_image_data =
-       evas_object_image_data_get(v->image, EINA_FALSE);
-   sb->ew = w;
-   sb->eh = h;
    if (sb->history_pos < (eina_list_count(sb->history)-1))
      {
         int count;
@@ -503,11 +496,11 @@ _orient_apply(Ephoto_Single_Browser *sb)
           }
      }
    eh = calloc(1, sizeof(Ephoto_History));
-   eh->im_data = malloc(sizeof(unsigned int) * sb->ew * sb->eh);
-   eh->im_data = memcpy(eh->im_data, sb->edited_image_data,
-       sizeof(unsigned int) * sb->ew * sb->eh);
-   eh->w = sb->ew;
-   eh->h = sb->eh;
+   eh->im_data = malloc(sizeof(unsigned int) * w * h);
+   eh->im_data = memcpy(eh->im_data, evas_object_image_data_get(v->image, 
EINA_FALSE),
+       sizeof(unsigned int) * w * h);
+   eh->w = w;
+   eh->h = h;
    eh->orient = sb->orient;
    sb->history = eina_list_append(sb->history, eh);
    sb->history_pos = eina_list_count(sb->history) - 1;
@@ -2155,12 +2148,6 @@ ephoto_single_browser_entry_set(Evas_Object *obj, 
Ephoto_Entry *entry)
    else if (entry)
      sb->entry = entry;
    _ephoto_single_browser_recalc(sb);
-   if (sb->edited_image_data)
-     {
-       sb->edited_image_data = NULL;
-       sb->ew = 0;
-       sb->eh = 0;
-     }
    if (sb->history)
      {
         EINA_LIST_FREE(sb->history, eh)
@@ -2272,6 +2259,8 @@ ephoto_single_browser_image_data_done(Evas_Object *main,
    Eina_List *l;
    char buf[PATH_MAX];
 
+   if (!image_data)
+     return;
    if (sb->editing)
      {
         _ephoto_single_browser_recalc(sb);
@@ -2282,9 +2271,6 @@ ephoto_single_browser_image_data_done(Evas_Object *main,
         evas_object_image_data_set(v->image, image_data);
         evas_object_image_data_update_add(v->image, 0, 0, w,
             h);
-        sb->edited_image_data = image_data;
-        sb->ew = w;
-        sb->eh = h;
         if (sb->history_pos < (eina_list_count(sb->history)-1))
           {
              int count;
@@ -2302,11 +2288,11 @@ ephoto_single_browser_image_data_done(Evas_Object *main,
                }
           }
         eh = calloc(1, sizeof(Ephoto_History));
-        eh->im_data = malloc(sizeof(unsigned int) * sb->ew * sb->eh);
-        eh->im_data = memcpy(eh->im_data, sb->edited_image_data,
-            sizeof(unsigned int) * sb->ew * sb->eh);
-        eh->w = sb->ew;
-        eh->h = sb->eh;
+        eh->im_data = malloc(sizeof(unsigned int) * w * h);
+        memcpy(eh->im_data, image_data,
+            sizeof(unsigned int) * w * h);
+        eh->w = w;
+        eh->h = h;
         eh->orient = sb->orient;
         sb->history = eina_list_append(sb->history, eh);
         sb->history_pos = eina_list_count(sb->history) - 1;
@@ -2329,14 +2315,15 @@ ephoto_single_browser_cancel_editing(Evas_Object *main)
         Ephoto_Viewer *v = evas_object_data_get(sb->viewer, "viewer");
        if (sb->cropping)
           sb->cropping = EINA_FALSE;
-       if (sb->edited_image_data)
+       if (sb->history_pos)
          {
-            evas_object_image_size_set(v->image, sb->ew,
-                sb->eh);
+             Ephoto_History *eh = eina_list_nth(sb->history, sb->history_pos);
+            evas_object_image_size_set(v->image, eh->w,
+                eh->h);
             evas_object_image_data_set(v->image,
-                sb->edited_image_data);
+                eh->im_data);
             evas_object_image_data_update_add(v->image, 0,
-                0, sb->ew, sb->eh);
+                0, eh->w, eh->h);
          }
        sb->editing = EINA_FALSE;
        _zoom_fit(sb);

-- 


Reply via email to