pikl 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +3 -0
- data/Manifest.txt +2 -0
- data/config/hoe.rb +2 -2
- data/ext/pikl/pikl.h +5 -0
- data/ext/pikl/pikl_png.c +10 -10
- data/ext/pikl/pikl_png.h +1 -1
- data/ext/pikl/pikl_rotate2.c +312 -0
- data/ext/pikl/pikl_rotate2.h +19 -0
- data/lib/pikl/ext.rb +3 -1
- data/lib/pikl/image.rb +23 -3
- data/lib/pikl/version.rb +1 -1
- data/test/test_pikl_image.rb +7 -1
- metadata +42 -47
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/config/hoe.rb
CHANGED
@@ -61,7 +61,7 @@ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
|
61
61
|
p.description = DESCRIPTION
|
62
62
|
p.summary = DESCRIPTION
|
63
63
|
p.url = HOMEPATH
|
64
|
-
p.rubyforge_name = (PACKAGE_PLATFORM =~ /mswin32/) ? "#{GEM_NAME}-mswin32" : GEM_NAME
|
64
|
+
p.rubyforge_name = (PACKAGE_PLATFORM =~ /mswin32/) ? "#{GEM_NAME}-x86-mswin32" : GEM_NAME
|
65
65
|
|
66
66
|
p.test_globs = ["test/**/test_*.rb"]
|
67
67
|
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
@@ -70,7 +70,7 @@ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
|
70
70
|
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
71
71
|
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
72
72
|
if PACKAGE_PLATFORM =~ /mswin32/
|
73
|
-
platform = Gem::Platform.new('mswin32')
|
73
|
+
platform = Gem::Platform.respond_to?(:new) ? Gem::Platform.new('mswin32') : Gem::Platform::WIN32
|
74
74
|
p.spec_extras[:platform] = platform
|
75
75
|
else
|
76
76
|
p.spec_extras[:extensions] = ['ext/pikl/extconf.rb']
|
data/ext/pikl/pikl.h
CHANGED
@@ -131,6 +131,11 @@ PKLExport int pkl_trim(PKLImage pkl, int sx, int sy, int width, int height);
|
|
131
131
|
*/
|
132
132
|
PKLExport int pkl_rotate(PKLImage pkl, PKL_ANGLE angle);
|
133
133
|
|
134
|
+
//#define pkl_color(a,b,c,d) ((a<<24)+(b<<16)+(c<<8)+d)
|
135
|
+
//PKLExport int pkl_rotate2(PKLImage pkl, float angle, PKL_SAMPLE sample, int backcolor);
|
136
|
+
PKLExport int pkl_rotate2(PKLImage pkl, float angle, PKL_SAMPLE sample,
|
137
|
+
unsigned char a, unsigned char b, unsigned char c, unsigned char d);
|
138
|
+
|
134
139
|
/*!
|
135
140
|
拡大・縮小します。<br>
|
136
141
|
@param pkl [in] PKLImageオブジェクト
|
data/ext/pikl/pikl_png.c
CHANGED
@@ -24,11 +24,11 @@ int load_png(PKLImage pkl, FILE *image)
|
|
24
24
|
return(1);
|
25
25
|
}
|
26
26
|
|
27
|
-
if( setjmp(png_jmpbuf(png_ptr)) ){
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
}
|
27
|
+
//if( setjmp(png_jmpbuf(png_ptr)) ){
|
28
|
+
// png_destroy_info_struct(png_ptr, &info_ptr);
|
29
|
+
// png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
|
30
|
+
// return(1);
|
31
|
+
//}
|
32
32
|
|
33
33
|
png_init_io(png_ptr, image);
|
34
34
|
png_read_info(png_ptr, info_ptr);
|
@@ -75,11 +75,11 @@ int save_png(PKLImage pkl, FILE *image)
|
|
75
75
|
return(1);
|
76
76
|
}
|
77
77
|
|
78
|
-
if( setjmp(png_jmpbuf(png_ptr)) ){
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
}
|
78
|
+
//if( setjmp(png_jmpbuf(png_ptr)) ){
|
79
|
+
// png_destroy_info_struct(png_ptr, &info_ptr);
|
80
|
+
// png_destroy_write_struct(&png_ptr, &info_ptr);
|
81
|
+
// return(1);
|
82
|
+
//}
|
83
83
|
|
84
84
|
png_init_io(png_ptr, image);
|
85
85
|
info_ptr->width = pkl->width;
|
data/ext/pikl/pikl_png.h
CHANGED
@@ -0,0 +1,312 @@
|
|
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_RGB(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_RGB(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
|
+
//}
|
@@ -0,0 +1,19 @@
|
|
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/lib/pikl/ext.rb
CHANGED
@@ -13,6 +13,7 @@ module Pikl
|
|
13
13
|
typealias("PKL_FORMAT", "int")
|
14
14
|
typealias("PKL_ANGLE", "int")
|
15
15
|
typealias("PKL_SAMPLE", "int")
|
16
|
+
typealias("uchar", "unsigned char")
|
16
17
|
|
17
18
|
extern "PKLImage *pkl_open(char*)"
|
18
19
|
extern "void pkl_close(PKLImage*)"
|
@@ -22,7 +23,8 @@ module Pikl
|
|
22
23
|
extern "int pkl_width(PKLImage *)"
|
23
24
|
extern "int pkl_height(PKLImage *)"
|
24
25
|
extern "int pkl_trim(PKLImage *, int, int, int, int)"
|
25
|
-
extern "int pkl_rotate(PKLImage
|
26
|
+
extern "int pkl_rotate(PKLImage*, PKL_ANGLE)"
|
27
|
+
extern "int pkl_rotate2(PKLImage*, float, PKL_SAMPLE, uchar, uchar, uchar, uchar)"
|
26
28
|
extern "int pkl_resize(PKLImage*, int, int, PKL_SAMPLE)"
|
27
29
|
extern "int pkl_unsharp(PKLImage *, int, double)"
|
28
30
|
extern "int pkl_contrast(PKLImage *, int)"
|
data/lib/pikl/image.rb
CHANGED
@@ -70,11 +70,31 @@ module Pikl
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
def rotate(angle)
|
74
|
-
|
75
|
-
|
73
|
+
def rotate(angle, backcolor = "#FFFFFF", sample = :bilinear)
|
74
|
+
|
75
|
+
if ROTATE_ANGLE.has_key?(angle.to_i)
|
76
|
+
validate_rotate(angle)
|
77
|
+
Ext.pkl_rotate(@pkl_image, ROTATE_ANGLE[angle.to_i])
|
78
|
+
else
|
79
|
+
ci = color_int(backcolor)
|
80
|
+
Ext.pkl_rotate2(@pkl_image, angle.to_f, SAMPLES[sample.to_sym], ci[0], ci[1], ci[2], ci[3])
|
81
|
+
end
|
76
82
|
self
|
77
83
|
end
|
84
|
+
|
85
|
+
def color_int(colorstr)
|
86
|
+
validate_color(colorstr)
|
87
|
+
cs = colorstr.gsub(/^#/,"")
|
88
|
+
color = []
|
89
|
+
0.step(6,2) do |i|
|
90
|
+
color << ( cs[i,2].to_s.empty? ? "FF" : cs[i,2] )
|
91
|
+
end
|
92
|
+
color.map!{|c| c.hex}
|
93
|
+
end
|
94
|
+
|
95
|
+
def validate_color(v)
|
96
|
+
error("invalid color parameter. # => #{v}") unless /^#[a-f|A-F|0-9]+$/ =~ v.to_s
|
97
|
+
end
|
78
98
|
|
79
99
|
def resize(width, height, sample = :pixcel_averate)
|
80
100
|
validate_auto(width,height)
|
data/lib/pikl/version.rb
CHANGED
data/test/test_pikl_image.rb
CHANGED
@@ -119,7 +119,13 @@ class TestPiklImage < Test::Unit::TestCase
|
|
119
119
|
assert_equal(SAMPLE_IMAGE_H,imgout.width)
|
120
120
|
assert_equal(SAMPLE_IMAGE_W,imgout.height)
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
|
+
img.rotate(285,"#000000")
|
124
|
+
img.save(SAMPLE_OUTPUT)
|
125
|
+
Pikl::Image.open(SAMPLE_OUTPUT) do |imgout|
|
126
|
+
assert_equal(157,imgout.width)
|
127
|
+
assert_equal(185,imgout.height)
|
128
|
+
end
|
123
129
|
end
|
124
130
|
end
|
125
131
|
|
metadata
CHANGED
@@ -1,30 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.2
|
3
|
+
specification_version: 1
|
2
4
|
name: pikl
|
3
5
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
6
|
+
version: 0.2.4
|
7
|
+
date: 2008-06-13 00:00:00 +09:00
|
8
|
+
summary: Pikl is an image librarry for JPEG, PNG and Bitmap.Pikl's API is designed to process the image easily with method chain.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
- ext
|
12
|
+
email:
|
13
|
+
- ""
|
14
|
+
homepage: http://pikl.rubyforge.org
|
15
|
+
rubyforge_project: pikl
|
16
|
+
description: Pikl is an image librarry for JPEG, PNG and Bitmap.Pikl's API is designed to process the image easily with method chain.
|
17
|
+
autorequire:
|
18
|
+
default_executable:
|
19
|
+
bindir: bin
|
20
|
+
has_rdoc: true
|
21
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 0.0.0
|
26
|
+
version:
|
5
27
|
platform: ruby
|
28
|
+
signing_key:
|
29
|
+
cert_chain:
|
30
|
+
post_install_message:
|
6
31
|
authors:
|
7
32
|
- Ryota Maruko
|
8
|
-
autorequire:
|
9
|
-
bindir: bin
|
10
|
-
cert_chain: []
|
11
|
-
|
12
|
-
date: 2008-05-24 00:00:00 +09:00
|
13
|
-
default_executable:
|
14
|
-
dependencies: []
|
15
|
-
|
16
|
-
description: Pikl is an image librarry for JPEG, PNG and Bitmap.Pikl's API is designed to process the image easily with method chain.
|
17
|
-
email:
|
18
|
-
- ""
|
19
|
-
executables: []
|
20
|
-
|
21
|
-
extensions:
|
22
|
-
- ext/pikl/extconf.rb
|
23
|
-
extra_rdoc_files:
|
24
|
-
- History.txt
|
25
|
-
- License.txt
|
26
|
-
- Manifest.txt
|
27
|
-
- README.txt
|
28
33
|
files:
|
29
34
|
- History.txt
|
30
35
|
- License.txt
|
@@ -50,6 +55,8 @@ files:
|
|
50
55
|
- ext/pikl/pikl_resize.h
|
51
56
|
- ext/pikl/pikl_rotate.c
|
52
57
|
- ext/pikl/pikl_rotate.h
|
58
|
+
- ext/pikl/pikl_rotate2.c
|
59
|
+
- ext/pikl/pikl_rotate2.h
|
53
60
|
- ext/pikl/pikl_trim.c
|
54
61
|
- ext/pikl/pikl_trim.h
|
55
62
|
- lib/pikl.rb
|
@@ -62,34 +69,22 @@ files:
|
|
62
69
|
- test/sample.jpg
|
63
70
|
- test/test_helper.rb
|
64
71
|
- test/test_pikl_image.rb
|
65
|
-
|
66
|
-
|
67
|
-
|
72
|
+
test_files:
|
73
|
+
- test/test_helper.rb
|
74
|
+
- test/test_pikl_image.rb
|
68
75
|
rdoc_options:
|
69
76
|
- --main
|
70
77
|
- README.txt
|
71
|
-
|
72
|
-
-
|
73
|
-
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
-
requirements:
|
82
|
-
- - ">="
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
version: "0"
|
85
|
-
version:
|
78
|
+
extra_rdoc_files:
|
79
|
+
- History.txt
|
80
|
+
- License.txt
|
81
|
+
- Manifest.txt
|
82
|
+
- README.txt
|
83
|
+
executables: []
|
84
|
+
|
85
|
+
extensions:
|
86
|
+
- ext/pikl/extconf.rb
|
86
87
|
requirements: []
|
87
88
|
|
88
|
-
|
89
|
-
|
90
|
-
signing_key:
|
91
|
-
specification_version: 2
|
92
|
-
summary: Pikl is an image librarry for JPEG, PNG and Bitmap.Pikl's API is designed to process the image easily with method chain.
|
93
|
-
test_files:
|
94
|
-
- test/test_helper.rb
|
95
|
-
- test/test_pikl_image.rb
|
89
|
+
dependencies: []
|
90
|
+
|