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

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

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