+i_img**
+i_readtiff_multi_wiol(io_glue *ig, int length, int *count) {
+ TIFF* tif;
+ TIFFErrorHandler old_handler;
+ TIFFErrorHandler old_warn_handler;
+ i_img **results = NULL;
+ int result_alloc = 0;
+ int dirnum = 0;
+
+ i_clear_error();
+ old_handler = TIFFSetErrorHandler(error_handler);
+ old_warn_handler = TIFFSetWarningHandler(warn_handler);
+
+ /* Add code to get the filename info from the iolayer */
+ /* Also add code to check for mmapped code */
+
+ io_glue_commit_types(ig);
+ mm_log((1, "i_readtiff_wiol(ig %p, length %d)\n", ig, length));
+
+ tif = TIFFClientOpen("(Iolayer)",
+ "rm",
+ (thandle_t) ig,
+ (TIFFReadWriteProc) ig->readcb,
+ (TIFFReadWriteProc) ig->writecb,
+ (TIFFSeekProc) comp_seek,
+ (TIFFCloseProc) ig->closecb,
+ ig->sizecb ? (TIFFSizeProc) ig->sizecb : (TIFFSizeProc) sizeproc,
+ (TIFFMapFileProc) comp_mmap,
+ (TIFFUnmapFileProc) comp_munmap);
+
+ if (!tif) {
+ mm_log((1, "i_readtiff_wiol: Unable to open tif file\n"));
+ i_push_error(0, "opening file");
+ TIFFSetErrorHandler(old_handler);
+ TIFFSetWarningHandler(old_warn_handler);
+ return NULL;
+ }
+
+ *count = 0;
+ do {
+ i_img *im = read_one_tiff(tif);
+ if (!im)
+ break;
+ if (++*count > result_alloc) {
+ if (result_alloc == 0) {
+ result_alloc = 5;
+ results = mymalloc(result_alloc * sizeof(i_img *));
+ }
+ else {
+ i_img **newresults;
+ result_alloc *= 2;
+ newresults = myrealloc(results, result_alloc * sizeof(i_img *));
+ if (!newresults) {
+ i_img_destroy(im); /* don't leak it */
+ break;
+ }
+ results = newresults;
+ }
+ }
+ results[*count-1] = im;
+ } while (TIFFSetDirectory(tif, ++dirnum));
+
+ TIFFSetWarningHandler(old_warn_handler);
+ TIFFSetErrorHandler(old_handler);
+ TIFFClose(tif);
+ return results;
+}
+
+undef_int
+i_writetiff_low_faxable(TIFF *tif, i_img *im, int fine) {
+ uint32 width, height;
+ unsigned char *linebuf = NULL;
+ uint32 y;
+ int rc;
+ uint32 x;
+ int luma_mask;
+ uint32 rowsperstrip;
+ float vres = fine ? 196 : 98;
+ int luma_chan;
+
+ width = im->xsize;
+ height = im->ysize;
+
+ switch (im->channels) {
+ case 1:
+ case 2:
+ luma_chan = 0;
+ break;
+ case 3:
+ case 4:
+ luma_chan = 1;
+ break;
+ default:
+ /* This means a colorspace we don't handle yet */
+ mm_log((1, "i_writetiff_wiol_faxable: don't handle %d channel images.\n", im->channels));
+ return 0;
+ }
+
+ /* Add code to get the filename info from the iolayer */
+ /* Also add code to check for mmapped code */
+
+
+ mm_log((1, "i_writetiff_wiol_faxable: width=%d, height=%d, channels=%d\n", width, height, im->channels));
+
+ if (!TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width) )
+ { mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField width=%d failed\n", width)); return 0; }
+ if (!TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height) )
+ { mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField length=%d failed\n", height)); return 0; }
+ if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1))
+ { mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField samplesperpixel=1 failed\n")); return 0; }
+ if (!TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT))
+ { mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField Orientation=topleft\n")); return 0; }
+ if (!TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 1) )
+ { mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField bitpersample=1\n")); return 0; }
+ if (!TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG))
+ { mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField planarconfig\n")); return 0; }
+ if (!TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK))
+ { mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField photometric=%d\n", PHOTOMETRIC_MINISBLACK)); return 0; }
+ if (!TIFFSetField(tif, TIFFTAG_COMPRESSION, 3))
+ { mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField compression=3\n")); return 0; }
+
+ linebuf = (unsigned char *)_TIFFmalloc( TIFFScanlineSize(tif) );
+
+ if (!TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tif, -1))) {
+ mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField rowsperstrip=-1\n")); return 0; }
+
+ TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
+ TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &rc);
+
+ mm_log((1, "i_writetiff_wiol_faxable: TIFFGetField rowsperstrip=%d\n", rowsperstrip));
+ 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, (float)204))
+ { mm_log((1, "i_writetiff_wiol_faxable: TIFFSetField Xresolution=204\n")); return 0; }
+ 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;
+ }
+
+ if (!save_tiff_tags(tif, im)) {
+ return 0;
+ }