Bladeren bron

compensate for byte order

David Rose 16 jaren geleden
bovenliggende
commit
1a78b5851d
2 gewijzigde bestanden met toevoegingen van 32 en 1 verwijderingen
  1. 31 0
      direct/src/plugin/p3dInstance.cxx
  2. 1 1
      direct/src/plugin/p3dSession.cxx

+ 31 - 0
direct/src/plugin/p3dInstance.cxx

@@ -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();

+ 1 - 1
direct/src/plugin/p3dSession.cxx

@@ -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.