mirror of
https://github.com/kevinbentley/Descent3.git
synced 2025-01-22 11:28:56 +00:00
MVE: add copyright headers, clang-format
This commit is contained in:
parent
ef60434f72
commit
ce74c43b44
@ -14,3 +14,8 @@ set(CPPS
|
||||
|
||||
add_library(libmve STATIC ${CPPS})
|
||||
target_link_libraries(libmve PRIVATE SDL2::SDL2)
|
||||
target_include_directories(libmve PUBLIC
|
||||
$<BUILD_INTERFACE:
|
||||
${PROJECT_SOURCE_DIR}/libmve
|
||||
>
|
||||
)
|
||||
|
1200
libmve/decoder16.c
1200
libmve/decoder16.c
File diff suppressed because it is too large
Load Diff
1559
libmve/decoder8.c
1559
libmve/decoder8.c
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,20 @@
|
||||
/*
|
||||
* Copyright (C) 2002-2024 D2X Project
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* INTERNAL header - not to be included outside of libmve
|
||||
@ -10,7 +27,9 @@
|
||||
extern int g_width, g_height;
|
||||
extern void *g_vBackBuf1, *g_vBackBuf2;
|
||||
|
||||
extern void decodeFrame8(unsigned char *pFrame, unsigned char *pMap, int mapRemain, unsigned char *pData, int dataRemain);
|
||||
extern void decodeFrame16(unsigned char *pFrame, unsigned char *pMap, int mapRemain, unsigned char *pData, int dataRemain);
|
||||
extern void decodeFrame8(unsigned char *pFrame, unsigned char *pMap, int mapRemain, unsigned char *pData,
|
||||
int dataRemain);
|
||||
extern void decodeFrame16(unsigned char *pFrame, unsigned char *pMap, int mapRemain, unsigned char *pData,
|
||||
int dataRemain);
|
||||
|
||||
#endif // _DECODERS_H
|
||||
|
@ -1,18 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2002-2024 D2X Project
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _LIBMVE_H
|
||||
#define _LIBMVE_H
|
||||
|
||||
#define MVE_ERR_EOF 1
|
||||
|
||||
typedef struct{
|
||||
int screenWidth;
|
||||
int screenHeight;
|
||||
int width;
|
||||
int height;
|
||||
int truecolor;
|
||||
typedef struct {
|
||||
int screenWidth;
|
||||
int screenHeight;
|
||||
int width;
|
||||
int height;
|
||||
int truecolor;
|
||||
} MVE_videoSpec;
|
||||
|
||||
int MVE_rmPrepMovie(void *stream, int x, int y, int track);
|
||||
int MVE_rmStepMovie(void);
|
||||
int MVE_rmPrepMovie(void *stream, int x, int y, int track);
|
||||
int MVE_rmStepMovie(void);
|
||||
void MVE_rmHoldMovie(void);
|
||||
void MVE_rmEndMovie(void);
|
||||
|
||||
@ -20,21 +37,15 @@ void MVE_getVideoSpec(MVE_videoSpec *vSpec);
|
||||
|
||||
void MVE_sndInit(int x);
|
||||
|
||||
typedef unsigned int (*mve_cb_Read)(void *stream,
|
||||
void *buffer,
|
||||
unsigned int count);
|
||||
typedef unsigned int (*mve_cb_Read)(void *stream, void *buffer, unsigned int count);
|
||||
|
||||
typedef void *(*mve_cb_Alloc)(unsigned int size);
|
||||
typedef void (*mve_cb_Free)(void *ptr);
|
||||
|
||||
typedef void (*mve_cb_ShowFrame)(unsigned char *buffer,
|
||||
unsigned int bufw, unsigned int bufh,
|
||||
unsigned int sx, unsigned int sy,
|
||||
unsigned int w, unsigned int h,
|
||||
unsigned int dstx, unsigned int dsty);
|
||||
typedef void (*mve_cb_ShowFrame)(unsigned char *buffer, unsigned int bufw, unsigned int bufh, unsigned int sx,
|
||||
unsigned int sy, unsigned int w, unsigned int h, unsigned int dstx, unsigned int dsty);
|
||||
|
||||
typedef void (*mve_cb_SetPalette)(unsigned char *p,
|
||||
unsigned int start, unsigned int count);
|
||||
typedef void (*mve_cb_SetPalette)(unsigned char *p, unsigned int start, unsigned int count);
|
||||
|
||||
void MVE_ioCallbacks(mve_cb_Read io_read);
|
||||
void MVE_memCallbacks(mve_cb_Alloc mem_alloc, mve_cb_Free mem_free);
|
||||
|
@ -1,55 +1,80 @@
|
||||
static int audio_exp_table[256] =
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
||||
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 47, 51, 56, 61,
|
||||
66, 72, 79, 86, 94, 102, 112, 122, 133, 145, 158, 173, 189, 206, 225, 245,
|
||||
267, 292, 318, 348, 379, 414, 452, 493, 538, 587, 640, 699, 763, 832, 908, 991,
|
||||
1081, 1180, 1288, 1405, 1534, 1673, 1826, 1993, 2175, 2373, 2590, 2826, 3084, 3365, 3672, 4008,
|
||||
4373, 4772, 5208, 5683, 6202, 6767, 7385, 8059, 8794, 9597, 10472, 11428, 12471, 13609, 14851, 16206,
|
||||
17685, 19298, 21060, 22981, 25078, 27367, 29864, 32589, -29973, -26728, -23186, -19322, -15105, -10503, -5481, -1,
|
||||
1, 1, 5481, 10503, 15105, 19322, 23186, 26728, 29973, -32589, -29864, -27367, -25078, -22981, -21060, -19298,
|
||||
-17685, -16206, -14851, -13609, -12471, -11428, -10472, -9597, -8794, -8059, -7385, -6767, -6202, -5683, -5208, -4772,
|
||||
-4373, -4008, -3672, -3365, -3084, -2826, -2590, -2373, -2175, -1993, -1826, -1673, -1534, -1405, -1288, -1180,
|
||||
-1081, -991, -908, -832, -763, -699, -640, -587, -538, -493, -452, -414, -379, -348, -318, -292,
|
||||
-267, -245, -225, -206, -189, -173, -158, -145, -133, -122, -112, -102, -94, -86, -79, -72,
|
||||
-66, -61, -56, -51, -47, -43, -42, -41, -40, -39, -38, -37, -36, -35, -34, -33,
|
||||
-32, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17,
|
||||
-16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1
|
||||
/*
|
||||
* Copyright (C) 2002-2024 D2X Project
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
static int audio_exp_table[256] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, // 8
|
||||
8, 9, 10, 11, 12, 13, 14, 15, //
|
||||
16, 17, 18, 19, 20, 21, 22, 23, //
|
||||
24, 25, 26, 27, 28, 29, 30, 31, //
|
||||
32, 33, 34, 35, 36, 37, 38, 39, //
|
||||
40, 41, 42, 43, 47, 51, 56, 61, //
|
||||
66, 72, 79, 86, 94, 102, 112, 122, //
|
||||
133, 145, 158, 173, 189, 206, 225, 245, // 64
|
||||
267, 292, 318, 348, 379, 414, 452, 493, //
|
||||
538, 587, 640, 699, 763, 832, 908, 991, //
|
||||
1081, 1180, 1288, 1405, 1534, 1673, 1826, 1993, //
|
||||
2175, 2373, 2590, 2826, 3084, 3365, 3672, 4008, //
|
||||
4373, 4772, 5208, 5683, 6202, 6767, 7385, 8059, //
|
||||
8794, 9597, 10472, 11428, 12471, 13609, 14851, 16206, //
|
||||
17685, 19298, 21060, 22981, 25078, 27367, 29864, 32589, //
|
||||
-29973, -26728, -23186, -19322, -15105, -10503, -5481, -1, // 128
|
||||
1, 1, 5481, 10503, 15105, 19322, 23186, 26728, //
|
||||
29973, -32589, -29864, -27367, -25078, -22981, -21060, -19298, //
|
||||
-17685, -16206, -14851, -13609, -12471, -11428, -10472, -9597, //
|
||||
-8794, -8059, -7385, -6767, -6202, -5683, -5208, -4772, //
|
||||
-4373, -4008, -3672, -3365, -3084, -2826, -2590, -2373, //
|
||||
-2175, -1993, -1826, -1673, -1534, -1405, -1288, -1180, //
|
||||
-1081, -991, -908, -832, -763, -699, -640, -587, //
|
||||
-538, -493, -452, -414, -379, -348, -318, -292, // 196
|
||||
-267, -245, -225, -206, -189, -173, -158, -145, //
|
||||
-133, -122, -112, -102, -94, -86, -79, -72, //
|
||||
-66, -61, -56, -51, -47, -43, -42, -41, //
|
||||
-40, -39, -38, -37, -36, -35, -34, -33, //
|
||||
-32, -31, -30, -29, -28, -27, -26, -25, //
|
||||
-24, -23, -22, -21, -20, -19, -18, -17, //
|
||||
-16, -15, -14, -13, -12, -11, -10, -9, //
|
||||
-8, -7, -6, -5, -4, -3, -2, -1, // 256
|
||||
};
|
||||
|
||||
static int getWord(unsigned char **fin)
|
||||
{
|
||||
int value = ((*fin)[1] << 8) | (*fin)[0];
|
||||
*fin += 2;
|
||||
return value;
|
||||
static int getWord(unsigned char **fin) {
|
||||
int value = ((*fin)[1] << 8) | (*fin)[0];
|
||||
*fin += 2;
|
||||
return value;
|
||||
}
|
||||
|
||||
static void sendWord(short **fout, int nOffset)
|
||||
{
|
||||
*(*fout)++ = nOffset;
|
||||
static void sendWord(short **fout, int nOffset) { *(*fout)++ = nOffset; }
|
||||
|
||||
static void processSwath(short *fout, unsigned char *data, int swath, int *offsets) {
|
||||
int i;
|
||||
for (i = 0; i < swath; i++) {
|
||||
offsets[i & 1] += audio_exp_table[data[i]];
|
||||
sendWord(&fout, offsets[i & 1]);
|
||||
}
|
||||
}
|
||||
|
||||
static void processSwath(short *fout, unsigned char *data, int swath, int *offsets)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<swath; i++)
|
||||
{
|
||||
offsets[i&1] += audio_exp_table[data[i]];
|
||||
sendWord(&fout, offsets[i&1]);
|
||||
}
|
||||
}
|
||||
void mveaudio_uncompress(short *buffer, unsigned char *data, int length) {
|
||||
int nCurOffsets[2];
|
||||
int swath;
|
||||
|
||||
void mveaudio_uncompress(short *buffer, unsigned char *data, int length)
|
||||
{
|
||||
int nCurOffsets[2];
|
||||
int swath;
|
||||
|
||||
data += 4;
|
||||
swath = getWord(&data) / 2;
|
||||
nCurOffsets[0] = getWord(&data);
|
||||
nCurOffsets[1] = getWord(&data);
|
||||
sendWord(&buffer, nCurOffsets[0]);
|
||||
sendWord(&buffer, nCurOffsets[1]);
|
||||
processSwath(buffer, data, swath, nCurOffsets);
|
||||
data += 4;
|
||||
swath = getWord(&data) / 2;
|
||||
nCurOffsets[0] = getWord(&data);
|
||||
nCurOffsets[1] = getWord(&data);
|
||||
sendWord(&buffer, nCurOffsets[0]);
|
||||
sendWord(&buffer, nCurOffsets[1]);
|
||||
processSwath(buffer, data, swath, nCurOffsets);
|
||||
}
|
||||
|
@ -1,3 +1,20 @@
|
||||
/*
|
||||
* Copyright (C) 2002-2024 D2X Project
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_MVE_AUDIO_H
|
||||
#define INCLUDED_MVE_AUDIO_H
|
||||
|
||||
|
529
libmve/mvelib.c
529
libmve/mvelib.c
@ -1,3 +1,20 @@
|
||||
/*
|
||||
* Copyright (C) 2002-2024 D2X Project
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "conf.h"
|
||||
#endif
|
||||
@ -12,7 +29,7 @@
|
||||
|
||||
#include "mvelib.h"
|
||||
|
||||
static const char MVE_HEADER[] = "Interplay MVE File\x1A";
|
||||
static const char MVE_HEADER[] = "Interplay MVE File\x1A";
|
||||
static const short MVE_HDRCONST1 = 0x001A;
|
||||
static const short MVE_HDRCONST2 = 0x0100;
|
||||
static const short MVE_HDRCONST3 = 0x1133;
|
||||
@ -36,7 +53,7 @@ static MVEFILE *_mvefile_alloc(void);
|
||||
static void _mvefile_free(MVEFILE *movie);
|
||||
static int _mvefile_open(MVEFILE *movie, void *stream);
|
||||
static void _mvefile_reset(MVEFILE *movie);
|
||||
static int _mvefile_read_header(MVEFILE *movie);
|
||||
static int _mvefile_read_header(MVEFILE *movie);
|
||||
static void _mvefile_set_buffer_size(MVEFILE *movie, int buf_size);
|
||||
static int _mvefile_fetch_next_chunk(MVEFILE *movie);
|
||||
|
||||
@ -55,157 +72,140 @@ static void _mvestream_reset(MVESTREAM *movie);
|
||||
/*
|
||||
* open an MVE file
|
||||
*/
|
||||
MVEFILE *mvefile_open(void *stream)
|
||||
{
|
||||
MVEFILE *file;
|
||||
MVEFILE *mvefile_open(void *stream) {
|
||||
MVEFILE *file;
|
||||
|
||||
/* create the file */
|
||||
file = _mvefile_alloc();
|
||||
if (! _mvefile_open(file, stream))
|
||||
{
|
||||
_mvefile_free(file);
|
||||
return NULL;
|
||||
}
|
||||
/* create the file */
|
||||
file = _mvefile_alloc();
|
||||
if (!_mvefile_open(file, stream)) {
|
||||
_mvefile_free(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* initialize the file */
|
||||
_mvefile_set_buffer_size(file, 1024);
|
||||
/* initialize the file */
|
||||
_mvefile_set_buffer_size(file, 1024);
|
||||
|
||||
/* verify the file's header */
|
||||
if (! _mvefile_read_header(file))
|
||||
{
|
||||
_mvefile_free(file);
|
||||
return NULL;
|
||||
}
|
||||
/* verify the file's header */
|
||||
if (!_mvefile_read_header(file)) {
|
||||
_mvefile_free(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* now, prefetch the next chunk */
|
||||
_mvefile_fetch_next_chunk(file);
|
||||
/* now, prefetch the next chunk */
|
||||
_mvefile_fetch_next_chunk(file);
|
||||
|
||||
return file;
|
||||
return file;
|
||||
}
|
||||
|
||||
/*
|
||||
* close a MVE file
|
||||
*/
|
||||
void mvefile_close(MVEFILE *movie)
|
||||
{
|
||||
_mvefile_free(movie);
|
||||
}
|
||||
void mvefile_close(MVEFILE *movie) { _mvefile_free(movie); }
|
||||
|
||||
/*
|
||||
* reset a MVE file
|
||||
*/
|
||||
void mvefile_reset(MVEFILE *file)
|
||||
{
|
||||
_mvefile_reset(file);
|
||||
void mvefile_reset(MVEFILE *file) {
|
||||
_mvefile_reset(file);
|
||||
|
||||
/* initialize the file */
|
||||
_mvefile_set_buffer_size(file, 1024);
|
||||
/* initialize the file */
|
||||
_mvefile_set_buffer_size(file, 1024);
|
||||
|
||||
/* verify the file's header */
|
||||
if (! _mvefile_read_header(file))
|
||||
{
|
||||
_mvefile_free(file);
|
||||
//return NULL;
|
||||
}
|
||||
/* verify the file's header */
|
||||
if (!_mvefile_read_header(file)) {
|
||||
_mvefile_free(file);
|
||||
// return NULL;
|
||||
}
|
||||
|
||||
/* now, prefetch the next chunk */
|
||||
_mvefile_fetch_next_chunk(file);
|
||||
/* now, prefetch the next chunk */
|
||||
_mvefile_fetch_next_chunk(file);
|
||||
}
|
||||
|
||||
/*
|
||||
* get the size of the next segment
|
||||
*/
|
||||
int mvefile_get_next_segment_size(MVEFILE *movie)
|
||||
{
|
||||
/* if nothing is cached, fail */
|
||||
if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill)
|
||||
return -1;
|
||||
int mvefile_get_next_segment_size(MVEFILE *movie) {
|
||||
/* if nothing is cached, fail */
|
||||
if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill)
|
||||
return -1;
|
||||
|
||||
/* if we don't have enough data to get a segment, fail */
|
||||
if (movie->cur_fill - movie->next_segment < 4)
|
||||
return -1;
|
||||
/* if we don't have enough data to get a segment, fail */
|
||||
if (movie->cur_fill - movie->next_segment < 4)
|
||||
return -1;
|
||||
|
||||
/* otherwise, get the data length */
|
||||
return _mve_get_short(movie->cur_chunk + movie->next_segment);
|
||||
/* otherwise, get the data length */
|
||||
return _mve_get_short(movie->cur_chunk + movie->next_segment);
|
||||
}
|
||||
|
||||
/*
|
||||
* get type of next segment in chunk (0xff if no more segments in chunk)
|
||||
*/
|
||||
unsigned char mvefile_get_next_segment_major(MVEFILE *movie)
|
||||
{
|
||||
/* if nothing is cached, fail */
|
||||
if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill)
|
||||
return 0xff;
|
||||
unsigned char mvefile_get_next_segment_major(MVEFILE *movie) {
|
||||
/* if nothing is cached, fail */
|
||||
if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill)
|
||||
return 0xff;
|
||||
|
||||
/* if we don't have enough data to get a segment, fail */
|
||||
if (movie->cur_fill - movie->next_segment < 4)
|
||||
return 0xff;
|
||||
/* if we don't have enough data to get a segment, fail */
|
||||
if (movie->cur_fill - movie->next_segment < 4)
|
||||
return 0xff;
|
||||
|
||||
/* otherwise, get the data length */
|
||||
return movie->cur_chunk[movie->next_segment + 2];
|
||||
/* otherwise, get the data length */
|
||||
return movie->cur_chunk[movie->next_segment + 2];
|
||||
}
|
||||
|
||||
/*
|
||||
* get subtype (version) of next segment in chunk (0xff if no more segments in
|
||||
* chunk)
|
||||
*/
|
||||
unsigned char mvefile_get_next_segment_minor(MVEFILE *movie)
|
||||
{
|
||||
/* if nothing is cached, fail */
|
||||
if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill)
|
||||
return 0xff;
|
||||
unsigned char mvefile_get_next_segment_minor(MVEFILE *movie) {
|
||||
/* if nothing is cached, fail */
|
||||
if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill)
|
||||
return 0xff;
|
||||
|
||||
/* if we don't have enough data to get a segment, fail */
|
||||
if (movie->cur_fill - movie->next_segment < 4)
|
||||
return 0xff;
|
||||
/* if we don't have enough data to get a segment, fail */
|
||||
if (movie->cur_fill - movie->next_segment < 4)
|
||||
return 0xff;
|
||||
|
||||
/* otherwise, get the data length */
|
||||
return movie->cur_chunk[movie->next_segment + 3];
|
||||
/* otherwise, get the data length */
|
||||
return movie->cur_chunk[movie->next_segment + 3];
|
||||
}
|
||||
|
||||
/*
|
||||
* see next segment (return NULL if no next segment)
|
||||
*/
|
||||
unsigned char *mvefile_get_next_segment(MVEFILE *movie)
|
||||
{
|
||||
/* if nothing is cached, fail */
|
||||
if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill)
|
||||
return NULL;
|
||||
unsigned char *mvefile_get_next_segment(MVEFILE *movie) {
|
||||
/* if nothing is cached, fail */
|
||||
if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill)
|
||||
return NULL;
|
||||
|
||||
/* if we don't have enough data to get a segment, fail */
|
||||
if (movie->cur_fill - movie->next_segment < 4)
|
||||
return NULL;
|
||||
/* if we don't have enough data to get a segment, fail */
|
||||
if (movie->cur_fill - movie->next_segment < 4)
|
||||
return NULL;
|
||||
|
||||
/* otherwise, get the data length */
|
||||
return movie->cur_chunk + movie->next_segment + 4;
|
||||
/* otherwise, get the data length */
|
||||
return movie->cur_chunk + movie->next_segment + 4;
|
||||
}
|
||||
|
||||
/*
|
||||
* advance to next segment
|
||||
*/
|
||||
void mvefile_advance_segment(MVEFILE *movie)
|
||||
{
|
||||
/* if nothing is cached, fail */
|
||||
if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill)
|
||||
return;
|
||||
void mvefile_advance_segment(MVEFILE *movie) {
|
||||
/* if nothing is cached, fail */
|
||||
if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill)
|
||||
return;
|
||||
|
||||
/* if we don't have enough data to get a segment, fail */
|
||||
if (movie->cur_fill - movie->next_segment < 4)
|
||||
return;
|
||||
/* if we don't have enough data to get a segment, fail */
|
||||
if (movie->cur_fill - movie->next_segment < 4)
|
||||
return;
|
||||
|
||||
/* else, advance to next segment */
|
||||
movie->next_segment +=
|
||||
(4 + _mve_get_ushort(movie->cur_chunk + movie->next_segment));
|
||||
/* else, advance to next segment */
|
||||
movie->next_segment += (4 + _mve_get_ushort(movie->cur_chunk + movie->next_segment));
|
||||
}
|
||||
|
||||
/*
|
||||
* fetch the next chunk (return 0 if at end of stream)
|
||||
*/
|
||||
int mvefile_fetch_next_chunk(MVEFILE *movie)
|
||||
{
|
||||
return _mvefile_fetch_next_chunk(movie);
|
||||
}
|
||||
int mvefile_fetch_next_chunk(MVEFILE *movie) { return _mvefile_fetch_next_chunk(movie); }
|
||||
|
||||
/************************************************************
|
||||
* public MVESTREAM functions
|
||||
@ -214,90 +214,75 @@ int mvefile_fetch_next_chunk(MVEFILE *movie)
|
||||
/*
|
||||
* open an MVE stream
|
||||
*/
|
||||
MVESTREAM *mve_open(void *stream)
|
||||
{
|
||||
MVESTREAM *movie;
|
||||
MVESTREAM *mve_open(void *stream) {
|
||||
MVESTREAM *movie;
|
||||
|
||||
/* allocate */
|
||||
movie = _mvestream_alloc();
|
||||
/* allocate */
|
||||
movie = _mvestream_alloc();
|
||||
|
||||
/* open */
|
||||
if (! _mvestream_open(movie, stream))
|
||||
{
|
||||
_mvestream_free(movie);
|
||||
return NULL;
|
||||
}
|
||||
/* open */
|
||||
if (!_mvestream_open(movie, stream)) {
|
||||
_mvestream_free(movie);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return movie;
|
||||
return movie;
|
||||
}
|
||||
|
||||
/*
|
||||
* close an MVE stream
|
||||
*/
|
||||
void mve_close(MVESTREAM *movie)
|
||||
{
|
||||
_mvestream_free(movie);
|
||||
}
|
||||
void mve_close(MVESTREAM *movie) { _mvestream_free(movie); }
|
||||
|
||||
/*
|
||||
* reset an MVE stream
|
||||
*/
|
||||
void mve_reset(MVESTREAM *movie)
|
||||
{
|
||||
_mvestream_reset(movie);
|
||||
}
|
||||
void mve_reset(MVESTREAM *movie) { _mvestream_reset(movie); }
|
||||
|
||||
/*
|
||||
* set segment type handler
|
||||
*/
|
||||
void mve_set_handler(MVESTREAM *movie, unsigned char major, MVESEGMENTHANDLER handler)
|
||||
{
|
||||
if (major < 32)
|
||||
movie->handlers[major] = handler;
|
||||
void mve_set_handler(MVESTREAM *movie, unsigned char major, MVESEGMENTHANDLER handler) {
|
||||
if (major < 32)
|
||||
movie->handlers[major] = handler;
|
||||
}
|
||||
|
||||
/*
|
||||
* set segment handler context
|
||||
*/
|
||||
void mve_set_handler_context(MVESTREAM *movie, void *context)
|
||||
{
|
||||
movie->context = context;
|
||||
}
|
||||
void mve_set_handler_context(MVESTREAM *movie, void *context) { movie->context = context; }
|
||||
|
||||
/*
|
||||
* play next chunk
|
||||
*/
|
||||
int mve_play_next_chunk(MVESTREAM *movie)
|
||||
{
|
||||
unsigned char major, minor;
|
||||
unsigned char *data;
|
||||
int len;
|
||||
int mve_play_next_chunk(MVESTREAM *movie) {
|
||||
unsigned char major, minor;
|
||||
unsigned char *data;
|
||||
int len;
|
||||
|
||||
/* loop over segments */
|
||||
major = mvefile_get_next_segment_major(movie->movie);
|
||||
while (major != 0xff)
|
||||
{
|
||||
/* check whether to handle the segment */
|
||||
if (major < 32 && movie->handlers[major] != NULL)
|
||||
{
|
||||
minor = mvefile_get_next_segment_minor(movie->movie);
|
||||
len = mvefile_get_next_segment_size(movie->movie);
|
||||
data = mvefile_get_next_segment(movie->movie);
|
||||
/* loop over segments */
|
||||
major = mvefile_get_next_segment_major(movie->movie);
|
||||
while (major != 0xff) {
|
||||
/* check whether to handle the segment */
|
||||
if (major < 32 && movie->handlers[major] != NULL) {
|
||||
minor = mvefile_get_next_segment_minor(movie->movie);
|
||||
len = mvefile_get_next_segment_size(movie->movie);
|
||||
data = mvefile_get_next_segment(movie->movie);
|
||||
|
||||
if (! movie->handlers[major](major, minor, data, len, movie->context))
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* advance to next segment */
|
||||
mvefile_advance_segment(movie->movie);
|
||||
major = mvefile_get_next_segment_major(movie->movie);
|
||||
if (!movie->handlers[major](major, minor, data, len, movie->context))
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (! mvefile_fetch_next_chunk(movie->movie))
|
||||
return 0;
|
||||
/* advance to next segment */
|
||||
mvefile_advance_segment(movie->movie);
|
||||
major = mvefile_get_next_segment_major(movie->movie);
|
||||
}
|
||||
|
||||
/* return status */
|
||||
return 1;
|
||||
if (!mvefile_fetch_next_chunk(movie->movie))
|
||||
return 0;
|
||||
|
||||
/* return status */
|
||||
return 1;
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
@ -307,57 +292,53 @@ int mve_play_next_chunk(MVESTREAM *movie)
|
||||
/*
|
||||
* allocate an MVEFILE
|
||||
*/
|
||||
static MVEFILE *_mvefile_alloc(void)
|
||||
{
|
||||
MVEFILE *file = (MVEFILE *)mve_alloc(sizeof(MVEFILE));
|
||||
file->stream = NULL;
|
||||
file->cur_chunk = NULL;
|
||||
file->buf_size = 0;
|
||||
file->cur_fill = 0;
|
||||
file->next_segment = 0;
|
||||
static MVEFILE *_mvefile_alloc(void) {
|
||||
MVEFILE *file = (MVEFILE *)mve_alloc(sizeof(MVEFILE));
|
||||
file->stream = NULL;
|
||||
file->cur_chunk = NULL;
|
||||
file->buf_size = 0;
|
||||
file->cur_fill = 0;
|
||||
file->next_segment = 0;
|
||||
|
||||
return file;
|
||||
return file;
|
||||
}
|
||||
|
||||
/*
|
||||
* free an MVE file
|
||||
*/
|
||||
static void _mvefile_free(MVEFILE *movie)
|
||||
{
|
||||
/* free the stream */
|
||||
movie->stream = NULL;
|
||||
static void _mvefile_free(MVEFILE *movie) {
|
||||
/* free the stream */
|
||||
movie->stream = NULL;
|
||||
|
||||
/* free the buffer */
|
||||
if (movie->cur_chunk)
|
||||
mve_free(movie->cur_chunk);
|
||||
movie->cur_chunk = NULL;
|
||||
/* free the buffer */
|
||||
if (movie->cur_chunk)
|
||||
mve_free(movie->cur_chunk);
|
||||
movie->cur_chunk = NULL;
|
||||
|
||||
/* not strictly necessary */
|
||||
movie->buf_size = 0;
|
||||
movie->cur_fill = 0;
|
||||
movie->next_segment = 0;
|
||||
/* not strictly necessary */
|
||||
movie->buf_size = 0;
|
||||
movie->cur_fill = 0;
|
||||
movie->next_segment = 0;
|
||||
|
||||
/* free the struct */
|
||||
mve_free(movie);
|
||||
/* free the struct */
|
||||
mve_free(movie);
|
||||
}
|
||||
|
||||
/*
|
||||
* open the file stream in thie object
|
||||
*/
|
||||
static int _mvefile_open(MVEFILE *file, void *stream)
|
||||
{
|
||||
file->stream = stream;
|
||||
if (! file->stream)
|
||||
return 0;
|
||||
static int _mvefile_open(MVEFILE *file, void *stream) {
|
||||
file->stream = stream;
|
||||
if (!file->stream)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* allocate an MVEFILE
|
||||
*/
|
||||
static void _mvefile_reset(MVEFILE *file)
|
||||
{
|
||||
static void _mvefile_reset(MVEFILE *file) {
|
||||
#if 0
|
||||
file->cur_chunk = NULL;
|
||||
file->buf_size = 0;
|
||||
@ -369,152 +350,140 @@ static void _mvefile_reset(MVEFILE *file)
|
||||
/*
|
||||
* read and verify the header of the recently opened file
|
||||
*/
|
||||
static int _mvefile_read_header(MVEFILE *movie)
|
||||
{
|
||||
unsigned char buffer[26];
|
||||
static int _mvefile_read_header(MVEFILE *movie) {
|
||||
unsigned char buffer[26];
|
||||
|
||||
/* check the file is open */
|
||||
if (! movie->stream)
|
||||
return 0;
|
||||
/* check the file is open */
|
||||
if (!movie->stream)
|
||||
return 0;
|
||||
|
||||
/* check the file is long enough */
|
||||
if (! mve_read(movie->stream, buffer, 26))
|
||||
return 0;
|
||||
/* check the file is long enough */
|
||||
if (!mve_read(movie->stream, buffer, 26))
|
||||
return 0;
|
||||
|
||||
/* check the signature */
|
||||
if (memcmp(buffer, MVE_HEADER, 20))
|
||||
return 0;
|
||||
/* check the signature */
|
||||
if (memcmp(buffer, MVE_HEADER, 20))
|
||||
return 0;
|
||||
|
||||
/* check the hard-coded constants */
|
||||
if (_mve_get_short(buffer+20) != MVE_HDRCONST1)
|
||||
return 0;
|
||||
if (_mve_get_short(buffer+22) != MVE_HDRCONST2)
|
||||
return 0;
|
||||
if (_mve_get_short(buffer+24) != MVE_HDRCONST3)
|
||||
return 0;
|
||||
/* check the hard-coded constants */
|
||||
if (_mve_get_short(buffer + 20) != MVE_HDRCONST1)
|
||||
return 0;
|
||||
if (_mve_get_short(buffer + 22) != MVE_HDRCONST2)
|
||||
return 0;
|
||||
if (_mve_get_short(buffer + 24) != MVE_HDRCONST3)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void _mvefile_set_buffer_size(MVEFILE *movie, int buf_size)
|
||||
{
|
||||
unsigned char *new_buffer;
|
||||
int new_len;
|
||||
static void _mvefile_set_buffer_size(MVEFILE *movie, int buf_size) {
|
||||
unsigned char *new_buffer;
|
||||
int new_len;
|
||||
|
||||
/* check if this would be a redundant operation */
|
||||
if (buf_size <= movie->buf_size)
|
||||
return;
|
||||
/* check if this would be a redundant operation */
|
||||
if (buf_size <= movie->buf_size)
|
||||
return;
|
||||
|
||||
/* allocate new buffer */
|
||||
new_len = 100 + buf_size;
|
||||
new_buffer = (unsigned char *)mve_alloc(new_len);
|
||||
/* allocate new buffer */
|
||||
new_len = 100 + buf_size;
|
||||
new_buffer = (unsigned char *)mve_alloc(new_len);
|
||||
|
||||
/* copy old data */
|
||||
if (movie->cur_chunk && movie->cur_fill)
|
||||
memcpy(new_buffer, movie->cur_chunk, movie->cur_fill);
|
||||
/* copy old data */
|
||||
if (movie->cur_chunk && movie->cur_fill)
|
||||
memcpy(new_buffer, movie->cur_chunk, movie->cur_fill);
|
||||
|
||||
/* free old buffer */
|
||||
if (movie->cur_chunk)
|
||||
{
|
||||
mve_free(movie->cur_chunk);
|
||||
movie->cur_chunk = 0;
|
||||
}
|
||||
/* free old buffer */
|
||||
if (movie->cur_chunk) {
|
||||
mve_free(movie->cur_chunk);
|
||||
movie->cur_chunk = 0;
|
||||
}
|
||||
|
||||
/* install new buffer */
|
||||
movie->cur_chunk = new_buffer;
|
||||
movie->buf_size = new_len;
|
||||
/* install new buffer */
|
||||
movie->cur_chunk = new_buffer;
|
||||
movie->buf_size = new_len;
|
||||
}
|
||||
|
||||
static int _mvefile_fetch_next_chunk(MVEFILE *movie)
|
||||
{
|
||||
unsigned char buffer[4];
|
||||
unsigned short length;
|
||||
static int _mvefile_fetch_next_chunk(MVEFILE *movie) {
|
||||
unsigned char buffer[4];
|
||||
unsigned short length;
|
||||
|
||||
/* fail if not open */
|
||||
if (! movie->stream)
|
||||
return 0;
|
||||
/* fail if not open */
|
||||
if (!movie->stream)
|
||||
return 0;
|
||||
|
||||
/* fail if we can't read the next segment descriptor */
|
||||
if (! mve_read(movie->stream, buffer, 4))
|
||||
return 0;
|
||||
/* fail if we can't read the next segment descriptor */
|
||||
if (!mve_read(movie->stream, buffer, 4))
|
||||
return 0;
|
||||
|
||||
/* pull out the next length */
|
||||
length = _mve_get_short(buffer);
|
||||
/* pull out the next length */
|
||||
length = _mve_get_short(buffer);
|
||||
|
||||
/* make sure we've got sufficient space */
|
||||
_mvefile_set_buffer_size(movie, length);
|
||||
/* make sure we've got sufficient space */
|
||||
_mvefile_set_buffer_size(movie, length);
|
||||
|
||||
/* read the chunk */
|
||||
if (! mve_read(movie->stream, movie->cur_chunk, length))
|
||||
return 0;
|
||||
movie->cur_fill = length;
|
||||
movie->next_segment = 0;
|
||||
/* read the chunk */
|
||||
if (!mve_read(movie->stream, movie->cur_chunk, length))
|
||||
return 0;
|
||||
movie->cur_fill = length;
|
||||
movie->next_segment = 0;
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static short _mve_get_short(unsigned char *data)
|
||||
{
|
||||
short value;
|
||||
value = data[0] | (data[1] << 8);
|
||||
return value;
|
||||
static short _mve_get_short(unsigned char *data) {
|
||||
short value;
|
||||
value = data[0] | (data[1] << 8);
|
||||
return value;
|
||||
}
|
||||
|
||||
static unsigned short _mve_get_ushort(unsigned char *data)
|
||||
{
|
||||
unsigned short value;
|
||||
value = data[0] | (data[1] << 8);
|
||||
return value;
|
||||
static unsigned short _mve_get_ushort(unsigned char *data) {
|
||||
unsigned short value;
|
||||
value = data[0] | (data[1] << 8);
|
||||
return value;
|
||||
}
|
||||
|
||||
/*
|
||||
* allocate an MVESTREAM
|
||||
*/
|
||||
static MVESTREAM *_mvestream_alloc(void)
|
||||
{
|
||||
MVESTREAM *movie;
|
||||
static MVESTREAM *_mvestream_alloc(void) {
|
||||
MVESTREAM *movie;
|
||||
|
||||
/* allocate and zero-initialize everything */
|
||||
movie = (MVESTREAM *)mve_alloc(sizeof(MVESTREAM));
|
||||
movie->movie = NULL;
|
||||
movie->context = 0;
|
||||
memset(movie->handlers, 0, sizeof(movie->handlers));
|
||||
/* allocate and zero-initialize everything */
|
||||
movie = (MVESTREAM *)mve_alloc(sizeof(MVESTREAM));
|
||||
movie->movie = NULL;
|
||||
movie->context = 0;
|
||||
memset(movie->handlers, 0, sizeof(movie->handlers));
|
||||
|
||||
return movie;
|
||||
return movie;
|
||||
}
|
||||
|
||||
/*
|
||||
* free an MVESTREAM
|
||||
*/
|
||||
static void _mvestream_free(MVESTREAM *movie)
|
||||
{
|
||||
/* close MVEFILE */
|
||||
if (movie->movie)
|
||||
mvefile_close(movie->movie);
|
||||
movie->movie = NULL;
|
||||
static void _mvestream_free(MVESTREAM *movie) {
|
||||
/* close MVEFILE */
|
||||
if (movie->movie)
|
||||
mvefile_close(movie->movie);
|
||||
movie->movie = NULL;
|
||||
|
||||
/* clear context and handlers */
|
||||
movie->context = NULL;
|
||||
memset(movie->handlers, 0, sizeof(movie->handlers));
|
||||
/* clear context and handlers */
|
||||
movie->context = NULL;
|
||||
memset(movie->handlers, 0, sizeof(movie->handlers));
|
||||
|
||||
/* free the struct */
|
||||
mve_free(movie);
|
||||
/* free the struct */
|
||||
mve_free(movie);
|
||||
}
|
||||
|
||||
/*
|
||||
* open an MVESTREAM object
|
||||
*/
|
||||
static int _mvestream_open(MVESTREAM *movie, void *stream)
|
||||
{
|
||||
movie->movie = mvefile_open(stream);
|
||||
static int _mvestream_open(MVESTREAM *movie, void *stream) {
|
||||
movie->movie = mvefile_open(stream);
|
||||
|
||||
return (movie->movie == NULL) ? 0 : 1;
|
||||
return (movie->movie == NULL) ? 0 : 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* reset an MVESTREAM
|
||||
*/
|
||||
static void _mvestream_reset(MVESTREAM *movie)
|
||||
{
|
||||
mvefile_reset(movie->movie);
|
||||
}
|
||||
static void _mvestream_reset(MVESTREAM *movie) { mvefile_reset(movie->movie); }
|
||||
|
@ -1,3 +1,20 @@
|
||||
/*
|
||||
* Copyright (C) 2002-2024 D2X Project
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_MVELIB_H
|
||||
#define INCLUDED_MVELIB_H
|
||||
|
||||
@ -15,13 +32,12 @@ extern mve_cb_SetPalette mve_setpalette;
|
||||
/*
|
||||
* structure for maintaining info on a MVEFILE stream
|
||||
*/
|
||||
typedef struct MVEFILE
|
||||
{
|
||||
void *stream;
|
||||
unsigned char *cur_chunk;
|
||||
int buf_size;
|
||||
int cur_fill;
|
||||
int next_segment;
|
||||
typedef struct MVEFILE {
|
||||
void *stream;
|
||||
unsigned char *cur_chunk;
|
||||
int buf_size;
|
||||
int cur_fill;
|
||||
int next_segment;
|
||||
} MVEFILE;
|
||||
|
||||
/*
|
||||
@ -73,11 +89,10 @@ typedef int (*MVESEGMENTHANDLER)(unsigned char major, unsigned char minor, unsig
|
||||
/*
|
||||
* structure for maintaining an MVE stream
|
||||
*/
|
||||
typedef struct MVESTREAM
|
||||
{
|
||||
MVEFILE *movie;
|
||||
void *context;
|
||||
MVESEGMENTHANDLER handlers[32];
|
||||
typedef struct MVESTREAM {
|
||||
MVEFILE *movie;
|
||||
void *context;
|
||||
MVESEGMENTHANDLER handlers[32];
|
||||
} MVESTREAM;
|
||||
|
||||
/*
|
||||
|
988
libmve/mveplay.c
988
libmve/mveplay.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user