[cvs] / xvidcore / vfw / src / config.c Repository:
ViewVC logotype

Diff of /xvidcore/vfw/src/config.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.2.1, Sat Feb 22 08:24:01 2003 UTC revision 1.5, Sun Apr 18 07:55:11 2004 UTC
# Line 57  Line 57 
57    
58  #include <windows.h>  #include <windows.h>
59  #include <commctrl.h>  #include <commctrl.h>
60  #include <shlobj.h>  #include <stdio.h>  /* sprintf */
61  #include <prsht.h>  #include <xvid.h>       /* XviD API */
62    
63  #include <xvid.h>       // XviD API  #include "debug.h"
   
 #include "codec.h"  
64  #include "config.h"  #include "config.h"
65  #include "resource.h"  #include "resource.h"
66    
67    
68    #define CONSTRAINVAL(X,Y,Z) if((X)<(Y)) X=Y; if((X)>(Z)) X=Z;
69    #define IsDlgChecked(hwnd,idc)  (IsDlgButtonChecked(hwnd,idc) == BST_CHECKED)
70    #define CheckDlg(hwnd,idc,value) CheckDlgButton(hwnd,idc, value?BST_CHECKED:BST_UNCHECKED)
71    #define EnableDlgWindow(hwnd,idc,state) EnableWindow(GetDlgItem(hwnd,idc),state)
72    
73    static void zones_update(HWND hDlg, CONFIG * config);
74    
75    HINSTANCE g_hInst;
76    HWND g_hTooltip;
77    
78    static int g_use_bitrate = 1;
79    
80    
81    int pp_brightness, pp_dy, pp_duv, pp_fe, pp_dry, pp_druv; /* decoder options */
82    
83    /* enumerates child windows, assigns tooltips */
84    BOOL CALLBACK enum_tooltips(HWND hWnd, LPARAM lParam)
85    {
86            char help[500];
87    
88            if (LoadString(g_hInst, GetDlgCtrlID(hWnd), help, 500))
89            {
90                    TOOLINFO ti;
91                    ti.cbSize = sizeof(TOOLINFO);
92                    ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
93                    ti.hwnd = GetParent(hWnd);
94                    ti.uId  = (LPARAM)hWnd;
95                    ti.lpszText = help;
96                    SendMessage(g_hTooltip, TTM_ADDTOOL, 0, (LPARAM)&ti);
97            }
98    
99            return TRUE;
100    }
101    
102    
103    /* ===================================================================================== */
104    /* MPEG-4 PROFILES/LEVELS ============================================================== */
105    /* ===================================================================================== */
106    
107    
108    
109    /* default vbv_occupancy is (64/170)*vbv_buffer_size */
110    
111    const profile_t profiles[] =
112    {
113    /*      name                             p@l,   w       h  fps  obj  Tvmv  vmv  vcv   ac%        vbv      pkt   kbps  flags */
114            { "Simple @ L0",           0x08,  176, 144, 15,  1,  198,   99,   1485, 100,  10*16368,  2048,   64, 0 },
115            /* simple@l0: max f_code=1, intra_dc_vlc_threshold=0 */
116            /* if ac preidition is used, adaptive quantization must not be used */
117            /* <=qcif must be used */
118            { "Simple @ L1",           0x01,  176, 144, 15,  4,  198,   99,   1485, 100,  10*16368,  2048,   64, PROFILE_ADAPTQUANT },
119            { "Simple @ L2",           0x02,  352, 288, 15,  4,  792,  396,   5940, 100,  40*16368,  4096,  128, PROFILE_ADAPTQUANT },
120            { "Simple @ L3",           0x03,  352, 288, 15,  4,  792,  396,  11880, 100,  40*16368,  8192,  384, PROFILE_ADAPTQUANT },
121    
122            { "ARTS @ L1",           0x91,  176, 144, 15,  4,  198,   99,   1485, 100,  10*16368,  8192,   64, PROFILE_ARTS },
123            { "ARTS @ L2",           0x92,  352, 288, 15,  4,  792,  396,   5940, 100,  40*16368, 16384,  128, PROFILE_ARTS },
124            { "ARTS @ L3",           0x93,  352, 288, 30,  4,  792,  396,  11880, 100,  40*16368, 16384,  384, PROFILE_ARTS },
125            { "ARTS @ L4",           0x94,  352, 288, 30, 16,  792,  396,  11880, 100,  80*16368, 16384, 2000, PROFILE_ARTS },
126    
127            { "AS @ L0",               0xf0,  176, 144, 30,  1,  297,   99,   2970, 100,  10*16368,  2048,  128, PROFILE_AS },
128            { "AS @ L1",               0xf1,  176, 144, 30,  4,  297,   99,   2970, 100,  10*16368,  2048,  128, PROFILE_AS },
129            { "AS @ L2",               0xf2,  352, 288, 15,  4, 1188,  396,   5940, 100,  40*16368,  4096,  384, PROFILE_AS },
130            { "AS @ L3",               0xf3,  352, 288, 30,  4, 1188,  396,  11880, 100,  40*16368,  4096,  768, PROFILE_AS },
131     /*  ISMA Profile 1, (ASP) @ L3b (CIF, 1.5 Mb/s) CIF(352x288), 30fps, 1.5Mbps max ??? */
132            { "AS @ L4",               0xf4,  352, 576, 30,  4, 2376,  792,  23760,  50,  80*16368,  8192, 3000, PROFILE_AS },
133            { "AS @ L5",               0xf5,  720, 576, 30,  4, 4860, 1620,  48600,  25, 112*16368, 16384, 8000, PROFILE_AS },
134    
135    #ifdef DXN_PROFILES
136            { "DXN Handheld",          0x00,  176, 144, 15, -1,  198,   99,   1485, 100,  16*16368, -1,  128, PROFILE_ADAPTQUANT },
137            { "DXN Portable NTSC", 0x00,  352, 240, 30, -1,  990,  330,   9900, 100,  64*16368,     -1,  768, PROFILE_ADAPTQUANT|PROFILE_BVOP },
138            { "DXN Portable PAL",  0x00,  352, 288, 25, -1, 1188,  396,   9900, 100,  64*16368,     -1,  768, PROFILE_ADAPTQUANT|PROFILE_BVOP },
139            { "DXN HT NTSC",           0x00,  720, 480, 30, -1, 4050, 1350,  40500, 100, 192*16368, -1, 4000, PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_INTERLACE },
140            { "DXN HT PAL",         0x00,  720, 576, 25, -1, 4860, 1620,  40500, 100, 192*16368,    -1, 4000, PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_INTERLACE },
141            { "DXN HDTV",             0x00, 1280, 720, 30, -1,10800, 3600, 108000, 100, 384*16368,  -1, 8000, PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_INTERLACE },
142    #endif
143    
144            { "(unrestricted)",     0x00,   0,   0,  0,  0, 0,      0,        0, 100,   0*16368,     0,     0, 0xffffffff },
145    };
146    
 /* registry info structs */  
