Optimised apply_weight_helper function

Function is used when processing 24-bit files, this change results in a
speed increase