MCPcopy Create free account
hub / github.com/Panzerschrek/Chasm-Reverse / LoadPalette

Function LoadPalette

PanzerChasm/images.cpp:64–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62}
63
64void LoadPalette(
65 const Vfs& vfs,
66 Palette& out_palette )
67{
68 const Vfs::FileContent palette_file= vfs.ReadFile( "CHASM2.PAL" );
69
70 // Convert from 6-bit to 8-bit.
71 for( unsigned int i= 0u; i < 768u; i++ )
72 out_palette[i]= palette_file[i] << 2u;
73
74 // Make color correction.
75 // TODO - do color correction as screen image postprocessing.
76 const float c_mix_k= 1.3f;
77 const float c_one_minux_mix_k= 1.0f - c_mix_k;
78
79 for( unsigned int i= 0u; i < 256u; i++ )
80 {
81 float rgb[3];
82 for( unsigned int j= 0u; j < 3u; j++ )
83 rgb[j]= float( out_palette[ i * 3u + j ] );
84 const float grey= ( rgb[0] + rgb[1] + rgb[2] ) / 3.0f;
85
86 for( unsigned int j= 0u; j < 3u; j++ )
87 {
88 const int c= static_cast<int>( std::round( rgb[j] * c_mix_k + grey * c_one_minux_mix_k ) );
89 out_palette[ i * 3u + j ]= std::max( std::min( c, 255 ), 0 );
90 }
91 }
92}
93
94void CreateConsoleBackground(
95 const Size2& size,

Callers 2

LoadGameResourcesFunction · 0.70
mainFunction · 0.50

Calls 1

ReadFileMethod · 0.80

Tested by

no test coverage detected