Ephoto: Add file operations, context menus, sorting, and more.

v-1.6.0
Stephen Houston 8 years ago
parent 0b62428e24
commit cf25f7c561
  1. 3
      src/bin/Makefile.am
  2. 84
      src/bin/ephoto.c
  3. 253
      src/bin/ephoto.h
  4. 295
      src/bin/ephoto_bcg.c
  5. 250
      src/bin/ephoto_color.c
  6. 258
      src/bin/ephoto_config.c
  7. 504
      src/bin/ephoto_cropper.c
  8. 398
      src/bin/ephoto_filters.c
  9. 293
      src/bin/ephoto_hsv.c
  10. 534
      src/bin/ephoto_main.c
  11. 2083
      src/bin/ephoto_single_browser.c
  12. 437
      src/bin/ephoto_slideshow.c
  13. 3236
      src/bin/ephoto_thumb_browser.c

@ -6,6 +6,9 @@ ephoto_CPPFLAGS = \
-I$(top_srcdir) \
-I$(top_srcdir)/src/bin \
-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
-Wall \
-Wextra \
-Wshadow \
@EFL_CFLAGS@
ephoto_LDADD = @EFL_LIBS@
if HAVE_PO

@ -2,9 +2,6 @@
static void _ephoto_display_usage(void);
/* Global log domain pointer */
int __log_domain = -1;
EAPI int
elm_main(int argc, char **argv)
{
@ -23,79 +20,70 @@ elm_main(int argc, char **argv)
textdomain(PACKAGE);
#endif
__log_domain = eina_log_domain_register("ephoto", EINA_COLOR_ORANGE);
if (!__log_domain)
{
EINA_LOG_ERR("Could not register log domain: Ephoto");
r = 1;
goto end_log_domain;
}
if (!efreet_mime_init())
ERR("Could not init efreet_mime!");
printf("Could not initialize Efreet_Mime!\n");
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
DBG("Logging initialized");
if (argc > 2)
{
printf("Too Many Arguments!\n");
_ephoto_display_usage();
r = 1;
goto end;
printf("Too Many Arguments!\n");
_ephoto_display_usage();
r = 1;
goto end;
}
else if (argc < 2)
{
Evas_Object *win = ephoto_window_add(NULL);
if (!win)
{
r = 1;
goto end;
}
Evas_Object *win = ephoto_window_add(NULL);
if (!win)
{
r = 1;
goto end;
}
}
else if (!strncmp(argv[1], "--help", 6))
{
_ephoto_display_usage();
r = 0;
goto end;
_ephoto_display_usage();
r = 0;
goto end;
}
else
{
char *real = ecore_file_realpath(argv[1]);
if (!real)
{
printf("invalid file or directory: '%s'\n", argv[1]);
r = 1;
goto end;
}
Evas_Object *win = ephoto_window_add(real);
free(real);
if (!win)
{
r = 1;
goto end;
}
char *real = ecore_file_realpath(argv[1]);
if (!real)
{
printf("invalid file or directory: '%s'\n", argv[1]);
r = 1;
goto end;
}
Evas_Object *win = ephoto_window_add(real);
free(real);
if (!win)
{
r = 1;
goto end;
}
}
elm_run();
end:
eina_log_domain_unregister(__log_domain);
end:
efreet_mime_shutdown();
end_log_domain:
eio_shutdown();
return r;
}
/*Display useage commands for ephoto*/
/* Display useage commands for ephoto */
static void
_ephoto_display_usage(void)
{
printf("Ephoto Usage: \n"
"ephoto --help : This page\n"
"ephoto filename : Specifies a file to open\n"
"ephoto dirname : Specifies a directory to open\n");
printf("Ephoto Usage: \n" "ephoto --help : This page\n"
"ephoto filename : Specifies a file to open\n"
"ephoto dirname : Specifies a directory to open\n");
}
ELM_MAIN()

