--- branches/dev-api-4/xvidcore/vfw/src/config.c 2003/02/22 08:24:01 889 +++ branches/dev-api-4/xvidcore/vfw/src/config.c 2004/01/23 11:17:24 1326 @@ -47,7 +47,7 @@ * advanced controls are now enabled/disabled by mode * added modulated quantization, DX50 fourcc * 11.03.2002 Min Chen - * now get Core Version use xvid_init() + * now get Core Version use xvid_init() * 05.03.2002 Min Chen * Add Core version display to about box * 01.12.2001 inital version; (c)2001 peter ross @@ -60,179 +60,301 @@ #include #include -#include // XviD API +#include /* sprintf */ +#include /* XviD API */ -#include "codec.h" +#include "debug.h" #include "config.h" #include "resource.h" +#define CONSTRAINVAL(X,Y,Z) if((X)<(Y)) X=Y; if((X)>(Z)) X=Z; +#define IsDlgChecked(hwnd,idc) (IsDlgButtonChecked(hwnd,idc) == BST_CHECKED) +#define CheckDlg(hwnd,idc,value) CheckDlgButton(hwnd,idc, value?BST_CHECKED:BST_UNCHECKED) +#define EnableDlgWindow(hwnd,idc,state) EnableWindow(GetDlgItem(hwnd,idc),state) + +static void zones_update(HWND hDlg, CONFIG * config); + +HINSTANCE g_hInst; +HWND g_hTooltip; + +int pp_dy, pp_duv, pp_dr, pp_fe; /* decoder options */ + +/* enumerates child windows, assigns tooltips */ +BOOL CALLBACK enum_tooltips(HWND hWnd, LPARAM lParam) +{ + char help[500]; + + if (LoadString(g_hInst, GetDlgCtrlID(hWnd), help, 500)) + { + TOOLINFO ti; + ti.cbSize = sizeof(TOOLINFO); + ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND; + ti.hwnd = GetParent(hWnd); + ti.uId = (LPARAM)hWnd; + ti.lpszText = help; + SendMessage(g_hTooltip, TTM_ADDTOOL, 0, (LPARAM)&ti); + } + + return TRUE; +} + + +/* ===================================================================================== */ +/* MPEG-4 PROFILES/LEVELS ============================================================== */ +/* ===================================================================================== */ + + + +/* default vbv_occupancy is (64/170)*vbv_buffer_size */ + +const profile_t profiles[] = +{ +/* name p@l, w h fps obj Tvmv vmv vcv ac% vbv pkt kbps flags */ + { "Simple @ L0", 0x08, 176, 144, 15, 1, 198, 99, 1485, 100, 10*16368, 2048, 64, 0 }, + /* simple@l0: max f_code=1, intra_dc_vlc_threshold=0 */ + /* if ac preidition is used, adaptive quantization must not be used */ + /* <=qcif must be used */ + { "Simple @ L1", 0x01, 176, 144, 15, 4, 198, 99, 1485, 100, 10*16368, 2048, 64, PROFILE_ADAPTQUANT }, + { "Simple @ L2", 0x02, 352, 288, 15, 4, 792, 396, 5940, 100, 40*16368, 4096, 128, PROFILE_ADAPTQUANT }, + { "Simple @ L3", 0x03, 352, 288, 15, 4, 792, 396, 11880, 100, 40*16368, 8192, 384, PROFILE_ADAPTQUANT }, + + { "ARTS @ L1", 0x91, 176, 144, 15, 4, 198, 99, 1485, 100, 10*16368, 8192, 64, PROFILE_ARTS }, + { "ARTS @ L2", 0x92, 352, 288, 15, 4, 792, 396, 5940, 100, 40*16368, 16384, 128, PROFILE_ARTS }, + { "ARTS @ L3", 0x93, 352, 288, 30, 4, 792, 396, 11880, 100, 40*16368, 16384, 384, PROFILE_ARTS }, + { "ARTS @ L4", 0x94, 352, 288, 30, 16, 792, 396, 11880, 100, 80*16368, 16384, 2000, PROFILE_ARTS }, + + { "AS @ L0", 0xf0, 176, 144, 30, 1, 297, 99, 2970, 100, 10*16368, 2048, 128, PROFILE_AS }, + { "AS @ L1", 0xf1, 176, 144, 30, 4, 297, 99, 2970, 100, 10*16368, 2048, 128, PROFILE_AS }, + { "AS @ L2", 0xf2, 352, 288, 15, 4, 1188, 396, 5940, 100, 40*16368, 4096, 384, PROFILE_AS }, + { "AS @ L3", 0xf3, 352, 288, 30, 4, 1188, 396, 11880, 100, 40*16368, 4096, 768, PROFILE_AS }, + /* ISMA Profile 1, (ASP) @ L3b (CIF, 1.5 Mb/s) CIF(352x288), 30fps, 1.5Mbps max ??? */ + { "AS @ L4", 0xf4, 352, 576, 30, 4, 2376, 792, 23760, 50, 80*16368, 8192, 3000, PROFILE_AS }, + { "AS @ L5", 0xf5, 720, 576, 30, 4, 4860, 1620, 48600, 25, 112*16368, 16384, 8000, PROFILE_AS }, + +#ifdef DXN_PROFILES + { "DXN Handheld", 0x00, 176, 144, 15, -1, 198, 99, 1485, 100, 16*16368, -1, 128, PROFILE_ADAPTQUANT }, + { "DXN Portable NTSC", 0x00, 352, 240, 30, -1, 990, 330, 9900, 100, 64*16368, -1, 768, PROFILE_ADAPTQUANT|PROFILE_BVOP }, + { "DXN Portable PAL", 0x00, 352, 288, 25, -1, 1188, 396, 9900, 100, 64*16368, -1, 768, PROFILE_ADAPTQUANT|PROFILE_BVOP }, + { "DXN HT NTSC", 0x00, 720, 480, 30, -1, 4050, 1350, 40500, 100, 192*16368, -1, 4000, PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_INTERLACE }, + { "DXN HT PAL", 0x00, 720, 576, 25, -1, 4860, 1620, 40500, 100, 192*16368, -1, 4000, PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_INTERLACE }, + { "DXN HDTV", 0x00, 1280, 720, 30, -1,10800, 3600, 108000, 100, 384*16368, -1, 8000, PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_INTERLACE }, +#endif + + { "(unrestricted)", 0x00, 0, 0, 0, 0, 0, 0, 0, 100, 0*16368, 0, 0, 0xffffffff }, +}; -/* registry info structs */ +/* ===================================================================================== */ +/* REGISTRY ============================================================================ */ +/* ===================================================================================== */ + +/* registry info structs */ CONFIG reg; -REG_INT const reg_ints[] = { - {"mode", ®.mode, DLG_MODE_CBR}, - {"quality", ®.quality, 85}, - {"quant", ®.quant, 5}, - {"rc_bitrate", ®.rc_bitrate, 900000}, - {"rc_reaction_delay_factor",®.rc_reaction_delay_factor, 16}, - {"rc_averaging_period", ®.rc_averaging_period, 100}, - {"rc_buffer", ®.rc_buffer, 100}, +static const REG_INT reg_ints[] = { + {"mode", ®.mode, RC_MODE_1PASS}, + {"bitrate", ®.bitrate, 700}, + {"desired_size", ®.desired_size, 570000}, + {"use_2pass_bitrate", ®.use_2pass_bitrate, 0}, - {"motion_search", ®.motion_search, 6}, + /* profile */ {"quant_type", ®.quant_type, 0}, - {"fourcc_used", ®.fourcc_used, 0}, - {"vhq_mode", ®.vhq_mode, 0}, - {"max_key_interval", ®.max_key_interval, 300}, - {"min_key_interval", ®.min_key_interval, 1}, {"lum_masking", ®.lum_masking, 0}, {"interlacing", ®.interlacing, 0}, {"qpel", ®.qpel, 0}, {"gmc", ®.gmc, 0}, - {"chromame", ®.chromame, 0}, -//added by koepi for gruel's greyscale_mode - {"greyscale", ®.greyscale, 0}, -// end of koepi's additions - {"max_bframes", ®.max_bframes, -1}, - {"bquant_ratio", ®.bquant_ratio, 150}, - {"bquant_offset", ®.bquant_offset, 100}, - {"packed", ®.packed, 0}, - {"dx50bvop", ®.dx50bvop, 1}, - {"debug", ®.debug, 0}, {"reduced_resolution", ®.reduced_resolution, 0}, - {"chroma_opt", ®.chroma_opt, 0}, + {"use_bvop", ®.use_bvop, 1}, + {"max_bframes", ®.max_bframes, 2}, + {"bquant_ratio", ®.bquant_ratio, 150}, /* 100-base float */ + {"bquant_offset", ®.bquant_offset, 100}, /* 100-base float */ + {"packed", ®.packed, 1}, + {"closed_gov", ®.closed_gov, 1}, + + /* aspect ratio */ + {"ar_mode", ®.ar_mode, 0}, + {"aspect_ratio", ®.display_aspect_ratio, 0}, + {"par_x", ®.par_x, 1}, + {"par_y", ®.par_y, 1}, + {"ar_x", ®.ar_x, 4}, + {"ar_y", ®.ar_y, 3}, + + /* zones */ + {"num_zones", ®.num_zones, 1}, + + /* single pass */ + {"rc_reaction_delay_factor",®.rc_reaction_delay_factor, 16}, + {"rc_averaging_period", ®.rc_averaging_period, 100}, + {"rc_buffer", ®.rc_buffer, 100}, + + /* 2pass1 */ + {"discard1pass", ®.discard1pass, 1}, + + /* 2pass2 */ + {"keyframe_boost", ®.keyframe_boost, 0}, + {"kfreduction", ®.kfreduction, 20}, + {"kfthreshold", ®.kfthreshold, 1}, + {"curve_compression_high", ®.curve_compression_high, 0}, + {"curve_compression_low", ®.curve_compression_low, 0}, + {"overflow_control_strength", ®.overflow_control_strength, 5}, + {"twopass_max_overflow_improvement", ®.twopass_max_overflow_improvement, 5}, + {"twopass_max_overflow_degradation", ®.twopass_max_overflow_degradation, 5}, + + /* motion */ + {"motion_search", ®.motion_search, 6}, + {"vhq_mode", ®.vhq_mode, 1}, + {"chromame", ®.chromame, 1}, + {"cartoon_mode", ®.cartoon_mode, 0}, + {"turbo", ®.turbo, 0}, + {"max_key_interval", ®.max_key_interval, 300}, {"frame_drop_ratio", ®.frame_drop_ratio, 0}, + /* quant */ {"min_iquant", ®.min_iquant, 2}, {"max_iquant", ®.max_iquant, 31}, {"min_pquant", ®.min_pquant, 2}, {"max_pquant", ®.max_pquant, 31}, + {"min_bquant", ®.min_bquant, 2}, + {"max_bquant", ®.max_bquant, 31}, + {"trellis_quant", ®.trellis_quant, 0}, - {"desired_size", ®.desired_size, 570000}, - {"keyframe_boost", ®.keyframe_boost, 0}, - {"discard1pass", ®.discard1pass, 1}, - {"dummy2pass", ®.dummy2pass, 0}, -// added by koepi for new two-pass curve treatment - {"kftreshold", ®.kftreshold, 10}, - {"kfreduction", ®.kfreduction, 20}, -// end of koepi's additions - {"curve_compression_high", ®.curve_compression_high, 0}, - {"curve_compression_low", ®.curve_compression_low, 0}, - {"use_alt_curve", ®.use_alt_curve, 0}, - {"alt_curve_use_auto", ®.alt_curve_use_auto, 1}, - {"alt_curve_auto_str", ®.alt_curve_auto_str, 30}, - {"alt_curve_use_auto_bonus_bias", ®.alt_curve_use_auto_bonus_bias, 1}, - {"alt_curve_bonus_bias", ®.alt_curve_bonus_bias, 50}, - {"alt_curve_type", ®.alt_curve_type, 1}, - {"alt_curve_high_dist", ®.alt_curve_high_dist, 500}, - {"alt_curve_low_dist", ®.alt_curve_low_dist, 90}, - {"alt_curve_min_rel_qual", ®.alt_curve_min_rel_qual, 50}, - {"bitrate_payback_delay", ®.bitrate_payback_delay, 250}, - {"bitrate_payback_method", ®.bitrate_payback_method, 0}, - {"twopass_max_bitrate", ®.twopass_max_bitrate, 10000 * CONFIG_KBPS}, - {"twopass_max_overflow_improvement", ®.twopass_max_overflow_improvement, 60}, - {"twopass_max_overflow_degradation", ®.twopass_max_overflow_degradation, 60}, - {"hinted_me", ®.hinted_me, 0}, - - {"credits_start", ®.credits_start, 0}, - {"credits_start_begin", ®.credits_start_begin, 0}, - {"credits_start_end", ®.credits_start_end, 0}, - {"credits_end", ®.credits_end, 0}, - {"credits_end_begin", ®.credits_end_begin, 0}, - {"credits_end_end", ®.credits_end_end, 0}, - -// added by koepi for greyscale credits - {"credits_greyscale", ®.credits_greyscale, 0}, -// end of koepi's addition - {"credits_mode", ®.credits_mode, 0}, - {"credits_rate", ®.credits_rate, 20}, - {"credits_quant_i", ®.credits_quant_i, 20}, - {"credits_quant_p", ®.credits_quant_p, 20}, - {"credits_start_size", ®.credits_start_size, 10000}, - {"credits_end_size", ®.credits_end_size, 10000}, - - /* decoder */ - {"deblock_y", ®.deblock_y, 0}, - {"deblock_uv", ®.deblock_uv, 0} + /* debug */ + {"fourcc_used", ®.fourcc_used, 0}, + {"debug", ®.debug, 0x0}, + {"vop_debug", ®.vop_debug, 0}, + {"display_status", ®.display_status, 1}, + + /* decoder, shared with dshow */ + {"Deblock_Y", &pp_dy, 0}, + {"Deblock_UV", &pp_duv, 0}, + {"Dering", &pp_dr, 0}, + {"FilmEffect", &pp_fe, 0}, + +}; + +static const REG_STR reg_strs[] = { + {"profile", reg.profile_name, "(unrestricted)"}, + {"stats", reg.stats, CONFIG_2PASS_FILE}, }; -REG_STR const reg_strs[] = { - {"hintfile", reg.hintfile, CONFIG_HINTFILE}, - {"stats1", reg.stats1, CONFIG_2PASS_1_FILE}, - {"stats2", reg.stats2, CONFIG_2PASS_2_FILE} -// {"build", reg.build, XVID_BUILD} + +zone_t stmp; +static const REG_INT reg_zone[] = { + {"zone%i_frame", &stmp.frame, 0}, + {"zone%i_mode", &stmp.mode, RC_ZONE_WEIGHT}, + {"zone%i_weight", &stmp.weight, 100}, /* 100-base float */ + {"zone%i_quant", &stmp.quant, 500}, /* 100-base float */ + {"zone%i_type", &stmp.type, XVID_TYPE_AUTO}, + {"zone%i_greyscale", &stmp.greyscale, 0}, + {"zone%i_chroma_opt", &stmp.chroma_opt, 0}, + {"zone%i_bvop_threshold", &stmp.bvop_threshold, 0}, +}; + +static const BYTE default_qmatrix_intra[] = { + 8, 17,18,19,21,23,25,27, + 17,18,19,21,23,25,27,28, + 20,21,22,23,24,26,28,30, + 21,22,23,24,26,28,30,32, + 22,23,24,26,28,30,32,35, + 23,24,26,28,30,32,35,38, + 25,26,28,30,32,35,38,41, + 27,28,30,32,35,38,41,45 }; -/* get config settings from registry */ +static const BYTE default_qmatrix_inter[] = { + 16,17,18,19,20,21,22,23, + 17,18,19,20,21,22,23,24, + 18,19,20,21,22,23,24,25, + 19,20,21,22,23,24,26,27, + 20,21,22,23,25,26,27,28, + 21,22,23,24,26,27,28,30, + 22,23,24,26,27,28,30,31, + 23,24,25,27,28,30,31,33 +}; + + #define REG_GET_B(X, Y, Z) size=sizeof((Z));if(RegQueryValueEx(hKey, X, 0, 0, Y, &size) != ERROR_SUCCESS) {memcpy(Y, Z, sizeof((Z)));} +#define XVID_DLL_NAME "xvidcore.dll" + void config_reg_get(CONFIG * config) { + char tmp[32]; HKEY hKey; DWORD size; - int i; + int i,j; xvid_gbl_info_t info; + HINSTANCE m_hdll; memset(&info, 0, sizeof(info)); info.version = XVID_VERSION; - xvid_global(0, XVID_GBL_INFO, &info, NULL); + + m_hdll = LoadLibrary(XVID_DLL_NAME); + if (m_hdll != NULL) { + + ((int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global")) + (0, XVID_GBL_INFO, &info, NULL); + + FreeLibrary(m_hdll); + } + reg.cpu = info.cpu_flags; reg.num_threads = info.num_threads; - + RegOpenKeyEx(XVID_REG_KEY, XVID_REG_PARENT "\\" XVID_REG_CHILD, 0, KEY_READ, &hKey); - for (i=0 ; iqmatrix_intra, default_qmatrix_intra); + REG_GET_B("qmatrix_inter", config->qmatrix_inter, default_qmatrix_inter); + + + /* read zones */ + if (config->num_zones>MAX_ZONES) { + config->num_zones=MAX_ZONES; + }else if (config->num_zones<=0) { + config->num_zones = 1; + } + + for (i=0; inum_zones; i++) { + for (j=0; jzones[i], &stmp, sizeof(zone_t)); + } + RegCloseKey(hKey); } @@ -243,9 +365,10 @@ void config_reg_set(CONFIG * config) { + char tmp[64]; HKEY hKey; DWORD dispo; - int i; + int i,j; if (RegCreateKeyEx( XVID_REG_KEY, @@ -254,28 +377,39 @@ XVID_REG_CLASS, REG_OPTION_NON_VOLATILE, KEY_WRITE, - 0, - &hKey, + 0, + &hKey, &dispo) != ERROR_SUCCESS) { - DEBUG1("Couldn't create XVID_REG_SUBKEY - ", GetLastError()); + DPRINTF("Couldn't create XVID_REG_SUBKEY - GetLastError=%i", GetLastError()); return; } memcpy(®, config, sizeof(CONFIG)); - for (i=0 ; iqmatrix_intra); + REG_SET_B("qmatrix_inter", config->qmatrix_inter); + + /* set seections */ + for (i=0; inum_zones; i++) { + memcpy(&stmp, &config->zones[i], sizeof(zone_t)); + for (j=0; jmode) - { - default : - case DLG_MODE_CBR : - config->rc_bitrate = config_get_uint(hDlg, IDC_VALUE, config->rc_bitrate) * CONFIG_KBPS; - break; + char buf[FLOAT_BUF_SZ]; - case DLG_MODE_VBR_QUAL : - config->quality = config_get_uint(hDlg, IDC_VALUE, config->quality); - break; + if (GetDlgItemText(hDlg, item, buf, FLOAT_BUF_SZ) == 0) + return def; - case DLG_MODE_VBR_QUANT : - config->quant = config_get_uint(hDlg, IDC_VALUE, config->quant); - break; + return (int)(atof(buf)*100); +} - case DLG_MODE_2PASS_2_INT : - config->desired_size = config_get_uint(hDlg, IDC_VALUE, config->desired_size); - break; +void set_dlgitem_float(HWND hDlg, UINT item, int value) +{ + char buf[FLOAT_BUF_SZ]; + sprintf(buf, "%.2f", (float)value/100); + SetDlgItemText(hDlg, item, buf); +} + + +#define HEX_BUF_SZ 16 +unsigned int get_dlgitem_hex(HWND hDlg, UINT item, unsigned int def) +{ + char buf[HEX_BUF_SZ]; + unsigned int value; + + if (GetDlgItemText(hDlg, item, buf, HEX_BUF_SZ) == 0) + return def; + + if (sscanf(buf,"0x%x", &value)==1 || sscanf(buf,"%x", &value)==1) { + return value; } - config->mode = SendDlgItemMessage(hDlg, IDC_MODE, CB_GETCURSEL, 0, 0); + return def; } +void set_dlgitem_hex(HWND hDlg, UINT item, int value) +{ + char buf[HEX_BUF_SZ]; + wsprintf(buf, "0x%x", value); + SetDlgItemText(hDlg, item, buf); +} -/* updates the edit box */ +/* ===================================================================================== */ +/* QUANT MATRIX DIALOG ================================================================= */ +/* ===================================================================================== */ -void main_value(HWND hDlg, CONFIG* config) +void quant_upload(HWND hDlg, CONFIG* config) { - char* text; - int value; - int enabled = TRUE; + int i; - switch (config->mode) - { - default : - enabled = FALSE; + for (i=0 ; i<64; i++) { + SetDlgItemInt(hDlg, IDC_QINTRA00 + i, config->qmatrix_intra[i], FALSE); + SetDlgItemInt(hDlg, IDC_QINTER00 + i, config->qmatrix_inter[i], FALSE); + } +} - case DLG_MODE_CBR : - text = "Bitrate (Kbps):"; - value = config->rc_bitrate / CONFIG_KBPS; - break; - case DLG_MODE_VBR_QUAL : - text = "Quality:"; - value = config->quality; - break; +void quant_download(HWND hDlg, CONFIG* config) +{ + int i; - case DLG_MODE_VBR_QUANT : - text = "Quantizer:"; - value = config->quant; - break; + for (i=0; i<64; i++) { + int temp; - case DLG_MODE_2PASS_2_INT : - text = "Desired size (Kbtyes):"; - value = config->desired_size; - break; + temp = config_get_uint(hDlg, i + IDC_QINTRA00, config->qmatrix_intra[i]); + CONSTRAINVAL(temp, 1, 255); + config->qmatrix_intra[i] = temp; + + temp = config_get_uint(hDlg, i + IDC_QINTER00, config->qmatrix_inter[i]); + CONSTRAINVAL(temp, 1, 255); + config->qmatrix_inter[i] = temp; } +} - SetDlgItemText(hDlg, IDC_VALUE_STATIC, text); - SetDlgItemInt(hDlg, IDC_VALUE, value, FALSE); - EnableWindow(GetDlgItem(hDlg, IDC_VALUE_STATIC), enabled); - EnableWindow(GetDlgItem(hDlg, IDC_VALUE), enabled); -} +void quant_loadsave(HWND hDlg, CONFIG * config, int save) +{ + char file[MAX_PATH]; + OPENFILENAME ofn; + HANDLE hFile; + DWORD read=128, wrote=0; + BYTE quant_data[128]; + + strcpy(file, "\\matrix"); + memset(&ofn, 0, sizeof(OPENFILENAME)); + ofn.lStructSize = sizeof(OPENFILENAME); + + ofn.hwndOwner = hDlg; + ofn.lpstrFilter = "All files (*.*)\0*.*\0\0"; + ofn.lpstrFile = file; + ofn.nMaxFile = MAX_PATH; + ofn.Flags = OFN_PATHMUSTEXIST; + + if (save) { + ofn.Flags |= OFN_OVERWRITEPROMPT; + if (GetSaveFileName(&ofn)) { + hFile = CreateFile(file, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + + quant_download(hDlg, config); + memcpy(quant_data, config->qmatrix_intra, 64); + memcpy(quant_data+64, config->qmatrix_inter, 64); + if (hFile == INVALID_HANDLE_VALUE) { + DPRINTF("Couldn't save quant matrix"); + }else{ + if (!WriteFile(hFile, quant_data, 128, &wrote, 0)) { + DPRINTF("Couldnt write quant matrix"); + } + } + CloseHandle(hFile); + } + }else{ + ofn.Flags |= OFN_FILEMUSTEXIST; + if (GetOpenFileName(&ofn)) { + hFile = CreateFile(file, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + + if (hFile == INVALID_HANDLE_VALUE) { + DPRINTF("Couldn't load quant matrix"); + } else { + if (!ReadFile(hFile, quant_data, 128, &read, 0)) { + DPRINTF("Couldnt read quant matrix"); + }else{ + memcpy(config->qmatrix_intra, quant_data, 64); + memcpy(config->qmatrix_inter, quant_data+64, 64); + quant_upload(hDlg, config); + } + } + CloseHandle(hFile); + } + } +} -/* updates the slider */ +/* quantization matrix dialog proc */ -void main_slider(HWND hDlg, CONFIG * config) +BOOL CALLBACK quantmatrix_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - char* text; - long range; - int pos; - int enabled = TRUE; + CONFIG* config = (CONFIG*)GetWindowLong(hDlg, GWL_USERDATA); - switch (config->mode) + switch (uMsg) { - default : - enabled = FALSE; + case WM_INITDIALOG : + SetWindowLong(hDlg, GWL_USERDATA, lParam); + config = (CONFIG*)lParam; + quant_upload(hDlg, config); - case DLG_MODE_CBR : - text = "Bitrate (Kbps):"; - range = MAKELONG(0,10000); - pos = config->rc_bitrate / CONFIG_KBPS; + if (g_hTooltip) + { + EnumChildWindows(hDlg, enum_tooltips, 0); + } break; - case DLG_MODE_VBR_QUAL : - text = "Quality:"; - range = MAKELONG(0,100); - pos = config->quality; - break; + case WM_COMMAND : - case DLG_MODE_VBR_QUANT : - text = "Quantizer:"; - range = MAKELONG(1,31); - pos = config->quant; - break; - } + if (HIWORD(wParam) == BN_CLICKED) { + switch(LOWORD(wParam)) { + case IDOK : + quant_download(hDlg, config); + EndDialog(hDlg, IDOK); + break; + + case IDCANCEL : + EndDialog(hDlg, IDCANCEL); + break; - SetDlgItemText(hDlg, IDC_SLIDER_STATIC, text); - SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETRANGE, TRUE, range); - SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE, pos); + case IDC_SAVE : + quant_loadsave(hDlg, config, 1); + break; + + case IDC_LOAD : + quant_loadsave(hDlg, config, 0); + break; + + default : + return FALSE; + } + break; + } + return FALSE; - EnableWindow(GetDlgItem(hDlg, IDC_SLIDER_STATIC), enabled); - EnableWindow(GetDlgItem(hDlg, IDC_SLIDER), enabled); + default : + return FALSE; + } + + return TRUE; } -/* load advanced options property sheet */ +/* ===================================================================================== */ +/* ADVANCED DIALOG PAGES ================================================================ */ +/* ===================================================================================== */ -void adv_dialog(HWND hParent, CONFIG * config) +/* initialise pages */ +void adv_init(HWND hDlg, int idd, CONFIG * config) { - PROPSHEETINFO psi[DLG_COUNT]; - PROPSHEETPAGE psp[DLG_COUNT]; - PROPSHEETHEADER psh; - CONFIG temp; - int i; + unsigned int i; - config->save = FALSE; - memcpy(&temp, config, sizeof(CONFIG)); + switch(idd) { + case IDD_PROFILE : + for (i=0; ici_valid); + break; - psp[DLG_GLOBAL].pszTemplate = MAKEINTRESOURCE(IDD_GLOBAL); - psp[DLG_QUANT].pszTemplate = MAKEINTRESOURCE(IDD_QUANT); - psp[DLG_2PASS].pszTemplate = MAKEINTRESOURCE(IDD_2PASS); - psp[DLG_2PASSALT].pszTemplate = MAKEINTRESOURCE(IDD_2PASSALT); - psp[DLG_CREDITS].pszTemplate = MAKEINTRESOURCE(IDD_CREDITS); - psp[DLG_CPU].pszTemplate = MAKEINTRESOURCE(IDD_CPU); + case IDD_MOTION : + SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"0 - None"); + SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"1 - Very Low"); + SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"2 - Low"); + SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"3 - Medium"); + SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"4 - High"); + SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"5 - Very High"); + SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"6 - Ultra High"); - psh.dwSize = sizeof(PROPSHEETHEADER); - psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW; - psh.hwndParent = hParent; - psh.hInstance = hInst; - psh.pszCaption = (LPSTR) "XviD Configuration"; - psh.nPages = DLG_COUNT; - psh.nStartPage = DLG_GLOBAL; - psh.ppsp = (LPCPROPSHEETPAGE)&psp; - psh.pfnCallback = NULL; + SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"0 - Off"); + SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"1 - Mode Decision"); + SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"2 - Limited Search"); + SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"3 - Medium Search"); + SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"4 - Wide Search"); + break; - PropertySheet(&psh); + case IDD_DEBUG : + /* force threads disabled */ + EnableWindow(GetDlgItem(hDlg, IDC_NUMTHREADS_STATIC), FALSE); + EnableWindow(GetDlgItem(hDlg, IDC_NUMTHREADS), FALSE); - if (temp.save) - { - memcpy(config, &temp, sizeof(CONFIG)); + SendDlgItemMessage(hDlg, IDC_FOURCC, CB_ADDSTRING, 0, (LPARAM)"XVID"); + SendDlgItemMessage(hDlg, IDC_FOURCC, CB_ADDSTRING, 0, (LPARAM)"DIVX"); + SendDlgItemMessage(hDlg, IDC_FOURCC, CB_ADDSTRING, 0, (LPARAM)"DX50"); + break; } } -/* enable/disable advanced controls based on encoder mode */ - -#define CONTROLDLG(X,Y) EnableWindow(GetDlgItem(hDlg, (X)), (Y)) -#define ISDLGSET(X) (IsDlgButtonChecked(hDlg, (X)) == BST_CHECKED) +/* enable/disable controls based on encoder-mode or user selection */ -#define MOD_CBR - -void adv_mode(HWND hDlg, int mode) +void adv_mode(HWND hDlg, int idd, CONFIG * config) { - // create arrays of controls to be disabled for each mode - const short twopass_disable[] = { - IDC_KFBOOST, IDC_DUMMY2PASS, IDC_USEALT, -// added by koepi for new curve treatment - IDC_KFTRESHOLD, IDC_KFREDUCTION, -//end of koepi's additions - IDC_CURVECOMPH, IDC_CURVECOMPL, IDC_PAYBACK, IDC_PAYBACKBIAS, IDC_PAYBACKPROP, - IDC_STATS2, IDC_STATS2_BROWSE, - }; - - const short cbr_disable[] = { - IDC_STATS1, IDC_STATS1_BROWSE, IDC_DISCARD1PASS, IDC_HINTEDME, - IDC_CREDITS_START, IDC_CREDITS_END, IDC_CREDITS_START_BEGIN, IDC_CREDITS_START_END, - IDC_CREDITS_END_BEGIN, IDC_CREDITS_END_END, IDC_CREDITS_RATE_RADIO, - IDC_CREDITS_QUANT_RADIO, IDC_CREDITS_QUANT_STATIC, IDC_CREDITS_SIZE_RADIO, - IDC_CREDITS_QUANTI, IDC_CREDITS_QUANTP, IDC_CREDITS_END_STATIC, IDC_CREDITS_RATE, - IDC_CREDITS_START_SIZE, IDC_CREDITS_END_SIZE, IDC_CREDITS_GREYSCALE, IDC_HINTFILE - }; - - const short qual_disable[] = { - IDC_STATS1, IDC_STATS1_BROWSE, IDC_DISCARD1PASS, IDC_HINTEDME, - IDC_CBR_REACTIONDELAY, IDC_CBR_AVERAGINGPERIOD, IDC_CBR_BUFFER, - IDC_CREDITS_SIZE_RADIO, IDC_CREDITS_END_STATIC, IDC_CREDITS_START_SIZE, IDC_CREDITS_END_SIZE, - IDC_HINTFILE - }; - - const short quant_disable[] = { - IDC_STATS1, IDC_STATS1_BROWSE, IDC_DISCARD1PASS, IDC_HINTEDME, - IDC_CBR_REACTIONDELAY, IDC_CBR_AVERAGINGPERIOD, IDC_CBR_BUFFER, - IDC_MINIQUANT, IDC_MAXIQUANT, IDC_MINPQUANT, IDC_MAXPQUANT, - IDC_CREDITS_SIZE_RADIO, IDC_CREDITS_END_STATIC, IDC_CREDITS_START_SIZE, IDC_CREDITS_END_SIZE, - IDC_HINTFILE - }; - - const short twopass1_disable[] = { - IDC_CBR_REACTIONDELAY, IDC_CBR_AVERAGINGPERIOD, IDC_CBR_BUFFER, - IDC_MINIQUANT, IDC_MAXIQUANT, IDC_MINPQUANT, IDC_MAXPQUANT, - IDC_CREDITS_RATE_RADIO, IDC_CREDITS_RATE, IDC_CREDITS_SIZE_RADIO, IDC_CREDITS_END_STATIC, - IDC_CREDITS_START_SIZE, IDC_CREDITS_END_SIZE - }; - - const short twopass2_ext_disable[] = { - IDC_CBR_REACTIONDELAY, IDC_CBR_AVERAGINGPERIOD, IDC_CBR_BUFFER, - IDC_CREDITS_RATE_RADIO, - IDC_CREDITS_SIZE_RADIO, IDC_CREDITS_END_STATIC, IDC_CREDITS_RATE, - IDC_CREDITS_START_SIZE, IDC_CREDITS_END_SIZE - }; - - const short twopass2_int_disable[] = { - IDC_CBR_REACTIONDELAY, IDC_CBR_AVERAGINGPERIOD, IDC_CBR_BUFFER, - IDC_STATS2, IDC_STATS2_BROWSE - }; - - // store pointers in order so we can lookup using config->mode - const short* modes[] = { - cbr_disable, qual_disable, quant_disable, - twopass1_disable, twopass2_ext_disable, twopass2_int_disable - }; - - // ditto modes[] - const int lengths[] = { - sizeof(cbr_disable)/sizeof(short), sizeof(qual_disable)/sizeof(short), - sizeof(quant_disable)/sizeof(short), sizeof(twopass1_disable)/sizeof(short), - sizeof(twopass2_ext_disable)/sizeof(short), sizeof(twopass2_int_disable)/sizeof(short), 0 - }; - - int i; - int hinted_me, use_alt, use_alt_auto, use_alt_auto_bonus; - int credits_start, credits_end, credits_rate, credits_quant, credits_size; + int profile; + int weight_en, quant_en; int cpu_force; + int custom_quant, bvops; + int ar_mode, ar_par; - // first perform checkbox-based enable/disable - hinted_me = ISDLGSET(IDC_HINTEDME); - CONTROLDLG(IDC_HINTFILE, hinted_me); - CONTROLDLG(IDC_HINT_BROWSE, hinted_me); - - use_alt = ISDLGSET(IDC_USEALT) && (mode == DLG_MODE_2PASS_2_EXT || mode == DLG_MODE_2PASS_2_INT); - use_alt_auto = ISDLGSET(IDC_USEAUTO); - use_alt_auto_bonus = ISDLGSET(IDC_USEAUTOBONUS); - CONTROLDLG(IDC_USEAUTO, use_alt); - CONTROLDLG(IDC_AUTOSTR, use_alt && use_alt_auto); - CONTROLDLG(IDC_USEAUTOBONUS, use_alt); - CONTROLDLG(IDC_BONUSBIAS, use_alt && !use_alt_auto_bonus); - CONTROLDLG(IDC_CURVETYPE, use_alt); - CONTROLDLG(IDC_ALTCURVEHIGH, use_alt); - CONTROLDLG(IDC_ALTCURVELOW, use_alt); - CONTROLDLG(IDC_MINQUAL, use_alt && !use_alt_auto); - - credits_start = ISDLGSET(IDC_CREDITS_START); - CONTROLDLG(IDC_CREDITS_START_BEGIN, credits_start); - CONTROLDLG(IDC_CREDITS_START_END, credits_start); - - credits_end = ISDLGSET(IDC_CREDITS_END); - CONTROLDLG(IDC_CREDITS_END_BEGIN, credits_end); - CONTROLDLG(IDC_CREDITS_END_END, credits_end); - - credits_rate = ISDLGSET(IDC_CREDITS_RATE_RADIO); - credits_quant = ISDLGSET(IDC_CREDITS_QUANT_RADIO); - credits_size = ISDLGSET(IDC_CREDITS_SIZE_RADIO); - CONTROLDLG(IDC_CREDITS_RATE, credits_rate); - CONTROLDLG(IDC_CREDITS_QUANTI, credits_quant); - CONTROLDLG(IDC_CREDITS_QUANTP, credits_quant); - CONTROLDLG(IDC_CREDITS_START_SIZE, credits_size); - CONTROLDLG(IDC_CREDITS_END_SIZE, credits_size); - - cpu_force = ISDLGSET(IDC_CPU_FORCE); - CONTROLDLG(IDC_CPU_MMX, cpu_force); - CONTROLDLG(IDC_CPU_MMXEXT, cpu_force); - CONTROLDLG(IDC_CPU_SSE, cpu_force); - CONTROLDLG(IDC_CPU_SSE2, cpu_force); - CONTROLDLG(IDC_CPU_3DNOW, cpu_force); - CONTROLDLG(IDC_CPU_3DNOWEXT, cpu_force); - - // now perform codec mode enable/disable - for (i=0 ; ipar_y, FALSE); + SetDlgItemInt(hDlg, IDC_PARX, config->par_x, FALSE); + + EnableDlgWindow(hDlg, IDC_PARX, ar_mode); + EnableDlgWindow(hDlg, IDC_PARY, ar_mode); + } else { + SetDlgItemInt(hDlg, IDC_PARX, PARS[ar_par][0], FALSE); + SetDlgItemInt(hDlg, IDC_PARY, PARS[ar_par][1], FALSE); + EnableDlgWindow(hDlg, IDC_PARX, FALSE); + EnableDlgWindow(hDlg, IDC_PARY, FALSE); + } + + ar_mode = IsDlgChecked(hDlg, IDC_AR); + + config->ar_x = config_get_uint(hDlg, IDC_ARX, config->ar_x); + config->ar_y = config_get_uint(hDlg, IDC_ARY, config->ar_y); + + EnableDlgWindow(hDlg, IDC_ARX, ar_mode); + EnableDlgWindow(hDlg, IDC_ARY, ar_mode); + break; + + case IDD_LEVEL : + profile = SendDlgItemMessage(hDlg, IDC_LEVEL_PROFILE, CB_GETCURSEL, 0, 0); + SetDlgItemInt(hDlg, IDC_LEVEL_WIDTH, profiles[profile].width, FALSE); + SetDlgItemInt(hDlg, IDC_LEVEL_HEIGHT, profiles[profile].height, FALSE); + SetDlgItemInt(hDlg, IDC_LEVEL_FPS, profiles[profile].fps, FALSE); + SetDlgItemInt(hDlg, IDC_LEVEL_VMV, profiles[profile].max_vmv_buffer_sz, FALSE); + SetDlgItemInt(hDlg, IDC_LEVEL_VCV, profiles[profile].vcv_decoder_rate, FALSE); + SetDlgItemInt(hDlg, IDC_LEVEL_VBV, profiles[profile].max_vbv_size, FALSE); + SetDlgItemInt(hDlg, IDC_LEVEL_BITRATE, profiles[profile].max_bitrate, FALSE); + break; + + case IDD_ZONE : + weight_en = IsDlgChecked(hDlg, IDC_ZONE_MODE_WEIGHT); + quant_en = IsDlgChecked(hDlg, IDC_ZONE_MODE_QUANT); + EnableDlgWindow(hDlg, IDC_ZONE_WEIGHT, weight_en); + EnableDlgWindow(hDlg, IDC_ZONE_QUANT, quant_en); + EnableDlgWindow(hDlg, IDC_ZONE_SLIDER, weight_en|quant_en); + + if (weight_en) { + SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(001,200)); + SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETPOS, TRUE, get_dlgitem_float(hDlg, IDC_ZONE_WEIGHT, 100)); + SetDlgItemText(hDlg, IDC_ZONE_MIN, "0.01"); + SetDlgItemText(hDlg, IDC_ZONE_MAX, "2.00"); + }else if (quant_en) { + SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(100,3100)); + SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETPOS, TRUE, get_dlgitem_float(hDlg, IDC_ZONE_QUANT, 100)); + SetDlgItemText(hDlg, IDC_ZONE_MIN, "1"); + SetDlgItemText(hDlg, IDC_ZONE_MAX, "31"); + } + + bvops = (profiles[config->profile].flags&PROFILE_BVOP) && config->use_bvop; + EnableDlgWindow(hDlg, IDC_ZONE_BVOPTHRESHOLD_S, bvops); + EnableDlgWindow(hDlg, IDC_ZONE_BVOPTHRESHOLD, bvops); + break; + + case IDD_DEBUG : + cpu_force = IsDlgChecked(hDlg, IDC_CPU_FORCE); + EnableDlgWindow(hDlg, IDC_CPU_MMX, cpu_force); + EnableDlgWindow(hDlg, IDC_CPU_MMXEXT, cpu_force); + EnableDlgWindow(hDlg, IDC_CPU_SSE, cpu_force); + EnableDlgWindow(hDlg, IDC_CPU_SSE2, cpu_force); + EnableDlgWindow(hDlg, IDC_CPU_3DNOW, cpu_force); + EnableDlgWindow(hDlg, IDC_CPU_3DNOWEXT, cpu_force); + break; } } /* upload config data into dialog */ - -void adv_upload(HWND hDlg, int page, CONFIG * config) +void adv_upload(HWND hDlg, int idd, CONFIG * config) { - switch (page) + switch (idd) { - case DLG_GLOBAL : - SendDlgItemMessage(hDlg, IDC_MOTION, CB_SETCURSEL, config->motion_search, 0); + case IDD_PROFILE : + SendDlgItemMessage(hDlg, IDC_PROFILE_PROFILE, CB_SETCURSEL, config->profile, 0); + SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_SETCURSEL, config->quant_type, 0); - SendDlgItemMessage(hDlg, IDC_FOURCC, CB_SETCURSEL, config->fourcc_used, 0); - SendDlgItemMessage(hDlg, IDC_VHQ, CB_SETCURSEL, config->vhq_mode, 0); - SetDlgItemInt(hDlg, IDC_MAXKEY, config->max_key_interval, FALSE); - SetDlgItemInt(hDlg, IDC_MINKEY, config->min_key_interval, FALSE); - CheckDlgButton(hDlg, IDC_LUMMASK, config->lum_masking ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg, IDC_INTERLACING, config->interlacing ? BST_CHECKED : BST_UNCHECKED); - - CheckDlgButton(hDlg, IDC_QPEL, config->qpel ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg, IDC_GMC, config->gmc ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg, IDC_CHROMAME, config->chromame ? BST_CHECKED : BST_UNCHECKED); -// added by koepi for gruel's greyscale_mode - CheckDlgButton(hDlg, IDC_GREYSCALE, config->greyscale ? BST_CHECKED : BST_UNCHECKED); -// end of koepi's addition - SetDlgItemInt(hDlg, IDC_MAXBFRAMES, config->max_bframes, TRUE); - SetDlgItemInt(hDlg, IDC_BQUANTRATIO, config->bquant_ratio, FALSE); - SetDlgItemInt(hDlg, IDC_BQUANTOFFSET, config->bquant_offset, FALSE); - CheckDlgButton(hDlg, IDC_PACKED, config->packed ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg, IDC_DX50BVOP, config->dx50bvop ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg, IDC_DEBUG, config->debug ? BST_CHECKED : BST_UNCHECKED); - - CheckDlgButton(hDlg, IDC_REDUCED, config->reduced_resolution ? BST_CHECKED : BST_UNCHECKED); + CheckDlg(hDlg, IDC_LUMMASK, config->lum_masking); + CheckDlg(hDlg, IDC_INTERLACING, config->interlacing); + CheckDlg(hDlg, IDC_QPEL, config->qpel); + CheckDlg(hDlg, IDC_GMC, config->gmc); + CheckDlg(hDlg, IDC_REDUCED, config->reduced_resolution); + CheckDlg(hDlg, IDC_BVOP, config->use_bvop); + + SetDlgItemInt(hDlg, IDC_MAXBFRAMES, config->max_bframes, FALSE); + set_dlgitem_float(hDlg, IDC_BQUANTRATIO, config->bquant_ratio); + set_dlgitem_float(hDlg, IDC_BQUANTOFFSET, config->bquant_offset); + CheckDlg(hDlg, IDC_PACKED, config->packed); + CheckDlg(hDlg, IDC_CLOSEDGOV, config->closed_gov); + + break; + case IDD_AR: + CheckRadioButton(hDlg, IDC_AR, IDC_PAR, config->ar_mode == 0 ? IDC_PAR : IDC_AR); + SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_SETCURSEL, (config->display_aspect_ratio), 0); + SetDlgItemInt(hDlg, IDC_ARX, config->ar_x, FALSE); + SetDlgItemInt(hDlg, IDC_ARY, config->ar_y, FALSE); break; - case DLG_QUANT : - SetDlgItemInt(hDlg, IDC_MINIQUANT, config->min_iquant, FALSE); - SetDlgItemInt(hDlg, IDC_MAXIQUANT, config->max_iquant, FALSE); - SetDlgItemInt(hDlg, IDC_MINPQUANT, config->min_pquant, FALSE); - SetDlgItemInt(hDlg, IDC_MAXPQUANT, config->max_pquant, FALSE); + case IDD_LEVEL : + SendDlgItemMessage(hDlg, IDC_LEVEL_PROFILE, CB_SETCURSEL, config->profile, 0); + break; + + case IDD_RC_CBR : + SetDlgItemInt(hDlg, IDC_CBR_REACTIONDELAY, config->rc_reaction_delay_factor, FALSE); + SetDlgItemInt(hDlg, IDC_CBR_AVERAGINGPERIOD, config->rc_averaging_period, FALSE); + SetDlgItemInt(hDlg, IDC_CBR_BUFFER, config->rc_buffer, FALSE); break; - case DLG_2PASS : + case IDD_RC_2PASS1 : + SetDlgItemText(hDlg, IDC_STATS, config->stats); + CheckDlg(hDlg, IDC_DISCARD1PASS, config->discard1pass); + break; + + case IDD_RC_2PASS2 : + SetDlgItemText(hDlg, IDC_STATS, config->stats); SetDlgItemInt(hDlg, IDC_KFBOOST, config->keyframe_boost, FALSE); - CheckDlgButton(hDlg, IDC_DISCARD1PASS, config->discard1pass ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg, IDC_DUMMY2PASS, config->dummy2pass ? BST_CHECKED : BST_UNCHECKED); -// added by koepi for new 2pass curve treatment - SetDlgItemInt(hDlg, IDC_KFTRESHOLD, config->kftreshold, FALSE); SetDlgItemInt(hDlg, IDC_KFREDUCTION, config->kfreduction, FALSE); -// end of koepi's additions + + SetDlgItemInt(hDlg, IDC_OVERFLOW_CONTROL_STRENGTH, config->overflow_control_strength, FALSE); + SetDlgItemInt(hDlg, IDC_OVERIMP, config->twopass_max_overflow_improvement, FALSE); + SetDlgItemInt(hDlg, IDC_OVERDEG, config->twopass_max_overflow_degradation, FALSE); + SetDlgItemInt(hDlg, IDC_CURVECOMPH, config->curve_compression_high, FALSE); SetDlgItemInt(hDlg, IDC_CURVECOMPL, config->curve_compression_low, FALSE); - SetDlgItemInt(hDlg, IDC_PAYBACK, config->bitrate_payback_delay, FALSE); - CheckDlgButton(hDlg, IDC_PAYBACKBIAS, (config->bitrate_payback_method == 0)); - CheckDlgButton(hDlg, IDC_PAYBACKPROP, (config->bitrate_payback_method == 1)); - - CheckDlgButton(hDlg, IDC_HINTEDME, config->hinted_me ? BST_CHECKED : BST_UNCHECKED); - SetDlgItemText(hDlg, IDC_HINTFILE, config->hintfile); - SetDlgItemText(hDlg, IDC_STATS1, config->stats1); - SetDlgItemText(hDlg, IDC_STATS2, config->stats2); + SetDlgItemInt(hDlg, IDC_MINKEY, config->kfthreshold, FALSE); break; - case DLG_2PASSALT : - CheckDlgButton(hDlg, IDC_USEALT, config->use_alt_curve ? BST_CHECKED : BST_UNCHECKED); + case IDD_ZONE : + SetDlgItemInt(hDlg, IDC_ZONE_FRAME, config->zones[config->cur_zone].frame, FALSE); - SendDlgItemMessage(hDlg, IDC_CURVETYPE, CB_SETCURSEL, config->alt_curve_type, 0); - SetDlgItemInt(hDlg, IDC_ALTCURVEHIGH, config->alt_curve_high_dist, FALSE); - SetDlgItemInt(hDlg, IDC_ALTCURVELOW, config->alt_curve_low_dist, FALSE); - SetDlgItemInt(hDlg, IDC_MINQUAL, config->alt_curve_min_rel_qual, FALSE); + CheckDlgButton(hDlg, IDC_ZONE_MODE_WEIGHT, config->zones[config->cur_zone].mode == RC_ZONE_WEIGHT); + CheckDlgButton(hDlg, IDC_ZONE_MODE_QUANT, config->zones[config->cur_zone].mode == RC_ZONE_QUANT); - CheckDlgButton(hDlg, IDC_USEAUTO, config->alt_curve_use_auto ? BST_CHECKED : BST_UNCHECKED); - SetDlgItemInt(hDlg, IDC_AUTOSTR, config->alt_curve_auto_str, FALSE); + set_dlgitem_float(hDlg, IDC_ZONE_WEIGHT, config->zones[config->cur_zone].weight); + set_dlgitem_float(hDlg, IDC_ZONE_QUANT, config->zones[config->cur_zone].quant); + + CheckDlgButton(hDlg, IDC_ZONE_FORCEIVOP, config->zones[config->cur_zone].type==XVID_TYPE_IVOP); + CheckDlgButton(hDlg, IDC_ZONE_GREYSCALE, config->zones[config->cur_zone].greyscale); + CheckDlgButton(hDlg, IDC_ZONE_CHROMAOPT, config->zones[config->cur_zone].chroma_opt); - CheckDlgButton(hDlg, IDC_USEAUTOBONUS, config->alt_curve_use_auto_bonus_bias ? BST_CHECKED : BST_UNCHECKED); - SetDlgItemInt(hDlg, IDC_BONUSBIAS, config->alt_curve_bonus_bias, FALSE); - - SetDlgItemInt(hDlg, IDC_MAXBITRATE, config->twopass_max_bitrate / CONFIG_KBPS, FALSE); - SetDlgItemInt(hDlg, IDC_OVERIMP, config->twopass_max_overflow_improvement, FALSE); - SetDlgItemInt(hDlg, IDC_OVERDEG, config->twopass_max_overflow_degradation, FALSE); + SetDlgItemInt(hDlg, IDC_ZONE_BVOPTHRESHOLD, config->zones[config->cur_zone].bvop_threshold, TRUE); break; - case DLG_CREDITS : - CheckDlgButton(hDlg, IDC_CREDITS_START, config->credits_start ? BST_CHECKED : BST_UNCHECKED); - SetDlgItemInt(hDlg, IDC_CREDITS_START_BEGIN, config->credits_start_begin, FALSE); - SetDlgItemInt(hDlg, IDC_CREDITS_START_END, config->credits_start_end, FALSE); - CheckDlgButton(hDlg, IDC_CREDITS_END, config->credits_end ? BST_CHECKED : BST_UNCHECKED); - SetDlgItemInt(hDlg, IDC_CREDITS_END_BEGIN, config->credits_end_begin, FALSE); - SetDlgItemInt(hDlg, IDC_CREDITS_END_END, config->credits_end_end, FALSE); - -// added by koepi for credits greyscale - CheckDlgButton(hDlg, IDC_CREDITS_GREYSCALE, config->credits_greyscale ? BST_CHECKED : BST_UNCHECKED); -// end of koepi's addition - SetDlgItemInt(hDlg, IDC_CREDITS_RATE, config->credits_rate, FALSE); - SetDlgItemInt(hDlg, IDC_CREDITS_QUANTI, config->credits_quant_i, FALSE); - SetDlgItemInt(hDlg, IDC_CREDITS_QUANTP, config->credits_quant_p, FALSE); - SetDlgItemInt(hDlg, IDC_CREDITS_START_SIZE, config->credits_start_size, FALSE); - SetDlgItemInt(hDlg, IDC_CREDITS_END_SIZE, config->credits_end_size, FALSE); + case IDD_MOTION : + SendDlgItemMessage(hDlg, IDC_MOTION, CB_SETCURSEL, config->motion_search, 0); + SendDlgItemMessage(hDlg, IDC_VHQ, CB_SETCURSEL, config->vhq_mode, 0); + CheckDlg(hDlg, IDC_CHROMAME, config->chromame); + CheckDlg(hDlg, IDC_CARTOON, config->cartoon_mode); + CheckDlg(hDlg, IDC_TURBO, config->turbo); + SetDlgItemInt(hDlg, IDC_FRAMEDROP, config->frame_drop_ratio, FALSE); + SetDlgItemInt(hDlg, IDC_MAXKEY, config->max_key_interval, FALSE); + break; - if (config->credits_mode == CREDITS_MODE_RATE) - { - CheckDlgButton(hDlg, IDC_CREDITS_RATE_RADIO, BST_CHECKED); - } - else if (config->credits_mode == CREDITS_MODE_QUANT) - { - CheckDlgButton(hDlg, IDC_CREDITS_QUANT_RADIO, BST_CHECKED); - } - else // CREDITS_MODE_SIZE - { - CheckDlgButton(hDlg, IDC_CREDITS_SIZE_RADIO, BST_CHECKED); - } + case IDD_QUANT : + SetDlgItemInt(hDlg, IDC_MINIQUANT, config->min_iquant, FALSE); + SetDlgItemInt(hDlg, IDC_MAXIQUANT, config->max_iquant, FALSE); + SetDlgItemInt(hDlg, IDC_MINPQUANT, config->min_pquant, FALSE); + SetDlgItemInt(hDlg, IDC_MAXPQUANT, config->max_pquant, FALSE); + SetDlgItemInt(hDlg, IDC_MINBQUANT, config->min_bquant, FALSE); + SetDlgItemInt(hDlg, IDC_MAXBQUANT, config->max_bquant, FALSE); + CheckDlg(hDlg, IDC_TRELLISQUANT, config->trellis_quant); break; - case DLG_CPU : - CheckDlgButton(hDlg, IDC_CPU_MMX, (config->cpu & XVID_CPU_MMX) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg, IDC_CPU_MMXEXT, (config->cpu & XVID_CPU_MMXEXT) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg, IDC_CPU_SSE, (config->cpu & XVID_CPU_SSE) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg, IDC_CPU_SSE2, (config->cpu & XVID_CPU_SSE2) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg, IDC_CPU_3DNOW, (config->cpu & XVID_CPU_3DNOW) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg, IDC_CPU_3DNOWEXT, (config->cpu & XVID_CPU_3DNOWEXT) ? BST_CHECKED : BST_UNCHECKED); + case IDD_DEBUG : + CheckDlg(hDlg, IDC_CPU_MMX, (config->cpu & XVID_CPU_MMX)); + CheckDlg(hDlg, IDC_CPU_MMXEXT, (config->cpu & XVID_CPU_MMXEXT)); + CheckDlg(hDlg, IDC_CPU_SSE, (config->cpu & XVID_CPU_SSE)); + CheckDlg(hDlg, IDC_CPU_SSE2, (config->cpu & XVID_CPU_SSE2)); + CheckDlg(hDlg, IDC_CPU_3DNOW, (config->cpu & XVID_CPU_3DNOW)); + CheckDlg(hDlg, IDC_CPU_3DNOWEXT, (config->cpu & XVID_CPU_3DNOWEXT)); - CheckRadioButton(hDlg, IDC_CPU_AUTO, IDC_CPU_FORCE, + CheckRadioButton(hDlg, IDC_CPU_AUTO, IDC_CPU_FORCE, config->cpu & XVID_CPU_FORCE ? IDC_CPU_FORCE : IDC_CPU_AUTO ); SetDlgItemInt(hDlg, IDC_NUMTHREADS, config->num_threads, FALSE); - CheckDlgButton(hDlg, IDC_CHROMA_OPT, (config->chroma_opt) ? BST_CHECKED : BST_UNCHECKED); - SetDlgItemInt(hDlg, IDC_FRAMEDROP, config->frame_drop_ratio, FALSE); - SetDlgItemInt(hDlg, IDC_CBR_REACTIONDELAY, config->rc_reaction_delay_factor, FALSE); - SetDlgItemInt(hDlg, IDC_CBR_AVERAGINGPERIOD, config->rc_averaging_period, FALSE); - SetDlgItemInt(hDlg, IDC_CBR_BUFFER, config->rc_buffer, FALSE); + + SendDlgItemMessage(hDlg, IDC_FOURCC, CB_SETCURSEL, config->fourcc_used, 0); + set_dlgitem_hex(hDlg, IDC_DEBUG, config->debug); + CheckDlg(hDlg, IDC_VOPDEBUG, config->vop_debug); + CheckDlg(hDlg, IDC_DISPLAY_STATUS, config->display_status); + break; + + case IDD_DEC : + CheckDlg(hDlg, IDC_DEC_DY, pp_dy); + CheckDlg(hDlg, IDC_DEC_DUV, pp_duv); + CheckDlg(hDlg, IDC_DEC_DR, pp_dr); + CheckDlg(hDlg, IDC_DEC_FE, pp_fe); break; } } -/* download config data from dialog - replaces invalid values instead of alerting user for now -*/ - -#define CONSTRAINVAL(X,Y,Z) if((X)<(Y)) X=Y; if((X)>(Z)) X=Z; +/* download config data from dialog */ -void adv_download(HWND hDlg, int page, CONFIG * config) +void adv_download(HWND hDlg, int idd, CONFIG * config) { - switch (page) + switch (idd) { - case DLG_GLOBAL : - config->motion_search = SendDlgItemMessage(hDlg, IDC_MOTION, CB_GETCURSEL, 0, 0); - config->quant_type = SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_GETCURSEL, 0, 0); - config->fourcc_used = SendDlgItemMessage(hDlg, IDC_FOURCC, CB_GETCURSEL, 0, 0); - config->vhq_mode = SendDlgItemMessage(hDlg, IDC_VHQ, CB_GETCURSEL, 0, 0); - config->max_key_interval = config_get_uint(hDlg, IDC_MAXKEY, config->max_key_interval); - config->min_key_interval = config_get_uint(hDlg, IDC_MINKEY, config->min_key_interval); - config->lum_masking = ISDLGSET(IDC_LUMMASK); - config->interlacing = ISDLGSET(IDC_INTERLACING); - - config->qpel = ISDLGSET(IDC_QPEL); - config->gmc = ISDLGSET(IDC_GMC); - config->chromame = ISDLGSET(IDC_CHROMAME); -// added by koepi for gruel's greyscale_mode - config->greyscale = ISDLGSET(IDC_GREYSCALE); -// end of koepi's addition - config->max_bframes = config_get_int(hDlg, IDC_MAXBFRAMES, config->max_bframes); - config->bquant_ratio = config_get_uint(hDlg, IDC_BQUANTRATIO, config->bquant_ratio); - config->bquant_offset = config_get_uint(hDlg, IDC_BQUANTOFFSET, config->bquant_offset); - config->packed = ISDLGSET(IDC_PACKED); - config->dx50bvop = ISDLGSET(IDC_DX50BVOP); - config->debug = ISDLGSET(IDC_DEBUG); - config->reduced_resolution = ISDLGSET(IDC_REDUCED); - break; + case IDD_PROFILE : + config->profile = SendDlgItemMessage(hDlg, IDC_PROFILE_PROFILE, CB_GETCURSEL, 0, 0); - case DLG_QUANT : - config->min_iquant = config_get_uint(hDlg, IDC_MINIQUANT, config->min_iquant); - config->max_iquant = config_get_uint(hDlg, IDC_MAXIQUANT, config->max_iquant); - config->min_pquant = config_get_uint(hDlg, IDC_MINPQUANT, config->min_pquant); - config->max_pquant = config_get_uint(hDlg, IDC_MAXPQUANT, config->max_pquant); + config->quant_type = SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_GETCURSEL, 0, 0); + config->lum_masking = IsDlgChecked(hDlg, IDC_LUMMASK); + config->interlacing = IsDlgChecked(hDlg, IDC_INTERLACING); + config->qpel = IsDlgChecked(hDlg, IDC_QPEL); + config->gmc = IsDlgChecked(hDlg, IDC_GMC); + config->reduced_resolution = IsDlgChecked(hDlg, IDC_REDUCED); - CONSTRAINVAL(config->min_iquant, 1, 31); - CONSTRAINVAL(config->max_iquant, config->min_iquant, 31); - CONSTRAINVAL(config->min_pquant, 1, 31); - CONSTRAINVAL(config->max_pquant, config->min_pquant, 31); + config->use_bvop = IsDlgChecked(hDlg, IDC_BVOP); + config->max_bframes = config_get_uint(hDlg, IDC_MAXBFRAMES, config->max_bframes); + config->bquant_ratio = get_dlgitem_float(hDlg, IDC_BQUANTRATIO, config->bquant_ratio); + config->bquant_offset = get_dlgitem_float(hDlg, IDC_BQUANTOFFSET, config->bquant_offset); + config->packed = IsDlgChecked(hDlg, IDC_PACKED); + config->closed_gov = IsDlgChecked(hDlg, IDC_CLOSEDGOV); break; - case DLG_2PASS : - config->keyframe_boost = GetDlgItemInt(hDlg, IDC_KFBOOST, NULL, FALSE); -// added by koepi for the new 2pass curve treatment - config->kftreshold = GetDlgItemInt(hDlg, IDC_KFTRESHOLD, NULL, FALSE); - config->kfreduction = GetDlgItemInt(hDlg, IDC_KFREDUCTION, NULL, FALSE); -//end of koepi's additions - config->discard1pass = ISDLGSET(IDC_DISCARD1PASS); - config->dummy2pass = ISDLGSET(IDC_DUMMY2PASS); - config->curve_compression_high = GetDlgItemInt(hDlg, IDC_CURVECOMPH, NULL, FALSE); - config->curve_compression_low = GetDlgItemInt(hDlg, IDC_CURVECOMPL, NULL, FALSE); - config->bitrate_payback_delay = config_get_uint(hDlg, IDC_PAYBACK, config->bitrate_payback_delay); - config->bitrate_payback_method = ISDLGSET(IDC_PAYBACKPROP); - config->hinted_me = ISDLGSET(IDC_HINTEDME); - - if (GetDlgItemText(hDlg, IDC_HINTFILE, config->hintfile, MAX_PATH) == 0) - { - lstrcpy(config->hintfile, CONFIG_HINTFILE); + case IDD_AR: + config->ar_mode = IsDlgChecked(hDlg, IDC_PAR) ? 0:1; + config->ar_x = config_get_uint(hDlg, IDC_ARX, config->ar_x); + config->ar_y = config_get_uint(hDlg, IDC_ARY, config->ar_y); + config->display_aspect_ratio = SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_GETCURSEL, 0, 0); + if (config->display_aspect_ratio == 5) { + config->par_x = config_get_uint(hDlg, IDC_PARX, config->par_x); + config->par_y = config_get_uint(hDlg, IDC_PARY, config->par_y); } - if (GetDlgItemText(hDlg, IDC_STATS1, config->stats1, MAX_PATH) == 0) - { - lstrcpy(config->stats1, CONFIG_2PASS_1_FILE); - } - if (GetDlgItemText(hDlg, IDC_STATS2, config->stats2, MAX_PATH) == 0) - { - lstrcpy(config->stats2, CONFIG_2PASS_2_FILE); - } - - CONSTRAINVAL(config->bitrate_payback_delay, 1, 10000); - CONSTRAINVAL(config->keyframe_boost, 0, 1000); - CONSTRAINVAL(config->curve_compression_high, 0, 100); - CONSTRAINVAL(config->curve_compression_low, 0, 100); - break; - - case DLG_2PASSALT : - config->use_alt_curve = ISDLGSET(IDC_USEALT); - - config->alt_curve_use_auto = ISDLGSET(IDC_USEAUTO); - config->alt_curve_auto_str = config_get_uint(hDlg, IDC_AUTOSTR, config->alt_curve_auto_str); - - config->alt_curve_use_auto_bonus_bias = ISDLGSET(IDC_USEAUTOBONUS); - config->alt_curve_bonus_bias = config_get_uint(hDlg, IDC_BONUSBIAS, config->alt_curve_bonus_bias); - - config->alt_curve_type = SendDlgItemMessage(hDlg, IDC_CURVETYPE, CB_GETCURSEL, 0, 0); - config->alt_curve_high_dist = config_get_uint(hDlg, IDC_ALTCURVEHIGH, config->alt_curve_high_dist); - config->alt_curve_low_dist = config_get_uint(hDlg, IDC_ALTCURVELOW, config->alt_curve_low_dist); - config->alt_curve_min_rel_qual = config_get_uint(hDlg, IDC_MINQUAL, config->alt_curve_min_rel_qual); - - config->twopass_max_bitrate /= CONFIG_KBPS; - config->twopass_max_bitrate = config_get_uint(hDlg, IDC_MAXBITRATE, config->twopass_max_bitrate); - config->twopass_max_bitrate *= CONFIG_KBPS; - config->twopass_max_overflow_improvement = config_get_uint(hDlg, IDC_OVERIMP, config->twopass_max_overflow_improvement); - config->twopass_max_overflow_degradation = config_get_uint(hDlg, IDC_OVERDEG, config->twopass_max_overflow_degradation); - - CONSTRAINVAL(config->twopass_max_overflow_improvement, 1, 80); - CONSTRAINVAL(config->twopass_max_overflow_degradation, 1, 80); break; - case DLG_CREDITS : - config->credits_start = ISDLGSET(IDC_CREDITS_START); - config->credits_start_begin = GetDlgItemInt(hDlg, IDC_CREDITS_START_BEGIN, NULL, FALSE); - config->credits_start_end = config_get_uint(hDlg, IDC_CREDITS_START_END, config->credits_start_end); - config->credits_end = ISDLGSET(IDC_CREDITS_END); - config->credits_end_begin = config_get_uint(hDlg, IDC_CREDITS_END_BEGIN, config->credits_end_begin); - config->credits_end_end = config_get_uint(hDlg, IDC_CREDITS_END_END, config->credits_end_end); - -// added by koepi for gruel's greyscale_mode - config->credits_greyscale = ISDLGSET(IDC_CREDITS_GREYSCALE); -// end of koepi's addition - config->credits_rate = config_get_uint(hDlg, IDC_CREDITS_RATE, config->credits_rate); - config->credits_quant_i = config_get_uint(hDlg, IDC_CREDITS_QUANTI, config->credits_quant_i); - config->credits_quant_p = config_get_uint(hDlg, IDC_CREDITS_QUANTP, config->credits_quant_p); - config->credits_start_size = config_get_uint(hDlg, IDC_CREDITS_START_SIZE, config->credits_start_size); - config->credits_end_size = config_get_uint(hDlg, IDC_CREDITS_END_SIZE, config->credits_end_size); - - config->credits_mode = 0; - config->credits_mode = ISDLGSET(IDC_CREDITS_RATE_RADIO) ? CREDITS_MODE_RATE : config->credits_mode; - config->credits_mode = ISDLGSET(IDC_CREDITS_QUANT_RADIO) ? CREDITS_MODE_QUANT : config->credits_mode; - config->credits_mode = ISDLGSET(IDC_CREDITS_SIZE_RADIO) ? CREDITS_MODE_SIZE : config->credits_mode; - - CONSTRAINVAL(config->credits_rate, 1, 100); - CONSTRAINVAL(config->credits_quant_i, 1, 31); - CONSTRAINVAL(config->credits_quant_p, 1, 31); - - if (config->credits_start_begin > config->credits_start_end) - { - config->credits_start_begin = config->credits_start_end; - config->credits_start = 0; - } - if (config->credits_end_begin > config->credits_end_end) - { - config->credits_end_begin = config->credits_end_end; - config->credits_end = 0; - } + case IDD_LEVEL : + config->profile = SendDlgItemMessage(hDlg, IDC_LEVEL_PROFILE, CB_GETCURSEL, 0, 0); break; - case DLG_CPU : - config->cpu = 0; - config->cpu |= ISDLGSET(IDC_CPU_MMX) ? XVID_CPU_MMX : 0; - config->cpu |= ISDLGSET(IDC_CPU_MMXEXT) ? XVID_CPU_MMXEXT: 0; - config->cpu |= ISDLGSET(IDC_CPU_SSE) ? XVID_CPU_SSE: 0; - config->cpu |= ISDLGSET(IDC_CPU_SSE2) ? XVID_CPU_SSE2: 0; - config->cpu |= ISDLGSET(IDC_CPU_3DNOW) ? XVID_CPU_3DNOW: 0; - config->cpu |= ISDLGSET(IDC_CPU_3DNOWEXT) ? XVID_CPU_3DNOWEXT: 0; - config->cpu |= ISDLGSET(IDC_CPU_FORCE) ? XVID_CPU_FORCE : 0; - - config->num_threads = config_get_uint(hDlg, IDC_NUMTHREADS, config->num_threads); - config->chroma_opt = ISDLGSET(IDC_CHROMA_OPT); - config->frame_drop_ratio = config_get_uint(hDlg, IDC_FRAMEDROP, config->frame_drop_ratio); + case IDD_RC_CBR : config->rc_reaction_delay_factor = config_get_uint(hDlg, IDC_CBR_REACTIONDELAY, config->rc_reaction_delay_factor); config->rc_averaging_period = config_get_uint(hDlg, IDC_CBR_AVERAGINGPERIOD, config->rc_averaging_period); config->rc_buffer = config_get_uint(hDlg, IDC_CBR_BUFFER, config->rc_buffer); break; - } -} + case IDD_RC_2PASS1 : + if (GetDlgItemText(hDlg, IDC_STATS, config->stats, MAX_PATH) == 0) + lstrcpy(config->stats, CONFIG_2PASS_FILE); + config->discard1pass = IsDlgChecked(hDlg, IDC_DISCARD1PASS); + break; -void quant_upload(HWND hDlg, CONFIG* config) -{ - int i; + case IDD_RC_2PASS2 : + if (GetDlgItemText(hDlg, IDC_STATS, config->stats, MAX_PATH) == 0) + lstrcpy(config->stats, CONFIG_2PASS_FILE); - for (i=0 ; i<64 ; ++i) - { - SetDlgItemInt(hDlg, IDC_QINTRA00 + i, config->qmatrix_intra[i], FALSE); - SetDlgItemInt(hDlg, IDC_QINTER00 + i, config->qmatrix_inter[i], FALSE); - } -} + config->keyframe_boost = GetDlgItemInt(hDlg, IDC_KFBOOST, NULL, FALSE); + config->kfreduction = GetDlgItemInt(hDlg, IDC_KFREDUCTION, NULL, FALSE); + CONSTRAINVAL(config->keyframe_boost, 0, 1000); + config->overflow_control_strength = GetDlgItemInt(hDlg, IDC_OVERFLOW_CONTROL_STRENGTH, NULL, FALSE); + config->twopass_max_overflow_improvement = config_get_uint(hDlg, IDC_OVERIMP, config->twopass_max_overflow_improvement); + config->twopass_max_overflow_degradation = config_get_uint(hDlg, IDC_OVERDEG, config->twopass_max_overflow_degradation); + CONSTRAINVAL(config->twopass_max_overflow_improvement, 1, 80); + CONSTRAINVAL(config->twopass_max_overflow_degradation, 1, 80); + CONSTRAINVAL(config->overflow_control_strength, 0, 100); -void quant_download(HWND hDlg, CONFIG* config) -{ - int i; + config->curve_compression_high = GetDlgItemInt(hDlg, IDC_CURVECOMPH, NULL, FALSE); + config->curve_compression_low = GetDlgItemInt(hDlg, IDC_CURVECOMPL, NULL, FALSE); + CONSTRAINVAL(config->curve_compression_high, 0, 100); + CONSTRAINVAL(config->curve_compression_low, 0, 100); - for (i=0 ; i<64 ; ++i) - { - int temp; + config->kfthreshold = config_get_uint(hDlg, IDC_MINKEY, config->kfthreshold); - temp = config_get_uint(hDlg, i + IDC_QINTRA00, config->qmatrix_intra[i]); - CONSTRAINVAL(temp, 1, 255); - config->qmatrix_intra[i] = temp; + break; - temp = config_get_uint(hDlg, i + IDC_QINTER00, config->qmatrix_inter[i]); - CONSTRAINVAL(temp, 1, 255); - config->qmatrix_inter[i] = temp; - } -} + case IDD_ZONE : + config->zones[config->cur_zone].frame = config_get_uint(hDlg, IDC_ZONE_FRAME, config->zones[config->cur_zone].frame); + if (IsDlgChecked(hDlg, IDC_ZONE_MODE_WEIGHT)) { + config->zones[config->cur_zone].mode = RC_ZONE_WEIGHT; + }else if (IsDlgChecked(hDlg, IDC_ZONE_MODE_QUANT)) { + config->zones[config->cur_zone].mode = RC_ZONE_QUANT; + } -/* enumerates child windows, assigns tooltips */ + config->zones[config->cur_zone].weight = get_dlgitem_float(hDlg, IDC_ZONE_WEIGHT, config->zones[config->cur_zone].weight); + config->zones[config->cur_zone].quant = get_dlgitem_float(hDlg, IDC_ZONE_QUANT, config->zones[config->cur_zone].quant); -BOOL CALLBACK enum_tooltips(HWND hWnd, LPARAM lParam) -{ - char help[500]; + config->zones[config->cur_zone].type = IsDlgButtonChecked(hDlg, IDC_ZONE_FORCEIVOP)?XVID_TYPE_IVOP:XVID_TYPE_AUTO; + config->zones[config->cur_zone].greyscale = IsDlgButtonChecked(hDlg, IDC_ZONE_GREYSCALE); + config->zones[config->cur_zone].chroma_opt = IsDlgButtonChecked(hDlg, IDC_ZONE_CHROMAOPT); - if (LoadString(hInst, GetDlgCtrlID(hWnd), help, 500)) - { - TOOLINFO ti; + config->zones[config->cur_zone].bvop_threshold = config_get_int(hDlg, IDC_ZONE_BVOPTHRESHOLD, config->zones[config->cur_zone].bvop_threshold); + break; - ti.cbSize = sizeof(TOOLINFO); - ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND; - ti.hwnd = GetParent(hWnd); - ti.uId = (LPARAM)hWnd; - ti.lpszText = help; + case IDD_MOTION : + config->motion_search = SendDlgItemMessage(hDlg, IDC_MOTION, CB_GETCURSEL, 0, 0); + config->vhq_mode = SendDlgItemMessage(hDlg, IDC_VHQ, CB_GETCURSEL, 0, 0); + config->chromame = IsDlgChecked(hDlg, IDC_CHROMAME); + config->cartoon_mode = IsDlgChecked(hDlg, IDC_CARTOON); + config->turbo = IsDlgChecked(hDlg, IDC_TURBO); - SendMessage(hTooltip, TTM_ADDTOOL, 0, (LPARAM)&ti); - } + config->frame_drop_ratio = config_get_uint(hDlg, IDC_FRAMEDROP, config->frame_drop_ratio); - return TRUE; -} + config->max_key_interval = config_get_uint(hDlg, IDC_MAXKEY, config->max_key_interval); + break; + case IDD_QUANT : + config->min_iquant = config_get_uint(hDlg, IDC_MINIQUANT, config->min_iquant); + config->max_iquant = config_get_uint(hDlg, IDC_MAXIQUANT, config->max_iquant); + config->min_pquant = config_get_uint(hDlg, IDC_MINPQUANT, config->min_pquant); + config->max_pquant = config_get_uint(hDlg, IDC_MAXPQUANT, config->max_pquant); + config->min_bquant = config_get_uint(hDlg, IDC_MINBQUANT, config->min_bquant); + config->max_bquant = config_get_uint(hDlg, IDC_MAXBQUANT, config->max_bquant); + CONSTRAINVAL(config->min_iquant, 1, 31); + CONSTRAINVAL(config->max_iquant, config->min_iquant, 31); + CONSTRAINVAL(config->min_pquant, 1, 31); + CONSTRAINVAL(config->max_pquant, config->min_pquant, 31); + CONSTRAINVAL(config->min_bquant, 1, 31); + CONSTRAINVAL(config->max_bquant, config->min_bquant, 31); -/* --- decoder options dialog --- */ + config->trellis_quant = IsDlgChecked(hDlg, IDC_TRELLISQUANT); + break; -#define DEC_DLG_COUNT 1 -#define DEC_DLG_POSTPROC 0 + case IDD_DEBUG : + config->cpu = 0; + config->cpu |= IsDlgChecked(hDlg, IDC_CPU_MMX) ? XVID_CPU_MMX : 0; + config->cpu |= IsDlgChecked(hDlg, IDC_CPU_MMXEXT) ? XVID_CPU_MMXEXT : 0; + config->cpu |= IsDlgChecked(hDlg, IDC_CPU_SSE) ? XVID_CPU_SSE : 0; + config->cpu |= IsDlgChecked(hDlg, IDC_CPU_SSE2) ? XVID_CPU_SSE2 : 0; + config->cpu |= IsDlgChecked(hDlg, IDC_CPU_3DNOW) ? XVID_CPU_3DNOW : 0; + config->cpu |= IsDlgChecked(hDlg, IDC_CPU_3DNOWEXT) ? XVID_CPU_3DNOWEXT : 0; + config->cpu |= IsDlgChecked(hDlg, IDC_CPU_FORCE) ? XVID_CPU_FORCE : 0; -/* decoder dialog: upload config data */ + config->num_threads = config_get_uint(hDlg, IDC_NUMTHREADS, config->num_threads); -void dec_upload(HWND hDlg, int page, CONFIG * config) -{ - switch (page) - { - case DEC_DLG_POSTPROC : - CheckDlgButton(hDlg, IDC_DEBLOCK_Y, config->deblock_y ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg, IDC_DEBLOCK_UV, config->deblock_uv ? BST_CHECKED : BST_UNCHECKED); + config->fourcc_used = SendDlgItemMessage(hDlg, IDC_FOURCC, CB_GETCURSEL, 0, 0); + config->debug = get_dlgitem_hex(hDlg, IDC_DEBUG, config->debug); + config->vop_debug = IsDlgChecked(hDlg, IDC_VOPDEBUG); + config->display_status = IsDlgChecked(hDlg, IDC_DISPLAY_STATUS); break; - } -} - - -/* dec dialog: download config data */ -void dec_download(HWND hDlg, int page, CONFIG * config) -{ - switch (page) - { - case DEC_DLG_POSTPROC : - config->deblock_y = ISDLGSET(IDC_DEBLOCK_Y); - config->deblock_uv = ISDLGSET(IDC_DEBLOCK_UV); + case IDD_DEC : + pp_dy = IsDlgChecked(hDlg, IDC_DEC_DY); + pp_duv = IsDlgChecked(hDlg, IDC_DEC_DUV); + pp_dr = IsDlgChecked(hDlg, IDC_DEC_DR); + pp_fe = IsDlgChecked(hDlg, IDC_DEC_FE); break; } } -/* decoder dialog proc */ -BOOL CALLBACK dec_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) + +/* advanced dialog proc */ + +BOOL CALLBACK adv_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { PROPSHEETINFO *psi; @@ -1022,31 +1109,144 @@ { case WM_INITDIALOG : psi = (PROPSHEETINFO*) ((LPPROPSHEETPAGE)lParam)->lParam; - SetWindowLong(hDlg, GWL_USERDATA, (LPARAM)psi); - if (hTooltip) - { + if (g_hTooltip) EnumChildWindows(hDlg, enum_tooltips, 0); - } - dec_upload(hDlg, psi->page, psi->config); + adv_init(hDlg, psi->idd, psi->config); + break; + + case WM_COMMAND : + if (HIWORD(wParam) == BN_CLICKED) + { + switch (LOWORD(wParam)) + { + case IDC_BVOP : + case IDC_ZONE_MODE_WEIGHT : + case IDC_ZONE_MODE_QUANT : + case IDC_ZONE_BVOPTHRESHOLD_ENABLE : + case IDC_CPU_AUTO : + case IDC_CPU_FORCE : + case IDC_AR : + case IDC_PAR : + adv_mode(hDlg, psi->idd, psi->config); + break; + + case IDC_QUANTMATRIX : + DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_QUANTMATRIX), hDlg, quantmatrix_proc, (LPARAM)psi->config); + break; + + case IDC_STATS_BROWSE : + { + OPENFILENAME ofn; + char tmp[MAX_PATH]; + + GetDlgItemText(hDlg, IDC_STATS, tmp, MAX_PATH); + + memset(&ofn, 0, sizeof(OPENFILENAME)); + ofn.lStructSize = sizeof(OPENFILENAME); + + ofn.hwndOwner = hDlg; + ofn.lpstrFilter = "bitrate curve (*.stats)\0*.stats\0All files (*.*)\0*.*\0\0"; + ofn.lpstrFile = tmp; + ofn.nMaxFile = MAX_PATH; + ofn.Flags = OFN_PATHMUSTEXIST; + + if (psi->idd == IDD_RC_2PASS1) { + ofn.Flags |= OFN_OVERWRITEPROMPT; + }else{ + ofn.Flags |= OFN_FILEMUSTEXIST; + } + + if (GetSaveFileName(&ofn)) + { + SetDlgItemText(hDlg, IDC_STATS, tmp); + } + } + + case IDC_ZONE_FETCH : + SetDlgItemInt(hDlg, IDC_ZONE_FRAME, psi->config->ci.ciActiveFrame, FALSE); + break; + + case IDC_AR_DEFAULT: + CheckRadioButton(hDlg, IDC_AR, IDC_PAR, IDC_PAR); + SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_SETCURSEL, 0, 0); + adv_mode(hDlg, psi->idd, psi->config); + break; + case IDC_AR_4_3: + SetDlgItemInt(hDlg, IDC_ARX, 4, FALSE); + SetDlgItemInt(hDlg, IDC_ARY, 3, FALSE); + CheckRadioButton(hDlg, IDC_AR, IDC_PAR, IDC_AR); + adv_mode(hDlg, psi->idd, psi->config); + break; + case IDC_AR_16_9: + SetDlgItemInt(hDlg, IDC_ARX, 16, FALSE); + SetDlgItemInt(hDlg, IDC_ARY, 9, FALSE); + CheckRadioButton(hDlg, IDC_AR, IDC_PAR, IDC_AR); + adv_mode(hDlg, psi->idd, psi->config); + break; + case IDC_AR_235_100: + SetDlgItemInt(hDlg, IDC_ARX, 235, FALSE); + SetDlgItemInt(hDlg, IDC_ARY, 100, FALSE); + CheckRadioButton(hDlg, IDC_AR, IDC_PAR, IDC_AR); + adv_mode(hDlg, psi->idd, psi->config); + break; + + default : + return TRUE; + } + }else if (HIWORD(wParam) == LBN_SELCHANGE && + (LOWORD(wParam) == IDC_PROFILE_PROFILE || + LOWORD(wParam) == IDC_LEVEL_PROFILE || + LOWORD(wParam) == IDC_QUANTTYPE || + LOWORD(wParam) == IDC_ASPECT_RATIO)) + { + adv_mode(hDlg, psi->idd, psi->config); + }else if (HIWORD(wParam) == EN_UPDATE && (LOWORD(wParam)==IDC_ZONE_WEIGHT || LOWORD(wParam)==IDC_ZONE_QUANT)) { + + SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETPOS, TRUE, + get_dlgitem_float(hDlg, LOWORD(wParam), 100)); + } else if (HIWORD(wParam) == EN_UPDATE && (LOWORD(wParam)==IDC_PARX || LOWORD(wParam)==IDC_PARY)) { + if (5 == SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_GETCURSEL, 0, 0)) { + if(LOWORD(wParam)==IDC_PARX) + psi->config->par_x = config_get_uint(hDlg, LOWORD(wParam), psi->config->par_x); + else + psi->config->par_y = config_get_uint(hDlg, LOWORD(wParam), psi->config->par_y); + } + } else + return 0; break; + case WM_HSCROLL : + if((HWND)lParam == GetDlgItem(hDlg, IDC_ZONE_SLIDER)) { + int idc = IsDlgChecked(hDlg, IDC_ZONE_MODE_WEIGHT) ? IDC_ZONE_WEIGHT : IDC_ZONE_QUANT; + set_dlgitem_float(hDlg, idc, SendMessage((HWND)lParam, TBM_GETPOS, 0, 0) ); + break; + } + return 0; + + case WM_NOTIFY : switch (((NMHDR *)lParam)->code) { - case PSN_KILLACTIVE : - /* validate */ - dec_download(hDlg, psi->page, psi->config); + case PSN_SETACTIVE : + OutputDebugString("PSN_SET"); + adv_upload(hDlg, psi->idd, psi->config); + adv_mode(hDlg, psi->idd, psi->config); SetWindowLong(hDlg, DWL_MSGRESULT, FALSE); break; - case PSN_APPLY : - /* apply */ - dec_download(hDlg, psi->page, psi->config); + case PSN_KILLACTIVE : + OutputDebugString("PSN_KILL"); + adv_download(hDlg, psi->idd, psi->config); SetWindowLong(hDlg, DWL_MSGRESULT, FALSE); + break; + + case PSN_APPLY : + OutputDebugString("PSN_APPLY"); psi->config->save = TRUE; + SetWindowLong(hDlg, DWL_MSGRESULT, FALSE); break; } break; @@ -1059,10 +1259,17 @@ } -void dec_dialog(HWND hParent, CONFIG * config) + + +/* load advanced options property sheet + returns true, if the user accepted the changes + or fasle if changes were canceled. + + */ +BOOL adv_dialog(HWND hParent, CONFIG * config, const int * dlgs, int size) { - PROPSHEETINFO psi[DEC_DLG_COUNT]; - PROPSHEETPAGE psp[DEC_DLG_COUNT]; + PROPSHEETINFO psi[6]; + PROPSHEETPAGE psp[6]; PROPSHEETHEADER psh; CONFIG temp; int i; @@ -1070,434 +1277,421 @@ config->save = FALSE; memcpy(&temp, config, sizeof(CONFIG)); - for (i=0 ; iframe); - config = (CONFIG*)lParam; + if (insert) { + LVITEM lvi; - SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"1 Pass - CBR"); - SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"1 Pass - quality"); - SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"1 Pass - quantizer"); - SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"2 Pass - 1st pass"); - SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"2 Pass - 2nd pass Ext."); - SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"2 Pass - 2nd pass Int."); - SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"Null - test speed"); + lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE; + lvi.state = 0; + lvi.stateMask = 0; + lvi.iImage = 0; + lvi.pszText = tmp; + lvi.cchTextMax = strlen(tmp); + lvi.iItem = i; + lvi.iSubItem = 0; + ListView_InsertItem(hDlg, &lvi); + }else{ + ListView_SetItemText(hDlg, i, 0, tmp); + } - SendDlgItemMessage(hDlg, IDC_MODE, CB_SETCURSEL, config->mode, 0); + if (s->mode == RC_ZONE_WEIGHT) { + sprintf(tmp,"W %.2f",(float)s->weight/100); + }else if (s->mode == RC_ZONE_QUANT) { + sprintf(tmp,"Q %.2f",(float)s->quant/100); + }else { + strcpy(tmp,"EXT"); + } + ListView_SetItemText(hDlg, i, 1, tmp); - InitCommonControls(); + tmp[0] = '\0'; + if (s->type==XVID_TYPE_IVOP) + strcat(tmp, "K "); - if ((hTooltip = CreateWindow(TOOLTIPS_CLASS, NULL, TTS_ALWAYSTIP, - CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, - NULL, NULL, hInst, NULL))) - { - SetWindowPos(hTooltip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); - SendMessage(hTooltip, TTM_SETDELAYTIME, TTDT_AUTOMATIC, MAKELONG(1500, 0)); - SendMessage(hTooltip, TTM_SETMAXTIPWIDTH, 0, 400); + if (s->greyscale) + strcat(tmp, "G "); - EnumChildWindows(hDlg, enum_tooltips, 0); - } + if (s->chroma_opt) + strcat(tmp, "C "); - main_slider(hDlg, config); - main_value(hDlg, config); - break; + ListView_SetItemText(hDlg, i, 2, tmp); +} - case WM_HSCROLL : - if((HWND)lParam == GetDlgItem(hDlg, IDC_SLIDER)) - { - SetDlgItemInt(hDlg, IDC_VALUE, SendMessage((HWND)lParam, TBM_GETPOS, 0, 0), FALSE); - } - else - { - return 0; - } - break; +static int g_use_bitrate = 1; - case WM_COMMAND : - if (LOWORD(wParam) == IDC_MODE && HIWORD(wParam) == LBN_SELCHANGE) - { - main_download(hDlg, config); - main_slider(hDlg, config); - main_value(hDlg, config); - } - else if (LOWORD(wParam) == IDC_ADVANCED && HIWORD(wParam) == BN_CLICKED) - { - adv_dialog(hDlg, config); +void main_mode(HWND hDlg, CONFIG * config) +{ + const int profile = SendDlgItemMessage(hDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0); + const int rc_mode = SendDlgItemMessage(hDlg, IDC_MODE, CB_GETCURSEL, 0, 0); + /* enable target rate/size control only for 1pass and 2pass modes*/ + const int target_en = rc_mode==RC_MODE_1PASS || rc_mode==RC_MODE_2PASS2; + + char buf[16]; + int max; - if (config->save) - { - config_reg_set(config); - } - } - else if (LOWORD(wParam) == IDC_DECODER && HIWORD(wParam) == BN_CLICKED) - { - dec_dialog(hDlg, config); + g_use_bitrate = rc_mode==RC_MODE_1PASS || config->use_2pass_bitrate; - if (config->save) - { - config_reg_set(config); - } - } - else if (LOWORD(wParam) == IDC_DEFAULTS && HIWORD(wParam) == BN_CLICKED) - { - config_reg_default(config); + if (g_use_bitrate) { + SetDlgItemText(hDlg, IDC_BITRATE_S, "Target bitrate (kbps):"); - SendDlgItemMessage(hDlg, IDC_MODE, CB_SETCURSEL, config->mode, 0); + wsprintf(buf, "%i kbps", DEFAULT_MIN_KBPS); + SetDlgItemText(hDlg, IDC_BITRATE_MIN, buf); - main_slider(hDlg, config); - main_value(hDlg, config); - } - else if (HIWORD(wParam) == EN_UPDATE && LOWORD(wParam) == IDC_VALUE) - { - int value = config_get_uint(hDlg, IDC_VALUE, 1); - int max = 1; + max = profiles[profile].max_bitrate; + if (max == 0) max = DEFAULT_MAX_KBPS; + wsprintf(buf, "%i kbps", max); + SetDlgItemText(hDlg, IDC_BITRATE_MAX, buf); - max = (config->mode == DLG_MODE_CBR) ? 10000 : - ((config->mode == DLG_MODE_VBR_QUAL) ? 100 : - ((config->mode == DLG_MODE_VBR_QUANT) ? 31 : 1<<30)); + SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(DEFAULT_MIN_KBPS, max)); + SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE, + config_get_uint(hDlg, IDC_BITRATE, DEFAULT_MIN_KBPS) ); - if (value < 1) - { - value = 1; - } - if (value > max) - { - value = max; - SetDlgItemInt(hDlg, IDC_VALUE, value, FALSE); - } + }else{ + SetDlgItemText(hDlg, IDC_BITRATE_S, "Target size (kbytes):"); + } - if (config->mode != DLG_MODE_2PASS_2_INT) - { - SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE, value); - } - } - else if (LOWORD(wParam) == IDOK && HIWORD(wParam) == BN_CLICKED) - { - main_download(hDlg, config); - config->save = TRUE; - EndDialog(hDlg, IDOK); - } - else if (LOWORD(wParam) == IDCANCEL) - { - config->save = FALSE; - EndDialog(hDlg, IDCANCEL); - } - break; + EnableDlgWindow(hDlg, IDC_BITRATE_S, target_en); + EnableDlgWindow(hDlg, IDC_BITRATE, target_en); - default : - return 0; + EnableDlgWindow(hDlg, IDC_BITRATE_MIN, target_en && g_use_bitrate); + EnableDlgWindow(hDlg, IDC_BITRATE_MAX, target_en && g_use_bitrate); + EnableDlgWindow(hDlg, IDC_SLIDER, target_en && g_use_bitrate); +} + + + +void main_upload(HWND hDlg, CONFIG * config) +{ + + SendDlgItemMessage(hDlg, IDC_PROFILE, CB_SETCURSEL, config->profile, 0); + SendDlgItemMessage(hDlg, IDC_MODE, CB_SETCURSEL, config->mode, 0); + + if (g_use_bitrate) { + SetDlgItemInt(hDlg, IDC_BITRATE, config->bitrate, FALSE); + }else{ + SetDlgItemInt(hDlg, IDC_BITRATE, config->desired_size, FALSE); } - return 1; + zones_update(hDlg, config);} + + +/* downloads data from main dialog */ +void main_download(HWND hDlg, CONFIG * config) +{ + config->profile = SendDlgItemMessage(hDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0); + config->mode = SendDlgItemMessage(hDlg, IDC_MODE, CB_GETCURSEL, 0, 0); + + if (g_use_bitrate) { + config->bitrate = config_get_uint(hDlg, IDC_BITRATE, config->bitrate); + }else{ + config->desired_size = config_get_uint(hDlg, IDC_BITRATE, config->desired_size); + } } -/* advanced dialog proc */ +/* main dialog proc */ -BOOL CALLBACK adv_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - PROPSHEETINFO *psi; +static const int profile_dlgs[] = { IDD_PROFILE, IDD_LEVEL, IDD_AR }; +static const int single_dlgs[] = { IDD_RC_CBR }; +static const int pass1_dlgs[] = { IDD_RC_2PASS1 }; +static const int pass2_dlgs[] = { IDD_RC_2PASS2 }; +static const int zone_dlgs[] = { IDD_ZONE }; +static const int decoder_dlgs[] = { IDD_DEC }; +static const int adv_dlgs[] = { IDD_MOTION, IDD_QUANT, IDD_DEBUG}; - psi = (PROPSHEETINFO*)GetWindowLong(hDlg, GWL_USERDATA); + +BOOL CALLBACK main_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + CONFIG* config = (CONFIG*)GetWindowLong(hDlg, GWL_USERDATA); + unsigned int i; switch (uMsg) { case WM_INITDIALOG : - psi = (PROPSHEETINFO*) ((LPPROPSHEETPAGE)lParam)->lParam; + SetWindowLong(hDlg, GWL_USERDATA, lParam); + config = (CONFIG*)lParam; - SetWindowLong(hDlg, GWL_USERDATA, (LPARAM)psi); + for (i=0; ipage == DLG_GLOBAL) - { - SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"0 - None"); - SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"1 - Very Low"); - SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"2 - Low"); - SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"3 - Medium"); - SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"4 - High"); - SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"5 - Very High"); - SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"6 - Ultra High"); - - SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_ADDSTRING, 0, (LPARAM)"H.263"); - SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_ADDSTRING, 0, (LPARAM)"MPEG"); - SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_ADDSTRING, 0, (LPARAM)"MPEG-Custom"); - SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_ADDSTRING, 0, (LPARAM)"Modulated"); - SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_ADDSTRING, 0, (LPARAM)"New Modulated HQ"); - - SendDlgItemMessage(hDlg, IDC_FOURCC, CB_ADDSTRING, 0, (LPARAM)"XVID"); - SendDlgItemMessage(hDlg, IDC_FOURCC, CB_ADDSTRING, 0, (LPARAM)"DIVX"); - SendDlgItemMessage(hDlg, IDC_FOURCC, CB_ADDSTRING, 0, (LPARAM)"DX50"); - - SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"0 - Off"); - SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"1 - Mode Decision"); - SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"2 - Limited Search"); - SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"3 - Medium Search"); - SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"4 - Wide Search"); - /* XXX: reduced resolution is not ready for prime-time */ - ShowWindow(GetDlgItem(hDlg, IDC_REDUCED), SW_HIDE); - } - else if (psi->page == DLG_2PASSALT) - { - SendDlgItemMessage(hDlg, IDC_CURVETYPE, CB_ADDSTRING, 0, (LPARAM)"Low"); - SendDlgItemMessage(hDlg, IDC_CURVETYPE, CB_ADDSTRING, 0, (LPARAM)"Medium"); - SendDlgItemMessage(hDlg, IDC_CURVETYPE, CB_ADDSTRING, 0, (LPARAM)"High"); - } - else if (psi->page == DLG_CPU) - { - EnableWindow(GetDlgItem(hDlg, IDC_NUMTHREADS_STATIC), FALSE); - EnableWindow(GetDlgItem(hDlg, IDC_NUMTHREADS), FALSE); - } + SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"Single pass"); + SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"Twopass - 1st pass"); + SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"Twopass - 2nd pass"); +#ifdef _DEBUG + SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"Null test speed"); +#endif + + InitCommonControls(); - if (hTooltip) + if ((g_hTooltip = CreateWindow(TOOLTIPS_CLASS, NULL, TTS_ALWAYSTIP, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + NULL, NULL, g_hInst, NULL))) { + SetWindowPos(g_hTooltip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); + SendMessage(g_hTooltip, TTM_SETDELAYTIME, TTDT_AUTOMATIC, MAKELONG(1500, 0)); + SendMessage(g_hTooltip, TTM_SETMAXTIPWIDTH, 0, 400); + EnumChildWindows(hDlg, enum_tooltips, 0); } - adv_upload(hDlg, psi->page, psi->config); - adv_mode(hDlg, psi->config->mode); - break; + SetClassLong(GetDlgItem(hDlg, IDC_BITRATE_S), GCL_HCURSOR, (LONG)LoadCursor(NULL, IDC_HAND)); - case WM_COMMAND : - if (HIWORD(wParam) == BN_CLICKED) { - switch (LOWORD(wParam)) - { - case IDC_HINTEDME : - case IDC_USEALT : - case IDC_USEAUTO : - case IDC_USEAUTOBONUS : - case IDC_CREDITS_START : - case IDC_CREDITS_END : - case IDC_CREDITS_RATE_RADIO : - case IDC_CREDITS_QUANT_RADIO : - case IDC_CREDITS_SIZE_RADIO : - case IDC_CPU_AUTO : - case IDC_CPU_FORCE : - adv_mode(hDlg, psi->config->mode); - break; - } + DWORD ext_style = ListView_GetExtendedListViewStyle(GetDlgItem(hDlg,IDC_ZONES)); + ext_style |= LVS_EX_FULLROWSELECT | LVS_EX_FLATSB ; + ListView_SetExtendedListViewStyle(GetDlgItem(hDlg,IDC_ZONES), ext_style); } - if ((LOWORD(wParam) == IDC_HINT_BROWSE || LOWORD(wParam) == IDC_STATS1_BROWSE || LOWORD(wParam) == IDC_STATS2_BROWSE) && HIWORD(wParam) == BN_CLICKED) + { - OPENFILENAME ofn; - char tmp[MAX_PATH]; - int hComponent = (LOWORD(wParam) == IDC_STATS1_BROWSE ? IDC_STATS1 : IDC_STATS2); - - GetDlgItemText(hDlg, hComponent, tmp, MAX_PATH); - - memset(&ofn, 0, sizeof(OPENFILENAME)); - ofn.lStructSize = sizeof(OPENFILENAME); - - ofn.hwndOwner = hDlg; - ofn.lpstrFilter = "bitrate curve (*.stats)\0*.stats\0All files (*.*)\0*.*\0\0"; - ofn.lpstrFile = tmp; - ofn.nMaxFile = MAX_PATH; - ofn.Flags = OFN_PATHMUSTEXIST; + typedef struct { + char * name; + int value; + } char_int_t; - if (LOWORD(wParam) == IDC_HINT_BROWSE) - { - ofn.lpstrFilter = "motion hints (*.mvh)\0*.mvh\0All files (*.*)\0*.*\0\0"; - if (GetOpenFileName(&ofn)) - { - SetDlgItemText(hDlg, IDC_HINTFILE, tmp); - } - } - else if (LOWORD(wParam) == IDC_STATS1_BROWSE && - psi->config->mode == DLG_MODE_2PASS_1) - { - ofn.Flags |= OFN_OVERWRITEPROMPT; - if (GetSaveFileName(&ofn)) - { - SetDlgItemText(hDlg, hComponent, tmp); - } - } - else - { - ofn.Flags |= OFN_FILEMUSTEXIST; - if (GetOpenFileName(&ofn)) { - SetDlgItemText(hDlg, hComponent, tmp); - } + const static char_int_t columns[] = { + {"Frame #", 64}, + {"Weight/Quant", 82}, + {"Modifiers", 120}}; + + LVCOLUMN lvc; + int i; + + /* Initialize the LVCOLUMN structure. */ + lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; + lvc.fmt = LVCFMT_LEFT; + + /* Add the columns. */ + for (i=0; iconfig); - } + + /* XXX: main_mode needs RC_MODE_xxx, main_upload needs g_use_bitrate set correctly... */ + main_upload(hDlg, config); + main_mode(hDlg, config); + main_upload(hDlg, config); break; case WM_NOTIFY : - switch (((NMHDR *)lParam)->code) { - case PSN_KILLACTIVE : - /* validate */ - adv_download(hDlg, psi->page, psi->config); - SetWindowLong(hDlg, DWL_MSGRESULT, FALSE); - break; + NMHDR * n = (NMHDR*)lParam; - case PSN_APPLY : - /* apply */ - adv_download(hDlg, psi->page, psi->config); - SetWindowLong(hDlg, DWL_MSGRESULT, FALSE); - psi->config->save = TRUE; - break; - } + if (n->code == NM_DBLCLK) { + NMLISTVIEW * nmlv = (NMLISTVIEW*) lParam; + config->cur_zone = nmlv->iItem; + + main_download(hDlg, config); + if (config->cur_zone >= 0 && adv_dialog(hDlg, config, zone_dlgs, sizeof(zone_dlgs)/sizeof(int))) { + zones_update(hDlg, config); + } + break; + } + + if (n->code == NM_RCLICK) { + OutputDebugString("Right click"); + } break; + } - default : - return 0; - } + case WM_COMMAND : + if (HIWORD(wParam) == BN_CLICKED) { - return 1; -} + switch(LOWORD(wParam)) { + case IDC_PROFILE_ADV : + main_download(hDlg, config); + adv_dialog(hDlg, config, profile_dlgs, sizeof(profile_dlgs)/sizeof(int)); + SendDlgItemMessage(hDlg, IDC_PROFILE, CB_SETCURSEL, config->profile, 0); + main_mode(hDlg, config); + break; -/* quantization matrix dialog proc */ + case IDC_MODE_ADV : + main_download(hDlg, config); + if (config->mode == RC_MODE_1PASS) { + adv_dialog(hDlg, config, single_dlgs, sizeof(single_dlgs)/sizeof(int)); + }else if (config->mode == RC_MODE_2PASS1) { + adv_dialog(hDlg, config, pass1_dlgs, sizeof(pass1_dlgs)/sizeof(int)); + }else if (config->mode == RC_MODE_2PASS2) { + adv_dialog(hDlg, config, pass2_dlgs, sizeof(pass2_dlgs)/sizeof(int)); + } + break; -BOOL CALLBACK quantmatrix_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - CONFIG* config = (CONFIG*)GetWindowLong(hDlg, GWL_USERDATA); - switch (uMsg) - { - case WM_INITDIALOG : - SetWindowLong(hDlg, GWL_USERDATA, lParam); - config = (CONFIG*)lParam; - quant_upload(hDlg, config); + case IDC_BITRATE_S : + /* alternate between bitrate/desired_length metrics */ + main_download(hDlg, config); + config->use_2pass_bitrate = !config->use_2pass_bitrate; + main_mode(hDlg, config); + main_upload(hDlg, config); + break; - if (hTooltip) - { - EnumChildWindows(hDlg, enum_tooltips, 0); - } - break; + case IDC_DECODER : + main_download(hDlg, config); + adv_dialog(hDlg, config, decoder_dlgs, sizeof(decoder_dlgs)/sizeof(int)); + main_mode(hDlg, config); + break; - case WM_COMMAND : - if (LOWORD(wParam) == IDOK && HIWORD(wParam) == BN_CLICKED) - { - quant_download(hDlg, config); - EndDialog(hDlg, IDOK); - } - else if (LOWORD(wParam) == IDCANCEL) - { - EndDialog(hDlg, IDCANCEL); - } - else if ((LOWORD(wParam) == IDC_LOAD || LOWORD(wParam) == IDC_SAVE) && HIWORD(wParam) == BN_CLICKED) - { - OPENFILENAME ofn; - char file[MAX_PATH]; + case IDC_ADD : + { + int i, sel, new_frame; - HANDLE hFile; - DWORD read=128, wrote=0; - BYTE quant_data[128]; - - strcpy(file, "\\matrix"); - memset(&ofn, 0, sizeof(OPENFILENAME)); - ofn.lStructSize = sizeof(OPENFILENAME); - - ofn.hwndOwner = hDlg; - ofn.lpstrFilter = "All files (*.*)\0*.*\0\0"; - ofn.lpstrFile = file; - ofn.nMaxFile = MAX_PATH; - ofn.Flags = OFN_PATHMUSTEXIST; + if (config->num_zones >= MAX_ZONES) { + MessageBox(hDlg, "Exceeded maximum number of zones.\nIncrease config.h:MAX_ZONES and rebuild.", "Warning", 0); + break; + } - if (LOWORD(wParam) == IDC_SAVE) - { - ofn.Flags |= OFN_OVERWRITEPROMPT; - if (GetSaveFileName(&ofn)) - { - hFile = CreateFile(file, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + sel = ListView_GetNextItem(GetDlgItem(hDlg, IDC_ZONES), -1, LVNI_SELECTED); - quant_download(hDlg, config); - memcpy(quant_data, config->qmatrix_intra, 64); - memcpy(quant_data+64, config->qmatrix_inter, 64); - - if (hFile == INVALID_HANDLE_VALUE) - { - DEBUGERR("Couldn't save quant matrix"); - } - else - { - if (!WriteFile(hFile, quant_data, 128, &wrote, 0)) - { - DEBUGERR("Couldnt write quant matrix"); - } + if (sel<0) { + if (config->ci_valid && config->ci.ciActiveFrame>0) { + for(sel=0; selnum_zones-1 && config->zones[sel].frameci.ciActiveFrame; sel++) ; + sel--; + new_frame = config->ci.ciActiveFrame; + }else{ + sel = config->num_zones-1; + new_frame = sel<0 ? 0 : config->zones[sel].frame + 1; } + }else{ + new_frame = config->zones[sel].frame + 1; + } - CloseHandle(hFile); + for(i=config->num_zones-1; i>sel; i--) { + config->zones[i+1] = config->zones[i]; } + config->num_zones++; + config->zones[sel+1].frame = new_frame; + config->zones[sel+1].mode = RC_ZONE_WEIGHT; + config->zones[sel+1].weight = 100; + config->zones[sel+1].quant = 500; + config->zones[sel+1].type = XVID_TYPE_AUTO; + config->zones[sel+1].greyscale = 0; + config->zones[sel+1].chroma_opt = 0; + config->zones[sel+1].bvop_threshold = 0; + + ListView_SetItemState(GetDlgItem(hDlg, IDC_ZONES), sel, 0x00000000, LVIS_SELECTED); + zones_update(hDlg, config); + ListView_SetItemState(GetDlgItem(hDlg, IDC_ZONES), sel+1, 0xffffffff, LVIS_SELECTED); + break; } - else + + case IDC_REMOVE : { - ofn.Flags |= OFN_FILEMUSTEXIST; - if (GetOpenFileName(&ofn)) - { - hFile = CreateFile(file, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + int i, sel; + sel = ListView_GetNextItem(GetDlgItem(hDlg, IDC_ZONES), -1, LVNI_SELECTED); - if (hFile == INVALID_HANDLE_VALUE) - { - DEBUGERR("Couldn't load quant matrix"); - } - else - { - if (!ReadFile(hFile, quant_data, 128, &read, 0)) - { - DEBUGERR("Couldnt read quant matrix"); - } - else - { - memcpy(config->qmatrix_intra, quant_data, 64); - memcpy(config->qmatrix_inter, quant_data+64, 64); - quant_upload(hDlg, config); - } - } + if (sel == -1 || config->num_zones < 1) { + /*MessageBox(hDlg, "Nothing selected", "Warning", 0);*/ + break; + } + + for (i=sel; inum_zones-1; i++) + config->zones[i] = config->zones[i+1]; + + config->num_zones--; + + zones_update(hDlg, config); + break; + } - CloseHandle(hFile); + case IDC_EDIT : + main_download(hDlg, config); + config->cur_zone = ListView_GetNextItem(GetDlgItem(hDlg, IDC_ZONES), -1, LVNI_SELECTED); + if (config->cur_zone != -1 && adv_dialog(hDlg, config, zone_dlgs, sizeof(zone_dlgs)/sizeof(int))) { + zones_update(hDlg, config); } + break; + + case IDC_ADVANCED : + main_download(hDlg, config); + adv_dialog(hDlg, config, adv_dlgs, sizeof(adv_dlgs)/sizeof(int)); + break; + + case IDC_DEFAULTS : + config_reg_default(config); + main_upload(hDlg, config); + break; + + case IDOK : + main_download(hDlg, config); + config->save = TRUE; + EndDialog(hDlg, IDOK); + break; + + case IDCANCEL : + config->save = FALSE; + EndDialog(hDlg, IDCANCEL); + break; + } + }else if (HIWORD(wParam) == LBN_SELCHANGE && + (LOWORD(wParam)==IDC_PROFILE || LOWORD(wParam)==IDC_MODE)) { + + main_download(hDlg, config); + main_mode(hDlg, config); + main_upload(hDlg, config); + + }else if (HIWORD(wParam)==EN_UPDATE && LOWORD(wParam)==IDC_BITRATE) { + + if (g_use_bitrate) { + SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE, + config_get_uint(hDlg, IDC_BITRATE, DEFAULT_MIN_KBPS) ); } + + }else { + return 0; } break; + case WM_HSCROLL : + if((HWND)lParam == GetDlgItem(hDlg, IDC_SLIDER)) { + SetDlgItemInt(hDlg, IDC_BITRATE, SendMessage((HWND)lParam, TBM_GETPOS, 0, 0), FALSE); + break; + } + return 0; + default : return 0; } @@ -1506,7 +1700,10 @@ } -/* about dialog proc */ + +/* ===================================================================================== */ +/* ABOUT DIALOG ======================================================================== */ +/* ===================================================================================== */ BOOL CALLBACK about_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { @@ -1518,30 +1715,40 @@ char core[100]; HFONT hFont; LOGFONT lfData; + HINSTANCE m_hdll; SetDlgItemText(hDlg, IDC_BUILD, XVID_BUILD); SetDlgItemText(hDlg, IDC_SPECIAL_BUILD, XVID_SPECIAL_BUILD); memset(&info, 0, sizeof(info)); info.version = XVID_VERSION; - xvid_global(0, XVID_GBL_INFO, &info, NULL); - wsprintf(core, "libxvidcore version %d.%d.%d (\"%s\")", - XVID_MAJOR(info.actual_version), - XVID_MINOR(info.actual_version), - XVID_PATCH(info.actual_version), - info.build); + + m_hdll = LoadLibrary(XVID_DLL_NAME); + if (m_hdll != NULL) { + + ((int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global")) + (0, XVID_GBL_INFO, &info, NULL); + + wsprintf(core, "xvidcore.dll version %d.%d.%d (\"%s\")", + XVID_VERSION_MAJOR(info.actual_version), + XVID_VERSION_MINOR(info.actual_version), + XVID_VERSION_PATCH(info.actual_version), + info.build); + + FreeLibrary(m_hdll); + } else { + wsprintf(core, "xvidcore.dll not found!"); + } SetDlgItemText(hDlg, IDC_CORE, core); hFont = (HFONT)SendDlgItemMessage(hDlg, IDC_WEBSITE, WM_GETFONT, 0, 0L); - if (GetObject(hFont, sizeof(LOGFONT), &lfData)) - { + if (GetObject(hFont, sizeof(LOGFONT), &lfData)) { lfData.lfUnderline = 1; hFont = CreateFontIndirect(&lfData); - if (hFont) - { + if (hFont) { SendDlgItemMessage(hDlg, IDC_WEBSITE, WM_SETFONT, (WPARAM)hFont, 1L); } } @@ -1550,18 +1757,17 @@ SetDlgItemText(hDlg, IDC_WEBSITE, XVID_WEBSITE); } break; - case WM_CTLCOLORSTATIC : if ((HWND)lParam == GetDlgItem(hDlg, IDC_WEBSITE)) { - SetBkMode((HDC)wParam, TRANSPARENT) ; + SetBkMode((HDC)wParam, TRANSPARENT) ; SetTextColor((HDC)wParam, RGB(0x00,0x00,0xc0)); - return (BOOL)GetStockObject(NULL_BRUSH); + return (BOOL)GetStockObject(NULL_BRUSH); } return 0; case WM_COMMAND : - if (LOWORD(wParam) == IDC_WEBSITE && HIWORD(wParam) == STN_CLICKED) + if (LOWORD(wParam) == IDC_WEBSITE && HIWORD(wParam) == STN_CLICKED) { ShellExecute(hDlg, "open", XVID_WEBSITE, NULL, NULL, SW_SHOWNORMAL); } @@ -1577,3 +1783,49 @@ return 1; } + +static void +sort_zones(zone_t * zones, int zone_num, int * sel) +{ + int i, j; + zone_t tmp; + for (i = 0; i < zone_num; i++) { + int cur = i; + int min_f = zones[i].frame; + for (j = i + 1; j < zone_num; j++) { + if (zones[j].frame < min_f) { + min_f = zones[j].frame; + cur = j; + } + } + if (cur != i) { + tmp = zones[i]; + zones[i] = zones[cur]; + zones[cur] = tmp; + if (i == *sel) *sel = cur; + else if (cur == *sel) *sel = i; + } + } +} + + +static void +zones_update(HWND hDlg, CONFIG * config) +{ + int i, sel; + + sel = ListView_GetNextItem(GetDlgItem(hDlg, IDC_ZONES), -1, LVNI_SELECTED); + + sort_zones(config->zones, config->num_zones, &sel); + + ListView_DeleteAllItems(GetDlgItem(hDlg,IDC_ZONES)); + + for (i = 0; i < config->num_zones; i++) + main_insert_zone(GetDlgItem(hDlg,IDC_ZONES), &config->zones[i], i, TRUE); + + if (sel == -1 && config->num_zones > 0) sel = 0; + if (sel >= config->num_zones) sel = config->num_zones-1; + + config->cur_zone = sel; + ListView_SetItemState(GetDlgItem(hDlg, IDC_ZONES), sel, 0xffffffff, LVIS_SELECTED); +}