[svn] / branches / dev-api-4 / xvidcore / vfw / src / config.c Repository:
ViewVC logotype

Diff of /branches/dev-api-4/xvidcore/vfw/src/config.c

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

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

Legend:
Removed from v.983  
changed lines
  Added in v.1338

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