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
|
||||
>
|
||||
)
|
||||
|
@ -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/>.
|
||||
*/
|
||||
|
||||
/* 16 bit decoding routines */
|
||||
|
||||
#include <stdio.h>
|
||||
@ -9,11 +26,11 @@
|
||||
static unsigned short *backBuf1, *backBuf2;
|
||||
static int lookup_initialized;
|
||||
|
||||
static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, unsigned char **pData, unsigned char **pOffData, int *pDataRemain, int *curXb, int *curYb);
|
||||
static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, unsigned char **pData,
|
||||
unsigned char **pOffData, int *pDataRemain, int *curXb, int *curYb);
|
||||
static void genLoopkupTable(void);
|
||||
|
||||
void decodeFrame16(unsigned char *pFrame, unsigned char *pMap, int mapRemain, unsigned char *pData, int dataRemain)
|
||||
{
|
||||
void decodeFrame16(unsigned char *pFrame, unsigned char *pMap, int mapRemain, unsigned char *pData, int dataRemain) {
|
||||
unsigned char *pOrig;
|
||||
unsigned char *pOffData, *pEnd;
|
||||
unsigned short offset;
|
||||
@ -33,7 +50,7 @@ void decodeFrame16(unsigned char *pFrame, unsigned char *pMap, int mapRemain, un
|
||||
xb = g_width >> 3;
|
||||
yb = g_height >> 3;
|
||||
|
||||
offset = pData[0]|(pData[1]<<8);
|
||||
offset = pData[0] | (pData[1] << 8);
|
||||
|
||||
pOffData = pData + offset;
|
||||
pEnd = pData + offset;
|
||||
@ -43,18 +60,16 @@ void decodeFrame16(unsigned char *pFrame, unsigned char *pMap, int mapRemain, un
|
||||
pOrig = pData;
|
||||
length = offset - 2; /*dataRemain-2;*/
|
||||
|
||||
for (j=0; j<yb; j++)
|
||||
{
|
||||
for (i=0; i<xb/2; i++)
|
||||
{
|
||||
for (j = 0; j < yb; j++) {
|
||||
for (i = 0; i < xb / 2; i++) {
|
||||
op = (*pMap) & 0xf;
|
||||
dispatchDecoder16(&FramePtr, op, &pData, &pOffData, &dataRemain, &i, &j);
|
||||
|
||||
/*
|
||||
if (FramePtr < backBuf1)
|
||||
fprintf(stderr, "danger! pointing out of bounds below after dispatch decoder: %d, %d (1) [%x]\n", i, j, (*pMap) & 0xf);
|
||||
else if (FramePtr >= backBuf1 + g_width*g_height)
|
||||
fprintf(stderr, "danger! pointing out of bounds above after dispatch decoder: %d, %d (1) [%x]\n", i, j, (*pMap) & 0xf);
|
||||
fprintf(stderr, "danger! pointing out of bounds below after dispatch decoder: %d, %d (1) [%x]\n", i, j, (*pMap)
|
||||
& 0xf); else if (FramePtr >= backBuf1 + g_width*g_height) fprintf(stderr, "danger! pointing out of bounds above
|
||||
after dispatch decoder: %d, %d (1) [%x]\n", i, j, (*pMap) & 0xf);
|
||||
*/
|
||||
|
||||
op = ((*pMap) >> 4) & 0xf;
|
||||
@ -62,37 +77,34 @@ void decodeFrame16(unsigned char *pFrame, unsigned char *pMap, int mapRemain, un
|
||||
|
||||
/*
|
||||
if (FramePtr < backBuf1)
|
||||
fprintf(stderr, "danger! pointing out of bounds below after dispatch decoder: %d, %d (2) [%x]\n", i, j, (*pMap) >> 4);
|
||||
else if (FramePtr >= backBuf1 + g_width*g_height)
|
||||
fprintf(stderr, "danger! pointing out of bounds above after dispatch decoder: %d, %d (2) [%x]\n", i, j, (*pMap) >> 4);
|
||||
fprintf(stderr, "danger! pointing out of bounds below after dispatch decoder: %d, %d (2) [%x]\n", i, j, (*pMap)
|
||||
>> 4); else if (FramePtr >= backBuf1 + g_width*g_height) fprintf(stderr, "danger! pointing out of bounds above
|
||||
after dispatch decoder: %d, %d (2) [%x]\n", i, j, (*pMap) >> 4);
|
||||
*/
|
||||
|
||||
++pMap;
|
||||
--mapRemain;
|
||||
}
|
||||
|
||||
FramePtr += 7*g_width;
|
||||
FramePtr += 7 * g_width;
|
||||
}
|
||||
|
||||
if ( (length - (pData - pOrig)) != 0 )
|
||||
fprintf(stderr, "DEBUG: junk left over: %d,%d,%d\n", (int)(pData-pOrig), length, (int)(length-(pData-pOrig)));
|
||||
if ((length - (pData - pOrig)) != 0)
|
||||
fprintf(stderr, "DEBUG: junk left over: %d,%d,%d\n", (int)(pData - pOrig), length, (int)(length - (pData - pOrig)));
|
||||
}
|
||||
|
||||
static unsigned short GETPIXEL(unsigned char **buf, int off)
|
||||
{
|
||||
unsigned short val = (*buf)[0+off] | ((*buf)[1+off] << 8);
|
||||
static unsigned short GETPIXEL(unsigned char **buf, int off) {
|
||||
unsigned short val = (*buf)[0 + off] | ((*buf)[1 + off] << 8);
|
||||
return val;
|
||||
}
|
||||
|
||||
static unsigned short GETPIXELI(unsigned char **buf, int off)
|
||||
{
|
||||
unsigned short val = (*buf)[0+off] | ((*buf)[1+off] << 8);
|
||||
static unsigned short GETPIXELI(unsigned char **buf, int off) {
|
||||
unsigned short val = (*buf)[0 + off] | ((*buf)[1 + off] << 8);
|
||||
(*buf) += 2;
|
||||
return val;
|
||||
}
|
||||
|
||||
static void relClose(int i, int *x, int *y)
|
||||
{
|
||||
static void relClose(int i, int *x, int *y) {
|
||||
int ma, mi;
|
||||
|
||||
ma = i >> 4;
|
||||
@ -102,15 +114,11 @@ static void relClose(int i, int *x, int *y)
|
||||
*y = ma - 8;
|
||||
}
|
||||
|
||||
static void relFar(int i, int sign, int *x, int *y)
|
||||
{
|
||||
if (i < 56)
|
||||
{
|
||||
static void relFar(int i, int sign, int *x, int *y) {
|
||||
if (i < 56) {
|
||||
*x = sign * (8 + (i % 7));
|
||||
*y = sign * (i / 7);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
*x = sign * (-14 + (i - 56) % 29);
|
||||
*y = sign * (8 + (i - 56) / 29);
|
||||
}
|
||||
@ -120,65 +128,55 @@ static int close_table[512];
|
||||
static int far_p_table[512];
|
||||
static int far_n_table[512];
|
||||
|
||||
static void genLoopkupTable()
|
||||
{
|
||||
static void genLoopkupTable() {
|
||||
int i;
|
||||
int x, y;
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
relClose(i, &x, &y);
|
||||
|
||||
close_table[i*2+0] = x;
|
||||
close_table[i*2+1] = y;
|
||||
close_table[i * 2 + 0] = x;
|
||||
close_table[i * 2 + 1] = y;
|
||||
|
||||
relFar(i, 1, &x, &y);
|
||||
|
||||
far_p_table[i*2+0] = x;
|
||||
far_p_table[i*2+1] = y;
|
||||
far_p_table[i * 2 + 0] = x;
|
||||
far_p_table[i * 2 + 1] = y;
|
||||
|
||||
relFar(i, -1, &x, &y);
|
||||
|
||||
far_n_table[i*2+0] = x;
|
||||
far_n_table[i*2+1] = y;
|
||||
far_n_table[i * 2 + 0] = x;
|
||||
far_n_table[i * 2 + 1] = y;
|
||||
}
|
||||
|
||||
lookup_initialized = 1;
|
||||
}
|
||||
|
||||
static void copyFrame(unsigned short *pDest, unsigned short *pSrc)
|
||||
{
|
||||
static void copyFrame(unsigned short *pDest, unsigned short *pSrc) {
|
||||
int i;
|
||||
|
||||
for (i=0; i<8; i++)
|
||||
{
|
||||
for (i = 0; i < 8; i++) {
|
||||
memcpy(pDest, pSrc, 16);
|
||||
pDest += g_width;
|
||||
pSrc += g_width;
|
||||
}
|
||||
}
|
||||
|
||||
static void patternRow4Pixels(unsigned short *pFrame,
|
||||
unsigned char pat0, unsigned char pat1,
|
||||
unsigned short *p)
|
||||
{
|
||||
unsigned short mask=0x0003;
|
||||
unsigned short shift=0;
|
||||
static void patternRow4Pixels(unsigned short *pFrame, unsigned char pat0, unsigned char pat1, unsigned short *p) {
|
||||
unsigned short mask = 0x0003;
|
||||
unsigned short shift = 0;
|
||||
unsigned short pattern = (pat1 << 8) | pat0;
|
||||
|
||||
while (mask != 0)
|
||||
{
|
||||
while (mask != 0) {
|
||||
*pFrame++ = p[(mask & pattern) >> shift];
|
||||
mask <<= 2;
|
||||
shift += 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void patternRow4Pixels2(unsigned short *pFrame,
|
||||
unsigned char pat0,
|
||||
unsigned short *p)
|
||||
{
|
||||
unsigned char mask=0x03;
|
||||
unsigned char shift=0;
|
||||
static void patternRow4Pixels2(unsigned short *pFrame, unsigned char pat0, unsigned short *p) {
|
||||
unsigned char mask = 0x03;
|
||||
unsigned char shift = 0;
|
||||
unsigned short pel;
|
||||
/* ORIGINAL VERSION IS BUGGY
|
||||
int skip=1;
|
||||
@ -196,8 +194,7 @@ static void patternRow4Pixels2(unsigned short *pFrame,
|
||||
shift += 2;
|
||||
}
|
||||
*/
|
||||
while (mask != 0)
|
||||
{
|
||||
while (mask != 0) {
|
||||
pel = p[(mask & pat0) >> shift];
|
||||
pFrame[0] = pel;
|
||||
pFrame[1] = pel;
|
||||
@ -209,15 +206,12 @@ static void patternRow4Pixels2(unsigned short *pFrame,
|
||||
}
|
||||
}
|
||||
|
||||
static void patternRow4Pixels2x1(unsigned short *pFrame, unsigned char pat,
|
||||
unsigned short *p)
|
||||
{
|
||||
unsigned char mask=0x03;
|
||||
unsigned char shift=0;
|
||||
static void patternRow4Pixels2x1(unsigned short *pFrame, unsigned char pat, unsigned short *p) {
|
||||
unsigned char mask = 0x03;
|
||||
unsigned char shift = 0;
|
||||
unsigned short pel;
|
||||
|
||||
while (mask != 0)
|
||||
{
|
||||
while (mask != 0) {
|
||||
pel = p[(mask & pat) >> shift];
|
||||
pFrame[0] = pel;
|
||||
pFrame[1] = pel;
|
||||
@ -227,20 +221,17 @@ static void patternRow4Pixels2x1(unsigned short *pFrame, unsigned char pat,
|
||||
}
|
||||
}
|
||||
|
||||
static void patternQuadrant4Pixels(unsigned short *pFrame,
|
||||
unsigned char pat0, unsigned char pat1, unsigned char pat2,
|
||||
unsigned char pat3, unsigned short *p)
|
||||
{
|
||||
static void patternQuadrant4Pixels(unsigned short *pFrame, unsigned char pat0, unsigned char pat1, unsigned char pat2,
|
||||
unsigned char pat3, unsigned short *p) {
|
||||
unsigned long mask = 0x00000003UL;
|
||||
int shift=0;
|
||||
int shift = 0;
|
||||
int i;
|
||||
unsigned long pat = (pat3 << 24) | (pat2 << 16) | (pat1 << 8) | pat0;
|
||||
|
||||
for (i=0; i<16; i++)
|
||||
{
|
||||
pFrame[i&3] = p[(pat & mask) >> shift];
|
||||
for (i = 0; i < 16; i++) {
|
||||
pFrame[i & 3] = p[(pat & mask) >> shift];
|
||||
|
||||
if ((i&3) == 3)
|
||||
if ((i & 3) == 3)
|
||||
pFrame += g_width;
|
||||
|
||||
mask <<= 2;
|
||||
@ -248,24 +239,18 @@ static void patternQuadrant4Pixels(unsigned short *pFrame,
|
||||
}
|
||||
}
|
||||
|
||||
static void patternRow2Pixels(unsigned short *pFrame, unsigned char pat, unsigned short *p) {
|
||||
unsigned char mask = 0x01;
|
||||
|
||||
static void patternRow2Pixels(unsigned short *pFrame, unsigned char pat,
|
||||
unsigned short *p)
|
||||
{
|
||||
unsigned char mask=0x01;
|
||||
|
||||
while (mask != 0)
|
||||
{
|
||||
while (mask != 0) {
|
||||
*pFrame++ = p[(mask & pat) ? 1 : 0];
|
||||
mask <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void patternRow2Pixels2(unsigned short *pFrame, unsigned char pat,
|
||||
unsigned short *p)
|
||||
{
|
||||
static void patternRow2Pixels2(unsigned short *pFrame, unsigned char pat, unsigned short *p) {
|
||||
unsigned short pel;
|
||||
unsigned char mask=0x1;
|
||||
unsigned char mask = 0x1;
|
||||
|
||||
/* ORIGINAL VERSION IS BUGGY
|
||||
int skip=1;
|
||||
@ -294,26 +279,23 @@ static void patternRow2Pixels2(unsigned short *pFrame, unsigned char pat,
|
||||
}
|
||||
}
|
||||
|
||||
static void patternQuadrant2Pixels(unsigned short *pFrame, unsigned char pat0,
|
||||
unsigned char pat1, unsigned short *p)
|
||||
{
|
||||
static void patternQuadrant2Pixels(unsigned short *pFrame, unsigned char pat0, unsigned char pat1, unsigned short *p) {
|
||||
unsigned short mask = 0x0001;
|
||||
int i;
|
||||
unsigned short pat = (pat1 << 8) | pat0;
|
||||
|
||||
for (i=0; i<16; i++)
|
||||
{
|
||||
pFrame[i&3] = p[(pat & mask) ? 1 : 0];
|
||||
for (i = 0; i < 16; i++) {
|
||||
pFrame[i & 3] = p[(pat & mask) ? 1 : 0];
|
||||
|
||||
if ((i&3) == 3)
|
||||
if ((i & 3) == 3)
|
||||
pFrame += g_width;
|
||||
|
||||
mask <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, unsigned char **pData, unsigned char **pOffData, int *pDataRemain, int *curXb, int *curYb)
|
||||
{
|
||||
static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, unsigned char **pData,
|
||||
unsigned char **pOffData, int *pDataRemain, int *curXb, int *curYb) {
|
||||
unsigned short p[4];
|
||||
unsigned char pat[16];
|
||||
int i, j, k;
|
||||
@ -322,8 +304,7 @@ static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, u
|
||||
|
||||
pDstBak = *pFrame;
|
||||
|
||||
switch(codeType)
|
||||
{
|
||||
switch (codeType) {
|
||||
case 0x0:
|
||||
copyFrame(*pFrame, *pFrame + (backBuf2 - backBuf1));
|
||||
case 0x1:
|
||||
@ -333,10 +314,10 @@ static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, u
|
||||
*/
|
||||
|
||||
k = *(*pOffData)++;
|
||||
x = far_p_table[k*2+0];
|
||||
y = far_p_table[k*2+1];
|
||||
x = far_p_table[k * 2 + 0];
|
||||
y = far_p_table[k * 2 + 1];
|
||||
|
||||
copyFrame(*pFrame, *pFrame + x + y*g_width);
|
||||
copyFrame(*pFrame, *pFrame + x + y * g_width);
|
||||
--*pDataRemain;
|
||||
break;
|
||||
case 0x3: /*
|
||||
@ -344,10 +325,10 @@ static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, u
|
||||
*/
|
||||
|
||||
k = *(*pOffData)++;
|
||||
x = far_n_table[k*2+0];
|
||||
y = far_n_table[k*2+1];
|
||||
x = far_n_table[k * 2 + 0];
|
||||
y = far_n_table[k * 2 + 1];
|
||||
|
||||
copyFrame(*pFrame, *pFrame + x + y*g_width);
|
||||
copyFrame(*pFrame, *pFrame + x + y * g_width);
|
||||
--*pDataRemain;
|
||||
break;
|
||||
case 0x4: /*
|
||||
@ -355,26 +336,24 @@ static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, u
|
||||
*/
|
||||
|
||||
k = *(*pOffData)++;
|
||||
x = close_table[k*2+0];
|
||||
y = close_table[k*2+1];
|
||||
x = close_table[k * 2 + 0];
|
||||
y = close_table[k * 2 + 1];
|
||||
|
||||
copyFrame(*pFrame, *pFrame + (backBuf2 - backBuf1) + x + y*g_width);
|
||||
copyFrame(*pFrame, *pFrame + (backBuf2 - backBuf1) + x + y * g_width);
|
||||
--*pDataRemain;
|
||||
break;
|
||||
case 0x5:
|
||||
x = (char)*(*pData)++;
|
||||
y = (char)*(*pData)++;
|
||||
copyFrame(*pFrame, *pFrame + (backBuf2 - backBuf1) + x + y*g_width);
|
||||
copyFrame(*pFrame, *pFrame + (backBuf2 - backBuf1) + x + y * g_width);
|
||||
*pDataRemain -= 2;
|
||||
break;
|
||||
case 0x6:
|
||||
fprintf(stderr, "STUB: encoding 6 not tested\n");
|
||||
for (i=0; i<2; i++)
|
||||
{
|
||||
for (i = 0; i < 2; i++) {
|
||||
*pFrame += 16;
|
||||
if (++*curXb == (g_width >> 3))
|
||||
{
|
||||
*pFrame += 7*g_width;
|
||||
if (++*curXb == (g_width >> 3)) {
|
||||
*pFrame += 7 * g_width;
|
||||
*curXb = 0;
|
||||
if (++*curYb == (g_height >> 3))
|
||||
return;
|
||||
@ -386,26 +365,21 @@ static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, u
|
||||
p[0] = GETPIXELI(pData, 0);
|
||||
p[1] = GETPIXELI(pData, 0);
|
||||
|
||||
if (!((p[0]/*|p[1]*/)&0x8000))
|
||||
{
|
||||
for (i=0; i<8; i++)
|
||||
{
|
||||
if (!((p[0] /*|p[1]*/) & 0x8000)) {
|
||||
for (i = 0; i < 8; i++) {
|
||||
patternRow2Pixels(*pFrame, *(*pData), p);
|
||||
(*pData)++;
|
||||
|
||||
*pFrame += g_width;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=0; i<2; i++)
|
||||
{
|
||||
} else {
|
||||
for (i = 0; i < 2; i++) {
|
||||
patternRow2Pixels2(*pFrame, *(*pData) & 0xf, p);
|
||||
*pFrame += 2*g_width;
|
||||
*pFrame += 2 * g_width;
|
||||
patternRow2Pixels2(*pFrame, *(*pData) >> 4, p);
|
||||
(*pData)++;
|
||||
|
||||
*pFrame += 2*g_width;
|
||||
*pFrame += 2 * g_width;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -413,10 +387,8 @@ static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, u
|
||||
case 0x8:
|
||||
p[0] = GETPIXEL(pData, 0);
|
||||
|
||||
if (!(p[0] & 0x8000))
|
||||
{
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
if (!(p[0] & 0x8000)) {
|
||||
for (i = 0; i < 4; i++) {
|
||||
p[0] = GETPIXELI(pData, 0);
|
||||
p[1] = GETPIXELI(pData, 0);
|
||||
|
||||
@ -427,20 +399,17 @@ static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, u
|
||||
patternQuadrant2Pixels(*pFrame, pat[0], pat[1], p);
|
||||
|
||||
if (i & 1)
|
||||
*pFrame -= (4*g_width - 4);
|
||||
*pFrame -= (4 * g_width - 4);
|
||||
else
|
||||
*pFrame += 4*g_width;
|
||||
*pFrame += 4 * g_width;
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
p[2] = GETPIXEL(pData, 8);
|
||||
|
||||
if (!(p[2]&0x8000)) {
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
if ((i & 1) == 0)
|
||||
{
|
||||
if (!(p[2] & 0x8000)) {
|
||||
for (i = 0; i < 4; i++) {
|
||||
if ((i & 1) == 0) {
|
||||
p[0] = GETPIXELI(pData, 0);
|
||||
p[1] = GETPIXELI(pData, 0);
|
||||
}
|
||||
@ -449,15 +418,13 @@ static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, u
|
||||
patternQuadrant2Pixels(*pFrame, pat[0], pat[1], p);
|
||||
|
||||
if (i & 1)
|
||||
*pFrame -= (4*g_width - 4);
|
||||
*pFrame -= (4 * g_width - 4);
|
||||
else
|
||||
*pFrame += 4*g_width;
|
||||
*pFrame += 4 * g_width;
|
||||
}
|
||||
} else {
|
||||
for (i=0; i<8; i++)
|
||||
{
|
||||
if ((i & 3) == 0)
|
||||
{
|
||||
for (i = 0; i < 8; i++) {
|
||||
if ((i & 3) == 0) {
|
||||
p[0] = GETPIXELI(pData, 0);
|
||||
p[1] = GETPIXELI(pData, 0);
|
||||
}
|
||||
@ -478,13 +445,10 @@ static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, u
|
||||
|
||||
*pDataRemain -= 8;
|
||||
|
||||
if (!(p[0] & 0x8000))
|
||||
{
|
||||
if (!(p[2] & 0x8000))
|
||||
{
|
||||
if (!(p[0] & 0x8000)) {
|
||||
if (!(p[2] & 0x8000)) {
|
||||
|
||||
for (i=0; i<8; i++)
|
||||
{
|
||||
for (i = 0; i < 8; i++) {
|
||||
pat[0] = (*pData)[0];
|
||||
pat[1] = (*pData)[1];
|
||||
(*pData) += 2;
|
||||
@ -493,39 +457,29 @@ static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, u
|
||||
}
|
||||
*pDataRemain -= 16;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
patternRow4Pixels2(*pFrame, (*pData)[0], p);
|
||||
*pFrame += 2*g_width;
|
||||
*pFrame += 2 * g_width;
|
||||
patternRow4Pixels2(*pFrame, (*pData)[1], p);
|
||||
*pFrame += 2*g_width;
|
||||
*pFrame += 2 * g_width;
|
||||
patternRow4Pixels2(*pFrame, (*pData)[2], p);
|
||||
*pFrame += 2*g_width;
|
||||
*pFrame += 2 * g_width;
|
||||
patternRow4Pixels2(*pFrame, (*pData)[3], p);
|
||||
|
||||
(*pData) += 4;
|
||||
*pDataRemain -= 4;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(p[2] & 0x8000))
|
||||
{
|
||||
for (i=0; i<8; i++)
|
||||
{
|
||||
} else {
|
||||
if (!(p[2] & 0x8000)) {
|
||||
for (i = 0; i < 8; i++) {
|
||||
pat[0] = (*pData)[0];
|
||||
(*pData) += 1;
|
||||
patternRow4Pixels2x1(*pFrame, pat[0], p);
|
||||
*pFrame += g_width;
|
||||
}
|
||||
*pDataRemain -= 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
} else {
|
||||
for (i = 0; i < 4; i++) {
|
||||
pat[0] = (*pData)[0];
|
||||
pat[1] = (*pData)[1];
|
||||
|
||||
@ -544,10 +498,8 @@ static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, u
|
||||
case 0xa:
|
||||
p[0] = GETPIXEL(pData, 0);
|
||||
|
||||
if (!(p[0] & 0x8000))
|
||||
{
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
if (!(p[0] & 0x8000)) {
|
||||
for (i = 0; i < 4; i++) {
|
||||
p[0] = GETPIXELI(pData, 0);
|
||||
p[1] = GETPIXELI(pData, 0);
|
||||
p[2] = GETPIXELI(pData, 0);
|
||||
@ -562,21 +514,16 @@ static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, u
|
||||
patternQuadrant4Pixels(*pFrame, pat[0], pat[1], pat[2], pat[3], p);
|
||||
|
||||
if (i & 1)
|
||||
*pFrame -= (4*g_width - 4);
|
||||
*pFrame -= (4 * g_width - 4);
|
||||
else
|
||||
*pFrame += 4*g_width;
|
||||
*pFrame += 4 * g_width;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
p[0] = GETPIXEL(pData, 16);
|
||||
|
||||
if (!(p[0] & 0x8000))
|
||||
{
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
if ((i&1) == 0)
|
||||
{
|
||||
if (!(p[0] & 0x8000)) {
|
||||
for (i = 0; i < 4; i++) {
|
||||
if ((i & 1) == 0) {
|
||||
p[0] = GETPIXELI(pData, 0);
|
||||
p[1] = GETPIXELI(pData, 0);
|
||||
p[2] = GETPIXELI(pData, 0);
|
||||
@ -593,17 +540,13 @@ static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, u
|
||||
patternQuadrant4Pixels(*pFrame, pat[0], pat[1], pat[2], pat[3], p);
|
||||
|
||||
if (i & 1)
|
||||
*pFrame -= (4*g_width - 4);
|
||||
*pFrame -= (4 * g_width - 4);
|
||||
else
|
||||
*pFrame += 4*g_width;
|
||||
*pFrame += 4 * g_width;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=0; i<8; i++)
|
||||
{
|
||||
if ((i&3) == 0)
|
||||
{
|
||||
} else {
|
||||
for (i = 0; i < 8; i++) {
|
||||
if ((i & 3) == 0) {
|
||||
p[0] = GETPIXELI(pData, 0);
|
||||
p[1] = GETPIXELI(pData, 0);
|
||||
p[2] = GETPIXELI(pData, 0);
|
||||
@ -622,8 +565,7 @@ static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, u
|
||||
break;
|
||||
|
||||
case 0xb:
|
||||
for (i=0; i<8; i++)
|
||||
{
|
||||
for (i = 0; i < 8; i++) {
|
||||
memcpy(*pFrame, *pData, 16);
|
||||
*pFrame += g_width;
|
||||
*pData += 16;
|
||||
@ -632,19 +574,16 @@ static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, u
|
||||
break;
|
||||
|
||||
case 0xc:
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
for (i = 0; i < 4; i++) {
|
||||
p[0] = GETPIXEL(pData, 0);
|
||||
p[1] = GETPIXEL(pData, 2);
|
||||
p[2] = GETPIXEL(pData, 4);
|
||||
p[3] = GETPIXEL(pData, 6);
|
||||
|
||||
for (j=0; j<2; j++)
|
||||
{
|
||||
for (k=0; k<4; k++)
|
||||
{
|
||||
(*pFrame)[j+2*k] = p[k];
|
||||
(*pFrame)[g_width+j+2*k] = p[k];
|
||||
for (j = 0; j < 2; j++) {
|
||||
for (k = 0; k < 4; k++) {
|
||||
(*pFrame)[j + 2 * k] = p[k];
|
||||
(*pFrame)[g_width + j + 2 * k] = p[k];
|
||||
}
|
||||
*pFrame += g_width;
|
||||
}
|
||||
@ -654,21 +593,18 @@ static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, u
|
||||
break;
|
||||
|
||||
case 0xd:
|
||||
for (i=0; i<2; i++)
|
||||
{
|
||||
for (i = 0; i < 2; i++) {
|
||||
p[0] = GETPIXEL(pData, 0);
|
||||
p[1] = GETPIXEL(pData, 2);
|
||||
|
||||
for (j=0; j<4; j++)
|
||||
{
|
||||
for (k=0; k<4; k++)
|
||||
{
|
||||
(*pFrame)[k*g_width+j] = p[0];
|
||||
(*pFrame)[k*g_width+j+4] = p[1];
|
||||
for (j = 0; j < 4; j++) {
|
||||
for (k = 0; k < 4; k++) {
|
||||
(*pFrame)[k * g_width + j] = p[0];
|
||||
(*pFrame)[k * g_width + j + 4] = p[1];
|
||||
}
|
||||
}
|
||||
|
||||
*pFrame += 4*g_width;
|
||||
*pFrame += 4 * g_width;
|
||||
|
||||
*pData += 4;
|
||||
*pDataRemain -= 4;
|
||||
@ -695,11 +631,9 @@ static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, u
|
||||
p[0] = GETPIXEL(pData, 0);
|
||||
p[1] = GETPIXEL(pData, 1);
|
||||
|
||||
for (i=0; i<8; i++)
|
||||
{
|
||||
for (j=0; j<8; j++)
|
||||
{
|
||||
(*pFrame)[j] = p[(i+j)&1];
|
||||
for (i = 0; i < 8; i++) {
|
||||
for (j = 0; j < 8; j++) {
|
||||
(*pFrame)[j] = p[(i + j) & 1];
|
||||
}
|
||||
*pFrame += g_width;
|
||||
}
|
||||
@ -712,5 +646,5 @@ static void dispatchDecoder16(unsigned short **pFrame, unsigned char codeType, u
|
||||
break;
|
||||
}
|
||||
|
||||
*pFrame = pDstBak+8;
|
||||
*pFrame = pDstBak + 8;
|
||||
}
|
||||
|
@ -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/>.
|
||||
*/
|
||||
|
||||
/* 8 bit decoding routines */
|
||||
|
||||
#include <stdio.h>
|
||||
@ -5,40 +22,41 @@
|
||||
|
||||
#include "decoders.h"
|
||||
|
||||
static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsigned char **pData, int *pDataRemain, int *curXb, int *curYb);
|
||||
static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsigned char **pData, int *pDataRemain,
|
||||
int *curXb, int *curYb);
|
||||
|
||||
void decodeFrame8(unsigned char *pFrame, unsigned char *pMap, int mapRemain, unsigned char *pData, int dataRemain)
|
||||
{
|
||||
void decodeFrame8(unsigned char *pFrame, unsigned char *pMap, int mapRemain, unsigned char *pData, int dataRemain) {
|
||||
int i, j;
|
||||
int xb, yb;
|
||||
|
||||
xb = g_width >> 3;
|
||||
yb = g_height >> 3;
|
||||
for (j=0; j<yb; j++)
|
||||
{
|
||||
for (i=0; i<xb/2; i++)
|
||||
{
|
||||
for (j = 0; j < yb; j++) {
|
||||
for (i = 0; i < xb / 2; i++) {
|
||||
dispatchDecoder(&pFrame, (*pMap) & 0xf, &pData, &dataRemain, &i, &j);
|
||||
if (pFrame < (unsigned char *)g_vBackBuf1)
|
||||
fprintf(stderr, "danger! pointing out of bounds below after dispatch decoder: %d, %d (1) [%x]\n", i, j, (*pMap) & 0xf);
|
||||
else if (pFrame >= ((unsigned char *)g_vBackBuf1) + g_width*g_height)
|
||||
fprintf(stderr, "danger! pointing out of bounds above after dispatch decoder: %d, %d (1) [%x]\n", i, j, (*pMap) & 0xf);
|
||||
fprintf(stderr, "danger! pointing out of bounds below after dispatch decoder: %d, %d (1) [%x]\n", i, j,
|
||||
(*pMap) & 0xf);
|
||||
else if (pFrame >= ((unsigned char *)g_vBackBuf1) + g_width * g_height)
|
||||
fprintf(stderr, "danger! pointing out of bounds above after dispatch decoder: %d, %d (1) [%x]\n", i, j,
|
||||
(*pMap) & 0xf);
|
||||
dispatchDecoder(&pFrame, (*pMap) >> 4, &pData, &dataRemain, &i, &j);
|
||||
if (pFrame < (unsigned char *)g_vBackBuf1)
|
||||
fprintf(stderr, "danger! pointing out of bounds below after dispatch decoder: %d, %d (2) [%x]\n", i, j, (*pMap) >> 4);
|
||||
else if (pFrame >= ((unsigned char *)g_vBackBuf1) + g_width*g_height)
|
||||
fprintf(stderr, "danger! pointing out of bounds above after dispatch decoder: %d, %d (2) [%x]\n", i, j, (*pMap) >> 4);
|
||||
fprintf(stderr, "danger! pointing out of bounds below after dispatch decoder: %d, %d (2) [%x]\n", i, j,
|
||||
(*pMap) >> 4);
|
||||
else if (pFrame >= ((unsigned char *)g_vBackBuf1) + g_width * g_height)
|
||||
fprintf(stderr, "danger! pointing out of bounds above after dispatch decoder: %d, %d (2) [%x]\n", i, j,
|
||||
(*pMap) >> 4);
|
||||
|
||||
++pMap;
|
||||
--mapRemain;
|
||||
}
|
||||
|
||||
pFrame += 7*g_width;
|
||||
pFrame += 7 * g_width;
|
||||
}
|
||||
}
|
||||
|
||||
static void relClose(int i, int *x, int *y)
|
||||
{
|
||||
static void relClose(int i, int *x, int *y) {
|
||||
int ma, mi;
|
||||
|
||||
ma = i >> 4;
|
||||
@ -48,15 +66,11 @@ static void relClose(int i, int *x, int *y)
|
||||
*y = ma - 8;
|
||||
}
|
||||
|
||||
static void relFar(int i, int sign, int *x, int *y)
|
||||
{
|
||||
if (i < 56)
|
||||
{
|
||||
static void relFar(int i, int sign, int *x, int *y) {
|
||||
if (i < 56) {
|
||||
*x = sign * (8 + (i % 7));
|
||||
*y = sign * (i / 7);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
*x = sign * (-14 + (i - 56) % 29);
|
||||
*y = sign * (8 + (i - 56) / 29);
|
||||
}
|
||||
@ -64,12 +78,10 @@ static void relFar(int i, int sign, int *x, int *y)
|
||||
|
||||
/* copies an 8x8 block from pSrc to pDest.
|
||||
pDest and pSrc are both g_width bytes wide */
|
||||
static void copyFrame(unsigned char *pDest, unsigned char *pSrc)
|
||||
{
|
||||
static void copyFrame(unsigned char *pDest, unsigned char *pSrc) {
|
||||
int i;
|
||||
|
||||
for (i=0; i<8; i++)
|
||||
{
|
||||
for (i = 0; i < 8; i++) {
|
||||
memcpy(pDest, pSrc, 8);
|
||||
pDest += g_width;
|
||||
pSrc += g_width;
|
||||
@ -78,16 +90,12 @@ static void copyFrame(unsigned char *pDest, unsigned char *pSrc)
|
||||
|
||||
// Fill in the next eight bytes with p[0], p[1], p[2], or p[3],
|
||||
// depending on the corresponding two-bit value in pat0 and pat1
|
||||
static void patternRow4Pixels(unsigned char *pFrame,
|
||||
unsigned char pat0, unsigned char pat1,
|
||||
unsigned char *p)
|
||||
{
|
||||
unsigned short mask=0x0003;
|
||||
unsigned short shift=0;
|
||||
static void patternRow4Pixels(unsigned char *pFrame, unsigned char pat0, unsigned char pat1, unsigned char *p) {
|
||||
unsigned short mask = 0x0003;
|
||||
unsigned short shift = 0;
|
||||
unsigned short pattern = (pat1 << 8) | pat0;
|
||||
|
||||
while (mask != 0)
|
||||
{
|
||||
while (mask != 0) {
|
||||
*pFrame++ = p[(mask & pattern) >> shift];
|
||||
mask <<= 2;
|
||||
shift += 2;
|
||||
@ -96,16 +104,12 @@ static void patternRow4Pixels(unsigned char *pFrame,
|
||||
|
||||
// Fill in the next four 2x2 pixel blocks with p[0], p[1], p[2], or p[3],
|
||||
// depending on the corresponding two-bit value in pat0.
|
||||
static void patternRow4Pixels2(unsigned char *pFrame,
|
||||
unsigned char pat0,
|
||||
unsigned char *p)
|
||||
{
|
||||
unsigned char mask=0x03;
|
||||
unsigned char shift=0;
|
||||
static void patternRow4Pixels2(unsigned char *pFrame, unsigned char pat0, unsigned char *p) {
|
||||
unsigned char mask = 0x03;
|
||||
unsigned char shift = 0;
|
||||
unsigned char pel;
|
||||
|
||||
while (mask != 0)
|
||||
{
|
||||
while (mask != 0) {
|
||||
pel = p[(mask & pat0) >> shift];
|
||||
pFrame[0] = pel;
|
||||
pFrame[1] = pel;
|
||||
@ -119,14 +123,12 @@ static void patternRow4Pixels2(unsigned char *pFrame,
|
||||
|
||||
// Fill in the next four 2x1 pixel blocks with p[0], p[1], p[2], or p[3],
|
||||
// depending on the corresponding two-bit value in pat.
|
||||
static void patternRow4Pixels2x1(unsigned char *pFrame, unsigned char pat, unsigned char *p)
|
||||
{
|
||||
unsigned char mask=0x03;
|
||||
unsigned char shift=0;
|
||||
static void patternRow4Pixels2x1(unsigned char *pFrame, unsigned char pat, unsigned char *p) {
|
||||
unsigned char mask = 0x03;
|
||||
unsigned char shift = 0;
|
||||
unsigned char pel;
|
||||
|
||||
while (mask != 0)
|
||||
{
|
||||
while (mask != 0) {
|
||||
pel = p[(mask & pat) >> shift];
|
||||
pFrame[0] = pel;
|
||||
pFrame[1] = pel;
|
||||
@ -138,18 +140,17 @@ static void patternRow4Pixels2x1(unsigned char *pFrame, unsigned char pat, unsig
|
||||
|
||||
// Fill in the next 4x4 pixel block with p[0], p[1], p[2], or p[3],
|
||||
// depending on the corresponding two-bit value in pat0, pat1, pat2, and pat3.
|
||||
static void patternQuadrant4Pixels(unsigned char *pFrame, unsigned char pat0, unsigned char pat1, unsigned char pat2, unsigned char pat3, unsigned char *p)
|
||||
{
|
||||
static void patternQuadrant4Pixels(unsigned char *pFrame, unsigned char pat0, unsigned char pat1, unsigned char pat2,
|
||||
unsigned char pat3, unsigned char *p) {
|
||||
unsigned long mask = 0x00000003UL;
|
||||
int shift=0;
|
||||
int shift = 0;
|
||||
int i;
|
||||
unsigned long pat = (pat3 << 24) | (pat2 << 16) | (pat1 << 8) | pat0;
|
||||
|
||||
for (i=0; i<16; i++)
|
||||
{
|
||||
pFrame[i&3] = p[(pat & mask) >> shift];
|
||||
for (i = 0; i < 16; i++) {
|
||||
pFrame[i & 3] = p[(pat & mask) >> shift];
|
||||
|
||||
if ((i&3) == 3)
|
||||
if ((i & 3) == 3)
|
||||
pFrame += g_width;
|
||||
|
||||
mask <<= 2;
|
||||
@ -158,25 +159,21 @@ static void patternQuadrant4Pixels(unsigned char *pFrame, unsigned char pat0, un
|
||||
}
|
||||
|
||||
// fills the next 8 pixels with either p[0] or p[1], depending on pattern
|
||||
static void patternRow2Pixels(unsigned char *pFrame, unsigned char pat, unsigned char *p)
|
||||
{
|
||||
unsigned char mask=0x01;
|
||||
static void patternRow2Pixels(unsigned char *pFrame, unsigned char pat, unsigned char *p) {
|
||||
unsigned char mask = 0x01;
|
||||
|
||||
while (mask != 0)
|
||||
{
|
||||
while (mask != 0) {
|
||||
*pFrame++ = p[(mask & pat) ? 1 : 0];
|
||||
mask <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
// fills the next four 2 x 2 pixel boxes with either p[0] or p[1], depending on pattern
|
||||
static void patternRow2Pixels2(unsigned char *pFrame, unsigned char pat, unsigned char *p)
|
||||
{
|
||||
static void patternRow2Pixels2(unsigned char *pFrame, unsigned char pat, unsigned char *p) {
|
||||
unsigned char pel;
|
||||
unsigned char mask=0x1;
|
||||
unsigned char mask = 0x1;
|
||||
|
||||
while (mask != 0x10)
|
||||
{
|
||||
while (mask != 0x10) {
|
||||
pel = p[(mask & pat) ? 1 : 0];
|
||||
|
||||
pFrame[0] = pel; // upper-left
|
||||
@ -190,17 +187,14 @@ static void patternRow2Pixels2(unsigned char *pFrame, unsigned char pat, unsigne
|
||||
}
|
||||
|
||||
// fills pixels in the next 4 x 4 pixel boxes with either p[0] or p[1], depending on pat0 and pat1.
|
||||
static void patternQuadrant2Pixels(unsigned char *pFrame, unsigned char pat0, unsigned char pat1, unsigned char *p)
|
||||
{
|
||||
static void patternQuadrant2Pixels(unsigned char *pFrame, unsigned char pat0, unsigned char pat1, unsigned char *p) {
|
||||
unsigned char pel;
|
||||
unsigned short mask = 0x0001;
|
||||
int i, j;
|
||||
unsigned short pat = (pat1 << 8) | pat0;
|
||||
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
for (j=0; j<4; j++)
|
||||
{
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
pel = p[(pat & mask) ? 1 : 0];
|
||||
|
||||
pFrame[j + i * g_width] = pel;
|
||||
@ -210,8 +204,8 @@ static void patternQuadrant2Pixels(unsigned char *pFrame, unsigned char pat0, un
|
||||
}
|
||||
}
|
||||
|
||||
static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsigned char **pData, int *pDataRemain, int *curXb, int *curYb)
|
||||
{
|
||||
static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsigned char **pData, int *pDataRemain,
|
||||
int *curXb, int *curYb) {
|
||||
unsigned char p[4];
|
||||
unsigned char pat[16];
|
||||
int i, j, k;
|
||||
@ -221,8 +215,7 @@ static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsi
|
||||
There are 16 ways to encode each block.
|
||||
*/
|
||||
|
||||
switch(codeType)
|
||||
{
|
||||
switch (codeType) {
|
||||
case 0x0:
|
||||
/* block is copied from block in current frame */
|
||||
copyFrame(*pFrame, *pFrame + ((unsigned char *)g_vBackBuf2 - (unsigned char *)g_vBackBuf1));
|
||||
@ -246,7 +239,7 @@ static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsi
|
||||
y = 8 + ((B - 56) / 29)
|
||||
*/
|
||||
relFar(*(*pData)++, 1, &x, &y);
|
||||
copyFrame(*pFrame, *pFrame + x + y*g_width);
|
||||
copyFrame(*pFrame, *pFrame + x + y * g_width);
|
||||
*pFrame += 8;
|
||||
--*pDataRemain;
|
||||
break;
|
||||
@ -263,7 +256,7 @@ static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsi
|
||||
y = -( 8 + ((B - 56) / 29))
|
||||
*/
|
||||
relFar(*(*pData)++, -1, &x, &y);
|
||||
copyFrame(*pFrame, *pFrame + x + y*g_width);
|
||||
copyFrame(*pFrame, *pFrame + x + y * g_width);
|
||||
*pFrame += 8;
|
||||
--*pDataRemain;
|
||||
break;
|
||||
@ -283,7 +276,7 @@ static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsi
|
||||
y = -8 + BH
|
||||
*/
|
||||
relClose(*(*pData)++, &x, &y);
|
||||
copyFrame(*pFrame, *pFrame + ((unsigned char *)g_vBackBuf2 - (unsigned char *)g_vBackBuf1) + x + y*g_width);
|
||||
copyFrame(*pFrame, *pFrame + ((unsigned char *)g_vBackBuf2 - (unsigned char *)g_vBackBuf1) + x + y * g_width);
|
||||
*pFrame += 8;
|
||||
--*pDataRemain;
|
||||
break;
|
||||
@ -296,7 +289,7 @@ static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsi
|
||||
*/
|
||||
x = (signed char)*(*pData)++;
|
||||
y = (signed char)*(*pData)++;
|
||||
copyFrame(*pFrame, *pFrame + ((unsigned char *)g_vBackBuf2 - (unsigned char *)g_vBackBuf1) + x + y*g_width);
|
||||
copyFrame(*pFrame, *pFrame + ((unsigned char *)g_vBackBuf2 - (unsigned char *)g_vBackBuf1) + x + y * g_width);
|
||||
*pFrame += 8;
|
||||
*pDataRemain -= 2;
|
||||
break;
|
||||
@ -311,12 +304,10 @@ static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsi
|
||||
Note that if you've reached the end of a row, this means going on
|
||||
to the next row.
|
||||
*/
|
||||
for (i=0; i<2; i++)
|
||||
{
|
||||
for (i = 0; i < 2; i++) {
|
||||
*pFrame += 16;
|
||||
if (++*curXb == (g_width >> 3))
|
||||
{
|
||||
*pFrame += 7*g_width;
|
||||
if (++*curXb == (g_width >> 3)) {
|
||||
*pFrame += 7 * g_width;
|
||||
*curXb = 0;
|
||||
if (++*curYb == (g_height >> 3))
|
||||
return;
|
||||
@ -391,25 +382,20 @@ static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsi
|
||||
*/
|
||||
p[0] = *(*pData)++;
|
||||
p[1] = *(*pData)++;
|
||||
if (p[0] <= p[1])
|
||||
{
|
||||
for (i=0; i<8; i++)
|
||||
{
|
||||
if (p[0] <= p[1]) {
|
||||
for (i = 0; i < 8; i++) {
|
||||
patternRow2Pixels(*pFrame, *(*pData)++, p);
|
||||
*pFrame += g_width;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=0; i<2; i++)
|
||||
{
|
||||
} else {
|
||||
for (i = 0; i < 2; i++) {
|
||||
patternRow2Pixels2(*pFrame, *(*pData) & 0xf, p);
|
||||
*pFrame += 2*g_width;
|
||||
*pFrame += 2 * g_width;
|
||||
patternRow2Pixels2(*pFrame, *(*pData)++ >> 4, p);
|
||||
*pFrame += 2*g_width;
|
||||
*pFrame += 2 * g_width;
|
||||
}
|
||||
}
|
||||
*pFrame -= (8*g_width - 8);
|
||||
*pFrame -= (8 * g_width - 8);
|
||||
break;
|
||||
|
||||
case 0x8:
|
||||
@ -501,11 +487,9 @@ static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsi
|
||||
66 11 66 66 66 66 11 66 ; 42: 01000010
|
||||
11 66 66 66 66 66 66 11 ; 81: 10000001
|
||||
*/
|
||||
if ( (*pData)[0] <= (*pData)[1])
|
||||
{
|
||||
if ((*pData)[0] <= (*pData)[1]) {
|
||||
// four quadrant case
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
for (i = 0; i < 4; i++) {
|
||||
p[0] = *(*pData)++;
|
||||
p[1] = *(*pData)++;
|
||||
pat[0] = *(*pData)++;
|
||||
@ -514,18 +498,14 @@ static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsi
|
||||
|
||||
// alternate between moving down and moving up and right
|
||||
if (i & 1)
|
||||
*pFrame += 4 - 4*g_width; // up and right
|
||||
*pFrame += 4 - 4 * g_width; // up and right
|
||||
else
|
||||
*pFrame += 4*g_width; // down
|
||||
*pFrame += 4 * g_width; // down
|
||||
}
|
||||
}
|
||||
else if ( (*pData)[6] <= (*pData)[7])
|
||||
{
|
||||
} else if ((*pData)[6] <= (*pData)[7]) {
|
||||
// split horizontal
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
if ((i & 1) == 0)
|
||||
{
|
||||
for (i = 0; i < 4; i++) {
|
||||
if ((i & 1) == 0) {
|
||||
p[0] = *(*pData)++;
|
||||
p[1] = *(*pData)++;
|
||||
}
|
||||
@ -534,25 +514,21 @@ static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsi
|
||||
patternQuadrant2Pixels(*pFrame, pat[0], pat[1], p);
|
||||
|
||||
if (i & 1)
|
||||
*pFrame -= (4*g_width - 4);
|
||||
*pFrame -= (4 * g_width - 4);
|
||||
else
|
||||
*pFrame += 4*g_width;
|
||||
*pFrame += 4 * g_width;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// split vertical
|
||||
for (i=0; i<8; i++)
|
||||
{
|
||||
if ((i & 3) == 0)
|
||||
{
|
||||
for (i = 0; i < 8; i++) {
|
||||
if ((i & 3) == 0) {
|
||||
p[0] = *(*pData)++;
|
||||
p[1] = *(*pData)++;
|
||||
}
|
||||
patternRow2Pixels(*pFrame, *(*pData)++, p);
|
||||
*pFrame += g_width;
|
||||
}
|
||||
*pFrame -= (8*g_width - 8);
|
||||
*pFrame -= (8 * g_width - 8);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -582,71 +558,59 @@ static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsi
|
||||
if P0 > P1 AND P2 > P3, we get 8 bytes of pattern, each 2 bits
|
||||
representing a 1x2 pixel (i.e. 1 pixel wide, and 2 high).
|
||||
*/
|
||||
if ( (*pData)[0] <= (*pData)[1])
|
||||
{
|
||||
if ( (*pData)[2] <= (*pData)[3])
|
||||
{
|
||||
if ((*pData)[0] <= (*pData)[1]) {
|
||||
if ((*pData)[2] <= (*pData)[3]) {
|
||||
p[0] = *(*pData)++;
|
||||
p[1] = *(*pData)++;
|
||||
p[2] = *(*pData)++;
|
||||
p[3] = *(*pData)++;
|
||||
|
||||
for (i=0; i<8; i++)
|
||||
{
|
||||
for (i = 0; i < 8; i++) {
|
||||
pat[0] = *(*pData)++;
|
||||
pat[1] = *(*pData)++;
|
||||
patternRow4Pixels(*pFrame, pat[0], pat[1], p);
|
||||
*pFrame += g_width;
|
||||
}
|
||||
|
||||
*pFrame -= (8*g_width - 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
*pFrame -= (8 * g_width - 8);
|
||||
} else {
|
||||
p[0] = *(*pData)++;
|
||||
p[1] = *(*pData)++;
|
||||
p[2] = *(*pData)++;
|
||||
p[3] = *(*pData)++;
|
||||
|
||||
patternRow4Pixels2(*pFrame, *(*pData)++, p);
|
||||
*pFrame += 2*g_width;
|
||||
*pFrame += 2 * g_width;
|
||||
patternRow4Pixels2(*pFrame, *(*pData)++, p);
|
||||
*pFrame += 2*g_width;
|
||||
*pFrame += 2 * g_width;
|
||||
patternRow4Pixels2(*pFrame, *(*pData)++, p);
|
||||
*pFrame += 2*g_width;
|
||||
*pFrame += 2 * g_width;
|
||||
patternRow4Pixels2(*pFrame, *(*pData)++, p);
|
||||
*pFrame -= (6*g_width - 8);
|
||||
*pFrame -= (6 * g_width - 8);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( (*pData)[2] <= (*pData)[3])
|
||||
{
|
||||
} else {
|
||||
if ((*pData)[2] <= (*pData)[3]) {
|
||||
// draw 2x1 strips
|
||||
p[0] = *(*pData)++;
|
||||
p[1] = *(*pData)++;
|
||||
p[2] = *(*pData)++;
|
||||
p[3] = *(*pData)++;
|
||||
|
||||
for (i=0; i<8; i++)
|
||||
{
|
||||
for (i = 0; i < 8; i++) {
|
||||
pat[0] = *(*pData)++;
|
||||
patternRow4Pixels2x1(*pFrame, pat[0], p);
|
||||
*pFrame += g_width;
|
||||
}
|
||||
|
||||
*pFrame -= (8*g_width - 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
*pFrame -= (8 * g_width - 8);
|
||||
} else {
|
||||
// draw 1x2 strips
|
||||
p[0] = *(*pData)++;
|
||||
p[1] = *(*pData)++;
|
||||
p[2] = *(*pData)++;
|
||||
p[3] = *(*pData)++;
|
||||
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
for (i = 0; i < 4; i++) {
|
||||
pat[0] = *(*pData)++;
|
||||
pat[1] = *(*pData)++;
|
||||
patternRow4Pixels(*pFrame, pat[0], pat[1], p);
|
||||
@ -655,7 +619,7 @@ static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsi
|
||||
*pFrame += g_width;
|
||||
}
|
||||
|
||||
*pFrame -= (8*g_width - 8);
|
||||
*pFrame -= (8 * g_width - 8);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -694,10 +658,8 @@ static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsi
|
||||
P5, then [P0 P1 P2 P3 B0 B1 B2 B3 B4 B5 B6 B7] represent the top
|
||||
half of the block and the other bytes represent the bottom half.
|
||||
*/
|
||||
if ( (*pData)[0] <= (*pData)[1])
|
||||
{
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
if ((*pData)[0] <= (*pData)[1]) {
|
||||
for (i = 0; i < 4; i++) {
|
||||
p[0] = *(*pData)++;
|
||||
p[1] = *(*pData)++;
|
||||
p[2] = *(*pData)++;
|
||||
@ -710,20 +672,15 @@ static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsi
|
||||
patternQuadrant4Pixels(*pFrame, pat[0], pat[1], pat[2], pat[3], p);
|
||||
|
||||
if (i & 1)
|
||||
*pFrame -= (4*g_width - 4);
|
||||
*pFrame -= (4 * g_width - 4);
|
||||
else
|
||||
*pFrame += 4*g_width;
|
||||
*pFrame += 4 * g_width;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( (*pData)[12] <= (*pData)[13])
|
||||
{
|
||||
} else {
|
||||
if ((*pData)[12] <= (*pData)[13]) {
|
||||
// split vertical
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
if ((i&1) == 0)
|
||||
{
|
||||
for (i = 0; i < 4; i++) {
|
||||
if ((i & 1) == 0) {
|
||||
p[0] = *(*pData)++;
|
||||
p[1] = *(*pData)++;
|
||||
p[2] = *(*pData)++;
|
||||
@ -738,18 +695,14 @@ static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsi
|
||||
patternQuadrant4Pixels(*pFrame, pat[0], pat[1], pat[2], pat[3], p);
|
||||
|
||||
if (i & 1)
|
||||
*pFrame -= (4*g_width - 4);
|
||||
*pFrame -= (4 * g_width - 4);
|
||||
else
|
||||
*pFrame += 4*g_width;
|
||||
*pFrame += 4 * g_width;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// split horizontal
|
||||
for (i=0; i<8; i++)
|
||||
{
|
||||
if ((i&3) == 0)
|
||||
{
|
||||
for (i = 0; i < 8; i++) {
|
||||
if ((i & 3) == 0) {
|
||||
p[0] = *(*pData)++;
|
||||
p[1] = *(*pData)++;
|
||||
p[2] = *(*pData)++;
|
||||
@ -762,7 +715,7 @@ static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsi
|
||||
*pFrame += g_width;
|
||||
}
|
||||
|
||||
*pFrame -= (8*g_width - 8);
|
||||
*pFrame -= (8 * g_width - 8);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -772,14 +725,13 @@ static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsi
|
||||
bytes of pixel data. 1 byte for each pixel, and in the standard
|
||||
order (l->r, t->b).
|
||||
*/
|
||||
for (i=0; i<8; i++)
|
||||
{
|
||||
for (i = 0; i < 8; i++) {
|
||||
memcpy(*pFrame, *pData, 8);
|
||||
*pFrame += g_width;
|
||||
*pData += 8;
|
||||
*pDataRemain -= 8;
|
||||
}
|
||||
*pFrame -= (8*g_width - 8);
|
||||
*pFrame -= (8 * g_width - 8);
|
||||
break;
|
||||
|
||||
case 0xc:
|
||||
@ -787,21 +739,18 @@ static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsi
|
||||
bytes of pixel data. 1 byte for each block of 2x2 pixels, and in
|
||||
the standard order (l->r, t->b).
|
||||
*/
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
for (j=0; j<2; j++)
|
||||
{
|
||||
for (k=0; k<4; k++)
|
||||
{
|
||||
(*pFrame)[2*k] = (*pData)[k];
|
||||
(*pFrame)[2*k+1] = (*pData)[k];
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 2; j++) {
|
||||
for (k = 0; k < 4; k++) {
|
||||
(*pFrame)[2 * k] = (*pData)[k];
|
||||
(*pFrame)[2 * k + 1] = (*pData)[k];
|
||||
}
|
||||
*pFrame += g_width;
|
||||
}
|
||||
*pData += 4;
|
||||
*pDataRemain -= 4;
|
||||
}
|
||||
*pFrame -= (8*g_width - 8);
|
||||
*pFrame -= (8 * g_width - 8);
|
||||
break;
|
||||
|
||||
case 0xd:
|
||||
@ -809,35 +758,31 @@ static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsi
|
||||
bytes of pixel data. 1 byte for each block of 4x4 pixels, and in
|
||||
the standard order (l->r, t->b).
|
||||
*/
|
||||
for (i=0; i<2; i++)
|
||||
{
|
||||
for (j=0; j<4; j++)
|
||||
{
|
||||
for (k=0; k<4; k++)
|
||||
{
|
||||
(*pFrame)[k*g_width+j] = (*pData)[0];
|
||||
(*pFrame)[k*g_width+j+4] = (*pData)[1];
|
||||
for (i = 0; i < 2; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
for (k = 0; k < 4; k++) {
|
||||
(*pFrame)[k * g_width + j] = (*pData)[0];
|
||||
(*pFrame)[k * g_width + j + 4] = (*pData)[1];
|
||||
}
|
||||
}
|
||||
*pFrame += 4*g_width;
|
||||
*pFrame += 4 * g_width;
|
||||
*pData += 2;
|
||||
*pDataRemain -= 2;
|
||||
}
|
||||
*pFrame -= (8*g_width - 8);
|
||||
*pFrame -= (8 * g_width - 8);
|
||||
break;
|
||||
|
||||
case 0xe:
|
||||
/* This encoding represents a solid 8x8 frame. We get 1 byte of pixel
|
||||
data from the data stream.
|
||||
*/
|
||||
for (i=0; i<8; i++)
|
||||
{
|
||||
for (i = 0; i < 8; i++) {
|
||||
memset(*pFrame, **pData, 8);
|
||||
*pFrame += g_width;
|
||||
}
|
||||
++*pData;
|
||||
--*pDataRemain;
|
||||
*pFrame -= (8*g_width - 8);
|
||||
*pFrame -= (8 * g_width - 8);
|
||||
break;
|
||||
|
||||
case 0xf:
|
||||
@ -852,17 +797,15 @@ static void dispatchDecoder(unsigned char **pFrame, unsigned char codeType, unsi
|
||||
P0 P1 P0 P1 P0 P1 P0 P1
|
||||
P1 P0 P1 P0 P1 P0 P1 P0
|
||||
*/
|
||||
for (i=0; i<8; i++)
|
||||
{
|
||||
for (j=0; j<8; j++)
|
||||
{
|
||||
(*pFrame)[j] = (*pData)[(i+j)&1];
|
||||
for (i = 0; i < 8; i++) {
|
||||
for (j = 0; j < 8; j++) {
|
||||
(*pFrame)[j] = (*pData)[(i + j) & 1];
|
||||
}
|
||||
*pFrame += g_width;
|
||||
}
|
||||
*pData += 2;
|
||||
*pDataRemain -= 2;
|
||||
*pFrame -= (8*g_width - 8);
|
||||
*pFrame -= (8 * g_width - 8);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -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,9 +1,26 @@
|
||||
/*
|
||||
* 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{
|
||||
typedef struct {
|
||||
int screenWidth;
|
||||
int screenHeight;
|
||||
int width;
|
||||
@ -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,47 +1,72 @@
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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]);
|
||||
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)
|
||||
{
|
||||
void mveaudio_uncompress(short *buffer, unsigned char *data, int length) {
|
||||
int nCurOffsets[2];
|
||||
int swath;
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
161
libmve/mvelib.c
161
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
|
||||
@ -55,14 +72,12 @@ static void _mvestream_reset(MVESTREAM *movie);
|
||||
/*
|
||||
* open an MVE file
|
||||
*/
|
||||
MVEFILE *mvefile_open(void *stream)
|
||||
{
|
||||
MVEFILE *mvefile_open(void *stream) {
|
||||
MVEFILE *file;
|
||||
|
||||
/* create the file */
|
||||
file = _mvefile_alloc();
|
||||
if (! _mvefile_open(file, stream))
|
||||
{
|
||||
if (!_mvefile_open(file, stream)) {
|
||||
_mvefile_free(file);
|
||||
return NULL;
|
||||
}
|
||||
@ -71,8 +86,7 @@ MVEFILE *mvefile_open(void *stream)
|
||||
_mvefile_set_buffer_size(file, 1024);
|
||||
|
||||
/* verify the file's header */
|
||||
if (! _mvefile_read_header(file))
|
||||
{
|
||||
if (!_mvefile_read_header(file)) {
|
||||
_mvefile_free(file);
|
||||
return NULL;
|
||||
}
|
||||
@ -86,26 +100,21 @@ MVEFILE *mvefile_open(void *stream)
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
void mvefile_reset(MVEFILE *file) {
|
||||
_mvefile_reset(file);
|
||||
|
||||
/* initialize the file */
|
||||
_mvefile_set_buffer_size(file, 1024);
|
||||
|
||||
/* verify the file's header */
|
||||
if (! _mvefile_read_header(file))
|
||||
{
|
||||
if (!_mvefile_read_header(file)) {
|
||||
_mvefile_free(file);
|
||||
//return NULL;
|
||||
// return NULL;
|
||||
}
|
||||
|
||||
/* now, prefetch the next chunk */
|
||||
@ -115,8 +124,7 @@ void mvefile_reset(MVEFILE *file)
|
||||
/*
|
||||
* 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 (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill)
|
||||
return -1;
|
||||
@ -132,8 +140,7 @@ int mvefile_get_next_segment_size(MVEFILE *movie)
|
||||
/*
|
||||
* 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 (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill)
|
||||
return 0xff;
|
||||
@ -150,8 +157,7 @@ unsigned char mvefile_get_next_segment_major(MVEFILE *movie)
|
||||
* get subtype (version) of next segment in chunk (0xff if no more segments in
|
||||
* 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 (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill)
|
||||
return 0xff;
|
||||
@ -167,8 +173,7 @@ unsigned char mvefile_get_next_segment_minor(MVEFILE *movie)
|
||||
/*
|
||||
* 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 (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill)
|
||||
return NULL;
|
||||
@ -184,8 +189,7 @@ unsigned char *mvefile_get_next_segment(MVEFILE *movie)
|
||||
/*
|
||||
* advance to next segment
|
||||
*/
|
||||
void mvefile_advance_segment(MVEFILE *movie)
|
||||
{
|
||||
void mvefile_advance_segment(MVEFILE *movie) {
|
||||
/* if nothing is cached, fail */
|
||||
if (movie->cur_chunk == NULL || movie->next_segment >= movie->cur_fill)
|
||||
return;
|
||||
@ -195,17 +199,13 @@ void mvefile_advance_segment(MVEFILE *movie)
|
||||
return;
|
||||
|
||||
/* else, advance to next segment */
|
||||
movie->next_segment +=
|
||||
(4 + _mve_get_ushort(movie->cur_chunk + movie->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,16 +214,14 @@ int mvefile_fetch_next_chunk(MVEFILE *movie)
|
||||
/*
|
||||
* open an MVE stream
|
||||
*/
|
||||
MVESTREAM *mve_open(void *stream)
|
||||
{
|
||||
MVESTREAM *mve_open(void *stream) {
|
||||
MVESTREAM *movie;
|
||||
|
||||
/* allocate */
|
||||
movie = _mvestream_alloc();
|
||||
|
||||
/* open */
|
||||
if (! _mvestream_open(movie, stream))
|
||||
{
|
||||
if (!_mvestream_open(movie, stream)) {
|
||||
_mvestream_free(movie);
|
||||
return NULL;
|
||||
}
|
||||
@ -234,24 +232,17 @@ MVESTREAM *mve_open(void *stream)
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
void mve_set_handler(MVESTREAM *movie, unsigned char major, MVESEGMENTHANDLER handler) {
|
||||
if (major < 32)
|
||||
movie->handlers[major] = handler;
|
||||
}
|
||||
@ -259,32 +250,26 @@ void mve_set_handler(MVESTREAM *movie, unsigned char major, MVESEGMENTHANDLER ha
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
while (major != 0xff) {
|
||||
/* 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);
|
||||
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;
|
||||
}
|
||||
|
||||
@ -293,7 +278,7 @@ int mve_play_next_chunk(MVESTREAM *movie)
|
||||
major = mvefile_get_next_segment_major(movie->movie);
|
||||
}
|
||||
|
||||
if (! mvefile_fetch_next_chunk(movie->movie))
|
||||
if (!mvefile_fetch_next_chunk(movie->movie))
|
||||
return 0;
|
||||
|
||||
/* return status */
|
||||
@ -307,8 +292,7 @@ int mve_play_next_chunk(MVESTREAM *movie)
|
||||
/*
|
||||
* allocate an MVEFILE
|
||||
*/
|
||||
static MVEFILE *_mvefile_alloc(void)
|
||||
{
|
||||
static MVEFILE *_mvefile_alloc(void) {
|
||||
MVEFILE *file = (MVEFILE *)mve_alloc(sizeof(MVEFILE));
|
||||
file->stream = NULL;
|
||||
file->cur_chunk = NULL;
|
||||
@ -322,8 +306,7 @@ static MVEFILE *_mvefile_alloc(void)
|
||||
/*
|
||||
* free an MVE file
|
||||
*/
|
||||
static void _mvefile_free(MVEFILE *movie)
|
||||
{
|
||||
static void _mvefile_free(MVEFILE *movie) {
|
||||
/* free the stream */
|
||||
movie->stream = NULL;
|
||||
|
||||
@ -344,10 +327,9 @@ static void _mvefile_free(MVEFILE *movie)
|
||||
/*
|
||||
* 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;
|
||||
if (! file->stream)
|
||||
if (!file->stream)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
@ -356,8 +338,7 @@ static int _mvefile_open(MVEFILE *file, void *stream)
|
||||
/*
|
||||
* 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,16 +350,15 @@ static void _mvefile_reset(MVEFILE *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];
|
||||
|
||||
/* check the file is open */
|
||||
if (! movie->stream)
|
||||
if (!movie->stream)
|
||||
return 0;
|
||||
|
||||
/* check the file is long enough */
|
||||
if (! mve_read(movie->stream, buffer, 26))
|
||||
if (!mve_read(movie->stream, buffer, 26))
|
||||
return 0;
|
||||
|
||||
/* check the signature */
|
||||
@ -386,18 +366,17 @@ static int _mvefile_read_header(MVEFILE *movie)
|
||||
return 0;
|
||||
|
||||
/* check the hard-coded constants */
|
||||
if (_mve_get_short(buffer+20) != MVE_HDRCONST1)
|
||||
if (_mve_get_short(buffer + 20) != MVE_HDRCONST1)
|
||||
return 0;
|
||||
if (_mve_get_short(buffer+22) != MVE_HDRCONST2)
|
||||
if (_mve_get_short(buffer + 22) != MVE_HDRCONST2)
|
||||
return 0;
|
||||
if (_mve_get_short(buffer+24) != MVE_HDRCONST3)
|
||||
if (_mve_get_short(buffer + 24) != MVE_HDRCONST3)
|
||||
return 0;
|
||||
|
||||
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;
|
||||
int new_len;
|
||||
|
||||
@ -414,8 +393,7 @@ static void _mvefile_set_buffer_size(MVEFILE *movie, int buf_size)
|
||||
memcpy(new_buffer, movie->cur_chunk, movie->cur_fill);
|
||||
|
||||
/* free old buffer */
|
||||
if (movie->cur_chunk)
|
||||
{
|
||||
if (movie->cur_chunk) {
|
||||
mve_free(movie->cur_chunk);
|
||||
movie->cur_chunk = 0;
|
||||
}
|
||||
@ -425,17 +403,16 @@ static void _mvefile_set_buffer_size(MVEFILE *movie, int buf_size)
|
||||
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 short length;
|
||||
|
||||
/* fail if not open */
|
||||
if (! movie->stream)
|
||||
if (!movie->stream)
|
||||
return 0;
|
||||
|
||||
/* 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;
|
||||
|
||||
/* pull out the next length */
|
||||
@ -445,7 +422,7 @@ static int _mvefile_fetch_next_chunk(MVEFILE *movie)
|
||||
_mvefile_set_buffer_size(movie, length);
|
||||
|
||||
/* read the chunk */
|
||||
if (! mve_read(movie->stream, movie->cur_chunk, length))
|
||||
if (!mve_read(movie->stream, movie->cur_chunk, length))
|
||||
return 0;
|
||||
movie->cur_fill = length;
|
||||
movie->next_segment = 0;
|
||||
@ -453,15 +430,13 @@ static int _mvefile_fetch_next_chunk(MVEFILE *movie)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static short _mve_get_short(unsigned char *data)
|
||||
{
|
||||
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)
|
||||
{
|
||||
static unsigned short _mve_get_ushort(unsigned char *data) {
|
||||
unsigned short value;
|
||||
value = data[0] | (data[1] << 8);
|
||||
return value;
|
||||
@ -470,8 +445,7 @@ static unsigned short _mve_get_ushort(unsigned char *data)
|
||||
/*
|
||||
* allocate an MVESTREAM
|
||||
*/
|
||||
static MVESTREAM *_mvestream_alloc(void)
|
||||
{
|
||||
static MVESTREAM *_mvestream_alloc(void) {
|
||||
MVESTREAM *movie;
|
||||
|
||||
/* allocate and zero-initialize everything */
|
||||
@ -486,8 +460,7 @@ static MVESTREAM *_mvestream_alloc(void)
|
||||
/*
|
||||
* free an MVESTREAM
|
||||
*/
|
||||
static void _mvestream_free(MVESTREAM *movie)
|
||||
{
|
||||
static void _mvestream_free(MVESTREAM *movie) {
|
||||
/* close MVEFILE */
|
||||
if (movie->movie)
|
||||
mvefile_close(movie->movie);
|
||||
@ -504,8 +477,7 @@ static void _mvestream_free(MVESTREAM *movie)
|
||||
/*
|
||||
* 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);
|
||||
|
||||
return (movie->movie == NULL) ? 0 : 1;
|
||||
@ -514,7 +486,4 @@ static int _mvestream_open(MVESTREAM *movie, void *stream)
|
||||
/*
|
||||
* 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,8 +32,7 @@ extern mve_cb_SetPalette mve_setpalette;
|
||||
/*
|
||||
* structure for maintaining info on a MVEFILE stream
|
||||
*/
|
||||
typedef struct MVEFILE
|
||||
{
|
||||
typedef struct MVEFILE {
|
||||
void *stream;
|
||||
unsigned char *cur_chunk;
|
||||
int buf_size;
|
||||
@ -73,8 +89,7 @@ typedef int (*MVESEGMENTHANDLER)(unsigned char major, unsigned char minor, unsig
|
||||
/*
|
||||
* structure for maintaining an MVE stream
|
||||
*/
|
||||
typedef struct MVESTREAM
|
||||
{
|
||||
typedef struct MVESTREAM {
|
||||
MVEFILE *movie;
|
||||
void *context;
|
||||
MVESEGMENTHANDLER handlers[32];
|
||||
|
306
libmve/mveplay.c
306
libmve/mveplay.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
|
||||
@ -5,24 +22,24 @@
|
||||
#ifndef __MSDOS__
|
||||
#define AUDIO
|
||||
#endif
|
||||
//#define DEBUG
|
||||
// #define DEBUG
|
||||
|
||||
#include <string.h>
|
||||
#ifdef _WIN32
|
||||
# include <windows.h>
|
||||
#include <windows.h>
|
||||
#else
|
||||
# include <errno.h>
|
||||
# include <time.h>
|
||||
# include <fcntl.h>
|
||||
# ifdef macintosh
|
||||
# include <types.h>
|
||||
# include <OSUtils.h>
|
||||
# else
|
||||
# include <sys/time.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
# include <unistd.h>
|
||||
# endif // macintosh
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef macintosh
|
||||
#include <types.h>
|
||||
#include <OSUtils.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#endif // macintosh
|
||||
#endif // _WIN32
|
||||
|
||||
#if defined(AUDIO)
|
||||
@ -60,46 +77,40 @@
|
||||
#define MVE_AUDIO_FLAGS_16BIT 2
|
||||
#define MVE_AUDIO_FLAGS_COMPRESSED 4
|
||||
|
||||
int g_spdFactorNum=0;
|
||||
static int g_spdFactorDenom=10;
|
||||
int g_spdFactorNum = 0;
|
||||
static int g_spdFactorDenom = 10;
|
||||
static int g_frameUpdated = 0;
|
||||
|
||||
static short get_short(unsigned char *data)
|
||||
{
|
||||
static short get_short(unsigned char *data) {
|
||||
short value;
|
||||
value = data[0] | (data[1] << 8);
|
||||
return value;
|
||||
}
|
||||
|
||||
static unsigned short get_ushort(unsigned char *data)
|
||||
{
|
||||
static unsigned short get_ushort(unsigned char *data) {
|
||||
unsigned short value;
|
||||
value = data[0] | (data[1] << 8);
|
||||
return value;
|
||||
}
|
||||
|
||||
static int get_int(unsigned char *data)
|
||||
{
|
||||
static int get_int(unsigned char *data) {
|
||||
int value;
|
||||
value = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
|
||||
return value;
|
||||
}
|
||||
|
||||
static unsigned int unhandled_chunks[32*256];
|
||||
static unsigned int unhandled_chunks[32 * 256];
|
||||
|
||||
static int default_seg_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
|
||||
{
|
||||
unhandled_chunks[major<<8|minor]++;
|
||||
//fprintf(stderr, "unknown chunk type %02x/%02x\n", major, minor);
|
||||
static int default_seg_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context) {
|
||||
unhandled_chunks[major << 8 | minor]++;
|
||||
// fprintf(stderr, "unknown chunk type %02x/%02x\n", major, minor);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*************************
|
||||
* general handlers
|
||||
*************************/
|
||||
static int end_movie_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
|
||||
{
|
||||
static int end_movie_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -111,14 +122,13 @@ static int end_movie_handler(unsigned char major, unsigned char minor, unsigned
|
||||
* timer variables
|
||||
*/
|
||||
static int timer_created = 0;
|
||||
static int micro_frame_delay=0;
|
||||
static int timer_started=0;
|
||||
static int micro_frame_delay = 0;
|
||||
static int timer_started = 0;
|
||||
static unsigned long int timer_expire = 0;
|
||||
|
||||
#if defined(_WIN32) || defined(macintosh)
|
||||
|
||||
unsigned long int timer_getmicroseconds()
|
||||
{
|
||||
unsigned long int timer_getmicroseconds() {
|
||||
static int counter = 0;
|
||||
#ifdef _WIN32
|
||||
DWORD now = GetTickCount();
|
||||
@ -132,8 +142,7 @@ unsigned long int timer_getmicroseconds()
|
||||
|
||||
#else
|
||||
|
||||
unsigned long int timer_getmicroseconds()
|
||||
{
|
||||
unsigned long int timer_getmicroseconds() {
|
||||
struct timeval tv;
|
||||
static time_t starttime = 0;
|
||||
|
||||
@ -147,8 +156,7 @@ unsigned long int timer_getmicroseconds()
|
||||
|
||||
#endif
|
||||
|
||||
void timer_sleepmicroseconds(unsigned long int usec)
|
||||
{
|
||||
void timer_sleepmicroseconds(unsigned long int usec) {
|
||||
#ifdef _WIN32
|
||||
Sleep(usec / 1000);
|
||||
#elif defined(macintosh)
|
||||
@ -161,8 +169,7 @@ void timer_sleepmicroseconds(unsigned long int usec)
|
||||
#endif
|
||||
}
|
||||
|
||||
static int create_timer_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
|
||||
{
|
||||
static int create_timer_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context) {
|
||||
|
||||
#if !defined(_WIN32) && !defined(macintosh) // FIXME
|
||||
__extension__ long long temp;
|
||||
@ -175,9 +182,8 @@ static int create_timer_handler(unsigned char major, unsigned char minor, unsign
|
||||
else
|
||||
timer_created = 1;
|
||||
|
||||
micro_frame_delay = get_int(data) * (int)get_short(data+4);
|
||||
if (g_spdFactorNum != 0)
|
||||
{
|
||||
micro_frame_delay = get_int(data) * (int)get_short(data + 4);
|
||||
if (g_spdFactorNum != 0) {
|
||||
temp = micro_frame_delay;
|
||||
temp *= g_spdFactorNum;
|
||||
temp /= g_spdFactorDenom;
|
||||
@ -187,25 +193,22 @@ static int create_timer_handler(unsigned char major, unsigned char minor, unsign
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void timer_stop(void)
|
||||
{
|
||||
static void timer_stop(void) {
|
||||
timer_expire = 0;
|
||||
timer_started = 0;
|
||||
}
|
||||
|
||||
static void timer_start(void)
|
||||
{
|
||||
static void timer_start(void) {
|
||||
timer_expire = timer_getmicroseconds();
|
||||
timer_expire += micro_frame_delay;
|
||||
timer_started=1;
|
||||
timer_started = 1;
|
||||
}
|
||||
|
||||
static void do_timer_wait(void)
|
||||
{
|
||||
static void do_timer_wait(void) {
|
||||
unsigned long int ts;
|
||||
unsigned long int tv;
|
||||
|
||||
if (! timer_started)
|
||||
if (!timer_started)
|
||||
return;
|
||||
|
||||
tv = timer_getmicroseconds();
|
||||
@ -216,7 +219,7 @@ static void do_timer_wait(void)
|
||||
|
||||
timer_sleepmicroseconds(ts);
|
||||
|
||||
end:
|
||||
end:
|
||||
timer_expire += micro_frame_delay;
|
||||
}
|
||||
|
||||
@ -230,45 +233,44 @@ static int audiobuf_created = 0;
|
||||
static void mve_audio_callback(void *userdata, unsigned char *stream, int len);
|
||||
static short *mve_audio_buffers[TOTAL_AUDIO_BUFFERS];
|
||||
static int mve_audio_buflens[TOTAL_AUDIO_BUFFERS];
|
||||
static int mve_audio_curbuf_curpos=0;
|
||||
static int mve_audio_bufhead=0;
|
||||
static int mve_audio_buftail=0;
|
||||
static int mve_audio_playing=0;
|
||||
static int mve_audio_canplay=0;
|
||||
static int mve_audio_compressed=0;
|
||||
static int mve_audio_curbuf_curpos = 0;
|
||||
static int mve_audio_bufhead = 0;
|
||||
static int mve_audio_buftail = 0;
|
||||
static int mve_audio_playing = 0;
|
||||
static int mve_audio_canplay = 0;
|
||||
static int mve_audio_compressed = 0;
|
||||
static int mve_audio_enabled = 1;
|
||||
|
||||
|
||||
static void mve_audio_callback(void *userdata, unsigned char *stream, int len)
|
||||
{
|
||||
int total=0;
|
||||
static void mve_audio_callback(void *userdata, unsigned char *stream, int len) {
|
||||
int total = 0;
|
||||
int length;
|
||||
if (mve_audio_bufhead == mve_audio_buftail)
|
||||
return /* 0 */;
|
||||
|
||||
//fprintf(stderr, "+ <%d (%d), %d, %d>\n", mve_audio_bufhead, mve_audio_curbuf_curpos, mve_audio_buftail, len);
|
||||
// fprintf(stderr, "+ <%d (%d), %d, %d>\n", mve_audio_bufhead, mve_audio_curbuf_curpos, mve_audio_buftail, len);
|
||||
|
||||
while (mve_audio_bufhead != mve_audio_buftail /* while we have more buffers */
|
||||
&& len > (mve_audio_buflens[mve_audio_bufhead]-mve_audio_curbuf_curpos)) /* and while we need more data */
|
||||
&& len > (mve_audio_buflens[mve_audio_bufhead] - mve_audio_curbuf_curpos)) /* and while we need more data */
|
||||
{
|
||||
length = mve_audio_buflens[mve_audio_bufhead]-mve_audio_curbuf_curpos;
|
||||
length = mve_audio_buflens[mve_audio_bufhead] - mve_audio_curbuf_curpos;
|
||||
memcpy(stream, /* cur output position */
|
||||
((unsigned char *)mve_audio_buffers[mve_audio_bufhead])+mve_audio_curbuf_curpos, /* cur input position */
|
||||
((unsigned char *)mve_audio_buffers[mve_audio_bufhead]) + mve_audio_curbuf_curpos, /* cur input position */
|
||||
length); /* cur input length */
|
||||
|
||||
total += length;
|
||||
stream += length; /* advance output */
|
||||
len -= length; /* decrement avail ospace */
|
||||
mve_free(mve_audio_buffers[mve_audio_bufhead]); /* free the buffer */
|
||||
mve_audio_buffers[mve_audio_bufhead]=NULL; /* free the buffer */
|
||||
mve_audio_buflens[mve_audio_bufhead]=0; /* free the buffer */
|
||||
mve_audio_buffers[mve_audio_bufhead] = NULL; /* free the buffer */
|
||||
mve_audio_buflens[mve_audio_bufhead] = 0; /* free the buffer */
|
||||
|
||||
if (++mve_audio_bufhead == TOTAL_AUDIO_BUFFERS) /* next buffer */
|
||||
mve_audio_bufhead = 0;
|
||||
mve_audio_curbuf_curpos = 0;
|
||||
}
|
||||
|
||||
//fprintf(stderr, "= <%d (%d), %d, %d>: %d\n", mve_audio_bufhead, mve_audio_curbuf_curpos, mve_audio_buftail, len, total);
|
||||
// fprintf(stderr, "= <%d (%d), %d, %d>: %d\n", mve_audio_bufhead, mve_audio_curbuf_curpos, mve_audio_buftail, len,
|
||||
// total);
|
||||
/* return total; */
|
||||
|
||||
if (len != 0 /* ospace remaining */
|
||||
@ -285,8 +287,8 @@ static void mve_audio_callback(void *userdata, unsigned char *stream, int len)
|
||||
if (mve_audio_curbuf_curpos >= mve_audio_buflens[mve_audio_bufhead]) /* if this ends the current chunk */
|
||||
{
|
||||
mve_free(mve_audio_buffers[mve_audio_bufhead]); /* free buffer */
|
||||
mve_audio_buffers[mve_audio_bufhead]=NULL;
|
||||
mve_audio_buflens[mve_audio_bufhead]=0;
|
||||
mve_audio_buffers[mve_audio_bufhead] = NULL;
|
||||
mve_audio_buflens[mve_audio_bufhead] = 0;
|
||||
|
||||
if (++mve_audio_bufhead == TOTAL_AUDIO_BUFFERS) /* next buffer */
|
||||
mve_audio_bufhead = 0;
|
||||
@ -294,12 +296,12 @@ static void mve_audio_callback(void *userdata, unsigned char *stream, int len)
|
||||
}
|
||||
}
|
||||
|
||||
//fprintf(stderr, "- <%d (%d), %d, %d>\n", mve_audio_bufhead, mve_audio_curbuf_curpos, mve_audio_buftail, len);
|
||||
// fprintf(stderr, "- <%d (%d), %d, %d>\n", mve_audio_bufhead, mve_audio_curbuf_curpos, mve_audio_buftail, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int create_audiobuf_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
|
||||
{
|
||||
static int create_audiobuf_handler(unsigned char major, unsigned char minor, unsigned char *data, int len,
|
||||
void *context) {
|
||||
#ifdef AUDIO
|
||||
int flags;
|
||||
int sample_rate;
|
||||
@ -345,16 +347,13 @@ static int create_audiobuf_handler(unsigned char major, unsigned char minor, uns
|
||||
}
|
||||
|
||||
fprintf(stderr, "creating audio buffers:\n");
|
||||
fprintf(stderr, "sample rate = %d, stereo = %d, bitsize = %d, compressed = %d\n",
|
||||
sample_rate, stereo, bitsize ? 16 : 8, compressed);
|
||||
fprintf(stderr, "sample rate = %d, stereo = %d, bitsize = %d, compressed = %d\n", sample_rate, stereo,
|
||||
bitsize ? 16 : 8, compressed);
|
||||
|
||||
if (Mix_OpenAudio(sample_rate, format, stereo ? 2 : 1, 4096) == 0)
|
||||
{
|
||||
if (Mix_OpenAudio(sample_rate, format, stereo ? 2 : 1, 4096) == 0) {
|
||||
fprintf(stderr, " success\n");
|
||||
mve_audio_canplay = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
fprintf(stderr, " failure : %s\n", Mix_GetError());
|
||||
mve_audio_canplay = 0;
|
||||
}
|
||||
@ -369,11 +368,9 @@ static int create_audiobuf_handler(unsigned char major, unsigned char minor, uns
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int play_audio_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
|
||||
{
|
||||
static int play_audio_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context) {
|
||||
#ifdef AUDIO
|
||||
if (mve_audio_canplay && !mve_audio_playing && mve_audio_bufhead != mve_audio_buftail)
|
||||
{
|
||||
if (mve_audio_canplay && !mve_audio_playing && mve_audio_bufhead != mve_audio_buftail) {
|
||||
Mix_Resume(-1);
|
||||
mve_audio_playing = 1;
|
||||
}
|
||||
@ -381,18 +378,15 @@ static int play_audio_handler(unsigned char major, unsigned char minor, unsigned
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int audio_data_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
|
||||
{
|
||||
static int audio_data_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context) {
|
||||
#ifdef AUDIO
|
||||
static const int selected_chan=1;
|
||||
static const int selected_chan = 1;
|
||||
int chan;
|
||||
int nsamp;
|
||||
if (mve_audio_canplay)
|
||||
{
|
||||
if (mve_audio_canplay) {
|
||||
chan = get_ushort(data + 2);
|
||||
nsamp = get_ushort(data + 4);
|
||||
if (chan & selected_chan)
|
||||
{
|
||||
if (chan & selected_chan) {
|
||||
/* HACK: +4 mveaudio_uncompress adds 4 more bytes */
|
||||
if (major == MVE_OPCODE_AUDIOFRAMEDATA) {
|
||||
if (mve_audio_compressed) {
|
||||
@ -439,12 +433,12 @@ void *g_vBuffers = NULL, *g_vBackBuf1, *g_vBackBuf2;
|
||||
|
||||
static int g_destX, g_destY;
|
||||
static int g_screenWidth, g_screenHeight;
|
||||
static unsigned char *g_pCurMap=NULL;
|
||||
static int g_nMapLength=0;
|
||||
static unsigned char *g_pCurMap = NULL;
|
||||
static int g_nMapLength = 0;
|
||||
static int g_truecolor;
|
||||
|
||||
static int create_videobuf_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
|
||||
{
|
||||
static int create_videobuf_handler(unsigned char major, unsigned char minor, unsigned char *data, int len,
|
||||
void *context) {
|
||||
short w, h;
|
||||
short count, truecolor;
|
||||
|
||||
@ -454,16 +448,16 @@ static int create_videobuf_handler(unsigned char major, unsigned char minor, uns
|
||||
videobuf_created = 1;
|
||||
|
||||
w = get_short(data);
|
||||
h = get_short(data+2);
|
||||
h = get_short(data + 2);
|
||||
|
||||
if (minor > 0) {
|
||||
count = get_short(data+4);
|
||||
count = get_short(data + 4);
|
||||
} else {
|
||||
count = 1;
|
||||
}
|
||||
|
||||
if (minor > 1) {
|
||||
truecolor = get_short(data+6);
|
||||
truecolor = get_short(data + 6);
|
||||
} else {
|
||||
truecolor = 0;
|
||||
}
|
||||
@ -492,23 +486,21 @@ static int create_videobuf_handler(unsigned char major, unsigned char minor, uns
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int display_video_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
|
||||
{
|
||||
static int display_video_handler(unsigned char major, unsigned char minor, unsigned char *data, int len,
|
||||
void *context) {
|
||||
if (g_destX == -1) // center it
|
||||
g_destX = (g_screenWidth - g_width) >> 1;
|
||||
if (g_destY == -1) // center it
|
||||
g_destY = (g_screenHeight - g_height) >> 1;
|
||||
|
||||
mve_showframe(g_vBackBuf1, g_width, g_height, 0, 0,
|
||||
g_width, g_height, g_destX, g_destY);
|
||||
mve_showframe(g_vBackBuf1, g_width, g_height, 0, 0, g_width, g_height, g_destX, g_destY);
|
||||
|
||||
g_frameUpdated = 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int init_video_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
|
||||
{
|
||||
static int init_video_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context) {
|
||||
short width, height;
|
||||
|
||||
if (video_initialized)
|
||||
@ -517,37 +509,36 @@ static int init_video_handler(unsigned char major, unsigned char minor, unsigned
|
||||
video_initialized = 1;
|
||||
|
||||
width = get_short(data);
|
||||
height = get_short(data+2);
|
||||
height = get_short(data + 2);
|
||||
g_screenWidth = width;
|
||||
g_screenHeight = height;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int video_palette_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
|
||||
{
|
||||
static int video_palette_handler(unsigned char major, unsigned char minor, unsigned char *data, int len,
|
||||
void *context) {
|
||||
short start, count;
|
||||
unsigned char *p;
|
||||
|
||||
start = get_short(data);
|
||||
count = get_short(data+2);
|
||||
count = get_short(data + 2);
|
||||
|
||||
p = data + 4;
|
||||
|
||||
mve_setpalette(p - 3*start, start, count);
|
||||
mve_setpalette(p - 3 * start, start, count);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int video_codemap_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
|
||||
{
|
||||
static int video_codemap_handler(unsigned char major, unsigned char minor, unsigned char *data, int len,
|
||||
void *context) {
|
||||
g_pCurMap = data;
|
||||
g_nMapLength = len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int video_data_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
|
||||
{
|
||||
static int video_data_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context) {
|
||||
short nFrameHot, nFrameCold;
|
||||
short nXoffset, nYoffset;
|
||||
short nXsize, nYsize;
|
||||
@ -555,15 +546,14 @@ static int video_data_handler(unsigned char major, unsigned char minor, unsigned
|
||||
unsigned char *temp;
|
||||
|
||||
nFrameHot = get_short(data);
|
||||
nFrameCold = get_short(data+2);
|
||||
nXoffset = get_short(data+4);
|
||||
nYoffset = get_short(data+6);
|
||||
nXsize = get_short(data+8);
|
||||
nYsize = get_short(data+10);
|
||||
nFlags = get_ushort(data+12);
|
||||
nFrameCold = get_short(data + 2);
|
||||
nXoffset = get_short(data + 4);
|
||||
nYoffset = get_short(data + 6);
|
||||
nXsize = get_short(data + 8);
|
||||
nYsize = get_short(data + 10);
|
||||
nFlags = get_ushort(data + 12);
|
||||
|
||||
if (nFlags & 1)
|
||||
{
|
||||
if (nFlags & 1) {
|
||||
temp = (unsigned char *)g_vBackBuf1;
|
||||
g_vBackBuf1 = g_vBackBuf2;
|
||||
g_vBackBuf2 = temp;
|
||||
@ -571,46 +561,33 @@ static int video_data_handler(unsigned char major, unsigned char minor, unsigned
|
||||
|
||||
/* convert the frame */
|
||||
if (g_truecolor) {
|
||||
decodeFrame16((unsigned char *)g_vBackBuf1, g_pCurMap, g_nMapLength, data+14, len-14);
|
||||
decodeFrame16((unsigned char *)g_vBackBuf1, g_pCurMap, g_nMapLength, data + 14, len - 14);
|
||||
} else {
|
||||
decodeFrame8(g_vBackBuf1, g_pCurMap, g_nMapLength, data+14, len-14);
|
||||
decodeFrame8(g_vBackBuf1, g_pCurMap, g_nMapLength, data + 14, len - 14);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int end_chunk_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
|
||||
{
|
||||
g_pCurMap=NULL;
|
||||
static int end_chunk_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context) {
|
||||
g_pCurMap = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static MVESTREAM *mve = NULL;
|
||||
|
||||
void MVE_ioCallbacks(mve_cb_Read io_read)
|
||||
{
|
||||
mve_read = io_read;
|
||||
}
|
||||
void MVE_ioCallbacks(mve_cb_Read io_read) { mve_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) {
|
||||
mve_alloc = mem_alloc;
|
||||
mve_free = mem_free;
|
||||
}
|
||||
|
||||
void MVE_sfCallbacks(mve_cb_ShowFrame showframe)
|
||||
{
|
||||
mve_showframe = showframe;
|
||||
}
|
||||
void MVE_sfCallbacks(mve_cb_ShowFrame showframe) { mve_showframe = showframe; }
|
||||
|
||||
void MVE_palCallbacks(mve_cb_SetPalette setpalette)
|
||||
{
|
||||
mve_setpalette = setpalette;
|
||||
}
|
||||
void MVE_palCallbacks(mve_cb_SetPalette setpalette) { mve_setpalette = setpalette; }
|
||||
|
||||
int MVE_rmPrepMovie(void *src, int x, int y, int track)
|
||||
{
|
||||
int MVE_rmPrepMovie(void *src, int x, int y, int track) {
|
||||
int i;
|
||||
|
||||
if (mve) {
|
||||
@ -655,9 +632,7 @@ int MVE_rmPrepMovie(void *src, int x, int y, int track)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void MVE_getVideoSpec(MVE_videoSpec *vSpec)
|
||||
{
|
||||
void MVE_getVideoSpec(MVE_videoSpec *vSpec) {
|
||||
vSpec->screenWidth = g_screenWidth;
|
||||
vSpec->screenHeight = g_screenHeight;
|
||||
vSpec->width = g_width;
|
||||
@ -665,11 +640,9 @@ void MVE_getVideoSpec(MVE_videoSpec *vSpec)
|
||||
vSpec->truecolor = g_truecolor;
|
||||
}
|
||||
|
||||
|
||||
int MVE_rmStepMovie()
|
||||
{
|
||||
static int init_timer=0;
|
||||
int cont=1;
|
||||
int MVE_rmStepMovie() {
|
||||
static int init_timer = 0;
|
||||
int cont = 1;
|
||||
|
||||
if (!timer_started)
|
||||
timer_start();
|
||||
@ -691,8 +664,7 @@ int MVE_rmStepMovie()
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MVE_rmEndMovie()
|
||||
{
|
||||
void MVE_rmEndMovie() {
|
||||
#ifdef AUDIO
|
||||
int i;
|
||||
#endif
|
||||
@ -711,19 +683,19 @@ void MVE_rmEndMovie()
|
||||
mve_free(mve_audio_buffers[i]);
|
||||
memset(mve_audio_buffers, 0, sizeof(mve_audio_buffers));
|
||||
memset(mve_audio_buflens, 0, sizeof(mve_audio_buflens));
|
||||
mve_audio_curbuf_curpos=0;
|
||||
mve_audio_bufhead=0;
|
||||
mve_audio_buftail=0;
|
||||
mve_audio_playing=0;
|
||||
mve_audio_canplay=0;
|
||||
mve_audio_compressed=0;
|
||||
mve_audio_curbuf_curpos = 0;
|
||||
mve_audio_bufhead = 0;
|
||||
mve_audio_buftail = 0;
|
||||
mve_audio_playing = 0;
|
||||
mve_audio_canplay = 0;
|
||||
mve_audio_compressed = 0;
|
||||
audiobuf_created = 0;
|
||||
#endif
|
||||
|
||||
mve_free(g_vBuffers);
|
||||
g_vBuffers = NULL;
|
||||
g_pCurMap=NULL;
|
||||
g_nMapLength=0;
|
||||
g_pCurMap = NULL;
|
||||
g_nMapLength = 0;
|
||||
videobuf_created = 0;
|
||||
video_initialized = 0;
|
||||
|
||||
@ -731,15 +703,9 @@ void MVE_rmEndMovie()
|
||||
mve = NULL;
|
||||
}
|
||||
|
||||
void MVE_rmHoldMovie() { timer_started = 0; }
|
||||
|
||||
void MVE_rmHoldMovie()
|
||||
{
|
||||
timer_started = 0;
|
||||
}
|
||||
|
||||
|
||||
void MVE_sndInit(int x)
|
||||
{
|
||||
void MVE_sndInit(int x) {
|
||||
#ifdef AUDIO
|
||||
if (x == -1)
|
||||
mve_audio_enabled = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user