pikl 0.2.8-x86-mswin32 → 0.3.0-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/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/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/pikl.dll +0 -0
- 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_effect4.c
DELETED
@@ -1,495 +0,0 @@
|
|
1
|
-
#include "pikl_effect4.h"
|
2
|
-
|
3
|
-
//=============================================================================
|
4
|
-
// pkl_edgeposter
|
5
|
-
//=============================================================================
|
6
|
-
PKLExport int pkl_edgeposter(PKLImage pkl, int level, int up)
|
7
|
-
{
|
8
|
-
if(pkl_posterize(pkl, level)) return(1);
|
9
|
-
if(pkl_noisecut(pkl)) return(1);
|
10
|
-
if(pkl_brightness(pkl, up)) return(1);
|
11
|
-
if(pkl_edgepaint(pkl)) return(1);
|
12
|
-
return(0);
|
13
|
-
}
|
14
|
-
|
15
|
-
//=============================================================================
|
16
|
-
// pkl_edgepaint
|
17
|
-
//=============================================================================
|
18
|
-
PKLExport int pkl_edgepaint(PKLImage pkl)
|
19
|
-
{
|
20
|
-
unsigned char *wrk, *p, *q;
|
21
|
-
int i, j, s, t, k, color, clipx, clipy, gray;
|
22
|
-
const int filter[9] = { -1, -1, -1,
|
23
|
-
-1, 8, -1,
|
24
|
-
-1, -1, -1};
|
25
|
-
|
26
|
-
wrk = malloc(pkl->width*pkl->height*pkl->channel);
|
27
|
-
if(!wrk) return(1);
|
28
|
-
memset(wrk, 0, pkl->width*pkl->height*pkl->channel);
|
29
|
-
|
30
|
-
/* convert grayscale */
|
31
|
-
for(i=0; i<pkl->width*pkl->height*pkl->channel; i+=pkl->channel){
|
32
|
-
gray=0;
|
33
|
-
for(k=0; k<pkl->channel; k++)
|
34
|
-
gray += pkl->image[i+k];
|
35
|
-
wrk[i] = PKL_COLOR_CLIP(gray/pkl->channel);
|
36
|
-
}
|
37
|
-
|
38
|
-
for(i=0; i<pkl->height; i++){
|
39
|
-
for(j=0; j<pkl->width; j++){
|
40
|
-
color=0;
|
41
|
-
for(s=0; s<3; s++){
|
42
|
-
for(t=0; t<3; t++){
|
43
|
-
clipx = (j+t)>=pkl->width ? pkl->width-1 : j+t;
|
44
|
-
clipy = (i+s)>=pkl->height ? pkl->height-1 : i+s;
|
45
|
-
color += wrk[(clipy*pkl->width+clipx) * pkl->channel] * filter[t+s*3];
|
46
|
-
}
|
47
|
-
}
|
48
|
-
|
49
|
-
if(color>0){
|
50
|
-
memset(&wrk[(i*pkl->width+j)*pkl->channel], 0, pkl->channel);
|
51
|
-
}else{
|
52
|
-
p = &wrk[(i*pkl->width+j)*pkl->channel];
|
53
|
-
q = &pkl->image[(i*pkl->width+j)*pkl->channel];
|
54
|
-
for(k=0; k<pkl->channel; k++) *p++=*q++;
|
55
|
-
}
|
56
|
-
}
|
57
|
-
}
|
58
|
-
|
59
|
-
free(pkl->image);
|
60
|
-
pkl->image = wrk;
|
61
|
-
return(0);
|
62
|
-
}
|
63
|
-
|
64
|
-
//=============================================================================
|
65
|
-
// pkl_tileslit
|
66
|
-
//=============================================================================
|
67
|
-
PKLExport int pkl_tileslit(PKLImage pkl, int area, int shift)
|
68
|
-
{
|
69
|
-
unsigned char *wrk;
|
70
|
-
int i, j, k, tx, ty;
|
71
|
-
int w, h, offsetx, offsety;
|
72
|
-
|
73
|
-
if(shift==0) return(0);
|
74
|
-
if(area<=1 && (area>pkl->width || area>pkl->height)) return(1);
|
75
|
-
|
76
|
-
wrk = malloc(pkl->width*pkl->height*pkl->channel);
|
77
|
-
if(!wrk) return(1);
|
78
|
-
memset(wrk, 0, pkl->width*pkl->height*pkl->channel);
|
79
|
-
|
80
|
-
//invert
|
81
|
-
for(i=0; i<pkl->height*pkl->width*pkl->channel; i++)
|
82
|
-
wrk[i] = (pkl->image[i] ^ 0xff);
|
83
|
-
|
84
|
-
srand48(1);
|
85
|
-
for(i=0; i<pkl->height; i+=area){
|
86
|
-
for(j=0; j<pkl->width; j+=area){
|
87
|
-
w = j+area>pkl->width ? pkl->width-j : area;
|
88
|
-
h = i+area>pkl->height ? pkl->height : i+area;
|
89
|
-
|
90
|
-
//�i�q�̂��炵��
|
91
|
-
//offsetx = rand()%(shift*2+1)-shift;
|
92
|
-
//offsety = rand()%(shift*2+1)-shift;
|
93
|
-
offsetx = lrand48()%(shift*2+1)-shift;
|
94
|
-
offsety = lrand48()%(shift*2+1)-shift;
|
95
|
-
|
96
|
-
for(k=i; k<h; k++){
|
97
|
-
tx = j+offsetx<0 ? 0 : j+offsetx>=pkl->width ? pkl->width-1 : j+offsetx;
|
98
|
-
ty = k+offsety<0 ? 0 : k+offsety>=pkl->height ? pkl->height-1 : k+offsety;
|
99
|
-
memcpy(&wrk[(ty*pkl->width+tx)*pkl->channel], &pkl->image[(k*pkl->width+j)*pkl->channel], w*pkl->channel);
|
100
|
-
}
|
101
|
-
}
|
102
|
-
}
|
103
|
-
|
104
|
-
free(pkl->image);
|
105
|
-
pkl->image = wrk;
|
106
|
-
return(0);
|
107
|
-
}
|
108
|
-
|
109
|
-
//=============================================================================
|
110
|
-
// pkl_grid
|
111
|
-
//=============================================================================
|
112
|
-
PKLExport int pkl_grid(PKLImage pkl, int msx, int msy, int color)
|
113
|
-
{
|
114
|
-
unsigned char *p;
|
115
|
-
int i, j, k, mpx, mpy;
|
116
|
-
|
117
|
-
//��U���U�C�N��
|
118
|
-
if(pkl_mosaic(pkl, msx, msy)) return(1);
|
119
|
-
|
120
|
-
mpx = (msx<1) ? 1 : (msx>=pkl->width) ? pkl->width-1 : msx;
|
121
|
-
mpy = (msy<1) ? 1 : (msy>=pkl->height) ? pkl->height-1 : msy;
|
122
|
-
|
123
|
-
for(i=0; i<pkl->height-1; i++){
|
124
|
-
if(i%mpy==0){
|
125
|
-
for(j=0; j<pkl->width; j++){
|
126
|
-
p = &pkl->image[(i*pkl->width+j)*pkl->channel];
|
127
|
-
for(k=0; k<pkl->channel; k++){
|
128
|
-
*p = PKL_COLOR_CLIP(*p+color);
|
129
|
-
p++;
|
130
|
-
}
|
131
|
-
}
|
132
|
-
}
|
133
|
-
for(j=mpx; j<pkl->width; j+=mpx){
|
134
|
-
p = &pkl->image[(i*pkl->width+j)*pkl->channel];
|
135
|
-
for(k=0; k<pkl->channel; k++){
|
136
|
-
*p = PKL_COLOR_CLIP(*p+color);
|
137
|
-
p++;
|
138
|
-
}
|
139
|
-
}
|
140
|
-
}
|
141
|
-
|
142
|
-
return(0);
|
143
|
-
}
|
144
|
-
|
145
|
-
//=============================================================================
|
146
|
-
// pkl_kuwahara
|
147
|
-
//=============================================================================
|
148
|
-
PKLExport int pkl_kuwahara(PKLImage pkl, int range)
|
149
|
-
{
|
150
|
-
unsigned char *wrk, *p;
|
151
|
-
int i, j, k, count, tr, t, tx, ty, clipx, clipy;
|
152
|
-
int value[4], mincolor, idx, total[PKL_CHANNEL];
|
153
|
-
struct { int sx, sy, ex, ey; } r[4]; //rect
|
154
|
-
unsigned char max_color[PKL_CHANNEL], min_color[PKL_CHANNEL], c;
|
155
|
-
|
156
|
-
if(range<=1) return(0);
|
157
|
-
|
158
|
-
wrk = malloc(pkl->width*pkl->height*pkl->channel);
|
159
|
-
if(!wrk) return(1);
|
160
|
-
memset(wrk, 0, pkl->width*pkl->height*pkl->channel);
|
161
|
-
|
162
|
-
//�̈�̃s�N�Z����
|
163
|
-
count = range*range;
|
164
|
-
tr = range-1;
|
165
|
-
|
166
|
-
for(i=0; i<pkl->height; i++){
|
167
|
-
for(j=0; j<pkl->width; j++){
|
168
|
-
/* �J�����g�s�N�Z���𒆐S��4�̗̈�ɕ����� */
|
169
|
-
//����(0)
|
170
|
-
r[0].sx = j-tr;
|
171
|
-
r[0].sy = i-tr;
|
172
|
-
r[0].ex = j;
|
173
|
-
r[0].ey = i;
|
174
|
-
//�E��(1)
|
175
|
-
r[1].sx = j;
|
176
|
-
r[1].sy = i-tr;
|
177
|
-
r[1].ex = j+tr;
|
178
|
-
r[1].ey = i;
|
179
|
-
//�E��(2)
|
180
|
-
r[2].sx = j;
|
181
|
-
r[2].sy = i;
|
182
|
-
r[2].ex = j+tr;
|
183
|
-
r[2].ey = i+tr;
|
184
|
-
//����(3)
|
185
|
-
r[3].sx = j-tr;
|
186
|
-
r[3].sy = i;
|
187
|
-
r[3].ex = j;
|
188
|
-
r[3].ey = i+tr;
|
189
|
-
|
190
|
-
/* �e�̈�Ŋe�F�̍ő�l�ƍŏ��l�̍���ݐς��� */
|
191
|
-
memset(value, 0, sizeof(value));
|
192
|
-
for(t=0; t<4; t++){
|
193
|
-
memset(max_color, 0x00, PKL_CHANNEL);
|
194
|
-
memset(min_color, 0xff, PKL_CHANNEL);
|
195
|
-
for(ty=r[t].sy; ty<=r[t].ey; ty++){
|
196
|
-
for(tx=r[t].sx; tx<=r[t].ex; tx++){
|
197
|
-
clipx = tx<0 ? 0 : tx>=pkl->width ? pkl->width-1 : tx;
|
198
|
-
clipy = ty<0 ? 0 : ty>=pkl->height ? pkl->height-1 : ty;
|
199
|
-
p = &pkl->image[(ty*pkl->width+tx)*pkl->channel];
|
200
|
-
for(k=0; k<pkl->channel; k++){
|
201
|
-
c = *p++;
|
202
|
-
max_color[k] = (c > max_color[k]) ? c : max_color[k];
|
203
|
-
min_color[k] = (c < min_color[k]) ? c : min_color[k];
|
204
|
-
}
|
205
|
-
}
|
206
|
-
}
|
207
|
-
|
208
|
-
for(k=0; k<pkl->channel; k++)
|
209
|
-
value[t] += (max_color[k] - min_color[k]);
|
210
|
-
}
|
211
|
-
|
212
|
-
/* �e�̈�ōł��F�̍������������̈��I������ */
|
213
|
-
mincolor = value[0];
|
214
|
-
idx = 0;
|
215
|
-
for(t=1; t<4; t++){
|
216
|
-
if(value[t]<mincolor){
|
217
|
-
mincolor = value[t];
|
218
|
-
idx = t;
|
219
|
-
}
|
220
|
-
}
|
221
|
-
|
222
|
-
/* �I�����ꂽ�̈�̐F�̕��ς��s�N�Z���ɓK�p���� */
|
223
|
-
memset(total, 0, sizeof(total));
|
224
|
-
for(ty=r[idx].sy; ty<=r[idx].ey; ty++){
|
225
|
-
for(tx=r[idx].sx; tx<=r[idx].ex; tx++){
|
226
|
-
clipx = tx<0 ? 0 : tx>=pkl->width ? pkl->width-1 : tx;
|
227
|
-
clipy = ty<0 ? 0 : ty>=pkl->height ? pkl->height-1 : ty;
|
228
|
-
p = &pkl->image[(ty*pkl->width+tx)*pkl->channel];
|
229
|
-
for(k=0; k<pkl->channel; k++)
|
230
|
-
total[k] += *p++;
|
231
|
-
}
|
232
|
-
}
|
233
|
-
p =&wrk[(i*pkl->width+j)*pkl->channel];
|
234
|
-
for(k=0; k<pkl->channel; k++)
|
235
|
-
*p++ = PKL_COLOR_CLIP(total[k]/count);
|
236
|
-
}
|
237
|
-
}
|
238
|
-
|
239
|
-
free(pkl->image);
|
240
|
-
pkl->image = wrk;
|
241
|
-
return(0);
|
242
|
-
}
|
243
|
-
|
244
|
-
//=============================================================================
|
245
|
-
// pkl_alphablend
|
246
|
-
//=============================================================================
|
247
|
-
PKLExport int pkl_alphablend(PKLImage parent, PKLImage child, int xpos, int ypos, int alpha)
|
248
|
-
{
|
249
|
-
int tw, th, i, j, k, alp, pp, cp;
|
250
|
-
const int limits=PKL_COLOR-1;
|
251
|
-
|
252
|
-
if(parent->channel != child->channel) return(1);
|
253
|
-
if(xpos<0 || xpos>=parent->width || ypos<0 || ypos>=parent->height) return(1);
|
254
|
-
alp = PKL_COLOR_CLIP(alpha);
|
255
|
-
|
256
|
-
tw = (xpos+child->width > parent->width) ? parent->width-xpos : child->width;
|
257
|
-
th = (ypos+child->height > parent->height) ? parent->height-ypos : child->height;
|
258
|
-
|
259
|
-
for(i=ypos; i<th+ypos; i++){
|
260
|
-
for(j=0; j<tw; j++){
|
261
|
-
pp = (i*parent->width+xpos+j)*parent->channel;
|
262
|
-
cp = ((i-ypos)*child->width+j)*child->channel;
|
263
|
-
for(k=0; k<parent->channel; k++)
|
264
|
-
parent->image[pp+k] =PKL_COLOR_CLIP((parent->image[pp+k]*alp + child->image[cp+k]*(limits-alp)) / limits);
|
265
|
-
}
|
266
|
-
|
267
|
-
}
|
268
|
-
|
269
|
-
return(0);
|
270
|
-
}
|
271
|
-
|
272
|
-
//=============================================================================
|
273
|
-
// pkl_alphablend2
|
274
|
-
//=============================================================================
|
275
|
-
PKLExport int pkl_alphablend2(PKLImage parent, PKLImage child, int xpos, int ypos)
|
276
|
-
{
|
277
|
-
int tw, th, i, j, k, pp, cp;
|
278
|
-
double alpha;
|
279
|
-
|
280
|
-
if(parent->channel != child->channel) return(1);
|
281
|
-
if(xpos<0 || xpos>=parent->width || ypos<0 || ypos>=parent->height) return(1);
|
282
|
-
|
283
|
-
tw = (xpos+child->width > parent->width) ? parent->width-xpos : child->width;
|
284
|
-
th = (ypos+child->height > parent->height) ? parent->height-ypos : child->height;
|
285
|
-
|
286
|
-
for(i=ypos; i<th+ypos; i++){
|
287
|
-
for(j=0; j<tw; j++){
|
288
|
-
alpha = sin((i-ypos)*M_PI/child->height) * sin(j*M_PI/child->width);
|
289
|
-
pp = (i*parent->width+xpos+j)*parent->channel;
|
290
|
-
cp = ((i-ypos)*child->width+j)*child->channel;
|
291
|
-
for(k=0; k<parent->channel; k++)
|
292
|
-
parent->image[pp+k] =PKL_COLOR_CLIP(parent->image[pp+k]*(1.0-alpha) + child->image[cp+k]*alpha);
|
293
|
-
}
|
294
|
-
|
295
|
-
}
|
296
|
-
return(0);
|
297
|
-
}
|
298
|
-
|
299
|
-
//=============================================================================
|
300
|
-
// pkl_shadowframe
|
301
|
-
//=============================================================================
|
302
|
-
PKLExport int pkl_shadowframe(PKLImage pkl, int margin, int backcolor, int shadowcolor)
|
303
|
-
{
|
304
|
-
unsigned char *img, back[PKL_CHANNEL], shadow[PKL_CHANNEL];
|
305
|
-
int i, j, w, h;
|
306
|
-
|
307
|
-
if(margin<=0) return(1);
|
308
|
-
|
309
|
-
w = pkl->width;
|
310
|
-
h = pkl->height;
|
311
|
-
img = pkl->image;
|
312
|
-
pkl->width = w + margin*3;
|
313
|
-
pkl->height = h + margin*3;
|
314
|
-
|
315
|
-
pkl->image = malloc(pkl->width*pkl->height*pkl->channel);
|
316
|
-
if(!pkl->image) return(1);
|
317
|
-
memset(pkl->image, 0, pkl->width*pkl->height*pkl->channel);
|
318
|
-
|
319
|
-
for(i=0; i<pkl->channel; i++){
|
320
|
-
back[i] = (backcolor>>((pkl->channel-i)*8) & 0xFF);
|
321
|
-
shadow[i] = (shadowcolor>>((pkl->channel-i)*8) & 0xFF);
|
322
|
-
}
|
323
|
-
|
324
|
-
//�w�i�F�ݒ�
|
325
|
-
for(i=0; i<pkl->width*pkl->height*pkl->channel; i+=pkl->channel)
|
326
|
-
memcpy(&pkl->image[i], back, pkl->channel);
|
327
|
-
|
328
|
-
//�t���[���ݒ�
|
329
|
-
for(i=margin*2; i<h+margin*2; i++)
|
330
|
-
for(j=margin*2; j<w+margin*2; j++)
|
331
|
-
memcpy(&pkl->image[(i*pkl->width+j)*pkl->channel], shadow, pkl->channel);
|
332
|
-
|
333
|
-
//shadowframe�����(�P�Ƀu���[)
|
334
|
-
pkl_gaussblur(pkl, 5.0);
|
335
|
-
|
336
|
-
for(i=margin,j=0; i<h+margin; i++,j++)
|
337
|
-
memcpy(&pkl->image[(i*pkl->width+margin)*pkl->channel], &img[(j*w)*pkl->channel], w*pkl->channel);
|
338
|
-
|
339
|
-
free(img);
|
340
|
-
return(0);
|
341
|
-
}
|
342
|
-
|
343
|
-
//=============================================================================
|
344
|
-
// pkl_edge
|
345
|
-
//=============================================================================
|
346
|
-
PKLExport int pkl_edge(PKLImage pkl, int threshold)
|
347
|
-
{
|
348
|
-
unsigned char *wrk, *p;
|
349
|
-
int i, j, k, color[PKL_CHANNEL], total;
|
350
|
-
int r1, r2, r3;
|
351
|
-
|
352
|
-
wrk = malloc(pkl->width*pkl->height*pkl->channel);
|
353
|
-
if(!wrk) return(1);
|
354
|
-
memset(wrk, 0xff, pkl->width*pkl->height*pkl->channel);
|
355
|
-
|
356
|
-
r3 = sqrt((double)pkl->channel);
|
357
|
-
|
358
|
-
for(i=0; i<pkl->height; i++){
|
359
|
-
r1=r2=0;
|
360
|
-
for(j=0; j<pkl->width; j++){
|
361
|
-
//x����
|
362
|
-
if(j+1 < pkl->width){
|
363
|
-
p = &pkl->image[(i*pkl->width+j)*pkl->channel];
|
364
|
-
for(k=0; k<pkl->channel; k++){
|
365
|
-
color[k] = *p - *(p+pkl->channel);
|
366
|
-
color[k] *= color[k];
|
367
|
-
p++;
|
368
|
-
}
|
369
|
-
total=0;
|
370
|
-
for(k=0; k<pkl->channel; k++)
|
371
|
-
total += color[k];
|
372
|
-
r1 = sqrt(total)/r3;
|
373
|
-
}
|
374
|
-
|
375
|
-
//y����
|
376
|
-
if(i+1 < pkl->height){
|
377
|
-
p = &pkl->image[(i*pkl->width+j)*pkl->channel];
|
378
|
-
for(k=0; k<pkl->channel; k++){
|
379
|
-
color[k] = *p - *(p+pkl->width*pkl->channel);
|
380
|
-
color[k] *= color[k];
|
381
|
-
p++;
|
382
|
-
}
|
383
|
-
total=0;
|
384
|
-
for(k=0; k<pkl->channel; k++)
|
385
|
-
total += color[k];
|
386
|
-
r2 = sqrt(total)/r3;
|
387
|
-
}
|
388
|
-
|
389
|
-
p = &wrk[(i*pkl->width+j)*pkl->channel];
|
390
|
-
if(r1>=threshold || r2>=threshold)
|
391
|
-
for(k=0; k<pkl->channel; k++) *p++=0;
|
392
|
-
}
|
393
|
-
}
|
394
|
-
free(pkl->image);
|
395
|
-
pkl->image = wrk;
|
396
|
-
return(0);
|
397
|
-
}
|
398
|
-
|
399
|
-
//=============================================================================
|
400
|
-
// pkl_dither
|
401
|
-
//=============================================================================
|
402
|
-
PKLExport int pkl_dither(PKLImage pkl, PKL_DITHER dither)
|
403
|
-
{
|
404
|
-
double FloydSteinberg[2][3] = {
|
405
|
-
{ -1, -1, 7.0/16.0},
|
406
|
-
{ 3.0/16.0, 5.0/16.0, 1.0/16.0} };
|
407
|
-
|
408
|
-
double Stucci[3][5] = {
|
409
|
-
{ -1, -1, -1, 8.0/42.0, 4.0/42.0},
|
410
|
-
{2.0/42.0, 4.0/42.0, 8.0/42.0, 4.0/42.0, 2.0/42.0},
|
411
|
-
{1.0/42.0, 2.0/42.0, 4.0/42.0, 2.0/42.0, 1.0/42.0} };
|
412
|
-
|
413
|
-
double Sierra[3][5] = {
|
414
|
-
{ -1, -1, -1, 5.0/32.0, 3.0/32.0},
|
415
|
-
{2.0/32.0, 4.0/32.0, 5.0/32.0, 4.0/32.0, 2.0/32.0},
|
416
|
-
{ -1, 2.0/32.0, 3.0/32.0, 2.0/32.0, -1} };
|
417
|
-
|
418
|
-
double JaJuNi[3][5] = {
|
419
|
-
{ -1, -1, -1, 7.0/48.0, 5.0/48.0},
|
420
|
-
{3.0/48.0, 5.0/48.0, 7.0/48.0, 5.0/48.0, 3.0/48.0},
|
421
|
-
{1.0/48.0, 3.0/48.0, 5.0/48.0, 3.0/48.0, 1.0/48.0} };
|
422
|
-
|
423
|
-
unsigned char *wrk, pix;
|
424
|
-
double *pt, err;
|
425
|
-
int i, j, k, gray, s, t, tx, ty, row, col, xrange;
|
426
|
-
|
427
|
-
wrk = malloc(pkl->width*pkl->height*pkl->channel);
|
428
|
-
if(!wrk) return(1);
|
429
|
-
|
430
|
-
//�f�B�U�p�^����I��
|
431
|
-
switch(dither){
|
432
|
-
case PKL_DITHER_STUCCI:
|
433
|
-
row = 5;
|
434
|
-
col = 3;
|
435
|
-
pt = &(Stucci[0][0]);
|
436
|
-
break;
|
437
|
-
|
438
|
-
case PKL_DITHER_SIERRA:
|
439
|
-
row = 5;
|
440
|
-
col = 3;
|
441
|
-
pt = &(Sierra[0][0]);
|
442
|
-
break;
|
443
|
-
|
444
|
-
case PKL_DITHER_JAJUNI:
|
445
|
-
row = 5;
|
446
|
-
col = 3;
|
447
|
-
pt = &(JaJuNi[0][0]);
|
448
|
-
break;
|
449
|
-
|
450
|
-
case PKL_DITHER_FLOYDSTEINBERG:
|
451
|
-
default:
|
452
|
-
row = 3;
|
453
|
-
col = 2;
|
454
|
-
pt = &(FloydSteinberg[0][0]);
|
455
|
-
}
|
456
|
-
|
457
|
-
for(i=0; i<pkl->height; i++){
|
458
|
-
for(j=0; j<pkl->width; j++){
|
459
|
-
gray=0;
|
460
|
-
for(k=0; k<pkl->channel; k++)
|
461
|
-
gray += pkl->image[(i*pkl->width+j)*pkl->channel+k];
|
462
|
-
pkl->image[(i*pkl->width+j)*pkl->channel] = PKL_COLOR_CLIP(gray/pkl->channel);
|
463
|
-
}
|
464
|
-
}
|
465
|
-
|
466
|
-
xrange = (row-1)/2;
|
467
|
-
|
468
|
-
for(i=0; i<pkl->height; i++){
|
469
|
-
for(j=0; j<pkl->width; j++){
|
470
|
-
pix = pkl->image[(i*pkl->width+j)*pkl->channel];
|
471
|
-
if(pix>127)
|
472
|
-
memset(&wrk[(i*pkl->width+j)*pkl->channel], 0xff, pkl->channel);
|
473
|
-
else
|
474
|
-
memset(&wrk[(i*pkl->width+j)*pkl->channel], 0x00, pkl->channel);
|
475
|
-
err = pix>127 ? pix-255 : pix;
|
476
|
-
|
477
|
-
for(s=0; s<col; s++){
|
478
|
-
for(t=-xrange; t<=xrange; t++){
|
479
|
-
tx = j+t;
|
480
|
-
ty = i+s;
|
481
|
-
if(tx<0 || tx>=pkl->width || ty>=pkl->height) continue;
|
482
|
-
if (pt[s*row+t+xrange] < 0) continue;
|
483
|
-
|
484
|
-
pkl->image[(ty*pkl->width+tx)*pkl->channel] =
|
485
|
-
PKL_COLOR_CLIP(pkl->image[(ty*pkl->width+tx)*pkl->channel] + err * pt[s*row+t+xrange]);
|
486
|
-
}
|
487
|
-
}
|
488
|
-
}
|
489
|
-
}
|
490
|
-
|
491
|
-
free(pkl->image);
|
492
|
-
pkl->image = wrk;
|
493
|
-
return(0);
|
494
|
-
}
|
495
|
-
|