blib/lib/Video/DVDRip/GUI/ZoomCalculator.pm untested

filter: Statementstmt 0.0% 0 / 125 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 27 Podpod 0.0% 0 / 23 totaltotal 0.0% 0 / 183 CC 5 SCAR 12.5
CC
5
Cov
0%
build_zoom_calc_table
12.0
open_window
6.0
build
6.0
CRAP 3.5
1 # $Id: ZoomCalculator.pm 2187 2006-08-16 19:34:38Z joern $
2  
3 #-----------------------------------------------------------------------
4 # Copyright (C) 2001-2006 Jörn Reder <joern AT zyn.de>.
5 # All Rights Reserved. See file COPYRIGHT for details.
6 #
7 # This module is part of Video::DVDRip, which is free software; you can
8 # redistribute it and/or modify it under the same terms as Perl itself.
9 #-----------------------------------------------------------------------
10  
11 package Video::DVDRip::GUI::ZoomCalculator;
12 use Locale::TextDomain qw (video.dvdrip);
13  
14 use base qw(Video::DVDRip::GUI::Base);
15  
16 use strict;
17 use Carp;
18  
19 my $zoom_calc_ff;
20  
21 sub fast_resize_align { shift->{fast_resize_align} }
22 sub set_fast_resize_align { shift->{fast_resize_align} = $_[1] }
23  
24 sub fast_resize_align_list {
25 [
26 [ 0, => __"No fast resizing" ],
27 [ 8, => 8 ],
28 [ 16 => 16 ],
29 [ 32 => 32 ],
30 ]
31 }
32  
33 sub result_frame_align { shift->{result_frame_align} }
34 sub set_result_frame_align { shift->{result_frame_align} = $_[1] }
35  
36 sub result_frame_align_presets {
37 [ 16 ]
38 }
39  
40 sub achieve_result_align { shift->{achieve_result_align} }
41 sub set_achieve_result_align { shift->{achieve_result_align} = $_[1] }
42  
43 sub achieve_result_align_list {
44 [
45 [ 'clip2' => __"Using clip2" ],
46 [ 'zoom' => __"Using zoom" ],
47 ]
48 }
49  
50 sub auto_clip { shift->{auto_clip} }
51 sub set_auto_clip { shift->{auto_clip} = $_[1] }
52  
53 sub auto_clip_list {
54 [
55 [ "clip1" => __"Yes - use clip1" ],
56 [ "clip2" => __"Yes - use clip2" ],
57 [ "no" => __"No - take existent clip1" ],
58 ]
59 }
60  
61 sub selected_row { shift->{selected_row} }
62 sub get_calc_lref { shift->{calc_lref} }
63  
64 sub set_selected_row { shift->{selected_row} = $_[1] }
65 sub set_calc_lref { shift->{calc_lref} = $_[1] }
66  
67 sub open_window {
68 my $self = shift;
69  
70 return if $zoom_calc_ff;
71  
72 $self->set_fast_resize_align(8);
73 $self->set_result_frame_align(16);
74 $self->set_achieve_result_align("clip2");
75 $self->set_auto_clip("clip2");
76 $self->set_selected_row( [0] );
77  
78 $self->build;
79  
80 $self->get_context->set_object( zoom_calc => $self );
81  
82 1;
83 }
84  
85 sub build {
86 my $self = shift;
87  
88 my $context = $self->get_context;
89  
90 $zoom_calc_ff = Gtk2::Ex::FormFactory->new(
91 context => $context,
92 parent_ff => $self->get_form_factory,
93 sync => 1,
94 content => [
95 Gtk2::Ex::FormFactory::Window->new(
96 title => __ "dvd::rip - Zoom Calculator",
97 customize_hook => sub {
98 my ($gtk_window) = @_;
99 $_[0]->parent->set( default_height => 550, );
100 1;
101 },
102 closed_hook => sub {
103 $zoom_calc_ff->close if $zoom_calc_ff;
104 $zoom_calc_ff = undef;
105 1;
106 },
107 content => [
108 Gtk2::Ex::FormFactory::Table->new(
109 expand => 1,
110 layout => "
111 +>---------------+>--------------+
112 | Parameters | Bitrate Calc |
113 +----------------+---------------+
114 ^ Zoom Calc Table |
115 | |
116 +--------------------------------+
117 | Some Space |
118 +-------------------------------]+
119 | Buttons |
120 +--------------------------------+
121 ",
122 content => [
123 $self->build_zoom_calc_params,
124 $self->build_video_bitrate_calc,
125 $self->build_zoom_calc_table,
126 Gtk2::Ex::FormFactory::Label->new( label => "", ),
127 Gtk2::Ex::FormFactory::HBox->new(
128 content => [
129 Gtk2::Ex::FormFactory::Button->new(
130 label => __
131 "Apply Clip & Zoom settings",
132 stock => "gtk-apply",
133 clicked_hook => sub {
134 $self->apply_values;
135 1;
136 },
137 ),
138 Gtk2::Ex::FormFactory::Button->new(
139 stock => "gtk-close",
140 clicked_hook => sub {
141 $zoom_calc_ff->close;
142 $zoom_calc_ff = undef;
143 },
144 ),
145 ],
146 properties => { homogeneous => 1, },
147 ),
148 ],
149 ),
150 ],
151 ),
152  
153 ],
154 );
155  
156 $zoom_calc_ff->build;
157 $zoom_calc_ff->update;
158 $zoom_calc_ff->show;
159  
160 1;
161 }
162  
163 sub build_zoom_calc_params {
164 my $self = shift;
165  
166 return Gtk2::Ex::FormFactory::Form->new(
167 title => __ "Parameters",
168 content => [
169 Gtk2::Ex::FormFactory::Popup->new(
170 attr => "zoom_calc.fast_resize_align",
171 label => __ "Fast resize align",
172 ),
173 Gtk2::Ex::FormFactory::Combo->new(
174 attr => "zoom_calc.result_frame_align",
175 label => __ "Result frame align",
176 ),
177 Gtk2::Ex::FormFactory::Popup->new(
178 attr => "zoom_calc.achieve_result_align",
179 label => __ "Achieve result align",
180 ),
181 Gtk2::Ex::FormFactory::Popup->new(
182 attr => "zoom_calc.auto_clip",
183 label => __ "Auto clipping",
184 ),
185 ],
186 );
187 }
188  
189 sub build_video_bitrate_calc {
190 my $self = shift;
191  
192 my $video_bitrate_calc = $self->get_context->get_object("transcode")
193 ->build_video_bitrate_factory;
194  
195 my $calc_plus_result = Gtk2::Ex::FormFactory::VBox->new(
196 title => $video_bitrate_calc->get_title,
197 content => [
198 $video_bitrate_calc,
199 Gtk2::Ex::FormFactory::HBox->new(
200 content => [
201 Gtk2::Ex::FormFactory::Label->new(
202 label => __ "V-Rate" . ": ",
203 attr => "title.tc_video_bitrate",
204 bold => 1,
205 ),
206 Gtk2::Ex::FormFactory::Label->new(
207 label => " " . __ "BPP" . ": ",
208 attr => "title.tc_video_bpp",
209 bold => 1,
210 ),
211 Gtk2::Ex::FormFactory::Label->new(
212 label => " " . __ "Total size" . ": ",
213 attr => "title.storage_total_size",
214 bold => 1,
215 ),
216 Gtk2::Ex::FormFactory::Label->new( label => __ "MB", ),
217 ],
218 ),
219 ],
220 );
221  
222 $video_bitrate_calc->set_title("");
223  
224 return $calc_plus_result;
225 }
226  
227 sub build_zoom_calc_table {
228 my $self = shift;
229  
230 Gtk2::SimpleList->add_column_type(
231 'zoom_calc_text',
232 type => "Glib::Scalar",
233 renderer => "Gtk2::CellRendererText",
234 attr => sub {
235 my ( $treecol, $cell, $model, $iter, $col_num ) = @_;
236 my $info = $model->get( $iter, $col_num );
237 my $ar_perfect = $model->get( $iter, 7 );
238 my $ar_ok = $model->get( $iter, 8 );
239 $cell->set( text => $info );
240 $cell->set( foreground => $ar_perfect ? "#ff0000" : "#000000" );
241 $cell->set( weight => $ar_ok ? 700 : 500 );
242 1;
243 },
244 );
245  
246 return Gtk2::Ex::FormFactory::VBox->new(
247 title => __ "Zoom calculations",
248 content => [
249 Gtk2::Ex::FormFactory::List->new(
250 name => "zoom_calc_result_list",
251 attr => "zoom_calc.result_list",
252 attr_select => "zoom_calc.selected_row",
253 expand => 1,
254 scrollbars => [ "never", "automatic" ],
255 columns => [
256 __ "Result size",
257 __ "BPP",
258 __ "Eff. AR",
259 __ "AR error",
260 __ "Clip1 (t/b/l/r)",
261 __ "Zoom size",
262 __ "Clip2 (t/b/l/r)",
263 "ar_perfect",
264 "ar_ok",
265 ],
266 types => [ ("zoom_calc_text") x 7, "int", "int" ],
267 selection_mode => "browse",
268 customize_hook => sub {
269 my ($gtk_simple_list) = @_;
270 ( $gtk_simple_list->get_columns )[7]->set( visible => 0 );
271 ( $gtk_simple_list->get_columns )[8]->set( visible => 0 );
272 1;
273 },
274 )
275 ],
276 );
277 }
278  
279 sub result_list {
280 my $self = shift;
281  
282 my $fast_resize_align = $self->fast_resize_align;
283 my $result_align = $self->result_frame_align;
284 my $result_align_clip2 = ( $self->achieve_result_align eq 'clip2' );
285 my $auto_clip = ( $self->auto_clip ne 'no' );
286 my $use_clip1 = ( $self->auto_clip eq 'clip1' );
287 my $video_bitrate = $self->selected_title->tc_video_bitrate;
288  
289 my $calc_lref = $self->selected_title->calculator(
290 fast_resize_align => $fast_resize_align,
291 result_align => $result_align,
292 result_align_clip2 => $result_align_clip2,
293 auto_clip => $auto_clip,
294 use_clip1 => $use_clip1,
295 video_bitrate => $video_bitrate,
296 );
297  
298 $self->set_calc_lref($calc_lref);
299  
300 my @result;
301 foreach my $result ( @{$calc_lref} ) {
302 push @result, [
303 "$result->{clip2_width}x$result->{clip2_height}",
304 sprintf( "%.3f", $result->{bpp} ),
305 sprintf( "%.4f", $result->{eff_ar} ),
306 sprintf( "%.4f%%", $result->{ar_err} ),
307 "$result->{clip1_top} / $result->{clip1_bottom} / "
308 . "$result->{clip1_left} / $result->{clip1_right}",
309 "$result->{zoom_width}x$result->{zoom_height}",
310 "$result->{clip2_top} / $result->{clip2_bottom} / "
311 . "$result->{clip2_left} / $result->{clip2_right}",
312 ( $result->{ar_err} < 0.000001 ),
313 ( $result->{ar_err} < 0.3 ),
314  
315 ];
316 }
317  
318 return \@result;
319 }
320  
321 sub apply_values {
322 my $self = shift;
323  
324 my $result_widget = $zoom_calc_ff->lookup_widget("zoom_calc_result_list");
325 $result_widget->set_no_widget_update(1);
326  
327 my $calc_lref = $self->get_calc_lref;
328 my $row = $self->selected_row->[0];
329 my $result = $calc_lref->[$row];
330 my $title = $self->selected_title;
331 my $context = $self->get_context;
332 my $proxy = $context->get_proxy("title");
333  
334 $zoom_calc_ff->change_mouse_cursor("watch");
335  
336 $proxy->set_attrs(
337 { tc_zoom_width => $result->{zoom_width},
338 tc_zoom_height => $result->{zoom_height},
339 tc_clip1_left => $result->{clip1_left},
340 tc_clip1_right => $result->{clip1_right},
341 tc_clip1_top => $result->{clip1_top},
342 tc_clip1_bottom => $result->{clip1_bottom},
343 tc_clip2_left => $result->{clip2_left},
344 tc_clip2_right => $result->{clip2_right},
345 tc_clip2_top => $result->{clip2_top},
346 tc_clip2_bottom => $result->{clip2_bottom},
347 tc_fast_resize => ( $self->fast_resize_align != 0 ),
348 }
349 );
350  
351 $context->get_object("clip_zoom")->make_previews;
352  
353 $zoom_calc_ff->change_mouse_cursor();
354  
355 $result_widget->set_no_widget_update(0);
356  
357 1;
358 }
359  
360 1;