Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

Commit

Permalink
[egl] fixed, bookmarks were inverted and saved as RGBA instead of BGR…
Browse files Browse the repository at this point in the history
…A. note that inverting should be handled by g_matrices operations but is not.
  • Loading branch information
davilla committed Jul 16, 2011
1 parent 44fe23d commit b5460dc
Showing 1 changed file with 52 additions and 2 deletions.
54 changes: 52 additions & 2 deletions xbmc/cores/VideoRenderers/LinuxRendererGLES.cpp
Expand Up @@ -28,6 +28,7 @@
#include <locale.h>
#include "guilib/MatrixGLES.h"
#include "LinuxRendererGLES.h"
#include "utils/fastmemcpy.h"
#include "utils/MathUtils.h"
#include "utils/GLUtils.h"
#include "settings/Settings.h"
Expand Down Expand Up @@ -1241,10 +1242,11 @@ bool CLinuxRendererGLES::RenderCapture(CRenderCapture* capture)

// clear framebuffer and invert Y axis to get non-inverted image
glDisable(GL_BLEND);

g_matrices.MatrixMode(MM_MODELVIEW);
g_matrices.PushMatrix();
g_matrices.Translatef(0, capture->GetHeight(), 0);
g_matrices.Scalef(1.0, -1.0f, 1.0f);
g_matrices.Translatef(0.0f, capture->GetHeight(), 0.0f);
g_matrices.Scalef(1.0f, -1.0f, 1.0f);

capture->BeginRender();

Expand All @@ -1253,6 +1255,54 @@ bool CLinuxRendererGLES::RenderCapture(CRenderCapture* capture)
glReadPixels(0, rv.y2 - capture->GetHeight(), capture->GetWidth(), capture->GetHeight(),
GL_RGBA, GL_UNSIGNED_BYTE, capture->GetRenderBuffer());

// OpenGLES returns byte in RGBA order but CRenderCapture needs BGRA order
/*
unsigned int pitch = capture->GetWidth() * 4;
unsigned char *dst, *pixels = (unsigned char*)capture->GetRenderBuffer();
for (unsigned int y = 0; y < capture->GetHeight(); y++)
{
dst = pixels + (y * pitch);
for (unsigned int x = 0; x < pitch; x+=4)
std::swap(dst[x], dst[x+2]);
}
*/
// flip top/bottom and swap RGBA to BGRA.
// we should NOT have to do this as the matrix transform
// should take care of this. TODO: figure out why.
{
int top = 0;
int bot = capture->GetHeight() - 1;
int rowbytes = capture->GetWidth() * 4;
unsigned char *base_ptr = (unsigned char*)capture->GetRenderBuffer();
unsigned char *rowbuffer = (unsigned char*)malloc(rowbytes);
unsigned char *t1_ptr, *b1_ptr, *b2_ptr, *rb_ptr;
while ( top < bot )
{
t1_ptr = base_ptr + (rowbytes * top++);
b2_ptr = b1_ptr = base_ptr + (rowbytes * bot--);

// save out top line.
fast_memcpy(rowbuffer, t1_ptr, rowbytes);
// copy bottom line to top, swapping from RGBA to BGRA
for (int x = 0; x < rowbytes; x+=4, b1_ptr+=4)
{
*t1_ptr++ = b1_ptr[2];
*t1_ptr++ = b1_ptr[1];
*t1_ptr++ = b1_ptr[0];
*t1_ptr++ = b1_ptr[3];
}
// copy saved top line to bottom, swapping from RGBA to BGRA
rb_ptr = rowbuffer;
for (int x = 0; x < rowbytes; x+=4, rb_ptr+=4)
{
*b2_ptr++ = rb_ptr[2];
*b2_ptr++ = rb_ptr[1];
*b2_ptr++ = rb_ptr[0];
*b2_ptr++ = rb_ptr[3];
}
}
free(rowbuffer);
}
capture->EndRender();

// revert model view matrix
Expand Down

0 comments on commit b5460dc

Please sign in to comment.