From: <fu...@us...> - 2009-05-20 19:10:31
|
Revision: 6012 http://gemrb.svn.sourceforge.net/gemrb/?rev=6012&view=rev Author: fuzzie Date: 2009-05-20 19:10:20 +0000 (Wed, 20 May 2009) Log Message: ----------- rewrite MVE player Modified Paths: -------------- gemrb/trunk/NEWS gemrb/trunk/gemrb/plugins/MVEPlayer/CMakeLists.txt gemrb/trunk/gemrb/plugins/MVEPlayer/MVEPlay.cpp gemrb/trunk/gemrb/plugins/MVEPlayer/MVEPlay.h gemrb/trunk/gemrb/plugins/MVEPlayer/Makefile.am Added Paths: ----------- gemrb/trunk/gemrb/plugins/MVEPlayer/gstmvedemux.h gemrb/trunk/gemrb/plugins/MVEPlayer/mve.h gemrb/trunk/gemrb/plugins/MVEPlayer/mve_player.cpp gemrb/trunk/gemrb/plugins/MVEPlayer/mve_player.h gemrb/trunk/gemrb/plugins/MVEPlayer/mveaudiodec.cpp gemrb/trunk/gemrb/plugins/MVEPlayer/mvevideodec16.cpp gemrb/trunk/gemrb/plugins/MVEPlayer/mvevideodec8.cpp Removed Paths: ------------- gemrb/trunk/gemrb/plugins/MVEPlayer/decoder16.cpp gemrb/trunk/gemrb/plugins/MVEPlayer/decoder8.cpp gemrb/trunk/gemrb/plugins/MVEPlayer/decoders.h gemrb/trunk/gemrb/plugins/MVEPlayer/libmve.h gemrb/trunk/gemrb/plugins/MVEPlayer/mve_audio.cpp gemrb/trunk/gemrb/plugins/MVEPlayer/mve_audio.h gemrb/trunk/gemrb/plugins/MVEPlayer/mve_play.cpp gemrb/trunk/gemrb/plugins/MVEPlayer/mvelib.cpp gemrb/trunk/gemrb/plugins/MVEPlayer/mvelib.h Modified: gemrb/trunk/NEWS =================================================================== --- gemrb/trunk/NEWS 2009-05-20 15:55:26 UTC (rev 6011) +++ gemrb/trunk/NEWS 2009-05-20 19:10:20 UTC (rev 6012) @@ -21,6 +21,7 @@ - regeneration, hp bonuses, healing - animations and projectiles - various guiscripts + - rewritten MVE player - bugfixes Applied patches: Modified: gemrb/trunk/gemrb/plugins/MVEPlayer/CMakeLists.txt =================================================================== --- gemrb/trunk/gemrb/plugins/MVEPlayer/CMakeLists.txt 2009-05-20 15:55:26 UTC (rev 6011) +++ gemrb/trunk/gemrb/plugins/MVEPlayer/CMakeLists.txt 2009-05-20 19:10:20 UTC (rev 6012) @@ -1,3 +1,3 @@ -ADD_GEMRB_PLUGIN ( MVEPlayer decoder16.cpp decoder8.cpp mve_audio.cpp mve_play.cpp mvelib.cpp MVEPlay.cpp MVEPlayer.cpp MVEPlayerDesc.cpp ) +ADD_GEMRB_PLUGIN ( MVEPlayer mvevideodec8.cpp mvevideodec16.cpp mveaudiodec.cpp mve_player.cpp MVEPlay.cpp MVEPlayer.cpp MVEPlayerDesc.cpp ) INSTALL( TARGETS MVEPlayer DESTINATION ${PLUGIN_INSTALL_DIR} ) Modified: gemrb/trunk/gemrb/plugins/MVEPlayer/MVEPlay.cpp =================================================================== --- gemrb/trunk/gemrb/plugins/MVEPlayer/MVEPlay.cpp 2009-05-20 15:55:26 UTC (rev 6011) +++ gemrb/trunk/gemrb/plugins/MVEPlayer/MVEPlay.cpp 2009-05-20 19:10:20 UTC (rev 6012) @@ -28,7 +28,7 @@ #include "../Core/Audio.h" #include "../Core/Variables.h" #include "MVEPlay.h" -#include "libmve.h" +#include "mve_player.h" #include "../../includes/ie_types.h" static const char MVESignature[] = "Interplay MVE File\x1A"; @@ -134,55 +134,44 @@ } //Start Movie Playback frameCount = 0; - doPlay( str ); - return 0; + return doPlay( ); } -int MVEPlay::doPlay(const DataStream* mve) +int MVEPlay::doPlay() { - int result; int done = 0; - int bpp = 0; - MVE_videoSpec vSpec; + MVEPlayer player(this); memset( g_palette, 0, 768 ); - ieDword volume; - core->GetDictionary()->Lookup( "Volume Movie", volume ); - MVE_sndInit( core->GetAudioDrv()->CanPlay()?1:-1, volume ); - MVE_memCallbacks( malloc, free ); - MVE_ioCallbacks( fileRead ); - MVE_sfCallbacks( showFrame ); - MVE_palCallbacks( setPalette ); - MVE_audioCallbacks( setAudioStream, freeAudioStream, queueBuffer ) ; + //ieDword volume; + //core->GetDictionary()->Lookup( "Volume Movie", volume ); + player.sound_init( core->GetAudioDrv()->CanPlay() ); int w,h; video->InitMovieScreen(w,h); - MVE_rmPrepMovie( ( void * ) mve, -1, -1, 1 ); + player.video_init(w, h); - vSpec.screenWidth = w; - vSpec.screenHeight = h; + if (!player.start_playback()) { + printf("Failed to decode movie!\n"); + return 1; + } - MVE_getVideoSpec( &vSpec ); - bpp = vSpec.truecolor ? 16 : 8; + g_truecolor = player.is_truecolour(); - g_truecolor = vSpec.truecolor; - - while (!done && ( result = MVE_rmStepMovie() ) == 0) { + while (!done && player.next_frame()) { done = video->PollMovieEvents(); } - MVE_rmEndMovie(); - return 0; } -unsigned int MVEPlay::fileRead(void* handle, void* buf, unsigned int count) +unsigned int MVEPlay::fileRead(void* buf, unsigned int count) { unsigned numread; - numread = ( ( DataStream * ) handle )->Read( buf, count );//fread(buf, 1, count, (FILE *)handle); + numread = str->Read( buf, count ); return ( numread == count ); } Modified: gemrb/trunk/gemrb/plugins/MVEPlayer/MVEPlay.h =================================================================== --- gemrb/trunk/gemrb/plugins/MVEPlayer/MVEPlay.h 2009-05-20 15:55:26 UTC (rev 6011) +++ gemrb/trunk/gemrb/plugins/MVEPlayer/MVEPlay.h 2009-05-20 19:10:20 UTC (rev 6012) @@ -28,21 +28,23 @@ #include "../Core/Interface.h" class MVEPlay : public MoviePlayer { + friend class MVEPlayer; + private: DataStream* str; bool autoFree; bool validVideo; - static int doPlay(const DataStream* mve); - static unsigned int fileRead(void* handle, void* buf, unsigned int count); - static void showFrame(unsigned char* buf, unsigned int bufw, + int doPlay(); + unsigned int fileRead(void* buf, unsigned int count); + void showFrame(unsigned char* buf, unsigned int bufw, unsigned int bufh, unsigned int sx, unsigned int sy, unsigned int w, unsigned int h, unsigned int dstx, unsigned int dsty); - static void setPalette(unsigned char* p, unsigned start, unsigned count); - static int pollEvents(); - static int setAudioStream(); - static void freeAudioStream(int stream); - static void queueBuffer(int stream, unsigned short bits, + void setPalette(unsigned char* p, unsigned start, unsigned count); + int pollEvents(); + int setAudioStream(); + void freeAudioStream(int stream); + void queueBuffer(int stream, unsigned short bits, int channels, short* memory, int size, int samplerate); public: Modified: gemrb/trunk/gemrb/plugins/MVEPlayer/Makefile.am =================================================================== --- gemrb/trunk/gemrb/plugins/MVEPlayer/Makefile.am 2009-05-20 15:55:26 UTC (rev 6011) +++ gemrb/trunk/gemrb/plugins/MVEPlayer/Makefile.am 2009-05-20 19:10:20 UTC (rev 6012) @@ -6,10 +6,9 @@ MVEPlay.cpp \ MVEPlayer.cpp \ MVEPlayerDesc.cpp \ - decoder16.cpp \ - decoder8.cpp \ - mve_audio.cpp \ - mve_play.cpp \ - mvelib.cpp + mvevideodec8.cpp \ + mvevideodec16.cpp \ + mveaudiodec.cpp \ + mve_player.cpp -noinst_HEADERS = MVEPlayerDesc.h MVEPlay.h decoders.h libmve.h mve_audio.h mvelib.h +noinst_HEADERS = MVEPlayerDesc.h MVEPlay.h gstmvedemux.h mve.h mve_player.h Deleted: gemrb/trunk/gemrb/plugins/MVEPlayer/decoder16.cpp =================================================================== --- gemrb/trunk/gemrb/plugins/MVEPlayer/decoder16.cpp 2009-05-20 15:55:26 UTC (rev 6011) +++ gemrb/trunk/gemrb/plugins/MVEPlayer/decoder16.cpp 2009-05-20 19:10:20 UTC (rev 6012) @@ -1,671 +0,0 @@ -/* 16 bit decoding routines */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "decoders.h" - -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 genLoopkupTable(); - -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; - unsigned short * FramePtr = ( unsigned short * ) pFrame; - int length; - int op; - int i, j; - int xb, yb; - - if (!lookup_initialized) { - genLoopkupTable(); - } - - backBuf1 = ( unsigned short * ) g_vBackBuf1; - backBuf2 = ( unsigned short * ) g_vBackBuf2; - - xb = g_width >> 3; - yb = g_height >> 3; - - offset = pData[0] | ( pData[1] << 8 ); - - pOffData = pData + offset; - pEnd = pData + offset; - - pData += 2; - - pOrig = pData; - length = offset - 2; /*dataRemain-2;*/ - - 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); - */ - - op = ( ( *pMap ) >> 4 ) & 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 (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; - } -/* - if (( length - ( pData - pOrig ) ) != 0) { - fprintf( stderr, "DEBUG: junk left over: %d,%d,%d\n", - ( pData - pOrig ), length, ( length - ( pData - pOrig ) ) ); - } -*/ -} - -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 ); - ( *buf ) += 2; - return val; -} - -static void relClose(int i, int* x, int* y) -{ - int ma, mi; - - ma = i >> 4; - mi = i & 0xf; - - *x = mi - 8; - *y = ma - 8; -} - -static void relFar(int i, int sign, int* x, int* y) -{ - if (i < 56) { - *x = sign * ( 8 + ( i % 7 ) ); - *y = sign * ( i / 7 ); - } else { - *x = sign * ( -14 + ( i - 56 ) % 29 ); - *y = sign * ( 8 + ( i - 56 ) / 29 ); - } -} - -static int close_table[512]; -static int far_p_table[512]; -static int far_n_table[512]; - -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; - - relFar( i, 1, &x, &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; - } - - lookup_initialized = 1; -} - -static void copyFrame(unsigned short* pDest, unsigned short* pSrc) -{ - int 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; - unsigned short pattern = ( pat1 << 8 ) | pat0; - - 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; - unsigned short pel; - /* ORIGINAL VERSION IS BUGGY - int skip=1; - while (mask != 0) - { - pel = p[(mask & pat0) >> shift]; - pFrame[0] = pel; - pFrame[2] = pel; - pFrame[g_width + 0] = pel; - pFrame[g_width + 2] = pel; - pFrame += skip; - skip = 4 - skip; - mask <<= 2; - shift += 2; - } - */ - while (mask != 0) { - pel = p[( mask & pat0 ) >> shift]; - pFrame[0] = pel; - pFrame[1] = pel; - pFrame[g_width + 0] = pel; - pFrame[g_width + 1] = pel; - pFrame += 2; - mask <<= 2; - shift += 2; - } -} - -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) { - pel = p[( mask & pat ) >> shift]; - pFrame[0] = pel; - pFrame[1] = pel; - pFrame += 2; - mask <<= 2; - shift += 2; - } -} - -static void patternQuadrant4Pixels(unsigned short* pFrame, unsigned char pat0, - unsigned char pat1, unsigned char pat2, unsigned char pat3, - unsigned short* p) -{ - unsigned int mask = 0x00000003UL; - int shift = 0; - int i; - unsigned int pat = ( pat3 << 24 ) | - ( pat2 << 16 ) | - ( pat1 << 8 ) | - pat0; - - for (i = 0; i < 16; i++) { - pFrame[i & 3] = p[( pat & mask ) >> shift]; - - if (( i & 3 ) == 3) - pFrame += g_width; - - mask <<= 2; - shift += 2; - } -} - - -static void patternRow2Pixels(unsigned short* pFrame, unsigned char pat, - unsigned short* p) -{ - unsigned char mask = 0x01; - - while (mask != 0) { - *pFrame++ = p[( mask & pat ) ? 1 : 0]; - mask <<= 1; - } -} - -static void patternRow2Pixels2(unsigned short* pFrame, unsigned char pat, - unsigned short* p) -{ - unsigned short pel; - unsigned char mask = 0x1; - - /* ORIGINAL VERSION IS BUGGY - int skip=1; - while (mask != 0x10) - { - pel = p[(mask & pat) ? 1 : 0]; - pFrame[0] = pel; - pFrame[2] = pel; - pFrame[g_width + 0] = pel; - pFrame[g_width + 2] = pel; - pFrame += skip; - skip = 4 - skip; - mask <<= 1; - } - */ - while (mask != 0x10) { - pel = p[( mask & pat ) ? 1 : 0]; - - pFrame[0] = pel; - pFrame[1] = pel; - pFrame[g_width + 0] = pel; - pFrame[g_width + 1] = pel; - pFrame += 2; - - mask <<= 1; - } -} - -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]; - - 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) -{ - unsigned short p[4]; - unsigned char pat[16]; - int i, j, k; - int x, y; - unsigned short * pDstBak; - - pDstBak = *pFrame; - - switch (codeType) { - case 0x0: - copyFrame( *pFrame, *pFrame + ( backBuf2 - backBuf1 ) ); - case 0x1: - break; - case 0x2: - /* - relFar(*(*pOffData)++, 1, &x, &y); - */ - - k = *( *pOffData )++; - x = far_p_table[k * 2 + 0]; - y = far_p_table[k * 2 + 1]; - - copyFrame( *pFrame, *pFrame + x + y * g_width ); - -- * pDataRemain; - break; - case 0x3: - /* - relFar(*(*pOffData)++, -1, &x, &y); - */ - - k = *( *pOffData )++; - x = far_n_table[k * 2 + 0]; - y = far_n_table[k * 2 + 1]; - - copyFrame( *pFrame, *pFrame + x + y * g_width ); - -- * pDataRemain; - break; - case 0x4: - /* - relClose(*(*pOffData)++, &x, &y); - */ - - k = *( *pOffData )++; - x = close_table[k * 2 + 0]; - y = close_table[k * 2 + 1]; - - 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 ); - *pDataRemain -= 2; - break; - case 0x6: - fprintf( stderr, "STUB: encoding 6 not tested\n" ); - for (i = 0; i < 2; i++) { - *pFrame += 16; - if (++ * curXb == ( g_width >> 3 )) { - *pFrame += 7 * g_width; - *curXb = 0; - if (++ * curYb == ( g_height >> 3 )) - return; - } - } - break; - - case 0x7: - p[0] = GETPIXELI( pData, 0 ); - p[1] = GETPIXELI( pData, 0 ); - - 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++) { - patternRow2Pixels2( *pFrame, *( *pData ) & 0xf, p ); - *pFrame += 2 * g_width; - patternRow2Pixels2( *pFrame, *( *pData ) >> 4, p ); - ( *pData )++; - - *pFrame += 2 * g_width; - } - } - break; - - case 0x8: - p[0] = GETPIXEL( pData, 0 ); - - if (!( p[0] & 0x8000 )) { - for (i = 0; i < 4; i++) { - p[0] = GETPIXELI( pData, 0 ); - p[1] = GETPIXELI( pData, 0 ); - - pat[0] = ( *pData )[0]; - pat[1] = ( *pData )[1]; - ( *pData ) += 2; - - patternQuadrant2Pixels( *pFrame, pat[0], pat[1], p ); - - if (i & 1) - *pFrame -= ( 4 * g_width - 4 ); - else - *pFrame += 4 * g_width; - } - } else { - p[2] = GETPIXEL( pData, 8 ); - - if (!( p[2] & 0x8000 )) { - for (i = 0; i < 4; i++) { - if (( i & 1 ) == 0) { - p[0] = GETPIXELI( pData, 0 ); - p[1] = GETPIXELI( pData, 0 ); - } - pat[0] = *( *pData )++; - pat[1] = *( *pData )++; - patternQuadrant2Pixels( *pFrame, pat[0], pat[1], p ); - - if (i & 1) - *pFrame -= ( 4 * g_width - 4 ); - else - *pFrame += 4 * g_width; - } - } else { - for (i = 0; i < 8; i++) { - if (( i & 3 ) == 0) { - p[0] = GETPIXELI( pData, 0 ); - p[1] = GETPIXELI( pData, 0 ); - } - patternRow2Pixels( *pFrame, *( *pData ), p ); - ( *pData )++; - - *pFrame += g_width; - } - } - } - break; - - case 0x9: - p[0] = GETPIXELI( pData, 0 ); - p[1] = GETPIXELI( pData, 0 ); - p[2] = GETPIXELI( pData, 0 ); - p[3] = GETPIXELI( pData, 0 ); - - *pDataRemain -= 8; - - if (!( p[0] & 0x8000 )) { - if (!( p[2] & 0x8000 )) { - for (i = 0; i < 8; i++) { - pat[0] = ( *pData )[0]; - pat[1] = ( *pData )[1]; - ( *pData ) += 2; - patternRow4Pixels( *pFrame, pat[0], pat[1], p ); - *pFrame += g_width; - } - *pDataRemain -= 16; - } else { - patternRow4Pixels2( *pFrame, ( *pData )[0], p ); - *pFrame += 2 * g_width; - patternRow4Pixels2( *pFrame, ( *pData )[1], p ); - *pFrame += 2 * g_width; - patternRow4Pixels2( *pFrame, ( *pData )[2], p ); - *pFrame += 2 * g_width; - patternRow4Pixels2( *pFrame, ( *pData )[3], p ); - - ( *pData ) += 4; - *pDataRemain -= 4; - } - } 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++) { - pat[0] = ( *pData )[0]; - pat[1] = ( *pData )[1]; - - ( *pData ) += 2; - - patternRow4Pixels( *pFrame, pat[0], pat[1], p ); - *pFrame += g_width; - patternRow4Pixels( *pFrame, pat[0], pat[1], p ); - *pFrame += g_width; - } - *pDataRemain -= 8; - } - } - break; - - case 0xa: - p[0] = GETPIXEL( pData, 0 ); - - 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 ); - p[3] = GETPIXELI( pData, 0 ); - pat[0] = ( *pData )[0]; - pat[1] = ( *pData )[1]; - pat[2] = ( *pData )[2]; - pat[3] = ( *pData )[3]; - - ( *pData ) += 4; - - patternQuadrant4Pixels( *pFrame, pat[0], pat[1], pat[2], - pat[3], p ); - - if (i & 1) - *pFrame -= ( 4 * g_width - 4 ); - else - *pFrame += 4 * g_width; - } - } else { - p[0] = GETPIXEL( pData, 16 ); - - 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 ); - p[3] = GETPIXELI( pData, 0 ); - } - - pat[0] = ( *pData )[0]; - pat[1] = ( *pData )[1]; - pat[2] = ( *pData )[2]; - pat[3] = ( *pData )[3]; - - ( *pData ) += 4; - - patternQuadrant4Pixels( *pFrame, pat[0], pat[1], - pat[2], pat[3], p ); - - if (i & 1) - *pFrame -= ( 4 * g_width - 4 ); - else - *pFrame += 4 * g_width; - } - } 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 ); - p[3] = GETPIXELI( pData, 0 ); - } - - pat[0] = ( *pData )[0]; - pat[1] = ( *pData )[1]; - patternRow4Pixels( *pFrame, pat[0], pat[1], p ); - *pFrame += g_width; - - ( *pData ) += 2; - } - } - } - break; - - case 0xb: - for (i = 0; i < 8; i++) { - for (j = 0; j < 8; j++) - (*pFrame)[j] = GETPIXEL ( pData, 2*j ); - *pFrame += g_width; - *pData += 16; - *pDataRemain -= 16; - } - break; - - case 0xc: - 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]; - } - *pFrame += g_width; - } - *pData += 8; - *pDataRemain -= 8; - } - break; - - case 0xd: - 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]; - } - } - - *pFrame += 4 * g_width; - - *pData += 4; - *pDataRemain -= 4; - } - break; - - case 0xe: - p[0] = GETPIXEL( pData, 0 ); - - for (i = 0; i < 8; i++) { - for (j = 0; j < 8; j++) { - ( *pFrame )[j] = p[0]; - } - - *pFrame += g_width; - } - - *pData += 2; - *pDataRemain -= 2; - - break; - - case 0xf: - 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]; - } - *pFrame += g_width; - } - - *pData += 4; - *pDataRemain -= 4; - break; - - default: - break; - } - - *pFrame = pDstBak + 8; -} Deleted: gemrb/trunk/gemrb/plugins/MVEPlayer/decoder8.cpp =================================================================== --- gemrb/trunk/gemrb/plugins/MVEPlayer/decoder8.cpp 2009-05-20 15:55:26 UTC (rev 6011) +++ gemrb/trunk/gemrb/plugins/MVEPlayer/decoder8.cpp 2009-05-20 19:10:20 UTC (rev 6012) @@ -1,789 +0,0 @@ -/* 8 bit decoding routines */ - -#include <stdio.h> -#include <string.h> - -#include "decoders.h" - -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) -{ - 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++) { - 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 ); - 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 ); - - ++pMap; - --mapRemain; - } - - pFrame += 7 * g_width; - } -} - -static void relClose(int i, int* x, int* y) -{ - int ma, mi; - - ma = i >> 4; - mi = i & 0xf; - - *x = mi - 8; - *y = ma - 8; -} - -static void relFar(int i, int sign, int* x, int* y) -{ - if (i < 56) { - *x = sign * ( 8 + ( i % 7 ) ); - *y = sign * ( i / 7 ); - } else { - *x = sign * ( -14 + ( i - 56 ) % 29 ); - *y = sign * ( 8 + ( i - 56 ) / 29 ); - } -} - -/* 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) -{ - int i; - - for (i = 0; i < 8; i++) { - memcpy( pDest, pSrc, 8 ); - pDest += g_width; - pSrc += g_width; - } -} - -// 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; - unsigned short pattern = ( pat1 << 8 ) | pat0; - - while (mask != 0) { - *pFrame++ = p[( mask & pattern ) >> shift]; - mask <<= 2; - shift += 2; - } -} - -// 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; - unsigned char pel; - - while (mask != 0) { - pel = p[( mask & pat0 ) >> shift]; - pFrame[0] = pel; - pFrame[1] = pel; - pFrame[g_width + 0] = pel; - pFrame[g_width + 1] = pel; - pFrame += 2; - mask <<= 2; - shift += 2; - } -} - -// 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; - unsigned char pel; - - while (mask != 0) { - pel = p[( mask & pat ) >> shift]; - pFrame[0] = pel; - pFrame[1] = pel; - pFrame += 2; - mask <<= 2; - shift += 2; - } -} - -// 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) -{ - unsigned int mask = 0x00000003UL; - int shift = 0; - int i; - unsigned int pat = ( pat3 << 24 ) | - ( pat2 << 16 ) | - ( pat1 << 8 ) | - pat0; - - for (i = 0; i < 16; i++) { - pFrame[i & 3] = p[( pat & mask ) >> shift]; - - if (( i & 3 ) == 3) - pFrame += g_width; - - mask <<= 2; - shift += 2; - } -} - -// 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; - - 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) -{ - unsigned char pel; - unsigned char mask = 0x1; - - while (mask != 0x10) { - pel = p[( mask & pat ) ? 1 : 0]; - - pFrame[0] = pel; // upper-left - pFrame[1] = pel; // upper-right - pFrame[g_width + 0] = pel; // lower-left - pFrame[g_width + 1] = pel; // lower-right - pFrame += 2; - - mask <<= 1; - } -} - -// 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) -{ - 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++) { - pel = p[( pat & mask ) ? 1 : 0]; - - pFrame[j + i * g_width] = pel; - - mask <<= 1; - } - } -} - -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; - int x, y; - - /* Data is processed in 8x8 pixel blocks. - There are 16 ways to encode each block. - */ - - switch (codeType) { - case 0x0: - /* block is copied from block in current frame */ - copyFrame( *pFrame, - *pFrame + - ( ( unsigned char * ) g_vBackBuf2 - - ( unsigned char * ) g_vBackBuf1 ) ); - case 0x1: - /* block is unchanged from two frames ago */ - *pFrame += 8; - break; - - case 0x2: - /* Block is copied from nearby (below and/or to the right) within the - new frame. The offset within the buffer from which to grab the - patch of 8 pixels is given by grabbing a byte B from the data - stream, which is broken into a positive x and y offset according - to the following mapping: - if B < 56: - x = 8 + (B % 7) - y = B / 7 - else - x = -14 + ((B - 56) % 29) - y = 8 + ((B - 56) / 29) - */ - relFar( *( *pData )++, 1, &x, &y ); - copyFrame( *pFrame, *pFrame + x + y * g_width ); - *pFrame += 8; - -- * pDataRemain; - break; - - case 0x3: - /* Block is copied from nearby (above and/or to the left) within the - new frame. - if B < 56: - x = -(8 + (B % 7)) - y = -(B / 7) - else - x = -(-14 + ((B - 56) % 29)) - y = -( 8 + ((B - 56) / 29)) - */ - relFar( *( *pData )++, -1, &x, &y ); - copyFrame( *pFrame, *pFrame + x + y * g_width ); - *pFrame += 8; - -- * pDataRemain; - break; - - case 0x4: - /* Similar to 0x2 and 0x3, except this method copies from the - "current" frame, rather than the "new" frame, and instead of the - lopsided mapping they use, this one uses one which is symmetric - and centered around the top-left corner of the block. This uses - only 1 byte still, though, so the range is decreased, since we - have to encode all directions in a single byte. The byte we pull - from the data stream, I'll call B. Call the highest 4 bits of B - BH and the lowest 4 bytes BL. Then the offset from which to copy - the data is: - x = -8 + BL - y = -8 + BH - */ - relClose( *( *pData )++, &x, &y ); - copyFrame( *pFrame, - *pFrame + - ( ( unsigned char * ) g_vBackBuf2 - - ( unsigned char * ) g_vBackBuf1 ) + - x + - y * g_width ); - *pFrame += 8; - -- * pDataRemain; - break; - - case 0x5: - /* Similar to 0x4, but instead of one byte for the offset, this uses - two bytes to encode a larger range, the first being the x offset - as a signed 8-bit value, and the second being the y offset as a - signed 8-bit value. - */ - x = ( signed char ) * ( *pData )++; - y = ( signed char ) * ( *pData )++; - copyFrame( *pFrame, - *pFrame + - ( ( unsigned char * ) g_vBackBuf2 - - ( unsigned char * ) g_vBackBuf1 ) + - x + - y * g_width ); - *pFrame += 8; - *pDataRemain -= 2; - break; - - case 0x6: - /* I can't figure out how any file containing a block of this type - could still be playable, since it appears that it would leave the - internal bookkeeping in an inconsistent state in the BG player - code. Ahh, well. Perhaps it was a bug in the BG player code that - just didn't happen to be exposed by any of the included movies. - Anyway, this skips the next two blocks, doing nothing to them. - 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++) { - *pFrame += 16; - if (++ * curXb == ( g_width >> 3 )) { - *pFrame += 7 * g_width; - *curXb = 0; - if (++ * curYb == ( g_height >> 3 )) - return; - } - } - break; - - case 0x7: - /* Ok, here's where it starts to get really...interesting. This is, - incidentally, the part where they started using self-modifying - code. So, most of the following encodings are "patterned" blocks, - where we are given a number of pixel values and then bitmapped - values to specify which pixel values belong to which squares. For - this encoding, we are given the following in the data stream: - P0 P1 - These are pixel values (i.e. 8-bit indices into the palette). If - P0 <= P1, we then get 8 more bytes from the data stream, one for - each row in the block: - B0 B1 B2 B3 B4 B5 B6 B7 - For each row, the leftmost pixel is represented by the low-order - bit, and the rightmost by the high-order bit. Use your imagination - in between. If a bit is set, the pixel value is P1 and if it is - unset, the pixel value is P0. - So, for example, if we had: - 11 22 fe 83 83 83 83 83 83 fe - This would represent the following layout: - 11 22 22 22 22 22 22 22 ; fe == 11111110 - 22 22 11 11 11 11 11 22 ; 83 == 10000011 - 22 22 11 11 11 11 11 22 ; 83 == 10000011 - 22 22 11 11 11 11 11 22 ; 83 == 10000011 - 22 22 11 11 11 11 11 22 ; 83 == 10000011 - 22 22 11 11 11 11 11 22 ; 83 == 10000011 - 22 22 11 11 11 11 11 22 ; 83 == 10000011 - 11 22 22 22 22 22 22 22 ; fe == 11111110 - If, on the other hand, P0 > P1, we get two more bytes from the - data stream: - B0 B1 - Each of these bytes contains two 4-bit patterns. These patterns - work like the patterns above with 8 bytes, except each bit - represents a 2x2 pixel region. - B0 contains the pattern for the top two rows and B1 contains - the pattern for the bottom two rows. Note that the low-order - nibble of each byte contains the pattern for the upper of the - two rows that that byte controls. - So if we had: - 22 11 7e 83 - The output would be: - 11 11 22 22 22 22 22 22 ; e == 1 1 1 0 - 11 11 22 22 22 22 22 22 ; - 22 22 22 22 22 22 11 11 ; 7 == 0 1 1 1 - 22 22 22 22 22 22 11 11 ; - 11 11 11 11 11 11 22 22 ; 3 == 1 0 0 0 - 11 11 11 11 11 11 22 22 ; - 22 22 22 22 11 11 11 11 ; 8 == 0 0 1 1 - 22 22 22 22 11 11 11 11 ; - */ - p[0] = *( *pData )++; - p[1] = *( *pData )++; - 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++) { - patternRow2Pixels2( *pFrame, *( *pData ) & 0xf, p ); - *pFrame += 2 * g_width; - patternRow2Pixels2( *pFrame, *( *pData )++ >> 4, p ); - *pFrame += 2 * g_width; - } - } - *pFrame -= ( 8 * g_width - 8 ); - break; - - case 0x8: - /* Ok, this one is basically like encoding 0x7, only more - complicated. Again, we start out by getting two bytes on the data - stream: - P0 P1 - if P0 <= P1 then we get the following from the data stream: - B0 B1 - P2 P3 B2 B3 - P4 P5 B4 B5 - P6 P7 B6 B7 - P0 P1 and B0 B1 are used for the top-left corner, P2 P3 B2 B3 for - the bottom-left corner, P4 P5 B4 B5 for the top-right, P6 P7 B6 B7 - for the bottom-right. (So, each codes for a 4x4 pixel array.) - Since we have 16 bits in B0 B1, there is one bit for each pixel in - the array. The convention for the bit-mapping is, again, left to - right and top to bottom. - So, basically, the top-left quarter of the block is an arbitrary - pattern with 2 pixels, the bottom-left a different arbitrary - pattern with 2 different pixels, and so on. - For example if the next 16 bytes were: - 00 22 f9 9f 44 55 aa 55 11 33 cc 33 66 77 01 ef - We'd draw: - 22 22 22 22 | 11 11 33 33 ; f = 1111, c = 1100 - 22 00 00 22 | 11 11 33 33 ; 9 = 1001, c = 1100 - 22 00 00 22 | 33 33 11 11 ; 9 = 1001, 3 = 0011 - 22 22 22 22 | 33 33 11 11 ; f = 1111, 3 = 0011 - ------------+------------ - 44 55 44 55 | 66 66 66 66 ; a = 1010, 0 = 0000 - 44 55 44 55 | 77 66 66 66 ; a = 1010, 1 = 0001 - 55 44 55 44 | 66 77 77 77 ; 5 = 0101, e = 1110 - 55 44 55 44 | 77 77 77 77 ; 5 = 0101, f = 1111 - I've added a dividing line in the above to clearly delineate the - quadrants. - Now, if P0 > P1 then we get 10 more bytes from the data stream: - B0 B1 B2 B3 P2 P3 B4 B5 B6 B7 - Now, if P2 <= P3, then the first six bytes [P0 P1 B0 B1 B2 B3] - represent the left half of the block and the latter six bytes - [P2 P3 B4 B5 B6 B7] represent the right half. - For example: - 22 00 01 37 f7 31 11 66 8c e6 73 31 - yeilds: - 22 22 22 22 | 11 11 11 66 ; 0: 0000 | 8: 1000 - 00 22 22 22 | 11 11 66 66 ; 1: 0001 | C: 1100 - 00 00 22 22 | 11 66 66 66 ; 3: 0011 | e: 1110 - 00 00 00 22 | 11 66 11 66 ; 7: 0111 | 6: 0101 - 00 00 00 00 | 66 66 66 11 ; f: 1111 | 7: 0111 - 00 00 00 22 | 66 66 11 11 ; 7: 0111 | 3: 0011 - 00 00 22 22 | 66 66 11 11 ; 3: 0011 | 3: 0011 - 00 22 22 22 | 66 11 11 11 ; 1: 0001 | 1: 0001 - On the other hand, if P0 > P1 and P2 > P3, then - [P0 P1 B0 B1 B2 B3] represent the top half of the - block and [P2 P3 B4 B5 B6 B7] represent the bottom half. - For example: - 22 00 cc 66 33 19 66 11 18 24 42 81 - yeilds: - 22 22 00 00 22 22 00 00 ; cc: 11001100 - 22 00 00 22 22 00 00 22 ; 66: 01100110 - 00 00 22 22 00 00 22 22 ; 33: 00110011 - 00 22 22 00 00 22 22 22 ; 19: 00011001 - ----------------------- - 66 66 66 11 11 66 66 66 ; 18: 00011000 - 66 66 11 66 66 11 66 66 ; 24: 00100100 - 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]) { - // four quadrant case - for (i = 0; i < 4; i++) { - p[0] = *( *pData )++; - p[1] = *( *pData )++; - pat[0] = *( *pData )++; - pat[1] = *( *pData )++; - patternQuadrant2Pixels( *pFrame, pat[0], pat[1], p ); - - // alternate between moving down and moving up and right - if (i & 1) - *pFrame += 4 - 4 * g_width; // up and right - else - *pFrame += 4 * g_width; // down - - } - } else if (( *pData )[6] <= ( *pData )[7]) { - // split horizontal - for (i = 0; i < 4; i++) { - if (( i & 1 ) == 0) { - p[0] = *( *pData )++; - p[1] = *( *pData )++; - } - pat[0] = *( *pData )++; - pat[1] = *( *pData )++; - patternQuadrant2Pixels( *pFrame, pat[0], pat[1], p ); - - if (i & 1) - *pFrame -= ( 4 * g_width - 4 ); - else - *pFrame += 4 * g_width; - } - } else { - // split vertical - 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 ); - } - break; - - case 0x9: - /* Similar to the previous 2 encodings, only more complicated. And - it will get worse before it gets better. No longer are we dealing - with patterns over two pixel values. Now we are dealing with - patterns over 4 pixel values with 2 bits assigned to each pixel - (or block of pixels). - So, first on the data stream are our 4 pixel values: - P0 P1 P2 P3 - Now, if P0 <= P1 AND P2 <= P3, we get 16 bytes of pattern, each - 2 bits representing a 1x1 pixel (00=P0, 01=P1, 10=P2, 11=P3). The - ordering is again left to right and top to bottom. The most - significant bits represent the left side at the top, and so on. - If P0 <= P1 AND P2 > P3, we get 4 bytes of pattern, each 2 bits - representing a 2x2 pixel. Ordering is left to right and top to - bottom. - if P0 > P1 AND P2 <= P3, we get 8 bytes of pattern, each 2 bits - representing a 2x1 pixel (i.e. 2 pixels wide, and 1 high). - 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]) { - p[0] = *( *pData )++; - p[1] = *( *pData )++; - p[2] = *( *pData )++; - p[3] = *( *pData )++; - - 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 { - p[0] = *( *pData )++; - p[1] = *( *pData )++; - p[2] = *( *pData )++; - p[3] = *( *pData )++; - - patternRow4Pixels2( *pFrame, *( *pData )++, p ); - *pFrame += 2 * g_width; - patternRow4Pixels2( *pFrame, *( *pData )++, p ); - *pFrame += 2 * g_width; - patternRow4Pixels2( *pFrame, *( *pData )++, p ); - *pFrame += 2 * g_width; - patternRow4Pixels2( *pFrame, *( *pData )++, p ); - *pFrame -= ( 6 * g_width - 8 ); - } - } 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++) { - pat[0] = *( *pData )++; - patternRow4Pixels2x1( *pFrame, pat[0], p ); - *pFrame += g_width; - } - - *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++) { - pat[0] = *( *pData )++; - pat[1] = *( *pData )++; - patternRow4Pixels( *pFrame, pat[0], pat[1], p ); - *pFrame += g_width; - patternRow4Pixels( *pFrame, pat[0], pat[1], p ); - *pFrame += g_width; - } - - *pFrame -= ( 8 * g_width - 8 ); - } - } - break; - - case 0xa: - /* Similar to the previous, only a little more complicated. - We are still dealing with patterns over 4 pixel values with 2 bits - assigned to each pixel (or block of pixels). - So, first on the data stream are our 4 pixel values: - P0 P1 P2 P3 - Now, if P0 <= P1, the block is divided into 4 quadrants, ordered - (as with opcode 0x8) TL, BL, TR, BR. In this case the next data - in the data stream should be: - B0 B1 B2 B3 - P4 P5 P6 P7 B4 B5 B6 B7 - P8 P9 P10 P11 B8 B9 B10 B11 - P12 P13 P14 P15 B12 B13 B14 B15 - Each 2 bits represent a 1x1 pixel (00=P0, 01=P1, 10=P2, 11=P3). - The ordering is again left to right and top to bottom. The most - significant bits represent the right side at the top, and so on. - If P0 > P1 then the next data on the data stream is: - B0 B1 B2 B3 B4 B5 B6 B7 - P4 P5 P6 P7 B8 B9 B10 B11 B12 B13 B14 B15 - Now, in this case, if P4 <= P5, - [P0 P1 P2 P3 B0 B1 B2 B3 B4 B5 B6 B7] represent the left half of - the block and the other bytes represent the right half. If P4 > - 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++) { - p[0] = *( *pData )++; - p[1] = *( *pData )++; - p[2] = *( *pData )++; - p[3] = *( *pData )++; - pat[0] = *( *pData )++; - pat[1] = *( *pData )++; - pat[2] = *( *pData )++; - pat[3] = *( *pData )++; - - patternQuadrant4Pixels( *pFrame, pat[0], pat[1], pat[2], - pat[3], p ); - - if (i & 1) - *pFrame -= ( 4 * g_width - 4 ); - else - *pFrame += 4 * g_width; - } - } else { - if (( *pData )[12] <= ( *pData )[13]) { - // split vertical - for (i = 0; i < 4; i++) { - if (( i & 1 ) == 0) { - p[0] = *( *pData )++; - p[1] = *( *pData )++; - p[2] = *( *pData )++; - p[3] = *( *pData )++; - } - - pat[0] = *( *pData )++; - pat[1] = *( *pData )++; - pat[2] = *( *pData )++; - pat[3] = *( *pData )++; - - patternQuadrant4Pixels( *pFrame, pat[0], pat[1], - pat[2], pat[3], p ); - - if (i & 1) - *pFrame -= ( 4 * g_width - 4 ); - else - *pFrame += 4 * g_width; - } - } else { - // split horizontal - for (i = 0; i < 8; i++) { - if (( i & 3 ) == 0) { - p[0] = *( *pData )++; - p[1] = *( *pData )++; - p[2] = *( *pData )++; - p[3] = *( *pData )++; - } - - pat[0] = *( *pData )++; - pat[1] = *( *pData )++; - patternRow4Pixels( *pFrame, pat[0], pat[1], p ); - *pFrame += g_width; - } - - *pFrame -= ( 8 * g_width - 8 ); - } - } - break; - - case 0xb: - /* In this encoding we get raw pixel data in the data stream -- 64 - bytes of pixel data. 1 byte for each pixel, and in the standard - order (l->r, t->b). - */ - for (i = 0; i < 8; i++) { - memcpy( *pFrame, *pData, 8 ); - *pFrame += g_width; - *pData += 8; - *pDataRemain -= 8; - } - *pFrame -= ( 8 * g_width - 8 ); - break; - - case 0xc: - /* In this encoding we get raw pixel data in the data stream -- 16 - 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]; - } - *pFrame += g_width; - } - *pData += 4; - *pDataRemain -= 4; - } - *pFrame -= ( 8 * g_width - 8 ); - break; - - case 0xd: - /* In this encoding we get raw pixel data in the data stream -- 4 - 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]; - } - } - *pFrame += 4 * g_width; - *pData += 2; - *pDataRemain -= 2; - } - *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++) { - memset( *pFrame, **pData, 8 ); - *pFrame += g_width; - } - ++ * pData; - -- * pDataRemain; - *pFrame -= ( 8 * g_width - 8 ); - break; - - case 0xf: - /* This encoding represents a "dithered" frame, which is - checkerboarded with alternate pixels of two colors. We get 2 - bytes of pixel data from the data stream, and these bytes are - alternated: - P0 P1 P0 P1 P0 P1 P0 P1 - P1 P0 P1 P0 P1 P0 P1 P0 - ... - 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]; - } - *pFrame += g_width; - } - *pData += 2; - *pDataRemain -= 2; - *pFrame -= ( 8 * g_width - 8 ); - break; - - default: - break; - } -} Deleted: gemrb/trunk/gemrb/plugins/MVEPlayer/decoders.h =================================================================== --- gemrb/trunk/gemrb/plugins/MVEPlayer/decoders.h 2009-05-20 15:55:26 UTC (rev 6011) +++ gemrb/trunk/gemrb/plugins/MVEPlayer/decoders.h 2009-05-20 19:10:20 UTC (rev 6012) @@ -1,18 +0,0 @@ -/* - * - * INTERNAL header - not to be included outside of libmve - * - */ - -#ifndef _DECODERS_H -#define _DECODERS_H - -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); - -#endif // _DECODERS_H Added: gemrb/trunk/gemrb/plugins/MVEPlayer/gstmvedemux.h =================================================================== --- gemrb/trunk/gemrb/plugins/MVEPlayer/gstmvedemux.h (rev 0) +++ gemrb/trunk/gemrb/plugins/MVEPlayer/gstmvedemux.h 2009-05-20 19:10:20 UTC (rev 6012) @@ -0,0 +1,141 @@ +/* + * GStreamer demultiplexer plugin for Interplay MVE movie files + * + * Copyright (C) 2006 Jens Granseuer <je...@gm...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_MVE_DEMUX_H__ +#define __GST_MVE_DEMUX_H__ + +#include "../../includes/win32def.h" +#include "../../includes/globals.h" + +#define G_UNLIKELY(x) (x) +#define GST_WARNING printf +#define GST_ERROR printf + +/* Define GET function for unaligned memory */ +#define _GST_GET(__data, __idx, __size, __shift) \ + (((guint##__size) (((guint8 *) (__data))[__idx])) << __shift) + +/** + * GST_READ_UINT16_LE: + * @data: memory location + * + * Read a 16 bit unsigned integer value in little endian format from the memory buffer. + */ +#define GST_READ_UINT16_LE(data) (_GST_GET (data, 1, 16, 8) | \ + _GST_GET (data, 0, 16, 0)) + +/** + * GST_READ_UINT32_LE: + * @data: memory location + * + * Read a 32 bit unsigned integer value in little endian format from the memory buffer. + */ +#define GST_READ_UINT32_LE(data) (_GST_GET (data, 3, 32, 24) | \ + _GST_GET (data, 2, 32, 16) | \ + _GST_GET (data, 1, 32, 8) | \ + _GST_GET (data, 0, 32, 0)) + +/*#include <gst/gst.h> +#include <gst/base/gstadapter.h> + +G_BEGIN_DECLS + +#define GST_TYPE_MVE_DEMUX \ + (gst_mve_demux_get_type()) +#define GST_MVE_DEMUX(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MVE_DEMUX,GstMveDemux)) +#define GST_MVE_DEMUX_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MVE_DEMUX,GstMveDemuxClass)) +#define GST_IS_MVE_DEMUX(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MVE_DEMUX)) +#define GST_IS_MVE_DEMUX_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MVE_DEMUX))*/ + +typedef int gint; +typedef gint gboolean; +typedef ieByte guint8; +typedef ieWord guint16; +typedef ieDword guint32; + +/*typedef struct _GstMveDemux GstMveDemux; +typedef struct _GstMveDemuxClass GstMveDemuxClass;*/ +typedef struct _GstMveDemuxStream GstMveDemuxStream; + +/*struct _GstMveDemux +{ + GstElement element; + + GstPad *sinkpad; + + GstMveDemuxStream *video_stream; + GstMveDemuxStream *audio_stream; + + gint state;*/ + + /* time per frame (1/framerate) */ +/* GstClockTime frame_duration;*/ + + /* push based variables */ +/* guint16 needed_bytes; + GstAdapter *adapter;*/ + + /* size of current chunk */ +/* guint32 chunk_size;*/ + /* offset in current chunk */ +/* guint32 chunk_offset; +};*/ + +/*struct _GstMveDemuxClass +{ + GstElementClass parent_class; +};*/ + +struct _GstMveDemuxStream { + /* shared properties */ + /*GstCaps *caps; + GstPad *pad; + GstClockTime last_ts;*/ + /*gint64 offset;*/ + + /* video properties */ + guint16 width; + guint16 height; + /*guint8 bpp;*/ /* bytes per pixel */ + guint8 *code_map; + /*gboolean code_map_avail;*/ + guint8 *back_buf1; + guint8 *back_buf2; + guint32 max_block_offset; + /*GstBuffer *palette; + GstBuffer *buffer;*/ + + /* audio properties */ + /*guint16 sample_rate; + guint16 n_channels; + guint16 sample_size; + gboolean compression;*/ +}; + +/*GType gst_mve_demux_get_type (void); + +G_END_DECLS*/ + +#endif /* __GST_MVE_DEMUX_H__ */ Deleted: gemrb/trunk/gemrb/plugins/MVEPlayer/libmve.h =================================================================== --- gemrb/trunk/gemrb/plugins/MVEPlayer/libmve.h 2009-05-20 15:55:26 UTC (rev 6011) +++ gemrb/trunk/gemrb/plugins/MVEPlayer/libmve.h 2009-05-20 19:10:20 UTC (rev 6012) @@ -1,49 +0,0 @@ -#ifndef _LIBMVE_H -#define _LIBMVE_H - -#define MVE_ERR_EOF 1 - -typedef struct { - int screenWidth; - int screenHeight; - int width; - int height; - int truecolor; -} MVE_videoSpec; - -int MVE_rmPrepMovie(void* stream, int x, int y, int track); -int MVE_rmStepMovie(); -void MVE_rmHoldMovie(); -void MVE_rmEndMovie(); - -void MVE_getVideoSpec(MVE_videoSpec* vSpec); - -void MVE_sndInit(int x, unsigned short volume); - -typedef unsigned int (*mve_cb_Read)(void* stream, void* buffer, - unsigned int count); - -typedef void*(*mve_cb_Alloc)(size_t 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_SetPalette)(unsigned char* p, unsigned int start, - unsigned int count); - -typedef int (*mve_cb_CreateAudioStream)(); -typedef void (*mve_cb_FreeAudioStream)(int stream); -typedef void (*mve_cb_QueueBuffer)(int stream, unsigned short bits, - int channels, short* memory,int size, int samplerate); - -void MVE_ioCallbacks(mve_cb_Read io_read); -void MVE_memCallbacks(mve_cb_Alloc mem_alloc, mve_cb_Free mem_free); -void MVE_sfCallbacks(mve_cb_ShowFrame showframe); -void MVE_palCallbacks(mve_cb_SetPalette setpalette); -void MVE_audioCallbacks(mve_cb_CreateAudioStream createaudiostream, - mve_cb_FreeAudioStream freeaudiostream, - mve_cb_QueueBuffer queuebuffer); - -#endif /* _LIBMVE_H */ Added: gemrb/trunk/gemrb/plugins/MVEPlayer/mve.h =================================================================== --- gemrb/trunk/gemrb/plugins/MVEPlayer/mve.h (rev 0) +++ gemrb/trunk/gemrb/plugins/MVEPlayer/mve.h 2009-05-20 19:10:20 UTC (rev 6012) @@ -0,0 +1,64 @@ +/* + * Interplay MVE movie definitions + * + * Copyright (C) 2006 Jens Granseuer <je...@gm...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __MVE_H__ +#define __MVE_H__ + +#define MVE_PREAMBLE "Interplay MVE File\032\000\032\000\000\001\063\021" +#define MVE_PREAMBLE_SIZE 26 + +#define MVE_PALETTE_COUNT 256 + +#define MVE_DEFAULT_AUDIO_STREAM 0x01 + +/* MVE chunk types */ +#define MVE_CHUNK_INIT_AUDIO 0x0000 +#define MVE_CHUNK_AUDIO_ONLY 0x0001 +#define MVE_CHUNK_INIT_VIDEO 0x0002 +#define MVE_CHUNK_VIDEO 0x0003 +#define MVE_CHUNK_SHUTDOWN 0x0004 +#define MVE_CHUNK_END 0x0005 + +/* MVE segment opcodes */ +#define MVE_OC_END_OF_STREAM 0x00 +#define MVE_OC_END_OF_CHUNK 0x01 +#define MVE_OC_CREATE_TIMER 0x02 +#define MVE_OC_AUDIO_BUFFERS 0x03 +#define MVE_OC_PLAY_AUDIO 0x04 +#define MVE_OC_VIDEO_BUFFERS 0x05 +#define MVE_OC_PLAY_VIDEO 0x07 +#define MVE_OC_AUDIO_DATA 0x08 +#define MVE_OC_AUDIO_SILENCE 0x09 +#define MVE_OC_VIDEO_MODE 0x0A +#define MVE_OC_PALETTE 0x0C +#define MVE_OC_PALETTE_COMPRESSED 0x0D +#define MVE_OC_CODE_MAP 0x0F +#define MVE_OC_VIDEO_DATA 0x11 + +/* audio flags */ +#define MVE_AUDIO_STEREO 0x0001 +#define MVE_AUDIO_16BIT 0x0002 +#define MVE_AUDIO_COMPRESSED 0x0004 + +/* video flags */ +#define MVE_VIDEO_DELTA_FRAME 0x0001 + +#endif /* __MVE_H__ */ Deleted: gemrb/trunk/gemrb/plugins/MVEPlayer/mve_audio.cpp =================================================================== --- gemrb/trunk/gemrb/plugins/MVEPlayer/mve_audio.cpp 2009-05-20 15:55:26 UTC (rev 6011) +++ gemrb/trunk/gemrb/plugins/MVEPlayer/mve_audio.cpp 2009-05-20 19:10:20 UTC (rev 6012) @@ -1,58 +0,0 @@ -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 -}; - -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 processSwath(short* fout, unsigned char* data, int swath, - int* offsets) -{ - int i; - for (i = 0; i < swath; i++) { - offsets[i & 1] += audio_exp_table[data[i]]; - sendWord( &fout, offsets[i & 1] ); - } -} - -void mveaudio_uncompress(short* buffer, unsigned char* data, int /*length*/) -{ - int nCurOffsets[2]; - int swath; - - data += 4; - swath = getWord( &data ) / 2; - nCurOffsets[0] = getWord( &data ); - nCurOffsets[1] = getWord( &data ); - sendWord( &buffer, nCurOffsets[0] ); - sendWord( &buffer, nCurOffsets[1] ); - processSwath( buffer, data, swath, nCurOffsets ); -} Deleted: gemrb/trunk/gemrb/plugins/MVEPlayer/mve_audio.h =================================================================== --- gemrb/trunk/gemrb/plugins/MVEPlayer/mve_audio.h 2009-05-20 15:55:26 UTC (rev 6011) +++ ... [truncated message content] |