@ -1,34 +1,38 @@
#ifndef _EPHOTO_H_
#define _EPHOTO_H_
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <Eet.h>
#include <Ecore.h>
#include <Ecore_Evas.h>
#include <Ecore_File.h>
#include <Efreet_Mime.h>
#include <Elementary.h>
#include <Eina.h>
#include <Edje.h>
#include <Evas.h>
#include <Eio.h>
#include <Ethumb_Client.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#ifdef HAVE_PO
#include <locale.h>
#endif
#ifdef HAVE_GETTEXT
#include "gettext.h"
# define _EPHOTO_H_
# ifdef HAVE_CONFIG_H
# include "config.h"
# endif
# include <Eet.h>
# include <Ecore.h>
# include <Ecore_Evas.h>
# include <Ecore_File.h>
# include <Efreet_Mime.h>
# include <Elementary.h>
# include <Elementary_Cursor.h>
# include <Eina.h>
# include <Edje.h>
# include <Evas.h>
# include <Eio.h>
# include <Ethumb_Client.h>
# include <limits.h>
# include <math.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <dirent.h>
# ifdef HAVE_PO
# include <locale.h>
# endif
#if HAVE_GETTEXT && ENABLE_NLS
#define _(string) gettext (string)
#else
#define _(string) (string)
#define ngettext(String1, String2, Var) Var == 1 ? String1 : String2
#endif
typedef struct _Ephoto_Config Ephoto_Config;
@ -38,77 +42,88 @@ typedef struct _Ephoto_Event_Entry_Create Ephoto_Event_Entry_Create;
typedef enum _Ephoto_State Ephoto_State;
typedef enum _Ephoto_Orient Ephoto_Orient;
typedef enum _Ephoto_Sort Ephoto_Sort;
Evas_Object *ephoto_window_add(const char *path);
void ephoto_title_set(Ephoto *ephoto, const char *title);
void ephoto_thumb_size_set(Ephoto *ephoto, int size);
Evas_Object *ephoto_thumb_add(Ephoto *ephoto, Evas_Object *parent, const char *path);
void ephoto_thumb_path_set(Evas_Object *obj, const char *path);
void ephoto_directory_set(Ephoto *ephoto, const char *path);
Eina_Bool ephoto_config_init(Ephoto *em);
void ephoto_config_save(Ephoto *em);
void ephoto_config_free(Ephoto *em);
void ephoto_config_general(Ephoto *em);
void ephoto_config_slideshow(Ephoto *em);
void ephoto_config_about(Ephoto *em);
void ephoto_title_set(Ephoto *ephoto, const char *title);
void ephoto_thumb_size_set(Ephoto *ephoto, int size);
Evas_Object *ephoto_thumb_add(Ephoto *ephoto, Evas_Object *parent,
const char *path);
void ephoto_thumb_path_set(Evas_Object *obj, const char *path);
void ephoto_directory_set(Ephoto *ephoto, const char *path,
Elm_Widget_Item *expanded, Eina_Bool dirs_only);
Eina_Bool ephoto_config_init(Ephoto *em);
void ephoto_config_save(Ephoto *em);
void ephoto_config_free(Ephoto *em);
void ephoto_config_general(Ephoto *em);
void ephoto_config_slideshow(Ephoto *em);
void ephoto_config_about(Ephoto *em);
Evas_Object *ephoto_single_browser_add(Ephoto *ephoto, Evas_Object *parent);
void ephoto_single_browser_entry_set(Evas_Object *obj, Ephoto_Entry *entry);
void ephoto_single_browser_path_pending_set(Evas_Object *obj, const char *path);
void ephoto_single_browser_image_data_update(Evas_Object *main, Evas_Object *image, Eina_Bool finished, unsigned int *image_data, int w, int h);
void ephoto_single_browser_cancel_editing(Evas_Object *main, Evas_Object *image);
/* smart callbacks called:
* "back" - the user wants to go back to the previous screen.
*/
void ephoto_single_browser_entry_set(Evas_Object *obj, Ephoto_Entry *entry);
void ephoto_single_browser_path_pending_set(Evas_Object *obj,
const char *path);
void ephoto_single_browser_image_data_update(Evas_Object *main,
Evas_Object *image, Eina_Bool finished, unsigned int *image_data, int w,
int h);
void ephoto_single_browser_cancel_editing(Evas_Object *main,
Evas_Object *image);
/* smart callbacks called: "back" - the user wants to go back to the previous
* screen. */
Evas_Object *ephoto_slideshow_add(Ephoto *ephoto, Evas_Object *parent);
void ephoto_slideshow_entry_set(Evas_Object *obj, Ephoto_Entry *entry);
/* smart callbacks called:
* "back" - the user wants to go back to the previous screen.
*/
void ephoto_slideshow_entry_set(Evas_Object *obj, Ephoto_Entry *entry);
Evas_Object *ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent);
/* smart callbacks called:
* "selected" - an item in the thumb browser is selected. The selected Ephoto_Entry is passed as event_info argument.
*/
/* smart callbacks called: "back" - the user wants to go back to the previous
* screen. */
void ephoto_cropper_add(Evas_Object *main, Evas_Object *parent, Evas_Object *image_parent, Evas_Object *image);
void ephoto_bcg_add(Evas_Object *main, Evas_Object *parent, Evas_Object *image);
void ephoto_hsv_add(Evas_Object *main, Evas_Object *parent, Evas_Object *image);
void ephoto_color_add(Evas_Object *main, Evas_Object *parent, Evas_Object *image);
void ephoto_filter_blur(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_old_photo(Evas_Object *main, Evas_Object *image);
void ephoto_filter_histogram_eq(Evas_Object *main, Evas_Object *image);
Evas_Object *ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent);
void ephoto_thumb_browser_fsel_clear(Ephoto *ephoto);
/* smart callbacks called: "selected" - an item in the thumb browser is
* selected. The selected Ephoto_Entry is passed as event_info argument. */
void ephoto_cropper_add(Evas_Object *main, Evas_Object *parent,
Evas_Object *image_parent, Evas_Object *image);
void ephoto_bcg_add(Evas_Object *main, Evas_Object *parent,
Evas_Object *image);
void ephoto_hsv_add(Evas_Object *main, Evas_Object *parent,
Evas_Object *image);
void ephoto_color_add(Evas_Object *main, Evas_Object *parent,
Evas_Object *image);
void ephoto_filter_blur(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_old_photo(Evas_Object *main, Evas_Object *image);
void ephoto_filter_histogram_eq(Evas_Object *main, Evas_Object *image);
enum _Ephoto_State
{
EPHOTO_STATE_THUMB,
EPHOTO_STATE_SINGLE,
EPHOTO_STATE_SLIDESHOW
EPHOTO_STATE_THUMB,
EPHOTO_STATE_SINGLE,
EPHOTO_STATE_SLIDESHOW
};
enum _Ephoto_Orient /* matches with exif orientation tag */
enum _Ephoto_Orient
{
EPHOTO_ORIENT_0 = 1,
EPHOTO_ORIENT_FLIP_HORIZ = 2,
EPHOTO_ORIENT_180 = 3,
EPHOTO_ORIENT_FLIP_VERT = 4,
EPHOTO_ORIENT_FLIP_VERT_90 = 5,
EPHOTO_ORIENT_90 = 6,
EPHOTO_ORIENT_FLIP_HORIZ_90 = 7,
EPHOTO_ORIENT_270 = 8
EPHOTO_ORIENT_0 = 1,
EPHOTO_ORIENT_FLIP_HORIZ = 2,
EPHOTO_ORIENT_180 = 3,
EPHOTO_ORIENT_FLIP_VERT = 4,
EPHOTO_ORIENT_FLIP_VERT_90 = 5,
EPHOTO_ORIENT_90 = 6,
EPHOTO_ORIENT_FLIP_HORIZ_90 = 7,
EPHOTO_ORIENT_270 = 8
};
enum _Ephoto_Sort
{
EPHOTO_SORT_ALPHABETICAL_ASCENDING,
EPHOTO_SORT_ALPHABETICAL_DESCENDING,
EPHOTO_SORT_MODTIME_ASCENDING,
EPHOTO_SORT_MODTIME_DESCENDING
};
/* TODO: split into window & global config, allow multi window
*
* This also requires single instance, as 2 instances changing the
* same configuration will lead to problems.
*
* Single instance is better done as DBus, using FDO standard methods.
*/
struct _Ephoto_Config
{
int config_version;
@ -122,11 +137,15 @@ struct _Ephoto_Config
int fsel_hide;
int tool_hide;
const char *open;
int prompts;
int drop;
Evas_Object *slide_time;
Evas_Object *slide_trans;
Evas_Object *hide_toolbar;
Evas_Object *open_dir;
Evas_Object *open_dir_custom;
Evas_Object *show_prompts;
Evas_Object *move_drop;
};
struct _Ephoto
@ -144,14 +163,16 @@ struct _Ephoto
Eina_List *entries;
Eina_List *direntries;
Eina_List *thumbs; /* live thumbs that need to be regenerated on changes */
Eina_List *thumbs;
int thumb_gen_size; /* pending value for thumb_regen */
Evas_Coord bottom_bar_size;
struct {
int thumb_gen_size;
Evas_Coord bottom_bar_size;
struct
{
Ecore_Timer *thumb_regen;
} timer;
struct {
struct
{
Ecore_Job *change_dir;
} job;
@ -166,10 +187,11 @@ struct _Ephoto
struct _Ephoto_Entry
{
const char *path;
const char *basename; /* pointer inside path */
const char *basename;
const char *label;
Ephoto *ephoto;
Elm_Object_Item *item;
Elm_Object_Item *parent;
Eina_List *free_listeners;
Eina_Bool is_dir;
};
@ -179,17 +201,15 @@ struct _Ephoto_Event_Entry_Create
Ephoto_Entry *entry;
};
Ephoto_Entry *ephoto_entry_new(Ephoto *ephoto, const char *path, const char *label, Eina_File_Type type);
void ephoto_entry_free(Ephoto_Entry *entry);
void ephoto_entry_free_listener_add(Ephoto_Entry *entry, void (*cb)(void *data, const Ephoto_Entry *entry), const void *data);
void ephoto_entry_free_listener_del(Ephoto_Entry *entry, void (*cb)(void *data, const Ephoto_Entry *entry), const void *data);
void ephoto_entries_free(Ephoto *ephoto);
int ephoto_entries_cmp(const void *pa, const void *pb);
extern int __log_domain;
#define DBG(...) EINA_LOG_DOM_DBG(__log_domain, __VA_ARGS__)
#define INF(...) EINA_LOG_DOM_INFO(__log_domain, __VA_ARGS__)
#define ERR(...) EINA_LOG_DOM_ERR(__log_domain, __VA_ARGS__)
Ephoto_Entry *ephoto_entry_new(Ephoto *ephoto, const char *path,
const char *label, Eina_File_Type type);
void ephoto_entry_free(Ephoto_Entry *entry);
void ephoto_entry_free_listener_add(Ephoto_Entry *entry,
void (*cb) (void *data, const Ephoto_Entry *entry), const void *data);
void ephoto_entry_free_listener_del(Ephoto_Entry *entry,
void (*cb) (void *data, const Ephoto_Entry *entry), const void *data);
void ephoto_entries_free(Ephoto *ephoto);
int ephoto_entries_cmp(const void *pa, const void *pb);
static inline Eina_Bool
_ephoto_eina_file_direct_info_image_useful(const Eina_File_Direct_Info *info)
@ -197,29 +217,28 @@ _ephoto_eina_file_direct_info_image_useful(const Eina_File_Direct_Info *info)
const char *type, *bname;
int i = 0;
const char *filters[] =
{
"png", "jpeg", "jpg", "eet", "xpm", "tiff", "gif", "svg", "webp", "pmaps",
"bmp", "tga", "wbmp", "ico", "psd", "jp2k", "generic"
const char *filters[] = {
"png", "jpeg", "jpg", "eet", "xpm", "tiff", "gif", "svg", "webp", "pmaps",
"bmp", "tga", "wbmp", "ico", "psd", "jp2k", "generic"
};
bname = info->path + info->name_start;
if (bname[0] == '.') return EINA_FALSE;
if (bname[0] == '.')
return EINA_FALSE;
if ((info->type != EINA_FILE_REG) && (info->type != EINA_FILE_UNKNOWN))
return EINA_FALSE;
return EINA_FALSE;
type = strrchr(bname, '.');
if(!type) return EINA_FALSE;
int count = sizeof(filters)/sizeof(filters[0]);
for (i=0; i < count; i++)
if (!type)
return EINA_FALSE;
int count = sizeof(filters) / sizeof(filters[0]);
for (i = 0; i < count; i++)
{
if (!strcasecmp(type+1, filters[i]))
return evas_object_image_extension_can_load_get(bname);
if (!strcasecmp(type + 1, filters[i]))
return evas_object_image_extension_can_load_get(bname);
}
return EINA_FALSE;
/* seems that this does not play nice with threads */
//if (!(type = efreet_mime_type_get(info->path))) return EINA_FALSE;
//return strncmp(type, "image/", sizeof("image/") - 1) == 0;
}
extern int EPHOTO_EVENT_ENTRY_CREATE;

@ -21,221 +21,236 @@ static int
_normalize_color(int color)
{
if (color < 0)
return 0;
return 0;
else if (color > 255)
return 255;
return 255;
else
return color;
return color;
}
static int
_mul_color_alpha(int color, int alpha)
{
if (alpha > 0 && alpha < 255)
return (color * (255 / alpha));
return color * (255 / alpha);
else
return color;
return color;
}
static int
_demul_color_alpha(int color, int alpha)
{
if (alpha > 0 && alpha < 255)
return ((color * alpha) / 255);
return (color * alpha) / 255;
else
return color;
return color;
}
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;
int x, y, w, h;
int x, y;
int a, r, g, b, bb, gg, rr;
im_data = malloc(sizeof(unsigned int) * ebcg->w * ebcg->h);
if (image_data)
memcpy(im_data, image_data, sizeof(unsigned int) * ebcg->w * ebcg->h);
memcpy(im_data, image_data, sizeof(unsigned int) * ebcg->w * ebcg->h);
else
memcpy(im_data, ebcg->original_im_data, sizeof(unsigned int) * ebcg->w * ebcg->h);
memcpy(im_data, ebcg->original_im_data,
sizeof(unsigned int) * ebcg->w * ebcg->h);
ebcg->brightness = brightness;
im_data_new = malloc(sizeof(unsigned int) * ebcg->w * ebcg->h);
for (y = 0; y < ebcg->h; y++)
{
p1 = im_data + (y * ebcg->w);
p2 = im_data_new + (y * ebcg->w);
for (x = 0; x < ebcg->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);
bb = (int)b+ebcg->brightness;
gg = (int)g+ebcg->brightness;
rr = (int)r+ebcg->brightness;
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++;
}
p1 = im_data + (y * ebcg->w);
p2 = im_data_new + (y * ebcg->w);
for (x = 0; x < ebcg->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);
bb = (int) b + ebcg->brightness;
gg = (int) g + ebcg->brightness;
rr = (int) r + ebcg->brightness;
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(ebcg->main, ebcg->image, EINA_FALSE, im_data_new, ebcg->w, ebcg->h);
ephoto_single_browser_image_data_update(ebcg->main, ebcg->image, EINA_FALSE,
im_data_new, ebcg->w, ebcg->h);
free(im_data);
return im_data_new;
}
unsigned int *
_ephoto_bcg_adjust_contrast(Ephoto_BCG *ebcg, int contrast, unsigned int *image_data)
_ephoto_bcg_adjust_contrast(Ephoto_BCG *ebcg, int contrast,
unsigned int *image_data)
{
unsigned int *im_data, *im_data_new, *p1, *p2;
int x, y, w, h, top, bottom;
int x, y, top, bottom;
int a, r, g, b, bb, gg, rr;
float factor;
im_data = malloc(sizeof(unsigned int) * ebcg->w * ebcg->h);
if (image_data)
memcpy(im_data, image_data, sizeof(unsigned int) * ebcg->w * ebcg->h);
memcpy(im_data, image_data, sizeof(unsigned int) * ebcg->w * ebcg->h);
else
memcpy(im_data, ebcg->original_im_data, sizeof(unsigned int) * ebcg->w * ebcg->h);
memcpy(im_data, ebcg->original_im_data,
sizeof(unsigned int) * ebcg->w * ebcg->h);
ebcg->contrast = contrast;
top = ((255+(contrast))*259);
bottom = ((259-(contrast))*255);
factor = (float)top / (float)bottom;
top = ((255 + (contrast)) * 259);
bottom = ((259 - (contrast)) * 255);
factor = (float) top / (float) bottom;
im_data_new = malloc(sizeof(unsigned int) * ebcg->w * ebcg->h);
for (y = 0; y < ebcg->h; y++)
{
p1 = im_data + (y * ebcg->w);
p2 = im_data_new + (y * ebcg->w);
for (x = 0; x < ebcg->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);
bb = (int)((factor * (b - 128)) + 128);
gg = (int)((factor * (g - 128)) + 128);
rr = (int)((factor * (r - 128)) + 128);
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(ebcg->main, ebcg->image, EINA_FALSE, im_data_new, ebcg->w, ebcg->h);
p1 = im_data + (y * ebcg->w);
p2 = im_data_new + (y * ebcg->w);
for (x = 0; x < ebcg->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);
bb = (int) ((factor * (b - 128)) + 128);
gg = (int) ((factor * (g - 128)) + 128);
rr = (int) ((factor * (r - 128)) + 128);
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(ebcg->main, ebcg->image, EINA_FALSE,
im_data_new, ebcg->w, ebcg->h);
free(im_data);
return im_data_new;
}
unsigned int *
_ephoto_bcg_adjust_gamma(Ephoto_BCG *ebcg, double gamma, unsigned int *image_data)
_ephoto_bcg_adjust_gamma(Ephoto_BCG *ebcg, double gamma,
unsigned int *image_data)
{
unsigned int *im_data, *im_data_new, *p1, *p2;
int x, y, w, h;
int x, y;
int a, r, g, b, bb, gg, rr;
im_data = malloc(sizeof(unsigned int) * ebcg->w * ebcg->h);
if (image_data)
memcpy(im_data, image_data, sizeof(unsigned int) * ebcg->w * ebcg->h);
memcpy(im_data, image_data, sizeof(unsigned int) * ebcg->w * ebcg->h);
else
memcpy(im_data, ebcg->original_im_data, sizeof(unsigned int) * ebcg->w * ebcg->h);
memcpy(im_data, ebcg->original_im_data,
sizeof(unsigned int) * ebcg->w * ebcg->h);
ebcg->gamma = 1/gamma;
ebcg->gamma = 1 / gamma;
im_data_new = malloc(sizeof(unsigned int) * ebcg->w * ebcg->h);
for (y = 0; y < ebcg->h; y++)
{
p1 = im_data + (y * ebcg->w);
p2 = im_data_new + (y * ebcg->w);
for (x = 0; x < ebcg->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);
bb = (int)(pow(((double)b/255), ebcg->gamma) * 255);
gg = (int)(pow(((double)g/255), ebcg->gamma) * 255);
rr = (int)(pow(((double)r/255), ebcg->gamma) * 255);
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(ebcg->main, ebcg->image, EINA_FALSE, im_data_new, ebcg->w, ebcg->h);
p1 = im_data + (y * ebcg->w);
p2 = im_data_new + (y * ebcg->w);
for (x = 0; x < ebcg->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);
bb = (int) (pow(((double) b / 255), ebcg->gamma) * 255);
gg = (int) (pow(((double) g / 255), ebcg->gamma) * 255);
rr = (int) (pow(((double) r / 255), ebcg->gamma) * 255);
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(ebcg->main, ebcg->image, EINA_FALSE,
im_data_new, ebcg->w, ebcg->h);
free(im_data);
return im_data_new;
}
static void
_brightness_slider_changed(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
_brightness_slider_changed(void *data, Evas_Object *obj,
void *event_info EINA_UNUSED)
{
Ephoto_BCG *ebcg = data;
int brightness;
unsigned int *image_data, *image_data_two, *image_data_three;
unsigned int *image_data, *image_data_two;
brightness = elm_slider_value_get(obj);
image_data = _ephoto_bcg_adjust_brightness(ebcg, brightness, NULL);
image_data_two = _ephoto_bcg_adjust_contrast(ebcg, ebcg->contrast, image_data);
image_data_three = _ephoto_bcg_adjust_gamma(ebcg, ebcg->gamma, image_data_two);
image_data_two =
_ephoto_bcg_adjust_contrast(ebcg, ebcg->contrast, image_data);
_ephoto_bcg_adjust_gamma(ebcg, ebcg->gamma, image_data_two);
}
static void
_contrast_slider_changed(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
_contrast_slider_changed(void *data, Evas_Object *obj,
void *event_info EINA_UNUSED)
{
Ephoto_BCG *ebcg = data;
int contrast;
unsigned int *image_data, *image_data_two, *image_data_three;
unsigned int *image_data, *image_data_two;
contrast = elm_slider_value_get(obj);
image_data = _ephoto_bcg_adjust_contrast(ebcg, contrast, NULL);
image_data_two = _ephoto_bcg_adjust_brightness(ebcg, ebcg->brightness, image_data);
image_data_three = _ephoto_bcg_adjust_gamma(ebcg, ebcg->gamma, image_data_two);
image_data_two =
_ephoto_bcg_adjust_brightness(ebcg, ebcg->brightness, image_data);
_ephoto_bcg_adjust_gamma(ebcg, ebcg->gamma, image_data_two);
}
static void
_gamma_slider_changed(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
_gamma_slider_changed(void *data, Evas_Object *obj,
void *event_info EINA_UNUSED)
{
Ephoto_BCG *ebcg = data;
double gamma;
unsigned int *image_data, *image_data_two, *image_data_three;
unsigned int *image_data, *image_data_two;
gamma = elm_slider_value_get(obj);
image_data = _ephoto_bcg_adjust_gamma(ebcg, gamma, NULL);
image_data_two = _ephoto_bcg_adjust_brightness(ebcg, ebcg->brightness, image_data);
image_data_three = _ephoto_bcg_adjust_contrast(ebcg, ebcg->contrast, image_data_two);
image_data_two =
_ephoto_bcg_adjust_brightness(ebcg, ebcg->brightness, image_data);
_ephoto_bcg_adjust_contrast(ebcg, ebcg->contrast, image_data_two);
}
static void
_bcg_reset(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
_bcg_reset(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ephoto_BCG *ebcg = data;
@ -249,20 +264,25 @@ _bcg_reset(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSE
}
static void
_bcg_apply(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
_bcg_apply(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ephoto_BCG *ebcg = data;
unsigned int *image_data;
int w, h;
image_data = evas_object_image_data_get(elm_image_object_get(ebcg->image), EINA_FALSE);
image_data =
evas_object_image_data_get(elm_image_object_get(ebcg->image),
EINA_FALSE);
evas_object_image_size_get(elm_image_object_get(ebcg->image), &w, &h);
ephoto_single_browser_image_data_update(ebcg->main, ebcg->image, EINA_TRUE, image_data, w, h);
ephoto_single_browser_image_data_update(ebcg->main, ebcg->image, EINA_TRUE,
image_data, w, h);
evas_object_del(ebcg->frame);
}
static void
_bcg_cancel(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
_bcg_cancel(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ephoto_BCG *ebcg = data;
@ -278,16 +298,19 @@ _bcg_cancel(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUS
}
static void
_frame_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
_frame_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ephoto_BCG *ebcg = data;
free(ebcg->original_im_data);
free(ebcg);
}
void ephoto_bcg_add(Evas_Object *main, Evas_Object *parent, Evas_Object *image)
void
ephoto_bcg_add(Evas_Object *main, Evas_Object *parent, Evas_Object *image)
{
Evas_Object *win, *box, *slider, *ic, *button;
Evas_Object *box, *slider, *ic, *button;
Ephoto_BCG *ebcg;
unsigned int *im_data;
@ -302,10 +325,14 @@ void ephoto_bcg_add(Evas_Object *main, Evas_Object *parent, Evas_Object *image)
ebcg->main = main;
ebcg->parent = parent;
ebcg->image = image;
im_data = evas_object_image_data_get(elm_image_object_get(ebcg->image), EINA_FALSE);
evas_object_image_size_get(elm_image_object_get(ebcg->image), &ebcg->w, &ebcg->h);
im_data =
evas_object_image_data_get(elm_image_object_get(ebcg->image),
EINA_FALSE);
evas_object_image_size_get(elm_image_object_get(ebcg->image), &ebcg->w,
&ebcg->h);
ebcg->original_im_data = malloc(sizeof(unsigned int) * ebcg->w * ebcg->h);
memcpy(ebcg->original_im_data, im_data, sizeof(unsigned int) * ebcg->w * ebcg->h);
memcpy(ebcg->original_im_data, im_data,
sizeof(unsigned int) * ebcg->w * ebcg->h);
ebcg->frame = elm_frame_add(parent);
elm_object_text_set(ebcg->frame, _("Brightness/Contrast/Gamma"));
@ -313,7 +340,8 @@ void ephoto_bcg_add(Evas_Object *main, Evas_Object *parent, Evas_Object *image)
evas_object_size_hint_align_set(ebcg->frame, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(parent, ebcg->frame);
evas_object_data_set(ebcg->frame, "ebcg", ebcg);
evas_object_event_callback_add(ebcg->frame, EVAS_CALLBACK_DEL, _frame_del, ebcg);
evas_object_event_callback_add(ebcg->frame, EVAS_CALLBACK_DEL, _frame_del,
ebcg);
evas_object_show(ebcg->frame);
box = elm_box_add(ebcg->frame);
@ -331,7 +359,8 @@ void ephoto_bcg_add(Evas_Object *main, Evas_Object *parent, Evas_Object *image)
elm_slider_unit_format_set(slider, "%1.0f");
evas_object_size_hint_weight_set(slider, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, 0.5);
evas_object_smart_callback_add(slider, "delay,changed", _brightness_slider_changed, ebcg);
evas_object_smart_callback_add(slider, "delay,changed",
_brightness_slider_changed, ebcg);
elm_box_pack_end(box, slider);
evas_object_show(slider);
ebcg->bslider = slider;
@ -344,7 +373,8 @@ void ephoto_bcg_add(Evas_Object *main, Evas_Object *parent, Evas_Object *image)
elm_slider_unit_format_set(slider, "%1.0f");
evas_object_size_hint_weight_set(slider, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, 0.5);
evas_object_smart_callback_add(slider, "delay,changed", _contrast_slider_changed, ebcg);
evas_object_smart_callback_add(slider, "delay,changed",
_contrast_slider_changed, ebcg);
elm_box_pack_end(box, slider);
evas_object_show(slider);
ebcg->cslider = slider;
@ -357,7 +387,8 @@ void ephoto_bcg_add(Evas_Object *main, Evas_Object *parent, Evas_Object *image)
elm_slider_unit_format_set(slider, "%1.2f");
evas_object_size_hint_weight_set(slider, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, 0.5);
evas_object_smart_callback_add(slider, "delay,changed", _gamma_slider_changed, ebcg);
evas_object_smart_callback_add(slider, "delay,changed",
_gamma_slider_changed, ebcg);
elm_box_pack_end(box, slider);
evas_object_show(slider);
ebcg->gslider = slider;
@ -406,6 +437,6 @@ void ephoto_bcg_add(Evas_Object *main, Evas_Object *parent, Evas_Object *image)
return;
error:
return;
error:
return;
}

@ -21,165 +21,173 @@ static int
_normalize_color(int color)
{
if (color < 0)
return 0;
return 0;
else if (color > 255)
return 255;
return 255;
else
return color;
return color;
}
static int
_mul_color_alpha(int color, int alpha)
{
if (alpha > 0 && alpha < 255)
return (color * (255 / alpha));
return color * (255 / alpha);
else
return color;
return color;
}
static int
_demul_color_alpha(int color, int alpha)
{
if (alpha > 0 && alpha < 255)
return ((color * alpha) / 255);
return (color * alpha) / 255;
else
return color;
return color;
}
unsigned int *
_ephoto_color_adjust_red(Ephoto_Color *eco, int red, unsigned int *image_data)
{
unsigned int *im_data, *im_data_new, *p1, *p2;
int x, y, w, h;
int x, y;
int a, r, g, b, rr;
im_data = malloc(sizeof(unsigned int) * eco->w * eco->h);
if (image_data)
memcpy(im_data, image_data, sizeof(unsigned int) * eco->w * eco->h);
memcpy(im_data, image_data, sizeof(unsigned int) * eco->w * eco->h);
else
memcpy(im_data, eco->original_im_data, sizeof(unsigned int) * eco->w * eco->h);
memcpy(im_data, eco->original_im_data,
sizeof(unsigned int) * eco->w * eco->h);
eco->red = red;
im_data_new = malloc(sizeof(unsigned int) * eco->w * eco->h);
for (y = 0; y < eco->h; y++)
{
p1 = im_data + (y * eco->w);
p2 = im_data_new + (y * eco->w);
for (x = 0; x < eco->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);
rr = (int)r+eco->red;
b = _normalize_color(b);
g = _normalize_color(g);
rr = _normalize_color(rr);
b = _demul_color_alpha(b, a);
g = _demul_color_alpha(g, a);
rr = _demul_color_alpha(rr, a);
*p2 = (a << 24) | (rr << 16) | (g << 8) | b;
p2++;
p1++;
}
p1 = im_data + (y * eco->w);
p2 = im_data_new + (y * eco->w);
for (x = 0; x < eco->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);
rr = (int) r + eco->red;
b = _normalize_color(b);
g = _normalize_color(g);
rr = _normalize_color(rr);
b = _demul_color_alpha(b, a);
g = _demul_color_alpha(g, a);
rr = _demul_color_alpha(rr, a);
*p2 = (a << 24) | (rr << 16) | (g << 8) | b;
p2++;
p1++;
}
}
ephoto_single_browser_image_data_update(eco->main, eco->image, EINA_FALSE, im_data_new, eco->w, eco->h);
ephoto_single_browser_image_data_update(eco->main, eco->image, EINA_FALSE,
im_data_new, eco->w, eco->h);
free(im_data);
return im_data_new;
}
unsigned int *
_ephoto_color_adjust_green(Ephoto_Color *eco, int green, unsigned int *image_data)
_ephoto_color_adjust_green(Ephoto_Color *eco, int green,
unsigned int *image_data)
{
unsigned int *im_data, *im_data_new, *p1, *p2;
int x, y, w, h;
int x, y;
int a, r, g, b, gg;
im_data = malloc(sizeof(unsigned int) * eco->w * eco->h);
if (image_data)
memcpy(im_data, image_data, sizeof(unsigned int) * eco->w * eco->h);
memcpy(im_data, image_data, sizeof(unsigned int) * eco->w * eco->h);
else
memcpy(im_data, eco->original_im_data, sizeof(unsigned int) * eco->w * eco->h);
memcpy(im_data, eco->original_im_data,
sizeof(unsigned int) * eco->w * eco->h);
eco->green = green;
im_data_new = malloc(sizeof(unsigned int) * eco->w * eco->h);
for (y = 0; y < eco->h; y++)
{
p1 = im_data + (y * eco->w);
p2 = im_data_new + (y * eco->w);
for (x = 0; x < eco->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);
gg = (int)g+eco->green;
b = _normalize_color(b);
gg = _normalize_color(gg);
r = _normalize_color(r);
b = _demul_color_alpha(b, a);
gg = _demul_color_alpha(gg, a);
r = _demul_color_alpha(r, a);
*p2 = (a << 24) | (r << 16) | (gg << 8) | b;
p2++;
p1++;
}
p1 = im_data + (y * eco->w);
p2 = im_data_new + (y * eco->w);
for (x = 0; x < eco->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);
gg = (int) g + eco->green;
b = _normalize_color(b);
gg = _normalize_color(gg);
r = _normalize_color(r);
b = _demul_color_alpha(b, a);
gg = _demul_color_alpha(gg, a);
r = _demul_color_alpha(r, a);
*p2 = (a << 24) | (r << 16) | (gg << 8) | b;
p2++;
p1++;
}
}
ephoto_single_browser_image_data_update(eco->main, eco->image, EINA_FALSE, im_data_new, eco->w, eco->h);
ephoto_single_browser_image_data_update(eco->main, eco->image, EINA_FALSE,
im_data_new, eco->w, eco->h);
free(im_data);
return im_data_new;
}
unsigned int *
_ephoto_color_adjust_blue(Ephoto_Color *eco, int blue, unsigned int *image_data)
_ephoto_color_adjust_blue(Ephoto_Color *eco, int blue,
unsigned int *image_data)
{
unsigned int *im_data, *im_data_new, *p1, *p2;
int x, y, w, h;
int x, y;
int a, r, g, b, bb;
im_data = malloc(sizeof(unsigned int) * eco->w * eco->h);
if (image_data)
memcpy(im_data, image_data, sizeof(unsigned int) * eco->w * eco->h);
memcpy(im_data, image_data, sizeof(unsigned int) * eco->w * eco->h);
else
memcpy(im_data, eco->original_im_data, sizeof(unsigned int) * eco->w * eco->h);
memcpy(im_data, eco->original_im_data,
sizeof(unsigned int) * eco->w * eco->h);
eco->blue = blue;
im_data_new = malloc(sizeof(unsigned int) * eco->w * eco->h);
for (y = 0; y < eco->h; y++)
{
p1 = im_data + (y * eco->w);
p2 = im_data_new + (y * eco->w);
for (x = 0; x < eco->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);
bb = (int)b+eco->blue;
bb = _normalize_color(bb);
g = _normalize_color(g);
r = _normalize_color(r);
bb = _demul_color_alpha(bb, a);
g = _demul_color_alpha(g, a);
r = _demul_color_alpha(r, a);
*p2 = (a << 24) | (r << 16) | (g << 8) | bb;
p2++;
p1++;
}
p1 = im_data + (y * eco->w);
p2 = im_data_new + (y * eco->w);
for (x = 0; x < eco->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);
bb = (int) b + eco->blue;
bb = _normalize_color(bb);
g = _normalize_color(g);
r = _normalize_color(r);
bb = _demul_color_alpha(bb, a);
g = _demul_color_alpha(g, a);
r = _demul_color_alpha(r, a);
*p2 = (a << 24) | (r << 16) | (g << 8) | bb;
p2++;
p1++;
}
}
ephoto_single_browser_image_data_update(eco->main, eco->image, EINA_FALSE, im_data_new, eco->w, eco->h);
ephoto_single_browser_image_data_update(eco->main, eco->image, EINA_FALSE,
im_data_new, eco->w, eco->h);
free(im_data);
return im_data_new;
}
@ -189,43 +197,45 @@ _red_slider_changed(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
Ephoto_Color *eco = data;
int red;
unsigned int *image_data, *image_data_two, *image_data_three;
unsigned int *image_data, *image_data_two;
red = elm_slider_value_get(obj);
image_data = _ephoto_color_adjust_red(eco, red, NULL);
image_data_two = _ephoto_color_adjust_green(eco, eco->green, image_data);
image_data_three = _ephoto_color_adjust_blue(eco, eco->blue, image_data_two);
_ephoto_color_adjust_blue(eco, eco->blue, image_data_two);
}
static void
_green_slider_changed(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
_green_slider_changed(void *data, Evas_Object *obj,
void *event_info EINA_UNUSED)
{
Ephoto_Color *eco = data;
int green;
unsigned int *image_data, *image_data_two, *image_data_three;
unsigned int *image_data, *image_data_two;
green = elm_slider_value_get(obj);
image_data = _ephoto_color_adjust_green(eco, green, NULL);
image_data_two = _ephoto_color_adjust_red(eco, eco->red, image_data);
image_data_three = _ephoto_color_adjust_blue(eco, eco->blue, image_data_two);
_ephoto_color_adjust_blue(eco, eco->blue, image_data_two);
}
static void
_blue_slider_changed(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
_blue_slider_changed(void *data, Evas_Object *obj,
void *event_info EINA_UNUSED)
{
Ephoto_Color *eco = data;
int blue;
unsigned int *image_data, *image_data_two, *image_data_three;
</