summaryrefslogtreecommitdiff
path: root/src/bin/ephoto_color.c
diff options
context:
space:
mode:
authorStephen 'Okra' Houston <smhouston88@gmail.com>2017-05-02 11:19:43 -0500
committerStephen 'Okra' Houston <smhouston88@gmail.com>2017-05-02 11:19:43 -0500
commit3480bb44b39a169b8eb052a3a8826452b2265cd8 (patch)
treeab2b88a48b541acdd8f86e144e82e69addcbee6f /src/bin/ephoto_color.c
parentd8e2df3092f564c0462ba12d7d909da86114e544 (diff)
Ephoto: Factor out common code, use "start" for Windows based devices instead of xdg-open, improve compiler flags.
Diffstat (limited to 'src/bin/ephoto_color.c')
-rw-r--r--src/bin/ephoto_color.c219
1 files changed, 59 insertions, 160 deletions
diff --git a/src/bin/ephoto_color.c b/src/bin/ephoto_color.c
index e6bc6a2..15d0465 100644
--- a/src/bin/ephoto_color.c
+++ b/src/bin/ephoto_color.c
@@ -18,174 +18,73 @@ struct _Ephoto_Color
18 unsigned int *original_im_data; 18 unsigned int *original_im_data;
19}; 19};
20 20
21static int 21typedef enum _Ephoto_Color_Adjust Ephoto_Color_Adjust;
22_normalize_color(int color) 22enum _Ephoto_Color_Adjust
23{ 23{
24 if (color < 0) 24 EPHOTO_COLOR_ADJUST_RED,
25 return 0; 25 EPHOTO_COLOR_ADJUST_GREEN,
26 else if (color > 255) 26 EPHOTO_COLOR_ADJUST_BLUE
27 return 255; 27};
28 else
29 return color;
30}
31
32static int
33_mul_color_alpha(int color, int alpha)
34{
35 if (alpha > 0 && alpha < 255)
36 return color * (255 / alpha);
37 else
38 return color;
39}
40
41static int
42_demul_color_alpha(int color, int alpha)
43{
44 if (alpha > 0 && alpha < 255)
45 return (color * alpha) / 255;
46 else
47 return color;
48}
49
50unsigned int *
51_ephoto_color_adjust_red(Ephoto_Color *eco, int red, unsigned int *image_data)
52{
53 unsigned int *im_data, *im_data_new, *p1, *p2;
54 Evas_Coord x, y;
55 int a, r, g, b, rr;
56
57 im_data = malloc(sizeof(unsigned int) * eco->w * eco->h);
58 if (image_data)
59 memcpy(im_data, image_data, sizeof(unsigned int) * eco->w * eco->h);
60 else
61 memcpy(im_data, eco->original_im_data,
62 sizeof(unsigned int) * eco->w * eco->h);
63
64 eco->red = red;
65 im_data_new = malloc(sizeof(unsigned int) * eco->w * eco->h);
66
67 for (y = 0; y < eco->h; y++)
68 {
69 p1 = im_data + (y * eco->w);
70 p2 = im_data_new + (y * eco->w);
71 for (x = 0; x < eco->w; x++)
72 {
73 b = (int) ((*p1) & 0xff);
74 g = (int) ((*p1 >> 8) & 0xff);
75 r = (int) ((*p1 >> 16) & 0xff);
76 a = (int) ((*p1 >> 24) & 0xff);
77 b = _mul_color_alpha(b, a);
78 g = _mul_color_alpha(g, a);
79 r = _mul_color_alpha(r, a);
80 rr = (int) r + eco->red;
81 b = _normalize_color(b);
82 g = _normalize_color(g);
83 rr = _normalize_color(rr);
84 b = _demul_color_alpha(b, a);
85 g = _demul_color_alpha(g, a);
86 rr = _demul_color_alpha(rr, a);
87 *p2 = (a << 24) | (rr << 16) | (g << 8) | b;
88 p2++;
89 p1++;
90 }
91 }
92 ephoto_single_browser_image_data_update(eco->main, eco->image,
93 im_data_new, eco->w, eco->h);
94 free(im_data);
95 return im_data_new;
96}
97
98unsigned int *
99_ephoto_color_adjust_green(Ephoto_Color *eco, int green,
100 unsigned int *image_data)
101{
102 unsigned int *im_data, *im_data_new, *p1, *p2;
103 Evas_Coord x, y;
104 int a, r, g, b, gg;
105
106 im_data = malloc(sizeof(unsigned int) * eco->w * eco->h);
107 if (image_data)
108 memcpy(im_data, image_data, sizeof(unsigned int) * eco->w * eco->h);
109 else
110 memcpy(im_data, eco->original_im_data,
111 sizeof(unsigned int) * eco->w * eco->h);
112
113 eco->green = green;
114 im_data_new = malloc(sizeof(unsigned int) * eco->w * eco->h);
115
116 for (y = 0; y < eco->h; y++)
117 {
118 p1 = im_data + (y * eco->w);
119 p2 = im_data_new + (y * eco->w);
120 for (x = 0; x < eco->w; x++)
121 {
122 b = (int) ((*p1) & 0xff);
123 g = (int) ((*p1 >> 8) & 0xff);
124 r = (int) ((*p1 >> 16) & 0xff);
125 a = (int) ((*p1 >> 24) & 0xff);
126 b = _mul_color_alpha(b, a);
127 g = _mul_color_alpha(g, a);
128 r = _mul_color_alpha(r, a);
129 gg = (int) g + eco->green;
130 b = _normalize_color(b);
131 gg = _normalize_color(gg);
132 r = _normalize_color(r);
133 b = _demul_color_alpha(b, a);
134 gg = _demul_color_alpha(gg, a);
135 r = _demul_color_alpha(r, a);
136 *p2 = (a << 24) | (r << 16) | (gg << 8) | b;
137 p2++;
138 p1++;
139 }
140 }
141 ephoto_single_browser_image_data_update(eco->main, eco->image,
142 im_data_new, eco->w, eco->h);
143 free(im_data);
144 return im_data_new;
145}
146 28
147unsigned int * 29unsigned int *
148_ephoto_color_adjust_blue(Ephoto_Color *eco, int blue, 30_ephoto_apply_color_adjustment(Ephoto_Color *eco, unsigned int *image_data, int adjust, Ephoto_Color_Adjust color)
149 unsigned int *image_data)
150{ 31{
151 unsigned int *im_data, *im_data_new, *p1, *p2; 32 unsigned int *im_data, *im_data_new, *p1, *p2;
152 Evas_Coord x, y; 33 Evas_Coord x, y;
153 int a, r, g, b, bb; 34 int a, r, g, b, cc;
154 35
155 im_data = malloc(sizeof(unsigned int) * eco->w * eco->h); 36 im_data = malloc(sizeof(unsigned int) * eco->w * eco->h);
156 if (image_data) 37 if (image_data)
157 memcpy(im_data, image_data, sizeof(unsigned int) * eco->w * eco->h); 38 memcpy(im_data, image_data, sizeof(unsigned int) * eco->w * eco->h);
158 else 39 else
159 memcpy(im_data, eco->original_im_data, 40 memcpy(im_data, eco->original_im_data,
160 sizeof(unsigned int) * eco->w * eco->h); 41 sizeof(unsigned int) * eco->w * eco->h);
161 42
162 eco->blue = blue;
163 im_data_new = malloc(sizeof(unsigned int) * eco->w * eco->h); 43 im_data_new = malloc(sizeof(unsigned int) * eco->w * eco->h);
164 44
165 for (y = 0; y < eco->h; y++) 45 for (y = 0; y < eco->h; y++)
166 { 46 {
167 p1 = im_data + (y * eco->w); 47 p1 = im_data + (y * eco->w);
168 p2 = im_data_new + (y * eco->w); 48 p2 = im_data_new + (y * eco->w);
169 for (x = 0; x < eco->w; x++) 49 for (x = 0; x < eco->w; x++)
170 { 50 {
171 b = (int) ((*p1) & 0xff); 51 b = (int) ((*p1) & 0xff);
172 g = (int) ((*p1 >> 8) & 0xff); 52 g = (int) ((*p1 >> 8) & 0xff);
173 r = (int) ((*p1 >> 16) & 0xff); 53 r = (int) ((*p1 >> 16) & 0xff);
174 a = (int) ((*p1 >> 24) & 0xff); 54 a = (int) ((*p1 >> 24) & 0xff);
175 b = _mul_color_alpha(b, a); 55 b = ephoto_mul_color_alpha(b, a);
176 g = _mul_color_alpha(g, a); 56 g = ephoto_mul_color_alpha(g, a);
177 r = _mul_color_alpha(r, a); 57 r = ephoto_mul_color_alpha(r, a);
178 bb = (int) b + eco->blue; 58 switch (color)
179 bb = _normalize_color(bb); 59 {
180 g = _normalize_color(g); 60 case EPHOTO_COLOR_ADJUST_RED:
181 r = _normalize_color(r); 61 eco->red = adjust;
182 bb = _demul_color_alpha(bb, a); 62 cc = (int) r + eco->red;
183 g = _demul_color_alpha(g, a); 63 r = cc;
184 r = _demul_color_alpha(r, a); 64 break;
185 *p2 = (a << 24) | (r << 16) | (g << 8) | bb; 65 case EPHOTO_COLOR_ADJUST_BLUE:
186 p2++; 66 eco->blue = adjust;
187 p1++; 67 cc = (int) b + eco->blue;
188 } 68 b = cc;
69 break;
70 case EPHOTO_COLOR_ADJUST_GREEN:
71 eco->green = adjust;
72 cc = (int) g + eco->green;
73 g = cc;
74 break;
75 default:
76 break;
77 }
78 b = ephoto_normalize_color(b);
79 g = ephoto_normalize_color(g);
80 r = ephoto_normalize_color(r);
81 b = ephoto_demul_color_alpha(b, a);
82 g = ephoto_demul_color_alpha(g, a);
83 r = ephoto_demul_color_alpha(r, a);
84 *p2 = (a << 24) | (r << 16) | (g << 8) | b;
85 p2++;
86 p1++;
87 }
189 } 88 }
190 ephoto_single_browser_image_data_update(eco->main, eco->image, 89 ephoto_single_browser_image_data_update(eco->main, eco->image,
191 im_data_new, eco->w, eco->h); 90 im_data_new, eco->w, eco->h);
@@ -201,9 +100,9 @@ _red_slider_changed(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
201 unsigned int *image_data, *image_data_two; 100 unsigned int *image_data, *image_data_two;
202 101
203 red = elm_slider_value_get(obj); 102 red = elm_slider_value_get(obj);
204 image_data = _ephoto_color_adjust_red(eco, red, NULL); 103 image_data = _ephoto_apply_color_adjustment(eco, NULL, red, EPHOTO_COLOR_ADJUST_RED);
205 image_data_two = _ephoto_color_adjust_green(eco, eco->green, image_data); 104 image_data_two = _ephoto_apply_color_adjustment(eco, image_data, eco->green, EPHOTO_COLOR_ADJUST_GREEN);
206 _ephoto_color_adjust_blue(eco, eco->blue, image_data_two); 105 _ephoto_apply_color_adjustment(eco, image_data_two, eco->blue, EPHOTO_COLOR_ADJUST_BLUE);
207} 106}
208 107
209static void 108static void
@@ -215,9 +114,9 @@ _green_slider_changed(void *data, Evas_Object *obj,
215 unsigned int *image_data, *image_data_two; 114 unsigned int *image_data, *image_data_two;
216 115
217 green = elm_slider_value_get(obj); 116 green = elm_slider_value_get(obj);
218 image_data = _ephoto_color_adjust_green(eco, green, NULL); 117 image_data = _ephoto_apply_color_adjustment(eco, NULL, green, EPHOTO_COLOR_ADJUST_GREEN);
219 image_data_two = _ephoto_color_adjust_red(eco, eco->red, image_data); 118 image_data_two = _ephoto_apply_color_adjustment(eco, image_data, eco->red, EPHOTO_COLOR_ADJUST_RED);
220 _ephoto_color_adjust_blue(eco, eco->blue, image_data_two); 119 _ephoto_apply_color_adjustment(eco, image_data_two, eco->blue, EPHOTO_COLOR_ADJUST_BLUE);
221} 120}
222 121
223static void 122static void
@@ -229,9 +128,9 @@ _blue_slider_changed(void *data, Evas_Object *obj,
229 unsigned int *image_data, *image_data_two; 128 unsigned int *image_data, *image_data_two;
230 129
231 blue = elm_slider_value_get(obj); 130 blue = elm_slider_value_get(obj);
232 image_data = _ephoto_color_adjust_blue(eco, blue, NULL); 131 image_data = _ephoto_apply_color_adjustment(eco, NULL, blue, EPHOTO_COLOR_ADJUST_BLUE);
233 image_data_two = _ephoto_color_adjust_red(eco, eco->red, image_data); 132 image_data_two = _ephoto_apply_color_adjustment(eco, image_data, eco->red, EPHOTO_COLOR_ADJUST_RED);
234 _ephoto_color_adjust_green(eco, eco->green, image_data_two); 133 _ephoto_apply_color_adjustment(eco, image_data_two, eco->green, EPHOTO_COLOR_ADJUST_GREEN);
235} 134}
236 135
237static Eina_Bool 136static Eina_Bool