[svn] / trunk / xvidcore / vfw / src / config.c Repository:
ViewVC logotype

Annotation of /trunk/xvidcore/vfw/src/config.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1382 - (view) (download)

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

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