strip size related bugfix in tif_jpeg encode raw

This commit is contained in:
Joris Van Damme 2006-03-25 18:04:34 +00:00
parent 64bd1138df
commit 84281a8949
3 changed files with 86 additions and 18 deletions

View File

@ -1,3 +1,13 @@
2006-03-25 Joris Van Damme <joris.at.lebbeke@skynet.be>
* libtiff/tif_jpeg.c: strip size related bugfix in encode raw
* libtiff/tif_strip.c: temporarilly added two new versions of
- TIFFNewScanlineSize: proposed new version, after all related
issues and side-effects are sorted out
- TIFFOldScanlineSize: old version, from prior to 2006-03-21 change
This needs further sorting out.
2006-03-25 Joris Van Damme <joris.at.lebbeke@skynet.be>
* contrib/addtiffo/tif_ovrcache.c: bugfix to correctly pass size

View File

@ -1,4 +1,4 @@
/* $Id: tif_jpeg.c,v 1.46 2006-03-25 08:01:08 joris Exp $ */
/* $Id: tif_jpeg.c,v 1.47 2006-03-25 18:04:34 joris Exp $ */
/*
* Copyright (c) 1994-1997 Sam Leffler
@ -1049,7 +1049,8 @@ JPEGDecodeRaw(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
sp->scancount ++;
tif->tif_row += sp->v_sampling;
/* increment/decrement of buf and cc is still incorrect, but should not matter */
/* increment/decrement of buf and cc is still incorrect, but should not matter
* TODO: resolve this */
buf += sp->bytesperline;
cc -= sp->bytesperline;
nrows -= sp->v_sampling;
@ -1278,7 +1279,7 @@ JPEGPreEncode(TIFF* tif, tsample_t s)
segment_height = td->td_imagelength - tif->tif_row;
if (segment_height > td->td_rowsperstrip)
segment_height = td->td_rowsperstrip;
sp->bytesperline = TIFFScanlineSize(tif);
sp->bytesperline = TIFFOldScanlineSize(tif);
}
if (td->td_planarconfig == PLANARCONFIG_SEPARATE && s > 0) {
/* for PC 2, scale down the strip/tile size
@ -1416,18 +1417,25 @@ JPEGEncodeRaw(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
int clumpoffset, ci, xpos, ypos;
jpeg_component_info* compptr;
int samples_per_clump = sp->samplesperclump;
tsize_t bytesperclumpline;
(void) s;
assert(sp != NULL);
/* data is expected to be supplied in multiples of a scanline */
nrows = cc / sp->bytesperline;
if (cc % sp->bytesperline)
/* data is expected to be supplied in multiples of a clumpline */
/* a clumpline is equivalent to v_sampling desubsampled scanlines */
/* TODO: the following calculation of bytesperclumpline, should substitute calculation of sp->bytesperline, except that it is per v_sampling lines */
bytesperclumpline = (((sp->cinfo.c.image_width+sp->h_sampling-1)/sp->h_sampling)
*(sp->h_sampling*sp->v_sampling+2)*sp->cinfo.c.data_precision+7)
/8;
nrows = ( cc / bytesperclumpline ) * sp->v_sampling;
if (cc % bytesperclumpline)
TIFFWarningExt(tif->tif_clientdata, tif->tif_name, "fractional scanline discarded");
/* Cb,Cr both have sampling factors 1, so this is correct */
clumps_per_line = sp->cinfo.c.comp_info[1].downsampled_width;
while (nrows-- > 0) {
while (nrows > 0) {
/*
* Fastest way to separate the data is to make one pass
* over the scanline for each row of each component.
@ -1472,9 +1480,9 @@ JPEGEncodeRaw(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
return (0);
sp->scancount = 0;
}
if (nrows > 0)
tif->tif_row++;
tif->tif_row += sp->v_sampling;
buf += sp->bytesperline;
nrows -= sp->v_sampling;
}
return (1);
}
@ -1703,7 +1711,6 @@ JPEGVGetField(TIFF* tif, ttag_t tag, va_list ap)
case TIFFTAG_YCBCRSUBSAMPLING:
JPEGFixupTestSubsampling( tif );
return (*sp->vgetparent)(tif, tag, ap);
break;
case TIFFTAG_FAXRECVPARAMS:
*va_arg(ap, uint32*) = sp->recvparams;
break;

View File

@ -1,4 +1,4 @@
/* $Id: tif_strip.c,v 1.18 2006-03-25 08:01:08 joris Exp $ */
/* $Id: tif_strip.c,v 1.19 2006-03-25 18:04:35 joris Exp $ */
/*
* Copyright (c) 1991-1997 Sam Leffler
@ -285,6 +285,57 @@ TIFFOldScanlineSize(TIFF* tif)
return ((tsize_t) TIFFhowmany8(scanline));
}
/*
* Return the number of bytes to read/write in a call to
* one of the scanline-oriented i/o routines. Note that
* this number may be 1/samples-per-pixel if data is
* stored as separate planes.
* The ScanlineSize in case of YCbCrSubsampling is defined as the
* strip size divided by the strip height, i.e. the size of a pack of vertical
* subsampling lines divided by vertical subsampling. It should thus make
* sense when multiplied by a multiple of vertical subsampling.
* Some stuff depends on this newer version of TIFFScanlineSize
* TODO: resolve this
*/
tsize_t
TIFFNewScanlineSize(TIFF* tif)
{
TIFFDirectory *td = &tif->tif_dir;
tsize_t scanline;
if (td->td_planarconfig == PLANARCONFIG_CONTIG) {
if (td->td_photometric == PHOTOMETRIC_YCBCR
&& !isUpSampled(tif)) {
uint16 ycbcrsubsampling[2];
TIFFGetField(tif, TIFFTAG_YCBCRSUBSAMPLING,
ycbcrsubsampling + 0,
ycbcrsubsampling + 1);
if (ycbcrsubsampling[0]*ycbcrsubsampling[1] == 0) {
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
"Invalid YCbCr subsampling");
return 0;
}
return((tsize_t) ((((td->td_imagewidth+ycbcrsubsampling[0]-1)
/ycbcrsubsampling[0])
*(ycbcrsubsampling[0]*ycbcrsubsampling[1]+2)
*td->td_bitspersample+7)
/8)/ycbcrsubsampling[1]);
} else {
scanline = multiply(tif, td->td_imagewidth,
td->td_samplesperpixel,
"TIFFScanlineSize");
}
} else
scanline = td->td_imagewidth;
return ((tsize_t) TIFFhowmany8(multiply(tif, scanline,
td->td_bitspersample,
"TIFFScanlineSize")));
}
/*
* Return the number of bytes required to store a complete
* decoded and packed raster scanline (as opposed to the