pikl 0.2.7-x86-mswin32 → 0.2.8-x86-mswin32
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/Manifest.txt +23 -0
- data/ext/pikl/decrease/fsdither.h +554 -0
- data/ext/pikl/decrease/median.c +1179 -0
- data/ext/pikl/decrease/median.h +7 -0
- data/ext/pikl/decrease/neuquan5.c +563 -0
- data/ext/pikl/decrease/neuquant.h +62 -0
- data/ext/pikl/decrease/wu.c +447 -0
- data/ext/pikl/decrease/wu.h +7 -0
- data/ext/pikl/pikl_affine.c +250 -0
- data/ext/pikl/pikl_affine.h +20 -0
- data/ext/pikl/pikl_blur.c +244 -0
- data/ext/pikl/pikl_blur.h +12 -0
- data/ext/pikl/pikl_decrease.c +126 -0
- data/ext/pikl/pikl_decrease.h +19 -0
- data/ext/pikl/pikl_effect2.c +240 -0
- data/ext/pikl/pikl_effect2.h +55 -0
- data/ext/pikl/pikl_effect3.c +266 -0
- data/ext/pikl/pikl_effect3.h +12 -0
- data/ext/pikl/pikl_effect4.c +495 -0
- data/ext/pikl/pikl_effect4.h +12 -0
- data/ext/pikl/pikl_pattern.c +611 -0
- data/ext/pikl/pikl_pattern.h +12 -0
- data/ext/pikl/pikl_scrap.c +731 -0
- data/ext/pikl/pikl_scrap.h +12 -0
- data/lib/pikl/version.rb +1 -1
- metadata +26 -3
@@ -0,0 +1,126 @@
|
|
1
|
+
#include "pikl_decrease.h"
|
2
|
+
|
3
|
+
//=============================================================================
|
4
|
+
// median
|
5
|
+
//=============================================================================
|
6
|
+
PKLExport int pkl_mediancut(PKLImage pkl, int ncolors, int dither)
|
7
|
+
{
|
8
|
+
unsigned char QuantizedPalette[256*3], *Picture256;
|
9
|
+
int i, j;
|
10
|
+
|
11
|
+
if(pkl->color!=PKL_RGB) return(1);
|
12
|
+
if(ncolors<=0 || ncolors>256) return(1);
|
13
|
+
|
14
|
+
Picture256 = malloc(pkl->width*pkl->height);
|
15
|
+
if(!Picture256) return(1);
|
16
|
+
|
17
|
+
to_indexed(pkl->image, ncolors, dither, pkl->width, pkl->height, Picture256, QuantizedPalette);
|
18
|
+
|
19
|
+
for(i=0,j=0; i<pkl->height*pkl->width*3; i+=3,j++)
|
20
|
+
memcpy(&pkl->image[i], &QuantizedPalette[ Picture256[j]*3 ], pkl->channel);
|
21
|
+
|
22
|
+
free(Picture256);
|
23
|
+
return(0);
|
24
|
+
}
|
25
|
+
|
26
|
+
//=============================================================================
|
27
|
+
// pkl_neuquant
|
28
|
+
//=============================================================================
|
29
|
+
PKLExport int pkl_neuquant(PKLImage pkl, int ncolors, int sample)
|
30
|
+
{
|
31
|
+
unsigned char QuantizedPalette[256*3], *Picture256;
|
32
|
+
int i, j;
|
33
|
+
|
34
|
+
if(pkl->color!=PKL_RGB) return(1);
|
35
|
+
if(ncolors<=0 || ncolors>256) return(1);
|
36
|
+
if(sample<=0 || sample>30) return(1);
|
37
|
+
|
38
|
+
Picture256 = malloc(pkl->width*pkl->height);
|
39
|
+
|
40
|
+
neuReduce(pkl->image, ncolors, pkl->width*pkl->height, sample, Picture256, QuantizedPalette);
|
41
|
+
|
42
|
+
for(i=0,j=0; i<pkl->height*pkl->width*3; i+=3,j++)
|
43
|
+
memcpy(&pkl->image[i], &QuantizedPalette[ Picture256[j]*3 ], pkl->channel);
|
44
|
+
|
45
|
+
free(Picture256);
|
46
|
+
return(0);
|
47
|
+
}
|
48
|
+
|
49
|
+
//=============================================================================
|
50
|
+
// pkl_wu
|
51
|
+
//=============================================================================
|
52
|
+
PKLExport int pkl_wu(PKLImage pkl, int ncolors)
|
53
|
+
{
|
54
|
+
unsigned char QuantizedPalette[256*3], *QuantizedPicture;
|
55
|
+
unsigned char *p, *q;
|
56
|
+
int i;
|
57
|
+
|
58
|
+
if(pkl->color!=PKL_RGB) return(1);
|
59
|
+
if(ncolors<=0 || ncolors>256) return(1);
|
60
|
+
|
61
|
+
QuantizedPicture = malloc(pkl->width*pkl->height);
|
62
|
+
|
63
|
+
wuReduce(pkl->image, ncolors, pkl->width*pkl->height, QuantizedPicture, QuantizedPalette);
|
64
|
+
|
65
|
+
p = pkl->image;
|
66
|
+
q = QuantizedPicture;
|
67
|
+
for(i=0; i<pkl->height*pkl->width; i++){
|
68
|
+
*p++ = QuantizedPalette[ (*q)*3+0 ];
|
69
|
+
*p++ = QuantizedPalette[ (*q)*3+1 ];
|
70
|
+
*p++ = QuantizedPalette[ (*q)*3+2 ];
|
71
|
+
q++;
|
72
|
+
}
|
73
|
+
free(QuantizedPicture);
|
74
|
+
return(0);
|
75
|
+
}
|
76
|
+
|
77
|
+
//=============================================================================
|
78
|
+
// pkl_posterize
|
79
|
+
//=============================================================================
|
80
|
+
PKLExport int pkl_posterize(PKLImage pkl, int level)
|
81
|
+
{
|
82
|
+
unsigned char *p, color[PKL_COLOR];
|
83
|
+
int i, j, k;
|
84
|
+
double d, n;
|
85
|
+
|
86
|
+
if(level<1 && level>256) return(1);
|
87
|
+
|
88
|
+
n = (256.0/(double)level);
|
89
|
+
d = 255.0/(double)((double)level-1.0);
|
90
|
+
|
91
|
+
for(i=0; i<level; i++)
|
92
|
+
for(j=floor(i*n); j<floor((i+1)*n); j++)
|
93
|
+
color[j]= PKL_COLOR_CLIP(d*i);
|
94
|
+
|
95
|
+
for(i=0; i<pkl->height; i++){
|
96
|
+
for(j=0; j<pkl->width; j++){
|
97
|
+
p = &pkl->image[(i*pkl->width+j)*pkl->channel];
|
98
|
+
for(k=0; k<pkl->channel; k++,p++)
|
99
|
+
*p = color[*p];
|
100
|
+
}
|
101
|
+
}
|
102
|
+
return(0);
|
103
|
+
}
|
104
|
+
|
105
|
+
//=============================================================================
|
106
|
+
// pkl_cutcolor
|
107
|
+
//=============================================================================
|
108
|
+
PKLExport int pkl_cutcolor(PKLImage pkl, int level)
|
109
|
+
{
|
110
|
+
unsigned char *p;
|
111
|
+
int i, j, k;
|
112
|
+
|
113
|
+
if(level<0 && level>256) return(1);
|
114
|
+
|
115
|
+
for(i=0; i<pkl->height; i++){
|
116
|
+
for(j=0; j<pkl->width; j++){
|
117
|
+
p = &pkl->image[(i*pkl->width+j)*pkl->channel];
|
118
|
+
for(k=0; k<pkl->channel; k++){
|
119
|
+
*p = (*p & level);
|
120
|
+
p++;
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
return(0);
|
125
|
+
}
|
126
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#ifndef _LIB_PIKL_DECREASE_
|
2
|
+
#define _LIB_PIKL_DECREASE_
|
3
|
+
|
4
|
+
#include <stdio.h>
|
5
|
+
#include <stdlib.h>
|
6
|
+
#include <string.h>
|
7
|
+
#include <math.h>
|
8
|
+
|
9
|
+
#include "pikl.h"
|
10
|
+
#include "pikl_private.h"
|
11
|
+
|
12
|
+
|
13
|
+
#include "decrease/median.h"
|
14
|
+
#include "decrease/neuquant.h"
|
15
|
+
#include "decrease/wu.h"
|
16
|
+
//#include "decrease/dl.h"
|
17
|
+
//#include "decrease/ccmap.h"
|
18
|
+
|
19
|
+
#endif
|
@@ -0,0 +1,240 @@
|
|
1
|
+
#include "pikl_effect2.h"
|
2
|
+
|
3
|
+
//=============================================================================
|
4
|
+
// pkl_invert
|
5
|
+
//=============================================================================
|
6
|
+
PKLExport int pkl_invert(PKLImage pkl)
|
7
|
+
{
|
8
|
+
int i;
|
9
|
+
for(i=0; i<pkl->height*pkl->width*pkl->channel; i++)
|
10
|
+
pkl->image[i] ^= 0xff;
|
11
|
+
return(0);
|
12
|
+
}
|
13
|
+
|
14
|
+
//=============================================================================
|
15
|
+
// pkl_composite
|
16
|
+
//=============================================================================
|
17
|
+
PKLExport int pkl_composite(PKLImage parent, PKLImage child, int xpos, int ypos)
|
18
|
+
{
|
19
|
+
int tw, th, i, j;
|
20
|
+
|
21
|
+
if(parent->channel != child->channel) return(1);
|
22
|
+
if(xpos<0 || xpos>=parent->width || ypos<0 || ypos>=parent->height) return(1);
|
23
|
+
|
24
|
+
tw = (xpos+child->width > parent->width) ? parent->width-xpos : child->width;
|
25
|
+
th = (ypos+child->height > parent->height) ? parent->height-ypos : child->height;
|
26
|
+
|
27
|
+
for(i=ypos,j=0; i<th+ypos; i++,j++){
|
28
|
+
memcpy(&parent->image[(i*parent->width+xpos)*parent->channel],
|
29
|
+
&child->image[j*child->width*child->channel], tw*child->channel);
|
30
|
+
}
|
31
|
+
|
32
|
+
return(0);
|
33
|
+
}
|
34
|
+
|
35
|
+
//=============================================================================
|
36
|
+
// pkl_composite2
|
37
|
+
//=============================================================================
|
38
|
+
PKLExport int pkl_composite2(PKLImage parent, PKLImage child, int xpos, int ypos, int transcolor)
|
39
|
+
{
|
40
|
+
int tw, th, i, j, s, t, hit;
|
41
|
+
unsigned char trans[PKL_CHANNEL];
|
42
|
+
|
43
|
+
if(parent->channel != child->channel) return(1);
|
44
|
+
if(xpos<0 || xpos>=parent->width || ypos<0 || ypos>=parent->height) return(1);
|
45
|
+
|
46
|
+
for(i=0; i<parent->channel; i++)
|
47
|
+
trans[i] = (transcolor>>((parent->channel-i)*8) & 0xFF);
|
48
|
+
|
49
|
+
tw = (xpos+child->width > parent->width) ? parent->width-xpos : child->width;
|
50
|
+
th = (ypos+child->height > parent->height) ? parent->height-ypos : child->height;
|
51
|
+
|
52
|
+
for(i=ypos,j=0; i<th+ypos; i++,j++){
|
53
|
+
for(s=0; s<tw; s++){
|
54
|
+
hit = 0;
|
55
|
+
for(t=0; t<child->channel; t++){
|
56
|
+
if(child->image[(j*child->width+s)*child->channel+t] == trans[t]) hit++;
|
57
|
+
}
|
58
|
+
|
59
|
+
if(hit!=child->channel){
|
60
|
+
memcpy(&parent->image[(i*parent->width+xpos+s)*parent->channel],
|
61
|
+
&child->image[(j*child->width+s)*child->channel], child->channel);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
return(0);
|
67
|
+
}
|
68
|
+
|
69
|
+
//=============================================================================
|
70
|
+
// pkl_sepia
|
71
|
+
//=============================================================================
|
72
|
+
PKLExport int pkl_sepia(PKLImage pkl, double red_weight, double green_weight, double blue_weight)
|
73
|
+
{
|
74
|
+
unsigned char *wrk;
|
75
|
+
int i, j, color;
|
76
|
+
|
77
|
+
if(pkl->color!=PKL_RGB) return(1);
|
78
|
+
|
79
|
+
wrk = malloc(pkl->width*pkl->height*pkl->channel);
|
80
|
+
if(!wrk) return(1);
|
81
|
+
memset(wrk, 0, pkl->width*pkl->height*pkl->channel);
|
82
|
+
|
83
|
+
for(i=0; i<pkl->height; i++){
|
84
|
+
for(j=0; j<pkl->width; j++){
|
85
|
+
color = ((pkl->image[(i*pkl->width+j)*pkl->channel+0]+
|
86
|
+
pkl->image[(i*pkl->width+j)*pkl->channel+1]+
|
87
|
+
pkl->image[(i*pkl->width+j)*pkl->channel+2]) / 3);
|
88
|
+
|
89
|
+
wrk[(i*pkl->width+j)*pkl->channel+0] = PKL_COLOR_CLIP(color*red_weight);
|
90
|
+
wrk[(i*pkl->width+j)*pkl->channel+1] = PKL_COLOR_CLIP(color*green_weight);
|
91
|
+
wrk[(i*pkl->width+j)*pkl->channel+2] = PKL_COLOR_CLIP(color*blue_weight);
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
free(pkl->image);
|
96
|
+
pkl->image = wrk;
|
97
|
+
return(0);
|
98
|
+
}
|
99
|
+
|
100
|
+
//=============================================================================
|
101
|
+
// pkl_oilpaint
|
102
|
+
//=============================================================================
|
103
|
+
PKLExport int pkl_oilpaint(PKLImage pkl, int weight)
|
104
|
+
{
|
105
|
+
int color[PKL_COLOR], gray;
|
106
|
+
int i, j, k, max, s, t, sx, sy, tx, ty;
|
107
|
+
unsigned char *wrk;
|
108
|
+
|
109
|
+
wrk = malloc(pkl->width*pkl->height*pkl->channel);
|
110
|
+
if(!wrk) return(1);
|
111
|
+
memset(wrk, 0, pkl->width*pkl->height*pkl->channel);
|
112
|
+
|
113
|
+
for(i=0; i<pkl->width*pkl->height*pkl->channel; i+=pkl->channel){
|
114
|
+
gray=0;
|
115
|
+
for(k=0; k<pkl->channel; k++)
|
116
|
+
gray += pkl->image[i+k];
|
117
|
+
wrk[i] = PKL_COLOR_CLIP(gray/pkl->channel);
|
118
|
+
}
|
119
|
+
|
120
|
+
//get histgram
|
121
|
+
memset(color, 0, sizeof(int)*PKL_COLOR);
|
122
|
+
for(i=0; i<pkl->height*pkl->width; i+=pkl->channel) color[wrk[i]]++;
|
123
|
+
|
124
|
+
//���Ӄs�N�Z������ŕp�F��I��
|
125
|
+
for(i=0; i<pkl->height; i++){
|
126
|
+
for(j=0; j<pkl->width; j++){
|
127
|
+
max = 0;
|
128
|
+
tx=j;
|
129
|
+
ty=i;
|
130
|
+
for(s=0; s<weight; s++){
|
131
|
+
for(t=0; t<weight; t++){
|
132
|
+
sx = (t+j > pkl->width) ? pkl->width-1 : t+j;
|
133
|
+
sy = (s+i > pkl->height) ? pkl->height-1 : s+i;
|
134
|
+
if(max<color[wrk[(sy*pkl->width+sx)*pkl->channel]]){
|
135
|
+
max = color[wrk[(sy*pkl->width+sx)*pkl->channel]];
|
136
|
+
tx = sx;
|
137
|
+
ty = sy;
|
138
|
+
}
|
139
|
+
}
|
140
|
+
}
|
141
|
+
//�I���W�i���̐F��K�p
|
142
|
+
memcpy(&wrk[(i*pkl->width+j)*pkl->channel], &pkl->image[(ty*pkl->width+tx)*pkl->channel], pkl->channel);
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
free(pkl->image);
|
147
|
+
pkl->image = wrk;
|
148
|
+
return(0);
|
149
|
+
}
|
150
|
+
|
151
|
+
//=============================================================================
|
152
|
+
// pkl_focus
|
153
|
+
//=============================================================================
|
154
|
+
PKLExport int pkl_focus(PKLImage pkl, PKL_FOCUS type)
|
155
|
+
{
|
156
|
+
unsigned char *wrk;
|
157
|
+
int i, j, s, t, k, clipx, clipy, weight=1;
|
158
|
+
int *matrix, color[PKL_CHANNEL];
|
159
|
+
|
160
|
+
//select filter
|
161
|
+
matrix=focus_filter[0].matrix;
|
162
|
+
for(i=0; i<sizeof(focus_filter)/sizeof(struct PKL_FILTER); i++){
|
163
|
+
if(type==focus_filter[i].type){
|
164
|
+
matrix=focus_filter[i].matrix;
|
165
|
+
break;
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
for(i=0; i<9; i++)
|
170
|
+
weight += matrix[i];
|
171
|
+
|
172
|
+
wrk = malloc(pkl->width*pkl->height*pkl->channel);
|
173
|
+
if(!wrk) return(1);
|
174
|
+
memset(wrk, 0, pkl->width*pkl->height*pkl->channel);
|
175
|
+
|
176
|
+
for(i=0; i<pkl->height; i++){
|
177
|
+
for(j=0; j<pkl->width; j++){
|
178
|
+
memset(color, 0, sizeof(color));
|
179
|
+
for(s=0; s<3; s++){
|
180
|
+
for(t=0; t<3; t++){
|
181
|
+
clipx = (j+t)>=pkl->width ? pkl->width-1 : j+t;
|
182
|
+
clipy = (i+s)>=pkl->height ? pkl->height-1 : i+s;
|
183
|
+
for(k=0; k<pkl->channel; k++)
|
184
|
+
color[k] += pkl->image[(clipy*pkl->width+clipx) * pkl->channel + k] * matrix[t+s*3];
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
188
|
+
for(k=0; k<pkl->channel; k++)
|
189
|
+
wrk[(i*pkl->width+j)*pkl->channel+k] = PKL_COLOR_CLIP(color[k]/weight);
|
190
|
+
}
|
191
|
+
}
|
192
|
+
|
193
|
+
free(pkl->image);
|
194
|
+
pkl->image = wrk;
|
195
|
+
return(0);
|
196
|
+
}
|
197
|
+
|
198
|
+
//=============================================================================
|
199
|
+
// pkl_emboss
|
200
|
+
//=============================================================================
|
201
|
+
PKLExport int pkl_emboss(PKLImage pkl, PKL_EMBOSS type)
|
202
|
+
{
|
203
|
+
unsigned char *wrk;
|
204
|
+
int i, j, s, t, k, clipx, clipy;
|
205
|
+
int *matrix, color[PKL_CHANNEL];
|
206
|
+
|
207
|
+
//select filter
|
208
|
+
matrix=focus_filter[0].matrix;
|
209
|
+
for(i=0; i<sizeof(emboss_filter)/sizeof(struct PKL_FILTER); i++){
|
210
|
+
if(type==emboss_filter[i].type){
|
211
|
+
matrix=emboss_filter[i].matrix;
|
212
|
+
break;
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
216
|
+
wrk = malloc(pkl->width*pkl->height*pkl->channel);
|
217
|
+
if(!wrk) return(1);
|
218
|
+
memset(wrk, 0, pkl->width*pkl->height*pkl->channel);
|
219
|
+
|
220
|
+
for(i=0; i<pkl->height; i++){
|
221
|
+
for(j=0; j<pkl->width; j++){
|
222
|
+
memset(color, 0, sizeof(color));
|
223
|
+
for(s=0; s<3; s++){
|
224
|
+
for(t=0; t<3; t++){
|
225
|
+
clipx = (j+t)>=pkl->width ? pkl->width-1 : j+t;
|
226
|
+
clipy = (i+s)>=pkl->height ? pkl->height-1 : i+s;
|
227
|
+
for(k=0; k<pkl->channel; k++)
|
228
|
+
color[k] += pkl->image[(clipy*pkl->width+clipx) * pkl->channel + k] * matrix[t+s*3];
|
229
|
+
}
|
230
|
+
}
|
231
|
+
|
232
|
+
for(k=0; k<pkl->channel; k++)
|
233
|
+
wrk[(i*pkl->width+j)*pkl->channel+k] = PKL_COLOR_CLIP(color[k]+127);
|
234
|
+
}
|
235
|
+
}
|
236
|
+
|
237
|
+
free(pkl->image);
|
238
|
+
pkl->image = wrk;
|
239
|
+
return(0);
|
240
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#ifndef _LIB_PIKL_EFFECT2_
|
2
|
+
#define _LIB_PIKL_EFFECT2_
|
3
|
+
|
4
|
+
#include <stdio.h>
|
5
|
+
#include <stdlib.h>
|
6
|
+
#include <string.h>
|
7
|
+
#include <math.h>
|
8
|
+
|
9
|
+
#include "pikl.h"
|
10
|
+
#include "pikl_private.h"
|
11
|
+
|
12
|
+
struct PKL_FILTER {
|
13
|
+
int type;
|
14
|
+
int matrix[9];
|
15
|
+
};
|
16
|
+
|
17
|
+
struct PKL_FILTER emboss_filter[] =
|
18
|
+
{
|
19
|
+
{ PKL_EMBOSS_EMBOSS, { 0, 0, -1,
|
20
|
+
0, 0, 0,
|
21
|
+
1, 0, 0 }},
|
22
|
+
|
23
|
+
{ PKL_EMBOSS_LAPLACIAN, {-1, -1, -1,
|
24
|
+
-1, 8, -1,
|
25
|
+
-1, -1, -1 }},
|
26
|
+
|
27
|
+
{ PKL_EMBOSS_HEAVY, { 2, 0, 0,
|
28
|
+
0, -1, 0,
|
29
|
+
0, 0, -1 }},
|
30
|
+
|
31
|
+
{ PKL_EMBOSS_LIGHT, { 0, 0, 0,
|
32
|
+
0, 1, 0,
|
33
|
+
0, 0, -1 }},
|
34
|
+
};
|
35
|
+
|
36
|
+
|
37
|
+
struct PKL_FILTER focus_filter[] =
|
38
|
+
{
|
39
|
+
{ PKL_FOCUS_DETAIL, { 0, -1, 0,
|
40
|
+
-1, 10, -1,
|
41
|
+
0, -1, 0 }},
|
42
|
+
|
43
|
+
{ PKL_FOCUS_EDGES, {-1, -1, -1,
|
44
|
+
-1, 9, -1,
|
45
|
+
-1, -1, -1 }},
|
46
|
+
|
47
|
+
{ PKL_FOCUS_FOCUS, {-1, 0, -1,
|
48
|
+
0, 7, 0,
|
49
|
+
-1, 0, -1 }},
|
50
|
+
};
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
#endif
|