Enlightenment CVS committal Author : titan Project : e17 Module : apps/ephoto
Dir : e17/apps/ephoto/src/bin Modified Files: ephoto.h ephoto_edit_view.c ephoto_imaging.c Log Message: Fix black and white conversion with alpha. Add the beginnings of sepia conversion, it does not work quite right yet though, need to work on constrast and brightness functions to get it working perfectly. =================================================================== RCS file: /cvs/e/e17/apps/ephoto/src/bin/ephoto.h,v retrieving revision 1.22 retrieving revision 1.23 diff -u -3 -r1.22 -r1.23 --- ephoto.h 22 May 2007 23:04:02 -0000 1.22 +++ ephoto.h 23 May 2007 22:02:56 -0000 1.23 @@ -16,6 +16,7 @@ #include <libgen.h> #include <limits.h> +#include <math.h> #include <sqlite3.h> #include <stdio.h> #include <stdlib.h> @@ -86,6 +87,7 @@ unsigned int *blur_image(Ewl_Widget *image); unsigned int *sharpen_image(Ewl_Widget *image); unsigned int *grayscale_image(Ewl_Widget *image); +unsigned int *sepia_image(Ewl_Widget *image); void update_image(Ewl_Widget *image, int w, int h, unsigned int *data); void save_dialog(const char *file); =================================================================== RCS file: /cvs/e/e17/apps/ephoto/src/bin/ephoto_edit_view.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -3 -r1.22 -r1.23 --- ephoto_edit_view.c 22 May 2007 23:04:02 -0000 1.22 +++ ephoto_edit_view.c 23 May 2007 22:02:56 -0000 1.23 @@ -15,6 +15,7 @@ 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); +static void image_sepia(Ewl_Widget *w, void *event, void *data); /*Add the edit view*/ Ewl_Widget *add_edit_view(Ewl_Widget *c) @@ -145,6 +146,11 @@ 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, "Sepia", NULL, image_sepia, 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; } @@ -332,3 +338,18 @@ return; } + +/*Convert image to Sepia*/ +static void image_sepia(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 = sepia_image(em->eimage); + update_image(em->eimage, nw, nh, image_data); + ewl_widget_configure(em->eimage->parent); + + return; +} + =================================================================== RCS file: /cvs/e/e17/apps/ephoto/src/bin/ephoto_imaging.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -3 -r1.12 -r1.13 --- ephoto_imaging.c 22 May 2007 23:04:02 -0000 1.12 +++ ephoto_imaging.c 23 May 2007 22:02:56 -0000 1.13 @@ -1,5 +1,8 @@ #include "ephoto.h" +static void rgb_to_hsv(int r, int g, int b, float *h, float *s, float *v); +static void hsv_to_rgb(float h, float s, float v, int *r, int *g, int *b); + static void close_dialog(Ewl_Widget *w, void *event, void *data); static void close_progress(Ewl_Widget *w, void *event, void *data); static void save_clicked(Ewl_Widget *w, void *event, void *data); @@ -7,6 +10,110 @@ static Ewl_Widget *save_win, *qseek; +static void rgb_to_hsv(int r, int g, int b, float *h, float *s, float *v) +{ + int delta, min, max; + + max = (r + g + abs(r - g)) / 2; + max = (max + b + abs(max - b)) / 2; + min = (r + g - abs(r - g)) / 2; + min = (min + b - abs(min - b)) / 2; + + delta = max - min; + *v = (float)(100 * max) / 255.0; + + if (max != 0) *s = (float)(100 * delta) / (float)max; + + else + { + *s = 0.0; + *h = 0.0; + *v = 0.0; + } + + if (r == max) *h = (float)(100 * (g - b)) / (float)(6.0 * delta); + + else + { + if (g == max) *h = (float)(100 * (2 * delta + b - r)) / (float)(6.0 * delta); + else *h = (float)(100 * (4 * delta + r - g)) / (float)(6.0 * delta); + } + if (*h < 0.0) *h += 100.0; + if (*h > 100.0) *h -= 100.0; + + return; +} + +static void hsv_to_rgb(float h, float s, float v, int *r, int *g, int *b) +{ + float hh, f, p, q, t; + int i; + + if (s == 0.0) + { + *r = (int)(((v * 255.0) / 100.0) + 0.5); + *g = (int)(((v * 255.0) / 100.0) + 0.5); + *b = (int)(((v * 255.0) / 100.0) + 0.5); + + return; + } + + hh = (h * 6.0) / 100.0; + i = floor(hh); + f = hh - (float)i; + + p = v * (1.0 - s / 100.0) / 100.0; + q = v * (1.0 - (s * f) / 100.0) / 100.0; + t = v * (1.0 - s * (1.0 - f) / 100.0) / 100.0; + + switch (i) + { + case 0: + { + *r = (int)((v * 255.0 / 100.0) + 0.5); + *g = (int)((t * 255.0) + 0.5); + *b = (int)((p * 255.0) + 0.5); + break; + } + case 1: + { + *r = (int)((q * 255.0) + 0.5); + *g = (int)((v * 255.0 / 100.0) + 0.5); + *b = (int)((p * 255.0) + 0.5); + break; + } + case 2: + { + *r = (int)((p * 255.0) + 0.5); + *g = (int)((v * 255.0 / 100.0) + 0.5); + *b = (int)((t * 255.0) + 0.5); + break; + } + case 3: + { + *r = (int)((p * 255.0) + 0.5); + *g = (int)((q * 255.0) + 0.5); + *b = (int)((v * 255.0 / 100.0) + 0.5); + break; + } + case 4: + { + *r = (int)((t * 255.0) + 0.5); + *g = (int)((p * 255.0) + 0.5); + *b = (int)((v * 255.0 / 100.0) + 0.5); + break; + } + case 5: + { + *r = (int)((v * 255.0 / 100.0) + 0.5); + *g = (int)((p * 255.0) + 0.5); + *b = (int)((q * 255.0) + 0.5); + break; + } + } + return; +} + unsigned int *flip_horizontal(Ewl_Widget *image) { unsigned int *im_data, *im_data_new; @@ -299,11 +406,37 @@ gray = (int)((0.3 * r) + (0.59 * g) + (0.11 * b)); - im_data_new[i] = (gray << 24) | (gray << 16) | (gray << 8) | gray; + im_data_new[i] = (a << 24) | (gray << 16) | (gray << 8) | gray; } return im_data_new; } +unsigned int *sepia_image(Ewl_Widget *image) +{ + unsigned int *im_data, *im_data_new; + int i, r, g, b, a, ew, eh; + float h, s, v; + + 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); + + rgb_to_hsv(r, g, b, &h, &s, &v); + hsv_to_rgb(25, s, v, &r, &g, &b); + + im_data_new[i] = (a << 24) | (r << 16) | (g << 8) | b; + } + return im_data_new; +} + void update_image(Ewl_Widget *image, int w, int h, unsigned int *data) { if (w && h && !data) @@ -344,11 +477,11 @@ snprintf(flags, PATH_MAX, "compress=%i", (int)ewl_range_value_get(EWL_RANGE(qseek))); } - if (!strncmp(ext, "jpg", 3) || !strncmp(ext, "jpeg", 4)) + else { double svalue; float jvalue; - + svalue = ewl_range_value_get(EWL_RANGE(qseek)); jvalue = (svalue / 9) * 100; ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs