Permalink
Browse files

move JPEG into it's own module

  • Loading branch information...
1 parent e5ee047 commit 797a9f9c550162e151a2d4210891ad324e562d5b Tony Cook committed Aug 31, 2010
View
@@ -74,9 +74,6 @@ use Imager::Font;
i_tt_text
i_tt_bbox
- i_readjpeg_wiol
- i_writejpeg_wiol
-
i_readpnm_wiol
i_writeppm_wiol
@@ -1368,16 +1365,6 @@ sub read {
return;
}
- # Setup data source
- if ( $input{'type'} eq 'jpeg' ) {
- ($self->{IMG},$self->{IPTCRAW}) = i_readjpeg_wiol( $IO );
- if ( !defined($self->{IMG}) ) {
- $self->{ERRSTR}=$self->_error_as_msg(); return undef;
- }
- $self->{DEBUG} && print "loading a jpeg file\n";
- return $self;
- }
-
my $allow_incomplete = $input{allow_incomplete};
defined $allow_incomplete or $allow_incomplete = 0;
View
@@ -2334,57 +2334,11 @@ i_tt_glyph_name(handle, text_sv, utf8 = 0)
#endif
-
-#ifdef HAVE_LIBJPEG
-undef_int
-i_writejpeg_wiol(im, ig, qfactor)
- Imager::ImgRaw im
- Imager::IO ig
- int qfactor
-
-
-void
-i_readjpeg_wiol(ig)
- Imager::IO ig
- PREINIT:
- char* iptc_itext;
- int tlength;
- i_img* rimg;
- SV* r;
- PPCODE:
- iptc_itext = NULL;
- rimg = i_readjpeg_wiol(ig,-1,&iptc_itext,&tlength);
- if (iptc_itext == NULL) {
- r = sv_newmortal();
- EXTEND(SP,1);
- sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
- PUSHs(r);
- } else {
- r = sv_newmortal();
- EXTEND(SP,2);
- sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
- PUSHs(r);
- PUSHs(sv_2mortal(newSVpv(iptc_itext,tlength)));
- myfree(iptc_itext);
- }
-
-int
-i_exif_enabled()
-
-#endif
-
-
const char *
i_test_format_probe(ig, length)
Imager::IO ig
int length
-
-
-
-
-
-
Imager::ImgRaw
i_readpnm_wiol(ig, allow_incomplete)
Imager::IO ig
View
@@ -0,0 +1,89 @@
+package Imager::File::JPEG;
+use strict;
+use Imager;
+use vars qw($VERSION @ISA);
+
+BEGIN {
+ $VERSION = "0.77";
+
+ eval {
+ require XSLoader;
+ XSLoader::load('Imager::File::JPEG', $VERSION);
+ 1;
+ } or do {
+ require DynaLoader;
+ push @ISA, 'DynaLoader';
+ bootstrap 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;
+ },
+ );
+
+__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;
+
+=head1 DESCRIPTION
+
+Imager's JPEG support is documented in L<Imager::Files>.
+
+=head1 AUTHOR
+
+Tony Cook <tony@imager.perl.org>
+
+=head1 SEE ALSO
+
+Imager, Imager::Files.
+
+=cut
View
@@ -0,0 +1,49 @@
+#define PERL_NO_GET_CONTEXT
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+#include "imext.h"
+#include "imperl.h"
+#include "imjpeg.h"
+
+DEFINE_IMAGER_CALLBACKS;
+
+MODULE = Imager::File::JPEG PACKAGE = Imager::File::JPEG
+
+undef_int
+i_writejpeg_wiol(im, ig, qfactor)
+ Imager::ImgRaw im
+ Imager::IO ig
+ int qfactor
+
+
+void
+i_readjpeg_wiol(ig)
+ Imager::IO ig
+ PREINIT:
+ char* iptc_itext;
+ int tlength;
+ i_img* rimg;
+ SV* r;
+ PPCODE:
+ iptc_itext = NULL;
+ rimg = i_readjpeg_wiol(ig,-1,&iptc_itext,&tlength);
+ if (iptc_itext == NULL) {
+ r = sv_newmortal();
+ EXTEND(SP,1);
+ sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
+ PUSHs(r);
+ } else {
+ r = sv_newmortal();
+ EXTEND(SP,2);
+ sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
+ PUSHs(r);
+ PUSHs(sv_2mortal(newSVpv(iptc_itext,tlength)));
+ myfree(iptc_itext);
+ }
+
+BOOT:
+ PERL_INITIALIZE_IMAGER_CALLBACKS;
View
@@ -0,0 +1,113 @@
+#!perl -w
+use strict;
+use ExtUtils::MakeMaker qw(WriteMakefile WriteEmptyMakefile);
+use Getopt::Long;
+use Config;
+
+my $verbose = $ENV{IM_VERBOSE};
+my @libpaths;
+my @incpaths;
+
+GetOptions("incpath=s", \@incpaths,
+ "libpath=s" => \@libpaths,
+ "verbose|v" => \$verbose);
+
+our $BUILDING_IMAGER;
+
+my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
+
+my %opts =
+ (
+ NAME => 'Imager::File::JPEG',
+ VERSION_FROM => 'JPEG.pm',
+ OBJECT => 'JPEG.o imjpeg.o imexif.o',
+ );
+
+my @inc;
+if ($BUILDING_IMAGER) {
+ push @inc, "-I..";
+ unshift @INC, "../lib";
+}
+else {
+ unshift @INC, "inc";
+ print "JPEG: building independently\n";
+ require Imager::ExtUtils;
+ push @inc, Imager::ExtUtils->includes;
+ $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];
+
+ # Imager required configure through use
+ my @Imager_req = ( Imager => "0.77" );
+ if ($MM_ver >= 6.46) {
+ $opts{META_MERGE} =
+ {
+ configure_requires =>
+ {
+ @Imager_req,
+ },
+ build_requires =>
+ {
+ @Imager_req,
+ "Test::More" => "0.47",
+ },
+ resources =>
+ {
+ homepage => "http://imager.perl.org/",
+ repository =>
+ {
+ url => "http://imager.perl.org/svn/trunk/Imager-File-JPEG",
+ web => "http://imager.perl.org/svnweb/public/browse/trunk/Imager-File-JPEG",
+ type => "svn",
+ },
+ },
+ };
+ $opts{PREREQ_PM} =
+ {
+ @Imager_req,
+ };
+ }
+}
+
+require Imager::Probe;
+
+my %probe =
+ (
+ name => "JPEG",
+ inccheck => sub { -e File::Spec->catfile($_[0], "jpeglib.h") },
+ libbase => "jpeg",
+ #testcode => _jpeg_test_code(),
+ #testcodeheaders => [ "stdio.h", "stddef.h", "jpeglib.h", "jerror.h" ],
+ incpath => join($Config{path_sep}, @incpaths),
+ libpath => join($Config{path_sep}, @libpaths),
+ );
+
+my $probe_res = Imager::Probe->probe(\%probe);
+if ($probe_res) {
+ push @inc, $probe_res->{INC};
+ $opts{LIBS} = $probe_res->{LIBS};
+
+ $opts{INC} = "@inc";
+
+ if ($MM_ver > 6.06) {
+ $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>';
+ $opts{ABSTRACT} = 'JPEG Image file support';
+ }
+
+ WriteMakefile(%opts);
+}
+else {
+ if ($BUILDING_IMAGER) {
+ WriteEmptyMakefile(%opts);
+ }
+ else {
+ # fail in good way
+ die "OS unsupported: JPEG libraries or headers not found\n";
+ }
+}
+
+sub _jpeg_test_code {
+ return <<'CODE';
+
+/*fprintf(stderr, "PNG: library version %ld, header version %ld\n", (long)png_access_version_number(), (long)PNG_LIBPNG_VER);*/
+return 0;
+CODE
+}
Oops, something went wrong.

0 comments on commit 797a9f9

Please sign in to comment.