147    
148    typedef struct {
149            char * name;
150            float value;
151    } named_float_t;
152    
153    static const named_float_t video_fps_list[] = {
154            {  "15.0",                              15.0F   },
155            {  "23.976 (FILM)",             23.976F },
156            {  "25.0 (PAL)",                25.0F   },
157            {  "29.97 (NTSC)",              29.970F },
158            {  "30.0",                              30.0F   },
159            {  "50.0 (HD PAL)",             50.0F   },
160            {  "59.94 (HD NTSC)",   59.940F },
161            {  "60.0",                              60.0F   },
162    };
163    
164    
165    typedef struct {
166            char * name;
167            int avi_interval;               /* audio overhead intervals (milliseconds) */
168            float mkv_multiplier;   /* mkv multiplier */
169    } named_int_t;
170    
171    
172    #define NO_AUDIO        5
173    static const named_int_t audio_type_list[] = {
174            {       "MP3-CBR",              1000,   48000/1152/6                                    },
175            {       "MP3-VBR",                24,   48000/1152/6                                    },
176            {       "OGG",     /*?*/1000,   48000*(0.7F/1024 + 0.3F/180)    },
177            {       "AC3",                    64,   48000/1536/6                                    },
178            {       "DTS",                    21,   /*?*/48000/1152/6                               },
179            {       "(None)",                  0,   0                                                               },
180    };
181    
182    
183    /* ===================================================================================== */
184    /* REGISTRY ============================================================================ */
185    /* ===================================================================================== */
186    
187    /* registry info structs */
188  CONFIG reg;  CONFIG reg;
189    
190  REG_INT const reg_ints[] = {  static const REG_INT reg_ints[] = {
191          {"mode",                                        &reg.mode,                                              DLG_MODE_CBR},          {"mode",                                        &reg.mode,                                              RC_MODE_1PASS},
192          {"quality",                                     &reg.quality,                                   85},          {"bitrate",                                     &reg.bitrate,                                   700},
193          {"quant",                                       &reg.quant,                                             5},          {"desired_size",                        &reg.desired_size,                              570000},
194          {"rc_bitrate",                          &reg.rc_bitrate,                                900000},          {"use_2pass_bitrate",           &reg.use_2pass_bitrate,                 0},
195          {"rc_reaction_delay_factor",&reg.rc_reaction_delay_factor,      16},          {"desired_quant",                       &reg.desired_quant,                             DEFAULT_QUANT}, /* 100-base float */
         {"rc_averaging_period",         &reg.rc_averaging_period,               100},  
         {"rc_buffer",                           &reg.rc_buffer,                                 100},  
196    
197          {"motion_search",                       &reg.motion_search,                             6},          /* profile */
198          {"quant_type",                          &reg.quant_type,                                0},          {"quant_type",                          &reg.quant_type,                                0},
         {"fourcc_used",                         &reg.fourcc_used,                               0},  
         {"vhq_mode",                            &reg.vhq_mode,                                  0},  
         {"max_key_interval",            &reg.max_key_interval,                  300},  
         {"min_key_interval",            &reg.min_key_interval,                  1},  
199          {"lum_masking",                         &reg.lum_masking,                               0},          {"lum_masking",                         &reg.lum_masking,                               0},
200          {"interlacing",                         &reg.interlacing,                               0},          {"interlacing",                         &reg.interlacing,                               0},
201          {"qpel",                                        &reg.qpel,                                              0},          {"qpel",                                        &reg.qpel,                                              0},
202          {"gmc",                                         &reg.gmc,                                               0},          {"gmc",                                         &reg.gmc,                                               0},
         {"chromame",                            &reg.chromame,                                  0},  
 //added by koepi for gruel's greyscale_mode  
         {"greyscale",                           &reg.greyscale,                                 0},  
 // end of koepi's additions  
         {"max_bframes",                         &reg.max_bframes,                               -1},  
         {"bquant_ratio",                        &reg.bquant_ratio,                              150},  
         {"bquant_offset",                       &reg.bquant_offset,                             100},  
         {"packed",                                      &reg.packed,                                    0},  
         {"dx50bvop",                            &reg.dx50bvop,                                  1},  
         {"debug",                                       &reg.debug,                                             0},  
203          {"reduced_resolution",          &reg.reduced_resolution,                0},          {"reduced_resolution",          &reg.reduced_resolution,                0},
204          {"chroma_opt",                          &reg.chroma_opt,                                0},          {"use_bvop",                            &reg.use_bvop,                                  1},
205          {"frame_drop_ratio",            &reg.frame_drop_ratio,                  0},          {"max_bframes",                         &reg.max_bframes,                               2},
206            {"bquant_ratio",                        &reg.bquant_ratio,                              150},   /* 100-base float */
207            {"bquant_offset",                       &reg.bquant_offset,                             100},   /* 100-base float */
208            {"packed",                                      &reg.packed,                                    1},
209            {"closed_gov",                          &reg.closed_gov,                                1},
210    
211            /* aspect ratio */
212            {"ar_mode",                                     &reg.ar_mode,                                   0},
213            {"aspect_ratio",                        &reg.display_aspect_ratio,              0},
214            {"par_x",                                       &reg.par_x,                                             1},
215            {"par_y",                                       &reg.par_y,                                             1},
216            {"ar_x",                                        &reg.ar_x,                                              4},
217            {"ar_y",                                        &reg.ar_y,                                              3},
218    
219          {"min_iquant",                          &reg.min_iquant,                                2},          /* zones */
220          {"max_iquant",                          &reg.max_iquant,                                31},          {"num_zones",                           &reg.num_zones,                                 1},
         {"min_pquant",                          &reg.min_pquant,                                2},  
         {"max_pquant",                          &reg.max_pquant,                                31},  
221    
222          {"desired_size",                        &reg.desired_size,                              570000},          /* single pass */
223          {"keyframe_boost",                      &reg.keyframe_boost,                    0},          {"rc_reaction_delay_factor",&reg.rc_reaction_delay_factor,      16},
224            {"rc_averaging_period",         &reg.rc_averaging_period,               100},
225            {"rc_buffer",                           &reg.rc_buffer,                                 100},
226    
227            /* 2pass1 */
228          {"discard1pass",                        &reg.discard1pass,                              1},          {"discard1pass",                        &reg.discard1pass,                              1},
229          {"dummy2pass",                          &reg.dummy2pass,                                0},          {"full1pass",                           &reg.full1pass,                                 0},
230  // added by koepi for new two-pass curve treatment  
231          {"kftreshold",                          &reg.kftreshold,                                10},          /* 2pass2 */
232            {"keyframe_boost",                      &reg.keyframe_boost,                    10},
233          {"kfreduction",                         &reg.kfreduction,                               20},          {"kfreduction",                         &reg.kfreduction,                               20},
234  // end of koepi's additions          {"kfthreshold",                         &reg.kfthreshold,                               1},
235          {"curve_compression_high",      &reg.curve_compression_high,    0},          {"curve_compression_high",      &reg.curve_compression_high,    0},
236          {"curve_compression_low",       &reg.curve_compression_low,             0},          {"curve_compression_low",       &reg.curve_compression_low,             0},
237          {"use_alt_curve",                       &reg.use_alt_curve,                             0},          {"overflow_control_strength", &reg.overflow_control_strength, 5},
238          {"alt_curve_use_auto",          &reg.alt_curve_use_auto,                1},          {"twopass_max_overflow_improvement", &reg.twopass_max_overflow_improvement, 5},
239          {"alt_curve_auto_str",          &reg.alt_curve_auto_str,                30},          {"twopass_max_overflow_degradation", &reg.twopass_max_overflow_degradation, 5},
240          {"alt_curve_use_auto_bonus_bias",       &reg.alt_curve_use_auto_bonus_bias,     1},  
241          {"alt_curve_bonus_bias",        &reg.alt_curve_bonus_bias,              50},          /* bitrate calculator */
242          {"alt_curve_type",                      &reg.alt_curve_type,                    1},          {"container_type",                      &reg.container_type,                    1},
243          {"alt_curve_high_dist",         &reg.alt_curve_high_dist,               500},          {"target_size",                         &reg.target_size,                               650 * 1024},
244          {"alt_curve_low_dist",          &reg.alt_curve_low_dist,                90},          {"subtitle_size",                       &reg.subtitle_size,                             0},
245          {"alt_curve_min_rel_qual",      &reg.alt_curve_min_rel_qual,    50},          {"hours",                               &reg.hours,                                             1},
246          {"bitrate_payback_delay",       &reg.bitrate_payback_delay,             250},          {"minutes",                             &reg.minutes,                                   30},
247          {"bitrate_payback_method",      &reg.bitrate_payback_method,    0},          {"seconds",                             &reg.seconds,                                   0},
248          {"twopass_max_bitrate",         &reg.twopass_max_bitrate,               10000 * CONFIG_KBPS},          {"fps",                                 &reg.fps,                                               2},
249          {"twopass_max_overflow_improvement", &reg.twopass_max_overflow_improvement, 60},          {"audio_mode",                          &reg.audio_mode,                                0},
250          {"twopass_max_overflow_degradation", &reg.twopass_max_overflow_degradation, 60},          {"audio_type",                          &reg.audio_type,                                0},
251          {"hinted_me",                           &reg.hinted_me,                                 0},          {"audio_rate",                          &reg.audio_rate,                                128},
252            {"audio_size",                          &reg.audio_size,                                0},
253          {"credits_start",                       &reg.credits_start,                             0},  
254          {"credits_start_begin",         &reg.credits_start_begin,               0},          /* motion */
255          {"credits_start_end",           &reg.credits_start_end,                 0},          {"motion_search",                       &reg.motion_search,                             6},
256          {"credits_end",                         &reg.credits_end,                               0},          {"vhq_mode",                            &reg.vhq_mode,                                  1},
257          {"credits_end_begin",           &reg.credits_end_begin,                 0},          {"chromame",                            &reg.chromame,                                  1},
258          {"credits_end_end",                     &reg.credits_end_end,                   0},          {"cartoon_mode",                        &reg.cartoon_mode,                              0},
259            {"turbo",                                       &reg.turbo,                                             0},
260  // added by koepi for greyscale credits          {"max_key_interval",            &reg.max_key_interval,                  300},
261          {"credits_greyscale",           &reg.credits_greyscale,                 0},          {"frame_drop_ratio",            &reg.frame_drop_ratio,                  0},
262  // end of koepi's addition  
263          {"credits_mode",                        &reg.credits_mode,                              0},          /* quant */
264          {"credits_rate",                        &reg.credits_rate,                              20},          {"min_iquant",                          &reg.min_iquant,                                1},
265          {"credits_quant_i",                     &reg.credits_quant_i,                   20},          {"max_iquant",                          &reg.max_iquant,                                31},
266          {"credits_quant_p",                     &reg.credits_quant_p,                   20},          {"min_pquant",                          &reg.min_pquant,                                1},
267          {"credits_start_size",          &reg.credits_start_size,                10000},          {"max_pquant",                          &reg.max_pquant,                                31},
268          {"credits_end_size",            &reg.credits_end_size,                  10000},          {"min_bquant",                          &reg.min_bquant,                                1},
269            {"max_bquant",                          &reg.max_bquant,                                31},
270          /* decoder */          {"trellis_quant",                       &reg.trellis_quant,                             0},
271          {"deblock_y",                           &reg.deblock_y,                                 0},  
272          {"deblock_uv",                          &reg.deblock_uv,                                0}          /* debug */
273            {"fourcc_used",                         &reg.fourcc_used,                               0},
274            {"debug",                                       &reg.debug,                                             0x0},
275            {"vop_debug",                           &reg.vop_debug,                                 0},
276            {"display_status",                      &reg.display_status,                    1},
277    
278            /* decoder, shared with dshow */
279            {"Brightness",                          &pp_brightness,                                 0},
280            {"Deblock_Y",                           &pp_dy,                                                 0},
281            {"Deblock_UV",                          &pp_duv,                                                0},
282            {"Dering_Y",                            &pp_dry,                                                0},
283            {"Dering_UV",                           &pp_druv,                                               0},
284            {"FilmEffect",                          &pp_fe,                                                 0},
285    
286    };
287    
288    static const REG_STR reg_strs[] = {
289            {"profile",                                     reg.profile_name,                               "AS @ L5"},
290            {"stats",                                       reg.stats,                                              CONFIG_2PASS_FILE},
291    };
292    
293    
294    zone_t stmp;
295    static const REG_INT reg_zone[] = {
296            {"zone%i_frame",                        &stmp.frame,                                    0},
297            {"zone%i_mode",                         &stmp.mode,                                             RC_ZONE_WEIGHT},
298            {"zone%i_weight",                       &stmp.weight,                                   100},     /* 100-base float */
299            {"zone%i_quant",                        &stmp.quant,                                    500},     /* 100-base float */
300            {"zone%i_type",                         &stmp.type,                                             XVID_TYPE_AUTO},
301            {"zone%i_greyscale",            &stmp.greyscale,                                0},
302            {"zone%i_chroma_opt",           &stmp.chroma_opt,                               0},
303            {"zone%i_bvop_threshold",   &stmp.bvop_threshold,                       0},
304    };
305    
306    static const BYTE default_qmatrix_intra[] = {
307            8, 17,18,19,21,23,25,27,
308            17,18,19,21,23,25,27,28,
309            20,21,22,23,24,26,28,30,
310            21,22,23,24,26,28,30,32,
311            22,23,24,26,28,30,32,35,
312            23,24,26,28,30,32,35,38,
313            25,26,28,30,32,35,38,41,
314            27,28,30,32,35,38,41,45
315  };  };
316    
317  REG_STR const reg_strs[] = {  static const BYTE default_qmatrix_inter[] = {
318          {"hintfile",                            reg.hintfile,                                   CONFIG_HINTFILE},          16,17,18,19,20,21,22,23,
319          {"stats1",                                      reg.stats1,                                             CONFIG_2PASS_1_FILE},          17,18,19,20,21,22,23,24,
320          {"stats2",                                      reg.stats2,                                             CONFIG_2PASS_2_FILE}          18,19,20,21,22,23,24,25,
321  //      {"build",                                       reg.build,                                              XVID_BUILD}          19,20,21,22,23,24,26,27,
322            20,21,22,23,25,26,27,28,
323            21,22,23,24,26,27,28,30,
324            22,23,24,26,27,28,30,31,
325            23,24,25,27,28,30,31,33
326  };  };
327    
328  /* get config settings from registry */  
329    
330  #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 REG_GET_B(X, Y, Z) size=sizeof((Z));if(RegQueryValueEx(hKey, X, 0, 0, Y, &size) != ERROR_SUCCESS) {memcpy(Y, Z, sizeof((Z)));}
331    
332    #define XVID_DLL_NAME "xvidcore.dll"
333    
334  void config_reg_get(CONFIG * config)  void config_reg_get(CONFIG * config)
335  {  {
336            char tmp[32];
337          HKEY hKey;          HKEY hKey;
338          DWORD size;          DWORD size;
339      int i;          int i,j;
340          xvid_gbl_info_t info;          xvid_gbl_info_t info;
341            HINSTANCE m_hdll;
342    
343          memset(&info, 0, sizeof(info));          memset(&info, 0, sizeof(info));
344          info.version = XVID_VERSION;          info.version = XVID_VERSION;
345          xvid_global(0, XVID_GBL_INFO, &info, NULL);  
346            m_hdll = LoadLibrary(XVID_DLL_NAME);
347            if (m_hdll != NULL) {
348    
349                    ((int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global"))
350                            (0, XVID_GBL_INFO, &info, NULL);
351    
352                    FreeLibrary(m_hdll);
353            }
354    
355          reg.cpu = info.cpu_flags;          reg.cpu = info.cpu_flags;
356          reg.num_threads = info.num_threads;          reg.num_threads = info.num_threads;
357    
358          RegOpenKeyEx(XVID_REG_KEY, XVID_REG_PARENT "\\" XVID_REG_CHILD, 0, KEY_READ, &hKey);          RegOpenKeyEx(XVID_REG_KEY, XVID_REG_PARENT "\\" XVID_REG_CHILD, 0, KEY_READ, &hKey);
359    
360          for (i=0 ; i<sizeof(reg_ints)/sizeof(REG_INT) ; ++i)          /* read integer values */
361          {          for (i=0 ; i<sizeof(reg_ints)/sizeof(REG_INT); i++) {
362                  size = sizeof(int);                  size = sizeof(int);
363                    if (RegQueryValueEx(hKey, reg_ints[i].reg_value, 0, 0, (LPBYTE)reg_ints[i].config_int, &size) != ERROR_SUCCESS) {
                 if (RegQueryValueEx(hKey, reg_ints[i].reg_value, 0, 0, (LPBYTE)reg_ints[i].config_int, &size) != ERROR_SUCCESS)  
                 {  
364                          *reg_ints[i].config_int = reg_ints[i].def;                          *reg_ints[i].config_int = reg_ints[i].def;
365                  }                  }
366          }          }
367    
368          for (i=0 ; i<sizeof(reg_strs)/sizeof(REG_STR) ; ++i)          /* read string values */
369          {          for (i=0 ; i<sizeof(reg_strs)/sizeof(REG_STR); i++) {
370                  size = MAX_PATH;                  size = MAX_PATH;
371                    if (RegQueryValueEx(hKey, reg_strs[i].reg_value, 0, 0, (LPBYTE)reg_strs[i].config_str, &size) != ERROR_SUCCESS) {
                 if (RegQueryValueEx(hKey, reg_strs[i].reg_value, 0, 0, (LPBYTE)reg_strs[i].config_str, &size) != ERROR_SUCCESS)  
                 {  
372                          memcpy(reg_strs[i].config_str, reg_strs[i].def, MAX_PATH);                          memcpy(reg_strs[i].config_str, reg_strs[i].def, MAX_PATH);
373                  }                  }
374          }          }
375    
376          {          reg.profile = 0;
377                  BYTE default_qmatrix_intra[] = {          for (i=0; i<sizeof(profiles)/sizeof(profile_t); i++) {
378                          8, 17,18,19,21,23,25,27,                  if (lstrcmpi(profiles[i].name, reg.profile_name) == 0) {
379                          17,18,19,21,23,25,27,28,                          reg.profile = i;
380                          20,21,22,23,24,26,28,30,                  }
381                          21,22,23,24,26,28,30,32,          }
382                          22,23,24,26,28,30,32,35,  
383                          23,24,26,28,30,32,35,38,          memcpy(config, &reg, sizeof(CONFIG));
                         25,26,28,30,32,35,38,41,  
                         27,28,30,32,35,38,41,45  
                 };  
384    
                 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  
                 };  
385    
386                  REG_GET_B("qmatrix_intra", reg.qmatrix_intra, default_qmatrix_intra);          /* read quant matrices */
387                  REG_GET_B("qmatrix_inter", reg.qmatrix_inter, default_qmatrix_inter);          REG_GET_B("qmatrix_intra", config->qmatrix_intra, default_qmatrix_intra);
388            REG_GET_B("qmatrix_inter", config->qmatrix_inter, default_qmatrix_inter);
389    
390    
391            /* read zones */
392            if (config->num_zones>MAX_ZONES) {
393                    config->num_zones=MAX_ZONES;
394            }else if (config->num_zones<=0) {
395                    config->num_zones = 1;
396          }          }
397    
398          memcpy(config, &reg, sizeof(CONFIG));          for (i=0; i<config->num_zones; i++) {
399                    for (j=0; j<sizeof(reg_zone)/sizeof(REG_INT); j++)  {
400                            size = sizeof(int);
401    
402                            wsprintf(tmp, reg_zone[j].reg_value, i);
403                            if (RegQueryValueEx(hKey, tmp, 0, 0, (LPBYTE)reg_zone[j].config_int, &size) != ERROR_SUCCESS)
404                                    *reg_zone[j].config_int = reg_zone[j].def;
405                    }
406    
407                    memcpy(&config->zones[i], &stmp, sizeof(zone_t));
408            }
409    
410          RegCloseKey(hKey);          RegCloseKey(hKey);
411  }  }
# Line 243  Line 417 
417    
418  void config_reg_set(CONFIG * config)  void config_reg_set(CONFIG * config)
419  {  {
420            char tmp[64];
421          HKEY hKey;          HKEY hKey;
422          DWORD dispo;          DWORD dispo;
423          int i;          int i,j;
424    
425          if (RegCreateKeyEx(          if (RegCreateKeyEx(
426                          XVID_REG_KEY,                          XVID_REG_KEY,
# Line 258  Line 433 
433                          &hKey,                          &hKey,
434                          &dispo) != ERROR_SUCCESS)                          &dispo) != ERROR_SUCCESS)
435          {          {
436                  DEBUG1("Couldn't create XVID_REG_SUBKEY - ", GetLastError());                  DPRINTF("Couldn't create XVID_REG_SUBKEY - GetLastError=%i", GetLastError());
437                  return;                  return;
438          }          }
439    
440          memcpy(&reg, config, sizeof(CONFIG));          memcpy(&reg, config, sizeof(CONFIG));
441    
442          for (i=0 ; i<sizeof(reg_ints)/sizeof(REG_INT) ; ++i)          /* set integer values */
443          {          for (i=0 ; i<sizeof(reg_ints)/sizeof(REG_INT); i++) {
444                  RegSetValueEx(hKey, reg_ints[i].reg_value, 0, REG_DWORD, (LPBYTE)reg_ints[i].config_int, sizeof(int));                  RegSetValueEx(hKey, reg_ints[i].reg_value, 0, REG_DWORD, (LPBYTE)reg_ints[i].config_int, sizeof(int));
445          }          }
446    
447          for (i=0 ; i<sizeof(reg_strs)/sizeof(REG_STR) ; ++i)          /* set string values */
448          {          strcpy(reg.profile_name, profiles[reg.profile].name);
449            for (i=0 ; i<sizeof(reg_strs)/sizeof(REG_STR); i++) {
450                  RegSetValueEx(hKey, reg_strs[i].reg_value, 0, REG_SZ, reg_strs[i].config_str, lstrlen(reg_strs[i].config_str)+1);                  RegSetValueEx(hKey, reg_strs[i].reg_value, 0, REG_SZ, reg_strs[i].config_str, lstrlen(reg_strs[i].config_str)+1);
451          }          }
452    
453          REG_SET_B("qmatrix_intra", reg.qmatrix_intra);          /* set quant matrices */
454          REG_SET_B("qmatrix_inter", reg.qmatrix_inter);          REG_SET_B("qmatrix_intra", config->qmatrix_intra);
455            REG_SET_B("qmatrix_inter", config->qmatrix_inter);
456    
457            /* set seections */
458            for (i=0; i<config->num_zones; i++) {
459                    memcpy(&stmp, &config->zones[i], sizeof(zone_t));
460                    for (j=0; j<sizeof(reg_zone)/sizeof(REG_INT); j++)  {
461                            wsprintf(tmp, reg_zone[j].reg_value, i);
462                            RegSetValueEx(hKey, tmp, 0, REG_DWORD, (LPBYTE)reg_zone[j].config_int, sizeof(int));
463                    }
464            }
465    
466          RegCloseKey(hKey);          RegCloseKey(hKey);
467  }  }
# Line 283  Line 469 
469    
470  /* clear XviD registry key, load defaults */  /* clear XviD registry key, load defaults */
471    
472  void config_reg_default(CONFIG * config)  static void config_reg_default(CONFIG * config)
473  {  {
474          HKEY hKey;          HKEY hKey;
475    
476          if (RegOpenKeyEx(XVID_REG_KEY, XVID_REG_PARENT, 0, KEY_ALL_ACCESS, &hKey))          if (RegOpenKeyEx(XVID_REG_KEY, XVID_REG_PARENT, 0, KEY_ALL_ACCESS, &hKey)) {
477          {                  DPRINTF("Couldn't open registry key for deletion - GetLastError=%i", GetLastError());
                 DEBUG1("Couldn't open registry key for deletion - ", GetLastError());  
478                  return;                  return;
479          }          }
480    
481          if (RegDeleteKey(hKey, XVID_REG_CHILD))          if (RegDeleteKey(hKey, XVID_REG_CHILD)) {
482          {                  DPRINTF("Couldn't delete registry key - GetLastError=%i", GetLastError());
                 DEBUG1("Couldn't delete registry key - ", GetLastError());  
483                  return;                  return;
484          }          }
485    
# Line 306  Line 490 
490    
491    
492  /* leaves current config value if dialog item is empty */  /* leaves current config value if dialog item is empty */
493    static int config_get_int(HWND hDlg, INT item, int config)
 int config_get_int(HWND hDlg, INT item, int config)  
494  {  {
495          BOOL success = FALSE;          BOOL success = FALSE;
   
496          int tmp = GetDlgItemInt(hDlg, item, &success, TRUE);          int tmp = GetDlgItemInt(hDlg, item, &success, TRUE);
   
497          return (success) ? tmp : config;          return (success) ? tmp : config;
498  }  }
499    
500    
501  int config_get_uint(HWND hDlg, UINT item, int config)  static int config_get_uint(HWND hDlg, UINT item, int config)
502  {  {
503          BOOL success = FALSE;          BOOL success = FALSE;
   
504          int tmp = GetDlgItemInt(hDlg, item, &success, FALSE);          int tmp = GetDlgItemInt(hDlg, item, &success, FALSE);
   
505          return (success) ? tmp : config;          return (success) ? tmp : config;
506  }  }
507    
508    /* get uint from combobox
509  /* downloads data from main dialog */     GetDlgItemInt doesnt work properly for cb list items */
510    #define UINT_BUF_SZ     20
511  void main_download(HWND hDlg, CONFIG * config)  static int config_get_cbuint(HWND hDlg, UINT item, int def)
 {  
         switch(config->mode)  
512          {          {
513          default :          int sel = SendMessage(GetDlgItem(hDlg, item), CB_GETCURSEL, 0, 0);
514          case DLG_MODE_CBR :          char buf[UINT_BUF_SZ];
                 config->rc_bitrate = config_get_uint(hDlg, IDC_VALUE, config->rc_bitrate) * CONFIG_KBPS;  
                 break;  
   
         case DLG_MODE_VBR_QUAL :  
                 config->quality = config_get_uint(hDlg, IDC_VALUE, config->quality);  
                 break;  
515    
516          case DLG_MODE_VBR_QUANT :          if (sel<0) {
517                  config->quant = config_get_uint(hDlg, IDC_VALUE, config->quant);                  return config_get_uint(hDlg, item, def);
                 break;  
   
         case DLG_MODE_2PASS_2_INT :  
                 config->desired_size = config_get_uint(hDlg, IDC_VALUE, config->desired_size);  
                 break;  
518          }          }
519    
520          config->mode = SendDlgItemMessage(hDlg, IDC_MODE, CB_GETCURSEL, 0, 0);          if (SendMessage(GetDlgItem(hDlg, item), CB_GETLBTEXT, sel, (LPARAM)buf) == CB_ERR) {
521                    return def;
522  }  }
523    
524            return atoi(buf);
525    }
526    
 /* updates the edit box */  
527    
528  void main_value(HWND hDlg, CONFIG* config)  /* we use "100 base" floats */
 {  
         char* text;  
         int value;  
         int enabled = TRUE;  
529    
530          switch (config->mode)  #define FLOAT_BUF_SZ    20
531    static int get_dlgitem_float(HWND hDlg, UINT item, int def)
532          {          {
533          default :          char buf[FLOAT_BUF_SZ];
                 enabled = 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;  
534    
535          case DLG_MODE_VBR_QUANT :          if (GetDlgItemText(hDlg, item, buf, FLOAT_BUF_SZ) == 0)
536                  text = "Quantizer:";                  return def;
                 value = config->quant;  
                 break;  
537    
538          case DLG_MODE_2PASS_2_INT :          return (int)(atof(buf)*100);
                 text = "Desired size (Kbtyes):";  
                 value = config->desired_size;  
                 break;  
539          }          }
540    
541          SetDlgItemText(hDlg, IDC_VALUE_STATIC, text);  static void set_dlgitem_float(HWND hDlg, UINT item, int value)
542          SetDlgItemInt(hDlg, IDC_VALUE, value, FALSE);  {
543            char buf[FLOAT_BUF_SZ];
544          EnableWindow(GetDlgItem(hDlg, IDC_VALUE_STATIC), enabled);          sprintf(buf, "%.2f", (float)value/100);
545          EnableWindow(GetDlgItem(hDlg, IDC_VALUE), enabled);          SetDlgItemText(hDlg, item, buf);
546  }  }
547    
548    
549  /* updates the slider */  #define HEX_BUF_SZ  16
550    static unsigned int get_dlgitem_hex(HWND hDlg, UINT item, unsigned int def)
 void main_slider(HWND hDlg, CONFIG * config)  
 {  
         char* text;  
         long range;  
         int pos;  
         int enabled = TRUE;  
   
         switch (config->mode)  
551          {          {
552          default :          char buf[HEX_BUF_SZ];
553                  enabled = FALSE;          unsigned int value;
554    
555          case DLG_MODE_CBR :          if (GetDlgItemText(hDlg, item, buf, HEX_BUF_SZ) == 0)
556                  text = "Bitrate (Kbps):";                  return def;
                 range = MAKELONG(0,10000);  
                 pos = config->rc_bitrate / CONFIG_KBPS;  
                 break;  
   
         case DLG_MODE_VBR_QUAL :  
                 text = "Quality:";  
                 range = MAKELONG(0,100);  
                 pos = config->quality;  
                 break;  
557    
558          case DLG_MODE_VBR_QUANT :          if (sscanf(buf,"0x%x", &value)==1 || sscanf(buf,"%x", &value)==1) {
559                  text = "Quantizer:";                  return value;
                 range = MAKELONG(1,31);  
                 pos = config->quant;  
                 break;  
560          }          }
561    
562          SetDlgItemText(hDlg, IDC_SLIDER_STATIC, text);          return def;
         SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETRANGE, TRUE, range);  
         SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE, pos);  
   
         EnableWindow(GetDlgItem(hDlg, IDC_SLIDER_STATIC), enabled);  
         EnableWindow(GetDlgItem(hDlg, IDC_SLIDER), enabled);  
563  }  }
564    
565    static void set_dlgitem_hex(HWND hDlg, UINT item, int value)
 /* load advanced options property sheet */  
   
 void adv_dialog(HWND hParent, CONFIG * config)  
 {  
         PROPSHEETINFO psi[DLG_COUNT];  
         PROPSHEETPAGE psp[DLG_COUNT];  
         PROPSHEETHEADER psh;  
         CONFIG temp;  
         int i;  
   
         config->save = FALSE;  
         memcpy(&temp, config, sizeof(CONFIG));  
   
         for (i=0 ; i<DLG_COUNT ; ++i)  
566          {          {
567                  psp[i].dwSize = sizeof(PROPSHEETPAGE);          char buf[HEX_BUF_SZ];
568                  psp[i].dwFlags = 0;          wsprintf(buf, "0x%x", value);
569                  psp[i].hInstance = hInst;          SetDlgItemText(hDlg, item, buf);
                 psp[i].pfnDlgProc = adv_proc;  
                 psp[i].lParam = (LPARAM)&psi[i];  
                 psp[i].pfnCallback = NULL;  
   
                 psi[i].page = i;  
                 psi[i].config = &temp;  
570          }          }
571    
572          psp[DLG_GLOBAL].pszTemplate             = MAKEINTRESOURCE(IDD_GLOBAL);  /* ===================================================================================== */
573          psp[DLG_QUANT].pszTemplate              = MAKEINTRESOURCE(IDD_QUANT);  /* QUANT MATRIX DIALOG ================================================================= */
574          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);  
   
         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;  
   
         PropertySheet(&psh);  
575    
576          if (temp.save)  static void quant_upload(HWND hDlg, CONFIG* config)
577          {          {
578                  memcpy(config, &temp, sizeof(CONFIG));          int i;
579    
580            for (i=0 ; i<64; i++) {
581                    SetDlgItemInt(hDlg, IDC_QINTRA00 + i, config->qmatrix_intra[i], FALSE);
582                    SetDlgItemInt(hDlg, IDC_QINTER00 + i, config->qmatrix_inter[i], FALSE);
583          }          }
584  }  }
585    
586    
587  /* enable/disable advanced controls based on encoder mode */  static void quant_download(HWND hDlg, CONFIG* config)
   
 #define CONTROLDLG(X,Y) EnableWindow(GetDlgItem(hDlg, (X)), (Y))  
 #define ISDLGSET(X)     (IsDlgButtonChecked(hDlg, (X)) == BST_CHECKED)  
   
 #define MOD_CBR  
   
 void adv_mode(HWND hDlg, int mode)  
