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

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

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