-/*\r
-Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
-For a list of contributors, see the accompanying CONTRIBUTORS file.\r
-\r
-This file is part of GtkRadiant.\r
-\r
-GtkRadiant is free software; you can redistribute it and/or modify\r
-it under the terms of the GNU General Public License as published by\r
-the Free Software Foundation; either version 2 of the License, or\r
-(at your option) any later version.\r
-\r
-GtkRadiant is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-GNU General Public License for more details.\r
-\r
-You should have received a copy of the GNU General Public License\r
-along with GtkRadiant; if not, write to the Free Software\r
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\r
-*/\r
-\r
-#include "qdata.h"\r
-\r
-/*\r
-=============================================================================\r
-\r
-ALPHALIGHT GENERATION\r
-\r
-Find alphamap values that best match modulated lightmap values\r
-\r
-This isn't used anymore, but I'm keeping it around...\r
-=============================================================================\r
-*/\r
-\r
-unsigned short alphamap[32*32*32];\r
-unsigned char inverse16to8table[65536];\r
-\r
-/*\r
-static int FindNearestColor( unsigned int color )\r
-{\r
- int i;\r
- int closest_so_far = 0;\r
- float closest_distance_so_far = 100000000;\r
- float d;\r
- float r[2], g[2], b[2];\r
-\r
- // incoming color is assumed to be in 0xRRGGBB format\r
- r[0] = ( color & 31 ) << 3;\r
- g[0] = ( ( color >> 5 ) & 63 ) << 2;\r
- b[0] = ( ( color >> 11 ) & 31 ) << 3;\r
-\r
- for ( i = 0; i < 256; i++ )\r
- {\r
- r[1] = ( d_8to24table[i] >> 0 ) & 0xFF;\r
- g[1] = ( d_8to24table[i] >> 8 ) & 0xFF;\r
- b[1] = ( d_8to24table[i] >> 16 ) & 0xFF;\r
-\r
- d = ( r[1] - r[0] ) * ( r[1] - r[0] ) +\r
- ( g[1] - g[0] ) * ( g[1] - g[0] ) +\r
- ( b[1] - b[0] ) * ( b[1] - b[0] );\r
-\r
- if ( d < closest_distance_so_far )\r
- {\r
- closest_distance_so_far = d;\r
- closest_so_far = i;\r
- }\r
- }\r
-\r
- return closest_so_far;\r
-}\r
-*/\r
-\r
-extern byte BestColor( int, int, int, int, int );\r
-\r
-void Inverse16_BuildTable( void )\r
-{\r
- int i;\r
-\r
- /*\r
- ** create the 16-to-8 table\r
- */\r
- for ( i = 0; i < 65536; i++ )\r
- {\r
- int r = i & 31;\r
- int g = ( i >> 5 ) & 63;\r
- int b = ( i >> 11 ) & 31;\r
-\r
- r <<= 3;\r
- g <<= 2;\r
- b <<= 3;\r
-\r
- inverse16to8table[i] = BestColor( r, g, b, 0, 255 );\r
- }\r
-}\r
-\r
-void Alphalight_Thread (int i)\r
-{\r
- int j;\r
- float r, g, b;\r
- float mr, mg, mb, ma;\r
- float distortion, bestdistortion;\r
- float v;\r
-\r
- r = (i>>10) * (1.0/16);\r
- g = ((i>>5)&31) * (1.0/16);\r
- b = (i&31) * (1.0/16);\r
-\r
- bestdistortion = 999999;\r
- for (j=0 ; j<16*16*16*16 ; j++)\r
- {\r
- mr = (j>>12) * (1.0/16);\r
- mg = ((j>>8)&15) * (1.0/16);\r
- mb = ((j>>4)&15) * (1.0/16);\r
- ma = (j&15) * (1.0/16);\r
-\r
- v = r * 0.5 - (mr*ma + 0.5*(1.0-ma));\r
- distortion = v*v;\r
- v = g * 0.5 - (mg*ma + 0.5*(1.0-ma));\r
- distortion += v*v;\r
- v = b * 0.5 - (mb*ma + 0.5*(1.0-ma));\r
- distortion += v*v;\r
-\r
- distortion *= 1.0 + ma*4;\r
-\r
- if (distortion < bestdistortion)\r
- {\r
- bestdistortion = distortion;\r
- alphamap[i] = j;\r
- }\r
- }\r
-}\r
-\r
-void Cmd_Alphalight (void)\r
-{\r
- char savename[1024];\r
-\r
- GetScriptToken (false);\r
-\r
- if (g_release)\r
- {\r
- ReleaseFile (token);\r
- return;\r
- }\r
-\r
- sprintf (savename, "%s%s", gamedir, token);\r
- printf ("Building alphalight table...\n");\r
-\r
- RunThreadsOnIndividual (32*32*32, true, Alphalight_Thread);\r
-\r
- SaveFile (savename, (byte *)alphamap, sizeof(alphamap));\r
-}\r
-\r
-\r
-void Cmd_Inverse16Table( void )\r
-{\r
- char savename[1024];\r
-\r
- if ( g_release )\r
- {\r
- sprintf (savename, "pics/16to8.dat");\r
- ReleaseFile( savename );\r
- return;\r
- }\r
-\r
- sprintf (savename, "%spics/16to8.dat", gamedir);\r
- printf ("Building inverse 16-to-8 table...\n");\r
-\r
- Inverse16_BuildTable();\r
-\r
- SaveFile( savename, (byte *) inverse16to8table, sizeof( inverse16to8table ) );\r
-}\r
+/*
+ Copyright (C) 1999-2007 id Software, Inc. and contributors.
+ For a list of contributors, see the accompanying CONTRIBUTORS file.
+
+ This file is part of GtkRadiant.
+
+ GtkRadiant is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ GtkRadiant is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GtkRadiant; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "qdata.h"
+
+/*
+ =============================================================================
+
+ ALPHALIGHT GENERATION
+
+ Find alphamap values that best match modulated lightmap values
+
+ This isn't used anymore, but I'm keeping it around...
+ =============================================================================
+ */
+
+unsigned short alphamap[32 * 32 * 32];
+unsigned char inverse16to8table[65536];
+
+/*
+ static int FindNearestColor( unsigned int color )
+ {
+ int i;
+ int closest_so_far = 0;
+ float closest_distance_so_far = 100000000;
+ float d;
+ float r[2], g[2], b[2];
+
+ // incoming color is assumed to be in 0xRRGGBB format
+ r[0] = ( color & 31 ) << 3;
+ g[0] = ( ( color >> 5 ) & 63 ) << 2;
+ b[0] = ( ( color >> 11 ) & 31 ) << 3;
+
+ for ( i = 0; i < 256; i++ )
+ {
+ r[1] = ( d_8to24table[i] >> 0 ) & 0xFF;
+ g[1] = ( d_8to24table[i] >> 8 ) & 0xFF;
+ b[1] = ( d_8to24table[i] >> 16 ) & 0xFF;
+
+ d = ( r[1] - r[0] ) * ( r[1] - r[0] ) +
+ ( g[1] - g[0] ) * ( g[1] - g[0] ) +
+ ( b[1] - b[0] ) * ( b[1] - b[0] );
+
+ if ( d < closest_distance_so_far )
+ {
+ closest_distance_so_far = d;
+ closest_so_far = i;
+ }
+ }
+
+ return closest_so_far;
+ }
+ */
+
+extern byte BestColor( int, int, int, int, int );
+
+void Inverse16_BuildTable( void ){
+ int i;
+
+ /*
+ ** create the 16-to-8 table
+ */
+ for ( i = 0; i < 65536; i++ )
+ {
+ int r = i & 31;
+ int g = ( i >> 5 ) & 63;
+ int b = ( i >> 11 ) & 31;
+
+ r <<= 3;
+ g <<= 2;
+ b <<= 3;
+
+ inverse16to8table[i] = BestColor( r, g, b, 0, 255 );
+ }
+}
+
+void Alphalight_Thread( int i ){
+ int j;
+ float r, g, b;
+ float mr, mg, mb, ma;
+ float distortion, bestdistortion;
+ float v;
+
+ r = ( i >> 10 ) * ( 1.0 / 16 );
+ g = ( ( i >> 5 ) & 31 ) * ( 1.0 / 16 );
+ b = ( i & 31 ) * ( 1.0 / 16 );
+
+ bestdistortion = 999999;
+ for ( j = 0 ; j < 16 * 16 * 16 * 16 ; j++ )
+ {
+ mr = ( j >> 12 ) * ( 1.0 / 16 );
+ mg = ( ( j >> 8 ) & 15 ) * ( 1.0 / 16 );
+ mb = ( ( j >> 4 ) & 15 ) * ( 1.0 / 16 );
+ ma = ( j & 15 ) * ( 1.0 / 16 );
+
+ v = r * 0.5 - ( mr * ma + 0.5 * ( 1.0 - ma ) );
+ distortion = v * v;
+ v = g * 0.5 - ( mg * ma + 0.5 * ( 1.0 - ma ) );
+ distortion += v * v;
+ v = b * 0.5 - ( mb * ma + 0.5 * ( 1.0 - ma ) );
+ distortion += v * v;
+
+ distortion *= 1.0 + ma * 4;
+
+ if ( distortion < bestdistortion ) {
+ bestdistortion = distortion;
+ alphamap[i] = j;
+ }
+ }
+}
+
+void Cmd_Alphalight( void ){
+ char savename[1024];
+
+ GetScriptToken( false );
+
+ if ( g_release ) {
+ ReleaseFile( token );
+ return;
+ }
+
+ sprintf( savename, "%s%s", gamedir, token );
+ printf( "Building alphalight table...\n" );
+
+ RunThreadsOnIndividual( 32 * 32 * 32, true, Alphalight_Thread );
+
+ SaveFile( savename, (byte *)alphamap, sizeof( alphamap ) );
+}
+
+
+void Cmd_Inverse16Table( void ){
+ char savename[1024];
+
+ if ( g_release ) {
+ sprintf( savename, "pics/16to8.dat" );
+ ReleaseFile( savename );
+ return;
+ }
+
+ sprintf( savename, "%spics/16to8.dat", gamedir );
+ printf( "Building inverse 16-to-8 table...\n" );
+
+ Inverse16_BuildTable();
+
+ SaveFile( savename, (byte *) inverse16to8table, sizeof( inverse16to8table ) );
+}