2 ? devel/lib/Imager/Regops.pm
4 ===================================================================
5 RCS file: /u02/cvsroot/Imager/devel/Imager.pm,v
6 retrieving revision 1.12
7 diff -u -r1.12 Imager.pm
8 --- devel/Imager.pm 2001/05/05 14:40:23 1.12
9 +++ devel/Imager.pm 2001/05/07 12:58:59
14 + i_writetiff_wiol_faxable
21 my %input=(jpegquality=>75, gifquant=>'mc', lmdither=>6.0, lmfixed=>[], @_);
23 my ($fh, $rc, $fd, $IO);
25 my %iolready=( tiff=>1 ); # this will be SO MUCH BETTER once they are all in there
31 if ($iolready{$input{type}}) {
35 if (!i_writetiff_wiol($self->{IMG}, $IO)) { $self->{ERRSTR}='Could not write to buffer'; return undef; }
38 + if ($input{type} eq 'fax') {
39 + print STDERR "writing a faxable; TIFF\n";
40 + if (!i_writetiff_wiol_faxable($self->{IMG}, $IO)) { $self->{ERRSTR}='Could not write to buffer'; return undef; }
43 my $data = io_slurp($IO);
44 if (!$data) { $self->{ERRSTR}='Could not slurp from buffer'; return undef; }
47 $self->{DEBUG} && print "writing a raw file\n";
48 } elsif ( $input{type} eq 'tiff' ) {
49 $rc=i_writetiff_wiol($self->{IMG},io_new_fd($fd) );
50 + if ( !defined($rc) ) {
51 + $self->{ERRSTR}='unable to write tiff image'; return undef;
53 + $self->{DEBUG} && print "writing a tiff file\n";
54 + } elsif ( $input{type} eq 'fax' ) {
55 + print STDERR "writing a faxable tiff (2)\n";
56 + $rc=i_writetiff_wiol_faxable($self->{IMG},io_new_fd($fd) );
57 if ( !defined($rc) ) {
58 $self->{ERRSTR}='unable to write tiff image'; return undef;
60 Index: devel/Imager.xs
61 ===================================================================
62 RCS file: /u02/cvsroot/Imager/devel/Imager.xs,v
63 retrieving revision 1.9
64 diff -u -r1.9 Imager.xs
65 --- devel/Imager.xs 2001/05/04 07:15:09 1.9
66 +++ devel/Imager.xs 2001/05/07 12:59:02
67 @@ -1023,6 +1023,11 @@
72 +i_writetiff_wiol_faxable(im, ig)
77 #endif /* HAVE_LIBTIFF */
80 ===================================================================
81 RCS file: /u02/cvsroot/Imager/devel/feat.h,v
82 retrieving revision 1.1.1.1
83 diff -u -r1.1.1.1 feat.h
84 --- devel/feat.h 2001/03/25 11:55:00 1.1.1.1
85 +++ devel/feat.h 2001/05/07 12:59:02
95 ===================================================================
96 RCS file: /u02/cvsroot/Imager/devel/tiff.c,v
97 retrieving revision 1.1.1.1
98 diff -u -r1.1.1.1 tiff.c
99 --- devel/tiff.c 2001/03/25 11:55:00 1.1.1.1
100 +++ devel/tiff.c 2001/05/07 12:59:03
101 @@ -344,3 +344,126 @@
106 +i_writetiff_wiol_faxable(i_img *im, io_glue *ig) {
107 + uint32 width, height;
109 + unsigned char *linebuf = NULL;
116 + uint32 rowsperstrip;
119 + height = im->ysize;
121 + switch (im->channels) {
129 + /* This means a colorspace we don't handle yet */
130 + mm_log((1, "i_writetiff_wiol_faxable: don't handle %d channel images.\n", im->channels));
134 + /* Add code to get the filename info from the iolayer */
135 + /* Also add code to check for mmapped code */
137 + io_glue_commit_types(ig);
138 + mm_log((1, "i_writetiff_wiol_faxable(im 0x%p, ig 0x%p)\n", im, ig));
140 + /* FIXME: Enable the mmap interface */
142 + tif = TIFFClientOpen("No name",
145 + (TIFFReadWriteProc) ig->readcb,
146 + (TIFFReadWriteProc) ig->writecb,
147 + (TIFFSeekProc) comp_seek,
148 + (TIFFCloseProc) ig->closecb,
149 + (TIFFSizeProc) ig->sizecb,
150 + (TIFFMapFileProc) NULL,
151 + (TIFFUnmapFileProc) NULL);
154 + mm_log((1, "i_writetiff_wiol_faxable: Unable to open tif file for writing\n"));
158 + mm_log((1, "i_writetiff_wiol_faxable: width=%d, height=%d, channels=%d\n", width, height, im->channels));
160 + if (!TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width) )
161 + { mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField width=%d failed\n", width)); return 0; }
162 + if (!TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height) )
163 + { mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField length=%d failed\n", height)); return 0; }
164 + if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1))
165 + { mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField samplesperpixel=1 failed\n")); return 0; }
166 + if (!TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT))
167 + { mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField Orientation=topleft\n")); return 0; }
168 + if (!TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 1) )
169 + { mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField bitpersample=1\n")); return 0; }
170 + if (!TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG))
171 + { mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField planarconfig\n")); return 0; }
172 + if (!TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK))
173 + { mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField photometric=%d\n", PHOTOMETRIC_MINISBLACK)); return 0; }
174 + if (!TIFFSetField(tif, TIFFTAG_COMPRESSION, 3))
175 + { mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField compression=3\n")); return 0; }
177 + linebuf = (unsigned char *)_TIFFmalloc( TIFFScanlineSize(tif) );
179 + if (!TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tif, -1))) {
180 + mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField rowsperstrip=-1\n")); return 0; }
182 + TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
183 + TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &rc);
185 + mm_log((1, "i_writetiff_wiol_faxable: TIFFGetField rowsperstrip=%d\n", rowsperstrip));
186 + mm_log((1, "i_writetiff_wiol_faxable: TIFFGetField scanlinesize=%d\n", TIFFScanlineSize(tif) ));
187 + mm_log((1, "i_writetiff_wiol_faxable: TIFFGetField planarconfig=%d == %d\n", rc, PLANARCONFIG_CONTIG));
190 + if (!TIFFSetField(tif, TIFFTAG_XRESOLUTION, 204))
191 + { mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField Xresolution=204\n")); return 0; }
192 + if (!TIFFSetField(tif, TIFFTAG_YRESOLUTION, 196))
193 + { mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField Yresolution=196\n")); return 0; }
194 + if (!TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH)) {
195 + mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField ResolutionUnit=%d\n", RESUNIT_INCH)); return 0;
199 + for (y=0; y<height; y++) {
201 + for(x=0; x<width; x+=8) {
204 + uint8 bitval = 128;
205 + linebuf[linebufpos]=0;
206 + bits = width-x; if(bits>8) bits=8;
207 + for(bitpos=0;bitpos<bits;bitpos++) {
209 + luma = im->data[(x+bitpos+y*im->xsize)*im->channels+luma_channel];
210 + linebuf[linebufpos] |= ((luma>=128)?bitval:0);
215 + if (TIFFWriteScanline(tif, linebuf, y, 0) < 0) {
216 + mm_log((1, "i_writetiff_wiol_faxable: TIFFWriteScanline failed.\n"));
220 + (void) TIFFClose(tif);
221 + if (linebuf) _TIFFfree(linebuf);