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

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

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

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

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.1.2.35

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