ljpegenc: split bgr encoding into a separate function