move commong code into separate source file (more could be done, but it's a start)
svn-id: r13358
This commit is contained in:
parent
a9789acfc6
commit
4466a85598
6 changed files with 252 additions and 409 deletions
|
@ -21,3 +21,160 @@
|
||||||
|
|
||||||
#include "common/stdafx.h"
|
#include "common/stdafx.h"
|
||||||
#include "graphics/animation.h"
|
#include "graphics/animation.h"
|
||||||
|
#include "common/file.h"
|
||||||
|
#include "sound/audiostream.h"
|
||||||
|
|
||||||
|
namespace Graphics {
|
||||||
|
|
||||||
|
BaseAnimationState::BaseAnimationState(SoundMixer *snd, OSystem *sys, int width, int height)
|
||||||
|
: _snd(snd), _sys(sys), MOVIE_WIDTH(width), MOVIE_HEIGHT(height) {
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseAnimationState::~BaseAnimationState() {
|
||||||
|
#ifdef USE_MPEG2
|
||||||
|
_snd->stopHandle(bgSound);
|
||||||
|
if (decoder)
|
||||||
|
mpeg2_close(decoder);
|
||||||
|
delete mpgfile;
|
||||||
|
delete sndfile;
|
||||||
|
#ifndef BACKEND_8BIT
|
||||||
|
_sys->hide_overlay();
|
||||||
|
free(overlay);
|
||||||
|
#endif
|
||||||
|
if (bgSoundStream)
|
||||||
|
delete bgSoundStream;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef BACKEND_8BIT
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build 'Best-Match' RGB lookup table
|
||||||
|
*/
|
||||||
|
void BaseAnimationState::buildLookup(int p, int lines) {
|
||||||
|
int y, cb;
|
||||||
|
int r, g, b, ii;
|
||||||
|
|
||||||
|
if (p >= maxPalnum)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (p != curpal) {
|
||||||
|
curpal = p;
|
||||||
|
cr = 0;
|
||||||
|
pos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cr > BITDEPTH)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (ii = 0; ii < lines; ii++) {
|
||||||
|
r = (-16 * 256 + (int) (256 * 1.596) * ((cr << SHIFT) - 128)) / 256;
|
||||||
|
for (cb = 0; cb <= BITDEPTH; cb++) {
|
||||||
|
g = (-16 * 256 - (int) (0.813 * 256) * ((cr << SHIFT) - 128) - (int) (0.391 * 256) * ((cb << SHIFT) - 128)) / 256;
|
||||||
|
b = (-16 * 256 + (int) (2.018 * 256) * ((cb << SHIFT) - 128)) / 256;
|
||||||
|
|
||||||
|
for (y = 0; y <= BITDEPTH; y++) {
|
||||||
|
int idx, bst = 0;
|
||||||
|
int dis = 2 * SQR(r - palettes[p].pal[0]) + 4 * SQR(g - palettes[p].pal[1]) + SQR(b - palettes[p].pal[2]);
|
||||||
|
|
||||||
|
for (idx = 1; idx < 256; idx++) {
|
||||||
|
long d2 = 2 * SQR(r - palettes[p].pal[4 * idx]) + 4 * SQR(g - palettes[p].pal[4 * idx + 1]) + SQR(b - palettes[p].pal[4 * idx + 2]);
|
||||||
|
if (d2 < dis) {
|
||||||
|
bst = idx;
|
||||||
|
dis = d2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lut2[pos++] = bst;
|
||||||
|
|
||||||
|
r += (1 << SHIFT);
|
||||||
|
g += (1 << SHIFT);
|
||||||
|
b += (1 << SHIFT);
|
||||||
|
}
|
||||||
|
r -= (BITDEPTH+1)*(1 << SHIFT);
|
||||||
|
}
|
||||||
|
cr++;
|
||||||
|
if (cr > BITDEPTH)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BaseAnimationState::checkPaletteSwitch() {
|
||||||
|
// if we have reached the last image with this palette, switch to new one
|
||||||
|
if (framenum == palettes[palnum].end) {
|
||||||
|
unsigned char *l = lut2;
|
||||||
|
palnum++;
|
||||||
|
setPalette(palettes[palnum].pal);
|
||||||
|
lutcalcnum = (BITDEPTH + palettes[palnum].end - (framenum + 1) + 2) / (palettes[palnum].end - (framenum + 1) + 2);
|
||||||
|
lut2 = lut;
|
||||||
|
lut = l;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
OverlayColor *BaseAnimationState::lookup = 0;
|
||||||
|
|
||||||
|
void BaseAnimationState::buildLookup() {
|
||||||
|
if (lookup)
|
||||||
|
return;
|
||||||
|
|
||||||
|
lookup = (OverlayColor *)calloc((BITDEPTH+1) * (BITDEPTH+1) * 256, sizeof(OverlayColor));
|
||||||
|
|
||||||
|
int y, cb, cr;
|
||||||
|
int r, g, b;
|
||||||
|
int pos = 0;
|
||||||
|
|
||||||
|
for (cr = 0; cr <= BITDEPTH; cr++) {
|
||||||
|
for (cb = 0; cb <= BITDEPTH; cb++) {
|
||||||
|
for (y = 0; y < 256; y++) {
|
||||||
|
r = ((y - 16) * 256 + (int) (256 * 1.596) * ((cr << SHIFT) - 128)) / 256;
|
||||||
|
g = ((y - 16) * 256 - (int) (0.813 * 256) * ((cr << SHIFT) - 128) - (int) (0.391 * 256) * ((cb << SHIFT) - 128)) / 256;
|
||||||
|
b = ((y - 16) * 256 + (int) (2.018 * 256) * ((cb << SHIFT) - 128)) / 256;
|
||||||
|
|
||||||
|
if (r < 0) r = 0;
|
||||||
|
else if (r > 255) r = 255;
|
||||||
|
if (g < 0) g = 0;
|
||||||
|
else if (g > 255) g = 255;
|
||||||
|
if (b < 0) b = 0;
|
||||||
|
else if (b > 255) b = 255;
|
||||||
|
|
||||||
|
lookup[pos++] = _sys->RGBToColor(r, g, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseAnimationState::plotYUV(OverlayColor *lut, int width, int height, byte *const *dat) {
|
||||||
|
|
||||||
|
OverlayColor *ptr = overlay + (MOVIE_HEIGHT - height) / 2 * MOVIE_WIDTH + (MOVIE_WIDTH - width) / 2;
|
||||||
|
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
int ypos = 0;
|
||||||
|
int cpos = 0;
|
||||||
|
int linepos = 0;
|
||||||
|
|
||||||
|
for (y = 0; y < height; y += 2) {
|
||||||
|
for (x = 0; x < width; x += 2) {
|
||||||
|
int i = ((((dat[2][cpos] + ROUNDADD) >> SHIFT) * (BITDEPTH+1)) + ((dat[1][cpos] + ROUNDADD)>>SHIFT)) * 256;
|
||||||
|
cpos++;
|
||||||
|
|
||||||
|
ptr[linepos ] = lut[i + dat[0][ ypos ]];
|
||||||
|
ptr[MOVIE_WIDTH + linepos++] = lut[i + dat[0][width + ypos++]];
|
||||||
|
ptr[linepos ] = lut[i + dat[0][ ypos ]];
|
||||||
|
ptr[MOVIE_WIDTH + linepos++] = lut[i + dat[0][width + ypos++]];
|
||||||
|
|
||||||
|
}
|
||||||
|
linepos += (2 * MOVIE_WIDTH - width);
|
||||||
|
ypos += width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // End of namespace Graphics
|
||||||
|
|
|
@ -22,6 +22,11 @@
|
||||||
#ifndef GRAPHICS_ANIMATION_H
|
#ifndef GRAPHICS_ANIMATION_H
|
||||||
#define GRAPHICS_ANIMATION_H
|
#define GRAPHICS_ANIMATION_H
|
||||||
|
|
||||||
|
#include "common/scummsys.h"
|
||||||
|
#include "sound/mixer.h"
|
||||||
|
|
||||||
|
class AudioStream;
|
||||||
|
|
||||||
// Uncomment this if you are using libmpeg2 0.3.1.
|
// Uncomment this if you are using libmpeg2 0.3.1.
|
||||||
// #define USE_MPEG2_0_3_1
|
// #define USE_MPEG2_0_3_1
|
||||||
|
|
||||||
|
@ -50,7 +55,85 @@ typedef sequence_t mpeg2_sequence_t;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef BACKEND_8BIT
|
||||||
|
#define SQR(x) ((x) * (x))
|
||||||
|
#define SHIFT 3
|
||||||
|
#else
|
||||||
|
#define SHIFT 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BITDEPTH (1 << (8 - SHIFT))
|
||||||
|
#define ROUNDADD (1 << (SHIFT - 1))
|
||||||
|
|
||||||
|
#define BUFFER_SIZE 4096
|
||||||
|
|
||||||
|
|
||||||
|
namespace Graphics {
|
||||||
|
|
||||||
|
class BaseAnimationState {
|
||||||
|
protected:
|
||||||
|
const int MOVIE_WIDTH;
|
||||||
|
const int MOVIE_HEIGHT;
|
||||||
|
|
||||||
|
SoundMixer *_snd;
|
||||||
|
OSystem *_sys;
|
||||||
|
|
||||||
|
uint framenum;
|
||||||
|
uint frameskipped;
|
||||||
|
uint32 ticks;
|
||||||
|
|
||||||
|
#ifdef USE_MPEG2
|
||||||
|
mpeg2dec_t *decoder;
|
||||||
|
const mpeg2_info_t *info;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
File *mpgfile;
|
||||||
|
File *sndfile;
|
||||||
|
|
||||||
|
byte buffer[BUFFER_SIZE];
|
||||||
|
|
||||||
|
PlayingSoundHandle bgSound;
|
||||||
|
AudioStream *bgSoundStream;
|
||||||
|
|
||||||
|
#ifdef BACKEND_8BIT
|
||||||
|
int palnum;
|
||||||
|
int maxPalnum;
|
||||||
|
|
||||||
|
byte lookup[2][(BITDEPTH+1) * (BITDEPTH+1) * (BITDEPTH+1)];
|
||||||
|
byte *lut;
|
||||||
|
byte *lut2;
|
||||||
|
int lutcalcnum;
|
||||||
|
|
||||||
|
int curpal;
|
||||||
|
int cr;
|
||||||
|
int pos;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
uint cnt;
|
||||||
|
uint end;
|
||||||
|
byte pal[4 * 256];
|
||||||
|
} palettes[50];
|
||||||
|
#else
|
||||||
|
static OverlayColor *lookup;
|
||||||
|
OverlayColor *overlay;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public:
|
||||||
|
BaseAnimationState(SoundMixer *snd, OSystem *sys, int width, int height);
|
||||||
|
virtual ~BaseAnimationState();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
#ifdef BACKEND_8BIT
|
||||||
|
void buildLookup(int p, int lines);
|
||||||
|
bool checkPaletteSwitch();
|
||||||
|
virtual void setPalette(byte *pal) = 0;
|
||||||
|
#else
|
||||||
|
void buildLookup(void);
|
||||||
|
void plotYUV(OverlayColor *lut, int width, int height, byte *const *dat);
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // End of namespace Graphics
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -22,31 +22,16 @@
|
||||||
#include "common/stdafx.h"
|
#include "common/stdafx.h"
|
||||||
#include "common/file.h"
|
#include "common/file.h"
|
||||||
#include "sword1/animation.h"
|
#include "sword1/animation.h"
|
||||||
|
#include "sound/audiostream.h"
|
||||||
|
|
||||||
|
|
||||||
#define MOVIE_WIDTH 640
|
|
||||||
#define MOVIE_HEIGHT 400
|
|
||||||
|
|
||||||
namespace Sword1 {
|
namespace Sword1 {
|
||||||
|
|
||||||
AnimationState::AnimationState(Screen *scr, SoundMixer *snd, OSystem *sys)
|
AnimationState::AnimationState(Screen *scr, SoundMixer *snd, OSystem *sys)
|
||||||
: _scr(scr), _snd(snd), _sys(sys) {
|
: BaseAnimationState(snd, sys, 640, 400), _scr(scr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimationState::~AnimationState() {
|
AnimationState::~AnimationState() {
|
||||||
#ifdef USE_MPEG2
|
|
||||||
_snd->stopHandle(bgSound);
|
|
||||||
if (decoder)
|
|
||||||
mpeg2_close(decoder);
|
|
||||||
delete mpgfile;
|
|
||||||
delete sndfile;
|
|
||||||
#ifndef BACKEND_8BIT
|
|
||||||
_sys->hide_overlay();
|
|
||||||
free(overlay);
|
|
||||||
#endif
|
|
||||||
if (bgSoundStream)
|
|
||||||
delete bgSoundStream;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AnimationState::init(const char *name) {
|
bool AnimationState::init(const char *name) {
|
||||||
|
@ -155,137 +140,11 @@ bool AnimationState::init(const char *name) {
|
||||||
|
|
||||||
|
|
||||||
#ifdef BACKEND_8BIT
|
#ifdef BACKEND_8BIT
|
||||||
/**
|
|
||||||
* Build 'Best-Match' RGB lookup table
|
|
||||||
*/
|
|
||||||
void AnimationState::buildLookup(int p, int lines) {
|
|
||||||
int y, cb;
|
|
||||||
int r, g, b, ii;
|
|
||||||
|
|
||||||
if (p >= maxPalnum)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (p != curpal) {
|
|
||||||
curpal = p;
|
|
||||||
cr = 0;
|
|
||||||
pos = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cr > BITDEPTH)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (ii = 0; ii < lines; ii++) {
|
|
||||||
r = (-16 * 256 + (int) (256 * 1.596) * ((cr << SHIFT) - 128)) / 256;
|
|
||||||
for (cb = 0; cb <= BITDEPTH; cb++) {
|
|
||||||
g = (-16 * 256 - (int) (0.813 * 256) * ((cr << SHIFT) - 128) - (int) (0.391 * 256) * ((cb << SHIFT) - 128)) / 256;
|
|
||||||
b = (-16 * 256 + (int) (2.018 * 256) * ((cb << SHIFT) - 128)) / 256;
|
|
||||||
|
|
||||||
for (y = 0; y <= BITDEPTH; y++) {
|
|
||||||
int idx, bst = 0;
|
|
||||||
int dis = 2 * SQR(r - palettes[p].pal[0]) + 4 * SQR(g - palettes[p].pal[1]) + SQR(b - palettes[p].pal[2]);
|
|
||||||
|
|
||||||
for (idx = 1; idx < 256; idx++) {
|
|
||||||
long d2 = 2 * SQR(r - palettes[p].pal[4 * idx]) + 4 * SQR(g - palettes[p].pal[4 * idx + 1]) + SQR(b - palettes[p].pal[4 * idx + 2]);
|
|
||||||
if (d2 < dis) {
|
|
||||||
bst = idx;
|
|
||||||
dis = d2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
lut2[pos++] = bst;
|
|
||||||
|
|
||||||
r += (1 << SHIFT);
|
|
||||||
g += (1 << SHIFT);
|
|
||||||
b += (1 << SHIFT);
|
|
||||||
}
|
|
||||||
r -= (BITDEPTH+1)*(1 << SHIFT);
|
|
||||||
}
|
|
||||||
cr++;
|
|
||||||
if (cr > BITDEPTH)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AnimationState::checkPaletteSwitch() {
|
|
||||||
// if we have reached the last image with this palette, switch to new one
|
|
||||||
if (framenum == palettes[palnum].end) {
|
|
||||||
unsigned char *l = lut2;
|
|
||||||
palnum++;
|
|
||||||
setPalette(palettes[palnum].pal);
|
|
||||||
lutcalcnum = (BITDEPTH + palettes[palnum].end - (framenum + 1) + 2) / (palettes[palnum].end - (framenum + 1) + 2);
|
|
||||||
lut2 = lut;
|
|
||||||
lut = l;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AnimationState::setPalette(byte *pal) {
|
void AnimationState::setPalette(byte *pal) {
|
||||||
_sys->setPalette(pal, 0, 256);
|
_sys->setPalette(pal, 0, 256);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
OverlayColor *AnimationState::lookup = 0;
|
|
||||||
|
|
||||||
void AnimationState::buildLookup() {
|
|
||||||
if (lookup)
|
|
||||||
return;
|
|
||||||
|
|
||||||
lookup = (OverlayColor *)calloc((BITDEPTH+1) * (BITDEPTH+1) * 256, sizeof(OverlayColor));
|
|
||||||
|
|
||||||
int y, cb, cr;
|
|
||||||
int r, g, b;
|
|
||||||
int pos = 0;
|
|
||||||
|
|
||||||
for (cr = 0; cr <= BITDEPTH; cr++) {
|
|
||||||
for (cb = 0; cb <= BITDEPTH; cb++) {
|
|
||||||
for (y = 0; y < 256; y++) {
|
|
||||||
r = ((y - 16) * 256 + (int) (256 * 1.596) * ((cr << SHIFT) - 128)) / 256;
|
|
||||||
g = ((y - 16) * 256 - (int) (0.813 * 256) * ((cr << SHIFT) - 128) - (int) (0.391 * 256) * ((cb << SHIFT) - 128)) / 256;
|
|
||||||
b = ((y - 16) * 256 + (int) (2.018 * 256) * ((cb << SHIFT) - 128)) / 256;
|
|
||||||
|
|
||||||
if (r < 0) r = 0;
|
|
||||||
else if (r > 255) r = 255;
|
|
||||||
if (g < 0) g = 0;
|
|
||||||
else if (g > 255) g = 255;
|
|
||||||
if (b < 0) b = 0;
|
|
||||||
else if (b > 255) b = 255;
|
|
||||||
|
|
||||||
lookup[pos++] = _sys->RGBToColor(r, g, b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AnimationState::plotYUV(OverlayColor *lut, int width, int height, byte *const *dat) {
|
|
||||||
|
|
||||||
OverlayColor *ptr = overlay + (MOVIE_HEIGHT - height) / 2 * MOVIE_WIDTH + (MOVIE_WIDTH - width) / 2;
|
|
||||||
|
|
||||||
int x, y;
|
|
||||||
|
|
||||||
int ypos = 0;
|
|
||||||
int cpos = 0;
|
|
||||||
int linepos = 0;
|
|
||||||
|
|
||||||
for (y = 0; y < height; y += 2) {
|
|
||||||
for (x = 0; x < width; x += 2) {
|
|
||||||
int i = ((((dat[2][cpos] + ROUNDADD) >> SHIFT) * (BITDEPTH+1)) + ((dat[1][cpos] + ROUNDADD)>>SHIFT)) * 256;
|
|
||||||
cpos++;
|
|
||||||
|
|
||||||
ptr[linepos ] = lut[i + dat[0][ ypos ]];
|
|
||||||
ptr[MOVIE_WIDTH + linepos++] = lut[i + dat[0][width + ypos++]];
|
|
||||||
ptr[linepos ] = lut[i + dat[0][ ypos ]];
|
|
||||||
ptr[MOVIE_WIDTH + linepos++] = lut[i + dat[0][width + ypos++]];
|
|
||||||
|
|
||||||
}
|
|
||||||
linepos += (2 * MOVIE_WIDTH - width);
|
|
||||||
ypos += width;
|
|
||||||
}
|
|
||||||
|
|
||||||
_sys->copy_rect_overlay(overlay, MOVIE_WIDTH, 0, 40, MOVIE_WIDTH, MOVIE_HEIGHT);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool AnimationState::decodeFrame() {
|
bool AnimationState::decodeFrame() {
|
||||||
|
@ -344,13 +203,16 @@ bool AnimationState::decodeFrame() {
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
if ((bgSoundStream == NULL) || ((_snd->getChannelElapsedTime(bgSound) * 12) / 1000 < framenum + 1) || frameskipped > 10) {
|
if ((bgSoundStream == NULL) ||
|
||||||
|
((_snd->getChannelElapsedTime(bgSound) * 12) / 1000 < framenum + 1) || frameskipped > 10) {
|
||||||
if (frameskipped > 10) {
|
if (frameskipped > 10) {
|
||||||
warning("force frame %i redraw", framenum);
|
warning("force frame %i redraw", framenum);
|
||||||
frameskipped = 0;
|
frameskipped = 0;
|
||||||
}
|
}
|
||||||
plotYUV(lookup, sequence_i->width, sequence_i->height, info->display_fbuf->buf);
|
plotYUV(lookup, sequence_i->width, sequence_i->height, info->display_fbuf->buf);
|
||||||
|
|
||||||
|
_sys->copy_rect_overlay(overlay, MOVIE_WIDTH, 0, 40, MOVIE_WIDTH, MOVIE_HEIGHT);
|
||||||
|
|
||||||
if (bgSoundStream) {
|
if (bgSoundStream) {
|
||||||
while ((_snd->getChannelElapsedTime(bgSound) * 12) / 1000 < framenum)
|
while ((_snd->getChannelElapsedTime(bgSound) * 12) / 1000 < framenum)
|
||||||
_sys->delay_msecs(10);
|
_sys->delay_msecs(10);
|
||||||
|
|
|
@ -27,71 +27,15 @@
|
||||||
#include "sword1/screen.h"
|
#include "sword1/screen.h"
|
||||||
#include "sword1/sound.h"
|
#include "sword1/sound.h"
|
||||||
|
|
||||||
#include "sound/audiostream.h"
|
|
||||||
|
|
||||||
namespace Sword1 {
|
namespace Sword1 {
|
||||||
|
|
||||||
|
class AnimationState : public Graphics::BaseAnimationState {
|
||||||
#ifdef BACKEND_8BIT
|
|
||||||
#define SQR(x) ((x) * (x))
|
|
||||||
#define SHIFT 3
|
|
||||||
#else
|
|
||||||
#define SHIFT 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define BITDEPTH (1 << (8 - SHIFT))
|
|
||||||
#define ROUNDADD (1 << (SHIFT - 1))
|
|
||||||
|
|
||||||
#define BUFFER_SIZE 4096
|
|
||||||
|
|
||||||
class AnimationState {
|
|
||||||
private:
|
private:
|
||||||
Screen *_scr;
|
Screen *_scr;
|
||||||
SoundMixer *_snd;
|
|
||||||
OSystem *_sys;
|
|
||||||
|
|
||||||
uint framenum;
|
|
||||||
uint frameskipped;
|
|
||||||
uint32 ticks;
|
|
||||||
|
|
||||||
#ifdef USE_MPEG2
|
|
||||||
mpeg2dec_t *decoder;
|
|
||||||
const mpeg2_info_t *info;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
File *mpgfile;
|
|
||||||
File *sndfile;
|
|
||||||
|
|
||||||
byte buffer[BUFFER_SIZE];
|
|
||||||
|
|
||||||
PlayingSoundHandle bgSound;
|
|
||||||
AudioStream *bgSoundStream;
|
|
||||||
|
|
||||||
#ifdef BACKEND_8BIT
|
|
||||||
int palnum;
|
|
||||||
int maxPalnum;
|
|
||||||
|
|
||||||
byte lookup[2][(BITDEPTH+1) * (BITDEPTH+1) * (BITDEPTH+1)];
|
|
||||||
byte *lut;
|
|
||||||
byte *lut2;
|
|
||||||
int lutcalcnum;
|
|
||||||
|
|
||||||
int curpal;
|
|
||||||
int cr;
|
|
||||||
int pos;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
uint cnt;
|
|
||||||
uint end;
|
|
||||||
byte pal[4 * 256];
|
|
||||||
} palettes[50];
|
|
||||||
#else
|
|
||||||
static OverlayColor *lookup;
|
|
||||||
OverlayColor * overlay;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
AnimationState(Screen *scr, SoundMixer *snd, OSystem *sys);
|
AnimationState(Screen *scr, SoundMixer *snd, OSystem *sys);
|
||||||
~AnimationState();
|
~AnimationState();
|
||||||
|
|
||||||
|
@ -101,12 +45,7 @@ public:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
#ifdef BACKEND_8BIT
|
#ifdef BACKEND_8BIT
|
||||||
void buildLookup(int p, int lines);
|
|
||||||
bool checkPaletteSwitch();
|
|
||||||
void setPalette(byte *pal);
|
void setPalette(byte *pal);
|
||||||
#else
|
|
||||||
void buildLookup(void);
|
|
||||||
void plotYUV(OverlayColor *lut, int width, int height, byte *const *dat);
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -32,29 +32,13 @@
|
||||||
#include "sword2/driver/menu.h"
|
#include "sword2/driver/menu.h"
|
||||||
#include "sword2/driver/render.h"
|
#include "sword2/driver/render.h"
|
||||||
|
|
||||||
#define MOVIE_WIDTH 640
|
|
||||||
#define MOVIE_HEIGHT 480
|
|
||||||
|
|
||||||
namespace Sword2 {
|
namespace Sword2 {
|
||||||
|
|
||||||
AnimationState::AnimationState(Sword2Engine *vm)
|
AnimationState::AnimationState(Sword2Engine *vm)
|
||||||
: _vm(vm), _snd(_vm->_mixer), _sys(_vm->_system) {
|
: BaseAnimationState(_vm->_mixer, _vm->_system, 640, 480), _vm(vm) {
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimationState::~AnimationState() {
|
AnimationState::~AnimationState() {
|
||||||
#ifdef USE_MPEG2
|
|
||||||
_snd->stopHandle(bgSound);
|
|
||||||
if (decoder)
|
|
||||||
mpeg2_close(decoder);
|
|
||||||
delete mpgfile;
|
|
||||||
delete sndfile;
|
|
||||||
#ifndef BACKEND_8BIT
|
|
||||||
_sys->hide_overlay();
|
|
||||||
free(overlay);
|
|
||||||
#endif
|
|
||||||
if (bgSoundStream)
|
|
||||||
delete bgSoundStream;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AnimationState::init(const char *name) {
|
bool AnimationState::init(const char *name) {
|
||||||
|
@ -163,70 +147,6 @@ bool AnimationState::init(const char *name) {
|
||||||
|
|
||||||
|
|
||||||
#ifdef BACKEND_8BIT
|
#ifdef BACKEND_8BIT
|
||||||
/**
|
|
||||||
* Build 'Best-Match' RGB lookup table
|
|
||||||
*/
|
|
||||||
void AnimationState::buildLookup(int p, int lines) {
|
|
||||||
int y, cb;
|
|
||||||
int r, g, b, ii;
|
|
||||||
|
|
||||||
if (p >= maxPalnum)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (p != curpal) {
|
|
||||||
curpal = p;
|
|
||||||
cr = 0;
|
|
||||||
pos = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cr > BITDEPTH)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (ii = 0; ii < lines; ii++) {
|
|
||||||
r = (-16 * 256 + (int) (256 * 1.596) * ((cr << SHIFT) - 128)) / 256;
|
|
||||||
for (cb = 0; cb <= BITDEPTH; cb++) {
|
|
||||||
g = (-16 * 256 - (int) (0.813 * 256) * ((cr << SHIFT) - 128) - (int) (0.391 * 256) * ((cb << SHIFT) - 128)) / 256;
|
|
||||||
b = (-16 * 256 + (int) (2.018 * 256) * ((cb << SHIFT) - 128)) / 256;
|
|
||||||
|
|
||||||
for (y = 0; y <= BITDEPTH; y++) {
|
|
||||||
int idx, bst = 0;
|
|
||||||
int dis = 2 * SQR(r - palettes[p].pal[0]) + 4 * SQR(g - palettes[p].pal[1]) + SQR(b - palettes[p].pal[2]);
|
|
||||||
|
|
||||||
for (idx = 1; idx < 256; idx++) {
|
|
||||||
long d2 = 2 * SQR(r - palettes[p].pal[4 * idx]) + 4 * SQR(g - palettes[p].pal[4 * idx + 1]) + SQR(b - palettes[p].pal[4 * idx + 2]);
|
|
||||||
if (d2 < dis) {
|
|
||||||
bst = idx;
|
|
||||||
dis = d2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
lut2[pos++] = bst;
|
|
||||||
|
|
||||||
r += (1 << SHIFT);
|
|
||||||
g += (1 << SHIFT);
|
|
||||||
b += (1 << SHIFT);
|
|
||||||
}
|
|
||||||
r -= (BITDEPTH+1)*(1 << SHIFT);
|
|
||||||
}
|
|
||||||
cr++;
|
|
||||||
if (cr > BITDEPTH)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AnimationState::checkPaletteSwitch() {
|
|
||||||
// if we have reached the last image with this palette, switch to new one
|
|
||||||
if (framenum == palettes[palnum].end) {
|
|
||||||
unsigned char *l = lut2;
|
|
||||||
palnum++;
|
|
||||||
setPalette(palettes[palnum].pal);
|
|
||||||
lutcalcnum = (BITDEPTH + palettes[palnum].end - (framenum + 1) + 2) / (palettes[palnum].end - (framenum + 1) + 2);
|
|
||||||
lut2 = lut;
|
|
||||||
lut = l;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AnimationState::setPalette(byte *pal) {
|
void AnimationState::setPalette(byte *pal) {
|
||||||
_vm->_graphics->setPalette(0, 256, pal, RDPAL_INSTANT);
|
_vm->_graphics->setPalette(0, 256, pal, RDPAL_INSTANT);
|
||||||
|
@ -234,64 +154,6 @@ void AnimationState::setPalette(byte *pal) {
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
OverlayColor *AnimationState::lookup = 0;
|
|
||||||
|
|
||||||
void AnimationState::buildLookup() {
|
|
||||||
if (lookup)
|
|
||||||
return;
|
|
||||||
|
|
||||||
lookup = (OverlayColor *)calloc((BITDEPTH+1) * (BITDEPTH+1) * 256, sizeof(OverlayColor));
|
|
||||||
|
|
||||||
int y, cb, cr;
|
|
||||||
int r, g, b;
|
|
||||||
int pos = 0;
|
|
||||||
|
|
||||||
for (cr = 0; cr <= BITDEPTH; cr++) {
|
|
||||||
for (cb = 0; cb <= BITDEPTH; cb++) {
|
|
||||||
for (y = 0; y < 256; y++) {
|
|
||||||
r = ((y - 16) * 256 + (int) (256 * 1.596) * ((cr << SHIFT) - 128)) / 256;
|
|
||||||
g = ((y - 16) * 256 - (int) (0.813 * 256) * ((cr << SHIFT) - 128) - (int) (0.391 * 256) * ((cb << SHIFT) - 128)) / 256;
|
|
||||||
b = ((y - 16) * 256 + (int) (2.018 * 256) * ((cb << SHIFT) - 128)) / 256;
|
|
||||||
|
|
||||||
if (r < 0) r = 0;
|
|
||||||
else if (r > 255) r = 255;
|
|
||||||
if (g < 0) g = 0;
|
|
||||||
else if (g > 255) g = 255;
|
|
||||||
if (b < 0) b = 0;
|
|
||||||
else if (b > 255) b = 255;
|
|
||||||
|
|
||||||
lookup[pos++] = _sys->RGBToColor(r, g, b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AnimationState::plotYUV(OverlayColor *lut, int width, int height, byte *const *dat) {
|
|
||||||
|
|
||||||
OverlayColor *ptr = overlay + (MOVIE_HEIGHT - height) / 2 * MOVIE_WIDTH + (MOVIE_WIDTH - width) / 2;
|
|
||||||
|
|
||||||
int x, y;
|
|
||||||
|
|
||||||
int ypos = 0;
|
|
||||||
int cpos = 0;
|
|
||||||
int linepos = 0;
|
|
||||||
|
|
||||||
for (y = 0; y < height; y += 2) {
|
|
||||||
for (x = 0; x < width; x += 2) {
|
|
||||||
int i = ((((dat[2][cpos] + ROUNDADD) >> SHIFT) * (BITDEPTH+1)) + ((dat[1][cpos] + ROUNDADD)>>SHIFT)) * 256;
|
|
||||||
cpos++;
|
|
||||||
|
|
||||||
ptr[linepos ] = lut[i + dat[0][ ypos ]];
|
|
||||||
ptr[RENDERWIDE + linepos++] = lut[i + dat[0][width + ypos++]];
|
|
||||||
ptr[linepos ] = lut[i + dat[0][ ypos ]];
|
|
||||||
ptr[RENDERWIDE + linepos++] = lut[i + dat[0][width + ypos++]];
|
|
||||||
|
|
||||||
}
|
|
||||||
linepos += (2 * MOVIE_WIDTH - width);
|
|
||||||
ypos += width;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AnimationState::drawTextObject(SpriteInfo *s, uint8 *src) {
|
void AnimationState::drawTextObject(SpriteInfo *s, uint8 *src) {
|
||||||
OverlayColor *dst = overlay + RENDERWIDE * (s->y) + s->x;
|
OverlayColor *dst = overlay + RENDERWIDE * (s->y) + s->x;
|
||||||
|
|
||||||
|
@ -666,7 +528,7 @@ int32 MoviePlayer::playDummy(const char *filename, MovieTextObject *text[], uint
|
||||||
memset(_vm->_graphics->_buffer, 0, _vm->_graphics->_screenWide * MENUDEEP);
|
memset(_vm->_graphics->_buffer, 0, _vm->_graphics->_screenWide * MENUDEEP);
|
||||||
|
|
||||||
uint8 msg[] = "Cutscene - Narration Only: Press ESC to exit, or visit www.scummvm.org to download cutscene videos";
|
uint8 msg[] = "Cutscene - Narration Only: Press ESC to exit, or visit www.scummvm.org to download cutscene videos";
|
||||||
Memory *data = _vm->_fontRenderer->makeTextSprite(msg, MOVIE_WIDTH, 255, _vm->_speechFontId);
|
Memory *data = _vm->_fontRenderer->makeTextSprite(msg, RENDERWIDE, 255, _vm->_speechFontId);
|
||||||
FrameHeader *frame = (FrameHeader *) data->ad;
|
FrameHeader *frame = (FrameHeader *) data->ad;
|
||||||
SpriteInfo msgSprite;
|
SpriteInfo msgSprite;
|
||||||
uint8 *msgSurface;
|
uint8 *msgSurface;
|
||||||
|
|
|
@ -29,66 +29,11 @@
|
||||||
|
|
||||||
namespace Sword2 {
|
namespace Sword2 {
|
||||||
|
|
||||||
#ifdef BACKEND_8BIT
|
class AnimationState : public ::Graphics::BaseAnimationState {
|
||||||
#define SQR(x) ((x) * (x))
|
|
||||||
#define SHIFT 3
|
|
||||||
#else
|
|
||||||
#define SHIFT 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define BITDEPTH (1 << (8 - SHIFT))
|
|
||||||
#define ROUNDADD (1 << (SHIFT - 1))
|
|
||||||
|
|
||||||
#define BUFFER_SIZE 4096
|
|
||||||
|
|
||||||
class AnimationState {
|
|
||||||
private:
|
private:
|
||||||
Sword2Engine *_vm;
|
Sword2Engine *_vm;
|
||||||
SoundMixer *_snd;
|
|
||||||
OSystem *_sys;
|
|
||||||
|
|
||||||
uint framenum;
|
|
||||||
uint frameskipped;
|
|
||||||
int ticks;
|
|
||||||
|
|
||||||
#ifdef USE_MPEG2
|
|
||||||
mpeg2dec_t *decoder;
|
|
||||||
const mpeg2_info_t *info;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
File *mpgfile;
|
|
||||||
File *sndfile;
|
|
||||||
|
|
||||||
byte buffer[BUFFER_SIZE];
|
|
||||||
|
|
||||||
PlayingSoundHandle bgSound;
|
|
||||||
AudioStream *bgSoundStream;
|
|
||||||
|
|
||||||
#ifdef BACKEND_8BIT
|
|
||||||
int palnum;
|
|
||||||
int maxPalnum;
|
|
||||||
|
|
||||||
byte lookup[2][(BITDEPTH+1) * (BITDEPTH+1) * (BITDEPTH+1)];
|
|
||||||
byte *lut;
|
|
||||||
byte *lut2;
|
|
||||||
int lutcalcnum;
|
|
||||||
|
|
||||||
int curpal;
|
|
||||||
int cr;
|
|
||||||
int pos;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
uint cnt;
|
|
||||||
uint end;
|
|
||||||
byte pal[4 * 256];
|
|
||||||
} palettes[50];
|
|
||||||
#else
|
|
||||||
static OverlayColor *lookup;
|
|
||||||
OverlayColor *overlay;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
AnimationState(Sword2Engine *vm);
|
AnimationState(Sword2Engine *vm);
|
||||||
~AnimationState();
|
~AnimationState();
|
||||||
|
|
||||||
|
@ -104,12 +49,7 @@ public:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
#ifdef BACKEND_8BIT
|
#ifdef BACKEND_8BIT
|
||||||
void buildLookup(int p, int lines);
|
|
||||||
bool checkPaletteSwitch();
|
|
||||||
void setPalette(byte *pal);
|
void setPalette(byte *pal);
|
||||||
#else
|
|
||||||
void buildLookup(void);
|
|
||||||
void plotYUV(OverlayColor *lut, int width, int height, byte *const *dat);
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue