- several fixes to i_readgif_low()
- Fixed crop() method so that it is consistent with documentation.
- make clean now removes the testout directory
+ - added tests for the OO interface for tiff, added an option to
+ choose the resolution for fax tiffs, removed some unused code,
+ fixed minor problems with Imager::write() handling of image types
~~~~~~~~~~~~~^ ^ ^~~~~~~~~~~~~~
sub write {
my $self = shift;
- my %input=(jpegquality=>75, gifquant=>'mc', lmdither=>6.0, lmfixed=>[], @_);
+ my %input=(jpegquality=>75, gifquant=>'mc', lmdither=>6.0, lmfixed=>[],
+ fax_fine=>1, @_);
my ($fh, $rc, $fd, $IO);
my %iolready=( tiff=>1 ); # this will be SO MUCH BETTER once they are all in there
unless ($self->{IMG}) { $self->{ERRSTR}='empty input image'; return undef; }
if (!$input{file} and !$input{'fd'} and !$input{'data'}) { $self->{ERRSTR}='file/fd/data parameter missing'; return undef; }
- if (!$input{type}) { $input{type}=$FORMATGUESS->($input{file}); }
+ if (!$input{type} and $input{file}) { $input{type}=$FORMATGUESS->($input{file}); }
if (!$input{type}) { $self->{ERRSTR}='type parameter missing and not possible to guess from extension'; return undef; }
if (!$formats{$input{type}}) { $self->{ERRSTR}='format not supported'; return undef; }
if ($iolready{$input{type}}) {
- if ($fd) {
+ if (defined $fd) {
$IO = io_new_fd($fd);
}
if ($input{type} eq 'tiff') {
- if ($input{class} eq 'fax') {
- if (!i_writetiff_wiol_faxable($self->{IMG}, $IO)) {
+ if (defined $input{class} && $input{class} eq 'fax') {
+ if (!i_writetiff_wiol_faxable($self->{IMG}, $IO, $input{fax_fine})) {
$self->{ERRSTR}='Could not write to buffer';
return undef;
}
}
}
-
if (exists $input{'data'}) {
my $data = io_slurp($IO);
if (!$data) {
$self->{ERRSTR}='unable to write raw image'; return undef;
}
$self->{DEBUG} && print "writing a raw file\n";
- } elsif ( $input{type} eq 'tiff' ) {
- if ($input{class} eq 'fax') {
- $rc=i_writetiff_wiol($self->{IMG},io_new_fd($fd) );
- }
- else {
- $rc=i_writetiff_wiol_faxable($self->{IMG},io_new_fd($fd) );
- }
- if ( !defined($rc) ) {
- $self->{ERRSTR}='unable to write tiff image'; return undef;
- }
- $self->{DEBUG} && print "writing a tiff file\n";
}
}
parameter, which can currently take a single value, "fax". If class
is set to fax then a tiff image which should be suitable for faxing
will be written. For the best results start with a grayscale image.
+By default the image is written at fine resolution you can override
+this by setting the "fax_fine" parameter to 0.
If you are reading from a gif image file, you can supply a 'colors'
parameter which must be a reference to a scalar. The referenced
Imager::IO ig
undef_int
-i_writetiff_wiol_faxable(im, ig)
+i_writetiff_wiol_faxable(im, ig, fine)
Imager::ImgRaw im
Imager::IO ig
+ int fine
#endif /* HAVE_LIBTIFF */
#ifdef HAVE_LIBTIFF
i_img* i_readtiff_wiol(io_glue *ig, int length);
undef_int i_writetiff_wiol(i_img *im, io_glue *ig);
+undef_int i_writetiff_wiol_faxable(i_img *im, io_glue *ig, int fine);
#endif /* HAVE_LIBTIFF */
-print "1..4\n";
+print "1..13\n";
use Imager qw(:all);
-
+$^W=1; # warnings during command-line tests
+$|=1; # give us some progress in the test harness
init_log("testout/t106tiff.log",1);
$green=i_color_new(0,255,0,255);
print "# tiff average mean square pixel difference: ",sqrt(i_img_diff($img,$cmpimg))/150*150,"\n";
print "ok 2\n";
+ i_img_diff($img, $cmpimg) and print "not ";
+ print "ok 3\n";
+
$IO = Imager::io_new_bufchain();
Imager::i_writetiff_wiol($img, $IO) or die "Cannot write to bufferchain\n";
}
if ($odata eq $tiffdata) {
- print "ok 3\n";
+ print "ok 4\n";
} else {
- print "not ok 3\n";
+ print "not ok 4\n";
}
# test Micksa's tiff writer
or die "Cannot create testout/t106tiff_fax.tiff: $!";
binmode FH;
$IO = Imager::io_new_fd(fileno(FH));
- i_writetiff_wiol_faxable($faximg, $IO)
+ i_writetiff_wiol_faxable($faximg, $IO, 1)
or print "not ";
- print "ok 4\n";
+ print "ok 5\n";
close FH;
+
+ # test the OO interface
+ my $ooim = Imager->new;
+ $ooim->read(file=>'testout/t106.tiff')
+ or print "not ";
+ print "ok 6\n";
+ $ooim->write(file=>'testout/t106_oo.tiff')
+ or print "not ";
+ print "ok 7\n";
+
+ # OO with the fax image
+ my $oofim = Imager->new;
+ $oofim->read(file=>'testout/t106tiff_fax.tiff')
+ or print "not ";
+ print "ok 8\n";
+ $oofim->write(file=>'testout/t106_oo_fax.tiff', class=>'fax')
+ or print "not ";
+ print "ok 9\n";
+
+ # the following should fail since there's no type and no filename
+ my $oodata;
+ $ooim->write(data=>\$oodata)
+ and print "not ";
+ print "ok 10\n";
+
+ # OO to data
+ $ooim->write(data=>\$oodata, type=>'tiff')
+ or print 'not ';
+ print "ok 11\n";
+ $oodata eq $tiffdata or print "not ";
+ print "ok 12\n";
+
+ # make sure we can write non-fine mode
+ $oofim->write(file=>'testout/t106_oo_faxlo.tiff', class=>'fax', fax_fine=>0)
+ or print "not ";
+ print "ok 13\n";
}
*/
undef_int
-i_writetiff_wiol_faxable(i_img *im, io_glue *ig) {
+i_writetiff_wiol_faxable(i_img *im, io_glue *ig, int fine) {
uint32 width, height;
unsigned char *linebuf = NULL;
uint32 y;
TIFF* tif;
int luma_channel;
uint32 rowsperstrip;
+ float vres = fine ? 196 : 98;
width = im->xsize;
height = im->ysize;
mm_log((1, "i_writetiff_wiol_faxable: TIFFGetField scanlinesize=%d\n", TIFFScanlineSize(tif) ));
mm_log((1, "i_writetiff_wiol_faxable: TIFFGetField planarconfig=%d == %d\n", rc, PLANARCONFIG_CONTIG));
- /*
- if (!TIFFSetField(tif, TIFFTAG_XRESOLUTION, 204))
+ if (!TIFFSetField(tif, TIFFTAG_XRESOLUTION, (float)204))
{ mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField Xresolution=204\n")); return 0; }
- if (!TIFFSetField(tif, TIFFTAG_YRESOLUTION, 196))
+ if (!TIFFSetField(tif, TIFFTAG_YRESOLUTION, vres))
{ mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField Yresolution=196\n")); return 0; }
if (!TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH)) {
mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField ResolutionUnit=%d\n", RESUNIT_INCH)); return 0;
}
- */
for (y=0; y<height; y++) {
int linebufpos=0;