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

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

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

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

Legend:
Removed from v.1497  
changed lines
  Added in v.1500

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