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_pattern.h
CHANGED
File without changes
|
@@ -0,0 +1,173 @@
|
|
1
|
+
#include "pikl_pixel.h"
|
2
|
+
|
3
|
+
static int check_offset(PKLImage pkl, int x, int y, PKL_COLOR_MODEL target);
|
4
|
+
|
5
|
+
//=============================================================================
|
6
|
+
// pkl_color_create
|
7
|
+
//=============================================================================
|
8
|
+
PKLExport PKLColor pkl_color_create(unsigned char a, unsigned char b, unsigned char c, unsigned char d)
|
9
|
+
{
|
10
|
+
PKLColor pcolor;
|
11
|
+
|
12
|
+
pcolor = malloc(sizeof(struct _PKLColor));
|
13
|
+
if(!pcolor) return(NULL);
|
14
|
+
memset(pcolor, 0, sizeof(struct _PKLColor));
|
15
|
+
|
16
|
+
pcolor->color[0] = a;
|
17
|
+
pcolor->color[1] = b;
|
18
|
+
pcolor->color[2] = c;
|
19
|
+
pcolor->color[3] = d;
|
20
|
+
return(pcolor);
|
21
|
+
}
|
22
|
+
|
23
|
+
//=============================================================================
|
24
|
+
// pkl_color_gray
|
25
|
+
//=============================================================================
|
26
|
+
PKLExport PKLColor pkl_color_gray(unsigned char gray)
|
27
|
+
{
|
28
|
+
return pkl_color_create(gray, 0, 0, 0);
|
29
|
+
}
|
30
|
+
|
31
|
+
//=============================================================================
|
32
|
+
// pkl_color_rgb
|
33
|
+
//=============================================================================
|
34
|
+
PKLExport PKLColor pkl_color_rgb(unsigned char red, unsigned char green, unsigned char blue)
|
35
|
+
{
|
36
|
+
return pkl_color_create(red, green, blue, 0);
|
37
|
+
}
|
38
|
+
|
39
|
+
//=============================================================================
|
40
|
+
// pkl_color_cmyk
|
41
|
+
//=============================================================================
|
42
|
+
PKLExport PKLColor pkl_color_cmyk(unsigned char c, unsigned char m, unsigned char y, unsigned char k)
|
43
|
+
{
|
44
|
+
return pkl_color_create(c, m, y, k);
|
45
|
+
}
|
46
|
+
|
47
|
+
//=============================================================================
|
48
|
+
// pkl_color_close
|
49
|
+
//=============================================================================
|
50
|
+
PKLExport void pkl_color_close(PKLColor color)
|
51
|
+
{
|
52
|
+
if(color) free(color);
|
53
|
+
}
|
54
|
+
|
55
|
+
//=============================================================================
|
56
|
+
// pkl_color_get
|
57
|
+
//=============================================================================
|
58
|
+
PKLExport unsigned char pkl_get_color(PKLImage pkl, int x, int y, PKL_COLOR_MODEL target)
|
59
|
+
{
|
60
|
+
int offset=0;
|
61
|
+
|
62
|
+
if((offset=check_offset(pkl, x, y, target)) == -1) return(0);
|
63
|
+
return pkl->image[(y*pkl->width+x)*pkl->channel+offset];
|
64
|
+
}
|
65
|
+
|
66
|
+
//=============================================================================
|
67
|
+
// pkl_color_set
|
68
|
+
//=============================================================================
|
69
|
+
PKLExport int pkl_set_color(PKLImage pkl, int x, int y, PKL_COLOR_MODEL target, unsigned char color)
|
70
|
+
{
|
71
|
+
int offset=0;
|
72
|
+
|
73
|
+
if((offset=check_offset(pkl, x, y, target)) == -1) return(1);
|
74
|
+
pkl->image[(y*pkl->width+x)*pkl->channel+offset]=color;
|
75
|
+
return(0);
|
76
|
+
}
|
77
|
+
|
78
|
+
//=============================================================================
|
79
|
+
// check_offset
|
80
|
+
//=============================================================================
|
81
|
+
static int check_offset(PKLImage pkl, int x, int y, PKL_COLOR_MODEL target)
|
82
|
+
{
|
83
|
+
if(x<0 || x>=pkl->width || y<0 || y>=pkl->height) return(-1);
|
84
|
+
|
85
|
+
switch(pkl->color){
|
86
|
+
case PKL_GRAYSCALE:
|
87
|
+
if(target != PKL_GRAY) return(-1);
|
88
|
+
return(0);
|
89
|
+
case PKL_RGB:
|
90
|
+
switch(target){
|
91
|
+
case PKL_RED: return(0);
|
92
|
+
case PKL_GREEN: return(1);
|
93
|
+
case PKL_BLUE: return(2);
|
94
|
+
default:
|
95
|
+
return(-1);
|
96
|
+
}
|
97
|
+
break;
|
98
|
+
case PKL_CMYK:
|
99
|
+
switch(target){
|
100
|
+
case PKL_CYAN: return(0);
|
101
|
+
case PKL_MAGENTA: return(1);
|
102
|
+
case PKL_YELLOW: return(2);
|
103
|
+
case PKL_BLACK: return(3);
|
104
|
+
default:
|
105
|
+
return(-1);
|
106
|
+
}
|
107
|
+
break;
|
108
|
+
case PKL_UNKNOWN:
|
109
|
+
case PKL_BLACKWHITE:
|
110
|
+
case PKL_RGBA:
|
111
|
+
case PKL_YCbCr:
|
112
|
+
case PKL_YCCK:
|
113
|
+
default:
|
114
|
+
return(-1);
|
115
|
+
}
|
116
|
+
return(-1);
|
117
|
+
}
|
118
|
+
|
119
|
+
//=============================================================================
|
120
|
+
// pkl_pixel_get
|
121
|
+
//=============================================================================
|
122
|
+
PKLExport PKLColor pkl_get_pixel(PKLImage pkl, int x, int y)
|
123
|
+
{
|
124
|
+
PKLColor pcolor;
|
125
|
+
|
126
|
+
if(x<0 || x>=pkl->width || y<0 || y>=pkl->height) return(NULL);
|
127
|
+
|
128
|
+
pcolor = malloc(sizeof(struct _PKLColor));
|
129
|
+
if(!pcolor) return(NULL);
|
130
|
+
memset(pcolor, 0, sizeof(struct _PKLColor));
|
131
|
+
memcpy(pcolor->color, &pkl->image[(y*pkl->width+x)*pkl->channel], pkl->channel);
|
132
|
+
return(pcolor);
|
133
|
+
}
|
134
|
+
|
135
|
+
//=============================================================================
|
136
|
+
// pkl_pixel_set
|
137
|
+
//=============================================================================
|
138
|
+
PKLExport int pkl_set_pixel(PKLImage pkl, int x, int y, PKLColor color)
|
139
|
+
{
|
140
|
+
if(x<0 || x>=pkl->width || y<0 || y>=pkl->height) return(1);
|
141
|
+
memcpy(&pkl->image[(y*pkl->width+x)*pkl->channel], color->color, pkl->channel);
|
142
|
+
return(0);
|
143
|
+
}
|
144
|
+
|
145
|
+
//=============================================================================
|
146
|
+
// pkl_color
|
147
|
+
//=============================================================================
|
148
|
+
PKLExport unsigned char pkl_color(PKLColor color, PKL_COLOR_MODEL target)
|
149
|
+
{
|
150
|
+
int offset;
|
151
|
+
|
152
|
+
switch(target){
|
153
|
+
case PKL_GRAY:
|
154
|
+
case PKL_RED:
|
155
|
+
case PKL_CYAN:
|
156
|
+
offset=0;
|
157
|
+
break;
|
158
|
+
case PKL_GREEN:
|
159
|
+
case PKL_MAGENTA:
|
160
|
+
offset=1;
|
161
|
+
break;
|
162
|
+
case PKL_BLUE:
|
163
|
+
case PKL_YELLOW:
|
164
|
+
offset=2;
|
165
|
+
break;
|
166
|
+
case PKL_BLACK:
|
167
|
+
offset=3;
|
168
|
+
break;
|
169
|
+
default:
|
170
|
+
return(0);
|
171
|
+
}
|
172
|
+
return color->color[offset];
|
173
|
+
}
|
data/ext/pikl/pikl_png.c
CHANGED
File without changes
|
data/ext/pikl/pikl_png.h
CHANGED
File without changes
|
data/ext/pikl/pikl_private.h
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
#ifndef _LIB_PIKL_PRIVATE_
|
2
2
|
#define _LIB_PIKL_PRIVATE_
|
3
3
|
|
4
|
+
#ifdef DEBUG
|
5
|
+
#include "dbg/dbg.h"
|
6
|
+
#endif
|
7
|
+
|
4
8
|
#define PKL_MINMAX(a,b,i) (((a>=i)?a:((b<=i)?b:i)))
|
9
|
+
#define PKL_MIN(a,b) ((a<b)?a:b)
|
10
|
+
#define PKL_MAX(a,b) ((a>b)?a:b)
|
5
11
|
#define PKL_COLOR_CLIP(v) v<0?0:v>255?255:v
|
6
12
|
#define PKL_CHANNEL 4
|
7
13
|
#define PKL_COLOR 256
|
@@ -19,11 +25,12 @@ struct _PKLImage {
|
|
19
25
|
unsigned char *image;
|
20
26
|
PKL_FORMAT format;
|
21
27
|
int compress;
|
22
|
-
|
23
|
-
//affine
|
24
|
-
double x_scale, y_scale;
|
25
|
-
double angle;
|
26
|
-
double x_trns, y_trns;
|
27
28
|
};
|
28
29
|
|
30
|
+
//=============================================================================
|
31
|
+
// PKLColor
|
32
|
+
//=============================================================================
|
33
|
+
struct _PKLColor {
|
34
|
+
unsigned char color[PKL_CHANNEL];
|
35
|
+
};
|
29
36
|
#endif
|
data/ext/pikl/pikl_resize.c
CHANGED
File without changes
|
data/ext/pikl/pikl_resize.h
CHANGED
File without changes
|
data/ext/pikl/pikl_rotate.c
CHANGED
@@ -1,70 +1,428 @@
|
|
1
1
|
#include "pikl_rotate.h"
|
2
2
|
|
3
|
+
static int rotate_90(PKLImage pkl, float angle);
|
4
|
+
static int rotate_custom(PKLImage pkl, float angle, PKL_SAMPLE sample, PKLColor backcolor);
|
5
|
+
static void bsort(int *p);
|
6
|
+
|
7
|
+
static int pkl_rotate_nr(PKLImage pkl, PIKL_ROTATE *ri);
|
8
|
+
static int pkl_rotate_nn(PKLImage pkl, PIKL_ROTATE *ri);
|
9
|
+
static int pkl_rotate_bl(PKLImage pkl, PIKL_ROTATE *ri);
|
10
|
+
static int pkl_rotate_bc(PKLImage pkl, PIKL_ROTATE *ri);
|
11
|
+
//static int pkl_rotate_pa(PKLImage pkl, float angle, int backcolor);
|
12
|
+
|
3
13
|
//=================================================================================
|
4
14
|
// pkl_rotate
|
5
15
|
//=================================================================================
|
6
|
-
PKLExport int pkl_rotate(PKLImage pkl,
|
16
|
+
PKLExport int pkl_rotate(PKLImage pkl, float angle, PKL_SAMPLE sample, PKLColor backcolor)
|
7
17
|
{
|
8
|
-
|
9
|
-
int
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
18
|
+
/* 90�x�̔{�p���ǂ����ŏ�������(�덷����̂���) */
|
19
|
+
if((int)angle%90){
|
20
|
+
return rotate_custom(pkl, angle, sample, backcolor);
|
21
|
+
}else{
|
22
|
+
return rotate_90(pkl, angle);
|
23
|
+
}
|
24
|
+
return(1);
|
25
|
+
}
|
26
|
+
|
27
|
+
//=============================================================================
|
28
|
+
// rotate_90
|
29
|
+
//=============================================================================
|
30
|
+
static int rotate_90(PKLImage pkl, float angle)
|
31
|
+
{
|
32
|
+
PIKL_ROTATE ri;
|
33
|
+
float c, s, rad;
|
34
|
+
|
35
|
+
rad = -angle*M_PI/180.0;
|
36
|
+
c = cos(rad);
|
37
|
+
s = sin(rad);
|
38
|
+
ri.rcos = (int)c==0 ? 0.0 : (int)c==1 ? 1.0 : -1.0;
|
39
|
+
ri.rsin = (int)s==0 ? 0.0 : (int)s==1 ? 1.0 : -1.0;
|
40
|
+
|
41
|
+
/*90*/
|
42
|
+
if(ri.rcos==0 && ri.rsin==1){
|
43
|
+
ri.width = pkl->height;
|
44
|
+
ri.height = pkl->width;
|
45
|
+
ri.sx = 0;
|
46
|
+
ri.sy = -(pkl->width-1);
|
47
|
+
ri.ex = pkl->height-1;
|
48
|
+
ri.ey = 0;
|
49
|
+
}else
|
50
|
+
/*180*/
|
51
|
+
if(ri.rcos==-1 && ri.rsin==0){
|
52
|
+
ri.width = pkl->width;
|
53
|
+
ri.height = pkl->height;
|
54
|
+
ri.sx = -(pkl->width-1);
|
55
|
+
ri.sy = -(pkl->height-1);
|
56
|
+
ri.ex = 0;
|
57
|
+
ri.ey = 0;
|
58
|
+
}else
|
59
|
+
/*270*/
|
60
|
+
if(ri.rcos==0 && ri.rsin==-1){
|
61
|
+
ri.width = pkl->height;
|
62
|
+
ri.height = pkl->width;
|
63
|
+
ri.sx = -(pkl->height-1);
|
64
|
+
ri.sy = 0;
|
65
|
+
ri.ex = 0;
|
66
|
+
ri.ey = pkl->width-1;
|
67
|
+
}
|
68
|
+
|
69
|
+
return pkl_rotate_nr(pkl, &ri);
|
70
|
+
}
|
71
|
+
|
72
|
+
//=============================================================================
|
73
|
+
// rotate_custom
|
74
|
+
//=============================================================================
|
75
|
+
static int rotate_custom(PKLImage pkl, float angle, PKL_SAMPLE sample, PKLColor backcolor)
|
76
|
+
{
|
77
|
+
PIKL_ROTATE ri;
|
78
|
+
float rad;
|
79
|
+
int px[4], py[4], i, x, y;
|
80
|
+
|
81
|
+
rad = -angle*M_PI/180.0;
|
82
|
+
ri.rcos = cos(rad);
|
83
|
+
ri.rsin = sin(rad);
|
84
|
+
|
85
|
+
px[0] = 0;
|
86
|
+
py[0] = 0;
|
87
|
+
px[1] = pkl->width;
|
88
|
+
py[1] = 0;
|
89
|
+
px[2] = 0;
|
90
|
+
py[2] = pkl->height;
|
91
|
+
px[3] = pkl->width;
|
92
|
+
py[3] = pkl->height;
|
93
|
+
|
94
|
+
for(i=0; i<4; i++){
|
95
|
+
x = (int)(cos(-rad)*px[i] - sin(-rad)*py[i]);
|
96
|
+
y = (int)(sin(-rad)*px[i] + cos(-rad)*py[i]);
|
97
|
+
px[i] = x;
|
98
|
+
py[i] = y;
|
99
|
+
}
|
100
|
+
|
101
|
+
//�����ɕ��т���(qsort���g���ƒx���̂Ńo�u���\�[�g�A���S���Y����)
|
102
|
+
bsort(px);
|
103
|
+
bsort(py);
|
104
|
+
ri.sx = px[0];
|
105
|
+
ri.sy = py[0];
|
106
|
+
ri.ex = px[3];
|
107
|
+
ri.ey = py[3];
|
108
|
+
ri.width = ri.ex - ri.sx;
|
109
|
+
ri.height = ri.ey - ri.sy;
|
110
|
+
|
111
|
+
//for(i=0; i<pkl->channel; i++)
|
112
|
+
// ri.back[i] = (backcolor>>((pkl->channel-i)*8) & 0xFF);
|
113
|
+
if(backcolor)
|
114
|
+
memcpy(ri.back, backcolor->color, PKL_CHANNEL);
|
115
|
+
else
|
116
|
+
memset(ri.back, 0xff, PKL_CHANNEL);
|
117
|
+
|
118
|
+
switch(sample){
|
119
|
+
case PKL_SAMPLE_BL:
|
120
|
+
return pkl_rotate_bl(pkl, &ri);
|
121
|
+
case PKL_SAMPLE_BC:
|
122
|
+
case PKL_SAMPLE_PA:
|
123
|
+
case PKL_SAMPLE_LZ:
|
124
|
+
return pkl_rotate_bc(pkl, &ri);
|
125
|
+
case PKL_SAMPLE_NN:
|
47
126
|
default:
|
48
|
-
return(
|
127
|
+
return pkl_rotate_nn(pkl, &ri);
|
49
128
|
}
|
129
|
+
return(1);
|
130
|
+
}
|
131
|
+
|
132
|
+
//=============================================================================
|
133
|
+
// bsort
|
134
|
+
//=============================================================================
|
135
|
+
static void bsort(int *p)
|
136
|
+
{
|
137
|
+
int i, j, k, t;
|
50
138
|
|
51
|
-
|
52
|
-
|
139
|
+
k=3;
|
140
|
+
while(k>=0){
|
141
|
+
j=-1;
|
142
|
+
for(i=1; i<=k; i++){
|
143
|
+
if(p[i-1] > p[i]){
|
144
|
+
j = i-1;
|
145
|
+
t=p[j]; p[i-1]=p[i]; p[i]=t;
|
146
|
+
}
|
147
|
+
}
|
148
|
+
k=j;
|
149
|
+
}
|
150
|
+
}
|
53
151
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
152
|
+
//=============================================================================
|
153
|
+
// pkl_rotate_nr
|
154
|
+
//=============================================================================
|
155
|
+
static int pkl_rotate_nr(PKLImage pkl, PIKL_ROTATE *ri)
|
156
|
+
{
|
157
|
+
unsigned char *wrk;
|
158
|
+
int i, j, px, py;
|
159
|
+
|
160
|
+
wrk = malloc(ri->width * ri->height * pkl->channel);
|
161
|
+
if(!wrk) return(1);
|
162
|
+
|
163
|
+
for(i=ri->sy; i<=ri->ey; i++){
|
164
|
+
for(j=ri->sx; j<=ri->ex; j++){
|
165
|
+
px = (int)ri->rcos * j - (int)ri->rsin * i;
|
166
|
+
py = (int)ri->rsin * j + (int)ri->rcos * i;
|
167
|
+
memcpy(&wrk[((i-ri->sy)*ri->width+j-ri->sx)*pkl->channel], &pkl->image[(py*pkl->width+px)*pkl->channel], pkl->channel);
|
59
168
|
}
|
60
169
|
}
|
61
170
|
|
62
171
|
free(pkl->image);
|
63
|
-
pkl->image
|
64
|
-
pkl->width
|
65
|
-
pkl->height = height;
|
172
|
+
pkl->image = wrk;
|
173
|
+
pkl->width = ri->width;
|
174
|
+
pkl->height = ri->height;
|
175
|
+
return(0);
|
176
|
+
}
|
177
|
+
|
178
|
+
//=============================================================================
|
179
|
+
// pkl_rotate_nn
|
180
|
+
//=============================================================================
|
181
|
+
static int pkl_rotate_nn(PKLImage pkl, PIKL_ROTATE *ri)
|
182
|
+
{
|
183
|
+
unsigned char *wrk;
|
184
|
+
int i, j, px, py;
|
185
|
+
float x, y;
|
66
186
|
|
187
|
+
wrk = malloc(ri->width * ri->height * pkl->channel);
|
188
|
+
if(!wrk) return(1);
|
189
|
+
|
190
|
+
for(i=ri->sy; i<ri->ey; i++){
|
191
|
+
for(j=ri->sx; j<ri->ex; j++){
|
192
|
+
x = ri->rcos * j - ri->rsin * i;
|
193
|
+
y = ri->rsin * j + ri->rcos * i;
|
194
|
+
px = x < 0.0f ? (int)(x-0.5f) : (int)(x+0.5f);
|
195
|
+
py = y < 0.0f ? (int)(y-0.5f) : (int)(y+0.5f);
|
196
|
+
//px = ri->rcos * j - ri->rsin * i;
|
197
|
+
//py = ri->rsin * j + ri->rcos * i;
|
198
|
+
if(px>=0 && px<pkl->width && py>=0 && py<pkl->height){
|
199
|
+
memcpy(&wrk[((i-ri->sy)*ri->width+j-ri->sx)*pkl->channel],
|
200
|
+
&pkl->image[(py*pkl->width+px)*pkl->channel], pkl->channel);
|
201
|
+
}else{
|
202
|
+
memcpy(&wrk[((i-ri->sy)*ri->width+j-ri->sx)*pkl->channel], ri->back, pkl->channel);
|
203
|
+
}
|
204
|
+
}
|
205
|
+
}
|
206
|
+
|
207
|
+
free(pkl->image);
|
208
|
+
pkl->image = wrk;
|
209
|
+
pkl->width = ri->width;
|
210
|
+
pkl->height = ri->height;
|
67
211
|
return(0);
|
68
212
|
}
|
69
213
|
|
214
|
+
//=============================================================================
|
215
|
+
// pkl_rotate_bl
|
216
|
+
// +----+----+
|
217
|
+
// | d0 | d1 |
|
218
|
+
// +----+----+
|
219
|
+
// | d2 | d3 |
|
220
|
+
// +----+----+
|
221
|
+
//=============================================================================
|
222
|
+
static int pkl_rotate_bl(PKLImage pkl, PIKL_ROTATE *ri)
|
223
|
+
{
|
224
|
+
unsigned char *wrk, *d0, *d1, *d2, *d3;
|
225
|
+
int p0x, p0y, i, j, k;
|
226
|
+
double dx, dy, fracx, fracy;
|
227
|
+
double pixel[PKL_CHANNEL];
|
228
|
+
|
229
|
+
wrk = malloc(ri->width * ri->height * pkl->channel);
|
230
|
+
if(!wrk) return(1);
|
231
|
+
|
232
|
+
for(i=ri->sy; i<ri->ey; i++){
|
233
|
+
for(j=ri->sx; j<ri->ex; j++){
|
234
|
+
dx = ri->rcos*j-ri->rsin*i;
|
235
|
+
dy = ri->rsin*j+ri->rcos*i;
|
236
|
+
p0x = (int)floor(dx);
|
237
|
+
p0y = (int)floor(dy);
|
238
|
+
fracx = dx - p0x;
|
239
|
+
fracy = dy - p0y;
|
240
|
+
//if(p0x<0 || p0x>=pkl->width || p0y<0 || p0y>=pkl->height){
|
241
|
+
if(p0x<-1 || p0x>=pkl->width || p0y<-1 || p0y>=pkl->height){
|
242
|
+
memcpy(&wrk[((i-ri->sy)*ri->width+j-ri->sx)*pkl->channel], ri->back, pkl->channel);
|
243
|
+
continue;
|
244
|
+
}
|
245
|
+
|
246
|
+
//if((p0x==-1 && p0y==-1) || (p0x+1>=pkl->width && p0y+1>=pkl->height)){
|
247
|
+
if((p0x==-1 && p0y==-1) || (p0x+1>=pkl->width && p0y+1>=pkl->height) ||
|
248
|
+
(p0x==-1 && p0y+1>=pkl->height) || (p0x+1>=pkl->width && p0y==-1)){
|
249
|
+
//�e���_
|
250
|
+
d0 = &pkl->image[(p0y*pkl->width+p0x)*pkl->channel];
|
251
|
+
d1 = &pkl->image[(p0y*pkl->width+p0x)*pkl->channel];
|
252
|
+
d2 = &pkl->image[(p0y*pkl->width+p0x)*pkl->channel];
|
253
|
+
d3 = &pkl->image[(p0y*pkl->width+p0x)*pkl->channel];
|
254
|
+
}else{
|
255
|
+
if(p0x==-1 && p0y>-1){
|
256
|
+
//���G�b�W
|
257
|
+
d0 = ri->back;
|
258
|
+
d1 = &pkl->image[(p0y*pkl->width+p0x+1)*pkl->channel];
|
259
|
+
d2 = ri->back;
|
260
|
+
d3 = &pkl->image[((p0y+1)*pkl->width+p0x+1)*pkl->channel];
|
261
|
+
}else if(p0x>-1 && p0y==-1){
|
262
|
+
//��G�b�W
|
263
|
+
d0 = ri->back;
|
264
|
+
d1 = ri->back;
|
265
|
+
d2 = &pkl->image[((p0y+1)*pkl->width+p0x)*pkl->channel];
|
266
|
+
d3 = &pkl->image[((p0y+1)*pkl->width+p0x+1)*pkl->channel];
|
267
|
+
}else if(p0x+1<pkl->width && p0y+1>=pkl->height){
|
268
|
+
//���G�b�W
|
269
|
+
d0 = &pkl->image[(p0y*pkl->width+p0x)*pkl->channel];
|
270
|
+
d1 = &pkl->image[(p0y*pkl->width+p0x+1)*pkl->channel];
|
271
|
+
d2 = ri->back;
|
272
|
+
d3 = ri->back;
|
273
|
+
}else if(p0x+1>=pkl->width && p0y+1<pkl->height){
|
274
|
+
//�E�G�b�W
|
275
|
+
d0 = &pkl->image[(p0y*pkl->width+p0x)*pkl->channel];
|
276
|
+
d1 = ri->back;
|
277
|
+
d2 = &pkl->image[((p0y+1)*pkl->width+p0x)*pkl->channel];
|
278
|
+
d3 = ri->back;
|
279
|
+
}else{
|
280
|
+
//�G�b�W�ȊO
|
281
|
+
d0 = &pkl->image[(p0y*pkl->width+p0x)*pkl->channel];
|
282
|
+
d1 = &pkl->image[(p0y*pkl->width+p0x+1)*pkl->channel];
|
283
|
+
d2 = &pkl->image[((p0y+1)*pkl->width+p0x)*pkl->channel];
|
284
|
+
d3 = &pkl->image[((p0y+1)*pkl->width+p0x+1)*pkl->channel];
|
285
|
+
}
|
286
|
+
}
|
287
|
+
|
288
|
+
memset(pixel, 0, sizeof(double)*PKL_CHANNEL);
|
289
|
+
for(k=0; k<pkl->channel; k++){
|
290
|
+
pixel[k] += d0[k] * (1-fracx)*(1-fracy);
|
291
|
+
pixel[k] += d1[k] * fracx*(1-fracy);
|
292
|
+
pixel[k] += d2[k] * (1-fracx)*fracy;
|
293
|
+
pixel[k] += d3[k] * fracx*fracy;
|
294
|
+
}
|
295
|
+
for(k=0; k<pkl->channel; k++)
|
296
|
+
wrk[((i-ri->sy)*ri->width+j-ri->sx)*pkl->channel+k] = PKL_COLOR_CLIP(pixel[k]);
|
297
|
+
}
|
298
|
+
}
|
299
|
+
|
300
|
+
free(pkl->image);
|
301
|
+
pkl->image = wrk;
|
302
|
+
pkl->width = ri->width;
|
303
|
+
pkl->height = ri->height;
|
304
|
+
return(0);
|
305
|
+
}
|
306
|
+
|
307
|
+
//=============================================================================
|
308
|
+
// pkl_rotate_bc
|
309
|
+
//=============================================================================
|
310
|
+
static int pkl_rotate_bc(PKLImage pkl, PIKL_ROTATE *ri)
|
311
|
+
{
|
312
|
+
unsigned char *wrk;
|
313
|
+
int i, j, k, px, py;
|
314
|
+
float wx, wy, dx, dy, sx, sy;
|
315
|
+
float data[PKL_CHANNEL];
|
316
|
+
|
317
|
+
wrk = malloc(ri->width * ri->height * pkl->channel);
|
318
|
+
if(!wrk) return(1);
|
319
|
+
|
320
|
+
for(i=ri->sy; i<ri->ey; i++){
|
321
|
+
for(j=ri->sx; j<ri->ex; j++){
|
322
|
+
sx = ri->rcos * j - ri->rsin * i;
|
323
|
+
sy = ri->rsin * j + ri->rcos * i;
|
324
|
+
|
325
|
+
if(sx<0 || sx>=pkl->width || sy<0 || sy>=pkl->height){
|
326
|
+
memcpy(&wrk[((i-ri->sy)*ri->width+j-ri->sx)*pkl->channel], ri->back, pkl->channel);
|
327
|
+
continue;
|
328
|
+
}
|
329
|
+
|
330
|
+
memset(&data, 0, sizeof(data));
|
331
|
+
for(py=(int)sy-1; py<=(int)sy+2; py++){
|
332
|
+
for(px=(int)sx-1; px<=(int)sx+2; px++){
|
333
|
+
dx = fabs(sx-px);
|
334
|
+
dy = fabs(sy-py);
|
335
|
+
wx = (dx<1) ? (dx-1)*(dx*dx-dx-1) : -(dx-1)*(dx-2)*(dx-2);
|
336
|
+
wy = (dy<1) ? (dy-1)*(dy*dy-dy-1) : -(dy-1)*(dy-2)*(dy-2);
|
337
|
+
|
338
|
+
if(px>=0 && px<pkl->width && py>=0 && py<pkl->height){
|
339
|
+
for(k=0; k<pkl->channel; k++)
|
340
|
+
data[k] += pkl->image[(py*pkl->width+px)*pkl->channel+k]*wx*wy;
|
341
|
+
}else{
|
342
|
+
for(k=0; k<pkl->channel; k++)
|
343
|
+
data[k] += ri->back[k]*wx*wy;
|
344
|
+
}
|
345
|
+
}
|
346
|
+
}
|
347
|
+
for(k=0; k<pkl->channel; k++)
|
348
|
+
wrk[((i-ri->sy)*ri->width+j-ri->sx)*pkl->channel+k] = PKL_COLOR_CLIP(data[k]);
|
349
|
+
}
|
350
|
+
}
|
351
|
+
|
352
|
+
free(pkl->image);
|
353
|
+
pkl->image = wrk;
|
354
|
+
pkl->width = ri->width;
|
355
|
+
pkl->height = ri->height;
|
356
|
+
return(0);
|
357
|
+
}
|
70
358
|
|
359
|
+
////=============================================================================
|
360
|
+
//// pkl_rotate_pa
|
361
|
+
////=============================================================================
|
362
|
+
//static int pkl_rotate_pa(PKLImage pkl, float angle, int backcolor)
|
363
|
+
//{
|
364
|
+
// int width, height;
|
365
|
+
// PIKL_RECT rect;
|
366
|
+
// float rad;
|
367
|
+
// unsigned char *wrk, back[PKL_CHANNEL];
|
368
|
+
// int i, j;
|
369
|
+
// double zx, zy, power;
|
370
|
+
//
|
371
|
+
// rad = -angle*M_PI/180;
|
372
|
+
// get_rect(&rect, pkl->width, pkl->height, rad);
|
373
|
+
// width = rect.right - rect.left;
|
374
|
+
// height = rect.bottom - rect.top;
|
375
|
+
//
|
376
|
+
// wrk = malloc(width * height * pkl->channel);
|
377
|
+
// if(!wrk) return(1);
|
378
|
+
// memset(wrk, 0, width*height*pkl->channel);
|
379
|
+
//
|
380
|
+
// for(i=0; i<pkl->channel; i++)
|
381
|
+
// back[i] = (backcolor>>((pkl->channel-i)*8) & 0xFF);
|
382
|
+
//
|
383
|
+
// zx = (double)pkl->width / (double)width;
|
384
|
+
// zy = (double)pkl->height / (double)height;
|
385
|
+
// //���_�����������ϒl�Z�o�l
|
386
|
+
// power= zx*zy + (zx*zy * angle*M_PI/180 * angle*M_PI/180);
|
387
|
+
//
|
388
|
+
// for(i=rect.top; i<rect.bottom; i++){
|
389
|
+
// for(j=rect.left; j<rect.right; j++){
|
390
|
+
// double w1, w2, h1, h2;
|
391
|
+
// double w1b, w2b, h1b, h2b;
|
392
|
+
// double bi, ixg[PKL_CHANNEL] = {0.0, 0.0, 0.0, 0.0};
|
393
|
+
// int fsx ,fsy, s, t, k;
|
394
|
+
//
|
395
|
+
// w1b = modf(cos(rad)*j -sin(rad)*i, &w1);
|
396
|
+
// w2b = modf(cos(rad)*(j+1)-sin(rad)*i, &w2);
|
397
|
+
// h1b = modf(sin(rad)*j +cos(rad)*i, &h1);
|
398
|
+
// h2b = modf(sin(rad)*j+cos(rad)*(i+1), &h2);
|
399
|
+
//
|
400
|
+
// for(s=(int)w1; s<=(int)w2; s++){
|
401
|
+
// for(t=(int)h1; t<=(int)h2; t++){
|
402
|
+
// bi = 1.0;
|
403
|
+
// if(s == (int)w1) bi*=(1-w1b);
|
404
|
+
// if(s == (int)w2) bi*=(w2b);
|
405
|
+
// if(t == (int)h1) bi*=(1-h1b);
|
406
|
+
// if(t == (int)h2) bi*=(h2b);
|
407
|
+
// fsx = (s < 0) ? 0 : (s > pkl->width -1) ? pkl->width -1 : s;
|
408
|
+
// fsy = (t < 0) ? 0 : (t > pkl->height-1) ? pkl->height-1 : t;
|
409
|
+
// for(k=0; k<pkl->channel; k++)
|
410
|
+
// ixg[k] += pkl->image[(fsy*pkl->width+fsx)*pkl->channel+k] * bi;
|
411
|
+
// }
|
412
|
+
// }
|
413
|
+
//
|
414
|
+
// if((int)w1>=0 && (int)w1<pkl->width && (int)h1>=0 && (int)h1<pkl->height){
|
415
|
+
// for(k=0; k<pkl->channel; k++)
|
416
|
+
// wrk[((i-rect.top)*width+j-rect.left)*pkl->channel+k] = PKL_RGB(ixg[k]/power);
|
417
|
+
// }else{
|
418
|
+
// memcpy(&wrk[((i-rect.top)*width+j-rect.left)*pkl->channel], back, pkl->channel);
|
419
|
+
// }
|
420
|
+
//
|
421
|
+
// }
|
422
|
+
// }
|
423
|
+
// free(pkl->image);
|
424
|
+
// pkl->image = wrk;
|
425
|
+
// pkl->width = width;
|
426
|
+
// pkl->height = height;
|
427
|
+
// return(0);
|
428
|
+
//}
|