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

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

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