aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xlib/Parse/EDID.pm678
1 files changed, 339 insertions, 339 deletions
diff --git a/lib/Parse/EDID.pm b/lib/Parse/EDID.pm
index 6b416b1..055b633 100755
--- a/lib/Parse/EDID.pm
+++ b/lib/Parse/EDID.pm
@@ -59,123 +59,123 @@ my @edid_info = group_by2(
my %subfields = (
manufacturer_name => [ group_by2(
- 1 => '',
- 5 => '1',
- 5 => '2',
- 5 => '3',
+ 1 => '',
+ 5 => '1',
+ 5 => '2',
+ 5 => '3',
) ],
video_input_definition => [ group_by2(
- 1 => 'digital',
- 1 => 'separate_sync',
- 1 => 'composite_sync',
- 1 => 'sync_on_green',
- 2 => '',
- 2 => 'voltage_level',
+ 1 => 'digital',
+ 1 => 'separate_sync',
+ 1 => 'composite_sync',
+ 1 => 'sync_on_green',
+ 2 => '',
+ 2 => 'voltage_level',
) ],
feature_support => [ group_by2(
- 1 => 'DPMS_standby',
- 1 => 'DPMS_suspend',
- 1 => 'DPMS_active_off',
- 1 => 'rgb',
+ 1 => 'DPMS_standby',
+ 1 => 'DPMS_suspend',
+ 1 => 'DPMS_active_off',
+ 1 => 'rgb',
- 1 => '',
+ 1 => '',
1 => 'sRGB_compliance',
- 1 => 'has_preferred_timing',
+ 1 => 'has_preferred_timing',
1 => 'GTF_compliance',
) ],
established_timings => [ group_by2(
- 1 => '720x400_70',
- 1 => '720x400_88',
- 1 => '640x480_60',
- 1 => '640x480_67',
- 1 => '640x480_72',
- 1 => '640x480_75',
- 1 => '800x600_56',
- 1 => '800x600_60',
- 1 => '800x600_72',
- 1 => '800x600_75',
- 1 => '832x624_75',
- 1 => '1024x768_87i',
- 1 => '1024x768_60',
- 1 => '1024x768_70',
- 1 => '1024x768_75',
- 1 => '1280x1024_75',
+ 1 => '720x400_70',
+ 1 => '720x400_88',
+ 1 => '640x480_60',
+ 1 => '640x480_67',
+ 1 => '640x480_72',
+ 1 => '640x480_75',
+ 1 => '800x600_56',
+ 1 => '800x600_60',
+ 1 => '800x600_72',
+ 1 => '800x600_75',
+ 1 => '832x624_75',
+ 1 => '1024x768_87i',
+ 1 => '1024x768_60',
+ 1 => '1024x768_70',
+ 1 => '1024x768_75',
+ 1 => '1280x1024_75',
) ],
detailed_timing => [ group_by2(
- 8 => 'horizontal_active',
- 8 => 'horizontal_blanking',
- 4 => 'horizontal_active_hi',
- 4 => 'horizontal_blanking_hi',
- 8 => 'vertical_active',
- 8 => 'vertical_blanking',
- 4 => 'vertical_active_hi',
- 4 => 'vertical_blanking_hi',
- 8 => 'horizontal_sync_offset',
- 8 => 'horizontal_sync_pulse_width',
- 4 => 'vertical_sync_offset',
- 4 => 'vertical_sync_pulse_width',
- 2 => 'horizontal_sync_offset_hi',
- 2 => 'horizontal_sync_pulse_width_hi',
- 2 => 'vertical_sync_offset_hi',
- 2 => 'vertical_sync_pulse_width_hi',
- 8 => 'horizontal_image_size', # in mm
- 8 => 'vertical_image_size', # in mm
- 4 => 'horizontal_image_size_hi',
- 4 => 'vertical_image_size_hi',
- 8 => 'horizontal_border',
- 8 => 'vertical_border',
-
- 1 => 'interlaced',
- 2 => 'stereo',
- 2 => 'digital_composite',
- 1 => 'horizontal_sync_positive',
- 1 => 'vertical_sync_positive',
- 1 => '',
+ 8 => 'horizontal_active',
+ 8 => 'horizontal_blanking',
+ 4 => 'horizontal_active_hi',
+ 4 => 'horizontal_blanking_hi',
+ 8 => 'vertical_active',
+ 8 => 'vertical_blanking',
+ 4 => 'vertical_active_hi',
+ 4 => 'vertical_blanking_hi',
+ 8 => 'horizontal_sync_offset',
+ 8 => 'horizontal_sync_pulse_width',
+ 4 => 'vertical_sync_offset',
+ 4 => 'vertical_sync_pulse_width',
+ 2 => 'horizontal_sync_offset_hi',
+ 2 => 'horizontal_sync_pulse_width_hi',
+ 2 => 'vertical_sync_offset_hi',
+ 2 => 'vertical_sync_pulse_width_hi',
+ 8 => 'horizontal_image_size', # in mm
+ 8 => 'vertical_image_size', # in mm
+ 4 => 'horizontal_image_size_hi',
+ 4 => 'vertical_image_size_hi',
+ 8 => 'horizontal_border',
+ 8 => 'vertical_border',
+
+ 1 => 'interlaced',
+ 2 => 'stereo',
+ 2 => 'digital_composite',
+ 1 => 'horizontal_sync_positive',
+ 1 => 'vertical_sync_positive',
+ 1 => '',
) ],
standard_timing => [ group_by2(
- 8 => 'X',
- 2 => 'aspect',
- 6 => 'vfreq',
+ 8 => 'X',
+ 2 => 'aspect',
+ 6 => 'vfreq',
) ],
monitor_range => [ group_by2(
- 8 => 'vertical_min',
- 8 => 'vertical_max',
- 8 => 'horizontal_min',
- 8 => 'horizontal_max',
- 8 => 'pixel_clock_max',
+ 8 => 'vertical_min',
+ 8 => 'vertical_max',
+ 8 => 'horizontal_min',
+ 8 => 'horizontal_max',
+ 8 => 'pixel_clock_max',
) ],
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)
- 8 => 'horizontal_sync_pulse_width_max',
- 8 => 'horizontal_back_porch_min', # t_hbp
- 8 => 'horizontal_back_porch_max',
- 8 => 'vertical_sync_pulse_width_min', # VSPW (Vertical Sync Pulse Width)
- 8 => 'vertical_sync_pulse_width_max',
- 8 => 'vertical_back_porch_min', # t_vbp (Vertical Back Porch)
- 8 => 'vertical_back_porch_max',
- 8 => 'horizontal_blanking_min', # t_hp (Horizontal Period)
- 8 => 'horizontal_blanking_max',
- 8 => 'vertical_blanking_min', # t_vp
- 8 => 'vertical_blanking_max',
- 8 => 'module_revision',
+ # 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)
+ 8 => 'horizontal_sync_pulse_width_max',
+ 8 => 'horizontal_back_porch_min', # t_hbp
+ 8 => 'horizontal_back_porch_max',
+ 8 => 'vertical_sync_pulse_width_min', # VSPW (Vertical Sync Pulse Width)
+ 8 => 'vertical_sync_pulse_width_max',
+ 8 => 'vertical_back_porch_min', # t_vbp (Vertical Back Porch)
+ 8 => 'vertical_back_porch_max',
+ 8 => 'horizontal_blanking_min', # t_hp (Horizontal Period)
+ 8 => 'horizontal_blanking_max',
+ 8 => 'vertical_blanking_min', # t_vp
+ 8 => 'vertical_blanking_max',
+ 8 => 'module_revision',
) ],
cea_data_block_collection => [ group_by2(
- 3 => 'type',
- 5 => 'size',
+ 3 => 'type',
+ 5 => 'size',
) ],
cea_video_data_block => [ group_by2(
- 1 => 'native',
- 7 => 'mode',
+ 1 => 'native',
+ 7 => 'mode',
) ],
);
@@ -275,9 +275,9 @@ sub get_many_bits {
my @bits = split('', unpack('B*', $s));
my %h;
foreach (@{$subfields{$field_name}}) {
- my ($size, $field) = @$_;
- my @l = ('0' x (8 - $size), splice(@bits, 0, $size));
- $h{$field} = unpack("C", pack('B*', join('', @l))) if $field && $field !~ /^_/;
+ my ($size, $field) = @$_;
+ my @l = ('0' x (8 - $size), splice(@bits, 0, $size));
+ $h{$field} = unpack("C", pack('B*', join('', @l))) if $field && $field !~ /^_/;
}
\%h;
}
@@ -289,12 +289,12 @@ sub check_parsed_edid {
$edid->{edid_revision} != 0xff or return 'bad edid_revision';
if ($edid->{monitor_range}) {
- $edid->{monitor_range}{horizontal_min} &&
- $edid->{monitor_range}{horizontal_min} <= $edid->{monitor_range}{horizontal_max}
- or return 'bad HorizSync';
- $edid->{monitor_range}{vertical_min} &&
- $edid->{monitor_range}{vertical_min} <= $edid->{monitor_range}{vertical_max}
- or return 'bad VertRefresh';
+ $edid->{monitor_range}{horizontal_min} &&
+ $edid->{monitor_range}{horizontal_min} <= $edid->{monitor_range}{horizontal_max}
+ or return 'bad HorizSync';
+ $edid->{monitor_range}{vertical_min} &&
+ $edid->{monitor_range}{vertical_min} <= $edid->{monitor_range}{vertical_max}
+ or return 'bad VertRefresh';
}
'';
@@ -307,9 +307,9 @@ sub build_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) {
- $field =~ s/_hi$// or next;
- my $hi = delete($h->{$field . '_hi'});
- $h->{$field} += $hi << $detailed_timing_field_size{$field};
+ $field =~ s/_hi$// or next;
+ my $hi = delete($h->{$field . '_hi'});
+ $h->{$field} += $hi << $detailed_timing_field_size{$field};
}
$h;
}
@@ -318,20 +318,20 @@ sub add_standard_timing_modes {
my ($edid, $v) = @_;
my @aspect2ratio = (
- $edid->{edid_version} > 1 || $edid->{edid_revision} > 2 ? '16/10' : '1/1',
- '4/3', '5/4', '16/9',
+ $edid->{edid_version} > 1 || $edid->{edid_revision} > 2 ? '16/10' : '1/1',
+ '4/3', '5/4', '16/9',
);
$v = [ map {
- 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;
- if ($h->{ratio} = $aspect2ratio[$h->{aspect}]) {
- delete $h->{aspect};
- $h->{Y} = $h->{X} / eval($h->{ratio});
- }
- $h;
- } else { () }
+ 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;
+ if ($h->{ratio} = $aspect2ratio[$h->{aspect}]) {
+ delete $h->{aspect};
+ $h->{Y} = $h->{X} / eval($h->{ratio});
+ }
+ $h;
+ } else { () }
} unpack('a2' x (length($v) / 2), $v) ];
$v;
}
@@ -344,238 +344,238 @@ sub parse_edid {
my @vals = unpack(join('', map { $_->[0] } @edid_info), $main_edid);
my $i;
foreach (@edid_info) {
- my ($field, $v) = ($_->[1], $vals[$i++]);
-
- if ($field eq 'year') {
- $v += 1990;
- } elsif ($field eq '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');
- } elsif ($field eq 'feature_support') {
- $v = get_many_bits($v, 'feature_support');
- } elsif ($field eq '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);
- } 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);
- push @{$edid{detailed_timings}}, $h
- if $h->{horizontal_active} > 1 && $h->{vertical_active} > 1;
- } else {
- (my $flag, $vv) = unpack("n x a*", $vv);
-
- if ($flag == 0xfd) {
- # 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 $e = $edid{detailed_timings}[0];
- my $valid = 1;
- foreach my $m ('min', 'max') {
- my %total;
- foreach my $dir ('horizontal', 'vertical') {
- $range->{$dir . '_sync_pulse_width_' . $m} *= 2;
- $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'},
- $m, $range->{$dir . '_back_porch_' . $m})) {
- $total{$dir} = $e->{$dir . '_active'} + $range->{$dir . '_blanking_' . $m};
- }
- }
- 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);
- } else {
- $valid = 0;
- }
- }
- $edid{$valid ? 'monitor_range' : 'manufacturer_specified_range_timing'} = $range;
-
- } elsif ($flag == 0xfa) {
- 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);
- } elsif ($flag == 0xfe) {
- push @{$edid{monitor_text}}, unpack('A13', $vv);
- } elsif ($flag == 0xff) {
- push @{$edid{serial_number2}}, unpack('A13', $vv);
- } else {
- $verbose && $vv ne "\0" x 13 && $vv ne " " x 13 and
- warn "parse_edid: unknown flag $flag\n";
- }
- }
- }
- }
-
- $edid{$field} = $v if $field && $field !~ /^_/;
+ my ($field, $v) = ($_->[1], $vals[$i++]);
+
+ if ($field eq 'year') {
+ $v += 1990;
+ } elsif ($field eq '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');
+ } elsif ($field eq 'feature_support') {
+ $v = get_many_bits($v, 'feature_support');
+ } elsif ($field eq '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);
+ } 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);
+ push @{$edid{detailed_timings}}, $h
+ if $h->{horizontal_active} > 1 && $h->{vertical_active} > 1;
+ } else {
+ (my $flag, $vv) = unpack("n x a*", $vv);
+
+ if ($flag == 0xfd) {
+ # 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 $e = $edid{detailed_timings}[0];
+ my $valid = 1;
+ foreach my $m ('min', 'max') {
+ my %total;
+ foreach my $dir ('horizontal', 'vertical') {
+ $range->{$dir . '_sync_pulse_width_' . $m} *= 2;
+ $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'},
+ $m, $range->{$dir . '_back_porch_' . $m})) {
+ $total{$dir} = $e->{$dir . '_active'} + $range->{$dir . '_blanking_' . $m};
+ }
+ }
+ 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);
+ } else {
+ $valid = 0;
+ }
+ }
+ $edid{$valid ? 'monitor_range' : 'manufacturer_specified_range_timing'} = $range;
+
+ } elsif ($flag == 0xfa) {
+ 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);
+ } elsif ($flag == 0xfe) {
+ push @{$edid{monitor_text}}, unpack('A13', $vv);
+ } elsif ($flag == 0xff) {
+ push @{$edid{serial_number2}}, unpack('A13', $vv);
+ } else {
+ $verbose && $vv ne "\0" x 13 && $vv ne " " x 13 and
+ warn "parse_edid: unknown flag $flag\n";
+ }
+ }
+ }
+ }
+
+ $edid{$field} = $v if $field && $field !~ /^_/;
}
foreach (@eedid_blocks) {
- my ($tag, $v) = unpack("C a*", $_);
-
- if ($tag == 0x02) { # CEA EDID
- my $dtd_offset;
- ($dtd_offset, $v) = unpack("x C x a*", $v);
-
- next if $dtd_offset < 4;
- $dtd_offset -= 4;
-
- while ($dtd_offset > 0) {
- my $h = get_many_bits($v, 'cea_data_block_collection');
- $dtd_offset -= $h->{size} + 1;
-
- my $vv;
- ($vv, $v) = unpack("x a$h->{size} a*", $v);
- 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');
- my $cea_mode = $cea_video_modes[$h->{mode} - 1];
- if (!$cea_mode) {
- warn "parse_edid: unhandled CEA mode $h->{mode}\n" if $verbose;
- next;
- }
- my %det_mode = (source => 'cea_vdb');
- @det_mode{@cea_video_mode_to_detailed_timing} = @$cea_mode;
- push @{$edid{detailed_timings}}, \%det_mode;
- }
- }
- }
-
- 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);
- push @{$edid{detailed_timings}}, $h
- if $h->{horizontal_active} > 1 && $h->{vertical_active} > 1;
- }
- } else {
- $verbose && warn "parse_edid: unknown tag $tag\n";
- }
+ my ($tag, $v) = unpack("C a*", $_);
+
+ if ($tag == 0x02) { # CEA EDID
+ my $dtd_offset;
+ ($dtd_offset, $v) = unpack("x C x a*", $v);
+
+ next if $dtd_offset < 4;
+ $dtd_offset -= 4;
+
+ while ($dtd_offset > 0) {
+ my $h = get_many_bits($v, 'cea_data_block_collection');
+ $dtd_offset -= $h->{size} + 1;
+
+ my $vv;
+ ($vv, $v) = unpack("x a$h->{size} a*", $v);
+ 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');
+ my $cea_mode = $cea_video_modes[$h->{mode} - 1];
+ if (!$cea_mode) {
+ warn "parse_edid: unhandled CEA mode $h->{mode}\n" if $verbose;
+ next;
+ }
+ my %det_mode = (source => 'cea_vdb');
+ @det_mode{@cea_video_mode_to_detailed_timing} = @$cea_mode;
+ push @{$edid{detailed_timings}}, \%det_mode;
+ }
+ }
+ }
+
+ 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);
+ push @{$edid{detailed_timings}}, $h
+ if $h->{horizontal_active} > 1 && $h->{vertical_active} > 1;
+ }
+ } else {
+ $verbose && warn "parse_edid: unknown tag $tag\n";
+ }
}
$edid{max_size_precision} = 'cm';
$edid{EISA_ID} = $edid{manufacturer_name} . sprintf('%04x', $edid{product_code}) if $edid{product_code} && $edid{manufacturer_name};
if ($edid{monitor_range}) {
- $edid{HorizSync} = $edid{monitor_range}{horizontal_min} . '-' . $edid{monitor_range}{horizontal_max};
- $edid{VertRefresh} = $edid{monitor_range}{vertical_min} . '-' . $edid{monitor_range}{vertical_max};
+ $edid{HorizSync} = $edid{monitor_range}{horizontal_min} . '-' . $edid{monitor_range}{horizontal_max};
+ $edid{VertRefresh} = $edid{monitor_range}{vertical_min} . '-' . $edid{monitor_range}{vertical_max};
}
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_precision} = 'cm';
+ $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_precision} = 'cm';
}
if ($edid{feature_support}{has_preferred_timing} && $edid{detailed_timings}[0]) {
- $edid{detailed_timings}[0]{preferred} = 1;
+ $edid{detailed_timings}[0]{preferred} = 1;
}
foreach my $h (@{$edid{detailed_timings}}) {
- # EDID standard is ambiguous on how interlaced modes should be
- # specified; workaround clearly broken modes:
- if ($h->{interlaced}) {
- foreach ("720x480", "1440x480", "2880x480", "720x576", "1440x576", "2880x576", "1920x1080") {
- if ($_ eq $h->{horizontal_active} . 'x' . $h->{vertical_active} * 2) {
- $h->{vertical_active} *= 2;
- $h->{vertical_blanking} *= 2;
- $h->{vertical_sync_offset} *= 2;
- $h->{vertical_sync_pulse_width} *= 2;
- $h->{vertical_blanking} |= 1;
- }
- }
- }
-
- # if the mm size given in the detailed_timing is not far from the cm size
- # put it as a more precise cm size
- my %in_cm = map { $_ => $h->{$_ . '_image_size'} / 10 } ('horizontal', 'vertical');
- my ($error) = sort { $b <=> $a } map { abs($edid{'max_size_' . $_} - $in_cm{$_}) } keys %in_cm;
- if ($error <= 0.5) {
- $edid{'max_size_' . $_} = $in_cm{$_} foreach keys %in_cm;
- $edid{max_size_precision} = 'mm';
- }
- 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_precision} = 'mm';
- }
-
- $h->{bad_ratio} = 1 if abs($edid{ratio} - $h->{horizontal_active} / $h->{vertical_active}) > ($edid{ratio_precision} eq 'mm' ? 0.02 : 0.2);
-
- if ($edid{max_size_vertical}) {
- $h->{vertical_dpi} = $h->{vertical_active} / $edid{max_size_vertical} * 2.54;
- }
- if ($edid{max_size_horizontal}) {
- $h->{horizontal_dpi} = $h->{horizontal_active} / $edid{max_size_horizontal} * 2.54;
- }
- my $dpi_string = '';
- if ($h->{vertical_dpi} && $h->{horizontal_dpi}) {
- $dpi_string =
- abs($h->{vertical_dpi} / $h->{horizontal_dpi} - 1) < 0.05 ?
- sprintf("%d dpi", $h->{horizontal_dpi}) :
- sprintf("%dx%d dpi", $h->{horizontal_dpi}, $h->{vertical_dpi});
- }
-
- my $horizontal_total = $h->{horizontal_active} + $h->{horizontal_blanking};
- my $vertical_total = $h->{vertical_active} + $h->{vertical_blanking};
+ # EDID standard is ambiguous on how interlaced modes should be
+ # specified; workaround clearly broken modes:
+ if ($h->{interlaced}) {
+ foreach ("720x480", "1440x480", "2880x480", "720x576", "1440x576", "2880x576", "1920x1080") {
+ if ($_ eq $h->{horizontal_active} . 'x' . $h->{vertical_active} * 2) {
+ $h->{vertical_active} *= 2;
+ $h->{vertical_blanking} *= 2;
+ $h->{vertical_sync_offset} *= 2;
+ $h->{vertical_sync_pulse_width} *= 2;
+ $h->{vertical_blanking} |= 1;
+ }
+ }
+ }
+
+ # if the mm size given in the detailed_timing is not far from the cm size
+ # put it as a more precise cm size
+ my %in_cm = map { $_ => $h->{$_ . '_image_size'} / 10 } ('horizontal', 'vertical');
+ my ($error) = sort { $b <=> $a } map { abs($edid{'max_size_' . $_} - $in_cm{$_}) } keys %in_cm;
+ if ($error <= 0.5) {
+ $edid{'max_size_' . $_} = $in_cm{$_} foreach keys %in_cm;
+ $edid{max_size_precision} = 'mm';
+ }
+ 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_precision} = 'mm';
+ }
+
+ $h->{bad_ratio} = 1 if abs($edid{ratio} - $h->{horizontal_active} / $h->{vertical_active}) > ($edid{ratio_precision} eq 'mm' ? 0.02 : 0.2);
+
+ if ($edid{max_size_vertical}) {
+ $h->{vertical_dpi} = $h->{vertical_active} / $edid{max_size_vertical} * 2.54;
+ }
+ if ($edid{max_size_horizontal}) {
+ $h->{horizontal_dpi} = $h->{horizontal_active} / $edid{max_size_horizontal} * 2.54;
+ }
+ my $dpi_string = '';
+ if ($h->{vertical_dpi} && $h->{horizontal_dpi}) {
+ $dpi_string =
+ abs($h->{vertical_dpi} / $h->{horizontal_dpi} - 1) < 0.05 ?
+ sprintf("%d dpi", $h->{horizontal_dpi}) :
+ sprintf("%dx%d dpi", $h->{horizontal_dpi}, $h->{vertical_dpi});
+ }
+
+ my $horizontal_total = $h->{horizontal_active} + $h->{horizontal_blanking};
+ my $vertical_total = $h->{vertical_active} + $h->{vertical_blanking};
no warnings 'uninitialized';
- $h->{ModeLine_comment} = sprintf qq(# Monitor %s%s modeline (%.1f Hz vsync, %.1f kHz hsync, %sratio %s%s)),
- $h->{preferred} ? "preferred" : "supported",
- $h->{source} eq 'cea_vdb' ? " CEA" : '',
- $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}),
- $dpi_string ? ", $dpi_string" : '';
-
- $h->{ModeLine} = sprintf qq("%dx%d" $h->{pixel_clock} %d %d %d %d %d %d %d %d %shsync %svsync%s),
- $h->{horizontal_active}, $h->{vertical_active},
-
- $h->{horizontal_active},
- $h->{horizontal_active} + $h->{horizontal_sync_offset},
- $h->{horizontal_active} + $h->{horizontal_sync_offset} + $h->{horizontal_sync_pulse_width},
- $horizontal_total,
-
- $h->{vertical_active},
- $h->{vertical_active} + $h->{vertical_sync_offset},
- $h->{vertical_active} + $h->{vertical_sync_offset} + $h->{vertical_sync_pulse_width},
- $vertical_total,
-
- $h->{horizontal_sync_positive} ? '+' : '-',
- $h->{vertical_sync_positive} ? '+' : '-',
- $h->{interlaced} ? ' Interlace' : '';
+ $h->{ModeLine_comment} = sprintf qq(# Monitor %s%s modeline (%.1f Hz vsync, %.1f kHz hsync, %sratio %s%s)),
+ $h->{preferred} ? "preferred" : "supported",
+ $h->{source} eq 'cea_vdb' ? " CEA" : '',
+ $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}),
+ $dpi_string ? ", $dpi_string" : '';
+
+ $h->{ModeLine} = sprintf qq("%dx%d" $h->{pixel_clock} %d %d %d %d %d %d %d %d %shsync %svsync%s),
+ $h->{horizontal_active}, $h->{vertical_active},
+
+ $h->{horizontal_active},
+ $h->{horizontal_active} + $h->{horizontal_sync_offset},
+ $h->{horizontal_active} + $h->{horizontal_sync_offset} + $h->{horizontal_sync_pulse_width},
+ $horizontal_total,
+
+ $h->{vertical_active},
+ $h->{vertical_active} + $h->{vertical_sync_offset},
+ $h->{vertical_active} + $h->{vertical_sync_offset} + $h->{vertical_sync_pulse_width},
+ $vertical_total,
+
+ $h->{horizontal_sync_positive} ? '+' : '-',
+ $h->{vertical_sync_positive} ? '+' : '-',
+ $h->{interlaced} ? ' Interlace' : '';
}
$edid{diagonal_size} = sqrt(sqr($edid{max_size_horizontal}) +
- sqr($edid{max_size_vertical})) / 2.54;
+ sqr($edid{max_size_vertical})) / 2.54;
\%edid;
}
@@ -584,10 +584,10 @@ sub nearest_ratio {
my ($ratio, $max_error) = @_;
my @sorted =
sort { $a->[1] <=> $b->[1] }
- map {
- my $error = abs($ratio - eval($_));
- $error > $max_error ? () : [ $_, $error ];
- } @known_ratios;
+ map {
+ my $error = abs($ratio - eval($_));
+ $error > $max_error ? () : [ $_, $error ];
+ } @known_ratios;
$sorted[0][0];
}
@@ -595,18 +595,18 @@ 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);
- $ratio1 && $ratio2 or return;
- if ($ratio1 eq $ratio2) {
- $ratio1;
- } else {
- my $ratio = nearest_ratio($horizontal / $vertical, 0.2);
- join(' or ', $ratio, $ratio eq $ratio1 ? $ratio2 : $ratio1);
- }
+ my $error = 0.5;
+ 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);
+ join(' or ', $ratio, $ratio eq $ratio1 ? $ratio2 : $ratio1);
+ }
}
}
@@ -614,7 +614,7 @@ 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) {
- return ();
+ return ();
}
pack("C*", map { hex($_) } $edid_str =~ /(..)/g);
}
@@ -624,10 +624,10 @@ sub find_edid_in_string {
my @edids;
while ($input =~ /(?:EDID_DATA|: EDID \(in hex\)):\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;
}
@@ -637,7 +637,7 @@ sub round { int($_[0] + 0.5) }
sub group_by2 {
my @l;
for (my $i = 0; $i < @_; $i += 2) {
- push @l, [ $_[$i], $_[$i+1] ];
+ push @l, [ $_[$i], $_[$i+1] ];
}
@l;
}