i_writegif_callback
i_readpnm_wiol
- i_writeppm
+ i_writeppm_wiol
i_readraw
i_writeraw
undef_int
i_writegifmc(im,fd,colors)
- Imager::ImgRaw im
+ Imager::ImgRaw im
int fd
int colors
Imager::ImgRaw im
int fd
+undef_int
+i_writeppm_wiol(im, ig)
+ Imager::ImgRaw im
+ Imager::IO ig
+
+
Imager::ImgRaw
i_readraw(fd,x,y,datachannels,storechannels,intrl)
int fd
i_img *i_readpnm_wiol(io_glue *ig, int length);
undef_int i_writeppm(i_img *im,int fd);
+undef_int i_writeppm_wiol(i_img *im, io_glue *ig);
i_img* i_scaleaxis(i_img *im, float Value, int Axis);
#include "image.h"
#include "io.h"
#include "log.h"
+#include "iolayer.h"
#include <stdlib.h>
#include <errno.h>
}
+undef_int
+i_writeppm_wiol(i_img *im, io_glue *ig) {
+ char header[255];
+ int rc;
+ writep write_func;
+ mm_log((1,"i_writeppm(im %p, ig %p)\n", im, ig));
+ i_clear_error();
+ /* Add code to get the filename info from the iolayer */
+ /* Also add code to check for mmapped code */
+ io_glue_commit_types(ig);
-
+ if (im->channels==3) {
+ sprintf(header,"P6\n#CREATOR: Imager\n%d %d\n255\n",im->xsize,im->ysize);
+
+ if (ig->writecb(ig, header, strlen(header) )<0) {
+ i_push_error(errno, "could not write ppm header");
+ mm_log((1,"i_writeppm: unable to write ppm header.\n"));
+ return(0);
+ }
+
+ rc = ig->writecb(ig, im->data, im->bytes);
+ if (rc<0) {
+ i_push_error(errno, "could not write ppm data");
+ mm_log((1,"i_writeppm: unable to write ppm data.\n"));
+ return(0);
+ }
+ }
+ else if (im->channels == 1) {
+ sprintf(header, "P5\n#CREATOR: Imager\n%d %d\n255\n",
+ im->xsize, im->ysize);
+ if (ig->writecb(ig, header, strlen(header)) < 0) {
+ i_push_error(errno, "could not write pgm header");
+ mm_log((1,"i_writeppm: unable to write pgm header.\n"));
+ return(0);
+ }
+
+ rc = ig->writecb(ig, im->data, im->bytes);
+ if (rc<0) {
+ i_push_error(errno, "could not write pgm data");
+ mm_log((1,"i_writeppm: unable to write pgm data.\n"));
+ return(0);
+ }
+ }
+ else {
+ i_push_error(0, "can only save 1 or 3 channel images to pnm");
+ mm_log((1,"i_writeppm: ppm/pgm is 1 or 3 channel only (current image is %d)\n",im->channels));
+ return(0);
+ }
+
+ return(1);
+}
use Imager ':all';
-print "1..6\n";
+print "1..8\n";
init_log("testout/t104ppm.log",1);
-$green=i_color_new(0,255,0,255);
-$blue=i_color_new(0,0,255,255);
-$red=i_color_new(255,0,0,255);
+my $green = i_color_new(0,255,0,255);
+my $blue = i_color_new(0,0,255,255);
+my $red = i_color_new(255,0,0,255);
-$img=Imager::ImgRaw::new(150,150,3);
-$cmpimg=Imager::ImgRaw::new(150,150,3);
+my $img = Imager::ImgRaw::new(150,150,3);
i_box_filled($img,70,25,130,125,$green);
i_box_filled($img,20,25,80,125,$blue);
i_arc($img,75,75,30,0,361,$red);
i_conv($img,[0.1, 0.2, 0.4, 0.2, 0.1]);
-my $timg = Imager::ImgRaw::new(20, 20, 4);
-my $trans = i_color_new(255, 0, 0, 127);
-i_box_filled($timg, 0, 0, 20, 20, $green);
-i_box_filled($timg, 2, 2, 18, 18, $trans);
-
-open(FH,">testout/t104.ppm") || die "Cannot open testout/t104.ppm\n";
-binmode(FH);
-i_writeppm($img,fileno(FH)) || die "Cannot write testout/t104.ppm\n";
-close(FH);
+my $fh = openimage(">testout/104.ppm");
+$IO = Imager::io_new_fd(fileno($fh));
+i_writeppm_wiol($img, $IO)
+ or die "Cannot write testout/t104.ppm\n";
+close($fh);
print "ok 1\n";
-open(FH,"testout/t104.ppm") || die "Cannot open testout/t104.ppm\n";
-binmode(FH);
+$IO = Imager::io_new_bufchain();
+i_writeppm_wiol($img, $IO)
+ or die "Cannot write to bufchain";
+$data = Imager::io_slurp($IO);
+print "ok 2\n";
-my $IO = Imager::io_new_fd(fileno(FH));
-$cmpimg=i_readpnm_wiol($IO,-1) || die "Cannot read testout/t104.ppm\n";
-close(FH);
+$fh = openimage("testout/t104.ppm");
+$IO = Imager::io_new_fd( fileno($fh) );
+$cmpimg = i_readpnm_wiol($IO,-1) || die "Cannot read testout/t104.ppm\n";
+close($fh);
+print "ok 3\n";
-print "ok 2\n";
+print i_img_diff($img, $cmpimg) ? "not ok 4 # saved image different\n" : "ok 4\n";
+
+my $rdata = slurp("testout/t104.ppm");
+print "not " if $rdata ne $data;
+print "ok 5\n";
-print i_img_diff($img, $cmpimg)
- ? "not ok 3 # saved image different\n" : "ok 3\n";
# build a grayscale image
my $gimg = Imager::ImgRaw::new(150, 150, 1);
i_box_filled($gimg, 20, 20, 130, 130, $gray);
i_box_filled($gimg, 40, 40, 110, 110, $dgray);
i_arc($gimg, 75, 75, 30, 0, 361, $white);
-open FH, "> testout/t104_gray.pgm"
- or die "Cannot create testout/t104_gray.pgm: $!\n";
+
+open FH, "> testout/t104_gray.pgm" or die "Cannot create testout/t104_gray.pgm: $!\n";
binmode FH;
-i_writeppm($gimg, fileno(FH))
- or print "not ";
-print "ok 4\n";
+my $IO = Imager::io_new_fd(fileno(FH));
+i_writeppm_wiol($gimg, $IO) or print "not ";
+print "ok 6\n";
close FH;
-open FH, "< testout/t104_gray.pgm"
- or die "Cannot open testout/t104_gray.pgm: $!\n";
+
+open FH, "< testout/t104_gray.pgm" or die "Cannot open testout/t104_gray.pgm: $!\n";
binmode FH;
$IO = Imager::io_new_fd(fileno(FH));
-my $gcmpimg = i_readpnm_wiol($IO, -1)
- or print "not ";
-print "ok 5\n";
+my $gcmpimg = i_readpnm_wiol($IO, -1) or print "not ";
+print "ok 7\n";
i_img_diff($gimg, $gcmpimg) == 0 or print "not ";
-print "ok 6\n";
+print "ok 8\n";
+
+sub openimage {
+ my $fname = shift;
+ local(*FH);
+ open(FH, $fname) or die "Cannot open $fname: $!\n";
+ binmode(FH);
+ return *FH;
+}
+sub slurp {
+ my $fh = openimage(shift);
+ local $/;
+ my $data = <$fh>;
+ close($fh);
+ return $data;
+}
$palette=''; # just to skip a warning.
print "ok 3\n";
-
+
# check that reading interlaced/non-interlaced versions of
# the same GIF produce the same image
# I could replace this with code that used Imager's built-in
open FH, ">testout/t105i.ppm" or die "Cannot create testout/t105i.ppm";
binmode FH;
- i_writeppm($imgi, fileno(FH)) or die "Cannot write testout/t105i.ppm";
+ $IO = Imager::io_new_fd( fileno(FH) );
+ i_writeppm_wiol($imgi, $IO) or die "Cannot write testout/t105i.ppm";
close FH;
+
open FH, ">testout/t105ni.ppm" or die "Cannot create testout/t105ni.ppm";
binmode FH;
- i_writeppm($imgni, fileno(FH)) or die "Cannot write testout/t105ni.ppm";
+ $IO = Imager::io_new_fd( fileno(FH) );
+ i_writeppm_wiol($imgni, $IO) or die "Cannot write testout/t105ni.ppm";
close FH;
# compare them
open FH, "<testout/t105i.ppm" or die "Cannot open testout/t105i.ppm";
$datai = do { local $/; <FH> };
close FH;
+
open FH, "<testout/t105ni.ppm" or die "Cannot open testout/t105ni.ppm";
$datani = do { local $/; <FH> };
close FH;
my $img2 = i_readgif_callback(sub { my $tmp; read(FH, $tmp, $_[0]) and $tmp });
close FH;
print $img ? "ok 7\n" : "not ok 7\n";
-
+
print test_readgif_cb(1) ? "ok 8\n" : "not ok 8\n";
print test_readgif_cb(512) ? "ok 9\n" : "not ok 9\n";
print test_readgif_cb(1024) ? "ok 10\n" : "not ok 10\n";
} else {
print "# has t1\n";
-
+
$fontname_pfb=$ENV{'T1FONTTESTPFB'}||'./fontfiles/dcr10.pfb';
$fontname_afm=$ENV{'T1FONTTESTAFM'}||'./fontfiles/dcr10.afm';
i_init_fonts();
i_t1_set_aa(1);
-
+
$fnum=Imager::i_t1_new($fontname_pfb,$fontname_afm); # this will load the pfb font
if ($fnum<0) { die "Couldn't load font $fontname_pfb"; }
-
+
$bgcolor=Imager::Color->new(255,0,0,0);
$overlay=Imager::ImgRaw::new(200,70,3);
-
+
i_t1_cp($overlay,5,50,1,$fnum,50.0,'XMCLH',5,1);
i_draw($overlay,0,50,100,50,$bgcolor);
-
+
@bbox=i_t1_bbox(0,50.0,'XMCLH',5);
print "bbox: ($bbox[0], $bbox[1]) - ($bbox[2], $bbox[3])\n";
-
+
open(FH,">testout/t30t1font.ppm") || die "cannot open testout/t35t1font.ppm\n";
binmode(FH); # for os2
- i_writeppm($overlay,fileno(FH));
+ $IO = Imager::io_new_fd( fileno(FH) );
+ i_writeppm_wiol($overlay,$IO);
close(FH);
print "ok 2\n";
-
+
$bgcolor=Imager::Color::set($bgcolor,200,200,200,0);
$backgr=Imager::ImgRaw::new(280,150,3);
i_t1_set_aa(2);
i_t1_text($backgr,10,100,$bgcolor,$fnum,150.0,'test',4,1);
-
+
open(FH,">testout/t30t1font2.ppm") || die "cannot open testout/t35t1font.ppm\n";
binmode(FH);
- i_writeppm($backgr,fileno(FH));
+ $IO = Imager::io_new_fd( fileno(FH) );
+ i_writeppm_wiol($backgr, $IO);
close(FH);
-
+
print "ok 3\n";
-
+
$rc=i_t1_destroy($fnum);
if ($fnum <0) { die "i_t1_destroy failed: rc=$rc\n"; }
open(FH,">testout/t35ttfont.ppm") || die "cannot open testout/t35ttfont.ppm\n";
binmode(FH);
-i_writeppm($overlay,fileno(FH));
+$IO = Imager::io_new_fd( fileno(FH) );
+i_writeppm_wiol($overlay, $IO);
close(FH);
print "ok 2\n";
open(FH,">testout/t35ttfont2.ppm") || die "cannot open testout/t35ttfont.ppm\n";
binmode(FH);
-i_writeppm($backgr,fileno(FH));
+$IO = Imager::io_new_fd( fileno(FH) );
+i_writeppm_wiol($backgr, $IO);
close(FH);
print "ok 3\n";
print "ok 2\n";
open(FH,">testout/t75.ppm") || die "Cannot open testout/t75.ppm\n";
-i_writeppm($img->{IMG},fileno(FH)) || die "Cannot write testout/t75.ppm\n";
+binmode(FH);
+$IO = Imager::io_new_fd( fileno(FH) );
+i_writeppm_wiol($img->{IMG}, $IO) || die "Cannot write testout/t75.ppm\n";
close(FH);
print "ok 3\n";