588  {  {
589          // create arrays of controls to be disabled for each mode          int i;
         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,  
         };  
590    
591          const short cbr_disable[] = {          for (i=0; i<64; i++) {
592                  IDC_STATS1, IDC_STATS1_BROWSE, IDC_DISCARD1PASS, IDC_HINTEDME,                  int temp;
                 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  
         };  
593    
594          const short qual_disable[] = {                  temp = config_get_uint(hDlg, i + IDC_QINTRA00, config->qmatrix_intra[i]);
595                  IDC_STATS1, IDC_STATS1_BROWSE, IDC_DISCARD1PASS, IDC_HINTEDME,                  CONSTRAINVAL(temp, 1, 255);
596                  IDC_CBR_REACTIONDELAY, IDC_CBR_AVERAGINGPERIOD, IDC_CBR_BUFFER,                  config->qmatrix_intra[i] = temp;
                 IDC_CREDITS_SIZE_RADIO, IDC_CREDITS_END_STATIC, IDC_CREDITS_START_SIZE, IDC_CREDITS_END_SIZE,  
                 IDC_HINTFILE  
         };  
597    
598          const short quant_disable[] = {                  temp = config_get_uint(hDlg, i + IDC_QINTER00, config->qmatrix_inter[i]);
599                  IDC_STATS1, IDC_STATS1_BROWSE, IDC_DISCARD1PASS, IDC_HINTEDME,                  CONSTRAINVAL(temp, 1, 255);
600                  IDC_CBR_REACTIONDELAY, IDC_CBR_AVERAGINGPERIOD, IDC_CBR_BUFFER,                  config->qmatrix_inter[i] = temp;
601                  IDC_MINIQUANT, IDC_MAXIQUANT, IDC_MINPQUANT, IDC_MAXPQUANT,          }
602                  IDC_CREDITS_SIZE_RADIO, IDC_CREDITS_END_STATIC, IDC_CREDITS_START_SIZE, IDC_CREDITS_END_SIZE,  }
                 IDC_HINTFILE  
         };  
603    
         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  
         };  
604    
605          const short twopass2_ext_disable[] = {  static void quant_loadsave(HWND hDlg, CONFIG * config, int save)
606                  IDC_CBR_REACTIONDELAY, IDC_CBR_AVERAGINGPERIOD, IDC_CBR_BUFFER,  {
607                  IDC_CREDITS_RATE_RADIO,          char file[MAX_PATH];
608                  IDC_CREDITS_SIZE_RADIO, IDC_CREDITS_END_STATIC, IDC_CREDITS_RATE,          OPENFILENAME ofn;
609                  IDC_CREDITS_START_SIZE, IDC_CREDITS_END_SIZE          HANDLE hFile;
610          };          DWORD read=128, wrote=0;
611            BYTE quant_data[128];
612    
613          const short twopass2_int_disable[] = {          strcpy(file, "\\matrix");
614                  IDC_CBR_REACTIONDELAY, IDC_CBR_AVERAGINGPERIOD, IDC_CBR_BUFFER,          memset(&ofn, 0, sizeof(OPENFILENAME));
615                  IDC_STATS2, IDC_STATS2_BROWSE          ofn.lStructSize = sizeof(OPENFILENAME);
         };  
616    
617          // store pointers in order so we can lookup using config->mode          ofn.hwndOwner = hDlg;
618          const short* modes[] = {          ofn.lpstrFilter = "All files (*.*)\0*.*\0\0";
619                  cbr_disable, qual_disable, quant_disable,          ofn.lpstrFile = file;
620                  twopass1_disable, twopass2_ext_disable, twopass2_int_disable          ofn.nMaxFile = MAX_PATH;
621          };          ofn.Flags = OFN_PATHMUSTEXIST;
622    
623          // ditto modes[]          if (save) {
624          const int lengths[] = {                  ofn.Flags |= OFN_OVERWRITEPROMPT;
625                  sizeof(cbr_disable)/sizeof(short), sizeof(qual_disable)/sizeof(short),                  if (GetSaveFileName(&ofn)) {
626                  sizeof(quant_disable)/sizeof(short), sizeof(twopass1_disable)/sizeof(short),                          hFile = CreateFile(file, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
                 sizeof(twopass2_ext_disable)/sizeof(short), sizeof(twopass2_int_disable)/sizeof(short), 0  
         };  
627    
628          int i;                          quant_download(hDlg, config);
629          int hinted_me, use_alt, use_alt_auto, use_alt_auto_bonus;                          memcpy(quant_data, config->qmatrix_intra, 64);
630          int credits_start, credits_end, credits_rate, credits_quant, credits_size;                          memcpy(quant_data+64, config->qmatrix_inter, 64);
         int cpu_force;  
631    
632          // first perform checkbox-based enable/disable                          if (hFile == INVALID_HANDLE_VALUE) {
633          hinted_me = ISDLGSET(IDC_HINTEDME);                                  DPRINTF("Couldn't save quant matrix");
634          CONTROLDLG(IDC_HINTFILE,                        hinted_me);                          }else{
635          CONTROLDLG(IDC_HINT_BROWSE,                     hinted_me);                                  if (!WriteFile(hFile, quant_data, 128, &wrote, 0)) {
636                                            DPRINTF("Couldnt write quant matrix");
         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 ; i<lengths[mode] ; ++i)  
         {  
                 EnableWindow(GetDlgItem(hDlg, modes[mode][i]), FALSE);  
637          }          }
638                            }
639                            CloseHandle(hFile);
640                    }
641            }else{
642                    ofn.Flags |= OFN_FILEMUSTEXIST;
643                    if (GetOpenFileName(&ofn)) {
644                            hFile = CreateFile(file, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
645    
646          if (mode != DLG_MODE_2PASS_2_EXT && mode != DLG_MODE_2PASS_2_INT)                          if (hFile == INVALID_HANDLE_VALUE) {
647          {                                  DPRINTF("Couldn't load quant matrix");
648                  for (i=0 ; i<sizeof(twopass_disable)/sizeof(short) ; ++i)                          } else {
649                  {                                  if (!ReadFile(hFile, quant_data, 128, &read, 0)) {
650                          EnableWindow(GetDlgItem(hDlg, twopass_disable[i]), FALSE);                                          DPRINTF("Couldnt read quant matrix");
651                                    }else{
652                                            memcpy(config->qmatrix_intra, quant_data, 64);
653                                            memcpy(config->qmatrix_inter, quant_data+64, 64);
654                                            quant_upload(hDlg, config);
655                                    }
656                            }
657                            CloseHandle(hFile);
658                  }                  }
659          }          }
660  }  }
661    
662    /* quantization matrix dialog proc */
663    
664  /* upload config data into dialog */  static BOOL CALLBACK quantmatrix_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
665    {
666            CONFIG* config = (CONFIG*)GetWindowLong(hDlg, GWL_USERDATA);
667    
668  void adv_upload(HWND hDlg, int page, CONFIG * config)          switch (uMsg)
669  {  {
670          switch (page)          case WM_INITDIALOG :
671                    SetWindowLong(hDlg, GWL_USERDATA, lParam);
672                    config = (CONFIG*)lParam;
673                    quant_upload(hDlg, config);
674    
675                    if (g_hTooltip)
676          {          {
677          case DLG_GLOBAL :                          EnumChildWindows(hDlg, enum_tooltips, 0);
678                  SendDlgItemMessage(hDlg, IDC_MOTION, CB_SETCURSEL, config->motion_search, 0);                  }
679                  SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_SETCURSEL, config->quant_type, 0);                  break;
                 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);  
680    
681                  CheckDlgButton(hDlg, IDC_REDUCED, config->reduced_resolution ? BST_CHECKED : BST_UNCHECKED);          case WM_COMMAND :
682    
683                    if (HIWORD(wParam) == BN_CLICKED) {
684                            switch(LOWORD(wParam)) {
685                            case IDOK :
686                                    quant_download(hDlg, config);
687                                    EndDialog(hDlg, IDOK);
688                  break;                  break;
689    
690          case DLG_QUANT :                          case IDCANCEL :
691                  SetDlgItemInt(hDlg, IDC_MINIQUANT, config->min_iquant, FALSE);                                  EndDialog(hDlg, IDCANCEL);
                 SetDlgItemInt(hDlg, IDC_MAXIQUANT, config->max_iquant, FALSE);  
                 SetDlgItemInt(hDlg, IDC_MINPQUANT, config->min_pquant, FALSE);  
                 SetDlgItemInt(hDlg, IDC_MAXPQUANT, config->max_pquant, FALSE);  
692                  break;                  break;
693    
694          case DLG_2PASS :                          case IDC_SAVE :
695                  SetDlgItemInt(hDlg, IDC_KFBOOST, config->keyframe_boost, FALSE);                                  quant_loadsave(hDlg, config, 1);
696                  CheckDlgButton(hDlg, IDC_DISCARD1PASS, config->discard1pass ? BST_CHECKED : BST_UNCHECKED);                                  break;
                 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_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));  
697    
698                  CheckDlgButton(hDlg, IDC_HINTEDME, config->hinted_me ? BST_CHECKED : BST_UNCHECKED);                          case IDC_LOAD :
699                  SetDlgItemText(hDlg, IDC_HINTFILE, config->hintfile);                                  quant_loadsave(hDlg, config, 0);
                 SetDlgItemText(hDlg, IDC_STATS1, config->stats1);  
                 SetDlgItemText(hDlg, IDC_STATS2, config->stats2);  
700                  break;                  break;
701    
702          case DLG_2PASSALT :                          default :
703                  CheckDlgButton(hDlg, IDC_USEALT, config->use_alt_curve ? BST_CHECKED : BST_UNCHECKED);                                  return FALSE;
704                            }
705                            break;
706                    }
707                    return FALSE;
708    
709                  SendDlgItemMessage(hDlg, IDC_CURVETYPE, CB_SETCURSEL, config->alt_curve_type, 0);          default :
710                  SetDlgItemInt(hDlg, IDC_ALTCURVEHIGH, config->alt_curve_high_dist, FALSE);                  return FALSE;
711                  SetDlgItemInt(hDlg, IDC_ALTCURVELOW, config->alt_curve_low_dist, FALSE);          }
                 SetDlgItemInt(hDlg, IDC_MINQUAL, config->alt_curve_min_rel_qual, FALSE);  
712    
713                  CheckDlgButton(hDlg, IDC_USEAUTO, config->alt_curve_use_auto ? BST_CHECKED : BST_UNCHECKED);          return TRUE;
714                  SetDlgItemInt(hDlg, IDC_AUTOSTR, config->alt_curve_auto_str, FALSE);  }
715    
                 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);  
716    
717                  SetDlgItemInt(hDlg, IDC_MAXBITRATE, config->twopass_max_bitrate / CONFIG_KBPS, FALSE);  /* ===================================================================================== */
718                  SetDlgItemInt(hDlg, IDC_OVERIMP, config->twopass_max_overflow_improvement, FALSE);  /* ADVANCED DIALOG PAGES ================================================================ */
719                  SetDlgItemInt(hDlg, IDC_OVERDEG, config->twopass_max_overflow_degradation, FALSE);  /* ===================================================================================== */
720    
721    /* initialise pages */
722    static void adv_init(HWND hDlg, int idd, CONFIG * config)
723    {
724            unsigned int i;
725    
726            switch(idd) {
727            case IDD_PROFILE :
728                    for (i=0; i<sizeof(profiles)/sizeof(profile_t); i++)
729                            SendDlgItemMessage(hDlg, IDC_PROFILE_PROFILE, CB_ADDSTRING, 0, (LPARAM)profiles[i].name);
730                    SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_ADDSTRING, 0, (LPARAM)"H.263");
731                    SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_ADDSTRING, 0, (LPARAM)"MPEG");
732                    SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_ADDSTRING, 0, (LPARAM)"MPEG-Custom");
733                  break;                  break;
734    
735          case DLG_CREDITS :          case IDD_AR:
736                  CheckDlgButton(hDlg, IDC_CREDITS_START, config->credits_start ? BST_CHECKED : BST_UNCHECKED);                  SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_ADDSTRING, 0, (LPARAM)"Square (default)");
737                  SetDlgItemInt(hDlg, IDC_CREDITS_START_BEGIN, config->credits_start_begin, FALSE);                  SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_ADDSTRING, 0, (LPARAM)"4:3 PAL");
738                  SetDlgItemInt(hDlg, IDC_CREDITS_START_END, config->credits_start_end, FALSE);                  SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_ADDSTRING, 0, (LPARAM)"4:3 NTSC");
739                  CheckDlgButton(hDlg, IDC_CREDITS_END, config->credits_end ? BST_CHECKED : BST_UNCHECKED);                  SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_ADDSTRING, 0, (LPARAM)"16:9 PAL");
740                  SetDlgItemInt(hDlg, IDC_CREDITS_END_BEGIN, config->credits_end_begin, FALSE);                  SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_ADDSTRING, 0, (LPARAM)"16:9 NTSC");
741                  SetDlgItemInt(hDlg, IDC_CREDITS_END_END, config->credits_end_end, FALSE);                  SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_ADDSTRING, 0, (LPARAM)"Custom...");
742                    break;
743    
744            case IDD_LEVEL :
745                    for (i=0; i<sizeof(profiles)/sizeof(profile_t); i++)
746                            SendDlgItemMessage(hDlg, IDC_LEVEL_PROFILE, CB_ADDSTRING, 0, (LPARAM)profiles[i].name);
747                    break;
748    
749            case IDD_BITRATE :
750                    SendDlgItemMessage(hDlg, IDC_BITRATE_CFORMAT, CB_ADDSTRING, 0, (LPARAM)"AVI-Legacy");
751                    SendDlgItemMessage(hDlg, IDC_BITRATE_CFORMAT, CB_ADDSTRING, 0, (LPARAM)"AVI-OpenDML");
752                    SendDlgItemMessage(hDlg, IDC_BITRATE_CFORMAT, CB_ADDSTRING, 0, (LPARAM)"Matroska");
753                    SendDlgItemMessage(hDlg, IDC_BITRATE_CFORMAT, CB_ADDSTRING, 0, (LPARAM)"OGM");
754                    SendDlgItemMessage(hDlg, IDC_BITRATE_CFORMAT, CB_ADDSTRING, 0, (LPARAM)"(None)");
755    
756                    SendDlgItemMessage(hDlg, IDC_BITRATE_TSIZE, CB_ADDSTRING, 0, (LPARAM)"665600");
757                    SendDlgItemMessage(hDlg, IDC_BITRATE_TSIZE, CB_ADDSTRING, 0, (LPARAM)"716800");
758                    SendDlgItemMessage(hDlg, IDC_BITRATE_TSIZE, CB_ADDSTRING, 0, (LPARAM)"1331200");
759                    SendDlgItemMessage(hDlg, IDC_BITRATE_TSIZE, CB_ADDSTRING, 0, (LPARAM)"1433600");
760    
761                    for (i=0; i<sizeof(video_fps_list)/sizeof(named_float_t); i++)
762                            SendDlgItemMessage(hDlg, IDC_BITRATE_FPS, CB_ADDSTRING, 0, (LPARAM)video_fps_list[i].name);
763    
764                    for (i=0; i<sizeof(audio_type_list)/sizeof(named_int_t); i++)
765                            SendDlgItemMessage(hDlg, IDC_BITRATE_AFORMAT, CB_ADDSTRING, 0, (LPARAM)audio_type_list[i].name);
766    
767                    SendDlgItemMessage(hDlg, IDC_BITRATE_ARATE, CB_ADDSTRING, 0, (LPARAM)"32");
768                    SendDlgItemMessage(hDlg, IDC_BITRATE_ARATE, CB_ADDSTRING, 0, (LPARAM)"56");
769                    SendDlgItemMessage(hDlg, IDC_BITRATE_ARATE, CB_ADDSTRING, 0, (LPARAM)"64");
770                    SendDlgItemMessage(hDlg, IDC_BITRATE_ARATE, CB_ADDSTRING, 0, (LPARAM)"96");
771                    SendDlgItemMessage(hDlg, IDC_BITRATE_ARATE, CB_ADDSTRING, 0, (LPARAM)"112");
772                    SendDlgItemMessage(hDlg, IDC_BITRATE_ARATE, CB_ADDSTRING, 0, (LPARAM)"128");
773                    SendDlgItemMessage(hDlg, IDC_BITRATE_ARATE, CB_ADDSTRING, 0, (LPARAM)"160");
774                    SendDlgItemMessage(hDlg, IDC_BITRATE_ARATE, CB_ADDSTRING, 0, (LPARAM)"192");
775                    SendDlgItemMessage(hDlg, IDC_BITRATE_ARATE, CB_ADDSTRING, 0, (LPARAM)"224");
776                    SendDlgItemMessage(hDlg, IDC_BITRATE_ARATE, CB_ADDSTRING, 0, (LPARAM)"256");
777                    SendDlgItemMessage(hDlg, IDC_BITRATE_ARATE, CB_ADDSTRING, 0, (LPARAM)"384");
778                    SendDlgItemMessage(hDlg, IDC_BITRATE_ARATE, CB_ADDSTRING, 0, (LPARAM)"448");
779                    SendDlgItemMessage(hDlg, IDC_BITRATE_ARATE, CB_ADDSTRING, 0, (LPARAM)"512");
780                    break;
781    
782  // added by koepi for credits greyscale          case IDD_ZONE :
783                  CheckDlgButton(hDlg, IDC_CREDITS_GREYSCALE, config->credits_greyscale ? BST_CHECKED : BST_UNCHECKED);                  EnableDlgWindow(hDlg, IDC_ZONE_FETCH, config->ci_valid);
784  // end of koepi's addition                  break;
                 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);  
