ruby-miyako 2.1.4 → 2.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README +42 -5
- data/lib/Miyako/API/choices.rb +0 -2
- data/lib/Miyako/API/collision.rb +0 -4
- data/lib/Miyako/API/fixedmap.rb +0 -3
- data/lib/Miyako/API/i_yuki.rb +28 -46
- data/lib/Miyako/API/layout.rb +0 -1
- data/lib/Miyako/API/map.rb +0 -2
- data/lib/Miyako/API/map_event.rb +0 -3
- data/lib/Miyako/API/map_struct.rb +0 -2
- data/lib/Miyako/API/parts.rb +0 -11
- data/lib/Miyako/API/screen.rb +3 -4
- data/lib/Miyako/API/shape.rb +27 -27
- data/lib/Miyako/API/sprite.rb +0 -2
- data/lib/Miyako/API/story.rb +0 -2
- data/lib/Miyako/API/textbox.rb +9 -11
- data/lib/Miyako/API/utility.rb +2 -2
- data/lib/Miyako/API/yuki.rb +19 -8
- data/lib/Miyako/miyako.rb +3 -0
- data/miyako_basicdata.c +52 -5
- data/miyako_bitmap.c +351 -342
- data/miyako_collision.c +77 -67
- data/miyako_diagram.c +22 -21
- data/miyako_drawing.c +9 -6
- data/miyako_font.c +63 -53
- data/miyako_hsv.c +428 -436
- data/miyako_input_audio.c +17 -14
- data/miyako_layout.c +23 -18
- data/miyako_no_katana.c +284 -248
- data/miyako_sprite2.c +30 -18
- data/miyako_transform.c +95 -93
- data/miyako_utility.c +9 -18
- data/miyako_yuki.c +10 -6
- data/sample/Diagram_sample/diagram_sample_yuki2.rb +2 -2
- data/sample/Room3/room3.rb +8 -10
- data/sample/ball_action_sample.rb +8 -8
- data/sample/map_test/main_scene.rb +1 -1
- data/sample/map_test/map_test.rb +8 -8
- data/sample/takahashi.rb +14 -14
- data/win/miyako_no_katana.so +0 -0
- metadata +6 -4
data/miyako_hsv.c
CHANGED
@@ -20,8 +20,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
20
20
|
*/
|
21
21
|
|
22
22
|
/*
|
23
|
-
|
24
|
-
Authors::
|
23
|
+
=miyako_no_katana
|
24
|
+
Authors:: Cyross Makoto
|
25
25
|
Version:: 2.0
|
26
26
|
Copyright:: 2007-2008 Cyross Makoto
|
27
27
|
License:: LGPL2.1
|
@@ -45,10 +45,10 @@ static volatile int one = Qnil;
|
|
45
45
|
|
46
46
|
// from rubysdl_video.c
|
47
47
|
static GLOBAL_DEFINE_GET_STRUCT(Surface, GetSurface, cSurface, "SDL::Surface");
|
48
|
-
|
48
|
+
|
49
49
|
#define MIYAKO_RGB2HSV(RGBSTRUCT, HSVH, HSVS, HSVV) \
|
50
|
-
|
51
|
-
|
50
|
+
imax = RGBSTRUCT.r; \
|
51
|
+
imin = imax; \
|
52
52
|
imax = imax < RGBSTRUCT.g ? RGBSTRUCT.g : imax; \
|
53
53
|
imax = imax < RGBSTRUCT.b ? RGBSTRUCT.b : imax; \
|
54
54
|
imin = imin > RGBSTRUCT.g ? RGBSTRUCT.g : imin; \
|
@@ -57,7 +57,7 @@ static GLOBAL_DEFINE_GET_STRUCT(Surface, GetSurface, cSurface, "SDL::Surface");
|
|
57
57
|
else \
|
58
58
|
{ \
|
59
59
|
HSVV = div255[imax]; \
|
60
|
-
|
60
|
+
delta = HSVV - div255[imin]; \
|
61
61
|
HSVS = delta / HSVV; \
|
62
62
|
if(HSVS == 0.0){ HSVH = 0.0; } \
|
63
63
|
else \
|
@@ -75,7 +75,7 @@ static GLOBAL_DEFINE_GET_STRUCT(Surface, GetSurface, cSurface, "SDL::Surface");
|
|
75
75
|
if(HSVS == 0.0){ RGBSTRUCT.r = RGBSTRUCT.g = RGBSTRUCT.b = (Uint32)(HSVV * 255.0); } \
|
76
76
|
else \
|
77
77
|
{ \
|
78
|
-
|
78
|
+
tmp_i = HSVH / 60.0; \
|
79
79
|
if( tmp_i < 1.0){ i = 0.0; } \
|
80
80
|
else if(tmp_i < 2.0){ i = 1.0; } \
|
81
81
|
else if(tmp_i < 3.0){ i = 2.0; } \
|
@@ -96,124 +96,121 @@ static GLOBAL_DEFINE_GET_STRUCT(Surface, GetSurface, cSurface, "SDL::Surface");
|
|
96
96
|
RGBSTRUCT.g = (Uint32)(g * 255.0); \
|
97
97
|
RGBSTRUCT.b = (Uint32)(b * 255.0); \
|
98
98
|
}
|
99
|
-
|
99
|
+
|
100
100
|
static volatile double div255[256];
|
101
101
|
|
102
|
-
/*
|
103
|
-
画像の色相を変更する
|
104
|
-
*/
|
105
102
|
static VALUE bitmap_miyako_hue(VALUE self, VALUE vsrc, VALUE vdst, VALUE degree)
|
106
103
|
{
|
107
104
|
MiyakoBitmap src, dst;
|
108
105
|
MiyakoSize size;
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
if(_miyako_init_rect(&src, &dst, &size) == 0) return Qnil;
|
114
|
-
|
115
|
-
int x, y;
|
106
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
107
|
+
int x, y, a1, a2;
|
108
|
+
Uint32 imax, imin;
|
116
109
|
|
110
|
+
double delta, tmp_i;
|
117
111
|
double deg = NUM2DBL(degree);
|
118
112
|
double d_pi = 360.0;
|
119
113
|
double ph = 0.0, ps = 0.0, pv = 0.0;
|
120
114
|
double r = 0.0, g = 0.0, b = 0.0;
|
121
115
|
double i = 0.0, f, m, n, k;
|
122
116
|
|
117
|
+
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
118
|
+
|
119
|
+
if(_miyako_init_rect(&src, &dst, &size) == 0) return Qnil;
|
120
|
+
|
123
121
|
if(deg <= -360.0 || deg >= 360.0){ return Qnil; }
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
122
|
+
|
123
|
+
SDL_LockSurface(src.surface);
|
124
|
+
SDL_LockSurface(dst.surface);
|
125
|
+
|
126
|
+
for(y = 0; y < size.h; y++)
|
127
|
+
{
|
128
|
+
Uint32 *psrc = src.ptr + (src.rect.y + y) * src.rect.w + src.rect.x;
|
129
|
+
Uint32 *pdst = dst.ptr + (dst.rect.y + src.y + y) * dst.rect.w + dst.rect.x + src.x;
|
130
|
+
for(x = 0; x < size.w; x++)
|
131
|
+
{
|
134
132
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
135
133
|
src.color.r = (*psrc >> 16) & 0xff;
|
136
134
|
src.color.g = (*psrc >> 8) & 0xff;
|
137
135
|
src.color.b = (*psrc ) & 0xff;
|
138
136
|
src.color.a = (*psrc >> 24) & 0xff | src.a255;
|
139
|
-
|
137
|
+
if(src.color.a == 0){ psrc++; pdst++; continue; }
|
140
138
|
dst.color.r = (*pdst >> 16) & 0xff;
|
141
139
|
dst.color.g = (*pdst >> 8) & 0xff;
|
142
140
|
dst.color.b = (*pdst ) & 0xff;
|
143
141
|
dst.color.a = (*pdst >> 24) & 0xff | dst.a255;
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
142
|
+
MIYAKO_RGB2HSV(src.color, ph, ps, pv);
|
143
|
+
ph += deg;
|
144
|
+
if(ph < 0.0){ ph += d_pi; }
|
145
|
+
if(ph >= d_pi){ ph -= d_pi; }
|
146
|
+
MIYAKO_HSV2RGB(ph, ps, pv, src.color);
|
147
|
+
if(dst.color.a == 0 || src.color.a == 255){
|
148
|
+
*pdst = (src.color.r) << 16 |
|
149
|
+
(src.color.g) << 8 |
|
150
|
+
(src.color.b) |
|
151
|
+
(src.color.a) << 24;
|
152
|
+
psrc++;
|
153
|
+
pdst++;
|
154
|
+
continue;
|
155
|
+
}
|
156
|
+
a1 = src.color.a + 1;
|
157
|
+
a2 = 256 - src.color.a;
|
158
|
+
*pdst = ((src.color.r * a1 + dst.color.r * a2) >> 8) << 16 |
|
159
|
+
((src.color.g * a1 + dst.color.g * a2) >> 8) << 8 |
|
160
|
+
((src.color.b * a1 + dst.color.b * a2) >> 8) |
|
161
|
+
0xff << 24;
|
164
162
|
#else
|
165
163
|
src.color.r = (*psrc & src.fmt->Rmask) >> src.fmt->Rshift;
|
166
164
|
src.color.g = (*psrc & src.fmt->Gmask) >> src.fmt->Gshift;
|
167
165
|
src.color.b = (*psrc & src.fmt->Bmask) >> src.fmt->Bshift;
|
168
166
|
src.color.a = (*psrc & src.fmt->Amask) | src.a255;
|
169
|
-
|
167
|
+
if(src.color.a == 0){ psrc++; pdst++; continue; }
|
170
168
|
dst.color.r = (*pdst & dst.fmt->Rmask) >> dst.fmt->Rshift);
|
171
169
|
dst.color.g = (*pdst & dst.fmt->Gmask) >> dst.fmt->Gshift);
|
172
170
|
dst.color.b = (*pdst & dst.fmt->Bmask) >> dst.fmt->Bshift);
|
173
171
|
dst.color.a = (*pdst & dst.fmt->Amask) | dst.a255;
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
172
|
+
MIYAKO_RGB2HSV(src.color, ph, ps, pv);
|
173
|
+
ph += deg;
|
174
|
+
if(ph < 0.0){ ph += d_pi; }
|
175
|
+
if(ph >= d_pi){ ph -= d_pi; }
|
176
|
+
MIYAKO_HSV2RGB(ph, ps, pv, src.color);
|
177
|
+
if(dst.color.a == 0 || src.color.a == 255){
|
178
|
+
*pdst = src.color.r << dst.fmt->Rshift |
|
179
|
+
src.color.g << dst.fmt->Gshift |
|
180
|
+
src.color.b << dst.fmt->Bshift |
|
181
|
+
src.color.a;
|
182
|
+
psrc++;
|
183
|
+
pdst++;
|
184
|
+
continue;
|
185
|
+
}
|
186
|
+
a1 = src.color.a + 1;
|
187
|
+
a2 = 256 - src.color.a;
|
188
|
+
*pdst = ((src.color.r * a1 + dst.color.r * a2) >> 8) << dst.fmt->Rshift |
|
189
|
+
((src.color.g * a1 + dst.color.g * a2) >> 8) << dst.fmt->Gshift |
|
190
|
+
((src.color.b * a1 + dst.color.b * a2) >> 8) << dst.fmt->Bshift |
|
191
|
+
0xff;
|
194
192
|
#endif
|
195
193
|
psrc++;
|
196
|
-
|
197
|
-
|
198
|
-
|
194
|
+
pdst++;
|
195
|
+
}
|
196
|
+
}
|
199
197
|
|
200
|
-
|
201
|
-
|
198
|
+
SDL_UnlockSurface(src.surface);
|
199
|
+
SDL_UnlockSurface(dst.surface);
|
202
200
|
|
203
201
|
return vdst;
|
204
202
|
}
|
205
203
|
|
206
|
-
/*
|
207
|
-
画像の彩度を変更する
|
208
|
-
*/
|
209
204
|
static VALUE bitmap_miyako_saturation(VALUE self, VALUE vsrc, VALUE vdst, VALUE saturation)
|
210
205
|
{
|
211
206
|
MiyakoBitmap src, dst;
|
212
207
|
MiyakoSize size;
|
213
|
-
|
208
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
209
|
+
Uint32 imax, imin;
|
214
210
|
|
215
|
-
|
211
|
+
int x, y, a1, a2;
|
216
212
|
|
213
|
+
double delta, tmp_i;
|
217
214
|
double sat = NUM2DBL(saturation);
|
218
215
|
double ph = 0.0, ps = 0.0, pv = 0.0;
|
219
216
|
double r = 0.0, g = 0.0, b = 0.0;
|
@@ -222,101 +219,100 @@ static VALUE bitmap_miyako_saturation(VALUE self, VALUE vsrc, VALUE vdst, VALUE
|
|
222
219
|
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
223
220
|
|
224
221
|
if(_miyako_init_rect(&src, &dst, &size) == 0) return Qnil;
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
222
|
+
|
223
|
+
SDL_LockSurface(src.surface);
|
224
|
+
SDL_LockSurface(dst.surface);
|
225
|
+
|
226
|
+
for(y = 0; y < size.h; y++)
|
227
|
+
{
|
228
|
+
Uint32 *psrc = src.ptr + (src.rect.y + y) * src.rect.w + src.rect.x;
|
229
|
+
Uint32 *pdst = dst.ptr + (dst.rect.y + src.y + y) * dst.rect.w + dst.rect.x + src.x;
|
230
|
+
for(x = 0; x < size.w; x++)
|
231
|
+
{
|
235
232
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
236
233
|
src.color.r = (*psrc >> 16) & 0xff;
|
237
234
|
src.color.g = (*psrc >> 8) & 0xff;
|
238
235
|
src.color.b = (*psrc ) & 0xff;
|
239
236
|
src.color.a = (*psrc >> 24) & 0xff | src.a255;
|
240
|
-
|
237
|
+
if(src.color.a == 0){ psrc++; pdst++; continue; }
|
241
238
|
dst.color.r = (*pdst >> 16) & 0xff;
|
242
239
|
dst.color.g = (*pdst >> 8) & 0xff;
|
243
240
|
dst.color.b = (*pdst ) & 0xff;
|
244
241
|
dst.color.a = (*pdst >> 24) & 0xff | dst.a255;
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
242
|
+
MIYAKO_RGB2HSV(src.color, ph, ps, pv);
|
243
|
+
ps += sat;
|
244
|
+
if(ps < 0.0){ ps = 0.0; }
|
245
|
+
if(ps > 1.0){ ps = 1.0; }
|
246
|
+
MIYAKO_HSV2RGB(ph, ps, pv, src.color);
|
247
|
+
if(dst.color.a == 0 || src.color.a == 255){
|
248
|
+
*pdst = (src.color.r) << 16 |
|
249
|
+
(src.color.g) << 8 |
|
250
|
+
(src.color.b) |
|
251
|
+
(src.color.a) << 24;
|
252
|
+
psrc++;
|
253
|
+
pdst++;
|
254
|
+
continue;
|
255
|
+
}
|
256
|
+
a1 = src.color.a + 1;
|
257
|
+
a2 = 256 - src.color.a;
|
258
|
+
*pdst = ((src.color.r * a1 + dst.color.r * a2) >> 8) << 16 |
|
259
|
+
((src.color.g * a1 + dst.color.g * a2) >> 8) << 8 |
|
260
|
+
((src.color.b * a1 + dst.color.b * a2) >> 8) |
|
261
|
+
0xff << 24;
|
262
|
+
psrc++;
|
263
|
+
pdst++;
|
267
264
|
#else
|
268
265
|
src.color.r = (*psrc & src.fmt->Rmask) >> src.fmt->Rshift;
|
269
266
|
src.color.g = (*psrc & src.fmt->Gmask) >> src.fmt->Gshift;
|
270
267
|
src.color.b = (*psrc & src.fmt->Bmask) >> src.fmt->Bshift;
|
271
268
|
src.color.a = (*psrc & src.fmt->Amask) | src.a255;
|
272
|
-
|
269
|
+
if(src.color.a == 0){ psrc++; pdst++; continue; }
|
273
270
|
dst.color.r = (*pdst & dst.fmt->Rmask) >> dst.fmt->Rshift);
|
274
271
|
dst.color.g = (*pdst & dst.fmt->Gmask) >> dst.fmt->Gshift);
|
275
272
|
dst.color.b = (*pdst & dst.fmt->Bmask) >> dst.fmt->Bshift);
|
276
273
|
dst.color.a = (*pdst & dst.fmt->Amask) | dst.a255;
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
274
|
+
MIYAKO_RGB2HSV(src.color, ph, ps, pv);
|
275
|
+
ps += sat;
|
276
|
+
if(ps < 0.0){ ps = 0.0; }
|
277
|
+
if(ps > 1.0){ ps = 1.0; }
|
278
|
+
MIYAKO_HSV2RGB(ph, ps, pv, src.color);
|
279
|
+
if(dst.color.a == 0 || src.color.a == 255){
|
280
|
+
*pdst = src.color.r << dst.fmt->Rshift |
|
281
|
+
src.color.g << dst.fmt->Gshift |
|
282
|
+
src.color.b << dst.fmt->Bshift |
|
283
|
+
src.color.a;
|
284
|
+
psrc++;
|
285
|
+
pdst++;
|
286
|
+
continue;
|
287
|
+
}
|
288
|
+
a1 = src.color.a + 1;
|
289
|
+
a2 = 256 - src.color.a;
|
290
|
+
*pdst = ((src.color.r * a1 + dst.color.r * a2) >> 8) << dst.fmt->Rshift |
|
291
|
+
((src.color.g * a1 + dst.color.g * a2) >> 8) << dst.fmt->Gshift |
|
292
|
+
((src.color.b * a1 + dst.color.b * a2) >> 8) << dst.fmt->Bshift |
|
293
|
+
0xff;
|
294
|
+
psrc++;
|
295
|
+
pdst++;
|
299
296
|
#endif
|
300
297
|
}
|
301
|
-
|
298
|
+
}
|
302
299
|
|
303
|
-
|
304
|
-
|
300
|
+
SDL_UnlockSurface(src.surface);
|
301
|
+
SDL_UnlockSurface(dst.surface);
|
305
302
|
|
306
303
|
return vdst;
|
307
304
|
}
|
308
305
|
|
309
|
-
/*
|
310
|
-
画像の明度を変更する
|
311
|
-
*/
|
312
306
|
static VALUE bitmap_miyako_value(VALUE self, VALUE vsrc, VALUE vdst, VALUE value)
|
313
307
|
{
|
314
308
|
MiyakoBitmap src, dst;
|
315
309
|
MiyakoSize size;
|
316
|
-
|
310
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
317
311
|
double val = NUM2DBL(value);
|
318
|
-
|
319
|
-
|
312
|
+
Uint32 imax, imin;
|
313
|
+
|
314
|
+
int x, y, a1, a2;
|
315
|
+
double delta, tmp_i;
|
320
316
|
double ph = 0.0, ps = 0.0, pv = 0.0;
|
321
317
|
double r = 0.0, g = 0.0, b = 0.0;
|
322
318
|
double i = 0.0, f, m, n, k;
|
@@ -324,99 +320,98 @@ static VALUE bitmap_miyako_value(VALUE self, VALUE vsrc, VALUE vdst, VALUE value
|
|
324
320
|
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
325
321
|
|
326
322
|
if(_miyako_init_rect(&src, &dst, &size) == 0) return Qnil;
|
327
|
-
|
323
|
+
|
328
324
|
SDL_LockSurface(src.surface);
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
325
|
+
SDL_LockSurface(dst.surface);
|
326
|
+
|
327
|
+
for(y = 0; y < size.h; y++)
|
328
|
+
{
|
329
|
+
Uint32 *psrc = src.ptr + (src.rect.y + y) * src.rect.w + src.rect.x;
|
330
|
+
Uint32 *pdst = dst.ptr + (dst.rect.y + src.y + y) * dst.rect.w + dst.rect.x + src.x;
|
331
|
+
for(x = 0; x < size.w; x++)
|
332
|
+
{
|
337
333
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
338
334
|
src.color.r = (*psrc >> 16) & 0xff;
|
339
335
|
src.color.g = (*psrc >> 8) & 0xff;
|
340
336
|
src.color.b = (*psrc ) & 0xff;
|
341
337
|
src.color.a = (*psrc >> 24) & 0xff | src.a255;
|
342
|
-
|
338
|
+
if(src.color.a == 0){ psrc++; pdst++; continue; }
|
343
339
|
dst.color.r = (*pdst >> 16) & 0xff;
|
344
340
|
dst.color.g = (*pdst >> 8) & 0xff;
|
345
341
|
dst.color.b = (*pdst ) & 0xff;
|
346
342
|
dst.color.a = (*pdst >> 24) & 0xff | dst.a255;
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
343
|
+
MIYAKO_RGB2HSV(src.color, ph, ps, pv);
|
344
|
+
pv += val;
|
345
|
+
if(pv < 0.0){ pv = 0.0; }
|
346
|
+
if(pv > 1.0){ pv = 1.0; }
|
347
|
+
MIYAKO_HSV2RGB(ph, ps, pv, src.color);
|
348
|
+
if(dst.color.a == 0 || src.color.a == 255){
|
349
|
+
*pdst = (src.color.r) << 16 |
|
350
|
+
(src.color.g) << 8 |
|
351
|
+
(src.color.b) |
|
352
|
+
(src.color.a) << 24;
|
353
|
+
psrc++;
|
354
|
+
pdst++;
|
355
|
+
continue;
|
356
|
+
}
|
357
|
+
a1 = src.color.a + 1;
|
358
|
+
a2 = 256 - src.color.a;
|
359
|
+
*pdst = ((src.color.r * a1 + dst.color.r * a2) >> 8) << 16 |
|
360
|
+
((src.color.g * a1 + dst.color.g * a2) >> 8) << 8 |
|
361
|
+
((src.color.b * a1 + dst.color.b * a2) >> 8) |
|
362
|
+
0xff << 24;
|
367
363
|
#else
|
368
364
|
src.color.r = (*psrc & src.fmt->Rmask) >> src.fmt->Rshift;
|
369
365
|
src.color.g = (*psrc & src.fmt->Gmask) >> src.fmt->Gshift;
|
370
366
|
src.color.b = (*psrc & src.fmt->Bmask) >> src.fmt->Bshift;
|
371
367
|
src.color.a = (*psrc & src.fmt->Amask) | src.a255;
|
372
|
-
|
368
|
+
if(src.color.a == 0){ psrc++; pdst++; continue; }
|
373
369
|
dst.color.r = (*pdst & dst.fmt->Rmask) >> dst.fmt->Rshift);
|
374
370
|
dst.color.g = (*pdst & dst.fmt->Gmask) >> dst.fmt->Gshift);
|
375
371
|
dst.color.b = (*pdst & dst.fmt->Bmask) >> dst.fmt->Bshift);
|
376
372
|
dst.color.a = (*pdst & dst.fmt->Amask) | dst.a255;
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
373
|
+
MIYAKO_RGB2HSV(src.color, ph, ps, pv);
|
374
|
+
pv += val;
|
375
|
+
if(pv < 0.0){ pv = 0.0; }
|
376
|
+
if(pv > 1.0){ pv = 1.0; }
|
377
|
+
MIYAKO_HSV2RGB(ph, ps, pv, src.color);
|
378
|
+
if(dst.color.a == 0 || src.color.a == 255){
|
379
|
+
*pdst = src.color.r << dst.fmt->Rshift |
|
380
|
+
src.color.g << dst.fmt->Gshift |
|
381
|
+
src.color.b << dst.fmt->Bshift |
|
382
|
+
src.color.a;
|
383
|
+
psrc++;
|
384
|
+
pdst++;
|
385
|
+
continue;
|
386
|
+
}
|
387
|
+
a1 = src.color.a + 1;
|
388
|
+
a2 = 256 - src.color.a;
|
389
|
+
*pdst = ((src.color.r * a1 + dst.color.r * a2) >> 8) << dst.fmt->Rshift |
|
390
|
+
((src.color.g * a1 + dst.color.g * a2) >> 8) << dst.fmt->Gshift |
|
391
|
+
((src.color.b * a1 + dst.color.b * a2) >> 8) << dst.fmt->Bshift |
|
392
|
+
0xff;
|
397
393
|
#endif
|
398
394
|
psrc++;
|
399
|
-
|
400
|
-
|
401
|
-
|
395
|
+
pdst++;
|
396
|
+
}
|
397
|
+
}
|
402
398
|
|
403
|
-
|
404
|
-
|
399
|
+
SDL_UnlockSurface(src.surface);
|
400
|
+
SDL_UnlockSurface(dst.surface);
|
405
401
|
|
406
|
-
|
402
|
+
return vdst;
|
407
403
|
}
|
408
404
|
|
409
|
-
/*
|
410
|
-
画像の色相・彩度・明度を変更する
|
411
|
-
*/
|
412
405
|
static VALUE bitmap_miyako_hsv(VALUE self, VALUE vsrc, VALUE vdst, VALUE degree, VALUE saturation, VALUE value)
|
413
406
|
{
|
414
407
|
MiyakoBitmap src, dst;
|
415
408
|
MiyakoSize size;
|
416
|
-
|
417
|
-
|
418
|
-
int x, y;
|
409
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
410
|
+
Uint32 imax, imin;
|
419
411
|
|
412
|
+
int x, y, a1, a2;
|
413
|
+
|
414
|
+
double delta, tmp_i;
|
420
415
|
double deg = NUM2DBL(degree);
|
421
416
|
double sat = NUM2DBL(saturation);
|
422
417
|
double val = NUM2DBL(value);
|
@@ -430,304 +425,299 @@ static VALUE bitmap_miyako_hsv(VALUE self, VALUE vsrc, VALUE vdst, VALUE degree,
|
|
430
425
|
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
431
426
|
|
432
427
|
if(_miyako_init_rect(&src, &dst, &size) == 0) return Qnil;
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
428
|
+
|
429
|
+
SDL_LockSurface(src.surface);
|
430
|
+
SDL_LockSurface(dst.surface);
|
431
|
+
|
432
|
+
for(y = 0; y < size.h; y++)
|
433
|
+
{
|
434
|
+
Uint32 *psrc = src.ptr + (src.rect.y + y) * src.rect.w + src.rect.x;
|
435
|
+
Uint32 *pdst = dst.ptr + (dst.rect.y + src.y + y) * dst.rect.w + dst.rect.x + src.x;
|
436
|
+
for(x = 0; x < size.w; x++)
|
437
|
+
{
|
443
438
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
444
439
|
src.color.r = (*psrc >> 16) & 0xff;
|
445
440
|
src.color.g = (*psrc >> 8) & 0xff;
|
446
441
|
src.color.b = (*psrc ) & 0xff;
|
447
442
|
src.color.a = (*psrc >> 24) & 0xff | src.a255;
|
448
|
-
|
443
|
+
if(src.color.a == 0){ psrc++; pdst++; continue; }
|
449
444
|
dst.color.r = (*pdst >> 16) & 0xff;
|
450
445
|
dst.color.g = (*pdst >> 8) & 0xff;
|
451
446
|
dst.color.b = (*pdst ) & 0xff;
|
452
447
|
dst.color.a = (*pdst >> 24) & 0xff | dst.a255;
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
448
|
+
MIYAKO_RGB2HSV(src.color, ph, ps, pv);
|
449
|
+
ph += deg;
|
450
|
+
if(ph < 0.0){ ph += d_pi; }
|
451
|
+
if(ph >= d_pi){ ph -= d_pi; }
|
452
|
+
ps += sat;
|
453
|
+
if(ps < 0.0){ ps = 0.0; }
|
454
|
+
if(ps > 1.0){ ps = 1.0; }
|
455
|
+
pv += val;
|
456
|
+
if(pv < 0.0){ pv = 0.0; }
|
457
|
+
if(pv > 1.0){ pv = 1.0; }
|
458
|
+
MIYAKO_HSV2RGB(ph, ps, pv, src.color);
|
459
|
+
if(dst.color.a == 0 || src.color.a == 255){
|
460
|
+
*pdst = (src.color.r) << 16 |
|
461
|
+
(src.color.g) << 8 |
|
462
|
+
(src.color.b) |
|
463
|
+
(src.color.a) << 24;
|
464
|
+
psrc++;
|
465
|
+
pdst++;
|
466
|
+
continue;
|
467
|
+
}
|
468
|
+
a1 = src.color.a + 1;
|
469
|
+
a2 = 256 - src.color.a;
|
470
|
+
*pdst = ((src.color.r * a1 + dst.color.r * a2) >> 8) << 16 |
|
471
|
+
((src.color.g * a1 + dst.color.g * a2) >> 8) << 8 |
|
472
|
+
((src.color.b * a1 + dst.color.b * a2) >> 8) |
|
473
|
+
0xff << 24;
|
474
|
+
psrc++;
|
475
|
+
pdst++;
|
481
476
|
#else
|
482
477
|
src.color.r = (*psrc & src.fmt->Rmask) >> src.fmt->Rshift;
|
483
478
|
src.color.g = (*psrc & src.fmt->Gmask) >> src.fmt->Gshift;
|
484
479
|
src.color.b = (*psrc & src.fmt->Bmask) >> src.fmt->Bshift;
|
485
480
|
src.color.a = (*psrc & src.fmt->Amask) | src.a255;
|
486
|
-
|
481
|
+
if(src.color.a == 0){ psrc++; pdst++; continue; }
|
487
482
|
dst.color.r = (*pdst & dst.fmt->Rmask) >> dst.fmt->Rshift);
|
488
483
|
dst.color.g = (*pdst & dst.fmt->Gmask) >> dst.fmt->Gshift);
|
489
484
|
dst.color.b = (*pdst & dst.fmt->Bmask) >> dst.fmt->Bshift);
|
490
485
|
dst.color.a = (*pdst & dst.fmt->Amask) | dst.a255;
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
486
|
+
MIYAKO_RGB2HSV(src.color, ph, ps, pv);
|
487
|
+
ph += deg;
|
488
|
+
if(ph < 0.0){ ph += d_pi; }
|
489
|
+
if(ph >= d_pi){ ph -= d_pi; }
|
490
|
+
ps += sat;
|
491
|
+
if(ps < 0.0){ ps = 0.0; }
|
492
|
+
if(ps > 1.0){ ps = 1.0; }
|
493
|
+
pv += val;
|
494
|
+
if(pv < 0.0){ pv = 0.0; }
|
495
|
+
if(pv > 1.0){ pv = 1.0; }
|
496
|
+
MIYAKO_HSV2RGB(ph, ps, pv, src.color);
|
497
|
+
if(dst.color.a == 0 || src.color.a == 255){
|
498
|
+
*pdst = src.color.r << dst.fmt->Rshift |
|
499
|
+
src.color.g << dst.fmt->Gshift |
|
500
|
+
src.color.b << dst.fmt->Bshift |
|
501
|
+
src.color.a;
|
502
|
+
psrc++;
|
503
|
+
pdst++;
|
504
|
+
continue;
|
505
|
+
}
|
506
|
+
a1 = src.color.a + 1;
|
507
|
+
a2 = 256 - src.color.a;
|
508
|
+
*pdst = ((src.color.r * a1 + dst.color.r * a2) >> 8) << dst.fmt->Rshift |
|
509
|
+
((src.color.g * a1 + dst.color.g * a2) >> 8) << dst.fmt->Gshift |
|
510
|
+
((src.color.b * a1 + dst.color.b * a2) >> 8) << dst.fmt->Bshift |
|
511
|
+
0xff;
|
512
|
+
psrc++;
|
513
|
+
pdst++;
|
519
514
|
#endif
|
520
515
|
}
|
521
|
-
|
516
|
+
}
|
522
517
|
|
523
|
-
|
524
|
-
|
518
|
+
SDL_UnlockSurface(src.surface);
|
519
|
+
SDL_UnlockSurface(dst.surface);
|
525
520
|
|
526
|
-
|
521
|
+
return vdst;
|
527
522
|
}
|
528
523
|
|
529
|
-
/*
|
530
|
-
画像の色相を変更する
|
531
|
-
*/
|
532
524
|
static VALUE bitmap_miyako_hue_self(VALUE self, VALUE vdst, VALUE degree)
|
533
525
|
{
|
534
526
|
MiyakoBitmap dst;
|
535
|
-
|
527
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
528
|
+
Uint32 imax, imin;
|
536
529
|
|
537
|
-
|
538
|
-
|
539
|
-
int x, y;
|
530
|
+
int x, y;
|
531
|
+
double delta, tmp_i;
|
540
532
|
double deg = NUM2DBL(degree);
|
541
533
|
double d_pi = 360.0;
|
542
534
|
double ph = 0.0, ps = 0.0, pv = 0.0;
|
543
535
|
double r = 0.0, g = 0.0, b = 0.0;
|
544
536
|
double i = 0.0, f, m, n, k;
|
545
537
|
|
538
|
+
_miyako_setup_unit(vdst, scr, &dst, Qnil, Qnil, 1);
|
539
|
+
|
546
540
|
if(deg <= -360.0 || deg >= 360.0){ return Qnil; }
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
541
|
+
|
542
|
+
SDL_LockSurface(dst.surface);
|
543
|
+
|
544
|
+
for(y = 0; y < dst.rect.h; y++)
|
545
|
+
{
|
546
|
+
Uint32 *pdst = dst.ptr + (dst.rect.y + y) * dst.rect.w + dst.rect.x;
|
547
|
+
for(x = 0; x < dst.rect.w; x++)
|
548
|
+
{
|
555
549
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
556
550
|
dst.color.r = (*pdst >> 16) & 0xff;
|
557
551
|
dst.color.g = (*pdst >> 8) & 0xff;
|
558
552
|
dst.color.b = (*pdst ) & 0xff;
|
559
553
|
dst.color.a = (*pdst >> 24) & 0xff | dst.a255;
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
554
|
+
if(dst.color.a == 0){ pdst++; continue; }
|
555
|
+
MIYAKO_RGB2HSV(dst.color, ph, ps, pv);
|
556
|
+
ph += deg;
|
557
|
+
if(ph < 0.0){ ph += d_pi; }
|
558
|
+
if(ph >= d_pi){ ph -= d_pi; }
|
559
|
+
MIYAKO_HSV2RGB(ph, ps, pv, dst.color);
|
560
|
+
*pdst = (dst.color.r) << 16 |
|
561
|
+
(dst.color.g) << 8 |
|
562
|
+
(dst.color.b) |
|
563
|
+
(dst.color.a) << 24;
|
570
564
|
#else
|
571
565
|
dst.color.r = (*pdst & dst.fmt->Rmask) >> dst.fmt->Rshift);
|
572
566
|
dst.color.g = (*pdst & dst.fmt->Gmask) >> dst.fmt->Gshift);
|
573
567
|
dst.color.b = (*pdst & dst.fmt->Bmask) >> dst.fmt->Bshift);
|
574
568
|
dst.color.a = (*pdst & dst.fmt->Amask) | dst.a255;
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
569
|
+
if(dst.color.a == 0){ pdst++; continue; }
|
570
|
+
MIYAKO_RGB2HSV(dst.color, ph, ps, pv);
|
571
|
+
ph += deg;
|
572
|
+
if(ph < 0.0){ ph += d_pi; }
|
573
|
+
if(ph >= d_pi){ ph -= d_pi; }
|
574
|
+
MIYAKO_HSV2RGB(ph, ps, pv, dst.color);
|
575
|
+
*pdst = dst.color.r << dst.fmt->Rshift |
|
576
|
+
dst.color.g << dst.fmt->Gshift |
|
577
|
+
dst.color.b << dst.fmt->Bshift |
|
578
|
+
dst.color.a;
|
585
579
|
#endif
|
586
580
|
pdst++;
|
587
|
-
|
588
|
-
|
581
|
+
}
|
582
|
+
}
|
589
583
|
|
590
|
-
|
584
|
+
SDL_UnlockSurface(dst.surface);
|
591
585
|
|
592
586
|
return vdst;
|
593
587
|
}
|
594
588
|
|
595
|
-
/*
|
596
|
-
画像の彩度を変更する
|
597
|
-
*/
|
598
589
|
static VALUE bitmap_miyako_saturation_self(VALUE self, VALUE vdst, VALUE saturation)
|
599
590
|
{
|
600
591
|
MiyakoBitmap dst;
|
601
|
-
|
602
|
-
|
603
|
-
_miyako_setup_unit(vdst, scr, &dst, Qnil, Qnil, 1);
|
592
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
593
|
+
Uint32 imax, imin;
|
604
594
|
|
595
|
+
int x, y;
|
596
|
+
double delta, tmp_i;
|
605
597
|
double sat = NUM2DBL(saturation);
|
606
598
|
double ph = 0.0, ps = 0.0, pv = 0.0;
|
607
599
|
double r = 0.0, g = 0.0, b = 0.0;
|
608
600
|
double i = 0.0, f, m, n, k;
|
609
601
|
|
610
|
-
|
602
|
+
_miyako_setup_unit(vdst, scr, &dst, Qnil, Qnil, 1);
|
603
|
+
|
604
|
+
SDL_LockSurface(dst.surface);
|
611
605
|
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
{
|
606
|
+
for(y = 0; y < dst.rect.h; y++)
|
607
|
+
{
|
608
|
+
Uint32 *pdst = dst.ptr + (dst.rect.y + y) * dst.rect.w + dst.rect.x;
|
609
|
+
for(x = 0; x < dst.rect.w; x++)
|
610
|
+
{
|
618
611
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
619
612
|
dst.color.r = (*pdst >> 16) & 0xff;
|
620
613
|
dst.color.g = (*pdst >> 8) & 0xff;
|
621
614
|
dst.color.b = (*pdst ) & 0xff;
|
622
615
|
dst.color.a = (*pdst >> 24) & 0xff | dst.a255;
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
616
|
+
if(dst.color.a == 0){ pdst++; continue; }
|
617
|
+
MIYAKO_RGB2HSV(dst.color, ph, ps, pv);
|
618
|
+
ps += sat;
|
619
|
+
if(ps < 0.0){ ps = 0.0; }
|
620
|
+
if(ps > 1.0){ ps = 1.0; }
|
621
|
+
MIYAKO_HSV2RGB(ph, ps, pv, dst.color);
|
629
622
|
*pdst = (dst.color.r) << 16 |
|
630
623
|
(dst.color.g) << 8 |
|
631
|
-
|
632
|
-
|
624
|
+
(dst.color.b) |
|
625
|
+
(dst.color.a) << 24;
|
633
626
|
#else
|
634
627
|
dst.color.r = (*pdst & dst.fmt->Rmask) >> dst.fmt->Rshift);
|
635
628
|
dst.color.g = (*pdst & dst.fmt->Gmask) >> dst.fmt->Gshift);
|
636
629
|
dst.color.b = (*pdst & dst.fmt->Bmask) >> dst.fmt->Bshift);
|
637
630
|
dst.color.a = (*pdst & dst.fmt->Amask) | dst.a255;
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
631
|
+
if(dst.color.a == 0){ pdst++; continue; }
|
632
|
+
MIYAKO_RGB2HSV(dst.color, ph, ps, pv);
|
633
|
+
ps += sat;
|
634
|
+
if(ps < 0.0){ ps = 0.0; }
|
635
|
+
if(ps > 1.0){ ps = 1.0; }
|
636
|
+
MIYAKO_HSV2RGB(ph, ps, pv, dst.color);
|
637
|
+
*pdst = dst.color.r << dst.fmt->Rshift |
|
638
|
+
dst.color.g << dst.fmt->Gshift |
|
639
|
+
dst.color.b << dst.fmt->Bshift |
|
640
|
+
dst.color.a;
|
648
641
|
#endif
|
649
642
|
pdst++;
|
650
|
-
|
651
|
-
|
643
|
+
}
|
644
|
+
}
|
652
645
|
|
653
|
-
|
646
|
+
SDL_UnlockSurface(dst.surface);
|
654
647
|
|
655
648
|
return vdst;
|
656
649
|
}
|
657
650
|
|
658
|
-
/*
|
659
|
-
画像の明度を変更する
|
660
|
-
*/
|
661
651
|
static VALUE bitmap_miyako_value_self(VALUE self, VALUE vdst, VALUE value)
|
662
652
|
{
|
663
653
|
MiyakoBitmap dst;
|
664
|
-
|
665
|
-
|
666
|
-
_miyako_setup_unit(vdst, scr, &dst, Qnil, Qnil, 1);
|
654
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
655
|
+
Uint32 imax, imin;
|
667
656
|
|
657
|
+
int x, y;
|
658
|
+
double delta, tmp_i;
|
668
659
|
double val = NUM2DBL(value);
|
669
660
|
double ph = 0.0, ps = 0.0, pv = 0.0;
|
670
661
|
double r = 0.0, g = 0.0, b = 0.0;
|
671
662
|
double i = 0.0, f, m, n, k;
|
672
663
|
|
673
|
-
|
664
|
+
_miyako_setup_unit(vdst, scr, &dst, Qnil, Qnil, 1);
|
665
|
+
|
666
|
+
SDL_LockSurface(dst.surface);
|
674
667
|
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
{
|
668
|
+
for(y = 0; y < dst.rect.h; y++)
|
669
|
+
{
|
670
|
+
Uint32 *pdst = dst.ptr + (dst.rect.y + y) * dst.rect.w + dst.rect.x;
|
671
|
+
for(x = 0; x < dst.rect.w; x++)
|
672
|
+
{
|
681
673
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
682
674
|
dst.color.r = (*pdst >> 16) & 0xff;
|
683
675
|
dst.color.g = (*pdst >> 8) & 0xff;
|
684
676
|
dst.color.b = (*pdst ) & 0xff;
|
685
677
|
dst.color.a = (*pdst >> 24) & 0xff | dst.a255;
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
678
|
+
if(dst.color.a == 0){ pdst++; continue; }
|
679
|
+
MIYAKO_RGB2HSV(dst.color, ph, ps, pv);
|
680
|
+
pv += val;
|
681
|
+
if(pv < 0.0){ pv = 0.0; }
|
682
|
+
if(pv > 1.0){ pv = 1.0; }
|
683
|
+
MIYAKO_HSV2RGB(ph, ps, pv, dst.color);
|
692
684
|
*pdst = (dst.color.r) << 16 |
|
693
685
|
(dst.color.g) << 8 |
|
694
|
-
|
695
|
-
|
686
|
+
(dst.color.b) |
|
687
|
+
(dst.color.a) << 24;
|
696
688
|
#else
|
697
689
|
dst.color.r = (*pdst & dst.fmt->Rmask) >> dst.fmt->Rshift);
|
698
690
|
dst.color.g = (*pdst & dst.fmt->Gmask) >> dst.fmt->Gshift);
|
699
691
|
dst.color.b = (*pdst & dst.fmt->Bmask) >> dst.fmt->Bshift);
|
700
692
|
dst.color.a = (*pdst & dst.fmt->Amask) | dst.a255;
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
693
|
+
if(dst.color.a == 0){ pdst++; continue; }
|
694
|
+
MIYAKO_RGB2HSV(dst.color, ph, ps, pv);
|
695
|
+
pv += val;
|
696
|
+
if(pv < 0.0){ pv = 0.0; }
|
697
|
+
if(pv > 1.0){ pv = 1.0; }
|
698
|
+
MIYAKO_HSV2RGB(ph, ps, pv, dst.color);
|
699
|
+
*pdst = dst.color.r << dst.fmt->Rshift |
|
700
|
+
dst.color.g << dst.fmt->Gshift |
|
701
|
+
dst.color.b << dst.fmt->Bshift |
|
702
|
+
dst.color.a;
|
711
703
|
#endif
|
712
704
|
pdst++;
|
713
|
-
|
714
|
-
|
705
|
+
}
|
706
|
+
}
|
715
707
|
|
716
|
-
|
708
|
+
SDL_UnlockSurface(dst.surface);
|
717
709
|
|
718
710
|
return vdst;
|
719
711
|
}
|
720
712
|
|
721
|
-
/*
|
722
|
-
画像の色相・彩度・明度を変更する
|
723
|
-
*/
|
724
713
|
static VALUE bitmap_miyako_hsv_self(VALUE self, VALUE vdst, VALUE degree, VALUE saturation, VALUE value)
|
725
714
|
{
|
726
715
|
MiyakoBitmap dst;
|
727
|
-
|
728
|
-
|
729
|
-
_miyako_setup_unit(vdst, scr, &dst, Qnil, Qnil, 1);
|
716
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
717
|
+
Uint32 imax, imin;
|
730
718
|
|
719
|
+
int x, y;
|
720
|
+
double delta, tmp_i;
|
731
721
|
double deg = NUM2DBL(degree);
|
732
722
|
double sat = NUM2DBL(saturation);
|
733
723
|
double val = NUM2DBL(value);
|
@@ -736,70 +726,73 @@ static VALUE bitmap_miyako_hsv_self(VALUE self, VALUE vdst, VALUE degree, VALUE
|
|
736
726
|
double r = 0.0, g = 0.0, b = 0.0;
|
737
727
|
double i = 0.0, f, m, n, k;
|
738
728
|
|
729
|
+
_miyako_setup_unit(vdst, scr, &dst, Qnil, Qnil, 1);
|
730
|
+
|
739
731
|
if(deg <= -360.0 || deg >= 360.0){ return Qnil; }
|
740
732
|
|
741
|
-
|
733
|
+
SDL_LockSurface(dst.surface);
|
742
734
|
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
{
|
735
|
+
for(y = 0; y < dst.rect.h; y++)
|
736
|
+
{
|
737
|
+
Uint32 *pdst = dst.ptr + (dst.rect.y + y) * dst.rect.w + dst.rect.x;
|
738
|
+
for(x = 0; x < dst.rect.w; x++)
|
739
|
+
{
|
749
740
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
750
741
|
dst.color.r = (*pdst >> 16) & 0xff;
|
751
742
|
dst.color.g = (*pdst >> 8) & 0xff;
|
752
743
|
dst.color.b = (*pdst ) & 0xff;
|
753
744
|
dst.color.a = (*pdst >> 24) & 0xff | dst.a255;
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
745
|
+
if(dst.color.a == 0){ pdst++; continue; }
|
746
|
+
MIYAKO_RGB2HSV(dst.color, ph, ps, pv);
|
747
|
+
ph += deg;
|
748
|
+
if(ph < 0.0){ ph += d_pi; }
|
749
|
+
if(ph >= d_pi){ ph -= d_pi; }
|
750
|
+
ps += sat;
|
751
|
+
if(ps < 0.0){ ps = 0.0; }
|
752
|
+
if(ps > 1.0){ ps = 1.0; }
|
753
|
+
pv += val;
|
754
|
+
if(pv < 0.0){ pv = 0.0; }
|
755
|
+
if(pv > 1.0){ pv = 1.0; }
|
756
|
+
MIYAKO_HSV2RGB(ph, ps, pv, dst.color);
|
757
|
+
*pdst = (dst.color.r) << 16 |
|
758
|
+
(dst.color.g) << 8 |
|
759
|
+
(dst.color.b) |
|
760
|
+
(dst.color.a) << 24;
|
770
761
|
#else
|
771
762
|
dst.color.r = (*pdst & dst.fmt->Rmask) >> dst.fmt->Rshift);
|
772
763
|
dst.color.g = (*pdst & dst.fmt->Gmask) >> dst.fmt->Gshift);
|
773
764
|
dst.color.b = (*pdst & dst.fmt->Bmask) >> dst.fmt->Bshift);
|
774
765
|
dst.color.a = (*pdst & dst.fmt->Amask) | dst.a255;
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
766
|
+
if(dst.color.a == 0){ pdst++; continue; }
|
767
|
+
MIYAKO_RGB2HSV(dst.color, ph, ps, pv);
|
768
|
+
ph += deg;
|
769
|
+
if(ph < 0.0){ ph += d_pi; }
|
770
|
+
if(ph >= d_pi){ ph -= d_pi; }
|
771
|
+
ps += sat;
|
772
|
+
if(ps < 0.0){ ps = 0.0; }
|
773
|
+
if(ps > 1.0){ ps = 1.0; }
|
774
|
+
pv += val;
|
775
|
+
if(pv < 0.0){ pv = 0.0; }
|
776
|
+
if(pv > 1.0){ pv = 1.0; }
|
777
|
+
MIYAKO_HSV2RGB(ph, ps, pv, dst.color);
|
778
|
+
*pdst = dst.color.r << dst.fmt->Rshift |
|
779
|
+
dst.color.g << dst.fmt->Gshift |
|
780
|
+
dst.color.b << dst.fmt->Bshift |
|
781
|
+
dst.color.a;
|
791
782
|
#endif
|
792
783
|
pdst++;
|
793
|
-
|
794
|
-
|
784
|
+
}
|
785
|
+
}
|
795
786
|
|
796
|
-
|
787
|
+
SDL_UnlockSurface(dst.surface);
|
797
788
|
|
798
789
|
return vdst;
|
799
790
|
}
|
800
791
|
|
801
792
|
void Init_miyako_hsv()
|
802
793
|
{
|
794
|
+
int i;
|
795
|
+
|
803
796
|
mSDL = rb_define_module("SDL");
|
804
797
|
mMiyako = rb_define_module("Miyako");
|
805
798
|
mScreen = rb_define_module_under(mMiyako, "Screen");
|
@@ -824,7 +817,6 @@ void Init_miyako_hsv()
|
|
824
817
|
rb_define_singleton_method(cBitmap, "saturation!", bitmap_miyako_saturation_self, 2);
|
825
818
|
rb_define_singleton_method(cBitmap, "value!", bitmap_miyako_value_self, 2);
|
826
819
|
rb_define_singleton_method(cBitmap, "hsv!", bitmap_miyako_hsv_self, 4);
|
827
|
-
|
828
|
-
int i;
|
820
|
+
|
829
821
|
for(i=0; i<256; i++){ div255[i] = (double)i / 255.0; }
|
830
822
|
}
|