i_readpnm_wiol
i_writeppm_wiol
- i_readraw
- i_writeraw
+ i_readraw_wiol
+ i_writeraw_wiol
i_contrast
i_hardinvert
undef($self->{IMG});
}
- if (!$input{fd} and !$input{file} and !$input{data}) { $self->{ERRSTR}='no file, fd or data parameter'; return undef; }
+ if (!$input{fd} and !$input{file} and !$input{data}) {
+ $self->{ERRSTR}='no file, fd or data parameter'; return undef;
+ }
if ($input{file}) {
$fh = new IO::File($input{file},"r");
- if (!defined $fh) { $self->{ERRSTR}='Could not open file'; return undef; }
+ if (!defined $fh) {
+ $self->{ERRSTR}='Could not open file'; return undef;
+ }
binmode($fh);
$fd = $fh->fileno();
}
- if ($input{fd}) { $fd=$input{fd} };
+ if ($input{fd}) {
+ $fd=$input{fd};
+ }
# FIXME: Find the format here if not specified
# yes the code isn't here yet - next week maybe?
- if (!$input{type} and $input{file}) { $input{type}=$FORMATGUESS->($input{file}); }
- if (!$formats{$input{type}}) { $self->{ERRSTR}='format not supported'; return undef; }
+ if (!$input{type} and $input{file}) {
+ $input{type}=$FORMATGUESS->($input{file});
+ }
+ if (!$formats{$input{type}}) {
+ $self->{ERRSTR}='format not supported'; return undef;
+ }
- my %iolready=(jpeg=>1, tiff=>1, pnm=>1);
+ my %iolready=(jpeg=>1, tiff=>1, pnm=>1, raw=>1);
if ($iolready{$input{type}}) {
# Setup data source
- $IO = io_new_fd($fd); # sort of simple for now eh?
+ $IO = io_new_fd($fd); # sort of simple for now eh?
if ( $input{type} eq 'jpeg' ) {
($self->{IMG},$self->{IPTCRAW})=i_readjpeg_wiol( $IO );
- if ( !defined($self->{IMG}) ) { $self->{ERRSTR}='unable to read jpeg image'; return undef; }
+ if ( !defined($self->{IMG}) ) {
+ $self->{ERRSTR}='unable to read jpeg image'; return undef;
+ }
$self->{DEBUG} && print "loading a jpeg file\n";
return $self;
}
if ( $input{type} eq 'tiff' ) {
$self->{IMG}=i_readtiff_wiol( $IO, -1 ); # Fixme, check if that length parameter is ever needed
- if ( !defined($self->{IMG}) ) { $self->{ERRSTR}='unable to read tiff image'; return undef; }
+ if ( !defined($self->{IMG}) ) {
+ $self->{ERRSTR}='unable to read tiff image'; return undef;
+ }
$self->{DEBUG} && print "loading a tiff file\n";
return $self;
}
if ( $input{type} eq 'pnm' ) {
$self->{IMG}=i_readpnm_wiol( $IO, -1 ); # Fixme, check if that length parameter is ever needed
- if ( !defined($self->{IMG}) ) { $self->{ERRSTR}='unable to read pnm image: '._error_as_msg(); return undef; }
+ if ( !defined($self->{IMG}) ) {
+ $self->{ERRSTR}='unable to read pnm image: '._error_as_msg(); return undef;
+ }
$self->{DEBUG} && print "loading a pnm file\n";
return $self;
}
- } else {
+ if ( $input{type} eq 'raw' ) {
+ my %params=(datachannels=>3,storechannels=>3,interleave=>1,%input);
- # Old code for reference while changing the new stuff
+ if ( !($params{xsize} && $params{ysize}) ) {
+ $self->{ERRSTR}='missing xsize or ysize parameter for raw';
+ return undef;
+ }
+
+ $self->{IMG} = i_readraw_wiol( $IO,
+ $params{xsize},
+ $params{ysize},
+ $params{datachannels},
+ $params{storechannels},
+ $params{interleave});
+ if ( !defined($self->{IMG}) ) {
+ $self->{ERRSTR}='unable to read raw image';
+ return undef;
+ }
+ $self->{DEBUG} && print "loading a raw file\n";
+ }
+ } else {
+ # Old code for reference while changing the new stuff
- 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 (!$input{type} and $input{file}) {
+ $input{type}=$FORMATGUESS->($input{file});
+ }
- if ($input{file}) {
- $fh = new IO::File($input{file},"r");
- if (!defined $fh) { $self->{ERRSTR}='Could not open file'; return undef; }
- binmode($fh);
- $fd = $fh->fileno();
- }
- if ($input{fd}) { $fd=$input{fd} };
+ if (!$input{type}) {
+ $self->{ERRSTR}='type parameter missing and not possible to guess from extension'; return undef;
+ }
- if ( $input{type} eq 'gif' ) {
- my $colors;
- if ($input{colors} && !ref($input{colors})) {
- # must be a reference to a scalar that accepts the colour map
- $self->{ERRSTR} = "option 'colors' must be a scalar reference";
+ if (!$formats{$input{type}}) {
+ $self->{ERRSTR}='format not supported';
return undef;
}
- if (exists $input{data}) {
- if ($input{colors}) {
- ($self->{IMG}, $colors) = i_readgif_scalar($input{data});
- }
- else {
- $self->{IMG}=i_readgif_scalar($input{data});
+
+ if ($input{file}) {
+ $fh = new IO::File($input{file},"r");
+ if (!defined $fh) {
+ $self->{ERRSTR}='Could not open file';
+ return undef;
}
+ binmode($fh);
+ $fd = $fh->fileno();
+ }
+
+ if ($input{fd}) {
+ $fd=$input{fd};
}
- else {
- if ($input{colors}) {
- ($self->{IMG}, $colors) = i_readgif( $fd );
+
+ if ( $input{type} eq 'gif' ) {
+ my $colors;
+ if ($input{colors} && !ref($input{colors})) {
+ # must be a reference to a scalar that accepts the colour map
+ $self->{ERRSTR} = "option 'colors' must be a scalar reference";
+ return undef;
}
- else {
- $self->{IMG} = i_readgif( $fd )
+ if (exists $input{data}) {
+ if ($input{colors}) {
+ ($self->{IMG}, $colors) = i_readgif_scalar($input{data});
+ } else {
+ $self->{IMG}=i_readgif_scalar($input{data});
+ }
+ } else {
+ if ($input{colors}) {
+ ($self->{IMG}, $colors) = i_readgif( $fd );
+ } else {
+ $self->{IMG} = i_readgif( $fd )
+ }
}
+ if ($colors) {
+ # we may or may not change i_readgif to return blessed objects...
+ ${ $input{colors} } = [ map { NC(@$_) } @$colors ];
+ }
+ if ( !defined($self->{IMG}) ) {
+ $self->{ERRSTR}= 'reading GIF:'._error_as_msg();
+ return undef;
+ }
+ $self->{DEBUG} && print "loading a gif file\n";
+
+
+ } elsif ( $input{type} eq 'jpeg' ) {
+ if (exists $input{data}) {
+ ($self->{IMG},$self->{IPTCRAW})=i_readjpeg_scalar($input{data});
+ } else {
+ ($self->{IMG},$self->{IPTCRAW})=i_readjpeg( $fd );
+ }
+ if ( !defined($self->{IMG}) ) {
+ $self->{ERRSTR}='unable to read jpeg image';
+ return undef;
+ }
+ $self->{DEBUG} && print "loading a jpeg file\n";
+ } elsif ( $input{type} eq 'png' ) {
+ if (exists $input{data}) {
+ $self->{IMG}=i_readpng_scalar($input{data});
+ } else {
+ $self->{IMG}=i_readpng( $fd );
+ }
+ if ( !defined($self->{IMG}) ) {
+ $self->{ERRSTR}='unable to read png image';
+ return undef;
+ }
+ $self->{DEBUG} && print "loading a png file\n";
}
- if ($colors) {
- # we may or may not change i_readgif to return blessed objects...
- ${$input{colors}} = [ map { NC(@$_) } @$colors ];
- }
- if ( !defined($self->{IMG}) ) {
- $self->{ERRSTR}= 'reading GIF:'._error_as_msg(); return undef;
- }
- $self->{DEBUG} && print "loading a gif file\n";
- } elsif ( $input{type} eq 'jpeg' ) {
- if (exists $input{data}) { ($self->{IMG},$self->{IPTCRAW})=i_readjpeg_scalar($input{data}); }
- else { ($self->{IMG},$self->{IPTCRAW})=i_readjpeg( $fd ); }
- if ( !defined($self->{IMG}) ) { $self->{ERRSTR}='unable to read jpeg image'; return undef; }
- $self->{DEBUG} && print "loading a jpeg file\n";
- } elsif ( $input{type} eq 'png' ) {
- if (exists $input{data}) { $self->{IMG}=i_readpng_scalar($input{data}); }
- else { $self->{IMG}=i_readpng( $fd ); }
- if ( !defined($self->{IMG}) ) { $self->{ERRSTR}='unable to read png image'; return undef; }
- $self->{DEBUG} && print "loading a png file\n";
- } elsif ( $input{type} eq 'raw' ) {
- my %params=(datachannels=>3,storechannels=>3,interleave=>1);
- for(keys(%input)) { $params{$_}=$input{$_}; }
-
- if ( !($params{xsize} && $params{ysize}) ) { $self->{ERRSTR}='missing xsize or ysize parameter for raw'; return undef; }
- $self->{IMG}=i_readraw( $fd, $params{xsize}, $params{ysize},
- $params{datachannels}, $params{storechannels}, $params{interleave});
- if ( !defined($self->{IMG}) ) { $self->{ERRSTR}='unable to read raw image'; return undef; }
- $self->{DEBUG} && print "loading a raw file\n";
}
return $self;
- }
}
colour_table = NULL;
colours = 0;
- if(GIMME_V == G_ARRAY) {
+ if(GIMME_V == G_ARRAY) {
rimg = i_readgif(fd,&colour_table,&colours);
} else {
/* don't waste time with colours if they aren't wanted */
rimg = i_readgif(fd,NULL,NULL);
}
-
+
if (colour_table == NULL) {
EXTEND(SP,1);
r=sv_newmortal();
av_store(ct, q, (SV*)newRV_noinc((SV*)av_make(3, temp)));
}
myfree(colour_table);
-
+
EXTEND(SP,2);
- r=sv_newmortal();
+ r = sv_newmortal();
sv_setref_pv(r, "Imager::ImgRaw", (void*)rimg);
PUSHs(r);
PUSHs(newRV_noinc((SV*)ct));
Imager::ImgRaw
-i_readraw(fd,x,y,datachannels,storechannels,intrl)
- int fd
+i_readraw_wiol(ig,x,y,datachannels,storechannels,intrl)
+ Imager::IO ig
int x
int y
int datachannels
int intrl
undef_int
-i_writeraw(im,fd)
+i_writeraw_wiol(im,ig)
Imager::ImgRaw im
- int fd
+ Imager::IO ig
+
Imager::ImgRaw
quant.c # comments, lots of changing code
-
+=====================
+
+Iolayer todo list:
+Format Read/Write
+Gif: O O
+png: O O
+raw: O O
+jpeg: X O
+tiff: X X
+pnm: X X
non-NULL, but we check that to see if we need to free an allocated
colour table on error.
*/
- if (colour_table)
- *colour_table = NULL;
+ if (colour_table) *colour_table = NULL;
BackGround = GifFile->SBackGroundColor;
ColorMap = (GifFile->Image.ColorMap ? GifFile->Image.ColorMap : GifFile->SColorMap);
}
- im = i_img_empty_ch(NULL,GifFile->SWidth,GifFile->SHeight,3);
+ im = i_img_empty_ch(NULL, GifFile->SWidth, GifFile->SHeight, 3);
Size = GifFile->SWidth * sizeof(GifPixelType);
Width = GifFile->Image.Width;
Height = GifFile->Image.Height;
ImageNum++;
- mm_log((1,"i_readgif: Image %d at (%d, %d) [%dx%d]: \n",ImageNum, Col, Row, Width, Height));
+ mm_log((1,"i_readgif_low: Image %d at (%d, %d) [%dx%d]: \n",ImageNum, Col, Row, Width, Height));
if (GifFile->Image.Left + GifFile->Image.Width > GifFile->SWidth ||
GifFile->Image.Top + GifFile->Image.Height > GifFile->SHeight) {
#endif /* HAVE_LIBGIF */
-i_img *i_readraw(int fd,int x,int y,int datachannels,int storechannels,int intrl);
-undef_int i_writeraw(i_img* im,int fd);
+i_img *i_readraw_wiol(io_glue *ig, int x, int y, int datachannels, int storechannels, int intrl);
+undef_int i_writeraw_wiol(i_img* im, io_glue *ig);
i_img *i_readpnm_wiol(io_glue *ig, int length);
undef_int i_writeppm(i_img *im,int fd);
#include "image.h"
#include <stdio.h>
+#include "iolayer.h"
#ifndef _MSC_VER
#include <unistd.h>
#endif
#include <string.h>
+
#define TRUE 1
#define FALSE 0
}
i_img *
-i_readraw(int fd,int x,int y,int datachannels,int storechannels,int intrl) {
+i_readraw_wiol(io_glue *ig, int x, int y, int datachannels, int storechannels, int intrl) {
i_img* im;
int rc,k;
int inbuflen,ilbuflen,exbuflen;
- mm_log((1,"readraw(fd %d,x %d,y %d,datachannels %d,storechannels %d,intrl %d)\n",fd,x,y,datachannels,storechannels,intrl));
+ io_glue_commit_types(ig);
+ mm_log((1, "i_readraw(ig %p,x %d,y %d,datachannels %d,storechannels %d,intrl %d)\n",
+ ig, x, y, datachannels, storechannels, intrl));
- im=i_img_empty_ch(NULL,x,y,storechannels);
+ im = i_img_empty_ch(NULL,x,y,storechannels);
- inbuflen=im->xsize*datachannels;
- ilbuflen=inbuflen;
- exbuflen=im->xsize*storechannels;
- inbuffer=(unsigned char*)mymalloc(inbuflen);
+ inbuflen = im->xsize*datachannels;
+ ilbuflen = inbuflen;
+ exbuflen = im->xsize*storechannels;
+ inbuffer = (unsigned char*)mymalloc(inbuflen);
mm_log((1,"inbuflen: %d, ilbuflen: %d, exbuflen: %d.\n",inbuflen,ilbuflen,exbuflen));
if (intrl==0) ilbuffer=inbuffer; else ilbuffer=(unsigned char*)mymalloc(inbuflen);
k=0;
while(k<im->ysize) {
- rc=myread(fd,inbuffer,inbuflen);
+ rc = ig->readcb(ig, inbuffer, inbuflen);
if (rc!=inbuflen) { fprintf(stderr,"Premature end of file.\n"); exit(2); }
interleave(inbuffer,ilbuffer,im->xsize,datachannels);
expandchannels(ilbuffer,exbuffer,im->xsize,datachannels,storechannels);
undef_int
-i_writeraw(i_img* im,int fd) {
+i_writeraw_wiol(i_img* im, io_glue *ig) {
int rc;
- mm_log((1,"writeraw(im 0x%x,fd %d)\n",im,fd));
+ io_glue_commit_types(ig);
+ mm_log((1,"writeraw(im %p,ig %p)\n", im, ig));
if (im == NULL) { mm_log((1,"Image is empty\n")); return(0); }
- rc=mywrite(fd,im->data,im->bytes);
- if (rc!=im->bytes) { mm_log((1,"i_writeraw: Couldn't write to file\n")); return(0); }
+ rc = ig->writecb(ig, im->data, im->bytes);
+ if (rc != im->bytes) {
+ mm_log((1,"i_writeraw: Couldn't write to file\n"));
+ return(0);
+ }
return(1);
}
open(FH,">testout/t103.raw") || die "Cannot open testout/t103.raw for writing\n";
binmode(FH);
-i_writeraw($img,fileno(FH)) || die "Cannot write testout/t103.raw\n";
+$IO = Imager::io_new_fd( fileno(FH) );
+i_writeraw_wiol($img, $IO) || die "Cannot write testout/t103.raw\n";
close(FH);
print "ok 1\n";
open(FH,"testout/t103.raw") || die "Cannot open testout/t103.raw\n";
binmode(FH);
-$cmpimg=i_readraw(fileno(FH),150,150,3,3,0) || die "Cannot read testout/t103.raw\n";
+$IO = Imager::io_new_fd( fileno(FH) );
+$cmpimg = i_readraw_wiol($IO, 150, 150, 3, 3, 0) || die "Cannot read testout/t103.raw\n";
close(FH);
print "# raw average mean square pixel difference: ",sqrt(i_img_diff($img,$cmpimg))/150*150,"\n";
open FH, "testout/t103_base.raw"
or die "Cannot open testout/t103_base.raw: $!";
binmode FH;
-my $baseimg = i_readraw(fileno(FH), 4, 4, 3, 3, 0)
+$IO = Imager::io_new_fd( fileno(FH) );
+
+my $baseimg = i_readraw_wiol( $IO, 4, 4, 3, 3, 0)
or die "Cannot read base raw image";
close FH;
my ($in, $xsize, $ysize, $data, $store, $intrl, $base, $test) = @_;
open FH, $in or die "Cannot open $in: $!";
binmode FH;
- my $img = i_readraw(fileno(FH), $xsize, $ysize, $data, $store, $intrl);
+ my $IO = Imager::io_new_fd( fileno(FH) );
+
+ my $img = i_readraw_wiol($IO, $xsize, $ysize, $data, $store, $intrl);
if ($img) {
print "ok $test\n";
if (i_img_diff($img, $baseimg)) {
$img->read( %opts ) or die "failed: ",$img->errstr,"\n";
}
-$img2=$img->crop(width=>50, height=>50);
-$img2->write(file=> 'testout/t50.ppm', type=>'pnm');
+$img2 = $img->crop(width=>50, height=>50);
+$img2 -> write(file=> 'testout/t50.ppm', type=>'pnm');
undef($img);
/* Also add code to check for mmapped code */
io_glue_commit_types(ig);
- mm_log((1, "i_readtiff_wiol(ig 0x%p, length %d)\n", ig, length));
+ mm_log((1, "i_readtiff_wiol(ig %p, length %d)\n", ig, length));
tif = TIFFClientOpen("Iolayer: FIXME",
"rm",