785    
786                  if (config->credits_mode == CREDITS_MODE_RATE)          case IDD_MOTION :
787                  {                  SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"0 - None");
788                          CheckDlgButton(hDlg, IDC_CREDITS_RATE_RADIO, BST_CHECKED);                  SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"1 - Very Low");
789                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"2 - Low");
790                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"3 - Medium");
791                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"4 - High");
792                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"5 - Very High");
793                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"6 - Ultra High");
794    
795                    SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"0 - Off");
796                    SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"1 - Mode Decision");
797                    SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"2 - Limited Search");
798                    SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"3 - Medium Search");
799                    SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"4 - Wide Search");
800                    break;
801    
802            case IDD_DEBUG :
803                    /* force threads disabled */
804                    EnableWindow(GetDlgItem(hDlg, IDC_NUMTHREADS_STATIC), FALSE);
805                    EnableWindow(GetDlgItem(hDlg, IDC_NUMTHREADS), FALSE);
806    
807                    SendDlgItemMessage(hDlg, IDC_FOURCC, CB_ADDSTRING, 0, (LPARAM)"XVID");
808                    SendDlgItemMessage(hDlg, IDC_FOURCC, CB_ADDSTRING, 0, (LPARAM)"DIVX");
809                    SendDlgItemMessage(hDlg, IDC_FOURCC, CB_ADDSTRING, 0, (LPARAM)"DX50");
810                    break;
811    
812            case IDD_DEC :
813                    SendDlgItemMessage(hDlg, IDC_DEC_BRIGHTNESS, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(-96, 96));
814                    SendDlgItemMessage(hDlg, IDC_DEC_BRIGHTNESS, TBM_SETTICFREQ, (WPARAM)16, (LPARAM)0);
815                    break;
816                  }                  }
                 else if (config->credits_mode == CREDITS_MODE_QUANT)  
                 {  
                         CheckDlgButton(hDlg, IDC_CREDITS_QUANT_RADIO, BST_CHECKED);  
817                  }                  }
818                  else    // CREDITS_MODE_SIZE  
819    
820    /* enable/disable controls based on encoder-mode or user selection */
821    
822    static void adv_mode(HWND hDlg, int idd, CONFIG * config)
823                  {                  {
824                          CheckDlgButton(hDlg, IDC_CREDITS_SIZE_RADIO, BST_CHECKED);          int profile;
825            int weight_en, quant_en;
826            int cpu_force;
827            int custom_quant, bvops;
828            int ar_mode, ar_par;
829    
830            switch(idd) {
831            case IDD_PROFILE :
832                    profile = SendDlgItemMessage(hDlg, IDC_PROFILE_PROFILE, CB_GETCURSEL, 0, 0);
833                    EnableDlgWindow(hDlg, IDC_BVOP, profiles[profile].flags&PROFILE_BVOP);
834    
835                    EnableDlgWindow(hDlg, IDC_QUANTTYPE_S, profiles[profile].flags&PROFILE_MPEGQUANT);
836                    EnableDlgWindow(hDlg, IDC_QUANTTYPE_S, profiles[profile].flags&PROFILE_MPEGQUANT);
837                    EnableDlgWindow(hDlg, IDC_QUANTTYPE, profiles[profile].flags&PROFILE_MPEGQUANT);
838                    custom_quant = (profiles[profile].flags&PROFILE_MPEGQUANT) && SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_GETCURSEL, 0, 0)==QUANT_MODE_CUSTOM;
839                    EnableDlgWindow(hDlg, IDC_QUANTMATRIX, custom_quant);
840                    EnableDlgWindow(hDlg, IDC_LUMMASK, profiles[profile].flags&PROFILE_ADAPTQUANT);
841                    EnableDlgWindow(hDlg, IDC_INTERLACING, profiles[profile].flags&PROFILE_INTERLACE);
842                    EnableDlgWindow(hDlg, IDC_QPEL, profiles[profile].flags&PROFILE_QPEL);
843                    EnableDlgWindow(hDlg, IDC_GMC, profiles[profile].flags&PROFILE_GMC);
844                    EnableDlgWindow(hDlg, IDC_REDUCED, profiles[profile].flags&PROFILE_REDUCED);
845    
846                    bvops = (profiles[profile].flags&PROFILE_BVOP) && IsDlgChecked(hDlg, IDC_BVOP);
847                    EnableDlgWindow(hDlg, IDC_MAXBFRAMES,      bvops);
848                    EnableDlgWindow(hDlg, IDC_BQUANTRATIO,    bvops);
849                    EnableDlgWindow(hDlg, IDC_BQUANTOFFSET,  bvops);
850                    EnableDlgWindow(hDlg, IDC_MAXBFRAMES_S,  bvops);
851                    EnableDlgWindow(hDlg, IDC_BQUANTRATIO_S,        bvops);
852                    EnableDlgWindow(hDlg, IDC_BQUANTOFFSET_S,   bvops);
853                    EnableDlgWindow(hDlg, IDC_PACKED,                  bvops);
854                    EnableDlgWindow(hDlg, IDC_CLOSEDGOV,            bvops);
855                    break;
856    
857            case IDD_AR:
858                    ar_mode = IsDlgChecked(hDlg, IDC_PAR);
859                    EnableDlgWindow(hDlg, IDC_ASPECT_RATIO, ar_mode);
860    
861                    ar_par = SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_GETCURSEL, 0, 0);
862                    if (ar_par == 5) { /* custom par */
863                            SetDlgItemInt(hDlg, IDC_PARY, config->par_y, FALSE);
864                            SetDlgItemInt(hDlg, IDC_PARX, config->par_x, FALSE);
865    
866                            EnableDlgWindow(hDlg, IDC_PARX, ar_mode);
867                            EnableDlgWindow(hDlg, IDC_PARY, ar_mode);
868                    } else {
869                            SetDlgItemInt(hDlg, IDC_PARX, PARS[ar_par][0], FALSE);
870                            SetDlgItemInt(hDlg, IDC_PARY, PARS[ar_par][1], FALSE);
871                            EnableDlgWindow(hDlg, IDC_PARX, FALSE);
872                            EnableDlgWindow(hDlg, IDC_PARY, FALSE);
873                  }                  }
874    
875                    ar_mode = IsDlgChecked(hDlg, IDC_AR);
876    
877                    config->ar_x = config_get_uint(hDlg, IDC_ARX, config->ar_x);
878                    config->ar_y = config_get_uint(hDlg, IDC_ARY, config->ar_y);
879    
880                    EnableDlgWindow(hDlg, IDC_ARX, ar_mode);
881                    EnableDlgWindow(hDlg, IDC_ARY, ar_mode);
882                  break;                  break;
883    
884          case DLG_CPU :          case IDD_LEVEL :
885                  CheckDlgButton(hDlg, IDC_CPU_MMX, (config->cpu & XVID_CPU_MMX) ? BST_CHECKED : BST_UNCHECKED);                  profile = SendDlgItemMessage(hDlg, IDC_LEVEL_PROFILE, CB_GETCURSEL, 0, 0);
886                  CheckDlgButton(hDlg, IDC_CPU_MMXEXT, (config->cpu & XVID_CPU_MMXEXT) ? BST_CHECKED : BST_UNCHECKED);                  SetDlgItemInt(hDlg, IDC_LEVEL_WIDTH, profiles[profile].width, FALSE);
887                  CheckDlgButton(hDlg, IDC_CPU_SSE, (config->cpu & XVID_CPU_SSE) ? BST_CHECKED : BST_UNCHECKED);                  SetDlgItemInt(hDlg, IDC_LEVEL_HEIGHT, profiles[profile].height, FALSE);
888                  CheckDlgButton(hDlg, IDC_CPU_SSE2, (config->cpu & XVID_CPU_SSE2) ? BST_CHECKED : BST_UNCHECKED);                  SetDlgItemInt(hDlg, IDC_LEVEL_FPS, profiles[profile].fps, FALSE);
889                  CheckDlgButton(hDlg, IDC_CPU_3DNOW, (config->cpu & XVID_CPU_3DNOW) ? BST_CHECKED : BST_UNCHECKED);                  SetDlgItemInt(hDlg, IDC_LEVEL_VMV, profiles[profile].max_vmv_buffer_sz, FALSE);
890                  CheckDlgButton(hDlg, IDC_CPU_3DNOWEXT, (config->cpu & XVID_CPU_3DNOWEXT) ? BST_CHECKED : BST_UNCHECKED);                  SetDlgItemInt(hDlg, IDC_LEVEL_VCV, profiles[profile].vcv_decoder_rate, FALSE);
891                    SetDlgItemInt(hDlg, IDC_LEVEL_VBV, profiles[profile].max_vbv_size, FALSE);
892                    SetDlgItemInt(hDlg, IDC_LEVEL_BITRATE, profiles[profile].max_bitrate, FALSE);
893                    break;
894    
895                  CheckRadioButton(hDlg, IDC_CPU_AUTO, IDC_CPU_FORCE,          case IDD_BITRATE :
896                          config->cpu & XVID_CPU_FORCE ? IDC_CPU_FORCE : IDC_CPU_AUTO );                  {
897                            int ctype = SendDlgItemMessage(hDlg, IDC_BITRATE_CFORMAT, CB_GETCURSEL, 0, 0);
898                            int target_size = config_get_cbuint(hDlg, IDC_BITRATE_TSIZE, 0);
899                            int subtitle_size = config_get_uint(hDlg, IDC_BITRATE_SSIZE, 0);
900                            int fps = SendDlgItemMessage(hDlg, IDC_BITRATE_FPS, CB_GETCURSEL, 0, 0);
901    
902                  SetDlgItemInt(hDlg, IDC_NUMTHREADS, config->num_threads, FALSE);                          int duration =
903                  CheckDlgButton(hDlg, IDC_CHROMA_OPT, (config->chroma_opt) ? BST_CHECKED : BST_UNCHECKED);                                  3600 * config_get_uint(hDlg, IDC_BITRATE_HOURS, 0) +
904                  SetDlgItemInt(hDlg, IDC_FRAMEDROP, config->frame_drop_ratio, FALSE);                                  60 * config_get_uint(hDlg, IDC_BITRATE_MINUTES, 0) +
905                  SetDlgItemInt(hDlg, IDC_CBR_REACTIONDELAY, config->rc_reaction_delay_factor, FALSE);                                  config_get_uint(hDlg, IDC_BITRATE_SECONDS, 0);
906                  SetDlgItemInt(hDlg, IDC_CBR_AVERAGINGPERIOD, config->rc_averaging_period, FALSE);  
907                  SetDlgItemInt(hDlg, IDC_CBR_BUFFER, config->rc_buffer, FALSE);                          int audio_type = SendDlgItemMessage(hDlg, IDC_BITRATE_AFORMAT, CB_GETCURSEL, 0, 0);
908                            int audio_mode = IsDlgChecked(hDlg, IDC_BITRATE_AMODE_SIZE);
909                            int audio_rate = config_get_cbuint(hDlg, IDC_BITRATE_ARATE, 0);
910                            int audio_size = config_get_uint(hDlg, IDC_BITRATE_ASIZE, 0);
911    
912                            int frames;
913                            int overhead;
914                            int vsize;
915    
916                            if (duration == 0)
917                  break;                  break;
918    
919                            if (fps < 0 || fps >= sizeof(video_fps_list)/sizeof(named_float_t)) {
920                                    fps = 0;
921          }          }
922                            if (audio_type < 0 || audio_type >= sizeof(audio_type_list)/sizeof(named_int_t)) {
923                                    audio_type = 0;
924  }  }
925    
926                            EnableDlgWindow(hDlg, IDC_BITRATE_AMODE_RATE, audio_type!=NO_AUDIO);
927                            EnableDlgWindow(hDlg, IDC_BITRATE_AMODE_SIZE, audio_type!=NO_AUDIO);
928                            EnableDlgWindow(hDlg, IDC_BITRATE_ARATE, audio_type!=NO_AUDIO && !audio_mode);
929                            EnableDlgWindow(hDlg, IDC_BITRATE_ASIZE, audio_type!=NO_AUDIO && audio_mode);
930                            EnableDlgWindow(hDlg, IDC_BITRATE_ASELECT, audio_type!=NO_AUDIO && audio_mode);
931    
932  /* download config data from dialog                          /* step 1: calculate number of frames */
933     replaces invalid values instead of alerting user for now                          frames = (int)(duration * video_fps_list[fps].value);
 */  
934    
935  #define CONSTRAINVAL(X,Y,Z) if((X)<(Y)) X=Y; if((X)>(Z)) X=Z;                          /* step 2: calculate audio_size (kbytes)*/
936                            if (audio_type!=NO_AUDIO) {
937                                    if (audio_mode==0) {
938                                            audio_size = (duration * audio_rate) / 8;
939                                    }
940                            }else{
941                                    audio_size = 0;
942                            }
943    
944  void adv_download(HWND hDlg, int page, CONFIG * config)                          /* step 3: calculate container overhead */
945  {  
946          switch (page)                          switch(ctype) {
947          {                          case 0 :        /* AVI */
948          case DLG_GLOBAL :                          case 1 :        /* AVI-OpenDML */
949                  config->motion_search = SendDlgItemMessage(hDlg, IDC_MOTION, CB_GETCURSEL, 0, 0);  
950                  config->quant_type = SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_GETCURSEL, 0, 0);                                  overhead = frames;
951                  config->fourcc_used = SendDlgItemMessage(hDlg, IDC_FOURCC, CB_GETCURSEL, 0, 0);  
952                  config->vhq_mode = SendDlgItemMessage(hDlg, IDC_VHQ, CB_GETCURSEL, 0, 0);                                  if (audio_type!=NO_AUDIO) {
953                  config->max_key_interval = config_get_uint(hDlg, IDC_MAXKEY, config->max_key_interval);                                          overhead += (duration * 1000) / audio_type_list[audio_type].avi_interval;
954                  config->min_key_interval = config_get_uint(hDlg, IDC_MINKEY, config->min_key_interval);                                  }
955                  config->lum_masking = ISDLGSET(IDC_LUMMASK);  
956                  config->interlacing = ISDLGSET(IDC_INTERLACING);                                  overhead *= (ctype==0) ? 24 : 16;
957    
958                  config->qpel = ISDLGSET(IDC_QPEL);                                  overhead /= 1024;
                 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);  
959                  break;                  break;
960    
961          case DLG_QUANT :                          case 2 :        /* Matroska: gknot formula */
                 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);  
962    
963                  CONSTRAINVAL(config->min_iquant, 1, 31);                                  /* common overhead */
964                  CONSTRAINVAL(config->max_iquant, config->min_iquant, 31);                                  overhead = 40 + 12 + 8+ 16*duration + 200 + 100*1/*one audio stream*/ + 11*duration;
965                  CONSTRAINVAL(config->min_pquant, 1, 31);  
966                  CONSTRAINVAL(config->max_pquant, config->min_pquant, 31);                                  /* video overhead */
967                                    overhead += frames*8 + (int)(frames * 4 * 0.94);
968    
969                                    /* cue tables and menu seek entries (300k default) */
970                                    overhead += 300 * 1024;
971    
972                                    /* audio */
973                                    overhead += (int)(duration * audio_type_list[audio_type].mkv_multiplier);
974    
975                                    overhead /= 1024;
976                  break;                  break;
977    
978          case DLG_2PASS :                          case 3 :        /* OGM: inaccurate model */
979                  config->keyframe_boost = GetDlgItemInt(hDlg, IDC_KFBOOST, NULL, FALSE);                                  overhead = (int)(0.0039F * (target_size - subtitle_size));
980  // added by koepi for the new 2pass curve treatment                                  break;
                 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);  
981    
982                  if (GetDlgItemText(hDlg, IDC_HINTFILE, config->hintfile, MAX_PATH) == 0)                          default :       /* (none) */
983                  {                                  overhead = 0;
984                          lstrcpy(config->hintfile, CONFIG_HINTFILE);                                  break;
985                  }                  }
986                  if (GetDlgItemText(hDlg, IDC_STATS1, config->stats1, MAX_PATH) == 0)  
987                  {                          SetDlgItemInt(hDlg, IDC_BITRATE_COVERHEAD, overhead, TRUE);
988                          lstrcpy(config->stats1, CONFIG_2PASS_1_FILE);  
989                            /* final video bitstream size */
990                            vsize = target_size - subtitle_size - audio_size - overhead;
991                            if (vsize > 0) {
992                                    SetDlgItemInt(hDlg, IDC_BITRATE_VSIZE, vsize, TRUE);
993                                    /* convert from kbytes to kbits-per-second */
994                                    SetDlgItemInt(hDlg, IDC_BITRATE_VRATE, (vsize * 8 * 128) / (duration * 125), TRUE);
995                            }else{
996                                    SetDlgItemText(hDlg, IDC_BITRATE_VSIZE, "Overflow");
997                                    SetDlgItemText(hDlg, IDC_BITRATE_VRATE, "Overflow");
998                  }                  }
999                  if (GetDlgItemText(hDlg, IDC_STATS2, config->stats2, MAX_PATH) == 0)  
                 {  
                         lstrcpy(config->stats2, CONFIG_2PASS_2_FILE);  
1000                  }                  }
1001                    break;
1002    
1003                  CONSTRAINVAL(config->bitrate_payback_delay, 1, 10000);          case IDD_ZONE :
1004                  CONSTRAINVAL(config->keyframe_boost, 0, 1000);                  weight_en = IsDlgChecked(hDlg, IDC_ZONE_MODE_WEIGHT);
1005                  CONSTRAINVAL(config->curve_compression_high, 0, 100);                  quant_en =   IsDlgChecked(hDlg, IDC_ZONE_MODE_QUANT);
1006                  CONSTRAINVAL(config->curve_compression_low, 0, 100);                  EnableDlgWindow(hDlg, IDC_ZONE_WEIGHT, weight_en);
1007                    EnableDlgWindow(hDlg, IDC_ZONE_QUANT, quant_en);
1008                    EnableDlgWindow(hDlg, IDC_ZONE_SLIDER, weight_en|quant_en);
1009    
1010                    if (weight_en) {
1011                            SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(001,200));
1012                            SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETPOS, TRUE, get_dlgitem_float(hDlg, IDC_ZONE_WEIGHT, 100));
1013                            SetDlgItemText(hDlg, IDC_ZONE_MIN, "0.01");
1014                            SetDlgItemText(hDlg, IDC_ZONE_MAX, "2.00");
1015                    }else if (quant_en) {
1016                            SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(100,3100));
1017                            SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETPOS, TRUE, get_dlgitem_float(hDlg, IDC_ZONE_QUANT, 100));
1018                            SetDlgItemText(hDlg, IDC_ZONE_MIN, "1");
1019                            SetDlgItemText(hDlg, IDC_ZONE_MAX, "31");
1020                    }
1021    
1022                    bvops = (profiles[config->profile].flags&PROFILE_BVOP) && config->use_bvop;
1023                    EnableDlgWindow(hDlg, IDC_ZONE_BVOPTHRESHOLD_S, bvops);
1024                    EnableDlgWindow(hDlg, IDC_ZONE_BVOPTHRESHOLD, bvops);
1025                  break;                  break;
1026    
1027          case DLG_2PASSALT :          case IDD_DEBUG :
1028                  config->use_alt_curve = ISDLGSET(IDC_USEALT);                  cpu_force                       = IsDlgChecked(hDlg, IDC_CPU_FORCE);
1029                    EnableDlgWindow(hDlg, IDC_CPU_MMX,              cpu_force);
1030                    EnableDlgWindow(hDlg, IDC_CPU_MMXEXT,   cpu_force);
1031                    EnableDlgWindow(hDlg, IDC_CPU_SSE,              cpu_force);
1032                    EnableDlgWindow(hDlg, IDC_CPU_SSE2,             cpu_force);
1033                    EnableDlgWindow(hDlg, IDC_CPU_3DNOW,    cpu_force);
1034                    EnableDlgWindow(hDlg, IDC_CPU_3DNOWEXT, cpu_force);
1035                    break;
1036            }
1037    }
1038    
                 config->alt_curve_use_auto = ISDLGSET(IDC_USEAUTO);  
                 config->alt_curve_auto_str = config_get_uint(hDlg, IDC_AUTOSTR, config->alt_curve_auto_str);  
1039    
1040                  config->alt_curve_use_auto_bonus_bias = ISDLGSET(IDC_USEAUTOBONUS);  /* upload config data into dialog */
1041                  config->alt_curve_bonus_bias = config_get_uint(hDlg, IDC_BONUSBIAS, config->alt_curve_bonus_bias);  static void adv_upload(HWND hDlg, int idd, CONFIG * config)
1042    {
1043            switch (idd)
1044            {
1045            case IDD_PROFILE :
1046                    SendDlgItemMessage(hDlg, IDC_PROFILE_PROFILE, CB_SETCURSEL, config->profile, 0);
1047    
1048                  config->alt_curve_type = SendDlgItemMessage(hDlg, IDC_CURVETYPE, CB_GETCURSEL, 0, 0);                  SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_SETCURSEL, config->quant_type, 0);
1049                  config->alt_curve_high_dist = config_get_uint(hDlg, IDC_ALTCURVEHIGH, config->alt_curve_high_dist);                  CheckDlg(hDlg, IDC_LUMMASK, config->lum_masking);
1050                  config->alt_curve_low_dist = config_get_uint(hDlg, IDC_ALTCURVELOW, config->alt_curve_low_dist);                  CheckDlg(hDlg, IDC_INTERLACING, config->interlacing);
1051                  config->alt_curve_min_rel_qual = config_get_uint(hDlg, IDC_MINQUAL, config->alt_curve_min_rel_qual);                  CheckDlg(hDlg, IDC_QPEL, config->qpel);
1052                    CheckDlg(hDlg, IDC_GMC, config->gmc);
1053                  config->twopass_max_bitrate /= CONFIG_KBPS;                  CheckDlg(hDlg, IDC_REDUCED, config->reduced_resolution);
1054                  config->twopass_max_bitrate = config_get_uint(hDlg, IDC_MAXBITRATE, config->twopass_max_bitrate);                  CheckDlg(hDlg, IDC_BVOP, config->use_bvop);
                 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);  
1055    
1056                  CONSTRAINVAL(config->twopass_max_overflow_improvement, 1, 80);                  SetDlgItemInt(hDlg, IDC_MAXBFRAMES, config->max_bframes, FALSE);
1057                  CONSTRAINVAL(config->twopass_max_overflow_degradation, 1, 80);                  set_dlgitem_float(hDlg, IDC_BQUANTRATIO, config->bquant_ratio);
1058                    set_dlgitem_float(hDlg, IDC_BQUANTOFFSET, config->bquant_offset);
1059                    CheckDlg(hDlg, IDC_PACKED, config->packed);
1060                    CheckDlg(hDlg, IDC_CLOSEDGOV, config->closed_gov);
1061    
1062                    break;
1063            case IDD_AR:
1064                    CheckRadioButton(hDlg, IDC_AR, IDC_PAR, config->ar_mode == 0 ? IDC_PAR : IDC_AR);
1065                    SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_SETCURSEL, (config->display_aspect_ratio), 0);
1066                    SetDlgItemInt(hDlg, IDC_ARX, config->ar_x, FALSE);
1067                    SetDlgItemInt(hDlg, IDC_ARY, config->ar_y, FALSE);
1068                  break;                  break;
1069    
1070          case DLG_CREDITS :          case IDD_LEVEL :
1071                  config->credits_start = ISDLGSET(IDC_CREDITS_START);                  SendDlgItemMessage(hDlg, IDC_LEVEL_PROFILE, CB_SETCURSEL, config->profile, 0);
1072                  config->credits_start_begin = GetDlgItemInt(hDlg, IDC_CREDITS_START_BEGIN, NULL, FALSE);                  break;
                 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);  
