int TIFFSetupStrips(TIFF* tif) { TIFFDirectory* td = &tif->tif_dir; if (isTiled(tif)) td->td_stripsperimage = isUnspecified(tif, FIELD_TILEDIMENSIONS) ? td->td_samplesperpixel : TIFFNumberOfTiles(tif); else td->td_stripsperimage = isUnspecified(tif, FIELD_ROWSPERSTRIP) ? td->td_samplesperpixel : TIFFNumberOfStrips(tif); td->td_nstrips = td->td_stripsperimage; if (td->td_planarconfig == PLANARCONFIG_SEPARATE) td->td_stripsperimage /= td->td_samplesperpixel; td->td_stripoffset = (uint64 *) _TIFFmalloc(td->td_nstrips * sizeof (uint64)); td->td_stripbytecount = (uint64 *) _TIFFmalloc(td->td_nstrips * sizeof (uint64)); if (td->td_stripoffset == NULL || td->td_stripbytecount == NULL) return (0); /* * Place data at the end-of-file * (by setting offsets to zero). */ _TIFFmemset(td->td_stripoffset, 0, td->td_nstrips*sizeof (uint64)); _TIFFmemset(td->td_stripbytecount, 0, td->td_nstrips*sizeof (uint64)); TIFFSetFieldBit(tif, FIELD_STRIPOFFSETS); TIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS); return (1); }
static int cpTiles(TIFF* in, TIFF* out) { tsize_t bufsize = TIFFTileSize(in); unsigned char *buf = (unsigned char *)_TIFFmalloc(bufsize); if (buf) { ttile_t t, nt = TIFFNumberOfTiles(in); uint32 *bytecounts; if (!TIFFGetField(in, TIFFTAG_TILEBYTECOUNTS, &bytecounts)) { fprintf(stderr, "tiffsplit: tile byte counts are missing\n"); return (0); } for (t = 0; t < nt; t++) { if (bytecounts[t] > (uint32) bufsize) { buf = (unsigned char *)_TIFFrealloc(buf, bytecounts[t]); if (!buf) return (0); bufsize = bytecounts[t]; } if (TIFFReadRawTile(in, t, buf, bytecounts[t]) < 0 || TIFFWriteRawTile(out, t, buf, bytecounts[t]) < 0) { _TIFFfree(buf); return (0); } } _TIFFfree(buf); return (1); } return (0); }
static int TIFFSetupStrips(TIFF* tif) { #define isUnspecified(td, v) \ (td->v == (uint32) -1 || (td)->td_imagelength == 0) register TIFFDirectory *td = &tif->tif_dir; if (!isTiled(tif)) td->td_stripsperimage = isUnspecified(td, td_rowsperstrip) ? 1 : howmany(td->td_imagelength, td->td_rowsperstrip); else td->td_stripsperimage = isUnspecified(td, td_tilelength) ? 1 : TIFFNumberOfTiles(tif); td->td_nstrips = td->td_stripsperimage; if (td->td_planarconfig == PLANARCONFIG_SEPARATE) td->td_nstrips *= td->td_samplesperpixel; td->td_stripoffset = (uint32 *) _TIFFmalloc(td->td_nstrips * sizeof (uint32)); td->td_stripbytecount = (uint32 *) _TIFFmalloc(td->td_nstrips * sizeof (uint32)); if (td->td_stripoffset == NULL || td->td_stripbytecount == NULL) return (0); /* * Place data at the end-of-file * (by setting offsets to zero). */ _TIFFmemset(td->td_stripoffset, 0, td->td_nstrips*sizeof (uint32)); _TIFFmemset(td->td_stripbytecount, 0, td->td_nstrips*sizeof (uint32)); TIFFSetFieldBit(tif, FIELD_STRIPOFFSETS); TIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS); return (1); #undef isUnspecified }
static int cpTiles(TIFF* in, TIFF* out) { tsize_t bufsize = TIFFTileSize(in); unsigned char *buf = (unsigned char *)_TIFFmalloc(bufsize); if (buf) { ttile_t t, nt = TIFFNumberOfTiles(in); tsize_t *bytecounts; TIFFGetField(in, TIFFTAG_TILEBYTECOUNTS, &bytecounts); for (t = 0; t < nt; t++) { if (bytecounts[t] > bufsize) { buf = (unsigned char *)_TIFFrealloc(buf, bytecounts[t]); if (!buf) goto bad; bufsize = bytecounts[t]; } if (TIFFReadRawTile(in, t, buf, bytecounts[t]) < 0 || TIFFWriteRawTile(out, t, buf, bytecounts[t]) < 0) { _TIFFfree(buf); return 0; } } _TIFFfree(buf); return 1; } bad: TIFFError(TIFFFileName(in), "Can't allocate space for tile buffer."); return (0); }
static int cpTiles(TIFF* in, TIFF* out) { tmsize_t bufsize = TIFFTileSize(in); unsigned char *buf = (unsigned char *)_TIFFmalloc(bufsize); if (buf) { ttile_t t, nt = TIFFNumberOfTiles(in); uint64 *bytecounts; TIFFGetField(in, TIFFTAG_TILEBYTECOUNTS, &bytecounts); for (t = 0; t < nt; t++) { if (bytecounts[t] > (uint64) bufsize) { buf = (unsigned char *)_TIFFrealloc(buf, (tmsize_t)bytecounts[t]); if (!buf) return (0); bufsize = (tmsize_t)bytecounts[t]; } if (TIFFReadRawTile(in, t, buf, (tmsize_t)bytecounts[t]) < 0 || TIFFWriteRawTile(out, t, buf, (tmsize_t)bytecounts[t]) < 0) { _TIFFfree(buf); return (0); } } _TIFFfree(buf); return (1); } return (0); }
static void get_tiff_info(struct tiff_info *t, TIFF *tif) { TIFFGetFieldDefaulted(tif, TIFFTAG_IMAGEWIDTH, &t->w); TIFFGetFieldDefaulted(tif, TIFFTAG_IMAGELENGTH, &t->h); TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &t->spp); TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &t->bps); TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLEFORMAT, &t->fmt); uint16_t planarity, compression; TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planarity); TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &compression); t->broken = planarity != PLANARCONFIG_CONTIG; t->compressed = compression != COMPRESSION_NONE; t->packed = 0 != t->bps % 8; t->tiled = TIFFIsTiled(tif); if (t->tiled) { TIFFGetField(tif, TIFFTAG_TILEWIDTH, &t->tw); TIFFGetField(tif, TIFFTAG_TILELENGTH, &t->th); t->ta = how_many(t->w, t->tw); t->td = how_many(t->h, t->th); t->ntiles = TIFFNumberOfTiles(tif); assert(t->ta * t->td == t->ntiles); } else { t->ta = t->td = 1; t->tw = t->w; t->th = t->h; t->ntiles = 1; } }
static int TileBasedXform(cmsHTRANSFORM hXForm, TIFF* in, TIFF* out, int nPlanes) { tsize_t BufSizeIn = TIFFTileSize(in); tsize_t BufSizeOut = TIFFTileSize(out); unsigned char *BufferIn, *BufferOut; ttile_t i, TileCount = TIFFNumberOfTiles(in) / nPlanes; uint32 tw, tl; int PixelCount, j; TIFFGetFieldDefaulted(in, TIFFTAG_TILEWIDTH, &tw); TIFFGetFieldDefaulted(in, TIFFTAG_TILELENGTH, &tl); PixelCount = (int) tw * tl; BufferIn = (unsigned char *) _TIFFmalloc(BufSizeIn * nPlanes); if (!BufferIn) OutOfMem(BufSizeIn * nPlanes); BufferOut = (unsigned char *) _TIFFmalloc(BufSizeOut * nPlanes); if (!BufferOut) OutOfMem(BufSizeOut * nPlanes); for (i = 0; i < TileCount; i++) { for (j=0; j < nPlanes; j++) { if (TIFFReadEncodedTile(in, i + (j* TileCount), BufferIn + (j*BufSizeIn), BufSizeIn) < 0) goto cleanup; } cmsDoTransform(hXForm, BufferIn, BufferOut, PixelCount); for (j=0; j < nPlanes; j++) { if (TIFFWriteEncodedTile(out, i + (j*TileCount), BufferOut + (j*BufSizeOut), BufSizeOut) < 0) goto cleanup; } } _TIFFfree(BufferIn); _TIFFfree(BufferOut); return 1; cleanup: _TIFFfree(BufferIn); _TIFFfree(BufferOut); return 0; }
/** * Constructor. * * @param ifd the directory the tile belongs to. */ Impl(std::shared_ptr<IFD>& ifd): ifd(ifd), tilewidth(), tileheight(), planarconfig(), samples(), tilecount(), nrows(), ncols(), ntiles(), buffersize() { Sentry sentry; ::TIFF *tiff = getTIFF(); // Get basic image metadata. uint32_t imagewidth = ifd->getImageWidth(); uint32_t imageheight = ifd->getImageHeight(); planarconfig = ifd->getPlanarConfiguration(); samples = ifd->getSamplesPerPixel(); tilewidth = ifd->getTileWidth(); tileheight = ifd->getTileHeight(); type = ifd->getTileType(); // Get tile-specific metadata, falling back to // strip-specific metadata if not present. if (type == TILE) { tilecount = TIFFNumberOfTiles(tiff); buffersize = TIFFTileSize(tiff); } else { tilecount = TIFFNumberOfStrips(tiff); buffersize = TIFFStripSize(tiff); } // Compute row and column counts. nrows = imageheight / tileheight; if (imageheight % tileheight) ++nrows; ncols = imagewidth / tilewidth; if (imagewidth % tilewidth) ++ncols; ntiles = nrows * ncols; }
static void read_tile_from_file(struct tiff_tile *t, char *filename, int tidx) { TIFF *tif = tiffopen_fancy(filename, "r"); if (!tif) fail("could not open TIFF file \"%s\" for reading", filename); uint32_t w, h; uint16_t spp, bps, fmt, planarity; TIFFGetFieldDefaulted(tif, TIFFTAG_IMAGEWIDTH, &w); TIFFGetFieldDefaulted(tif, TIFFTAG_IMAGELENGTH, &h); TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &spp); TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &bps); TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLEFORMAT, &fmt); TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planarity); t->spp = spp; t->bps = bps; t->fmt = fmt; t->broken = false; if (planarity != PLANARCONFIG_CONTIG) fail("broken pixels not supported yet"); if (TIFFIsTiled(tif)) { int nt = TIFFNumberOfTiles(tif); if (tidx < 0 || tidx >= nt) fail("bad tile index %d", tidx); t->w = tiff_tilewidth(tif);; t->h = tiff_tilelength(tif); int ii[2]; tiff_tile_corner(ii, tif, tidx); //int ii = tw*i; //int jj = th*j; int tbytes = TIFFTileSize(tif); t->data = xmalloc(tbytes); memset(t->data, 0, tbytes); int r = my_readtile(tif, t->data, ii[0], ii[1], 0, 0); if (r != tbytes) fail("could not read tile"); } else { // not tiled, read the whole image into 0th tile read_scanlines(t, tif); } TIFFClose(tif); }
/* * Setup strips/tiles; buffers will be allocated in TIFFSetOffset / TIFFSetByteCount */ int TIFFSetupStrips(TIFF* tif) { TIFFDirectory* td = &tif->tif_dir; if (isTiled(tif)) td->td_stripsperimage = isUnspecified(tif, FIELD_TILEDIMENSIONS) ? td->td_samplesperpixel : TIFFNumberOfTiles(tif); else td->td_stripsperimage = isUnspecified(tif, FIELD_ROWSPERSTRIP) ? td->td_samplesperpixel : TIFFNumberOfStrips(tif); td->td_nstrips = td->td_stripsperimage; if (td->td_planarconfig == PLANARCONFIG_SEPARATE) td->td_stripsperimage /= td->td_samplesperpixel; TIFFSetFieldBit(tif, FIELD_STRIPOFFSETS); TIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS); return (1); }
/* * Read the next TIFF directory from a file * and convert it to the internal format. * We read directories sequentially. */ int TIFFReadDirectory(TIFF* tif) { register TIFFDirEntry* dp; register int n; register TIFFDirectory* td; TIFFDirEntry* dir; int iv; long v; double dv; const TIFFFieldInfo* fip; int fix; uint16 dircount; toff_t nextdiroff; char* cp; int diroutoforderwarning = 0; tif->tif_diroff = tif->tif_nextdiroff; if (tif->tif_diroff == 0) /* no more directories */ return (0); /* * Cleanup any previous compression state. */ (*tif->tif_cleanup)(tif); tif->tif_curdir++; nextdiroff = 0; if (!isMapped(tif)) { if (!SeekOK(tif, tif->tif_diroff)) { TIFFError(tif->tif_name, "Seek error accessing TIFF directory"); return (0); } if (!ReadOK(tif, &dircount, sizeof (uint16))) { TIFFError(tif->tif_name, "Can not read TIFF directory count"); return (0); } if (tif->tif_flags & TIFF_SWAB) TIFFSwabShort(&dircount); dir = (TIFFDirEntry *)CheckMalloc(tif, dircount * sizeof (TIFFDirEntry), "to read TIFF directory"); if (dir == NULL) return (0); if (!ReadOK(tif, dir, dircount*sizeof (TIFFDirEntry))) { TIFFError(tif->tif_name, "Can not read TIFF directory"); goto bad; } /* * Read offset to next directory for sequential scans. */ (void) ReadOK(tif, &nextdiroff, sizeof (uint32)); } else { toff_t off = tif->tif_diroff; if (off + sizeof (uint16) > tif->tif_size) { TIFFError(tif->tif_name, "Can not read TIFF directory count"); return (0); } else _TIFFmemcpy(&dircount, tif->tif_base + off, sizeof (uint16)); off += sizeof (uint16); if (tif->tif_flags & TIFF_SWAB) TIFFSwabShort(&dircount); dir = (TIFFDirEntry *)CheckMalloc(tif, dircount * sizeof (TIFFDirEntry), "to read TIFF directory"); if (dir == NULL) return (0); if (off + dircount*sizeof (TIFFDirEntry) > tif->tif_size) { TIFFError(tif->tif_name, "Can not read TIFF directory"); goto bad; } else _TIFFmemcpy(dir, tif->tif_base + off, dircount*sizeof (TIFFDirEntry)); off += dircount* sizeof (TIFFDirEntry); if (off + sizeof (uint32) <= tif->tif_size) _TIFFmemcpy(&nextdiroff, tif->tif_base+off, sizeof (uint32)); } if (tif->tif_flags & TIFF_SWAB) TIFFSwabLong(&nextdiroff); tif->tif_nextdiroff = nextdiroff; tif->tif_flags &= ~TIFF_BEENWRITING; /* reset before new dir */ /* * Setup default value and then make a pass over * the fields to check type and tag information, * and to extract info required to size data * structures. A second pass is made afterwards * to read in everthing not taken in the first pass. */ td = &tif->tif_dir; /* free any old stuff and reinit */ TIFFFreeDirectory(tif); TIFFDefaultDirectory(tif); /* * Electronic Arts writes gray-scale TIFF files * without a PlanarConfiguration directory entry. * Thus we setup a default value here, even though * the TIFF spec says there is no default value. */ TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); /* * Sigh, we must make a separate pass through the * directory for the following reason: * * We must process the Compression tag in the first pass * in order to merge in codec-private tag definitions (otherwise * we may get complaints about unknown tags). However, the * Compression tag may be dependent on the SamplesPerPixel * tag value because older TIFF specs permited Compression * to be written as a SamplesPerPixel-count tag entry. * Thus if we don't first figure out the correct SamplesPerPixel * tag value then we may end up ignoring the Compression tag * value because it has an incorrect count value (if the * true value of SamplesPerPixel is not 1). * * It sure would have been nice if Aldus had really thought * this stuff through carefully. */ for (dp = dir, n = dircount; n > 0; n--, dp++) { if (tif->tif_flags & TIFF_SWAB) { TIFFSwabArrayOfShort(&dp->tdir_tag, 2); TIFFSwabArrayOfLong(&dp->tdir_count, 2); } if (dp->tdir_tag == TIFFTAG_SAMPLESPERPIXEL) { if (!TIFFFetchNormalTag(tif, dp)) goto bad; dp->tdir_tag = IGNORE; } } /* * First real pass over the directory. */ fix = 0; for (dp = dir, n = dircount; n > 0; n--, dp++) { /* * Find the field information entry for this tag. * Added check for tags to ignore ... [BFC] */ if( TIFFReassignTagToIgnore(TIS_EXTRACT, dp->tdir_tag) ) dp->tdir_tag = IGNORE; if (dp->tdir_tag == IGNORE) continue; /* * Silicon Beach (at least) writes unordered * directory tags (violating the spec). Handle * it here, but be obnoxious (maybe they'll fix it?). */ if (dp->tdir_tag < tif->tif_fieldinfo[fix]->field_tag) { if (!diroutoforderwarning) { TIFFWarning(tif->tif_name, "invalid TIFF directory; tags are not sorted in ascending order"); diroutoforderwarning = 1; } fix = 0; /* O(n^2) */ } while (fix < tif->tif_nfields && tif->tif_fieldinfo[fix]->field_tag < dp->tdir_tag) fix++; if (fix == tif->tif_nfields || tif->tif_fieldinfo[fix]->field_tag != dp->tdir_tag) { TIFFWarning(tif->tif_name, "unknown field with tag %d (0x%x) ignored", dp->tdir_tag, dp->tdir_tag); dp->tdir_tag = IGNORE; fix = 0; /* restart search */ continue; } /* * Null out old tags that we ignore. */ if (tif->tif_fieldinfo[fix]->field_bit == FIELD_IGNORE) { ignore: dp->tdir_tag = IGNORE; continue; } /* * Check data type. */ fip = tif->tif_fieldinfo[fix]; while (dp->tdir_type != (u_short) fip->field_type) { if (fip->field_type == TIFF_ANY) /* wildcard */ break; fip++, fix++; if (fix == tif->tif_nfields || fip->field_tag != dp->tdir_tag) { TIFFWarning(tif->tif_name, "wrong data type %d for \"%s\"; tag ignored", dp->tdir_type, fip[-1].field_name); goto ignore; } } /* * Check count if known in advance. */ if (fip->field_readcount != TIFF_VARIABLE) { uint32 expected = (fip->field_readcount == TIFF_SPP) ? (uint32) td->td_samplesperpixel : (uint32) fip->field_readcount; if (!CheckDirCount(tif, dp, expected)) goto ignore; } switch (dp->tdir_tag) { case TIFFTAG_COMPRESSION: /* * The 5.0 spec says the Compression tag has * one value, while earlier specs say it has * one value per sample. Because of this, we * accept the tag if one value is supplied. */ if (dp->tdir_count == 1) { v = TIFFExtractData(tif, dp->tdir_type, dp->tdir_offset); if (!TIFFSetField(tif, dp->tdir_tag, (int)v)) goto bad; break; } if (!TIFFFetchPerSampleShorts(tif, dp, &iv) || !TIFFSetField(tif, dp->tdir_tag, iv)) goto bad; dp->tdir_tag = IGNORE; break; case TIFFTAG_STRIPOFFSETS: case TIFFTAG_STRIPBYTECOUNTS: case TIFFTAG_TILEOFFSETS: case TIFFTAG_TILEBYTECOUNTS: TIFFSetFieldBit(tif, fip->field_bit); break; case TIFFTAG_IMAGEWIDTH: case TIFFTAG_IMAGELENGTH: case TIFFTAG_IMAGEDEPTH: case TIFFTAG_TILELENGTH: case TIFFTAG_TILEWIDTH: case TIFFTAG_TILEDEPTH: case TIFFTAG_PLANARCONFIG: case TIFFTAG_ROWSPERSTRIP: if (!TIFFFetchNormalTag(tif, dp)) goto bad; dp->tdir_tag = IGNORE; break; case TIFFTAG_EXTRASAMPLES: (void) TIFFFetchExtraSamples(tif, dp); dp->tdir_tag = IGNORE; break; } } /* * Allocate directory structure and setup defaults. */ if (!TIFFFieldSet(tif, FIELD_IMAGEDIMENSIONS)) { MissingRequired(tif, "ImageLength"); goto bad; } if (!TIFFFieldSet(tif, FIELD_PLANARCONFIG)) { MissingRequired(tif, "PlanarConfiguration"); goto bad; } /* * Setup appropriate structures (by strip or by tile) */ if (!TIFFFieldSet(tif, FIELD_TILEDIMENSIONS)) { td->td_nstrips = TIFFNumberOfStrips(tif); td->td_tilewidth = td->td_imagewidth; td->td_tilelength = td->td_rowsperstrip; td->td_tiledepth = td->td_imagedepth; tif->tif_flags &= ~TIFF_ISTILED; } else { td->td_nstrips = TIFFNumberOfTiles(tif); tif->tif_flags |= TIFF_ISTILED; } td->td_stripsperimage = td->td_nstrips; if (td->td_planarconfig == PLANARCONFIG_SEPARATE) td->td_stripsperimage /= td->td_samplesperpixel; if (!TIFFFieldSet(tif, FIELD_STRIPOFFSETS)) { MissingRequired(tif, isTiled(tif) ? "TileOffsets" : "StripOffsets"); goto bad; } /* * Second pass: extract other information. */ for (dp = dir, n = dircount; n > 0; n--, dp++) { if (dp->tdir_tag == IGNORE) continue; switch (dp->tdir_tag) { case TIFFTAG_MINSAMPLEVALUE: case TIFFTAG_MAXSAMPLEVALUE: case TIFFTAG_BITSPERSAMPLE: /* * The 5.0 spec says the Compression tag has * one value, while earlier specs say it has * one value per sample. Because of this, we * accept the tag if one value is supplied. * * The MinSampleValue, MaxSampleValue and * BitsPerSample tags are supposed to be written * as one value/sample, but some vendors incorrectly * write one value only -- so we accept that * as well (yech). */ if (dp->tdir_count == 1) { v = TIFFExtractData(tif, dp->tdir_type, dp->tdir_offset); if (!TIFFSetField(tif, dp->tdir_tag, (int)v)) goto bad; break; } /* fall thru... */ case TIFFTAG_DATATYPE: case TIFFTAG_SAMPLEFORMAT: if (!TIFFFetchPerSampleShorts(tif, dp, &iv) || !TIFFSetField(tif, dp->tdir_tag, iv)) goto bad; break; case TIFFTAG_SMINSAMPLEVALUE: case TIFFTAG_SMAXSAMPLEVALUE: if (!TIFFFetchPerSampleAnys(tif, dp, &dv) || !TIFFSetField(tif, dp->tdir_tag, dv)) goto bad; break; case TIFFTAG_STRIPOFFSETS: case TIFFTAG_TILEOFFSETS: if (!TIFFFetchStripThing(tif, dp, td->td_nstrips, &td->td_stripoffset)) goto bad; break; case TIFFTAG_STRIPBYTECOUNTS: case TIFFTAG_TILEBYTECOUNTS: if (!TIFFFetchStripThing(tif, dp, td->td_nstrips, &td->td_stripbytecount)) goto bad; break; case TIFFTAG_COLORMAP: case TIFFTAG_TRANSFERFUNCTION: /* * TransferFunction can have either 1x or 3x data * values; Colormap can have only 3x items. */ v = 1L<<td->td_bitspersample; if (dp->tdir_tag == TIFFTAG_COLORMAP || dp->tdir_count != (uint32) v) { if (!CheckDirCount(tif, dp, (uint32)(3*v))) break; } v *= sizeof (uint16); cp = CheckMalloc(tif, dp->tdir_count * sizeof (uint16), "to read \"TransferFunction\" tag"); if (cp != NULL) { if (TIFFFetchData(tif, dp, cp)) { /* * This deals with there being only * one array to apply to all samples. */ uint32 c = (uint32)1 << td->td_bitspersample; if (dp->tdir_count == c) v = 0; TIFFSetField(tif, dp->tdir_tag, cp, cp+v, cp+2*v); } _TIFFfree(cp); } break; case TIFFTAG_PAGENUMBER: case TIFFTAG_HALFTONEHINTS: case TIFFTAG_YCBCRSUBSAMPLING: case TIFFTAG_DOTRANGE: (void) TIFFFetchShortPair(tif, dp); break; #ifdef COLORIMETRY_SUPPORT case TIFFTAG_REFERENCEBLACKWHITE: (void) TIFFFetchRefBlackWhite(tif, dp); break; #endif /* BEGIN REV 4.0 COMPATIBILITY */ case TIFFTAG_OSUBFILETYPE: v = 0; switch (TIFFExtractData(tif, dp->tdir_type, dp->tdir_offset)) { case OFILETYPE_REDUCEDIMAGE: v = FILETYPE_REDUCEDIMAGE; break; case OFILETYPE_PAGE: v = FILETYPE_PAGE; break; } if (v) (void) TIFFSetField(tif, TIFFTAG_SUBFILETYPE, (int)v); break; /* END REV 4.0 COMPATIBILITY */ default: (void) TIFFFetchNormalTag(tif, dp); break; } } /* * Verify Palette image has a Colormap. */ if (td->td_photometric == PHOTOMETRIC_PALETTE && !TIFFFieldSet(tif, FIELD_COLORMAP)) { MissingRequired(tif, "Colormap"); goto bad; } /* * Attempt to deal with a missing StripByteCounts tag. */ if (!TIFFFieldSet(tif, FIELD_STRIPBYTECOUNTS)) { /* * Some manufacturers violate the spec by not giving * the size of the strips. In this case, assume there * is one uncompressed strip of data. */ if ((td->td_planarconfig == PLANARCONFIG_CONTIG && td->td_nstrips > 1) || (td->td_planarconfig == PLANARCONFIG_SEPARATE && td->td_nstrips != td->td_samplesperpixel)) { MissingRequired(tif, "StripByteCounts"); goto bad; } TIFFWarning(tif->tif_name, "TIFF directory is missing required \"%s\" field, calculating from imagelength", _TIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name); EstimateStripByteCounts(tif, dir, dircount); #define BYTECOUNTLOOKSBAD \ ((td->td_stripbytecount[0] == 0 && td->td_stripoffset[0] != 0) || \ (td->td_compression == COMPRESSION_NONE && \ td->td_stripbytecount[0] > TIFFGetFileSize(tif) - td->td_stripoffset[0])) } else if (td->td_nstrips == 1 && BYTECOUNTLOOKSBAD) { /* * Plexus (and others) sometimes give a value * of zero for a tag when they don't know what * the correct value is! Try and handle the * simple case of estimating the size of a one * strip image. */ TIFFWarning(tif->tif_name, "Bogus \"%s\" field, ignoring and calculating from imagelength", _TIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name); EstimateStripByteCounts(tif, dir, dircount); } if (dir) _TIFFfree((char *)dir); if (!TIFFFieldSet(tif, FIELD_MAXSAMPLEVALUE)) td->td_maxsamplevalue = (uint16)((1L<<td->td_bitspersample)-1); /* * Setup default compression scheme. */ if (!TIFFFieldSet(tif, FIELD_COMPRESSION)) TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE); /* * Some manufacturers make life difficult by writing * large amounts of uncompressed data as a single strip. * This is contrary to the recommendations of the spec. * The following makes an attempt at breaking such images * into strips closer to the recommended 8k bytes. A * side effect, however, is that the RowsPerStrip tag * value may be changed. */ if (td->td_nstrips == 1 && td->td_compression == COMPRESSION_NONE && (tif->tif_flags & (TIFF_STRIPCHOP|TIFF_ISTILED)) == TIFF_STRIPCHOP) ChopUpSingleUncompressedStrip(tif); /* * Reinitialize i/o since we are starting on a new directory. */ tif->tif_row = (uint32) -1; tif->tif_curstrip = (tstrip_t) -1; tif->tif_col = (uint32) -1; tif->tif_curtile = (ttile_t) -1; tif->tif_tilesize = TIFFTileSize(tif); tif->tif_scanlinesize = TIFFScanlineSize(tif); return (1); bad: if (dir) _TIFFfree(dir); return (0); }
/* Copy a TIFF file ... we know we wrote it, so just copy the tags we know * we might have set. */ static int write_copy_tiff( Write *write, TIFF *out, TIFF *in ) { uint32 i32; uint16 i16; float f; tdata_t buf; ttile_t tile; ttile_t n; /* All the fields we might have set. */ CopyField( TIFFTAG_IMAGEWIDTH, i32 ); CopyField( TIFFTAG_IMAGELENGTH, i32 ); CopyField( TIFFTAG_PLANARCONFIG, i16 ); CopyField( TIFFTAG_ORIENTATION, i16 ); CopyField( TIFFTAG_XRESOLUTION, f ); CopyField( TIFFTAG_YRESOLUTION, f ); CopyField( TIFFTAG_RESOLUTIONUNIT, i16 ); CopyField( TIFFTAG_COMPRESSION, i16 ); CopyField( TIFFTAG_SAMPLESPERPIXEL, i16 ); CopyField( TIFFTAG_BITSPERSAMPLE, i16 ); CopyField( TIFFTAG_PHOTOMETRIC, i16 ); CopyField( TIFFTAG_ORIENTATION, i16 ); CopyField( TIFFTAG_TILEWIDTH, i32 ); CopyField( TIFFTAG_TILELENGTH, i32 ); CopyField( TIFFTAG_ROWSPERSTRIP, i32 ); CopyField( TIFFTAG_SUBFILETYPE, i32 ); if( write->predictor != VIPS_FOREIGN_TIFF_PREDICTOR_NONE ) TIFFSetField( out, TIFFTAG_PREDICTOR, write->predictor ); /* TIFFTAG_JPEGQUALITY is a pesudo-tag, so we can't copy it. * Set explicitly from Write. */ if( write->compression == COMPRESSION_JPEG ) { TIFFSetField( out, TIFFTAG_JPEGQUALITY, write->jpqual ); /* Only for three-band, 8-bit images. */ if( write->im->Bands == 3 && write->im->BandFmt == VIPS_FORMAT_UCHAR ) { /* Enable rgb->ycbcr conversion in the jpeg write. */ if( !write->rgbjpeg && write->jpqual < 90 ) TIFFSetField( out, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB ); /* And we want ycbcr expanded to rgb on read. Otherwise * TIFFTileSize() will give us the size of a chrominance * subsampled tile. */ TIFFSetField( in, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB ); } } /* We can't copy profiles or xmp :( Set again from Write. */ if( !write->strip ) if( write_embed_profile( write, out ) || write_embed_xmp( write, out ) || write_embed_ipct( write, out ) || write_embed_photoshop( write, out ) || write_embed_imagedescription( write, out ) ) return( -1 ); buf = vips_malloc( NULL, TIFFTileSize( in ) ); n = TIFFNumberOfTiles( in ); for( tile = 0; tile < n; tile++ ) { tsize_t len; /* It'd be good to use TIFFReadRawTile()/TIFFWriteRawTile() * here to save compression/decompression, but sadly it seems * not to work :-( investigate at some point. */ len = TIFFReadEncodedTile( in, tile, buf, -1 ); if( len < 0 || TIFFWriteEncodedTile( out, tile, buf, len ) < 0 ) { vips_free( buf ); return( -1 ); } } vips_free( buf ); return( 0 ); }
int PS_Lvl2page(FILE* fd, TIFF* tif, uint32 w, uint32 h) { uint16 fillorder; int use_rawdata, tiled_image, breaklen; uint32 chunk_no, num_chunks, *bc; unsigned char *buf_data, *cp; tsize_t chunk_size, byte_count; #if defined( EXP_ASCII85ENCODER ) int ascii85_l; /* Length, in bytes, of ascii85_p[] data */ uint8 * ascii85_p = 0; /* Holds ASCII85 encoded data */ #endif PS_Lvl2colorspace(fd, tif); use_rawdata = PS_Lvl2ImageDict(fd, tif, w, h); fputs("%%BeginData:\n", fd); fputs("exec\n", fd); tiled_image = TIFFIsTiled(tif); if (tiled_image) { num_chunks = TIFFNumberOfTiles(tif); TIFFGetField(tif, TIFFTAG_TILEBYTECOUNTS, &bc); } else { num_chunks = TIFFNumberOfStrips(tif); TIFFGetField(tif, TIFFTAG_STRIPBYTECOUNTS, &bc); } if (use_rawdata) { chunk_size = bc[0]; for (chunk_no = 1; chunk_no < num_chunks; chunk_no++) if (bc[chunk_no] > chunk_size) chunk_size = bc[chunk_no]; } else { if (tiled_image) chunk_size = TIFFTileSize(tif); else chunk_size = TIFFStripSize(tif); } buf_data = (unsigned char *)_TIFFmalloc(chunk_size); if (!buf_data) { TIFFError(filename, "Can't alloc %u bytes for %s.", chunk_size, tiled_image ? "tiles" : "strips"); return(FALSE); } #if defined( EXP_ASCII85ENCODER ) if ( ascii85 ) { /* * Allocate a buffer to hold the ASCII85 encoded data. Note * that it is allocated with sufficient room to hold the * encoded data (5*chunk_size/4) plus the EOD marker (+8) * and formatting line breaks. The line breaks are more * than taken care of by using 6*chunk_size/4 rather than * 5*chunk_size/4. */ ascii85_p = _TIFFmalloc( (chunk_size+(chunk_size/2)) + 8 ); if ( !ascii85_p ) { _TIFFfree( buf_data ); TIFFError( filename, "Cannot allocate ASCII85 encoding buffer." ); return ( FALSE ); } } #endif TIFFGetFieldDefaulted(tif, TIFFTAG_FILLORDER, &fillorder); for (chunk_no = 0; chunk_no < num_chunks; chunk_no++) { if (ascii85) Ascii85Init(); else breaklen = 36; if (use_rawdata) { if (tiled_image) byte_count = TIFFReadRawTile(tif, chunk_no, buf_data, chunk_size); else byte_count = TIFFReadRawStrip(tif, chunk_no, buf_data, chunk_size); if (fillorder == FILLORDER_LSB2MSB) TIFFReverseBits(buf_data, byte_count); } else { if (tiled_image) byte_count = TIFFReadEncodedTile(tif, chunk_no, buf_data, chunk_size); else byte_count = TIFFReadEncodedStrip(tif, chunk_no, buf_data, chunk_size); } if (byte_count < 0) { TIFFError(filename, "Can't read %s %d.", tiled_image ? "tile" : "strip", chunk_no); if (ascii85) Ascii85Put('\0', fd); } if (ascii85) { #if defined( EXP_ASCII85ENCODER ) ascii85_l = Ascii85EncodeBlock(ascii85_p, 1, buf_data, byte_count ); if ( ascii85_l > 0 ) fwrite( ascii85_p, ascii85_l, 1, fd ); #else for (cp = buf_data; byte_count > 0; byte_count--) Ascii85Put(*cp++, fd); #endif } else { for (cp = buf_data; byte_count > 0; byte_count--) { putc(hex[((*cp)>>4)&0xf], fd); putc(hex[(*cp)&0xf], fd); cp++; if (--breaklen <= 0) { putc('\n', fd); breaklen = 36; } } } if ( !ascii85 ) { if ( level2 ) putc( '>', fd ); putc('\n', fd); } #if !defined( EXP_ASCII85ENCODER ) else Ascii85Flush(fd); #endif } #if defined( EXP_ASCII85ENCODER ) if ( ascii85_p ) _TIFFfree( ascii85_p ); #endif _TIFFfree(buf_data); fputs("%%EndData\n", fd); return(TRUE); }
static int PS_Lvl2ImageDict(FILE* fd, TIFF* tif, uint32 w, uint32 h) { int use_rawdata; uint32 tile_width, tile_height; uint16 predictor, minsamplevalue, maxsamplevalue; int repeat_count; char im_h[64], im_x[64], im_y[64]; char * imageOp = "image"; if ( useImagemask && (bitspersample == 1) ) imageOp = "imagemask"; (void)strcpy(im_x, "0"); (void)sprintf(im_y, "%lu", (long) h); (void)sprintf(im_h, "%lu", (long) h); tile_width = w; tile_height = h; if (TIFFIsTiled(tif)) { repeat_count = TIFFNumberOfTiles(tif); TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tile_width); TIFFGetField(tif, TIFFTAG_TILELENGTH, &tile_height); if (tile_width > w || tile_height > h || (w % tile_width) != 0 || (h % tile_height != 0)) { /* * The tiles does not fit image width and height. * Set up a clip rectangle for the image unit square. */ fputs("0 0 1 1 rectclip\n", fd); } if (tile_width < w) { fputs("/im_x 0 def\n", fd); (void)strcpy(im_x, "im_x neg"); } if (tile_height < h) { fputs("/im_y 0 def\n", fd); (void)sprintf(im_y, "%lu im_y sub", (unsigned long) h); } } else { repeat_count = tf_numberstrips; tile_height = tf_rowsperstrip; if (tile_height > h) tile_height = h; if (repeat_count > 1) { fputs("/im_y 0 def\n", fd); fprintf(fd, "/im_h %lu def\n", (unsigned long) tile_height); (void)strcpy(im_h, "im_h"); (void)sprintf(im_y, "%lu im_y sub", (unsigned long) h); } } /* * Output start of exec block */ fputs("{ % exec\n", fd); if (repeat_count > 1) fprintf(fd, "%d { %% repeat\n", repeat_count); /* * Output filter options and image dictionary. */ if (ascii85) fputs(" /im_stream currentfile /ASCII85Decode filter def\n", fd); fputs(" <<\n", fd); fputs(" /ImageType 1\n", fd); fprintf(fd, " /Width %lu\n", (unsigned long) tile_width); fprintf(fd, " /Height %lu\n", (unsigned long) tile_height); if (planarconfiguration == PLANARCONFIG_SEPARATE && samplesperpixel > 1) fputs(" /MultipleDataSources true\n", fd); fprintf(fd, " /ImageMatrix [ %lu 0 0 %ld %s %s ]\n", (unsigned long) w, - (long)h, im_x, im_y); fprintf(fd, " /BitsPerComponent %d\n", bitspersample); fprintf(fd, " /Interpolate %s\n", interpolate ? "true" : "false"); switch (samplesperpixel) { case 1: switch (photometric) { case PHOTOMETRIC_MINISBLACK: fputs(" /Decode [0 1]\n", fd); break; case PHOTOMETRIC_MINISWHITE: switch (compression) { case COMPRESSION_CCITTRLE: case COMPRESSION_CCITTRLEW: case COMPRESSION_CCITTFAX3: case COMPRESSION_CCITTFAX4: /* * Manage inverting with /Blackis1 flag * since there migth be uncompressed parts */ fputs(" /Decode [0 1]\n", fd); break; default: /* * ERROR... */ fputs(" /Decode [1 0]\n", fd); break; } break; case PHOTOMETRIC_PALETTE: TIFFGetFieldDefaulted(tif, TIFFTAG_MINSAMPLEVALUE, &minsamplevalue); TIFFGetFieldDefaulted(tif, TIFFTAG_MAXSAMPLEVALUE, &maxsamplevalue); fprintf(fd, " /Decode [%u %u]\n", minsamplevalue, maxsamplevalue); break; default: /* * ERROR ? */ fputs(" /Decode [0 1]\n", fd); break; } break; case 3: switch (photometric) { case PHOTOMETRIC_RGB: fputs(" /Decode [0 1 0 1 0 1]\n", fd); break; case PHOTOMETRIC_MINISWHITE: case PHOTOMETRIC_MINISBLACK: default: /* * ERROR?? */ fputs(" /Decode [0 1 0 1 0 1]\n", fd); break; } break; case 4: /* * ERROR?? */ fputs(" /Decode [0 1 0 1 0 1 0 1]\n", fd); break; } fputs(" /DataSource", fd); if (planarconfiguration == PLANARCONFIG_SEPARATE && samplesperpixel > 1) fputs(" [", fd); if (ascii85) fputs(" im_stream", fd); else fputs(" currentfile /ASCIIHexDecode filter", fd); use_rawdata = TRUE; switch (compression) { case COMPRESSION_NONE: /* 1: uncompressed */ break; case COMPRESSION_CCITTRLE: /* 2: CCITT modified Huffman RLE */ case COMPRESSION_CCITTRLEW: /* 32771: #1 w/ word alignment */ case COMPRESSION_CCITTFAX3: /* 3: CCITT Group 3 fax encoding */ case COMPRESSION_CCITTFAX4: /* 4: CCITT Group 4 fax encoding */ fputs("\n\t<<\n", fd); if (compression == COMPRESSION_CCITTFAX3) { uint32 g3_options; fputs("\t /EndOfLine true\n", fd); fputs("\t /EndOfBlock false\n", fd); if (!TIFFGetField(tif, TIFFTAG_GROUP3OPTIONS, &g3_options)) g3_options = 0; if (g3_options & GROUP3OPT_2DENCODING) fprintf(fd, "\t /K %s\n", im_h); if (g3_options & GROUP3OPT_UNCOMPRESSED) fputs("\t /Uncompressed true\n", fd); if (g3_options & GROUP3OPT_FILLBITS) fputs("\t /EncodedByteAlign true\n", fd); } if (compression == COMPRESSION_CCITTFAX4) { uint32 g4_options; fputs("\t /K -1\n", fd); TIFFGetFieldDefaulted(tif, TIFFTAG_GROUP4OPTIONS, &g4_options); if (g4_options & GROUP4OPT_UNCOMPRESSED) fputs("\t /Uncompressed true\n", fd); } if (!(tile_width == w && w == 1728U)) fprintf(fd, "\t /Columns %lu\n", (unsigned long) tile_width); fprintf(fd, "\t /Rows %s\n", im_h); if (compression == COMPRESSION_CCITTRLE || compression == COMPRESSION_CCITTRLEW) { fputs("\t /EncodedByteAlign true\n", fd); fputs("\t /EndOfBlock false\n", fd); } if (photometric == PHOTOMETRIC_MINISBLACK) fputs("\t /BlackIs1 true\n", fd); fprintf(fd, "\t>> /CCITTFaxDecode filter"); break; case COMPRESSION_LZW: /* 5: Lempel-Ziv & Welch */ TIFFGetFieldDefaulted(tif, TIFFTAG_PREDICTOR, &predictor); if (predictor == 2) { fputs("\n\t<<\n", fd); fprintf(fd, "\t /Predictor %u\n", predictor); fprintf(fd, "\t /Columns %lu\n", (unsigned long) tile_width); fprintf(fd, "\t /Colors %u\n", samplesperpixel); fprintf(fd, "\t /BitsPerComponent %u\n", bitspersample); fputs("\t>>", fd); } fputs(" /LZWDecode filter", fd); break; case COMPRESSION_PACKBITS: /* 32773: Macintosh RLE */ fputs(" /RunLengthDecode filter", fd); use_rawdata = TRUE; break; case COMPRESSION_OJPEG: /* 6: !6.0 JPEG */ case COMPRESSION_JPEG: /* 7: %JPEG DCT compression */ #ifdef notdef /* * Code not tested yet */ fputs(" /DCTDecode filter", fd); use_rawdata = TRUE; #else use_rawdata = FALSE; #endif break; case COMPRESSION_NEXT: /* 32766: NeXT 2-bit RLE */ case COMPRESSION_THUNDERSCAN: /* 32809: ThunderScan RLE */ case COMPRESSION_PIXARFILM: /* 32908: Pixar companded 10bit LZW */ case COMPRESSION_DEFLATE: /* 32946: Deflate compression */ case COMPRESSION_JBIG: /* 34661: ISO JBIG */ use_rawdata = FALSE; break; case COMPRESSION_SGILOG: /* 34676: SGI LogL or LogLuv */ case COMPRESSION_SGILOG24: /* 34677: SGI 24-bit LogLuv */ use_rawdata = FALSE; break; default: /* * ERROR... */ use_rawdata = FALSE; break; } if (planarconfiguration == PLANARCONFIG_SEPARATE && samplesperpixel > 1) { uint16 i; /* * NOTE: This code does not work yet... */ for (i = 1; i < samplesperpixel; i++) fputs(" dup", fd); fputs(" ]", fd); } fprintf( fd, "\n >> %s\n", imageOp ); if (ascii85) fputs(" im_stream status { im_stream flushfile } if\n", fd); if (repeat_count > 1) { if (tile_width < w) { fprintf(fd, " /im_x im_x %lu add def\n", (unsigned long) tile_width); if (tile_height < h) { fprintf(fd, " im_x %lu ge {\n", (unsigned long) w); fputs(" /im_x 0 def\n", fd); fprintf(fd, " /im_y im_y %lu add def\n", (unsigned long) tile_height); fputs(" } if\n", fd); } } if (tile_height < h) { if (tile_width >= w) { fprintf(fd, " /im_y im_y %lu add def\n", (unsigned long) tile_height); if (!TIFFIsTiled(tif)) { fprintf(fd, " /im_h %lu im_y sub", (unsigned long) h); fprintf(fd, " dup %lu gt { pop", (unsigned long) tile_height); fprintf(fd, " %lu } if def\n", (unsigned long) tile_height); } } } fputs("} repeat\n", fd); } /* * End of exec function */ fputs("}\n", fd); return(use_rawdata); }
int vglPrintTiffInfo(char* inFilename, char* msg){ if (msg){ printf("====== %s:\n", msg); } else { printf("====== vglPrintTiffInfo:\n"); } TIFF* tif = TIFFOpen(inFilename, "r"); if (tif == NULL){ fprintf(stderr, "%s:%s: Error: File %s not found.\n", __FILE__, __FUNCTION__, inFilename); return 1; } if (tif) { uint32 w, h; uint16 bps, spp, photo, config, pageNumber, numberPages; uint32 subfileType; tdir_t dirCount; tstrip_t stripMax; tstrip_t istrip; tsize_t stripSize; tsize_t npixels; tsize_t pixelSize; tdata_t raster; tsize_t result, offset; char* rasterc; uint32 iw, ih; int i; do{ TIFFPrintDirectory(tif, stdout, 255); } while(TIFFReadDirectory(tif)); printf("TIFFScanlineSize = %ld\n", (long int) TIFFScanlineSize(tif)); printf("TIFFRasterScanlineSize = %ld\n", (long int) TIFFRasterScanlineSize(tif)); printf("TIFFStripSize = %ld\n", (long int) TIFFStripSize(tif)); printf("TIFFNumberOfStrips = %d\n", TIFFNumberOfStrips(tif)); printf("TIFFVStripSize = %ld\n", (long int) TIFFVStripSize(tif,0)); printf("TIFFTileRowSize = %ld\n", (long int) TIFFTileRowSize(tif)); printf("TIFFTileSize = %ld\n", (long int) TIFFTileSize(tif)); printf("TIFFNumberOfTiles = %d\n", TIFFNumberOfTiles(tif)); printf("TIFFVTileSize = %ld\n", (long int) TIFFVTileSize(tif,0)); printf("TIFFDefaultStripSize = %d\n", TIFFDefaultStripSize(tif,0)); printf("TIFFFileno = %d\n", TIFFFileno(tif)); printf("TIFFGetMode = %d\n", TIFFGetMode(tif)); printf("TIFFIsTiled = %d\n", TIFFIsTiled(tif)); printf("TIFFIsByteSwapped = %d\n", TIFFIsByteSwapped(tif)); printf("TIFFRGBAImageOK = %d\n", TIFFRGBAImageOK(tif, (char*)"TIFFRGBAImageOK mesg\n")); TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w); TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h); TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bps); TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &spp); TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photo); TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &config); TIFFGetField(tif, TIFFTAG_PAGENUMBER, &pageNumber, &numberPages); TIFFGetField(tif, TIFFTAG_SUBFILETYPE, &subfileType); stripSize = TIFFStripSize(tif); stripMax = TIFFNumberOfStrips(tif); switch(bps){ case 8: pixelSize = 1; break; case 16: pixelSize = 2; break; default: pixelSize = 0; break; } dirCount = tif_DirCount(tif); printf("size = %lu, w = %d, h = %d, spp = %d, bps = %d, pixelSize = %ld\n", sizeof(w), w, h, spp, bps, (long int) pixelSize); printf("Page Number = %d\n", pageNumber); printf("Number Pages = %d\n", numberPages); printf("Photometric interpretation = %d\n", photo); printf("Planar configuration = %d\n", config); printf("stripSize = %ld, stripMax = %d\n", (long int) stripSize, stripMax); printf("Number of directories = %d\n", dirCount); printf("Subfile type = %d\n", subfileType); //printbin((char*)&w, sizeof(w)); //printbin((char*)&h, sizeof(h)); //raster = tif_ReadData(tif); //tif_PrintAsc(tif, raster, (char*)"ascimg.txt"); TIFFClose(tif); } return 0; }