Ephoto: Add auto histogram equalization filter. Clean up some code.
This commit is contained in:
parent
76cfa1d52c
commit
fba9a17b48
|
@ -78,6 +78,7 @@ void ephoto_filter_blur(Evas_Object *main, Evas_Object *image);
|
||||||
void ephoto_filter_sharpen(Evas_Object *main, Evas_Object *image);
|
void ephoto_filter_sharpen(Evas_Object *main, Evas_Object *image);
|
||||||
void ephoto_filter_black_and_white(Evas_Object *main, Evas_Object *image);
|
void ephoto_filter_black_and_white(Evas_Object *main, Evas_Object *image);
|
||||||
void ephoto_filter_old_photo(Evas_Object *main, Evas_Object *image);
|
void ephoto_filter_old_photo(Evas_Object *main, Evas_Object *image);
|
||||||
|
void ephoto_filter_histogram_eq(Evas_Object *main, Evas_Object *image);
|
||||||
|
|
||||||
enum _Ephoto_State
|
enum _Ephoto_State
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,12 +17,41 @@ struct _Ephoto_BCG
|
||||||
unsigned int *original_im_data;
|
unsigned int *original_im_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int
|
||||||
|
_normalize_color(int color)
|
||||||
|
{
|
||||||
|
if (color < 0)
|
||||||
|
return 0;
|
||||||
|
else if (color > 255)
|
||||||
|
return 255;
|
||||||
|
else
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
_mul_color_alpha(int color, int alpha)
|
||||||
|
{
|
||||||
|
if (alpha > 0 && alpha < 255)
|
||||||
|
return (color * (255 / alpha));
|
||||||
|
else
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
_demul_color_alpha(int color, int alpha)
|
||||||
|
{
|
||||||
|
if (alpha > 0 && alpha < 255)
|
||||||
|
return ((color * alpha) / 255);
|
||||||
|
else
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int *
|
unsigned int *
|
||||||
_ephoto_bcg_adjust_brightness(Ephoto_BCG *ebcg, int brightness, unsigned int *image_data)
|
_ephoto_bcg_adjust_brightness(Ephoto_BCG *ebcg, int brightness, unsigned int *image_data)
|
||||||
{
|
{
|
||||||
unsigned int *im_data, *im_data_new, *p1, *p2;
|
unsigned int *im_data, *im_data_new, *p1, *p2;
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
int a, r, g, b, nb, ng, nr;
|
int a, r, g, b, bb, gg, rr;
|
||||||
|
|
||||||
im_data = malloc(sizeof(unsigned int) * ebcg->w * ebcg->h);
|
im_data = malloc(sizeof(unsigned int) * ebcg->w * ebcg->h);
|
||||||
if (image_data)
|
if (image_data)
|
||||||
|
@ -43,28 +72,19 @@ _ephoto_bcg_adjust_brightness(Ephoto_BCG *ebcg, int brightness, unsigned int *im
|
||||||
g = (int)((*p1 >> 8) & 0xff);
|
g = (int)((*p1 >> 8) & 0xff);
|
||||||
r = (int)((*p1 >> 16) & 0xff);
|
r = (int)((*p1 >> 16) & 0xff);
|
||||||
a = (int)((*p1 >> 24) & 0xff);
|
a = (int)((*p1 >> 24) & 0xff);
|
||||||
if (a > 0 && a < 255)
|
b = _mul_color_alpha(b, a);
|
||||||
{
|
g = _mul_color_alpha(g, a);
|
||||||
b = b * (255 / a);
|
r = _mul_color_alpha(r, a);
|
||||||
g = g * (255 / a);
|
bb = (int)b+ebcg->brightness;
|
||||||
r = r * (255 / a);
|
gg = (int)g+ebcg->brightness;
|
||||||
}
|
rr = (int)r+ebcg->brightness;
|
||||||
nb = (int)b+ebcg->brightness;
|
bb = _normalize_color(bb);
|
||||||
ng = (int)g+ebcg->brightness;
|
gg = _normalize_color(gg);
|
||||||
nr = (int)r+ebcg->brightness;
|
rr = _normalize_color(rr);
|
||||||
if (nb < 0) nb = 0;
|
bb = _demul_color_alpha(bb, a);
|
||||||
if (nb > 255) nb = 255;
|
gg = _demul_color_alpha(gg, a);
|
||||||
if (ng < 0) ng = 0;
|
rr = _demul_color_alpha(rr, a);
|
||||||
if (ng > 255) ng = 255;
|
*p2 = (a << 24) | (rr << 16) | (gg << 8) | bb;
|
||||||
if (nr < 0) nr = 0;
|
|
||||||
if (nr > 255) nr = 255;
|
|
||||||
if (a > 0 && a < 255)
|
|
||||||
{
|
|
||||||
nb = (nb * a) / 255;
|
|
||||||
ng = (ng * a) / 255;
|
|
||||||
nr = (nr * a) / 255;
|
|
||||||
}
|
|
||||||
*p2 = (a << 24) | (nr << 16) | (ng << 8) | nb;
|
|
||||||
p2++;
|
p2++;
|
||||||
p1++;
|
p1++;
|
||||||
}
|
}
|
||||||
|
@ -79,7 +99,7 @@ _ephoto_bcg_adjust_contrast(Ephoto_BCG *ebcg, int contrast, unsigned int *image_
|
||||||
{
|
{
|
||||||
unsigned int *im_data, *im_data_new, *p1, *p2;
|
unsigned int *im_data, *im_data_new, *p1, *p2;
|
||||||
int x, y, w, h, top, bottom;
|
int x, y, w, h, top, bottom;
|
||||||
int a, r, g, b, nb, ng, nr;
|
int a, r, g, b, bb, gg, rr;
|
||||||
float factor;
|
float factor;
|
||||||
|
|
||||||
im_data = malloc(sizeof(unsigned int) * ebcg->w * ebcg->h);
|
im_data = malloc(sizeof(unsigned int) * ebcg->w * ebcg->h);
|
||||||
|
@ -104,28 +124,19 @@ _ephoto_bcg_adjust_contrast(Ephoto_BCG *ebcg, int contrast, unsigned int *image_
|
||||||
g = (int)((*p1 >> 8) & 0xff);
|
g = (int)((*p1 >> 8) & 0xff);
|
||||||
r = (int)((*p1 >> 16) & 0xff);
|
r = (int)((*p1 >> 16) & 0xff);
|
||||||
a = (int)((*p1 >> 24) & 0xff);
|
a = (int)((*p1 >> 24) & 0xff);
|
||||||
if (a > 0 && a < 255)
|
b = _mul_color_alpha(b, a);
|
||||||
{
|
g = _mul_color_alpha(g, a);
|
||||||
b = b * (255 / a);
|
r = _mul_color_alpha(r, a);
|
||||||
g = g * (255 / a);
|
bb = (int)((factor * (b - 128)) + 128);
|
||||||
r = r * (255 / a);
|
gg = (int)((factor * (g - 128)) + 128);
|
||||||
}
|
rr = (int)((factor * (r - 128)) + 128);
|
||||||
nb = (int)((factor * (b - 128)) + 128);
|
bb = _normalize_color(bb);
|
||||||
ng = (int)((factor * (g - 128)) + 128);
|
gg = _normalize_color(gg);
|
||||||
nr = (int)((factor * (r - 128)) + 128);
|
rr = _normalize_color(rr);
|
||||||
if (nb < 0) nb = 0;
|
bb = _demul_color_alpha(bb, a);
|
||||||
if (nb > 255) nb = 255;
|
gg = _demul_color_alpha(gg, a);
|
||||||
if (ng < 0) ng = 0;
|
rr = _demul_color_alpha(rr, a);
|
||||||
if (ng > 255) ng = 255;
|
*p2 = (a << 24) | (rr << 16) | (gg << 8) | bb;
|
||||||
if (nr < 0) nr = 0;
|
|
||||||
if (nr > 255) nr = 255;
|
|
||||||
if (a > 0 && a < 255)
|
|
||||||
{
|
|
||||||
nb = (nb * a) / 255;
|
|
||||||
ng = (ng * a) / 255;
|
|
||||||
nr = (nr * a) / 255;
|
|
||||||
}
|
|
||||||
*p2 = (a << 24) | (nr << 16) | (ng << 8) | nb;
|
|
||||||
p2++;
|
p2++;
|
||||||
p1++;
|
p1++;
|
||||||
}
|
}
|
||||||
|
@ -140,7 +151,7 @@ _ephoto_bcg_adjust_gamma(Ephoto_BCG *ebcg, double gamma, unsigned int *image_dat
|
||||||
{
|
{
|
||||||
unsigned int *im_data, *im_data_new, *p1, *p2;
|
unsigned int *im_data, *im_data_new, *p1, *p2;
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
int a, r, g, b, nb, ng, nr;
|
int a, r, g, b, bb, gg, rr;
|
||||||
|
|
||||||
im_data = malloc(sizeof(unsigned int) * ebcg->w * ebcg->h);
|
im_data = malloc(sizeof(unsigned int) * ebcg->w * ebcg->h);
|
||||||
if (image_data)
|
if (image_data)
|
||||||
|
@ -161,28 +172,19 @@ _ephoto_bcg_adjust_gamma(Ephoto_BCG *ebcg, double gamma, unsigned int *image_dat
|
||||||
g = (int)((*p1 >> 8) & 0xff);
|
g = (int)((*p1 >> 8) & 0xff);
|
||||||
r = (int)((*p1 >> 16) & 0xff);
|
r = (int)((*p1 >> 16) & 0xff);
|
||||||
a = (int)((*p1 >> 24) & 0xff);
|
a = (int)((*p1 >> 24) & 0xff);
|
||||||
if (a > 0 && a < 255)
|
b = _mul_color_alpha(b, a);
|
||||||
{
|
g = _mul_color_alpha(g, a);
|
||||||
b = b * (255 / a);
|
r = _mul_color_alpha(r, a);
|
||||||
g = g * (255 / a);
|
bb = (int)(pow(((double)b/255), ebcg->gamma) * 255);
|
||||||
r = r * (255 / a);
|
gg = (int)(pow(((double)g/255), ebcg->gamma) * 255);
|
||||||
}
|
rr = (int)(pow(((double)r/255), ebcg->gamma) * 255);
|
||||||
nb = (int)(pow(((double)b/255), ebcg->gamma) * 255);
|
bb = _normalize_color(bb);
|
||||||
ng = (int)(pow(((double)g/255), ebcg->gamma) * 255);
|
gg = _normalize_color(gg);
|
||||||
nr = (int)(pow(((double)r/255), ebcg->gamma) * 255);
|
rr = _normalize_color(rr);
|
||||||
if (nb < 0) nb = 0;
|
bb = _demul_color_alpha(bb, a);
|
||||||
if (nb > 255) nb = 255;
|
gg = _demul_color_alpha(gg, a);
|
||||||
if (ng < 0) ng = 0;
|
rr = _demul_color_alpha(rr, a);
|
||||||
if (ng > 255) ng = 255;
|
*p2 = (a << 24) | (rr << 16) | (gg << 8) | bb;
|
||||||
if (nr < 0) nr = 0;
|
|
||||||
if (nr > 255) nr = 255;
|
|
||||||
if (a > 0 && a < 255)
|
|
||||||
{
|
|
||||||
nb = (nb * a) / 255;
|
|
||||||
ng = (ng * a) / 255;
|
|
||||||
nr = (nr * a) / 255;
|
|
||||||
}
|
|
||||||
*p2 = (a << 24) | (nr << 16) | (ng << 8) | nb;
|
|
||||||
p2++;
|
p2++;
|
||||||
p1++;
|
p1++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,34 @@
|
||||||
#include "ephoto.h"
|
#include "ephoto.h"
|
||||||
|
|
||||||
|
static int
|
||||||
|
_normalize_color(int color)
|
||||||
|
{
|
||||||
|
if (color < 0)
|
||||||
|
return 0;
|
||||||
|
else if (color > 255)
|
||||||
|
return 255;
|
||||||
|
else
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
_mul_color_alpha(int color, int alpha)
|
||||||
|
{
|
||||||
|
if (alpha > 0 && alpha < 255)
|
||||||
|
return (color * (255 / alpha));
|
||||||
|
else
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
_demul_color_alpha(int color, int alpha)
|
||||||
|
{
|
||||||
|
if (alpha > 0 && alpha < 255)
|
||||||
|
return ((color * alpha) / 255);
|
||||||
|
else
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ephoto_filter_blur(Evas_Object *main, Evas_Object *image)
|
ephoto_filter_blur(Evas_Object *main, Evas_Object *image)
|
||||||
{
|
{
|
||||||
|
@ -168,12 +197,9 @@ ephoto_filter_black_and_white(Evas_Object *main, Evas_Object *image)
|
||||||
g = (int)((im_data[i] >> 8) & 0xff);
|
g = (int)((im_data[i] >> 8) & 0xff);
|
||||||
r = (int)((im_data[i] >> 16) & 0xff);
|
r = (int)((im_data[i] >> 16) & 0xff);
|
||||||
a = (int)((im_data[i] >> 24) & 0xff);
|
a = (int)((im_data[i] >> 24) & 0xff);
|
||||||
if (a > 0 && a < 255)
|
b = _mul_color_alpha(b, a);
|
||||||
{
|
g = _mul_color_alpha(g, a);
|
||||||
b = b * (255 / a);
|
r = _mul_color_alpha(r, a);
|
||||||
g = g * (255 / a);
|
|
||||||
r = r * (255 / a);
|
|
||||||
}
|
|
||||||
gray = (int)((0.3 * r) + (0.59 * g) + (0.11 * b));
|
gray = (int)((0.3 * r) + (0.59 * g) + (0.11 * b));
|
||||||
if (a >= 0 && a < 255)
|
if (a >= 0 && a < 255)
|
||||||
gray = (gray * a) / 255;
|
gray = (gray * a) / 255;
|
||||||
|
@ -197,34 +223,89 @@ ephoto_filter_old_photo(Evas_Object *main, Evas_Object *image)
|
||||||
g = (int)((im_data[i] >> 8) & 0xff);
|
g = (int)((im_data[i] >> 8) & 0xff);
|
||||||
r = (int)((im_data[i] >> 16) & 0xff);
|
r = (int)((im_data[i] >> 16) & 0xff);
|
||||||
a = (int)((im_data[i] >> 24) & 0xff);
|
a = (int)((im_data[i] >> 24) & 0xff);
|
||||||
if (a > 0 && a < 255)
|
b = _mul_color_alpha(b, a);
|
||||||
{
|
g = _mul_color_alpha(g, a);
|
||||||
b = b * (255 / a);
|
r = _mul_color_alpha(r, a);
|
||||||
g = g * (255 / a);
|
|
||||||
r = r * (255 / a);
|
|
||||||
}
|
|
||||||
rr = (int)((r* .393) + (g*.769) + (b*.189));
|
rr = (int)((r* .393) + (g*.769) + (b*.189));
|
||||||
if (rr < 0)
|
rr = _normalize_color(rr);
|
||||||
rr = 0;
|
|
||||||
if (rr > 255)
|
|
||||||
rr = 255;
|
|
||||||
gg = (int)((r* .349) + (g*.686) + (b*.168));
|
gg = (int)((r* .349) + (g*.686) + (b*.168));
|
||||||
if (gg < 0)
|
gg = _normalize_color(gg);
|
||||||
gg = 0;
|
|
||||||
if (gg > 255)
|
|
||||||
gg = 255;
|
|
||||||
bb = (int)((r* .272) + (g*.534) + (b*.131));
|
bb = (int)((r* .272) + (g*.534) + (b*.131));
|
||||||
if (bb < 0)
|
bb = _normalize_color(bb);
|
||||||
bb = 0;
|
bb = _demul_color_alpha(bb, a);
|
||||||
if (bb > 255)
|
gg = _demul_color_alpha(gg, a);
|
||||||
bb = 255;
|
rr = _demul_color_alpha(rr, a);
|
||||||
if (a >= 0 && a < 255)
|
|
||||||
{
|
|
||||||
rr = (rr * a) / 255;
|
|
||||||
gg = (gg * a) / 255;
|
|
||||||
bb = (bb * a) / 255;
|
|
||||||
}
|
|
||||||
im_data_new[i] = (a << 24) | (rr << 16) | (gg << 8) | bb;
|
im_data_new[i] = (a << 24) | (rr << 16) | (gg << 8) | bb;
|
||||||
}
|
}
|
||||||
ephoto_single_browser_image_data_update(main, image, EINA_TRUE, im_data_new, w, h);
|
ephoto_single_browser_image_data_update(main, image, EINA_TRUE, im_data_new, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ephoto_filter_histogram_eq(Evas_Object *main, Evas_Object *image)
|
||||||
|
{
|
||||||
|
unsigned int *im_data, *im_data_new, *p1, *p2;
|
||||||
|
int x, y, w, h, i, hist[256], cdf[256];
|
||||||
|
int a, r, g, b, bb, gg, rr, norm, total;
|
||||||
|
float hh, s, v, nv, sum;
|
||||||
|
|
||||||
|
im_data = evas_object_image_data_get(elm_image_object_get(image), EINA_FALSE);
|
||||||
|
evas_object_image_size_get(elm_image_object_get(image), &w, &h);
|
||||||
|
im_data_new = malloc(sizeof(unsigned int) * w * h);
|
||||||
|
total = w * h;
|
||||||
|
for (i = 0; i < 256; i++)
|
||||||
|
hist[i] = 0;
|
||||||
|
for (y = 0; y < h; y++)
|
||||||
|
{
|
||||||
|
p1 = im_data + (y * w);
|
||||||
|
for (x = 0; x < w; x++)
|
||||||
|
{
|
||||||
|
b = (int)((*p1) & 0xff);
|
||||||
|
g = (int)((*p1 >> 8) & 0xff);
|
||||||
|
r = (int)((*p1 >> 16) & 0xff);
|
||||||
|
a = (int)((*p1 >> 24) & 0xff);
|
||||||
|
b = _mul_color_alpha(b, a);
|
||||||
|
g = _mul_color_alpha(g, a);
|
||||||
|
r = _mul_color_alpha(r, a);
|
||||||
|
evas_color_rgb_to_hsv(r, g, b, &hh, &s, &v);
|
||||||
|
norm = (int)round((double)v * (double)255);
|
||||||
|
hist[norm] += 1;
|
||||||
|
p1++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sum = 0;
|
||||||
|
for (i = 0; i < 256; i++)
|
||||||
|
{
|
||||||
|
sum += ((double)hist[i] / (double)total);
|
||||||
|
cdf[i] = (int)round(sum * 255);
|
||||||
|
}
|
||||||
|
for (y = 0; y < h; y++)
|
||||||
|
{
|
||||||
|
p1 = im_data + (y * w);
|
||||||
|
p2 = im_data_new + (y * w);
|
||||||
|
for (x = 0; x < w; x++)
|
||||||
|
{
|
||||||
|
b = (int)((*p1) & 0xff);
|
||||||
|
g = (int)((*p1 >> 8) & 0xff);
|
||||||
|
r = (int)((*p1 >> 16) & 0xff);
|
||||||
|
a = (int)((*p1 >> 24) & 0xff);
|
||||||
|
b = _mul_color_alpha(b, a);
|
||||||
|
g = _mul_color_alpha(g, a);
|
||||||
|
r = _mul_color_alpha(r, a);
|
||||||
|
evas_color_rgb_to_hsv(r, g, b, &hh, &s, &v);
|
||||||
|
norm = (int)round((double)v * (double)255);
|
||||||
|
nv = (float)cdf[norm] / (float)255;
|
||||||
|
evas_color_hsv_to_rgb(hh, s, nv, &rr, &gg, &bb);
|
||||||
|
bb = _normalize_color(bb);
|
||||||
|
gg = _normalize_color(gg);
|
||||||
|
rr = _normalize_color(rr);
|
||||||
|
bb = _demul_color_alpha(bb, a);
|
||||||
|
gg = _demul_color_alpha(gg, a);
|
||||||
|
rr = _demul_color_alpha(rr, a);
|
||||||
|
*p2 = (a << 24) | (rr << 16) | (gg << 8) | bb;
|
||||||
|
p2++;
|
||||||
|
p1++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ephoto_single_browser_image_data_update(main, image, EINA_TRUE, im_data_new, w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,41 @@ struct _Ephoto_HSV
|
||||||
unsigned int *original_im_data;
|
unsigned int *original_im_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int
|
||||||
|
_normalize_color(int color)
|
||||||
|
{
|
||||||
|
if (color < 0)
|
||||||
|
return 0;
|
||||||
|
else if (color > 255)
|
||||||
|
return 255;
|
||||||
|
else
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
_mul_color_alpha(int color, int alpha)
|
||||||
|
{
|
||||||
|
if (alpha > 0 && alpha < 255)
|
||||||
|
return (color * (255 / alpha));
|
||||||
|
else
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
_demul_color_alpha(int color, int alpha)
|
||||||
|
{
|
||||||
|
if (alpha > 0 && alpha < 255)
|
||||||
|
return ((color * alpha) / 255);
|
||||||
|
else
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int *
|
unsigned int *
|
||||||
_ephoto_hsv_adjust_hue(Ephoto_HSV *ehsv, double hue, unsigned int *image_data)
|
_ephoto_hsv_adjust_hue(Ephoto_HSV *ehsv, double hue, unsigned int *image_data)
|
||||||
{
|
{
|
||||||
unsigned int *im_data, *im_data_new, *p1, *p2;
|
unsigned int *im_data, *im_data_new, *p1, *p2;
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
int a, r, g, b, nb, ng, nr;
|
int a, r, g, b, bb, gg, rr;
|
||||||
float hh, s, v;
|
float hh, s, v;
|
||||||
|
|
||||||
im_data = malloc(sizeof(unsigned int) * ehsv->w * ehsv->h);
|
im_data = malloc(sizeof(unsigned int) * ehsv->w * ehsv->h);
|
||||||
|
@ -43,32 +72,23 @@ _ephoto_hsv_adjust_hue(Ephoto_HSV *ehsv, double hue, unsigned int *image_data)
|
||||||
g = (int)((*p1 >> 8) & 0xff);
|
g = (int)((*p1 >> 8) & 0xff);
|
||||||
r = (int)((*p1 >> 16) & 0xff);
|
r = (int)((*p1 >> 16) & 0xff);
|
||||||
a = (int)((*p1 >> 24) & 0xff);
|
a = (int)((*p1 >> 24) & 0xff);
|
||||||
if (a > 0 && a < 255)
|
b = _mul_color_alpha(b, a);
|
||||||
{
|
g = _mul_color_alpha(g, a);
|
||||||
b = b * (255 / a);
|
r = _mul_color_alpha(r, a);
|
||||||
g = g * (255 / a);
|
|
||||||
r = r * (255 / a);
|
|
||||||
}
|
|
||||||
evas_color_rgb_to_hsv(r, g, b, &hh, &s, &v);
|
evas_color_rgb_to_hsv(r, g, b, &hh, &s, &v);
|
||||||
hh += hue;
|
hh += hue;
|
||||||
if (hh < 0)
|
if (hh < 0)
|
||||||
hh += 360;
|
hh += 360;
|
||||||
if (hh > 360)
|
if (hh > 360)
|
||||||
hh -= 360;
|
hh -= 360;
|
||||||
evas_color_hsv_to_rgb(hh, s, v, &nr, &ng, &nb);
|
evas_color_hsv_to_rgb(hh, s, v, &rr, &gg, &bb);
|
||||||
if (nb < 0) nb = 0;
|
bb = _normalize_color(bb);
|
||||||
if (nb > 255) nb = 255;
|
gg = _normalize_color(gg);
|
||||||
if (ng < 0) ng = 0;
|
rr = _normalize_color(rr);
|
||||||
if (ng > 255) ng = 255;
|
bb = _demul_color_alpha(bb, a);
|
||||||
if (nr < 0) nr = 0;
|
gg = _demul_color_alpha(gg, a);
|
||||||
if (nr > 255) nr = 255;
|
rr = _demul_color_alpha(rr, a);
|
||||||
if (a > 0 && a < 255)
|
*p2 = (a << 24) | (rr << 16) | (gg << 8) | bb;
|
||||||
{
|
|
||||||
nb = (nb * a) / 255;
|
|
||||||
ng = (ng * a) / 255;
|
|
||||||
nr = (nr * a) / 255;
|
|
||||||
}
|
|
||||||
*p2 = (a << 24) | (nr << 16) | (ng << 8) | nb;
|
|
||||||
p2++;
|
p2++;
|
||||||
p1++;
|
p1++;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +104,7 @@ _ephoto_hsv_adjust_saturation(Ephoto_HSV *ehsv, double saturation, unsigned int
|
||||||
{
|
{
|
||||||
unsigned int *im_data, *im_data_new, *p1, *p2;
|
unsigned int *im_data, *im_data_new, *p1, *p2;
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
int a, r, g, b, nb, ng, nr;
|
int a, r, g, b, bb, gg, rr;
|
||||||
float hh, s, v;
|
float hh, s, v;
|
||||||
|
|
||||||
im_data = malloc(sizeof(unsigned int) * ehsv->w * ehsv->h);
|
im_data = malloc(sizeof(unsigned int) * ehsv->w * ehsv->h);
|
||||||
|
@ -105,32 +125,23 @@ _ephoto_hsv_adjust_saturation(Ephoto_HSV *ehsv, double saturation, unsigned int
|
||||||
g = (int)((*p1 >> 8) & 0xff);
|
g = (int)((*p1 >> 8) & 0xff);
|
||||||
r = (int)((*p1 >> 16) & 0xff);
|
r = (int)((*p1 >> 16) & 0xff);
|
||||||
a = (int)((*p1 >> 24) & 0xff);
|
a = (int)((*p1 >> 24) & 0xff);
|
||||||
if (a > 0 && a < 255)
|
b = _mul_color_alpha(b, a);
|
||||||
{
|
g = _mul_color_alpha(g, a);
|
||||||
b = b * (255 / a);
|
r = _mul_color_alpha(r, a);
|
||||||
g = g * (255 / a);
|
|
||||||
r = r * (255 / a);
|
|
||||||
}
|
|
||||||
evas_color_rgb_to_hsv(r, g, b, &hh, &s, &v);
|
evas_color_rgb_to_hsv(r, g, b, &hh, &s, &v);
|
||||||
s += s*((float)saturation / 100);
|
s += s*((float)saturation / 100);
|
||||||
if (s < 0)
|
if (s < 0)
|
||||||
s = 0;
|
s = 0;
|
||||||
if (s > 1)
|
if (s > 1)
|
||||||
s = 1;
|
s = 1;
|
||||||
evas_color_hsv_to_rgb(hh, s, v, &nr, &ng, &nb);
|
evas_color_hsv_to_rgb(hh, s, v, &rr, &gg, &bb);
|
||||||
if (nb < 0) nb = 0;
|
bb = _normalize_color(bb);
|
||||||
if (nb > 255) nb = 255;
|
gg = _normalize_color(gg);
|
||||||
if (ng < 0) ng = 0;
|
rr = _normalize_color(rr);
|
||||||
if (ng > 255) ng = 255;
|
bb = _demul_color_alpha(bb, a);
|
||||||
if (nr < 0) nr = 0;
|
gg = _demul_color_alpha(gg, a);
|
||||||
if (nr > 255) nr = 255;
|
rr = _demul_color_alpha(rr, a);
|
||||||
if (a > 0 && a < 255)
|
*p2 = (a << 24) | (rr << 16) | (gg << 8) | bb;
|
||||||
{
|
|
||||||
nb = (nb * a) / 255;
|
|
||||||
ng = (ng * a) / 255;
|
|
||||||
nr = (nr * a) / 255;
|
|
||||||
}
|
|
||||||
*p2 = (a << 24) | (nr << 16) | (ng << 8) | nb;
|
|
||||||
p2++;
|
p2++;
|
||||||
p1++;
|
p1++;
|
||||||
}
|
}
|
||||||
|
@ -146,7 +157,7 @@ _ephoto_hsv_adjust_value(Ephoto_HSV *ehsv, double value, unsigned int *image_dat
|
||||||
{
|
{
|
||||||
unsigned int *im_data, *im_data_new, *p1, *p2;
|
unsigned int *im_data, *im_data_new, *p1, *p2;
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
int a, r, g, b, nb, ng, nr;
|
int a, r, g, b, bb, gg, rr;
|
||||||
float hh, s, v;
|
float hh, s, v;
|
||||||
|
|
||||||
im_data = malloc(sizeof(unsigned int) * ehsv->w * ehsv->h);
|
im_data = malloc(sizeof(unsigned int) * ehsv->w * ehsv->h);
|
||||||
|
@ -167,32 +178,23 @@ _ephoto_hsv_adjust_value(Ephoto_HSV *ehsv, double value, unsigned int *image_dat
|
||||||
g = (int)((*p1 >> 8) & 0xff);
|
g = (int)((*p1 >> 8) & 0xff);
|
||||||
r = (int)((*p1 >> 16) & 0xff);
|
r = (int)((*p1 >> 16) & 0xff);
|
||||||
a = (int)((*p1 >> 24) & 0xff);
|
a = (int)((*p1 >> 24) & 0xff);
|
||||||
if (a > 0 && a < 255)
|
b = _mul_color_alpha(b, a);
|
||||||
{
|
g = _mul_color_alpha(g, a);
|
||||||
b = b * (255 / a);
|
r = _mul_color_alpha(r, a);
|
||||||
g = g * (255 / a);
|
|
||||||
r = r * (255 / a);
|
|
||||||
}
|
|
||||||
evas_color_rgb_to_hsv(r, g, b, &hh, &s, &v);
|
evas_color_rgb_to_hsv(r, g, b, &hh, &s, &v);
|
||||||
v += (v*((float)value/100));
|
v += (v*((float)value/100));
|
||||||
if (v < 0)
|
if (v < 0)
|
||||||
v = 0;
|
v = 0;
|
||||||
if (v > 1)
|
if (v > 1)
|
||||||
v = 1;
|
v = 1;
|
||||||
evas_color_hsv_to_rgb(hh, s, v, &nr, &ng, &nb);
|
evas_color_hsv_to_rgb(hh, s, v, &rr, &gg, &bb);
|
||||||
if (nb < 0) nb = 0;
|
bb = _normalize_color(bb);
|
||||||
if (nb > 255) nb = 255;
|
gg = _normalize_color(gg);
|
||||||
if (ng < 0) ng = 0;
|
rr = _normalize_color(rr);
|
||||||
if (ng > 255) ng = 255;
|
bb = _demul_color_alpha(bb, a);
|
||||||
if (nr < 0) nr = 0;
|
gg = _demul_color_alpha(gg, a);
|
||||||
if (nr > 255) nr = 255;
|
rr = _demul_color_alpha(rr, a);
|
||||||
if (a > 0 && a < 255)
|
*p2 = (a << 24) | (rr << 16) | (gg << 8) | bb;
|
||||||
{
|
|
||||||
nb = (nb * a) / 255;
|
|
||||||
ng = (ng * a) / 255;
|
|
||||||
nr = (nr * a) / 255;
|
|
||||||
}
|
|
||||||
*p2 = (a << 24) | (nr << 16) | (ng << 8) | nb;
|
|
||||||
p2++;
|
p2++;
|
||||||
p1++;
|
p1++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1209,6 +1209,20 @@ _go_hsv(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_go_auto_eq(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||||
|
{
|
||||||
|
Ephoto_Single_Browser *sb = data;
|
||||||
|
if (sb->viewer)
|
||||||
|
{
|
||||||
|
sb->editing = EINA_TRUE;
|
||||||
|
elm_object_disabled_set(sb->bar, EINA_TRUE);
|
||||||
|
evas_object_freeze_events_set(sb->bar, EINA_TRUE);
|
||||||
|
Ephoto_Viewer *v = evas_object_data_get(sb->viewer, "viewer");
|
||||||
|
ephoto_filter_histogram_eq(sb->main, v->image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_go_blur(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
_go_blur(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||||
{
|
{
|
||||||
|
@ -1464,6 +1478,7 @@ ephoto_single_browser_add(Ephoto *ephoto, Evas_Object *parent)
|
||||||
elm_menu_item_add(menu, menu_it, "insert-image", _("Brightness/Contrast/Gamma"), _go_bcg, sb);
|
elm_menu_item_add(menu, menu_it, "insert-image", _("Brightness/Contrast/Gamma"), _go_bcg, sb);
|
||||||
elm_menu_item_add(menu, menu_it, "insert-image", _("Hue/Saturation/Value"), _go_hsv, sb);
|
elm_menu_item_add(menu, menu_it, "insert-image", _("Hue/Saturation/Value"), _go_hsv, sb);
|
||||||
menu_it = elm_menu_item_add(menu, NULL, "document-properties", _("Filters"), NULL, NULL);
|
menu_it = elm_menu_item_add(menu, NULL, "document-properties", _("Filters"), NULL, NULL);
|
||||||
|
elm_menu_item_add(menu, menu_it, "insert-image", _("Auto Equalize"), _go_auto_eq, sb);
|
||||||
elm_menu_item_add(menu, menu_it, "insert-image", _("Black and White"), _go_black_and_white, sb);
|
elm_menu_item_add(menu, menu_it, "insert-image", _("Black and White"), _go_black_and_white, sb);
|
||||||
elm_menu_item_add(menu, menu_it, "insert-image", _("Old Photo"), _go_old_photo, sb);
|
elm_menu_item_add(menu, menu_it, "insert-image", _("Old Photo"), _go_old_photo, sb);
|
||||||
/*FIXME: Use separators once they don't mess up homogeneous toolbar*/
|
/*FIXME: Use separators once they don't mess up homogeneous toolbar*/
|
||||||
|
@ -1536,9 +1551,13 @@ ephoto_single_browser_entry_set(Evas_Object *obj, Ephoto_Entry *entry)
|
||||||
ephoto_entry_free_listener_add(entry, _entry_free, sb);
|
ephoto_entry_free_listener_add(entry, _entry_free, sb);
|
||||||
|
|
||||||
_ephoto_single_browser_recalc(sb);
|
_ephoto_single_browser_recalc(sb);
|
||||||
sb->edited_image_data = NULL;
|
if (sb->edited_image_data)
|
||||||
sb->ew = 0;
|
{
|
||||||
sb->eh = 0;
|
free(sb->edited_image_data);
|
||||||
|
sb->edited_image_data = NULL;
|
||||||
|
sb->ew = 0;
|
||||||
|
sb->eh = 0;
|
||||||
|
}
|
||||||
if (sb->viewer)
|
if (sb->viewer)
|
||||||
_zoom_fit(sb);
|
_zoom_fit(sb);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue