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

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

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