ruby-miyako 2.1.0

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