X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=dpvsimpledecode.c;h=011c95bf4d32260c3078aaebec28fa304779b10f;hp=7519c3f6ecd6dad1cf0cb48a418fbf1bc470849d;hb=8289ce6a72d06635b6667d7e6e80ee0890ea7c09;hpb=cd7454f9df6b152a24c5a28750041d27023fbc1f diff --git a/dpvsimpledecode.c b/dpvsimpledecode.c index 7519c3f6..011c95bf 100644 --- a/dpvsimpledecode.c +++ b/dpvsimpledecode.c @@ -1,3 +1,22 @@ +/* +Copyright (C) 2002-2013 DarkPlaces contributors + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ #include "quakedef.h" #include "dpvsimpledecode.h" @@ -34,11 +53,11 @@ typedef struct hz_bitstream_readblocks_s } hz_bitstream_readblocks_t; -hz_bitstream_read_t *hz_bitstream_read_open(char *filename) +static 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, false))) + if ((file = FS_OpenVirtualFile(filename, false))) { stream = (hz_bitstream_read_t *)Z_Malloc(sizeof(hz_bitstream_read_t)); memset(stream, 0, sizeof(*stream)); @@ -49,7 +68,7 @@ hz_bitstream_read_t *hz_bitstream_read_open(char *filename) return NULL; } -void hz_bitstream_read_close(hz_bitstream_read_t *stream) +static void hz_bitstream_read_close(hz_bitstream_read_t *stream) { if (stream) { @@ -58,7 +77,7 @@ void hz_bitstream_read_close(hz_bitstream_read_t *stream) } } -hz_bitstream_readblocks_t *hz_bitstream_read_blocks_new(void) +static hz_bitstream_readblocks_t *hz_bitstream_read_blocks_new(void) { hz_bitstream_readblocks_t *blocks; blocks = (hz_bitstream_readblocks_t *)Z_Malloc(sizeof(hz_bitstream_readblocks_t)); @@ -68,7 +87,7 @@ hz_bitstream_readblocks_t *hz_bitstream_read_blocks_new(void) return blocks; } -void hz_bitstream_read_blocks_free(hz_bitstream_readblocks_t *blocks) +static void hz_bitstream_read_blocks_free(hz_bitstream_readblocks_t *blocks) { hz_bitstream_readblock_t *b, *n; if (blocks == NULL) @@ -81,13 +100,13 @@ void hz_bitstream_read_blocks_free(hz_bitstream_readblocks_t *blocks) Z_Free(blocks); } -void hz_bitstream_read_flushbits(hz_bitstream_readblocks_t *blocks) +static void hz_bitstream_read_flushbits(hz_bitstream_readblocks_t *blocks) { blocks->store = 0; blocks->count = 0; } -int hz_bitstream_read_blocks_read(hz_bitstream_readblocks_t *blocks, hz_bitstream_read_t *stream, unsigned int size) +static int hz_bitstream_read_blocks_read(hz_bitstream_readblocks_t *blocks, hz_bitstream_read_t *stream, unsigned int size) { int s; hz_bitstream_readblock_t *b, *p; @@ -134,7 +153,7 @@ int hz_bitstream_read_blocks_read(hz_bitstream_readblocks_t *blocks, hz_bitstrea return HZREADERROR_OK; } -unsigned int hz_bitstream_read_blocks_getbyte(hz_bitstream_readblocks_t *blocks) +static unsigned int hz_bitstream_read_blocks_getbyte(hz_bitstream_readblocks_t *blocks) { while (blocks->current != NULL && blocks->position >= blocks->current->size) { @@ -146,7 +165,7 @@ unsigned int hz_bitstream_read_blocks_getbyte(hz_bitstream_readblocks_t *blocks) return blocks->current->data[blocks->position++]; } -int hz_bitstream_read_bit(hz_bitstream_readblocks_t *blocks) +static int hz_bitstream_read_bit(hz_bitstream_readblocks_t *blocks) { if (!blocks->count) { @@ -158,7 +177,7 @@ int hz_bitstream_read_bit(hz_bitstream_readblocks_t *blocks) return (blocks->store >> blocks->count) & 1; } -unsigned int hz_bitstream_read_bits(hz_bitstream_readblocks_t *blocks, int size) +static unsigned int hz_bitstream_read_bits(hz_bitstream_readblocks_t *blocks, int size) { unsigned int num = 0; // we can only handle about 24 bits at a time safely @@ -179,18 +198,18 @@ unsigned int hz_bitstream_read_bits(hz_bitstream_readblocks_t *blocks, int size) return num; } -unsigned int hz_bitstream_read_byte(hz_bitstream_readblocks_t *blocks) +static unsigned int hz_bitstream_read_byte(hz_bitstream_readblocks_t *blocks) { return hz_bitstream_read_blocks_getbyte(blocks); } -unsigned int hz_bitstream_read_short(hz_bitstream_readblocks_t *blocks) +static unsigned int hz_bitstream_read_short(hz_bitstream_readblocks_t *blocks) { return (hz_bitstream_read_byte(blocks) << 8) | (hz_bitstream_read_byte(blocks)); } -unsigned int hz_bitstream_read_int(hz_bitstream_readblocks_t *blocks) +static unsigned int hz_bitstream_read_int(hz_bitstream_readblocks_t *blocks) { return (hz_bitstream_read_byte(blocks) << 24) | (hz_bitstream_read_byte(blocks) << 16) @@ -198,7 +217,7 @@ unsigned int hz_bitstream_read_int(hz_bitstream_readblocks_t *blocks) | (hz_bitstream_read_byte(blocks)); } -void hz_bitstream_read_bytes(hz_bitstream_readblocks_t *blocks, void *outdata, unsigned int size) +static void hz_bitstream_read_bytes(hz_bitstream_readblocks_t *blocks, void *outdata, unsigned int size) { unsigned char *out; out = (unsigned char *)outdata; @@ -231,6 +250,7 @@ typedef struct dpvsimpledecodestream_s unsigned int info_imageBmask; unsigned int info_imageBshift; unsigned int info_imagesize; + double info_aspectratio; // current video frame (needed because of delta compression) int videoframenum; @@ -279,7 +299,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); @@ -334,7 +353,7 @@ static int dpvsimpledecode_setpixelformat(dpvsimpledecodestream_t *s, unsigned i // opening and closing streams // opens a stream -void *dpvsimpledecode_open(char *filename, char **errorstring) +void *dpvsimpledecode_open(clvideo_t *video, char *filename, const char **errorstring) { dpvsimpledecodestream_t *s; char t[8], *wavename; @@ -362,6 +381,7 @@ void *dpvsimpledecode_open(char *filename, char **errorstring) s->info_imagewidth = hz_bitstream_read_short(s->framedatablocks); s->info_imageheight = hz_bitstream_read_short(s->framedatablocks); s->info_framerate = (double) hz_bitstream_read_int(s->framedatablocks) * (1.0 / 65536.0); + s->info_aspectratio = (double)s->info_imagewidth / (double)s->info_imageheight; if (s->info_framerate > 0.0) { @@ -369,7 +389,7 @@ void *dpvsimpledecode_open(char *filename, char **errorstring) if (s->videopixels != NULL) { size_t namelen; - + namelen = strlen(filename) + 10; wavename = (char *)Z_Malloc(namelen); if (wavename) @@ -386,7 +406,15 @@ void *dpvsimpledecode_open(char *filename, char **errorstring) Z_Free(wavename); } // all is well... + // set the module functions s->videoframenum = -10000; + video->close = dpvsimpledecode_close; + video->getwidth = dpvsimpledecode_getwidth; + video->getheight = dpvsimpledecode_getheight; + video->getframerate = dpvsimpledecode_getframerate; + video->decodeframe = dpvsimpledecode_video; + video->getaspectratio = dpvsimpledecode_getaspectratio; + return s; } else if (errorstring != NULL) @@ -424,7 +452,7 @@ void dpvsimpledecode_close(void *stream) if (s->videopixels) Z_Free(s->videopixels); if (s->sndchan != -1) - S_StopChannel (s->sndchan); + S_StopChannel (s->sndchan, true, true); if (s->framedatablocks) hz_bitstream_read_blocks_free(s->framedatablocks); if (s->bitstream) @@ -438,7 +466,7 @@ void dpvsimpledecode_close(void *stream) // number to DPVSIMPLEDECODEERROR_NONE // if the supplied string pointer variable is not NULL, it will be set to the // error message -int dpvsimpledecode_error(void *stream, char **errorstring) +int dpvsimpledecode_error(void *stream, const char **errorstring) { dpvsimpledecodestream_t *s = (dpvsimpledecodestream_t *)stream; int e; @@ -507,9 +535,12 @@ double dpvsimpledecode_getframerate(void *stream) return s->info_framerate; } - - - +// return aspect ratio of the stream +double dpvsimpledecode_getaspectratio(void *stream) +{ + dpvsimpledecodestream_t *s = (dpvsimpledecodestream_t *)stream; + return s->info_aspectratio; +} static int dpvsimpledecode_convertpixels(dpvsimpledecodestream_t *s, void *imagedata, int imagebytesperrow) {