1073    
1074  // added by koepi for gruel's greyscale_mode          case IDD_RC_CBR :
1075                  config->credits_greyscale = ISDLGSET(IDC_CREDITS_GREYSCALE);                  SetDlgItemInt(hDlg, IDC_CBR_REACTIONDELAY, config->rc_reaction_delay_factor, FALSE);
1076  // end of koepi's addition                  SetDlgItemInt(hDlg, IDC_CBR_AVERAGINGPERIOD, config->rc_averaging_period, FALSE);
1077                  config->credits_rate = config_get_uint(hDlg, IDC_CREDITS_RATE, config->credits_rate);                  SetDlgItemInt(hDlg, IDC_CBR_BUFFER, config->rc_buffer, FALSE);
1078                  config->credits_quant_i = config_get_uint(hDlg, IDC_CREDITS_QUANTI, config->credits_quant_i);                  break;
                 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);  
1079    
1080                  config->credits_mode = 0;          case IDD_RC_2PASS1 :
1081                  config->credits_mode = ISDLGSET(IDC_CREDITS_RATE_RADIO) ? CREDITS_MODE_RATE : config->credits_mode;                  SetDlgItemText(hDlg, IDC_STATS, config->stats);
1082                  config->credits_mode = ISDLGSET(IDC_CREDITS_QUANT_RADIO) ? CREDITS_MODE_QUANT : config->credits_mode;                  CheckDlg(hDlg, IDC_DISCARD1PASS, config->discard1pass);
1083                  config->credits_mode = ISDLGSET(IDC_CREDITS_SIZE_RADIO) ? CREDITS_MODE_SIZE : config->credits_mode;                  CheckDlg(hDlg, IDC_FULL1PASS, config->full1pass);
1084                    break;
1085    
1086                  CONSTRAINVAL(config->credits_rate, 1, 100);          case IDD_RC_2PASS2 :
1087                  CONSTRAINVAL(config->credits_quant_i, 1, 31);                  SetDlgItemText(hDlg, IDC_STATS, config->stats);
1088                  CONSTRAINVAL(config->credits_quant_p, 1, 31);                  SetDlgItemInt(hDlg, IDC_KFBOOST, config->keyframe_boost, FALSE);
1089                    SetDlgItemInt(hDlg, IDC_KFREDUCTION, config->kfreduction, FALSE);
1090    
1091                  if (config->credits_start_begin > config->credits_start_end)                  SetDlgItemInt(hDlg, IDC_OVERFLOW_CONTROL_STRENGTH, config->overflow_control_strength, FALSE);
1092                  {                  SetDlgItemInt(hDlg, IDC_OVERIMP, config->twopass_max_overflow_improvement, FALSE);
1093                          config->credits_start_begin = config->credits_start_end;                  SetDlgItemInt(hDlg, IDC_OVERDEG, config->twopass_max_overflow_degradation, FALSE);
1094                          config->credits_start = 0;  
1095                    SetDlgItemInt(hDlg, IDC_CURVECOMPH, config->curve_compression_high, FALSE);
1096                    SetDlgItemInt(hDlg, IDC_CURVECOMPL, config->curve_compression_low, FALSE);
1097                    SetDlgItemInt(hDlg, IDC_MINKEY, config->kfthreshold, FALSE);
1098                    break;
1099    
1100            case IDD_BITRATE :
1101                    SendDlgItemMessage(hDlg, IDC_BITRATE_CFORMAT, CB_SETCURSEL, config->container_type, 0);
1102                    SetDlgItemInt(hDlg, IDC_BITRATE_TSIZE, config->target_size, FALSE);
1103                    SetDlgItemInt(hDlg, IDC_BITRATE_SSIZE, config->subtitle_size, FALSE);
1104    
1105                    SetDlgItemInt(hDlg, IDC_BITRATE_HOURS, config->hours, FALSE);
1106                    SetDlgItemInt(hDlg, IDC_BITRATE_MINUTES, config->minutes, FALSE);
1107                    SetDlgItemInt(hDlg, IDC_BITRATE_SECONDS, config->seconds, FALSE);
1108                    SendDlgItemMessage(hDlg, IDC_BITRATE_FPS, CB_SETCURSEL, config->fps, 0);
1109    
1110                    SendDlgItemMessage(hDlg, IDC_BITRATE_AFORMAT, CB_SETCURSEL, config->audio_type, 0);
1111                    CheckRadioButton(hDlg, IDC_BITRATE_AMODE_RATE, IDC_BITRATE_AMODE_SIZE, config->audio_mode == 0 ? IDC_BITRATE_AMODE_RATE : IDC_BITRATE_AMODE_SIZE);
1112                    SetDlgItemInt(hDlg, IDC_BITRATE_ARATE, config->audio_rate, FALSE);
1113                    SetDlgItemInt(hDlg, IDC_BITRATE_ASIZE, config->audio_size, FALSE);
1114                    break;
1115    
1116            case IDD_ZONE :
1117                    SetDlgItemInt(hDlg, IDC_ZONE_FRAME, config->zones[config->cur_zone].frame, FALSE);
1118    
1119                    CheckDlgButton(hDlg, IDC_ZONE_MODE_WEIGHT,   config->zones[config->cur_zone].mode == RC_ZONE_WEIGHT);
1120                    CheckDlgButton(hDlg, IDC_ZONE_MODE_QUANT,                config->zones[config->cur_zone].mode == RC_ZONE_QUANT);
1121    
1122                    set_dlgitem_float(hDlg, IDC_ZONE_WEIGHT, config->zones[config->cur_zone].weight);
1123                    set_dlgitem_float(hDlg, IDC_ZONE_QUANT, config->zones[config->cur_zone].quant);
1124    
1125                    CheckDlgButton(hDlg, IDC_ZONE_FORCEIVOP, config->zones[config->cur_zone].type==XVID_TYPE_IVOP);
1126                    CheckDlgButton(hDlg, IDC_ZONE_GREYSCALE, config->zones[config->cur_zone].greyscale);
1127                    CheckDlgButton(hDlg, IDC_ZONE_CHROMAOPT, config->zones[config->cur_zone].chroma_opt);
1128    
1129                    SetDlgItemInt(hDlg, IDC_ZONE_BVOPTHRESHOLD, config->zones[config->cur_zone].bvop_threshold, TRUE);
1130                    break;
1131    
1132            case IDD_MOTION :
1133                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_SETCURSEL, config->motion_search, 0);
1134                    SendDlgItemMessage(hDlg, IDC_VHQ, CB_SETCURSEL, config->vhq_mode, 0);
1135                    CheckDlg(hDlg, IDC_CHROMAME, config->chromame);
1136                    CheckDlg(hDlg, IDC_CARTOON, config->cartoon_mode);
1137                    CheckDlg(hDlg, IDC_TURBO, config->turbo);
1138                    SetDlgItemInt(hDlg, IDC_FRAMEDROP, config->frame_drop_ratio, FALSE);
1139                    SetDlgItemInt(hDlg, IDC_MAXKEY, config->max_key_interval, FALSE);
1140                    break;
1141    
1142            case IDD_QUANT :
1143                    SetDlgItemInt(hDlg, IDC_MINIQUANT, config->min_iquant, FALSE);
1144                    SetDlgItemInt(hDlg, IDC_MAXIQUANT, config->max_iquant, FALSE);
1145                    SetDlgItemInt(hDlg, IDC_MINPQUANT, config->min_pquant, FALSE);
1146                    SetDlgItemInt(hDlg, IDC_MAXPQUANT, config->max_pquant, FALSE);
1147                    SetDlgItemInt(hDlg, IDC_MINBQUANT, config->min_bquant, FALSE);
1148                    SetDlgItemInt(hDlg, IDC_MAXBQUANT, config->max_bquant, FALSE);
1149                    CheckDlg(hDlg, IDC_TRELLISQUANT, config->trellis_quant);
1150                    break;
1151    
1152            case IDD_DEBUG :
1153                    CheckDlg(hDlg, IDC_CPU_MMX, (config->cpu & XVID_CPU_MMX));
1154                    CheckDlg(hDlg, IDC_CPU_MMXEXT, (config->cpu & XVID_CPU_MMXEXT));
1155                    CheckDlg(hDlg, IDC_CPU_SSE, (config->cpu & XVID_CPU_SSE));
1156                    CheckDlg(hDlg, IDC_CPU_SSE2, (config->cpu & XVID_CPU_SSE2));
1157                    CheckDlg(hDlg, IDC_CPU_3DNOW, (config->cpu & XVID_CPU_3DNOW));
1158                    CheckDlg(hDlg, IDC_CPU_3DNOWEXT, (config->cpu & XVID_CPU_3DNOWEXT));
1159    
1160                    CheckRadioButton(hDlg, IDC_CPU_AUTO, IDC_CPU_FORCE,
1161                            config->cpu & XVID_CPU_FORCE ? IDC_CPU_FORCE : IDC_CPU_AUTO );
1162    
1163                    SetDlgItemInt(hDlg, IDC_NUMTHREADS, config->num_threads, FALSE);
1164    
1165                    SendDlgItemMessage(hDlg, IDC_FOURCC, CB_SETCURSEL, config->fourcc_used, 0);
1166                    set_dlgitem_hex(hDlg, IDC_DEBUG, config->debug);
1167                    CheckDlg(hDlg, IDC_VOPDEBUG, config->vop_debug);
1168                    CheckDlg(hDlg, IDC_DISPLAY_STATUS, config->display_status);
1169                    break;
1170    
1171            case IDD_DEC :
1172                    SendDlgItemMessage(hDlg, IDC_DEC_BRIGHTNESS, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)pp_brightness);
1173                    CheckDlg(hDlg, IDC_DEC_DY,      pp_dy);
1174                    CheckDlg(hDlg, IDC_DEC_DUV,     pp_duv);
1175                    CheckDlg(hDlg, IDC_DEC_DRY,     pp_dry);
1176                    CheckDlg(hDlg, IDC_DEC_DRUV,pp_druv);
1177                    CheckDlg(hDlg, IDC_DEC_FE,      pp_fe);
1178                    EnableDlgWindow(hDlg, IDC_DEC_DRY, pp_dy);
1179                    EnableDlgWindow(hDlg, IDC_DEC_DRUV, pp_duv);
1180                    break;
1181                  }                  }
1182                  if (config->credits_end_begin > config->credits_end_end)  }
1183    
1184    
1185    /* download config data from dialog */
1186    
1187    static void adv_download(HWND hDlg, int idd, CONFIG * config)
1188    {
1189            switch (idd)
1190                  {                  {
1191                          config->credits_end_begin = config->credits_end_end;          case IDD_PROFILE :
1192                          config->credits_end = 0;                  config->profile = SendDlgItemMessage(hDlg, IDC_PROFILE_PROFILE, CB_GETCURSEL, 0, 0);
1193    
1194                    config->quant_type = SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_GETCURSEL, 0, 0);
1195                    config->lum_masking = IsDlgChecked(hDlg, IDC_LUMMASK);
1196                    config->interlacing = IsDlgChecked(hDlg, IDC_INTERLACING);
1197                    config->qpel = IsDlgChecked(hDlg, IDC_QPEL);
1198                    config->gmc = IsDlgChecked(hDlg, IDC_GMC);
1199                    config->reduced_resolution = IsDlgChecked(hDlg, IDC_REDUCED);
1200    
1201                    config->use_bvop = IsDlgChecked(hDlg, IDC_BVOP);
1202                    config->max_bframes = config_get_uint(hDlg, IDC_MAXBFRAMES, config->max_bframes);
1203                    config->bquant_ratio = get_dlgitem_float(hDlg, IDC_BQUANTRATIO, config->bquant_ratio);
1204                    config->bquant_offset = get_dlgitem_float(hDlg, IDC_BQUANTOFFSET, config->bquant_offset);
1205                    config->packed = IsDlgChecked(hDlg, IDC_PACKED);
1206                    config->closed_gov = IsDlgChecked(hDlg, IDC_CLOSEDGOV);
1207                    break;
1208    
1209            case IDD_AR:
1210                    config->ar_mode = IsDlgChecked(hDlg, IDC_PAR) ? 0:1;
1211                    config->ar_x = config_get_uint(hDlg, IDC_ARX, config->ar_x);
1212                    config->ar_y = config_get_uint(hDlg, IDC_ARY, config->ar_y);
1213                    config->display_aspect_ratio = SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_GETCURSEL, 0, 0);
1214                    if (config->display_aspect_ratio == 5) {
1215                            config->par_x = config_get_uint(hDlg, IDC_PARX, config->par_x);
1216                            config->par_y = config_get_uint(hDlg, IDC_PARY, config->par_y);
1217                  }                  }
1218                  break;                  break;
1219    
1220          case DLG_CPU :          case IDD_LEVEL :
1221                  config->cpu = 0;                  config->profile = SendDlgItemMessage(hDlg, IDC_LEVEL_PROFILE, CB_GETCURSEL, 0, 0);
1222                  config->cpu |= ISDLGSET(IDC_CPU_MMX) ? XVID_CPU_MMX : 0;                  break;
                 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;  
1223    
1224                  config->num_threads = config_get_uint(hDlg, IDC_NUMTHREADS, config->num_threads);          case IDD_RC_CBR :
                 config->chroma_opt = ISDLGSET(IDC_CHROMA_OPT);  
                 config->frame_drop_ratio = config_get_uint(hDlg, IDC_FRAMEDROP, config->frame_drop_ratio);  
1225                  config->rc_reaction_delay_factor = config_get_uint(hDlg, IDC_CBR_REACTIONDELAY, config->rc_reaction_delay_factor);                  config->rc_reaction_delay_factor = config_get_uint(hDlg, IDC_CBR_REACTIONDELAY, config->rc_reaction_delay_factor);
1226                  config->rc_averaging_period = config_get_uint(hDlg, IDC_CBR_AVERAGINGPERIOD, config->rc_averaging_period);                  config->rc_averaging_period = config_get_uint(hDlg, IDC_CBR_AVERAGINGPERIOD, config->rc_averaging_period);
1227                  config->rc_buffer = config_get_uint(hDlg, IDC_CBR_BUFFER, config->rc_buffer);                  config->rc_buffer = config_get_uint(hDlg, IDC_CBR_BUFFER, config->rc_buffer);
1228                  break;                  break;
         }  
 }  
1229    
1230            case IDD_RC_2PASS1 :
1231                    if (GetDlgItemText(hDlg, IDC_STATS, config->stats, MAX_PATH) == 0)
1232                            lstrcpy(config->stats, CONFIG_2PASS_FILE);
1233                    config->discard1pass = IsDlgChecked(hDlg, IDC_DISCARD1PASS);
1234                    config->full1pass = IsDlgChecked(hDlg, IDC_FULL1PASS);
1235                    break;
1236    
1237  void quant_upload(HWND hDlg, CONFIG* config)          case IDD_RC_2PASS2 :
1238  {                  if (GetDlgItemText(hDlg, IDC_STATS, config->stats, MAX_PATH) == 0)
1239          int i;                          lstrcpy(config->stats, CONFIG_2PASS_FILE);
1240    
1241          for (i=0 ; i<64 ; ++i)                  config->keyframe_boost = GetDlgItemInt(hDlg, IDC_KFBOOST, NULL, FALSE);
1242          {                  config->kfreduction = GetDlgItemInt(hDlg, IDC_KFREDUCTION, NULL, FALSE);
1243                  SetDlgItemInt(hDlg, IDC_QINTRA00 + i, config->qmatrix_intra[i], FALSE);                  CONSTRAINVAL(config->keyframe_boost, 0, 1000);
                 SetDlgItemInt(hDlg, IDC_QINTER00 + i, config->qmatrix_inter[i], FALSE);  
         }  
 }  
1244    
1245                    config->overflow_control_strength = GetDlgItemInt(hDlg, IDC_OVERFLOW_CONTROL_STRENGTH, NULL, FALSE);
1246                    config->twopass_max_overflow_improvement = config_get_uint(hDlg, IDC_OVERIMP, config->twopass_max_overflow_improvement);
1247                    config->twopass_max_overflow_degradation = config_get_uint(hDlg, IDC_OVERDEG, config->twopass_max_overflow_degradation);
1248                    CONSTRAINVAL(config->twopass_max_overflow_improvement, 1, 80);
1249                    CONSTRAINVAL(config->twopass_max_overflow_degradation, 1, 80);
1250                    CONSTRAINVAL(config->overflow_control_strength, 0, 100);
1251    
1252  void quant_download(HWND hDlg, CONFIG* config)                  config->curve_compression_high = GetDlgItemInt(hDlg, IDC_CURVECOMPH, NULL, FALSE);
1253  {                  config->curve_compression_low = GetDlgItemInt(hDlg, IDC_CURVECOMPL, NULL, FALSE);
1254          int i;                  CONSTRAINVAL(config->curve_compression_high, 0, 100);
1255                    CONSTRAINVAL(config->curve_compression_low, 0, 100);
1256    
1257          for (i=0 ; i<64 ; ++i)                  config->kfthreshold = config_get_uint(hDlg, IDC_MINKEY, config->kfthreshold);
         {  
                 int temp;  
1258    
1259                  temp = config_get_uint(hDlg, i + IDC_QINTRA00, config->qmatrix_intra[i]);                  break;
                 CONSTRAINVAL(temp, 1, 255);  
                 config->qmatrix_intra[i] = temp;  
1260    
1261                  temp = config_get_uint(hDlg, i + IDC_QINTER00, config->qmatrix_inter[i]);          case IDD_BITRATE :
1262                  CONSTRAINVAL(temp, 1, 255);                  config->container_type = SendDlgItemMessage(hDlg, IDC_BITRATE_CFORMAT, CB_GETCURSEL, 0, 0);
1263                  config->qmatrix_inter[i] = temp;                  config->target_size = config_get_uint(hDlg, IDC_BITRATE_TSIZE, config->target_size);
1264          }                  config->subtitle_size = config_get_uint(hDlg, IDC_BITRATE_SSIZE, config->subtitle_size);
 }  
