compensate for byte order

This commit is contained in:
David Rose 2009-07-16 01:49:44 +00:00
parent 375fd5c352
commit 1a78b5851d
2 changed files with 32 additions and 1 deletions

View File

@ -994,6 +994,37 @@ paint_window() {
memcpy(_reversed_buffer + (y_size - 1 - yi) * rowsize,
(char *)framebuffer + yi * rowsize,
rowsize);
#ifdef __BIG_ENDIAN__
// It appears that kBGRAPixelFormat, below, is ignored on
// big-endian machines, and it is treated as KARGBPixelFormat
// regardless of what we specify. Vexing. To compensate for
// this, we have to reverse the color channels ourselves on
// big-endian machines.
/*
unsigned int *b = (unsigned int *)(_reversed_buffer + (y_size - 1 - yi) * rowsize);
for (int xi = 0; xi < x_size; ++xi) {
unsigned int w = *b;
*b = ((w >> 24) & 0xff) | ((w >> 8) & 0xff00) | ((w << 8) & 0xff0000) | ((w << 24) & 0xff000000);
++b;
}
*/
// This was measured to be faster than the above.
unsigned char *t = (unsigned char *)(_reversed_buffer + (y_size - 1 - yi) * rowsize);
for (int xi = 0; xi < x_size; ++xi) {
unsigned char b = t[0];
unsigned char g = t[1];
unsigned char r = t[2];
unsigned char a = t[3];
t[0] = a;
t[1] = r;
t[2] = g;
t[3] = b;
t += 4;
}
#endif
}
_swbuffer->close_read_framebuffer();

View File

@ -140,7 +140,7 @@ shutdown() {
struct timeval now;
gettimeofday(&now, NULL);
int now_ms = now.tv_sec * 1000 + now.tv_usec / 1000;
double elapsed = now_ms - start_ms;
int elapsed = now_ms - start_ms;
if (elapsed > max_wait_ms) {
// Tired of waiting. Kill the process.