flip pixel buffer

I have a 3D scene which I am rendering in a GLUT window. I want to take snapshots of the scene randomly and display them on another machine as JPG images. I capture pixel data using glReadPixels and convert to JPG but I see that the images are flipped on Y-AXIS. When I flip the pixel data using 2 for loops everything works fine. But is there a more efficient way of flipping pixel data obtained from glReadPixels? I cant use glScale(1, -1, 1) before rendering since this would flip 3D scene as well.