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. SVN revision: 30060
This commit is contained in:
parent
3997b3374c
commit
046f7d8274
|
@ -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 *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);
|
||||
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);
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ 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);
|
||||
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 @@ 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, "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 @@ static void image_grayscale(Ewl_Widget *w, void *event, void *data)
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 void save_image(Ewl_Widget *w, void *event, void *data);
|
|||
|
||||
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,7 +406,33 @@ unsigned int *grayscale_image(Ewl_Widget *image)
|
|||
|
||||
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;
|
||||
}
|
||||
|
@ -344,7 +477,7 @@ static void save_image(Ewl_Widget *w, void *event, void *data)
|
|||
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;
|
||||
|
|
Loading…
Reference in New Issue