MAINT: refactor packbits/unpackbits

Pushes the GIL release one loop outward.
I tried to inline it, but the function became very long and had too many variables for my taste, so I decided to leave the algorithm in this function and the boilerplate (ndarray handling, corner cases) in the other.