Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 124ab45
Author: CasualPokePlayer <[email protected]>
Date:   Sat Mar 12 12:24:18 2022 -0800

    option for bob vs weave deinterlacing

commit 5691df2
Author: CasualPokePlayer <[email protected]>
Date:   Fri Mar 11 23:28:34 2022 -0800

    implement read screen
  • Loading branch information
CasualPokePlayer committed Mar 12, 2022
1 parent 6660e93 commit e00febf
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/core/n64video.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ struct n64video_config
bool vsync; // enable vsync if true
bool exclusive; // run in exclusive mode when in fullscreen if true
bool integer_scaling; // one native pixel is displayed as a multiple of a screen pixel if true
bool bob_deinterlacer; // deinterlaces n64video_read_screen() output with a bob deinterlacer
} vi;
struct {
enum dp_compat_profile compat; // multithreading compatibility mode
Expand All @@ -113,5 +114,6 @@ struct n64video_config
void n64video_config_init(struct n64video_config* config);
void n64video_init(struct n64video_config* config);
void n64video_update_screen(struct n64video_frame_buffer* fb);
void n64video_read_screen(struct n64video_frame_buffer* fb);
void n64video_process_list(void);
void n64video_close(void);
49 changes: 49 additions & 0 deletions src/core/n64video/vi.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,55 @@ void n64video_update_screen(struct n64video_frame_buffer* fb)
}
}

void n64video_read_screen(struct n64video_frame_buffer* fb)
{
fb->width = PRESCALE_WIDTH;
fb->height = (ispal ? V_RES_PAL : V_RES_NTSC) >> !ctrl.serrate;
fb->pixels = (struct n64video_pixel*)malloc(PRESCALE_WIDTH * (ispal ? V_RES_PAL : V_RES_NTSC) * sizeof(struct n64video_pixel));
if (fb->height < V_RES_NTSC) // progressive; double the height
{
struct n64video_pixel* src = prescale;
struct n64video_pixel* dst = fb->pixels;
uint32_t double_width = fb->width * 2;
for (uint32_t i = 0; i < fb->height; i++)
{
memcpy(dst, src, fb->width * sizeof(struct n64video_pixel));
memcpy(dst + fb->width, src, fb->width * sizeof(struct n64video_pixel));
src += fb->width;
dst += double_width;
}
fb->height *= 2;
}
else // interlaced; deinterlace
{
if (config.vi.bob_deinterlacer)
{
struct n64video_pixel* src = prescale + lowerfield * fb->width;
struct n64video_pixel* dst = fb->pixels;
uint32_t double_width = fb->width * 2;
uint32_t half_height = fb->height / 2;
for (uint32_t i = 0; i < half_height; i++)
{
memcpy(dst, src, fb->width * sizeof(struct n64video_pixel));
memcpy(dst + fb->width, src, fb->width * sizeof(struct n64video_pixel));
src += double_width;
dst += double_width;
}
}
else // result is already weaved
{
struct n64video_pixel* src = prescale;
struct n64video_pixel* dst = fb->pixels;
for (uint32_t i = 0; i < fb->height; i++)
{
memcpy(dst, src, fb->width * sizeof(struct n64video_pixel));
src += fb->width;
dst += fb->width;
}
}
}
}

static void vi_close(void)
{
}
Expand Down
11 changes: 11 additions & 0 deletions src/plugin/zilmar/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#define KEY_VI_HIDE_OVERSCAN "hide_overscan"
#define KEY_VI_EXCLUSIVE "exclusive"
#define KEY_VI_VSYNC "vsync"
#define KEY_VI_INTEGER_SCALING "integer_scaling"
#define KEY_VI_BOB_DEINTERLACER "bob_deinterlacer"

#define KEY_DP_COMPAT "compat"

