LoadPCX has been rewritten and now functions!!

This commit is contained in:
Zephaniah E. Hull 2000-03-04 20:32:38 +00:00
parent 27825ed5fe
commit 41c969c2ac
7 changed files with 118 additions and 149 deletions

View File

@ -572,6 +572,7 @@ R_LoadSkys ( void ) {
for (i=0 ; i<6 ; i++) {
GL_Bind (SKY_TEX + i);
snprintf(name, sizeof(name), "gfx/env/%s%s.tga",
// snprintf(name, sizeof(name), "gfx/env/%s%s.pcx",
r_skyname->string, suf[i]);
COM_FOpenFile (name, &f);
if (!f) {

View File

@ -21,6 +21,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <zone.h>
typedef struct
{
char manufacturer;
@ -38,5 +40,5 @@ typedef struct
unsigned char data; // unbounded
} pcx_t;
void LoadPCX (QFile *f, byte **pcx_rgb);
byte *LoadPCX (char *file, cache_user_t *cache, int buf_x, int buf_y);

View File

@ -42,6 +42,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <X11/Xatom.h>
#include <X11/keysym.h>
#include <X11/extensions/XShm.h>
#include <X11/extensions/xf86dga.h>
#include <errno.h>
#include <quakedef.h>
@ -242,26 +243,32 @@ static void event_button(XEvent *event)
static void event_motion(XEvent *event)
{
#ifdef HAS_DGA
if (dgamouse) {
mouse_x += event->xmotion.x_root * vid_dga_mouseaccel->value;
mouse_y += event->xmotion.y_root * vid_dga_mouseaccel->value;
} else
if (dgamouse) {
mouse_x += event->xmotion.x_root * vid_dga_mouseaccel->value;
mouse_y += event->xmotion.y_root * vid_dga_mouseaccel->value;
} else
#endif
if (_windowed_mouse->value) {
mouse_x = (float) ((int) event->xmotion.x - ((int) vid.width / 2));
mouse_y = (float) ((int) event->xmotion.y - ((int) vid.height / 2));
//printf("_windowed_mouse: %f\n", _windowed_mouse->value);
//printf("CurrentTime: %ld\n", CurrentTime);
if (_windowed_mouse->value) {
mouse_x = (float) ((int) event->xmotion.x - ((int) vid.width / 2));
mouse_y = (float) ((int) event->xmotion.y - ((int) vid.height / 2));
/* move the mouse to the window center again */
XSelectInput(x_disp, x_win, INPUT_MASK & ~PointerMotionMask);
XWarpPointer(x_disp, None, x_win, 0, 0, 0, 0,
(vid.width / 2), (vid.height / 2));
XSelectInput(x_disp, x_win, INPUT_MASK);
} else {
mouse_x = (event->xmotion.x - p_mouse_x);
mouse_y = (event->xmotion.y - p_mouse_y);
p_mouse_x = event->xmotion.x;
p_mouse_y = event->xmotion.y;
}
/* move the mouse to the window center again */
XGrabPointer(x_disp, x_win, True, MOUSE_MASK & ~PointerMotionMask,
GrabModeAsync, GrabModeAsync, x_win, None, CurrentTime);
XSelectInput(x_disp, x_win, INPUT_MASK & ~PointerMotionMask);
XWarpPointer(x_disp, None, x_win, 0, 0, 0, 0,
(vid.width / 2), (vid.height / 2));
XSelectInput(x_disp, x_win, INPUT_MASK);
XGrabPointer(x_disp, x_win, True, MOUSE_MASK, GrabModeAsync,
GrabModeAsync, x_win, None, CurrentTime);
} else {
mouse_x = (event->xmotion.x - p_mouse_x);
mouse_y = (event->xmotion.y - p_mouse_y);
p_mouse_x = event->xmotion.x;
p_mouse_y = event->xmotion.y;
}
}
@ -276,8 +283,10 @@ IN_Frame(void)
XUngrabPointer(x_disp,CurrentTime);
} else {
/* grab the pointer */
XGrabPointer(x_disp,x_win,True,0,GrabModeAsync,
GrabModeAsync,x_win,None,CurrentTime);
XGrabPointer(x_disp, x_win, True, MOUSE_MASK, GrabModeAsync,
GrabModeAsync, x_win, None, CurrentTime);
//XGrabPointer(x_disp,x_win,True,0,GrabModeAsync,
// GrabModeAsync,x_win,None,CurrentTime);
}
}
}
@ -375,6 +384,13 @@ int IN_Init ()
// Cvar_RegisterVariable(&vid_dga_mouseaccel);
vid_dga_mouseaccel = Cvar_Get ("vid_dga_mouseaccel","1",CVAR_ARCHIVE,
"None");
XF86DGASetViewPort(x_disp, x_win, 0, 0);
XF86DGADirectVideo(x_disp, x_win, XF86DGADirectGraphics|XF86DGADirectMouse|XF86DGADirectKeyb);
XF86DGASetVidPage(x_disp, x_win, 0);
XGrabKeyboard(x_disp, x_win, True, GrabModeAsync, GrabModeAsync, CurrentTime);
XGrabPointer(x_disp, x_win, True, MOUSE_MASK, GrabModeAsync, GrabModeAsync,
x_win, None, CurrentTime);
#endif
if (COM_CheckParm("-nomouse")) return 1;
mouse_x = mouse_y = 0.0;

