Simplify Fl_OpenGL_Display_Device::capture_gl_rectangle() under Mac OS.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11328 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2016-03-09 11:40:13 +00:00
parent fc3adbd7cb
commit d4577f0d0a
1 changed files with 6 additions and 23 deletions

View File

@ -41,11 +41,12 @@ Fl_OpenGL_Display_Device::Fl_OpenGL_Display_Device(Fl_OpenGL_Graphics_Driver *gr
#ifdef FL_CFG_GFX_QUARTZ
// convert BGRA to RGB and also exchange top and bottom
uchar *convert_BGRA_to_RGB(uchar *baseAddress, int w, int h, int mByteWidth)
{
uchar *newimg = new uchar[3*w*h];
uchar *to = newimg;
for (int i = 0; i < h; i++) {
for (int i = h-1; i >= 0; i--) {
uchar *from = baseAddress + i * mByteWidth;
for (int j = 0; j < w; j++, from += 4) {
#if __ppc__
@ -64,7 +65,6 @@ uchar *convert_BGRA_to_RGB(uchar *baseAddress, int w, int h, int mByteWidth)
Fl_RGB_Image* Fl_OpenGL_Display_Device::capture_gl_rectangle(Fl_Gl_Window* glw, int x, int y, int w, int h)
{
const int bytesperpixel = 4;
int factor = glw->pixels_per_unit();
if (factor > 1) {
w *= factor; h *= factor; x *= factor; y *= factor;
@ -78,31 +78,16 @@ Fl_RGB_Image* Fl_OpenGL_Display_Device::capture_gl_rectangle(Fl_Gl_Window* glw,
glPixelStorei(GL_PACK_SKIP_ROWS, 0);
glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
// Read a block of pixels from the frame buffer
int mByteWidth = w * bytesperpixel;
int mByteWidth = w * 4;
mByteWidth = (mByteWidth + 3) & ~3; // Align to 4 bytes
uchar *baseAddress = new uchar[mByteWidth * h];
glReadPixels(x, glw->pixel_h() - (y+h), w, h,
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
baseAddress);
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, baseAddress);
glPopClientAttrib();
baseAddress = convert_BGRA_to_RGB(baseAddress, w, h, mByteWidth);
mByteWidth = 3 * w;
// GL gives a bottom-to-top image, convert it to top-to-bottom
uchar *tmp = new uchar[mByteWidth];
uchar *p = baseAddress ;
uchar *q = baseAddress + (h-1)*mByteWidth;
for (int i = 0; i < h/2; i++, p += mByteWidth, q -= mByteWidth) {
memcpy(tmp, p, mByteWidth);
memcpy(p, q, mByteWidth);
memcpy(q, tmp, mByteWidth);
}
delete[] tmp;
Fl_RGB_Image *img = new Fl_RGB_Image(baseAddress, w, h, 3, mByteWidth);
Fl_RGB_Image *img = new Fl_RGB_Image(baseAddress, w, h, 3, 3 * w);
img->alloc_array = 1;
return img;
}
#elif defined(FL_CFG_GFX_GDI) || defined(FL_CFG_GFX_XLIB)
@ -110,7 +95,6 @@ Fl_RGB_Image* Fl_OpenGL_Display_Device::capture_gl_rectangle(Fl_Gl_Window *glw,
/* captures a rectangle of a Fl_Gl_Window window, and returns it as a RGB image
*/
{
const int bytesperpixel = 3;
glw->flush(); // forces a GL redraw, necessary for the glpuzzle demo
// Read OpenGL context pixels directly.
// For extra safety, save & restore OpenGL states that are changed
@ -120,14 +104,13 @@ Fl_RGB_Image* Fl_OpenGL_Display_Device::capture_gl_rectangle(Fl_Gl_Window *glw,
glPixelStorei(GL_PACK_SKIP_ROWS, 0);
glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
// Read a block of pixels from the frame buffer
int mByteWidth = w * bytesperpixel;
int mByteWidth = w * 3;
mByteWidth = (mByteWidth + 3) & ~3; // Align to 4 bytes
uchar *baseAddress = new uchar[mByteWidth * h];
glReadPixels(x, glw->pixel_h() - (y+h), w, h,
GL_RGB, GL_UNSIGNED_BYTE,
baseAddress);
glPopClientAttrib();
// GL gives a bottom-to-top image, convert it to top-to-bottom
uchar *tmp = new uchar[mByteWidth];
uchar *p = baseAddress ;