BGRA to BGR?

I want to encode a BGRA image to BGR so that I can encode it with nvjpeg. Is there a better way than manually copying everything but the alpha values to a new array?