morandi 0.12.0 → 0.99.03
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -1
- data/README.md +6 -1
- data/ext/gdk_pixbuf_cairo/extconf.rb +124 -0
- data/ext/gdk_pixbuf_cairo/gdk_pixbuf_cairo.c +260 -0
- data/ext/morandi_native/extconf.rb +121 -0
- data/ext/morandi_native/filter.h +229 -0
- data/ext/morandi_native/gamma.h +48 -0
- data/ext/morandi_native/mask.h +75 -0
- data/ext/morandi_native/morandi_native.c +1126 -0
- data/ext/morandi_native/rotate.h +79 -0
- data/ext/morandi_native/tint.h +72 -0
- data/lib/gdk_pixbuf_cairo.so +0 -0
- data/lib/morandi/cairo_ext.rb +56 -0
- data/lib/morandi/crop_utils.rb +95 -0
- data/lib/morandi/image_operation.rb +205 -0
- data/lib/morandi/image_processor.rb +180 -180
- data/lib/morandi/pixbuf_ext.rb +19 -0
- data/lib/morandi/profiled_pixbuf.rb +40 -61
- data/lib/morandi/redeye.rb +35 -47
- data/lib/morandi/version.rb +3 -1
- data/lib/morandi.rb +33 -11
- data/lib/morandi_native.so +0 -0
- metadata +52 -117
- data/.gitignore +0 -18
- data/.rspec +0 -3
- data/.ruby-version +0 -1
- data/Gemfile +0 -4
- data/Rakefile +0 -1
- data/lib/morandi/image-ops.rb +0 -307
- data/lib/morandi/utils.rb +0 -136
- data/morandi.gemspec +0 -33
- data/sample/100_mb_image.jpg +0 -0
- data/sample/sample.jpg +0 -0
- data/spec/morandi_spec.rb +0 -208
- data/spec/spec_helper.rb +0 -19
@@ -0,0 +1,229 @@
|
|
1
|
+
#include <math.h>
|
2
|
+
|
3
|
+
inline unsigned char pix_value(int value) {
|
4
|
+
if (value < 0)
|
5
|
+
return 0;
|
6
|
+
if (value > 255)
|
7
|
+
return 255;
|
8
|
+
return (unsigned char) value;
|
9
|
+
}
|
10
|
+
|
11
|
+
static GdkPixbuf *pixbuf_adjust_brightness(GdkPixbuf *src, GdkPixbuf *dest, int adjust) {
|
12
|
+
int s_has_alpha, d_has_alpha;
|
13
|
+
int s_width, s_height, s_rowstride;
|
14
|
+
int d_width, d_height, d_rowstride;
|
15
|
+
guchar *s_pix, *sp;
|
16
|
+
guchar *d_pix, *dp;
|
17
|
+
int i, j, pix_width;
|
18
|
+
int mod = (int) floor(255 * ((double) adjust / 100.0));
|
19
|
+
|
20
|
+
|
21
|
+
g_return_val_if_fail(src != NULL, NULL);
|
22
|
+
g_return_val_if_fail(dest != NULL, NULL);
|
23
|
+
|
24
|
+
s_width = gdk_pixbuf_get_width(src);
|
25
|
+
s_height = gdk_pixbuf_get_height(src);
|
26
|
+
s_has_alpha = gdk_pixbuf_get_has_alpha(src);
|
27
|
+
s_rowstride = gdk_pixbuf_get_rowstride(src);
|
28
|
+
s_pix = gdk_pixbuf_get_pixels(src);
|
29
|
+
|
30
|
+
d_width = gdk_pixbuf_get_width(dest);
|
31
|
+
d_height = gdk_pixbuf_get_height(dest);
|
32
|
+
d_has_alpha = gdk_pixbuf_get_has_alpha(dest);
|
33
|
+
d_rowstride = gdk_pixbuf_get_rowstride(dest);
|
34
|
+
d_pix = gdk_pixbuf_get_pixels(dest);
|
35
|
+
|
36
|
+
g_return_val_if_fail(d_width == s_width, NULL);
|
37
|
+
g_return_val_if_fail(d_height == s_height, NULL);
|
38
|
+
g_return_val_if_fail(d_has_alpha == s_has_alpha, NULL);
|
39
|
+
|
40
|
+
pix_width = (s_has_alpha ? 4 : 3);
|
41
|
+
|
42
|
+
|
43
|
+
for (i = 0; i < s_height; i++) {
|
44
|
+
sp = s_pix;
|
45
|
+
dp = d_pix;
|
46
|
+
|
47
|
+
for (j = 0; j < s_width; j++) {
|
48
|
+
|
49
|
+
dp[0] = pix_value(mod + sp[0]);
|
50
|
+
dp[1] = pix_value(mod + sp[1]);
|
51
|
+
dp[2] = pix_value(mod + sp[2]);
|
52
|
+
|
53
|
+
if (s_has_alpha) {
|
54
|
+
dp[3] = sp[3]; /* alpha */
|
55
|
+
}
|
56
|
+
|
57
|
+
dp += pix_width;
|
58
|
+
sp += pix_width;
|
59
|
+
}
|
60
|
+
|
61
|
+
d_pix += d_rowstride;
|
62
|
+
s_pix += s_rowstride;
|
63
|
+
}
|
64
|
+
|
65
|
+
return dest;
|
66
|
+
}
|
67
|
+
|
68
|
+
static GdkPixbuf *pixbuf_adjust_contrast(GdkPixbuf *src, GdkPixbuf *dest, int adjust) {
|
69
|
+
int s_has_alpha, d_has_alpha;
|
70
|
+
int s_width, s_height, s_rowstride;
|
71
|
+
int d_width, d_height, d_rowstride;
|
72
|
+
guchar *s_pix, *sp;
|
73
|
+
guchar *d_pix, *dp;
|
74
|
+
int i, j, pix_width;
|
75
|
+
double mod = pow(((double) adjust + 100.0) / 100.0, 2);
|
76
|
+
|
77
|
+
|
78
|
+
g_return_val_if_fail(src != NULL, NULL);
|
79
|
+
g_return_val_if_fail(dest != NULL, NULL);
|
80
|
+
|
81
|
+
s_width = gdk_pixbuf_get_width(src);
|
82
|
+
s_height = gdk_pixbuf_get_height(src);
|
83
|
+
s_has_alpha = gdk_pixbuf_get_has_alpha(src);
|
84
|
+
s_rowstride = gdk_pixbuf_get_rowstride(src);
|
85
|
+
s_pix = gdk_pixbuf_get_pixels(src);
|
86
|
+
|
87
|
+
d_width = gdk_pixbuf_get_width(dest);
|
88
|
+
d_height = gdk_pixbuf_get_height(dest);
|
89
|
+
d_has_alpha = gdk_pixbuf_get_has_alpha(dest);
|
90
|
+
d_rowstride = gdk_pixbuf_get_rowstride(dest);
|
91
|
+
d_pix = gdk_pixbuf_get_pixels(dest);
|
92
|
+
|
93
|
+
g_return_val_if_fail(d_width == s_width, NULL);
|
94
|
+
g_return_val_if_fail(d_height == s_height, NULL);
|
95
|
+
g_return_val_if_fail(d_has_alpha == s_has_alpha, NULL);
|
96
|
+
|
97
|
+
pix_width = (s_has_alpha ? 4 : 3);
|
98
|
+
|
99
|
+
for (i = 0; i < s_height; i++) {
|
100
|
+
sp = s_pix;
|
101
|
+
dp = d_pix;
|
102
|
+
|
103
|
+
for (j = 0; j < s_width; j++) {
|
104
|
+
|
105
|
+
dp[0] = pix_value(127 + ((((double) sp[0]) - 127) * mod));
|
106
|
+
dp[1] = pix_value(127 + ((((double) sp[1]) - 127) * mod));
|
107
|
+
dp[2] = pix_value(127 + ((((double) sp[2]) - 127) * mod));
|
108
|
+
|
109
|
+
if (s_has_alpha) {
|
110
|
+
dp[3] = sp[3]; /* alpha */
|
111
|
+
}
|
112
|
+
|
113
|
+
dp += pix_width;
|
114
|
+
sp += pix_width;
|
115
|
+
}
|
116
|
+
|
117
|
+
d_pix += d_rowstride;
|
118
|
+
s_pix += s_rowstride;
|
119
|
+
}
|
120
|
+
|
121
|
+
return dest;
|
122
|
+
}
|
123
|
+
|
124
|
+
|
125
|
+
static GdkPixbuf *
|
126
|
+
pixbuf_convolution_matrix(GdkPixbuf *src, GdkPixbuf *dest, int matrix_size, double *matrix, double divisor) {
|
127
|
+
int s_has_alpha, d_has_alpha;
|
128
|
+
int s_width, s_height, s_rowstride;
|
129
|
+
int d_width, d_height, d_rowstride;
|
130
|
+
guchar *s_pix, *sp, *cp;
|
131
|
+
guchar *d_pix, *dp;
|
132
|
+
int i, j, pix_width;
|
133
|
+
|
134
|
+
int xx, yy, mp;
|
135
|
+
int matrix_from, matrix_to;
|
136
|
+
double sum_red, sum_green, sum_blue;
|
137
|
+
|
138
|
+
g_return_val_if_fail(src != NULL, NULL);
|
139
|
+
g_return_val_if_fail(dest != NULL, NULL);
|
140
|
+
|
141
|
+
s_width = gdk_pixbuf_get_width(src);
|
142
|
+
s_height = gdk_pixbuf_get_height(src);
|
143
|
+
s_has_alpha = gdk_pixbuf_get_has_alpha(src);
|
144
|
+
s_rowstride = gdk_pixbuf_get_rowstride(src);
|
145
|
+
s_pix = gdk_pixbuf_get_pixels(src);
|
146
|
+
|
147
|
+
d_width = gdk_pixbuf_get_width(dest);
|
148
|
+
d_height = gdk_pixbuf_get_height(dest);
|
149
|
+
d_has_alpha = gdk_pixbuf_get_has_alpha(dest);
|
150
|
+
d_rowstride = gdk_pixbuf_get_rowstride(dest);
|
151
|
+
d_pix = gdk_pixbuf_get_pixels(dest);
|
152
|
+
|
153
|
+
g_return_val_if_fail(d_width == s_width, NULL);
|
154
|
+
g_return_val_if_fail(d_height == s_height, NULL);
|
155
|
+
g_return_val_if_fail(d_has_alpha == s_has_alpha, NULL);
|
156
|
+
|
157
|
+
pix_width = (s_has_alpha ? 4 : 3);
|
158
|
+
|
159
|
+
mp = matrix_size >> 1;
|
160
|
+
matrix_from = -1 * mp;
|
161
|
+
matrix_to = mp;
|
162
|
+
|
163
|
+
/*
|
164
|
+
fprintf(stderr, "FILTER: %i -> %i", matrix_from, matrix_to);
|
165
|
+
for (yy = matrix_from; yy <= matrix_to; yy ++) {
|
166
|
+
for (xx = matrix_from; xx <= matrix_to; xx ++) {
|
167
|
+
int index = ((mp + yy) * matrix_size) + (mp + xx);
|
168
|
+
double multiplier = matrix[ index ];
|
169
|
+
if ((xx == matrix_from)) {
|
170
|
+
fprintf(stderr, "\n");
|
171
|
+
}
|
172
|
+
fprintf(stderr, "(%i,%i) [%i] : %5.3f ", xx, yy, index, multiplier);
|
173
|
+
}
|
174
|
+
}
|
175
|
+
fprintf(stderr, "\n\n");
|
176
|
+
// */
|
177
|
+
|
178
|
+
for (i = 0; i < s_height; i++) {
|
179
|
+
sp = s_pix;
|
180
|
+
dp = d_pix;
|
181
|
+
|
182
|
+
for (j = 0; j < s_width; j++) {
|
183
|
+
sum_red = 0.0;
|
184
|
+
sum_green = 0.0;
|
185
|
+
sum_blue = 0.0;
|
186
|
+
|
187
|
+
for (yy = matrix_from; yy <= matrix_to; yy++) {
|
188
|
+
for (xx = matrix_from; xx <= matrix_to; xx++) {
|
189
|
+
|
190
|
+
int index = ((mp + yy) * matrix_size) + (mp + xx);
|
191
|
+
double multiplier = matrix[index];
|
192
|
+
|
193
|
+
if (((j + xx) < 0) || ((j + xx) >= s_width) ||
|
194
|
+
((i + yy) < 0) || ((i + yy) >= s_height)) {
|
195
|
+
sum_red += multiplier;
|
196
|
+
sum_green += multiplier;
|
197
|
+
sum_blue += multiplier;
|
198
|
+
continue;
|
199
|
+
}
|
200
|
+
|
201
|
+
cp = sp + (yy * s_rowstride) + (xx * pix_width);
|
202
|
+
sum_red += (multiplier * (double) cp[0]);
|
203
|
+
sum_green += (multiplier * (double) cp[1]);
|
204
|
+
sum_blue += (multiplier * (double) cp[2]);
|
205
|
+
}
|
206
|
+
}
|
207
|
+
sum_red /= divisor;
|
208
|
+
sum_green /= divisor;
|
209
|
+
sum_blue /= divisor;
|
210
|
+
|
211
|
+
dp[0] = pix_value(sum_red); /* red */
|
212
|
+
dp[1] = pix_value(sum_green); /* green */
|
213
|
+
dp[2] = pix_value(sum_blue); /* blue */
|
214
|
+
|
215
|
+
if (s_has_alpha) {
|
216
|
+
dp[3] = sp[3]; /* alpha */
|
217
|
+
}
|
218
|
+
|
219
|
+
dp += pix_width;
|
220
|
+
sp += pix_width;
|
221
|
+
}
|
222
|
+
|
223
|
+
d_pix += d_rowstride;
|
224
|
+
s_pix += s_rowstride;
|
225
|
+
}
|
226
|
+
|
227
|
+
return dest;
|
228
|
+
}
|
229
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
static GdkPixbuf *pixbuf_gamma(GdkPixbuf *src, GdkPixbuf *dest, double gamma) {
|
2
|
+
int has_alpha;
|
3
|
+
int s_width, s_height, s_rowstride;
|
4
|
+
int d_width, d_height, d_rowstride;
|
5
|
+
guchar *s_pix;
|
6
|
+
guchar *d_pix;
|
7
|
+
guchar *sp;
|
8
|
+
guchar *dp;
|
9
|
+
int i, j, pix_width;
|
10
|
+
double map[256] = {0.0,};
|
11
|
+
|
12
|
+
for (i = 0; i < 256; i++)
|
13
|
+
map[i] = 255 * pow((double) i / 255, 1.0 / gamma);
|
14
|
+
|
15
|
+
g_return_val_if_fail(src != NULL, NULL);
|
16
|
+
g_return_val_if_fail(dest != NULL, NULL);
|
17
|
+
|
18
|
+
s_width = gdk_pixbuf_get_width(src);
|
19
|
+
s_height = gdk_pixbuf_get_height(src);
|
20
|
+
has_alpha = gdk_pixbuf_get_has_alpha(src);
|
21
|
+
s_rowstride = gdk_pixbuf_get_rowstride(src);
|
22
|
+
s_pix = gdk_pixbuf_get_pixels(src);
|
23
|
+
|
24
|
+
d_width = gdk_pixbuf_get_width(dest);
|
25
|
+
d_height = gdk_pixbuf_get_height(dest);
|
26
|
+
d_rowstride = gdk_pixbuf_get_rowstride(dest);
|
27
|
+
d_pix = gdk_pixbuf_get_pixels(dest);
|
28
|
+
|
29
|
+
g_return_val_if_fail(d_width == s_width, NULL);
|
30
|
+
g_return_val_if_fail(d_height == s_height, NULL);
|
31
|
+
g_return_val_if_fail(has_alpha == gdk_pixbuf_get_has_alpha(dest), NULL);
|
32
|
+
|
33
|
+
pix_width = (has_alpha ? 4 : 3);
|
34
|
+
|
35
|
+
for (i = 0; i < s_height; i++) {
|
36
|
+
sp = s_pix + (i * s_rowstride);
|
37
|
+
dp = d_pix + (i * d_rowstride);
|
38
|
+
for (j = 0; j < s_width; j++) {
|
39
|
+
*(dp++) = map[*(sp++)]; /* red */
|
40
|
+
*(dp++) = map[*(sp++)]; /* green */
|
41
|
+
*(dp++) = map[*(sp++)]; /* blue */
|
42
|
+
if (has_alpha) *(dp++) = map[*(sp++)]; /* alpha */
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
return dest;
|
47
|
+
}
|
48
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#define GIMP_RGB_TO_GREY(r,g,b) (((77 * r) + (151 * g) + (28 * b)) >> 8)
|
2
|
+
|
3
|
+
static GdkPixbuf *pixbuf_mask(GdkPixbuf *src, GdkPixbuf *mask)
|
4
|
+
{
|
5
|
+
int s_has_alpha, m_has_alpha;
|
6
|
+
int s_width, s_height, s_rowstride;
|
7
|
+
int d_width, d_height, d_rowstride;
|
8
|
+
int m_width, m_height, m_rowstride;
|
9
|
+
guchar *s_pix, *sp;
|
10
|
+
guchar *d_pix, *dp;
|
11
|
+
guchar *m_pix, *mp;
|
12
|
+
int i, j, pix_width, alpha, grey;
|
13
|
+
pixel_t pix;
|
14
|
+
GdkPixbuf *dest;
|
15
|
+
|
16
|
+
g_return_val_if_fail(src != NULL, NULL);
|
17
|
+
|
18
|
+
s_width = gdk_pixbuf_get_width(src);
|
19
|
+
s_height = gdk_pixbuf_get_height(src);
|
20
|
+
s_has_alpha = gdk_pixbuf_get_has_alpha(src);
|
21
|
+
s_rowstride = gdk_pixbuf_get_rowstride(src);
|
22
|
+
s_pix = gdk_pixbuf_get_pixels(src);
|
23
|
+
|
24
|
+
g_return_val_if_fail(mask != NULL, NULL);
|
25
|
+
|
26
|
+
m_width = gdk_pixbuf_get_width(mask);
|
27
|
+
m_height = gdk_pixbuf_get_height(mask);
|
28
|
+
m_has_alpha = gdk_pixbuf_get_has_alpha(mask);
|
29
|
+
m_rowstride = gdk_pixbuf_get_rowstride(mask);
|
30
|
+
m_pix = gdk_pixbuf_get_pixels(mask);
|
31
|
+
|
32
|
+
g_return_val_if_fail(m_width <= s_width, NULL);
|
33
|
+
g_return_val_if_fail(m_height <= s_height, NULL);
|
34
|
+
|
35
|
+
d_width = m_width;
|
36
|
+
d_height = m_height;
|
37
|
+
dest = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, d_width, d_height);
|
38
|
+
|
39
|
+
g_return_val_if_fail(dest != NULL, NULL);
|
40
|
+
|
41
|
+
d_rowstride = gdk_pixbuf_get_rowstride(dest);
|
42
|
+
d_pix = gdk_pixbuf_get_pixels(dest);
|
43
|
+
|
44
|
+
pix_width = (m_has_alpha ? 4 : 3);
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
for (i = 0; i < m_height; i++) {
|
49
|
+
sp = s_pix + (i * s_rowstride);
|
50
|
+
dp = d_pix + (i * d_rowstride);
|
51
|
+
mp = m_pix + (i * m_rowstride);
|
52
|
+
|
53
|
+
for (j = 0; j < m_width; j++) {
|
54
|
+
*(dp++) = *(sp++); /* red */
|
55
|
+
*(dp++) = *(sp++); /* green */
|
56
|
+
*(dp++) = *(sp++); /* blue */
|
57
|
+
|
58
|
+
if (s_has_alpha)
|
59
|
+
{
|
60
|
+
alpha = *(sp++); /* alpha */
|
61
|
+
}
|
62
|
+
else
|
63
|
+
{
|
64
|
+
alpha = 0xff;
|
65
|
+
}
|
66
|
+
|
67
|
+
pix = PIXEL(mp, pix_width, j);
|
68
|
+
grey = GIMP_RGB_TO_GREY(pix->r, pix->g, pix->b);
|
69
|
+
|
70
|
+
*(dp++) = sqrt(alpha * (255 - grey)); /* alpha */
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
return dest;
|
75
|
+
}
|