applyrules(): simplify opacity handling code