]> git.sesse.net Git - x264/blob - gtk/x264_gtk_mb.c
Update file headers throughout x264
[x264] / gtk / x264_gtk_mb.c
1 /*****************************************************************************
2  * x264_gtk_mb.c: h264 gtk encoder frontend
3  *****************************************************************************
4  * Copyright (C) 2006 Vincent Torri
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
19  *****************************************************************************/
20
21 #include <gtk/gtk.h>
22
23 #include "x264_gtk_i18n.h"
24 #include "x264_gtk_private.h"
25
26
27 /* Callbacks */
28 static void x264_mb_bframe_pyramid (GtkToggleButton *button,
29                                 gpointer         user_data);
30 static void x264_mb_inter_search_8 (GtkToggleButton *button,
31                                 gpointer         user_data);
32 static void x264_mb_transform_8x8  (GtkToggleButton *button,
33                                 gpointer         user_data);
34
35
36 GtkWidget *
37 x264_mb_page (X264_Gui_Config *config)
38 {
39   GtkWidget   *vbox;
40   GtkWidget   *frame;
41   GtkWidget   *vbox2;
42   GtkWidget   *table;
43   GtkWidget   *eb;
44   GtkWidget   *label;
45   GtkTooltips *tooltips;
46
47   tooltips = gtk_tooltips_new ();
48
49   vbox = gtk_vbox_new (FALSE, 0);
50   gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
51
52   /* Partitions */
53   frame = gtk_frame_new (_("Partitions"));
54   gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, TRUE, 6);
55   gtk_widget_show (frame);
56
57   vbox2 = gtk_vbox_new (FALSE, 6);
58   gtk_container_set_border_width (GTK_CONTAINER (vbox2), 6);
59   gtk_container_add (GTK_CONTAINER (frame), vbox2);
60   gtk_widget_show (vbox2);
61
62   config->mb.partitions.transform_8x8 = gtk_check_button_new_with_label (_("8x8 Transform"));
63   gtk_tooltips_set_tip (tooltips, config->mb.partitions.transform_8x8,
64                         _("8x8 Transform - description"),
65                         "");
66   g_signal_connect (G_OBJECT (config->mb.partitions.transform_8x8),
67                     "toggled",
68                     G_CALLBACK (x264_mb_transform_8x8), config);
69   gtk_box_pack_start (GTK_BOX (vbox2), config->mb.partitions.transform_8x8, FALSE, TRUE, 0);
70   gtk_widget_show (config->mb.partitions.transform_8x8);
71
72   config->mb.partitions.pframe_search_8 = gtk_check_button_new_with_label (_("8x16, 16x8 and 8x8 P-frame search"));
73   gtk_tooltips_set_tip (tooltips, config->mb.partitions.pframe_search_8,
74                         _("8x16, 16x8 and 8x8 P-frame search - description"),
75                         "");
76   gtk_box_pack_start (GTK_BOX (vbox2), config->mb.partitions.pframe_search_8, FALSE, TRUE, 0);
77   gtk_widget_show (config->mb.partitions.pframe_search_8);
78
79   config->mb.partitions.bframe_search_8 = gtk_check_button_new_with_label (_("8x16, 16x8 and 8x8 B-frame search"));
80   gtk_tooltips_set_tip (tooltips, config->mb.partitions.bframe_search_8,
81                         _("8x16, 16x8 and 8x8 B-frame search - description"),
82                         "");
83   gtk_box_pack_start (GTK_BOX (vbox2), config->mb.partitions.bframe_search_8, FALSE, TRUE, 0);
84   gtk_widget_show (config->mb.partitions.bframe_search_8);
85
86   config->mb.partitions.pframe_search_4 = gtk_check_button_new_with_label (_("4x8, 8x4 and 4x4 P-frame search"));
87   gtk_tooltips_set_tip (tooltips, config->mb.partitions.pframe_search_4,
88                         _("4x8, 8x4 and 4x4 P-frame search - description"),
89                         "");
90   gtk_box_pack_start (GTK_BOX (vbox2), config->mb.partitions.pframe_search_4, FALSE, TRUE, 0);
91   gtk_widget_show (config->mb.partitions.pframe_search_4);
92
93   config->mb.partitions.inter_search_8 = gtk_check_button_new_with_label (_("8x8 Intra search"));
94   gtk_tooltips_set_tip (tooltips, config->mb.partitions.inter_search_8,
95                         _("8x8 Intra search - description"),
96                         "");
97   g_signal_connect (G_OBJECT (config->mb.partitions.inter_search_8),
98                     "toggled",
99                     G_CALLBACK (x264_mb_inter_search_8), config);
100   gtk_box_pack_start (GTK_BOX (vbox2), config->mb.partitions.inter_search_8, FALSE, TRUE, 0);
101   gtk_widget_show (config->mb.partitions.inter_search_8);
102
103   config->mb.partitions.inter_search_4 = gtk_check_button_new_with_label (_("4x4 Intra search"));
104   gtk_tooltips_set_tip (tooltips, config->mb.partitions.inter_search_4,
105                         _("4x4 Intra search - description"),
106                         "");
107   gtk_box_pack_start (GTK_BOX (vbox2), config->mb.partitions.inter_search_4, FALSE, TRUE, 0);
108   gtk_widget_show (config->mb.partitions.inter_search_4);
109
110   /* B-Frames */
111   frame = gtk_frame_new (_("B-Frames"));
112   gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, TRUE, 6);
113   gtk_widget_show (frame);
114
115   table = gtk_table_new (5, 2, TRUE);
116   gtk_table_set_row_spacings (GTK_TABLE (table), 6);
117   gtk_container_set_border_width (GTK_CONTAINER (table), 6);
118   gtk_container_add (GTK_CONTAINER (frame), table);
119   gtk_widget_show (table);
120
121   eb = gtk_event_box_new ();
122   gtk_event_box_set_visible_window (GTK_EVENT_BOX (eb), FALSE);
123   gtk_tooltips_set_tip (tooltips, eb,
124                         _("Max consecutive - description"),
125                         "");
126   gtk_table_attach_defaults (GTK_TABLE (table), eb,
127                              0, 1, 0, 1);
128   gtk_widget_show (eb);
129
130   label = gtk_label_new (_("Max consecutive"));
131   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
132   gtk_container_add (GTK_CONTAINER (eb), label);
133   gtk_widget_show (label);
134
135   config->mb.bframes.bframe = gtk_entry_new_with_max_length (3);
136   gtk_table_attach_defaults (GTK_TABLE (table), config->mb.bframes.bframe,
137                              1, 2, 0, 1);
138   gtk_widget_show (config->mb.bframes.bframe);
139
140   eb = gtk_event_box_new ();
141   gtk_event_box_set_visible_window (GTK_EVENT_BOX (eb), FALSE);
142   gtk_tooltips_set_tip (tooltips, eb,
143                         _("Bias - description"),
144                         "");
145   gtk_table_attach_defaults (GTK_TABLE (table), eb,
146                              0, 1, 1, 2);
147   gtk_widget_show (eb);
148
149   label = gtk_label_new (_("Bias"));
150   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
151   gtk_container_add (GTK_CONTAINER (eb), label);
152   gtk_widget_show (label);
153
154   config->mb.bframes.bframe_bias = gtk_hscale_new_with_range (-100.0, 100.0, 1.0);
155   gtk_scale_set_digits (GTK_SCALE (config->mb.bframes.bframe_bias), 0);
156   gtk_scale_set_value_pos (GTK_SCALE (config->mb.bframes.bframe_bias), GTK_POS_RIGHT);
157   gtk_table_attach_defaults (GTK_TABLE (table), config->mb.bframes.bframe_bias,
158                              1, 2, 1, 2);
159   gtk_widget_show (config->mb.bframes.bframe_bias);
160
161   config->mb.bframes.bframe_pyramid = gtk_check_button_new_with_label (_("Use as references"));
162   gtk_tooltips_set_tip (tooltips, config->mb.bframes.bframe_pyramid,
163                         _("Use as references - description"),
164                         "");
165   g_signal_connect (G_OBJECT (config->mb.bframes.bframe_pyramid),
166                     "toggled",
167                     G_CALLBACK (x264_mb_bframe_pyramid), config);
168   gtk_table_attach_defaults (GTK_TABLE (table), config->mb.bframes.bframe_pyramid,
169                              0, 1, 2, 3);
170   gtk_widget_show (config->mb.bframes.bframe_pyramid);
171
172   config->mb.bframes.bidir_me = gtk_check_button_new_with_label (_("Bidirectional ME"));
173   gtk_tooltips_set_tip (tooltips, config->mb.bframes.bidir_me,
174                         _("Bidirectional ME - description"),
175                         "");
176   gtk_table_attach_defaults (GTK_TABLE (table), config->mb.bframes.bidir_me,
177                              1, 2, 2, 3);
178   gtk_widget_show (config->mb.bframes.bidir_me);
179
180   config->mb.bframes.bframe_adaptive = gtk_check_button_new_with_label (_("Adaptive"));
181   gtk_tooltips_set_tip (tooltips, config->mb.bframes.bframe_adaptive,
182                         _("Adaptive - description"),
183                         "");
184   gtk_table_attach_defaults (GTK_TABLE (table), config->mb.bframes.bframe_adaptive,
185                              0, 1, 3, 4);
186   gtk_widget_show (config->mb.bframes.bframe_adaptive);
187
188   config->mb.bframes.weighted_bipred = gtk_check_button_new_with_label (_("Weighted biprediction"));
189   gtk_tooltips_set_tip (tooltips, config->mb.bframes.weighted_bipred,
190                         _("Weighted biprediction - description"),
191                         "");
192   gtk_table_attach_defaults (GTK_TABLE (table), config->mb.bframes.weighted_bipred,
193                              1, 2, 3, 4);
194   gtk_widget_show (config->mb.bframes.weighted_bipred);
195
196   eb = gtk_event_box_new ();
197   gtk_event_box_set_visible_window (GTK_EVENT_BOX (eb), FALSE);
198   gtk_tooltips_set_tip (tooltips, eb,
199                         _("Direct mode - description"),
200                         "");
201   gtk_table_attach_defaults (GTK_TABLE (table), eb,
202                              0, 1, 4, 5);
203   gtk_widget_show (eb);
204
205   label = gtk_label_new (_("Direct mode"));
206   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
207   gtk_container_add (GTK_CONTAINER (eb), label);
208   gtk_widget_show (label);
209
210   config->mb.bframes.direct_mode = gtk_combo_box_new_text ();
211   gtk_combo_box_append_text (GTK_COMBO_BOX (config->mb.bframes.direct_mode),
212                              _("None"));
213   gtk_combo_box_append_text (GTK_COMBO_BOX (config->mb.bframes.direct_mode),
214                              _("Spatial"));
215   gtk_combo_box_append_text (GTK_COMBO_BOX (config->mb.bframes.direct_mode),
216                              _("Temporal"));
217   gtk_combo_box_append_text (GTK_COMBO_BOX (config->mb.bframes.direct_mode),
218                              _("Auto"));
219   gtk_table_attach_defaults (GTK_TABLE (table),
220                              config->mb.bframes.direct_mode,
221                              1, 2, 4, 5);
222   gtk_widget_show (config->mb.bframes.direct_mode);
223
224   return vbox;
225 }
226
227 static void
228 x264_mb_bframe_pyramid (GtkToggleButton *button,
229                     gpointer         user_data)
230 {
231   X264_Gui_Config *config;
232
233   config = (X264_Gui_Config *)user_data;
234
235   if (gtk_toggle_button_get_active (button)) {
236     const gchar *text;
237     gint         val;
238
239     text = gtk_entry_get_text (GTK_ENTRY (config->mb.bframes.bframe));
240     val = (gint)g_ascii_strtoull (text, NULL, 10);
241     if (val < 2)
242       gtk_entry_set_text (GTK_ENTRY (config->mb.bframes.bframe), "2");
243   }
244 }
245
246 static void
247 x264_mb_inter_search_8 (GtkToggleButton *button,
248                     gpointer         user_data)
249 {
250   X264_Gui_Config *config;
251
252   config = (X264_Gui_Config *)user_data;
253
254   if (gtk_toggle_button_get_active (button)) {
255     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.partitions.transform_8x8), TRUE);
256   }
257 }
258
259 static void
260 x264_mb_transform_8x8 (GtkToggleButton *button,
261                    gpointer         user_data)
262 {
263   X264_Gui_Config *config;
264
265   config = (X264_Gui_Config *)user_data;
266
267   if (!gtk_toggle_button_get_active (button)) {
268     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (config->mb.partitions.inter_search_8), FALSE);
269   }
270 }