X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=dpvsimpledecode.c;h=3f6567bd3bd29d2991dc93857820e287628b61ae;hb=f170ee3a587ffab1f06680de213b033838cb0b8a;hp=9927a7606e06eab2a1c75c2a709d7f309bc5d613;hpb=f3e79d752a76a9d6329759a83ec9800a5e4cc92b;p=xonotic%2Fdarkplaces.git diff --git a/dpvsimpledecode.c b/dpvsimpledecode.c index 9927a760..3f6567bd 100644 --- a/dpvsimpledecode.c +++ b/dpvsimpledecode.c @@ -6,9 +6,10 @@ #define HZREADERROR_EOF 1 #define HZREADERROR_MALLOCFAILED 2 -#define HZREADBLOCKSIZE 16000 +//#define HZREADBLOCKSIZE 16000 +#define HZREADBLOCKSIZE 1048576 -typedef struct +typedef struct hz_bitstream_read_s { qfile_t *file; int endoffile; @@ -23,7 +24,7 @@ typedef struct hz_bitstream_readblock_s } hz_bitstream_readblock_t; -typedef struct +typedef struct hz_bitstream_readblocks_s { hz_bitstream_readblock_t *blocks; hz_bitstream_readblock_t *current; @@ -37,9 +38,9 @@ hz_bitstream_read_t *hz_bitstream_read_open(char *filename) { qfile_t *file; hz_bitstream_read_t *stream; - if ((file = FS_Open (filename, "rb", false))) + if ((file = FS_OpenVirtualFile(filename, false))) { - stream = malloc(sizeof(hz_bitstream_read_t)); + stream = (hz_bitstream_read_t *)Z_Malloc(sizeof(hz_bitstream_read_t)); memset(stream, 0, sizeof(*stream)); stream->file = file; return stream; @@ -53,14 +54,14 @@ void hz_bitstream_read_close(hz_bitstream_read_t *stream) if (stream) { FS_Close(stream->file); - free(stream); + Z_Free(stream); } } hz_bitstream_readblocks_t *hz_bitstream_read_blocks_new(void) { hz_bitstream_readblocks_t *blocks; - blocks = malloc(sizeof(hz_bitstream_readblocks_t)); + blocks = (hz_bitstream_readblocks_t *)Z_Malloc(sizeof(hz_bitstream_readblocks_t)); if (blocks == NULL) return NULL; memset(blocks, 0, sizeof(hz_bitstream_readblocks_t)); @@ -75,9 +76,9 @@ void hz_bitstream_read_blocks_free(hz_bitstream_readblocks_t *blocks) for (b = blocks->blocks;b;b = n) { n = b->next; - free(b); + Z_Free(b); } - free(blocks); + Z_Free(blocks); } void hz_bitstream_read_flushbits(hz_bitstream_readblocks_t *blocks) @@ -97,7 +98,7 @@ int hz_bitstream_read_blocks_read(hz_bitstream_readblocks_t *blocks, hz_bitstrea { if (b == NULL) { - b = malloc(sizeof(hz_bitstream_readblock_t)); + b = (hz_bitstream_readblock_t *)Z_Malloc(sizeof(hz_bitstream_readblock_t)); if (b == NULL) return HZREADERROR_MALLOCFAILED; b->next = NULL; @@ -112,7 +113,7 @@ int hz_bitstream_read_blocks_read(hz_bitstream_readblocks_t *blocks, hz_bitstrea else b->size = s; s -= b->size; - if (FS_Read(stream->file, b->data, b->size) != b->size) + if (FS_Read(stream->file, b->data, b->size) != (fs_offset_t)b->size) { stream->endoffile = 1; break; @@ -200,7 +201,7 @@ unsigned int hz_bitstream_read_int(hz_bitstream_readblocks_t *blocks) void hz_bitstream_read_bytes(hz_bitstream_readblocks_t *blocks, void *outdata, unsigned int size) { unsigned char *out; - out = outdata; + out = (unsigned char *)outdata; while (size--) *out++ = hz_bitstream_read_byte(blocks); } @@ -278,7 +279,6 @@ static int dpvsimpledecode_setpixelformat(dpvsimpledecodestream_t *s, unsigned i default: s->error = DPVSIMPLEDECODEERROR_UNSUPPORTEDBPP; return s->error; - break; } for (Rshift = 0;!(Rmask & 1);Rshift++, Rmask >>= 1); for (Gshift = 0;!(Gmask & 1);Gshift++, Gmask >>= 1); @@ -332,30 +332,6 @@ static int dpvsimpledecode_setpixelformat(dpvsimpledecodestream_t *s, unsigned i // opening and closing streams -static void StripExtension(char *in, char *out) -{ - char *dot, *c; - dot = NULL; - for (c = in;*c;c++) - { - if (*c == ':' || *c == '\\' || *c == '/') - dot = NULL; - if (*c == '.') - dot = c; - } - if (dot == NULL) - { - // nothing to remove - strcpy(out, in); - return; - } - else - { - memcpy(out, in, dot - in); - out[dot - in] = 0; - } -} - // opens a stream void *dpvsimpledecode_open(char *filename, char **errorstring) { @@ -363,7 +339,7 @@ void *dpvsimpledecode_open(char *filename, char **errorstring) char t[8], *wavename; if (errorstring != NULL) *errorstring = NULL; - s = malloc(sizeof(dpvsimpledecodestream_t)); + s = (dpvsimpledecodestream_t *)Z_Malloc(sizeof(dpvsimpledecodestream_t)); if (s != NULL) { s->bitstream = hz_bitstream_read_open(filename); @@ -388,22 +364,25 @@ void *dpvsimpledecode_open(char *filename, char **errorstring) if (s->info_framerate > 0.0) { - s->videopixels = malloc(s->info_imagewidth * s->info_imageheight * sizeof(*s->videopixels)); + s->videopixels = (unsigned int *)Z_Malloc(s->info_imagewidth * s->info_imageheight * sizeof(*s->videopixels)); if (s->videopixels != NULL) { - wavename = malloc(strlen(filename) + 10); + size_t namelen; + + namelen = strlen(filename) + 10; + wavename = (char *)Z_Malloc(namelen); if (wavename) { sfx_t* sfx; - StripExtension(filename, wavename); - strcat(wavename, ".wav"); + FS_StripExtension(filename, wavename, namelen); + strlcat(wavename, ".wav", namelen); sfx = S_PrecacheSound (wavename, false, false); if (sfx != NULL) s->sndchan = S_StartSound (-1, 0, sfx, vec3_origin, 1.0f, 0); else s->sndchan = -1; - free(wavename); + Z_Free(wavename); } // all is well... s->videoframenum = -10000; @@ -428,7 +407,7 @@ void *dpvsimpledecode_open(char *filename, char **errorstring) } else if (errorstring != NULL) *errorstring = "unable to open file"; - free(s); + Z_Free(s); } else if (errorstring != NULL) *errorstring = "unable to allocate memory for stream info structure"; @@ -438,18 +417,18 @@ void *dpvsimpledecode_open(char *filename, char **errorstring) // closes a stream void dpvsimpledecode_close(void *stream) { - dpvsimpledecodestream_t *s = stream; + dpvsimpledecodestream_t *s = (dpvsimpledecodestream_t *)stream; if (s == NULL) return; if (s->videopixels) - free(s->videopixels); + Z_Free(s->videopixels); if (s->sndchan != -1) - S_StopChannel (s->sndchan); + S_StopChannel (s->sndchan, true); if (s->framedatablocks) hz_bitstream_read_blocks_free(s->framedatablocks); if (s->bitstream) hz_bitstream_read_close(s->bitstream); - free(s); + Z_Free(s); } // utilitarian functions @@ -460,7 +439,7 @@ void dpvsimpledecode_close(void *stream) // error message int dpvsimpledecode_error(void *stream, char **errorstring) { - dpvsimpledecodestream_t *s = stream; + dpvsimpledecodestream_t *s = (dpvsimpledecodestream_t *)stream; int e; e = s->error; s->error = 0; @@ -509,21 +488,21 @@ int dpvsimpledecode_error(void *stream, char **errorstring) // returns the width of the image data unsigned int dpvsimpledecode_getwidth(void *stream) { - dpvsimpledecodestream_t *s = stream; + dpvsimpledecodestream_t *s = (dpvsimpledecodestream_t *)stream; return s->info_imagewidth; } // returns the height of the image data unsigned int dpvsimpledecode_getheight(void *stream) { - dpvsimpledecodestream_t *s = stream; + dpvsimpledecodestream_t *s = (dpvsimpledecodestream_t *)stream; return s->info_imageheight; } // returns the framerate of the stream double dpvsimpledecode_getframerate(void *stream) { - dpvsimpledecodestream_t *s = stream; + dpvsimpledecodestream_t *s = (dpvsimpledecodestream_t *)stream; return s->info_framerate; } @@ -556,7 +535,7 @@ static int dpvsimpledecode_convertpixels(dpvsimpledecodestream_t *s, void *image unsigned int *outrow; for (y = 0;y < height;y++) { - outrow = (void *)((unsigned char *)imagedata + y * imagebytesperrow); + outrow = (unsigned int *)((unsigned char *)imagedata + y * imagebytesperrow); for (x = 0;x < width;x++) { a = *in++; @@ -569,7 +548,7 @@ static int dpvsimpledecode_convertpixels(dpvsimpledecodestream_t *s, void *image unsigned short *outrow; for (y = 0;y < height;y++) { - outrow = (void *)((unsigned char *)imagedata + y * imagebytesperrow); + outrow = (unsigned short *)((unsigned char *)imagedata + y * imagebytesperrow); if (Rloss == 19 && Gloss == 10 && Bloss == 3 && Rshift == 11 && Gshift == 5 && Bshift == 0) { // optimized @@ -639,7 +618,7 @@ static int dpvsimpledecode_decompressimage(dpvsimpledecodestream_t *s) // decodes a video frame to the supplied output pixels int dpvsimpledecode_video(void *stream, void *imagedata, unsigned int Rmask, unsigned int Gmask, unsigned int Bmask, unsigned int bytesperpixel, int imagebytesperrow) { - dpvsimpledecodestream_t *s = stream; + dpvsimpledecodestream_t *s = (dpvsimpledecodestream_t *)stream; unsigned int framedatasize; char t[4]; s->error = DPVSIMPLEDECODEERROR_NONE;