From f169aa5071bbeb5ca7fba596fc19be937bf4f7bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Nov=C3=A1k?= Date: Wed, 29 Jan 2025 20:46:35 +0100 Subject: [PATCH] improve MGF video quality --- game/globals.h | 1 + game/kouzla.c | 2 +- libs/mgifmapmem.c | 86 ++++++++++++++++++++++++++++++++++++++++-- platform/sdl/sound.cpp | 2 +- 4 files changed, 86 insertions(+), 5 deletions(-) diff --git a/game/globals.h b/game/globals.h index f469006..76b72b4 100644 --- a/game/globals.h +++ b/game/globals.h @@ -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; } diff --git a/game/kouzla.c b/game/kouzla.c index bd46e0a..e7c0359 100644 --- a/game/kouzla.c +++ b/game/kouzla.c @@ -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; diff --git a/libs/mgifmapmem.c b/libs/mgifmapmem.c index 5aeee60..4cab8ba 100644 --- a/libs/mgifmapmem.c +++ b/libs/mgifmapmem.c @@ -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;yampl_table,mgif_accnums,&mgif_writepos)==0); } diff --git a/platform/sdl/sound.cpp b/platform/sdl/sound.cpp index 839d426..367e815 100644 --- a/platform/sdl/sound.cpp +++ b/platform/sdl/sound.cpp @@ -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; }