darrenlafreniere / lafarren-image-completer

Implementation of the research titled: "Image Completion Using Efficient Belief Propagation via Priority Scheduling and Dynamic Pruning"
http://www.lafarren.com/image-completer/
GNU General Public License v3.0
32 stars 18 forks source link

Magic numbers in GetIndexAndShift #37

Open daviddoria opened 13 years ago

daviddoria commented 13 years ago

There is a 7 and 8 that should be commented.

daviddoria commented 13 years ago

line 185 of Label.cpp

The data is stored as a bit array (like a bool array, but there are 8 data points stored in each byte instead of just 1). The /8 determines which byte it is in. The &7 keeps the lower 3 bits, as there are only 8 bits in a byte so the shift output will be from 0 to 7. ?

it might help to think of the /8 as a >>3

and in that sense, an absolute 32-bit integer index resembles BBBBBBBBBBBBBBBBBBBBBBBBBBBBB.bbb where the Bs contain the byte index and the b's contain the bit indices within the byte