File Coverage

blib/lib/Image/PNG/Simple.pm
Criterion Covered Total %
statement 48 48 100.0
branch 5 10 50.0
condition n/a
subroutine 8 8 100.0
pod 3 3 100.0
total 64 69 92.7


line stmt bran cond sub pod time code
1             package Image::PNG::Simple;
2              
3 1     1   38769 use 5.008007;
  1         3  
4 1     1   3 use strict;
  1         2  
  1         16  
5 1     1   3 use warnings;
  1         10  
  1         27  
6 1     1   3 use File::Temp ();
  1         1  
  1         17  
7 1     1   3 use Carp 'croak';
  1         0  
  1         364  
8              
9             our $VERSION = '0.07';
10              
11             require XSLoader;
12             XSLoader::load('Image::PNG::Simple', $VERSION);
13              
14             sub parse_bmp_data {
15 1     1 1 614 my ($self, $data) = @_;
16            
17 1         17 my $tmp_dir = File::Temp->newdir;
18 1         825 my $tmp_file = "$tmp_dir/tmp.bmp";
19            
20 1 50       97 open my $out_fh, '>', $tmp_file
21             or croak "Can't open file $tmp_file for write: $!";
22            
23 1         4 binmode $out_fh;
24 1         1150 print $out_fh $data;
25 1         37 close $out_fh;
26            
27 1         21306 $self->read_bmp_file($tmp_file);
28             }
29              
30             sub get_bmp_data {
31 1     1 1 701 my $self = shift;
32            
33 1         9 my $tmp_dir = File::Temp->newdir;
34 1         385 my $tmp_file = "$tmp_dir/tmp.bmp";
35            
36             # Write bmp data to temp file
37 1 50       69 open my $out_fh, '>', $tmp_file
38             or croak "Can't open file $tmp_file for write: $!";
39 1         19390 $self->write_bmp_file($tmp_file);
40 1         17 close $out_fh;
41            
42             # Read bmp data from temp file
43 1 50       51 open my $in_fh, '<', $tmp_file
44             or croak "Can't open file $tmp_file for read: $!";
45 1         2 binmode($in_fh);
46 1         3 my $bmp_data = do { local $/; <$in_fh> };
  1         5  
  1         391  
47 1         11 close $in_fh;
48            
49 1         17 return $bmp_data;
50             }
51              
52             sub get_png_data {
53 1     1 1 1490 my $self = shift;
54            
55 1         7 my $tmp_dir = File::Temp->newdir;
56 1         365 my $tmp_file = "$tmp_dir/tmp.png";
57            
58             # Write png data to temp file
59 1 50       67 open my $out_fh, '>', $tmp_file
60             or croak "Can't open file $tmp_file for write: $!";
61 1         214229 $self->write_png_file($tmp_file);
62 1         26 close $out_fh;
63            
64             # Read png data from temp file
65 1 50       89 open my $in_fh, '<', $tmp_file
66             or croak "Can't open file $tmp_file for read: $!";
67 1         3 binmode($in_fh);
68 1         3 my $png_data = do { local $/; <$in_fh> };
  1         7  
  1         200  
69 1         9 close $in_fh;
70            
71 1         20 return $png_data;
72             }
73              
74             1;
75              
76             =head1 NAME
77              
78             Image::PNG::Simple - Convert bitmap file to png file without C library dependency.
79              
80             =head1 CAUTION
81              
82             B
83              
84             =head1 SYNOPSIS
85              
86             use Image::PNG::Simple;
87            
88             # Create Image::PNG::Simple object
89             my $ips = Image::PNG::Simple->new;
90            
91             # Read bitmap file
92             $ips->read_bmp_file('dog.bmp');
93            
94             # Write png file
95             $ips->write_png_file('dog.png');
96              
97             =head1 DESCRIPTION
98              
99             Convert bitmap file to png file without C library dependency.
100              
101             =head1 METHODS
102              
103             =head2 new
104              
105             my $ips = Image::PNG::Simple->new;
106              
107             Create new Image::PNG::Simple object.
108              
109             =head2 read_bmp_file
110              
111             $ips->read_bmp_file('dog.bmp');
112              
113             Read bitmap file.
114              
115             =head2 parse_bmp_data
116              
117             $ips->parse_bmp_data($bmp_data);
118              
119             Prase bitmap binary data.
120              
121             =head2 get_bmp_data
122              
123             $ips->get_bmp_data;
124              
125             Get bitmap binary data.
126              
127             =head2 get_png_data
128              
129             $ips->get_png_data;
130            
131             Get png binary data.
132              
133             =head2 write_bmp_file
134              
135             $ips->write_bmp_file('dog_copy.bmp');
136              
137             Write bitmap file.
138              
139             =head2 write_png_file
140              
141             $ips->write_png_file('dog.png');
142              
143             Write png file.
144              
145             =head1 INTERNAL
146              
147             This module internally use libpng-1.6.17 and zlib-1.2.8.
148             So This module license follow Perl license, libpng license and zlib license.
149              
150             =head1 SEE ALSO
151              
152             L, L, L
153              
154             =head1 AUTHOR
155              
156             Yuki Kimoto Ekimoto.yuki@gmail.comE
157              
158             =head1 REPOSITORY and BUG REPORT
159              
160             Tell me on Github Repository
161              
162             L
163              
164             =head1 COPYRIGHT AND LICENSE
165              
166             Copyright (C) 2015 by Yuki Kimoto
167              
168             This library is free software; you can redistribute it and/or modify
169             it under the same terms as Perl, libpng, and zlib itself, either Perl version 5.16.3 or,
170             at your option, any later version of Perl 5 you may have available.
171              
172             =cut