Sepia works pretty well now, I do believe. Added a contrast formula based on

imlib2, and soon to add a brightness one.


SVN revision: 30068
This commit is contained in:
titan 2007-05-24 19:27:07 +00:00 committed by titan
parent 046f7d8274
commit 66031123a5
3 changed files with 104 additions and 106 deletions

View File

@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>

View File

@ -1,7 +1,20 @@
#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);
#define R_CMOD(r) \
red[(int)(r)]
#define G_CMOD(g) \
green[(int)(g)]
#define B_CMOD(b) \
blue[(int)(b)] \
/*#define A_CMOD(a) \
alpha[(int)(a)]*/
#define A_VAL(p) ((unsigned char *)(p))[3]
#define R_VAL(p) ((unsigned char *)(p))[2]
#define G_VAL(p) ((unsigned char *)(p))[1]
#define B_VAL(p) ((unsigned char *)(p))[0]
static unsigned int *set_contrast(unsigned int *data, int ew, int eh, float v);
static void close_dialog(Ewl_Widget *w, void *event, void *data);
static void close_progress(Ewl_Widget *w, void *event, void *data);
@ -10,108 +23,51 @@ 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)
static unsigned int *set_contrast(unsigned int *data, int ew, int eh, float v)
{
int delta, min, max;
int i, val;
unsigned int *p;
unsigned char red[256], green[256], blue[256], alpha[256];
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;
for (i = 0; i < 256; i++)
{
red[i] = (unsigned char)i;
green[i] = (unsigned char)i;
blue[i] = (unsigned char)i;
alpha[i] = (unsigned char)i;
}
for (i = 0; i < 256; i++)
{
val = (int)(((double)red[i] - 127) * v) + 127;
if (val < 0) val = 0;
if (val > 255) val = 255;
red[i] = (unsigned char)val;
delta = max - min;
*v = (float)(100 * max) / 255.0;
val = (int)(((double)green[i] - 127) * v) + 127;
if (val < 0) val = 0;
if (val > 255) val = 255;
green[i] = (unsigned char)val;
if (max != 0) *s = (float)(100 * delta) / (float)max;
val = (int)(((double)blue[i] - 127) * v) + 127;
if (val < 0) val = 0;
if (val > 255) val = 255;
blue[i] = (unsigned char)val;
else
{
*s = 0.0;
*h = 0.0;
*v = 0.0;
val = (int)(((double)alpha[i] - 127) * v) + 127;
if (val < 0) val = 0;
if (val > 255) val = 255;
alpha[i] = (unsigned char)val;
}
for (i = 0; i < (ew * eh); i++)
{
p = &data[i];
R_VAL(p) = R_CMOD(R_VAL(p));
G_VAL(p) = G_CMOD(G_VAL(p));
B_VAL(p) = B_CMOD(B_VAL(p));
// A_VAL(p) = A_CMOD(A_VAL(p));
}
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;
return data;
}
unsigned int *flip_horizontal(Ewl_Widget *image)
@ -413,27 +369,29 @@ unsigned int *grayscale_image(Ewl_Widget *image)
unsigned int *sepia_image(Ewl_Widget *image)
{
unsigned int *im_data, *im_data_new;
unsigned int *data, *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);
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);
im_data = set_contrast(data, ew, eh, 2);
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;
}
evas_color_rgb_to_hsv(r, g, b, &h, &s, &v);
evas_color_hsv_to_rgb(35, s, v, &r, &g, &b);
im_data_new[i] = (a << 24) | (r << 16) | (g << 8) | b;
}
return im_data_new;
}

View File

@ -1,6 +1,9 @@
#include "ephoto.h"
/*Ewl Callbacks*/
static void about_dialog(Ewl_Widget *w, void *event, void *data);
static void add_album(Ewl_Widget *w, void *event, void *data);
static void cancel(Ewl_Widget *w, void *event, void *data);
static void destroy(Ewl_Widget *w, void *event, void *data);
@ -87,7 +90,7 @@ static void update_view(Ewl_Widget *w, void *event, void *data)
return;
}
/*Cancel the Album Dialog*/
/*Cancel the Dialog*/
static void cancel(Ewl_Widget *w, void *event, void *data)
{
Ewl_Widget *win;
@ -152,6 +155,37 @@ static void add_album(Ewl_Widget *w, void *event, void *data)
ewl_button_image_size_set(EWL_BUTTON(button), 25, 25);
}
/*Add an About Dialog*/
static void about_dialog(Ewl_Widget *w, void *event, void *data)
{
Ewl_Widget *window, *button, *vbox, *text;
window = add_window("About Ephoto", 200, 100, NULL, NULL);
ewl_callback_append(window, EWL_CALLBACK_DELETE_WINDOW, cancel, window);
vbox = add_box(window, EWL_ORIENTATION_VERTICAL, 3);
ewl_object_fill_policy_set(EWL_OBJECT(vbox), EWL_FLAG_FILL_ALL);
text = add_text(vbox, "Ephoto is an advanced image viewer that allows\n"
"you to view images in several methods. They\n"
"include an icon view, a list view, and a single\n"
"image view. You can also view exif data, view\n"
"images in a fullscreen mode, and view images in a\n"
"slideshow. The edit view offers simple and advanced\n"
"editing options including rotations, flips, blurs,\n"
"sharpens, conversion to black and white, and\n"
"conversions to sepia.");
ewl_text_wrap_set(EWL_TEXT(text), EWL_TEXT_WRAP_WORD);
button = add_button(vbox, "Close",
PACKAGE_DATA_DIR "/images/dialog-close.png",
cancel, window);
ewl_button_image_size_set(EWL_BUTTON(button), 25, 25);
return;
}
/*Create the Main Ephoto Window*/
void create_main_gui(void)
{
@ -183,6 +217,11 @@ void create_main_gui(void)
PACKAGE_DATA_DIR "/images/add.png",
add_album, NULL);
menu = add_menu(mb, "Help");
mi = add_menu_item(menu, "About",
PACKAGE_DATA_DIR "/images/stock_help.png",
about_dialog, NULL);
hbox = add_box(vbox, EWL_ORIENTATION_HORIZONTAL, 2);
ewl_object_fill_policy_set(EWL_OBJECT(hbox), EWL_FLAG_FILL_ALL);