File: | home/HaikuArchives/ArtPaint/addons/AddOns/Wave/Wave.cpp |
Warning: | line 236, column 30 The right operand of '+' is a garbage value |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* | |||
2 | * Copyright 2003, Heikki Suhonen | |||
3 | * Distributed under the terms of the MIT License. | |||
4 | * | |||
5 | * Authors: | |||
6 | * Heikki Suhonen <heikki.suhonen@gmail.com> | |||
7 | * | |||
8 | */ | |||
9 | #include <Bitmap.h> | |||
10 | #include <Catalog.h> | |||
11 | #include <math.h> | |||
12 | #include <LayoutBuilder.h> | |||
13 | #include <Slider.h> | |||
14 | #include <StatusBar.h> | |||
15 | #include <StopWatch.h> | |||
16 | #include <Window.h> | |||
17 | ||||
18 | #include "AddOns.h" | |||
19 | #include "ManipulatorInformer.h" | |||
20 | #include "Wave.h" | |||
21 | #include "PixelOperations.h" | |||
22 | #include "Selection.h" | |||
23 | ||||
24 | #define PI3.14159265358979323846 M_PI3.14159265358979323846 | |||
25 | ||||
26 | #undef B_TRANSLATION_CONTEXT"AddOns_Wave" | |||
27 | #define B_TRANSLATION_CONTEXT"AddOns_Wave" "AddOns_Wave" | |||
28 | ||||
29 | ||||
30 | #ifdef __cplusplus201402L | |||
31 | extern "C" { | |||
32 | #endif | |||
33 | char name[255] = B_TRANSLATE_MARK("Wave" B_UTF8_ELLIPSIS)("Wave" "\xE2\x80\xA6"); | |||
34 | char menu_help_string[255] = B_TRANSLATE_MARK("Adds a wave to the active layer.")("Adds a wave to the active layer."); | |||
35 | int32 add_on_api_version = ADD_ON_API_VERSION; | |||
36 | add_on_types add_on_type = DISTORT_ADD_ON; | |||
37 | #ifdef __cplusplus201402L | |||
38 | } | |||
39 | #endif | |||
40 | ||||
41 | ||||
42 | Manipulator* instantiate_add_on(BBitmap *bm,ManipulatorInformer *i) | |||
43 | { | |||
44 | // Here create a view-manipulator. The class should inherit | |||
45 | // from WindowGuiManipulator base-class. It will be deleted | |||
46 | // in the application program. | |||
47 | delete i; | |||
48 | return new WaveManipulator(bm); | |||
49 | } | |||
50 | ||||
51 | ||||
52 | ||||
53 | WaveManipulator::WaveManipulator(BBitmap *bm) | |||
54 | : WindowGUIManipulator() | |||
55 | { | |||
56 | last_calculated_resolution = 8; | |||
57 | lowest_available_quality = 8; | |||
58 | ||||
59 | copy_of_the_preview_bitmap = NULL__null; | |||
60 | preview_bitmap = NULL__null; | |||
61 | config_view = NULL__null; | |||
62 | ||||
63 | SetPreviewBitmap(bm); | |||
64 | ||||
65 | sin_table = new float[720]; | |||
66 | for (int32 i=0;i<720;i++) | |||
67 | sin_table[i] = sin((float)i/720.0*2*PI3.14159265358979323846); | |||
68 | } | |||
69 | ||||
70 | ||||
71 | WaveManipulator::~WaveManipulator() | |||
72 | { | |||
73 | delete[] sin_table; | |||
74 | delete copy_of_the_preview_bitmap; | |||
75 | ||||
76 | if (config_view != NULL__null) { | |||
77 | config_view->RemoveSelf(); | |||
78 | delete config_view; | |||
79 | config_view = NULL__null; | |||
80 | } | |||
81 | } | |||
82 | ||||
83 | ||||
84 | BBitmap* WaveManipulator::ManipulateBitmap(ManipulatorSettings *set,BBitmap *original,Selection *selection,BStatusBar *status_bar) | |||
85 | { | |||
86 | WaveManipulatorSettings *new_settings = dynamic_cast<WaveManipulatorSettings*>(set); | |||
87 | ||||
88 | if (new_settings == NULL__null) | |||
| ||||
89 | return NULL__null; | |||
90 | ||||
91 | if (original == NULL__null) | |||
92 | return NULL__null; | |||
93 | ||||
94 | BBitmap *source_bitmap; | |||
95 | BBitmap *target_bitmap; | |||
96 | BBitmap *new_bitmap=NULL__null; | |||
97 | ||||
98 | if (original == preview_bitmap) { | |||
99 | target_bitmap = original; | |||
100 | source_bitmap = copy_of_the_preview_bitmap; | |||
101 | } | |||
102 | else { | |||
103 | target_bitmap = original; | |||
104 | new_bitmap = DuplicateBitmap(original,0); | |||
105 | source_bitmap = new_bitmap; | |||
106 | } | |||
107 | ||||
108 | ||||
109 | uint32 *source_bits = (uint32*)source_bitmap->Bits(); | |||
110 | uint32 *target_bits = (uint32*)target_bitmap->Bits(); | |||
111 | int32 source_bpr = source_bitmap->BytesPerRow()/4; | |||
112 | int32 target_bpr = target_bitmap->BytesPerRow()/4; | |||
113 | ||||
114 | int32 start_y = target_bitmap->Bounds().top; | |||
115 | int32 end_y = target_bitmap->Bounds().bottom; | |||
116 | ||||
117 | target_bits += start_y * target_bpr; | |||
118 | ||||
119 | BMessage progress_message = BMessage(B_UPDATE_STATUS_BAR); | |||
120 | progress_message.AddFloat("delta",0.0); | |||
121 | ||||
122 | float s = new_settings->wave_length; | |||
123 | float A = new_settings->wave_amount; | |||
124 | float k = 0; | |||
125 | float dx,dy; | |||
126 | float sqrt_x_plus_y; | |||
127 | float one_per_sqrt_x_plus_y; | |||
128 | float cx,cy; | |||
129 | int32 top,bottom; | |||
130 | top = start_y; | |||
131 | bottom = end_y; | |||
132 | ||||
133 | cx = floor(new_settings->center.x); | |||
134 | cy = floor(new_settings->center.y); | |||
135 | float R = sqrt(pow(max_c(fabs(cx),target_bpr-fabs(cx))((fabs(cx))>(target_bpr-fabs(cx))?(fabs(cx)):(target_bpr-fabs (cx))),2)+pow(max_c(fabs(cy),end_y-fabs(cy))((fabs(cy))>(end_y-fabs(cy))?(fabs(cy)):(end_y-fabs(cy))),2)); | |||
136 | float one_per_R = 1.0/R; | |||
137 | ||||
138 | float real_x,real_y; | |||
139 | float two_pi_per_s = 2*PI3.14159265358979323846/s; | |||
140 | float two_360_per_s = 720.0/s; | |||
141 | ||||
142 | union { | |||
143 | uint8 bytes[4]; | |||
144 | uint32 word; | |||
145 | } background; | |||
146 | ||||
147 | background.bytes[0] = 0xFF; | |||
148 | background.bytes[1] = 0xFF; | |||
149 | background.bytes[2] = 0xFF; | |||
150 | background.bytes[3] = 0x00; | |||
151 | ||||
152 | if ((selection == NULL__null) || (selection->IsEmpty())) { | |||
153 | uint32 p1,p2,p3,p4; | |||
154 | float float_end_y = end_y; | |||
155 | float float_target_bpr = target_bpr; | |||
156 | for (float y=start_y;y<=float_end_y;y++) { | |||
157 | for (float x=0;x<float_target_bpr;x++) { | |||
158 | real_x = x-cx; | |||
159 | real_y = y-cy; | |||
160 | uint32 target_value = 0x00000000; | |||
161 | if ((real_x != 0) && (real_y != 0)) { | |||
162 | sqrt_x_plus_y = sqrt(real_x*real_x+real_y*real_y); | |||
163 | dx = real_x/sqrt_x_plus_y*A*sin(sqrt_x_plus_y*two_pi_per_s); // The sin and div are slow. | |||
164 | dx = dx*(1-k*sqrt_x_plus_y*one_per_R); | |||
165 | dy = dx/real_x*real_y; | |||
166 | int32 ceil_y = ceil(y+dy); | |||
167 | int32 floor_y = ceil_y -1; | |||
168 | int32 floor_x = floor(x+dx); | |||
169 | int32 ceil_x = floor_x+1; | |||
170 | ||||
171 | float v = ceil_y-(y+dy); | |||
172 | float u = (x+dx)-floor_x; | |||
173 | if ((ceil_y <= bottom) && (ceil_y>=top)) { | |||
174 | if ((floor_x >= 0) && (floor_x <source_bpr)) { | |||
175 | p1 = *(source_bits + ceil_y*source_bpr + floor_x); | |||
176 | } | |||
177 | else | |||
178 | p1 = background.word; | |||
179 | ||||
180 | if ((ceil_x >= 0) && (ceil_x <source_bpr)) { | |||
181 | p2 = *(source_bits + ceil_y*source_bpr + ceil_x); | |||
182 | } | |||
183 | else | |||
184 | p2 = background.word; | |||
185 | } | |||
186 | else { | |||
187 | p1 = background.word; | |||
188 | p2 = background.word; | |||
189 | } | |||
190 | if ((floor_y <= bottom) && (floor_y>=top)) { | |||
191 | if ((floor_x >= 0) && (floor_x <source_bpr)) { | |||
192 | p3 = *(source_bits + floor_y*source_bpr + floor_x); | |||
193 | } | |||
194 | else | |||
195 | p3 = background.word; | |||
196 | ||||
197 | if ((ceil_x >= 0) && (ceil_x <source_bpr)) { | |||
198 | p4 = *(source_bits + floor_y*source_bpr + ceil_x); | |||
199 | } | |||
200 | else | |||
201 | p4 = background.word; | |||
202 | } | |||
203 | else { | |||
204 | p3 = background.word; | |||
205 | p4 = background.word; | |||
206 | } | |||
207 | *target_bits++ = bilinear_interpolation(p1,p2,p3,p4,u,v); | |||
208 | } | |||
209 | else { | |||
210 | if (real_x != 0) { | |||
211 | sqrt_x_plus_y = sqrt(real_x*real_x); | |||
212 | dx = real_x/sqrt_x_plus_y*A*sin(sqrt_x_plus_y*two_pi_per_s); | |||
213 | dx = dx*(1-k*sqrt_x_plus_y/R); | |||
214 | int32 ceil_y = ceil(y+dy); | |||
215 | int32 floor_y = ceil_y -1; | |||
216 | int32 floor_x = floor(x+dx); | |||
217 | int32 ceil_x = floor_x+1; | |||
218 | float x_mix_right = (x+dx)-floor_x; | |||
219 | if ((ceil_x >= 0) && (ceil_x<target_bpr)) | |||
220 | p1 = *(source_bits + (int32)y*target_bpr + ceil_x); | |||
221 | else | |||
222 | p1 = background.word; | |||
223 | ||||
224 | if ((floor_x >= 0) && (floor_x<target_bpr)) | |||
225 | p2 = *(source_bits + (int32)y*target_bpr + floor_x); | |||
226 | else | |||
227 | p2 = background.word; | |||
228 | *target_bits++ = mix_2_pixels_fixed(p1,p2,32768*x_mix_right); | |||
229 | } | |||
230 | else if (real_y != 0) { | |||
231 | sqrt_x_plus_y = sqrt(real_y*real_y); | |||
232 | dy = real_y/sqrt_x_plus_y*A*sin(sqrt_x_plus_y*two_pi_per_s); | |||
233 | dy = dy*(1-k*sqrt_x_plus_y/R); | |||
234 | int32 ceil_y = ceil(y+dy); | |||
235 | int32 floor_y = ceil_y -1; | |||
236 | int32 floor_x = floor(x+dx); | |||
| ||||
237 | int32 ceil_x = floor_x+1; | |||
238 | float y_mix_upper = ceil(y+dy)-(y+dy); | |||
239 | if ((ceil_y<=bottom) && (ceil_y >= top)) | |||
240 | p1 = *(source_bits + (int32)x + ceil_y*target_bpr); | |||
241 | else | |||
242 | p1 = background.word; | |||
243 | ||||
244 | if ((floor_y<=bottom) && (floor_y >= top)) | |||
245 | p2 = *(source_bits + (int32)x + floor_y*target_bpr); | |||
246 | else | |||
247 | p2 = background.word; | |||
248 | *target_bits++ = mix_2_pixels_fixed(p2,p1,32768*y_mix_upper); | |||
249 | } | |||
250 | else { | |||
251 | *target_bits++ = *(source_bits + (int32)x + (int32)y*source_bpr); | |||
252 | } | |||
253 | } | |||
254 | ||||
255 | } | |||
256 | // Send a progress-message if required | |||
257 | if ((status_bar != NULL__null) && ((int32)y%10 == 0)) { | |||
258 | progress_message.ReplaceFloat("delta",100.0/(float)(end_y-start_y)*10.0); | |||
259 | status_bar->Window()->PostMessage(&progress_message,status_bar); | |||
260 | } | |||
261 | } | |||
262 | } | |||
263 | else { | |||
264 | uint32 p1,p2,p3,p4; | |||
265 | for (float y=start_y;y<=end_y;y++) { | |||
266 | for (float x=0;x<target_bpr;x++) { | |||
267 | if (selection->ContainsPoint(x,y) == TRUE1) { | |||
268 | real_x = x-cx; | |||
269 | real_y = y-cy; | |||
270 | uint32 target_value = 0x00000000; | |||
271 | if ((real_x != 0) && (real_y != 0)) { | |||
272 | sqrt_x_plus_y = sqrt(real_x*real_x+real_y*real_y); | |||
273 | dx = real_x/sqrt_x_plus_y*A*sin(sqrt_x_plus_y*two_pi_per_s); // The sin and div are slow. | |||
274 | dx = dx*(1-k*sqrt_x_plus_y/R); | |||
275 | dy = dx/real_x*real_y; | |||
276 | float y_mix_upper = ceil(y+dy)-(y+dy); | |||
277 | float x_mix_right = (x+dx)- floor(x+dx); | |||
278 | if ((ceil(y+dy) <= bottom) && (ceil(y+dy)>=top)) { | |||
279 | if ((floor(x+dx) >= 0) && (floor(x+dx) <source_bpr)) { | |||
280 | p1 = *(source_bits + (int32)ceil(y+dy)*source_bpr + (int32)floor(x+dx)); | |||
281 | } | |||
282 | else | |||
283 | p1 = background.word; | |||
284 | ||||
285 | if ((ceil(x+dx) >= 0) && (ceil(x+dx) <source_bpr)) { | |||
286 | p2 = *(source_bits + (int32)ceil(y+dy)*source_bpr + (int32)ceil(x+dx)); | |||
287 | } | |||
288 | else | |||
289 | p2 = background.word; | |||
290 | } | |||
291 | else { | |||
292 | p1 = background.word; | |||
293 | p2 = background.word; | |||
294 | } | |||
295 | if ((floor(y+dy) <= bottom) && (floor(y+dy)>=top)) { | |||
296 | if ((floor(x+dx) >= 0) && (floor(x+dx) <source_bpr)) { | |||
297 | p3 = *(source_bits + (int32)floor(y+dy)*source_bpr + (int32)floor(x+dx)); | |||
298 | } | |||
299 | else | |||
300 | p3 = background.word; | |||
301 | ||||
302 | if ((ceil(x+dx) >= 0) && (ceil(x+dx) <source_bpr)) { | |||
303 | p4 = *(source_bits + (int32)floor(y+dy)*source_bpr + (int32)ceil(x+dx)); | |||
304 | } | |||
305 | else | |||
306 | p4 = background.word; | |||
307 | } | |||
308 | else { | |||
309 | p3 = background.word; | |||
310 | p4 = background.word; | |||
311 | } | |||
312 | *target_bits++ = combine_4_pixels(p1,p2,p3,p4,(1-y_mix_upper)*(1-x_mix_right),(1-y_mix_upper)*(x_mix_right),(y_mix_upper)*(1-x_mix_right),(y_mix_upper)*(x_mix_right)); | |||
313 | } | |||
314 | else { | |||
315 | if (real_x != 0) { | |||
316 | sqrt_x_plus_y = sqrt(real_x*real_x); | |||
317 | dx = real_x/sqrt_x_plus_y*A*sin(sqrt_x_plus_y*two_pi_per_s); | |||
318 | dx = dx*(1-k*sqrt_x_plus_y/R); | |||
319 | float x_mix_right = (x+dx)-floor(x+dx); | |||
320 | if ((ceil(x+dx) >= 0) && (ceil(x+dx)<target_bpr)) | |||
321 | p1 = *(source_bits + (int32)y*target_bpr + (int32)ceil((x +dx))); | |||
322 | else | |||
323 | p1 = background.word; | |||
324 | ||||
325 | if ((floor(x+dx) >= 0) && (floor(x+dx)<target_bpr)) | |||
326 | p2 = *(source_bits + (int32)y*target_bpr + (int32)floor((x +dx))); | |||
327 | else | |||
328 | p2 = background.word; | |||
329 | *target_bits++ = mix_2_pixels_fixed(p1,p2,32768*x_mix_right); | |||
330 | } | |||
331 | else if (real_y != 0) { | |||
332 | sqrt_x_plus_y = sqrt(real_y*real_y); | |||
333 | dy = real_y/sqrt_x_plus_y*A*sin(sqrt_x_plus_y*two_pi_per_s); | |||
334 | dy = dy*(1-k*sqrt_x_plus_y/R); | |||
335 | float y_mix_upper = ceil(y+dy)-(y+dy); | |||
336 | if ((ceil(y+dy)<=bottom) && (ceil(y+dy) >= top)) | |||
337 | p1 = *(source_bits + (int32)x + (int32)ceil((y + dy))*target_bpr); | |||
338 | else | |||
339 | p1 = background.word; | |||
340 | ||||
341 | if ((floor(y+dy)<=bottom) && (floor(y+dy) >= top)) | |||
342 | p2 = *(source_bits + (int32)x + (int32)floor((y + dy))*target_bpr); | |||
343 | else | |||
344 | p2 = background.word; | |||
345 | *target_bits++ = mix_2_pixels_fixed(p2,p1,32768*y_mix_upper); | |||
346 | } | |||
347 | else { | |||
348 | *target_bits++ = *(source_bits + (int32)x + (int32)y*source_bpr); | |||
349 | } | |||
350 | } | |||
351 | } | |||
352 | else { | |||
353 | *target_bits++ = *(source_bits + (int32)x + (int32)y*source_bpr); | |||
354 | } | |||
355 | } | |||
356 | // Send a progress-message if required | |||
357 | if ((status_bar != NULL__null) && ((int32)y%10 == 0)) { | |||
358 | progress_message.ReplaceFloat("delta",100.0/(float)(end_y-start_y)*10.0); | |||
359 | status_bar->Window()->PostMessage(&progress_message,status_bar); | |||
360 | } | |||
361 | } | |||
362 | } | |||
363 | ||||
364 | if (new_bitmap != NULL__null) { | |||
365 | delete new_bitmap; | |||
366 | } | |||
367 | ||||
368 | return original; | |||
369 | } | |||
370 | ||||
371 | int32 WaveManipulator::PreviewBitmap(Selection *selection,bool full_quality,BRegion *updated_region) | |||
372 | { | |||
373 | if ((settings == previous_settings) == FALSE0) { | |||
374 | previous_settings = settings; | |||
375 | last_calculated_resolution = lowest_available_quality; | |||
376 | } | |||
377 | else { | |||
378 | last_calculated_resolution = max_c(highest_available_quality,floor(last_calculated_resolution/2.0))((highest_available_quality)>(floor(last_calculated_resolution /2.0))?(highest_available_quality):(floor(last_calculated_resolution /2.0))); | |||
379 | } | |||
380 | if (full_quality == TRUE1) | |||
381 | last_calculated_resolution = min_c(last_calculated_resolution,1)((last_calculated_resolution)>(1)?(1):(last_calculated_resolution )); | |||
382 | ||||
383 | uint32 *source_bits = (uint32*)copy_of_the_preview_bitmap->Bits(); | |||
384 | uint32 *target_bits = (uint32*)preview_bitmap->Bits(); | |||
385 | int32 source_bpr = copy_of_the_preview_bitmap->BytesPerRow()/4; | |||
386 | int32 target_bpr = preview_bitmap->BytesPerRow()/4; | |||
387 | ||||
388 | int32 start_y = preview_bitmap->Bounds().top; | |||
389 | int32 end_y = preview_bitmap->Bounds().bottom; | |||
390 | ||||
391 | union { | |||
392 | uint8 bytes[4]; | |||
393 | uint32 word; | |||
394 | } background; | |||
395 | ||||
396 | background.bytes[0] = 0xFF; | |||
397 | background.bytes[1] = 0xFF; | |||
398 | background.bytes[2] = 0xFF; | |||
399 | background.bytes[3] = 0x00; | |||
400 | ||||
401 | if (last_calculated_resolution > 0) { | |||
402 | float real_x; | |||
403 | float real_y; | |||
404 | float one_per_sqrt_x_plus_y; | |||
405 | float sqrt_x_plus_y; | |||
406 | float cx = settings.center.x; | |||
407 | float cy = settings.center.y; | |||
408 | float dx; | |||
409 | float dy; | |||
410 | float A = settings.wave_amount; | |||
411 | float s = settings.wave_length; | |||
412 | float two_360_per_s = 720.0/s; | |||
413 | float k = 0; | |||
414 | float R = sqrt(pow(max_c(fabs(cx),target_bpr-fabs(cx))((fabs(cx))>(target_bpr-fabs(cx))?(fabs(cx)):(target_bpr-fabs (cx))),2)+pow(max_c(fabs(cy),end_y-fabs(cy))((fabs(cy))>(end_y-fabs(cy))?(fabs(cy)):(end_y-fabs(cy))),2)); | |||
415 | if (selection->IsEmpty()) { | |||
416 | for (float y=start_y;y<=end_y;y += last_calculated_resolution) { | |||
417 | int32 y_target_bpr = y*target_bpr; | |||
418 | for (float x=0;x<source_bpr;x += last_calculated_resolution) { | |||
419 | real_x = x-cx; | |||
420 | real_y = y-cy; | |||
421 | if ((real_x != 0) && (real_y != 0)) { | |||
422 | // Let's try the inline assemler function for square root estimation. | |||
423 | // On intel this does not yet work and the corresponding function is very slow. | |||
424 | #ifdef __POWERPC__ | |||
425 | one_per_sqrt_x_plus_y = reciprocal_of_square_root(real_x*real_x+real_y*real_y); | |||
426 | sqrt_x_plus_y = 1.0/one_per_sqrt_x_plus_y; | |||
427 | #else | |||
428 | // sqrt_x_plus_y = fsqrt(real_x*real_x+real_y*real_y); | |||
429 | sqrt_x_plus_y = sqrt(real_x*real_x+real_y*real_y); | |||
430 | one_per_sqrt_x_plus_y = 1.0 / sqrt_x_plus_y; | |||
431 | #endif | |||
432 | ||||
433 | dx = one_per_sqrt_x_plus_y*A*sin_table[(int32)(sqrt_x_plus_y*two_360_per_s)%720]; | |||
434 | dx = dx*(1-k*sqrt_x_plus_y/R); | |||
435 | dy = dx*real_y; | |||
436 | dx = dx*real_x; | |||
437 | // This if is quite slow. | |||
438 | if (((y+dy) <= end_y) && ((y+dy)>=0) && ((x+dx) >= 0) && ((x+dx)<target_bpr)) { | |||
439 | *(target_bits + (int32)x + y_target_bpr) = *(source_bits + (int32)(x+dx) + (int32)(y+dy)*source_bpr); | |||
440 | } | |||
441 | else { | |||
442 | *(target_bits +(int32)x + y_target_bpr) = background.word; | |||
443 | } | |||
444 | } | |||
445 | else { | |||
446 | if (real_x != 0) { | |||
447 | // We also have to estimate the sqrt here. | |||
448 | one_per_sqrt_x_plus_y = reciprocal_of_square_root(real_x*real_x); | |||
449 | sqrt_x_plus_y = 1/one_per_sqrt_x_plus_y; | |||
450 | dx = one_per_sqrt_x_plus_y*A*sin_table[(int32)(sqrt_x_plus_y*two_360_per_s)%720]*real_x; | |||
451 | dx = dx*(1-k*sqrt_x_plus_y/R); | |||
452 | if (((x+dx) >= 0) && ((x+dx)<target_bpr)) | |||
453 | *(target_bits +(int32)x +y_target_bpr) = *(source_bits + (int32)y*target_bpr + (int32)(x +dx)); | |||
454 | else | |||
455 | *(target_bits +(int32)x + y_target_bpr)= background.word; | |||
456 | } | |||
457 | else if (real_y != 0) { | |||
458 | one_per_sqrt_x_plus_y = reciprocal_of_square_root(real_y*real_y); | |||
459 | sqrt_x_plus_y = 1/one_per_sqrt_x_plus_y; | |||
460 | dy = one_per_sqrt_x_plus_y*A*sin_table[(int32)(sqrt_x_plus_y*two_360_per_s)%720]*real_y; | |||
461 | dy = dy*(1-k*sqrt_x_plus_y/R); | |||
462 | if (((y+dy)<=end_y) && ((y+dy) >= 0)) | |||
463 | *(target_bits +(int32)x + y_target_bpr) = *(source_bits + (int32)x + (int32)(y + dy)*source_bpr); | |||
464 | else | |||
465 | *(target_bits +(int32)x +y_target_bpr) = background.word; | |||
466 | } | |||
467 | else { | |||
468 | *(target_bits +(int32)x +y_target_bpr) = *(source_bits + (int32)x + (int32)y*source_bpr); | |||
469 | } | |||
470 | } | |||
471 | } | |||
472 | } | |||
473 | } | |||
474 | else { | |||
475 | for (float y=start_y;y<=end_y;y += last_calculated_resolution) { | |||
476 | int32 y_target_bpr = y*target_bpr; | |||
477 | for (float x=0;x<source_bpr;x += last_calculated_resolution) { | |||
478 | real_x = x-cx; | |||
479 | real_y = y-cy; | |||
480 | if (selection->ContainsPoint(x,y) == TRUE1) { | |||
481 | if ((real_x != 0) && (real_y != 0)) { | |||
482 | // Let's try the inline assemler function for square root estimation | |||
483 | #ifdef __POWERPC__ | |||
484 | one_per_sqrt_x_plus_y = reciprocal_of_square_root(real_x*real_x+real_y*real_y); | |||
485 | sqrt_x_plus_y = 1.0/one_per_sqrt_x_plus_y; | |||
486 | #else | |||
487 | // sqrt_x_plus_y = fsqrt(real_x*real_x+real_y*real_y); | |||
488 | sqrt_x_plus_y = sqrt(real_x*real_x+real_y*real_y); | |||
489 | one_per_sqrt_x_plus_y = 1.0 / sqrt_x_plus_y; | |||
490 | #endif | |||
491 | dx = one_per_sqrt_x_plus_y*A*sin_table[(int32)(sqrt_x_plus_y*two_360_per_s)%720]; | |||
492 | dx = dx*(1-k*sqrt_x_plus_y/R); | |||
493 | dy = dx*real_y; | |||
494 | dx = dx*real_x; | |||
495 | // This if is quite slow. | |||
496 | if (((y+dy) <= end_y) && ((y+dy)>=0) && ((x+dx) >= 0) && ((x+dx)<target_bpr)) { | |||
497 | *(target_bits + (int32)x + y_target_bpr) = *(source_bits + (int32)(x+dx) + (int32)(y+dy)*source_bpr); | |||
498 | } | |||
499 | else { | |||
500 | *(target_bits +(int32)x + y_target_bpr) = background.word; | |||
501 | } | |||
502 | } | |||
503 | else { | |||
504 | if (real_x != 0) { | |||
505 | // We also have to estimate the sqrt here. | |||
506 | one_per_sqrt_x_plus_y = reciprocal_of_square_root(real_x*real_x); | |||
507 | sqrt_x_plus_y = 1/one_per_sqrt_x_plus_y; | |||
508 | dx = one_per_sqrt_x_plus_y*A*sin_table[(int32)(sqrt_x_plus_y*two_360_per_s)%720]*real_x; | |||
509 | dx = dx*(1-k*sqrt_x_plus_y/R); | |||
510 | if (((x+dx) >= 0) && ((x+dx)<target_bpr)) | |||
511 | *(target_bits +(int32)x +y_target_bpr) = *(source_bits + (int32)y*target_bpr + (int32)(x +dx)); | |||
512 | else | |||
513 | *(target_bits +(int32)x + y_target_bpr)= background.word; | |||
514 | } | |||
515 | else if (real_y != 0) { | |||
516 | one_per_sqrt_x_plus_y = reciprocal_of_square_root(real_y*real_y); | |||
517 | sqrt_x_plus_y = 1/one_per_sqrt_x_plus_y; | |||
518 | dy = one_per_sqrt_x_plus_y*A*sin_table[(int32)(sqrt_x_plus_y*two_360_per_s)%720]*real_y; | |||
519 | dy = dy*(1-k*sqrt_x_plus_y/R); | |||
520 | if (((y+dy)<=end_y) && ((y+dy) >= 0)) | |||
521 | *(target_bits +(int32)x + y_target_bpr) = *(source_bits + (int32)x + (int32)(y + dy)*source_bpr); | |||
522 | else | |||
523 | *(target_bits +(int32)x +y_target_bpr) = background.word; | |||
524 | } | |||
525 | else { | |||
526 | *(target_bits +(int32)x +y_target_bpr) = *(source_bits + (int32)x + (int32)y*source_bpr); | |||
527 | } | |||
528 | } | |||
529 | } | |||
530 | else { | |||
531 | *(target_bits +(int32)x +y_target_bpr) = *(source_bits + (int32)x + (int32)y*source_bpr); | |||
532 | } | |||
533 | } | |||
534 | } | |||
535 | } | |||
536 | } | |||
537 | updated_region->Set(preview_bitmap->Bounds()); | |||
538 | return last_calculated_resolution; | |||
539 | } | |||
540 | ||||
541 | ||||
542 | void WaveManipulator::MouseDown(BPoint point,uint32,BView*,bool first_click) | |||
543 | { | |||
544 | if (first_click == TRUE1) | |||
545 | previous_settings = settings; | |||
546 | ||||
547 | settings.center = point; | |||
548 | if (config_view != NULL__null) | |||
549 | config_view->ChangeSettings(&settings); | |||
550 | } | |||
551 | ||||
552 | ||||
553 | ||||
554 | ||||
555 | //int32 WaveManipulator::wave_func(uint32 *target_bits,uint32 *source_bits,int32 target_bpr,int32 source_bpr,int32 start_y,int32 end_y,int32 amount_of_wave,int32 length_of_wave,int32 dampening_of_wave,float center_x, float center_y,float top_of_image,float bottom_of_image) | |||
556 | //{ | |||
557 | // // First move the bits to right starting positions. | |||
558 | // // In this manipulator do not move the source bits, because it will be | |||
559 | // // 'indexed' directly. | |||
560 | //// source_bits += start_y * source_bpr; | |||
561 | // target_bits += start_y * target_bpr; | |||
562 | // | |||
563 | // BMessage progress_message = BMessage(B_UPDATE_STATUS_BAR); | |||
564 | // progress_message.AddFloat("delta",0.0); | |||
565 | // | |||
566 | // BStopWatch *watch = new BStopWatch("Wave Time"); | |||
567 | // | |||
568 | // float s = length_of_wave; | |||
569 | // float A = amount_of_wave; | |||
570 | // float k = (float)(dampening_of_wave)/(float)MAX_WAVE_DAMPENING; | |||
571 | // float dx,dy; | |||
572 | // float sqrt_x_plus_y; | |||
573 | // float one_per_sqrt_x_plus_y; | |||
574 | // float cx,cy; | |||
575 | // float top,bottom; | |||
576 | // top = top_of_image; | |||
577 | // bottom = bottom_of_image; | |||
578 | // | |||
579 | // cx = floor(center_x); | |||
580 | // cy = floor(center_y); | |||
581 | // float R = sqrt(pow(max_c(abs(cx),target_bpr-abs(cx)),2)+pow(max_c(abs(cy),bottom_of_image-abs(cy)),2)); | |||
582 | // | |||
583 | // | |||
584 | // float real_x,real_y; | |||
585 | // float two_pi_per_s = 2*PI/s; | |||
586 | // float two_360_per_s = 720.0/s; | |||
587 | // | |||
588 | // if (preview_level == FULL_CALCULATION) { | |||
589 | // uint32 p1,p2,p3,p4; | |||
590 | // for (float y=start_y;y<=end_y;y++) { | |||
591 | // for (float x=0;x<source_bpr;x++) { | |||
592 | // real_x = x-cx; | |||
593 | // real_y = y-cy; | |||
594 | // uint32 target_value = 0x00000000; | |||
595 | // if ((real_x != 0) && (real_y != 0)) { | |||
596 | // sqrt_x_plus_y = sqrt(real_x*real_x+real_y*real_y); | |||
597 | // dx = real_x/sqrt_x_plus_y*A*sin(sqrt_x_plus_y*two_pi_per_s); // The sin and div are slow. | |||
598 | // dx = dx*(1-k*sqrt_x_plus_y/R); | |||
599 | // dy = dx/real_x*real_y; | |||
600 | // float y_mix_upper = ceil(y+dy)-(y+dy); | |||
601 | // float x_mix_right = (x+dx)- floor(x+dx); | |||
602 | // if ((ceil(y+dy) <= bottom) && (ceil(y+dy)>=top)) { | |||
603 | // if ((floor(x+dx) >= 0) && (floor(x+dx) <source_bpr)) { | |||
604 | // p1 = *(source_bits + (int32)ceil(y+dy)*source_bpr + (int32)floor(x+dx)); | |||
605 | // } | |||
606 | // else | |||
607 | // p1 = 0xFFFFFF00; | |||
608 | // | |||
609 | // if ((ceil(x+dx) >= 0) && (ceil(x+dx) <source_bpr)) { | |||
610 | // p2 = *(source_bits + (int32)ceil(y+dy)*source_bpr + (int32)ceil(x+dx)); | |||
611 | // } | |||
612 | // else | |||
613 | // p2 = 0xFFFFFF00; | |||
614 | // } | |||
615 | // else { | |||
616 | // p1 = 0xFFFFFF00; | |||
617 | // p2 = 0xFFFFFF00; | |||
618 | // } | |||
619 | // if ((floor(y+dy) <= bottom) && (floor(y+dy)>=top)) { | |||
620 | // if ((floor(x+dx) >= 0) && (floor(x+dx) <source_bpr)) { | |||
621 | // p3 = *(source_bits + (int32)floor(y+dy)*source_bpr + (int32)floor(x+dx)); | |||
622 | // } | |||
623 | // else | |||
624 | // p3 = 0xFFFFFF00; | |||
625 | // | |||
626 | // if ((ceil(x+dx) >= 0) && (ceil(x+dx) <source_bpr)) { | |||
627 | // p4 = *(source_bits + (int32)floor(y+dy)*source_bpr + (int32)ceil(x+dx)); | |||
628 | // } | |||
629 | // else | |||
630 | // p4 = 0xFFFFFF00; | |||
631 | // } | |||
632 | // else { | |||
633 | // p3 = 0xFFFFFF00; | |||
634 | // p4 = 0xFFFFFF00; | |||
635 | // } | |||
636 | // *target_bits++ = combine_4_pixels(p1,p2,p3,p4,(1-y_mix_upper)*(1-x_mix_right),(1-y_mix_upper)*(x_mix_right),(y_mix_upper)*(1-x_mix_right),(y_mix_upper)*(x_mix_right)); | |||
637 | // } | |||
638 | // else { | |||
639 | // if (real_x != 0) { | |||
640 | // sqrt_x_plus_y = sqrt(real_x*real_x); | |||
641 | // dx = real_x/sqrt_x_plus_y*A*sin(sqrt_x_plus_y*two_pi_per_s); | |||
642 | // dx = dx*(1-k*sqrt_x_plus_y/R); | |||
643 | // float x_mix_right = (x+dx)-floor(x+dx); | |||
644 | // if ((ceil(x+dx) >= 0) && (ceil(x+dx)<target_bpr)) | |||
645 | // p1 = *(source_bits + (int32)y*target_bpr + (int32)ceil((x +dx))); | |||
646 | // else | |||
647 | // p1 = 0xFFFFFF00; | |||
648 | // | |||
649 | // if ((floor(x+dx) >= 0) && (floor(x+dx)<target_bpr)) | |||
650 | // p2 = *(source_bits + (int32)y*target_bpr + (int32)floor((x +dx))); | |||
651 | // else | |||
652 | // p2 = 0xFFFFFF00; | |||
653 | // *target_bits++ = mix_2_pixels_fixed(p1,p2,32768*x_mix_right); | |||
654 | // } | |||
655 | // else if (real_y != 0) { | |||
656 | // sqrt_x_plus_y = sqrt(real_y*real_y); | |||
657 | // dy = real_y/sqrt_x_plus_y*A*sin(sqrt_x_plus_y*two_pi_per_s); | |||
658 | // dy = dy*(1-k*sqrt_x_plus_y/R); | |||
659 | // float y_mix_upper = ceil(y+dy)-(y+dy); | |||
660 | // if ((ceil(y+dy)<=bottom) && (ceil(y+dy) >= top)) | |||
661 | // p1 = *(source_bits + (int32)x + (int32)ceil((y + dy))*target_bpr); | |||
662 | // else | |||
663 | // p1 = 0xFFFFFF00; | |||
664 | // | |||
665 | // if ((floor(y+dy)<=bottom) && (floor(y+dy) >= top)) | |||
666 | // p2 = *(source_bits + (int32)x + (int32)floor((y + dy))*target_bpr); | |||
667 | // else | |||
668 | // p2 = 0xFFFFFF00; | |||
669 | // *target_bits++ = mix_2_pixels_fixed(p2,p1,32768*y_mix_upper); | |||
670 | // } | |||
671 | // else { | |||
672 | // *target_bits++ = *(source_bits + (int32)x + (int32)y*source_bpr); | |||
673 | // } | |||
674 | // } | |||
675 | // | |||
676 | // } | |||
677 | // // Send a progress-message if required | |||
678 | // if ((status_view != NULL) && ((int32)y%10 == 0)) { | |||
679 | // progress_message.ReplaceFloat("delta",(100.0*progress_step)/(float)(end_y-start_y)*10.0); | |||
680 | // status_view->Window()->PostMessage(&progress_message,status_view); | |||
681 | // } | |||
682 | // } | |||
683 | // } | |||
684 | // else if (preview_level == GOOD_PREVIEW) { | |||
685 | // for (float y=start_y;y<=end_y;y++) { | |||
686 | // for (float x=0;x<source_bpr;x++) { | |||
687 | // real_x = x-cx; | |||
688 | // real_y = y-cy; | |||
689 | // if ((real_x != 0) && (real_y != 0)) { | |||
690 | // // Let's try the inline assemler function for square root estimation | |||
691 | // one_per_sqrt_x_plus_y = reciprocal_of_square_root(real_x*real_x+real_y*real_y); | |||
692 | // sqrt_x_plus_y = 1.0/one_per_sqrt_x_plus_y; | |||
693 | // | |||
694 | // dx = one_per_sqrt_x_plus_y*A*sin_table[(int32)(sqrt_x_plus_y*two_360_per_s)%720]; | |||
695 | // dx = dx*(1-k*sqrt_x_plus_y/R); | |||
696 | // dy = dx*real_y; | |||
697 | // dx = dx*real_x; | |||
698 | // // This if is quite slow. | |||
699 | // if (((y+dy) <= bottom) && ((y+dy)>=top) && ((x+dx) >= 0) && ((x+dx)<target_bpr)) { | |||
700 | // *(target_bits) = *(source_bits + (int32)(x+dx) + (int32)(y+dy)*source_bpr); | |||
701 | // } | |||
702 | // else { | |||
703 | // *target_bits = 0xFFFFFF00; | |||
704 | // } | |||
705 | // } | |||
706 | // else { | |||
707 | // if (real_x != 0) { | |||
708 | // // We also have to estimate the sqrt here. | |||
709 | // one_per_sqrt_x_plus_y = reciprocal_of_square_root(real_x*real_x); | |||
710 | // sqrt_x_plus_y = 1/one_per_sqrt_x_plus_y; | |||
711 | // dx = one_per_sqrt_x_plus_y*A*sin_table[(int32)(sqrt_x_plus_y*two_360_per_s)%720]*real_x; | |||
712 | // dx = dx*(1-k*sqrt_x_plus_y/R); | |||
713 | // if (((x+dx) >= 0) && ((x+dx)<target_bpr)) | |||
714 | // *target_bits = *(source_bits + (int32)y*target_bpr + (int32)(x +dx)); | |||
715 | // else | |||
716 | // *target_bits = 0xFFFFFF00; | |||
717 | // } | |||
718 | // else if (real_y != 0) { | |||
719 | // one_per_sqrt_x_plus_y = reciprocal_of_square_root(real_y*real_y); | |||
720 | // sqrt_x_plus_y = 1/one_per_sqrt_x_plus_y; | |||
721 | // dy = one_per_sqrt_x_plus_y*A*sin_table[(int32)(sqrt_x_plus_y*two_360_per_s)%720]*real_y; | |||
722 | // dy = dy*(1-k*sqrt_x_plus_y/R); | |||
723 | // if (((y+dy)<=bottom) && ((y+dy) >= top)) | |||
724 | // *target_bits = *(source_bits + (int32)x + (int32)(y + dy)*target_bpr); | |||
725 | // else | |||
726 | // *target_bits = 0xFFFFFF00; | |||
727 | // } | |||
728 | // else { | |||
729 | // *target_bits = *(source_bits + (int32)x + (int32)y*target_bpr); | |||
730 | // } | |||
731 | // } | |||
732 | // target_bits++; | |||
733 | // } | |||
734 | // // Send a progress-message if required | |||
735 | // if ((status_view != NULL) && ((int32)y%10 == 0)) { | |||
736 | // progress_message.ReplaceFloat("delta",(100.0*progress_step)/(float)(end_y-start_y)*10.0); | |||
737 | // status_view->Window()->PostMessage(&progress_message,status_view); | |||
738 | // } | |||
739 | // } | |||
740 | // } | |||
741 | // else { | |||
742 | // int32 width = source_bpr/2*2; | |||
743 | // for (float y=start_y;y<end_y;y+=2) { | |||
744 | // for (float x=0;x<width;x+=2) { | |||
745 | // real_x = x-cx; | |||
746 | // real_y = y-cy; | |||
747 | // if ((real_x != 0) && (real_y != 0)) { | |||
748 | // one_per_sqrt_x_plus_y = reciprocal_of_square_root(real_x*real_x+real_y*real_y); | |||
749 | // sqrt_x_plus_y = 1.0/one_per_sqrt_x_plus_y; | |||
750 | // | |||
751 | // dx = one_per_sqrt_x_plus_y*A*sin_table[(int32)(sqrt_x_plus_y*two_360_per_s)%720]; | |||
752 | // dx = dx*(1-k*sqrt_x_plus_y/R); | |||
753 | // dy = dx*real_y; | |||
754 | // dx = dx*real_x; | |||
755 | // // This if is quite slow. | |||
756 | // if (((y+dy) < bottom) && ((y+dy)>=top) && ((x+dx) >= 0) && ((x+dx)<target_bpr-1)) { | |||
757 | // uint32 new_value = *(source_bits + (int32)(x+dx) + (int32)(y+dy)*source_bpr); | |||
758 | // *(target_bits) = new_value; | |||
759 | // *(target_bits+1) = new_value; | |||
760 | // *(target_bits+target_bpr) = new_value; | |||
761 | // *(target_bits+target_bpr+1) = new_value; | |||
762 | // | |||
763 | // } | |||
764 | // else { | |||
765 | // *target_bits = 0xFFFFFF00; | |||
766 | // *(target_bits+1) = 0xFFFFFF00; | |||
767 | // *(target_bits+target_bpr) = 0xFFFFFF00; | |||
768 | // *(target_bits+target_bpr+1) = 0xFFFFFF00; | |||
769 | // } | |||
770 | // } | |||
771 | // else { | |||
772 | // if (real_x != 0) { | |||
773 | // dx = A*sin(real_x*two_pi_per_s); | |||
774 | // dx = dx*(1-k*real_x/R); | |||
775 | // if (((x+dx) >= 0) && ((x+dx)<target_bpr)) { | |||
776 | // uint32 new_value = *(source_bits + (int32)y*target_bpr + (int32)(x +dx)); | |||
777 | // *target_bits = new_value; | |||
778 | // *(target_bits+1) = new_value; | |||
779 | // *(target_bits+target_bpr) = new_value; | |||
780 | // *(target_bits+target_bpr+1) = new_value; | |||
781 | // } | |||
782 | // else { | |||
783 | // *target_bits = 0xFFFFFF00; | |||
784 | // *(target_bits+1) = 0xFFFFFF00; | |||
785 | // *(target_bits+target_bpr) = 0xFFFFFF00; | |||
786 | // *(target_bits+target_bpr+1) = 0xFFFFFF00; | |||
787 | // } | |||
788 | // } | |||
789 | // else if (real_y != 0) { | |||
790 | // dy = A*sin(real_y*two_pi_per_s); | |||
791 | // dy = dy*(1-k*real_y/R); | |||
792 | // if (((y+dy)<=bottom) && ((y+dy) >= top)) { | |||
793 | // int32 new_value = *(source_bits + (int32)x + (int32)(y + dy)*target_bpr); | |||
794 | // *target_bits = new_value; | |||
795 | // *(target_bits+1) = new_value; | |||
796 | // *(target_bits+target_bpr) = new_value; | |||
797 | // *(target_bits+target_bpr+1) = new_value; | |||
798 | // } | |||
799 | // else { | |||
800 | // *target_bits = 0xFFFFFF00; | |||
801 | // *(target_bits+1) = 0xFFFFFF00; | |||
802 | // *(target_bits+target_bpr) = 0xFFFFFF00; | |||
803 | // *(target_bits+target_bpr+1) = 0xFFFFFF00; | |||
804 | // } | |||
805 | // } | |||
806 | // else { | |||
807 | // int32 new_value = *(source_bits + (int32)x + (int32)y*target_bpr); | |||
808 | // *target_bits = new_value; | |||
809 | // *(target_bits+1) = new_value; | |||
810 | // *(target_bits+target_bpr) = new_value; | |||
811 | // *(target_bits+target_bpr+1) = new_value; | |||
812 | // } | |||
813 | // } | |||
814 | // target_bits+=2; | |||
815 | // } | |||
816 | // if ((source_bpr % 2) == 0) { | |||
817 | // target_bits += target_bpr; | |||
818 | // } | |||
819 | // else | |||
820 | // target_bits += target_bpr + 1; | |||
821 | // } | |||
822 | // // Here we handle the last row separately if needed. | |||
823 | // if ((end_y-start_y)%2 == 0) { | |||
824 | // float y = end_y; | |||
825 | // for (float x=0;x<width;x+=2) { | |||
826 | // real_x = x-cx; | |||
827 | // real_y = y-cy; | |||
828 | // if ((real_x != 0) && (real_y != 0)) { | |||
829 | // one_per_sqrt_x_plus_y = reciprocal_of_square_root(real_x*real_x+real_y*real_y); | |||
830 | // sqrt_x_plus_y = 1.0/one_per_sqrt_x_plus_y; | |||
831 | // | |||
832 | // dx = one_per_sqrt_x_plus_y*A*sin_table[(int32)(sqrt_x_plus_y*two_360_per_s)%720]; | |||
833 | // dx = dx*(1-k*sqrt_x_plus_y/R); | |||
834 | // dy = dx*real_y; | |||
835 | // dx = dx*real_x; | |||
836 | // // This if is quite slow. | |||
837 | // if (((y+dy) < bottom) && ((y+dy)>=top) && ((x+dx) >= 0) && ((x+dx)<target_bpr-1)) { | |||
838 | // uint32 new_value = *(source_bits + (int32)(x+dx) + (int32)(y+dy)*source_bpr); | |||
839 | // *(target_bits) = new_value; | |||
840 | // *(target_bits+1) = new_value; | |||
841 | // } | |||
842 | // else { | |||
843 | // *target_bits = 0xFFFFFF00; | |||
844 | // *(target_bits + 1) = 0xFFFFFF00; | |||
845 | // } | |||
846 | // } | |||
847 | // else { | |||
848 | // if (real_x != 0) { | |||
849 | // dx = A*sin(real_x*two_pi_per_s); | |||
850 | // dx = dx*(1-k*real_x/R); | |||
851 | // if (((x+dx) >= 0) && ((x+dx)<target_bpr)) { | |||
852 | // uint32 new_value = *(source_bits + (int32)y*target_bpr + (int32)(x +dx)); | |||
853 | // *target_bits = new_value; | |||
854 | // *(target_bits+1) = new_value; | |||
855 | // } | |||
856 | // else { | |||
857 | // *target_bits = 0xFFFFFF00; | |||
858 | // *(target_bits+1) = 0xFFFFFF00; | |||
859 | // } | |||
860 | // } | |||
861 | // else if (real_y != 0) { | |||
862 | // dy = A*sin(real_y*two_pi_per_s); | |||
863 | // dy = dy*(1-k*real_y/R); | |||
864 | // if (((y+dy)<=bottom) && ((y+dy) >= top)) { | |||
865 | // int32 new_value = *(source_bits + (int32)x + (int32)(y + dy)*target_bpr); | |||
866 | // *target_bits = new_value; | |||
867 | // *(target_bits+1) = new_value; | |||
868 | // } | |||
869 | // else { | |||
870 | // *target_bits = 0xFFFFFF00; | |||
871 | // *(target_bits+1) = 0xFFFFFF00; | |||
872 | // } | |||
873 | // } | |||
874 | // else { | |||
875 | // int32 new_value = *(source_bits + (int32)x + (int32)y*target_bpr); | |||
876 | // *target_bits = new_value; | |||
877 | // *(target_bits+1) = new_value; | |||
878 | // } | |||
879 | // } | |||
880 | // target_bits+=2; | |||
881 | // } | |||
882 | // | |||
883 | // } | |||
884 | // } | |||
885 | // delete watch; | |||
886 | // return B_OK; | |||
887 | //} | |||
888 | ||||
889 | ||||
890 | const char* WaveManipulator::ReturnHelpString() | |||
891 | { | |||
892 | return B_TRANSLATE("Click to set the wave center. Use the sliders to adjust wave.")BLocaleRoster::Default()->GetCatalog()->GetString(("Click to set the wave center. Use the sliders to adjust wave." ), "AddOns_Wave"); | |||
893 | } | |||
894 | ||||
895 | ||||
896 | const char* WaveManipulator::ReturnName() | |||
897 | { | |||
898 | return B_TRANSLATE("Wave")BLocaleRoster::Default()->GetCatalog()->GetString(("Wave" ), "AddOns_Wave"); | |||
899 | } | |||
900 | ||||
901 | ||||
902 | void WaveManipulator::SetPreviewBitmap(BBitmap *bm) | |||
903 | { | |||
904 | if (preview_bitmap != bm) { | |||
905 | delete copy_of_the_preview_bitmap; | |||
906 | if (bm != NULL__null) { | |||
907 | preview_bitmap = bm; | |||
908 | copy_of_the_preview_bitmap = DuplicateBitmap(bm,0); | |||
909 | } | |||
910 | else { | |||
911 | preview_bitmap = NULL__null; | |||
912 | copy_of_the_preview_bitmap = NULL__null; | |||
913 | } | |||
914 | } | |||
915 | if (preview_bitmap != NULL__null) { | |||
916 | double speed = GetSystemClockSpeed() / 15000; | |||
917 | ||||
918 | BRect bounds = preview_bitmap->Bounds(); | |||
919 | float num_pixels = (bounds.Width()+1) * (bounds.Height() + 1); | |||
920 | lowest_available_quality = 1; | |||
921 | while ((2*num_pixels/lowest_available_quality/lowest_available_quality) > speed) | |||
922 | lowest_available_quality *= 2; | |||
923 | ||||
924 | lowest_available_quality = min_c(lowest_available_quality,16)((lowest_available_quality)>(16)?(16):(lowest_available_quality )); | |||
925 | highest_available_quality = max_c(lowest_available_quality/2,1)((lowest_available_quality/2)>(1)?(lowest_available_quality /2):(1)); | |||
926 | } | |||
927 | else { | |||
928 | lowest_available_quality = 1; | |||
929 | highest_available_quality = 1; | |||
930 | } | |||
931 | last_calculated_resolution = lowest_available_quality; | |||
932 | } | |||
933 | ||||
934 | ||||
935 | void WaveManipulator::Reset(Selection*) | |||
936 | { | |||
937 | if (preview_bitmap != NULL__null) { | |||
938 | uint32 *source_bits = (uint32*)copy_of_the_preview_bitmap->Bits(); | |||
939 | uint32 *target_bits = (uint32*)preview_bitmap->Bits(); | |||
940 | ||||
941 | int32 bits_length = preview_bitmap->BitsLength()/4; | |||
942 | ||||
943 | for (int32 i=0;i<bits_length;i++) | |||
944 | *target_bits++ = *source_bits++; | |||
945 | } | |||
946 | } | |||
947 | ||||
948 | BView* WaveManipulator::MakeConfigurationView(const BMessenger& target) | |||
949 | { | |||
950 | config_view = new WaveManipulatorView(BRect(0,0,0,0),this, target); | |||
951 | config_view->ChangeSettings(&settings); | |||
952 | return config_view; | |||
953 | } | |||
954 | ||||
955 | ||||
956 | ManipulatorSettings* WaveManipulator::ReturnSettings() | |||
957 | { | |||
958 | return new WaveManipulatorSettings(settings); | |||
959 | } | |||
960 | ||||
961 | void WaveManipulator::ChangeSettings(ManipulatorSettings *s) | |||
962 | { | |||
963 | WaveManipulatorSettings *new_settings = dynamic_cast<WaveManipulatorSettings*>(s); | |||
964 | if (new_settings != NULL__null) { | |||
965 | previous_settings = settings; | |||
966 | settings = *new_settings; | |||
967 | } | |||
968 | } | |||
969 | ||||
970 | //------------- | |||
971 | ||||
972 | ||||
973 | WaveManipulatorView::WaveManipulatorView(BRect rect,WaveManipulator *manip, | |||
974 | const BMessenger& t) | |||
975 | : WindowGUIManipulatorView() | |||
976 | { | |||
977 | manipulator = manip; | |||
978 | target = new BMessenger(t); | |||
979 | preview_started = FALSE0; | |||
980 | ||||
981 | wave_length_slider = new BSlider("wave_length_slider", | |||
982 | B_TRANSLATE("Wavelength:")BLocaleRoster::Default()->GetCatalog()->GetString(("Wavelength:" ), "AddOns_Wave"), new BMessage(WAVE_LENGTH_CHANGED'Wlec'), MIN_WAVE_LENGTH3, | |||
983 | MAX_WAVE_LENGTH200, B_HORIZONTAL, B_TRIANGLE_THUMB); | |||
984 | wave_length_slider->SetLimitLabels(B_TRANSLATE("Short")BLocaleRoster::Default()->GetCatalog()->GetString(("Short" ), "AddOns_Wave"), B_TRANSLATE("Long")BLocaleRoster::Default()->GetCatalog()->GetString(("Long" ), "AddOns_Wave")); | |||
985 | wave_length_slider->SetModificationMessage(new BMessage(WAVE_LENGTH_ADJUSTING_STARTED'Wlas')); | |||
986 | wave_length_slider->SetHashMarks(B_HASH_MARKS_BOTTOM); | |||
987 | wave_length_slider->SetHashMarkCount(11); | |||
988 | ||||
989 | wave_amount_slider = new BSlider("wave_amount_slider", B_TRANSLATE("Strength:")BLocaleRoster::Default()->GetCatalog()->GetString(("Strength:" ), "AddOns_Wave"), | |||
990 | new BMessage(WAVE_AMOUNT_CHANGED'Wamc'), MIN_WAVE_AMOUNT3, MAX_WAVE_AMOUNT100, | |||
991 | B_HORIZONTAL, B_TRIANGLE_THUMB); | |||
992 | wave_amount_slider->SetLimitLabels(B_TRANSLATE("Mild")BLocaleRoster::Default()->GetCatalog()->GetString(("Mild" ), "AddOns_Wave"), B_TRANSLATE("Strong")BLocaleRoster::Default()->GetCatalog()->GetString(("Strong" ), "AddOns_Wave")); | |||
993 | wave_amount_slider->SetModificationMessage(new BMessage(WAVE_AMOUNT_ADJUSTING_STARTED'Waas')); | |||
994 | wave_amount_slider->SetHashMarks(B_HASH_MARKS_BOTTOM); | |||
995 | wave_amount_slider->SetHashMarkCount(11); | |||
996 | ||||
997 | BLayoutBuilder::Group<>(this, B_VERTICAL, B_USE_ITEM_SPACING) | |||
998 | .Add(wave_length_slider) | |||
999 | .Add(wave_amount_slider) | |||
1000 | .SetInsets(B_USE_SMALL_INSETS) | |||
1001 | .End(); | |||
1002 | } | |||
1003 | ||||
1004 | ||||
1005 | WaveManipulatorView::~WaveManipulatorView() | |||
1006 | { | |||
1007 | delete target; | |||
1008 | } | |||
1009 | ||||
1010 | ||||
1011 | void WaveManipulatorView::AttachedToWindow() | |||
1012 | { | |||
1013 | WindowGUIManipulatorView::AttachedToWindow(); | |||
1014 | ||||
1015 | wave_length_slider->SetTarget(BMessenger(this)); | |||
1016 | wave_amount_slider->SetTarget(BMessenger(this)); | |||
1017 | } | |||
1018 | ||||
1019 | ||||
1020 | void WaveManipulatorView::AllAttached() | |||
1021 | { | |||
1022 | wave_length_slider->SetValue(settings.wave_length); | |||
1023 | wave_amount_slider->SetValue(settings.wave_amount); | |||
1024 | ||||
1025 | } | |||
1026 | ||||
1027 | ||||
1028 | void WaveManipulatorView::MessageReceived(BMessage *message) | |||
1029 | { | |||
1030 | switch (message->what) { | |||
1031 | case WAVE_LENGTH_ADJUSTING_STARTED'Wlas': | |||
1032 | if (preview_started == FALSE0) { | |||
1033 | preview_started = TRUE1; | |||
1034 | target->SendMessage(HS_MANIPULATOR_ADJUSTING_STARTED'Mast'); | |||
1035 | } | |||
1036 | settings.wave_length = wave_length_slider->Value(); | |||
1037 | manipulator->ChangeSettings(&settings); | |||
1038 | break; | |||
1039 | ||||
1040 | case WAVE_LENGTH_CHANGED'Wlec': | |||
1041 | preview_started = FALSE0; | |||
1042 | settings.wave_length = wave_length_slider->Value(); | |||
1043 | manipulator->ChangeSettings(&settings); | |||
1044 | target->SendMessage(HS_MANIPULATOR_ADJUSTING_FINISHED'Mafi'); | |||
1045 | break; | |||
1046 | ||||
1047 | case WAVE_AMOUNT_ADJUSTING_STARTED'Waas': | |||
1048 | if (preview_started == FALSE0) { | |||
1049 | preview_started = TRUE1; | |||
1050 | target->SendMessage(HS_MANIPULATOR_ADJUSTING_STARTED'Mast'); | |||
1051 | } | |||
1052 | settings.wave_amount = wave_amount_slider->Value(); | |||
1053 | manipulator->ChangeSettings(&settings); | |||
1054 | break; | |||
1055 | ||||
1056 | case WAVE_AMOUNT_CHANGED'Wamc': | |||
1057 | preview_started = FALSE0; | |||
1058 | settings.wave_amount = wave_amount_slider->Value(); | |||
1059 | manipulator->ChangeSettings(&settings); | |||
1060 | target->SendMessage(HS_MANIPULATOR_ADJUSTING_FINISHED'Mafi'); | |||
1061 | break; | |||
1062 | ||||
1063 | default: | |||
1064 | WindowGUIManipulatorView::MessageReceived(message); | |||
1065 | break; | |||
1066 | } | |||
1067 | } | |||
1068 | ||||
1069 | ||||
1070 | void WaveManipulatorView::ChangeSettings(WaveManipulatorSettings *s) | |||
1071 | { | |||
1072 | settings = *s; | |||
1073 | BWindow *window = Window(); | |||
1074 | ||||
1075 | if (window != NULL__null) { | |||
1076 | window->Lock(); | |||
1077 | ||||
1078 | wave_length_slider->SetValue(settings.wave_length); | |||
1079 | wave_amount_slider->SetValue(settings.wave_amount); | |||
1080 | ||||
1081 | window->Unlock(); | |||
1082 | } | |||
1083 | } |