OSDN Git Service

import 0.9.3
[handbrake-jp/handbrake-jp.git] / win / C# / frmMain / x264Panel.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Text;\r
4 using System.Windows.Forms;\r
5 \r
6 namespace Handbrake\r
7 {\r
8     class x264Panel\r
9     {\r
10         /// <summary>\r
11         /// Reset all components to defaults and clears the x264 rtf box\r
12         /// </summary>\r
13         public void reset2Defaults(frmMain mainWindow)\r
14         {\r
15             mainWindow.check_8x8DCT.CheckState = CheckState.Unchecked;\r
16             mainWindow.check_Cabac.CheckState = CheckState.Checked;\r
17             mainWindow.check_mixedReferences.CheckState = CheckState.Unchecked;\r
18             mainWindow.check_noDCTDecimate.CheckState = CheckState.Unchecked;\r
19             mainWindow.check_noFastPSkip.CheckState = CheckState.Unchecked;\r
20             mainWindow.check_pyrmidalBFrames.CheckState = CheckState.Unchecked;\r
21             mainWindow.check_weightedBFrames.CheckState = CheckState.Unchecked;\r
22             mainWindow.drop_analysis.SelectedIndex = 0;\r
23             mainWindow.drop_bFrames.SelectedIndex = 0;\r
24             mainWindow.drop_deblockAlpha.SelectedIndex = 0;\r
25             mainWindow.drop_deblockBeta.SelectedIndex = 0;\r
26             mainWindow.drop_directPrediction.SelectedIndex = 0;\r
27             mainWindow.drop_MotionEstimationMethod.SelectedIndex = 0;\r
28             mainWindow.drop_MotionEstimationRange.SelectedIndex = 0;\r
29             mainWindow.drop_refFrames.SelectedIndex = 0;\r
30             mainWindow.drop_subpixelMotionEstimation.SelectedIndex = 0;\r
31             mainWindow.drop_trellis.SelectedIndex = 0;\r
32 \r
33             mainWindow.rtf_x264Query.Text = "";\r
34         }\r
35 \r
36         /// <summary>\r
37         /// Update GUI componets from the current x264 rtf string\r
38         /// </summary>\r
39         public void X264_SetCurrentSettingsInPanel(frmMain mainWindow)\r
40         {\r
41             /* Set widgets depending on the opt string in field */\r
42             String thisOpt; // The separated option such as "bframes=3"\r
43             String optName = ""; // The option name such as "bframes"\r
44             String optValue = "";// The option value such as "3"\r
45             String[] currentOptsArray;\r
46 \r
47             //Set currentOptString to the contents of the text box.\r
48             String currentOptString = mainWindow.rtf_x264Query.Text.Replace("\n", "");\r
49 \r
50             /*verify there is an opt string to process */\r
51             if (currentOptString.Contains("="))\r
52             {\r
53                 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/\r
54                 currentOptsArray = currentOptString.Split(':');\r
55 \r
56                 /*iterate through the array and get <opts> and <values*/\r
57                 int loopcounter;\r
58                 int currentOptsArrayCount = currentOptsArray.Length;\r
59 \r
60 \r
61                 /*iterate through the array and get <opts> and <values*/\r
62                 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)\r
63                 {\r
64 \r
65                     thisOpt = currentOptsArray[loopcounter];\r
66                     String[] splitOptRange = thisOpt.Split('=');\r
67 \r
68                     if (thisOpt.Contains("="))\r
69                     {\r
70                         optName = splitOptRange[0];\r
71                         optValue = splitOptRange[1];\r
72 \r
73                         /*Run through the available widgets for x264 opts and set them, as you add widgets, \r
74                             they need to be added here. This should be moved to its own method probably*/\r
75 \r
76                         /*bframes NSPopUpButton*/\r
77                         if (optName.Equals("bframes"))\r
78                             mainWindow.drop_bFrames.SelectedItem = optValue;\r
79 \r
80                         /*ref NSPopUpButton*/\r
81                         else if (optName.Equals("ref"))\r
82                             mainWindow.drop_refFrames.SelectedItem = optValue;\r
83 \r
84                         /*No Fast PSkip NSPopUpButton*/\r
85                         else if (optName.Equals("no-fast-pskip"))\r
86                             mainWindow.check_noFastPSkip.CheckState = CheckState.Checked;\r
87 \r
88                         /*No Dict Decimate NSPopUpButton*/\r
89                         else if (optName.Equals("no-dct-decimate"))\r
90                             mainWindow.check_noDCTDecimate.CheckState = CheckState.Checked;\r
91 \r
92                         /*Sub Me NSPopUpButton*/\r
93                         else if (optName.Equals("subq"))\r
94                             mainWindow.drop_subpixelMotionEstimation.SelectedItem = optValue;\r
95 \r
96                         /*Trellis NSPopUpButton*/\r
97                         else if (optName.Equals("trellis"))\r
98                             mainWindow.drop_trellis.SelectedItem = optValue;\r
99 \r
100                         /*Mixed Refs NSButton*/\r
101                         else if (optName.Equals("mixed-refs"))\r
102                             mainWindow.check_mixedReferences.CheckState = CheckState.Checked;\r
103 \r
104                         /*Motion Estimation NSPopUpButton*/\r
105                         else if (optName.Equals("me"))\r
106                         {\r
107                             if (optValue.Equals("dia"))\r
108                                 mainWindow.drop_MotionEstimationMethod.SelectedItem = "Diamond";\r
109                             else if (optValue.Equals("hex"))\r
110                                 mainWindow.drop_MotionEstimationMethod.SelectedItem = "Hexagon";\r
111                             else if (optValue.Equals("umh"))\r
112                                 mainWindow.drop_MotionEstimationMethod.SelectedItem = "Uneven Multi-Hexagon";\r
113                             else if (optValue.Equals("esa"))\r
114                                 mainWindow.drop_MotionEstimationMethod.SelectedItem = "Exhaustive";\r
115 \r
116                         }\r
117                         /*ME Range NSPopUpButton*/\r
118                         else if (optName.Equals("merange"))\r
119                             mainWindow.drop_MotionEstimationRange.SelectedItem = optValue;\r
120 \r
121                         /*Weighted B-Frames NSPopUpButton*/\r
122                         else if (optName.Equals("weightb"))\r
123                             mainWindow.check_weightedBFrames.CheckState = CheckState.Checked;\r
124 \r
125                         /*B Pyramid NSPopUpButton*/\r
126                         else if (optName.Equals("b-pyramid"))\r
127                             mainWindow.check_pyrmidalBFrames.CheckState = CheckState.Checked;\r
128 \r
129                         /*Direct B-frame Prediction NSPopUpButton*/\r
130                         else if (optName.Equals("direct"))\r
131                         {\r
132                             if (optValue == "auto")\r
133                                 optValue = "Automatic";\r
134 \r
135                             if (optValue != "")\r
136                             {\r
137                                 Char[] letters = optValue.ToCharArray();\r
138                                 letters[0] = Char.ToUpper(letters[0]);\r
139                                 optValue = new string(letters);\r
140                             }\r
141 \r
142                             mainWindow.drop_directPrediction.SelectedItem = optValue;\r
143                         }\r
144 \r
145                         /*Deblocking NSPopUpButtons*/\r
146                         else if (optName.Equals("deblock"))\r
147                         {\r
148                             string alphaDeblock = "";\r
149                             string betaDeblock = "";\r
150 \r
151                             string[] splitDeblock = optValue.Split(',');\r
152                             alphaDeblock = splitDeblock[0];\r
153                             betaDeblock = splitDeblock[1];\r
154 \r
155                             if (alphaDeblock.Equals("0") && betaDeblock.Replace("\n", "").Equals("0"))\r
156                             {\r
157                                 mainWindow.drop_deblockAlpha.SelectedItem = "Default (0)";\r
158                                 mainWindow.drop_deblockBeta.SelectedItem = "Default (0)";\r
159                             }\r
160                             else\r
161                             {\r
162                                 if (!alphaDeblock.Equals("0"))\r
163                                     mainWindow.drop_deblockAlpha.SelectedItem = alphaDeblock;\r
164                                 else\r
165                                     mainWindow.drop_deblockAlpha.SelectedItem = "0";\r
166 \r
167                                 if (!betaDeblock.Replace("\n", "").Equals("0"))\r
168                                     mainWindow.drop_deblockBeta.SelectedItem = betaDeblock.Replace("\n", "");\r
169                                 else\r
170                                     mainWindow.drop_deblockBeta.SelectedItem = "0";\r
171                             }\r
172                         }\r
173                         /* Analysis NSPopUpButton */\r
174                         else if (optName.Equals("analyse"))\r
175                         {\r
176 \r
177                             if (optValue.Equals("p8x8,b8x8,i8x8,i4x4"))\r
178                                 mainWindow.drop_analysis.SelectedItem = "Default (some)";\r
179                             if (optValue.Equals("none"))\r
180                                 mainWindow.drop_analysis.SelectedItem = "None";\r
181                             if (optValue.Equals("all"))\r
182                                 mainWindow.drop_analysis.SelectedItem = "All";\r
183                         }\r
184                         /* 8x8 DCT NSButton */\r
185                         else if (optName.Equals("8x8dct"))\r
186                             mainWindow.check_8x8DCT.CheckState = CheckState.Checked;\r
187 \r
188                         /* CABAC NSButton */\r
189                         else if (optName.Equals("cabac"))\r
190                             mainWindow.check_Cabac.CheckState = CheckState.Unchecked;\r
191                     }\r
192                 }\r
193             }\r
194         }\r
195 \r
196         /// <summary>\r
197         /// Iterate over every x264 option, standardize it, write the full string to the x264 rtf box\r
198         /// </summary>\r
199         public void X264_StandardizeOptString(frmMain mainWindow)\r
200         {\r
201             /* Set widgets depending on the opt string in field */\r
202             String thisOpt; // The separated option such as "bframes=3"\r
203             String optName = ""; // The option name such as "bframes"\r
204             String optValue = "";// The option value such as "3"\r
205             String changedOptString = "";\r
206             String[] currentOptsArray;\r
207 \r
208             /*First, we get an opt string to process */\r
209             String currentOptString = mainWindow.rtf_x264Query.Text;\r
210 \r
211             /*verify there is an opt string to process */\r
212             if (currentOptString.Contains("="))\r
213             {\r
214                 /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/\r
215                 currentOptsArray = currentOptString.Split(':');\r
216 \r
217                 /*iterate through the array and get <opts> and <values*/\r
218                 //NSEnumerator * enumerator = [currentOptsArray objectEnumerator];\r
219                 int loopcounter;\r
220                 int currentOptsArrayCount = currentOptsArray.Length;\r
221                 for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)\r
222                 {\r
223                     thisOpt = currentOptsArray[loopcounter];\r
224                     if (currentOptsArray[currentOptsArrayCount - 1] == string.Empty)\r
225                         break;\r
226 \r
227                     String[] splitOptRange = thisOpt.Split('=');\r
228                     if (thisOpt != "")\r
229                     {\r
230                         if (thisOpt.Contains("="))\r
231                         {\r
232                             optName = splitOptRange[0];\r
233                             optValue = splitOptRange[1];\r
234 \r
235                             /* Standardize the names here depending on whats in the string */\r
236                             optName = X264_StandardizeOptNames(optName);\r
237                             thisOpt = optName + "=" + optValue;\r
238                         }\r
239                         else // No value given so we use a default of "1"\r
240                         {\r
241                             optName = thisOpt;\r
242                             /* Standardize the names here depending on whats in the string */\r
243                             optName = X264_StandardizeOptNames(optName);\r
244                             thisOpt = optName + "=1";\r
245                         }\r
246                     }\r
247 \r
248                     /* Construct New String for opts here */\r
249                     if (thisOpt == string.Empty)\r
250                         changedOptString = changedOptString + thisOpt;\r
251                     else\r
252                     {\r
253                         if (changedOptString == string.Empty)\r
254                             changedOptString = thisOpt;\r
255                         else\r
256                             changedOptString = changedOptString + ":" + thisOpt;\r
257                     }\r
258                 }\r
259             }\r
260 \r
261             /* Change the option string to reflect the new standardized option string */\r
262             if (changedOptString != "")\r
263                 mainWindow.rtf_x264Query.Text = changedOptString;\r
264         }\r
265         /*\r
266          * Take a single option and standardize it. Returns as a String\r
267          * Input: String. - Single X264 Option. Name only\r
268          * Output: String - Single X264 Option. Name only. Changed to standard format\r
269          */\r
270         private string X264_StandardizeOptNames(String cleanOptNameString)\r
271         {\r
272             String input = cleanOptNameString;\r
273 \r
274             if (input.Equals("ref") || input.Equals("frameref"))\r
275                 cleanOptNameString = "ref";\r
276 \r
277             /*No Fast PSkip nofast_pskip*/\r
278             if (input.Equals("no-fast-pskip") || input.Equals("no_fast_pskip") || input.Equals("nofast_pskip"))\r
279                 cleanOptNameString = "no-fast-pskip";\r
280 \r
281             /*No Dict Decimate*/\r
282             if (input.Equals("no-dct-decimate") || input.Equals("no_dct_decimate") || input.Equals("nodct_decimate"))\r
283                 cleanOptNameString = "no-dct-decimate";\r
284 \r
285             /*Subme*/\r
286             if (input.Equals("subme"))\r
287                 cleanOptNameString = "subq";\r
288 \r
289             /*ME Range*/\r
290             if (input.Equals("me-range") || input.Equals("me_range"))\r
291                 cleanOptNameString = "merange";\r
292 \r
293             /*WeightB*/\r
294             if (input.Equals("weight-b") || input.Equals("weight_b"))\r
295                 cleanOptNameString = "weightb";\r
296 \r
297             /*B Pyramid*/\r
298             if (input.Equals("b_pyramid"))\r
299                 cleanOptNameString = "b-pyramid";\r
300 \r
301             /*Direct Prediction*/\r
302             if (input.Equals("direct-pred") || input.Equals("direct_pred"))\r
303                 cleanOptNameString = "direct";\r
304 \r
305             /*Deblocking*/\r
306             if (input.Equals("filter"))\r
307                 cleanOptNameString = "deblock";\r
308 \r
309             /*Analysis*/\r
310             if (input.Equals("partitions"))\r
311                 cleanOptNameString = "analyse";\r
312 \r
313             return cleanOptNameString;\r
314         }\r
315 \r
316         /// <summary>\r
317         /// This function will update the X264 Query when one of the GUI widgets changes.\r
318         /// </summary>\r
319         public void on_x264_WidgetChange(string sender, frmMain mainWindow)\r
320         {\r
321             animate(mainWindow, sender);\r
322             String optNameToChange = sender;\r
323             String currentOptString = mainWindow.rtf_x264Query.Text;\r
324 \r
325             /*First, we create a pattern to check for ":"optNameToChange"=" to modify the option if the name falls after\r
326                 the first character of the opt string (hence the ":") */\r
327             String checkOptNameToChange = ":" + optNameToChange + "=";\r
328             String checkOptNameToChangeBegin = optNameToChange + "=";\r
329 \r
330             // IF the current H264 Option String Contains Multiple Items or Just 1 Item\r
331             if ((currentOptString.Contains(checkOptNameToChange)) || (currentOptString.StartsWith(checkOptNameToChangeBegin)))\r
332                 hasOptions(currentOptString, optNameToChange, mainWindow);\r
333             else // IF there is no options in the rich text box!\r
334                 hasNoOptions(optNameToChange, mainWindow);\r
335         }\r
336         /*\r
337          * Used by on_x264_WidgetChange()\r
338          ** hasOptions - Called when the current x264 option string contains multiple (or a single) item(s) in it seperated by :\r
339          * it updates the current option that the widget corrosponds to, if it is already in thes string.\r
340          ** hasNoOptions - Add's an option to the x264 query string.\r
341          * Handles 2 cases.  1 Where rtf_x264Query.Text is empty, and one where there is an option with no value,\r
342          * e.g no-fast-pskip\r
343          */\r
344         private void hasOptions(string currentOptString, string optNameToChange, frmMain mainWindow)\r
345         {\r
346             String thisOpt;             // The separated option such as "bframes=3"\r
347             String optName = "";        // The option name such as "bframes"\r
348             String optValue = "";       // The option value such as "3"\r
349             String[] currentOptsArray;\r
350 \r
351             /* Create new empty opt string*/\r
352             String changedOptString = "";\r
353 \r
354             /*Put individual options into an array based on the ":" separator for processing, result is "<opt>=<value>"*/\r
355             currentOptsArray = currentOptString.Split(':');\r
356 \r
357             /*iterate through the array and get <opts> and <values*/\r
358             for (int loopcounter = 0; loopcounter < currentOptsArray.Length; loopcounter++)\r
359             {\r
360                 thisOpt = currentOptsArray[loopcounter];\r
361 \r
362                 if (thisOpt.Contains("="))\r
363                 {\r
364                     string[] splitOptRange = thisOpt.Split('=');\r
365 \r
366                     optName = splitOptRange[0];     // e.g bframes\r
367                     optValue = splitOptRange[1];    // e.g 2\r
368 \r
369                     /* \r
370                      * Run through the available widgets for x264 opts and set them, as you add widgets,\r
371                      * they need to be added here. This should be moved to its own method probably\r
372                      * If the optNameToChange is found, appropriately change the value or delete it if\r
373                      * "unspecified" is set.\r
374                      */\r
375                     if (optName.Equals(optNameToChange))\r
376                     {\r
377                         if (optNameToChange.Equals("deblock"))\r
378                         {\r
379                             String da = mainWindow.drop_deblockAlpha.SelectedItem.ToString();\r
380                             String db = mainWindow.drop_deblockBeta.SelectedItem.ToString();\r
381 \r
382                             if (((da.Contains("Default")) && (db.Contains("Default"))) || ((da.Contains("0")) && (db.Contains("0"))))\r
383                             {\r
384                                 mainWindow.drop_deblockBeta.SelectedItem = "Default (0)";\r
385                                 mainWindow.drop_deblockAlpha.SelectedItem = "Default (0)";\r
386                                 thisOpt = "";\r
387                             }\r
388                             else if ((!da.Contains("Default")) && (db.Contains("Default")))\r
389                             {\r
390                                 mainWindow.drop_deblockBeta.SelectedItem = "0";\r
391                                 thisOpt = "deblock=" + da + ",0";\r
392                             }\r
393                             else if ((da.Contains("Default")) && (!db.Contains("Default")))\r
394                             {\r
395                                 mainWindow.drop_deblockAlpha.SelectedItem = "0";\r
396                                 thisOpt = "deblock=0," + db;\r
397                             }\r
398                             else if ((!da.Contains("Default")) && (!db.Contains("Default")))\r
399                                 thisOpt = "deblock=" + da + "," + db;\r
400                         }\r
401 \r
402                         else if (optNameToChange.Equals("mixed-refs"))\r
403                         {\r
404                             if (mainWindow.check_mixedReferences.CheckState == CheckState.Checked)\r
405                                 thisOpt = "mixed-refs=1";\r
406                             else\r
407                                 thisOpt = "";\r
408                         }\r
409                         else if (optNameToChange.Equals("weightb"))\r
410                         {\r
411                             if (mainWindow.check_weightedBFrames.CheckState == CheckState.Checked)\r
412                                 thisOpt = "weightb=1";\r
413                             else\r
414                                 thisOpt = "";\r
415                         }\r
416                         else if (optNameToChange.Equals("b-pyramid"))\r
417                         {\r
418                             if (mainWindow.check_pyrmidalBFrames.CheckState == CheckState.Checked)\r
419                                 thisOpt = "b-pyramid=1";\r
420                             else\r
421                                 thisOpt = "";\r
422                         }\r
423                         else if (optNameToChange.Equals("no-fast-pskip"))\r
424                         {\r
425                             if (mainWindow.check_noFastPSkip.CheckState == CheckState.Checked)\r
426                                 thisOpt = "no-fast-pskip=1";\r
427                             else\r
428                                 thisOpt = "";\r
429                         }\r
430                         else if (optNameToChange.Equals("no-dct-decimate"))\r
431                         {\r
432                             if (mainWindow.check_noDCTDecimate.CheckState == CheckState.Checked)\r
433                                 thisOpt = "no-dct-decimate=1";\r
434                             else\r
435                                 thisOpt = "";\r
436                         }\r
437                         else if (optNameToChange.Equals("8x8dct"))\r
438                         {\r
439                             if (mainWindow.check_8x8DCT.CheckState == CheckState.Checked)\r
440                                 thisOpt = "8x8dct=1";\r
441                             else\r
442                                 thisOpt = "";\r
443                         }\r
444                         else if (optNameToChange.Equals("cabac"))\r
445                         {\r
446                             if (mainWindow.check_Cabac.CheckState == CheckState.Checked)\r
447                                 thisOpt = "";\r
448                             else\r
449                                 thisOpt = "cabac=0";\r
450                         }\r
451                         else if (optNameToChange.Equals("me"))\r
452                         {\r
453                             switch (mainWindow.drop_MotionEstimationMethod.SelectedIndex)\r
454                             {\r
455                                 case 1:\r
456                                     thisOpt = "me=dia";\r
457                                     break;\r
458 \r
459                                 case 2:\r
460                                     thisOpt = "me=hex";\r
461                                     break;\r
462 \r
463                                 case 3:\r
464                                     thisOpt = "me=umh";\r
465                                     break;\r
466 \r
467                                 case 4:\r
468                                     thisOpt = "me=esa";\r
469                                     break;\r
470 \r
471                                 default:\r
472                                     thisOpt = "";\r
473                                     break;\r
474                             }\r
475                         }\r
476                         else if (optNameToChange.Equals("direct"))\r
477                         {\r
478                             switch (mainWindow.drop_directPrediction.SelectedIndex)\r
479                             {\r
480                                 case 1:\r
481                                     thisOpt = "direct=none";\r
482                                     break;\r
483 \r
484                                 case 2:\r
485                                     thisOpt = "direct=spatial";\r
486                                     break;\r
487 \r
488                                 case 3:\r
489                                     thisOpt = "direct=temporal";\r
490                                     break;\r
491 \r
492                                 case 4:\r
493                                     thisOpt = "direct=auto";\r
494                                     break;\r
495 \r
496                                 default:\r
497                                     thisOpt = "";\r
498                                     break;\r
499                             }\r
500                         }\r
501                         else if (optNameToChange.Equals("analyse"))\r
502                         {\r
503                             switch (mainWindow.drop_analysis.SelectedIndex)\r
504                             {\r
505                                 case 1:\r
506                                     thisOpt = "analyse=none";\r
507                                     break;\r
508 \r
509                                 case 2:\r
510                                     thisOpt = "analyse=all";\r
511                                     break;\r
512 \r
513                                 default:\r
514                                     thisOpt = "";\r
515                                     break;\r
516                             }\r
517                         }\r
518                         else if (optNameToChange.Equals("merange"))\r
519                         {\r
520                             if (!mainWindow.drop_MotionEstimationRange.SelectedItem.ToString().Contains("Default"))\r
521                                 thisOpt = "merange=" + mainWindow.drop_MotionEstimationRange.SelectedItem.ToString();\r
522                             else\r
523                                 thisOpt = "";\r
524                         }\r
525                         else if (optNameToChange.Equals("ref"))\r
526                         {\r
527                             if (!mainWindow.drop_refFrames.SelectedItem.ToString().Contains("Default"))\r
528                                 thisOpt = "ref=" + mainWindow.drop_refFrames.SelectedItem.ToString();\r
529                             else\r
530                                 thisOpt = "";\r
531                         }\r
532                         else if (optNameToChange.Equals("bframes"))\r
533                         {\r
534                             String value = mainWindow.drop_bFrames.SelectedItem.ToString();\r
535                             if (!mainWindow.drop_bFrames.SelectedItem.ToString().Contains("Default"))\r
536                                 thisOpt = "bframes=" + value;\r
537                             else\r
538                                 thisOpt = "";\r
539                         }\r
540                         else if (optNameToChange.Equals("subq"))\r
541                         {\r
542                             String value = mainWindow.drop_subpixelMotionEstimation.SelectedItem.ToString();\r
543                             if (!mainWindow.drop_subpixelMotionEstimation.SelectedItem.ToString().Contains("Default"))\r
544                                 thisOpt = "subq=" + value;\r
545                             else\r
546                                 thisOpt = "";\r
547                         }\r
548                         else if (optNameToChange.Equals("trellis"))\r
549                         {\r
550                             String value = mainWindow.drop_trellis.SelectedItem.ToString();\r
551                             if (!mainWindow.drop_trellis.SelectedItem.ToString().Contains("Default"))\r
552                                 thisOpt = "trellis=" + value;\r
553                             else\r
554                                 thisOpt = "";\r
555                         }\r
556 \r
557                     }\r
558                 }\r
559 \r
560                 /* Construct New String for opts here */\r
561                 if (!thisOpt.Equals(""))\r
562                 {\r
563                     if (changedOptString.Equals(""))\r
564                         changedOptString = thisOpt;\r
565                     else\r
566                         changedOptString = changedOptString + ":" + thisOpt;\r
567                 }\r
568             }\r
569 \r
570             /* Change the option string to reflect the new mod settings */\r
571             mainWindow.rtf_x264Query.Text = changedOptString;\r
572         }\r
573         private void hasNoOptions(string optNameToChange, frmMain mainWindow)\r
574         {\r
575             string query = "";\r
576             string colon = "";\r
577             if (mainWindow.rtf_x264Query.Text != "")\r
578                 colon = ":";\r
579 \r
580             query = mainWindow.rtf_x264Query.Text;\r
581             if (optNameToChange.Equals("me"))\r
582             {\r
583                 switch (mainWindow.drop_MotionEstimationMethod.SelectedIndex)\r
584                 {\r
585                     case 1:\r
586                         query = query + colon + "me=dia";\r
587                         break;\r
588 \r
589                     case 2:\r
590                         query = query + colon + "me=hex";\r
591                         break;\r
592 \r
593                     case 3:\r
594                         query = query + colon + "me=umh";\r
595                         break;\r
596 \r
597                     case 4:\r
598                         query = query + colon + "me=esa";\r
599                         break;\r
600 \r
601                     default:\r
602                         break;\r
603                 }\r
604             }\r
605             else if (optNameToChange.Equals("direct"))\r
606             {\r
607                 switch (mainWindow.drop_directPrediction.SelectedIndex)\r
608                 {\r
609                     case 1:\r
610                         query = query + colon + "direct=none";\r
611                         break;\r
612 \r
613                     case 2:\r
614                         query = query + colon + "direct=spatial";\r
615                         break;\r
616 \r
617                     case 3:\r
618                         query = query + colon + "direct=temporal";\r
619                         break;\r
620 \r
621                     case 4:\r
622                         query = query + colon + "direct=auto";\r
623                         break;\r
624 \r
625                     default:\r
626                         break;\r
627                 }\r
628             }\r
629             else if (optNameToChange.Equals("analyse"))\r
630             {\r
631                 switch (mainWindow.drop_analysis.SelectedIndex)\r
632                 {\r
633                     case 1:\r
634                         query = query + colon + "analyse=none";\r
635                         break;\r
636 \r
637                     case 2:\r
638                         query = query + colon + "analyse=all";\r
639                         break;\r
640 \r
641                     default:\r
642                         break;\r
643                 }\r
644             }\r
645             else if (optNameToChange.Equals("merange"))\r
646             {\r
647                 int value = mainWindow.drop_MotionEstimationRange.SelectedIndex + 3;\r
648                 query = query + colon + "merange=" + value.ToString();\r
649             }\r
650             else if (optNameToChange.Equals("deblock"))\r
651             {\r
652                 String da = mainWindow.drop_deblockAlpha.SelectedItem.ToString();\r
653                 String db = mainWindow.drop_deblockBeta.Text.ToString();\r
654 \r
655                 if (((da.Contains("Default")) && (db.Contains("Default"))) || ((da.Contains("0")) && (db.Contains("0"))))\r
656                 {\r
657                     mainWindow.drop_deblockBeta.SelectedItem = "Default (0)";\r
658                     mainWindow.drop_deblockAlpha.SelectedItem = "Default (0)";\r
659                 }\r
660                 else\r
661                 {\r
662                     if (db.Contains("Default"))\r
663                         db = "0";\r
664 \r
665                     if (da.Contains("Default"))\r
666                         da = "0";\r
667 \r
668                     query = query + colon + "deblock=" + da + "," + db;\r
669                 }\r
670             }\r
671             else if (optNameToChange.Equals("mixed-refs"))\r
672             {\r
673                 if (mainWindow.check_mixedReferences.CheckState == CheckState.Checked)\r
674                     query = query + colon + "mixed-refs=1";\r
675             }\r
676             else if (optNameToChange.Equals("weightb"))\r
677             {\r
678                 if (mainWindow.check_weightedBFrames.CheckState == CheckState.Checked)\r
679                     query = query + colon + "weightb=1";\r
680             }\r
681             else if (optNameToChange.Equals("b-pyramid"))\r
682             {\r
683                 if (mainWindow.check_pyrmidalBFrames.CheckState == CheckState.Checked)\r
684                     query = query + colon + "b-pyramid=1";\r
685             }\r
686             else if (optNameToChange.Equals("no-fast-pskip"))\r
687             {\r
688                 if (mainWindow.check_noFastPSkip.CheckState == CheckState.Checked)\r
689                     query = query + colon + "no-fast-pskip=1";\r
690             }\r
691             else if (optNameToChange.Equals("no-dct-decimate"))\r
692             {\r
693                 if (mainWindow.check_noDCTDecimate.CheckState == CheckState.Checked)\r
694                     query = query + colon + "no-dct-decimate=1";\r
695             }\r
696             else if (optNameToChange.Equals("8x8dct"))\r
697             {\r
698                 if (mainWindow.check_8x8DCT.CheckState == CheckState.Checked)\r
699                     query = query + colon + "8x8dct=1";\r
700             }\r
701             else if (optNameToChange.Equals("cabac"))\r
702             {\r
703                 if (mainWindow.check_Cabac.CheckState != CheckState.Checked)\r
704                     query = query + colon + "cabac=0";\r
705             }\r
706             else if (optNameToChange.Equals("ref"))\r
707             {\r
708                 if (!mainWindow.drop_refFrames.SelectedItem.ToString().Contains("Default"))\r
709                     query = query + colon + "ref=" + mainWindow.drop_refFrames.SelectedItem.ToString();\r
710             }\r
711             else if (optNameToChange.Equals("bframes"))\r
712             {\r
713                 String value = mainWindow.drop_bFrames.SelectedItem.ToString();\r
714                 if (!mainWindow.drop_bFrames.SelectedItem.ToString().Contains("Default"))\r
715                     query = query + colon + "bframes=" + value;\r
716             }\r
717             else if (optNameToChange.Equals("subq"))\r
718             {\r
719                 String value = mainWindow.drop_subpixelMotionEstimation.SelectedItem.ToString();\r
720                 if (!mainWindow.drop_subpixelMotionEstimation.SelectedItem.ToString().Contains("Default"))\r
721                     query = query + colon + "subq=" + value;\r
722             }\r
723             else if (optNameToChange.Equals("trellis"))\r
724             {\r
725                 if (!mainWindow.drop_trellis.SelectedItem.ToString().Contains("Default"))\r
726                     query = query + colon + "trellis=" + mainWindow.drop_trellis.SelectedItem.ToString();\r
727             }\r
728 \r
729             mainWindow.rtf_x264Query.Text = query;\r
730         }\r
731         private void animate(frmMain mainWindow, string sender)\r
732         {\r
733             /* Lots of situations to cover.\r
734                - B-frames (when 0 turn of b-frame specific stuff, when < 2 disable b-pyramid)\r
735                - CABAC (when 0 turn off trellis)\r
736                - analysis (if none, turn off 8x8dct)\r
737                - refs (under 2, disable mixed-refs)\r
738             */\r
739             if (mainWindow.drop_bFrames.SelectedIndex < 2)\r
740             {\r
741                 /* If the b-frame widget is at 0 or 1, the user has chosen\r
742                    not to use b-frames at all. So disable the options\r
743                    that can only be used when b-frames are enabled.        */\r
744                 mainWindow.check_weightedBFrames.Visible = false;\r
745                 mainWindow.check_pyrmidalBFrames.Visible = false;\r
746                 mainWindow.drop_directPrediction.Visible = false;\r
747                 mainWindow.lbl_direct_prediction.Visible = false;\r
748 \r
749                 mainWindow.check_weightedBFrames.CheckState = CheckState.Unchecked;\r
750                 mainWindow.check_pyrmidalBFrames.CheckState = CheckState.Unchecked;\r
751                 mainWindow.drop_directPrediction.SelectedIndex = 0;\r
752             }\r
753             else if (mainWindow.drop_bFrames.SelectedIndex == 2)\r
754             {\r
755                 /* Only 1 b-frame? Disable b-pyramid. */\r
756                 mainWindow.check_pyrmidalBFrames.Visible = false;\r
757                 mainWindow.check_pyrmidalBFrames.CheckState = CheckState.Unchecked;\r
758 \r
759                 mainWindow.check_weightedBFrames.Visible = true;\r
760                 mainWindow.drop_directPrediction.Visible = true;\r
761                 mainWindow.lbl_direct_prediction.Visible = true;\r
762                 \r
763             }\r
764             else\r
765             {\r
766                 mainWindow.check_weightedBFrames.Visible = true;\r
767                 mainWindow.check_pyrmidalBFrames.Visible = true;\r
768                 mainWindow.drop_directPrediction.Visible = true;\r
769                 mainWindow.lbl_direct_prediction.Visible = true;\r
770             }\r
771 \r
772             if (mainWindow.check_Cabac.Checked == false)\r
773             {\r
774                 /* Without CABAC entropy coding, trellis doesn't run. */\r
775                 mainWindow.drop_trellis.Visible = false;\r
776                 mainWindow.drop_trellis.SelectedIndex = 0;\r
777                 mainWindow.lbl_trellis.Visible = false;\r
778             }\r
779             else\r
780             {\r
781                 mainWindow.drop_trellis.Visible = true;\r
782                 mainWindow.lbl_trellis.Visible = true;\r
783             }\r
784 \r
785             if (mainWindow.drop_analysis.SelectedIndex == 1)\r
786             {\r
787                 /* No analysis? Disable 8x8dct */\r
788                 mainWindow.check_8x8DCT.Visible = false;\r
789                 if (sender != "8x8dct")\r
790                     mainWindow.check_8x8DCT.CheckState = CheckState.Unchecked;\r
791             }\r
792             else\r
793                 mainWindow.check_8x8DCT.Visible = true;\r
794 \r
795             if (mainWindow.drop_refFrames.SelectedIndex < 3)\r
796             {\r
797                 mainWindow.check_mixedReferences.Visible = false;\r
798                 if (sender != "mixed-refs")\r
799                     mainWindow.check_mixedReferences.CheckState = CheckState.Unchecked;\r
800             }\r
801             else\r
802             {\r
803                 mainWindow.check_mixedReferences.Visible = true;\r
804             }\r
805         }\r
806 \r
807     }\r
808 }