1265    
1266                    config->hours = config_get_uint(hDlg, IDC_BITRATE_HOURS, config->hours);
1267                    config->minutes = config_get_uint(hDlg, IDC_BITRATE_MINUTES, config->minutes);
1268                    config->seconds = config_get_uint(hDlg, IDC_BITRATE_SECONDS, config->seconds);
1269                    config->fps = SendDlgItemMessage(hDlg, IDC_BITRATE_FPS, CB_GETCURSEL, 0, 0);
1270    
1271  /* enumerates child windows, assigns tooltips */                  config->audio_type = SendDlgItemMessage(hDlg, IDC_BITRATE_AFORMAT, CB_GETCURSEL, 0, 0);
1272                    config->audio_mode = IsDlgChecked(hDlg, IDC_BITRATE_AMODE_SIZE) ? 1 : 0 ;
1273                    config->audio_rate = config_get_uint(hDlg, IDC_BITRATE_ARATE, config->audio_rate);
1274                    config->audio_size = config_get_uint(hDlg, IDC_BITRATE_ASIZE, config->audio_size);
1275    
1276  BOOL CALLBACK enum_tooltips(HWND hWnd, LPARAM lParam)                  /* the main window uses "AVI bitrate/filesize" not "video bitrate/filesize",
1277                       so we have to compensate by frames * 24 bytes */
1278  {  {
1279          char help[500];                          int frame_compensate = 24 * (int)(
1280                                    (3600*config->hours +
1281                                       60*config->minutes +
1282                                          config->seconds) * video_fps_list[config->fps].value) / 1024;
1283    
1284          if (LoadString(hInst, GetDlgCtrlID(hWnd), help, 500))                          int bitrate_compensate = (int)(24 * video_fps_list[config->fps].value) / 125;
         {  
                 TOOLINFO ti;  
1285    
1286                  ti.cbSize = sizeof(TOOLINFO);                          config->desired_size =
1287                  ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;                                                  config_get_uint(hDlg, IDC_BITRATE_VSIZE, config->desired_size) + frame_compensate;
                 ti.hwnd = GetParent(hWnd);  
                 ti.uId  = (LPARAM)hWnd;  
                 ti.lpszText = help;  
1288    
1289                  SendMessage(hTooltip, TTM_ADDTOOL, 0, (LPARAM)&ti);                          config->bitrate =
1290                                                    config_get_uint(hDlg, IDC_BITRATE_VRATE, config->bitrate) + bitrate_compensate;
1291          }          }
1292                    break;
1293    
1294          return TRUE;          case IDD_ZONE :
1295                    config->zones[config->cur_zone].frame = config_get_uint(hDlg, IDC_ZONE_FRAME, config->zones[config->cur_zone].frame);
1296    
1297                    if (IsDlgChecked(hDlg, IDC_ZONE_MODE_WEIGHT)) {
1298                            config->zones[config->cur_zone].mode = RC_ZONE_WEIGHT;
1299                    }else if (IsDlgChecked(hDlg, IDC_ZONE_MODE_QUANT)) {
1300                            config->zones[config->cur_zone].mode = RC_ZONE_QUANT;
1301  }  }
1302    
1303                    config->zones[config->cur_zone].weight = get_dlgitem_float(hDlg, IDC_ZONE_WEIGHT, config->zones[config->cur_zone].weight);
1304                    config->zones[config->cur_zone].quant =  get_dlgitem_float(hDlg, IDC_ZONE_QUANT, config->zones[config->cur_zone].quant);
1305    
1306                    config->zones[config->cur_zone].type = IsDlgButtonChecked(hDlg, IDC_ZONE_FORCEIVOP)?XVID_TYPE_IVOP:XVID_TYPE_AUTO;
1307                    config->zones[config->cur_zone].greyscale = IsDlgButtonChecked(hDlg, IDC_ZONE_GREYSCALE);
1308                    config->zones[config->cur_zone].chroma_opt = IsDlgButtonChecked(hDlg, IDC_ZONE_CHROMAOPT);
1309    
1310                    config->zones[config->cur_zone].bvop_threshold = config_get_int(hDlg, IDC_ZONE_BVOPTHRESHOLD, config->zones[config->cur_zone].bvop_threshold);
1311                    break;
1312    
1313  /* --- decoder options dialog  --- */          case IDD_MOTION :
1314                    config->motion_search = SendDlgItemMessage(hDlg, IDC_MOTION, CB_GETCURSEL, 0, 0);
1315                    config->vhq_mode = SendDlgItemMessage(hDlg, IDC_VHQ, CB_GETCURSEL, 0, 0);
1316                    config->chromame = IsDlgChecked(hDlg, IDC_CHROMAME);
1317                    config->cartoon_mode = IsDlgChecked(hDlg, IDC_CARTOON);
1318                    config->turbo = IsDlgChecked(hDlg, IDC_TURBO);
1319    
1320  #define DEC_DLG_COUNT   1                  config->frame_drop_ratio = config_get_uint(hDlg, IDC_FRAMEDROP, config->frame_drop_ratio);
 #define DEC_DLG_POSTPROC        0  
1321    
1322  /* decoder dialog: upload config data */                  config->max_key_interval = config_get_uint(hDlg, IDC_MAXKEY, config->max_key_interval);
1323                    break;
1324    
1325  void dec_upload(HWND hDlg, int page, CONFIG * config)          case IDD_QUANT :
1326  {                  config->min_iquant = config_get_uint(hDlg, IDC_MINIQUANT, config->min_iquant);
1327          switch (page)                  config->max_iquant = config_get_uint(hDlg, IDC_MAXIQUANT, config->max_iquant);
1328          {                  config->min_pquant = config_get_uint(hDlg, IDC_MINPQUANT, config->min_pquant);
1329          case DEC_DLG_POSTPROC :                  config->max_pquant = config_get_uint(hDlg, IDC_MAXPQUANT, config->max_pquant);
1330                  CheckDlgButton(hDlg, IDC_DEBLOCK_Y,  config->deblock_y ? BST_CHECKED : BST_UNCHECKED);                  config->min_bquant = config_get_uint(hDlg, IDC_MINBQUANT, config->min_bquant);
1331                  CheckDlgButton(hDlg, IDC_DEBLOCK_UV, config->deblock_uv ? BST_CHECKED : BST_UNCHECKED);                  config->max_bquant = config_get_uint(hDlg, IDC_MAXBQUANT, config->max_bquant);
1332    
1333                    CONSTRAINVAL(config->min_iquant, 1, 31);
1334                    CONSTRAINVAL(config->max_iquant, config->min_iquant, 31);
1335                    CONSTRAINVAL(config->min_pquant, 1, 31);
1336                    CONSTRAINVAL(config->max_pquant, config->min_pquant, 31);
1337                    CONSTRAINVAL(config->min_bquant, 1, 31);
1338                    CONSTRAINVAL(config->max_bquant, config->min_bquant, 31);
1339    
1340                    config->trellis_quant = IsDlgChecked(hDlg, IDC_TRELLISQUANT);
1341                  break;                  break;
         }  
 }  
1342    
1343            case IDD_DEBUG :
1344                    config->cpu = 0;
1345                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_MMX)    ? XVID_CPU_MMX : 0;
1346                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_MMXEXT)   ? XVID_CPU_MMXEXT : 0;
1347                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_SSE)    ? XVID_CPU_SSE : 0;
1348                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_SSE2)  ? XVID_CPU_SSE2 : 0;
1349                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_3DNOW)        ? XVID_CPU_3DNOW : 0;
1350                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_3DNOWEXT) ? XVID_CPU_3DNOWEXT : 0;
1351                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_FORCE)        ? XVID_CPU_FORCE : 0;
1352    
1353                    config->num_threads = config_get_uint(hDlg, IDC_NUMTHREADS, config->num_threads);
1354    
1355  /* dec dialog: download config data */                  config->fourcc_used = SendDlgItemMessage(hDlg, IDC_FOURCC, CB_GETCURSEL, 0, 0);
1356                    config->debug = get_dlgitem_hex(hDlg, IDC_DEBUG, config->debug);
1357                    config->vop_debug = IsDlgChecked(hDlg, IDC_VOPDEBUG);
1358                    config->display_status = IsDlgChecked(hDlg, IDC_DISPLAY_STATUS);
1359                    break;
1360    
1361  void dec_download(HWND hDlg, int page, CONFIG * config)          case IDD_DEC :
1362  {                  pp_brightness = SendDlgItemMessage(hDlg, IDC_DEC_BRIGHTNESS, TBM_GETPOS, (WPARAM)NULL, (LPARAM)NULL);
1363          switch (page)                  pp_dy = IsDlgChecked(hDlg, IDC_DEC_DY);
1364          {                  pp_duv = IsDlgChecked(hDlg, IDC_DEC_DUV);
1365          case DEC_DLG_POSTPROC :                  pp_dry = IsDlgChecked(hDlg, IDC_DEC_DRY);
1366                  config->deblock_y = ISDLGSET(IDC_DEBLOCK_Y);                  pp_druv = IsDlgChecked(hDlg, IDC_DEC_DRUV);
1367                  config->deblock_uv = ISDLGSET(IDC_DEBLOCK_UV);                  pp_fe = IsDlgChecked(hDlg, IDC_DEC_FE);
1368                  break;                  break;
1369          }          }
1370  }  }
1371    
 /* decoder dialog proc */  
1372    
1373  BOOL CALLBACK dec_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)  
1374    /* advanced dialog proc */
1375    
1376    static BOOL CALLBACK adv_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1377  {  {
1378          PROPSHEETINFO *psi;          PROPSHEETINFO *psi;
1379    
# Line 1022  Line 1383 
1383          {          {
1384          case WM_INITDIALOG :          case WM_INITDIALOG :
1385                  psi = (PROPSHEETINFO*) ((LPPROPSHEETPAGE)lParam)->lParam;                  psi = (PROPSHEETINFO*) ((LPPROPSHEETPAGE)lParam)->lParam;
   
1386                  SetWindowLong(hDlg, GWL_USERDATA, (LPARAM)psi);                  SetWindowLong(hDlg, GWL_USERDATA, (LPARAM)psi);
1387    
1388                  if (hTooltip)                  if (g_hTooltip)
                 {  
1389                          EnumChildWindows(hDlg, enum_tooltips, 0);                          EnumChildWindows(hDlg, enum_tooltips, 0);
1390    
1391                    adv_init(hDlg, psi->idd, psi->config);
1392                    break;
1393    
1394            case WM_COMMAND :
1395                    if (HIWORD(wParam) == BN_CLICKED)
1396                    {
1397                            switch (LOWORD(wParam))
1398                            {
1399                            case IDC_BVOP :
1400                            case IDC_ZONE_MODE_WEIGHT :
1401                            case IDC_ZONE_MODE_QUANT :
1402                            case IDC_ZONE_BVOPTHRESHOLD_ENABLE :
1403                            case IDC_CPU_AUTO :
1404                            case IDC_CPU_FORCE :
1405                            case IDC_AR :
1406                            case IDC_PAR :
1407                            case IDC_BITRATE_AMODE_RATE :
1408                            case IDC_BITRATE_AMODE_SIZE :
1409                                    adv_mode(hDlg, psi->idd, psi->config);
1410                                    break;
1411    
1412                            case IDC_BITRATE_SSELECT :
1413                            case IDC_BITRATE_ASELECT :
1414                                    {
1415                                    OPENFILENAME ofn;
1416                                    char filename[MAX_PATH] = "";
1417    
1418                                    memset(&ofn, 0, sizeof(OPENFILENAME));
1419                                    ofn.lStructSize = sizeof(OPENFILENAME);
1420    
1421                                    ofn.hwndOwner = hDlg;
1422                                    if (LOWORD(wParam)==IDC_BITRATE_SSELECT) {
1423                                            ofn.lpstrFilter = "Subtitle files (*.sub, *.ssa)\0*.sub;*.ssa\0All files (*.*)\0*.*\0\0";
1424                                    }else{
1425                                            ofn.lpstrFilter = "Audio files (*.mp3, *.ac3)\0*.mp3; *.ac3\0All files (*.*)\0*.*\0\0";
1426                                    }
1427    
1428                                    ofn.lpstrFile = filename;
1429                                    ofn.nMaxFile = MAX_PATH;
1430                                    ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
1431    
1432                                    if (GetOpenFileName(&ofn)) {
1433                                            HANDLE hFile;
1434                                            DWORD filesize;
1435    
1436                                            if ((hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)) == INVALID_HANDLE_VALUE ||
1437                                                    (filesize = GetFileSize(hFile, NULL)) == INVALID_FILE_SIZE) {
1438                                                    MessageBox(hDlg, "Could not get file size", "Error", 0);
1439                                            }else{
1440                                                    SetDlgItemInt(hDlg,
1441                                                                    LOWORD(wParam)==IDC_BITRATE_SSELECT? IDC_BITRATE_SSIZE : IDC_BITRATE_ASIZE,
1442                                                                    filesize / 1024, FALSE);
1443                                                    CloseHandle(hFile);
1444                                            }
1445                                    }
1446                  }                  }
1447                                    break;
1448    
1449                  dec_upload(hDlg, psi->page, psi->config);                          case IDC_QUANTMATRIX :
1450                                    DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_QUANTMATRIX), hDlg, quantmatrix_proc, (LPARAM)psi->config);
1451                  break;                  break;
1452    
1453                            case IDC_STATS_BROWSE :
1454                            {
1455                                    OPENFILENAME ofn;
1456                                    char tmp[MAX_PATH];
1457    
1458                                    GetDlgItemText(hDlg, IDC_STATS, tmp, MAX_PATH);
1459    
1460                                    memset(&ofn, 0, sizeof(OPENFILENAME));
1461                                    ofn.lStructSize = sizeof(OPENFILENAME);
1462    
1463                                    ofn.hwndOwner = hDlg;
1464                                    ofn.lpstrFilter = "bitrate curve (*.pass)\0*.pass\0All files (*.*)\0*.*\0\0";
1465                                    ofn.lpstrFile = tmp;
1466                                    ofn.nMaxFile = MAX_PATH;
1467                                    ofn.Flags = OFN_PATHMUSTEXIST;
1468    
1469                                    if (psi->idd == IDD_RC_2PASS1) {
1470                                            ofn.Flags |= OFN_OVERWRITEPROMPT;
1471                                    }else{
1472                                            ofn.Flags |= OFN_FILEMUSTEXIST;
1473                                    }
1474    
1475                                    if ((psi->idd==IDD_RC_2PASS1 && GetSaveFileName(&ofn)) ||
1476                                            (psi->idd==IDD_RC_2PASS2 && GetOpenFileName(&ofn))) {
1477                                            SetDlgItemText(hDlg, IDC_STATS, tmp);
1478                                    }
1479                                    }
1480                                    break;
1481    
1482                            case IDC_ZONE_FETCH :
1483                                    SetDlgItemInt(hDlg, IDC_ZONE_FRAME, psi->config->ci.ciActiveFrame, FALSE);
1484                                    break;
1485    
1486                            case IDC_AR_DEFAULT:
1487                                    CheckRadioButton(hDlg, IDC_AR, IDC_PAR, IDC_PAR);
1488                                    SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_SETCURSEL, 0, 0);
1489                                    adv_mode(hDlg, psi->idd, psi->config);
1490                                    break;
1491                            case IDC_AR_4_3:
1492                                    SetDlgItemInt(hDlg, IDC_ARX, 4, FALSE);
1493                                    SetDlgItemInt(hDlg, IDC_ARY, 3, FALSE);
1494                                    CheckRadioButton(hDlg, IDC_AR, IDC_PAR, IDC_AR);
1495                                    adv_mode(hDlg, psi->idd, psi->config);
1496                                    break;
1497                            case IDC_AR_16_9:
1498                                    SetDlgItemInt(hDlg, IDC_ARX, 16, FALSE);
1499                                    SetDlgItemInt(hDlg, IDC_ARY, 9, FALSE);
1500                                    CheckRadioButton(hDlg, IDC_AR, IDC_PAR, IDC_AR);
1501                                    adv_mode(hDlg, psi->idd, psi->config);
1502                                    break;
1503                            case IDC_AR_235_100:
1504                                    SetDlgItemInt(hDlg, IDC_ARX, 235, FALSE);
1505                                    SetDlgItemInt(hDlg, IDC_ARY, 100, FALSE);
1506                                    CheckRadioButton(hDlg, IDC_AR, IDC_PAR, IDC_AR);
1507                                    adv_mode(hDlg, psi->idd, psi->config);
1508                                    break;
1509                            case IDC_DEC_DY:
1510                            case IDC_DEC_DUV:
1511                                    EnableDlgWindow(hDlg, IDC_DEC_DRY, IsDlgChecked(hDlg, IDC_DEC_DY));
1512                                    EnableDlgWindow(hDlg, IDC_DEC_DRUV, IsDlgChecked(hDlg, IDC_DEC_DUV));
1513                                    break;
1514                            default :
1515                                    return TRUE;
1516                            }
1517                    }else if ((HIWORD(wParam) == CBN_EDITCHANGE || HIWORD(wParam)==CBN_SELCHANGE) &&
1518                            (LOWORD(wParam)==IDC_BITRATE_TSIZE ||
1519                             LOWORD(wParam)==IDC_BITRATE_ARATE )) {
1520    
1521                            adv_mode(hDlg, psi->idd, psi->config);
1522    
1523                    }else if (HIWORD(wParam) == LBN_SELCHANGE &&
1524                            (LOWORD(wParam) == IDC_PROFILE_PROFILE ||
1525                             LOWORD(wParam) == IDC_LEVEL_PROFILE ||
1526                             LOWORD(wParam) == IDC_QUANTTYPE ||
1527                             LOWORD(wParam) == IDC_ASPECT_RATIO ||
1528                             LOWORD(wParam) == IDC_BITRATE_CFORMAT ||
1529                             LOWORD(wParam) == IDC_BITRATE_AFORMAT ||
1530                             LOWORD(wParam) == IDC_BITRATE_FPS)) {
1531                            adv_mode(hDlg, psi->idd, psi->config);
1532                    }else if (HIWORD(wParam) == EN_UPDATE && (LOWORD(wParam)==IDC_ZONE_WEIGHT || LOWORD(wParam)==IDC_ZONE_QUANT)) {
1533    
1534                            SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETPOS, TRUE,
1535                                            get_dlgitem_float(hDlg, LOWORD(wParam), 100));
1536    
1537                    } else if (HIWORD(wParam) == EN_UPDATE && (LOWORD(wParam)==IDC_PARX || LOWORD(wParam)==IDC_PARY)) {
1538    
1539                            if (5 == SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_GETCURSEL, 0, 0)) {
1540                                    if(LOWORD(wParam)==IDC_PARX)
1541                                            psi->config->par_x = config_get_uint(hDlg, LOWORD(wParam), psi->config->par_x);
1542                                    else
1543                                            psi->config->par_y = config_get_uint(hDlg, LOWORD(wParam), psi->config->par_y);
1544                            }
1545                    } else if (HIWORD(wParam) == EN_UPDATE &&
1546                            (LOWORD(wParam)==IDC_BITRATE_SSIZE ||
1547                             LOWORD(wParam)==IDC_BITRATE_HOURS ||
1548                             LOWORD(wParam)==IDC_BITRATE_MINUTES ||
1549                             LOWORD(wParam)==IDC_BITRATE_SECONDS ||
1550                             LOWORD(wParam)==IDC_BITRATE_ASIZE)) {
1551                            adv_mode(hDlg, psi->idd, psi->config);
1552                    } else
1553                            return 0;
1554                    break;
1555    
1556            case WM_HSCROLL :
1557                    if((HWND)lParam == GetDlgItem(hDlg, IDC_ZONE_SLIDER)) {
1558                            int idc = IsDlgChecked(hDlg, IDC_ZONE_MODE_WEIGHT) ? IDC_ZONE_WEIGHT : IDC_ZONE_QUANT;
1559                            set_dlgitem_float(hDlg, idc, SendMessage((HWND)lParam, TBM_GETPOS, 0, 0) );
1560                            break;
1561                    }
1562                    return 0;
1563    
1564    
1565          case WM_NOTIFY :          case WM_NOTIFY :
1566                  switch (((NMHDR *)lParam)->code)                  switch (((NMHDR *)lParam)->code)
1567                  {                  {
1568                    case PSN_SETACTIVE :
1569                            DPRINTF("PSN_SET");
1570                            adv_upload(hDlg, psi->idd, psi->config);
1571                            adv_mode(hDlg, psi->idd, psi->config);
1572                            SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
1573                            break;
1574    
1575                  case PSN_KILLACTIVE :                  case PSN_KILLACTIVE :
1576                          /* validate */                          DPRINTF("PSN_KILL");
1577                          dec_download(hDlg, psi->page, psi->config);                          adv_download(hDlg, psi->idd, psi->config);
1578                          SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);                          SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
1579                          break;                          break;
1580    
1581                  case PSN_APPLY :                  case PSN_APPLY :
1582                          /* apply */                          DPRINTF("PSN_APPLY");
                         dec_download(hDlg, psi->page, psi->config);  
                         SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);  
