ruby-miyako 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1115 -0
- data/Rakefile +7 -0
- data/defines.h +144 -0
- data/extconf.rb +44 -0
- data/extern.h +29 -0
- data/img/cursor.png +0 -0
- data/img/cursors.png +0 -0
- data/img/dice.png +0 -0
- data/img/wait_cursor.png +0 -0
- data/img/win_base.png +0 -0
- data/img/window.png +0 -0
- data/install_miyako.rb +87 -0
- data/lib/Miyako/API/audio.rb +584 -0
- data/lib/Miyako/API/basic_data.rb +1026 -0
- data/lib/Miyako/API/bitmap.rb +534 -0
- data/lib/Miyako/API/choices.rb +481 -0
- data/lib/Miyako/API/collision.rb +638 -0
- data/lib/Miyako/API/diagram.rb +586 -0
- data/lib/Miyako/API/drawing.rb +151 -0
- data/lib/Miyako/API/exceptions.rb +105 -0
- data/lib/Miyako/API/fixedmap.rb +462 -0
- data/lib/Miyako/API/font.rb +430 -0
- data/lib/Miyako/API/input.rb +456 -0
- data/lib/Miyako/API/layout.rb +644 -0
- data/lib/Miyako/API/map.rb +583 -0
- data/lib/Miyako/API/map_event.rb +222 -0
- data/lib/Miyako/API/modules.rb +357 -0
- data/lib/Miyako/API/movie.rb +166 -0
- data/lib/Miyako/API/parts.rb +188 -0
- data/lib/Miyako/API/plane.rb +205 -0
- data/lib/Miyako/API/screen.rb +341 -0
- data/lib/Miyako/API/shape.rb +443 -0
- data/lib/Miyako/API/sprite.rb +773 -0
- data/lib/Miyako/API/sprite_animation.rb +494 -0
- data/lib/Miyako/API/sprite_list.rb +1135 -0
- data/lib/Miyako/API/spriteunit.rb +168 -0
- data/lib/Miyako/API/story.rb +350 -0
- data/lib/Miyako/API/textbox.rb +773 -0
- data/lib/Miyako/API/utility.rb +419 -0
- data/lib/Miyako/API/viewport.rb +190 -0
- data/lib/Miyako/API/yuki.rb +1180 -0
- data/lib/Miyako/EXT/miyako_cairo.rb +62 -0
- data/lib/Miyako/EXT/raster_scroll.rb +138 -0
- data/lib/Miyako/EXT/slides.rb +157 -0
- data/lib/Miyako/miyako.rb +201 -0
- data/lib/Miyako/miyako_require_only.rb +35 -0
- data/logo/EGSR_logo.png +0 -0
- data/logo/EGSR_logo_bg.png +0 -0
- data/logo/EGSR_logo_fg.png +0 -0
- data/logo/EGSR_title_banner.png +0 -0
- data/logo/EGSR_title_logo.png +0 -0
- data/logo/miyako.png +0 -0
- data/logo/miyako_banner.png +0 -0
- data/logo/space.png +0 -0
- data/miyako_basicdata.c +484 -0
- data/miyako_bitmap.c +1225 -0
- data/miyako_collision.c +403 -0
- data/miyako_drawing.c +187 -0
- data/miyako_font.c +334 -0
- data/miyako_hsv.c +830 -0
- data/miyako_input_audio.c +254 -0
- data/miyako_layout.c +191 -0
- data/miyako_no_katana.c +1086 -0
- data/miyako_sprite2.c +431 -0
- data/miyako_transform.c +438 -0
- data/miyako_utility.c +288 -0
- data/sample/Animation1/m1ku.rb +68 -0
- data/sample/Animation1/m1ku_arm_0.png +0 -0
- data/sample/Animation1/m1ku_arm_1.png +0 -0
- data/sample/Animation1/m1ku_arm_2.png +0 -0
- data/sample/Animation1/m1ku_arm_3.png +0 -0
- data/sample/Animation1/m1ku_back.jpg +0 -0
- data/sample/Animation1/m1ku_body.png +0 -0
- data/sample/Animation1/m1ku_eye_0.png +0 -0
- data/sample/Animation1/m1ku_eye_1.png +0 -0
- data/sample/Animation1/m1ku_eye_2.png +0 -0
- data/sample/Animation1/m1ku_eye_3.png +0 -0
- data/sample/Animation1/m1ku_hair_front.png +0 -0
- data/sample/Animation1/m1ku_hair_rear.png +0 -0
- data/sample/Animation1/readme.txt +72 -0
- data/sample/Animation2/lex.rb +96 -0
- data/sample/Animation2/lex_back.png +0 -0
- data/sample/Animation2/lex_body.png +0 -0
- data/sample/Animation2/lex_roadroller.png +0 -0
- data/sample/Animation2/lex_wheel_0.png +0 -0
- data/sample/Animation2/lex_wheel_1.png +0 -0
- data/sample/Animation2/lex_wheel_2.png +0 -0
- data/sample/Animation2/readme.txt +72 -0
- data/sample/Animation2/song_title.png +0 -0
- data/sample/Diagram_sample/back.png +0 -0
- data/sample/Diagram_sample/chr01.png +0 -0
- data/sample/Diagram_sample/chr02.png +0 -0
- data/sample/Diagram_sample/cursor.png +0 -0
- data/sample/Diagram_sample/diagram_sample_yuki2.rb +329 -0
- data/sample/Diagram_sample/readme.txt +90 -0
- data/sample/Diagram_sample/wait_cursor.png +0 -0
- data/sample/Room3/blue.rb +297 -0
- data/sample/Room3/ending.rb +180 -0
- data/sample/Room3/green.rb +220 -0
- data/sample/Room3/image/akamatsu.png +0 -0
- data/sample/Room3/image/aoyama.png +0 -0
- data/sample/Room3/image/congra.png +0 -0
- data/sample/Room3/image/congratulation.png +0 -0
- data/sample/Room3/image/congratulation_bg.png +0 -0
- data/sample/Room3/image/cursor.png +0 -0
- data/sample/Room3/image/midori.png +0 -0
- data/sample/Room3/image/mittsu_no_oheya.png +0 -0
- data/sample/Room3/image/mittsu_no_oheya_logo.png +0 -0
- data/sample/Room3/image/room_blue.png +0 -0
- data/sample/Room3/image/room_green.png +0 -0
- data/sample/Room3/image/room_red.png +0 -0
- data/sample/Room3/image/start.png +0 -0
- data/sample/Room3/image/three_doors.png +0 -0
- data/sample/Room3/image/wait_cursor.png +0 -0
- data/sample/Room3/main.rb +120 -0
- data/sample/Room3/main_component.rb +59 -0
- data/sample/Room3/readme.txt +76 -0
- data/sample/Room3/red.rb +227 -0
- data/sample/Room3/room3.rb +25 -0
- data/sample/Room3/title.rb +184 -0
- data/sample/ball_action_sample.rb +204 -0
- data/sample/blit_rop.rb +70 -0
- data/sample/cairo_sample.rb +25 -0
- data/sample/circle_collision_test.rb +66 -0
- data/sample/collision_test.rb +33 -0
- data/sample/collision_test2.rb +108 -0
- data/sample/fixed_map_test/cursor.png +0 -0
- data/sample/fixed_map_test/fixed_map_sample.rb +140 -0
- data/sample/fixed_map_test/map.csv +19 -0
- data/sample/fixed_map_test/map_01.png +0 -0
- data/sample/fixed_map_test/mapchip.csv +23 -0
- data/sample/fixed_map_test/monster.png +0 -0
- data/sample/fixed_map_test/readme.txt +72 -0
- data/sample/map_test/chara.rb +58 -0
- data/sample/map_test/chr1.png +0 -0
- data/sample/map_test/cursor.png +0 -0
- data/sample/map_test/main_parts.rb +69 -0
- data/sample/map_test/main_scene.rb +153 -0
- data/sample/map_test/map.png +0 -0
- data/sample/map_test/map2.png +0 -0
- data/sample/map_test/map_layer.csv +127 -0
- data/sample/map_test/map_manager.rb +75 -0
- data/sample/map_test/map_test.rb +23 -0
- data/sample/map_test/mapchip.csv +21 -0
- data/sample/map_test/oasis.rb +71 -0
- data/sample/map_test/readme.txt +89 -0
- data/sample/map_test/route.rb +157 -0
- data/sample/map_test/sea.png +0 -0
- data/sample/map_test/town.rb +74 -0
- data/sample/map_test/wait_cursor.png +0 -0
- data/sample/map_test/window.png +0 -0
- data/sample/polygon_test.rb +35 -0
- data/sample/rasterscroll.rb +25 -0
- data/sample/takahashi.rb +42 -0
- data/sample/text.png +0 -0
- data/sample/textbox_sample.rb +192 -0
- data/sample/transform.rb +54 -0
- data/sample/utility_test.rb +73 -0
- data/sample/utility_test2.rb +61 -0
- data/sample/utility_test3.rb +64 -0
- data/sample/utility_test4.rb +73 -0
- data/uninstall_miyako.rb +19 -0
- data/win/miyako_no_katana.so +0 -0
- metadata +216 -0
data/miyako_bitmap.c
ADDED
@@ -0,0 +1,1225 @@
|
|
1
|
+
/*
|
2
|
+
--
|
3
|
+
Miyako v2.0 Extend Library "Miyako no Katana"
|
4
|
+
Copyright (C) 2008 Cyross Makoto
|
5
|
+
|
6
|
+
This library is free software; you can redistribute it and/or
|
7
|
+
modify it under the terms of the GNU Lesser General Public
|
8
|
+
License as published by the Free Software Foundation; either
|
9
|
+
version 2.1 of the License, or (at your option) any later version.
|
10
|
+
|
11
|
+
This library is distributed in the hope that it will be useful,
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
Lesser General Public License for more details.
|
15
|
+
|
16
|
+
You should have received a copy of the GNU Lesser General Public
|
17
|
+
License along with this library; if not, write to the Free Software
|
18
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
++
|
20
|
+
*/
|
21
|
+
|
22
|
+
/*
|
23
|
+
=拡張ライブラリmiyako_no_katana
|
24
|
+
Authors:: サイロス誠
|
25
|
+
Version:: 2.0
|
26
|
+
Copyright:: 2007-2008 Cyross Makoto
|
27
|
+
License:: LGPL2.1
|
28
|
+
*/
|
29
|
+
#include "defines.h"
|
30
|
+
#include "extern.h"
|
31
|
+
|
32
|
+
static VALUE mSDL = Qnil;
|
33
|
+
static VALUE mMiyako = Qnil;
|
34
|
+
static VALUE mScreen = Qnil;
|
35
|
+
static VALUE eMiyakoError = Qnil;
|
36
|
+
static VALUE cSurface = Qnil;
|
37
|
+
static VALUE cBitmap = Qnil;
|
38
|
+
static VALUE nZero = Qnil;
|
39
|
+
static VALUE nOne = Qnil;
|
40
|
+
static volatile ID id_update = Qnil;
|
41
|
+
static volatile ID id_kakko = Qnil;
|
42
|
+
static volatile ID id_render = Qnil;
|
43
|
+
static volatile ID id_to_a = Qnil;
|
44
|
+
static volatile int zero = Qnil;
|
45
|
+
static volatile int one = Qnil;
|
46
|
+
|
47
|
+
// from rubysdl_video.c
|
48
|
+
static GLOBAL_DEFINE_GET_STRUCT(Surface, GetSurface, cSurface, "SDL::Surface");
|
49
|
+
|
50
|
+
/*
|
51
|
+
画像をαチャネル付き画像へ転送する
|
52
|
+
*/
|
53
|
+
static VALUE bitmap_miyako_blit_aa(VALUE self, VALUE vsrc, VALUE vdst, VALUE vx, VALUE vy)
|
54
|
+
{
|
55
|
+
MiyakoBitmap src, dst;
|
56
|
+
MiyakoSize size;
|
57
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
58
|
+
|
59
|
+
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, vx, vy, 1);
|
60
|
+
|
61
|
+
if(_miyako_init_rect(&src, &dst, &size) == 0) return Qnil;
|
62
|
+
|
63
|
+
SDL_LockSurface(src.surface);
|
64
|
+
SDL_LockSurface(dst.surface);
|
65
|
+
|
66
|
+
int x, y;
|
67
|
+
for(y = 0; y < size.h; y++)
|
68
|
+
{
|
69
|
+
Uint32 *ppsrc = src.ptr + (src.rect.y + y) * src.surface->w + src.rect.x;
|
70
|
+
Uint32 *ppdst = dst.ptr + (dst.rect.y + src.y + y) * dst.surface->w + dst.rect.x + src.x;
|
71
|
+
for(x = 0; x < size.w; x++)
|
72
|
+
{
|
73
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
74
|
+
dst.color.a = (*ppdst >> 24) & 0xff | dst.a255;
|
75
|
+
src.color.a = (*ppsrc >> 24) & 0xff | src.a255;
|
76
|
+
if(src.color.a == 0){ ppsrc++; ppdst++; continue; }
|
77
|
+
if(dst.color.a == 0 || src.color.a == 255){
|
78
|
+
*ppdst = *ppsrc;
|
79
|
+
ppsrc++;
|
80
|
+
ppdst++;
|
81
|
+
continue;
|
82
|
+
}
|
83
|
+
dst.color.r = (*ppdst >> 16) & 0xff;
|
84
|
+
dst.color.g = (*ppdst >> 8) & 0xff;
|
85
|
+
dst.color.b = (*ppdst ) & 0xff;
|
86
|
+
src.color.r = (*ppsrc >> 16) & 0xff;
|
87
|
+
src.color.g = (*ppsrc >> 8) & 0xff;
|
88
|
+
src.color.b = (*ppsrc ) & 0xff;
|
89
|
+
int a1 = src.color.a + 1;
|
90
|
+
int a2 = 256 - src.color.a;
|
91
|
+
*ppdst = ((src.color.r * a1 + dst.color.r * a2) >> 8) << 16 |
|
92
|
+
((src.color.g * a1 + dst.color.g * a2) >> 8) << 8 |
|
93
|
+
((src.color.b * a1 + dst.color.b * a2) >> 8) |
|
94
|
+
0xff << 24;
|
95
|
+
#else
|
96
|
+
dst.color.a = (*ppdst & dst.fmt->Amask) | dst.a255;
|
97
|
+
src.color.a = (*ppsrc & src.fmt->Amask) | src.a255;
|
98
|
+
if(src.color.a == 0){ ppsrc++; ppdst++; continue; }
|
99
|
+
if(dst.color.a == 0 || src.color.a == 255){
|
100
|
+
*ppdst = *ppsrc;
|
101
|
+
ppsrc++;
|
102
|
+
ppdst++;
|
103
|
+
continue;
|
104
|
+
}
|
105
|
+
dst.color.r = (*ppdst & dst.fmt->Rmask) >> dst.fmt->Rshift;
|
106
|
+
dst.color.g = (*ppdst & dst.fmt->Gmask) >> dst.fmt->Gshift;
|
107
|
+
dst.color.b = (*ppdst & dst.fmt->Bmask) >> dst.fmt->Bshift;
|
108
|
+
src.color.r = (*ppsrc & src.fmt->Rmask) >> src.fmt->Rshift;
|
109
|
+
src.color.g = (*ppsrc & src.fmt->Gmask) >> src.fmt->Gshift;
|
110
|
+
src.color.b = (*ppsrc & src.fmt->Bmask) >> src.fmt->Bshift;
|
111
|
+
int a1 = src.color.a + 1;
|
112
|
+
int a2 = 256 - src.color.a;
|
113
|
+
*ppdst = ((src.color.r * a1 + dst.color.r * a2) >> 8) << dst.fmt->Rshift |
|
114
|
+
((src.color.g * a1 + dst.color.g * a2) >> 8) << dst.fmt->Gshift |
|
115
|
+
((src.color.b * a1 + dst.color.b * a2) >> 8) << dst.fmt->Bshift |
|
116
|
+
0xff;
|
117
|
+
#endif
|
118
|
+
ppsrc++;
|
119
|
+
ppdst++;
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
SDL_UnlockSurface(src.surface);
|
124
|
+
SDL_UnlockSurface(dst.surface);
|
125
|
+
|
126
|
+
return vdst;
|
127
|
+
}
|
128
|
+
|
129
|
+
/*
|
130
|
+
2つの画像のandを取る
|
131
|
+
*/
|
132
|
+
static VALUE bitmap_miyako_blit_and(VALUE self, VALUE vsrc, VALUE vdst)
|
133
|
+
{
|
134
|
+
MiyakoBitmap src, dst;
|
135
|
+
MiyakoSize size;
|
136
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
137
|
+
|
138
|
+
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
139
|
+
|
140
|
+
if(_miyako_init_rect(&src, &dst, &size) == 0) return Qnil;
|
141
|
+
|
142
|
+
SDL_LockSurface(src.surface);
|
143
|
+
SDL_LockSurface(dst.surface);
|
144
|
+
|
145
|
+
int x, y;
|
146
|
+
for(y = 0; y < size.h; y++)
|
147
|
+
{
|
148
|
+
Uint32 *ppsrc = src.ptr + (src.rect.y + y) * src.surface->w + src.rect.x;
|
149
|
+
Uint32 *ppdst = dst.ptr + (dst.rect.y + src.y + y) * dst.surface->w + dst.rect.x + src.x;
|
150
|
+
for(x = 0; x < size.w; x++)
|
151
|
+
{
|
152
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
153
|
+
src.color.a = (*ppsrc >> 24) & 0xff | src.a255;
|
154
|
+
dst.color.a = (*ppdst >> 24) & 0xff | dst.a255;
|
155
|
+
#else
|
156
|
+
src.color.a = (*ppsrc & src.fmt->Amask) | src.a255;
|
157
|
+
dst.color.a = (*ppdst & dst.fmt->Amask) | dst.a255;
|
158
|
+
#endif
|
159
|
+
if(src.color.a == 0){ ppsrc++; ppdst++; continue; }
|
160
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
161
|
+
*ppdst = (*ppdst | (dst.a255 << 24)) & (*ppsrc | (src.a255 << 24));
|
162
|
+
#else
|
163
|
+
*ppdst = (*ppdst | dst.a255) & (*ppsrc | src.a255);
|
164
|
+
#endif
|
165
|
+
ppsrc++;
|
166
|
+
ppdst++;
|
167
|
+
}
|
168
|
+
}
|
169
|
+
|
170
|
+
SDL_UnlockSurface(src.surface);
|
171
|
+
SDL_UnlockSurface(dst.surface);
|
172
|
+
|
173
|
+
return vdst;
|
174
|
+
}
|
175
|
+
|
176
|
+
|
177
|
+
/*
|
178
|
+
2つの画像のorを取り、別の画像へ転送する
|
179
|
+
*/
|
180
|
+
static VALUE bitmap_miyako_blit_or(VALUE self, VALUE vsrc, VALUE vdst)
|
181
|
+
{
|
182
|
+
MiyakoBitmap src, dst;
|
183
|
+
MiyakoSize size;
|
184
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
185
|
+
|
186
|
+
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
187
|
+
|
188
|
+
if(_miyako_init_rect(&src, &dst, &size) == 0) return Qnil;
|
189
|
+
|
190
|
+
SDL_LockSurface(src.surface);
|
191
|
+
SDL_LockSurface(dst.surface);
|
192
|
+
|
193
|
+
int x, y;
|
194
|
+
for(y = 0; y < size.h; y++)
|
195
|
+
{
|
196
|
+
Uint32 *ppsrc = src.ptr + (src.rect.y + y) * src.surface->w + src.rect.x;
|
197
|
+
Uint32 *ppdst = dst.ptr + (dst.rect.y + src.y + y) * dst.surface->w + dst.rect.x + src.x;
|
198
|
+
for(x = 0; x < size.w; x++)
|
199
|
+
{
|
200
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
201
|
+
src.color.a = (*ppsrc >> 24) & 0xff | src.a255;
|
202
|
+
dst.color.a = (*ppdst >> 24) & 0xff | dst.a255;
|
203
|
+
#else
|
204
|
+
src.color.a = (*ppsrc & src.fmt->Amask) | src.a255;
|
205
|
+
dst.color.a = (*ppdst & dst.fmt->Amask) | dst.a255;
|
206
|
+
#endif
|
207
|
+
if(src.color.a == 0){ ppsrc++; ppdst++; continue; }
|
208
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
209
|
+
*ppdst = (*ppdst | (dst.a255 << 24)) | (*ppsrc | (src.a255 << 24));
|
210
|
+
#else
|
211
|
+
*ppdst = (*ppdst | dst.a255) \ (*ppsrc | src.a255);
|
212
|
+
#endif
|
213
|
+
ppsrc++;
|
214
|
+
ppdst++;
|
215
|
+
}
|
216
|
+
}
|
217
|
+
|
218
|
+
SDL_UnlockSurface(src.surface);
|
219
|
+
SDL_UnlockSurface(dst.surface);
|
220
|
+
|
221
|
+
return vdst;
|
222
|
+
}
|
223
|
+
|
224
|
+
|
225
|
+
/*
|
226
|
+
2つの画像のxorを取り、別の画像へ転送する
|
227
|
+
*/
|
228
|
+
static VALUE bitmap_miyako_blit_xor(VALUE self, VALUE vsrc, VALUE vdst)
|
229
|
+
{
|
230
|
+
MiyakoBitmap src, dst;
|
231
|
+
MiyakoSize size;
|
232
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
233
|
+
|
234
|
+
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
235
|
+
|
236
|
+
if(_miyako_init_rect(&src, &dst, &size) == 0) return Qnil;
|
237
|
+
|
238
|
+
SDL_LockSurface(src.surface);
|
239
|
+
SDL_LockSurface(dst.surface);
|
240
|
+
|
241
|
+
int x, y;
|
242
|
+
for(y = 0; y < size.h; y++)
|
243
|
+
{
|
244
|
+
Uint32 *ppsrc = src.ptr + (src.rect.y + y) * src.surface->w + src.rect.x;
|
245
|
+
Uint32 *ppdst = dst.ptr + (dst.rect.y + src.y + y) * dst.surface->w + dst.rect.x + src.x;
|
246
|
+
for(x = 0; x < size.w; x++)
|
247
|
+
{
|
248
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
249
|
+
src.color.a = (*ppsrc >> 24) & 0xff | src.a255;
|
250
|
+
dst.color.a = (*ppdst >> 24) & 0xff | dst.a255;
|
251
|
+
#else
|
252
|
+
src.color.a = (*ppsrc & src.fmt->Amask) | src.a255;
|
253
|
+
dst.color.a = (*ppdst & dst.fmt->Amask) | dst.a255;
|
254
|
+
#endif
|
255
|
+
if(src.color.a == 0){ ppsrc++; ppdst++; continue; }
|
256
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
257
|
+
*ppdst = (*ppdst | (dst.a255 << 24)) ^ (*ppsrc | (src.a255 << 24));
|
258
|
+
#else
|
259
|
+
*ppdst = (*ppdst | dst.a255) ^ (*ppsrc | src.a255);
|
260
|
+
#endif
|
261
|
+
ppsrc++;
|
262
|
+
ppdst++;
|
263
|
+
}
|
264
|
+
}
|
265
|
+
|
266
|
+
SDL_UnlockSurface(src.surface);
|
267
|
+
SDL_UnlockSurface(dst.surface);
|
268
|
+
|
269
|
+
return vdst;
|
270
|
+
}
|
271
|
+
|
272
|
+
/*
|
273
|
+
画像をαチャネル付き画像へ転送する
|
274
|
+
*/
|
275
|
+
static VALUE bitmap_miyako_colorkey_to_alphachannel(VALUE self, VALUE vsrc, VALUE vdst, VALUE vcolor_key)
|
276
|
+
{
|
277
|
+
MiyakoBitmap src, dst;
|
278
|
+
MiyakoSize size;
|
279
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
280
|
+
MiyakoColor color_key;
|
281
|
+
|
282
|
+
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
283
|
+
|
284
|
+
if(_miyako_init_rect(&src, &dst, &size) == 0) return Qnil;
|
285
|
+
|
286
|
+
color_key.r = NUM2INT(*(RARRAY_PTR(vcolor_key) + 0));
|
287
|
+
color_key.g = NUM2INT(*(RARRAY_PTR(vcolor_key) + 1));
|
288
|
+
color_key.b = NUM2INT(*(RARRAY_PTR(vcolor_key) + 2));
|
289
|
+
|
290
|
+
SDL_LockSurface(src.surface);
|
291
|
+
SDL_LockSurface(dst.surface);
|
292
|
+
|
293
|
+
int x, y;
|
294
|
+
for(y = 0; y < size.h; y++)
|
295
|
+
{
|
296
|
+
Uint32 *ppsrc = src.ptr + (src.rect.y + y) * src.surface->w + src.rect.x;
|
297
|
+
Uint32 *ppdst = dst.ptr + (dst.rect.y + src.y + y) * dst.surface->w + dst.rect.x + src.x;
|
298
|
+
for(x = 0; x < size.w; x++)
|
299
|
+
{
|
300
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
301
|
+
src.color.r = (*ppsrc >> 16) & 0xff;
|
302
|
+
src.color.g = (*ppsrc >> 8) & 0xff;
|
303
|
+
src.color.b = (*ppsrc ) & 0xff;
|
304
|
+
if(src.color.r == color_key.r && src.color.g == color_key.g && src.color.b == color_key.b) *ppdst = 0;
|
305
|
+
else *ppdst = *ppsrc | (0xff << 24);
|
306
|
+
#else
|
307
|
+
src.color.r = (*ppsrc & src.fmt->Rmask) >> src.fmt->Rshift;
|
308
|
+
src.color.g = (*ppsrc & src.fmt->Gmask) >> src.fmt->Gshift;
|
309
|
+
src.color.b = (*ppsrc & src.fmt->Bmask) >> src.fmt->Bshift;
|
310
|
+
if(src.color.r == color_key.r && src.color.g == color_key.g && src.color.b == color_key.b) *ppdst = 0;
|
311
|
+
else *ppdst = *ppsrc | 0xff;
|
312
|
+
#endif
|
313
|
+
ppsrc++;
|
314
|
+
ppdst++;
|
315
|
+
}
|
316
|
+
}
|
317
|
+
|
318
|
+
SDL_UnlockSurface(src.surface);
|
319
|
+
SDL_UnlockSurface(dst.surface);
|
320
|
+
|
321
|
+
return vdst;
|
322
|
+
}
|
323
|
+
|
324
|
+
/*
|
325
|
+
画像のαチャネルを255に拡張する
|
326
|
+
*/
|
327
|
+
static VALUE bitmap_miyako_reset_alphachannel(VALUE self, VALUE vsrc, VALUE vdst)
|
328
|
+
{
|
329
|
+
MiyakoBitmap src, dst;
|
330
|
+
MiyakoSize size;
|
331
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
332
|
+
|
333
|
+
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
334
|
+
|
335
|
+
if(_miyako_init_rect(&src, &dst, &size) == 0) return Qnil;
|
336
|
+
|
337
|
+
SDL_LockSurface(src.surface);
|
338
|
+
SDL_LockSurface(dst.surface);
|
339
|
+
|
340
|
+
int x, y;
|
341
|
+
for(y = 0; y < size.h; y++)
|
342
|
+
{
|
343
|
+
Uint32 *ppsrc = src.ptr + (src.rect.y + y) * src.surface->w + src.rect.x;
|
344
|
+
Uint32 *ppdst = dst.ptr + (dst.rect.y + src.y + y) * dst.surface->w + dst.rect.x + src.x;
|
345
|
+
for(x = 0; x < size.w; x++)
|
346
|
+
{
|
347
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
348
|
+
*ppdst = *ppsrc | (0xff << 24);
|
349
|
+
#else
|
350
|
+
*ppdst = *ppsrc | 0xff;
|
351
|
+
#endif
|
352
|
+
ppsrc++;
|
353
|
+
ppdst++;
|
354
|
+
}
|
355
|
+
}
|
356
|
+
|
357
|
+
SDL_UnlockSurface(src.surface);
|
358
|
+
SDL_UnlockSurface(dst.surface);
|
359
|
+
|
360
|
+
return vdst;
|
361
|
+
}
|
362
|
+
|
363
|
+
/*
|
364
|
+
画像をαチャネル付き画像へ転送する
|
365
|
+
*/
|
366
|
+
static VALUE bitmap_miyako_colorkey_to_alphachannel_self(VALUE self, VALUE vdst, VALUE vcolor_key)
|
367
|
+
{
|
368
|
+
MiyakoBitmap dst;
|
369
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
370
|
+
MiyakoColor color_key;
|
371
|
+
|
372
|
+
_miyako_setup_unit(vdst, scr, &dst, Qnil, Qnil, 1);
|
373
|
+
|
374
|
+
color_key.r = NUM2INT(*(RARRAY_PTR(vcolor_key) + 0));
|
375
|
+
color_key.g = NUM2INT(*(RARRAY_PTR(vcolor_key) + 1));
|
376
|
+
color_key.b = NUM2INT(*(RARRAY_PTR(vcolor_key) + 2));
|
377
|
+
|
378
|
+
SDL_LockSurface(dst.surface);
|
379
|
+
|
380
|
+
int x, y;
|
381
|
+
for(y = 0; y < dst.rect.h; y++)
|
382
|
+
{
|
383
|
+
Uint32 *ppdst = dst.ptr + (dst.rect.y + y) * dst.surface->w + dst.rect.x;
|
384
|
+
for(x = 0; x < dst.rect.w; x++)
|
385
|
+
{
|
386
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
387
|
+
dst.color.r = (*ppdst >> 16) & 0xff;
|
388
|
+
dst.color.g = (*ppdst >> 8) & 0xff;
|
389
|
+
dst.color.b = (*ppdst ) & 0xff;
|
390
|
+
if(dst.color.r == color_key.r && dst.color.g == color_key.g && dst.color.b == color_key.b) *ppdst = 0;
|
391
|
+
else *ppdst = *ppdst | (0xff << 24);
|
392
|
+
#else
|
393
|
+
dst.color.r = (*ppdst & dst.fmt->Rmask) >> dst.fmt->Rshift;
|
394
|
+
dst.color.g = (*ppdst & dst.fmt->Gmask) >> dst.fmt->Gshift;
|
395
|
+
dst.color.b = (*ppdst & dst.fmt->Bmask) >> dst.fmt->Bshift;
|
396
|
+
if(dst.color.r == color_key.r && dst.color.g == color_key.g && dst.color.b == color_key.b) *ppdst = 0;
|
397
|
+
else *ppdst = *ppdst | 0xff;
|
398
|
+
#endif
|
399
|
+
ppdst++;
|
400
|
+
}
|
401
|
+
}
|
402
|
+
|
403
|
+
SDL_UnlockSurface(dst.surface);
|
404
|
+
|
405
|
+
return vdst;
|
406
|
+
}
|
407
|
+
|
408
|
+
/*
|
409
|
+
画像のαチャネルを255に拡張する
|
410
|
+
*/
|
411
|
+
static VALUE bitmap_miyako_reset_alphachannel_self(VALUE self, VALUE vdst)
|
412
|
+
{
|
413
|
+
MiyakoBitmap dst;
|
414
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
415
|
+
|
416
|
+
_miyako_setup_unit(vdst, scr, &dst, Qnil, Qnil, 1);
|
417
|
+
|
418
|
+
SDL_LockSurface(dst.surface);
|
419
|
+
|
420
|
+
int x, y;
|
421
|
+
for(y = 0; y < dst.rect.h; y++)
|
422
|
+
{
|
423
|
+
Uint32 *ppdst = dst.ptr + (dst.rect.y + y) * dst.surface->w + dst.rect.x;
|
424
|
+
for(x = 0; x < dst.rect.w; x++)
|
425
|
+
{
|
426
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
427
|
+
*ppdst = *ppdst | 0xff << 24;
|
428
|
+
#else
|
429
|
+
*ppdst = *ppdst | 0xff;
|
430
|
+
#endif
|
431
|
+
ppdst++;
|
432
|
+
}
|
433
|
+
}
|
434
|
+
|
435
|
+
SDL_UnlockSurface(dst.surface);
|
436
|
+
|
437
|
+
return vdst;
|
438
|
+
}
|
439
|
+
|
440
|
+
/*
|
441
|
+
画像のαチャネルの値を一定の割合で変化させて転送する
|
442
|
+
*/
|
443
|
+
static VALUE bitmap_miyako_dec_alpha(VALUE self, VALUE vsrc, VALUE vdst, VALUE degree)
|
444
|
+
{
|
445
|
+
MiyakoBitmap src, dst;
|
446
|
+
MiyakoSize size;
|
447
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
448
|
+
|
449
|
+
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
450
|
+
|
451
|
+
if(_miyako_init_rect(&src, &dst, &size) == 0) return Qnil;
|
452
|
+
|
453
|
+
double deg = NUM2DBL(degree);
|
454
|
+
if(deg < -1.0 || deg > 1.0){
|
455
|
+
char buf[256];
|
456
|
+
sprintf(buf, "Illegal degree! : %.15g", deg);
|
457
|
+
rb_raise(eMiyakoError, buf);
|
458
|
+
}
|
459
|
+
deg = 1.0 - deg;
|
460
|
+
Uint32 da = (Uint32)(255.0 * deg);
|
461
|
+
|
462
|
+
SDL_LockSurface(src.surface);
|
463
|
+
SDL_LockSurface(dst.surface);
|
464
|
+
|
465
|
+
int x, y;
|
466
|
+
for(y = 0; y < size.h; y++)
|
467
|
+
{
|
468
|
+
Uint32 *ppsrc = src.ptr + (src.rect.y + y) * src.surface->w + src.rect.x;
|
469
|
+
Uint32 *ppdst = dst.ptr + (dst.rect.y + src.y + y) * dst.surface->w + dst.rect.x + src.x;
|
470
|
+
for(x = 0; x < size.w; x++)
|
471
|
+
{
|
472
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
473
|
+
src.color.r = (*ppsrc >> 16) & 0xff;
|
474
|
+
src.color.g = (*ppsrc >> 8) & 0xff;
|
475
|
+
src.color.b = (*ppsrc ) & 0xff;
|
476
|
+
src.color.a = (*ppsrc >> 24) & 0xff | src.a255;
|
477
|
+
src.color.a -= da;
|
478
|
+
if(src.color.a > 0x80000000){ src.color.a = 0; }
|
479
|
+
if(src.color.a > 255){ src.color.a = 255; }
|
480
|
+
dst.color.a = (*ppdst >> 24) & 0xff | dst.a255;
|
481
|
+
if(dst.color.a == 0 || src.color.a == 255){
|
482
|
+
*ppdst = src.color.r << 16 |
|
483
|
+
src.color.g << 8 |
|
484
|
+
src.color.b |
|
485
|
+
src.color.a << 24;
|
486
|
+
ppsrc++;
|
487
|
+
ppdst++;
|
488
|
+
continue;
|
489
|
+
}
|
490
|
+
dst.color.r = (*ppdst >> 16) & 0xff;
|
491
|
+
dst.color.g = (*ppdst >> 8) & 0xff;
|
492
|
+
dst.color.b = (*ppdst ) & 0xff;
|
493
|
+
int a1 = src.color.a + 1;
|
494
|
+
int a2 = 256 - src.color.a;
|
495
|
+
*ppdst = ((src.color.r * a1 + dst.color.r * a2) >> 8) << 16 |
|
496
|
+
((src.color.g * a1 + dst.color.g * a2) >> 8) << 8 |
|
497
|
+
((src.color.b * a1 + dst.color.b * a2) >> 8) |
|
498
|
+
(0xff) << 24;
|
499
|
+
#else
|
500
|
+
src.color.r = (*ppsrc & src.fmt->Rmask) >> src.fmt->Rshift;
|
501
|
+
src.color.g = (*ppsrc & src.fmt->Gmask) >> src.fmt->Gshift;
|
502
|
+
src.color.b = (*ppsrc & src.fmt->Bmask) >> src.fmt->Bshift;
|
503
|
+
src.color.a = (*ppsrc & src.fmt->Amask) | src.a255;
|
504
|
+
src.color.a -= da;
|
505
|
+
if(src.color.a > 0x80000000){ src.color.a = 0; }
|
506
|
+
if(src.color.a > 255){ src.color.a = 255; }
|
507
|
+
dst.color.a = (*pdst & dst.fmt->Amask) | dst.a255;
|
508
|
+
if(dst.color.a == 0 || src.color.a == 255){
|
509
|
+
*ppdst = src.color.r << dst.fmt->Rshift |
|
510
|
+
src.color.g << dst.fmt->Gshift |
|
511
|
+
src.color.b << dst.fmt->Bshift |
|
512
|
+
src.color.a;
|
513
|
+
ppsrc++;
|
514
|
+
ppdst++;
|
515
|
+
continue;
|
516
|
+
}
|
517
|
+
int a1 = src.color.a + 1;
|
518
|
+
int a2 = 256 - src.color.a;
|
519
|
+
*ppdst = ((src.color.r * a1 + dst.color.r * a2) >> 8) << dst.fmt->Rshift |
|
520
|
+
((src.color.g * a1 + dst.color.g * a2) >> 8) << dst.fmt->Gshift |
|
521
|
+
((src.color.b * a1 + dst.color.b * a2) >> 8) << dst.fmt->Bshift |
|
522
|
+
0xff;
|
523
|
+
#endif
|
524
|
+
ppsrc++;
|
525
|
+
ppdst++;
|
526
|
+
}
|
527
|
+
}
|
528
|
+
|
529
|
+
SDL_UnlockSurface(src.surface);
|
530
|
+
SDL_UnlockSurface(dst.surface);
|
531
|
+
|
532
|
+
return vdst;
|
533
|
+
}
|
534
|
+
|
535
|
+
/*
|
536
|
+
画像の色を一定の割合で黒に近づける(ブラックアウト)
|
537
|
+
*/
|
538
|
+
static VALUE bitmap_miyako_black_out(VALUE self, VALUE vsrc, VALUE vdst, VALUE degree)
|
539
|
+
{
|
540
|
+
MiyakoBitmap src, dst;
|
541
|
+
MiyakoSize size;
|
542
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
543
|
+
|
544
|
+
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
545
|
+
|
546
|
+
if(_miyako_init_rect(&src, &dst, &size) == 0) return Qnil;
|
547
|
+
|
548
|
+
double deg = NUM2DBL(degree);
|
549
|
+
if(deg < -1.0 || deg > 1.0){
|
550
|
+
char buf[256];
|
551
|
+
sprintf(buf, "Illegal degree! : %.15g", deg);
|
552
|
+
rb_raise(eMiyakoError, buf);
|
553
|
+
}
|
554
|
+
deg = 1.0 - deg;
|
555
|
+
Uint32 d = (Uint32)(255.0 * deg);
|
556
|
+
|
557
|
+
SDL_LockSurface(src.surface);
|
558
|
+
SDL_LockSurface(dst.surface);
|
559
|
+
|
560
|
+
int x, y;
|
561
|
+
for(y = 0; y < size.h; y++)
|
562
|
+
{
|
563
|
+
Uint32 *ppsrc = src.ptr + (src.rect.y + y) * src.surface->w + src.rect.x;
|
564
|
+
Uint32 *ppdst = dst.ptr + (dst.rect.y + src.y + y) * dst.surface->w + dst.rect.x + src.x;
|
565
|
+
for(x = 0; x < size.w; x++)
|
566
|
+
{
|
567
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
568
|
+
src.color.r = (*ppsrc >> 16) & 0xff;
|
569
|
+
src.color.g = (*ppsrc >> 8) & 0xff;
|
570
|
+
src.color.b = (*ppsrc ) & 0xff;
|
571
|
+
src.color.a = (*ppsrc >> 24) & 0xff | src.a255;
|
572
|
+
src.color.r -= d;
|
573
|
+
if(src.color.r > 0x80000000){ src.color.r = 0; }
|
574
|
+
src.color.g -= d;
|
575
|
+
if(src.color.g > 0x80000000){ src.color.g = 0; }
|
576
|
+
src.color.b -= d;
|
577
|
+
if(src.color.b > 0x80000000){ src.color.b = 0; }
|
578
|
+
if(src.color.a != 0)
|
579
|
+
{
|
580
|
+
src.color.a -= d;
|
581
|
+
if(src.color.a > 0x80000000){ src.color.a = 0; }
|
582
|
+
}
|
583
|
+
dst.color.r = (*ppdst >> 16) & 0xff;
|
584
|
+
dst.color.g = (*ppdst >> 8) & 0xff;
|
585
|
+
dst.color.b = (*ppdst ) & 0xff;
|
586
|
+
dst.color.a = (*ppdst >> 24) & 0xff | dst.a255;
|
587
|
+
if(dst.color.a == 0 || src.color.a == 255){
|
588
|
+
*ppdst = src.color.r << 16 |
|
589
|
+
src.color.g << 8 |
|
590
|
+
src.color.b |
|
591
|
+
src.color.a << 24;
|
592
|
+
ppsrc++;
|
593
|
+
ppdst++;
|
594
|
+
continue;
|
595
|
+
}
|
596
|
+
int a1 = src.color.a + 1;
|
597
|
+
int a2 = 256 - src.color.a;
|
598
|
+
*ppdst = ((src.color.r * a1 + dst.color.r * a2) >> 8) << 16 |
|
599
|
+
((src.color.g * a1 + dst.color.g * a2) >> 8) << 8 |
|
600
|
+
((src.color.b * a1 + dst.color.b * a2) >> 8) |
|
601
|
+
(0xff) << 24;
|
602
|
+
#else
|
603
|
+
src.color.r = (*ppsrc & src.fmt->Rmask) >> src.fmt->Rshift;
|
604
|
+
src.color.g = (*ppsrc & src.fmt->Gmask) >> src.fmt->Gshift;
|
605
|
+
src.color.b = (*ppsrc & src.fmt->Bmask) >> src.fmt->Bshift;
|
606
|
+
src.color.a = (*ppsrc & src.fmt->Amask) | src.a255;
|
607
|
+
src.color.r -= d;
|
608
|
+
if(src.color.r > 0x80000000){ src.color.r = 0; }
|
609
|
+
src.color.g -= d;
|
610
|
+
if(src.color.g > 0x80000000){ src.color.g = 0; }
|
611
|
+
src.color.b -= d;
|
612
|
+
if(src.color.b > 0x80000000){ src.color.b = 0; }
|
613
|
+
if(src.color.a != 0)
|
614
|
+
{
|
615
|
+
src.color.a -= d;
|
616
|
+
if(src.color.a > 0x80000000){ src.color.a = 0; }
|
617
|
+
}
|
618
|
+
dst.color.a = (*pdst & dst.fmt->Amask) | dst.a255;
|
619
|
+
if(dst.color.a == 0 || src.color.a == 255){
|
620
|
+
*ppdst = src.color.r << dst.fmt->Rshift |
|
621
|
+
src.color.g << dst.fmt->Gshift |
|
622
|
+
src.color.b << dst.fmt->Bshift |
|
623
|
+
src.color.a;
|
624
|
+
ppsrc++;
|
625
|
+
ppdst++;
|
626
|
+
continue;
|
627
|
+
}
|
628
|
+
int a1 = src.color.a + 1;
|
629
|
+
int a2 = 256 - src.color.a;
|
630
|
+
*ppdst = ((src.color.r * a1 + dst.color.r * a2) >> 8) << dst.fmt->Rshift |
|
631
|
+
((src.color.g * a1 + dst.color.g * a2) >> 8) << dst.fmt->Gshift |
|
632
|
+
((src.color.b * a1 + dst.color.b * a2) >> 8) << dst.fmt->Bshift |
|
633
|
+
0xff;
|
634
|
+
#endif
|
635
|
+
ppsrc++;
|
636
|
+
ppdst++;
|
637
|
+
}
|
638
|
+
}
|
639
|
+
|
640
|
+
SDL_UnlockSurface(src.surface);
|
641
|
+
SDL_UnlockSurface(dst.surface);
|
642
|
+
|
643
|
+
return vdst;
|
644
|
+
}
|
645
|
+
|
646
|
+
/*
|
647
|
+
画像の色を一定の割合で白に近づける(ホワイトアウト)
|
648
|
+
*/
|
649
|
+
static VALUE bitmap_miyako_white_out(VALUE self, VALUE vsrc, VALUE vdst, VALUE degree)
|
650
|
+
{
|
651
|
+
MiyakoBitmap src, dst;
|
652
|
+
MiyakoSize size;
|
653
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
654
|
+
|
655
|
+
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
656
|
+
|
657
|
+
if(_miyako_init_rect(&src, &dst, &size) == 0) return Qnil;
|
658
|
+
|
659
|
+
double deg = NUM2DBL(degree);
|
660
|
+
if(deg < -1.0 || deg > 1.0){
|
661
|
+
char buf[256];
|
662
|
+
sprintf(buf, "Illegal degree! : %.15g", deg);
|
663
|
+
rb_raise(eMiyakoError, buf);
|
664
|
+
}
|
665
|
+
deg = 1.0 - deg;
|
666
|
+
Uint32 d = (Uint32)(255.0 * deg);
|
667
|
+
|
668
|
+
SDL_LockSurface(src.surface);
|
669
|
+
SDL_LockSurface(dst.surface);
|
670
|
+
|
671
|
+
int x, y;
|
672
|
+
for(y = 0; y < size.h; y++)
|
673
|
+
{
|
674
|
+
Uint32 *ppsrc = src.ptr + (src.rect.y + y) * src.surface->w + src.rect.x;
|
675
|
+
Uint32 *ppdst = dst.ptr + (dst.rect.y + src.y + y) * dst.surface->w + dst.rect.x + src.x;
|
676
|
+
for(x = 0; x < size.w; x++)
|
677
|
+
{
|
678
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
679
|
+
src.color.r = (*ppsrc >> 16) & 0xff;
|
680
|
+
src.color.g = (*ppsrc >> 8) & 0xff;
|
681
|
+
src.color.b = (*ppsrc ) & 0xff;
|
682
|
+
src.color.a = (*ppsrc >> 24) & 0xff | src.a255;
|
683
|
+
src.color.r += d;
|
684
|
+
if(src.color.r > 255){ src.color.r = 255; }
|
685
|
+
src.color.g += d;
|
686
|
+
if(src.color.g > 255){ src.color.g = 255; }
|
687
|
+
src.color.b += d;
|
688
|
+
if(src.color.b > 255){ src.color.b = 255; }
|
689
|
+
if(src.color.a != 0)
|
690
|
+
{
|
691
|
+
src.color.a += d;
|
692
|
+
if(src.color.a > 255){ src.color.a = 255; }
|
693
|
+
}
|
694
|
+
dst.color.r = (*ppdst >> 16) & 0xff;
|
695
|
+
dst.color.g = (*ppdst >> 8) & 0xff;
|
696
|
+
dst.color.b = (*ppdst ) & 0xff;
|
697
|
+
dst.color.a = (*ppdst >> 24) & 0xff | dst.a255;
|
698
|
+
if(dst.color.a == 0 || src.color.a == 255){
|
699
|
+
*ppdst = src.color.r << 16 |
|
700
|
+
src.color.g << 8 |
|
701
|
+
src.color.b |
|
702
|
+
src.color.a << 24;
|
703
|
+
ppsrc++;
|
704
|
+
ppdst++;
|
705
|
+
continue;
|
706
|
+
}
|
707
|
+
int a1 = src.color.a + 1;
|
708
|
+
int a2 = 256 - src.color.a;
|
709
|
+
*ppdst = ((src.color.r * a1 + dst.color.r * a2) >> 8) << 16 |
|
710
|
+
((src.color.g * a1 + dst.color.g * a2) >> 8) << 8 |
|
711
|
+
((src.color.b * a1 + dst.color.b * a2) >> 8) |
|
712
|
+
(0xff) << 24;
|
713
|
+
#else
|
714
|
+
src.color.r = (*ppsrc & src.fmt->Rmask) >> src.fmt->Rshift;
|
715
|
+
src.color.g = (*ppsrc & src.fmt->Gmask) >> src.fmt->Gshift;
|
716
|
+
src.color.b = (*ppsrc & src.fmt->Bmask) >> src.fmt->Bshift;
|
717
|
+
src.color.a = (*ppsrc & src.fmt->Amask) | src.a255;
|
718
|
+
src.color.r += d;
|
719
|
+
if(src.color.r > 255){ src.color.r = 255; }
|
720
|
+
src.color.g += d;
|
721
|
+
if(src.color.g > 255){ src.color.g = 255; }
|
722
|
+
src.color.b += d;
|
723
|
+
if(src.color.b > 255){ src.color.b = 255; }
|
724
|
+
if(src.color.a != 0)
|
725
|
+
{
|
726
|
+
src.color.a += d;
|
727
|
+
if(src.color.a > 255){ src.color.a = 255; }
|
728
|
+
}
|
729
|
+
dst.color.a = (*pdst & dst.fmt->Amask) | dst.a255;
|
730
|
+
if(dst.color.a == 0 || src.color.a == 255){
|
731
|
+
*ppdst = src.color.r << dst.fmt->Rshift |
|
732
|
+
src.color.g << dst.fmt->Gshift |
|
733
|
+
src.color.b << dst.fmt->Bshift |
|
734
|
+
src.color.a;
|
735
|
+
ppsrc++;
|
736
|
+
ppdst++;
|
737
|
+
continue;
|
738
|
+
}
|
739
|
+
int a1 = src.color.a + 1;
|
740
|
+
int a2 = 256 - src.color.a;
|
741
|
+
*ppdst = ((src.color.r * a1 + dst.color.r * a2) >> 8) << dst.fmt->Rshift |
|
742
|
+
((src.color.g * a1 + dst.color.g * a2) >> 8) << dst.fmt->Gshift |
|
743
|
+
((src.color.b * a1 + dst.color.b * a2) >> 8) << dst.fmt->Bshift |
|
744
|
+
0xff;
|
745
|
+
#endif
|
746
|
+
ppsrc++;
|
747
|
+
ppdst++;
|
748
|
+
}
|
749
|
+
}
|
750
|
+
|
751
|
+
SDL_UnlockSurface(src.surface);
|
752
|
+
SDL_UnlockSurface(dst.surface);
|
753
|
+
|
754
|
+
return vdst;
|
755
|
+
}
|
756
|
+
|
757
|
+
/*
|
758
|
+
画像のRGB値を反転させる
|
759
|
+
*/
|
760
|
+
static VALUE bitmap_miyako_inverse(VALUE self, VALUE vsrc, VALUE vdst)
|
761
|
+
{
|
762
|
+
MiyakoBitmap src, dst;
|
763
|
+
MiyakoSize size;
|
764
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
765
|
+
|
766
|
+
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
767
|
+
|
768
|
+
if(_miyako_init_rect(&src, &dst, &size) == 0) return Qnil;
|
769
|
+
|
770
|
+
SDL_LockSurface(src.surface);
|
771
|
+
SDL_LockSurface(dst.surface);
|
772
|
+
|
773
|
+
int x, y;
|
774
|
+
for(y = 0; y < size.h; y++)
|
775
|
+
{
|
776
|
+
Uint32 *ppsrc = src.ptr + (src.rect.y + y) * src.surface->w + src.rect.x;
|
777
|
+
Uint32 *ppdst = dst.ptr + (dst.rect.y + src.y + y) * dst.surface->w + dst.rect.x + src.x;
|
778
|
+
for(x = 0; x < size.w; x++)
|
779
|
+
{
|
780
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
781
|
+
src.color.a = (*ppsrc >> 24) & 0xff | src.a255;
|
782
|
+
if(src.color.a == 0){ ppsrc++; ppdst++; continue; }
|
783
|
+
src.color.r = (*ppsrc >> 16) & 0xff;
|
784
|
+
src.color.g = (*ppsrc >> 8) & 0xff;
|
785
|
+
src.color.b = (*ppsrc ) & 0xff;
|
786
|
+
dst.color.a = (*ppdst >> 24) & 0xff | dst.a255;
|
787
|
+
if(dst.color.a == 0 || src.color.a == 255){
|
788
|
+
*ppdst = (src.color.r ^ 0xff) << 16 |
|
789
|
+
(src.color.g ^ 0xff) << 8 |
|
790
|
+
(src.color.b ^ 0xff) |
|
791
|
+
(src.color.a ) << 24;
|
792
|
+
ppsrc++;
|
793
|
+
ppdst++;
|
794
|
+
continue;
|
795
|
+
}
|
796
|
+
dst.color.r = (*ppdst >> 16) & 0xff;
|
797
|
+
dst.color.g = (*ppdst >> 8) & 0xff;
|
798
|
+
dst.color.b = (*ppdst ) & 0xff;
|
799
|
+
int a1 = src.color.a + 1;
|
800
|
+
int a2 = 256 - src.color.a;
|
801
|
+
*ppdst = (((src.color.r ^ 0xff) * a1 + dst.color.r * a2) >> 8) << 16 |
|
802
|
+
(((src.color.g ^ 0xff) * a1 + dst.color.g * a2) >> 8) << 8 |
|
803
|
+
(((src.color.b ^ 0xff) * a1 + dst.color.b * a2) >> 8) |
|
804
|
+
(0xff ) << 24;
|
805
|
+
#else
|
806
|
+
src.color.r = (*ppsrc & src.fmt->Rmask) >> src.fmt->Rshift;
|
807
|
+
src.color.g = (*ppsrc & src.fmt->Gmask) >> src.fmt->Gshift;
|
808
|
+
src.color.b = (*ppsrc & src.fmt->Bmask) >> src.fmt->Bshift;
|
809
|
+
src.color.a = (*ppsrc & src.fmt->Amask) | src.a255;
|
810
|
+
dst.color.a = (*ppdst & dst.fmt->Amask) | dst.a255;
|
811
|
+
if(dst.color.a == 0 || src.color.a == 255){
|
812
|
+
*ppdst = (src.color.r ^ 0xff) << dst.fmt->Rshift |
|
813
|
+
(src.color.g ^ 0xff) << dst.fmt->Gshift |
|
814
|
+
(src.color.b ^ 0xff) << dst.fmt->Bshift |
|
815
|
+
src.color.a;
|
816
|
+
ppsrc++;
|
817
|
+
ppdst++;
|
818
|
+
continue;
|
819
|
+
}
|
820
|
+
int a1 = src.color.a + 1;
|
821
|
+
int a2 = 256 - src.color.a;
|
822
|
+
*ppdst = (((src.color.r ^ 0xff) * a1 + dst.color.r * a2) >> 8) << dst.fmt->Rshift |
|
823
|
+
(((src.color.g ^ 0xff) * a1 + dst.color.g * a2) >> 8) << dst.fmt->Gshift |
|
824
|
+
(((src.color.b ^ 0xff) * a1 + dst.color.b * a2) >> 8) << dst.fmt->Bshift |
|
825
|
+
0xff;
|
826
|
+
#endif
|
827
|
+
ppsrc++;
|
828
|
+
ppdst++;
|
829
|
+
}
|
830
|
+
}
|
831
|
+
|
832
|
+
SDL_UnlockSurface(src.surface);
|
833
|
+
SDL_UnlockSurface(dst.surface);
|
834
|
+
|
835
|
+
return vdst;
|
836
|
+
}
|
837
|
+
|
838
|
+
/*
|
839
|
+
画像のαチャネルの値を一定の割合で変化させて転送する
|
840
|
+
*/
|
841
|
+
static VALUE bitmap_miyako_dec_alpha_self(VALUE self, VALUE vdst, VALUE degree)
|
842
|
+
{
|
843
|
+
MiyakoBitmap dst;
|
844
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
845
|
+
|
846
|
+
_miyako_setup_unit(vdst, scr, &dst, Qnil, Qnil, 1);
|
847
|
+
|
848
|
+
double deg = NUM2DBL(degree);
|
849
|
+
if(deg < -1.0 || deg > 1.0){
|
850
|
+
char buf[256];
|
851
|
+
sprintf(buf, "Illegal degree! : %.15g", deg);
|
852
|
+
rb_raise(eMiyakoError, buf);
|
853
|
+
}
|
854
|
+
deg = 1.0 - deg;
|
855
|
+
Uint32 da = (Uint32)(255.0 * deg);
|
856
|
+
|
857
|
+
SDL_LockSurface(dst.surface);
|
858
|
+
|
859
|
+
int x, y;
|
860
|
+
for(y = 0; y < dst.rect.h; y++)
|
861
|
+
{
|
862
|
+
Uint32 *ppdst = dst.ptr + (dst.rect.y + y) * dst.surface->w + dst.rect.x;
|
863
|
+
for(x = 0; x < dst.rect.w; x++)
|
864
|
+
{
|
865
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
866
|
+
dst.color.r = (*ppdst >> 16) & 0xff;
|
867
|
+
dst.color.g = (*ppdst >> 8) & 0xff;
|
868
|
+
dst.color.b = (*ppdst ) & 0xff;
|
869
|
+
dst.color.a = (*ppdst >> 24) & 0xff | dst.a255;
|
870
|
+
dst.color.a -= da;
|
871
|
+
if(dst.color.a > 0x80000000){ dst.color.a = 0; }
|
872
|
+
if(dst.color.a > 255){ dst.color.a = 255; }
|
873
|
+
*ppdst = dst.color.r << 16 |
|
874
|
+
dst.color.g << 8 |
|
875
|
+
dst.color.b |
|
876
|
+
dst.color.a << 24;
|
877
|
+
#else
|
878
|
+
dst.color.r = (*ppdst & dst.fmt->Rmask) >> dst.fmt->Rshift;
|
879
|
+
dst.color.g = (*ppdst & dst.fmt->Gmask) >> dst.fmt->Gshift;
|
880
|
+
dst.color.b = (*ppdst & dst.fmt->Bmask) >> dst.fmt->Bshift;
|
881
|
+
dst.color.a = (*ppdst & dst.fmt->Amask) | dst.a255;
|
882
|
+
dst.color.a -= da;
|
883
|
+
if(dst.color.a > 0x80000000){ dst.color.a = 0; }
|
884
|
+
if(dst.color.a > 255){ dst.color.a = 255; }
|
885
|
+
*ppdst = dst.color.r << dst.fmt->Rshift |
|
886
|
+
dst.color.g << dst.fmt->Gshift |
|
887
|
+
dst.color.b << dst.fmt->Bshift |
|
888
|
+
dst.color.a;
|
889
|
+
#endif
|
890
|
+
ppdst++;
|
891
|
+
}
|
892
|
+
}
|
893
|
+
|
894
|
+
SDL_UnlockSurface(dst.surface);
|
895
|
+
|
896
|
+
return vdst;
|
897
|
+
}
|
898
|
+
|
899
|
+
/*
|
900
|
+
画像の色を一定の割合で黒に近づける(ブラックアウト)
|
901
|
+
*/
|
902
|
+
static VALUE bitmap_miyako_black_out_self(VALUE self, VALUE vdst, VALUE degree)
|
903
|
+
{
|
904
|
+
MiyakoBitmap dst;
|
905
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
906
|
+
|
907
|
+
_miyako_setup_unit(vdst, scr, &dst, Qnil, Qnil, 1);
|
908
|
+
|
909
|
+
double deg = NUM2DBL(degree);
|
910
|
+
if(deg < -1.0 || deg > 1.0){
|
911
|
+
char buf[256];
|
912
|
+
sprintf(buf, "Illegal degree! : %.15g", deg);
|
913
|
+
rb_raise(eMiyakoError, buf);
|
914
|
+
}
|
915
|
+
deg = 1.0 - deg;
|
916
|
+
Uint32 d = (Uint32)(255.0 * deg);
|
917
|
+
|
918
|
+
SDL_LockSurface(dst.surface);
|
919
|
+
|
920
|
+
int x, y;
|
921
|
+
for(y = 0; y < dst.rect.h; y++)
|
922
|
+
{
|
923
|
+
Uint32 *ppdst = dst.ptr + (dst.rect.y + y) * dst.surface->w + dst.rect.x;
|
924
|
+
for(x = 0; x < dst.rect.w; x++)
|
925
|
+
{
|
926
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
927
|
+
dst.color.r = (*ppdst >> 16) & 0xff;
|
928
|
+
dst.color.g = (*ppdst >> 8) & 0xff;
|
929
|
+
dst.color.b = (*ppdst ) & 0xff;
|
930
|
+
dst.color.a = (*ppdst >> 24) & 0xff | dst.a255;
|
931
|
+
dst.color.r -= d;
|
932
|
+
if(dst.color.r > 0x80000000){ dst.color.r = 0; }
|
933
|
+
dst.color.g -= d;
|
934
|
+
if(dst.color.g > 0x80000000){ dst.color.g = 0; }
|
935
|
+
dst.color.b -= d;
|
936
|
+
if(dst.color.b > 0x80000000){ dst.color.b = 0; }
|
937
|
+
if(dst.color.a != 0)
|
938
|
+
{
|
939
|
+
dst.color.a -= d;
|
940
|
+
if(dst.color.a > 0x80000000){ dst.color.a = 0; }
|
941
|
+
}
|
942
|
+
*ppdst = dst.color.r << 16 |
|
943
|
+
dst.color.g << 8 |
|
944
|
+
dst.color.b |
|
945
|
+
dst.color.a << 24;
|
946
|
+
#else
|
947
|
+
dst.color.r = (*ppdst & dst.fmt->Rmask) >> dst.fmt->Rshift;
|
948
|
+
dst.color.g = (*ppdst & dst.fmt->Gmask) >> dst.fmt->Gshift;
|
949
|
+
dst.color.b = (*ppdst & dst.fmt->Bmask) >> dst.fmt->Bshift;
|
950
|
+
dst.color.a = (*ppdst & dst.fmt->Amask) | dst.a255;
|
951
|
+
dst.color.r -= d;
|
952
|
+
if(dst.color.r > 0x80000000){ dst.color.r = 0; }
|
953
|
+
dst.color.g -= d;
|
954
|
+
if(dst.color.g > 0x80000000){ dst.color.g = 0; }
|
955
|
+
dst.color.b -= d;
|
956
|
+
if(dst.color.b > 0x80000000){ dst.color.b = 0; }
|
957
|
+
if(dst.color.a != 0)
|
958
|
+
{
|
959
|
+
dst.color.a -= d;
|
960
|
+
if(dst.color.a > 0x80000000){ dst.color.a = 0; }
|
961
|
+
}
|
962
|
+
*ppdst = dst.color.r << dst.fmt->Rshift |
|
963
|
+
dst.color.g << dst.fmt->Gshift |
|
964
|
+
dst.color.b << dst.fmt->Bshift |
|
965
|
+
dst.color.a;
|
966
|
+
#endif
|
967
|
+
ppdst++;
|
968
|
+
}
|
969
|
+
}
|
970
|
+
|
971
|
+
SDL_UnlockSurface(dst.surface);
|
972
|
+
|
973
|
+
return vdst;
|
974
|
+
}
|
975
|
+
|
976
|
+
/*
|
977
|
+
画像の色を一定の割合で白に近づける(ホワイトアウト)
|
978
|
+
*/
|
979
|
+
static VALUE bitmap_miyako_white_out_self(VALUE self, VALUE vdst, VALUE degree)
|
980
|
+
{
|
981
|
+
MiyakoBitmap dst;
|
982
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
983
|
+
|
984
|
+
_miyako_setup_unit(vdst, scr, &dst, Qnil, Qnil, 1);
|
985
|
+
|
986
|
+
double deg = NUM2DBL(degree);
|
987
|
+
if(deg < -1.0 || deg > 1.0){
|
988
|
+
char buf[256];
|
989
|
+
sprintf(buf, "Illegal degree! : %.15g", deg);
|
990
|
+
rb_raise(eMiyakoError, buf);
|
991
|
+
}
|
992
|
+
deg = 1.0 - deg;
|
993
|
+
Uint32 d = (Uint32)(255.0 * deg);
|
994
|
+
|
995
|
+
SDL_LockSurface(dst.surface);
|
996
|
+
|
997
|
+
int x, y;
|
998
|
+
for(y = 0; y < dst.rect.h; y++)
|
999
|
+
{
|
1000
|
+
Uint32 *ppdst = dst.ptr + (dst.rect.y + y) * dst.surface->w + dst.rect.x;
|
1001
|
+
for(x = 0; x < dst.rect.w; x++)
|
1002
|
+
{
|
1003
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
1004
|
+
dst.color.r = (*ppdst >> 16) & 0xff;
|
1005
|
+
dst.color.g = (*ppdst >> 8) & 0xff;
|
1006
|
+
dst.color.b = (*ppdst ) & 0xff;
|
1007
|
+
dst.color.a = (*ppdst >> 24) & 0xff | dst.a255;
|
1008
|
+
dst.color.r += d;
|
1009
|
+
if(dst.color.r > 255){ dst.color.r = 255; }
|
1010
|
+
dst.color.g += d;
|
1011
|
+
if(dst.color.g > 255){ dst.color.g = 255; }
|
1012
|
+
dst.color.b += d;
|
1013
|
+
if(dst.color.b > 255){ dst.color.b = 255; }
|
1014
|
+
if(dst.color.a != 0)
|
1015
|
+
{
|
1016
|
+
dst.color.a += d;
|
1017
|
+
if(dst.color.a > 255){ dst.color.a = 255; }
|
1018
|
+
}
|
1019
|
+
*ppdst = dst.color.r << 16 |
|
1020
|
+
dst.color.g << 8 |
|
1021
|
+
dst.color.b |
|
1022
|
+
dst.color.a << 24;
|
1023
|
+
#else
|
1024
|
+
dst.color.r = (*ppdst & dst.fmt->Rmask) >> dst.fmt->Rshift;
|
1025
|
+
dst.color.g = (*ppdst & dst.fmt->Gmask) >> dst.fmt->Gshift;
|
1026
|
+
dst.color.b = (*ppdst & dst.fmt->Bmask) >> dst.fmt->Bshift;
|
1027
|
+
dst.color.a = (*ppdst & dst.fmt->Amask) | dst.a255;
|
1028
|
+
dst.color.r += d;
|
1029
|
+
if(dst.color.r > 255){ dst.color.r = 255; }
|
1030
|
+
dst.color.g += d;
|
1031
|
+
if(dst.color.g > 255){ dst.color.g = 255; }
|
1032
|
+
dst.color.b += d;
|
1033
|
+
if(dst.color.b > 255){ dst.color.b = 255; }
|
1034
|
+
if(dst.color.a != 0)
|
1035
|
+
{
|
1036
|
+
dst.color.a += d;
|
1037
|
+
if(dst.color.a > 255){ dst.color.a = 255; }
|
1038
|
+
}
|
1039
|
+
*ppdst = dst.color.r << dst.fmt->Rshift |
|
1040
|
+
dst.color.g << dst.fmt->Gshift |
|
1041
|
+
dst.color.b << dst.fmt->Bshift |
|
1042
|
+
dst.color.a;
|
1043
|
+
#endif
|
1044
|
+
ppdst++;
|
1045
|
+
}
|
1046
|
+
}
|
1047
|
+
|
1048
|
+
SDL_UnlockSurface(dst.surface);
|
1049
|
+
|
1050
|
+
return vdst;
|
1051
|
+
}
|
1052
|
+
|
1053
|
+
/*
|
1054
|
+
画像のRGB値を反転させる
|
1055
|
+
*/
|
1056
|
+
static VALUE bitmap_miyako_inverse_self(VALUE self, VALUE vdst)
|
1057
|
+
{
|
1058
|
+
MiyakoBitmap dst;
|
1059
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
1060
|
+
|
1061
|
+
_miyako_setup_unit(vdst, scr, &dst, Qnil, Qnil, 1);
|
1062
|
+
|
1063
|
+
SDL_LockSurface(dst.surface);
|
1064
|
+
|
1065
|
+
int x, y;
|
1066
|
+
for(y = 0; y < dst.rect.h; y++)
|
1067
|
+
{
|
1068
|
+
Uint32 *ppdst = dst.ptr + (dst.rect.y + y) * dst.surface->w + dst.rect.x;
|
1069
|
+
for(x = 0; x < dst.rect.w; x++)
|
1070
|
+
{
|
1071
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
1072
|
+
dst.color.r = (*ppdst >> 16) & 0xff;
|
1073
|
+
dst.color.g = (*ppdst >> 8) & 0xff;
|
1074
|
+
dst.color.b = (*ppdst ) & 0xff;
|
1075
|
+
dst.color.a = (*ppdst >> 24) & 0xff | dst.a255;
|
1076
|
+
*ppdst = (dst.color.r ^ 0xff) << 16 |
|
1077
|
+
(dst.color.g ^ 0xff) << 8 |
|
1078
|
+
(dst.color.b ^ 0xff) |
|
1079
|
+
dst.color.a << 24;
|
1080
|
+
#else
|
1081
|
+
dst.color.r = (*ppdst & dst.fmt->Rmask) >> dst.fmt->Rshift;
|
1082
|
+
dst.color.g = (*ppdst & dst.fmt->Gmask) >> dst.fmt->Gshift;
|
1083
|
+
dst.color.b = (*ppdst & dst.fmt->Bmask) >> dst.fmt->Bshift;
|
1084
|
+
dst.color.a = (*ppdst & dst.fmt->Amask) | dst.a255;
|
1085
|
+
*ppdst = (dst.color.r ^ 0xff) << dst.fmt->Rshift |
|
1086
|
+
(dst.color.g ^ 0xff) << dst.fmt->Gshift |
|
1087
|
+
(dst.color.b ^ 0xff) << dst.fmt->Bshift |
|
1088
|
+
dst.color.a;
|
1089
|
+
#endif
|
1090
|
+
ppdst++;
|
1091
|
+
}
|
1092
|
+
}
|
1093
|
+
|
1094
|
+
SDL_UnlockSurface(dst.surface);
|
1095
|
+
|
1096
|
+
return vdst;
|
1097
|
+
}
|
1098
|
+
|
1099
|
+
/*
|
1100
|
+
2枚の画像の加算合成を行う
|
1101
|
+
*/
|
1102
|
+
static VALUE bitmap_miyako_additive_synthesis(VALUE self, VALUE vsrc, VALUE vdst)
|
1103
|
+
{
|
1104
|
+
MiyakoBitmap src, dst;
|
1105
|
+
MiyakoSize size;
|
1106
|
+
SDL_Surface *scr = GetSurface(rb_iv_get(mScreen, "@@screen"))->surface;
|
1107
|
+
|
1108
|
+
_miyako_setup_unit_2(vsrc, vdst, scr, &src, &dst, Qnil, Qnil, 1);
|
1109
|
+
|
1110
|
+
if(_miyako_init_rect(&src, &dst, &size) == 0) return Qnil;
|
1111
|
+
|
1112
|
+
SDL_LockSurface(src.surface);
|
1113
|
+
SDL_LockSurface(dst.surface);
|
1114
|
+
|
1115
|
+
int x, y;
|
1116
|
+
for(y = 0; y < size.h; y++)
|
1117
|
+
{
|
1118
|
+
Uint32 *ppsrc = src.ptr + (src.rect.y + y) * src.surface->w + src.rect.x;
|
1119
|
+
Uint32 *ppdst = dst.ptr + (dst.rect.y + src.y + y) * dst.surface->w + dst.rect.x + src.x;
|
1120
|
+
for(x = 0; x < size.w; x++)
|
1121
|
+
{
|
1122
|
+
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
1123
|
+
src.color.r = (*ppsrc >> 16) & 0xff;
|
1124
|
+
src.color.g = (*ppsrc >> 8) & 0xff;
|
1125
|
+
src.color.b = (*ppsrc ) & 0xff;
|
1126
|
+
src.color.a = (*ppsrc >> 24) & 0xff | src.a255;
|
1127
|
+
dst.color.r = (*ppdst >> 16) & 0xff;
|
1128
|
+
dst.color.g = (*ppdst >> 8) & 0xff;
|
1129
|
+
dst.color.b = (*ppdst ) & 0xff;
|
1130
|
+
dst.color.a = (*ppdst >> 24) & 0xff | dst.a255;
|
1131
|
+
dst.color.r += src.color.r;
|
1132
|
+
if(dst.color.r > 255){ dst.color.r = 255; }
|
1133
|
+
dst.color.g += src.color.g;
|
1134
|
+
if(dst.color.g > 255){ dst.color.g = 255; }
|
1135
|
+
dst.color.b += src.color.b;
|
1136
|
+
if(dst.color.b > 255){ dst.color.b = 255; }
|
1137
|
+
dst.color.a = (dst.color.a > src.color.a ? dst.color.a : src.color.a);
|
1138
|
+
*ppdst = dst.color.r << 16 |
|
1139
|
+
dst.color.g << 8 |
|
1140
|
+
dst.color.b |
|
1141
|
+
dst.color.a << 24;
|
1142
|
+
#else
|
1143
|
+
src.color.r = (*ppsrc & src.fmt->Rmask) >> src.fmt->Rshift;
|
1144
|
+
src.color.g = (*ppsrc & src.fmt->Gmask) >> src.fmt->Gshift;
|
1145
|
+
src.color.b = (*ppsrc & src.fmt->Bmask) >> src.fmt->Bshift;
|
1146
|
+
src.color.a = (*ppsrc & src.fmt->Amask) | src.a255;
|
1147
|
+
dst.color.r = (*ppdst & dst.fmt->Rmask) >> dst.fmt->Rshift;
|
1148
|
+
dst.color.g = (*ppdst & dst.fmt->Gmask) >> dst.fmt->Gshift;
|
1149
|
+
dst.color.b = (*ppdst & dst.fmt->Bmask) >> dst.fmt->Bshift;
|
1150
|
+
dst.color.a = (*ppdst & dst.fmt->Amask) | dst.a255;
|
1151
|
+
dst.color.r += src.color.r;
|
1152
|
+
if(dst.color.r > 255){ dst.color.r = 255; }
|
1153
|
+
dst.color.g += src.color.g;
|
1154
|
+
if(dst.color.g > 255){ dst.color.g = 255; }
|
1155
|
+
dst.color.b += src.color.b;
|
1156
|
+
if(dst.color.b > 255){ dst.color.b = 255; }
|
1157
|
+
dst.color.a = (dst.color.a > src.color.a ? dst.color.a : src.color.a);
|
1158
|
+
*ppdst = dst.color.r << dst.fmt->Rshift |
|
1159
|
+
dst.color.g << dst.fmt->Gshift |
|
1160
|
+
dst.color.b << dst.fmt->Bshift |
|
1161
|
+
dst.color.a;
|
1162
|
+
#endif
|
1163
|
+
ppsrc++;
|
1164
|
+
ppdst++;
|
1165
|
+
}
|
1166
|
+
}
|
1167
|
+
|
1168
|
+
SDL_UnlockSurface(src.surface);
|
1169
|
+
SDL_UnlockSurface(dst.surface);
|
1170
|
+
|
1171
|
+
return vdst;
|
1172
|
+
}
|
1173
|
+
|
1174
|
+
/*
|
1175
|
+
2枚の画像の減算合成を行う
|
1176
|
+
*/
|
1177
|
+
static VALUE bitmap_miyako_subtraction_synthesis(VALUE self, VALUE src, VALUE dst)
|
1178
|
+
{
|
1179
|
+
bitmap_miyako_inverse(self, dst, dst);
|
1180
|
+
bitmap_miyako_additive_synthesis(self, src, dst);
|
1181
|
+
bitmap_miyako_inverse(self, dst, dst);
|
1182
|
+
return dst;
|
1183
|
+
}
|
1184
|
+
|
1185
|
+
void Init_miyako_bitmap()
|
1186
|
+
{
|
1187
|
+
mSDL = rb_define_module("SDL");
|
1188
|
+
mMiyako = rb_define_module("Miyako");
|
1189
|
+
mScreen = rb_define_module_under(mMiyako, "Screen");
|
1190
|
+
eMiyakoError = rb_define_class_under(mMiyako, "MiyakoError", rb_eException);
|
1191
|
+
cSurface = rb_define_class_under(mSDL, "Surface", rb_cObject);
|
1192
|
+
cBitmap = rb_define_class_under(mMiyako, "Bitmap", rb_cObject);
|
1193
|
+
|
1194
|
+
id_update = rb_intern("update");
|
1195
|
+
id_kakko = rb_intern("[]");
|
1196
|
+
id_render = rb_intern("render");
|
1197
|
+
id_to_a = rb_intern("to_a");
|
1198
|
+
|
1199
|
+
zero = 0;
|
1200
|
+
nZero = INT2NUM(zero);
|
1201
|
+
one = 1;
|
1202
|
+
nOne = INT2NUM(one);
|
1203
|
+
|
1204
|
+
rb_define_singleton_method(cBitmap, "blit_aa", bitmap_miyako_blit_aa, 4);
|
1205
|
+
rb_define_singleton_method(cBitmap, "blit_and", bitmap_miyako_blit_and, 2);
|
1206
|
+
rb_define_singleton_method(cBitmap, "blit_or", bitmap_miyako_blit_or, 2);
|
1207
|
+
rb_define_singleton_method(cBitmap, "blit_xor", bitmap_miyako_blit_xor, 2);
|
1208
|
+
rb_define_singleton_method(cBitmap, "ck_to_ac", bitmap_miyako_colorkey_to_alphachannel, 3);
|
1209
|
+
rb_define_singleton_method(cBitmap, "reset_ac", bitmap_miyako_reset_alphachannel, 2);
|
1210
|
+
rb_define_singleton_method(cBitmap, "normal_to_ac", bitmap_miyako_reset_alphachannel, 2);
|
1211
|
+
rb_define_singleton_method(cBitmap, "screen_to_ac", bitmap_miyako_reset_alphachannel, 2);
|
1212
|
+
rb_define_singleton_method(cBitmap, "ck_to_ac!", bitmap_miyako_colorkey_to_alphachannel_self, 2);
|
1213
|
+
rb_define_singleton_method(cBitmap, "reset_ac!", bitmap_miyako_reset_alphachannel_self, 1);
|
1214
|
+
rb_define_singleton_method(cBitmap, "normal_to_ac!", bitmap_miyako_reset_alphachannel_self, 1);
|
1215
|
+
rb_define_singleton_method(cBitmap, "dec_alpha", bitmap_miyako_dec_alpha, 3);
|
1216
|
+
rb_define_singleton_method(cBitmap, "black_out", bitmap_miyako_black_out, 3);
|
1217
|
+
rb_define_singleton_method(cBitmap, "white_out", bitmap_miyako_white_out, 3);
|
1218
|
+
rb_define_singleton_method(cBitmap, "inverse", bitmap_miyako_inverse, 2);
|
1219
|
+
rb_define_singleton_method(cBitmap, "dec_alpha!", bitmap_miyako_dec_alpha_self, 2);
|
1220
|
+
rb_define_singleton_method(cBitmap, "black_out!", bitmap_miyako_black_out_self, 2);
|
1221
|
+
rb_define_singleton_method(cBitmap, "white_out!", bitmap_miyako_white_out_self, 2);
|
1222
|
+
rb_define_singleton_method(cBitmap, "inverse!", bitmap_miyako_inverse_self, 1);
|
1223
|
+
rb_define_singleton_method(cBitmap, "additive", bitmap_miyako_additive_synthesis, 2);
|
1224
|
+
rb_define_singleton_method(cBitmap, "subtraction", bitmap_miyako_subtraction_synthesis, 2);
|
1225
|
+
}
|