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,731 @@
|
|
1
|
+
#include "pikl_scrap.h"
|
2
|
+
|
3
|
+
static void pkl_circle(PKLImage pkl, int x, int y, int radius, unsigned char *color);
|
4
|
+
|
5
|
+
//=============================================================================
|
6
|
+
// �A���`�G�C���A�X�����������~��`��
|
7
|
+
// x,y: �~�̒��S���W
|
8
|
+
// radius: ���a
|
9
|
+
// color: �h��F(unsigned char x[pkl->channel]�̗̈�����|�C���^)
|
10
|
+
//=============================================================================
|
11
|
+
static void pkl_circle(PKLImage pkl, int x, int y, int radius, unsigned char *color)
|
12
|
+
{
|
13
|
+
unsigned char *p;
|
14
|
+
int sx, sy, ex, ey, tx, ty;
|
15
|
+
int i, j, k, t, s;
|
16
|
+
int outside;
|
17
|
+
int stock[PKL_CHANNEL];
|
18
|
+
|
19
|
+
if(radius <= 0) return;
|
20
|
+
if(x<0 || x>=pkl->width || y<0 || y>=pkl->height) return;
|
21
|
+
|
22
|
+
//��`���W���Z�o
|
23
|
+
sx = x-radius;
|
24
|
+
sy = y-radius;
|
25
|
+
ex = x+radius;
|
26
|
+
ey = y+radius;
|
27
|
+
|
28
|
+
//tx,ty:���S����̋���
|
29
|
+
for(i=sy; i<=ey; i++){
|
30
|
+
ty = i-y;
|
31
|
+
for(j=sx; j<=ex; j++){
|
32
|
+
tx = j-x;
|
33
|
+
outside=0;
|
34
|
+
memset(stock, 0, sizeof(stock));
|
35
|
+
|
36
|
+
//�J�����g�s�N�Z���Ǝ��͂R�����~�̓������O���ɂ��邩�����āA�F��I������
|
37
|
+
for(t=0; t<=1; t++){
|
38
|
+
for(s=0; s<=1; s++){
|
39
|
+
if((tx+s)*(tx+s)+(ty+t)*(ty+t) > radius*radius){
|
40
|
+
if(j<0 || j>=pkl->width || i<0 || i>=pkl->height) continue;
|
41
|
+
p = &pkl->image[(i*pkl->width+j)*pkl->channel];
|
42
|
+
for(k=0; k<pkl->channel; k++)
|
43
|
+
stock[k] += *p++;
|
44
|
+
outside++;
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
if(j<0 || j>=pkl->width || i<0 || i>=pkl->height) continue;
|
50
|
+
|
51
|
+
p = &pkl->image[(i*pkl->width+j)*pkl->channel];
|
52
|
+
if(outside==0){
|
53
|
+
//�S�ĉ~�̓����ɂ���
|
54
|
+
for(k=0; k<pkl->channel; k++)
|
55
|
+
*p++ = color[k];
|
56
|
+
}else{
|
57
|
+
//�ꕔ�͉~�̊O���ɂ���
|
58
|
+
for(k=0; k<pkl->channel; k++)
|
59
|
+
*p++ = PKL_COLOR_CLIP((stock[k] + color[k]*(4-outside))/4);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
return;
|
65
|
+
}
|
66
|
+
|
67
|
+
//=============================================================================
|
68
|
+
// pkl_dots
|
69
|
+
//=============================================================================
|
70
|
+
PKLExport int pkl_dots(PKLImage pkl, int zone, int color)
|
71
|
+
{
|
72
|
+
unsigned char *wrk, *bp, *p, dc[PKL_CHANNEL];
|
73
|
+
int i, j, k, t, s, gray, count, stock;
|
74
|
+
double propc;
|
75
|
+
|
76
|
+
if(zone<3 || zone>10) return(1);
|
77
|
+
|
78
|
+
wrk = malloc(pkl->width*pkl->height*pkl->channel);
|
79
|
+
if(!wrk) return(1);
|
80
|
+
memset(wrk, 0xff, pkl->width*pkl->height*pkl->channel);
|
81
|
+
|
82
|
+
for(i=0; i<pkl->channel; i++)
|
83
|
+
dc[i] = (color>>((pkl->channel-i)*8) & 0xFF);
|
84
|
+
|
85
|
+
propc = zone/32.0;
|
86
|
+
|
87
|
+
bp = pkl->image;
|
88
|
+
pkl->image = wrk;
|
89
|
+
|
90
|
+
for(i=0; i<pkl->height; i+=zone){
|
91
|
+
for(j=0; j<pkl->width; j+=zone){
|
92
|
+
count=0;
|
93
|
+
stock=0;
|
94
|
+
for(t=i; t<i+zone; t++){
|
95
|
+
for(s=j; s<j+zone; s++){
|
96
|
+
if(t>=pkl->height || s>=pkl->width) continue;
|
97
|
+
p = &bp[(t*pkl->width+s)*pkl->channel];
|
98
|
+
for(k=0,gray=0; k<pkl->channel; k++)
|
99
|
+
gray += *p++;
|
100
|
+
stock += (255-gray/pkl->channel);
|
101
|
+
count++;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
if(count)
|
105
|
+
pkl_circle(pkl, j+zone/2, i+zone/2, sqrt(stock/count)*propc, dc);
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
free(bp);
|
110
|
+
return(0);
|
111
|
+
}
|
112
|
+
|
113
|
+
//=============================================================================
|
114
|
+
// pkl_swirl
|
115
|
+
//=============================================================================
|
116
|
+
PKLExport int pkl_swirl(PKLImage pkl, double factor, int x, int y, int backcolor)
|
117
|
+
{
|
118
|
+
unsigned char *wrk, color[PKL_CHANNEL], *p, *q;
|
119
|
+
int i, j, k, tx, ty, sx, sy;
|
120
|
+
double range, rad;
|
121
|
+
|
122
|
+
if(fabs(factor) > 1) return(1);
|
123
|
+
|
124
|
+
wrk = malloc(pkl->width*pkl->height*pkl->channel);
|
125
|
+
if(!wrk) return(1);
|
126
|
+
memset(wrk, 0, pkl->width*pkl->height*pkl->channel);
|
127
|
+
|
128
|
+
for(i=0; i<pkl->channel; i++)
|
129
|
+
color[i] = (backcolor>>((pkl->channel-i)*8) & 0xFF);
|
130
|
+
|
131
|
+
for(i=0; i<pkl->width*pkl->height; i++)
|
132
|
+
memcpy(&wrk[i*pkl->channel], color, pkl->channel);
|
133
|
+
|
134
|
+
//���S���W
|
135
|
+
tx = (x<0 || x>=pkl->width) ? pkl->width/2 : x;
|
136
|
+
ty = (y<0 || y>=pkl->height) ? pkl->height/2 : y;
|
137
|
+
|
138
|
+
for(i=0; i<pkl->height; i++){
|
139
|
+
for(j=0; j<pkl->width; j++){
|
140
|
+
range = sqrt((j-tx)*(j-tx) + (i-ty)*(i-ty));
|
141
|
+
rad = atan2(i-ty, j-tx) + (factor * range);
|
142
|
+
|
143
|
+
sx = range * cos(rad) + tx;
|
144
|
+
sy = range * sin(rad) + ty;
|
145
|
+
if(sx<0 || sx>=pkl->width || sy<0 || sy>=pkl->height) continue;
|
146
|
+
|
147
|
+
p = &pkl->image[(sy*pkl->width+sx)*pkl->channel];
|
148
|
+
q = &wrk[(i*pkl->width+j)*pkl->channel];
|
149
|
+
for(k=0; k<pkl->channel; k++)
|
150
|
+
*q++ = *p++;
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
154
|
+
free(pkl->image);
|
155
|
+
pkl->image = wrk;
|
156
|
+
return(0);
|
157
|
+
}
|
158
|
+
|
159
|
+
//=============================================================================
|
160
|
+
// pkl_wave
|
161
|
+
//=============================================================================
|
162
|
+
PKLExport int pkl_wave(PKLImage pkl, PKL_WAVE mode, double factor, double frequency)
|
163
|
+
{
|
164
|
+
unsigned char *wrk, *p, *q;
|
165
|
+
int i, j, k, tx, ty;
|
166
|
+
|
167
|
+
wrk = malloc(pkl->width*pkl->height*pkl->channel);
|
168
|
+
if(!wrk) return(1);
|
169
|
+
memset(wrk, 0, pkl->width*pkl->height*pkl->channel);
|
170
|
+
|
171
|
+
for(i=0; i<pkl->height; i++){
|
172
|
+
for(j=0; j<pkl->width; j++){
|
173
|
+
tx=j;
|
174
|
+
ty=i;
|
175
|
+
switch(mode){
|
176
|
+
case PKL_WAVE_HORZ:
|
177
|
+
ty += factor * sin(frequency * M_PI/180.0 * j);
|
178
|
+
break;
|
179
|
+
case PKL_WAVE_VERT:
|
180
|
+
tx += factor * sin(frequency * M_PI/180.0 * i);
|
181
|
+
break;
|
182
|
+
case PKL_WAVE_BOTH:
|
183
|
+
default:
|
184
|
+
tx += factor * sin(frequency * M_PI/180.0 * i);
|
185
|
+
ty += factor * sin(frequency * M_PI/180.0 * j);
|
186
|
+
}
|
187
|
+
|
188
|
+
tx = tx<0 ? 0 : tx>=pkl->width ? pkl->width-1 : tx;
|
189
|
+
ty = ty<0 ? 0 : ty>=pkl->height ? pkl->height-1 : ty;
|
190
|
+
|
191
|
+
p = &pkl->image[(ty*pkl->width+tx)*pkl->channel];
|
192
|
+
q = &wrk[(i*pkl->width+j)*pkl->channel];
|
193
|
+
for(k=0; k<pkl->channel; k++)
|
194
|
+
*q++ = *p++;
|
195
|
+
}
|
196
|
+
}
|
197
|
+
|
198
|
+
free(pkl->image);
|
199
|
+
pkl->image = wrk;
|
200
|
+
return(0);
|
201
|
+
}
|
202
|
+
|
203
|
+
//=============================================================================
|
204
|
+
// pkl_splitframe
|
205
|
+
//=============================================================================
|
206
|
+
PKLExport int pkl_splitframe(PKLImage pkl, int backcolor, int wbs, int hbs, int margin, int frame)
|
207
|
+
{
|
208
|
+
unsigned char *wrk, color[PKL_CHANNEL];
|
209
|
+
int i, j, k, s, t, u, tx, ty;
|
210
|
+
int offsetx, offsety, width, height, fw, fh;
|
211
|
+
int warea, harea;
|
212
|
+
int shift=5;
|
213
|
+
|
214
|
+
if(wbs<=0 || hbs<=0) return(1);
|
215
|
+
if(margin<0) return(1);
|
216
|
+
if(frame<1) return(1);
|
217
|
+
|
218
|
+
//1�̕����G���A�̃C���[�W�T�C�Y
|
219
|
+
warea = pkl->width / wbs;
|
220
|
+
harea = pkl->height / hbs;
|
221
|
+
//1�̃G���A�̃T�C�Y(�t���[���T�C�Y���܂�)
|
222
|
+
fw = warea + frame*2;
|
223
|
+
fh = harea + frame*2;
|
224
|
+
//�ŏI�I�ȃL�����o�X�̑傫��
|
225
|
+
width = fw * wbs + margin*2;
|
226
|
+
height = fh * hbs + margin*2;
|
227
|
+
|
228
|
+
wrk = malloc(width*height*pkl->channel);
|
229
|
+
if(!wrk) return(1);
|
230
|
+
|
231
|
+
//�w�i�F�̐ݒ�
|
232
|
+
for(i=0; i<pkl->channel; i++)
|
233
|
+
color[i] = (backcolor>>((pkl->channel-i)*8) & 0xFF);
|
234
|
+
for(i=0; i<width*height; i++)
|
235
|
+
memcpy(&wrk[i*pkl->channel], color, pkl->channel);
|
236
|
+
|
237
|
+
srand48(1);
|
238
|
+
for(i=margin,s=0; i<height-margin; i+=fh,s+=harea){
|
239
|
+
for(j=margin,t=0; j<width-margin; j+=fw,t+=warea){
|
240
|
+
offsetx = mrand48()%shift;
|
241
|
+
offsety = mrand48()%shift;
|
242
|
+
|
243
|
+
//�t�H�g�t���[��
|
244
|
+
k = i+offsety<0 ? 0 : i+offsety+fh>=height ? height-fh : i+offsety;
|
245
|
+
for(ty=k; ty<k+fh; ty++){
|
246
|
+
tx = j+offsetx<0 ? 0 : j+offsetx+fw>=width ? width-fw : j+offsetx;
|
247
|
+
//�w�i�F(��)
|
248
|
+
memset(&wrk[(ty*width+tx)*pkl->channel], 0xFF, fw*pkl->channel);
|
249
|
+
//�V�n�̃t���[��
|
250
|
+
if(ty==k || ty==k+fh-1)
|
251
|
+
memset(&wrk[(ty*width+tx)*pkl->channel], 0x00, fw*pkl->channel);
|
252
|
+
//���E�̃t���[��
|
253
|
+
memset(&wrk[(ty*width+tx)*pkl->channel], 0x00, pkl->channel);
|
254
|
+
memset(&wrk[(ty*width+tx+fw-1)*pkl->channel], 0x00, pkl->channel);
|
255
|
+
}
|
256
|
+
//�C���[�W
|
257
|
+
k = i+offsety<0 ? frame : i+offsety+fh>=height ? height-fh+frame : i+offsety+frame;
|
258
|
+
for(ty=k,u=s; ty<k+harea; ty++,u++){
|
259
|
+
tx = j+offsetx<0 ? frame : j+offsetx+fw>=width ? width-fw+frame : j+offsetx+frame;
|
260
|
+
memcpy(&wrk[(ty*width+tx)*pkl->channel], &pkl->image[(u*pkl->width+t)*pkl->channel], warea*pkl->channel);
|
261
|
+
}
|
262
|
+
}
|
263
|
+
}
|
264
|
+
|
265
|
+
free(pkl->image);
|
266
|
+
pkl->image = wrk;
|
267
|
+
pkl->width = width;
|
268
|
+
pkl->height = height;
|
269
|
+
return(0);
|
270
|
+
}
|
271
|
+
|
272
|
+
//=============================================================================
|
273
|
+
// pkl_colordither
|
274
|
+
//=============================================================================
|
275
|
+
PKLExport int pkl_colordither(PKLImage pkl, int weight)
|
276
|
+
{
|
277
|
+
double FloydSteinberg[2][3] = {
|
278
|
+
{ -1, -1, 7.0/16.0},
|
279
|
+
{ 3.0/16.0, 5.0/16.0, 1.0/16.0} };
|
280
|
+
unsigned char *wrk, pix, *graypic;
|
281
|
+
double *pt, err;
|
282
|
+
int i, j, k, gray, s, t, tx, ty, row, col, xrange;
|
283
|
+
|
284
|
+
row = 3;
|
285
|
+
col = 2;
|
286
|
+
pt = &(FloydSteinberg[0][0]);
|
287
|
+
|
288
|
+
wrk = malloc(pkl->width*pkl->height*pkl->channel);
|
289
|
+
if(!wrk) return(1);
|
290
|
+
memset(wrk, 0xff, pkl->width*pkl->height*pkl->channel);
|
291
|
+
|
292
|
+
graypic = malloc(pkl->width*pkl->height);
|
293
|
+
if(!wrk) return(1);
|
294
|
+
|
295
|
+
for(i=0; i<pkl->height; i++){
|
296
|
+
for(j=0; j<pkl->width; j++){
|
297
|
+
gray=0;
|
298
|
+
for(k=0; k<pkl->channel; k++)
|
299
|
+
gray += pkl->image[(i*pkl->width+j)*pkl->channel+k];
|
300
|
+
graypic[i*pkl->width+j] = PKL_COLOR_CLIP(gray/pkl->channel);
|
301
|
+
}
|
302
|
+
}
|
303
|
+
xrange = (row-1)/2;
|
304
|
+
|
305
|
+
for(i=0; i<pkl->height; i++){
|
306
|
+
for(j=0; j<pkl->width; j++){
|
307
|
+
pix = graypic[i*pkl->width+j];
|
308
|
+
if(pix<127){
|
309
|
+
memcpy(&wrk[(i*pkl->width+j)*pkl->channel], &pkl->image[(i*pkl->width+j)*pkl->channel], pkl->channel);
|
310
|
+
}else{
|
311
|
+
for(k=0; k<pkl->channel; k++)
|
312
|
+
wrk[(i*pkl->width+j)*pkl->channel+k] = PKL_COLOR_CLIP(pkl->image[(i*pkl->width+j)*pkl->channel+k]+weight);
|
313
|
+
}
|
314
|
+
err = pix>127 ? pix-255 : pix;
|
315
|
+
|
316
|
+
for(s=0; s<col; s++){
|
317
|
+
for(t=-xrange; t<=xrange; t++){
|
318
|
+
tx = j+t;
|
319
|
+
ty = i+s;
|
320
|
+
if(tx<0 || tx>=pkl->width || ty>=pkl->height) continue;
|
321
|
+
if (pt[s*row+t+xrange] < 0) continue;
|
322
|
+
graypic[ty*pkl->width+tx] = PKL_COLOR_CLIP(graypic[ty*pkl->width+tx] + err * pt[s*row+t+xrange]);
|
323
|
+
}
|
324
|
+
}
|
325
|
+
}
|
326
|
+
}
|
327
|
+
free(graypic);
|
328
|
+
free(pkl->image);
|
329
|
+
pkl->image = wrk;
|
330
|
+
return(0);
|
331
|
+
}
|
332
|
+
|
333
|
+
|
334
|
+
//=============================================================================
|
335
|
+
// pkl_ttt
|
336
|
+
//=============================================================================
|
337
|
+
PKLExport int pkl_ttt(PKLImage pkl)
|
338
|
+
{
|
339
|
+
unsigned char *wrk;
|
340
|
+
int i, j, s, t, k, clipx, clipy;
|
341
|
+
int color[PKL_CHANNEL];
|
342
|
+
|
343
|
+
int matrix[9] = { 0, 0, -1,
|
344
|
+
0, 0, 0,
|
345
|
+
1, 0, 0 };
|
346
|
+
|
347
|
+
// { PKL_EMBOSS_EMBOSS, { 0, 0, -1,
|
348
|
+
// 0, 0, 0,
|
349
|
+
// 1, 0, 0 }},
|
350
|
+
//
|
351
|
+
// { PKL_EMBOSS_LAPLACIAN, {-1, -1, -1,
|
352
|
+
// -1, 8, -1,
|
353
|
+
// -1, -1, -1 }},
|
354
|
+
//
|
355
|
+
// { PKL_EMBOSS_HEAVY, { 2, 0, 0,
|
356
|
+
// 0, -1, 0,
|
357
|
+
// 0, 0, -1 }},
|
358
|
+
//
|
359
|
+
// { PKL_EMBOSS_LIGHT, { 0, 0, 0,
|
360
|
+
// 0, 1, 0,
|
361
|
+
// 0, 0, -1 }},
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
wrk = malloc(pkl->width*pkl->height);
|
366
|
+
if(!wrk) return(1);
|
367
|
+
memset(wrk, 0, pkl->width*pkl->height);
|
368
|
+
|
369
|
+
for(i=0; i<pkl->height; i++){
|
370
|
+
for(j=0; j<pkl->width; j++){
|
371
|
+
memset(color, 0, sizeof(color));
|
372
|
+
for(s=0; s<3; s++){
|
373
|
+
for(t=0; t<3; t++){
|
374
|
+
clipx = (j+t)>=pkl->width ? pkl->width-1 : j+t;
|
375
|
+
clipy = (i+s)>=pkl->height ? pkl->height-1 : i+s;
|
376
|
+
//for(k=0; k<pkl->channel; k++)
|
377
|
+
color[0] += pkl->image[(clipy*pkl->width+clipx) * pkl->channel + 0] * matrix[t+s*3];
|
378
|
+
}
|
379
|
+
}
|
380
|
+
|
381
|
+
//for(k=0; k<pkl->channel; k++)
|
382
|
+
wrk[i*pkl->width+j] = PKL_COLOR_CLIP(color[0]-127);
|
383
|
+
}
|
384
|
+
}
|
385
|
+
|
386
|
+
for(i=0; i<pkl->height; i++){
|
387
|
+
for(j=0; j<pkl->width; j++){
|
388
|
+
for(k=0; k<pkl->channel; k++)
|
389
|
+
pkl->image[(i*pkl->width+j)*pkl->channel+k] =
|
390
|
+
PKL_COLOR_CLIP((pkl->image[(i*pkl->width+j)*pkl->channel+k] - wrk[i*pkl->width+j]));
|
391
|
+
}
|
392
|
+
}
|
393
|
+
|
394
|
+
|
395
|
+
free(wrk);
|
396
|
+
return(0);
|
397
|
+
}
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
////=============================================================================
|
402
|
+
//// pkl_sketch
|
403
|
+
////=============================================================================
|
404
|
+
//PKLExport int pkl_sketch(PKLImage pkl)
|
405
|
+
//{
|
406
|
+
// unsigned char *wrk, ave[PKL_CHANNEL];
|
407
|
+
// int color[PKL_CHANNEL];
|
408
|
+
// int i, j, k, s;
|
409
|
+
// int weight=10;
|
410
|
+
// int sx, sy, dx, dy, x1, x2, y1, y2, xadder;
|
411
|
+
// double t, adder;
|
412
|
+
//
|
413
|
+
// wrk = malloc(pkl->width*pkl->height*pkl->channel);
|
414
|
+
// if(!wrk) return(1);
|
415
|
+
// memset(wrk, 0xff, pkl->width*pkl->height*pkl->channel);
|
416
|
+
//
|
417
|
+
// srand48(1);
|
418
|
+
// for(i=0; i<pkl->height; i+=weight){
|
419
|
+
// for(j=0; j<pkl->width; j+=weight){
|
420
|
+
//
|
421
|
+
// for(k=0; k<weight*2; k++){
|
422
|
+
// //�����_���ȂQ�_��
|
423
|
+
// x1 = j + mrand48()%weight;
|
424
|
+
// y1 = i + mrand48()%weight;
|
425
|
+
// x2 = j + mrand48()%weight;
|
426
|
+
// y2 = i + mrand48()%weight;
|
427
|
+
//
|
428
|
+
// sx = x1;
|
429
|
+
// dx = x2;
|
430
|
+
// sy = y1<y2 ? y1 : y2;
|
431
|
+
// dy = y1<y2 ? y2 : y1;
|
432
|
+
//
|
433
|
+
// sx = sx<0 ? 0 : sx>=pkl->width ? pkl->width-1 : sx;
|
434
|
+
// dx = dx<0 ? 0 : dx>=pkl->width ? pkl->width-1 : dx;
|
435
|
+
// sy = sy<0 ? 0 : sy>=pkl->height ? pkl->height-1 : sy;
|
436
|
+
// dy = dy<0 ? 0 : dy>=pkl->height ? pkl->height-1 : dy;
|
437
|
+
//
|
438
|
+
// if(dx-sx != 0)
|
439
|
+
// adder = (double)(dy-sy)/(double)(dx-sx);
|
440
|
+
// else
|
441
|
+
// adder=1.0;
|
442
|
+
//
|
443
|
+
// if(sx<dx){
|
444
|
+
// for(s=sx,t=sy; s<dx; s++,t+=adder){
|
445
|
+
// if(t<pkl->height)
|
446
|
+
// memcpy(&wrk[((int)t*pkl->width+s)*pkl->channel], &pkl->image[((int)t*pkl->width+s)*pkl->channel], pkl->channel);
|
447
|
+
// }
|
448
|
+
// }else{
|
449
|
+
// for(s=sx,t=sy; s>=dx; s--,t-=adder){
|
450
|
+
// if(t>0.0)
|
451
|
+
// memcpy(&wrk[((int)t*pkl->width+s)*pkl->channel], &pkl->image[((int)t*pkl->width+s)*pkl->channel], pkl->channel);
|
452
|
+
// }
|
453
|
+
// }
|
454
|
+
// }
|
455
|
+
// }
|
456
|
+
// }
|
457
|
+
//
|
458
|
+
// free(pkl->image);
|
459
|
+
// pkl->image = wrk;
|
460
|
+
// return(0);
|
461
|
+
//}
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
// /** �X�g���[�N�̒��� */
|
470
|
+
// int LENGTH = 10; //1..50
|
471
|
+
// /** �u���V�̑傫�� */
|
472
|
+
// int BRUSHSIZE = 8; //1..50
|
473
|
+
// /** �Z�W����**/
|
474
|
+
// int Gray = 124; //50..200
|
475
|
+
// /** ���l */
|
476
|
+
// float ALPHA = .8f; //0.01 .. 1.0
|
477
|
+
//
|
478
|
+
// /** �C���[�W�̃\�[�X */
|
479
|
+
// protected AnimatedImage AI;
|
480
|
+
// protected int width;
|
481
|
+
// protected int height;
|
482
|
+
//
|
483
|
+
// /** (r, g, b)����P�x���Z�o���� */
|
484
|
+
// public int getLuminance(int r, int g, int b){
|
485
|
+
// return (int)(0.3f*r + 0.59f*g + 0.11f*b);
|
486
|
+
// }
|
487
|
+
//
|
488
|
+
// /** �摜�̃t�B���^�����O���s�� */
|
489
|
+
// public void filter(AnimatedImage AI){
|
490
|
+
// this.AI = AI;
|
491
|
+
// width = AI.getWidth();
|
492
|
+
// height = AI.getHeight();
|
493
|
+
//
|
494
|
+
// Random rand = new Random(System.currentTimeMillis());
|
495
|
+
//
|
496
|
+
// //�o�b�t�@�̏�����
|
497
|
+
// setUpBuffer();
|
498
|
+
//
|
499
|
+
// //�z���C�g�m�C�Y
|
500
|
+
// for (int y=0; y<height; y++) {
|
501
|
+
// for (int x=0; x<width; x++) {
|
502
|
+
// int r = AI.getR(x, y);
|
503
|
+
// int g = AI.getG(x, y);
|
504
|
+
// int b = AI.getB(x, y);
|
505
|
+
// int G=getLuminance(r,g,b);
|
506
|
+
// double T = 0.2*(1-G/40);
|
507
|
+
// double P = rand.nextInt()%1.0;
|
508
|
+
// if(P>=T)AI.setRGB(x, y, 255, 255, 255);
|
509
|
+
// else AI.setRGB(x, y, 0, 0, 0);
|
510
|
+
// }
|
511
|
+
// }
|
512
|
+
//
|
513
|
+
// //�����_���ɃX�g���[�N��z�u
|
514
|
+
// for (int i = 0; i < height; i++) {
|
515
|
+
// for(int j = 0; j < width/5; j++){
|
516
|
+
// int x = Math.abs(rand.nextInt()) % width;
|
517
|
+
// int y = i + Math.abs(rand.nextInt()) % (LENGTH+BRUSHSIZE);
|
518
|
+
// if ( y<0 || y>=height ) continue;
|
519
|
+
//
|
520
|
+
// int r = AI.getR(x, y);
|
521
|
+
// int g = AI.getG(x, y);
|
522
|
+
// int b = AI.getB(x, y);
|
523
|
+
//
|
524
|
+
// //�u���V�X�g���[�N��`��
|
525
|
+
// drawPenStroke(x, y, r, g, b);
|
526
|
+
// }
|
527
|
+
// }
|
528
|
+
// return;
|
529
|
+
// }
|
530
|
+
//
|
531
|
+
// //* �y���X�g���[�N���P�`�悷��
|
532
|
+
// protected void drawPenStroke(int x, int y, int r, int g, int b){
|
533
|
+
// // �摜�̋P�x�̌��z�������擾
|
534
|
+
// Point dir = getDirection(x, y);
|
535
|
+
// float vx, vy, l;
|
536
|
+
// vx = -dir.y/255.0f;
|
537
|
+
// vy = dir.x/255.0f;
|
538
|
+
// l = (float)Math.sqrt(vx*vx+vy*vy);
|
539
|
+
// vx /= l;
|
540
|
+
// vy /= l;
|
541
|
+
//
|
542
|
+
// //�`��̈���w�肷��
|
543
|
+
// int vxl = (int)(vx * LENGTH);
|
544
|
+
// int vyl = (int)(vy * LENGTH);
|
545
|
+
// int vxb = (int)(vx * BRUSHSIZE / 2);
|
546
|
+
// int vyb = (int)(vy * BRUSHSIZE / 2);
|
547
|
+
// int sx = x - vxl, sy = y - vyl ; //�n�_
|
548
|
+
// int ex = x + vxl, ey = y + vyl; //�I�_
|
549
|
+
//
|
550
|
+
// writeLine(sx - vyb, sy + vxb, ex - vyb, ey + vxb);
|
551
|
+
// //�`��̈���w��F�œh��Ԃ��B
|
552
|
+
// paintBuffer(r, g, b, ALPHA);
|
553
|
+
// }
|
554
|
+
//
|
555
|
+
// //* �P�x�̌��z�������擾����
|
556
|
+
// protected Point getDirection(int x, int y){
|
557
|
+
// int vx, vy;
|
558
|
+
// int[][] pixel = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
|
559
|
+
//
|
560
|
+
// for(int i = 0; i < pixel.length; i++){
|
561
|
+
// int yy = y + i - 1;
|
562
|
+
//
|
563
|
+
// if(yy < 0) continue;
|
564
|
+
// else if(yy >= height) break;
|
565
|
+
//
|
566
|
+
// for(int j = 0; j < pixel[i].length; j++){
|
567
|
+
// int xx = x + j - 1;
|
568
|
+
//
|
569
|
+
// if(xx < 0) continue;
|
570
|
+
// else if(xx >= width) break;
|
571
|
+
//
|
572
|
+
// int r = AI.getR(xx, yy);
|
573
|
+
// int g = AI.getG(xx, yy);
|
574
|
+
// int b = AI.getB(xx, yy);
|
575
|
+
//
|
576
|
+
// pixel[i][j] = getLuminance(r, g, b);
|
577
|
+
// }
|
578
|
+
// }
|
579
|
+
//
|
580
|
+
// vx = - pixel[0][0] + pixel[0][2] - 2 * pixel[1][0] + 2 * pixel[1][2] - pixel[2][0] + pixel[2][2];
|
581
|
+
// vy = - pixel[0][0] + pixel[2][0] - 2 * pixel[0][1] + 2 * pixel[2][1] - pixel[0][2] + pixel[2][2];
|
582
|
+
//
|
583
|
+
// return new Point(vx, vy);
|
584
|
+
// }
|
585
|
+
//
|
586
|
+
// //**************************************************************************
|
587
|
+
// // �ȍ~�A�O���t�B�b�N�X�֘A�̃����o���L�q����
|
588
|
+
// //**************************************************************************
|
589
|
+
//
|
590
|
+
// /* �`��̈�ׂ邽�߂̃o�b�t�@�B
|
591
|
+
// * �`��̈�͓ʂł���Ɖ��肵�Ă���B
|
592
|
+
// * ��{(x, y) | y �� {0, ... height - 1}, buf[y][0] <= x <= buf[y][1]}
|
593
|
+
// * �ŕ\�����̈悪�`��̈�ƂȂ�B
|
594
|
+
// */
|
595
|
+
// protected int[][] buf;
|
596
|
+
//
|
597
|
+
// /** �`��̈��y���W�̍ŏ��l */
|
598
|
+
// protected int yMin;
|
599
|
+
//
|
600
|
+
// /** �`��̈��y���W�̍ő�l */
|
601
|
+
// protected int yMax;
|
602
|
+
//
|
603
|
+
//
|
604
|
+
// /**
|
605
|
+
// * buf�̏��������s���B
|
606
|
+
// * �n�߂ɂP�x�����Ăяo�����ƁB
|
607
|
+
// */
|
608
|
+
// protected void setUpBuffer(){
|
609
|
+
// buf = new int[height][2];
|
610
|
+
// yMin = 0;
|
611
|
+
// yMax = height - 1;
|
612
|
+
// clearBuffer();
|
613
|
+
// }
|
614
|
+
//
|
615
|
+
// //* buf�̓��e���N���A����B
|
616
|
+
// protected void clearBuffer(){
|
617
|
+
// if(yMin < 0) yMin = 0;
|
618
|
+
// if(yMax >= height) yMax = height - 1;
|
619
|
+
//
|
620
|
+
// for(int i = yMin; i <= yMax; i++){
|
621
|
+
// buf[i][0] = width - 1; //�ŏ��l�̏����l�͍ő�l
|
622
|
+
// buf[i][1] = 0; //�ő�l�̏����l�͍ŏ��l
|
623
|
+
// }
|
624
|
+
// yMin = height - 1; //�ŏ��l�̏����l�͍ő�l
|
625
|
+
// yMax = 0; //�ő�l�̏����l�͍ŏ��l
|
626
|
+
// }
|
627
|
+
//
|
628
|
+
// // * buf�ŕ\�����`��̈��F(r, g, b, a)�œh��Ԃ��B
|
629
|
+
// protected void paintBuffer(int r, int g, int b, float a){
|
630
|
+
// if(yMin < 0) yMin = 0;
|
631
|
+
// if(yMax >= height) yMax = height - 1;
|
632
|
+
//
|
633
|
+
// for(int y = yMin; y <= yMax; y++){
|
634
|
+
// if(buf[y][0] < 0) buf[y][0] = 0;
|
635
|
+
// if(buf[y][1] >= width) buf[y][1] = width - 1;
|
636
|
+
//
|
637
|
+
// for(int x = buf[y][0]; x <= buf[y][1]; x++){
|
638
|
+
// int G=(int)(0.299*r+0.587*g+0.114*b);
|
639
|
+
// if(G>=3*Gray/2)
|
640
|
+
// AI.setRGBA(x, y,255, 255, 255, a);
|
641
|
+
// else if(G>=Gray&&G<3*Gray/2)
|
642
|
+
// AI.setRGBA(x, y,170, 170, 170, a);
|
643
|
+
// else if(G<Gray&&G>Gray/2)
|
644
|
+
// AI.setRGBA(x, y,80, 80, 80, a);
|
645
|
+
// else
|
646
|
+
// AI.setRGBA(x, y,0, 0, 0, a);
|
647
|
+
// }
|
648
|
+
// }
|
649
|
+
// clearBuffer();
|
650
|
+
// }
|
651
|
+
//
|
652
|
+
//// * �_�f�[�^��buf�ɏ������ށB
|
653
|
+
//// * yMin, yMax�͍X�V����Ȃ����Ƃɒ��ӁB
|
654
|
+
// protected void writePoint(int x, int y){
|
655
|
+
// if(y < 0 || y >= height) return;
|
656
|
+
// if(x < buf[y][0]) buf[y][0] = x;
|
657
|
+
// if(x > buf[y][1]) buf[y][1] = x;
|
658
|
+
// }
|
659
|
+
//
|
660
|
+
//
|
661
|
+
// /**
|
662
|
+
// * �����f�[�^��buf�ɏ������ށB
|
663
|
+
// * �u���[���n���̃A���S���Y����p���Ă���B
|
664
|
+
// */
|
665
|
+
// protected void writeLine(int x1, int y1, int x2, int y2){
|
666
|
+
// //yMin, yMax�̍X�V
|
667
|
+
// if(y1 < yMin) yMin = y1;
|
668
|
+
// if(y1 > yMax) yMax = y1;
|
669
|
+
// if(y2 < yMin) yMin = y2;
|
670
|
+
// if(y2 > yMax) yMax = y2;
|
671
|
+
//
|
672
|
+
// //dx, dy: X, Y�������̋���
|
673
|
+
// int dx = x2 - x1, dy = y2 - y1;
|
674
|
+
// int sx, sy; //dx, dy�̕�������
|
675
|
+
//
|
676
|
+
// if(dx >= 0)
|
677
|
+
// sx = 1;
|
678
|
+
// else{
|
679
|
+
// sx = -1; dx = -dx;
|
680
|
+
// }
|
681
|
+
// if(dy >= 0)
|
682
|
+
// sy = 1;
|
683
|
+
// else{
|
684
|
+
// sy = -1; dy = -dy;
|
685
|
+
// }
|
686
|
+
//
|
687
|
+
// int x = x1, y = y1;
|
688
|
+
// int d, tmp;
|
689
|
+
//
|
690
|
+
// if(dx >= dy){
|
691
|
+
// dy += dy; //dy *= 2
|
692
|
+
// d = dy - dx;
|
693
|
+
// tmp = dy - 2 * dx;
|
694
|
+
//
|
695
|
+
// //(x, y)��check
|
696
|
+
// writePoint(x, y);
|
697
|
+
//
|
698
|
+
// for(int i = 0; i < dx; i++){
|
699
|
+
// if(d > 0){
|
700
|
+
// y += sy; d += tmp;
|
701
|
+
// }else
|
702
|
+
// d += dy;
|
703
|
+
//
|
704
|
+
// x += sx;
|
705
|
+
//
|
706
|
+
// //(x, y)��check
|
707
|
+
// writePoint(x, y);
|
708
|
+
// }
|
709
|
+
// }else{
|
710
|
+
// dx += dx; //dx *= 2
|
711
|
+
// d = dx - dy;
|
712
|
+
// tmp = dx - 2 * dy;
|
713
|
+
//
|
714
|
+
// //(x, y)��check
|
715
|
+
// writePoint(x, y);
|
716
|
+
//
|
717
|
+
// for(int i = 0; i < dy; i++){
|
718
|
+
// if(d > 0){
|
719
|
+
// x += sx; d += tmp;
|
720
|
+
// }else
|
721
|
+
// d += dx;
|
722
|
+
//
|
723
|
+
// y += sy;
|
724
|
+
//
|
725
|
+
// //(x, y)��check
|
726
|
+
// writePoint(x, y);
|
727
|
+
// }
|
728
|
+
// }
|
729
|
+
// }
|
730
|
+
//
|
731
|
+
//}
|