pikl 0.2.8 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/History.txt +9 -0
  2. data/License.txt +0 -0
  3. data/Manifest.txt +17 -17
  4. data/README.txt +0 -0
  5. data/config/hoe.rb +9 -6
  6. data/config/requirements.rb +0 -0
  7. data/ext/pikl/extconf.rb +0 -0
  8. data/ext/pikl/pikl.h +617 -465
  9. data/ext/pikl/pikl_affine.c +38 -91
  10. data/ext/pikl/pikl_affine.h +0 -0
  11. data/ext/pikl/pikl_bitmap.c +0 -0
  12. data/ext/pikl/pikl_bitmap.h +0 -0
  13. data/ext/pikl/pikl_blur.c +4 -8
  14. data/ext/pikl/pikl_blur.h +0 -0
  15. data/ext/pikl/pikl_camera.c +218 -0
  16. data/ext/pikl/{pikl_effect3.h → pikl_camera.h} +2 -2
  17. data/ext/pikl/pikl_composite.c +175 -0
  18. data/ext/pikl/pikl_composite.h +12 -0
  19. data/ext/pikl/pikl_decrease.c +110 -45
  20. data/ext/pikl/pikl_decrease.h +0 -7
  21. data/ext/pikl/pikl_divide.c +116 -0
  22. data/ext/pikl/pikl_divide.h +11 -0
  23. data/ext/pikl/pikl_effect.c +583 -151
  24. data/ext/pikl/pikl_effect.h +32 -6
  25. data/ext/pikl/pikl_enhance.c +274 -0
  26. data/ext/pikl/pikl_enhance.h +20 -0
  27. data/ext/pikl/pikl_io.c +174 -23
  28. data/ext/pikl/pikl_io.h +0 -0
  29. data/ext/pikl/pikl_jpeg.c +0 -0
  30. data/ext/pikl/pikl_jpeg.h +0 -0
  31. data/ext/pikl/pikl_pattern.c +383 -357
  32. data/ext/pikl/pikl_pattern.h +0 -0
  33. data/ext/pikl/pikl_pixel.c +173 -0
  34. data/ext/pikl/{pikl_trim.h → pikl_pixel.h} +2 -2
  35. data/ext/pikl/pikl_png.c +0 -0
  36. data/ext/pikl/pikl_png.h +0 -0
  37. data/ext/pikl/pikl_private.h +12 -5
  38. data/ext/pikl/pikl_resize.c +0 -0
  39. data/ext/pikl/pikl_resize.h +0 -0
  40. data/ext/pikl/pikl_rotate.c +409 -51
  41. data/ext/pikl/pikl_rotate.h +8 -0
  42. data/ext/pikl/pikl_scrap.c +263 -483
  43. data/ext/pikl/pikl_scrap.h +0 -0
  44. data/ext/pikl/pikl_special.c +168 -0
  45. data/ext/pikl/{pikl_effect4.h → pikl_special.h} +2 -2
  46. data/ext/pikl/pikl_voronoi.c +320 -0
  47. data/ext/pikl/pikl_voronoi.h +37 -0
  48. data/lib/pikl.rb +4 -2
  49. data/lib/pikl/color.rb +47 -0
  50. data/lib/pikl/const.rb +106 -22
  51. data/lib/pikl/errors.rb +0 -0
  52. data/lib/pikl/ext.rb +115 -8
  53. data/lib/pikl/filter.rb +371 -0
  54. data/lib/pikl/image.rb +124 -117
  55. data/lib/pikl/version.rb +2 -2
  56. data/setup.rb +0 -0
  57. data/test/sample.jpg +0 -0
  58. data/test/test_helper.rb +0 -0
  59. data/test/test_pikl_image.rb +0 -14
  60. data/test/test_pikl_image2.rb +541 -0
  61. metadata +35 -23
  62. data/ext/pikl/decrease/fsdither.h +0 -554
  63. data/ext/pikl/decrease/median.c +0 -1179
  64. data/ext/pikl/decrease/median.h +0 -7
  65. data/ext/pikl/decrease/neuquan5.c +0 -563
  66. data/ext/pikl/decrease/neuquant.h +0 -62
  67. data/ext/pikl/decrease/wu.c +0 -447
  68. data/ext/pikl/decrease/wu.h +0 -7
  69. data/ext/pikl/pikl_effect2.c +0 -240
  70. data/ext/pikl/pikl_effect2.h +0 -55
  71. data/ext/pikl/pikl_effect3.c +0 -266
  72. data/ext/pikl/pikl_effect4.c +0 -495
  73. data/ext/pikl/pikl_rotate2.c +0 -312
  74. data/ext/pikl/pikl_rotate2.h +0 -19
  75. data/ext/pikl/pikl_trim.c +0 -28
