[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.28, Thu Jan 22 16:13:59 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 <shlobj.h>
61    #include <prsht.h>
62    
63    #include <stdio.h>  /* sprintf */
64    #include <xvid.h>       /* XviD API */
65    
66    #include "debug.h"
67    #include "config.h"
68    #include "resource.h"
69    
70    
71    #define CONSTRAINVAL(X,Y,Z) if((X)<(Y)) X=Y; if((X)>(Z)) X=Z;
72    #define IsDlgChecked(hwnd,idc)  (IsDlgButtonChecked(hwnd,idc) == BST_CHECKED)
73    #define CheckDlg(hwnd,idc,value) CheckDlgButton(hwnd,idc, value?BST_CHECKED:BST_UNCHECKED)
74    #define EnableDlgWindow(hwnd,idc,state) EnableWindow(GetDlgItem(hwnd,idc),state)
75    
76    HINSTANCE g_hInst;
77    HWND g_hTooltip;
78    
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    /* ===================================================================================== */
147    /* REGISTRY ============================================================================ */
148    /* ===================================================================================== */
149    
150    /* registry info structs */
151    CONFIG reg;
152    
153    static const REG_INT reg_ints[] = {
154            {"mode",                                        &reg.mode,                                              RC_MODE_1PASS},
155            {"bitrate",                                     &reg.bitrate,                                   700},
156            {"desired_size",                        &reg.desired_size,                              570000},
157            {"use_2pass_bitrate",      &reg.use_2pass_bitrate,               0},
158    
159            /* profile */
160            {"quant_type",                          &reg.quant_type,                                0},
161            {"lum_masking",                         &reg.lum_masking,                               0},
162            {"interlacing",                         &reg.interlacing,                               0},
163            {"qpel",                                        &reg.qpel,                                              0},
164            {"gmc",                                         &reg.gmc,                                               0},
165            {"reduced_resolution",          &reg.reduced_resolution,                0},
166            {"use_bvop",                            &reg.use_bvop,                                  1},
167            {"max_bframes",                         &reg.max_bframes,                               2},
168            {"bquant_ratio",                        &reg.bquant_ratio,                              150},   /* 100-base float */
169            {"bquant_offset",                       &reg.bquant_offset,                             100},   /* 100-base float */
170            {"packed",                                      &reg.packed,                                    1},
171            {"closed_gov",                          &reg.closed_gov,                                1},
172    
173            /* aspect ratio */
174            {"ar_mode",                                     &reg.ar_mode,                                   0},
175            {"aspect_ratio",                        &reg.display_aspect_ratio,              0},
176            {"par_x",                                       &reg.par_x,                                             1},
177            {"par_y",                                       &reg.par_y,                                             1},
178            {"ar_x",                                        &reg.ar_x,                                              4},
179            {"ar_y",                                        &reg.ar_y,                                              3},
180    
181            /* zones */
182            {"num_zones",                      &reg.num_zones,                               1},
183    
184            /* single pass */
185            {"rc_reaction_delay_factor",&reg.rc_reaction_delay_factor,      16},
186            {"rc_averaging_period",         &reg.rc_averaging_period,               100},
187            {"rc_buffer",                           &reg.rc_buffer,                                 100},
188    
189            /* 2pass1 */
190            {"discard1pass",                        &reg.discard1pass,                              1},
191    
192            /* 2pass2 */
193            {"keyframe_boost",                      &reg.keyframe_boost,                    0},
194            {"kfreduction",                         &reg.kfreduction,                               20},
195            {"kfthreshold",                         &reg.kfthreshold,                               1},
196            {"curve_compression_high",      &reg.curve_compression_high,    0},
197            {"curve_compression_low",       &reg.curve_compression_low,             0},
198            {"overflow_control_strength", &reg.overflow_control_strength, 5},
199            {"twopass_max_overflow_improvement", &reg.twopass_max_overflow_improvement, 5},
200            {"twopass_max_overflow_degradation", &reg.twopass_max_overflow_degradation, 5},
201    
202            /* motion */
203            {"motion_search",                       &reg.motion_search,                             6},
204            {"vhq_mode",                            &reg.vhq_mode,                                  1},
205            {"chromame",                            &reg.chromame,                                  1},
206            {"cartoon_mode",                        &reg.cartoon_mode,                              0},
207            {"turbo",                                       &reg.turbo,                                             0},
208            {"max_key_interval",            &reg.max_key_interval,                  300},
209            {"frame_drop_ratio",            &reg.frame_drop_ratio,                  0},
210    
211            /* quant */
212            {"min_iquant",                          &reg.min_iquant,                                2},
213            {"max_iquant",                          &reg.max_iquant,                                31},
214            {"min_pquant",                          &reg.min_pquant,                                2},
215            {"max_pquant",                          &reg.max_pquant,                                31},
216            {"min_bquant",                          &reg.min_bquant,                                2},
217            {"max_bquant",                          &reg.max_bquant,                                31},
218            {"trellis_quant",                  &reg.trellis_quant,                   0},
219    
220            /* debug */
221            {"fourcc_used",                         &reg.fourcc_used,                               0},
222            {"debug",                                       &reg.debug,                                             0x0},
223            {"vop_debug",                           &reg.vop_debug,                                 0},
224            {"display_status",                &reg.display_status,                  1},
225    
226            /* decoder, shared with dshow */
227            {"Deblock_Y",                           &pp_dy,                                                 0},
228            {"Deblock_UV",                          &pp_duv,                                                0},
229            {"Dering",                                      &pp_dr,                                                 0},
230            {"FilmEffect",                          &pp_fe,                                                 0},
231    
232    };
233    
234    static const REG_STR reg_strs[] = {
235            {"profile",                                     reg.profile_name,                               "(unrestricted)"},
236            {"stats",                                       reg.stats,                                              CONFIG_2PASS_FILE},
237    };
238    
239    
240    zone_t stmp;
241    static const REG_INT reg_zone[] = {
242            {"zone%i_frame",                        &stmp.frame,                                     0},
243            {"zone%i_mode",                  &stmp.mode,                                      RC_ZONE_WEIGHT},
244            {"zone%i_weight",                  &stmp.weight,                                        100},     /* 100-base float */
245            {"zone%i_quant",                        &stmp.quant,                                     500},    /* 100-base float */
246            {"zone%i_type",                  &stmp.type,                                      XVID_TYPE_AUTO},
247            {"zone%i_greyscale",            &stmp.greyscale,                                 0},
248            {"zone%i_chroma_opt",      &stmp.chroma_opt,                            0},
249            {"zone%i_bvop_threshold",   &stmp.bvop_threshold,                       0},
250    };
251    
252    static const BYTE default_qmatrix_intra[] = {
253            8, 17,18,19,21,23,25,27,
254            17,18,19,21,23,25,27,28,
255            20,21,22,23,24,26,28,30,
256            21,22,23,24,26,28,30,32,
257            22,23,24,26,28,30,32,35,
258            23,24,26,28,30,32,35,38,
259            25,26,28,30,32,35,38,41,
260            27,28,30,32,35,38,41,45
261    };
262    
263    static const BYTE default_qmatrix_inter[] = {
264            16,17,18,19,20,21,22,23,
265            17,18,19,20,21,22,23,24,
266            18,19,20,21,22,23,24,25,
267            19,20,21,22,23,24,26,27,
268            20,21,22,23,25,26,27,28,
269            21,22,23,24,26,27,28,30,
270            22,23,24,26,27,28,30,31,
271            23,24,25,27,28,30,31,33
272    };
273    
274    
275    
276    #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)));}
277    
278    #define XVID_DLL_NAME "xvidcore.dll"
279    
280    void config_reg_get(CONFIG * config)
281    {
282            char tmp[32];
283            HKEY hKey;
284            DWORD size;
285            int i,j;
286            xvid_gbl_info_t info;
287            HINSTANCE m_hdll;
288    
289            memset(&info, 0, sizeof(info));
290            info.version = XVID_VERSION;
291    
292            m_hdll = LoadLibrary(XVID_DLL_NAME);
293            if (m_hdll != NULL) {
294    
295                    ((int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global"))
296                            (0, XVID_GBL_INFO, &info, NULL);
297    
298                    FreeLibrary(m_hdll);
299            }
300    
301            reg.cpu = info.cpu_flags;
302            reg.num_threads = info.num_threads;
303    
304            RegOpenKeyEx(XVID_REG_KEY, XVID_REG_PARENT "\\" XVID_REG_CHILD, 0, KEY_READ, &hKey);
305    
306            /* read integer values */
307            for (i=0 ; i<sizeof(reg_ints)/sizeof(REG_INT); i++) {
308                    size = sizeof(int);
309                    if (RegQueryValueEx(hKey, reg_ints[i].reg_value, 0, 0, (LPBYTE)reg_ints[i].config_int, &size) != ERROR_SUCCESS) {
310                            *reg_ints[i].config_int = reg_ints[i].def;
311                    }
312            }
313    
314            /* read string values */
315            for (i=0 ; i<sizeof(reg_strs)/sizeof(REG_STR); i++) {
316                    size = MAX_PATH;
317                    if (RegQueryValueEx(hKey, reg_strs[i].reg_value, 0, 0, (LPBYTE)reg_strs[i].config_str, &size) != ERROR_SUCCESS) {
318                            memcpy(reg_strs[i].config_str, reg_strs[i].def, MAX_PATH);
319                    }
320            }
321    
322            reg.profile = 0;
323            for (i=0; i<sizeof(profiles)/sizeof(profile_t); i++) {
324                    if (strcmpi(profiles[i].name, reg.profile_name) == 0) {
325                            reg.profile = i;
326                    }
327            }
328    
329            memcpy(config, &reg, sizeof(CONFIG));
330    
331    
332            /* read quant matrices */
333            REG_GET_B("qmatrix_intra", config->qmatrix_intra, default_qmatrix_intra);
334            REG_GET_B("qmatrix_inter", config->qmatrix_inter, default_qmatrix_inter);
335    
336    
337            /* read zones */
338            if (config->num_zones>MAX_ZONES) {
339                    config->num_zones=MAX_ZONES;
340            }else if (config->num_zones<=0) {
341                    config->num_zones = 1;
342            }
343    
344            for (i=0; i<config->num_zones; i++) {
345                    for (j=0; j<sizeof(reg_zone)/sizeof(REG_INT); j++)  {
346                            size = sizeof(int);
347    
348                            wsprintf(tmp, reg_zone[j].reg_value, i);
349                            if (RegQueryValueEx(hKey, tmp, 0, 0, (LPBYTE)reg_zone[j].config_int, &size) != ERROR_SUCCESS)
350                                    *reg_zone[j].config_int = reg_zone[j].def;
351                    }
352    
353                    memcpy(&config->zones[i], &stmp, sizeof(zone_t));
354            }
355    
356            RegCloseKey(hKey);
357    }
358    
359    
360    /* put config settings in registry */
361    
362    #define REG_SET_B(X, Y) RegSetValueEx(hKey, X, 0, REG_BINARY, Y, sizeof((Y)))
363    
364    void config_reg_set(CONFIG * config)
365    {
366            char tmp[64];
367            HKEY hKey;
368            DWORD dispo;
369            int i,j;
370    
371            if (RegCreateKeyEx(
372                            XVID_REG_KEY,
373                            XVID_REG_PARENT "\\" XVID_REG_CHILD,
374                            0,
375                            XVID_REG_CLASS,
376                            REG_OPTION_NON_VOLATILE,
377                            KEY_WRITE,
378                            0,
379                            &hKey,
380                            &dispo) != ERROR_SUCCESS)
381            {
382                    DPRINTF("Couldn't create XVID_REG_SUBKEY - GetLastError=%i", GetLastError());
383                    return;
384            }
385    
386            memcpy(&reg, config, sizeof(CONFIG));
387    
388            /* set integer values */
389            for (i=0 ; i<sizeof(reg_ints)/sizeof(REG_INT); i++) {
390                    RegSetValueEx(hKey, reg_ints[i].reg_value, 0, REG_DWORD, (LPBYTE)reg_ints[i].config_int, sizeof(int));
391            }
392    
393            /* set string values */
394            strcpy(reg.profile_name, profiles[reg.profile].name);
395            for (i=0 ; i<sizeof(reg_strs)/sizeof(REG_STR); i++) {
396                    RegSetValueEx(hKey, reg_strs[i].reg_value, 0, REG_SZ, reg_strs[i].config_str, lstrlen(reg_strs[i].config_str)+1);
397            }
398    
399            /* set quant matrices */
400            REG_SET_B("qmatrix_intra", config->qmatrix_intra);
401            REG_SET_B("qmatrix_inter", config->qmatrix_inter);
402    
403            /* set seections */
404            for (i=0; i<config->num_zones; i++) {
405                    memcpy(&stmp, &config->zones[i], sizeof(zone_t));
406                    for (j=0; j<sizeof(reg_zone)/sizeof(REG_INT); j++)  {
407                            wsprintf(tmp, reg_zone[j].reg_value, i);
408                            RegSetValueEx(hKey, tmp, 0, REG_DWORD, (LPBYTE)reg_zone[j].config_int, sizeof(int));
409                    }
410            }
411    
412            RegCloseKey(hKey);
413    }
414    
415    
416    /* clear XviD registry key, load defaults */
417    
418    void config_reg_default(CONFIG * config)
419    {
420            HKEY hKey;
421    
422            if (RegOpenKeyEx(XVID_REG_KEY, XVID_REG_PARENT, 0, KEY_ALL_ACCESS, &hKey)) {
423                    DPRINTF("Couldn't open registry key for deletion - GetLastError=%i", GetLastError());
424                    return;
425            }
426    
427            if (RegDeleteKey(hKey, XVID_REG_CHILD)) {
428                    DPRINTF("Couldn't delete registry key - GetLastError=%i", GetLastError());
429                    return;
430            }
431    
432            RegCloseKey(hKey);
433            config_reg_get(config);
434            config_reg_set(config);
435    }
436    
437    
438    /* leaves current config value if dialog item is empty */
439    int config_get_int(HWND hDlg, INT item, int config)
440    {
441            BOOL success = FALSE;
442            int tmp = GetDlgItemInt(hDlg, item, &success, TRUE);
443            return (success) ? tmp : config;
444    }
445    
446    
447    int config_get_uint(HWND hDlg, UINT item, int config)
448    {
449            BOOL success = FALSE;
450            int tmp = GetDlgItemInt(hDlg, item, &success, FALSE);
451            return (success) ? tmp : config;
452    }
453    
454    
455    /* we use "100 base" floats */
456    
457    #define FLOAT_BUF_SZ    20
458    int get_dlgitem_float(HWND hDlg, UINT item, int def)
459    {
460            char buf[FLOAT_BUF_SZ];
461    
462            if (GetDlgItemText(hDlg, item, buf, FLOAT_BUF_SZ) == 0)
463                    return def;
464    
465            return (int)(atof(buf)*100);
466    }
467    
468    void set_dlgitem_float(HWND hDlg, UINT item, int value)
469    {
470            char buf[FLOAT_BUF_SZ];
471            sprintf(buf, "%.2f", (float)value/100);
472            SetDlgItemText(hDlg, item, buf);
473    }
474    
475    
476    #define HEX_BUF_SZ  16
477    unsigned int get_dlgitem_hex(HWND hDlg, UINT item, unsigned int def)
478    {
479            char buf[HEX_BUF_SZ];
480            unsigned int value;
481    
482            if (GetDlgItemText(hDlg, item, buf, HEX_BUF_SZ) == 0)
483                    return def;
484    
485            if (sscanf(buf,"0x%x", &value)==1 || sscanf(buf,"%x", &value)==1) {
486                    return value;
487            }
488    
489            return def;
490    }
491    
492    void set_dlgitem_hex(HWND hDlg, UINT item, int value)
493    {
494            char buf[HEX_BUF_SZ];
495            wsprintf(buf, "0x%x", value);
496            SetDlgItemText(hDlg, item, buf);
497    }
498    
499    /* ===================================================================================== */
500    /* QUANT MATRIX DIALOG ================================================================= */
501    /* ===================================================================================== */
502    
503    void quant_upload(HWND hDlg, CONFIG* config)
504    {
505            int i;
506    
507            for (i=0 ; i<64; i++) {
508                    SetDlgItemInt(hDlg, IDC_QINTRA00 + i, config->qmatrix_intra[i], FALSE);
509                    SetDlgItemInt(hDlg, IDC_QINTER00 + i, config->qmatrix_inter[i], FALSE);
510            }
511    }
512    
513    
514    void quant_download(HWND hDlg, CONFIG* config)
515    {
516            int i;
517    
518            for (i=0; i<64; i++) {
519                    int temp;
520    
521                    temp = config_get_uint(hDlg, i + IDC_QINTRA00, config->qmatrix_intra[i]);
522                    CONSTRAINVAL(temp, 1, 255);
523                    config->qmatrix_intra[i] = temp;
524    
525                    temp = config_get_uint(hDlg, i + IDC_QINTER00, config->qmatrix_inter[i]);
526                    CONSTRAINVAL(temp, 1, 255);
527                    config->qmatrix_inter[i] = temp;
528            }
529    }
530    
531    
532    void quant_loadsave(HWND hDlg, CONFIG * config, int save)
533    {
534            char file[MAX_PATH];
535            OPENFILENAME ofn;
536            HANDLE hFile;
537            DWORD read=128, wrote=0;
538            BYTE quant_data[128];
539    
540            strcpy(file, "\\matrix");
541            memset(&ofn, 0, sizeof(OPENFILENAME));
542            ofn.lStructSize = sizeof(OPENFILENAME);
543    
544            ofn.hwndOwner = hDlg;
545            ofn.lpstrFilter = "All files (*.*)\0*.*\0\0";
546            ofn.lpstrFile = file;
547            ofn.nMaxFile = MAX_PATH;
548            ofn.Flags = OFN_PATHMUSTEXIST;
549    
550            if (save) {
551                    ofn.Flags |= OFN_OVERWRITEPROMPT;
552                    if (GetSaveFileName(&ofn)) {
553                            hFile = CreateFile(file, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
554    
555                            quant_download(hDlg, config);
556                            memcpy(quant_data, config->qmatrix_intra, 64);
557                            memcpy(quant_data+64, config->qmatrix_inter, 64);
558    
559                            if (hFile == INVALID_HANDLE_VALUE) {
560                                    DPRINTF("Couldn't save quant matrix");
561                            }else{
562                                    if (!WriteFile(hFile, quant_data, 128, &wrote, 0)) {
563                                            DPRINTF("Couldnt write quant matrix");
564                                    }
565                            }
566                            CloseHandle(hFile);
567                    }
568            }else{
569                    ofn.Flags |= OFN_FILEMUSTEXIST;
570                    if (GetOpenFileName(&ofn)) {
571                            hFile = CreateFile(file, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
572    
573                            if (hFile == INVALID_HANDLE_VALUE) {
574                                    DPRINTF("Couldn't load quant matrix");
575                            } else {
576                                    if (!ReadFile(hFile, quant_data, 128, &read, 0)) {
577                                            DPRINTF("Couldnt read quant matrix");
578                                    }else{
579                                            memcpy(config->qmatrix_intra, quant_data, 64);
580                                            memcpy(config->qmatrix_inter, quant_data+64, 64);
581                                            quant_upload(hDlg, config);
582                                    }
583                            }
584                            CloseHandle(hFile);
585                    }
586            }
587    }
588    
589    /* quantization matrix dialog proc */
590    
591    BOOL CALLBACK quantmatrix_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
592    {
593            CONFIG* config = (CONFIG*)GetWindowLong(hDlg, GWL_USERDATA);
594    
595            switch (uMsg)
596            {
597            case WM_INITDIALOG :
598                    SetWindowLong(hDlg, GWL_USERDATA, lParam);
599                    config = (CONFIG*)lParam;
600                    quant_upload(hDlg, config);
601    
602                    if (g_hTooltip)
603                    {
604                            EnumChildWindows(hDlg, enum_tooltips, 0);
605                    }
606                    break;
607    
608            case WM_COMMAND :
609    
610                    if (HIWORD(wParam) == BN_CLICKED) {
611                            switch(LOWORD(wParam)) {
612                            case IDOK :
613                                    quant_download(hDlg, config);
614                                    EndDialog(hDlg, IDOK);
615                                    break;
616    
617                            case IDCANCEL :
618                                    EndDialog(hDlg, IDCANCEL);
619                                    break;
620    
621                            case IDC_SAVE :
622                                    quant_loadsave(hDlg, config, 1);
623                                    break;
624    
625                            case IDC_LOAD :
626                                    quant_loadsave(hDlg, config, 0);
627                                    break;
628    
629                            default :
630                                    return FALSE;
631                            }
632                            break;
633                    }
634                    return FALSE;
635    
636            default :
637                    return FALSE;
638            }
639    
640            return TRUE;
641    }
642    
643    
644    /* ===================================================================================== */
645    /* ADVANCED DIALOG PAGES ================================================================ */
646    /* ===================================================================================== */
647    
648    /* initialise pages */
649    void adv_init(HWND hDlg, int idd, CONFIG * config)
650    {
651            unsigned int i;
652    
653            switch(idd) {
654            case IDD_PROFILE :
655                    for (i=0; i<sizeof(profiles)/sizeof(profile_t); i++)
656                            SendDlgItemMessage(hDlg, IDC_PROFILE_PROFILE, CB_ADDSTRING, 0, (LPARAM)profiles[i].name);
657                    SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_ADDSTRING, 0, (LPARAM)"H.263");
658                    SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_ADDSTRING, 0, (LPARAM)"MPEG");
659                    SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_ADDSTRING, 0, (LPARAM)"MPEG-Custom");
660    
661                    break;
662            case IDD_AR:
663                    SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_ADDSTRING, 0, (LPARAM)"Square (default)");
664                    SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_ADDSTRING, 0, (LPARAM)"4:3 PAL");
665                    SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_ADDSTRING, 0, (LPARAM)"4:3 NTSC");
666                    SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_ADDSTRING, 0, (LPARAM)"16:9 PAL");
667                    SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_ADDSTRING, 0, (LPARAM)"16:9 NTSC");
668                    SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_ADDSTRING, 0, (LPARAM)"Custom...");
669                    break;
670    
671            case IDD_LEVEL :
672                    for (i=0; i<sizeof(profiles)/sizeof(profile_t); i++)
673                            SendDlgItemMessage(hDlg, IDC_LEVEL_PROFILE, CB_ADDSTRING, 0, (LPARAM)profiles[i].name);
674                    break;
675    
676            case IDD_ZONE :
677                    EnableDlgWindow(hDlg, IDC_ZONE_FETCH, config->ci_valid);
678                    break;
679    
680            case IDD_MOTION :
681                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"0 - None");
682                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"1 - Very Low");
683                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"2 - Low");
684                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"3 - Medium");
685                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"4 - High");
686                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"5 - Very High");
687                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_ADDSTRING, 0, (LPARAM)"6 - Ultra High");
688    
689                    SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"0 - Off");
690                    SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"1 - Mode Decision");
691                    SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"2 - Limited Search");
692                    SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"3 - Medium Search");
693                    SendDlgItemMessage(hDlg, IDC_VHQ, CB_ADDSTRING, 0, (LPARAM)"4 - Wide Search");
694                    break;
695    
696            case IDD_DEBUG :
697                    /* force threads disabled */
698                    EnableWindow(GetDlgItem(hDlg, IDC_NUMTHREADS_STATIC), FALSE);
699                    EnableWindow(GetDlgItem(hDlg, IDC_NUMTHREADS), FALSE);
700    
701                    SendDlgItemMessage(hDlg, IDC_FOURCC, CB_ADDSTRING, 0, (LPARAM)"XVID");
702                    SendDlgItemMessage(hDlg, IDC_FOURCC, CB_ADDSTRING, 0, (LPARAM)"DIVX");
703                    SendDlgItemMessage(hDlg, IDC_FOURCC, CB_ADDSTRING, 0, (LPARAM)"DX50");
704                    break;
705            }
706    }
707    
708    
709    /* enable/disable controls based on encoder-mode or user selection */
710    
711    void adv_mode(HWND hDlg, int idd, CONFIG * config)
712    {
713            int profile;
714            int weight_en, quant_en;
715            int cpu_force;
716            int custom_quant, bvops;
717            int ar_mode, ar_par;
718    
719            switch(idd) {
720            case IDD_PROFILE :
721                    profile = SendDlgItemMessage(hDlg, IDC_PROFILE_PROFILE, CB_GETCURSEL, 0, 0);
722                    EnableDlgWindow(hDlg, IDC_BVOP, profiles[profile].flags&PROFILE_BVOP);
723    
724                    EnableDlgWindow(hDlg, IDC_QUANTTYPE_S, profiles[profile].flags&PROFILE_MPEGQUANT);
725                    EnableDlgWindow(hDlg, IDC_QUANTTYPE_S, profiles[profile].flags&PROFILE_MPEGQUANT);
726                    EnableDlgWindow(hDlg, IDC_QUANTTYPE, profiles[profile].flags&PROFILE_MPEGQUANT);
727                    custom_quant = (profiles[profile].flags&PROFILE_MPEGQUANT) && SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_GETCURSEL, 0, 0)==QUANT_MODE_CUSTOM;
728                    EnableDlgWindow(hDlg, IDC_QUANTMATRIX, custom_quant);
729                    EnableDlgWindow(hDlg, IDC_LUMMASK, profiles[profile].flags&PROFILE_ADAPTQUANT);
730                    EnableDlgWindow(hDlg, IDC_INTERLACING, profiles[profile].flags&PROFILE_INTERLACE);
731                    EnableDlgWindow(hDlg, IDC_QPEL, profiles[profile].flags&PROFILE_QPEL);
732                    EnableDlgWindow(hDlg, IDC_GMC, profiles[profile].flags&PROFILE_GMC);
733                    EnableDlgWindow(hDlg, IDC_REDUCED, profiles[profile].flags&PROFILE_REDUCED);
734    
735                    bvops = (profiles[profile].flags&PROFILE_BVOP) && IsDlgChecked(hDlg, IDC_BVOP);
736                    EnableDlgWindow(hDlg, IDC_MAXBFRAMES,      bvops);
737                    EnableDlgWindow(hDlg, IDC_BQUANTRATIO,    bvops);
738                    EnableDlgWindow(hDlg, IDC_BQUANTOFFSET,  bvops);
739                    EnableDlgWindow(hDlg, IDC_MAXBFRAMES_S,  bvops);
740                    EnableDlgWindow(hDlg, IDC_BQUANTRATIO_S,        bvops);
741                    EnableDlgWindow(hDlg, IDC_BQUANTOFFSET_S,   bvops);
742                    EnableDlgWindow(hDlg, IDC_PACKED,                  bvops);
743                    EnableDlgWindow(hDlg, IDC_CLOSEDGOV,            bvops);
744                    break;
745    
746            case IDD_AR:
747                    ar_mode = IsDlgChecked(hDlg, IDC_PAR);
748                    EnableDlgWindow(hDlg, IDC_ASPECT_RATIO, ar_mode);
749    
750                    ar_par = SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_GETCURSEL, 0, 0);
751                    if (ar_par == 5) { /* custom par */
752                            SetDlgItemInt(hDlg, IDC_PARY, config->par_y, FALSE);
753                            SetDlgItemInt(hDlg, IDC_PARX, config->par_x, FALSE);
754    
755                            EnableDlgWindow(hDlg, IDC_PARX, ar_mode);
756                            EnableDlgWindow(hDlg, IDC_PARY, ar_mode);
757                    } else {
758                            SetDlgItemInt(hDlg, IDC_PARX, PARS[ar_par][0], FALSE);
759                            SetDlgItemInt(hDlg, IDC_PARY, PARS[ar_par][1], FALSE);
760                            EnableDlgWindow(hDlg, IDC_PARX, FALSE);
761                            EnableDlgWindow(hDlg, IDC_PARY, FALSE);
762                    }
763    
764                    ar_mode = IsDlgChecked(hDlg, IDC_AR);
765    
766                    config->ar_x = config_get_uint(hDlg, IDC_ARX, config->ar_x);
767                    config->ar_y = config_get_uint(hDlg, IDC_ARY, config->ar_y);
768    
769                    EnableDlgWindow(hDlg, IDC_ARX, ar_mode);
770                    EnableDlgWindow(hDlg, IDC_ARY, ar_mode);
771                    break;
772    
773            case IDD_LEVEL :
774                    profile = SendDlgItemMessage(hDlg, IDC_LEVEL_PROFILE, CB_GETCURSEL, 0, 0);
775                    SetDlgItemInt(hDlg, IDC_LEVEL_WIDTH, profiles[profile].width, FALSE);
776                    SetDlgItemInt(hDlg, IDC_LEVEL_HEIGHT, profiles[profile].height, FALSE);
777                    SetDlgItemInt(hDlg, IDC_LEVEL_FPS, profiles[profile].fps, FALSE);
778                    SetDlgItemInt(hDlg, IDC_LEVEL_VMV, profiles[profile].max_vmv_buffer_sz, FALSE);
779                    SetDlgItemInt(hDlg, IDC_LEVEL_VCV, profiles[profile].vcv_decoder_rate, FALSE);
780                    SetDlgItemInt(hDlg, IDC_LEVEL_VBV, profiles[profile].max_vbv_size, FALSE);
781                    SetDlgItemInt(hDlg, IDC_LEVEL_BITRATE, profiles[profile].max_bitrate, FALSE);
782                    break;
783    
784            case IDD_ZONE :
785                    weight_en = IsDlgChecked(hDlg, IDC_ZONE_MODE_WEIGHT);
786                    quant_en =   IsDlgChecked(hDlg, IDC_ZONE_MODE_QUANT);
787                    EnableDlgWindow(hDlg, IDC_ZONE_WEIGHT, weight_en);
788                    EnableDlgWindow(hDlg, IDC_ZONE_QUANT, quant_en);
789                    EnableDlgWindow(hDlg, IDC_ZONE_SLIDER, weight_en|quant_en);
790    
791                    if (weight_en) {
792                            SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(001,200));
793                            SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETPOS, TRUE, get_dlgitem_float(hDlg, IDC_ZONE_WEIGHT, 100));
794                            SetDlgItemText(hDlg, IDC_ZONE_MIN, "0.01");
795                            SetDlgItemText(hDlg, IDC_ZONE_MAX, "2.00");
796                    }else if (quant_en) {
797                            SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(100,3100));
798                            SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETPOS, TRUE, get_dlgitem_float(hDlg, IDC_ZONE_QUANT, 100));
799                            SetDlgItemText(hDlg, IDC_ZONE_MIN, "1");
800                            SetDlgItemText(hDlg, IDC_ZONE_MAX, "31");
801                    }
802    
803                    bvops = (profiles[config->profile].flags&PROFILE_BVOP) && config->use_bvop;
804                    EnableDlgWindow(hDlg, IDC_ZONE_BVOPTHRESHOLD_S, bvops);
805                    EnableDlgWindow(hDlg, IDC_ZONE_BVOPTHRESHOLD, bvops);
806                    break;
807    
808            case IDD_DEBUG :
809                    cpu_force                       = IsDlgChecked(hDlg, IDC_CPU_FORCE);
810                    EnableDlgWindow(hDlg, IDC_CPU_MMX,              cpu_force);
811                    EnableDlgWindow(hDlg, IDC_CPU_MMXEXT,   cpu_force);
812                    EnableDlgWindow(hDlg, IDC_CPU_SSE,              cpu_force);
813                    EnableDlgWindow(hDlg, IDC_CPU_SSE2,             cpu_force);
814                    EnableDlgWindow(hDlg, IDC_CPU_3DNOW,    cpu_force);
815                    EnableDlgWindow(hDlg, IDC_CPU_3DNOWEXT, cpu_force);
816                    break;
817            }
818    }
819    
820    
821    /* upload config data into dialog */
822    void adv_upload(HWND hDlg, int idd, CONFIG * config)
823    {
824            switch (idd)
825            {
826            case IDD_PROFILE :
827                    SendDlgItemMessage(hDlg, IDC_PROFILE_PROFILE, CB_SETCURSEL, config->profile, 0);
828    
829                    SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_SETCURSEL, config->quant_type, 0);
830                    CheckDlg(hDlg, IDC_LUMMASK, config->lum_masking);
831                    CheckDlg(hDlg, IDC_INTERLACING, config->interlacing);
832                    CheckDlg(hDlg, IDC_QPEL, config->qpel);
833                    CheckDlg(hDlg, IDC_GMC, config->gmc);
834                    CheckDlg(hDlg, IDC_REDUCED, config->reduced_resolution);
835                    CheckDlg(hDlg, IDC_BVOP, config->use_bvop);
836    
837                    SetDlgItemInt(hDlg, IDC_MAXBFRAMES, config->max_bframes, FALSE);
838                    set_dlgitem_float(hDlg, IDC_BQUANTRATIO, config->bquant_ratio);
839                    set_dlgitem_float(hDlg, IDC_BQUANTOFFSET, config->bquant_offset);
840                    CheckDlg(hDlg, IDC_PACKED, config->packed);
841                    CheckDlg(hDlg, IDC_CLOSEDGOV, config->closed_gov);
842    
843                    break;
844            case IDD_AR:
845                    CheckRadioButton(hDlg, IDC_AR, IDC_PAR, config->ar_mode == 0 ? IDC_PAR : IDC_AR);
846                    SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_SETCURSEL, (config->display_aspect_ratio), 0);
847                    SetDlgItemInt(hDlg, IDC_ARX, config->ar_x, FALSE);
848                    SetDlgItemInt(hDlg, IDC_ARY, config->ar_y, FALSE);
849                    break;
850    
851            case IDD_LEVEL :
852                    SendDlgItemMessage(hDlg, IDC_LEVEL_PROFILE, CB_SETCURSEL, config->profile, 0);
853                    break;
854    
855            case IDD_RC_CBR :
856                    SetDlgItemInt(hDlg, IDC_CBR_REACTIONDELAY, config->rc_reaction_delay_factor, FALSE);
857                    SetDlgItemInt(hDlg, IDC_CBR_AVERAGINGPERIOD, config->rc_averaging_period, FALSE);
858                    SetDlgItemInt(hDlg, IDC_CBR_BUFFER, config->rc_buffer, FALSE);
859                    break;
860    
861            case IDD_RC_2PASS1 :
862                    SetDlgItemText(hDlg, IDC_STATS, config->stats);
863                    CheckDlg(hDlg, IDC_DISCARD1PASS, config->discard1pass);
864                    break;
865    
866            case IDD_RC_2PASS2 :
867                    SetDlgItemText(hDlg, IDC_STATS, config->stats);
868                    SetDlgItemInt(hDlg, IDC_KFBOOST, config->keyframe_boost, FALSE);
869                    SetDlgItemInt(hDlg, IDC_KFREDUCTION, config->kfreduction, FALSE);
870    
871                    SetDlgItemInt(hDlg, IDC_OVERFLOW_CONTROL_STRENGTH, config->overflow_control_strength, FALSE);
872                    SetDlgItemInt(hDlg, IDC_OVERIMP, config->twopass_max_overflow_improvement, FALSE);
873                    SetDlgItemInt(hDlg, IDC_OVERDEG, config->twopass_max_overflow_degradation, FALSE);
874    
875                    SetDlgItemInt(hDlg, IDC_CURVECOMPH, config->curve_compression_high, FALSE);
876                    SetDlgItemInt(hDlg, IDC_CURVECOMPL, config->curve_compression_low, FALSE);
877                    SetDlgItemInt(hDlg, IDC_MINKEY, config->kfthreshold, FALSE);
878                    break;
879    
880            case IDD_ZONE :
881                    SetDlgItemInt(hDlg, IDC_ZONE_FRAME, config->zones[config->cur_zone].frame, FALSE);
882    
883                    CheckDlgButton(hDlg, IDC_ZONE_MODE_WEIGHT,   config->zones[config->cur_zone].mode == RC_ZONE_WEIGHT);
884                    CheckDlgButton(hDlg, IDC_ZONE_MODE_QUANT,                config->zones[config->cur_zone].mode == RC_ZONE_QUANT);
885    
886                    set_dlgitem_float(hDlg, IDC_ZONE_WEIGHT, config->zones[config->cur_zone].weight);
887                    set_dlgitem_float(hDlg, IDC_ZONE_QUANT, config->zones[config->cur_zone].quant);
888    
889                    CheckDlgButton(hDlg, IDC_ZONE_FORCEIVOP, config->zones[config->cur_zone].type==XVID_TYPE_IVOP);
890                    CheckDlgButton(hDlg, IDC_ZONE_GREYSCALE, config->zones[config->cur_zone].greyscale);
891                    CheckDlgButton(hDlg, IDC_ZONE_CHROMAOPT, config->zones[config->cur_zone].chroma_opt);
892    
893                    SetDlgItemInt(hDlg, IDC_ZONE_BVOPTHRESHOLD, config->zones[config->cur_zone].bvop_threshold, TRUE);
894                    break;
895    
896            case IDD_MOTION :
897                    SendDlgItemMessage(hDlg, IDC_MOTION, CB_SETCURSEL, config->motion_search, 0);
898                    SendDlgItemMessage(hDlg, IDC_VHQ, CB_SETCURSEL, config->vhq_mode, 0);
899                    CheckDlg(hDlg, IDC_CHROMAME, config->chromame);
900                    CheckDlg(hDlg, IDC_CARTOON, config->cartoon_mode);
901                    CheckDlg(hDlg, IDC_TURBO, config->turbo);
902                    SetDlgItemInt(hDlg, IDC_FRAMEDROP, config->frame_drop_ratio, FALSE);
903                    SetDlgItemInt(hDlg, IDC_MAXKEY, config->max_key_interval, FALSE);
904                    break;
905    
906            case IDD_QUANT :
907                    SetDlgItemInt(hDlg, IDC_MINIQUANT, config->min_iquant, FALSE);
908                    SetDlgItemInt(hDlg, IDC_MAXIQUANT, config->max_iquant, FALSE);
909                    SetDlgItemInt(hDlg, IDC_MINPQUANT, config->min_pquant, FALSE);
910                    SetDlgItemInt(hDlg, IDC_MAXPQUANT, config->max_pquant, FALSE);
911                    SetDlgItemInt(hDlg, IDC_MINBQUANT, config->min_bquant, FALSE);
912                    SetDlgItemInt(hDlg, IDC_MAXBQUANT, config->max_bquant, FALSE);
913                    CheckDlg(hDlg, IDC_TRELLISQUANT, config->trellis_quant);
914                    break;
915    
916            case IDD_DEBUG :
917                    CheckDlg(hDlg, IDC_CPU_MMX, (config->cpu & XVID_CPU_MMX));
918                    CheckDlg(hDlg, IDC_CPU_MMXEXT, (config->cpu & XVID_CPU_MMXEXT));
919                    CheckDlg(hDlg, IDC_CPU_SSE, (config->cpu & XVID_CPU_SSE));
920                    CheckDlg(hDlg, IDC_CPU_SSE2, (config->cpu & XVID_CPU_SSE2));
921                    CheckDlg(hDlg, IDC_CPU_3DNOW, (config->cpu & XVID_CPU_3DNOW));
922                    CheckDlg(hDlg, IDC_CPU_3DNOWEXT, (config->cpu & XVID_CPU_3DNOWEXT));
923    
924                    CheckRadioButton(hDlg, IDC_CPU_AUTO, IDC_CPU_FORCE,
925                            config->cpu & XVID_CPU_FORCE ? IDC_CPU_FORCE : IDC_CPU_AUTO );
926    
927                    SetDlgItemInt(hDlg, IDC_NUMTHREADS, config->num_threads, FALSE);
928    
929                    SendDlgItemMessage(hDlg, IDC_FOURCC, CB_SETCURSEL, config->fourcc_used, 0);
930                    set_dlgitem_hex(hDlg, IDC_DEBUG, config->debug);
931                    CheckDlg(hDlg, IDC_VOPDEBUG, config->vop_debug);
932                    CheckDlg(hDlg, IDC_DISPLAY_STATUS, config->display_status);
933                    break;
934    
935            case IDD_DEC :
936                    CheckDlg(hDlg, IDC_DEC_DY,      pp_dy);
937                    CheckDlg(hDlg, IDC_DEC_DUV,     pp_duv);
938                    CheckDlg(hDlg, IDC_DEC_DR,      pp_dr);
939                    CheckDlg(hDlg, IDC_DEC_FE,      pp_fe);
940                    break;
941            }
942    }
943    
944    
945    /* download config data from dialog */
946    
947    void adv_download(HWND hDlg, int idd, CONFIG * config)
948    {
949            switch (idd)
950            {
951            case IDD_PROFILE :
952                    config->profile = SendDlgItemMessage(hDlg, IDC_PROFILE_PROFILE, CB_GETCURSEL, 0, 0);
953    
954                    config->quant_type = SendDlgItemMessage(hDlg, IDC_QUANTTYPE, CB_GETCURSEL, 0, 0);
955                    config->lum_masking = IsDlgChecked(hDlg, IDC_LUMMASK);
956                    config->interlacing = IsDlgChecked(hDlg, IDC_INTERLACING);
957                    config->qpel = IsDlgChecked(hDlg, IDC_QPEL);
958                    config->gmc = IsDlgChecked(hDlg, IDC_GMC);
959                    config->reduced_resolution = IsDlgChecked(hDlg, IDC_REDUCED);
960    
961                    config->use_bvop = IsDlgChecked(hDlg, IDC_BVOP);
962                    config->max_bframes = config_get_uint(hDlg, IDC_MAXBFRAMES, config->max_bframes);
963                    config->bquant_ratio = get_dlgitem_float(hDlg, IDC_BQUANTRATIO, config->bquant_ratio);
964                    config->bquant_offset = get_dlgitem_float(hDlg, IDC_BQUANTOFFSET, config->bquant_offset);
965                    config->packed = IsDlgChecked(hDlg, IDC_PACKED);
966                    config->closed_gov = IsDlgChecked(hDlg, IDC_CLOSEDGOV);
967                    break;
968    
969            case IDD_AR:
970                    config->ar_mode = IsDlgChecked(hDlg, IDC_PAR) ? 0:1;
971                    config->ar_x = config_get_uint(hDlg, IDC_ARX, config->ar_x);
972                    config->ar_y = config_get_uint(hDlg, IDC_ARY, config->ar_y);
973                    config->display_aspect_ratio = SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_GETCURSEL, 0, 0);
974                    if (config->display_aspect_ratio == 5) {
975                            config->par_x = config_get_uint(hDlg, IDC_PARX, config->par_x);
976                            config->par_y = config_get_uint(hDlg, IDC_PARY, config->par_y);
977                    }
978                    break;
979    
980            case IDD_LEVEL :
981                    config->profile = SendDlgItemMessage(hDlg, IDC_LEVEL_PROFILE, CB_GETCURSEL, 0, 0);
982                    break;
983    
984            case IDD_RC_CBR :
985                    config->rc_reaction_delay_factor = config_get_uint(hDlg, IDC_CBR_REACTIONDELAY, config->rc_reaction_delay_factor);
986                    config->rc_averaging_period = config_get_uint(hDlg, IDC_CBR_AVERAGINGPERIOD, config->rc_averaging_period);
987                    config->rc_buffer = config_get_uint(hDlg, IDC_CBR_BUFFER, config->rc_buffer);
988                    break;
989    
990            case IDD_RC_2PASS1 :
991                    if (GetDlgItemText(hDlg, IDC_STATS, config->stats, MAX_PATH) == 0)
992                            lstrcpy(config->stats, CONFIG_2PASS_FILE);
993                    config->discard1pass = IsDlgChecked(hDlg, IDC_DISCARD1PASS);
994                    break;
995    
996            case IDD_RC_2PASS2 :
997                    if (GetDlgItemText(hDlg, IDC_STATS, config->stats, MAX_PATH) == 0)
998                            lstrcpy(config->stats, CONFIG_2PASS_FILE);
999    
1000                    config->keyframe_boost = GetDlgItemInt(hDlg, IDC_KFBOOST, NULL, FALSE);
1001                    config->kfreduction = GetDlgItemInt(hDlg, IDC_KFREDUCTION, NULL, FALSE);
1002                    CONSTRAINVAL(config->keyframe_boost, 0, 1000);
1003    
1004                    config->overflow_control_strength = GetDlgItemInt(hDlg, IDC_OVERFLOW_CONTROL_STRENGTH, NULL, FALSE);
1005                    config->twopass_max_overflow_improvement = config_get_uint(hDlg, IDC_OVERIMP, config->twopass_max_overflow_improvement);
1006                    config->twopass_max_overflow_degradation = config_get_uint(hDlg, IDC_OVERDEG, config->twopass_max_overflow_degradation);
1007                    CONSTRAINVAL(config->twopass_max_overflow_improvement, 1, 80);
1008                    CONSTRAINVAL(config->twopass_max_overflow_degradation, 1, 80);
1009                    CONSTRAINVAL(config->overflow_control_strength, 0, 100);
1010    
1011                    config->curve_compression_high = GetDlgItemInt(hDlg, IDC_CURVECOMPH, NULL, FALSE);
1012                    config->curve_compression_low = GetDlgItemInt(hDlg, IDC_CURVECOMPL, NULL, FALSE);
1013                    CONSTRAINVAL(config->curve_compression_high, 0, 100);
1014                    CONSTRAINVAL(config->curve_compression_low, 0, 100);
1015    
1016                    config->kfthreshold = config_get_uint(hDlg, IDC_MINKEY, config->kfthreshold);
1017    
1018                    break;
1019    
1020            case IDD_ZONE :
1021                    config->zones[config->cur_zone].frame = config_get_uint(hDlg, IDC_ZONE_FRAME, config->zones[config->cur_zone].frame);
1022    
1023                    if (IsDlgChecked(hDlg, IDC_ZONE_MODE_WEIGHT)) {
1024                            config->zones[config->cur_zone].mode = RC_ZONE_WEIGHT;
1025                    }else if (IsDlgChecked(hDlg, IDC_ZONE_MODE_QUANT)) {
1026                            config->zones[config->cur_zone].mode = RC_ZONE_QUANT;
1027                    }
1028    
1029                    config->zones[config->cur_zone].weight = get_dlgitem_float(hDlg, IDC_ZONE_WEIGHT, config->zones[config->cur_zone].weight);
1030                    config->zones[config->cur_zone].quant =  get_dlgitem_float(hDlg, IDC_ZONE_QUANT, config->zones[config->cur_zone].quant);
1031    
1032                    config->zones[config->cur_zone].type = IsDlgButtonChecked(hDlg, IDC_ZONE_FORCEIVOP)?XVID_TYPE_IVOP:XVID_TYPE_AUTO;
1033                    config->zones[config->cur_zone].greyscale = IsDlgButtonChecked(hDlg, IDC_ZONE_GREYSCALE);
1034                    config->zones[config->cur_zone].chroma_opt = IsDlgButtonChecked(hDlg, IDC_ZONE_CHROMAOPT);
1035    
1036                    config->zones[config->cur_zone].bvop_threshold = config_get_int(hDlg, IDC_ZONE_BVOPTHRESHOLD, config->zones[config->cur_zone].bvop_threshold);
1037                    break;
1038    
1039            case IDD_MOTION :
1040                    config->motion_search = SendDlgItemMessage(hDlg, IDC_MOTION, CB_GETCURSEL, 0, 0);
1041                    config->vhq_mode = SendDlgItemMessage(hDlg, IDC_VHQ, CB_GETCURSEL, 0, 0);
1042                    config->chromame = IsDlgChecked(hDlg, IDC_CHROMAME);
1043                    config->cartoon_mode = IsDlgChecked(hDlg, IDC_CARTOON);
1044                    config->turbo = IsDlgChecked(hDlg, IDC_TURBO);
1045    
1046                    config->frame_drop_ratio = config_get_uint(hDlg, IDC_FRAMEDROP, config->frame_drop_ratio);
1047    
1048                    config->max_key_interval = config_get_uint(hDlg, IDC_MAXKEY, config->max_key_interval);
1049                    break;
1050    
1051            case IDD_QUANT :
1052                    config->min_iquant = config_get_uint(hDlg, IDC_MINIQUANT, config->min_iquant);
1053                    config->max_iquant = config_get_uint(hDlg, IDC_MAXIQUANT, config->max_iquant);
1054                    config->min_pquant = config_get_uint(hDlg, IDC_MINPQUANT, config->min_pquant);
1055                    config->max_pquant = config_get_uint(hDlg, IDC_MAXPQUANT, config->max_pquant);
1056                    config->min_bquant = config_get_uint(hDlg, IDC_MINBQUANT, config->min_bquant);
1057                    config->max_bquant = config_get_uint(hDlg, IDC_MAXBQUANT, config->max_bquant);
1058    
1059                    CONSTRAINVAL(config->min_iquant, 1, 31);
1060                    CONSTRAINVAL(config->max_iquant, config->min_iquant, 31);
1061                    CONSTRAINVAL(config->min_pquant, 1, 31);
1062                    CONSTRAINVAL(config->max_pquant, config->min_pquant, 31);
1063                    CONSTRAINVAL(config->min_bquant, 1, 31);
1064                    CONSTRAINVAL(config->max_bquant, config->min_bquant, 31);
1065    
1066                    config->trellis_quant = IsDlgChecked(hDlg, IDC_TRELLISQUANT);
1067                    break;
1068    
1069            case IDD_DEBUG :
1070                    config->cpu = 0;
1071                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_MMX)    ? XVID_CPU_MMX : 0;
1072                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_MMXEXT)   ? XVID_CPU_MMXEXT : 0;
1073                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_SSE)    ? XVID_CPU_SSE : 0;
1074                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_SSE2)  ? XVID_CPU_SSE2 : 0;
1075                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_3DNOW)        ? XVID_CPU_3DNOW : 0;
1076                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_3DNOWEXT) ? XVID_CPU_3DNOWEXT : 0;
1077                    config->cpu |= IsDlgChecked(hDlg, IDC_CPU_FORCE)        ? XVID_CPU_FORCE : 0;
1078    
1079                    config->num_threads = config_get_uint(hDlg, IDC_NUMTHREADS, config->num_threads);
1080    
1081                    config->fourcc_used = SendDlgItemMessage(hDlg, IDC_FOURCC, CB_GETCURSEL, 0, 0);
1082                    config->debug = get_dlgitem_hex(hDlg, IDC_DEBUG, config->debug);
1083                    config->vop_debug = IsDlgChecked(hDlg, IDC_VOPDEBUG);
1084                    config->display_status = IsDlgChecked(hDlg, IDC_DISPLAY_STATUS);
1085                    break;
1086    
1087            case IDD_DEC :
1088                    pp_dy = IsDlgChecked(hDlg, IDC_DEC_DY);
1089                    pp_duv = IsDlgChecked(hDlg, IDC_DEC_DUV);
1090                    pp_dr = IsDlgChecked(hDlg, IDC_DEC_DR);
1091                    pp_fe = IsDlgChecked(hDlg, IDC_DEC_FE);
1092                    break;
1093            }
1094    }
1095    
1096    
1097    
1098    /* advanced dialog proc */
1099    
1100    BOOL CALLBACK adv_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1101    {
1102            PROPSHEETINFO *psi;
1103    
1104            psi = (PROPSHEETINFO*)GetWindowLong(hDlg, GWL_USERDATA);
1105    
1106            switch (uMsg)
1107            {
1108            case WM_INITDIALOG :
1109                    psi = (PROPSHEETINFO*) ((LPPROPSHEETPAGE)lParam)->lParam;
1110                    SetWindowLong(hDlg, GWL_USERDATA, (LPARAM)psi);
1111    
1112                    if (g_hTooltip)
1113                            EnumChildWindows(hDlg, enum_tooltips, 0);
1114    
1115                    adv_init(hDlg, psi->idd, psi->config);
1116                    break;
1117    
1118            case WM_COMMAND :
1119                    if (HIWORD(wParam) == BN_CLICKED)
1120                    {
1121                            switch (LOWORD(wParam))
1122                            {
1123                            case IDC_BVOP :
1124                            case IDC_ZONE_MODE_WEIGHT :
1125                            case IDC_ZONE_MODE_QUANT :
1126                            case IDC_ZONE_BVOPTHRESHOLD_ENABLE :
1127                            case IDC_CPU_AUTO :
1128                            case IDC_CPU_FORCE :
1129                            case IDC_AR :
1130                            case IDC_PAR :
1131                                    adv_mode(hDlg, psi->idd, psi->config);
1132                                    break;
1133    
1134                            case IDC_QUANTMATRIX :
1135                                    DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_QUANTMATRIX), hDlg, quantmatrix_proc, (LPARAM)psi->config);
1136                                    break;
1137    
1138                            case IDC_STATS_BROWSE :
1139                            {
1140                                    OPENFILENAME ofn;
1141                                    char tmp[MAX_PATH];
1142    
1143                                    GetDlgItemText(hDlg, IDC_STATS, tmp, MAX_PATH);
1144    
1145                                    memset(&ofn, 0, sizeof(OPENFILENAME));
1146                                    ofn.lStructSize = sizeof(OPENFILENAME);
1147    
1148                                    ofn.hwndOwner = hDlg;
1149                                    ofn.lpstrFilter = "bitrate curve (*.stats)\0*.stats\0All files (*.*)\0*.*\0\0";
1150                                    ofn.lpstrFile = tmp;
1151                                    ofn.nMaxFile = MAX_PATH;
1152                                    ofn.Flags = OFN_PATHMUSTEXIST;
1153    
1154                                    if (psi->idd == IDD_RC_2PASS1) {
1155                                            ofn.Flags |= OFN_OVERWRITEPROMPT;
1156                                    }else{
1157                                            ofn.Flags |= OFN_FILEMUSTEXIST;
1158                                    }
1159    
1160                                    if (GetSaveFileName(&ofn))
1161                                    {
1162                                            SetDlgItemText(hDlg, IDC_STATS, tmp);
1163                                    }
1164                            }
1165    
1166                            case IDC_ZONE_FETCH :
1167                                    SetDlgItemInt(hDlg, IDC_ZONE_FRAME, psi->config->ci.ciActiveFrame, FALSE);
1168                                    break;
1169    
1170                            case IDC_AR_DEFAULT:
1171                                    CheckRadioButton(hDlg, IDC_AR, IDC_PAR, IDC_PAR);
1172                                    SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_SETCURSEL, 0, 0);
1173                                    adv_mode(hDlg, psi->idd, psi->config);
1174                                    break;
1175                            case IDC_AR_4_3:
1176                                    SetDlgItemInt(hDlg, IDC_ARX, 4, FALSE);
1177                                    SetDlgItemInt(hDlg, IDC_ARY, 3, FALSE);
1178                                    CheckRadioButton(hDlg, IDC_AR, IDC_PAR, IDC_AR);
1179                                    adv_mode(hDlg, psi->idd, psi->config);
1180                                    break;
1181                            case IDC_AR_16_9:
1182                                    SetDlgItemInt(hDlg, IDC_ARX, 16, FALSE);
1183                                    SetDlgItemInt(hDlg, IDC_ARY, 9, FALSE);
1184                                    CheckRadioButton(hDlg, IDC_AR, IDC_PAR, IDC_AR);
1185                                    adv_mode(hDlg, psi->idd, psi->config);
1186                                    break;
1187                            case IDC_AR_235_100:
1188                                    SetDlgItemInt(hDlg, IDC_ARX, 235, FALSE);
1189                                    SetDlgItemInt(hDlg, IDC_ARY, 100, FALSE);
1190                                    CheckRadioButton(hDlg, IDC_AR, IDC_PAR, IDC_AR);
1191                                    adv_mode(hDlg, psi->idd, psi->config);
1192                                    break;
1193    
1194                            default :
1195                                    return TRUE;
1196                            }
1197                    }else if (HIWORD(wParam) == LBN_SELCHANGE &&
1198                            (LOWORD(wParam) == IDC_PROFILE_PROFILE ||
1199                             LOWORD(wParam) == IDC_LEVEL_PROFILE ||
1200                             LOWORD(wParam) == IDC_QUANTTYPE ||
1201                             LOWORD(wParam) == IDC_ASPECT_RATIO))
1202                    {
1203                            adv_mode(hDlg, psi->idd, psi->config);
1204                    }else if (HIWORD(wParam) == EN_UPDATE && (LOWORD(wParam)==IDC_ZONE_WEIGHT || LOWORD(wParam)==IDC_ZONE_QUANT)) {
1205    
1206                            SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETPOS, TRUE,
1207                                            get_dlgitem_float(hDlg, LOWORD(wParam), 100));
1208                    } else if (HIWORD(wParam) == EN_UPDATE && (LOWORD(wParam)==IDC_PARX || LOWORD(wParam)==IDC_PARY)) {
1209                            if (5 == SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_GETCURSEL, 0, 0)) {
1210                                    if(LOWORD(wParam)==IDC_PARX)
1211                                            psi->config->par_x = config_get_uint(hDlg, LOWORD(wParam), psi->config->par_x);
1212                                    else
1213                                            psi->config->par_y = config_get_uint(hDlg, LOWORD(wParam), psi->config->par_y);
1214                            }
1215                    } else
1216                            return 0;
1217                    break;
1218    
1219            case WM_HSCROLL :
1220                    if((HWND)lParam == GetDlgItem(hDlg, IDC_ZONE_SLIDER)) {
1221                            int idc = IsDlgChecked(hDlg, IDC_ZONE_MODE_WEIGHT) ? IDC_ZONE_WEIGHT : IDC_ZONE_QUANT;
1222                            set_dlgitem_float(hDlg, idc, SendMessage((HWND)lParam, TBM_GETPOS, 0, 0) );
1223                            break;
1224                    }
1225                    return 0;
1226    
1227    
1228            case WM_NOTIFY :
1229                    switch (((NMHDR *)lParam)->code)
1230                    {
1231                    case PSN_SETACTIVE :
1232                            OutputDebugString("PSN_SET");
1233                            adv_upload(hDlg, psi->idd, psi->config);
1234                            adv_mode(hDlg, psi->idd, psi->config);
1235                            SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
1236                            break;
1237    
1238                    case PSN_KILLACTIVE :
1239                            OutputDebugString("PSN_KILL");
1240                            adv_download(hDlg, psi->idd, psi->config);
1241                            SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
1242                            break;
1243    
1244                    case PSN_APPLY :
1245                            OutputDebugString("PSN_APPLY");
1246                            psi->config->save = TRUE;
1247                            SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
1248                            break;
1249                    }
1250                    break;
1251    
1252            default :
1253                    return 0;
1254            }
1255    
1256            return 1;
1257    }
1258    
1259    
1260    
1261    
1262    /* load advanced options property sheet
1263      returns true, if the user accepted the changes
1264      or fasle if changes were canceled.
1265    
1266      */
1267    BOOL adv_dialog(HWND hParent, CONFIG * config, const int * dlgs, int size)
1268    {
1269            PROPSHEETINFO psi[6];
1270            PROPSHEETPAGE psp[6];
1271            PROPSHEETHEADER psh;
1272            CONFIG temp;
1273            int i;
1274    
1275            config->save = FALSE;
1276            memcpy(&temp, config, sizeof(CONFIG));
1277    
1278            for (i=0; i<size; i++)
1279            {
1280                    psp[i].dwSize = sizeof(PROPSHEETPAGE);
1281                    psp[i].dwFlags = 0;
1282                    psp[i].hInstance = g_hInst;
1283                    psp[i].pfnDlgProc = adv_proc;
1284                    psp[i].lParam = (LPARAM)&psi[i];
1285                    psp[i].pfnCallback = NULL;
1286                    psp[i].pszTemplate = MAKEINTRESOURCE(dlgs[i]);
1287    
1288                    psi[i].idd = dlgs[i];
1289                    psi[i].config = &temp;
1290            }
1291    
1292            psh.dwSize = sizeof(PROPSHEETHEADER);
1293            psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
1294            psh.hwndParent = hParent;
1295            psh.hInstance = g_hInst;
1296            psh.pszCaption = (LPSTR) "XviD Configuration";
1297            psh.nPages = size;
1298            psh.nStartPage = 0;
1299            psh.ppsp = (LPCPROPSHEETPAGE)&psp;
1300            psh.pfnCallback = NULL;
1301            PropertySheet(&psh);
1302    
1303            if (temp.save)
1304                    memcpy(config, &temp, sizeof(CONFIG));
1305    
1306            return temp.save;
1307    }
1308    
1309    /* ===================================================================================== */
1310    /* MAIN DIALOG ========================================================================= */
1311    /* ===================================================================================== */
1312    
1313    
1314    void main_insert_zone(HWND hDlg, zone_t * s, int i, BOOL insert)
1315    {
1316            char tmp[32];
1317    
1318            wsprintf(tmp,"%i",s->frame);
1319    
1320            if (insert) {
1321                    LVITEM lvi;
1322    
1323                    lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
1324                    lvi.state = 0;
1325                    lvi.stateMask = 0;
1326                    lvi.iImage = 0;
1327                    lvi.pszText = tmp;
1328                    lvi.cchTextMax = strlen(tmp);
1329                    lvi.iItem = i;
1330                    lvi.iSubItem = 0;
1331                    ListView_InsertItem(hDlg, &lvi);
1332            }else{
1333                    ListView_SetItemText(hDlg, i, 0, tmp);
1334            }
1335    
1336            if (s->mode == RC_ZONE_WEIGHT) {
1337                    sprintf(tmp,"W %.2f",(float)s->weight/100);
1338            }else if (s->mode == RC_ZONE_QUANT) {
1339                    sprintf(tmp,"Q %.2f",(float)s->quant/100);
1340            }else {
1341                    strcpy(tmp,"EXT");
1342            }
1343            ListView_SetItemText(hDlg, i, 1, tmp);
1344    
1345            tmp[0] = '\0';
1346            if (s->type==XVID_TYPE_IVOP)
1347                    strcat(tmp, "K ");
1348    
1349            if (s->greyscale)
1350                    strcat(tmp, "G ");
1351    
1352            if (s->chroma_opt)
1353                    strcat(tmp, "C ");
1354    
1355            ListView_SetItemText(hDlg, i, 2, tmp);
1356    }
1357    
1358    static int g_use_bitrate = 1;
1359    
1360    void main_mode(HWND hDlg, CONFIG * config)
1361    {
1362            const int profile = SendDlgItemMessage(hDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0);
1363            const int rc_mode = SendDlgItemMessage(hDlg, IDC_MODE, CB_GETCURSEL, 0, 0);
1364            /* enable target rate/size control only for 1pass and 2pass  modes*/
1365            const int target_en = rc_mode==RC_MODE_1PASS || rc_mode==RC_MODE_2PASS2;
1366    
1367            char buf[16];
1368            int max;
1369    
1370            g_use_bitrate = rc_mode==RC_MODE_1PASS || config->use_2pass_bitrate;
1371    
1372            if (g_use_bitrate) {
1373                    SetDlgItemText(hDlg, IDC_BITRATE_S, "Target bitrate (kbps):");
1374    
1375                    wsprintf(buf, "%i kbps", DEFAULT_MIN_KBPS);
1376                    SetDlgItemText(hDlg, IDC_BITRATE_MIN, buf);
1377    
1378                    max = profiles[profile].max_bitrate;
1379                    if (max == 0) max = DEFAULT_MAX_KBPS;
1380                    wsprintf(buf, "%i kbps", max);
1381                    SetDlgItemText(hDlg, IDC_BITRATE_MAX, buf);
1382    
1383                    SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(DEFAULT_MIN_KBPS, max));
1384                    SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE,
1385                                                    config_get_uint(hDlg, IDC_BITRATE, DEFAULT_MIN_KBPS) );
1386    
1387            }else{
1388                    SetDlgItemText(hDlg, IDC_BITRATE_S, "Target size (kbytes):");
1389            }
1390    
1391            EnableDlgWindow(hDlg, IDC_BITRATE_S, target_en);
1392            EnableDlgWindow(hDlg, IDC_BITRATE, target_en);
1393    
1394            EnableDlgWindow(hDlg, IDC_BITRATE_MIN, target_en && g_use_bitrate);
1395            EnableDlgWindow(hDlg, IDC_BITRATE_MAX, target_en && g_use_bitrate);
1396            EnableDlgWindow(hDlg, IDC_SLIDER, target_en && g_use_bitrate);
1397    }
1398    
1399    
1400    
1401    void main_upload(HWND hDlg, CONFIG * config)
1402    {
1403    
1404            SendDlgItemMessage(hDlg, IDC_PROFILE, CB_SETCURSEL, config->profile, 0);
1405            SendDlgItemMessage(hDlg, IDC_MODE, CB_SETCURSEL, config->mode, 0);
1406    
1407            if (g_use_bitrate) {
1408                    SetDlgItemInt(hDlg, IDC_BITRATE, config->bitrate, FALSE);
1409            }else{
1410                    SetDlgItemInt(hDlg, IDC_BITRATE, config->desired_size, FALSE);
1411            }
1412    
1413            zones_update(hDlg, config);}
1414    
1415    
1416    /* downloads data from main dialog */
1417    void main_download(HWND hDlg, CONFIG * config)
1418    {
1419            config->profile = SendDlgItemMessage(hDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0);
1420            config->mode = SendDlgItemMessage(hDlg, IDC_MODE, CB_GETCURSEL, 0, 0);
1421    
1422            if (g_use_bitrate) {
1423                    config->bitrate = config_get_uint(hDlg, IDC_BITRATE, config->bitrate);
1424            }else{
1425                    config->desired_size = config_get_uint(hDlg, IDC_BITRATE, config->desired_size);
1426            }
1427    }
1428    
1429    
1430    /* main dialog proc */
1431    
1432    static const int profile_dlgs[] = { IDD_PROFILE, IDD_LEVEL, IDD_AR };
1433    static const int single_dlgs[] = { IDD_RC_CBR };
1434    static const int pass1_dlgs[] = { IDD_RC_2PASS1 };
1435    static const int pass2_dlgs[] = { IDD_RC_2PASS2 };
1436    static const int zone_dlgs[] = { IDD_ZONE };
1437    static const int decoder_dlgs[] = { IDD_DEC };
1438    static const int adv_dlgs[] = { IDD_MOTION, IDD_QUANT, IDD_DEBUG};
1439    
1440    
1441    BOOL CALLBACK main_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1442    {
1443            CONFIG* config = (CONFIG*)GetWindowLong(hDlg, GWL_USERDATA);
1444            unsigned int i;
1445    
1446            switch (uMsg)
1447            {
1448            case WM_INITDIALOG :
1449                    SetWindowLong(hDlg, GWL_USERDATA, lParam);
1450                    config = (CONFIG*)lParam;
1451    
1452                    for (i=0; i<sizeof(profiles)/sizeof(profile_t); i++)
1453                            SendDlgItemMessage(hDlg, IDC_PROFILE, CB_ADDSTRING, 0, (LPARAM)profiles[i].name);
1454    
1455                    SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"Single pass");
1456                    SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"Twopass - 1st pass");
1457                    SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"Twopass - 2nd pass");
1458    #ifdef _DEBUG
1459                    SendDlgItemMessage(hDlg, IDC_MODE, CB_ADDSTRING, 0, (LPARAM)"Null test speed");
1460    #endif
1461    
1462                    InitCommonControls();
1463    
1464                    if ((g_hTooltip = CreateWindow(TOOLTIPS_CLASS, NULL, TTS_ALWAYSTIP,
1465                                    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1466                                    NULL, NULL, g_hInst, NULL)))
1467                    {
1468                            SetWindowPos(g_hTooltip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
1469                            SendMessage(g_hTooltip, TTM_SETDELAYTIME, TTDT_AUTOMATIC, MAKELONG(1500, 0));
1470                            SendMessage(g_hTooltip, TTM_SETMAXTIPWIDTH, 0, 400);
1471    
1472                            EnumChildWindows(hDlg, enum_tooltips, 0);
1473                    }
1474    
1475                    SetClassLong(GetDlgItem(hDlg, IDC_BITRATE_S), GCL_HCURSOR, (LONG)LoadCursor(NULL, IDC_HAND));
1476    
1477                    {
1478                            DWORD ext_style = ListView_GetExtendedListViewStyle(GetDlgItem(hDlg,IDC_ZONES));
1479                            ext_style |= LVS_EX_FULLROWSELECT | LVS_EX_FLATSB ;
1480                            ListView_SetExtendedListViewStyle(GetDlgItem(hDlg,IDC_ZONES), ext_style);
1481                    }
1482    
1483                    {
1484                            typedef struct {
1485                                    char * name;
1486                                    int value;
1487                            } char_int_t;
1488    
1489                            const static char_int_t columns[] = {
1490                                    {"Frame #",      64},
1491                                    {"Weight/Quant",  82},
1492                                    {"Modifiers",   120}};
1493    
1494                            LVCOLUMN lvc;
1495                            int i;
1496    
1497                            /* Initialize the LVCOLUMN structure.  */
1498                            lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
1499                            lvc.fmt = LVCFMT_LEFT;
1500    
1501                            /* Add the columns.  */
1502                            for (i=0; i<sizeof(columns)/sizeof(char_int_t); i++) {
1503                                    lvc.pszText = (char*)columns[i].name;
1504                                    lvc.cchTextMax = strlen(columns[i].name);
1505                                    lvc.iSubItem = i;
1506                                    lvc.cx = columns[i].value;  /* column width, pixels */
1507                                    ListView_InsertColumn(GetDlgItem(hDlg,IDC_ZONES), i, &lvc);
1508                            }
1509                    }
1510    
1511                    /* XXX: main_mode needs RC_MODE_xxx, main_upload needs g_use_bitrate set correctly... */
1512                    main_upload(hDlg, config);
1513                    main_mode(hDlg, config);
1514                    main_upload(hDlg, config);
1515                    break;
1516    
1517            case WM_NOTIFY :
1518                    {
1519                            NMHDR * n = (NMHDR*)lParam;
1520    
1521                            if (n->code == NM_DBLCLK) {
1522                                     NMLISTVIEW * nmlv = (NMLISTVIEW*) lParam;
1523                                     config->cur_zone = nmlv->iItem;
1524    
1525                                     main_download(hDlg, config);
1526                                     if (config->cur_zone >= 0 && adv_dialog(hDlg, config, zone_dlgs, sizeof(zone_dlgs)/sizeof(int))) {
1527                                             zones_update(hDlg, config);
1528                                     }
1529                                     break;
1530                            }
1531    
1532                            if (n->code == NM_RCLICK) {
1533                                    OutputDebugString("Right click");
1534                            }
1535                    break;
1536                    }
1537    
1538            case WM_COMMAND :
1539                    if (HIWORD(wParam) == BN_CLICKED) {
1540    
1541                            switch(LOWORD(wParam)) {
1542                            case IDC_PROFILE_ADV :
1543                                    main_download(hDlg, config);
1544                                    adv_dialog(hDlg, config, profile_dlgs, sizeof(profile_dlgs)/sizeof(int));
1545    
1546                                    SendDlgItemMessage(hDlg, IDC_PROFILE, CB_SETCURSEL, config->profile, 0);
1547                                    main_mode(hDlg, config);
1548                                    break;
1549    
1550                            case IDC_MODE_ADV :
1551                                    main_download(hDlg, config);
1552                                    if (config->mode == RC_MODE_1PASS) {
1553                                            adv_dialog(hDlg, config, single_dlgs, sizeof(single_dlgs)/sizeof(int));
1554                                    }else if (config->mode == RC_MODE_2PASS1) {
1555                                            adv_dialog(hDlg, config, pass1_dlgs, sizeof(pass1_dlgs)/sizeof(int));
1556                                    }else if (config->mode == RC_MODE_2PASS2) {
1557                                            adv_dialog(hDlg, config, pass2_dlgs, sizeof(pass2_dlgs)/sizeof(int));
1558                                    }
1559                                    break;
1560    
1561    
1562                            case IDC_BITRATE_S :
1563                                    /* alternate between bitrate/desired_length metrics */
1564                                    main_download(hDlg, config);
1565                                    config->use_2pass_bitrate = !config->use_2pass_bitrate;
1566                                    main_mode(hDlg, config);
1567                                    main_upload(hDlg, config);
1568                                    break;
1569    
1570                            case IDC_DECODER :
1571                                    main_download(hDlg, config);
1572                                    adv_dialog(hDlg, config, decoder_dlgs, sizeof(decoder_dlgs)/sizeof(int));
1573                                    main_mode(hDlg, config);
1574                                    break;
1575    
1576                            case IDC_ADD :
1577                            {
1578                                    int i, sel, new_frame;
1579    
1580                                    if (config->num_zones >= MAX_ZONES) {
1581                                            MessageBox(hDlg, "Exceeded maximum number of zones.\nIncrease config.h:MAX_ZONES and rebuild.", "Warning", 0);
1582                                            break;
1583                                    }
1584    
1585                                    sel = ListView_GetNextItem(GetDlgItem(hDlg, IDC_ZONES), -1, LVNI_SELECTED);
1586    
1587                                    if (sel<0) {
1588                                            if (config->ci_valid && config->ci.ciActiveFrame>0) {
1589                                                    for(sel=0; sel<config->num_zones-1 && config->zones[sel].frame<config->ci.ciActiveFrame; sel++) ;
1590                                                    sel--;
1591                                                    new_frame = config->ci.ciActiveFrame;
1592                                            }else{
1593                                                    sel = config->num_zones-1;
1594                                                    new_frame = sel<0 ? 0 : config->zones[sel].frame + 1;
1595                                            }
1596                                    }else{
1597                                            new_frame = config->zones[sel].frame + 1;
1598                                    }
1599    
1600                                    for(i=config->num_zones-1; i>sel; i--) {
1601                                            config->zones[i+1] = config->zones[i];
1602                                    }
1603                                    config->num_zones++;
1604                                    config->zones[sel+1].frame = new_frame;
1605                                    config->zones[sel+1].mode = RC_ZONE_WEIGHT;
1606                                    config->zones[sel+1].weight = 100;
1607                                    config->zones[sel+1].quant = 500;
1608                                    config->zones[sel+1].type = XVID_TYPE_AUTO;
1609                                    config->zones[sel+1].greyscale = 0;
1610                                    config->zones[sel+1].chroma_opt = 0;
1611                                    config->zones[sel+1].bvop_threshold = 0;
1612    
1613                                    ListView_SetItemState(GetDlgItem(hDlg, IDC_ZONES), sel, 0x00000000, LVIS_SELECTED);
1614                                    zones_update(hDlg, config);
1615                                    ListView_SetItemState(GetDlgItem(hDlg, IDC_ZONES), sel+1, 0xffffffff, LVIS_SELECTED);
1616                                    break;
1617                            }
1618    
1619                            case IDC_REMOVE :
1620                            {
1621                                    int i, sel;
1622                                    sel = ListView_GetNextItem(GetDlgItem(hDlg, IDC_ZONES), -1, LVNI_SELECTED);
1623    
1624                                    if (sel == -1 || config->num_zones < 1) {
1625                                            /*MessageBox(hDlg, "Nothing selected", "Warning", 0);*/
1626                                            break;
1627                                    }
1628    
1629                                    for (i=sel; i<config->num_zones-1; i++)
1630                                            config->zones[i] = config->zones[i+1];
1631    
1632                                    config->num_zones--;
1633    
1634                                    zones_update(hDlg, config);
1635                                    break;
1636                            }
1637    
1638                            case IDC_EDIT :
1639                                    main_download(hDlg, config);
1640                                    config->cur_zone = ListView_GetNextItem(GetDlgItem(hDlg, IDC_ZONES), -1, LVNI_SELECTED);
1641                                    if (config->cur_zone != -1 && adv_dialog(hDlg, config, zone_dlgs, sizeof(zone_dlgs)/sizeof(int))) {
1642                                            zones_update(hDlg, config);
1643                                    }
1644                                    break;
1645    
1646                            case IDC_ADVANCED :
1647                                    main_download(hDlg, config);
1648                                    adv_dialog(hDlg, config, adv_dlgs, sizeof(adv_dlgs)/sizeof(int));
1649                                    break;
1650    
1651                            case IDC_DEFAULTS :
1652                                    config_reg_default(config);
1653                                    main_upload(hDlg, config);
1654                                    break;
1655    
1656                            case IDOK :
1657                                    main_download(hDlg, config);
1658                                    config->save = TRUE;
1659                                    EndDialog(hDlg, IDOK);
1660                                    break;
1661    
1662                            case IDCANCEL :
1663                                    config->save = FALSE;
1664                                    EndDialog(hDlg, IDCANCEL);
1665                                    break;
1666                            }
1667                    }else if (HIWORD(wParam) == LBN_SELCHANGE &&
1668                            (LOWORD(wParam)==IDC_PROFILE || LOWORD(wParam)==IDC_MODE)) {
1669    
1670                            main_download(hDlg, config);
1671                            main_mode(hDlg, config);
1672                            main_upload(hDlg, config);
1673    
1674                    }else if (HIWORD(wParam)==EN_UPDATE && LOWORD(wParam)==IDC_BITRATE) {
1675    
1676                            if (g_use_bitrate) {
1677                                    SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE,
1678                                                    config_get_uint(hDlg, IDC_BITRATE, DEFAULT_MIN_KBPS) );
1679                            }
1680    
1681                    }else {
1682                            return 0;
1683                    }
1684                    break;
1685    
1686            case WM_HSCROLL :
1687                    if((HWND)lParam == GetDlgItem(hDlg, IDC_SLIDER)) {
1688                            SetDlgItemInt(hDlg, IDC_BITRATE, SendMessage((HWND)lParam, TBM_GETPOS, 0, 0), FALSE);
1689                            break;
1690                    }
1691                    return 0;
1692    
1693            default :
1694                    return 0;
1695            }
1696    
1697            return 1;
1698    }
1699    
1700    
1701    
1702    /* ===================================================================================== */
1703    /* ABOUT DIALOG ======================================================================== */
1704    /* ===================================================================================== */
1705    
1706    BOOL CALLBACK about_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1707    {
1708            switch (uMsg)
1709            {
1710            case WM_INITDIALOG :
1711                    {
1712                            xvid_gbl_info_t info;
1713                            char core[100];
1714                            HFONT hFont;
1715                            LOGFONT lfData;
1716                            HINSTANCE m_hdll;
1717    
1718                            SetDlgItemText(hDlg, IDC_BUILD, XVID_BUILD);
1719                            SetDlgItemText(hDlg, IDC_SPECIAL_BUILD, XVID_SPECIAL_BUILD);
1720    
1721                            memset(&info, 0, sizeof(info));
1722                            info.version = XVID_VERSION;
1723    
1724                            m_hdll = LoadLibrary(XVID_DLL_NAME);
1725                            if (m_hdll != NULL) {
1726    
1727                                    ((int (__cdecl *)(void *, int, void *, void *))GetProcAddress(m_hdll, "xvid_global"))
1728                                            (0, XVID_GBL_INFO, &info, NULL);
1729    
1730                                    wsprintf(core, "xvidcore.dll version %d.%d.%d (\"%s\")",
1731                                            XVID_VERSION_MAJOR(info.actual_version),
1732                                            XVID_VERSION_MINOR(info.actual_version),
1733                                            XVID_VERSION_PATCH(info.actual_version),
1734                                            info.build);
1735    
1736                                    FreeLibrary(m_hdll);
1737                            } else {
1738                                    wsprintf(core, "xvidcore.dll not found!");
1739                            }
1740    
1741                            SetDlgItemText(hDlg, IDC_CORE, core);
1742    
1743                            hFont = (HFONT)SendDlgItemMessage(hDlg, IDC_WEBSITE, WM_GETFONT, 0, 0L);
1744    
1745                            if (GetObject(hFont, sizeof(LOGFONT), &lfData)) {
1746                                    lfData.lfUnderline = 1;
1747    
1748                                    hFont = CreateFontIndirect(&lfData);
1749                                    if (hFont) {
1750                                            SendDlgItemMessage(hDlg, IDC_WEBSITE, WM_SETFONT, (WPARAM)hFont, 1L);
1751                                    }
1752                            }
1753    
1754                            SetClassLong(GetDlgItem(hDlg, IDC_WEBSITE), GCL_HCURSOR, (LONG)LoadCursor(NULL, IDC_HAND));
1755                            SetDlgItemText(hDlg, IDC_WEBSITE, XVID_WEBSITE);
1756                    }
1757                    break;
1758            case WM_CTLCOLORSTATIC :
1759                    if ((HWND)lParam == GetDlgItem(hDlg, IDC_WEBSITE))
1760                    {
1761                            SetBkMode((HDC)wParam, TRANSPARENT) ;
1762                            SetTextColor((HDC)wParam, RGB(0x00,0x00,0xc0));
1763                            return (BOOL)GetStockObject(NULL_BRUSH);
1764                    }
1765                    return 0;
1766    
1767            case WM_COMMAND :
1768                    if (LOWORD(wParam) == IDC_WEBSITE && HIWORD(wParam) == STN_CLICKED)
1769                    {
1770                            ShellExecute(hDlg, "open", XVID_WEBSITE, NULL, NULL, SW_SHOWNORMAL);
1771                    }
1772                    else if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
1773                    {
1774                            EndDialog(hDlg, LOWORD(wParam));
1775                    }
1776                    break;
1777    
1778            default :
1779                    return 0;
1780            }
1781    
1782            return 1;
1783    }
1784    
1785    static void
1786    sort_zones(zone_t * zones, int zone_num, int * sel)
1787    {
1788            int i, j;
1789            zone_t tmp;
1790            for (i = 0; i < zone_num; i++) {
1791                    int cur = i;
1792                    int min_f = zones[i].frame;
1793                    for (j = i + 1; j < zone_num; j++) {
1794                            if (zones[j].frame < min_f) {
1795                                    min_f = zones[j].frame;
1796                                    cur = j;
1797                            }
1798                    }
1799                    if (cur != i) {
1800                            tmp = zones[i];
1801                            zones[i] = zones[cur];
1802                            zones[cur] = tmp;
1803                            if (i == *sel) *sel = cur;
1804                            else if (cur == *sel) *sel = i;
1805                    }
1806            }
1807    }
1808    
1809    
1810    static void
1811    zones_update(HWND hDlg, CONFIG * config)
1812    {
1813            int i, sel;
1814    
1815            sel = ListView_GetNextItem(GetDlgItem(hDlg, IDC_ZONES), -1, LVNI_SELECTED);
1816    
1817            sort_zones(config->zones, config->num_zones, &sel);
1818    
1819            ListView_DeleteAllItems(GetDlgItem(hDlg,IDC_ZONES));
1820    
1821            for (i = 0; i < config->num_zones; i++)
1822                    main_insert_zone(GetDlgItem(hDlg,IDC_ZONES), &config->zones[i], i, TRUE);
1823    
1824            if (sel == -1 && config->num_zones > 0) sel = 0;
1825            if (sel >= config->num_zones) sel = config->num_zones-1;
1826    
1827            config->cur_zone = sel;
1828            ListView_SetItemState(GetDlgItem(hDlg, IDC_ZONES), sel, 0xffffffff, LVIS_SELECTED);
1829    }

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

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