--- branches/dev-api-4/xvidcore/vfw/src/config.c 2003/04/12 06:58:50 983 +++ branches/dev-api-4/xvidcore/vfw/src/config.c 2004/01/27 10:09:05 1338 @@ -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 @@ -57,30 +57,33 @@ #include #include -#include -#include - -#include // XviD API +#include /* sprintf */ +#include /* XviD API */ #include "debug.h" -#include "codec.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; +static int g_use_bitrate = 1; +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)) + if (LoadString(g_hInst, GetDlgCtrlID(hWnd), help, 500)) { TOOLINFO ti; ti.cbSize = sizeof(TOOLINFO); @@ -99,66 +102,77 @@ /* MPEG-4 PROFILES/LEVELS ============================================================== */ /* ===================================================================================== */ -#define PROFILE_BVOP 0x00000001 -#define PROFILE_MPEGQUANT 0x00000002 -#define PROFILE_INTERLACE 0x00000004 -#define PROFILE_QPEL 0x00000008 -#define PROFILE_GMC 0x00000010 -#define PROFILE_REDUCED 0x00000020 /* dynamic resolution conversion */ -#define PROFILE_AS (PROFILE_BVOP|PROFILE_MPEGQUANT|PROFILE_INTERLACE|PROFILE_QPEL|PROFILE_GMC) -#define PROFILE_ARTS (PROFILE_REDUCED) +/* default vbv_occupancy is (64/170)*vbv_buffer_size */ -typedef struct +const profile_t profiles[] = { - char * name; - int width; - int height; - int fps; - int max_objects; - int total_vmv_buffer_sz; /* macroblock memory; when BVOPS=false, vmv = 2*vcv; when BVOPS=true, vmv = 3*vcv*/ - int max_vmv_buffer_sz; /* max macroblocks per vop */ - int vcv_decoder_rate; /* macroblocks decoded per second */ - int max_acpred_mbs; /* percentage */ - int max_vbv_size; /* max vbv size (bits) 16368 bits */ - int max_video_packet_length; /* bits */ - int max_bitrate; /* kbits/s */ - unsigned int flags; -} profile_t; +/* 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 -/* default vbv_occupancy is (64/170)*vbv_buffer_size */ + { "(unrestricted)", 0x00, 0, 0, 0, 0, 0, 0, 0, 100, 0*16368, 0, 0, 0xffffffff }, +}; -static const profile_t profiles[] = -{ -/* name w h fps obj Tvmv vmv vcv ac% vbv pkt kbps flags */ - { "(unrestricted)", 0, 0, 0, 0, 0, 0, 0, 100, 0*16368, 0, 0, 0xffffffff }, - - { "Simple @ L1", 176, 144, 15, 4, 198, 99, 1485, 100, 10*16368, 2048, 64, 0 }, - { "Simple @ L2", 352, 288, 15, 4, 792, 396, 5940, 100, 40*16368, 4096, 128, 0 }, - { "Simple @ L3", 352, 288, 15, 4, 792, 396, 11880, 100, 40*16368, 8192, 384, 0 }, - - { "ARTS @ L1", 176, 144, 15, 4, 198, 99, 1485, 100, 10*16368, 8192, 64, PROFILE_ARTS }, - { "ARTS @ L2", 352, 288, 15, 4, 792, 396, 5940, 100, 40*16368, 16384, 128, PROFILE_ARTS }, - { "ARTS @ L3", 352, 288, 30, 4, 792, 396, 11880, 100, 40*16368, 16384, 384, PROFILE_ARTS }, - { "ARTS @ L4", 352, 288, 30, 16, 792, 396, 11880, 100, 80*16368, 16384, 2000, PROFILE_ARTS }, - - { "AS @ L0", 176, 144, 30, 1, 297, 99, 2970, 100, 10*16368, 2048, 128, PROFILE_AS }, - { "AS @ L1", 176, 144, 30, 4, 297, 99, 2970, 100, 10*16368, 2048, 128, PROFILE_AS }, - { "AS @ L2", 352, 288, 15, 4, 1188, 396, 5940, 100, 40*16368, 4096, 384, PROFILE_AS }, - { "AS @ L3", 352, 288, 30, 4, 1188, 396, 11880, 100, 40*16368, 4096, 768, PROFILE_AS }, - { "AS @ L4", 352, 576, 30, 4, 2376, 792, 23760, 50, 80*16368, 8192, 3000, PROFILE_AS }, - { "AS @ L5", 720, 576, 30, 4, 4860, 1620, 48600, 25, 112*16368, 16384, 8000, PROFILE_AS }, - - { "DXN Handheld", 176, 144, 15, -1, 198, 99, 1485, 100, 16*16368, -1, 128, 0 }, - { "DXN Portable NTSC", 352, 240, 30, -1, 990, 330, 9900, 100, 64*16368, -1, 768, PROFILE_BVOP }, - { "DXN Portable PAL", 352, 288, 25, -1, 1188, 396, 9900, 100, 64*16368, -1, 768, PROFILE_BVOP }, - { "DXN HT NTSC", 720, 480, 30, -1, 4050, 1350, 40500, 100, 192*16368, -1, 4000, PROFILE_BVOP|PROFILE_INTERLACE }, - { "DXN HT NTSC", 720, 576, 25, -1, 4860, 1620, 40500, 100, 192*16368, -1, 4000, PROFILE_BVOP|PROFILE_INTERLACE }, - { "DXN HDTV", 1280, 720, 30, -1,10800, 3600, 108000, 100, 384*16368, -1, 8000, PROFILE_BVOP|PROFILE_INTERLACE }, + +typedef struct { + char * name; + float value; +} named_float_t; + +static const named_float_t video_fps_list[] = { + { "15.0", 15.0F }, + { "23.976 (FILM)", 23.976F }, + { "25.0 (PAL)", 25.0F }, + { "29.97 (NTSC)", 29.970F }, + { "30.0", 30.0F } }; +typedef struct { + char * name; + int value; +} named_int_t; + +/* audio overhead intervals (milliseconds) */ + +static const named_int_t audio_type_list[] = { + { "MP3-CBR", 1000 }, + { "MP3-VBR", 24 }, + { "AC3", 64 }, + { "DTS", 21 }, + { "(None)", 0 }, +}; + + /* ===================================================================================== */ /* REGISTRY ============================================================================ */ /* ===================================================================================== */ @@ -167,150 +181,222 @@ CONFIG reg; static const REG_INT reg_ints[] = { - {"mode", ®.mode, RC_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}, + {"mode", ®.mode, RC_MODE_1PASS}, + {"bitrate", ®.bitrate, 700}, + {"desired_size", ®.desired_size, 570000}, + {"use_2pass_bitrate", ®.use_2pass_bitrate, 0}, + {"desired_quant", ®.desired_quant, DEFAULT_QUANT}, /* 100-base float */ - {"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}, - {"greyscale", ®.greyscale, 0}, - {"use_bvop", ®.use_bvop, 0}, + {"reduced_resolution", ®.reduced_resolution, 0}, + {"use_bvop", ®.use_bvop, 1}, {"max_bframes", ®.max_bframes, 2}, - {"bquant_ratio", ®.bquant_ratio, 150}, - {"bquant_offset", ®.bquant_offset, 100}, - {"bvop_threshold", ®.bvop_threshold, 0}, - {"packed", ®.packed, 0}, + {"bquant_ratio", ®.bquant_ratio, 150}, /* 100-base float */ + {"bquant_offset", ®.bquant_offset, 100}, /* 100-base float */ + {"packed", ®.packed, 1}, {"closed_gov", ®.closed_gov, 1}, - {"debug", ®.debug, 0}, - {"reduced_resolution", ®.reduced_resolution, 0}, - {"chroma_opt", ®.chroma_opt, 0}, - {"frame_drop_ratio", ®.frame_drop_ratio, 0}, - {"min_iquant", ®.min_iquant, 2}, - {"max_iquant", ®.max_iquant, 31}, - {"min_pquant", ®.min_pquant, 2}, - {"max_pquant", ®.max_pquant, 31}, + /* 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}, - {"desired_size", ®.desired_size, 570000}, - {"keyframe_boost", ®.keyframe_boost, 0}, + /* 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}, - {"kftreshold", ®.kftreshold, 10}, + + /* 2pass2 */ + {"keyframe_boost", ®.keyframe_boost, 10}, {"kfreduction", ®.kfreduction, 20}, + {"kfthreshold", ®.kfthreshold, 1}, {"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}, - - /* decoder */ -// {"deblock_y", ®.deblock_y, 0}, -// {"deblock_uv", ®.deblock_uv, 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}, + + /* bitrate calculator */ + {"container_type", ®.container_type, 1}, + {"target_size", ®.target_size, 650 * 1024}, + {"subtitle_size", ®.subtitle_size, 0}, + {"hours", ®.hours, 1}, + {"minutes", ®.minutes, 30}, + {"seconds", ®.seconds, 0}, + {"fps", ®.fps, 2}, + {"audio_mode", ®.audio_mode, 0}, + {"audio_type", ®.audio_type, 0}, + {"audio_rate", ®.audio_rate, 128}, + {"audio_size", ®.audio_size, 0}, + + /* 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, 1}, + {"max_iquant", ®.max_iquant, 31}, + {"min_pquant", ®.min_pquant, 1}, + {"max_pquant", ®.max_pquant, 31}, + {"min_bquant", ®.min_bquant, 1}, + {"max_bquant", ®.max_bquant, 31}, + {"trellis_quant", ®.trellis_quant, 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}, + {"profile", reg.profile_name, "AS @ L5"}, + {"stats", reg.stats, CONFIG_2PASS_FILE}, +}; + + +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 +}; + +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 }; -/* get config settings from registry */ + #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); } @@ -321,9 +407,10 @@ void config_reg_set(CONFIG * config) { + char tmp[64]; HKEY hKey; DWORD dispo; - int i; + int i,j; if (RegCreateKeyEx( XVID_REG_KEY, @@ -332,8 +419,8 @@ XVID_REG_CLASS, REG_OPTION_NON_VOLATILE, KEY_WRITE, - 0, - &hKey, + 0, + &hKey, &dispo) != ERROR_SUCCESS) { DPRINTF("Couldn't create XVID_REG_SUBKEY - GetLastError=%i", GetLastError()); @@ -342,20 +429,29 @@ memcpy(®, config, sizeof(CONFIG)); - strcpy(reg.profile_name, profiles[reg.profile].name); - - 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; jqmatrix_intra[i], FALSE); SetDlgItemInt(hDlg, IDC_QINTER00 + i, config->qmatrix_inter[i], FALSE); } } -void quant_download(HWND hDlg, CONFIG* config) +static void quant_download(HWND hDlg, CONFIG* config) { int i; - for (i=0; i<64 ; ++i) - { + for (i=0; i<64; i++) { int temp; temp = config_get_uint(hDlg, i + IDC_QINTRA00, config->qmatrix_intra[i]); @@ -442,9 +572,67 @@ } } + +static 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); + } + } +} + /* quantization matrix dialog proc */ -BOOL CALLBACK quantmatrix_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +static BOOL CALLBACK quantmatrix_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { CONFIG* config = (CONFIG*)GetWindowLong(hDlg, GWL_USERDATA); @@ -462,96 +650,38 @@ 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]; - 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 (LOWORD(wParam) == IDC_SAVE) - { - ofn.Flags |= OFN_OVERWRITEPROMPT; - if (GetSaveFileName(&ofn)) - { - hFile = CreateFile(file, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + if (HIWORD(wParam) == BN_CLICKED) { + switch(LOWORD(wParam)) { + case IDOK : + quant_download(hDlg, config); + EndDialog(hDlg, IDOK); + break; - 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"); - } - } + case IDCANCEL : + EndDialog(hDlg, IDCANCEL); + break; - CloseHandle(hFile); - } - } - else - { - ofn.Flags |= OFN_FILEMUSTEXIST; - if (GetOpenFileName(&ofn)) - { - hFile = CreateFile(file, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + case IDC_SAVE : + quant_loadsave(hDlg, config, 1); + break; - 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); - } - } + case IDC_LOAD : + quant_loadsave(hDlg, config, 0); + break; - CloseHandle(hFile); - } + default : + return FALSE; } + break; } - break; + return FALSE; default : - return 0; + return FALSE; } - return 1; + return TRUE; } @@ -560,23 +690,66 @@ /* ===================================================================================== */ /* initialise pages */ -void adv_init(HWND hDlg, int idd, CONFIG * config) +static void adv_init(HWND hDlg, int idd, CONFIG * config) { unsigned int i; - switch(idd) { - case IDD_PROFILE : + switch(idd) { + case IDD_PROFILE : for (i=0; ici_valid); + break; - case IDD_MOTION : + 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"); @@ -590,15 +763,9 @@ 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; + break; - case IDD_TOOLS : - 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"); - break; - - case IDD_DEBUG : + case IDD_DEBUG : /* force threads disabled */ EnableWindow(GetDlgItem(hDlg, IDC_NUMTHREADS_STATIC), FALSE); EnableWindow(GetDlgItem(hDlg, IDC_NUMTHREADS), FALSE); @@ -606,86 +773,249 @@ 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; - } + break; + } } + /* enable/disable controls based on encoder-mode or user selection */ -void adv_mode(HWND hDlg, int idd, CONFIG * config) +static void adv_mode(HWND hDlg, int idd, CONFIG * config) { - int use_alt, use_alt_auto, use_alt_auto_bonus; - int cpu_force; - int bvops; - - switch(idd) { - case IDD_PROFILE : - CheckDlgButton(hDlg, IDC_PROFILE_BVOP, profiles[config->profile].flags&PROFILE_BVOP ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg, IDC_PROFILE_MPEGQUANT, profiles[config->profile].flags&PROFILE_MPEGQUANT ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg, IDC_PROFILE_INTERLACE, profiles[config->profile].flags&PROFILE_INTERLACE ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg, IDC_PROFILE_QPEL, profiles[config->profile].flags&PROFILE_QPEL ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg, IDC_PROFILE_GMC, profiles[config->profile].flags&PROFILE_GMC ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg, IDC_PROFILE_REDUCED, profiles[config->profile].flags&PROFILE_REDUCED ? BST_CHECKED : BST_UNCHECKED); - break; - - case IDD_RC_2PASS2_ALT : - use_alt = IsDlgChecked(hDlg, IDC_USEALT); - use_alt_auto = IsDlgChecked(hDlg, IDC_USEAUTO); - use_alt_auto_bonus = IsDlgChecked(hDlg, IDC_USEAUTOBONUS); - EnableDlgWindow(hDlg, IDC_USEAUTO, use_alt); - EnableDlgWindow(hDlg, IDC_AUTOSTR, use_alt && use_alt_auto); - EnableDlgWindow(hDlg, IDC_USEAUTOBONUS, use_alt); - EnableDlgWindow(hDlg, IDC_BONUSBIAS, use_alt && !use_alt_auto_bonus); - EnableDlgWindow(hDlg, IDC_CURVETYPE, use_alt); - EnableDlgWindow(hDlg, IDC_ALTCURVEHIGH, use_alt); - EnableDlgWindow(hDlg, IDC_ALTCURVELOW, use_alt); - EnableDlgWindow(hDlg, IDC_MINQUAL, use_alt && !use_alt_auto); - break; - - case IDD_TOOLS : - bvops = IsDlgChecked(hDlg, IDC_BVOP); - EnableDlgWindow(hDlg, IDC_MAXBFRAMES, bvops); - EnableDlgWindow(hDlg, IDC_BQUANTRATIO, bvops); - EnableDlgWindow(hDlg, IDC_BQUANTOFFSET, bvops); - EnableDlgWindow(hDlg, IDC_BVOP_THRESHOLD, bvops); - - EnableDlgWindow(hDlg, IDC_MAXBFRAMES_S, bvops); - EnableDlgWindow(hDlg, IDC_BQUANTRATIO_S, bvops); - EnableDlgWindow(hDlg, IDC_BQUANTOFFSET_S, bvops); - EnableDlgWindow(hDlg, IDC_BVOP_THRESHOLD_S, bvops); - - EnableDlgWindow(hDlg, IDC_PACKED, bvops); - EnableDlgWindow(hDlg, IDC_CLOSEDGOV, 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; - } -} + int profile; + int weight_en, quant_en; + int cpu_force; + int custom_quant, bvops; + int ar_mode, ar_par; + + switch(idd) { + case IDD_PROFILE : + profile = SendDlgItemMessage(hDlg, IDC_PROFILE_PROFILE, CB_GETCURSEL, 0, 0); + EnableDlgWindow(hDlg, IDC_BVOP, profiles[profile].flags&PROFILE_BVOP); + + EnableDlgWindow(hDlg, IDC_QUANTTYPE_S, profiles[profile].flags&PROFILE_MPEGQUANT); + EnableDlgWindow(hDlg, IDC_QUANTTYPE_S, profiles[profile].flags&PROFILE_MPEGQUANT); + EnableDlgWindow(hDlg, IDC_QUANTTYPE, profiles[profile].flags&PROFILE_MPEGQUANT); + custom_quant = (profiles[profile].flags&PROFILE_MPEGQUANT) && SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_GETCURSEL, 0, 0)==QUANT_MODE_CUSTOM; + EnableDlgWindow(hDlg, IDC_QUANTMATRIX, custom_quant); + EnableDlgWindow(hDlg, IDC_LUMMASK, profiles[profile].flags&PROFILE_ADAPTQUANT); + EnableDlgWindow(hDlg, IDC_INTERLACING, profiles[profile].flags&PROFILE_INTERLACE); + EnableDlgWindow(hDlg, IDC_QPEL, profiles[profile].flags&PROFILE_QPEL); + EnableDlgWindow(hDlg, IDC_GMC, profiles[profile].flags&PROFILE_GMC); + EnableDlgWindow(hDlg, IDC_REDUCED, profiles[profile].flags&PROFILE_REDUCED); + + bvops = (profiles[profile].flags&PROFILE_BVOP) && IsDlgChecked(hDlg, IDC_BVOP); + EnableDlgWindow(hDlg, IDC_MAXBFRAMES, bvops); + EnableDlgWindow(hDlg, IDC_BQUANTRATIO, bvops); + EnableDlgWindow(hDlg, IDC_BQUANTOFFSET, bvops); + EnableDlgWindow(hDlg, IDC_MAXBFRAMES_S, bvops); + EnableDlgWindow(hDlg, IDC_BQUANTRATIO_S, bvops); + EnableDlgWindow(hDlg, IDC_BQUANTOFFSET_S, bvops); + EnableDlgWindow(hDlg, IDC_PACKED, bvops); + EnableDlgWindow(hDlg, IDC_CLOSEDGOV, bvops); + break; + + case IDD_AR: + ar_mode = IsDlgChecked(hDlg, IDC_PAR); + EnableDlgWindow(hDlg, IDC_ASPECT_RATIO, ar_mode); + + ar_par = SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_GETCURSEL, 0, 0); + if (ar_par == 5) { /* custom par */ + SetDlgItemInt(hDlg, IDC_PARY, config->par_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_BITRATE : + { + int ctype = SendDlgItemMessage(hDlg, IDC_BITRATE_CFORMAT, CB_GETCURSEL, 0, 0); + int target_size = config_get_uint(hDlg, IDC_BITRATE_TSIZE, 0); + int subtitle_size = config_get_uint(hDlg, IDC_BITRATE_SSIZE, 0); + int fps = SendDlgItemMessage(hDlg, IDC_BITRATE_FPS, CB_GETCURSEL, 0, 0); + + int duration = + 3600 * config_get_uint(hDlg, IDC_BITRATE_HOURS, 0) + + 60 * config_get_uint(hDlg, IDC_BITRATE_MINUTES, 0) + + config_get_uint(hDlg, IDC_BITRATE_SECONDS, 0); + + int audio_type = SendDlgItemMessage(hDlg, IDC_BITRATE_AFORMAT, CB_GETCURSEL, 0, 0); + int audio_mode = IsDlgChecked(hDlg, IDC_BITRATE_AMODE_SIZE); + int audio_rate = config_get_uint(hDlg, IDC_BITRATE_ARATE, 0); + int audio_size = config_get_uint(hDlg, IDC_BITRATE_ASIZE, 0); + int audio_value; + + int frames; + int overhead; + int vsize; + + if (duration == 0) + break; + + if (fps < 0 || fps >= sizeof(video_fps_list)/sizeof(named_float_t)) { + fps = 0; + } + if (audio_type < 0 || audio_type >= sizeof(audio_type_list)/sizeof(named_int_t)) { + audio_type = 0; + } + + /* audio_value tells us the audio overhead interval (milliseconds), or + zero if audio is not selected*/ + + audio_value = audio_type_list[audio_type].value; + + EnableDlgWindow(hDlg, IDC_BITRATE_AMODE_RATE, audio_value); + EnableDlgWindow(hDlg, IDC_BITRATE_AMODE_SIZE, audio_value); + EnableDlgWindow(hDlg, IDC_BITRATE_ARATE, audio_value && !audio_mode); + EnableDlgWindow(hDlg, IDC_BITRATE_ASIZE, audio_value && audio_mode); + EnableDlgWindow(hDlg, IDC_BITRATE_ASELECT, audio_value && audio_mode); + + /* step 1: calculate number of frames */ + + frames = (int)(duration * video_fps_list[fps].value); + + /* step 2: calculate audio_size (kbytes)*/ + + if (audio_value) { + if (audio_mode==0) { + audio_size = (duration * audio_rate) / 8; + } + }else{ + audio_size = 0; + } + + /* step 3: calculate container overhead */ + + switch(ctype) { + case 0 : /* AVI */ + case 1 : /* AVI-OpenDML */ + + overhead = frames; + + if (audio_value) { + overhead += (duration * 1000) / audio_value; + } + + overhead *= (ctype==0) ? 24 : 16; + overhead /= 1024; + break; + + default : /* (none) */ + overhead = 0; + break; + } + + SetDlgItemInt(hDlg, IDC_BITRATE_COVERHEAD, overhead, TRUE); + + /* final video bitstream size */ + vsize = target_size - subtitle_size - audio_size - overhead; + if (vsize > 0) { + SetDlgItemInt(hDlg, IDC_BITRATE_VSIZE, vsize, TRUE); + /* convert from kbytes to kbits-per-second */ + SetDlgItemInt(hDlg, IDC_BITRATE_VRATE, (vsize * 8 * 128) / (duration * 125), TRUE); + }else{ + SetDlgItemText(hDlg, IDC_BITRATE_VSIZE, "Overflow"); + SetDlgItemText(hDlg, IDC_BITRATE_VRATE, "Overflow"); + } + + } + 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 idd, CONFIG * config) +static void adv_upload(HWND hDlg, int idd, CONFIG * config) { switch (idd) { case IDD_PROFILE : SendDlgItemMessage(hDlg, IDC_PROFILE_PROFILE, CB_SETCURSEL, config->profile, 0); - SetDlgItemInt(hDlg, IDC_PROFILE_WIDTH, profiles[config->profile].width, FALSE); - SetDlgItemInt(hDlg, IDC_PROFILE_HEIGHT, profiles[config->profile].height, FALSE); - SetDlgItemInt(hDlg, IDC_PROFILE_FPS, profiles[config->profile].fps, FALSE); - SetDlgItemInt(hDlg, IDC_PROFILE_VMV, profiles[config->profile].max_vmv_buffer_sz, FALSE); - SetDlgItemInt(hDlg, IDC_PROFILE_VCV, profiles[config->profile].vcv_decoder_rate, FALSE); - SetDlgItemInt(hDlg, IDC_PROFILE_VBV, profiles[config->profile].max_vbv_size, FALSE); - SetDlgItemInt(hDlg, IDC_PROFILE_BITRATE, profiles[config->profile].max_bitrate, FALSE); + + SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_SETCURSEL, config->quant_type, 0); + 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 IDD_LEVEL : + SendDlgItemMessage(hDlg, IDC_LEVEL_PROFILE, CB_SETCURSEL, config->profile, 0); break; case IDD_RC_CBR : @@ -694,109 +1024,65 @@ SetDlgItemInt(hDlg, IDC_CBR_BUFFER, config->rc_buffer, FALSE); break; - case IDD_RC_2PASS1 : - SetDlgItemText(hDlg, IDC_STATS, config->stats); - CheckDlgButton(hDlg, IDC_DISCARD1PASS, config->discard1pass ? BST_CHECKED : BST_UNCHECKED); - break; + 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); - SetDlgItemInt(hDlg, IDC_KFTRESHOLD, config->kftreshold, FALSE); + SetDlgItemInt(hDlg, IDC_KFBOOST, config->keyframe_boost, FALSE); SetDlgItemInt(hDlg, IDC_KFREDUCTION, config->kfreduction, FALSE); + + 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)); + SetDlgItemInt(hDlg, IDC_MINKEY, config->kfthreshold, FALSE); break; - case IDD_RC_2PASS2_ALT : - CheckDlgButton(hDlg, IDC_USEALT, config->use_alt_curve ? BST_CHECKED : BST_UNCHECKED); - - 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_USEAUTO, config->alt_curve_use_auto ? BST_CHECKED : BST_UNCHECKED); - SetDlgItemInt(hDlg, IDC_AUTOSTR, config->alt_curve_auto_str, FALSE); - - 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); + case IDD_BITRATE : + SendDlgItemMessage(hDlg, IDC_BITRATE_CFORMAT, CB_SETCURSEL, config->container_type, 0); + SetDlgItemInt(hDlg, IDC_BITRATE_TSIZE, config->target_size, FALSE); + SetDlgItemInt(hDlg, IDC_BITRATE_SSIZE, config->subtitle_size, FALSE); + + SetDlgItemInt(hDlg, IDC_BITRATE_HOURS, config->hours, FALSE); + SetDlgItemInt(hDlg, IDC_BITRATE_MINUTES, config->minutes, FALSE); + SetDlgItemInt(hDlg, IDC_BITRATE_SECONDS, config->seconds, FALSE); + SendDlgItemMessage(hDlg, IDC_BITRATE_FPS, CB_SETCURSEL, config->fps, 0); + + SendDlgItemMessage(hDlg, IDC_BITRATE_AFORMAT, CB_SETCURSEL, config->audio_type, 0); + CheckRadioButton(hDlg, IDC_BITRATE_AMODE_RATE, IDC_BITRATE_AMODE_SIZE, config->audio_mode == 0 ? IDC_BITRATE_AMODE_RATE : IDC_BITRATE_AMODE_SIZE); + SetDlgItemInt(hDlg, IDC_BITRATE_ARATE, config->audio_rate, FALSE); + SetDlgItemInt(hDlg, IDC_BITRATE_ASIZE, config->audio_size, FALSE); + break; + + case IDD_ZONE : + SetDlgItemInt(hDlg, IDC_ZONE_FRAME, config->zones[config->cur_zone].frame, 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); + + 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); - 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 IDD_MOTION : SendDlgItemMessage(hDlg, IDC_MOTION, CB_SETCURSEL, config->motion_search, 0); SendDlgItemMessage(hDlg, IDC_VHQ, CB_SETCURSEL, config->vhq_mode, 0); - CheckDlgButton(hDlg, IDC_CHROMAME, config->chromame ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg, IDC_GREYSCALE, config->greyscale ? BST_CHECKED : BST_UNCHECKED); - break; - - case IDD_TOOLS : - if (profiles[config->profile].flags & PROFILE_MPEGQUANT) { - EnableDlgWindow(hDlg, IDC_QUANTTYPE, TRUE); - SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_SETCURSEL, config->quant_type, 0); - }else{ - SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_SETCURSEL, 0 /* h263 */, 0); - EnableDlgWindow(hDlg, IDC_QUANTTYPE, FALSE); - } - - if (profiles[config->profile].flags & PROFILE_INTERLACE) { - EnableDlgWindow(hDlg, IDC_INTERLACING, TRUE); - CheckDlgButton(hDlg, IDC_INTERLACING, config->interlacing ? BST_CHECKED : BST_UNCHECKED); - }else{ - CheckDlgButton(hDlg, IDC_INTERLACING, BST_UNCHECKED); - EnableDlgWindow(hDlg, IDC_INTERLACING, FALSE); - } - - if (profiles[config->profile].flags & PROFILE_QPEL) { - EnableDlgWindow(hDlg, IDC_QPEL, TRUE); - CheckDlgButton(hDlg, IDC_QPEL, config->qpel ? BST_CHECKED : BST_UNCHECKED); - }else{ - CheckDlgButton(hDlg, IDC_QPEL, BST_UNCHECKED); - EnableDlgWindow(hDlg, IDC_QPEL, FALSE); - } - - if (profiles[config->profile].flags & PROFILE_GMC) { - EnableDlgWindow(hDlg, IDC_GMC, TRUE); - CheckDlgButton(hDlg, IDC_GMC, config->gmc ? BST_CHECKED : BST_UNCHECKED); - }else{ - CheckDlgButton(hDlg, IDC_GMC, BST_UNCHECKED); - EnableDlgWindow(hDlg, IDC_GMC, FALSE); - } - - if (profiles[config->profile].flags & PROFILE_REDUCED) { - EnableDlgWindow(hDlg, IDC_REDUCED, TRUE); - CheckDlgButton(hDlg, IDC_REDUCED, config->reduced_resolution ? BST_CHECKED : BST_UNCHECKED); - }else{ - CheckDlgButton(hDlg, IDC_REDUCED, BST_UNCHECKED); - EnableDlgWindow(hDlg, IDC_REDUCED, FALSE); - } - - if (profiles[config->profile].flags & PROFILE_BVOP) { - EnableDlgWindow(hDlg, IDC_BVOP, TRUE); - CheckDlgButton(hDlg, IDC_BVOP, config->use_bvop ? BST_CHECKED : BST_UNCHECKED); - }else{ - EnableDlgWindow(hDlg, IDC_BVOP, FALSE); - CheckDlgButton(hDlg, IDC_BVOP, BST_UNCHECKED); - } - SetDlgItemInt(hDlg, IDC_MAXBFRAMES, config->max_bframes, FALSE); - SetDlgItemInt(hDlg, IDC_BQUANTRATIO, config->bquant_ratio, FALSE); - SetDlgItemInt(hDlg, IDC_BQUANTOFFSET, config->bquant_offset, FALSE); - SetDlgItemInt(hDlg, IDC_BVOP_THRESHOLD, config->bvop_threshold, FALSE); - CheckDlgButton(hDlg, IDC_PACKED, config->packed ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hDlg, IDC_CLOSEDGOV, config->closed_gov ? BST_CHECKED : BST_UNCHECKED); - - CheckDlgButton(hDlg, IDC_LUMMASK, config->lum_masking ? BST_CHECKED : BST_UNCHECKED); + 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); - SetDlgItemInt(hDlg, IDC_MINKEY, config->min_key_interval, FALSE); - break; case IDD_QUANT : @@ -804,44 +1090,77 @@ 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 IDD_DEBUG : - 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); + 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); - CheckDlgButton(hDlg, IDC_DEBUG, config->debug ? BST_CHECKED : BST_UNCHECKED); 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_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); + 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 */ -void adv_download(HWND hDlg, int idd, CONFIG * config) +static void adv_download(HWND hDlg, int idd, CONFIG * config) { switch (idd) { case IDD_PROFILE : config->profile = SendDlgItemMessage(hDlg, IDC_PROFILE_PROFILE, CB_GETCURSEL, 0, 0); + + 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); + + 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 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); + } + break; + + case IDD_LEVEL : + config->profile = SendDlgItemMessage(hDlg, IDC_LEVEL_PROFILE, CB_GETCURSEL, 0, 0); break; case IDD_RC_CBR : @@ -851,118 +1170,126 @@ break; case IDD_RC_2PASS1 : - if (GetDlgItemText(hDlg, IDC_STATS, config->stats, MAX_PATH) == 0) + if (GetDlgItemText(hDlg, IDC_STATS, config->stats, MAX_PATH) == 0) lstrcpy(config->stats, CONFIG_2PASS_FILE); - config->discard1pass = IsDlgChecked(hDlg, IDC_DISCARD1PASS); - break; + config->discard1pass = IsDlgChecked(hDlg, IDC_DISCARD1PASS); + break; - case IDD_RC_2PASS2 : - if (GetDlgItemText(hDlg, IDC_STATS, config->stats, MAX_PATH) == 0) + case IDD_RC_2PASS2 : + if (GetDlgItemText(hDlg, IDC_STATS, config->stats, MAX_PATH) == 0) lstrcpy(config->stats, CONFIG_2PASS_FILE); - config->keyframe_boost = GetDlgItemInt(hDlg, IDC_KFBOOST, NULL, FALSE); - config->kftreshold = GetDlgItemInt(hDlg, IDC_KFTRESHOLD, NULL, FALSE); + config->keyframe_boost = GetDlgItemInt(hDlg, IDC_KFBOOST, NULL, FALSE); config->kfreduction = GetDlgItemInt(hDlg, IDC_KFREDUCTION, NULL, FALSE); - - 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 = IsDlgChecked(hDlg, IDC_PAYBACKPROP); + 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); - CONSTRAINVAL(config->bitrate_payback_delay, 1, 10000); - CONSTRAINVAL(config->keyframe_boost, 0, 1000); + 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); + + config->kfthreshold = config_get_uint(hDlg, IDC_MINKEY, config->kfthreshold); + break; - case IDD_RC_2PASS2_ALT : - config->use_alt_curve = IsDlgChecked(hDlg, IDC_USEALT); + case IDD_BITRATE : + config->container_type = SendDlgItemMessage(hDlg, IDC_BITRATE_CFORMAT, CB_GETCURSEL, 0, 0); + config->target_size = config_get_uint(hDlg, IDC_BITRATE_TSIZE, config->target_size); + config->subtitle_size = config_get_uint(hDlg, IDC_BITRATE_SSIZE, config->subtitle_size); - config->alt_curve_use_auto = IsDlgChecked(hDlg, IDC_USEAUTO); - config->alt_curve_auto_str = config_get_uint(hDlg, IDC_AUTOSTR, config->alt_curve_auto_str); + config->hours = config_get_uint(hDlg, IDC_BITRATE_HOURS, config->hours); + config->minutes = config_get_uint(hDlg, IDC_BITRATE_MINUTES, config->minutes); + config->seconds = config_get_uint(hDlg, IDC_BITRATE_SECONDS, config->seconds); + config->fps = SendDlgItemMessage(hDlg, IDC_BITRATE_FPS, CB_GETCURSEL, 0, 0); - config->alt_curve_use_auto_bonus_bias = IsDlgChecked(hDlg, IDC_USEAUTOBONUS); - config->alt_curve_bonus_bias = config_get_uint(hDlg, IDC_BONUSBIAS, config->alt_curve_bonus_bias); + config->audio_type = SendDlgItemMessage(hDlg, IDC_BITRATE_AFORMAT, CB_GETCURSEL, 0, 0); + config->audio_mode = IsDlgChecked(hDlg, IDC_BITRATE_AMODE_SIZE) ? 1 : 0 ; + config->audio_rate = config_get_uint(hDlg, IDC_BITRATE_ARATE, config->audio_rate); + config->audio_size = config_get_uint(hDlg, IDC_BITRATE_ASIZE, config->audio_size); - 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); + config->desired_size = config_get_uint(hDlg, IDC_BITRATE_VSIZE, config->desired_size); + config->bitrate = config_get_uint(hDlg, IDC_BITRATE_VRATE, config->bitrate); + break; - CONSTRAINVAL(config->twopass_max_overflow_improvement, 1, 80); - CONSTRAINVAL(config->twopass_max_overflow_degradation, 1, 80); + 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; + } + + 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); + + 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); + + config->zones[config->cur_zone].bvop_threshold = config_get_int(hDlg, IDC_ZONE_BVOPTHRESHOLD, config->zones[config->cur_zone].bvop_threshold); break; 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->greyscale = IsDlgChecked(hDlg, IDC_GREYSCALE); + config->cartoon_mode = IsDlgChecked(hDlg, IDC_CARTOON); + config->turbo = IsDlgChecked(hDlg, IDC_TURBO); - config->chroma_opt = IsDlgChecked(hDlg, IDC_CHROMA_OPT); config->frame_drop_ratio = config_get_uint(hDlg, IDC_FRAMEDROP, config->frame_drop_ratio); - break; - - case IDD_TOOLS : - config->quant_type = SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_GETCURSEL, 0, 0); - 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); - - config->use_bvop = IsDlgChecked(hDlg, IDC_BVOP); - 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->bvop_threshold = config_get_uint(hDlg, IDC_BVOP_THRESHOLD, config->bvop_threshold); - config->packed = IsDlgChecked(hDlg, IDC_PACKED); - config->closed_gov = IsDlgChecked(hDlg, IDC_CLOSEDGOV); - config->lum_masking = IsDlgChecked(hDlg, IDC_LUMMASK); 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); - break; + 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); + + config->trellis_quant = IsDlgChecked(hDlg, IDC_TRELLISQUANT); break; case IDD_DEBUG : config->cpu = 0; - config->cpu |= IsDlgChecked(hDlg, IDC_CPU_MMX) ? XVID_CPU_MMX : 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_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; + config->cpu |= IsDlgChecked(hDlg, IDC_CPU_FORCE) ? XVID_CPU_FORCE : 0; config->num_threads = config_get_uint(hDlg, IDC_NUMTHREADS, config->num_threads); - config->fourcc_used = SendDlgItemMessage(hDlg, IDC_FOURCC, CB_GETCURSEL, 0, 0); - config->debug = IsDlgChecked(hDlg, IDC_DEBUG); + 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; - - case IDD_POSTPROC : -// config->deblock_y = IsDlgChecked(hDlg, IDC_DEBLOCK_Y); -// config->deblock_uv = IsDlgChecked(hDlg, 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; } } @@ -971,7 +1298,7 @@ /* advanced dialog proc */ -BOOL CALLBACK adv_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +static BOOL CALLBACK adv_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { PROPSHEETINFO *psi; @@ -986,9 +1313,7 @@ if (g_hTooltip) EnumChildWindows(hDlg, enum_tooltips, 0); - adv_init(hDlg, psi->idd, psi->config); - adv_upload(hDlg, psi->idd, psi->config); - adv_mode(hDlg, psi->idd, psi->config); + adv_init(hDlg, psi->idd, psi->config); break; case WM_COMMAND : @@ -996,75 +1321,184 @@ { switch (LOWORD(wParam)) { - case IDC_PROFILE_MPEGQUANT : - case IDC_PROFILE_INTERLACE : - case IDC_PROFILE_QPEL : - case IDC_PROFILE_GMC : - case IDC_PROFILE_REDUCED : - case IDC_PROFILE_BVOP : - case IDC_USEALT : - case IDC_USEAUTO : - case IDC_USEAUTOBONUS : - case IDC_BVOP : + 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 : + case IDC_BITRATE_AMODE_RATE : + case IDC_BITRATE_AMODE_SIZE : 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); - } - } - } - }else if (LOWORD(wParam) == IDC_PROFILE_PROFILE && HIWORD(wParam) == LBN_SELCHANGE) - { - adv_download(hDlg, psi->idd, psi->config); - adv_upload(hDlg, psi->idd, psi->config); - adv_mode(hDlg, psi->idd, psi->config); - } + case IDC_BITRATE_SSELECT : + case IDC_BITRATE_ASELECT : + { + OPENFILENAME ofn; + char filename[MAX_PATH] = ""; + + memset(&ofn, 0, sizeof(OPENFILENAME)); + ofn.lStructSize = sizeof(OPENFILENAME); + + ofn.hwndOwner = hDlg; + if (LOWORD(wParam)==IDC_BITRATE_SSELECT) { + ofn.lpstrFilter = "Subtitle files (*.sub, *.ssa)\0*.sub;*.ssa\0All files (*.*)\0*.*\0\0"; + }else{ + ofn.lpstrFilter = "Audio files (*.mp3, *.ac3)\0*.mp3; *.ac3\0All files (*.*)\0*.*\0\0"; + } + + ofn.lpstrFile = filename; + ofn.nMaxFile = MAX_PATH; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; + + if (GetOpenFileName(&ofn)) { + HANDLE hFile; + DWORD filesize; + + if ((hFile = CreateFile(filename, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)) == INVALID_HANDLE_VALUE || + (filesize = GetFileSize(hFile, NULL)) == INVALID_FILE_SIZE) { + MessageBox(hDlg, "Could not get file size", "Error", 0); + }else{ + SetDlgItemInt(hDlg, IDC_BITRATE_SSIZE, filesize / 1024, FALSE); + CloseHandle(hFile); + } + } + } + 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 (*.pass)\0*.pass\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); + } + } + break; + + 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) == CBN_EDITCHANGE || HIWORD(wParam)==CBN_SELCHANGE) && + (LOWORD(wParam)==IDC_BITRATE_TSIZE || + LOWORD(wParam)==IDC_BITRATE_ARATE )) { + adv_mode(hDlg, psi->idd, psi->config); + }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 || + LOWORD(wParam) == IDC_BITRATE_CFORMAT || + LOWORD(wParam) == IDC_BITRATE_AFORMAT || + LOWORD(wParam) == IDC_BITRATE_FPS)) { + 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 if (HIWORD(wParam) == EN_UPDATE && + (LOWORD(wParam)==IDC_BITRATE_SSIZE || + LOWORD(wParam)==IDC_BITRATE_HOURS || + LOWORD(wParam)==IDC_BITRATE_MINUTES || + LOWORD(wParam)==IDC_BITRATE_SECONDS || + LOWORD(wParam)==IDC_BITRATE_ASIZE)) { + adv_mode(hDlg, psi->idd, psi->config); + } 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 */ - adv_download(hDlg, psi->idd, 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 */ + 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; @@ -1079,8 +1513,12 @@ -/* load advanced options property sheet */ -void adv_dialog(HWND hParent, CONFIG * config, const int * dlgs, int size) +/* load advanced options property sheet + returns true, if the user accepted the changes + or fasle if changes were canceled. + + */ +static BOOL adv_dialog(HWND hParent, CONFIG * config, const int * dlgs, int size) { PROPSHEETINFO psi[6]; PROPSHEETPAGE psp[6]; @@ -1117,9 +1555,9 @@ PropertySheet(&psh); if (temp.save) - { memcpy(config, &temp, sizeof(CONFIG)); - } + + return temp.save; } /* ===================================================================================== */ @@ -1127,130 +1565,149 @@ /* ===================================================================================== */ -/* downloads data from main dialog */ - -void main_download(HWND hDlg, CONFIG * config) +static void main_insert_zone(HWND hDlg, zone_t * s, int i, BOOL insert) { + char tmp[32]; - config->profile = SendDlgItemMessage(hDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0); - - switch(config->mode) - { - default : - case RC_MODE_CBR : - config->rc_bitrate = config_get_uint(hDlg, IDC_VALUE, config->rc_bitrate) * CONFIG_KBPS; - break; + wsprintf(tmp,"%i",s->frame); - /* case RC_MODE_VBR_QUAL : - config->quality = config_get_uint(hDlg, IDC_VALUE, config->quality); - break; */ + if (insert) { + LVITEM lvi; - case RC_MODE_FIXED : - config->quant = config_get_uint(hDlg, IDC_VALUE, config->quant); - break; + 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); + } - case RC_MODE_2PASS2_INT : - config->desired_size = config_get_uint(hDlg, IDC_VALUE, config->desired_size); - break; + 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); - config->mode = SendDlgItemMessage(hDlg, IDC_MODE, CB_GETCURSEL, 0, 0); -} + tmp[0] = '\0'; + if (s->type==XVID_TYPE_IVOP) + strcat(tmp, "K "); + if (s->greyscale) + strcat(tmp, "G "); -/* updates the edit box */ + if (s->chroma_opt) + strcat(tmp, "C "); -void main_value(HWND hDlg, CONFIG* config) + ListView_SetItemText(hDlg, i, 2, tmp); +} + + +static void main_mode(HWND hDlg, CONFIG * config) { - char* text; - int value; - int enabled = TRUE; + 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; + const int target_en_slider = rc_mode==RC_MODE_1PASS || + (rc_mode==RC_MODE_2PASS2 && config->use_2pass_bitrate); + + char buf[16]; + int max; - switch (config->mode) - { - default : - enabled = FALSE; + g_use_bitrate = config->use_2pass_bitrate; - case RC_MODE_CBR : - text = "Bitrate (Kbps):"; - value = config->rc_bitrate / CONFIG_KBPS; - break; + if (g_use_bitrate) { + SetDlgItemText(hDlg, IDC_BITRATE_S, "Target bitrate (kbps):"); - /* case DLG_MODE_VBR_QUAL : - text = "Quality:"; - value = config->quality; - break; */ + wsprintf(buf, "%i kbps", DEFAULT_MIN_KBPS); + SetDlgItemText(hDlg, IDC_BITRATE_MIN, buf); - case RC_MODE_FIXED : - text = "Quantizer:"; - value = config->quant; - break; + max = profiles[profile].max_bitrate; + if (max == 0) max = DEFAULT_MAX_KBPS; + wsprintf(buf, "%i kbps", max); + SetDlgItemText(hDlg, IDC_BITRATE_MAX, buf); - case RC_MODE_2PASS2_INT : - text = "Desired size (Kbtyes):"; - value = config->desired_size; - break; - } + 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) ); - SetDlgItemText(hDlg, IDC_VALUE_STATIC, text); - SetDlgItemInt(hDlg, IDC_VALUE, value, FALSE); + } else if (rc_mode==RC_MODE_2PASS2) { + SetDlgItemText(hDlg, IDC_BITRATE_S, "Target size (kbytes):"); + } else if (rc_mode==RC_MODE_1PASS) { + SetDlgItemText(hDlg, IDC_BITRATE_S, "Target quantizer:"); + SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(100, 3100)); + SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE, + get_dlgitem_float(hDlg, IDC_BITRATE, DEFAULT_QUANT )); + SetDlgItemText(hDlg, IDC_BITRATE_MIN, "1 (maximum quality)"); + SetDlgItemText(hDlg, IDC_BITRATE_MAX, "(smallest file) 31"); - EnableWindow(GetDlgItem(hDlg, IDC_VALUE_STATIC), enabled); - EnableWindow(GetDlgItem(hDlg, IDC_VALUE), enabled); + } - if (config->mode == RC_MODE_CBR || config->mode == RC_MODE_2PASS1 || - config->mode == RC_MODE_2PASS2_INT || config->mode == RC_MODE_2PASS2_EXT) { - EnableWindow(GetDlgItem(hDlg, IDC_MODE_ADV), TRUE); - }else{ - EnableWindow(GetDlgItem(hDlg, IDC_MODE_ADV), FALSE); - } -} + EnableDlgWindow(hDlg, IDC_BITRATE_S, target_en); + EnableDlgWindow(hDlg, IDC_BITRATE, target_en); + EnableDlgWindow(hDlg, IDC_BITRATE_MIN, target_en_slider); + EnableDlgWindow(hDlg, IDC_BITRATE_MAX, target_en_slider); + EnableDlgWindow(hDlg, IDC_SLIDER, target_en_slider); +} -/* updates the slider */ -void main_slider(HWND hDlg, CONFIG * config) +static void main_upload(HWND hDlg, CONFIG * config) { - char* text; - long range; - int pos; - int enabled = TRUE; - switch (config->mode) - { - default : - enabled = FALSE; + SendDlgItemMessage(hDlg, IDC_PROFILE, CB_SETCURSEL, config->profile, 0); + SendDlgItemMessage(hDlg, IDC_MODE, CB_SETCURSEL, config->mode, 0); - case RC_MODE_CBR : - text = "Bitrate (Kbps):"; - range = MAKELONG(0,10000); - pos = config->rc_bitrate / CONFIG_KBPS; - break; - - /* case RC_MODE_VBR_QUAL : - text = "Quality:"; - range = MAKELONG(0,100); - pos = config->quality; - break; */ + g_use_bitrate = config->use_2pass_bitrate; - case RC_MODE_FIXED : - text = "Quantizer:"; - range = MAKELONG(1,31); - pos = config->quant; - break; + if (g_use_bitrate) { + SetDlgItemInt(hDlg, IDC_BITRATE, config->bitrate, FALSE); + } else if (config->mode == RC_MODE_2PASS2) { + SetDlgItemInt(hDlg, IDC_BITRATE, config->desired_size, FALSE); + } else if (config->mode == RC_MODE_1PASS) { + set_dlgitem_float(hDlg, IDC_BITRATE, config->desired_quant); } - SetDlgItemText(hDlg, IDC_SLIDER_STATIC, text); - SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETRANGE, TRUE, range); - SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE, pos); + zones_update(hDlg, config); +} + + +/* downloads data from main dialog */ +static 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); - EnableWindow(GetDlgItem(hDlg, IDC_SLIDER_STATIC), enabled); - EnableWindow(GetDlgItem(hDlg, IDC_SLIDER), enabled); + if (g_use_bitrate) { + config->bitrate = config_get_uint(hDlg, IDC_BITRATE, config->bitrate); + } else if (config->mode == RC_MODE_2PASS2) { + config->desired_size = config_get_uint(hDlg, IDC_BITRATE, config->desired_size); + } else if (config->mode == RC_MODE_1PASS) { + config->desired_quant = get_dlgitem_float(hDlg, IDC_BITRATE, config->desired_quant); + } } /* main dialog proc */ +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 bitrate_dlgs[] = { IDD_BITRATE }; +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}; + + BOOL CALLBACK main_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { CONFIG* config = (CONFIG*)GetWindowLong(hDlg, GWL_USERDATA); @@ -1260,22 +1717,17 @@ { case WM_INITDIALOG : SetWindowLong(hDlg, GWL_USERDATA, lParam); - config = (CONFIG*)lParam; for (i=0; iprofile, 0); - 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"); - - SendDlgItemMessage(hDlg, IDC_MODE, CB_SETCURSEL, config->mode, 0); + 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(); @@ -1290,122 +1742,249 @@ EnumChildWindows(hDlg, enum_tooltips, 0); } - main_slider(hDlg, config); - main_value(hDlg, config); - break; + SetClassLong(GetDlgItem(hDlg, IDC_BITRATE_S), GCL_HCURSOR, (LONG)LoadCursor(NULL, IDC_HAND)); - 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; + 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); } - break; - case WM_COMMAND : - if (HIWORD(wParam) == LBN_SELCHANGE && (LOWORD(wParam) == IDC_PROFILE || LOWORD(wParam) == IDC_MODE)) - { - main_download(hDlg, config); - main_slider(hDlg, config); - main_value(hDlg, config); - } - else if (LOWORD(wParam) == IDC_PROFILE_ADV && HIWORD(wParam) == BN_CLICKED) /* profile dlg */ { - static const int dlgs[] = { IDD_PROFILE }; + typedef struct { + char * name; + int value; + } char_int_t; - adv_dialog(hDlg, config, dlgs, sizeof(dlgs)/sizeof(int)); - if (config->save) - { - config_reg_set(config); + 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; iprofile, 0); } - else if (LOWORD(wParam) == IDC_MODE_ADV && HIWORD(wParam) == BN_CLICKED) /* rate control dialog */ + + /* 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 : { - if (config->mode == RC_MODE_CBR) { - static const int dlgs[] = { IDD_RC_CBR }; - adv_dialog(hDlg, config, dlgs, sizeof(dlgs)/sizeof(int)); - }else if (config->mode == RC_MODE_2PASS1) { - static const int dlgs[] = { IDD_RC_2PASS1 }; - adv_dialog(hDlg, config, dlgs, sizeof(dlgs)/sizeof(int)); - }else if (config->mode == RC_MODE_2PASS2_INT || config->mode == RC_MODE_2PASS2_EXT) { - static const int dlgs[] = { IDD_RC_2PASS2, IDD_RC_2PASS2_ALT}; - adv_dialog(hDlg, config, dlgs, sizeof(dlgs)/sizeof(int)); + NMHDR * n = (NMHDR*)lParam; + + 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 (config->save) - { - config_reg_set(config); + + if (n->code == NM_RCLICK) { + OutputDebugString("Right click"); } + break; } - else if (LOWORD(wParam) == IDC_ADVANCED && HIWORD(wParam) == BN_CLICKED) - { - static const int dlgs[] = { IDD_MOTION, IDD_TOOLS, IDD_QUANT, IDD_DEBUG}; - adv_dialog(hDlg, config, dlgs, sizeof(dlgs)/sizeof(int)); - if (config->save) + case WM_COMMAND : + if (HIWORD(wParam) == BN_CLICKED) { + + 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; + + 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; + + 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; + + case IDC_BITRATE_ADV : + main_download(hDlg, config); + adv_dialog(hDlg, config, bitrate_dlgs, sizeof(bitrate_dlgs)/sizeof(int)); + main_mode(hDlg, config); + main_upload(hDlg, config); + 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 IDC_ADD : { - config_reg_set(config); + int i, sel, new_frame; + + if (config->num_zones >= MAX_ZONES) { + MessageBox(hDlg, "Exceeded maximum number of zones.\nIncrease config.h:MAX_ZONES and rebuild.", "Warning", 0); + break; + } + + sel = ListView_GetNextItem(GetDlgItem(hDlg, IDC_ZONES), -1, LVNI_SELECTED); + + 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; + } + + 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 if (LOWORD(wParam) == IDC_DECODER && HIWORD(wParam) == BN_CLICKED) - { - static const int dlgs[] = { IDD_POSTPROC }; - adv_dialog(hDlg, config, dlgs, sizeof(dlgs)/sizeof(int)); - if (config->save) + case IDC_REMOVE : { - config_reg_set(config); + int i, sel; + sel = ListView_GetNextItem(GetDlgItem(hDlg, IDC_ZONES), -1, LVNI_SELECTED); + + 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; } - } - else if (LOWORD(wParam) == IDC_DEFAULTS && HIWORD(wParam) == BN_CLICKED) - { - config_reg_default(config); - SendDlgItemMessage(hDlg, IDC_MODE, CB_SETCURSEL, config->mode, 0); + 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; - 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; + case IDC_ADVANCED : + main_download(hDlg, config); + adv_dialog(hDlg, config, adv_dlgs, sizeof(adv_dlgs)/sizeof(int)); + break; - max = (config->mode == RC_MODE_CBR) ? 10000 : - /*((config->mode == DLG_MODE_VBR_QUAL) ? 100 :*/ - ((config->mode == RC_MODE_FIXED) ? 31 : 1<<30) /*)*/; + case IDC_DEFAULTS : + config_reg_default(config); + main_mode(hDlg, config); + main_upload(hDlg, config); + break; - if (value < 1) - { - value = 1; + case IDOK : + main_download(hDlg, config); + config->save = TRUE; + EndDialog(hDlg, IDOK); + break; + + case IDCANCEL : + config->save = FALSE; + EndDialog(hDlg, IDCANCEL); + break; } - if (value > max) - { - value = max; - SetDlgItemInt(hDlg, IDC_VALUE, value, FALSE); + } else if (HIWORD(wParam) == LBN_SELCHANGE && + (LOWORD(wParam)==IDC_PROFILE || LOWORD(wParam)==IDC_MODE)) { + + config->mode = SendDlgItemMessage(hDlg, IDC_MODE, CB_GETCURSEL, 0, 0); + config->profile = SendDlgItemMessage(hDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0); + + if (!g_use_bitrate) { + if (config->mode == RC_MODE_1PASS) + set_dlgitem_float(hDlg, IDC_BITRATE, config->desired_quant); + else if (config->mode == RC_MODE_2PASS2) + SetDlgItemInt(hDlg, IDC_BITRATE, config->desired_size, FALSE); } - if (config->mode != RC_MODE_2PASS2_INT) - { - SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE, value); + 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 if (config->mode == RC_MODE_1PASS) { + SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE, + get_dlgitem_float(hDlg, IDC_BITRATE, DEFAULT_QUANT) ); } - } - 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); + + }else { + return 0; } break; + case WM_HSCROLL : + if((HWND)lParam == GetDlgItem(hDlg, IDC_SLIDER)) { + if (g_use_bitrate) + SetDlgItemInt(hDlg, IDC_BITRATE, SendMessage((HWND)lParam, TBM_GETPOS, 0, 0), FALSE); + else + set_dlgitem_float(hDlg, IDC_BITRATE, SendMessage((HWND)lParam, TBM_GETPOS, 0, 0)); + + main_download(hDlg, config); + break; + } + return 0; + default : return 0; } @@ -1429,30 +2008,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); } } @@ -1461,18 +2050,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); } @@ -1488,3 +2076,50 @@ return 1; } + + +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); +}