@@ -1,7 +0,0 @@
1
- #ifndef _EXTRA_WU_
2
- #define _EXTRA_WU_
3
-
4
- int wuReduce(unsigned char *RGBpic, int numcolors, long picsize,
5
- unsigned char *Picture256, unsigned char *QuantizedPalette);
6
-
7
- #endif
@@ -1,240 +0,0 @@
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
- }
@@ -1,55 +0,0 @@
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
@@ -1,266 +0,0 @@
1
- #include "pikl_effect3.h"
2
-
3
- static unsigned char lighting(unsigned char color, double dx, double dy, double dz,
4
- double mil, double env, double *light);
5
-
6
- //=============================================================================
7
- // pkl_illust
8
- //=============================================================================
9
- PKLExport int pkl_illust(PKLImage pkl, int edge, int gammaint)
10
- {
11
- int GAP=10;
12
- int sobel1[9] = { 1, 0, -1, 2, 0, -2, 1, 0, -1 }; //sobel filter
13
- int sobel2[9] = { 1, 2, 1, 0, 0, 0, -1, -2, -1 }; //sobel filter
14
- int i, j, k, s, t, px, py, rp, r1, r2, rc, gt;
15
- int wx[PKL_CHANNEL], wy[PKL_CHANNEL], rate[PKL_CHANNEL];
16
- unsigned char *wrk;
17
- double gamma;
18
- int th1, th2, th3;
19
-
20
- wrk = malloc(pkl->width*pkl->height*pkl->channel);
21
- if(!wrk) return(1);
22
- memset(wrk, 0, pkl->width*pkl->height*pkl->channel);
23
-
24
- gamma = 1.0/((double)gammaint/100.0);
25
- th1 = (int)(pow(128.0/255.0, gamma)*255.0);
26
- th2 = (int)(pow( 96.0/255.0, gamma)*255.0);
27
- th3 = (int)(pow( 64.0/255.0, gamma)*255.0);
28
-
29
- for(i=0; i<pkl->height; i++){
30
- for(j=0; j<pkl->width; j++){
31
-
32
- memset(wx, 0, sizeof(wx));
33
- memset(wy, 0, sizeof(wy));
34
-
35
- for(s=0; s<3; s++){
36
- for(t=0; t<3; t++){
37
- px = (j+t-1)<0 ? 0 : (j+t-1)>pkl->width ? pkl->width-1 : (j+t-1);
38
- py = (i+s-1)<0 ? 0 : (i+s-1)>pkl->height ? pkl->height-1 : (i+s-1);
39
- for(k=0; k<pkl->channel; k++){
40
- wx[k] += pkl->image[(py*pkl->width+px)*pkl->channel+k] * sobel1[s*3+t];
41
- wy[k] += pkl->image[(py*pkl->width+px)*pkl->channel+k] * sobel2[s*3+t];
42
- }
43
- }
44
- }
45
-
46
- for(k=0; k<pkl->channel; k++)
47
- rate[k] = (int)(sqrt((double)(wx[k]*wx[k]+wy[k]*wy[k]))/8.0);
48
- rp = 0;
49
- for(k=0; k<pkl->channel; k++)
50
- if(rate[k]>rp) rp=rate[k];
51
- r1 = (rp<edge) ? 255 : (rp<edge+GAP) ? 255-255*(rp-edge)/GAP : 0;
52
-
53
- gt = 0;
54
- for(k=0; k<pkl->channel; k++)
55
- gt += pkl->image[(i*pkl->width+j)*pkl->channel+k];
56
- gt /= pkl->channel;
57
- r2 = (gt>th1) ? 255 : (gt>th2) ? 128 : (gt>th3) ? 64 : 0;
58
-
59
- rc = PKL_COLOR_CLIP(r1*r2/256);
60
- for(k=0; k<pkl->channel; k++)
61
- wrk[(i*pkl->width+j)*pkl->channel+k] = rc;
62
- }
63
- }
64
-
65
- free(pkl->image);
66
- pkl->image = wrk;
67
- return(0);
68
- }
69
-
70
- //=============================================================================
71
- // pkl_color_emboss
72
- //=============================================================================
73
- PKLExport int pkl_color_emboss(PKLImage pkl, double mil, double env)
74
- {
75
- int sobel1[9] = { 1, 0, -1, 2, 0, -2, 1, 0, -1 }; //sobel filter
76
- int sobel2[9] = { 1, 2, 1, 0, 0, 0, -1, -2, -1 }; //sobel filter
77
- int i, j, k, s, t, wx, wy, gt, px, py;
78
- unsigned char *wrk, color[PKL_CHANNEL];
79
- double dx, dy, dz, light[3], abl;
80
-
81
- wrk = malloc(pkl->width*pkl->height*pkl->channel);
82
- if(!wrk) return(1);
83
- memset(wrk, 0, pkl->width*pkl->height*pkl->channel);
84
-
85
- //�����x�N�g����P�ʃx�N�g���ɕ␳����
86
- abl = sqrt(-1.0*-1.0 + -1.0*-1.0 + 1.0*1.0);
87
- light[0] = -1.0/abl;
88
- light[1] = -1.0/abl;
89
- light[2] = 1.0/abl;
90
-
91
- for(i=0; i<pkl->height; i++){
92
- for(j=0; j<pkl->width; j++){
93
- wx=wy=0;
94
- for(s=0; s<3; s++){
95
- for(t=0; t<3; t++){
96
- px = (j+t-1)<0 ? 0 : (j+t-1)>pkl->width ? pkl->width-1 : (j+t-1);
97
- py = (i+s-1)<0 ? 0 : (i+s-1)>pkl->height ? pkl->height-1 : (i+s-1);
98
-
99
- gt=0;
100
- for(k=0; k<pkl->channel; k++)
101
- gt += pkl->image[(py*pkl->width+px)*pkl->channel+k];
102
- gt /= pkl->channel;
103
- wx += gt*sobel1[s*3+t];
104
- wy += gt*sobel2[s*3+t];
105
- }
106
- }
107
- dx = (double)wx;
108
- dy = (double)wy;
109
- dz = 16.0;
110
- for(k=0; k<pkl->channel; k++)
111
- color[k] = lighting(pkl->image[(py*pkl->width+px)*pkl->channel+k], dx, dy, dz, mil, env, light);
112
- memcpy(&wrk[(i*pkl->width+j)*pkl->channel], color, pkl->channel);
113
- }
114
- }
115
-
116
- free(pkl->image);
117
- pkl->image = wrk;
118
- return(0);
119
- }
120
-
121
- //=============================================================================
122
- // �A�e�t��
123
- // (dx,dy,dz)��@���x�N�g���Ƃ���i�P�ʃx�N�g���łȂ��Ă��悢�j
124
- //=============================================================================
125
- static unsigned char lighting(unsigned char color, double dx, double dy, double dz,
126
- double mil, double env, double *light)
127
- {
128
- double abl, rz, env2, cosT, cosT2;
129
- int res;
130
-
131
- //�@���x�N�g����P�ʃx�N�g���ɕ␳
132
- abl = sqrt(dx*dx + dy*dy + dz*dz);
133
- cosT = (dx/abl)*light[0] + (dy/abl)*light[1] + (dz/abl)*light[2];
134
- rz = 2.0*cosT*(dz/abl) - light[2];
135
- cosT2 = (rz>0.0) ? pow(rz, 12.0) : 0.0;
136
- cosT = (cosT<0.0) ? 0.0 : cosT;
137
-
138
- env2=env*255.0/100.0;
139
- res=(int)((cosT*255.0+env2)*(double)color/255.0);
140
-
141
- if(res>color) res=color;
142
- res+=(mil*cosT2);
143
-
144
- return(PKL_COLOR_CLIP(res));
145
- }
146
-
147
- //=============================================================================
148
- // pkl_mosaic
149
- //=============================================================================
150
- PKLExport int pkl_mosaic(PKLImage pkl, int msx, int msy)
151
- {
152
- unsigned char *wrk;
153
- int mpx, mpy; //���U�C�N�̑傫��
154
- int mlx, mly; //�摜�̕�����
155
- int i, j, k, sx, sy, ex, ey, px, py, mm;
156
- long color[PKL_CHANNEL];
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
- mpx = (msx<1) ? 1 : (msx>=pkl->width) ? pkl->width-1 : msx;
163
- mpy = (msy<1) ? 1 : (msy>=pkl->height) ? pkl->height-1 : msy;
164
- mlx = (pkl->width+mpx-1)/mpx;
165
- mly = (pkl->height+mpy-1)/mpy;
166
-
167
- for(i=0; i<=mly; i++){
168
- for(j=0; j<=mlx; j++){
169
- sx = j*mpx;
170
- sy = i*mpy;
171
- ex = sx+mpx>=pkl->width ? pkl->width : sx+mpx;
172
- ey = sy+mpy>=pkl->height ? pkl->height : sy+mpy;
173
-
174
- //1�Z���̑��a�Z�o
175
- mm=0;
176
- memset(color, 0, sizeof(color));
177
- for(py=sy; py<ey; py++){
178
- for(px=sx; px<ex; px++){
179
- mm++;
180
- for(k=0; k<pkl->channel; k++)
181
- color[k] += pkl->image[(py*pkl->width+px)*pkl->channel+k];
182
- }
183
- }
184
- if(!mm) continue;
185
-
186
- //�Z���̕��ϐF���Z�o���āA�Z�����̃s�N�Z���ɓK�p
187
- for(k=0; k<pkl->channel; k++)
188
- color[k] = PKL_COLOR_CLIP(color[k]/mm);
189
- for(py=sy; py<ey; py++){
190
- for(px=sx; px<ex; px++){
191
- for(k=0; k<pkl->channel; k++)
192
- wrk[(py*pkl->width+px)*pkl->channel+k] = color[k];
193
- }
194
- }
195
- }
196
- }
197
-
198
- free(pkl->image);
199
- pkl->image = wrk;
200
- return(0);
201
- }
202
-
203
- //=============================================================================
204
- // pkl_noise
205
- //=============================================================================
206
- PKLExport int pkl_noise(PKLImage pkl, int noise)
207
- {
208
- unsigned char *wrk;
209
- int i, j, k, sx, sy, nw, nh;
210
-
211
- wrk = malloc(pkl->width*pkl->height*pkl->channel);
212
- if(!wrk) return(1);
213
- memset(wrk, 0, pkl->width*pkl->height*pkl->channel);
214
-
215
- srand48(1);
216
- for(i=0; i<pkl->height; i++){
217
- for(j=0; j<pkl->width; j++){
218
- //nw = rand()%(noise*2+1)-noise;
219
- nw = lrand48()%(noise*2+1)-noise;
220
- nh = lrand48()%(noise*2+1)-noise;
221
- sx = j+nw<0 ? 0 : j+nw>=pkl->width ? pkl->width-1 : j+nw;
222
- sy = i+nh<0 ? 0 : i+nh>=pkl->height ? pkl->height-1 : i+nh;
223
- for(k=0; k<pkl->channel; k++)
224
- wrk[(i*pkl->width+j)*pkl->channel+k] = pkl->image[(sy*pkl->width+sx)*pkl->channel+k];
225
- }
226
- }
227
-
228
- free(pkl->image);
229
- pkl->image = wrk;
230
- return(0);
231
- }
232
-
233
- //=============================================================================
234
- // pkl_vtr
235
- //=============================================================================
236
- PKLExport int pkl_vtr(PKLImage pkl, int colspace, int gst, int cst)
237
- {
238
- unsigned char *wrk;
239
- int i, j, k, t;
240
- int h=0, l_det=0;
241
-
242
- wrk = malloc(pkl->width*pkl->height*pkl->channel);
243
- if(!wrk) return(1);
244
- memset(wrk, 0, pkl->width*pkl->height*pkl->channel);
245
-
246
- for(i=0; i<pkl->height; i++){
247
- if(l_det >= colspace){
248
- h = !h;
249
- l_det=0;
250
- }
251
- l_det++;
252
-
253
- for(j=0; j<pkl->width; j++){
254
- t = j+gst<0 ? 0 : j+gst>=pkl->width ? pkl->width-1 : j+gst;
255
- for(k=0; k<pkl->channel; k++)
256
- wrk[(i*pkl->width+j)*pkl->channel+k] =
257
- PKL_COLOR_CLIP((pkl->image[(i*pkl->width+j)*pkl->channel+k] +
258
- pkl->image[(i*pkl->width+t)*pkl->channel+k])/2 + (cst-127)*h);
259
- }
260
- }
261
-
262
- free(pkl->image);
263
- pkl->image = wrk;
264
- return(0);
265
- }
266
-