From 34123b9d0460b50118a76290aafa0fc31eb365b1 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 7 Oct 2014 13:38:16 -0400 Subject: add some accessors --- lib/Image/PNM.pm | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'lib') diff --git a/lib/Image/PNM.pm b/lib/Image/PNM.pm index 31d4c93..bc748e7 100644 --- a/lib/Image/PNM.pm +++ b/lib/Image/PNM.pm @@ -35,6 +35,44 @@ sub as_string { return $self->$method; } +sub width { + my $self = shift; + return $self->{w}; +} + +sub height { + my $self = shift; + return $self->{h}; +} + +sub max_pixel_value { + my $self = shift; + return $self->{max}; +} + +sub pixel { + my $self = shift; + my ($row, $col) = @_; + + my $pixel = $self->raw_pixel($row, $col); + return [ map { $_ / $self->{max} } @$pixel ]; +} + +sub raw_pixel { + my $self = shift; + my ($row, $col) = @_; + + my $pixel = $self->{pixels}[$row][$col]; + die "invalid pixel location ($row, $col)" + unless defined $pixel; + + if (!ref $pixel) { + $pixel = [ $pixel, $pixel, $pixel ]; + } + + return $pixel; +} + sub _as_string_P3 { my $self = shift; -- cgit v1.2.3-54-g00ecf