mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-24 10:40:46 +00:00
Separate kpzload into two separate functions, kpzbufload (which now lives in cache1d, regardless of WITHKPLIB) and kpzdecode.
git-svn-id: https://svn.eduke32.com/eduke32@5175 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
b3639ae8e7
commit
40c704babe
5 changed files with 56 additions and 24 deletions
|
@ -12,10 +12,12 @@ extern "C" {
|
|||
|
||||
#ifdef WITHKPLIB
|
||||
int32_t cache1d_file_fromzip(int32_t fil);
|
||||
extern char *kpzbuf;
|
||||
extern int32_t kpzbufsiz;
|
||||
#endif
|
||||
|
||||
extern char *kpzbuf;
|
||||
extern int32_t kpzbufloadfil(int32_t);
|
||||
extern int32_t kpzbufload(const char *);
|
||||
|
||||
void initcache(intptr_t dacachestart, int32_t dacachesize);
|
||||
void allocache(intptr_t *newhandle, int32_t newbytes, char *newlockptr);
|
||||
void agecache(void);
|
||||
|
|
|
@ -25,6 +25,7 @@ typedef struct
|
|||
extern kzfilestate kzfs;
|
||||
|
||||
//High-level (easy) picture loading function:
|
||||
extern void kpzdecode (int32_t, intptr_t *, int32_t *, int32_t *, int32_t *);
|
||||
extern void kpzload (const char *, intptr_t *, int32_t *, int32_t *, int32_t *);
|
||||
//Low-level PNG/JPG functions:
|
||||
extern void kpgetdim (const char *, int32_t, int32_t *, int32_t *);
|
||||
|
|
|
@ -40,9 +40,6 @@
|
|||
#ifdef WITHKPLIB
|
||||
#include "kplib.h"
|
||||
|
||||
char *kpzbuf = NULL;
|
||||
int32_t kpzbufsiz = 0;
|
||||
|
||||
//Insert '|' in front of filename
|
||||
//Doing this tells kzopen to load the file only if inside a .ZIP file
|
||||
static intptr_t kzipopen(const char *filnam)
|
||||
|
@ -58,6 +55,39 @@ static intptr_t kzipopen(const char *filnam)
|
|||
|
||||
#endif
|
||||
|
||||
char *kpzbuf = NULL;
|
||||
|
||||
int32_t kpzbufloadfil(int32_t const handle)
|
||||
{
|
||||
static int32_t kpzbufsiz = 0;
|
||||
|
||||
int32_t const leng = kfilelength(handle);
|
||||
if (leng > kpzbufsiz)
|
||||
{
|
||||
kpzbuf = (char *) Xrealloc(kpzbuf, leng+1);
|
||||
kpzbufsiz = leng;
|
||||
if (!kpzbuf)
|
||||
return 0;
|
||||
}
|
||||
|
||||
kpzbuf[leng] = 0; // FIXME: buf[leng] read in kpegrend(), see BUF_LENG_READ
|
||||
kread(handle, kpzbuf, leng);
|
||||
|
||||
return leng;
|
||||
}
|
||||
|
||||
int32_t kpzbufload(char const * const filnam)
|
||||
{
|
||||
int32_t const handle = kopen4load(filnam, 0);
|
||||
if (handle < 0)
|
||||
return 0;
|
||||
|
||||
int32_t const leng = kpzbufloadfil(handle);
|
||||
|
||||
kclose(handle);
|
||||
|
||||
return leng;
|
||||
}
|
||||
|
||||
// This module keeps track of a standard linear cacheing system.
|
||||
// To use this module, here's all you need to do:
|
||||
|
|
|
@ -9272,9 +9272,7 @@ void uninitengine(void)
|
|||
#ifdef DYNALLOC_ARRAYS
|
||||
DO_FREE_AND_NULL(blockptr);
|
||||
#endif
|
||||
#ifdef WITHKPLIB
|
||||
DO_FREE_AND_NULL(kpzbuf);
|
||||
#endif
|
||||
|
||||
uninitsystem();
|
||||
|
||||
|
|
|
@ -3061,28 +3061,29 @@ int32_t kzseek(int32_t offset, int32_t whence)
|
|||
//===================== HANDY PICTURE function begins ========================
|
||||
#include "cache1d.h"
|
||||
|
||||
void kpzload(const char *filnam, intptr_t *pic, int32_t *bpl, int32_t *xsiz, int32_t *ysiz)
|
||||
void kpzdecode(int32_t const leng, intptr_t * const pic, int32_t * const bpl, int32_t * const xsiz, int32_t * const ysiz)
|
||||
{
|
||||
int32_t leng;
|
||||
int32_t handle = kopen4load((char *)filnam, 0);
|
||||
*pic = 0;
|
||||
|
||||
(*pic) = 0;
|
||||
if (handle < 0) return;
|
||||
leng = kfilelength(handle);
|
||||
kpgetdim(kpzbuf, leng, xsiz, ysiz);
|
||||
*bpl = (*xsiz)<<2;
|
||||
|
||||
if (leng+1 > kpzbufsiz)
|
||||
*pic = (intptr_t)Xmalloc(*ysiz * *bpl);
|
||||
if (!*pic)
|
||||
return;
|
||||
|
||||
if (kprender(kpzbuf, leng, *pic, *bpl, *xsiz, *ysiz) < 0)
|
||||
{
|
||||
kpzbuf = (char *) Xrealloc(kpzbuf, leng+1);
|
||||
kpzbufsiz = leng+1;
|
||||
if (!kpzbuf) { kclose(handle); return; }
|
||||
if (*pic)
|
||||
{
|
||||
Bfree((void *) *pic);
|
||||
*pic = 0;
|
||||
}
|
||||
}
|
||||
kpzbuf[leng]=0; // FIXME: buf[leng] read in kpegrend(), see BUF_LENG_READ
|
||||
kread(handle,kpzbuf,leng);
|
||||
kclose(handle);
|
||||
}
|
||||
|
||||
kpgetdim(kpzbuf,leng,xsiz,ysiz);
|
||||
(*bpl) = ((*xsiz)<<2);
|
||||
(*pic) = (intptr_t)Xmalloc((*ysiz)*(*bpl)); if (!(*pic)) { return; }
|
||||
if (kprender(kpzbuf, leng, *pic, *bpl, *xsiz, *ysiz) < 0) { if (*pic) { Bfree((void *) *pic), *pic = 0; return; } }
|
||||
void kpzload(const char * const filnam, intptr_t * const pic, int32_t * const bpl, int32_t * const xsiz, int32_t * const ysiz)
|
||||
{
|
||||
kpzdecode(kpzbufload(filnam), pic, bpl, xsiz, ysiz);
|
||||
}
|
||||
//====================== HANDY PICTURE function ends =========================
|
||||
|
|
Loading…
Reference in a new issue