From 00ddda303a247f01c208a0a5b9c0252ffef2a809 Mon Sep 17 00:00:00 2001 From: Joris Van Damme Date: Sat, 29 Sep 2007 10:34:37 +0000 Subject: [PATCH] tif_dirread.c: Fixed bad behaviour of strip chopping on uncompressed subsampled images. --- ChangeLog | 8 ++++++++ libtiff/tif_dirread.c | 33 +++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index b8a6a943..e13babb7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-09-29 Joris Van Damme + + * tif_dirread.c: Strip chopping interfered badly with uncompressed + subsampled images because it tried to divide subsamples rowblock, leading + to all sorts of errors throughout the library for these images. Fixed by + making strip chopping divide in row counts that are multiple of vertical + subsampling value. + 2007-09-28 Joris Van Damme * tif_dirread.c: Logical cast working around compiler warning diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c index 8992b27b..3b3ab4b3 100644 --- a/libtiff/tif_dirread.c +++ b/libtiff/tif_dirread.c @@ -1,4 +1,4 @@ -/* $Id: tif_dirread.c,v 1.133 2007-09-27 17:38:57 joris Exp $ */ +/* $Id: tif_dirread.c,v 1.134 2007-09-29 10:34:38 joris Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -5255,9 +5255,11 @@ static void ChopUpSingleUncompressedStrip(TIFF* tif) { register TIFFDirectory *td = &tif->tif_dir; - uint64 bytecount = td->td_stripbytecount[0]; - uint64 offset = td->td_stripoffset[0]; - uint64 rowbytes = TIFFVTileSize64(tif, 1), stripbytes; + uint64 bytecount; + uint64 offset; + uint32 rowblock; + uint64 rowblockbytes; + uint64 stripbytes; uint32 strip; uint64 nstrips64; uint32 nstrips32; @@ -5265,16 +5267,27 @@ ChopUpSingleUncompressedStrip(TIFF* tif) uint64* newcounts; uint64* newoffsets; + bytecount = td->td_stripbytecount[0]; + offset = td->td_stripoffset[0]; + assert(td->td_planarconfig == PLANARCONFIG_CONTIG); + if ((td->td_photometric == PHOTOMETRIC_YCBCR)&& + (!isUpSampled(tif))) + rowblock = td->td_ycbcrsubsampling[1]; + else + rowblock = 1; + rowblockbytes = TIFFVTileSize64(tif, rowblock); /* * Make the rows hold at least one scanline, but fill specified amount * of data if possible. */ - if (rowbytes > STRIP_SIZE_DEFAULT) { - stripbytes = rowbytes; - rowsperstrip = 1; - } else if (rowbytes > 0 ) { - rowsperstrip = (uint32) (STRIP_SIZE_DEFAULT / rowbytes); - stripbytes = rowbytes * rowsperstrip; + if (rowblockbytes > STRIP_SIZE_DEFAULT) { + stripbytes = rowblockbytes; + rowsperstrip = rowblock; + } else if (rowblockbytes > 0 ) { + uint32 rowblocksperstrip; + rowblocksperstrip = (uint32) (STRIP_SIZE_DEFAULT / rowblockbytes); + rowsperstrip = rowblocksperstrip * rowblock; + stripbytes = rowblocksperstrip * rowblockbytes; } else return;