Rewrite scaler_ctx_scale to make it more efficient