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

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

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