Add blur/sharpen options to ephoto!!!!!

SVN revision: 29955
This commit is contained in:
titan 2007-05-11 22:49:31 +00:00 committed by titan
parent 6b65a43b86
commit cd77e7fcf7
3 changed files with 216 additions and 11 deletions

View File

@ -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);

View File

@ -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)
{
@ -141,6 +164,7 @@ static void next_image(Ewl_Widget *w, void *event, void *data)
/*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;
@ -217,3 +241,31 @@ static void rotate_image_right(Ewl_Widget *w, void *event, void *data)
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;
}

View File

@ -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)