Debian Codegraph @

JPEG/JPEG.pm

raw
1 package Imager::File::JPEG;
2 use 5.006;
3 use strict;
4 use Imager;
5
6 BEGIN {
7 our $VERSION = "1.005";
8
9 require XSLoader;
10 XSLoader::load('Imager::File::JPEG', $VERSION);
11 }
12
13 Imager->register_reader
14 (
15 type=>'jpeg',
16 single =>
17 sub {
18 my ($im, $io, %hsh) = @_;
19
20 ($im->{IMG},$im->{IPTCRAW}) = i_readjpeg_wiol( $io );
21
22 unless ($im->{IMG}) {
23 $im->_set_error(Imager->_error_as_msg);
24 return;
25 }
26 return $im;
27 },
28 );
29
30 Imager->register_writer
31 (
32 type=>'jpeg',
33 single =>
34 sub {
35 my ($im, $io, %hsh) = @_;
36
37 $im->_set_opts(\%hsh, "i_", $im);
38 $im->_set_opts(\%hsh, "jpeg_", $im);
39 $im->_set_opts(\%hsh, "exif_", $im);
40
41 my $quality = $hsh{jpegquality};
42 defined $quality or $quality = 75;
43
44 if ( !i_writejpeg_wiol($im->{IMG}, $io, $quality)) {
45 $im->_set_error(Imager->_error_as_msg);
46 return;
47 }
48
49 return $im;
50 },
51 );
52
53
54 sub has_arith_coding {
55 my $cls = shift;
56
57 return $cls->has_encode_arith_coding && $cls->has_decode_arith_coding;
58 }
59
60 __END__
61
62 =head1 NAME
63
64 Imager::File::JPEG - read and write JPEG files
65
66 =head1 SYNOPSIS
67
68 use Imager;
69
70 my $img = Imager->new;
71 $img->read(file=>"foo.jpg")
72 or die $img->errstr;
73
74 $img->write(file => "foo.jpg")
75 or die $img->errstr;
76
77 my $version = Imager::File::JPEG->libjpeg_version();
78 if (Imager::File::JPEG->is_turbojpeg) { ... }
79 if (Imager::File::JPEG->is_mozjpeg) { ... }
80
81 if (Imager::File::JPEG->has_arith_coding) { ... }
82
83 =head1 DESCRIPTION
84
85 Imager's JPEG support is documented in L<Imager::Files>.
86
87 Besides providing JPEG support, Imager::File::JPEG has the following
88 methods:
89
90 =over
91
92 =item libjpeg_version()
93
94 Imager::File::JPEG->libjpeg_version();
95
96 Returns version information about the variety of C<libjpeg>
97 Imager::File::JPEG was compiled with. This is determined at build
98 time. This includes:
99
100 =over
101
102 =item *
103
104 The library type, one of C<libjpeg>, C<libjpeg-turbo> or C<mozjpeg>.
105
106 =item *
107
108 C<version> followed by the library version number.
109
110 =item *
111
112 C<api> followed by the C<libjpeg> API version.
113
114 =back
115
116 For C<libjpeg> the API and library versions are always equal.
117
118 =item is_turbojpeg()
119
120 Imager::File::JPEG->is_turbojpeg();
121
122 Returns true if Imager::File::JPEG was built with C<libjpeg-turbo>.
123 Note that C<mozjpeg> is built on top of C<libjpeg-turbo> so this will
124 return true for C<mozjpeg>.
125
126 =item is_mozjpeg()
127
128 Imager::File::JPEG->is_mozjpeg();
129
130 Returns true if Imager::File::JPEG was built with C<mozjpeg>. Note
131 that C<mozjpeg> doesn't define its own version numbering, so
132 C<mozjpeg> is detected by defines that only C<mozjpeg> currently
133 defines.
134
135 =item has_arith_coding()
136
137 Returns true if the C<libjpeg> variant C<Imager::File::JPEG> was built
138 with has both encoding and decoding support for arithmetic coding.
139
140 =item has_encode_arith_coding()
141
142 Returns true if the C<libjpeg> variant C<Imager::File::JPEG> was built
143 with has encoding support for arithmetic coding.
144
145 =item has_decode_arith_coding()
146
147 Returns true if the C<libjpeg> variant C<Imager::File::JPEG> was built
148 with has decoding support for arithmetic coding.
149
150 =back
151
152 =head1 AUTHOR
153
154 Tony Cook <[email protected]>
155
156 =head1 SEE ALSO
157
158 Imager, Imager::Files.
159
160 =cut