View File

@ -32,68 +32,100 @@
#include <quakeio.h>
#include <console.h>
#include <image.h>
#include <zone.h>
#include <quakefs.h>
#include <sys.h>
/*
LoadPCX
*/
void
LoadPCX (QFile *f, byte **pcx_rgb) {
byte *LoadPCX (char *file, cache_user_t *cache, int buf_x, int buf_y) {
pcx_t *pcx, pcxbuf;
byte palette[768];
pcx_t *pcx;
byte *pix;
byte *raw, *out;
int x, y;
int dataByte, runLength;
int count;
/*
Parse PCX file
*/
Qread (f, &pcxbuf, sizeof(pcxbuf));
pcx = &pcxbuf;
if (pcx->manufacturer != 0x0a || pcx->version != 5 || pcx->encoding != 1
|| pcx->bits_per_pixel != 8 || pcx->xmax >= 320
|| pcx->ymax >= 256) {
Con_Printf ("Bad PCX file\n");
return;
out = Cache_Check (cache);
if (out)
{
Con_Printf("Using cached version of %s\n", file);
return out;
}
raw = COM_LoadTempFile (file);
if (!raw) {
Con_Printf("Can not open %s\n", file);
return NULL;
}
// seek to palette
Qseek (f, -768, SEEK_END);
Qread (f, palette, 768);
pcx = (pcx_t *)raw;
raw = &pcx->data;
Qseek (f, sizeof(pcxbuf) - 4, SEEK_SET);
count = (pcx->xmax+1) * (pcx->ymax+1);
*pcx_rgb = malloc( count); // * 3);
for (y=0 ; y<=pcx->ymax ; y++)
if (pcx->manufacturer != 0x0a
|| pcx->version != 5
|| pcx->encoding != 1
|| pcx->bits_per_pixel != 8
|| pcx->xmax >= 320
|| pcx->ymax >= 200)
{
pix = *pcx_rgb + /*3**/y*(pcx->xmax+1);
for (x=0 ; x<=pcx->ymax ; )
{
dataByte = Qgetc(f);
Con_Printf ("Bad PCX file\n");
return NULL;
}
if ((dataByte & 0xC0) == 0xC0)
{
runLength = dataByte & 0x3F;
dataByte = Qgetc(f);
if (!buf_x)
buf_x = pcx->ymax;
if (!buf_y)
buf_y = pcx->ymax;
Con_Printf("PCX file %s %dx%d\n", file, buf_x, buf_y);
out = Cache_Alloc (cache, buf_x * buf_y, file);
if (!out)
Sys_Error("LoadPCX: couldn't allocate.");
pix = out;
memset(out, 0, buf_x * buf_y);
for (y=0 ; y<=pcx->ymax ; y++, pix += buf_x) {
for (x=0 ; x<=pcx->xmax ; ) {
if (raw - (byte*)pcx > com_filesize) {
Cache_Free(cache);
Con_Printf("PCX file %s was malformed. You should delete it.\n", file);
return NULL;
}
else
dataByte = *raw++;
if ((dataByte & 0xC0) == 0xC0) {
runLength = dataByte & 0x3F;
if (raw - (byte*)pcx > com_filesize) {
Cache_Free(cache);
Con_Printf("PCX file %s was malformed. You should delete it.\n", file);
return NULL;
}
dataByte = *raw++;
} else
runLength = 1;
while(runLength-- > 0) {
pix[x++] = dataByte;
// pix[0] = palette[dataByte*3];
// pix[1] = palette[dataByte*3+1];
// pix[2] = palette[dataByte*3+2];
// pix[3] = 255;
// pix += 4;
// x++;
if (runLength + x > pcx->xmax + 2) {
Cache_Free(cache);
Con_Printf("PCX file %s was malformed. You should delete it.\n", file);
return NULL;
}
while(runLength-- > 0)
pix[x++] = dataByte;
}
}
if (raw - (byte*)pcx > com_filesize) {
Cache_Free(cache);
Con_Printf("PCX file %s was malformed. You should delete it.\n", file);
return NULL;
}
return NULL;
}

View File

@ -111,7 +111,6 @@ byte *Skin_Cache (skin_t *skin)
// int x, y;
// int dataByte;
// int runLength;
QFile *f;
if (cls.downloadtype == dl_skin)
return NULL; // use base until downloaded
@ -130,99 +129,18 @@ byte *Skin_Cache (skin_t *skin)
// load the pic from disk
//
snprintf(name, sizeof(name), "skins/%s.pcx", skin->name);
// raw = COM_LoadTempFile (name);
COM_FOpenFile (name, &f);
if (f == NULL)
{
out = LoadPCX (name, &skin->cache, 320, 200);
if (out == NULL) {
Con_Printf ("Couldn't load skin %s\n", name);
snprintf(name, sizeof(name), "skins/%s.pcx", baseskin->string);
// raw = COM_LoadTempFile (name);
COM_FOpenFile (name, &f);
if (f == NULL)
{
out = LoadPCX (name, &skin->cache, 320, 200);
if (out == NULL) {
skin->failedload = true;
return NULL;
}
}
LoadPCX (f, &out);
#if 0
//
// parse the PCX file
//
pcx = (pcx_t *)raw;
raw = &pcx->data;
if (pcx->manufacturer != 0x0a
|| pcx->version != 5
|| pcx->encoding != 1
|| pcx->bits_per_pixel != 8
|| pcx->xmax >= 320
|| pcx->ymax >= 200)
{
skin->failedload = true;
Con_Printf ("Bad skin %s\n", name);
return NULL;
}
out = Cache_Alloc (&skin->cache, 320*200, skin->name);
if (!out)
Sys_Error ("Skin_Cache: couldn't allocate");
pix = out;
memset (out, 0, 320*200);
for (y=0 ; y<pcx->ymax ; y++, pix += 320)
{
for (x=0 ; x<=pcx->xmax ; )
{
if (raw - (byte*)pcx > com_filesize)
{
Cache_Free (&skin->cache);
skin->failedload = true;
Con_Printf ("Skin %s was malformed. You should delete it.\n", name);
return NULL;
}
dataByte = *raw++;
if((dataByte & 0xC0) == 0xC0)
{
runLength = dataByte & 0x3F;
if (raw - (byte*)pcx > com_filesize)
{
Cache_Free (&skin->cache);
skin->failedload = true;
Con_Printf ("Skin %s was malformed. You should delete it.\n", name);
return NULL;
}
dataByte = *raw++;
}
else
runLength = 1;
// skin sanity check
if (runLength + x > pcx->xmax + 2) {
Cache_Free (&skin->cache);
skin->failedload = true;
Con_Printf ("Skin %s was malformed. You should delete it.\n", name);
return NULL;
}
while(runLength-- > 0)
pix[x++] = dataByte;
}
}
if ( raw - (byte *)pcx > com_filesize)
{
Cache_Free (&skin->cache);
skin->failedload = true;
Con_Printf ("Skin %s was malformed. You should delete it.\n", name);
return NULL;
}
skin->failedload = false;
#endif
return out;
}

View File

@ -321,7 +321,7 @@ ALL_X11_OBJS = $(patsubst %,$(BUILD_DIR)/%,$(addsuffix .@OBJEXT@,\
$(BUILD_DIR)/common_lib.a $(TARGET_DIR)/sound_lib.a
X11_CFLAGS = -DX11 @X_CFLAGS@
X11_LDFLAGS = @X_LIBS@ -lX11 @X11_SHM_LIB@ @X_EXTRA_LIBS@
X11_LDFLAGS = @X_LIBS@ -lX11 @X11_SHM_LIB@ @X_EXTRA_LIBS@ @DGA_LIBS@
# FIXME: This rule is pathological because of the seperate sunx driver,
# either merge it into vid_x11.c or make a seperate sun target. In either

View File

@ -287,7 +287,7 @@ ALL_X11_OBJS = $(patsubst %,$(BUILD_DIR)/%,$(addsuffix .@OBJEXT@,\
$(TARGET_DIR)/sound_lib.a
X11_CFLAGS = -DX11 @X_CFLAGS@
X11_LDFLAGS = @X_LIBS@ -lX11 @X11_SHM_LIB@ @X_EXTRA_LIBS@
X11_LDFLAGS = @X_LIBS@ -lX11 @X11_SHM_LIB@ @X_EXTRA_LIBS@ @DGA_LIBS@
# FIXME: This rule is pathological because of the seperate sunx driver,
# either merge it into vid_x11.c or make a seperate sun target. In either