Why double malloc and why not swap through a temporary buffer?
Something like that:
GLubyte * raw = (GLubyte *) wyMalloc(size); LOGD("raw address %p", raw); glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, raw); const size_t end = h/2; const size_t W = 4*w; GLubyte row[4*w]; for (int i=0; i <= end; i++) { void * top = raw + (h - i - 1)*W; void * bottom = raw + i*W; memcpy(row, top, W); memcpy(top, bottom, W); memcpy(bottom, row, W); }
source share