1583                          psi->config->save = TRUE;                          psi->config->save = TRUE;
1584                            SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
1585                          break;                          break;
1586                  }                  }
1587                  break;                  break;
# Line 1059  Line 1594 
1594  }  }
1595    
1596    
1597  void dec_dialog(HWND hParent, CONFIG * config)  
1598    
1599    /* load advanced options property sheet
1600      returns true, if the user accepted the changes
1601      or fasle if changes were canceled.
1602    
1603      */
1604    
1605    #ifndef PSH_NOCONTEXTHELP
1606    #define PSH_NOCONTEXTHELP 0x02000000
1607    #endif
1608    
1609    static BOOL adv_dialog(HWND hParent, CONFIG * config, const int * dlgs, int size)
1610  {  {
1611          PROPSHEETINFO psi[DEC_DLG_COUNT];          PROPSHEETINFO psi[6];
1612          PROPSHEETPAGE psp[DEC_DLG_COUNT];          PROPSHEETPAGE psp[6];
1613          PROPSHEETHEADER psh;          PROPSHEETHEADER psh;
1614          CONFIG temp;          CONFIG temp;
1615          int i;          int i;
# Line 1070  Line 1617 
1617          config->save = FALSE;          config->save = FALSE;
1618          memcpy(&temp, config, sizeof(CONFIG));          memcpy(&temp, config, sizeof(CONFIG));
1619    
1620          for (i=0 ; i<DEC_DLG_COUNT ; ++i)          for (i=0; i<size; i++)
1621          {          {
1622                  psp[i].dwSize = sizeof(PROPSHEETPAGE);                  psp[i].dwSize = sizeof(PROPSHEETPAGE);
1623                  psp[i].dwFlags = 0;                  psp[i].dwFlags = 0;
1624                  psp[i].hInstance = hInst;                  psp[i].hInstance = g_hInst;
1625                  psp[i].pfnDlgProc = dec_proc;                  psp[i].pfnDlgProc = adv_proc;
1626                  psp[i].lParam = (LPARAM)&psi[i];                  psp[i].lParam = (LPARAM)&psi[i];
1627                  psp[i].pfnCallback = NULL;                  psp[i].pfnCallback = NULL;
1628                    psp[i].pszTemplate = MAKEINTRESOURCE(dlgs[i]);
1629    
1630                  psi[i].page = i;                  psi[i].idd = dlgs[i];
1631                  psi[i].config = &temp;                  psi[i].config = &temp;
1632          }          }
1633    
         psp[DEC_DLG_POSTPROC].pszTemplate = MAKEINTRESOURCE(IDD_POSTPROC);  
   
1634          psh.dwSize = sizeof(PROPSHEETHEADER);          psh.dwSize = sizeof(PROPSHEETHEADER);
1635          psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;          psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW | PSH_NOCONTEXTHELP;
1636          psh.hwndParent = hParent;          psh.hwndParent = hParent;
1637          psh.hInstance = hInst;          psh.hInstance = g_hInst;
1638          psh.pszCaption = (LPSTR) "XviD Configuration";          psh.pszCaption = (LPSTR) "XviD Configuration";
1639          psh.nPages = DEC_DLG_COUNT;          psh.nPages = size;
1640          psh.nStartPage = DEC_DLG_POSTPROC;          psh.nStartPage = 0;
1641          psh.ppsp = (LPCPROPSHEETPAGE)&psp;          psh.ppsp = (LPCPROPSHEETPAGE)&psp;
1642          psh.pfnCallback = NULL;          psh.pfnCallback = NULL;
   
1643          PropertySheet(&psh);          PropertySheet(&psh);
1644    
1645          if (temp.save)          if (temp.save)
         {  
1646                  memcpy(config, &temp, sizeof(CONFIG));                  memcpy(config, &temp, sizeof(CONFIG));
1647          }  
1648            return temp.save;
1649  }  }
1650    
1651    /* ===================================================================================== */
1652    /* MAIN DIALOG ========================================================================= */
1653    /* ===================================================================================== */
1654    
1655    
1656  /* main dialog proc */  static void main_insert_zone(HWND hDlg, zone_t * s, int i, BOOL insert)
   
 BOOL CALLBACK main_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)  
1657  {  {
1658          CONFIG* config = (CONFIG*)GetWindowLong(hDlg, GWL_USERDATA);          char tmp[32];
1659    
1660          switch (uMsg)          wsprintf(tmp,"%i",s->frame);
         {  
         case WM_INITDIALOG :  
                 SetWindowLong(hDlg, GWL_USERDATA, lParam);  
1661    
1662                  config = (CONFIG*)lParam;          if (insert) {
1663                    LVITEM lvi;
1664    
1665                  SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"1 Pass - CBR");                  lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
1666                  SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"1 Pass - quality");                  lvi.state = 0;
1667                  SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"1 Pass - quantizer");                  lvi.stateMask = 0;
1668                  SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"2 Pass - 1st pass");                  lvi.iImage = 0;
1669                  SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"2 Pass - 2nd pass Ext.");                  lvi.pszText = tmp;
1670                  SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"2 Pass - 2nd pass Int.");                  lvi.cchTextMax = strlen(tmp);
1671                  SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"Null - test speed");                  lvi.iItem = i;
1672                    lvi.iSubItem = 0;
1673                    ListView_InsertItem(hDlg, &lvi);
1674            }else{
1675                    ListView_SetItemText(hDlg, i, 0, tmp);
1676            }
1677    
1678                  SendDlgItemMessage(hDlg, IDC_MODE, CB_SETCURSEL, config->mode, 0);          if (s->mode == RC_ZONE_WEIGHT) {
1679                    sprintf(tmp,"W %.2f",(float)s->weight/100);
1680            }else if (s->mode == RC_ZONE_QUANT) {
1681                    sprintf(tmp,"Q %.2f",(float)s->quant/100);
1682            }else {
1683                    strcpy(tmp,"EXT");
1684            }
1685            ListView_SetItemText(hDlg, i, 1, tmp);
1686    
1687                  InitCommonControls();          tmp[0] = '\0';
1688            if (s->type==XVID_TYPE_IVOP)
1689                    strcat(tmp, "K ");
1690    
1691                  if ((hTooltip = CreateWindow(TOOLTIPS_CLASS, NULL, TTS_ALWAYSTIP,          if (s->greyscale)
1692                                  CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,                  strcat(tmp, "G ");
                                 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);  
1693    
1694                          EnumChildWindows(hDlg, enum_tooltips, 0);          if (s->chroma_opt)
1695                    strcat(tmp, "C ");
1696    
1697            ListView_SetItemText(hDlg, i, 2, tmp);
1698                  }                  }
1699    
                 main_slider(hDlg, config);  
                 main_value(hDlg, config);  
                 break;  
1700    
1701          case WM_HSCROLL :  static void main_mode(HWND hDlg, CONFIG * config)
                 if((HWND)lParam == GetDlgItem(hDlg, IDC_SLIDER))  
                 {  
                         SetDlgItemInt(hDlg, IDC_VALUE, SendMessage((HWND)lParam, TBM_GETPOS, 0, 0), FALSE);  
                 }  
                 else  
1702                  {                  {
1703                          return 0;          const int profile = SendDlgItemMessage(hDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0);
1704                  }          const int rc_mode = SendDlgItemMessage(hDlg, IDC_MODE, CB_GETCURSEL, 0, 0);
1705                  break;          /* enable target rate/size control only for 1pass and 2pass  modes*/
1706            const int target_en = rc_mode==RC_MODE_1PASS || rc_mode==RC_MODE_2PASS2;
1707            const int target_en_slider = rc_mode==RC_MODE_1PASS ||
1708                    (rc_mode==RC_MODE_2PASS2 && config->use_2pass_bitrate);
1709    
1710          case WM_COMMAND :          char buf[16];
1711                  if (LOWORD(wParam) == IDC_MODE && HIWORD(wParam) == LBN_SELCHANGE)          int max;
                 {  
                         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);  
1712    
1713                          if (config->save)          g_use_bitrate = config->use_2pass_bitrate;
1714                          {  
1715                                  config_reg_set(config);          if (g_use_bitrate) {
1716                          }                  SetDlgItemText(hDlg, IDC_BITRATE_S, "Target bitrate (kbps):");
1717                  }  
1718                  else if (LOWORD(wParam) == IDC_DECODER && HIWORD(wParam) == BN_CLICKED)                  wsprintf(buf, "%i kbps", DEFAULT_MIN_KBPS);
1719                  {                  SetDlgItemText(hDlg, IDC_BITRATE_MIN, buf);
1720                          dec_dialog(hDlg, config);  
1721                    max = profiles[profile].max_bitrate;
1722                    if (max == 0) max = DEFAULT_MAX_KBPS;
1723                    wsprintf(buf, "%i kbps", max);
1724                    SetDlgItemText(hDlg, IDC_BITRATE_MAX, buf);
1725    
1726                    SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(DEFAULT_MIN_KBPS, max));
1727                    SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE,
1728                                                    config_get_uint(hDlg, IDC_BITRATE, DEFAULT_MIN_KBPS) );
1729    
1730            } else if (rc_mode==RC_MODE_2PASS2) {
1731                    SetDlgItemText(hDlg, IDC_BITRATE_S, "Target size (kbytes):");
1732            } else if (rc_mode==RC_MODE_1PASS) {
1733                    SetDlgItemText(hDlg, IDC_BITRATE_S, "Target quantizer:");
1734                    SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(100, 3100));
1735                    SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE,
1736                                                            get_dlgitem_float(hDlg, IDC_BITRATE, DEFAULT_QUANT ));
1737                    SetDlgItemText(hDlg, IDC_BITRATE_MIN, "1 (maximum quality)");
1738                    SetDlgItemText(hDlg, IDC_BITRATE_MAX, "(smallest file) 31");
1739    
                         if (config->save)  
                         {  
                                 config_reg_set(config);  
                         }  
1740                  }                  }
                 else if (LOWORD(wParam) == IDC_DEFAULTS && HIWORD(wParam) == BN_CLICKED)  
                 {  
                         config_reg_default(config);  
1741    
1742                          SendDlgItemMessage(hDlg, IDC_MODE, CB_SETCURSEL, config->mode, 0);          EnableDlgWindow(hDlg, IDC_BITRATE_S, target_en);
1743            EnableDlgWindow(hDlg, IDC_BITRATE, target_en);
1744            EnableDlgWindow(hDlg, IDC_BITRATE_ADV, target_en);
1745    
1746                          main_slider(hDlg, config);          EnableDlgWindow(hDlg, IDC_BITRATE_MIN, target_en_slider);
1747                          main_value(hDlg, config);          EnableDlgWindow(hDlg, IDC_BITRATE_MAX, target_en_slider);
1748            EnableDlgWindow(hDlg, IDC_SLIDER, target_en_slider);
1749                  }                  }
1750                  else if (HIWORD(wParam) == EN_UPDATE && LOWORD(wParam) == IDC_VALUE)  
1751    
1752    static void main_upload(HWND hDlg, CONFIG * config)
1753                  {                  {
                         int value = config_get_uint(hDlg, IDC_VALUE, 1);  
                         int max = 1;  
1754    
1755                          max = (config->mode == DLG_MODE_CBR) ? 10000 :          SendDlgItemMessage(hDlg, IDC_PROFILE, CB_SETCURSEL, config->profile, 0);
1756                                  ((config->mode == DLG_MODE_VBR_QUAL) ? 100 :          SendDlgItemMessage(hDlg, IDC_MODE, CB_SETCURSEL, config->mode, 0);
1757                                  ((config->mode == DLG_MODE_VBR_QUANT) ? 31 : 1<<30));  
1758            g_use_bitrate = config->use_2pass_bitrate;
1759    
1760                          if (value < 1)          if (g_use_bitrate) {
1761                          {                  SetDlgItemInt(hDlg, IDC_BITRATE, config->bitrate, FALSE);
1762                                  value = 1;          } else if (config->mode == RC_MODE_2PASS2) {
1763                          }                  SetDlgItemInt(hDlg, IDC_BITRATE, config->desired_size, FALSE);
1764                          if (value > max)          } else if (config->mode == RC_MODE_1PASS) {
1765                          {                  set_dlgitem_float(hDlg, IDC_BITRATE, config->desired_quant);
                                 value = max;  
                                 SetDlgItemInt(hDlg, IDC_VALUE, value, FALSE);  
1766                          }                          }
1767    
1768                          if (config->mode != DLG_MODE_2PASS_2_INT)          zones_update(hDlg, config);
                         {  
                                 SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE, value);  
1769                          }                          }
1770                  }  
1771                  else if (LOWORD(wParam) == IDOK && HIWORD(wParam) == BN_CLICKED)  
1772    /* downloads data from main dialog */
1773    static void main_download(HWND hDlg, CONFIG * config)
1774                  {                  {
1775                          main_download(hDlg, config);          config->profile = SendDlgItemMessage(hDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0);
1776                          config->save = TRUE;          config->mode = SendDlgItemMessage(hDlg, IDC_MODE, CB_GETCURSEL, 0, 0);
1777                          EndDialog(hDlg, IDOK);  
1778            if (g_use_bitrate) {
1779                    config->bitrate = config_get_uint(hDlg, IDC_BITRATE, config->bitrate);
1780            } else if (config->mode == RC_MODE_2PASS2) {
1781                    config->desired_size = config_get_uint(hDlg, IDC_BITRATE, config->desired_size);
1782            } else if (config->mode == RC_MODE_1PASS) {
1783                    config->desired_quant = get_dlgitem_float(hDlg, IDC_BITRATE, config->desired_quant);
1784                  }                  }
                 else if (LOWORD(wParam) == IDCANCEL)  
                 {  
                         config->save = FALSE;  
                         EndDialog(hDlg, IDCANCEL);  
1785                  }                  }
                 break;  
1786    
         default :  
                 return 0;  
         }  
1787    
1788          return 1;  /* main dialog proc */
 }  
1789    
1790    static const int profile_dlgs[] = { IDD_PROFILE, IDD_LEVEL, IDD_AR };
1791    static const int single_dlgs[] = { IDD_RC_CBR };
1792    static const int pass1_dlgs[] = { IDD_RC_2PASS1 };
1793    static const int pass2_dlgs[] = { IDD_RC_2PASS2 };
1794    static const int bitrate_dlgs[] = { IDD_BITRATE };
1795    static const int zone_dlgs[] = { IDD_ZONE };
1796    static const int decoder_dlgs[] = { IDD_DEC };
1797    static const int adv_dlgs[] = { IDD_MOTION, IDD_QUANT, IDD_DEBUG};
1798    
 /* advanced dialog proc */  
1799    
1800  BOOL CALLBACK adv_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)  BOOL CALLBACK main_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1801  {  {
1802          PROPSHEETINFO *psi;          CONFIG* config = (CONFIG*)GetWindowLong(hDlg, GWL_USERDATA);
1803            unsigned int i;
         psi = (PROPSHEETINFO*)GetWindowLong(hDlg, GWL_USERDATA);  
1804    
1805          switch (uMsg)          switch (uMsg)
1806          {          {
1807          case WM_INITDIALOG :          case WM_INITDIALOG :
1808                  psi = (PROPSHEETINFO*) ((LPPROPSHEETPAGE)lParam)->lParam;                  SetWindowLong(hDlg, GWL_USERDATA, lParam);
1809                    config = (CONFIG*)lParam;
                 SetWindowLong(hDlg, GWL_USERDATA, (LPARAM)psi);  
1810    
1811                  if (psi->page == DLG_GLOBAL)                  for (i=0; i<sizeof(profiles)/sizeof(profile_t); i++)
1812                  {                          SendDlgItemMessage(hDlg, IDC_PROFILE, CB_ADDSTRING, 0, (LPARAM)profiles[i].name);
                         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");  
1813    
1814                          SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_ADDSTRING, 0, (LPARAM)"H.263");                  SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"Single pass");
1815                          SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_ADDSTRING, 0, (LPARAM)"MPEG");                  SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"Twopass - 1st pass");
1816                          SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_ADDSTRING, 0, (LPARAM)"MPEG-Custom");                  SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"Twopass - 2nd pass");
1817                          SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_ADDSTRING, 0, (LPARAM)"Modulated");  #ifdef _DEBUG
1818                          SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_ADDSTRING, 0, (LPARAM)"New Modulated HQ");                  SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"Null test speed");
1819    #endif
1820    
1821                          SendDlgItemMessage(hDlg, IDC_FOURCC, CB_ADDSTRING, 0, (LPARAM)"XVID");                  InitCommonControls();
                         SendDlgItemMessage(hDlg, IDC_FOURCC, CB_ADDSTRING, 0, (LPARAM)"DIVX");  
                         SendDlgItemMessage(hDlg, IDC_FOURCC, CB_ADDSTRING, 0, (LPARAM)"DX50");  
1822    
1823                          SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"0 - Off");                  if ((g_hTooltip = CreateWindow(TOOLTIPS_CLASS, NULL, TTS_ALWAYSTIP,
1824                          SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"1 - Mode Decision");                                  CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1825                          SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"2 - Limited Search");                                  NULL, NULL, g_hInst, NULL)))
                         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)  
1826                  {                  {
1827                          EnableWindow(GetDlgItem(hDlg, IDC_NUMTHREADS_STATIC), FALSE);                          SetWindowPos(g_hTooltip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
1828                          EnableWindow(GetDlgItem(hDlg, IDC_NUMTHREADS), FALSE);                          SendMessage(g_hTooltip, TTM_SETDELAYTIME, TTDT_AUTOMATIC, MAKELONG(1500, 0));
1829                  }                          SendMessage(g_hTooltip, TTM_SETMAXTIPWIDTH, 0, 400);
1830    
                 if (hTooltip)  
                 {  
1831                          EnumChildWindows(hDlg, enum_tooltips, 0);                          EnumChildWindows(hDlg, enum_tooltips, 0);
1832                  }                  }
1833    
1834                  adv_upload(hDlg, psi->page, psi->config);                  SetClassLong(GetDlgItem(hDlg, IDC_BITRATE_S), GCL_HCURSOR, (LONG)LoadCursor(NULL, IDC_HAND));
                 adv_mode(hDlg, psi->config->mode);  
                 break;  
1835    
         case WM_COMMAND :  
                 if (HIWORD(wParam) == BN_CLICKED)  
                 {  
                         switch (LOWORD(wParam))  
1836                          {                          {
1837                          case IDC_HINTEDME :                          DWORD ext_style = ListView_GetExtendedListViewStyle(GetDlgItem(hDlg,IDC_ZONES));
1838                          case IDC_USEALT :                          ext_style |= LVS_EX_FULLROWSELECT | LVS_EX_FLATSB ;
1839                          case IDC_USEAUTO :                          ListView_SetExtendedListViewStyle(GetDlgItem(hDlg,IDC_ZONES), ext_style);
                         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;  
1840                          }                          }
                 }  
                 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);  
1841    
1842                          GetDlgItemText(hDlg, hComponent, tmp, MAX_PATH);                  {
1843                            typedef struct {
1844                                    char * name;
1845                                    int value;
1846                            } char_int_t;
1847    
1848                          memset(&ofn, 0, sizeof(OPENFILENAME));                          const static char_int_t columns[] = {
1849                          ofn.lStructSize = sizeof(OPENFILENAME);                                  {"Frame #",      64},
1850                                    {"Weight/Quant",  82},
1851                                    {"Modifiers",   120}};
1852    
1853                          ofn.hwndOwner = hDlg;                          LVCOLUMN lvc;
1854                          ofn.lpstrFilter = "bitrate curve (*.stats)\0*.stats\0All files (*.*)\0*.*\0\0";                          int i;
                         ofn.lpstrFile = tmp;  
                         ofn.nMaxFile = MAX_PATH;  
                         ofn.Flags = OFN_PATHMUSTEXIST;  
1855    
1856                          if (LOWORD(wParam) == IDC_HINT_BROWSE)                          /* Initialize the LVCOLUMN structure.  */
1857                          {                          lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
1858                                  ofn.lpstrFilter = "motion hints (*.mvh)\0*.mvh\0All files (*.*)\0*.*\0\0";                          lvc.fmt = LVCFMT_LEFT;
1859                                  if (GetOpenFileName(&ofn))  
1860                                  {                          /* Add the columns.  */
1861                                          SetDlgItemText(hDlg, IDC_HINTFILE, tmp);                          for (i=0; i<sizeof(columns)/sizeof(char_int_t); i++) {
1862                                  }                                  lvc.pszText = (char*)columns[i].name;
1863                          }                                  lvc.cchTextMax = strlen(columns[i].name);
1864                          else if (LOWORD(wParam) == IDC_STATS1_BROWSE &&                                  lvc.iSubItem = i;
1865                                  psi->config->mode == DLG_MODE_2PASS_1)                                  lvc.cx = columns[i].value;  /* column width, pixels */
1866                          {                                  ListView_InsertColumn(GetDlgItem(hDlg,IDC_ZONES), i, &lvc);
                                 ofn.Flags |= OFN_OVERWRITEPROMPT;  
                                 if (GetSaveFileName(&ofn))  
                                 {  
                                         SetDlgItemText(hDlg, hComponent, tmp);  
                                 }  
                         }  
                         else  
                         {  
                                 ofn.Flags |= OFN_FILEMUSTEXIST;  
                                 if (GetOpenFileName(&ofn)) {  
                                         SetDlgItemText(hDlg, hComponent, tmp);  
1867                                  }                                  }
1868                          }                          }
1869                  }  
1870                  else if (LOWORD(wParam) == IDC_QUANTMATRIX && HIWORD(wParam) == BN_CLICKED)                  /* XXX: main_mode needs RC_MODE_xxx, main_upload needs g_use_bitrate set correctly... */
1871                  {                  main_upload(hDlg, config);
1872                          DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_QUANTMATRIX), hDlg, quantmatrix_proc, (LPARAM)psi->config);                  main_mode(hDlg, config);
1873                  }                  main_upload(hDlg, config);
1874                  break;                  break;
1875    
1876          case WM_NOTIFY :          case WM_NOTIFY :
                 switch (((NMHDR *)lParam)->code)  
