Bug Summary

File:home/HaikuArchives/ArtPaint/addons/AddOns/Blur/Blur.cpp
Warning:line 226, column 7
Value stored to 'blur_alpha' during its initialization is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-haiku -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name Blur.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /boot/system/lib/clang/12.0.1 -iquote ./ -iquote ../../UtilityClasses/ -iquote ./ -iquote ../../../artpaint/application -iquote ../../../artpaint/controls -iquote ../../../artpaint/layers -iquote ../../../artpaint/paintwindow -iquote ../../../artpaint/tools -iquote ../../../artpaint/viewmanipulators -iquote ../../../artpaint/windows -internal-isystem /system/develop/headers/c++ -internal-isystem /system/develop/headers/c++/x86_64-unknown-haiku -internal-isystem /system/develop/headers/c++/backward -O3 -fdeprecated-macro -fdebug-compilation-dir /boot/home/HaikuArchives/ArtPaint/addons/AddOns/Blur -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /tmp/scan-build-2022-06-19-103017-1294-1 -x c++ Blur.cpp
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 <LayoutBuilder.h>
12#include <Node.h>
13#include <StatusBar.h>
14#include <Slider.h>
15#include <Window.h>
16
17#include "AddOns.h"
18#include "Blur.h"
19#include "ManipulatorInformer.h"
20#include "Selection.h"
21
22#include <new>
23
24#undef B_TRANSLATION_CONTEXT"AddOns_Blur"
25#define B_TRANSLATION_CONTEXT"AddOns_Blur" "AddOns_Blur"
26
27
28#ifdef __cplusplus201402L
29extern "C" {
30#endif
31 int32 add_on_api_version = ADD_ON_API_VERSION;
32 char name[255] = B_TRANSLATE_MARK("Blur" B_UTF8_ELLIPSIS)("Blur" "\xE2\x80\xA6");
33 char menu_help_string[255] = B_TRANSLATE_MARK("Adds a blur.")("Adds a blur.");
34 add_on_types add_on_type = BLUR_FILTER_ADD_ON;
35#ifdef __cplusplus201402L
36}
37#endif
38
39
40Manipulator* instantiate_add_on(BBitmap *bm,ManipulatorInformer *i)
41{
42 delete i;
43 return new BlurManipulator(bm);
44}
45
46
47
48
49BlurManipulator::BlurManipulator(BBitmap *bm)
50 : WindowGUIManipulator()
51{
52 preview_bitmap = NULL__null;
53 wide_copy_of_the_preview_bitmap = NULL__null;
54 tall_copy_of_the_preview_bitmap = NULL__null;
55
56 config_view = NULL__null;
57 settings.blur_amount = 5;
58
59 SetPreviewBitmap(bm);
60}
61
62
63BlurManipulator::~BlurManipulator()
64{
65 if (tall_copy_of_the_preview_bitmap != NULL__null) {
66 delete tall_copy_of_the_preview_bitmap;
67 tall_copy_of_the_preview_bitmap = NULL__null;
68 }
69 if (wide_copy_of_the_preview_bitmap != NULL__null) {
70 delete wide_copy_of_the_preview_bitmap;
71 wide_copy_of_the_preview_bitmap = NULL__null;
72 }
73 if (config_view != NULL__null) {
74 config_view->RemoveSelf();
75 delete config_view;
76 }
77}
78
79
80BBitmap* BlurManipulator::ManipulateBitmap(ManipulatorSettings *set,BBitmap *original,Selection *selection,BStatusBar *status_bar)
81{
82 BlurManipulatorSettings *new_settings = dynamic_cast<BlurManipulatorSettings*>(set);
83
84 if (new_settings == NULL__null)
85 return NULL__null;
86
87 if (original == NULL__null)
88 return NULL__null;
89
90 if (new_settings->blur_amount < 1) {
91 return NULL__null;
92 }
93
94 BBitmap *source_bitmap;
95 BBitmap *target_bitmap;
96 BBitmap *new_bitmap = NULL__null;
97
98 if (original == preview_bitmap) {
99 return original;
100 }
101 else {
102// target_bitmap = original;
103// source_bitmap =
104// new_bitmap = source_bitmap;
105 }
106
107// CalculateBlur(source_bitmap,target_bitmap,1,new_settings,selection,status_bar);
108
109 return original;
110}
111
112
113int32 BlurManipulator::PreviewBitmap(Selection *sel, bool full_quality,BRegion *updated_region)
114{
115 updated_region->Set(preview_bitmap->Bounds());
116// if ((settings == previous_settings) == FALSE) {
117// last_calculated_quality = lowest_allowed_quality;
118// previous_settings = settings;
119// }
120// else
121// last_calculated_quality = floor(last_calculated_quality/2.0);
122//
123// if (full_quality == TRUE) {
124// if (last_calculated_quality > 1)
125// last_calculated_quality = 1;
126// }
127//
128// if (last_calculated_quality == 1)
129// CalculateBlur(copy_of_the_preview_bitmap,preview_bitmap,1,&settings,sel,NULL);
130//
131// else if (last_calculated_quality == 2)
132// CalculateBlur(half_preview_bitmap,preview_bitmap,2,&settings,sel,NULL);
133//
134// else if (last_calculated_quality == 4)
135// CalculateBlur(quarter_preview_bitmap,preview_bitmap,4,&settings,sel,NULL);
136//
137// else if (last_calculated_quality == 8)
138// CalculateBlur(eight_preview_bitmap,preview_bitmap,8,&settings,sel,NULL);
139//
140// return last_calculated_quality;
141 if ((settings == previous_settings) == FALSE0) {
142 // The blur will be done separably. First in the vertical direction and then in horizontal
143 // direction.
144 thread_count = GetSystemCpuCount();
145 tall_bits = (uint32*)tall_copy_of_the_preview_bitmap->Bits();
146 wide_bits = (uint32*)wide_copy_of_the_preview_bitmap->Bits();
147 final_bits = (uint32*)preview_bitmap->Bits();
148 tall_bpr = tall_copy_of_the_preview_bitmap->BytesPerRow()/4;
149 wide_bpr = wide_copy_of_the_preview_bitmap->BytesPerRow()/4;
150 final_bpr = preview_bitmap->BytesPerRow()/4;
151 final_width = preview_bitmap->Bounds().Width();
152 final_height = preview_bitmap->Bounds().Height();
153 selection = sel;
154 status_bar = NULL__null;
155 blur_amount = settings.blur_amount;
156 previous_settings = settings;
157 CalculateBlur();
158 return 1;
159 }
160 else
161 return DRAW_NOTHING;
162}
163
164
165void BlurManipulator::CalculateBlur()
166{
167 thread_id *threads = new thread_id[thread_count];
168
169 for (int32 i=0;i<thread_count;i++) {
170 threads[i] = spawn_thread(thread_entrythread_func,"vertical_blur_thread",B_NORMAL_PRIORITY10,this);
171 resume_thread(threads[i]);
172 send_data(threads[i],VERTICAL_THREAD,NULL__null,0);
173 send_data(threads[i],i,NULL__null,0);
174 }
175 for (int32 i=0;i<thread_count;i++) {
176 int32 return_value;
177 wait_for_thread(threads[i],&return_value);
178 }
179
180 for (int32 i=0;i<thread_count;i++) {
181 threads[i] = spawn_thread(thread_entrythread_func,"horizontal_blur_thread",B_NORMAL_PRIORITY10,this);
182 resume_thread(threads[i]);
183 send_data(threads[i],HORIZONTAL_THREAD,NULL__null,0);
184 send_data(threads[i],i,NULL__null,0);
185 }
186 for (int32 i=0;i<thread_count;i++) {
187 int32 return_value;
188 wait_for_thread(threads[i],&return_value);
189 }
190
191 delete[] threads;
192}
193
194
195int32 BlurManipulator::thread_entrythread_func(void *data)
196{
197 BlurManipulator *this_pointer = (BlurManipulator*)data;
198 thread_id sender;
199 int32 type = receive_data(&sender,NULL__null,0);
200 int32 thread_number = receive_data(&sender,NULL__null,0);
201 if (this_pointer != NULL__null) {
202 if (type == VERTICAL_THREAD) {
203 this_pointer->VerticalBlur(thread_number);
204 }
205 else {
206 this_pointer->HorizontalBlur(thread_number);
207 }
208 return B_OK((int)0);
209 }
210 return B_ERROR(-1);
211}
212
213
214int32 BlurManipulator::VerticalBlur(int32 thread_number)
215{
216 // vertical blur will be done columnwise so that we can use the
217 // partial sums.
218 int32 left = (final_width) / thread_count * thread_number;
219 int32 right = min_c(left + (final_width+1) / thread_count,final_width)((left + (final_width+1) / thread_count)>(final_width)?(final_width
):(left + (final_width+1) / thread_count))
;
220 float status_bar_update_amount = 50.0 / thread_count / (right-left) * 40;
221 int32 height = final_height;
222 uint32 *source_bits = tall_bits;
223 int32 source_bpr = tall_bpr;
224 uint32 *target_bits = wide_bits;
225 int32 target_bpr = wide_bpr;
226 bool blur_alpha = settings.blur_alpha;
Value stored to 'blur_alpha' during its initialization is never read
227
228 source_bits += MAX_BLUR_AMOUNT30*source_bpr;
229 union {
230 uint8 bytes[4];
231 uint32 word;
232 } color;
233 float red;
234 float green;
235 float blue;
236 float alpha;
237 float divider = 1.0/(2*blur_amount+1);
238 BWindow *status_bar_window = NULL__null;
239 if (status_bar != NULL__null)
240 status_bar_window = status_bar->Window();
241
242 for (int32 x=left;x<=right;x++) {
243 // Calculate the first pixel for this column.
244 red = green = blue = alpha = 0;
245 for (int32 dy=-blur_amount;dy<=blur_amount;dy++) {
246 color.word = *(source_bits + x + dy*source_bpr);
247 if (color.bytes[3] != 0) {
248 blue += color.bytes[0];
249 green += color.bytes[1];
250 red += color.bytes[2];
251 }
252 alpha += color.bytes[3];
253 }
254 color.bytes[0] = blue*divider;
255 color.bytes[1] = green*divider;
256 color.bytes[2] = red*divider;
257 color.bytes[3] = alpha*divider;
258 *(target_bits + x + MAX_BLUR_AMOUNT30) = color.word;
259
260 int32 positive_source_y_offset = (blur_amount+1) * source_bpr;
261 int32 negative_source_y_offset = (-blur_amount)*source_bpr;
262 int32 target_y_offset = 1 * target_bpr;
263 for (int32 y=1;y<=height;y++) {
264 color.word = *(source_bits + x + negative_source_y_offset);
265 if (color.bytes[3] != 0) {
266 blue -= color.bytes[0];
267 green -= color.bytes[1];
268 red -= color.bytes[2];
269 }
270 alpha -= color.bytes[3];
271
272 color.word = *(source_bits + x + positive_source_y_offset);
273 if (color.bytes[3] != 0) {
274 blue += color.bytes[0];
275 green += color.bytes[1];
276 red += color.bytes[2];
277 }
278 alpha += color.bytes[3];
279
280 color.bytes[0] = blue*divider;
281 color.bytes[1] = green*divider;
282 color.bytes[2] = red*divider;
283 color.bytes[3] = alpha*divider;
284 *(target_bits + x+MAX_BLUR_AMOUNT30 + target_y_offset) = color.word;
285 positive_source_y_offset += source_bpr;
286 negative_source_y_offset += source_bpr;
287 target_y_offset += target_bpr;
288 }
289 if (((x%40) == 0) && (status_bar_window != NULL__null) && (status_bar_window->LockWithTimeout(0) == B_OK((int)0))) {
290 status_bar->Update(status_bar_update_amount);
291 status_bar_window->Unlock();
292 }
293 }
294 return B_OK((int)0);
295}
296
297int32 BlurManipulator::HorizontalBlur(int32 thread_number)
298{
299 int32 top = (final_height) / thread_count * thread_number;
300 int32 bottom = min_c(top + (final_height+1) / thread_count,final_height)((top + (final_height+1) / thread_count)>(final_height)?(final_height
):(top + (final_height+1) / thread_count))
;
301 float status_bar_update_amount = 50.0 / thread_count / (bottom-top)*40.0;
302 int32 width = final_width;
303 uint32 *source_bits = wide_bits;
304 int32 source_bpr = wide_bpr;
305 uint32 *target_bits = final_bits;
306 int32 target_bpr = final_bpr;
307 bool blur_alpha = settings.blur_alpha;
308 union {
309 uint8 bytes[4];
310 uint32 word;
311 } color;
312 float red;
313 float green;
314 float blue;
315 float alpha;
316 float divider = 1.0/(2*blur_amount+1);
317 // In this loop we can use the sums that we already have calculated to remove the innermost
318 // loop.
319
320 BWindow *status_bar_window = NULL__null;
321 if (status_bar != NULL__null)
322 status_bar_window = status_bar->Window();
323
324 source_bits += top * source_bpr;
325 target_bits += top * target_bpr;
326
327 if ((selection == NULL__null) || (selection->IsEmpty())) {
328 for (int32 y=top;y<=bottom;y++) {
329 for (int32 dx=0;dx<MAX_BLUR_AMOUNT30;dx++) {
330 *(source_bits + dx) = *(source_bits + MAX_BLUR_AMOUNT30);
331 *(source_bits + source_bpr - dx - 1) = *(source_bits + source_bpr - MAX_BLUR_AMOUNT30-1);
332 }
333 source_bits += MAX_BLUR_AMOUNT30;
334 // Calculate the first pixel for this row.
335 red = green = blue = alpha = 0;
336 for (int32 dx=-blur_amount;dx<=blur_amount;dx++) {
337 color.word = *(source_bits + dx);
338 if (color.bytes[3] != 0) {
339 blue += color.bytes[0];
340 green += color.bytes[1];
341 red += color.bytes[2];
342 }
343 alpha += color.bytes[3];
344 }
345 color.bytes[0] = blue*divider;
346 color.bytes[1] = green*divider;
347 color.bytes[2] = red*divider;
348 color.bytes[3] = alpha*divider;
349 *target_bits++ = color.word;
350 ++source_bits;
351 for (int32 x=1;x<=width;x++) {
352 color.word = *(source_bits - blur_amount - 1);
353 if (color.bytes[3] != 0) {
354 blue -= color.bytes[0];
355 green -= color.bytes[1];
356 red -= color.bytes[2];
357 }
358 alpha -= color.bytes[3];
359
360 color.word = *(source_bits + blur_amount);
361 if (color.bytes[3] != 0) {
362 blue += color.bytes[0];
363 green += color.bytes[1];
364 red += color.bytes[2];
365 }
366 alpha += color.bytes[3];
367
368 color.bytes[0] = blue*divider;
369 color.bytes[1] = green*divider;
370 color.bytes[2] = red*divider;
371 color.bytes[3] = alpha*divider;
372 *target_bits++ = color.word;
373 ++source_bits;
374 }
375 source_bits += MAX_BLUR_AMOUNT30;
376 if (((y%40) == 0) && (status_bar_window != NULL__null) && (status_bar_window->LockWithTimeout(0) == B_OK((int)0))) {
377 status_bar->Update(status_bar_update_amount);
378 status_bar_window->Unlock();
379 }
380 }
381 }
382 else if (selection->IsEmpty() == false) {
383 for (int32 y=top;y<=bottom;y++) {
384 for (int32 dx=0;dx<MAX_BLUR_AMOUNT30;dx++) {
385 *(source_bits + dx) = *(source_bits + MAX_BLUR_AMOUNT30);
386 *(source_bits + source_bpr - dx - 1) = *(source_bits + source_bpr - MAX_BLUR_AMOUNT30-1);
387 }
388 source_bits += MAX_BLUR_AMOUNT30;
389 // Calculate the first pixel for this row.
390 red = green = blue = alpha = 0;
391 for (int32 dx=-blur_amount;dx<=blur_amount;dx++) {
392 color.word = *(source_bits + dx);
393 if (color.bytes[3] != 0) {
394 blue += color.bytes[0];
395 green += color.bytes[1];
396 red += color.bytes[2];
397 }
398 alpha += color.bytes[3];
399 }
400 if (selection->ContainsPoint(0,y)) {
401 color.bytes[0] = blue*divider;
402 color.bytes[1] = green*divider;
403 color.bytes[2] = red*divider;
404 color.bytes[3] = alpha*divider;
405 *target_bits++ = color.word;
406 ++source_bits;
407 }
408 else {
409 ++source_bits;
410 ++target_bits;
411 }
412 for (int32 x=1;x<=width;x++) {
413 color.word = *(source_bits - blur_amount - 1);
414 if (color.bytes[3] != 0) {
415 blue -= color.bytes[0];
416 green -= color.bytes[1];
417 red -= color.bytes[2];
418 }
419 alpha -= color.bytes[3];
420
421 color.word = *(source_bits + blur_amount);
422 if (color.bytes[3] != 0) {
423 blue += color.bytes[0];
424 green += color.bytes[1];
425 red += color.bytes[2];
426 }
427 alpha += color.bytes[3];
428
429 if (selection->ContainsPoint(x,y)) {
430 color.bytes[0] = blue*divider;
431 color.bytes[1] = green*divider;
432 color.bytes[2] = red*divider;
433 color.bytes[3] = alpha*divider;
434 *target_bits++ = color.word;
435 ++source_bits;
436 }
437 else {
438 ++target_bits;
439 ++source_bits;
440 }
441 }
442 source_bits += MAX_BLUR_AMOUNT30;
443 if (((y%40) == 0) && (status_bar_window != NULL__null) && (status_bar_window->LockWithTimeout(0) == B_OK((int)0))) {
444 status_bar->Update(status_bar_update_amount);
445 status_bar_window->Unlock();
446 }
447 }
448 }
449 return B_OK((int)0);
450}
451
452
453void BlurManipulator::SetPreviewBitmap(BBitmap *bm)
454{
455 if (bm != preview_bitmap) {
456 if (wide_copy_of_the_preview_bitmap != NULL__null) {
457 delete wide_copy_of_the_preview_bitmap;
458 wide_copy_of_the_preview_bitmap = NULL__null;
459 }
460 if (tall_copy_of_the_preview_bitmap != NULL__null) {
461 delete tall_copy_of_the_preview_bitmap;
462 tall_copy_of_the_preview_bitmap = NULL__null;
463 }
464 if (bm != NULL__null) {
465 preview_bitmap = bm;
466 BRect bounds = preview_bitmap->Bounds();
467 bounds.InsetBy(0,-MAX_BLUR_AMOUNT30);
468 bounds.OffsetTo(0,0);
469 tall_copy_of_the_preview_bitmap = new BBitmap(bounds,B_RGB32);
470 if (tall_copy_of_the_preview_bitmap->IsValid() == FALSE0) {
471 throw std::bad_alloc();
472 }
473 bounds.InsetBy(-MAX_BLUR_AMOUNT30,MAX_BLUR_AMOUNT30);
474 bounds.OffsetTo(0,0);
475 wide_copy_of_the_preview_bitmap = new BBitmap(bounds,B_RGB32);
476 if (wide_copy_of_the_preview_bitmap->IsValid() == FALSE0) {
477 delete tall_copy_of_the_preview_bitmap;
478 throw std::bad_alloc();
479 }
480
481
482 // After allocating the bitmaps we should copy the data from preview_bitmap to
483 // tall_copy_of_the_preview_bitmap.
484 uint32 *source_bits = (uint32*)preview_bitmap->Bits();
485 uint32 *target_bits = (uint32*)tall_copy_of_the_preview_bitmap->Bits();
486 int32 source_bpr = preview_bitmap->BytesPerRow()/4;
487 int32 target_bpr = tall_copy_of_the_preview_bitmap->BytesPerRow()/4;
488 int32 width = preview_bitmap->Bounds().Width();
489 int32 height = preview_bitmap->Bounds().Height();
490 // First copy the first row MAX_BLUR_AMOUNT times.
491 for (int32 y=0;y<MAX_BLUR_AMOUNT30;y++) {
492 for (int32 x=0;x<=width;x++) {
493 *target_bits++ = *source_bits++;
494 }
495 source_bits -= source_bpr;
496 }
497 // Then copy the actual bitmap
498 for (int32 y=0;y<=height;y++) {
499 for (int32 x=0;x<=width;x++) {
500 *target_bits++ = *source_bits++;
501 }
502 }
503 // Then copy the last row MAX_BLUR_AMOUNT times
504 for (int32 y=0;y<MAX_BLUR_AMOUNT30;y++) {
505 source_bits -= source_bpr;
506 for (int32 x=0;x<=width;x++) {
507 *target_bits++ = *source_bits++;
508 }
509 }
510 }
511 else {
512 preview_bitmap = NULL__null;
513 tall_copy_of_the_preview_bitmap = NULL__null;
514 wide_copy_of_the_preview_bitmap = NULL__null;
515 }
516 }
517}
518
519
520void BlurManipulator::Reset(Selection*)
521{
522 if (preview_bitmap != NULL__null) {
523 uint32 *source_bits = (uint32*)tall_copy_of_the_preview_bitmap->Bits();
524 uint32 *target_bits = (uint32*)preview_bitmap->Bits();
525 int32 source_bpr = tall_copy_of_the_preview_bitmap->BytesPerRow()/4;
526 int32 target_bpr = preview_bitmap->BytesPerRow()/4;
527
528 for (int32 y=0;y<preview_bitmap->Bounds().Height()+1;y++) {
529 for (int32 x=0;x<target_bpr;x++) {
530 *(target_bits + x + y*target_bpr) = *(source_bits + x + (y+MAX_BLUR_AMOUNT30)*source_bpr);
531 }
532 }
533 }
534}
535
536ManipulatorSettings* BlurManipulator::ReturnSettings()
537{
538 return new BlurManipulatorSettings(&settings);
539}
540
541const char* BlurManipulator::ReturnHelpString()
542{
543 return B_TRANSLATE("Adds a blur.")BLocaleRoster::Default()->GetCatalog()->GetString(("Adds a blur."
), "AddOns_Blur")
;
544}
545
546
547const char* BlurManipulator::ReturnName()
548{
549 return B_TRANSLATE("Blur")BLocaleRoster::Default()->GetCatalog()->GetString(("Blur"
), "AddOns_Blur")
;
550}
551
552
553void BlurManipulator::ChangeSettings(ManipulatorSettings *set)
554{
555 BlurManipulatorSettings *new_settings = dynamic_cast<BlurManipulatorSettings*>(set);
556
557 if (new_settings != NULL__null) {
558 settings = *new_settings;
559 }
560}
561
562BView* BlurManipulator::MakeConfigurationView(const BMessenger& target)
563{
564 config_view = new BlurManipulatorView(BRect(0,0,0,0),this,target);
565 config_view->ChangeSettings(&settings);
566 return config_view;
567}
568
569
570
571status_t BlurManipulator::ReadSettings(BNode *node)
572{
573 if (node != NULL__null) {
574 int32 new_amount;
575 if (node->ReadAttr("blur_amount",B_INT32_TYPE,0,&new_amount,sizeof(int32)) == sizeof(int32)) {
576 settings.blur_amount = new_amount;
577 previous_settings.blur_amount = new_amount-1;
578 return B_OK((int)0);
579 }
580 else
581 return B_ERROR(-1);
582 }
583 else
584 return B_ERROR(-1);
585}
586
587status_t BlurManipulator::WriteSettings(BNode *node)
588{
589 if (node != NULL__null) {
590 if (node->WriteAttr("blur_amount",B_INT32_TYPE,0,&settings.blur_amount,sizeof(int32)) == sizeof(int32))
591 return B_OK((int)0);
592 else
593 return B_ERROR(-1);
594 }
595 else
596 return B_ERROR(-1);
597}
598
599//***************
600
601
602BlurManipulatorView::BlurManipulatorView(BRect rect,BlurManipulator *manip,
603 const BMessenger& t)
604 : WindowGUIManipulatorView()
605{
606 manipulator = manip;
607 target = new BMessenger(t);
608
609 blur_amount_slider = new BSlider("blur_amount_slider",
610 B_TRANSLATE("Blur amount:")BLocaleRoster::Default()->GetCatalog()->GetString(("Blur amount:"
), "AddOns_Blur")
, new BMessage(BLUR_AMOUNT_CHANGED'Bamc'), 1, MAX_BLUR_AMOUNT30,
611 B_HORIZONTAL, B_TRIANGLE_THUMB);
612 blur_amount_slider->SetLimitLabels(B_TRANSLATE("Low")BLocaleRoster::Default()->GetCatalog()->GetString(("Low"
), "AddOns_Blur")
, B_TRANSLATE("High")BLocaleRoster::Default()->GetCatalog()->GetString(("High"
), "AddOns_Blur")
);
613 blur_amount_slider->SetHashMarks(B_HASH_MARKS_BOTTOM);
614 blur_amount_slider->SetHashMarkCount(11);
615 blur_amount_slider->SetModificationMessage(new BMessage(BLUR_AMOUNT_CHANGE_STARTED'Bacs'));
616
617// BRect frame_rect = blur_amount_slider->Frame();
618// frame_rect.bottom = frame_rect.top;
619// transparency_checkbox = new BCheckBox(frame_rect,"transparency_checkbox","Blur Transparency",new BMessage(BLUR_TRANSPARENCY_CHANGED));
620
621 BLayoutBuilder::Group<>(this, B_VERTICAL)
622 .Add(blur_amount_slider)
623 .SetInsets(B_USE_SMALL_INSETS)
624 .End();
625
626 preview_started = FALSE0;
627}
628
629BlurManipulatorView::~BlurManipulatorView()
630{
631 delete target;
632}
633
634
635void BlurManipulatorView::AttachedToWindow()
636{
637 WindowGUIManipulatorView::AttachedToWindow();
638 blur_amount_slider->SetTarget(BMessenger(this));
639// transparency_checkbox->SetTarget(this);
640}
641
642
643void BlurManipulatorView::MessageReceived(BMessage *message)
644{
645 switch (message->what) {
646 case BLUR_AMOUNT_CHANGE_STARTED'Bacs':
647 if (preview_started == FALSE0) {
648 preview_started = TRUE1;
649 target->SendMessage(HS_MANIPULATOR_ADJUSTING_STARTED'Mast');
650 }
651 settings.blur_amount = blur_amount_slider->Value();
652 manipulator->ChangeSettings(&settings);
653 break;
654
655 case BLUR_AMOUNT_CHANGED'Bamc':
656 settings.blur_amount = blur_amount_slider->Value();
657 manipulator->ChangeSettings(&settings);
658 preview_started = FALSE0;
659 target->SendMessage(HS_MANIPULATOR_ADJUSTING_FINISHED'Mafi');
660 break;
661
662// case BLUR_TRANSPARENCY_CHANGED:
663// settings.blur_alpha = (transparency_checkbox->Value() == B_CONTROL_ON);
664// manipulator->ChangeSettings(&settings);
665// break;
666
667 default:
668 WindowGUIManipulatorView::MessageReceived(message);
669 break;
670 }
671}
672
673
674void BlurManipulatorView::ChangeSettings(BlurManipulatorSettings *s)
675{
676 settings = *s;
677
678 BWindow *window = Window();
679
680 if (window != NULL__null)
681 window->Lock();
682
683 blur_amount_slider->SetValue(settings.blur_amount);
684
685 if (window != NULL__null)
686 window->Unlock();
687
688}