mightymandel v16

GPU-based Mandelbrot set explorer

completion.c
Go to the documentation of this file.
1 // mightymandel -- GPU-based Mandelbrot Set explorer
2 // Copyright (C) 2012,2013,2014,2015 Claude Heiland-Allen
3 // License GPL3+ http://www.gnu.org/licenses/gpl.html
4 
13 #include "completion.h"
14 #include "logging.h"
15 
16 void completion_start(struct completion *completion, int unescaped) {
17  completion->almost = false;
18  completion->done = false;
19  completion->iterations = 0;
20  completion->iteration_target = 1;
21  completion->unescaped = unescaped;
22  completion->escaped = 0;
23  completion->escaped_recently = 0;
24  debug_message("completion_start(): %d %d %d %d %s\n", completion->unescaped, completion->escaped, completion->escaped_recently, completion->iterations, completion->done ? "DONE" : "");
25 }
26 
27 void completion_reset(struct completion *completion, int unescaped) {
28  completion->almost = false;
29  completion->done = false;
30  completion->iterations = 0;
31  // don't reset iteration_target
32  completion->unescaped = unescaped;
33  completion->escaped = 0;
34  completion->escaped_recently = 0;
35  debug_message("completion_reset(): %d %d %d %d %s\n", completion->unescaped, completion->escaped, completion->escaped_recently, completion->iterations, completion->done ? "DONE" : "");
36 }
37 
38 bool completion_update(struct completion *completion, int unescaped, int escaped, int iterations, double sharpness) {
39  bool retval = false;
40  completion->iterations += iterations;
41  completion->unescaped = unescaped;
42  completion->escaped += escaped;
43  completion->escaped_recently += escaped;
44  debug_message("completion_update(): %d %d %d %d << %d %d %d\n", completion->unescaped, completion->escaped, completion->escaped_recently, completion->iterations, unescaped, escaped, iterations);
45  if (unescaped == 0) {
46  // no more unescaped pixels to iterate, must be done
47  completion->done = true;
48  retval = true;
49  } else if (completion->iterations >= completion->iteration_target) {
50  // have pixels ever escaped and is the current escape rate small?
51  if (completion->escaped > 0 && completion->escaped_recently <= sharpness * completion->unescaped) {
52  // it needs to happen twice, to avoid random failures when the
53  // first few pixels of an image escape
54  if (completion->almost) {
55  completion->done = true;
56  debug_message("done\n");
57  } else {
58  completion->almost = true;
59  debug_message("almost\n");
60  }
61  } else {
62  completion->almost = false;
63  }
64  completion->iteration_target <<= 1;
65  completion->escaped_recently = 0;
66  retval = true;
67  }
68  return retval;
69 }
70 
72  return completion->done;
73 }