Little cleanup and fixes
This commit is contained in:
parent
27278cdd88
commit
f27b36270d
3 changed files with 57 additions and 34 deletions
|
@ -115,14 +115,14 @@ int WritePCXfile (const char *filename, byte *data, int width, int height, int r
|
|||
ReadPCXFile
|
||||
==============
|
||||
*/
|
||||
byte *ReadPCXFile(byte *buf, int length, int *width, int *height)
|
||||
byte *ReadPCXFile(byte *buf, int length, int *width, int *height, byte *palette)
|
||||
{
|
||||
pcx_t *pcx;
|
||||
byte *palette;
|
||||
byte *pal;
|
||||
byte *pix;
|
||||
int x, y;
|
||||
int dataByte, runLength;
|
||||
int count;
|
||||
int x, y;
|
||||
int dataByte, runLength;
|
||||
|
||||
byte *data;
|
||||
|
||||
byte *pcx_rgb;
|
||||
|
@ -140,8 +140,8 @@ byte *ReadPCXFile(byte *buf, int length, int *width, int *height)
|
|||
|| pcx->version != 5
|
||||
|| pcx->encoding != 1
|
||||
|| pcx->bits_per_pixel != 8
|
||||
|| swidth >= 1024
|
||||
|| sheight >= 1024)
|
||||
|| swidth >= 512
|
||||
|| sheight >= 512)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
@ -149,13 +149,10 @@ byte *ReadPCXFile(byte *buf, int length, int *width, int *height)
|
|||
*width = swidth;
|
||||
*height = sheight;
|
||||
|
||||
|
||||
palette = host_basepal;
|
||||
pal = palette;
|
||||
|
||||
data = (char *)(pcx+1);
|
||||
|
||||
count = (swidth) * (sheight);
|
||||
pcx_rgb = malloc(count);
|
||||
pcx_rgb = malloc(swidth * sheight);
|
||||
|
||||
for (y=0 ; y<sheight ; y++)
|
||||
{
|
||||
|
@ -183,9 +180,9 @@ byte *ReadPCXFile(byte *buf, int length, int *width, int *height)
|
|||
while(runLength-- > 0)
|
||||
{
|
||||
int rgb[3];
|
||||
rgb[0] = palette[dataByte*3];
|
||||
rgb[1] = palette[dataByte*3+1];
|
||||
rgb[2] = palette[dataByte*3+2];
|
||||
rgb[0] = pal[dataByte*3];
|
||||
rgb[1] = pal[dataByte*3+1];
|
||||
rgb[2] = pal[dataByte*3+2];
|
||||
pix[0] = Convert_24_to_8(palette, rgb);
|
||||
pix++;
|
||||
x++;
|
||||
|
@ -211,8 +208,8 @@ byte *ReadPCXPalette(byte *buf, int len, byte *out)
|
|||
|| pcx->version != 5
|
||||
|| pcx->encoding != 1
|
||||
|| pcx->bits_per_pixel != 8
|
||||
|| LittleShort(pcx->xmax) >= 1024
|
||||
|| LittleShort(pcx->ymax) >= 1024)
|
||||
|| LittleShort(pcx->xmax) >= 512
|
||||
|| LittleShort(pcx->ymax) >= 512)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
// to touch the vid buffer
|
||||
|
||||
int WritePCXfile (const char *filename, byte *data, int width, int height, int rowbytes, byte *palette);
|
||||
byte *ReadPCXFile(byte *buf, int length, int *width, int *height);
|
||||
byte *ReadPCXFile(byte *buf, int length, int *width, int *height, byte *palette);
|
||||
byte *ReadPCXData(byte *buf, int length, int width, int height, byte *result);
|
||||
byte *ReadPCXPalette(byte *buf, int len, byte *out);
|
||||
|
|
|
@ -77,7 +77,7 @@ int config_notify=0;
|
|||
int config_notify_width;
|
||||
int config_notify_height;
|
||||
|
||||
qboolean vid_ineditor;
|
||||
qboolean vid_ineditor = false;
|
||||
static unsigned char *ed_palette;
|
||||
|
||||
void VID_HandleDeath(int signal_num)
|
||||
|
@ -783,6 +783,8 @@ gint VID_EditorLoadPalette(gpointer data)
|
|||
|
||||
if(palfile)
|
||||
{
|
||||
Con_Printf("[EDITOR] Switching palette to %s\n", filename);
|
||||
|
||||
for(i=0; i < 16*16*3; i++)
|
||||
ed_palette[i] = palfile->data[i];
|
||||
|
||||
|
@ -799,7 +801,6 @@ gint VID_EditorLoadPalette(gpointer data)
|
|||
}
|
||||
|
||||
ed_cmap = gdk_rgb_cmap_new(colors, 256);
|
||||
|
||||
}
|
||||
g_free (filename);
|
||||
}
|
||||
|
@ -849,9 +850,9 @@ gint VID_EditorViewColormap(gpointer data)
|
|||
|
||||
pic = COM_LoadFile (filename, 2);
|
||||
|
||||
|
||||
if(pic)
|
||||
{
|
||||
Con_Printf("[EDITOR] Previewing Colormap %s\n", filename);
|
||||
ed_file = Hunk_Alloc(16385 + (sizeof(int) * 2));
|
||||
|
||||
ed_file->width = 256;
|
||||
|
@ -859,10 +860,10 @@ gint VID_EditorViewColormap(gpointer data)
|
|||
|
||||
for(i = 0; i < 256 * 64; i++)
|
||||
ed_file->data[i] = pic->data[i];
|
||||
|
||||
|
||||
gtk_window_resize(ed_window, ed_file->width, ed_file->height + ed_menubar->allocation.height);
|
||||
}
|
||||
|
||||
gtk_window_resize(ed_window, ed_file->width, ed_file->height + ed_menubar->allocation.height);
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
|
@ -910,6 +911,7 @@ gint VID_EditorGenerateColormap(gpointer data)
|
|||
char *filename;
|
||||
filename = gtk_file_chooser_get_filename (chooser);
|
||||
unsigned char out_colormap[16384];
|
||||
Con_Printf("[EDITOR] Generating colormap based on current palette...\n");
|
||||
Colormap_Generate(ed_palette, out_colormap);
|
||||
COM_WriteFile (filename, out_colormap, 16384);
|
||||
g_free (filename);
|
||||
|
@ -970,6 +972,8 @@ gint VID_EditorSaveFile(gpointer data)
|
|||
char *filename;
|
||||
filename = gtk_file_chooser_get_filename (chooser);
|
||||
|
||||
Con_Printf("[EDITOR] Saving LUMP as %s...\n", filename);
|
||||
|
||||
pic = malloc((sizeof(int)*2) + (ed_file->width * ed_file->height));
|
||||
|
||||
pic[0] = ed_file->width;
|
||||
|
@ -1038,7 +1042,11 @@ gint VID_EditorLoadFile(gpointer data)
|
|||
pic = COM_LoadFile (filename, 2);
|
||||
|
||||
if(pic)
|
||||
{
|
||||
Con_Printf("[EDITOR] Loading LUMP at %s...\n", filename);
|
||||
ed_file = (qpic_t *)pic->data;
|
||||
gtk_window_resize(ed_window, ed_file->width, ed_file->height + ed_menubar->allocation.height);
|
||||
}
|
||||
#if 0
|
||||
int i;
|
||||
printf("Loading IMAGE: %i, %i\n", ed_file->width, ed_file->height);
|
||||
|
@ -1046,7 +1054,6 @@ gint VID_EditorLoadFile(gpointer data)
|
|||
printf("%i,", ed_file->data[i]);
|
||||
printf("\n...DONE\n");
|
||||
#endif
|
||||
gtk_window_resize(ed_window, ed_file->width, ed_file->height + ed_menubar->allocation.height);
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
|
@ -1069,7 +1076,7 @@ gint VID_EditorCreatePic(gpointer data)
|
|||
|
||||
mem = (size_t)((sizeof(int) * 2) + (gtk_spin_button_get_value_as_int (ed_widthbox) * gtk_spin_button_get_value_as_int (ed_heightbox)));
|
||||
//mem = 262152;
|
||||
printf("[EDITOR] Trying to allocate %i memory...\n", mem);
|
||||
Con_Printf("[EDITOR] Creating new %ix%i LUMP\n", gtk_spin_button_get_value_as_int (ed_widthbox), gtk_spin_button_get_value_as_int (ed_heightbox));
|
||||
ed_file = Hunk_Alloc((size_t)mem);
|
||||
ed_file->width = gtk_spin_button_get_value_as_int (ed_widthbox);
|
||||
ed_file->height = gtk_spin_button_get_value_as_int (ed_heightbox);
|
||||
|
@ -1088,7 +1095,7 @@ gint VID_EditorNewFile(gpointer data)
|
|||
|
||||
ed_newwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_position(GTK_WINDOW(ed_newwindow), GTK_WIN_POS_CENTER);
|
||||
gtk_window_set_title(GTK_WINDOW(ed_newwindow), "NGUNIXEd - New 2D LUMP File");
|
||||
gtk_window_set_title(GTK_WINDOW(ed_newwindow), "New LMP");
|
||||
gtk_container_set_border_width(GTK_CONTAINER(ed_newwindow), 10);
|
||||
|
||||
table = gtk_table_new(3, 2, FALSE);
|
||||
|
@ -1156,8 +1163,19 @@ gint VID_EditorImportFile(gpointer data)
|
|||
if (pic)
|
||||
{
|
||||
int pic_width, pic_height;
|
||||
|
||||
Con_Printf("[EDITOR] Importing PCX at %s...\n", filename);
|
||||
|
||||
byte *pic_data = Hunk_Alloc(pic->filelen);
|
||||
pic_data = ReadPCXFile(pic->data, pic->filelen, &pic_width, &pic_height);
|
||||
pic_data = ReadPCXFile(pic->data, pic->filelen, &pic_width, &pic_height, ed_palette);
|
||||
|
||||
if(pic_data == NULL)
|
||||
{
|
||||
g_free(filename);
|
||||
gtk_widget_destroy (dialog);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ed_file = Hunk_Alloc((sizeof(int) * 2) + (pic_width * pic_height));
|
||||
ed_file->width = pic_width;
|
||||
ed_file->height = pic_height;
|
||||
|
@ -1165,9 +1183,10 @@ gint VID_EditorImportFile(gpointer data)
|
|||
int i;
|
||||
for(i = 0; i < pic_width * pic_height; i++)
|
||||
ed_file->data[i] = pic_data[i];
|
||||
|
||||
gtk_window_resize(ed_window, ed_file->width, ed_file->height + ed_menubar->allocation.height);
|
||||
}
|
||||
|
||||
gtk_window_resize(ed_window, ed_file->width, ed_file->height + ed_menubar->allocation.height);
|
||||
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
|
@ -1225,6 +1244,8 @@ gint VID_EditorExportFile(gpointer data)
|
|||
char *filename;
|
||||
filename = gtk_file_chooser_get_filename (chooser);
|
||||
|
||||
Con_Printf("[EDITOR] Exporting PCX to %s...\n", filename);
|
||||
|
||||
int w, h;
|
||||
w = ed_file->width;
|
||||
h = ed_file->height;
|
||||
|
@ -1249,11 +1270,15 @@ gint VID_EditorExportFile(gpointer data)
|
|||
* ============
|
||||
* Kills the editor, unloads any pics, etc.
|
||||
*/
|
||||
void VID_EditorQuit(void)
|
||||
gint VID_EditorQuit(gpointer data)
|
||||
{
|
||||
gtk_widget_destroy(ed_window);
|
||||
vid_ineditor = false;
|
||||
gtk_main_quit();
|
||||
if(vid_ineditor == true)
|
||||
{
|
||||
Con_Printf("[EDITOR] Shutting down\n");
|
||||
gtk_widget_destroy(ed_window);
|
||||
vid_ineditor = false;
|
||||
gtk_main_quit();
|
||||
}
|
||||
}
|
||||
|
||||
/* EDITOR: UPDATE
|
||||
|
@ -1298,7 +1323,6 @@ void VID_LaunchEditor(void)
|
|||
ed_cmap = gdk_rgb_cmap_new(ed_colors, 256);
|
||||
}
|
||||
|
||||
vid_ineditor = true;
|
||||
ed_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_position(GTK_WINDOW(ed_window), GTK_WIN_POS_CENTER);
|
||||
gtk_window_set_default_size(GTK_WINDOW(ed_window), 300, 200);
|
||||
|
@ -1359,6 +1383,8 @@ void VID_LaunchEditor(void)
|
|||
ed_pic = gdk_gc_new(gtk_widget_get_window(ed_window));
|
||||
gtk_widget_show_all(ed_window);
|
||||
|
||||
Con_Printf("[EDITOR] Initialized\n");
|
||||
vid_ineditor = true;
|
||||
gtk_main();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue