From 8158161c68b41f775083117cfc1a6c48c0c073c7 Mon Sep 17 00:00:00 2001 From: Guillaume Rousse Date: Tue, 29 May 2012 17:29:54 +0000 Subject: rename internal function to mark themas private --- lib/Parse/EDID.pm | 106 +++++++++++++++++++++++++++--------------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/lib/Parse/EDID.pm b/lib/Parse/EDID.pm index 16ea32e..9731375 100755 --- a/lib/Parse/EDID.pm +++ b/lib/Parse/EDID.pm @@ -32,7 +32,7 @@ our @EXPORT = qw( my @CVT_ratios = qw(5/4 4/3 3/2 16/10 15/9 16/9); my @known_ratios = @CVT_ratios; -my @edid_info = group_by2( +my @edid_info = _group_by2( a8 => '_header', a2 => 'manufacturer_name', @@ -58,14 +58,14 @@ my @edid_info = group_by2( ); my %subfields = ( - manufacturer_name => [ group_by2( + manufacturer_name => [ _group_by2( 1 => '', 5 => '1', 5 => '2', 5 => '3', ) ], - video_input_definition => [ group_by2( + video_input_definition => [ _group_by2( 1 => 'digital', 1 => 'separate_sync', 1 => 'composite_sync', @@ -74,7 +74,7 @@ my %subfields = ( 2 => 'voltage_level', ) ], - feature_support => [ group_by2( + feature_support => [ _group_by2( 1 => 'DPMS_standby', 1 => 'DPMS_suspend', 1 => 'DPMS_active_off', @@ -86,7 +86,7 @@ my %subfields = ( 1 => 'GTF_compliance', ) ], - established_timings => [ group_by2( + established_timings => [ _group_by2( 1 => '720x400_70', 1 => '720x400_88', 1 => '640x480_60', @@ -105,7 +105,7 @@ my %subfields = ( 1 => '1280x1024_75', ) ], - detailed_timing => [ group_by2( + detailed_timing => [ _group_by2( 8 => 'horizontal_active', 8 => 'horizontal_blanking', 4 => 'horizontal_active_hi', @@ -137,12 +137,12 @@ my %subfields = ( 1 => '', ) ], - standard_timing => [ group_by2( + standard_timing => [ _group_by2( 8 => 'X', 2 => 'aspect', 6 => 'vfreq', ) ], - monitor_range => [ group_by2( + monitor_range => [ _group_by2( 8 => 'vertical_min', 8 => 'vertical_max', 8 => 'horizontal_min', @@ -150,7 +150,7 @@ my %subfields = ( 8 => 'pixel_clock_max', ) ], - manufacturer_specified_range_timing => [ group_by2( + manufacturer_specified_range_timing => [ _group_by2( # http://www.spwg.org/salisbury_march_19_2002.pdf # for the glossary: http://www.vesa.org/Public/PSWG/PSWG15v1.pdf 8 => 'horizontal_sync_pulse_width_min', # HSPW (Horizontal Sync Pulse Width) @@ -168,12 +168,12 @@ my %subfields = ( 8 => 'module_revision', ) ], - cea_data_block_collection => [ group_by2( + cea_data_block_collection => [ _group_by2( 3 => 'type', 5 => 'size', ) ], - cea_video_data_block => [ group_by2( + cea_video_data_block => [ _group_by2( 1 => 'native', 7 => 'mode', ) ], @@ -265,12 +265,12 @@ my @cea_video_modes = ( [ 297.000, 1920, 1080, "16/9", 720, 528, 44, 45, 4, 10, 1, 1, 0 ], # 64: 1920x1080@100.00 ); -sub within_limit { +sub _within_limit { my ($value, $type, $limit) = @_; $type eq 'min' ? $value >= $limit : $value <= $limit; } -sub get_many_bits { +sub _get_many_bits { my ($s, $field_name) = @_; my @bits = split('', unpack('B*', $s)); my %h; @@ -300,10 +300,10 @@ sub check_parsed_edid { ''; } -sub build_detailed_timing { +sub _build_detailed_timing { my ($pixel_clock, $vv) = @_; - my $h = get_many_bits($vv, 'detailed_timing'); + my $h = _get_many_bits($vv, 'detailed_timing'); $h->{pixel_clock} = $pixel_clock / 100; # to have it in MHz my %detailed_timing_field_size = map { $_->[1], $_->[0] } @{$subfields{detailed_timing}}; foreach my $field (keys %detailed_timing_field_size) { @@ -314,7 +314,7 @@ sub build_detailed_timing { $h; } -sub add_standard_timing_modes { +sub _add_standard_timing_modes { my ($edid, $v) = @_; my @aspect2ratio = ( @@ -322,7 +322,7 @@ sub add_standard_timing_modes { '4/3', '5/4', '16/9', ); $v = [ map { - my $h = get_many_bits($_, 'standard_timing'); + my $h = _get_many_bits($_, 'standard_timing'); $h->{X} = ($h->{X} + 31) * 8; if ($_ ne "\x20\x20" && $h->{X} > 256) { # cf VALID_TIMING in Xorg edid.h $h->{vfreq} += 60; @@ -349,28 +349,28 @@ sub parse_edid { if ($field eq 'year') { $v += 1990; } elsif ($field eq 'manufacturer_name') { - my $h = get_many_bits($v, 'manufacturer_name'); + my $h = _get_many_bits($v, 'manufacturer_name'); $v = join('', map { chr(ord('A') + $h->{$_} - 1) } 1 .. 3); $v = "" if $v eq "@@@"; } elsif ($field eq 'video_input_definition') { - $v = get_many_bits($v, 'video_input_definition'); + $v = _get_many_bits($v, 'video_input_definition'); } elsif ($field eq 'feature_support') { - $v = get_many_bits($v, 'feature_support'); + $v = _get_many_bits($v, 'feature_support'); } elsif ($field eq 'established_timings') { - my $h = get_many_bits($v, 'established_timings'); + my $h = _get_many_bits($v, 'established_timings'); $v = [ sort { $a->{X} <=> $b->{X} || $a->{vfreq} <=> $b->{vfreq} } map { /(\d+)x(\d+)_(\d+)(i?)/ ? { X => $1, Y => $2, vfreq => $3, $4 ? (interlace => 1) : () } : () } grep { $h->{$_} } keys %$h ]; } elsif ($field eq 'standard_timings') { - $v = add_standard_timing_modes(\%edid, $v); + $v = _add_standard_timing_modes(\%edid, $v); } elsif ($field eq 'monitor_details') { while ($v) { (my $pixel_clock, my $vv, $v) = unpack("v a16 a*", $v); if ($pixel_clock) { # detailed timing - my $h = build_detailed_timing($pixel_clock, $vv); + my $h = _build_detailed_timing($pixel_clock, $vv); push @{$edid{detailed_timings}}, $h if $h->{horizontal_active} > 1 && $h->{vertical_active} > 1; } else { @@ -378,14 +378,14 @@ sub parse_edid { if ($flag == 0xfd) { # range - $edid{monitor_range} = get_many_bits($vv, 'monitor_range'); + $edid{monitor_range} = _get_many_bits($vv, 'monitor_range'); if ($edid{monitor_range}{pixel_clock_max} == 0xff) { delete $edid{monitor_range}{pixel_clock_max}; } else { $edid{monitor_range}{pixel_clock_max} *= 10; #- to have it in MHz } } elsif ($flag == 0xf) { - my $range = get_many_bits($vv, 'manufacturer_specified_range_timing'); + my $range = _get_many_bits($vv, 'manufacturer_specified_range_timing'); my $e = $edid{detailed_timings}[0]; my $valid = 1; @@ -396,9 +396,9 @@ sub parse_edid { $range->{$dir . '_back_porch_' . $m} *= 2; $range->{$dir . '_blanking_' . $m} *= 2; if ($e && $e->{$dir . '_active'} - && within_limit($e->{$dir . '_blanking'}, $m, $range->{$dir . '_blanking_' . $m}) - && within_limit($e->{$dir . '_sync_pulse_width'}, $m, $range->{$dir . '_sync_pulse_width_' . $m}) - && within_limit($e->{$dir . '_blanking'} - $e->{$dir . '_sync_offset'} - $e->{$dir . '_sync_pulse_width'}, + && _within_limit($e->{$dir . '_blanking'}, $m, $range->{$dir . '_blanking_' . $m}) + && _within_limit($e->{$dir . '_sync_pulse_width'}, $m, $range->{$dir . '_sync_pulse_width_' . $m}) + && _within_limit($e->{$dir . '_blanking'} - $e->{$dir . '_sync_offset'} - $e->{$dir . '_sync_pulse_width'}, $m, $range->{$dir . '_back_porch_' . $m})) { $total{$dir} = $e->{$dir . '_active'} + $range->{$dir . '_blanking_' . $m}; } @@ -406,8 +406,8 @@ sub parse_edid { if ($total{horizontal} && $total{vertical}) { my $hfreq = $e->{pixel_clock} * 1000 / $total{horizontal}; my $vfreq = $hfreq * 1000 / $total{vertical}; - $range->{'horizontal_' . ($m eq 'min' ? 'max' : 'min')} = round($hfreq); - $range->{'vertical_' . ($m eq 'min' ? 'max' : 'min')} = round($vfreq); + $range->{'horizontal_' . ($m eq 'min' ? 'max' : 'min')} = _round($hfreq); + $range->{'vertical_' . ($m eq 'min' ? 'max' : 'min')} = _round($vfreq); } else { $valid = 0; } @@ -415,7 +415,7 @@ sub parse_edid { $edid{$valid ? 'monitor_range' : 'manufacturer_specified_range_timing'} = $range; } elsif ($flag == 0xfa) { - push @{$edid{standard_timings}}, add_standard_timing_modes(\%edid, unpack('a12', $vv)); + push @{$edid{standard_timings}}, _add_standard_timing_modes(\%edid, unpack('a12', $vv)); } elsif ($flag == 0xfc) { my $prev = $edid{monitor_name}; $edid{monitor_name} = ($prev ? "$prev " : '') . unpack('A13', $vv); @@ -445,7 +445,7 @@ sub parse_edid { $dtd_offset -= 4; while ($dtd_offset > 0) { - my $h = get_many_bits($v, 'cea_data_block_collection'); + my $h = _get_many_bits($v, 'cea_data_block_collection'); $dtd_offset -= $h->{size} + 1; my $vv; @@ -453,7 +453,7 @@ sub parse_edid { if ($h->{type} == 0x02) { # Video Data Block my @vmodes = unpack("a" x $h->{size}, $vv); foreach my $vmode (@vmodes) { - $h = get_many_bits($vmode, 'cea_video_data_block'); + $h = _get_many_bits($vmode, 'cea_video_data_block'); my $cea_mode = $cea_video_modes[$h->{mode} - 1]; if (!$cea_mode) { warn "parse_edid: unhandled CEA mode $h->{mode}\n" if $verbose; @@ -469,7 +469,7 @@ sub parse_edid { while (length($v) >= 18) { (my $pixel_clock, my $vv, $v) = unpack("v a16 a*", $v); last if !$pixel_clock; - my $h = build_detailed_timing($pixel_clock, $vv); + my $h = _build_detailed_timing($pixel_clock, $vv); push @{$edid{detailed_timings}}, $h if $h->{horizontal_active} > 1 && $h->{vertical_active} > 1; } @@ -488,7 +488,7 @@ sub parse_edid { if ($edid{max_size_vertical}) { $edid{ratio} = $edid{max_size_horizontal} / $edid{max_size_vertical}; - $edid{ratio_name} = ratio_name($edid{max_size_horizontal}, $edid{max_size_vertical}, 'cm'); + $edid{ratio_name} = _ratio_name($edid{max_size_horizontal}, $edid{max_size_vertical}, 'cm'); $edid{ratio_precision} = 'cm'; } @@ -523,7 +523,7 @@ sub parse_edid { if ($error < 1 && $in_cm{vertical}) { # using it for the ratio $edid{ratio} = $in_cm{horizontal} / $in_cm{vertical}; - $edid{ratio_name} = ratio_name($in_cm{horizontal}, $in_cm{vertical}, 'mm'); + $edid{ratio_name} = _ratio_name($in_cm{horizontal}, $in_cm{vertical}, 'mm'); $edid{ratio_precision} = 'mm'; } @@ -553,7 +553,7 @@ sub parse_edid { $h->{pixel_clock} / $horizontal_total / $vertical_total * 1000 * 1000 * ($h->{interlaced} ? 2 : 1), $h->{pixel_clock} / $horizontal_total * 1000, $h->{interlaced} ? "interlaced, " : '', - nearest_ratio($h->{horizontal_active} / $h->{vertical_active}, 0.01) || sprintf("%.2f", $h->{horizontal_active} / $h->{vertical_active}), + _nearest_ratio($h->{horizontal_active} / $h->{vertical_active}, 0.01) || sprintf("%.2f", $h->{horizontal_active} / $h->{vertical_active}), $dpi_string ? ", $dpi_string" : ''; $h->{ModeLine} = sprintf qq("%dx%d" $h->{pixel_clock} %d %d %d %d %d %d %d %d %shsync %svsync%s), @@ -574,13 +574,13 @@ sub parse_edid { $h->{interlaced} ? ' Interlace' : ''; } - $edid{diagonal_size} = sqrt(sqr($edid{max_size_horizontal}) + - sqr($edid{max_size_vertical})) / 2.54; + $edid{diagonal_size} = sqrt(_sqr($edid{max_size_horizontal}) + + _sqr($edid{max_size_vertical})) / 2.54; \%edid; } -sub nearest_ratio { +sub _nearest_ratio { my ($ratio, $max_error) = @_; my @sorted = sort { $a->[1] <=> $b->[1] } @@ -591,26 +591,26 @@ sub nearest_ratio { $sorted[0][0]; } -sub ratio_name { +sub _ratio_name { my ($horizontal, $vertical, $precision) = @_; if ($precision eq 'mm') { - nearest_ratio($horizontal / $vertical, 0.1); + _nearest_ratio($horizontal / $vertical, 0.1); } else { my $error = 0.5; - my $ratio1 = nearest_ratio(($horizontal + $error) / ($vertical - $error), 0.2); - my $ratio2 = nearest_ratio(($horizontal - $error) / ($vertical + $error), 0.2); + my $ratio1 = _nearest_ratio(($horizontal + $error) / ($vertical - $error), 0.2); + my $ratio2 = _nearest_ratio(($horizontal - $error) / ($vertical + $error), 0.2); $ratio1 && $ratio2 or return; if ($ratio1 eq $ratio2) { $ratio1; } else { - my $ratio = nearest_ratio($horizontal / $vertical, 0.2); + my $ratio = _nearest_ratio($horizontal / $vertical, 0.2); join(' or ', $ratio, $ratio eq $ratio1 ? $ratio2 : $ratio1); } } } -sub edid_from_lines { +sub _edid_from_lines { my (@l) = @_; my $edid_str = join('', map { /\s+([0-9a-f]{32})$/ && $1 } @l); if (length($edid_str) % (2 * 128) != 0 || length($edid_str) == 0) { @@ -624,17 +624,17 @@ sub find_edid_in_string { my @edids; while ($input =~ /(?:EDID_DATA|: EDID \(in hex\)|EDID):\n((.*\n){8})/g) { - push @edids, edid_from_lines(split '\n', $1); + push @edids, _edid_from_lines(split '\n', $1); } if (!@edids) { - @edids = edid_from_lines(split '\n', $input); + @edids = _edid_from_lines(split '\n', $input); } @edids; } -sub sqr { $_[0] * $_[0] } -sub round { int($_[0] + 0.5) } -sub group_by2 { +sub _sqr { $_[0] * $_[0] } +sub _round { int($_[0] + 0.5) } +sub _group_by2 { my @l; for (my $i = 0; $i < @_; $i += 2) { push @l, [ $_[$i], $_[$i+1] ]; @@ -651,8 +651,8 @@ Parse::EDID - Extended display identification data (EDID) parser =head1 DESCRIPTION -This module provides some function to parse Extended display identification -data binary data structures. +This module provides some function to parse Extended Display Identification +Data binary data structures. =head1 FUNCTIONS -- cgit v1.2.1