File: JPEG.pm

package info (click to toggle)
libimager-perl 1.019%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,824 kB
  • sloc: perl: 32,886; ansic: 28,193; makefile: 52; cpp: 4
file content (160 lines) | stat: -rw-r--r-- 3,195 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package Imager::File::JPEG;
use 5.006;
use strict;
use Imager;

BEGIN {
  our $VERSION = "0.97";

  require XSLoader;
  XSLoader::load('Imager::File::JPEG', $VERSION);
}

Imager->register_reader
  (
   type=>'jpeg',
   single =>
   sub { 
     my ($im, $io, %hsh) = @_;

     ($im->{IMG},$im->{IPTCRAW}) = i_readjpeg_wiol( $io );

     unless ($im->{IMG}) {
       $im->_set_error(Imager->_error_as_msg);
       return;
     }
     return $im;
   },
  );

Imager->register_writer
  (
   type=>'jpeg',
   single => 
   sub { 
     my ($im, $io, %hsh) = @_;

     $im->_set_opts(\%hsh, "i_", $im);
     $im->_set_opts(\%hsh, "jpeg_", $im);
     $im->_set_opts(\%hsh, "exif_", $im);

     my $quality = $hsh{jpegquality};
     defined $quality or $quality = 75;

     if ( !i_writejpeg_wiol($im->{IMG}, $io, $quality)) {
       $im->_set_error(Imager->_error_as_msg);
       return;
     }

     return $im;
   },
  );


sub has_arith_coding {
  my $cls = shift;

  return $cls->has_encode_arith_coding && $cls->has_decode_arith_coding;
}

__END__

=head1 NAME

Imager::File::JPEG - read and write JPEG files

=head1 SYNOPSIS

  use Imager;

  my $img = Imager->new;
  $img->read(file=>"foo.jpg")
    or die $img->errstr;

  $img->write(file => "foo.jpg")
    or die $img->errstr;

  my $version = Imager::File::JPEG->libjpeg_version();
  if (Imager::File::JPEG->is_turbojpeg) { ... }
  if (Imager::File::JPEG->is_mozjpeg) { ... }

  if (Imager::File::JPEG->has_arith_coding) { ... }

=head1 DESCRIPTION

Imager's JPEG support is documented in L<Imager::Files>.

Besides providing JPEG support, Imager::File::JPEG has the following
methods:

=over

=item libjpeg_version()

  Imager::File::JPEG->libjpeg_version();

Returns version information about the variety of C<libjpeg>
Imager::File::JPEG was compiled with.  This is determined at build
time.  This includes:

=over

=item *

The library type, one of C<libjpeg>, C<libjpeg-turbo> or C<mozjpeg>.

=item *

C<version> followed by the library version number.

=item *

C<api> followed by the C<libjpeg> API version.

=back

For C<libjpeg> the API and library versions are always equal.

=item is_turbojpeg()

  Imager::File::JPEG->is_turbojpeg();

Returns true if Imager::File::JPEG was built with C<libjpeg-turbo>.
Note that C<mozjpeg> is built on top of C<libjpeg-turbo> so this will
return true for C<mozjpeg>.

=item is_mozjpeg()

  Imager::File::JPEG->is_mozjpeg();

Returns true if Imager::File::JPEG was built with C<mozjpeg>.  Note
that C<mozjpeg> doesn't define its own version numbering, so
C<mozjpeg> is detected by defines that only C<mozjpeg> currently
defines.

=item has_arith_coding()

Returns true if the C<libjpeg> variant C<Imager::File::JPEG> was built
with has both encoding and decoding support for arithmetic coding.

=item has_encode_arith_coding()

Returns true if the C<libjpeg> variant C<Imager::File::JPEG> was built
with has encoding support for arithmetic coding.

=item has_decode_arith_coding()

Returns true if the C<libjpeg> variant C<Imager::File::JPEG> was built
with has decoding support for arithmetic coding.

=back

=head1 AUTHOR

Tony Cook <tonyc@cpan.org>

=head1 SEE ALSO

Imager, Imager::Files.

=cut