From cd77e7fcf73737b52584e7d3d031b920ae78ab88 Mon Sep 17 00:00:00 2001 From: titan Date: Fri, 11 May 2007 22:49:31 +0000 Subject: [PATCH] Add blur/sharpen options to ephoto!!!!! SVN revision: 29955 --- src/bin/ephoto.h | 2 + src/bin/ephoto_edit_view.c | 74 +++++++++++++++--- src/bin/ephoto_imaging.c | 151 +++++++++++++++++++++++++++++++++++++ 3 files changed, 216 insertions(+), 11 deletions(-) diff --git a/src/bin/ephoto.h b/src/bin/ephoto.h index 9700877..de2e025 100644 --- a/src/bin/ephoto.h +++ b/src/bin/ephoto.h @@ -83,6 +83,8 @@ unsigned int *flip_horizontal(Ewl_Widget *image); unsigned int *flip_vertical(Ewl_Widget *image); unsigned int *rotate_left(Ewl_Widget *image); unsigned int *rotate_right(Ewl_Widget *image); +unsigned int *blur_image(Ewl_Widget *image); +unsigned int *sharpen_image(Ewl_Widget *image); void update_image(Ewl_Widget *image, int w, int h, unsigned int *data); void save_dialog(const char *file); diff --git a/src/bin/ephoto_edit_view.c b/src/bin/ephoto_edit_view.c index 085cc21..271e74d 100644 --- a/src/bin/ephoto_edit_view.c +++ b/src/bin/ephoto_edit_view.c @@ -2,12 +2,15 @@ /*Ephoto Image Manipulation*/ static void add_standard_edit_tools(Ewl_Widget *c); +static void add_advanced_edit_tools(Ewl_Widget *c); static void previous_image(Ewl_Widget *w, void *event, void *data); static void next_image(Ewl_Widget *w, void *event, void *data); static void flip_image_horizontal(Ewl_Widget *w, void *event, void *data); static void flip_image_vertical(Ewl_Widget *w, void *event, void *data); static void rotate_image_left(Ewl_Widget *w, void *event, void *data); static void rotate_image_right(Ewl_Widget *w, void *event, void *data); +static void image_blur(Ewl_Widget *w, void *event, void *data); +static void image_sharpen(Ewl_Widget *w, void *event, void *data); /*Add the edit view*/ Ewl_Widget *add_edit_view(Ewl_Widget *c) @@ -37,6 +40,8 @@ Ewl_Widget *add_edit_view(Ewl_Widget *c) ewl_object_fill_policy_set(EWL_OBJECT(advanced), EWL_FLAG_FILL_VFILL); ewl_notebook_page_tab_text_set(EWL_NOTEBOOK(nb), advanced, "Advanced Tools"); + add_advanced_edit_tools(advanced); + vbox = add_box(hbox, EWL_ORIENTATION_VERTICAL, 0); ewl_object_fill_policy_set(EWL_OBJECT(vbox), EWL_FLAG_FILL_ALL); @@ -101,6 +106,24 @@ static void add_standard_edit_tools(Ewl_Widget *c) return; } +/* Add advanced edit tools */ +static void add_advanced_edit_tools(Ewl_Widget *c) +{ + Ewl_Widget *button; + + button = add_button(c, "Blur Image", PACKAGE_DATA_DIR "", image_blur, NULL); + ewl_button_image_size_set(EWL_BUTTON(button), 30, 30); + ewl_object_alignment_set(EWL_OBJECT(button), EWL_FLAG_ALIGN_LEFT); + ewl_object_fill_policy_set(EWL_OBJECT(button), EWL_FLAG_FILL_HFILL); + + button = add_button(c, "Sharpen Image", PACKAGE_DATA_DIR "", image_sharpen, NULL); + ewl_button_image_size_set(EWL_BUTTON(button), 30, 30); + ewl_object_alignment_set(EWL_OBJECT(button), EWL_FLAG_ALIGN_LEFT); + ewl_object_fill_policy_set(EWL_OBJECT(button), EWL_FLAG_FILL_HFILL); + + return; +} + /*Go to the previous image*/ static void previous_image(Ewl_Widget *w, void *event, void *data) { @@ -113,9 +136,9 @@ static void previous_image(Ewl_Widget *w, void *event, void *data) ecore_dlist_goto_last(em->images); image = ecore_dlist_current(em->images); } - ewl_image_file_path_set(EWL_IMAGE(em->eimage), image); - ewl_widget_configure(em->eimage->parent); - + ewl_image_file_path_set(EWL_IMAGE(em->eimage), image); + ewl_widget_configure(em->eimage->parent); + return; } @@ -134,17 +157,18 @@ static void next_image(Ewl_Widget *w, void *event, void *data) } ewl_image_file_path_set(EWL_IMAGE(em->eimage), image); ewl_widget_configure(em->eimage->parent); - + return; } /*Flip the image 180 degrees horizontally*/ static void flip_image_horizontal(Ewl_Widget *w, void *event, void *data) { + unsigned int *image_data; int nw, nh; Ewl_Image *image; - + evas_object_image_size_get(EWL_IMAGE(em->eimage)->image, &nw, &nh); image_data = flip_horizontal(em->eimage); update_image(em->eimage, nw, nh, image_data); @@ -171,7 +195,7 @@ static void flip_image_vertical(Ewl_Widget *w, void *event, void *data) ewl_image_size_set(EWL_IMAGE(em->eimage), nh, nw); image = (Ewl_Image *)em->eimage; image->ow = nw; - image->oh = nh; + image->oh = nh; ewl_object_preferred_inner_size_set(EWL_OBJECT(em->eimage), nh, nw); ewl_widget_configure(em->eimage->parent); @@ -194,7 +218,7 @@ static void rotate_image_left(Ewl_Widget *w, void *event, void *data) image->oh = nh; ewl_object_preferred_inner_size_set(EWL_OBJECT(em->eimage), nw, nh); ewl_widget_configure(em->eimage->parent); - + return; } @@ -204,16 +228,44 @@ static void rotate_image_right(Ewl_Widget *w, void *event, void *data) unsigned int *image_data; int nw, nh; Ewl_Image *image; - + evas_object_image_size_get(EWL_IMAGE(em->eimage)->image, &nh, &nw); image_data = rotate_right(em->eimage); update_image(em->eimage, nw, nh, image_data); image = (Ewl_Image *)em->eimage; - image->ow = nw; - image->oh = nh; - ewl_object_preferred_inner_size_set(EWL_OBJECT(em->eimage), nw, nh); + image->ow = nw; + image->oh = nh; + ewl_object_preferred_inner_size_set(EWL_OBJECT(em->eimage), nw, nh); ewl_widget_configure(em->eimage->parent); return; } +/* Blur the image*/ +static void image_blur(Ewl_Widget *w, void *event, void *data) +{ + unsigned int *image_data; + int nw, nh; + + evas_object_image_size_get(EWL_IMAGE(em->eimage)->image, &nw, &nh); + image_data = blur_image(em->eimage); + update_image(em->eimage, nw, nh, image_data); + ewl_widget_configure(em->eimage->parent); + + return; +} + +/* Sharpen the image*/ +static void image_sharpen(Ewl_Widget *w, void *event, void *data) +{ + unsigned int *image_data; + int nw, nh; + + evas_object_image_size_get(EWL_IMAGE(em->eimage)->image, &nw, &nh); + image_data = sharpen_image(em->eimage); + update_image(em->eimage, nw, nh, image_data); + ewl_widget_configure(em->eimage->parent); + + return; +} + diff --git a/src/bin/ephoto_imaging.c b/src/bin/ephoto_imaging.c index a4f1266..484be6f 100644 --- a/src/bin/ephoto_imaging.c +++ b/src/bin/ephoto_imaging.c @@ -127,6 +127,157 @@ unsigned int *rotate_right(Ewl_Widget *image) return im_data_new; } +unsigned int *blur_image(Ewl_Widget *image) +{ + unsigned int *im_data, *im_data_new, *p1, *p2; + int rad = 2; + int x, y, w, h, mx, my, mw, mh, mt, xx, yy; + int a, r, g, b; + int *as, *rs, *gs, *bs; + + im_data = evas_object_image_data_get(EWL_IMAGE(image)->image, FALSE); + evas_object_image_size_get(EWL_IMAGE(image)->image, &w, &h); + + im_data_new = malloc(sizeof(unsigned int) * w * h); + as = malloc(sizeof(int) * w); + rs = malloc(sizeof(int) * w); + gs = malloc(sizeof(int) * w); + bs = malloc(sizeof(int) * w); + + for (y = 0; y < h; y++) + { + my = y - rad; + mh = (rad << 1) + 1; + if (my < 0) + { + mh += my; + my = 0; + } + if ((my + mh) > h) + { + mh = h - my; + } + p1 = im_data_new + (y * w); + memset(as, 0, w * sizeof(int)); + memset(rs, 0, w * sizeof(int)); + memset(gs, 0, w * sizeof(int)); + memset(bs, 0, w * sizeof(int)); + + for (yy = 0; yy < mh; yy++) + { + p2 = im_data + ((yy + my) * w); + for (x = 0; x < w; x++) + { + as[x] += (*p2 >> 24) & 0xff; + rs[x] += (*p2 >> 16) & 0xff; + gs[x] += (*p2 >> 8) & 0xff; + bs[x] += *p2 & 0xff; + p2++; + } + } + if (w > ((rad << 1) + 1)) + { + for (x = 0; x < w; x++) + { + a = 0; + r = 0; + g = 0; + b = 0; + mx = x - rad; + mw = (rad << 1) + 1; + if (mx < 0) + { + mw += mx; + mx = 0; + } + if ((mx + mw) > w) + { + mw = w - mx; + } + mt = mw * mh; + for (xx = mx; xx < (mw + mx); xx++) + { + a += as[xx]; + r += rs[xx]; + g += gs[xx]; + b += bs[xx]; + } + a = a / mt; + r = r / mt; + g = g / mt; + b = b / mt; + *p1 = (a << 24) | (r << 16) | (g << 8) | b; + p1 ++; + } + } + } + free(as); + free(rs); + free(gs); + free(bs); + + return im_data_new; +} + +unsigned int *sharpen_image(Ewl_Widget *image) +{ + unsigned int *im_data, *im_data_new, *p1, *p2; + int a, r, g, b, x, y, w, h; + int mul, mul2, tot; + int rad = 2; + + im_data = evas_object_image_data_get(EWL_IMAGE(image)->image, FALSE); + evas_object_image_size_get(EWL_IMAGE(image)->image, &w, &h); + + im_data_new = malloc(sizeof(unsigned int) * w * h); + + mul = (rad * 4) + 1; + mul2 = rad; + tot = mul - (mul2 * 4); + for (y = 1; y < (h - 1); y ++) + { + p1 = im_data + 1 + (y * w); + p2 = im_data_new + 1 + (y * w); + for (x = 1; x < (w - 1); x++) + { + b = (int)((p1[0]) & 0xff) * 5; + g = (int)((p1[0] >> 8) & 0xff) * 5; + r = (int)((p1[0] >> 16) & 0xff) * 5; + a = (int)((p1[0] >> 24) & 0xff) * 5; + b -= (int)((p1[-1]) & 0xff); + g -= (int)((p1[-1] >> 8) & 0xff); + r -= (int)((p1[-1] >> 16) & 0xff); + a -= (int)((p1[-1] >> 24) & 0xff); + b -= (int)((p1[1]) & 0xff); + g -= (int)((p1[1] >> 8) & 0xff); + r -= (int)((p1[1] >> 16) & 0xff); + a -= (int)((p1[1] >> 24) & 0xff); + b -= (int)((p1[-w]) & 0xff); + g -= (int)((p1[-w] >> 8) & 0xff); + r -= (int)((p1[-w] >> 16) & 0xff); + a -= (int)((p1[-w] >> 24) & 0xff); + b -= (int)((p1[-w]) & 0xff); + g -= (int)((p1[-w] >> 8) & 0xff); + r -= (int)((p1[-w] >> 16) & 0xff); + a -= (int)((p1[-w] >> 24) & 0xff); + + a = (a & ((~a) >> 16)); + a = ((a | ((a & 256) - ((a & 256) >> 8)))); + r = (r & ((~r) >> 16)); + r = ((r | ((r & 256) - ((r & 256) >> 8)))); + g = (g & ((~g) >> 16)); + g = ((g | ((g & 256) - ((g & 256) >> 8)))); + b = (b & ((~b) >> 16)); + b = ((b | ((b & 256) - ((b & 256) >> 8)))); + + *p2 = (a << 24) | (r << 16) | (g << 8) | b; + p2++; + p1++; + } + } + return im_data_new; +} + void update_image(Ewl_Widget *image, int w, int h, unsigned int *data) { if (w && h && !data)