BigTIFF upgrade in progress - widespread temp mess - does not compile now

This commit is contained in:
Joris Van Damme 2007-05-31 13:33:50 +00:00
parent c81185549e
commit 2258bc2217
3 changed files with 97 additions and 87 deletions

View File

@ -1,4 +1,4 @@
/* $Id: tif_jpeg.c,v 1.60 2007-05-30 13:53:18 joris Exp $ */ /* $Id: tif_jpeg.c,v 1.61 2007-05-31 13:33:50 joris Exp $ */
/* /*
* Copyright (c) 1994-1997 Sam Leffler * Copyright (c) 1994-1997 Sam Leffler
@ -645,14 +645,14 @@ struct JPEGFixupTagsSubsamplingData
uint8* buffercurrentbyte; uint8* buffercurrentbyte;
uint32 bufferbytesleft; uint32 bufferbytesleft;
uint64_new fileoffset; uint64_new fileoffset;
uint8 filepositioned;
uint64_new filebytesleft; uint64_new filebytesleft;
uint8 filepositioned;
}; };
static void JPEGFixupTagsSubsampling(TIFF* tif); static void JPEGFixupTagsSubsampling(TIFF* tif);
static int JPEGFixupTagsSubsamplingSec(struct JPEGFixupTagsSubsamplingData* Data); static int JPEGFixupTagsSubsamplingSec(struct JPEGFixupTagsSubsamplingData* data);
static int JPEGFixupTagsSubsamplingReadByte(struct JPEGFixupTagsSubsamplingData* Data, uint8* Result); static int JPEGFixupTagsSubsamplingReadByte(struct JPEGFixupTagsSubsamplingData* data, uint8* result);
static int JPEGFixupTagsSubsamplingReadWord(struct JPEGFixupTagsSubsamplingData* Data, uint16* Result); static int JPEGFixupTagsSubsamplingReadWord(struct JPEGFixupTagsSubsamplingData* data, uint16* result);
static void JPEGFixupTagsSubsamplingSkip(struct JPEGFixupTagsSubsamplingData* Data, uint16 Skiplength); static void JPEGFixupTagsSubsamplingSkip(struct JPEGFixupTagsSubsamplingData* data, uint16 skiplength);
#endif #endif
@ -660,7 +660,9 @@ static int
JPEGFixupTags(TIFF* tif) JPEGFixupTags(TIFF* tif)
{ {
#ifdef CHECK_JPEG_YCBCR_SUBSAMPLING #ifdef CHECK_JPEG_YCBCR_SUBSAMPLING
if (tif->tif_dir.td_samplesperpixel>1) if ((tif->tif_dir.td_photometric==PHOTOMETRIC_YCBCR)&&
(tif->tif_dir.td_planarconfig==PLANARCONFIG_CONTIG)&&
(tif->tif_dir.td_samplesperpixel==3))
JPEGFixupTagsSubsampling(tif); JPEGFixupTagsSubsampling(tif);
#endif #endif
return(1); return(1);
@ -671,7 +673,6 @@ JPEGFixupTags(TIFF* tif)
static void static void
JPEGFixupTagsSubsampling(TIFF* tif) JPEGFixupTagsSubsampling(TIFF* tif)
{ {
static const char module[] = "JPEGFixupTagsSubsampling";
/* /*
* Some JPEG-in-TIFF produces do not emit the YCBCRSUBSAMPLING values in * Some JPEG-in-TIFF produces do not emit the YCBCRSUBSAMPLING values in
* the TIFF tags, but still use non-default (2,2) values within the jpeg * the TIFF tags, but still use non-default (2,2) values within the jpeg
@ -692,13 +693,15 @@ JPEGFixupTagsSubsampling(TIFF* tif)
* Frank Warmerdam, July 2002 * Frank Warmerdam, July 2002
* Joris Van Damme, May 2007 * Joris Van Damme, May 2007
*/ */
static const char module[] = "JPEGFixupTagsSubsampling";
struct JPEGFixupTagsSubsamplingData m; struct JPEGFixupTagsSubsamplingData m;
m.tif=tif; m.tif=tif;
m.buffersize=2048; m.buffersize=2048;
m.buffer=_TIFFmalloc(m.buffersize); m.buffer=_TIFFmalloc(m.buffersize);
if (m.buffer==NULL) if (m.buffer==NULL)
{ {
TIFFWarningExt(tif->tif_clientdata,module,"Unable to allocate memory for auto-correcting of subsampling values, auto-correcting skipped"); TIFFWarningExt(tif->tif_clientdata,module,
"Unable to allocate memory for auto-correcting of subsampling values; auto-correcting skipped");
return; return;
} }
m.buffercurrentbyte=NULL; m.buffercurrentbyte=NULL;
@ -707,32 +710,33 @@ JPEGFixupTagsSubsampling(TIFF* tif)
m.filepositioned=0; m.filepositioned=0;
m.filebytesleft=tif->tif_dir.td_stripbytecount[0]; m.filebytesleft=tif->tif_dir.td_stripbytecount[0];
if (!JPEGFixupTagsSubsamplingSec(&m)) if (!JPEGFixupTagsSubsamplingSec(&m))
TIFFWarningExt(tif->tif_clientdata,module,"Unable to auto-correct subsampling values, possibly corrupt JPEG compressed data"); TIFFWarningExt(tif->tif_clientdata,module,
"Unable to auto-correct subsampling values, likely corrupt JPEG compressed data in first strip/tile; auto-correcting skipped");
_TIFFfree(m.buffer); _TIFFfree(m.buffer);
} }
static int static int
JPEGFixupTagsSubsamplingSec(struct JPEGFixupTagsSubsamplingData* Data) JPEGFixupTagsSubsamplingSec(struct JPEGFixupTagsSubsamplingData* data)
{ {
static const char module[] = "JPEGFixupTagsSubsamplingSec"; static const char module[] = "JPEGFixupTagsSubsamplingSec";
uint8 n; uint8 m;
while (1) while (1)
{ {
while (1) while (1)
{ {
if (!JPEGFixupTagsSubsamplingReadByte(Data,&n)) if (!JPEGFixupTagsSubsamplingReadByte(data,&m))
return(0); return(0);
if (n==255) if (m==255)
break; break;
} }
while (1) while (1)
{ {
if (!JPEGFixupTagsSubsamplingReadByte(Data,&n)) if (!JPEGFixupTagsSubsamplingReadByte(data,&m))
return(0); return(0);
if (n!=255) if (m!=255)
break; break;
} }
switch (n) switch (m)
{ {
case JPEG_MARKER_SOI: case JPEG_MARKER_SOI:
/* this type of marker has no data and should be skipped */ /* this type of marker has no data and should be skipped */
@ -759,64 +763,64 @@ JPEGFixupTagsSubsamplingSec(struct JPEGFixupTagsSubsamplingData* Data)
case JPEG_MARKER_DRI: case JPEG_MARKER_DRI:
/* this type of marker has data, but it has no use to us and should be skipped */ /* this type of marker has data, but it has no use to us and should be skipped */
{ {
uint16 o; uint16 n;
if (!JPEGFixupTagsSubsamplingReadWord(Data,&o)) if (!JPEGFixupTagsSubsamplingReadWord(data,&n))
return(0); return(0);
if (o<2) if (n<2)
return(0); return(0);
o-=2; n-=2;
if (o>0) if (n>0)
JPEGFixupTagsSubsamplingSkip(Data,o); JPEGFixupTagsSubsamplingSkip(data,n);
} }
break; break;
case JPEG_MARKER_SOF0: case JPEG_MARKER_SOF0:
/* this marker contains the subsampling factors we're scanning for */ /* this marker contains the subsampling factors we're scanning for */
{ {
uint16 n;
uint16 o; uint16 o;
uint8 p; uint8 p;
uint8 q; uint8 ph,pv;
uint8 qh,qv; if (!JPEGFixupTagsSubsamplingReadWord(data,&n))
if (!JPEGFixupTagsSubsamplingReadWord(Data,&o))
return(0); return(0);
if (o!=8+Data->tif->tif_dir.td_samplesperpixel*3) if (n!=8+data->tif->tif_dir.td_samplesperpixel*3)
return(0); return(0);
JPEGFixupTagsSubsamplingSkip(Data,6); JPEGFixupTagsSubsamplingSkip(data,6);
for (p=0; p<Data->tif->tif_dir.td_samplesperpixel; p++) for (o=0; o<data->tif->tif_dir.td_samplesperpixel; o++)
{ {
JPEGFixupTagsSubsamplingSkip(Data,1); JPEGFixupTagsSubsamplingSkip(data,1);
if (!JPEGFixupTagsSubsamplingReadByte(Data,&q)) if (!JPEGFixupTagsSubsamplingReadByte(data,&p))
return(0); return(0);
if (p==0) if (o==0)
{ {
qh=(q>>4); ph=(p>>4);
qv=(q&15); pv=(p&15);
} }
else else
{ {
if (q!=0x11) if (p!=0x11)
{ {
TIFFWarningExt(Data->tif->tif_clientdata,module, TIFFWarningExt(data->tif->tif_clientdata,module,
"Subsampling values inside JPEG compressed data have no TIFF equivalent, auto-correction of TIFF subsampling values failed"); "Subsampling values inside JPEG compressed data have no TIFF equivalent, auto-correction of TIFF subsampling values failed");
return(1); return(1);
} }
} }
JPEGFixupTagsSubsamplingSkip(Data,1); JPEGFixupTagsSubsamplingSkip(data,1);
} }
if (((qh!=1)&&(qh!=2)&&(qh!=4))||((qv!=1)&&(qv!=2)&&(qv!=4))) if (((ph!=1)&&(ph!=2)&&(ph!=4))||((pv!=1)&&(pv!=2)&&(pv!=4)))
{ {
TIFFWarningExt(Data->tif->tif_clientdata,module, TIFFWarningExt(data->tif->tif_clientdata,module,
"Subsampling values inside JPEG compressed data have no TIFF equivalent, auto-correction of TIFF subsampling values failed"); "Subsampling values inside JPEG compressed data have no TIFF equivalent, auto-correction of TIFF subsampling values failed");
return(1); return(1);
} }
if ((qh!=Data->tif->tif_dir.td_ycbcrsubsampling[0])||(qv!=Data->tif->tif_dir.td_ycbcrsubsampling[1])) if ((ph!=data->tif->tif_dir.td_ycbcrsubsampling[0])||(pv!=data->tif->tif_dir.td_ycbcrsubsampling[1]))
{ {
TIFFWarningExt(Data->tif->tif_clientdata,module, TIFFWarningExt(data->tif->tif_clientdata,module,
"Auto-corrected former TIFF subsampling values [%d,%d] to match subsampling values inside JPEG compressed data [%d,%d]", "Auto-corrected former TIFF subsampling values [%d,%d] to match subsampling values inside JPEG compressed data [%d,%d]",
(uint32)Data->tif->tif_dir.td_ycbcrsubsampling[0], (int)data->tif->tif_dir.td_ycbcrsubsampling[0],
(uint32)Data->tif->tif_dir.td_ycbcrsubsampling[1], (int)data->tif->tif_dir.td_ycbcrsubsampling[1],
(uint32)qh,(uint32)qv); (int)ph,(int)pv);
Data->tif->tif_dir.td_ycbcrsubsampling[0]=qh; data->tif->tif_dir.td_ycbcrsubsampling[0]=ph;
Data->tif->tif_dir.td_ycbcrsubsampling[1]=qv; data->tif->tif_dir.td_ycbcrsubsampling[1]=pv;
} }
} }
return(1); return(1);
@ -827,70 +831,70 @@ JPEGFixupTagsSubsamplingSec(struct JPEGFixupTagsSubsamplingData* Data)
} }
static int static int
JPEGFixupTagsSubsamplingReadByte(struct JPEGFixupTagsSubsamplingData* Data, uint8* Result) JPEGFixupTagsSubsamplingReadByte(struct JPEGFixupTagsSubsamplingData* data, uint8* result)
{ {
if (Data->bufferbytesleft==0) if (data->bufferbytesleft==0)
{ {
uint32 m; uint32 m;
if (Data->filebytesleft==0) if (data->filebytesleft==0)
return(0); return(0);
if (!Data->filepositioned) if (!data->filepositioned)
{ {
TIFFSeekFile(Data->tif,Data->fileoffset,SEEK_SET); TIFFSeekFile(data->tif,data->fileoffset,SEEK_SET);
Data->filepositioned=1; data->filepositioned=1;
} }
m=Data->buffersize; m=data->buffersize;
if ((uint64_new)m>Data->filebytesleft) if ((uint64_new)m>data->filebytesleft)
m=(uint32)Data->filebytesleft; m=(uint32)data->filebytesleft;
if (TIFFReadFile(Data->tif,Data->buffer,m)!=m) if (TIFFReadFile(data->tif,data->buffer,m)!=m)
return(0); return(0);
Data->buffercurrentbyte=Data->buffer; data->buffercurrentbyte=data->buffer;
Data->bufferbytesleft=m; data->bufferbytesleft=m;
Data->fileoffset+=m; data->fileoffset+=m;
Data->filebytesleft-=m; data->filebytesleft-=m;
} }
*Result=*Data->buffercurrentbyte; *result=*data->buffercurrentbyte;
Data->buffercurrentbyte++; data->buffercurrentbyte++;
Data->bufferbytesleft--; data->bufferbytesleft--;
return(1); return(1);
} }
static int static int
JPEGFixupTagsSubsamplingReadWord(struct JPEGFixupTagsSubsamplingData* Data, uint16* Result) JPEGFixupTagsSubsamplingReadWord(struct JPEGFixupTagsSubsamplingData* data, uint16* result)
{ {
uint8 ma; uint8 ma;
uint8 mb; uint8 mb;
if (!JPEGFixupTagsSubsamplingReadByte(Data,&ma)) if (!JPEGFixupTagsSubsamplingReadByte(data,&ma))
return(0); return(0);
if (!JPEGFixupTagsSubsamplingReadByte(Data,&mb)) if (!JPEGFixupTagsSubsamplingReadByte(data,&mb))
return(0); return(0);
*Result=(ma<<8)|mb; *result=(ma<<8)|mb;
return(1); return(1);
} }
static void static void
JPEGFixupTagsSubsamplingSkip(struct JPEGFixupTagsSubsamplingData* Data, uint16 Skiplength) JPEGFixupTagsSubsamplingSkip(struct JPEGFixupTagsSubsamplingData* data, uint16 skiplength)
{ {
if (Skiplength<=Data->bufferbytesleft) if ((uint32)skiplength<=data->bufferbytesleft)
{ {
Data->buffercurrentbyte+=Skiplength; data->buffercurrentbyte+=skiplength;
Data->bufferbytesleft-=Skiplength; data->bufferbytesleft-=skiplength;
} }
else else
{ {
uint16 m; uint16 m;
m=Skiplength-Data->bufferbytesleft; m=skiplength-data->bufferbytesleft;
if (m<=Data->filebytesleft) if (m<=data->filebytesleft)
{ {
Data->bufferbytesleft=0; data->bufferbytesleft=0;
Data->fileoffset+=m; data->fileoffset+=m;
Data->filebytesleft-=m; data->filebytesleft-=m;
Data->filepositioned=0; data->filepositioned=0;
} }
else else
{ {
Data->bufferbytesleft=0; data->bufferbytesleft=0;
Data->filebytesleft=0; data->filebytesleft=0;
} }
} }
} }

View File

@ -1,4 +1,4 @@
/* $Id: tif_strip.c,v 1.24 2007-05-11 14:41:01 joris Exp $ */ /* $Id: tif_strip.c,v 1.25 2007-05-31 13:33:51 joris Exp $ */
/* /*
* Copyright (c) 1991-1997 Sam Leffler * Copyright (c) 1991-1997 Sam Leffler
@ -139,8 +139,10 @@ TIFFVStripSize64(TIFF* tif, uint32 nrows)
uint64_new samplingrow_samples; uint64_new samplingrow_samples;
uint64_new samplingrow_size; uint64_new samplingrow_size;
assert(td->td_samplesperpixel==3); assert(td->td_samplesperpixel==3);
TIFFGetField(tif,TIFFTAG_YCBCRSUBSAMPLING,ycbcrsubsampling+0, TIFFGetFieldDefaulted(tif,TIFFTAG_YCBCRSUBSAMPLING,ycbcrsubsampling+0,
ycbcrsubsampling+1); ycbcrsubsampling+1);
assert((ycbcrsubsampling[0]==1)||(ycbcrsubsampling[0]==2)||(ycbcrsubsampling[0]==4));
assert((ycbcrsubsampling[1]==1)||(ycbcrsubsampling[1]==2)||(ycbcrsubsampling[1]==4));
if (ycbcrsubsampling[0]*ycbcrsubsampling[1]==0) if (ycbcrsubsampling[0]*ycbcrsubsampling[1]==0)
{ {
TIFFErrorExt(tif->tif_clientdata,module, TIFFErrorExt(tif->tif_clientdata,module,
@ -300,7 +302,9 @@ TIFFScanlineSize64(TIFF* tif)
uint64_new scanline_size; uint64_new scanline_size;
if (td->td_planarconfig==PLANARCONFIG_CONTIG) if (td->td_planarconfig==PLANARCONFIG_CONTIG)
{ {
if ((td->td_photometric==PHOTOMETRIC_YCBCR)&&(!isUpSampled(tif))) if ((td->td_photometric==PHOTOMETRIC_YCBCR)&&
(td->td_samplesperpixel==3)&&
(!isUpSampled(tif)))
{ {
uint16 ycbcrsubsampling[2]; uint16 ycbcrsubsampling[2];
uint16 samplingblock_samples; uint16 samplingblock_samples;
@ -308,7 +312,7 @@ TIFFScanlineSize64(TIFF* tif)
uint64_new samplingrow_samples; uint64_new samplingrow_samples;
uint64_new samplingrow_size; uint64_new samplingrow_size;
assert(td->td_samplesperpixel==3); assert(td->td_samplesperpixel==3);
TIFFGetField(tif,TIFFTAG_YCBCRSUBSAMPLING,ycbcrsubsampling+0, TIFFGetFieldDefaulted(tif,TIFFTAG_YCBCRSUBSAMPLING,ycbcrsubsampling+0,
ycbcrsubsampling+1); ycbcrsubsampling+1);
assert((ycbcrsubsampling[0]==1)||(ycbcrsubsampling[0]==2)||(ycbcrsubsampling[0]==4)); assert((ycbcrsubsampling[0]==1)||(ycbcrsubsampling[0]==2)||(ycbcrsubsampling[0]==4));
assert((ycbcrsubsampling[1]==1)||(ycbcrsubsampling[1]==2)||(ycbcrsubsampling[1]==4)); assert((ycbcrsubsampling[1]==1)||(ycbcrsubsampling[1]==2)||(ycbcrsubsampling[1]==4));

View File

@ -1,4 +1,4 @@
/* $Id: tif_tile.c,v 1.16 2007-04-04 04:16:08 joris Exp $ */ /* $Id: tif_tile.c,v 1.17 2007-05-31 13:33:51 joris Exp $ */
/* /*
* Copyright (c) 1991-1997 Sam Leffler * Copyright (c) 1991-1997 Sam Leffler
@ -222,7 +222,8 @@ TIFFVTileSize64(TIFF* tif, uint32 nrows)
td->td_tiledepth == 0) td->td_tiledepth == 0)
return (0); return (0);
if ((td->td_planarconfig==PLANARCONFIG_CONTIG)&& if ((td->td_planarconfig==PLANARCONFIG_CONTIG)&&
(td->td_photometric == PHOTOMETRIC_YCBCR)&& (td->td_photometric==PHOTOMETRIC_YCBCR)&&
(td->td_samplesperpixel==3)&&
(!isUpSampled(tif))) (!isUpSampled(tif)))
{ {
/* /*
@ -239,9 +240,10 @@ TIFFVTileSize64(TIFF* tif, uint32 nrows)
uint32 samplingblocks_ver; uint32 samplingblocks_ver;
uint64_new samplingrow_samples; uint64_new samplingrow_samples;
uint64_new samplingrow_size; uint64_new samplingrow_size;
assert(td->td_samplesperpixel==3); TIFFGetFieldDefaulted(tif,TIFFTAG_YCBCRSUBSAMPLING,ycbcrsubsampling+0,
TIFFGetField(tif,TIFFTAG_YCBCRSUBSAMPLING,ycbcrsubsampling+0,
ycbcrsubsampling+1); ycbcrsubsampling+1);
assert((ycbcrsubsampling[0]==1)||(ycbcrsubsampling[0]==2)||(ycbcrsubsampling[0]==4));
assert((ycbcrsubsampling[1]==1)||(ycbcrsubsampling[1]==2)||(ycbcrsubsampling[1]==4));
if (ycbcrsubsampling[0]*ycbcrsubsampling[1]==0) if (ycbcrsubsampling[0]*ycbcrsubsampling[1]==0)
{ {
TIFFErrorExt(tif->tif_clientdata,module, TIFFErrorExt(tif->tif_clientdata,module,