@@ -311,6 +311,22 @@ static void deallocateVideoFrame(void)
311311 glDeleteTextures (1 , & video_texture );
312312}
313313
314+ #ifndef __BIG_ENDIAN__
315+ const int Rshift = 0 ;
316+ const int Gshift = 8 ;
317+ const int Bshift = 16 ;
318+ const int Ashift = 24 ;
319+ // RGBmask is used only after right-shifting, so ignore the leftmost bit of each byte
320+ const int RGBmask = 0x007f7f7f ;
321+ const int Amask = 0xff000000 ;
322+ #else
323+ const int Rshift = 24 ;
324+ const int Gshift = 16 ;
325+ const int Bshift = 8 ;
326+ const int Ashift = 0 ;
327+ const int RGBmask = 0x7f7f7f00 ;
328+ const int Amask = 0x000000ff ;
329+ #endif
314330#define Vclip ( x ) ( (x > 0) ? ((x < 255) ? x : 255) : 0 )
315331// main routine to display video on screen.
316332static void video_write (bool update )
@@ -356,17 +372,17 @@ static void video_write(bool update)
356372 int G = Vclip ((A - 100 * U - (C >> 1 ) + 128 ) >> 8 );
357373 int B = Vclip ((A + 516 * U + 128 ) >> 8 );
358374
359- uint32_t rgba = (B << 16 ) | (G << 8 ) | (R << 0 ) | (0xFF << 24 );
375+ uint32_t rgba = (R << Rshift ) | (G << Gshift ) | (B << Bshift ) | (0xFF << Ashift );
360376
361377 RGBAframe [rgb_offset ] = rgba ;
362378 if (use_scanlines == SCANLINES_50 )
363379 {
364380 // halve the rgb values for a dimmed scanline
365- RGBAframe [rgb_offset + video_width ] = (rgba >> 1 & 0x007f7f7f ) | 0xff000000 ;
381+ RGBAframe [rgb_offset + video_width ] = (rgba >> 1 & RGBmask ) | Amask ;
366382 }
367383 else if (use_scanlines == SCANLINES_BLACK )
368384 {
369- RGBAframe [rgb_offset + video_width ] = ( 0xFF << 24 ) ;
385+ RGBAframe [rgb_offset + video_width ] = Amask ;
370386 }
371387 rgb_offset ++ ;
372388
@@ -378,16 +394,16 @@ static void video_write(bool update)
378394 G = Vclip ((A - 100 * U - (C >> 1 ) + 128 ) >> 8 );
379395 B = Vclip ((A + 516 * U + 128 ) >> 8 );
380396
381- rgba = (B << 16 ) | (G << 8 ) | (R << 0 ) | (0xFF << 24 );
397+ rgba = (R << Rshift ) | (G << Gshift ) | (B << Bshift ) | (0xFF << Ashift );
382398 RGBAframe [rgb_offset ] = rgba ;
383399 if (use_scanlines == SCANLINES_50 )
384400 {
385401 // halve the rgb values for a dimmed scanline
386- RGBAframe [rgb_offset + video_width ] = (rgba >> 1 & 0x007f7f7f ) | 0xff000000 ;
402+ RGBAframe [rgb_offset + video_width ] = (rgba >> 1 & RGBmask ) | Amask ;
387403 }
388404 else if (use_scanlines == SCANLINES_BLACK )
389405 {
390- RGBAframe [rgb_offset + video_width ] = ( 0xFF << 24 ) ;
406+ RGBAframe [rgb_offset + video_width ] = Amask ;
391407 }
392408 rgb_offset ++ ;
393409 }
0 commit comments