24#define HZREADERROR_OK 0
25#define HZREADERROR_EOF 1
26#define HZREADERROR_MALLOCFAILED 2
29#define HZREADBLOCKSIZE 1048576
31typedef struct hz_bitstream_read_s
38typedef struct hz_bitstream_readblock_s
40 struct hz_bitstream_readblock_s *
next;
46typedef struct hz_bitstream_readblocks_s
63 memset(stream, 0,
sizeof(*stream));
182 unsigned int num = 0;
223 out = (
unsigned char *)outdata;
230typedef struct dpvsimpledecodestream_s
267 int Rshift, Rbits, Gshift, Gbits, Bshift, Bbits;
283 if (Rmask & Gmask || Rmask & Bmask || Gmask & Bmask)
288 switch (bytesperpixel)
291 if ((Rmask | Gmask | Bmask) > 65536)
303 for (Rshift = 0;!(Rmask & 1);Rshift++, Rmask >>= 1);
304 for (Gshift = 0;!(Gmask & 1);Gshift++, Gmask >>= 1);
305 for (Bshift = 0;!(Bmask & 1);Bshift++, Bmask >>= 1);
306 if (((Rmask + 1) & Rmask) != 0)
311 if (((Gmask + 1) & Gmask) != 0)
316 if (((Bmask + 1) & Bmask) != 0)
321 for (Rbits = 0;Rmask & 1;Rbits++, Rmask >>= 1);
322 for (Gbits = 0;Gmask & 1;Gbits++, Gmask >>= 1);
323 for (Bbits = 0;Bmask & 1;Bbits++, Bmask >>= 1);
326 Rshift += (Rbits - 8);
331 Gshift += (Gbits - 8);
336 Bshift += (Bbits - 8);
359 char t[8], *wavename;
360 if (errorstring !=
NULL)
374 if (!memcmp(t,
"DPVideo", 8))
393 namelen =
strlen(filename) + 10;
394 wavename = (
char *)
Z_Malloc(namelen);
420 else if (errorstring !=
NULL)
421 *errorstring =
"unable to allocate video image buffer";
423 else if (errorstring !=
NULL)
424 *errorstring =
"error in video info chunk";
426 else if (errorstring !=
NULL)
427 *errorstring =
"read error";
429 else if (errorstring !=
NULL)
430 *errorstring =
"not a dpvideo file";
433 else if (errorstring !=
NULL)
434 *errorstring =
"unable to allocate memory for reading buffer";
437 else if (errorstring !=
NULL)
438 *errorstring =
"unable to open file";
441 else if (errorstring !=
NULL)
442 *errorstring =
"unable to allocate memory for stream info structure";
480 *errorstring =
"no error";
483 *errorstring =
"end of file reached (this is not an error)";
486 *errorstring =
"read error (corrupt or incomplete file)";
489 *errorstring =
"sound buffer is too small for decoding frame (please allocate it as large as dpvsimpledecode_getneededsoundbufferlength suggests)";
492 *errorstring =
"invalid red bits mask";
495 *errorstring =
"invalid green bits mask";
498 *errorstring =
"invalid blue bits mask";
501 *errorstring =
"color bit masks overlap";
504 *errorstring =
"color masks too big for specified bytes per pixel";
507 *errorstring =
"unsupported bytes per pixel (must be 2 for 16bit, or 4 for 32bit)";
510 *errorstring =
"unknown error";
548 unsigned int Rloss, Rmask, Rshift, Gloss, Gmask, Gshift, Bloss, Bmask, Bshift;
567 unsigned int *outrow;
570 outrow = (
unsigned int *)((
unsigned char *)imagedata +
y * imagebytesperrow);
574 outrow[
x] = (((
a >> Rloss) & Rmask) << Rshift) | (((
a >> Gloss) & Gmask) << Gshift) | (((
a >> Bloss) & Bmask) << Bshift);
580 unsigned short *outrow;
583 outrow = (
unsigned short *)((
unsigned char *)imagedata +
y * imagebytesperrow);
584 if (Rloss == 19 && Gloss == 10 && Bloss == 3 && Rshift == 11 && Gshift == 5 && Bshift == 0)
590 outrow[
x] = ((
a >> 8) & 0xF800) | ((
a >> 5) & 0x07E0) | ((
a >> 3) & 0x001F);
598 outrow[
x] = (((
a >> Rloss) & Rmask) << Rshift) | (((
a >> Gloss) & Gmask) << Gshift) | (((
a >> Bloss) & Bmask) << Bshift);
608 int i,
a,
b, colors,
g,
x1, y1, bw, bh,
width,
height, palettebits;
609 unsigned int palette[256], *outrow, *out;
613 for (y1 = 0;y1 <
height;y1 +=
g)
629 colors = 1 << palettebits;
630 for (
i = 0;
i < colors;
i++)
634 for (
b = 0;
b < bh;
b++, out +=
width)
635 for (
a = 0;
a < bw;
a++)
640 for (
b = 0;
b < bh;
b++, out +=
width)
641 for (
a = 0;
a < bw;
a++)
651int dpvsimpledecode_video(
void *stream,
void *imagedata,
unsigned int Rmask,
unsigned int Gmask,
unsigned int Bmask,
unsigned int bytesperpixel,
int imagebytesperrow)
654 unsigned int framedatasize;
662 if (memcmp(t,
"VID0", 4))
#define dp_strlcat(dst, src, dsize)
static unsigned int hz_bitstream_read_byte(hz_bitstream_readblocks_t *blocks)
static int dpvsimpledecode_decompressimage(dpvsimpledecodestream_t *s)
static void hz_bitstream_read_close(hz_bitstream_read_t *stream)
static unsigned int hz_bitstream_read_int(hz_bitstream_readblocks_t *blocks)
static unsigned int hz_bitstream_read_bits(hz_bitstream_readblocks_t *blocks, int size)
static int hz_bitstream_read_bit(hz_bitstream_readblocks_t *blocks)
static hz_bitstream_read_t * hz_bitstream_read_open(char *filename)
double dpvsimpledecode_getframerate(void *stream)
unsigned int dpvsimpledecode_getwidth(void *stream)
void * dpvsimpledecode_open(clvideo_t *video, char *filename, const char **errorstring)
static unsigned int hz_bitstream_read_blocks_getbyte(hz_bitstream_readblocks_t *blocks)
static void hz_bitstream_read_bytes(hz_bitstream_readblocks_t *blocks, void *outdata, unsigned int size)
static int dpvsimpledecode_convertpixels(dpvsimpledecodestream_t *s, void *imagedata, int imagebytesperrow)
#define HZREADERROR_MALLOCFAILED
static void hz_bitstream_read_blocks_free(hz_bitstream_readblocks_t *blocks)
int dpvsimpledecode_error(void *stream, const char **errorstring)
void dpvsimpledecode_close(void *stream)
static int dpvsimpledecode_setpixelformat(dpvsimpledecodestream_t *s, unsigned int Rmask, unsigned int Gmask, unsigned int Bmask, unsigned int bytesperpixel)
static int hz_bitstream_read_blocks_read(hz_bitstream_readblocks_t *blocks, hz_bitstream_read_t *stream, unsigned int size)
double dpvsimpledecode_getaspectratio(void *stream)
int dpvsimpledecode_video(void *stream, void *imagedata, unsigned int Rmask, unsigned int Gmask, unsigned int Bmask, unsigned int bytesperpixel, int imagebytesperrow)
static hz_bitstream_readblocks_t * hz_bitstream_read_blocks_new(void)
unsigned int dpvsimpledecode_getheight(void *stream)
static void hz_bitstream_read_flushbits(hz_bitstream_readblocks_t *blocks)
static unsigned int hz_bitstream_read_short(hz_bitstream_readblocks_t *blocks)
#define DPVSIMPLEDECODEERROR_SOUNDBUFFERTOOSMALL
#define DPVSIMPLEDECODEERROR_INVALIDBMASK
#define DPVSIMPLEDECODEERROR_INVALIDRMASK
#define DPVSIMPLEDECODEERROR_READERROR
#define DPVSIMPLEDECODEERROR_COLORMASKSEXCEEDBPP
#define DPVSIMPLEDECODEERROR_INVALIDGMASK
#define DPVSIMPLEDECODEERROR_UNSUPPORTEDBPP
#define DPVSIMPLEDECODEERROR_COLORMASKSOVERLAP
#define DPVSIMPLEDECODEERROR_NONE
#define DPVSIMPLEDECODEERROR_EOF
fs_offset_t FS_Read(qfile_t *file, void *buffer, size_t buffersize)
qfile_t * FS_OpenVirtualFile(const char *filepath, qbool quiet)
void FS_StripExtension(const char *in, char *out, size_t size_out)
int FS_Close(qfile_t *file)
GLenum GLsizei GLsizei height
GLint GLenum GLint GLint y
GLsizeiptr const GLvoid * data
int S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation)
S_StartSound returns the channel index, or -1 if an error occurred.
void S_StopChannel(unsigned int channel_ind, qbool lockmutex, qbool freesfx)
sfx_t * S_PrecacheSound(const char *name, qbool complain, qbool levelsound)
void(* close)(void *stream)
double(* getframerate)(void *stream)
unsigned int(* getheight)(void *stream)
int(* decodeframe)(void *stream, void *imagedata, unsigned int Rmask, unsigned int Gmask, unsigned int Bmask, unsigned int bytesperpixel, int imagebytesperrow)
double(* getaspectratio)(void *stream)
unsigned int(* getwidth)(void *stream)
unsigned int * videopixels
unsigned int info_imageheight
unsigned int info_imageGloss
unsigned int info_imageBloss
unsigned int info_imageBmask
unsigned int info_imagewidth
unsigned int info_imageGmask
unsigned int info_imageRmask
unsigned int info_imagesize
unsigned int info_imageBshift
hz_bitstream_read_t * bitstream
hz_bitstream_readblocks_t * framedatablocks
unsigned int info_imageRshift
unsigned int info_imagebpp
unsigned int info_imageGshift
unsigned int info_imageRloss
unsigned char data[HZREADBLOCKSIZE]
struct hz_bitstream_readblock_s * next
hz_bitstream_readblock_t * current
hz_bitstream_readblock_t * blocks