📄 config.c.svn-base
字号:
/***************************************************************************** * config.c: vfw x264 encoder ***************************************************************************** * Copyright (C) 2003 Laurent Aimar * $Id: config.c,v 1.1 2004/06/03 19:27:09 fenrir Exp $ * * Authors: Justin Clay * Laurent Aimar <fenrir@via.ecp.fr> * Antony Boucher <proximodo@free.fr> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************//************************************************************************** * * History: * * 2004.05.14 CBR encode mode support * **************************************************************************/#include "x264vfw.h"#include <stdio.h> /* sprintf */#include <commctrl.h>#ifdef _MSC_VER#define X264_VERSION ""#else#include "config.h"#endif/* Registry */#define X264_REG_KEY HKEY_CURRENT_USER#define X264_REG_PARENT "Software\\GNU"#define X264_REG_CHILD "x264"#define X264_REG_CLASS "config"/* window controls */#define BITRATE_MAX 5000#define QUANT_MAX 51/* description */#define X264_NAME "x264"#define X264_DEF_TEXT "Are you sure you want to load default values?"/* Registery handling */typedef struct{ char *reg_value; int *config_int; int default_int;} reg_int_t;typedef struct{ char *reg_value; char *config_str; char *default_str; int max_len; /* maximum string length, including the terminating NULL char */} reg_str_t;CONFIG reg;HWND hTabs[8];static const reg_int_t reg_int_table[] ={ /* Main dialog */ { "bitrate", ®.bitrate, 800 }, { "quantizer", ®.i_qp, 26 }, { "encoding_type", ®.i_encoding_type, 1 }, { "passbitrate", ®.i_2passbitrate, 800 }, { "pass_number", ®.i_pass, 1 }, { "fast1pass", ®.b_fast1pass, 1 }, { "updatestats", ®.b_updatestats, 1 }, { "threads", ®.i_threads, 1 }, /* Advance dialog */ { "cabac", ®.b_cabac, 1 }, { "loop_filter", ®.b_filter, 1 }, { "keyint_max", ®.i_keyint_max, 250 }, { "keyint_min", ®.i_keyint_min, 25 }, { "scenecut", ®.i_scenecut_threshold, 40 }, { "qp_min", ®.i_qp_min, 10 }, { "qp_max", ®.i_qp_max, 51 }, { "qp_step", ®.i_qp_step, 4 }, { "refmax", ®.i_refmax, 1 }, { "bmax", ®.i_bframe, 2 }, { "direct_pred", ®.i_direct_mv_pred, 1 }, { "b_refs", ®.b_b_refs, 0 }, { "b_bias", ®.i_bframe_bias, 0 }, { "b_adapt", ®.b_bframe_adaptive, 1 }, { "b_wpred", ®.b_b_wpred, 1 }, { "inloop_a", ®.i_inloop_a, 0 }, { "inloop_b", ®.i_inloop_b, 0 }, { "key_boost", ®.i_key_boost, 40 }, { "b_red", ®.i_b_red, 30 }, { "curve_comp", ®.i_curve_comp, 60 }, { "sar_width", ®.i_sar_width, 1 }, { "sar_height", ®.i_sar_height, 1 }, { "log_level", ®.i_log_level, 1 }, /* analysis */ { "i4x4", ®.b_i4x4, 1 }, { "i8x8", ®.b_i8x8, 1 }, { "dct8x8", ®.b_dct8x8, 0 }, { "psub16x16", ®.b_psub16x16, 1 }, { "psub8x8", ®.b_psub8x8, 1 }, { "bsub16x16", ®.b_bsub16x16, 1 }, { "me_method", ®.i_me_method, 1 }, { "me_range", ®.i_me_range, 16 }, { "chroma_me", ®.b_chroma_me, 1 }, { "subpel", ®.i_subpel_refine, 4 }, { "mixedref", ®.b_mixedref, 0 }};static const reg_str_t reg_str_table[] ={ { "fourcc", reg.fcc, "H264", 5 }, { "statsfile", reg.stats, ".\\x264.stats", MAX_PATH-4 } // -4 because we add pass number};static void set_dlgitem_int(HWND hDlg, UINT item, int value){ char buf[8]; sprintf(buf, "%i", value); SetDlgItemText(hDlg, item, buf);}/* Registry access */void config_reg_load( CONFIG *config ){ HKEY hKey; DWORD i_size; int i; RegOpenKeyEx( X264_REG_KEY, X264_REG_PARENT "\\" X264_REG_CHILD, 0, KEY_READ, &hKey ); /* Read all integers */ for( i = 0; i < sizeof( reg_int_table )/sizeof( reg_int_t); i++ ) { i_size = sizeof( int ); if( RegQueryValueEx( hKey, reg_int_table[i].reg_value, 0, 0, (LPBYTE)reg_int_table[i].config_int, &i_size ) != ERROR_SUCCESS ) *reg_int_table[i].config_int = reg_int_table[i].default_int; } /* Read strings */ for( i = 0; i < sizeof( reg_str_table )/sizeof( reg_str_t); i++ ) { i_size = reg_str_table[i].max_len; if( RegQueryValueEx( hKey, reg_str_table[i].reg_value, 0, 0, (LPBYTE)reg_str_table[i].config_str, &i_size ) != ERROR_SUCCESS ) lstrcpy( reg_str_table[i].config_str, reg_str_table[i].default_str ); } RegCloseKey( hKey ); memcpy( config, ®, sizeof( CONFIG ) );}void config_reg_save( CONFIG *config ){ HKEY hKey; DWORD i_size; int i; if( RegCreateKeyEx( X264_REG_KEY, X264_REG_PARENT "\\" X264_REG_CHILD, 0, X264_REG_CLASS, REG_OPTION_NON_VOLATILE, KEY_WRITE, 0, &hKey, &i_size ) != ERROR_SUCCESS ) return; memcpy( ®, config, sizeof( CONFIG ) ); /* Save all integers */ for( i = 0; i < sizeof( reg_int_table )/sizeof( reg_int_t); i++ ) { RegSetValueEx( hKey, reg_int_table[i].reg_value, 0, REG_DWORD, (LPBYTE)reg_int_table[i].config_int, sizeof( int ) ); } /* Save strings */ for( i = 0; i < sizeof( reg_str_table )/sizeof( reg_str_t); i++ ) { RegSetValueEx( hKey, reg_str_table[i].reg_value, 0, REG_SZ, (LPBYTE)reg_str_table[i].config_str, lstrlen(reg_str_table[i].config_str)+1 ); } RegCloseKey( hKey );}void config_reg_defaults( CONFIG *config ){ HKEY hKey; if(RegOpenKeyEx( X264_REG_KEY, X264_REG_PARENT, 0, KEY_ALL_ACCESS, &hKey )) { return; } if( RegDeleteKey( hKey, X264_REG_CHILD ) ) { return; } RegCloseKey( hKey ); /* Just in case */ memset( config, 0, sizeof( CONFIG ) ); config_reg_load( config ); config_reg_save( config );}/* Main window */BOOL CALLBACK callback_main( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ){ TCITEM tie; CONFIG* config = (CONFIG*)GetWindowLong(hDlg, GWL_USERDATA); switch( uMsg ) { case WM_INITDIALOG : { RECT rect; HWND hTabCtrl = GetDlgItem( hDlg, IDC_TAB1 ); SetWindowLong( hDlg, GWL_USERDATA, lParam ); config = (CONFIG*)lParam; // insert tabs in tab control tie.mask = TCIF_TEXT; tie.iImage = -1; tie.pszText = "Bitrate"; TabCtrl_InsertItem(hTabCtrl, 0, &tie); tie.pszText = "Rate Control"; TabCtrl_InsertItem(hTabCtrl, 1, &tie); tie.pszText = "MBs&&Frames"; TabCtrl_InsertItem(hTabCtrl, 2, &tie); tie.pszText = "More..."; TabCtrl_InsertItem(hTabCtrl, 3, &tie); hTabs[0] = CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_TAB_BITRATE), hDlg, (DLGPROC)callback_tabs, lParam); hTabs[1] = CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_TAB_RATECONTROL), hDlg, (DLGPROC)callback_tabs, lParam); hTabs[2] = CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_TAB_IPFRAMES), hDlg, (DLGPROC)callback_tabs, lParam); hTabs[3] = CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_TAB_MISC), hDlg, (DLGPROC)callback_tabs, lParam); GetClientRect(hDlg, &rect); TabCtrl_AdjustRect(hTabCtrl, FALSE, &rect); MoveWindow(hTabs[0], rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top-40, TRUE); MoveWindow(hTabs[1], rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top-40, TRUE); MoveWindow(hTabs[2], rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top-40, TRUE); MoveWindow(hTabs[3], rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top-40, TRUE); tabs_enable_items( hDlg, config ); tabs_update_items( hDlg, config ); ShowWindow( hTabs[0], SW_SHOW ); BringWindowToTop( hTabs[0] ); UpdateWindow( hDlg ); break; } case WM_NOTIFY: { NMHDR FAR *tem = (NMHDR FAR *)lParam; if (tem->code == TCN_SELCHANGING) { HWND hTabCtrl = GetDlgItem( hDlg, IDC_TAB1 ); int num = TabCtrl_GetCurSel(hTabCtrl); ShowWindow( hTabs[num], SW_HIDE ); UpdateWindow( hDlg ); } else if (tem->code == TCN_SELCHANGE) { HWND hTabCtrl = GetDlgItem( hDlg, IDC_TAB1 ); int num = TabCtrl_GetCurSel(hTabCtrl); ShowWindow( hTabs[num], SW_SHOW ); BringWindowToTop( hTabs[num] ); UpdateWindow( hDlg ); } break; } case WM_COMMAND: switch ( HIWORD( wParam ) ) { case BN_CLICKED : switch( LOWORD( wParam ) ) { case IDOK : config->b_save = TRUE; EndDialog( hDlg, LOWORD(wParam) ); break; case IDCANCEL : config->b_save = FALSE; EndDialog( hDlg, LOWORD(wParam) ); break; case IDC_DEFAULTS : if( MessageBox( hDlg, X264_DEF_TEXT, X264_NAME, MB_YESNO ) == IDYES ) { config_reg_defaults( config ); tabs_enable_items( hDlg, config ); tabs_update_items( hDlg, config ); } break; } } default : return 0; } return 1;}/* Tabs */void tabs_enable_items( HWND hDlg, CONFIG * config ){ char szTmp[1024]; sprintf( szTmp, "Core %d%s, build %s %s", X264_BUILD, X264_VERSION, __DATE__, __TIME__ ); SetDlgItemText( hTabs[3], IDC_BUILDREV, szTmp ); switch( config->i_encoding_type ) { case 0 : /* 1 Pass, Bitrate Based */ SetDlgItemText( hTabs[0], IDC_BITRATELABEL, "Average Bitrate" ); SetDlgItemText( hTabs[0], IDC_BITRATELOW, "0" ); sprintf(szTmp, "%d", BITRATE_MAX); SetDlgItemText( hTabs[0], IDC_BITRATEHIGH, szTmp ); SendDlgItemMessage( hTabs[0], IDC_BITRATESLIDER, TBM_SETRANGE, TRUE,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -