i_video.c refactor port

This commit is contained in:
Lactozilla 2023-07-24 13:52:29 -03:00
parent 4f97b7730b
commit 4de2d81815
2 changed files with 600 additions and 669 deletions

View file

@ -57,7 +57,13 @@ static precise_t gif_prevframetime = 0;
static UINT32 gif_delayus = 0; // "us" is microseconds
static UINT8 gif_writeover = 0;
typedef struct
{
void *pixels;
size_t size;
boolean owns_pixels;
} gif_screen_t;
static gif_screen_t gif_screens[2];
// OPTIMIZE gif output
// ---
@ -535,7 +541,8 @@ static void GIF_rgbconvert(UINT8 *linear, UINT8 *scr)
static void GIF_framewrite(void)
{
UINT8 *p;
UINT8 *movie_screen = screens[2];
UINT8 *base_screen = gif_screens[0].pixels;
UINT8 *movie_screen = gif_screens[1].pixels;
INT32 blitx, blity, blitw, blith;
boolean palchanged;
@ -560,7 +567,7 @@ static void GIF_framewrite(void)
if (gif_optimize && gif_frames > 0 && (!palchanged))
{
// before blit movie_screen points to last frame, cur_screen points to this frame
UINT8 *cur_screen = screens[0];
UINT8 *cur_screen = base_screen;
GIF_optimizeregion(cur_screen, movie_screen, &blitx, &blity, &blitw, &blith);
// blit to temp screen
@ -586,7 +593,7 @@ static void GIF_framewrite(void)
if (rendermode == render_opengl)
{
UINT8 *linear = HWR_GetScreenshot();
GIF_rgbconvert(linear, screens[0]);
GIF_rgbconvert(linear, base_screen);
free(linear);
}
#endif
@ -596,7 +603,7 @@ static void GIF_framewrite(void)
if (gif_frames == 0 && rendermode == render_soft)
I_ReadScreen(movie_screen);
movie_screen = screens[0];
movie_screen = base_screen;
}
// screen regions are handled in GIF_lzw
@ -744,13 +751,66 @@ INT32 GIF_open(const char *filename)
return 1;
}
static void GIF_checkscreens(void)
{
for (size_t i = 0; i < sizeof(gif_screens) / sizeof(gif_screens[0]); i++)
{
if (rendermode == render_soft)
{
if (gif_screens[i].owns_pixels)
{
Z_Free(gif_screens[i].pixels);
gif_screens[i].owns_pixels = false;
}
gif_screens[i].size = 0;
if (i == 1)
gif_screens[i].pixels = screens[2];
else
gif_screens[i].pixels = screens[0];
}
else
{
size_t sz = vid.width * vid.height * vid.bpp;
if (!gif_screens[i].owns_pixels)
{
gif_screens[i].size = sz;
gif_screens[i].pixels = Z_Malloc(gif_screens[i].size, PU_STATIC, NULL);
gif_screens[i].owns_pixels = true;
}
else if (gif_screens[i].size != sz)
{
gif_screens[i].size = sz;
gif_screens[i].pixels = Z_Realloc(gif_screens[i].pixels, gif_screens[i].size, PU_STATIC, NULL);
}
}
}
}
static void GIF_freescreens(void)
{
for (size_t i = 0; i < sizeof(gif_screens) / sizeof(gif_screens[0]); i++)
{
if (gif_screens[i].owns_pixels)
{
Z_Free(gif_screens[i].pixels);
gif_screens[i].owns_pixels = false;
}
gif_screens[i].size = 0;
gif_screens[i].pixels = NULL;
}
}
//
// GIF_frame
// writes a frame into the output gif
//
void GIF_frame(void)
{
// there's not much actually needed here, is there.
GIF_checkscreens();
GIF_framewrite();
}
@ -780,6 +840,8 @@ INT32 GIF_close(void)
Z_Free(giflzw_hashTable);
giflzw_hashTable = NULL;
GIF_freescreens();
CONS_Printf(M_GetText("Animated gif closed; wrote %d frames\n"), gif_frames);
return 1;
}

File diff suppressed because it is too large Load diff