MVE: add copyright headers, clang-format

This commit is contained in:
Azamat H. Hackimov 2024-05-01 15:38:01 +03:00
parent ef60434f72
commit ce74c43b44
10 changed files with 2215 additions and 2311 deletions

View File

@ -14,3 +14,8 @@ set(CPPS
add_library(libmve STATIC ${CPPS}) add_library(libmve STATIC ${CPPS})
target_link_libraries(libmve PRIVATE SDL2::SDL2) target_link_libraries(libmve PRIVATE SDL2::SDL2)
target_include_directories(libmve PUBLIC
$<BUILD_INTERFACE:
${PROJECT_SOURCE_DIR}/libmve
>
)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -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 * INTERNAL header - not to be included outside of libmve
@ -10,7 +27,9 @@
extern int g_width, g_height; extern int g_width, g_height;
extern void *g_vBackBuf1, *g_vBackBuf2; extern void *g_vBackBuf1, *g_vBackBuf2;
extern void decodeFrame8(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,
extern void decodeFrame16(unsigned char *pFrame, unsigned char *pMap, int mapRemain, unsigned char *pData, int dataRemain); int dataRemain);
extern void decodeFrame16(unsigned char *pFrame, unsigned char *pMap, int mapRemain, unsigned char *pData,
int dataRemain);
#endif // _DECODERS_H #endif // _DECODERS_H

View File

@ -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 #ifndef _LIBMVE_H
#define _LIBMVE_H #define _LIBMVE_H
#define MVE_ERR_EOF 1 #define MVE_ERR_EOF 1
typedef struct{ typedef struct {
int screenWidth; int screenWidth;
int screenHeight; int screenHeight;
int width; int width;
int height; int height;
int truecolor; int truecolor;
} MVE_videoSpec; } MVE_videoSpec;
int MVE_rmPrepMovie(void *stream, int x, int y, int track); int MVE_rmPrepMovie(void *stream, int x, int y, int track);
int MVE_rmStepMovie(void); int MVE_rmStepMovie(void);
void MVE_rmHoldMovie(void); void MVE_rmHoldMovie(void);
void MVE_rmEndMovie(void); void MVE_rmEndMovie(void);
@ -20,21 +37,15 @@ void MVE_getVideoSpec(MVE_videoSpec *vSpec);
void MVE_sndInit(int x); void MVE_sndInit(int x);
typedef unsigned int (*mve_cb_Read)(void *stream, typedef unsigned int (*mve_cb_Read)(void *stream, void *buffer, unsigned int count);
void *buffer,
unsigned int count);
typedef void *(*mve_cb_Alloc)(unsigned int size); typedef void *(*mve_cb_Alloc)(unsigned int size);
typedef void (*mve_cb_Free)(void *ptr); typedef void (*mve_cb_Free)(void *ptr);
typedef void (*mve_cb_ShowFrame)(unsigned char *buffer, typedef void (*mve_cb_ShowFrame)(unsigned char *buffer, unsigned int bufw, unsigned int bufh, unsigned int sx,
unsigned int bufw, unsigned int bufh, unsigned int sy, unsigned int w, unsigned int h, unsigned int dstx, unsigned int dsty);
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, typedef void (*mve_cb_SetPalette)(unsigned char *p, unsigned int start, unsigned int count);
unsigned int start, unsigned int count);
void MVE_ioCallbacks(mve_cb_Read io_read); void MVE_ioCallbacks(mve_cb_Read io_read);
void MVE_memCallbacks(mve_cb_Alloc mem_alloc, mve_cb_Free mem_free); void MVE_memCallbacks(mve_cb_Alloc mem_alloc, mve_cb_Free mem_free);

View File

@ -1,55 +1,80 @@
static int audio_exp_table[256] = /*
{ * Copyright (C) 2002-2024 D2X Project
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, * This program is free software: you can redistribute it and/or modify
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 47, 51, 56, 61, * it under the terms of the GNU General Public License as published by
66, 72, 79, 86, 94, 102, 112, 122, 133, 145, 158, 173, 189, 206, 225, 245, * the Free Software Foundation, either version 3 of the License, or
267, 292, 318, 348, 379, 414, 452, 493, 538, 587, 640, 699, 763, 832, 908, 991, * (at your option) any later version.
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, * This program is distributed in the hope that it will be useful,
17685, 19298, 21060, 22981, 25078, 27367, 29864, 32589, -29973, -26728, -23186, -19322, -15105, -10503, -5481, -1, * but WITHOUT ANY WARRANTY; without even the implied warranty of
1, 1, 5481, 10503, 15105, 19322, 23186, 26728, 29973, -32589, -29864, -27367, -25078, -22981, -21060, -19298, * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-17685, -16206, -14851, -13609, -12471, -11428, -10472, -9597, -8794, -8059, -7385, -6767, -6202, -5683, -5208, -4772, * GNU General Public License for more details.
-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, * You should have received a copy of the GNU General Public License
-267, -245, -225, -206, -189, -173, -158, -145, -133, -122, -112, -102, -94, -86, -79, -72, * along with this program. If not, see <http://www.gnu.org/licenses/>.
-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 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) static int getWord(unsigned char **fin) {
{ int value = ((*fin)[1] << 8) | (*fin)[0];
int value = ((*fin)[1] << 8) | (*fin)[0]; *fin += 2;
*fin += 2; return value;
return value;
} }
static void sendWord(short **fout, int nOffset) static void sendWord(short **fout, int nOffset) { *(*fout)++ = 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) void mveaudio_uncompress(short *buffer, unsigned char *data, int length) {
{ int nCurOffsets[2];
int i; int swath;
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) data += 4;
{ swath = getWord(&data) / 2;
int nCurOffsets[2]; nCurOffsets[0] = getWord(&data);
int swath; nCurOffsets[1] = getWord(&data);
sendWord(&buffer, nCurOffsets[0]);
data += 4; sendWord(&buffer, nCurOffsets[1]);
swath = getWord(&data) / 2; processSwath(buffer, data, swath, nCurOffsets);
nCurOffsets[0] = getWord(&data);
nCurOffsets[1] = getWord(&data);
sendWord(&buffer, nCurOffsets[0]);
sendWord(&buffer, nCurOffsets[1]);
processSwath(buffer, data, swath, nCurOffsets);
} }

View File

@ -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 #ifndef INCLUDED_MVE_AUDIO_H
#define INCLUDED_MVE_AUDIO_H #define INCLUDED_MVE_AUDIO_H

View File

@ -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 #ifdef HAVE_CONFIG_H
#include "conf.h" #include "conf.h"
#endif #endif
@ -12,7 +29,7 @@
#include "mvelib.h" #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_HDRCONST1 = 0x001A;
static const short MVE_HDRCONST2 = 0x0100; static const short MVE_HDRCONST2 = 0x0100;
static const short MVE_HDRCONST3 = 0x1133; static const short MVE_HDRCONST3 = 0x1133;
@ -36,7 +53,7 @@ static MVEFILE *_mvefile_alloc(void);
static void _mvefile_free(MVEFILE *movie); static void _mvefile_free(MVEFILE *movie);
static int _mvefile_open(MVEFILE *movie, void *stream); static int _mvefile_open(MVEFILE *movie, void *stream);
static void _mvefile_reset(MVEFILE *movie); 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 void _mvefile_set_buffer_size(MVEFILE *movie, int buf_size);
static int _mvefile_fetch_next_chunk(MVEFILE *movie); static int _mvefile_fetch_next_chunk(MVEFILE *movie);
@ -55,157 +72,140 @@ static void _mvestream_reset(MVESTREAM *movie);
/* /*
* open an MVE file * open an MVE file
*/ */
MVEFILE *mvefile_open(void *stream) MVEFILE *mvefile_open(void *stream) {
{ MVEFILE *file;
MVEFILE *file;
/* create the file */ /* create the file */
file = _mvefile_alloc(); file = _mvefile_alloc();
if (! _mvefile_open(file, stream)) if (!_mvefile_open(file, stream)) {
{ _mvefile_free(file);
_mvefile_free(file); return NULL;
return NULL; }
}
/* initialize the file */ /* initialize the file */
_mvefile_set_buffer_size(file, 1024); _mvefile_set_buffer_size(file, 1024);
/* verify the file's header */ /* verify the file's header */
if (! _mvefile_read_header(file)) if (!_mvefile_read_header(file)) {
{ _mvefile_free(file);
_mvefile_free(file); return NULL;
return NULL; }
}
/* now, prefetch the next chunk */ /* now, prefetch the next chunk */
_mvefile_fetch_next_chunk(file); _mvefile_fetch_next_chunk(file);
return file; return file;
} }
/* /*
* close a MVE file * close a MVE file
*/ */
void mvefile_close(MVEFILE *movie) void mvefile_close(MVEFILE *movie) { _mvefile_free(movie); }
{
_mvefile_free(movie);
}
/* /*
* reset a MVE file * reset a MVE file
*/ */
void mvefile_reset(MVEFILE *file) void mvefile_reset(MVEFILE *file) {
{ _mvefile_reset(file);
_mvefile_reset(file);
/* initialize the file */ /* initialize the file */
_mvefile_set_buffer_size(file, 1024); _mvefile_set_buffer_size(file, 1024);
/* verify the file's header */ /* verify the file's header */
if (! _mvefile_read_header(file)) if (!_mvefile_read_header(file)) {
{ _mvefile_free(file);
_mvefile_free(file); // return NULL;
//return NULL; }
}
/* now, prefetch the next chunk */ /* now, prefetch the next chunk */
_mvefile_fetch_next_chunk(file); _mvefile_fetch_next_chunk(file);
} }
/* /*
* get the size of the next segment * get the size of the next segment
*/ */
int mvefile_get_next_segment_size(MVEFILE *movie) int mvefile_get_next_segment_size(MVEFILE *movie) {
{ /* if nothing is cached, fail */
/* if nothing is cached, fail */ if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill)
if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill) return -1;
return -1;
/* if we don't have enough data to get a segment, fail */ /* if we don't have enough data to get a segment, fail */
if (movie->cur_fill - movie->next_segment < 4) if (movie->cur_fill - movie->next_segment < 4)
return -1; return -1;
/* otherwise, get the data length */ /* otherwise, get the data length */
return _mve_get_short(movie->cur_chunk + movie->next_segment); return _mve_get_short(movie->cur_chunk + movie->next_segment);
} }
/* /*
* get type of next segment in chunk (0xff if no more segments in chunk) * get type of next segment in chunk (0xff if no more segments in chunk)
*/ */
unsigned char mvefile_get_next_segment_major(MVEFILE *movie) unsigned char mvefile_get_next_segment_major(MVEFILE *movie) {
{ /* if nothing is cached, fail */
/* if nothing is cached, fail */ if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill)
if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill) return 0xff;
return 0xff;
/* if we don't have enough data to get a segment, fail */ /* if we don't have enough data to get a segment, fail */
if (movie->cur_fill - movie->next_segment < 4) if (movie->cur_fill - movie->next_segment < 4)
return 0xff; return 0xff;
/* otherwise, get the data length */ /* otherwise, get the data length */
return movie->cur_chunk[movie->next_segment + 2]; return movie->cur_chunk[movie->next_segment + 2];
} }
/* /*
* get subtype (version) of next segment in chunk (0xff if no more segments in * get subtype (version) of next segment in chunk (0xff if no more segments in
* chunk) * chunk)
*/ */
unsigned char mvefile_get_next_segment_minor(MVEFILE *movie) unsigned char mvefile_get_next_segment_minor(MVEFILE *movie) {
{ /* if nothing is cached, fail */
/* if nothing is cached, fail */ if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill)
if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill) return 0xff;
return 0xff;
/* if we don't have enough data to get a segment, fail */ /* if we don't have enough data to get a segment, fail */
if (movie->cur_fill - movie->next_segment < 4) if (movie->cur_fill - movie->next_segment < 4)
return 0xff; return 0xff;
/* otherwise, get the data length */ /* otherwise, get the data length */
return movie->cur_chunk[movie->next_segment + 3]; return movie->cur_chunk[movie->next_segment + 3];
} }
/* /*
* see next segment (return NULL if no next segment) * see next segment (return NULL if no next segment)
*/ */
unsigned char *mvefile_get_next_segment(MVEFILE *movie) unsigned char *mvefile_get_next_segment(MVEFILE *movie) {
{ /* if nothing is cached, fail */
/* if nothing is cached, fail */ if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill)
if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill) return NULL;
return NULL;
/* if we don't have enough data to get a segment, fail */ /* if we don't have enough data to get a segment, fail */
if (movie->cur_fill - movie->next_segment < 4) if (movie->cur_fill - movie->next_segment < 4)
return NULL; return NULL;
/* otherwise, get the data length */ /* otherwise, get the data length */
return movie->cur_chunk + movie->next_segment + 4; return movie->cur_chunk + movie->next_segment + 4;
} }
/* /*
* advance to next segment * advance to next segment
*/ */
void mvefile_advance_segment(MVEFILE *movie) void mvefile_advance_segment(MVEFILE *movie) {
{ /* if nothing is cached, fail */
/* if nothing is cached, fail */ if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill)
if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill) return;
return;
/* if we don't have enough data to get a segment, fail */ /* if we don't have enough data to get a segment, fail */
if (movie->cur_fill - movie->next_segment < 4) if (movie->cur_fill - movie->next_segment < 4)
return; return;
/* else, advance to next segment */ /* else, advance to next segment */
movie->next_segment += movie->next_segment += (4 + _mve_get_ushort(movie->cur_chunk + movie->next_segment));
(4 + _mve_get_ushort(movie->cur_chunk + movie->next_segment));
} }
/* /*
* fetch the next chunk (return 0 if at end of stream) * fetch the next chunk (return 0 if at end of stream)
*/ */
int mvefile_fetch_next_chunk(MVEFILE *movie) int mvefile_fetch_next_chunk(MVEFILE *movie) { return _mvefile_fetch_next_chunk(movie); }
{
return _mvefile_fetch_next_chunk(movie);
}
/************************************************************ /************************************************************
* public MVESTREAM functions * public MVESTREAM functions
@ -214,90 +214,75 @@ int mvefile_fetch_next_chunk(MVEFILE *movie)
/* /*
* open an MVE stream * open an MVE stream
*/ */
MVESTREAM *mve_open(void *stream) MVESTREAM *mve_open(void *stream) {
{ MVESTREAM *movie;
MVESTREAM *movie;
/* allocate */ /* allocate */
movie = _mvestream_alloc(); movie = _mvestream_alloc();
/* open */ /* open */
if (! _mvestream_open(movie, stream)) if (!_mvestream_open(movie, stream)) {
{ _mvestream_free(movie);
_mvestream_free(movie); return NULL;
return NULL; }
}
return movie; return movie;
} }
/* /*
* close an MVE stream * close an MVE stream
*/ */
void mve_close(MVESTREAM *movie) void mve_close(MVESTREAM *movie) { _mvestream_free(movie); }
{
_mvestream_free(movie);
}
/* /*
* reset an MVE stream * reset an MVE stream
*/ */
void mve_reset(MVESTREAM *movie) void mve_reset(MVESTREAM *movie) { _mvestream_reset(movie); }
{
_mvestream_reset(movie);
}
/* /*
* set segment type handler * set segment type handler
*/ */
void mve_set_handler(MVESTREAM *movie, unsigned char major, MVESEGMENTHANDLER handler) void mve_set_handler(MVESTREAM *movie, unsigned char major, MVESEGMENTHANDLER handler) {
{ if (major < 32)
if (major < 32) movie->handlers[major] = handler;
movie->handlers[major] = handler;
} }
/* /*
* set segment handler context * set segment handler context
*/ */
void mve_set_handler_context(MVESTREAM *movie, void *context) void mve_set_handler_context(MVESTREAM *movie, void *context) { movie->context = context; }
{
movie->context = context;
}
/* /*
* play next chunk * play next chunk
*/ */
int mve_play_next_chunk(MVESTREAM *movie) int mve_play_next_chunk(MVESTREAM *movie) {
{ unsigned char major, minor;
unsigned char major, minor; unsigned char *data;
unsigned char *data; int len;
int len;
/* loop over segments */ /* loop over segments */
major = mvefile_get_next_segment_major(movie->movie); major = mvefile_get_next_segment_major(movie->movie);
while (major != 0xff) while (major != 0xff) {
{ /* check whether to handle the segment */
/* check whether to handle the segment */ if (major < 32 && movie->handlers[major] != NULL) {
if (major < 32 && movie->handlers[major] != NULL) minor = mvefile_get_next_segment_minor(movie->movie);
{ len = mvefile_get_next_segment_size(movie->movie);
minor = mvefile_get_next_segment_minor(movie->movie); data = mvefile_get_next_segment(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)) if (!movie->handlers[major](major, minor, data, len, movie->context))
return 0; return 0;
}
/* advance to next segment */
mvefile_advance_segment(movie->movie);
major = mvefile_get_next_segment_major(movie->movie);
} }
if (! mvefile_fetch_next_chunk(movie->movie)) /* advance to next segment */
return 0; mvefile_advance_segment(movie->movie);
major = mvefile_get_next_segment_major(movie->movie);
}
/* return status */ if (!mvefile_fetch_next_chunk(movie->movie))
return 1; return 0;
/* return status */
return 1;
} }
/************************************************************ /************************************************************
@ -307,57 +292,53 @@ int mve_play_next_chunk(MVESTREAM *movie)
/* /*
* allocate an MVEFILE * allocate an MVEFILE
*/ */
static MVEFILE *_mvefile_alloc(void) static MVEFILE *_mvefile_alloc(void) {
{ MVEFILE *file = (MVEFILE *)mve_alloc(sizeof(MVEFILE));
MVEFILE *file = (MVEFILE *)mve_alloc(sizeof(MVEFILE)); file->stream = NULL;
file->stream = NULL; file->cur_chunk = NULL;
file->cur_chunk = NULL; file->buf_size = 0;
file->buf_size = 0; file->cur_fill = 0;
file->cur_fill = 0; file->next_segment = 0;
file->next_segment = 0;
return file; return file;
} }
/* /*
* free an MVE file * free an MVE file
*/ */
static void _mvefile_free(MVEFILE *movie) static void _mvefile_free(MVEFILE *movie) {
{ /* free the stream */
/* free the stream */ movie->stream = NULL;
movie->stream = NULL;
/* free the buffer */ /* free the buffer */
if (movie->cur_chunk) if (movie->cur_chunk)
mve_free(movie->cur_chunk); mve_free(movie->cur_chunk);
movie->cur_chunk = NULL; movie->cur_chunk = NULL;
/* not strictly necessary */ /* not strictly necessary */
movie->buf_size = 0; movie->buf_size = 0;
movie->cur_fill = 0; movie->cur_fill = 0;
movie->next_segment = 0; movie->next_segment = 0;
/* free the struct */ /* free the struct */
mve_free(movie); mve_free(movie);
} }
/* /*
* open the file stream in thie object * open the file stream in thie object
*/ */
static int _mvefile_open(MVEFILE *file, void *stream) static int _mvefile_open(MVEFILE *file, void *stream) {
{ file->stream = stream;
file->stream = stream; if (!file->stream)
if (! file->stream) return 0;
return 0;
return 1; return 1;
} }
/* /*
* allocate an MVEFILE * allocate an MVEFILE
*/ */
static void _mvefile_reset(MVEFILE *file) static void _mvefile_reset(MVEFILE *file) {
{
#if 0 #if 0
file->cur_chunk = NULL; file->cur_chunk = NULL;
file->buf_size = 0; file->buf_size = 0;
@ -369,152 +350,140 @@ static void _mvefile_reset(MVEFILE *file)
/* /*
* read and verify the header of the recently opened file * read and verify the header of the recently opened file
*/ */
static int _mvefile_read_header(MVEFILE *movie) static int _mvefile_read_header(MVEFILE *movie) {
{ unsigned char buffer[26];
unsigned char buffer[26];
/* check the file is open */ /* check the file is open */
if (! movie->stream) if (!movie->stream)
return 0; return 0;
/* check the file is long enough */ /* check the file is long enough */
if (! mve_read(movie->stream, buffer, 26)) if (!mve_read(movie->stream, buffer, 26))
return 0; return 0;
/* check the signature */ /* check the signature */
if (memcmp(buffer, MVE_HEADER, 20)) if (memcmp(buffer, MVE_HEADER, 20))
return 0; return 0;
/* check the hard-coded constants */ /* check the hard-coded constants */
if (_mve_get_short(buffer+20) != MVE_HDRCONST1) if (_mve_get_short(buffer + 20) != MVE_HDRCONST1)
return 0; return 0;
if (_mve_get_short(buffer+22) != MVE_HDRCONST2) if (_mve_get_short(buffer + 22) != MVE_HDRCONST2)
return 0; return 0;
if (_mve_get_short(buffer+24) != MVE_HDRCONST3) if (_mve_get_short(buffer + 24) != MVE_HDRCONST3)
return 0; return 0;
return 1; return 1;
} }
static void _mvefile_set_buffer_size(MVEFILE *movie, int buf_size) static void _mvefile_set_buffer_size(MVEFILE *movie, int buf_size) {
{ unsigned char *new_buffer;
unsigned char *new_buffer; int new_len;
int new_len;
/* check if this would be a redundant operation */ /* check if this would be a redundant operation */
if (buf_size <= movie->buf_size) if (buf_size <= movie->buf_size)
return; return;
/* allocate new buffer */ /* allocate new buffer */
new_len = 100 + buf_size; new_len = 100 + buf_size;
new_buffer = (unsigned char *)mve_alloc(new_len); new_buffer = (unsigned char *)mve_alloc(new_len);
/* copy old data */ /* copy old data */
if (movie->cur_chunk && movie->cur_fill) if (movie->cur_chunk && movie->cur_fill)
memcpy(new_buffer, movie->cur_chunk, movie->cur_fill); memcpy(new_buffer, movie->cur_chunk, movie->cur_fill);
/* free old buffer */ /* free old buffer */
if (movie->cur_chunk) if (movie->cur_chunk) {
{ mve_free(movie->cur_chunk);
mve_free(movie->cur_chunk); movie->cur_chunk = 0;
movie->cur_chunk = 0; }
}
/* install new buffer */ /* install new buffer */
movie->cur_chunk = new_buffer; movie->cur_chunk = new_buffer;
movie->buf_size = new_len; movie->buf_size = new_len;
} }
static int _mvefile_fetch_next_chunk(MVEFILE *movie) static int _mvefile_fetch_next_chunk(MVEFILE *movie) {
{ unsigned char buffer[4];
unsigned char buffer[4]; unsigned short length;
unsigned short length;
/* fail if not open */ /* fail if not open */
if (! movie->stream) if (!movie->stream)
return 0; return 0;
/* fail if we can't read the next segment descriptor */ /* fail if we can't read the next segment descriptor */
if (! mve_read(movie->stream, buffer, 4)) if (!mve_read(movie->stream, buffer, 4))
return 0; return 0;
/* pull out the next length */ /* pull out the next length */
length = _mve_get_short(buffer); length = _mve_get_short(buffer);
/* make sure we've got sufficient space */ /* make sure we've got sufficient space */
_mvefile_set_buffer_size(movie, length); _mvefile_set_buffer_size(movie, length);
/* read the chunk */ /* read the chunk */
if (! mve_read(movie->stream, movie->cur_chunk, length)) if (!mve_read(movie->stream, movie->cur_chunk, length))
return 0; return 0;
movie->cur_fill = length; movie->cur_fill = length;
movie->next_segment = 0; movie->next_segment = 0;
return 1; return 1;
} }
static short _mve_get_short(unsigned char *data) static short _mve_get_short(unsigned char *data) {
{ short value;
short value; value = data[0] | (data[1] << 8);
value = data[0] | (data[1] << 8); return value;
return value;
} }
static unsigned short _mve_get_ushort(unsigned char *data) static unsigned short _mve_get_ushort(unsigned char *data) {
{ unsigned short value;
unsigned short value; value = data[0] | (data[1] << 8);
value = data[0] | (data[1] << 8); return value;
return value;
} }
/* /*
* allocate an MVESTREAM * allocate an MVESTREAM
*/ */
static MVESTREAM *_mvestream_alloc(void) static MVESTREAM *_mvestream_alloc(void) {
{ MVESTREAM *movie;
MVESTREAM *movie;
/* allocate and zero-initialize everything */ /* allocate and zero-initialize everything */
movie = (MVESTREAM *)mve_alloc(sizeof(MVESTREAM)); movie = (MVESTREAM *)mve_alloc(sizeof(MVESTREAM));
movie->movie = NULL; movie->movie = NULL;
movie->context = 0; movie->context = 0;
memset(movie->handlers, 0, sizeof(movie->handlers)); memset(movie->handlers, 0, sizeof(movie->handlers));
return movie; return movie;
} }
/* /*
* free an MVESTREAM * free an MVESTREAM
*/ */
static void _mvestream_free(MVESTREAM *movie) static void _mvestream_free(MVESTREAM *movie) {
{ /* close MVEFILE */
/* close MVEFILE */ if (movie->movie)
if (movie->movie) mvefile_close(movie->movie);
mvefile_close(movie->movie); movie->movie = NULL;
movie->movie = NULL;
/* clear context and handlers */ /* clear context and handlers */
movie->context = NULL; movie->context = NULL;
memset(movie->handlers, 0, sizeof(movie->handlers)); memset(movie->handlers, 0, sizeof(movie->handlers));
/* free the struct */ /* free the struct */
mve_free(movie); mve_free(movie);
} }
/* /*
* open an MVESTREAM object * open an MVESTREAM object
*/ */
static int _mvestream_open(MVESTREAM *movie, void *stream) static int _mvestream_open(MVESTREAM *movie, void *stream) {
{ movie->movie = mvefile_open(stream);
movie->movie = mvefile_open(stream);
return (movie->movie == NULL) ? 0 : 1; return (movie->movie == NULL) ? 0 : 1;
} }
/* /*
* reset an MVESTREAM * reset an MVESTREAM
*/ */
static void _mvestream_reset(MVESTREAM *movie) static void _mvestream_reset(MVESTREAM *movie) { mvefile_reset(movie->movie); }
{
mvefile_reset(movie->movie);
}

View File

@ -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 #ifndef INCLUDED_MVELIB_H
#define 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 * structure for maintaining info on a MVEFILE stream
*/ */
typedef struct MVEFILE typedef struct MVEFILE {
{ void *stream;
void *stream; unsigned char *cur_chunk;
unsigned char *cur_chunk; int buf_size;
int buf_size; int cur_fill;
int cur_fill; int next_segment;
int next_segment;
} MVEFILE; } MVEFILE;
/* /*
@ -73,11 +89,10 @@ typedef int (*MVESEGMENTHANDLER)(unsigned char major, unsigned char minor, unsig
/* /*
* structure for maintaining an MVE stream * structure for maintaining an MVE stream
*/ */
typedef struct MVESTREAM typedef struct MVESTREAM {
{ MVEFILE *movie;
MVEFILE *movie; void *context;
void *context; MVESEGMENTHANDLER handlers[32];
MVESEGMENTHANDLER handlers[32];
} MVESTREAM; } MVESTREAM;
/* /*

File diff suppressed because it is too large Load Diff