1877                  {                  {
1878                  case PSN_KILLACTIVE :                          NMHDR * n = (NMHDR*)lParam;
                         /* validate */  
                         adv_download(hDlg, psi->page, psi->config);  
                         SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);  
                         break;  
1879    
1880                  case PSN_APPLY :                          if (n->code == NM_DBLCLK) {
1881                          /* apply */                                   NMLISTVIEW * nmlv = (NMLISTVIEW*) lParam;
1882                          adv_download(hDlg, psi->page, psi->config);                                   config->cur_zone = nmlv->iItem;
1883                          SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);  
1884                          psi->config->save = TRUE;                                   main_download(hDlg, config);
1885                          break;                                   if (config->cur_zone >= 0 && adv_dialog(hDlg, config, zone_dlgs, sizeof(zone_dlgs)/sizeof(int))) {
1886                                             zones_update(hDlg, config);
1887                  }                  }
1888                  break;                  break;
   
         default :  
                 return 0;  
1889          }          }
1890    
1891          return 1;                  break;
1892  }  }
1893    
1894            case WM_COMMAND :
1895                    if (HIWORD(wParam) == BN_CLICKED) {
1896    
1897  /* quantization matrix dialog proc */                          switch(LOWORD(wParam)) {
1898                            case IDC_PROFILE_ADV :
1899  BOOL CALLBACK quantmatrix_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)                                  main_download(hDlg, config);
1900  {                                  adv_dialog(hDlg, config, profile_dlgs, sizeof(profile_dlgs)/sizeof(int));
         CONFIG* config = (CONFIG*)GetWindowLong(hDlg, GWL_USERDATA);  
   
         switch (uMsg)  
         {  
         case WM_INITDIALOG :  
                 SetWindowLong(hDlg, GWL_USERDATA, lParam);  
                 config = (CONFIG*)lParam;  
                 quant_upload(hDlg, config);  
1901    
1902                  if (hTooltip)                                  SendDlgItemMessage(hDlg, IDC_PROFILE, CB_SETCURSEL, config->profile, 0);
1903                  {                                  main_mode(hDlg, config);
                         EnumChildWindows(hDlg, enum_tooltips, 0);  
                 }  
1904                  break;                  break;
1905    
1906          case WM_COMMAND :                          case IDC_MODE_ADV :
1907                  if (LOWORD(wParam) == IDOK && HIWORD(wParam) == BN_CLICKED)                                  main_download(hDlg, config);
1908                  {                                  if (config->mode == RC_MODE_1PASS) {
1909                          quant_download(hDlg, config);                                          adv_dialog(hDlg, config, single_dlgs, sizeof(single_dlgs)/sizeof(int));
1910                          EndDialog(hDlg, IDOK);                                  }else if (config->mode == RC_MODE_2PASS1) {
1911                  }                                          adv_dialog(hDlg, config, pass1_dlgs, sizeof(pass1_dlgs)/sizeof(int));
1912                  else if (LOWORD(wParam) == IDCANCEL)                                  }else if (config->mode == RC_MODE_2PASS2) {
1913                  {                                          adv_dialog(hDlg, config, pass2_dlgs, sizeof(pass2_dlgs)/sizeof(int));
                         EndDialog(hDlg, IDCANCEL);  
1914                  }                  }
1915                  else if ((LOWORD(wParam) == IDC_LOAD || LOWORD(wParam) == IDC_SAVE) && HIWORD(wParam) == BN_CLICKED)                                  break;
                 {  
                         OPENFILENAME ofn;  
                         char file[MAX_PATH];  
1916    
1917                          HANDLE hFile;                          case IDC_BITRATE_S :
1918                          DWORD read=128, wrote=0;                                  /* alternate between bitrate/desired_length metrics */
1919                          BYTE quant_data[128];                                  main_download(hDlg, config);
1920                                    config->use_2pass_bitrate = !config->use_2pass_bitrate;
1921                                    main_mode(hDlg, config);
1922                                    main_upload(hDlg, config);
1923                                    break;
1924    
1925                          strcpy(file, "\\matrix");                          case IDC_BITRATE_ADV :
1926                          memset(&ofn, 0, sizeof(OPENFILENAME));                                  main_download(hDlg, config);
1927                          ofn.lStructSize = sizeof(OPENFILENAME);                                  adv_dialog(hDlg, config, bitrate_dlgs, sizeof(bitrate_dlgs)/sizeof(int));
1928                                    main_mode(hDlg, config);
1929                                    main_upload(hDlg, config);
1930                                    break;
1931    
1932                          ofn.hwndOwner = hDlg;                          case IDC_DECODER :
1933                          ofn.lpstrFilter = "All files (*.*)\0*.*\0\0";                                  main_download(hDlg, config);
1934                          ofn.lpstrFile = file;                                  adv_dialog(hDlg, config, decoder_dlgs, sizeof(decoder_dlgs)/sizeof(int));
1935                          ofn.nMaxFile = MAX_PATH;                                  main_mode(hDlg, config);
1936                          ofn.Flags = OFN_PATHMUSTEXIST;                                  break;
1937    
1938                          if (LOWORD(wParam) == IDC_SAVE)                          case IDC_ADD :
1939                          {                          {
1940                                  ofn.Flags |= OFN_OVERWRITEPROMPT;                                  int i, sel, new_frame;
                                 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);  
1941    
1942                                          if (hFile == INVALID_HANDLE_VALUE)                                  if (config->num_zones >= MAX_ZONES) {
1943                                          {                                          MessageBox(hDlg, "Exceeded maximum number of zones.\nIncrease config.h:MAX_ZONES and rebuild.", "Warning", 0);
1944                                                  DEBUGERR("Couldn't save quant matrix");                                          break;
1945                                          }                                          }
1946                                          else  
1947                                          {                                  sel = ListView_GetNextItem(GetDlgItem(hDlg, IDC_ZONES), -1, LVNI_SELECTED);
1948                                                  if (!WriteFile(hFile, quant_data, 128, &wrote, 0))  
1949                                                  {                                  if (sel<0) {
1950                                                          DEBUGERR("Couldnt write quant matrix");                                          if (config->ci_valid && config->ci.ciActiveFrame>0) {
1951                                                    for(sel=0; sel<config->num_zones-1 && config->zones[sel].frame<config->ci.ciActiveFrame; sel++) ;
1952                                                    sel--;
1953                                                    new_frame = config->ci.ciActiveFrame;
1954                                            }else{
1955                                                    sel = config->num_zones-1;
1956                                                    new_frame = sel<0 ? 0 : config->zones[sel].frame + 1;
1957                                                  }                                                  }
1958                                    }else{
1959                                            new_frame = config->zones[sel].frame + 1;
1960                                          }                                          }
1961    
1962                                          CloseHandle(hFile);                                  for(i=config->num_zones-1; i>sel; i--) {
1963                                  }                                          config->zones[i+1] = config->zones[i];
1964                          }                          }
1965                          else                                  config->num_zones++;
1966                          {                                  config->zones[sel+1].frame = new_frame;
1967                                  ofn.Flags |= OFN_FILEMUSTEXIST;                                  config->zones[sel+1].mode = RC_ZONE_WEIGHT;
1968                                  if (GetOpenFileName(&ofn))                                  config->zones[sel+1].weight = 100;
1969                                  {                                  config->zones[sel+1].quant = 500;
1970                                          hFile = CreateFile(file, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);                                  config->zones[sel+1].type = XVID_TYPE_AUTO;
1971                                    config->zones[sel+1].greyscale = 0;
1972                                    config->zones[sel+1].chroma_opt = 0;
1973                                    config->zones[sel+1].bvop_threshold = 0;
1974    
1975                                          if (hFile == INVALID_HANDLE_VALUE)                                  ListView_SetItemState(GetDlgItem(hDlg, IDC_ZONES), sel, 0x00000000, LVIS_SELECTED);
1976                                          {                                  zones_update(hDlg, config);
1977                                                  DEBUGERR("Couldn't load quant matrix");                                  ListView_SetItemState(GetDlgItem(hDlg, IDC_ZONES), sel+1, 0xffffffff, LVIS_SELECTED);
1978                                    break;
1979                                          }                                          }
1980                                          else  
1981                                          {                          case IDC_REMOVE :
                                                 if (!ReadFile(hFile, quant_data, 128, &read, 0))  
1982                                                  {                                                  {
1983                                                          DEBUGERR("Couldnt read quant matrix");                                  int i, sel;
1984                                    sel = ListView_GetNextItem(GetDlgItem(hDlg, IDC_ZONES), -1, LVNI_SELECTED);
1985    
1986                                    if (sel == -1 || config->num_zones < 1) {
1987                                            /*MessageBox(hDlg, "Nothing selected", "Warning", 0);*/
1988                                            break;
1989                                                  }                                                  }
1990                                                  else  
1991                                                  {                                  for (i=sel; i<config->num_zones-1; i++)
1992                                                          memcpy(config->qmatrix_intra, quant_data, 64);                                          config->zones[i] = config->zones[i+1];
1993                                                          memcpy(config->qmatrix_inter, quant_data+64, 64);  
1994                                                          quant_upload(hDlg, config);                                  config->num_zones--;
1995    
1996                                    zones_update(hDlg, config);
1997                                    break;
1998                                                  }                                                  }
1999    
2000                            case IDC_EDIT :
2001                                    main_download(hDlg, config);
2002                                    config->cur_zone = ListView_GetNextItem(GetDlgItem(hDlg, IDC_ZONES), -1, LVNI_SELECTED);
2003                                    if (config->cur_zone != -1 && adv_dialog(hDlg, config, zone_dlgs, sizeof(zone_dlgs)/sizeof(int))) {
2004                                            zones_update(hDlg, config);
2005                                          }                                          }
2006                                    break;
2007    
2008                                          CloseHandle(hFile);                          case IDC_ADVANCED :
2009                                    main_download(hDlg, config);
2010                                    adv_dialog(hDlg, config, adv_dlgs, sizeof(adv_dlgs)/sizeof(int));
2011                                    break;
2012    
2013                            case IDC_DEFAULTS :
2014                                    config_reg_default(config);
2015                                    main_mode(hDlg, config);
2016                                    main_upload(hDlg, config);
2017                                    break;
2018    
2019                            case IDOK :
2020                                    main_download(hDlg, config);
2021                                    config->save = TRUE;
2022                                    EndDialog(hDlg, IDOK);
2023                                    break;
2024    
2025                            case IDCANCEL :
2026                                    config->save = FALSE;
2027                                    EndDialog(hDlg, IDCANCEL);
2028                                    break;
2029                                  }                                  }
2030                    } else if (HIWORD(wParam) == LBN_SELCHANGE &&
2031                            (LOWORD(wParam)==IDC_PROFILE || LOWORD(wParam)==IDC_MODE)) {
2032    
2033                            config->mode = SendDlgItemMessage(hDlg, IDC_MODE, CB_GETCURSEL, 0, 0);
2034                            config->profile = SendDlgItemMessage(hDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0);
2035    
2036                            if (!g_use_bitrate) {
2037                                    if (config->mode == RC_MODE_1PASS)
2038                                            set_dlgitem_float(hDlg, IDC_BITRATE, config->desired_quant);
2039                                    else if (config->mode == RC_MODE_2PASS2)
2040                                            SetDlgItemInt(hDlg, IDC_BITRATE, config->desired_size, FALSE);
2041                            }
2042    
2043                            main_mode(hDlg, config);
2044                            main_upload(hDlg, config);
2045    
2046                    }else if (HIWORD(wParam)==EN_UPDATE && LOWORD(wParam)==IDC_BITRATE) {
2047    
2048                            if (g_use_bitrate) {
2049                                    SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE,
2050                                                    config_get_uint(hDlg, IDC_BITRATE, DEFAULT_MIN_KBPS) );
2051                            } else if (config->mode == RC_MODE_1PASS) {
2052                                    SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE,
2053                                                    get_dlgitem_float(hDlg, IDC_BITRATE, DEFAULT_QUANT) );
2054                          }                          }
2055                            main_download(hDlg, config);
2056    
2057                    }else {
2058                            return 0;
2059                  }                  }
2060                  break;                  break;
2061    
2062            case WM_HSCROLL :
2063                    if((HWND)lParam == GetDlgItem(hDlg, IDC_SLIDER)) {
2064                            if (g_use_bitrate)
2065                                    SetDlgItemInt(hDlg, IDC_BITRATE, SendMessage((HWND)lParam, TBM_GETPOS, 0, 0), FALSE);
2066                            else
2067                                    set_dlgitem_float(hDlg, IDC_BITRATE, SendMessage((HWND)lParam, TBM_GETPOS, 0, 0));
2068    
2069                            main_download(hDlg, config);
2070                            break;
2071                    }
2072                    return 0;
2073    
2074          default :          default :
2075                  return 0;                  return 0;
2076          }          }
# Line 1506  Line 2079 
2079  }  }
2080    
2081    
2082  /* about dialog proc */  
2083    /* ===================================================================================== */
2084    /* ABOUT DIALOG ======================================================================== */
2085    /* ===================================================================================== */
2086    
2087  BOOL CALLBACK about_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)  BOOL CALLBACK about_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
2088  {  {
# Line 1518  Line 2094 
2094                          char core[100];                          char core[100];
2095                          HFONT hFont;                          HFONT hFont;
2096                          LOGFONT lfData;                          LOGFONT lfData;
2097                            HINSTANCE m_hdll;
2098    
2099                          SetDlgItemText(hDlg, IDC_BUILD, XVID_BUILD);                          SetDlgItemText(hDlg, IDC_BUILD, XVID_BUILD);
2100                          SetDlgItemText(hDlg, IDC_SPECIAL_BUILD, XVID_SPECIAL_BUILD);                          SetDlgItemText(hDlg, IDC_SPECIAL_BUILD, XVID_SPECIAL_BUILD);
2101    
2102                          memset(&info, 0, sizeof(info));                          memset(&info, 0, sizeof(info));
2103                          info.version = XVID_VERSION;                          info.version = XVID_VERSION;
2104                          xvid_global(0, XVID_GBL_INFO, &info, NULL);  
2105                          wsprintf(core, "libxvidcore version %d.%d.%d (\"%s\")",                          m_hdll = LoadLibrary(XVID_DLL_NAME);
2106                                  XVID_MAJOR(info.actual_version),                          if (m_hdll != NULL) {
2107                                  XVID_MINOR(info.actual_version),  
2108                                  XVID_PATCH(info.actual_version),                                  ((int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global"))
2109                                            (0, XVID_GBL_INFO, &info, NULL);
2110    
2111                                    wsprintf(core, "xvidcore.dll version %d.%d.%d (\"%s\")",
2112                                            XVID_VERSION_MAJOR(info.actual_version),
2113                                            XVID_VERSION_MINOR(info.actual_version),
2114                                            XVID_VERSION_PATCH(info.actual_version),
2115                                  info.build);                                  info.build);
2116    
2117                                    FreeLibrary(m_hdll);
2118                            } else {
2119                                    wsprintf(core, "xvidcore.dll not found!");
2120                            }
2121    
2122                          SetDlgItemText(hDlg, IDC_CORE, core);                          SetDlgItemText(hDlg, IDC_CORE, core);
2123    
2124                          hFont = (HFONT)SendDlgItemMessage(hDlg, IDC_WEBSITE, WM_GETFONT, 0, 0L);                          hFont = (HFONT)SendDlgItemMessage(hDlg, IDC_WEBSITE, WM_GETFONT, 0, 0L);
2125    
2126                          if (GetObject(hFont, sizeof(LOGFONT), &lfData))                          if (GetObject(hFont, sizeof(LOGFONT), &lfData)) {
                         {  
2127                                  lfData.lfUnderline = 1;                                  lfData.lfUnderline = 1;
2128    
2129                                  hFont = CreateFontIndirect(&lfData);                                  hFont = CreateFontIndirect(&lfData);
2130                                  if (hFont)                                  if (hFont) {
                                 {  
2131                                          SendDlgItemMessage(hDlg, IDC_WEBSITE, WM_SETFONT, (WPARAM)hFont, 1L);                                          SendDlgItemMessage(hDlg, IDC_WEBSITE, WM_SETFONT, (WPARAM)hFont, 1L);
2132                                  }                                  }
2133                          }                          }
# Line 1550  Line 2136 
2136                          SetDlgItemText(hDlg, IDC_WEBSITE, XVID_WEBSITE);                          SetDlgItemText(hDlg, IDC_WEBSITE, XVID_WEBSITE);
2137                  }                  }
2138                  break;                  break;
   
2139          case WM_CTLCOLORSTATIC :          case WM_CTLCOLORSTATIC :
2140                  if ((HWND)lParam == GetDlgItem(hDlg, IDC_WEBSITE))                  if ((HWND)lParam == GetDlgItem(hDlg, IDC_WEBSITE))
2141                  {                  {
# Line 1577  Line 2162 
2162    
2163          return 1;          return 1;
2164  }  }
2165    
2166    
2167    void
2168    sort_zones(zone_t * zones, int zone_num, int * sel)
2169    {
2170            int i, j;
2171            zone_t tmp;
2172            for (i = 0; i < zone_num; i++) {
2173                    int cur = i;
2174                    int min_f = zones[i].frame;
2175                    for (j = i + 1; j < zone_num; j++) {
2176                            if (zones[j].frame < min_f) {
2177                                    min_f = zones[j].frame;
2178                                    cur = j;
2179                            }
2180                    }
2181                    if (cur != i) {
2182                            tmp = zones[i];
2183                            zones[i] = zones[cur];
2184                            zones[cur] = tmp;
2185                            if (i == *sel) *sel = cur;
2186                            else if (cur == *sel) *sel = i;
2187                    }
2188            }
2189    }
2190    
2191    
2192    static void
2193    zones_update(HWND hDlg, CONFIG * config)
2194    {
2195            int i, sel;
2196    
2197            sel = ListView_GetNextItem(GetDlgItem(hDlg, IDC_ZONES), -1, LVNI_SELECTED);
2198    
2199            sort_zones(config->zones, config->num_zones, &sel);
2200    
2201            ListView_DeleteAllItems(GetDlgItem(hDlg,IDC_ZONES));
2202    
2203            for (i = 0; i < config->num_zones; i++)
2204                    main_insert_zone(GetDlgItem(hDlg,IDC_ZONES), &config->zones[i], i, TRUE);
2205    
2206            if (sel == -1 && config->num_zones > 0) sel = 0;
2207            if (sel >= config->num_zones) sel = config->num_zones-1;
2208    
2209            config->cur_zone = sel;
2210            ListView_SetItemState(GetDlgItem(hDlg, IDC_ZONES), sel, 0xffffffff, LVIS_SELECTED);
2211    }

Legend:
Removed from v.1.1.2.1  
changed lines
  Added in v.1.5

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4