| 1 | =head1 NAME | ||
| 2 | |||
| 3 | Image::Magick::Iterator::PPM - read PPM images | ||
| 4 | |||
| 5 | =head1 DESCRIPTION | ||
| 6 | |||
| 7 | Image::Magick::Iterator delegates to this class for | ||
| 8 | low level image byte read()s. Don't use this class | ||
| 9 | directly. | ||
| 10 | |||
| 11 | =head1 FEEDBACK | ||
| 12 | |||
| 13 | See L<Image::Magick::Iterator>. | ||
| 14 | |||
| 15 | =head1 AUTHOR | ||
| 16 | |||
| 17 | Allen Day E<lt>allenday@ucla.eduE<gt> | ||
| 18 | |||
| 19 | =head1 COPYRIGHT AND LICENSE | ||
| 20 | |||
| 21 | Copyright (C) 2004 by Allen Day, allenday@ucla.edu | ||
| 22 | |||
| 23 | This library is released under GPL, the GNU General Public License | ||
| 24 | |||
| 25 | =head1 APPENDIX | ||
| 26 | |||
| 27 | The rest of the documentation details each of the object methods. | ||
| 28 | Internal methods are usually preceded with a '_'. Methods are | ||
| 29 | in alphabetical order for the most part. | ||
| 30 | |||
| 31 | =cut | ||
| 32 | |||
| 33 | |||
| 34 | # Let the code begin... | ||
| 35 | |||
| 36 | |||
| 37 | package Image::Magick::Iterator::PPM; | ||
| 38 | use strict; | ||
| 39 | use base qw(); | ||
| 40 | use Image::PBMlib; | ||
| 41 | our $VERSION = '0.01'; | ||
| 42 | |||
| 43 | =head2 read_image() | ||
| 44 | |||
| 45 | =over | ||
| 46 | |||
| 47 | =item Usage | ||
| 48 | |||
| 49 | $obj->read_image($filehandle); | ||
| 50 | |||
| 51 | =item Function | ||
| 52 | |||
| 53 | reads an image from a filehandle. | ||
| 54 | |||
| 55 | =item Returns | ||
| 56 | |||
| 57 | raw data for one PPM image. this is complete, | ||
| 58 | including header and pixels. | ||
| 59 | |||
| 60 | =item Arguments | ||
| 61 | |||
| 62 | a filehandle reference | ||
| 63 | |||
| 64 | =back | ||
| 65 | |||
| 66 | =cut | ||
| 67 | |||
| 68 | sub read_image { | ||
| 69 | my $pack = shift; | ||
| 70 | my $handle = shift; | ||
| 71 | |||
| 72 | my $bytes_per_pixel = 3; | ||
| 73 | |||
| 74 | my $header = readppmheader($handle); | ||
| 75 | |||
| 76 | return undef unless defined($header->{width}) and defined($header->{height}); | ||
| 77 | |||
| 78 | my $buf; | ||
| 79 | |||
| 80 | my $rc = read($handle,$buf, $header->{width} * $header->{height} * $bytes_per_pixel); | ||
| 81 | |||
| 82 | return undef unless( $rc == ($header->{width} * $header->{height}) * $bytes_per_pixel); | ||
| 83 | return makeppmheader($header).$buf; | ||
| 84 | } | ||
| 85 | |||
| 86 | 1; |