From 21e35bbf2f0879002563e0acceaf7794104bb9f8 Mon Sep 17 00:00:00 2001 From: Sorgelig Date: Wed, 29 Dec 2021 21:33:57 +0800 Subject: [PATCH] video: support 64 phases for scaler, separate filters for horizontal/vertical/scanlines. --- cfg.cpp | 2 + cfg.h | 2 + menu.cpp | 324 ++++++++++++++++++++++++++++++++++-------------------- video.cpp | 197 ++++++++++++++++++++++----------- video.h | 12 +- 5 files changed, 350 insertions(+), 187 deletions(-) diff --git a/cfg.cpp b/cfg.cpp index fce0bdc..e71c609 100644 --- a/cfg.cpp +++ b/cfg.cpp @@ -83,6 +83,8 @@ static const ini_var_t ini_vars[] = { "SPINNER_THROTTLE", (void*)(&(cfg.spinner_throttle)), INT32, -10000, 10000 }, { "AFILTER_DEFAULT", (void*)(&(cfg.afilter_default)), STRING, 0, sizeof(cfg.afilter_default) - 1 }, { "VFILTER_DEFAULT", (void*)(&(cfg.vfilter_default)), STRING, 0, sizeof(cfg.vfilter_default) - 1 }, + { "VFILTER_VERTICAL_DEFAULT", (void*)(&(cfg.vfilter_vertical_default)), STRING, 0, sizeof(cfg.vfilter_vertical_default) - 1 }, + { "VFILTER_SCANLINES_DEFAULT", (void*)(&(cfg.vfilter_scanlines_default)), STRING, 0, sizeof(cfg.vfilter_scanlines_default) - 1 }, { "SHMASK_DEFAULT", (void*)(&(cfg.shmask_default)), STRING, 0, sizeof(cfg.shmask_default) - 1 }, { "SHMASK_MODE_DEFAULT", (void*)(&(cfg.shmask_mode_default)), UINT8, 0, 255 }, { "LOG_FILE_ENTRY", (void*)(&(cfg.log_file_entry)), UINT8, 0, 1 }, diff --git a/cfg.h b/cfg.h index 3975c05..6795a7d 100644 --- a/cfg.h +++ b/cfg.h @@ -65,6 +65,8 @@ typedef struct { char custom_aspect_ratio[2][16]; char afilter_default[1023]; char vfilter_default[1023]; + char vfilter_vertical_default[1023]; + char vfilter_scanlines_default[1023]; char shmask_default[1023]; } cfg_t; diff --git a/menu.cpp b/menu.cpp index 8891514..9de5121 100644 --- a/menu.cpp +++ b/menu.cpp @@ -129,11 +129,14 @@ enum MENU MENU_SFONT_FILE_SELECTED, + MENU_VIDEOPROC1, + MENU_VIDEOPROC2, MENU_COEFF_FILE_SELECTED, MENU_GAMMA_FILE_SELECTED, - MENU_AFILTER_FILE_SELECTED, MENU_SMASK_FILE_SELECTED, + MENU_AFILTER_FILE_SELECTED, + // Generic MENU_GENERIC_MAIN1, MENU_GENERIC_MAIN2, @@ -211,10 +214,8 @@ const char *joy_ana_map[] = { " DPAD test: Press RIGHT", " DPAD test: Pres const char *config_stereo_msg[] = { "0%", "25%", "50%", "100%" }; const char *config_uart_msg[] = { " None", " PPP", " Console", " MIDI", " Modem"}; const char *config_midilink_mode[] = {"Local", "Local", " USB", " UDP", "-----", "-----", " USB" }; -const char *config_scaler_msg[] = { "Internal","Custom" }; const char *config_afilter_msg[] = { "Internal","Custom" }; const char *config_smask_msg[] = { "None", "1x", "2x", "1x Rotated", "2x Rotated" }; -const char *config_gamma_msg[] = { "Off","On" }; const char *config_scale[] = { "Normal", "V-Integer", "HV-Integer-", "HV-Integer+", "HV-Integer", "???", "???", "???" }; #define DPAD_NAMES 4 @@ -1003,6 +1004,7 @@ void HandleUI(void) static uint32_t saved_menustate = 0; static char addon[1024]; static int store_name; + static int vfilter_type; static char cp_MenuCancel; @@ -2271,7 +2273,7 @@ void HandleUI(void) while(1) { n = 0; - menumask = 0x3800f; + menumask = 0x3802f; if (!menusub) firstmenu = 0; adjvisible = 0; @@ -2298,41 +2300,8 @@ void HandleUI(void) MenuWrite(n++, s, menusub == 4); } - if (video_get_scaler_flt() >= 0 && !cfg.direct_video) - { - MenuWrite(n++); - menumask |= 0x60; - sprintf(s, " Scale filter - %s", config_scaler_msg[video_get_scaler_flt() ? 1 : 0]); - MenuWrite(n++, s, menusub == 5); - - memset(s, 0, sizeof(s)); - s[0] = ' '; - if (strlen(video_get_scaler_coeff())) strncpy(s+1, video_get_scaler_coeff(),25); - else strcpy(s, " < none >"); - - while(strlen(s) < 26) strcat(s, " "); - strcat(s, " \x16 "); - - MenuWrite(n++, s, menusub == 6, !video_get_scaler_flt() || !S_ISDIR(getFileType(COEFF_DIR))); - } - - if (video_get_gamma_en() >=0) - { - MenuWrite(n++); - menumask |= 0x180; - sprintf(s, " Gamma correction - %s", config_gamma_msg[video_get_gamma_en() ? 1 : 0]); - MenuWrite(n++, s, menusub == 7); - - memset(s, 0, sizeof(s)); - s[0] = ' '; - if (strlen(video_get_gamma_curve())) strncpy(s+1, video_get_gamma_curve(),25); - else strcpy(s, " < none >"); - - while(strlen(s) < 26) strcat(s, " "); - strcat(s, " \x16 "); - - MenuWrite(n++, s, menusub == 8, !video_get_gamma_en() || !S_ISDIR(getFileType(GAMMA_DIR))); - } + MenuWrite(n++); + MenuWrite(n++, " Video processing \x16", menusub==5); if (audio_filter_en() >= 0) { @@ -2352,25 +2321,6 @@ void HandleUI(void) MenuWrite(n++, s, menusub == 10, !audio_filter_en() || !S_ISDIR(getFileType(AFILTER_DIR))); } - if (video_get_shadow_mask_mode() >= 0) - { - MenuWrite(n++); - menumask |= 0x1800; - sprintf(s, " Shadow Mask - %s", config_smask_msg[video_get_shadow_mask_mode()]); - MenuWrite(n++, s, menusub == 11); - - memset(s, 0, sizeof(s)); - s[0] = ' '; - if (strlen(video_get_shadow_mask())) strncpy(s + 1, video_get_shadow_mask(), 25); - else strcpy(s, " < none >"); - - while (strlen(s) < 26) strcat(s, " "); - strcat(s, " \x16 "); - - MenuWrite(n++, s, menusub == 12, !video_get_shadow_mask_mode() || !S_ISDIR(getFileType(SMASK_DIR))); - } - - if (!is_minimig() && !is_st()) { menumask |= 0x6000; @@ -2479,31 +2429,12 @@ void HandleUI(void) break; case 5: - video_set_scaler_flt(video_get_scaler_flt() ? 0 : 1); - menustate = MENU_COMMON1; - break; - - case 6: - if (video_get_scaler_flt()) { - snprintf(Selected_tmp, sizeof(Selected_tmp), COEFF_DIR"/%s", video_get_scaler_coeff()); - if(!FileExists(Selected_tmp)) snprintf(Selected_tmp, sizeof(Selected_tmp), COEFF_DIR); - SelectFile(Selected_tmp, 0, SCANO_DIR | SCANO_TXT, MENU_COEFF_FILE_SELECTED, MENU_COMMON1); + menustate = MENU_VIDEOPROC1; + menusub = 0; } break; - case 7: - video_set_gamma_en(video_get_gamma_en() ? 0 : 1); - menustate = MENU_COMMON1; - break; - case 8: - if (video_get_gamma_en()) - { - snprintf(Selected_tmp, sizeof(Selected_tmp), GAMMA_DIR"/%s", video_get_gamma_curve()); - if (!FileExists(Selected_tmp)) snprintf(Selected_tmp, sizeof(Selected_tmp), GAMMA_DIR); - SelectFile(Selected_tmp, 0, SCANO_DIR | SCANO_TXT, MENU_GAMMA_FILE_SELECTED, MENU_COMMON1); - } - break; case 9: audio_set_filter_en(audio_filter_en() ? 0 : 1); menustate = MENU_COMMON1; @@ -2517,18 +2448,7 @@ void HandleUI(void) SelectFile(Selected_tmp, 0, SCANO_DIR | SCANO_TXT, MENU_AFILTER_FILE_SELECTED, MENU_COMMON1); } break; - case 11: - video_set_shadow_mask_mode(video_get_shadow_mask_mode() + 1); - menustate = MENU_COMMON1; - break; - case 12: - if (video_get_shadow_mask_mode()) - { - snprintf(Selected_tmp, sizeof(Selected_tmp), SMASK_DIR"/%s", video_get_shadow_mask()); - if (!FileExists(Selected_tmp)) snprintf(Selected_tmp, sizeof(Selected_tmp), SMASK_DIR); - SelectFile(Selected_tmp, 0, SCANO_DIR | SCANO_TXT, MENU_SMASK_FILE_SELECTED, MENU_COMMON1); - } - break; + case 13: if (!is_archie()) { @@ -2627,6 +2547,170 @@ void HandleUI(void) if(!hold_cnt && reboot_req) fpga_load_rbf("menu.rbf"); break; + case MENU_VIDEOPROC1: + helptext_idx = 0; + menumask = 0x7FF; + OsdSetTitle("Video Processing"); + menustate = MENU_VIDEOPROC2; + parentstate = MENU_VIDEOPROC1; + + while (1) + { + int n = 0; + if (!menusub) firstmenu = 0; + adjvisible = 0; + + sprintf(s, video_get_scaler_flt(VFILTER_HORZ) ? " Horz filter: From file" : " Video filter: NearNeighbour"); + MenuWrite(n++, s, menusub == 0, cfg.direct_video); + strcpy(s, " "); + if (strlen(video_get_scaler_coeff(VFILTER_HORZ))) strncat(s, video_get_scaler_coeff(VFILTER_HORZ), 25); + else strcpy(s, " < none >"); + while (strlen(s) < 26) strcat(s, " "); + strcat(s, " \x16 "); + MenuWrite(n++, s, menusub == 1, !video_get_scaler_flt(VFILTER_HORZ) || !S_ISDIR(getFileType(COEFF_DIR))); + + MenuWrite(n++); + sprintf(s, " Vert filter: %s", video_get_scaler_flt(VFILTER_VERT) ? "From file" : "Same as Horz"); + MenuWrite(n++, s, menusub == 2, cfg.direct_video || !video_get_scaler_flt(VFILTER_HORZ)); + strcpy(s, " "); + if (strlen(video_get_scaler_coeff(VFILTER_VERT))) strncat(s, video_get_scaler_coeff(VFILTER_VERT), 25); + else strcpy(s, " < none >"); + while (strlen(s) < 26) strcat(s, " "); + strcat(s, " \x16 "); + MenuWrite(n++, s, menusub == 3, !video_get_scaler_flt(VFILTER_VERT) || !video_get_scaler_flt(VFILTER_HORZ) || !S_ISDIR(getFileType(COEFF_DIR)) || cfg.direct_video); + + MenuWrite(n++); + sprintf(s, " Scan filter: %s", video_get_scaler_flt(VFILTER_SCAN) ? "From file" : "Same as Vert"); + MenuWrite(n++, s, menusub == 4, cfg.direct_video || !video_get_scaler_flt(VFILTER_HORZ)); + strcpy(s, " "); + if (strlen(video_get_scaler_coeff(VFILTER_SCAN))) strncat(s, video_get_scaler_coeff(VFILTER_SCAN), 25); + else strcpy(s, " < none >"); + while (strlen(s) < 26) strcat(s, " "); + strcat(s, " \x16 "); + MenuWrite(n++, s, menusub == 5, !video_get_scaler_flt(VFILTER_SCAN) || !video_get_scaler_flt(VFILTER_HORZ) || !S_ISDIR(getFileType(COEFF_DIR)) || cfg.direct_video); + + MenuWrite(n++); + sprintf(s, " Gamma correction - %s", (video_get_gamma_en() > 0) ? "On" : "Off"); + MenuWrite(n++, s, menusub == 6, video_get_gamma_en() < 0); + strcpy(s, " "); + if (strlen(video_get_gamma_curve())) strncat(s, video_get_gamma_curve(), 25); + else strcpy(s, " < none >"); + while (strlen(s) < 26) strcat(s, " "); + strcat(s, " \x16 "); + MenuWrite(n++, s, menusub == 7, (video_get_gamma_en() <= 0) || !S_ISDIR(getFileType(GAMMA_DIR))); + + MenuWrite(n++); + sprintf(s, " Shadow Mask - %s", config_smask_msg[video_get_shadow_mask_mode()]); + MenuWrite(n++, s, menusub == 8, video_get_shadow_mask_mode() < 0); + strcpy(s, " "); + if (strlen(video_get_shadow_mask())) strncat(s, video_get_shadow_mask(), 25); + else strcpy(s, " < none >"); + while (strlen(s) < 26) strcat(s, " "); + strcat(s, " \x16 "); + MenuWrite(n++, s, menusub == 9, (video_get_shadow_mask_mode() <= 0) || !S_ISDIR(getFileType(SMASK_DIR))); + + MenuWrite(n++); + MenuWrite(n++, STD_BACK, menusub == 10); + + if (!adjvisible) break; + firstmenu += adjvisible; + } + break; + + case MENU_VIDEOPROC2: + if (menu || left) + { + menusub = 5; + menustate = MENU_COMMON1; + break; + } + + if (plus || minus) + { + if (menusub == 8) + { + video_set_shadow_mask_mode(video_get_shadow_mask_mode() + (plus ? 1 : -1)); + } + menustate = parentstate; + break; + } + + if (select) + { + switch (menusub) + { + case 0: + if (!cfg.direct_video) + { + video_set_scaler_flt(VFILTER_HORZ, video_get_scaler_flt(VFILTER_HORZ) ? 0 : 1); + menustate = parentstate; + } + break; + + case 1: + case 3: + case 5: + vfilter_type = (menusub == 1) ? VFILTER_HORZ : (menusub == 3) ? VFILTER_VERT : VFILTER_SCAN; + if (video_get_scaler_flt(VFILTER_HORZ)) + { + snprintf(Selected_tmp, sizeof(Selected_tmp), COEFF_DIR"/%s", video_get_scaler_coeff(vfilter_type)); + if (!FileExists(Selected_tmp)) snprintf(Selected_tmp, sizeof(Selected_tmp), COEFF_DIR); + SelectFile(Selected_tmp, 0, SCANO_DIR | SCANO_TXT, MENU_COEFF_FILE_SELECTED, parentstate); + } + break; + + case 2: + if (!cfg.direct_video && video_get_scaler_flt(VFILTER_HORZ)) + { + video_set_scaler_flt(VFILTER_VERT, video_get_scaler_flt(VFILTER_VERT) ? 0 : 1); + menustate = parentstate; + } + break; + + case 4: + if (!cfg.direct_video && video_get_scaler_flt(VFILTER_HORZ)) + { + video_set_scaler_flt(VFILTER_SCAN, video_get_scaler_flt(VFILTER_SCAN) ? 0 : 1); + menustate = parentstate; + } + break; + + case 6: + if (video_get_gamma_en() >= 0) video_set_gamma_en(video_get_gamma_en() ? 0 : 1); + menustate = parentstate; + break; + + case 7: + if (video_get_gamma_en() > 0) + { + snprintf(Selected_tmp, sizeof(Selected_tmp), GAMMA_DIR"/%s", video_get_gamma_curve()); + if (!FileExists(Selected_tmp)) snprintf(Selected_tmp, sizeof(Selected_tmp), GAMMA_DIR); + SelectFile(Selected_tmp, 0, SCANO_DIR | SCANO_TXT, MENU_GAMMA_FILE_SELECTED, parentstate); + } + break; + + case 8: + if (video_get_shadow_mask_mode() >= 0) video_set_shadow_mask_mode(video_get_shadow_mask_mode() + 1); + menustate = parentstate; + break; + + case 9: + if (video_get_shadow_mask_mode() > 0) + { + snprintf(Selected_tmp, sizeof(Selected_tmp), SMASK_DIR"/%s", video_get_shadow_mask()); + if (!FileExists(Selected_tmp)) snprintf(Selected_tmp, sizeof(Selected_tmp), SMASK_DIR); + SelectFile(Selected_tmp, 0, SCANO_DIR | SCANO_TXT, MENU_SMASK_FILE_SELECTED, parentstate); + } + break; + + case 10: + menusub = 5; + menustate = MENU_COMMON1; + break; + } + } + break; + case MENU_ARCADE_DIP1: helptext_idx = 0; menumask = 0; @@ -3078,34 +3162,6 @@ void HandleUI(void) } break; - case MENU_COEFF_FILE_SELECTED: - { - char *p = strcasestr(selPath, COEFF_DIR"/"); - if (!p) video_set_scaler_coeff(selPath); - else - { - p += strlen(COEFF_DIR); - while (*p == '/') p++; - video_set_scaler_coeff(p); - } - menustate = MENU_COMMON1; - } - break; - - case MENU_GAMMA_FILE_SELECTED: - { - char *p = strcasestr(selPath, GAMMA_DIR"/"); - if (!p) video_set_gamma_curve(selPath); - else - { - p += strlen(GAMMA_DIR); - while (*p == '/') p++; - video_set_gamma_curve(p); - } - menustate = MENU_COMMON1; - } - break; - case MENU_AFILTER_FILE_SELECTED: { char *p = strcasestr(selPath, AFILTER_DIR"/"); @@ -3120,6 +3176,34 @@ void HandleUI(void) } break; + case MENU_COEFF_FILE_SELECTED: + { + char *p = strcasestr(selPath, COEFF_DIR"/"); + if (!p) video_set_scaler_coeff(vfilter_type, selPath); + else + { + p += strlen(COEFF_DIR); + while (*p == '/') p++; + video_set_scaler_coeff(vfilter_type, p); + } + menustate = MENU_VIDEOPROC1; + } + break; + + case MENU_GAMMA_FILE_SELECTED: + { + char *p = strcasestr(selPath, GAMMA_DIR"/"); + if (!p) video_set_gamma_curve(selPath); + else + { + p += strlen(GAMMA_DIR); + while (*p == '/') p++; + video_set_gamma_curve(p); + } + menustate = MENU_VIDEOPROC1; + } + break; + case MENU_SMASK_FILE_SELECTED: { char *p = strcasestr(selPath, SMASK_DIR"/"); @@ -3130,7 +3214,7 @@ void HandleUI(void) while (*p == '/') p++; video_set_shadow_mask(p); } - menustate = MENU_COMMON1; + menustate = MENU_VIDEOPROC1; } break; diff --git a/video.cpp b/video.cpp index 1bcb51e..d919c28 100644 --- a/video.cpp +++ b/video.cpp @@ -198,14 +198,107 @@ static void setPLL(double Fout, vmode_custom_t *v) v->Fpix = Fpix; } -static char scaler_flt_cfg[1024] = { 0 }; -static char new_scaler = 0; +static char scaler_flt[3][1024] = { 0 }; + +static int get_phases_count(char *filename) +{ + fileTextReader reader = {}; + int res = 0; + + if (FileOpenTextReader(&reader, filename)) + { + const char *line; + while ((line = FileReadLine(&reader))) + { + int c0, c1, c2, c3; + int n = sscanf(line, "%d,%d,%d,%d", &c0, &c1, &c2, &c3); + if (n == 4) res++; + } + } + return res; +} + +static void send_phases(char* filename, int type, int phases, int ver) +{ + printf("send_phases(%s, %d, %d, %d)\n", filename, type, phases, ver); + fileTextReader reader = {}; + int phase = (type == VFILTER_VERT) ? 64 : 0; + + if (FileOpenTextReader(&reader, filename)) + { + int v2txt = (phases >= 64); + const char *line; + while ((line = FileReadLine(&reader))) + { + int c0, c1, c2, c3; + if (sscanf(line, "%d,%d,%d,%d", &c0, &c1, &c2, &c3) == 4) + { + if (ver == 2) + { + int rep = v2txt ? 1 : 4; + for (int i = 0; i < rep; i++) + { + spi_w((phase * 4) + 0); spi_w(c0 & 0x1FF); + spi_w((phase * 4) + 1); spi_w(c1 & 0x1FF); + spi_w((phase * 4) + 2); spi_w(c2 & 0x1FF); + spi_w((phase * 4) + 3); spi_w(c3 & 0x1FF); + phase++; + } + } + else + { + if (!(phase & 3)) + { + spi_w((c0 & 0x1FF) | ((phase + 0) << 9)); + spi_w((c1 & 0x1FF) | ((phase + 1) << 9)); + spi_w((c2 & 0x1FF) | ((phase + 2) << 9)); + spi_w((c3 & 0x1FF) | ((phase + 3) << 9)); + } + phase += v2txt ? 1 : 4; + } + if (!(phase & 63)) break; + } + } + } +} + +static void set_vfilter(int force) +{ + static char filename[1024]; + static int last_flags = 0; + + int flt_flags = spi_uio_cmd_cont(UIO_SET_FLTNUM); + if (!flt_flags || (!force && last_flags == flt_flags)) + { + DisableIO(); + return; + } + + last_flags = flt_flags; + printf("video_set_filter: flt_flags=%d\n", flt_flags); + + spi8(scaler_flt[0][0]); + DisableIO(); + + spi_uio_cmd_cont(UIO_SET_FLTCOEF); + int phases; + + //horizontal filter + snprintf(filename, sizeof(filename), COEFF_DIR"/%s", scaler_flt[VFILTER_HORZ] + 1); + phases = get_phases_count(filename); + if (phases) send_phases(filename, VFILTER_HORZ, phases, flt_flags & 0xF); + + //vertical/scanlines filter + int vert_flt = ((flt_flags & 0x30) && scaler_flt[VFILTER_SCAN][0]) ? VFILTER_SCAN : (scaler_flt[VFILTER_VERT][0]) ? VFILTER_VERT : VFILTER_HORZ; + snprintf(filename, sizeof(filename), COEFF_DIR"/%s", scaler_flt[vert_flt] + 1); + phases = get_phases_count(filename); + if (phases) send_phases(filename, VFILTER_VERT, phases, flt_flags & 0xF); + + DisableIO(); +} static void setScaler() { - fileTextReader reader = {}; - static char filename[1024]; - uint32_t arc[4] = {}; for (int i = 0; i < 2; i++) { @@ -222,71 +315,33 @@ static void setScaler() spi_uio_cmd_cont(UIO_SET_AR_CUST); for (int i = 0; i < 4; i++) spi_w(arc[i]); DisableIO(); - - if (!spi_uio_cmd_cont(UIO_SET_FLTNUM)) - { - DisableIO(); - return; - } - - new_scaler = 1; - spi8(scaler_flt_cfg[0]); - DisableIO(); - snprintf(filename, sizeof(filename), COEFF_DIR"/%s", scaler_flt_cfg + 1); - - if (FileOpenTextReader(&reader, filename)) - { - //printf("Read scaler coefficients\n"); - spi_uio_cmd_cont(UIO_SET_FLTCOEF); - - int phase = 0; - const char *line; - while ((line = FileReadLine(&reader))) - { - int c0, c1, c2, c3; - int n = sscanf(line, "%d,%d,%d,%d", &c0, &c1, &c2, &c3); - if (n == 4) - { - //printf(" phase %c-%02d: %4d,%4d,%4d,%4d\n", (phase >= 16) ? 'V' : 'H', phase % 16, c0, c1, c2, c3); - //printf("%03X: %03X %03X %03X %03X;\n",phase*4, c0 & 0x1FF, c1 & 0x1FF, c2 & 0x1FF, c3 & 0x1FF); - - spi_w((c0 & 0x1FF) | (((phase * 4) + 0) << 9)); - spi_w((c1 & 0x1FF) | (((phase * 4) + 1) << 9)); - spi_w((c2 & 0x1FF) | (((phase * 4) + 2) << 9)); - spi_w((c3 & 0x1FF) | (((phase * 4) + 3) << 9)); - - phase++; - if (phase >= 32) break; - } - } - DisableIO(); - } + set_vfilter(1); } -int video_get_scaler_flt() +int video_get_scaler_flt(int type) { - return new_scaler ? scaler_flt_cfg[0] : -1; + return scaler_flt[type][0]; } -char* video_get_scaler_coeff() +char* video_get_scaler_coeff(int type) { - return scaler_flt_cfg + 1; + return scaler_flt[type] + 1; } static char scaler_cfg[128] = { 0 }; -void video_set_scaler_flt(int n) +void video_set_scaler_flt(int type, int n) { - scaler_flt_cfg[0] = (char)n; - FileSaveConfig(scaler_cfg, &scaler_flt_cfg, sizeof(scaler_flt_cfg)); - spi_uio_cmd8(UIO_SET_FLTNUM, scaler_flt_cfg[0]); - spi_uio_cmd(UIO_SET_FLTCOEF); + scaler_flt[type][0] = (char)n; + FileSaveConfig(scaler_cfg, &scaler_flt, sizeof(scaler_flt)); + spi_uio_cmd8(UIO_SET_FLTNUM, scaler_flt[0][0]); + set_vfilter(1); } -void video_set_scaler_coeff(char *name) +void video_set_scaler_coeff(int type, char *name) { - strcpy(scaler_flt_cfg + 1, name); - FileSaveConfig(scaler_cfg, &scaler_flt_cfg, sizeof(scaler_flt_cfg)); + strcpy(scaler_flt[type] + 1, name); + FileSaveConfig(scaler_cfg, &scaler_flt, sizeof(scaler_flt)); setScaler(); user_io_send_buttons(1); } @@ -294,14 +349,28 @@ void video_set_scaler_coeff(char *name) static void loadScalerCfg() { sprintf(scaler_cfg, "%s_scaler.cfg", user_io_get_core_name()); - if (!FileLoadConfig(scaler_cfg, &scaler_flt_cfg, sizeof(scaler_flt_cfg) - 1) || scaler_flt_cfg[0]>4) + memset(scaler_flt, 0, sizeof(scaler_cfg)); + if (!FileLoadConfig(scaler_cfg, &scaler_flt, sizeof(scaler_flt)) || scaler_flt[0][0] > 1) { - memset(scaler_flt_cfg, 0, sizeof(scaler_flt_cfg)); - if (cfg.vfilter_default[0]) - { - strcpy(scaler_flt_cfg+1, cfg.vfilter_default); - scaler_flt_cfg[0] = 1; - } + memset(scaler_flt, 0, sizeof(scaler_flt)); + } + + if (!scaler_flt[VFILTER_HORZ][1] && cfg.vfilter_default[0]) + { + strcpy(scaler_flt[VFILTER_HORZ]+1, cfg.vfilter_default); + scaler_flt[VFILTER_HORZ][0] = 1; + } + + if (!scaler_flt[VFILTER_VERT][1] && cfg.vfilter_vertical_default[0]) + { + strcpy(scaler_flt[VFILTER_VERT] + 1, cfg.vfilter_vertical_default); + scaler_flt[VFILTER_VERT][0] = 1; + } + + if (!scaler_flt[VFILTER_SCAN][1] && cfg.vfilter_scanlines_default[0]) + { + strcpy(scaler_flt[VFILTER_SCAN] + 1, cfg.vfilter_scanlines_default); + scaler_flt[VFILTER_SCAN][0] = 1; } } @@ -911,6 +980,8 @@ void video_mode_adjust() user_io_send_buttons(1); force = 1; } + + set_vfilter(0); } void video_fb_enable(int enable, int n) diff --git a/video.h b/video.h index 06f2c87..e2d6ae4 100644 --- a/video.h +++ b/video.h @@ -1,10 +1,14 @@ #ifndef VIDEO_H #define VIDEO_H -int video_get_scaler_flt(); -void video_set_scaler_flt(int n); -char* video_get_scaler_coeff(); -void video_set_scaler_coeff(char *name); +#define VFILTER_HORZ 0 +#define VFILTER_VERT 1 +#define VFILTER_SCAN 2 + +int video_get_scaler_flt(int type); +void video_set_scaler_flt(int type, int n); +char* video_get_scaler_coeff(int type); +void video_set_scaler_coeff(int type, char *name); int video_get_gamma_en(); void video_set_gamma_en(int n);