improve MGF video quality

This commit is contained in:
Ondřej Novák 2025-01-29 20:46:35 +01:00
parent 2be84e406c
commit f169aa5071
4 changed files with 86 additions and 5 deletions

View file

@ -85,6 +85,7 @@
#define get_string(t) texty[t]
static __inline unsigned int rnd(unsigned int max) {
if (max == 0) return 0;
return rand() % max;
}

View file

@ -745,7 +745,7 @@ void spell_hit(int cil,int min,int max,int owner)
cil--;
h=&postavy[cil];
vysl=min+rnd(max-min);
vysl=min+rnd(max-min+1);
if (vysl<0)
{
h->lives-=vysl>h->vlastnosti[VLS_MAXHIT]?h->vlastnosti[VLS_MAXHIT]:vysl;

View file

@ -19,10 +19,79 @@ static word *picture;
static word *anim_render_buffer;
static void *sound;
static void StretchImageHQ(word *src, word *trg, uint32_t linelen, char full)
static inline word avg_pixels(word a, word b) {
return ((a & 0xF7DE)+(a & 0xF7DE)) >> 1;
}
static void StretchImageHQ(word *src, word *trg, int32_t linelen, char full)
{
word xs=src[0],ys=src[1];
word *s,*t;
word *src_row = src+3;
word *trg_row = trg;
for(int y = 0; y < ys; ++y) {
for (int x = 0; x < xs; ++x) {
word n = src_row[x];
trg_row[2*x] = n;
}
trg_row += linelen;
/*
if (y+1 < ys ) {
for (int x = 0; x < xs; ++x) {
word n1 = src_row[x];
word n2 = src_row[x+xs];
word n3 = y > 0?src_row[x-xs]:n1;
word n4 = y < (ys-2)?src_row[x+2*xs]:n2;
word n5 = avg_pixels(n1, n2);
word n6 = avg_pixels(n3, n4);
word n7 = avg_pixels(n5, n6);
trg_row[2*x] = n7;
trg_row[2*x+1] = n7;
}
}
*/
trg_row += linelen;
src_row += xs;
}
trg_row = trg;
for (int y = 0; y < ys; ++y) {
for (int x = 0; x < xs-1; ++x) {
word n1 = trg_row[2*x];
word n2 = trg_row[2*x+2];
word n3 = x > 0?trg_row[2*x-2]:n1;
word n4 = x < (xs-2)?trg_row[2*x+2]:n2;
word n5 = avg_pixels(n1, n2);
word n6 = avg_pixels(n3, n4);
word n7 = avg_pixels(n5, n6);
trg_row[2*x+1] = n7;
}
trg_row += 2*linelen;
}
trg_row = trg;
for (int y = 0; y < ys-1; ++y) {
for (int x = 0; x < 2*xs; ++x) {
word n1 = trg_row[x];
word n2 = trg_row[x+2*linelen];
word n3 = y > 1?trg_row[x-2*linelen]:n1;
word n4 = y < (ys-2)?trg_row[x+4*linelen]:n2;
word n5 = avg_pixels(n1, n2);
word n6 = avg_pixels(n3, n4);
word n7 = avg_pixels(n5, n6);
trg_row[x+linelen] = n7;
}
trg_row += 2*linelen;
}
#if 0
int x,y;
src+=3;
for (y=0,s=src,t=trg;y<ys;y++,t+=linelen*2,s+=xs)
@ -49,8 +118,11 @@ static void StretchImageHQ(word *src, word *trg, uint32_t linelen, char full)
}
}
}
#endif
}
static void PlayMGFFile(void *file, MGIF_PROC proc,int ypos,char full)
{
int32_t scr_linelen2 = GetScreenPitch();
@ -93,6 +165,14 @@ void show_delta_lfb12e_dx(void *target,void *buff,void *paleta);
void show_full_lfb12e_dx(void *target,void *buff,void *paleta);
word * load_mgf_palette(word *pal) {
static word paleta[256];
for (int i = 0; i < 256; ++i) {
paleta[i] = pal[i]+(pal[i]&0x7fe0);
}
return paleta;
}
void BigPlayProc(int act,void *data,int csize)
{
switch (act)
@ -100,7 +180,7 @@ void BigPlayProc(int act,void *data,int csize)
case MGIF_LZW:
case MGIF_COPY:show_full_lfb12e(anim_render_buffer,data,paleta);break;
case MGIF_DELTA:show_delta_lfb12e(anim_render_buffer,data,paleta);break;
case MGIF_PAL:paleta=data;break;
case MGIF_PAL:paleta=load_mgf_palette(data);break;
case MGIF_SOUND:
while (LoadNextVideoFrame(sound,data,csize,mgif_header->ampl_table,mgif_accnums,&mgif_writepos)==0);
}

View file

@ -68,7 +68,7 @@ void *PrepareVideoSound(int mixfreq, int buffsize) {
return 0;
}
char LoadNextVideoFrame(void *buffer, char *data, int size, short *xlat, short *accnums, int32_t *writepos) {
std::this_thread::sleep_for(std::chrono::milliseconds(50));
std::this_thread::sleep_for(std::chrono::milliseconds(20));
return 1;
}