pikl 0.2.8 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -0
- data/License.txt +0 -0
- data/Manifest.txt +17 -17
- data/README.txt +0 -0
- data/config/hoe.rb +9 -6
- data/config/requirements.rb +0 -0
- data/ext/pikl/extconf.rb +0 -0
- data/ext/pikl/pikl.h +617 -465
- data/ext/pikl/pikl_affine.c +38 -91
- data/ext/pikl/pikl_affine.h +0 -0
- data/ext/pikl/pikl_bitmap.c +0 -0
- data/ext/pikl/pikl_bitmap.h +0 -0
- data/ext/pikl/pikl_blur.c +4 -8
- data/ext/pikl/pikl_blur.h +0 -0
- data/ext/pikl/pikl_camera.c +218 -0
- data/ext/pikl/{pikl_effect3.h → pikl_camera.h} +2 -2
- data/ext/pikl/pikl_composite.c +175 -0
- data/ext/pikl/pikl_composite.h +12 -0
- data/ext/pikl/pikl_decrease.c +110 -45
- data/ext/pikl/pikl_decrease.h +0 -7
- data/ext/pikl/pikl_divide.c +116 -0
- data/ext/pikl/pikl_divide.h +11 -0
- data/ext/pikl/pikl_effect.c +583 -151
- data/ext/pikl/pikl_effect.h +32 -6
- data/ext/pikl/pikl_enhance.c +274 -0
- data/ext/pikl/pikl_enhance.h +20 -0
- data/ext/pikl/pikl_io.c +174 -23
- data/ext/pikl/pikl_io.h +0 -0
- data/ext/pikl/pikl_jpeg.c +0 -0
- data/ext/pikl/pikl_jpeg.h +0 -0
- data/ext/pikl/pikl_pattern.c +383 -357
- data/ext/pikl/pikl_pattern.h +0 -0
- data/ext/pikl/pikl_pixel.c +173 -0
- data/ext/pikl/{pikl_trim.h → pikl_pixel.h} +2 -2
- data/ext/pikl/pikl_png.c +0 -0
- data/ext/pikl/pikl_png.h +0 -0
- data/ext/pikl/pikl_private.h +12 -5
- data/ext/pikl/pikl_resize.c +0 -0
- data/ext/pikl/pikl_resize.h +0 -0
- data/ext/pikl/pikl_rotate.c +409 -51
- data/ext/pikl/pikl_rotate.h +8 -0
- data/ext/pikl/pikl_scrap.c +263 -483
- data/ext/pikl/pikl_scrap.h +0 -0
- data/ext/pikl/pikl_special.c +168 -0
- data/ext/pikl/{pikl_effect4.h → pikl_special.h} +2 -2
- data/ext/pikl/pikl_voronoi.c +320 -0
- data/ext/pikl/pikl_voronoi.h +37 -0
- data/lib/pikl.rb +4 -2
- data/lib/pikl/color.rb +47 -0
- data/lib/pikl/const.rb +106 -22
- data/lib/pikl/errors.rb +0 -0
- data/lib/pikl/ext.rb +115 -8
- data/lib/pikl/filter.rb +371 -0
- data/lib/pikl/image.rb +124 -117
- data/lib/pikl/version.rb +2 -2
- data/setup.rb +0 -0
- data/test/sample.jpg +0 -0
- data/test/test_helper.rb +0 -0
- data/test/test_pikl_image.rb +0 -14
- data/test/test_pikl_image2.rb +541 -0
- metadata +35 -23
- data/ext/pikl/decrease/fsdither.h +0 -554
- data/ext/pikl/decrease/median.c +0 -1179
- data/ext/pikl/decrease/median.h +0 -7
- data/ext/pikl/decrease/neuquan5.c +0 -563
- data/ext/pikl/decrease/neuquant.h +0 -62
- data/ext/pikl/decrease/wu.c +0 -447
- data/ext/pikl/decrease/wu.h +0 -7
- data/ext/pikl/pikl_effect2.c +0 -240
- data/ext/pikl/pikl_effect2.h +0 -55
- data/ext/pikl/pikl_effect3.c +0 -266
- data/ext/pikl/pikl_effect4.c +0 -495
- data/ext/pikl/pikl_rotate2.c +0 -312
- data/ext/pikl/pikl_rotate2.h +0 -19
- data/ext/pikl/pikl_trim.c +0 -28
data/ext/pikl/pikl_rotate2.c
DELETED
@@ -1,312 +0,0 @@
|
|
1
|
-
#include "pikl_rotate2.h"
|
2
|
-
|
3
|
-
static void get_rect(PIKL_RECT *rect, int w, int h, float rad);
|
4
|
-
static int ext_cmp_int(const void *a, const void *b);
|
5
|
-
static int pkl_rotate_nn(PKLImage pkl, float angle, unsigned char *backcolor);
|
6
|
-
static int pkl_rotate_bl(PKLImage pkl, float angle, unsigned char *backcolor);
|
7
|
-
static int pkl_rotate_bc(PKLImage pkl, float angle, unsigned char *backcolor);
|
8
|
-
//static int pkl_rotate_pa(PKLImage pkl, float angle, int backcolor);
|
9
|
-
//===================================================================
|
10
|
-
// pkl_rotate2
|
11
|
-
//===================================================================
|
12
|
-
PKLExport int pkl_rotate2(PKLImage pkl, float angle, PKL_SAMPLE sample,
|
13
|
-
unsigned char a, unsigned char b, unsigned char c, unsigned char d)
|
14
|
-
{
|
15
|
-
unsigned char backcolor[4];
|
16
|
-
|
17
|
-
backcolor[0] = a;
|
18
|
-
backcolor[1] = b;
|
19
|
-
backcolor[2] = c;
|
20
|
-
backcolor[3] = d;
|
21
|
-
|
22
|
-
switch(sample){
|
23
|
-
case PKL_SAMPLE_NN:
|
24
|
-
return pkl_rotate_nn(pkl, angle, backcolor);
|
25
|
-
case PKL_SAMPLE_BL:
|
26
|
-
return pkl_rotate_bl(pkl, angle, backcolor);
|
27
|
-
case PKL_SAMPLE_BC:
|
28
|
-
case PKL_SAMPLE_PA:
|
29
|
-
case PKL_SAMPLE_LZ:
|
30
|
-
return pkl_rotate_bc(pkl, angle, backcolor);
|
31
|
-
//return pkl_rotate_pa(pkl, angle, backcolor);
|
32
|
-
default:
|
33
|
-
return(1);
|
34
|
-
}
|
35
|
-
return(1);
|
36
|
-
}
|
37
|
-
|
38
|
-
//=============================================================================
|
39
|
-
// rotate_pos
|
40
|
-
//=============================================================================
|
41
|
-
static void get_rect(PIKL_RECT *rect, int width, int height, float rad)
|
42
|
-
{
|
43
|
-
int nimg_x[4], nimg_y[4];
|
44
|
-
int i, x, y;
|
45
|
-
|
46
|
-
nimg_x[0] = 0;
|
47
|
-
nimg_y[0] = 0;
|
48
|
-
nimg_x[1] = width;
|
49
|
-
nimg_y[1] = 0;
|
50
|
-
nimg_x[2] = 0;
|
51
|
-
nimg_y[2] = height;
|
52
|
-
nimg_x[3] = width;
|
53
|
-
nimg_y[3] = height;
|
54
|
-
|
55
|
-
for(i=0; i<4; i++){
|
56
|
-
x = (int)(cos(-rad)*nimg_x[i] - sin(-rad)*nimg_y[i]);
|
57
|
-
y = (int)(sin(-rad)*nimg_x[i] + cos(-rad)*nimg_y[i]);
|
58
|
-
nimg_x[i] = x;
|
59
|
-
nimg_y[i] = y;
|
60
|
-
}
|
61
|
-
qsort(nimg_x, 4, sizeof(int), ext_cmp_int);
|
62
|
-
qsort(nimg_y, 4, sizeof(int), ext_cmp_int);
|
63
|
-
rect->left = nimg_x[0];
|
64
|
-
rect->top = nimg_y[0];
|
65
|
-
rect->right = nimg_x[3];
|
66
|
-
rect->bottom = nimg_y[3];
|
67
|
-
}
|
68
|
-
|
69
|
-
//=================================================================================
|
70
|
-
// ext_cmp_int
|
71
|
-
//=================================================================================
|
72
|
-
static int ext_cmp_int(const void *a, const void *b)
|
73
|
-
{
|
74
|
-
return *((int *)a) - *((int *)b);
|
75
|
-
}
|
76
|
-
|
77
|
-
//=============================================================================
|
78
|
-
// pkl_rotate_nn
|
79
|
-
//=============================================================================
|
80
|
-
static int pkl_rotate_nn(PKLImage pkl, float angle, unsigned char *backcolor)
|
81
|
-
{
|
82
|
-
int width, height;
|
83
|
-
PIKL_RECT rect;
|
84
|
-
float rad;
|
85
|
-
unsigned char *wrk, back[4];
|
86
|
-
int i, j, px, py;
|
87
|
-
|
88
|
-
rad = -angle*M_PI/180;
|
89
|
-
get_rect(&rect, pkl->width, pkl->height, rad);
|
90
|
-
width = rect.right - rect.left;
|
91
|
-
height = rect.bottom - rect.top;
|
92
|
-
|
93
|
-
wrk = malloc(width * height * pkl->channel);
|
94
|
-
if(!wrk) return(1);
|
95
|
-
memset(wrk, 0, width*height*pkl->channel);
|
96
|
-
|
97
|
-
//for(i=0; i<pkl->channel; i++)
|
98
|
-
// back[i] = (backcolor>>((pkl->channel-i)*8) & 0xFF);
|
99
|
-
memcpy(back, backcolor, pkl->channel);
|
100
|
-
|
101
|
-
for(i=rect.top; i<rect.bottom; i++){
|
102
|
-
for(j=rect.left; j<rect.right; j++){
|
103
|
-
px = (int)(cos(rad) * j - sin(rad) * i);
|
104
|
-
py = (int)(sin(rad) * j + cos(rad) * i);
|
105
|
-
if(px>=0 && px<pkl->width && py>=0 && py<pkl->height){
|
106
|
-
memcpy(&wrk[((i-rect.top)*width+j-rect.left)*pkl->channel],
|
107
|
-
&pkl->image[(py*pkl->width+px)*pkl->channel], pkl->channel);
|
108
|
-
}else{
|
109
|
-
memcpy(&wrk[((i-rect.top)*width+j-rect.left)*pkl->channel], back, pkl->channel);
|
110
|
-
}
|
111
|
-
}
|
112
|
-
}
|
113
|
-
|
114
|
-
free(pkl->image);
|
115
|
-
pkl->image = wrk;
|
116
|
-
pkl->width = width;
|
117
|
-
pkl->height = height;
|
118
|
-
return(0);
|
119
|
-
}
|
120
|
-
|
121
|
-
//=============================================================================
|
122
|
-
// pkl_rotate_bl
|
123
|
-
//=============================================================================
|
124
|
-
static int pkl_rotate_bl(PKLImage pkl, float angle, unsigned char *backcolor)
|
125
|
-
{
|
126
|
-
int width, height;
|
127
|
-
PIKL_RECT rect;
|
128
|
-
float rad;
|
129
|
-
unsigned char *wrk, back[4];
|
130
|
-
int i, j, k, wx, wy, sx, sy;
|
131
|
-
double dx, dy, px, py, f[4];
|
132
|
-
|
133
|
-
rad = -angle*M_PI/180;
|
134
|
-
get_rect(&rect, pkl->width, pkl->height, rad);
|
135
|
-
width = rect.right - rect.left;
|
136
|
-
height = rect.bottom - rect.top;
|
137
|
-
|
138
|
-
wrk = malloc(width * height * pkl->channel);
|
139
|
-
if(!wrk) return(1);
|
140
|
-
memset(wrk, 0, width*height*pkl->channel);
|
141
|
-
|
142
|
-
//for(i=0; i<pkl->channel; i++)
|
143
|
-
// back[i] = (backcolor>>((pkl->channel-i)*8) & 0xFF);
|
144
|
-
memcpy(back, backcolor, pkl->channel);
|
145
|
-
|
146
|
-
for(i=rect.top; i<rect.bottom; i++){
|
147
|
-
for(j=rect.left; j<rect.right; j++){
|
148
|
-
dx = modf(cos(rad)*j-sin(rad)*i, &px);
|
149
|
-
dy = modf(sin(rad)*j+cos(rad)*i, &py);
|
150
|
-
f[0] = (1.0-dx)*(1.0-dy);
|
151
|
-
f[1] = dx*(1.0-dy);
|
152
|
-
f[2] = (1.0-dx)*dy;
|
153
|
-
f[3] = dx*dy;
|
154
|
-
|
155
|
-
for(wy=0; wy<2; wy++){
|
156
|
-
for(wx=0; wx<2; wx++){
|
157
|
-
sx = ((int)px+wx<0) ? pkl->width +((int)px+wx)%pkl->width -1 : ((int)px+wx)%pkl->width;
|
158
|
-
sy = ((int)py+wy<0) ? pkl->height+((int)py+wy)%pkl->height-1 : ((int)py+wy)%pkl->height;
|
159
|
-
if(px>=0 && px<pkl->width && py>=0 && py<pkl->height){
|
160
|
-
for(k=0; k<pkl->channel; k++){
|
161
|
-
wrk[((i-rect.top)*width+j-rect.left)*pkl->channel+k] =
|
162
|
-
PKL_COLOR_CLIP(wrk[((i-rect.top)*width+j-rect.left)*pkl->channel+k] +
|
163
|
-
pkl->image[(sy*pkl->width+sx)*pkl->channel+k] * f[wy*2+wx]);
|
164
|
-
}
|
165
|
-
}else{
|
166
|
-
memcpy(&wrk[((i-rect.top)*width+j-rect.left)*pkl->channel], back, pkl->channel);
|
167
|
-
}
|
168
|
-
}
|
169
|
-
}
|
170
|
-
}
|
171
|
-
}
|
172
|
-
|
173
|
-
free(pkl->image);
|
174
|
-
pkl->image = wrk;
|
175
|
-
pkl->width = width;
|
176
|
-
pkl->height = height;
|
177
|
-
return(0);
|
178
|
-
}
|
179
|
-
|
180
|
-
//=============================================================================
|
181
|
-
// pkl_rotate_bc
|
182
|
-
//=============================================================================
|
183
|
-
static int pkl_rotate_bc(PKLImage pkl, float angle, unsigned char *backcolor)
|
184
|
-
{
|
185
|
-
int width, height;
|
186
|
-
PIKL_RECT rect;
|
187
|
-
float rad;
|
188
|
-
unsigned char *wrk, back[4];
|
189
|
-
int i, j, k, px, py, x0, y0;
|
190
|
-
double wx, wy, dx, dy, sx, sy;
|
191
|
-
double data[PKL_CHANNEL];
|
192
|
-
|
193
|
-
rad = -angle*M_PI/180;
|
194
|
-
get_rect(&rect, pkl->width, pkl->height, rad);
|
195
|
-
width = rect.right - rect.left;
|
196
|
-
height = rect.bottom - rect.top;
|
197
|
-
|
198
|
-
wrk = malloc(width * height * pkl->channel);
|
199
|
-
if(!wrk) return(1);
|
200
|
-
memset(wrk, 0, width*height*pkl->channel);
|
201
|
-
|
202
|
-
//for(i=0; i<pkl->channel; i++)
|
203
|
-
// back[i] = (backcolor>>((pkl->channel-i)*8) & 0xFF);
|
204
|
-
memcpy(back, backcolor, pkl->channel);
|
205
|
-
|
206
|
-
for(i=rect.top; i<rect.bottom; i++){
|
207
|
-
for(j=rect.left; j<rect.right; j++){
|
208
|
-
memset(&data, 0, sizeof(data));
|
209
|
-
sx = cos(rad) * j - sin(rad) * i;
|
210
|
-
sy = sin(rad) * j + cos(rad) * i;
|
211
|
-
for(py=(int)sy-1; py<=(int)sy+2; py++){
|
212
|
-
for(px=(int)sx-1; px<=(int)sx+2; px++){
|
213
|
-
dx = fabs(sx-px);
|
214
|
-
dy = fabs(sy-py);
|
215
|
-
wx = (dx<1) ? (dx-1)*(dx*dx-dx-1) : -(dx-1)*(dx-2)*(dx-2);
|
216
|
-
wy = (dy<1) ? (dy-1)*(dy*dy-dy-1) : -(dy-1)*(dy-2)*(dy-2);
|
217
|
-
x0 = (px<0 || px>pkl->width -1) ? sx : px;
|
218
|
-
y0 = (py<0 || py>pkl->height-1) ? sy : py;
|
219
|
-
|
220
|
-
if(x0>=0 && x0<pkl->width && y0>=0 && y0<pkl->height){
|
221
|
-
for(k=0; k<pkl->channel; k++)
|
222
|
-
data[k] += pkl->image[(y0*pkl->width+x0)*pkl->channel+k]*wx*wy;
|
223
|
-
}
|
224
|
-
}
|
225
|
-
}
|
226
|
-
|
227
|
-
if(sx>=0 && sx<pkl->width && sy>=0 && sy<pkl->height){
|
228
|
-
for(k=0; k<pkl->channel; k++)
|
229
|
-
wrk[((i-rect.top)*width+j-rect.left)*pkl->channel+k] = PKL_COLOR_CLIP(data[k]);
|
230
|
-
}else{
|
231
|
-
memcpy(&wrk[((i-rect.top)*width+j-rect.left)*pkl->channel], back, pkl->channel);
|
232
|
-
}
|
233
|
-
}
|
234
|
-
}
|
235
|
-
|
236
|
-
free(pkl->image);
|
237
|
-
pkl->image = wrk;
|
238
|
-
pkl->width = width;
|
239
|
-
pkl->height = height;
|
240
|
-
return(0);
|
241
|
-
}
|
242
|
-
|
243
|
-
////=============================================================================
|
244
|
-
//// pkl_rotate_pa
|
245
|
-
////=============================================================================
|
246
|
-
//static int pkl_rotate_pa(PKLImage pkl, float angle, int backcolor)
|
247
|
-
//{
|
248
|
-
// int width, height;
|
249
|
-
// PIKL_RECT rect;
|
250
|
-
// float rad;
|
251
|
-
// unsigned char *wrk, back[4];
|
252
|
-
// int i, j;
|
253
|
-
// double zx, zy, power;
|
254
|
-
//
|
255
|
-
// rad = -angle*M_PI/180;
|
256
|
-
// get_rect(&rect, pkl->width, pkl->height, rad);
|
257
|
-
// width = rect.right - rect.left;
|
258
|
-
// height = rect.bottom - rect.top;
|
259
|
-
//
|
260
|
-
// wrk = malloc(width * height * pkl->channel);
|
261
|
-
// if(!wrk) return(1);
|
262
|
-
// memset(wrk, 0, width*height*pkl->channel);
|
263
|
-
//
|
264
|
-
// for(i=0; i<pkl->channel; i++)
|
265
|
-
// back[i] = (backcolor>>((pkl->channel-i)*8) & 0xFF);
|
266
|
-
//
|
267
|
-
// zx = (double)pkl->width / (double)width;
|
268
|
-
// zy = (double)pkl->height / (double)height;
|
269
|
-
// //���_�����������ϒl�Z�o�l
|
270
|
-
// power= zx*zy + (zx*zy * angle*M_PI/180 * angle*M_PI/180);
|
271
|
-
//
|
272
|
-
// for(i=rect.top; i<rect.bottom; i++){
|
273
|
-
// for(j=rect.left; j<rect.right; j++){
|
274
|
-
// double w1, w2, h1, h2;
|
275
|
-
// double w1b, w2b, h1b, h2b;
|
276
|
-
// double bi, ixg[PKL_CHANNEL] = {0.0, 0.0, 0.0, 0.0};
|
277
|
-
// int fsx ,fsy, s, t, k;
|
278
|
-
//
|
279
|
-
// w1b = modf(cos(rad)*j -sin(rad)*i, &w1);
|
280
|
-
// w2b = modf(cos(rad)*(j+1)-sin(rad)*i, &w2);
|
281
|
-
// h1b = modf(sin(rad)*j +cos(rad)*i, &h1);
|
282
|
-
// h2b = modf(sin(rad)*j+cos(rad)*(i+1), &h2);
|
283
|
-
//
|
284
|
-
// for(s=(int)w1; s<=(int)w2; s++){
|
285
|
-
// for(t=(int)h1; t<=(int)h2; t++){
|
286
|
-
// bi = 1.0;
|
287
|
-
// if(s == (int)w1) bi*=(1-w1b);
|
288
|
-
// if(s == (int)w2) bi*=(w2b);
|
289
|
-
// if(t == (int)h1) bi*=(1-h1b);
|
290
|
-
// if(t == (int)h2) bi*=(h2b);
|
291
|
-
// fsx = (s < 0) ? 0 : (s > pkl->width -1) ? pkl->width -1 : s;
|
292
|
-
// fsy = (t < 0) ? 0 : (t > pkl->height-1) ? pkl->height-1 : t;
|
293
|
-
// for(k=0; k<pkl->channel; k++)
|
294
|
-
// ixg[k] += pkl->image[(fsy*pkl->width+fsx)*pkl->channel+k] * bi;
|
295
|
-
// }
|
296
|
-
// }
|
297
|
-
//
|
298
|
-
// if((int)w1>=0 && (int)w1<pkl->width && (int)h1>=0 && (int)h1<pkl->height){
|
299
|
-
// for(k=0; k<pkl->channel; k++)
|
300
|
-
// wrk[((i-rect.top)*width+j-rect.left)*pkl->channel+k] = PKL_RGB(ixg[k]/power);
|
301
|
-
// }else{
|
302
|
-
// memcpy(&wrk[((i-rect.top)*width+j-rect.left)*pkl->channel], back, pkl->channel);
|
303
|
-
// }
|
304
|
-
//
|
305
|
-
// }
|
306
|
-
// }
|
307
|
-
// free(pkl->image);
|
308
|
-
// pkl->image = wrk;
|
309
|
-
// pkl->width = width;
|
310
|
-
// pkl->height = height;
|
311
|
-
// return(0);
|
312
|
-
//}
|
data/ext/pikl/pikl_rotate2.h
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
#ifndef _LIB_PIKL_ROTATE2_
|
2
|
-
#define _LIB_PIKL_ROTATE2_
|
3
|
-
|
4
|
-
#include <stdio.h>
|
5
|
-
#include <stdlib.h>
|
6
|
-
#include <string.h>
|
7
|
-
#include <math.h>
|
8
|
-
#include "pikl.h"
|
9
|
-
#include "pikl_private.h"
|
10
|
-
|
11
|
-
typedef struct{
|
12
|
-
int left;
|
13
|
-
int top;
|
14
|
-
int right;
|
15
|
-
int bottom;
|
16
|
-
} PIKL_RECT;
|
17
|
-
|
18
|
-
#endif
|
19
|
-
|
data/ext/pikl/pikl_trim.c
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
#include "pikl_trim.h"
|
2
|
-
|
3
|
-
//=================================================================================
|
4
|
-
// pkl_trim
|
5
|
-
//=================================================================================
|
6
|
-
PKLExport int pkl_trim(PKLImage pkl, int sx, int sy, int width, int height)
|
7
|
-
{
|
8
|
-
unsigned char *wrk;
|
9
|
-
int p, y;
|
10
|
-
|
11
|
-
if( sx < 0 || sy < 0 || width <= 0 || height <= 0 ) return(1);
|
12
|
-
if( sx+width > pkl->width ) return(1);
|
13
|
-
if( sy+height > pkl->height ) return(1);
|
14
|
-
|
15
|
-
wrk = malloc(height * width * pkl->channel);
|
16
|
-
if(!wrk) return(1);
|
17
|
-
|
18
|
-
for(p=0,y=sy; y<sy+height; p++,y++){
|
19
|
-
memcpy(&wrk[p*width*pkl->channel], &pkl->image[(y*pkl->width+sx)*pkl->channel], width*pkl->channel);
|
20
|
-
}
|
21
|
-
|
22
|
-
free(pkl->image);
|
23
|
-
pkl->image = wrk;
|
24
|
-
pkl->height = height;
|
25
|
-
pkl->width = width;
|
26
|
-
|
27
|
-
return(0);
|
28
|
-
}
|