以下代码从framebuffer(readpixels,openGL库的函数之后)创建一个jpeg。从帧缓冲区创建的JPEG旋转180度
问题是创建的jpeg(test.jpeg)向左旋转180度。
你能告诉我错误在哪里吗?
void CTaksiOGL::GetFrameFullSize(CVideoFrame& frame)
{
// Gets current frame to be stored in video file.
// select back buffer
s_glReadBuffer(GL_BACK);
// read the pixels data
s_glReadPixels(0, 0, frame.m_Size.cx, frame.m_Size.cy, GL_RGB, GL_UNSIGNED_BYTE, frame.m_pPixels);
// Adjust pixel encodings: RGB -> BGR
SwapColorComponents(frame.m_pPixels, frame.m_Size.cx, frame.m_Size.cy);
FILE* outfile = fopen("C:\\testgrab\\test.jpeg", "wb");
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
jpeg_stdio_dest(&cinfo, outfile);
GLubyte* flip = new GLubyte[sizeof(GLubyte)*frame.m_Size.cx*frame.m_Size.cy*3];
cinfo.image_width = frame.m_Size.cx;
cinfo.image_height = frame.m_Size.cy;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
int width=frame.m_Size.cx;
int height=frame.m_Size.cy;
jpeg_set_defaults(&cinfo);
/*set the quality [0..100] */
jpeg_set_quality (&cinfo, 75, true);
jpeg_start_compress(&cinfo, true);
JSAMPROW row_pointer; /* pointer to a single row */
// OpenGL writes from bottom to top.
// libjpeg goes from top to bottom.
// flip lines.
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
flip[(y*height+x)*3] = frame.m_pPixels[((width-1-y)*height+x)*3];
flip[(y*height+x)*3+1] = frame.m_pPixels[((width-1-y)*height+x)*3+1];
flip[(y*height+x)*3+2] = frame.m_pPixels[((width-1-y)*height+x)*3+2];
}
}
while (cinfo.next_scanline < cinfo.image_height) {
row_pointer = (JSAMPROW) &frame.m_pPixels[cinfo.next_scanline*width*3];
jpeg_write_scanlines(&cinfo, &row_pointer, 1);
}
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
fclose(outfile);
}
你应该修正你的indendation,这样我们可以更好地帮助你 –
你的意思是90度(四分之一回合)?没有任何东西是“向左180度”,180度与上下颠倒图像相同,并且无论您将图像向左还是向右旋转,结果都是相同的。 – Lindydancer
向左180度? \ *咯咯的笑容* –