File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -51,9 +51,18 @@ void JE_loadPals( void )
5151 {
5252 for (int i = 0 ; i < 256 ; ++ i )
5353 {
54- palettes [p ][i ].r = getc (f ) << 2 ;
55- palettes [p ][i ].g = getc (f ) << 2 ;
56- palettes [p ][i ].b = getc (f ) << 2 ;
54+ // The VGA hardware palette used only 6 bits per component, so the values need to be rescaled to
55+ // 8 bits. The naive way to do this is to simply do (c << 2), padding it with 0's, however this
56+ // makes the maximum value 252 instead of the proper 255. A trick to fix this is to use the upper 2
57+ // bits of the original value instead. This ensures that the value goes to 255 as the original goes
58+ // to 63.
59+
60+ int c = getc (f );
61+ palettes [p ][i ].r = (c << 2 ) | (c >> 4 );
62+ c = getc (f );
63+ palettes [p ][i ].g = (c << 2 ) | (c >> 4 );
64+ c = getc (f );
65+ palettes [p ][i ].b = (c << 2 ) | (c >> 4 );
5766 }
5867 }
5968
You can’t perform that action at this time.
0 commit comments