OSDN Git Service

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