Your program is many of orders of magnitude too convoluted and takes way too long to complete. Something simple like that should complete in milliseconds.
All you need to do is iterate over each pixel exactly once and add the values of all ellipses that are within range. Seems trivial. (there is no need to stack four FOR loops!). Also, the outer FOR loop does not seem to do anything useful. Why is it there?
You also have serious race conditions, for example there is no way to guarantee that the B^2 or A^2 local variables are being read after the control has been updated. Since there is no data dependency, the order is not predictable.