diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-10-07 13:38:16 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-10-07 13:38:16 -0400 |
commit | 34123b9d0460b50118a76290aafa0fc31eb365b1 (patch) | |
tree | 68ea9f0f025a63fbf0de3d9a069fe1e7c6e55976 /lib/Image | |
parent | 35a0bc2f82802800bdb0769882d667d59313f141 (diff) | |
download | image-pnm-34123b9d0460b50118a76290aafa0fc31eb365b1.tar.gz image-pnm-34123b9d0460b50118a76290aafa0fc31eb365b1.zip |
add some accessors
Diffstat (limited to 'lib/Image')
-rw-r--r-- | lib/Image/PNM.pm | 38 |
1 files changed, 38 insertions, 0 deletions
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; |