Expand All @@ -50,6 +52,7 @@ static HWND dlg_check_vi_overscan;
static HWND dlg_check_vi_exclusive;
static HWND dlg_check_vi_vsync;
static HWND dlg_check_vi_integer_scaling;
static HWND dlg_check_vi_bob_deinterlacer;
static HWND dlg_combo_dp_compat;
static HWND dlg_spin_workers;
static HWND dlg_edit_workers;
Expand Down Expand Up @@ -121,6 +124,7 @@ INT_PTR CALLBACK config_dialog_proc(HWND hwnd, UINT iMessage, WPARAM wParam, LPA
CONFIG_DLG_INIT_CHECKBOX(IDC_CHECK_VI_EXCLUSIVE, dlg_check_vi_exclusive, config.vi.exclusive);
CONFIG_DLG_INIT_CHECKBOX(IDC_CHECK_VI_VSYNC, dlg_check_vi_vsync, config.vi.vsync);
CONFIG_DLG_INIT_CHECKBOX(IDC_CHECK_VI_INTEGER_SCALING, dlg_check_vi_integer_scaling, config.vi.integer_scaling);
CONFIG_DLG_INIT_CHECKBOX(IDC_CHECK_VI_BOB_DEINTERLACER, dlg_check_vi_bob_deinterlacer, config.vi.bob_deinterlacer);

dlg_edit_workers = GetDlgItem(hwnd, IDC_EDIT_WORKERS);
SetDlgItemInt(hwnd, IDC_EDIT_WORKERS, config.num_workers, FALSE);
Expand Down Expand Up @@ -162,6 +166,7 @@ INT_PTR CALLBACK config_dialog_proc(HWND hwnd, UINT iMessage, WPARAM wParam, LPA
config.vi.exclusive = SendMessage(dlg_check_vi_exclusive, BM_GETCHECK, 0, 0);
config.vi.vsync = SendMessage(dlg_check_vi_vsync, BM_GETCHECK, 0, 0);
config.vi.integer_scaling = SendMessage(dlg_check_vi_integer_scaling, BM_GETCHECK, 0, 0);
config.vi.bob_deinterlacer = SendMessage(dlg_check_vi_bob_deinterlacer, BM_GETCHECK, 0, 0);
config.dp.compat = SendMessage(dlg_combo_dp_compat, CB_GETCURSEL, 0, 0);
config.parallel = SendMessage(dlg_check_multithread, BM_GETCHECK, 0, 0);
config.num_workers = GetDlgItemInt(hwnd, IDC_EDIT_WORKERS, FALSE, FALSE);
Expand Down Expand Up @@ -206,6 +211,10 @@ static void config_handle(const char* key, const char* value, const char* sectio
config.vi.exclusive = strtol(value, NULL, 0) != 0;
} else if (!_strcmpi(key, KEY_VI_VSYNC)) {
config.vi.vsync = strtol(value, NULL, 0) != 0;
} else if (!_strcmpi(key, KEY_VI_INTEGER_SCALING)) {
config.vi.integer_scaling = strtol(value, NULL, 0) != 0;
} else if (!_strcmpi(key, KEY_VI_BOB_DEINTERLACER)) {
config.vi.bob_deinterlacer = strtol(value, NULL, 0) != 0;
}
} else if (!_strcmpi(section, SECTION_DISPLAY_PROCESSOR)) {
if (!_strcmpi(key, KEY_DP_COMPAT)) {
Expand Down Expand Up @@ -315,6 +324,8 @@ bool config_save(void)
config_write_int32(fp, KEY_VI_HIDE_OVERSCAN, config.vi.hide_overscan);
config_write_int32(fp, KEY_VI_EXCLUSIVE, config.vi.exclusive);
config_write_int32(fp, KEY_VI_VSYNC, config.vi.vsync);
config_write_int32(fp, KEY_VI_INTEGER_SCALING, config.vi.integer_scaling);
config_write_int32(fp, KEY_VI_BOB_DEINTERLACER, config.vi.bob_deinterlacer);
fputs("\n", fp);

config_write_section(fp, SECTION_DISPLAY_PROCESSOR);
Expand Down
Binary file modified src/plugin/zilmar/config.rc
Binary file not shown.
30 changes: 27 additions & 3 deletions src/plugin/zilmar/gfx_1.3.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,35 @@ EXPORT void CALL DllConfig(HWND hParent)
config_dialog(hParent);
}

struct bgr24_pixel
{
uint8_t b;
uint8_t g;
uint8_t r;
};

EXPORT void CALL ReadScreen(void **dest, long *width, long *height)
{
UNUSED(dest);
UNUSED(width);
UNUSED(height);
struct n64video_frame_buffer fb;
n64video_read_screen(&fb);
*width = fb.width;
*height = fb.height;
*dest = malloc(fb.width * fb.height * sizeof(struct bgr24_pixel));
struct bgr24_pixel* out_pixels = (struct bgr24_pixel*)(*dest) + fb.width * (fb.height - 1);
for (uint32_t i = 0; i < fb.height; i++)
{
for (uint32_t j = 0; j < fb.width; j++)
{
struct n64video_pixel pixel = fb.pixels[i * fb.width + j];
out_pixels[(0 - i) * fb.width + j] = (struct bgr24_pixel){ pixel.b, pixel.g, pixel.r, };
}
}
free(fb.pixels);
}

EXPORT void CALL DllCrtFree(void *p)
{
free(p);
}

EXPORT void CALL DrawScreen(void)
Expand Down
Binary file modified src/plugin/zilmar/resource.h
Binary file not shown.

0 comments on commit e00febf

Please sign in to comment.