ref: 8e6da2170f2d7466b663c9ac7bd381fe20a3333d
parent: 1be4cc1546d794b4a7834683ab94c9202f50b827
author: fabien sanglard <[email protected]>
date: Fri Dec 21 15:00:48 EST 2012
Added tools to view palette.
--- a/Engine/src/display.c
+++ b/Engine/src/display.c
@@ -496,7 +496,7 @@
setview(0L,0L,xdim-1,ydim-1);
- setbrightness((uint8_t ) curbrightness, (uint8_t *) &palette[0]);
+ setbrightness(curbrightness, palette);
if (searchx < 0) {
searchx = halfxdimen;
@@ -969,7 +969,19 @@
}
}
}
+
+
+#ifdef __APPLE__
+ SDL_putenv("SDL_VIDEODRIVER=Quartz");
+#endif
+
+
+ if (SDL_Init(SDL_INIT_VIDEO) == -1){
+ Error(EXIT_FAILURE, "BUILDSDL: SDL_Init() failed!\nBUILDSDL: SDL_GetError() says \"%s\".\n", SDL_GetError());
+ }
+
+
// Set up the correct renderer
// Becarfull setenv can't reach dll in VC++
// A way to proceed is to integrate the SDL libs
@@ -1305,8 +1317,7 @@
int i;
assert(index < validmodecnt);
- printf("Removing resolution #%d, %dx%d [%s].",
- index, validmodexdim[index], validmodeydim[index], reason);
+ printf("Removing resolution #%d, %dx%d [%s].",index, validmodexdim[index], validmodeydim[index], reason);
for (i = index; i < validmodecnt - 1; i++)
{
@@ -1448,7 +1459,93 @@
output_vesa_modelist();
}
+uint8_t lastPalette[768];
+void WriteTranslucToFile(void){
+
+ uint8_t buffer[65535*4];
+ uint8_t tga_header[18];
+ uint8_t* transPointer = transluc;
+ uint8_t* bufferPointer = buffer;
+ int i;
+
+
+ for (i=0; i < 65535; i++) {
+
+ bufferPointer[0] = (lastPalette[(*transPointer)*3+0]) / 63.0 * 255;
+ bufferPointer[1] = (lastPalette[(*transPointer)*3+1]) / 63.0 * 255;
+ bufferPointer[2] = (lastPalette[(*transPointer)*3+2]) / 63.0 * 255;
+ bufferPointer[3] = 255;
+
+ printf("%d,",*transPointer);
+ if (i%255 ==0)
+ printf("\n");
+
+ transPointer +=1;
+ bufferPointer+=4;
+ }
+
+
+
+ FILE* file = fopen("transluc.tga", "w");
+
+ memset(tga_header, 0, 18);
+ tga_header[2] = 2;
+ tga_header[12] = (256 & 0x00FF);
+ tga_header[13] = (256 & 0xFF00) / 256;
+ tga_header[14] = (256 & 0x00FF) ;
+ tga_header[15] =(256 & 0xFF00) / 256;
+ tga_header[16] = 32 ;
+
+ fwrite(&tga_header, 18, sizeof(uint8_t), file);
+ fwrite(buffer, 65535, 4, file);
+ fclose(file);
+}
+void WritePaletteToFile(uint8_t* palette,const char* filename,int width, int height){
+
+ uint8_t tga_header[18];
+ uint8_t* buffer;
+ uint8_t* palettePointer = palette;
+ uint8_t* bufferPointer ;
+ int i;
+
+ FILE* file = fopen(filename, "w");
+
+
+ memset(tga_header, 0, 18);
+ tga_header[2] = 2;
+ tga_header[12] = (width & 0x00FF);
+ tga_header[13] = (width & 0xFF00) / 256;
+ tga_header[14] = (height & 0x00FF) ;
+ tga_header[15] =(height & 0xFF00) / 256;
+ tga_header[16] = 32 ;
+
+ fwrite(&tga_header, 18, sizeof(uint8_t), file);
+
+ bufferPointer = buffer = malloc(width*height*4);
+
+ for (i = 0 ; i < width*height ; i++)
+ {
+ bufferPointer[0] = palettePointer[0] / 63.0 * 255;
+ bufferPointer[1] = palettePointer[1] / 63.0 * 255;
+ bufferPointer[2] = palettePointer[2] / 63.0 * 255;
+ bufferPointer[3] = 255;
+
+ bufferPointer += 4;
+ palettePointer+= 3;
+ }
+
+ fwrite(buffer, width*height, 4, file);
+ fclose(file);
+
+ free(buffer);
+}
+
+
+void WriteLastPaletteToFile(){
+ WritePaletteToFile(lastPalette,"lastPalette.tga",16,16);
+}
+
int VBE_setPalette(uint8_t *palettebuffer)
/*
* (From Ken's docs:)
@@ -1468,7 +1565,19 @@
SDL_Color *sdlp = fmt_swap;
uint8_t *p = palettebuffer;
int i;
+ static updated=0;
+
+ if (updated >=1 )
+ return ;
+
+ WritePaletteToFile(palettebuffer,"lastPalette.tga",16,16);
+ updated++;
+
+ //CODE EXPLORATION
+ //Used only to write the last palette to file.
+ memcpy(lastPalette, palettebuffer, 768);
+
for (i = 0; i < 256; i++){
sdlp->b = (Uint8) ((((float) *p++) / 63.0) * 255.0);
sdlp->g = (Uint8) ((((float) *p++) / 63.0) * 255.0);
--- a/Engine/src/engine.c
+++ b/Engine/src/engine.c
@@ -2811,7 +2811,9 @@
}
int pixelRenderable = 100000000;
-
+#include "keyboard.h"
+void WriteLastPaletteToFile(void);
+void WriteTranslucToFile(void);
/*
FCS: Draw every walls in Front to Back Order.
*/
@@ -2827,6 +2829,15 @@
// clear the framebuffer to black.
if (CLEAR_FRAMEBUFFER)
clear2dscreen();
+
+
+ //CODE EXPLORATION
+ if( KB_KeyDown[0x39]){ // 0x39 = SPACE
+ //CODE EXPLORATION
+ WriteLastPaletteToFile();
+ WriteTranslucToFile();
+ }
+
pixelRenderable+=10;
if (pixelRenderable >= MAX_PIXEL_RENDERERED)
@@ -3559,7 +3570,7 @@
clearbufbyte((void *)FP_OFF(colhere),sizeof(colhere),0L);
clearbufbyte((void *)FP_OFF(colhead),sizeof(colhead),0L);
- pal1 = (uint8_t *)&palette[768-3];
+ pal1 = &palette[768-3];
for(i=255; i>=0; i--,pal1-=3)
{
j = (pal1[0]>>3)*FASTPALGRIDSIZ*FASTPALGRIDSIZ+(pal1[1]>>3)*FASTPALGRIDSIZ+(pal1[2]>>3)+FASTPALGRIDSIZ*FASTPALGRIDSIZ+FASTPALGRIDSIZ+1;
@@ -3579,7 +3590,7 @@
colscan[26] = i;
}
-
+extern uint8_t lastPalette[768];
static void loadpalette(void)
{
int32_t i, j, k, dist, fil;
@@ -3592,9 +3603,17 @@
return;
kread(fil,palette,768);
+
+ //CODE EXPLORATION
+ //WritePaletteToFile(palette,"palette.tga",16, 16);
+ memcpy(lastPalette, palette, 768);
+
+
kread16(fil,&numpalookups);
-
+ //CODE EXPLORATION
+ //printf("Num palettes lookup: %d.\n",numpalookups);
+
if ((palookup[0] = (uint8_t *)kkmalloc(numpalookups<<8)) == NULL)
allocache(&palookup[0],numpalookups<<8,&permanentlock);
@@ -3615,6 +3634,8 @@
for (k = 0; k < (65536 / 4); k++)
kread32(fil, ((int32_t *) transluc) + k);
+
+
kclose(fil);
initfastcolorlookup(30L,59L,11L);
@@ -3631,6 +3652,7 @@
palette[i*3+1] * 5+
palette[i*3+2] * 2;
ptr = palookup[k]+i;
+
for(j=0; j<32; j++)
ptr[j<<8] = (uint8_t )min(max(mulscale10(dist,32-j),0),15);
}
@@ -8377,7 +8399,8 @@
{
int32_t i, j, k;
- curbrightness = min(max((int32_t)dabrightness,0),15);
+ //Clamp bightness to [0-15]
+ curbrightness = min(max(dabrightness,0),15);
k = 0;
if (vidoption == 6)
@@ -8402,7 +8425,7 @@
}
}
- VBE_setPalette((uint8_t *) tempbuf);
+ VBE_setPalette(tempbuf);
}
//This is only used by drawmapview.
--- a/Game/src/duke3d.h
+++ b/Game/src/duke3d.h
@@ -511,7 +511,7 @@
uint8_t fakeplayer;
};
-extern char tempbuf[2048];
+extern uint8_t tempbuf[2048];
extern uint8_t packbuf[576];
extern int32_t gc,max_player_health,max_armour_amount,max_ammo_amount[MAX_WEAPONS];
--- a/Game/src/global.c
+++ b/Game/src/global.c
@@ -91,7 +91,7 @@
char fta_quotes[NUMOFFIRSTTIMEACTIVE][64];
-char tempbuf[2048];
+uint8_t tempbuf[2048];
uint8_t packbuf[576];
char buf[80];
--- a/Game/src/keyboard.c
+++ b/Game/src/keyboard.c
@@ -99,12 +99,12 @@
CONTROL_UpdateKeyboardState(lastkey, pressed);
}
-void KB_KeyEvent( int scancode, boolean keypressed )
+void KB_KeyEvent( int scancode, int keypressed )
{
STUBBED("KB_KeyEvent");
}
-boolean KB_KeyWaiting( void )
+int KB_KeyWaiting( void )
{
_handle_events();
return keyIsWaiting;
@@ -288,7 +288,7 @@
STUBBED("KB_TurnKeypadOff");
}
-boolean KB_KeypadActive( void )
+int KB_KeypadActive( void )
{
STUBBED("KB_KeypadActive");
return false;
--- a/Game/src/keyboard.h
+++ b/Game/src/keyboard.h
@@ -38,7 +38,7 @@
=============================================================================
*/
-typedef uint8 kb_scancode;
+typedef uint8_t kb_scancode;
#define sc_None 0
#define sc_Bad 0xff
@@ -173,7 +173,7 @@
=============================================================================
*/
-extern byte KB_KeyDown[ MAXKEYBOARDSCAN ]; // Keyboard state array
+extern uint8_t KB_KeyDown[ MAXKEYBOARDSCAN ]; // Keyboard state array
extern kb_scancode KB_LastScan;
@@ -204,8 +204,8 @@
=============================================================================
*/
-void KB_KeyEvent( int scancode, boolean keypressed ); // Interprets scancodes
-boolean KB_KeyWaiting( void ); // Checks if a character is waiting in the keyboard queue
+void KB_KeyEvent( int scancode, int keypressed ); // Interprets scancodes
+int KB_KeyWaiting( void ); // Checks if a character is waiting in the keyboard queue
uint8_t KB_Getch( void ); // Gets the next keypress
void KB_Addch( uint8_t ch ); // Adds key to end of queue
void KB_FlushKeyboardQueue( void ); // Empties the keyboard queue of all waiting characters.
@@ -214,7 +214,7 @@
kb_scancode KB_StringToScanCode( char * string ); // convert a string into a scancode
void KB_TurnKeypadOn( void ); // turn the keypad on
void KB_TurnKeypadOff( void ); // turn the keypad off
-boolean KB_KeypadActive( void ); // check whether keypad is active
+int KB_KeypadActive( void ); // check whether keypad is active
void KB_Startup( void );
void KB_Shutdown( void );
--- a/Game/src/menues.c
+++ b/Game/src/menues.c
@@ -4680,7 +4680,7 @@
tempbuf[j+3] = 0;
}
- VBE_setPalette((uint8_t*)tempbuf);
+ VBE_setPalette(tempbuf);
ototalclock = totalclock + 10;