Ephoto can now convert images to black and white. The filter is under

the
advanced tools in the edit view.


SVN revision: 30055
This commit is contained in:
titan 2007-05-22 23:04:02 +00:00 committed by titan
parent b294b27b58
commit 3997b3374c
3 changed files with 44 additions and 0 deletions

View File

@ -85,6 +85,7 @@ 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);
unsigned int *grayscale_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

@ -14,6 +14,7 @@ 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);
static void image_grayscale(Ewl_Widget *w, void *event, void *data);
/*Add the edit view*/
Ewl_Widget *add_edit_view(Ewl_Widget *c)
@ -139,6 +140,11 @@ static void add_advanced_edit_tools(Ewl_Widget *c)
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, "Black and White", NULL, image_grayscale, 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;
}
@ -313,3 +319,16 @@ static void image_sharpen(Ewl_Widget *w, void *event, void *data)
return;
}
/*Convert image to Black and White*/
static void image_grayscale(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 = grayscale_image(em->eimage);
update_image(em->eimage, nw, nh, image_data);
ewl_widget_configure(em->eimage->parent);
return;
}

View File

@ -280,6 +280,30 @@ unsigned int *sharpen_image(Ewl_Widget *image)
return im_data_new;
}
unsigned int *grayscale_image(Ewl_Widget *image)
{
unsigned int *im_data, *im_data_new;
int gray, i, r, g, b, a, ew, eh;
im_data = evas_object_image_data_get(EWL_IMAGE(image)->image, FALSE);
evas_object_image_size_get(EWL_IMAGE(image)->image, &ew, &eh);
im_data_new = malloc(sizeof(unsigned int) * ew * eh);
for (i = 0; i < (ew * eh); i++)
{
b = (int)((im_data[i]) & 0xff);
g = (int)((im_data[i] >> 8) & 0xff);
r = (int)((im_data[i] >> 16) & 0xff);
a = (int)((im_data[i] >> 24) & 0xff);
gray = (int)((0.3 * r) + (0.59 * g) + (0.11 * b));
im_data_new[i] = (gray << 24) | (gray << 16) | (gray << 8) | gray;
}
return im_data_new;
}
void update_image(Ewl_Widget *image, int w, int h, unsigned int *data)
{
if (w && h && !data)